1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
| <?php
class d3ribbon
{
/**
* D3Ribbon Class and Styles Folder Name
* @var string
*/
public $main_folder = 'd3ribbon';
/**
* Style folder name
*
* @var mixed
*/
public $stlye = 'blue';
/**
* Active tab for creating groups and buttons.
*
* @var mixed
*/
public $selected_category_id;
/**
* Active Button for set as selected
*
* @var mixed
*/
public $selected_button_id;
/**
* Category Objects
*
* @var mixed
*/
private $categories =array();
/**
* Group Objects
*
* @var mixed
*/
private $groups =array();
/**
* Button Objects
*
* @var mixed
*/
private $buttons =array();
/**
* Add Category (Tab)
*
* @param mixed $category_name
* @param mixed $category_link
* @param mixed $category_id
*
* @return mixed category id
*/
public function add_category($category_name,$category_link, $category_id = null)
{
if($category_id === null)
$category_id = count($this->categories)+1;
$this->categories[$category_id]=array(
'name' => $category_name,
'link' => $category_link,
'id' => $category_id
);
return (string)$category_id;
}
/**
* Add Group to a Created Category
*
* @param mixed $category_id owner category id
* @param mixed $group_name group display name
* @param mixed $group_width group width
* @param mixed $group_id group id
* @return string group id
*/
public function add_group($category_id,$group_name,$group_width = null,$group_id = null)
{
if($group_id === null)
$group_id = count($this->groups) + 1;
$this->groups[$category_id][$group_id] = array(
'name' => $group_name,
'id' => $group_id
);
$this->groups[$category_id][$group_id]['width'] = $group_width;
return (string)$group_id;
}
/**
* Add a button to created group
*
* @param mixed $group_id owner group id
* @param mixed $button_name button display name
* @param mixed $link button link
* @param mixed $image button image
* @param mixed $button_id button id
*/
function add_button($group_id,$button_name,$link,$image,$button_id=null)
{
if($button_id === null)
$button_id = count($this->buttons)+1;
$this->buttons[$group_id][$button_id]=array(
'name' => $button_name,
'link' => $link,
'image' => $image,
'id' => $button_id
);
return $button_id;
}
/**
* Build the Ribbon.
*
* @param mixed $return
*/
function build($return = true)
{
$ribbon='<table width="100%" cellspacing="0" cellpadding="0">
<tr>
<td id="cdnavcont" align="center">
'.$this->build_ribbon_header($this->selected_category_id).'
</td>
</tr>
<tr>
<td id="cdribbon" valign="top" align="center">
'.$this->build_ribbon_body($this->selected_category_id).'
</td></tr>
</table> ';
if ($return)
return $ribbon;
else
echo $ribbon;
}
/**
* Build Ribbon header for categories
*
* @param mixed $selected_category_id
* @param mixed $return
*/
private function build_ribbon_header($selected_category_id,$return = true)
{
$header = '<div id="cdnavheader">
<ul>
'.$this->build_ribbon_category_links($selected_category_id).'
</ul>
</div>';
if ($return)
return $header;
else
echo $header;
}
/**
* Build Category Links.
*
* @param mixed $selected_id
* @param mixed $return
*/
private function build_ribbon_category_links($selected_id = '',$return = true)
{
$cat_links = '';
foreach ($this->categories as $cat)
{
$cat_links.=$this->build_ribbon_category_link($cat['id'],$selected_id == $cat['id']);
}
if ($return)
return $cat_links;
else
echo $cat_links;
}
/**
* Build single category
*
* @param mixed $category_id
* @param mixed $selected
* @param mixed $return
*/
private function build_ribbon_category_link($category_id,$selected = false,$return = true)
{
$cat = &$this->categories[$category_id];
$category_link = '<li id="'.($selected ? 'current' : 'cat_'.$category_id).'"><a href="'.$cat['link'].'"><span>'.$cat['name'].'</span></a></li> ';
if($return)
return $category_link;
else
echo $category_link;
}
/**
* Build Ribbon body (Groups and buttons )
*
* @param mixed $category_id
* @param mixed $return
*/
private function build_ribbon_body($category_id,$return = true)
{
$rbody = '<div id="ribbon_cd">
<table cellpadding="0" cellspacing="0" width="100%" border="0">
<tr valign="top">
<td width="2" class="cdribtopl"> </td>
<td width="946" class="cdribtopc"><div></div></td>
<td width="2" class="cdribtopr"></td>
</tr>
<tr valign="middle" height="79">
<td width="1" class="cdribmidl"><div></div></td>
<td width="946" class="cdribmidc">
<div style="padding-top:1px;" id="ribbon_burda">
<table cellpadding="0" cellspacing="0" border="0" class="cdribbontext">
<tr valign="top">
<td width="2"> </td>
'.$this->build_groups($category_id).'
</tr>
</table>
</div>
</td>
<td width="1" class="cdribmidr"> <div></div></td>
</tr>
<tr valign="top">
<td width="2" class="cdribbotl"> </td>
<td width="946" class="cdribbotc"></td>
<td width="2" class="cdribbotr"></td>
</tr>
</table>
</div>';
if ($return)
return $rbody;
else
echo $rbody;
}
/**
* Build All Groups with their buttons by category_id
*
* @param mixed $category_id
* @param mixed $return
*/
function build_groups($category_id,$return = true)
{
$groups = "";
if (isset($this->groups[$category_id]) && is_array($this->groups[$category_id]))
{
foreach ($this->groups[$category_id] as $group)
{
$groups.=$this->build_group($category_id,$group['id']);
}
}
if ($return)
return $groups;
else
echo $groups;
}
/**
* Build Single Group
*
* @param mixed $category_id
* @param mixed $group_id
* @param mixed $return
*/
private function build_group($category_id,$group_id,$return = true)
{
$group = &$this->groups[$category_id][$group_id];
return ' <td>
<div class="cntRibbonborder">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="2" class="cdchutopl"></td>
<td class="cdchutopc"><div></div></td>
<td width="2" class="cdchutopr"></td></tr>
<tr valign="middle" height="74">
<td width="1" class="cdchumidl"><div></div></td>
<td '.(isset($group['width']) ? 'width="'.$group['width'].'"' : '').' class="cdchumidc" onmouseover="this.className=\'cdchumidcover\'" onmouseout="this.className=\'cdchumidc\'">
<table height="85" cellspacing="0" width="100%">
<tr><td class="buttonlar">
<table height="100%">
<tr>
'.$this->build_buttons($group_id).'
</tr>
</table>
</td></tr>
<tr><td class="kategori_foot" align="center">'.$group['name'].'</td></tr>
</table>
</td>
<td width="1" class="cdchumidr"><div></div></td>
</tr>
<tr valign="top"><td width="2" class="cdchubotl">
</td><td class="cdchubotc"><div></div></td>
<td width="2" class="cdchubotr"></td>
</tr>
</table>
</div>
</td>
<td width="2"></td> ';
}
/**
* Build all buttons in a group
*
* @param mixed $group_id
* @param mixed $return
*/
private function build_buttons($group_id,$return = true)
{
$buttons = "";
if (isset($this->buttons[$group_id]) && is_array($this->buttons[$group_id]))
{
foreach ($this->buttons[$group_id] as $btn)
{
$buttons.=$this->build_button($group_id,$btn['id']);
}
}
if ($return)
return $buttons;
else
echo $buttons;
}
/**
* build single button by id.
*
* @param mixed $group_id
* @param mixed $button_id
* @param mixed $return
*/
private function build_button($group_id,$button_id,$return = true)
{
$button = &$this->buttons[$group_id][$button_id];
if ($this->selected_button_id==$button_id)
{
$c1="button_over";
$c2="button_over";
}
else
{
$c1="button";
$c2="button_over";
}
$button_code = '<td align="center" class="'.$c1.'" onmouseover="this.className=\''.$c2.'\';" onmouseout="this.className=\''.$c1.'\';">
<a href="'.$button['link'].'"><img border="0" src="'.$button['image'].'" width="32"><br>
'.$button['name'].' </a>
</td>';
if ($return)
return $button_code;
else
echo $button_code;
}
/**
* get style folder path
*/
public function stlyes_folder() { return $this->main_folder.'/styles/'; }
/**
* get style file
*
*/
public function style_file() { return $this->stlyes_folder().$this->stlye.'/d3ribbon.css'; }
/**
* get style file link
*
*/
public function style_link() { return '<link href="'.$this->style_file().'" type="text/css" rel="stylesheet">';}
}
?> |
Partager