| [ Index ] |
|
Code source de e107 0.7.8 |
1 <?php 2 /* 3 + ----------------------------------------------------------------------------+ 4 | e107 website system 5 | 6 | ©Steve Dunstan 2001-2002 7 | http://e107.org 8 | jalist@e107.org 9 | 10 | Released under the terms and conditions of the 11 | GNU General Public License (http://gnu.org). 12 | 13 | $Source: /cvsroot/e107/e107_0.7/e107_handlers/theme_handler.php,v $ 14 | $Revision: 1.34 $ 15 | $Date: 2007/02/04 21:42:26 $ 16 | $Author: e107steved $ 17 +----------------------------------------------------------------------------+ 18 */ 19 20 if (!defined('e107_INIT')) { exit; } 21 22 class themeHandler{ 23 24 var $themeArray; 25 var $action; 26 var $id; 27 28 /* constructor */ 29 30 function themeHandler() { 31 32 if (isset($_POST['upload'])) { 33 $this -> themeUpload(); 34 } 35 36 $this -> themeArray = $this -> getThemes(); 37 38 foreach($_POST as $key => $post) 39 { 40 if(strstr($key,"preview")) 41 { 42 $this -> id = str_replace("preview_", "", $key); 43 $this -> themePreview(); 44 } 45 if(strstr($key,"selectmain")) 46 { 47 $this -> id = str_replace("selectmain_", "", $key); 48 $this -> setTheme(); 49 } 50 51 if(strstr($key,"selectadmin")) 52 { 53 $this -> id = str_replace("selectadmin_", "", $key); 54 $this -> setAdminTheme(); 55 } 56 } 57 58 if(isset($_POST['submit_adminstyle'])) 59 { 60 $this -> setAdminStyle(); 61 } 62 63 if(isset($_POST['submit_style'])) 64 { 65 $this -> setStyle(); 66 } 67 68 } 69 70 function getThemes($mode=FALSE) 71 { 72 $themeArray = array(); 73 $tloop = 1; 74 $handle = opendir(e_THEME); 75 while (false !== ($file = readdir($handle))) { 76 if ($file != "." && $file != ".." && $file != "CVS" && $file != "templates" && is_dir(e_THEME.$file) && file_exists(e_THEME.$file."/theme.php")) { 77 if($mode == "id") { 78 $themeArray[$tloop] = $file; 79 } else { 80 $themeArray[$file]['id'] = $tloop; 81 } 82 $tloop++; 83 $STYLESHEET = FALSE; 84 if(!$mode) { 85 $handle2 = opendir(e_THEME.$file."/"); 86 while (false !== ($file2 = readdir($handle2))) { 87 if ($file2 != "." && $file2 != ".." && $file != "CVS" && !is_dir(e_THEME.$file."/".$file2)) { 88 $themeArray[$file]['files'][] = $file2; 89 if(strstr($file2, "preview.")) { 90 $themeArray[$file]['preview'] = e_THEME.$file."/".$file2; 91 } 92 if(strstr($file2, "css") && !strstr($file2, "menu.css") && strpos($file2, "e_") !== 0 && strpos($file2, "admin_") !== 0) 93 { 94 /* get information string */ 95 $fp=fopen(e_THEME.$file."/".$file2, "r"); 96 $cssContents = fread ($fp, filesize(e_THEME.$file."/".$file2)); 97 fclose($fp); 98 $nonadmin = preg_match('/\* Non-Admin(.*?)\*\//', $cssContents) ? true : false; 99 preg_match('/\* info:(.*?)\*\//', $cssContents, $match); 100 $match[1]=varset($match[1],''); 101 $themeArray[$file]['css'][] = array("name" => $file2, "info" => $match[1], "nonadmin" => $nonadmin); 102 if($STYLESHEET) 103 { 104 $themeArray[$file]['multipleStylesheets'] = TRUE; 105 } 106 else 107 { 108 $STYLESHEET = TRUE; 109 } 110 111 } 112 } 113 $fp=fopen(e_THEME.$file."/theme.php", "r"); 114 $themeContents = fread ($fp, filesize(e_THEME.$file."/theme.php")); 115 fclose($fp); 116 preg_match('/themename(\s*?=\s*?)("|\')(.*?)("|\');/si', $themeContents, $match); 117 $themeArray[$file]['name'] = varset($match[3],''); 118 preg_match('/themeversion(\s*?=\s*?)("|\')(.*?)("|\');/si', $themeContents, $match); 119 $themeArray[$file]['version'] = varset($match[3],''); 120 preg_match('/themeauthor(\s*?=\s*?)("|\')(.*?)("|\');/si', $themeContents, $match); 121 $themeArray[$file]['author'] = varset($match[3],''); 122 preg_match('/themeemail(\s*?=\s*?)("|\')(.*?)("|\');/si', $themeContents, $match); 123 $themeArray[$file]['email'] = varset($match[3],''); 124 preg_match('/themewebsite(\s*?=\s*?)("|\')(.*?)("|\');/si', $themeContents, $match); 125 $themeArray[$file]['website'] = varset($match[3],''); 126 preg_match('/themedate(\s*?=\s*?)("|\')(.*?)("|\');/si', $themeContents, $match); 127 $themeArray[$file]['date'] = varset($match[3],''); 128 preg_match('/themeinfo(\s*?=\s*?)("|\')(.*?)("|\');/si', $themeContents, $match); 129 $themeArray[$file]['info'] = varset($match[3],''); 130 131 preg_match('/xhtmlcompliant(\s*?=\s*?)(\S*?);/si', $themeContents, $match); 132 $xhtml = strtolower($match[2]); 133 $themeArray[$file]['xhtmlcompliant'] = ($xhtml == "true" ? true : false); 134 135 preg_match('/csscompliant(\s*?=\s*?)(\S*?);/si', $themeContents, $match); 136 $css = strtolower($match[2]); 137 $themeArray[$file]['csscompliant'] = ($css == "true" ? true : false); 138 139 if (!$themeArray[$file]['name']) 140 { 141 unset($themeArray[$file]); 142 } 143 } 144 closedir($handle2); 145 } 146 } 147 } 148 closedir($handle); 149 return $themeArray; 150 } 151 152 function themeUpload() 153 { 154 if (!$_POST['ac'] == md5(ADMINPWCHANGE)) { 155 exit; 156 } 157 global $ns; 158 extract($_FILES); 159 if(!is_writable(e_THEME)) { 160 $ns->tablerender(TPVLAN_16, TPVLAN_20); 161 } else { 162 require_once(e_HANDLER."upload_handler.php"); 163 $fileName = $file_userfile['name'][0]; 164 $fileSize = $file_userfile['size'][0]; 165 $fileType = $file_userfile['type'][0]; 166 167 if(strstr($file_userfile['type'][0], "gzip")) { 168 $fileType = "tar"; 169 } else if (strstr($file_userfile['type'][0], "zip")) { 170 $fileType = "zip"; 171 } else { 172 $ns->tablerender(TPVLAN_16, TPVLAN_17); 173 require_once ("footer.php"); 174 exit; 175 } 176 177 if ($fileSize) { 178 179 $uploaded = file_upload(e_THEME); 180 181 $archiveName = $uploaded[0]['name']; 182 183 184 if($fileType == "zip") { 185 require_once(e_HANDLER."pclzip.lib.php"); 186 $archive = new PclZip(e_THEME.$archiveName); 187 $unarc = ($fileList = $archive -> extract(PCLZIP_OPT_PATH, e_THEME)); 188 $unarc = ($fileList = $archive -> extract(PCLZIP_OPT_PATH, e_THEME, PCLZIP_OPT_SET_CHMOD, 0666)); 189 } else { 190 require_once(e_HANDLER."pcltar.lib.php"); 191 $unarc = ($fileList = PclTarExtract($archiveName, e_THEME)); 192 } 193 194 if(!$unarc) { 195 if($fileType == "zip") { 196 $error = TPVLAN_46." '".$archive -> errorName(TRUE)."'"; 197 } else { 198 $error = TPVLAN_47.PclErrorString().", ".TPVLAN_48.intval(PclErrorCode()); 199 } 200 $ns->tablerender(TPVLAN_16, TPVLAN_18." ".$archiveName." ".$error); 201 require_once ("footer.php"); 202 exit; 203 } 204 205 $folderName = substr($fileList[0]['stored_filename'], 0, (strpos($fileList[0]['stored_filename'], "/"))); 206 $ns->tablerender(TPVLAN_16, "<div class='center'>".TPVLAN_19."</div>"); 207 208 @unlink(e_THEME.$archiveName); 209 } 210 } 211 } 212 213 function showThemes() 214 { 215 global $ns, $pref; 216 echo "<div class='center'> 217 <form enctype='multipart/form-data' method='post' action='".e_SELF."'>\n"; 218 219 foreach($this -> themeArray as $key => $theme) 220 { 221 if($key == $pref['sitetheme']) 222 { 223 $text = $this -> renderTheme(1, $theme); 224 } 225 } 226 227 $ns->tablerender(TPVLAN_26." :: ".TPVLAN_33, $text); 228 229 foreach($this -> themeArray as $key => $theme) 230 { 231 if($key == $pref['admintheme']) 232 { 233 $text = $this -> renderTheme(2, $theme); 234 } 235 } 236 $ns->tablerender(TPVLAN_26." :: ".TPVLAN_34, $text); 237 238 239 if(!is_writable(e_THEME)) { 240 $ns->tablerender(TPVLAN_16, TPVLAN_15); 241 $text = ""; 242 } else { 243 $text = "<div style='text-align:center'> 244 <table style='".ADMIN_WIDTH."' class='fborder'> 245 <tr> 246 <td class='forumheader3' style='width: 50%;'>".TPVLAN_13."</td> 247 <td class='forumheader3' style='width: 50%;'> 248 <input type='hidden' name='MAX_FILE_SIZE' value='1000000' /> 249 <input type='hidden' name='ac' value='".md5(ADMINPWCHANGE)."' /> 250 <input class='tbox' type='file' name='file_userfile[]' size='50' /> 251 </td> 252 </tr> 253 <tr> 254 <td colspan='2' style='text-align:center' class='forumheader'> 255 <input class='button' type='submit' name='upload' value='".TPVLAN_14."' /> 256 </td> 257 </tr> 258 </table> 259 <br /></div>\n"; 260 } 261 262 $ns->tablerender(TPVLAN_26." :: ".TPVLAN_38, $text); 263 $text = ""; 264 foreach($this -> themeArray as $key => $theme) 265 { 266 if($key != $pref['admintheme'] && $key != $pref['sitetheme']) 267 { 268 $text .= $this -> renderTheme(FALSE, $theme); 269 } 270 } 271 272 273 274 $ns->tablerender(TPVLAN_26." :: ".TPVLAN_39, $text); 275 echo "</form>\n</div>\n"; 276 } 277 278 279 280 281 function renderTheme($mode=FALSE, $theme) 282 { 283 284 /* 285 mode = 0 :: normal 286 mode = 1 :: selected site theme 287 mode = 2 :: selected admin theme 288 */ 289 290 global $ns, $pref; 291 292 $author = ($theme['email'] ? "<a href='mailto:".$theme['email']."' title='".$theme['email']."'>".$theme['author']."</a>" : $theme['author']); 293 $website = ($theme['website'] ? "<a href='".$theme['website']."' rel='external'>".$theme['website']."</a>" : ""); 294 $preview = "<a href='".e_BASE."news.php?themepreview.".$theme['id']."' title='".TPVLAN_9."' >".($theme['preview'] ? "<img src='".$theme['preview']."' style='border: 1px solid #000;width:200px' alt='' />" : "<img src='".e_IMAGE."admin_images/nopreview.png' style='border:0px' title='".TPVLAN_12."' alt='' />")."</a>"; 295 $selectmainbutton = ($mode != 1 ? "<input class='button' type='submit' name='selectmain_".$theme['id']."' value='".TPVLAN_10."' />" : ""); 296 $selectadminbutton = ($mode != 2 ? "<input class='button' type='submit' name='selectadmin_".$theme['id']."' value='".TPVLAN_32."' />" : ""); 297 $previewbutton = (!$mode ? "<input class='button' type='submit' name='preview_".$theme['id']."' value='".TPVLAN_9."' /> " : ""); 298 299 $text = "<div style='text-align:center;margin-left:auto;margin-right:auto'> 300 <table style='".ADMIN_WIDTH."' class='fborder'> 301 <tr> 302 <td class='forumheader3' style='width:202px; text-align:center; vertical-align:top'>$preview 303 <br /> 304 <br /> 305 <b><span class='mediumtext'>".$theme['name']."</span></b><br />".TPVLAN_11." ".$theme['version']." 306 <br /> 307 </td> 308 <td class='forumheader3' style='vertical-align:top'>"; 309 310 $itext = $author ? "<tr><td style='vertical-align:top; width:24%'><b>".TPVLAN_4."</b>:</td><td style='vertical-align:top'>".$author."</td></tr>" : ""; 311 $itext .= $website ? "<tr><td style='vertical-align:top; width:24%'><b>".TPVLAN_5."</b>:</td><td style='vertical-align:top'>".$website."</td></tr>" : ""; 312 $itext .= $theme['date'] ? "<tr><td style='vertical-align:top; width:24%'><b>".TPVLAN_6."</b>:</td><td style='vertical-align:top'>".$theme['date']."</td></tr>" : ""; 313 $itext .= $theme['info'] ? "<tr><td style='vertical-align:top; width:24%'><b>".TPVLAN_7."</b>:</td><td style='vertical-align:top'>".$theme['info']."</td></tr>" : ""; 314 $itext .= !$mode ? "<tr><td style='vertical-align:top'><b>".TPVLAN_8."</b>:</td><td style='vertical-align:top'>".$previewbutton.$selectmainbutton.$selectadminbutton."</td></tr>" : ""; 315 316 317 if ($itext) { 318 $text .= "<table cellspacing='3' style='width:97%'>".$itext."</table>"; 319 } 320 321 if(array_key_exists("multipleStylesheets", $theme)) 322 { 323 if($mode) 324 { 325 $text .= "<table cellspacing='3' style='width:97%'> 326 <tr><td style='vertical-align:top; width:50%;'><b>".TPVLAN_27.":</b></td><td style='vertical-align:top width:50%;'>\n"; 327 foreach($theme['css'] as $css) 328 { 329 330 if($mode == 2) 331 { 332 if (!$css['nonadmin']) { 333 $text .= " 334 <input type='radio' name='admincss' value='".$css['name']."' ".($pref['admincss'] == $css['name'] || (!$pref['admincss'] && $css['name'] == "style.css") ? " checked='checked'" : "")." /><b>".$css['name'].":</b><br />".($css['info'] ? $css['info'] : ($css['name'] == "style.css" ? TPVLAN_23 : TPVLAN_24))."<br />\n"; 335 } 336 } 337 338 if($mode == 1) 339 { 340 $text .= " 341 <input type='radio' name='themecss' value='".$css['name']."' ".($pref['themecss'] == $css['name'] || (!$pref['themecss'] && $css['name'] == "style.css") ? " checked='checked'" : "")." /><b>".$css['name'].":</b><br />".($css['info'] ? $css['info'] : ($css['name'] == "style.css" ? TPVLAN_23 : TPVLAN_24))."<br />\n"; 342 } 343 } 344 $text .= "</td></tr></table>"; 345 346 } 347 else 348 { 349 $text .= "<br /><table style='width:97%' cellspacing='3'><tr><td colspan='2'><b>".TPVLAN_22.": </b></td></tr>"; 350 foreach($theme['css'] as $css) 351 { 352 $text .= "<tr><td style='width:24%;vertical-align:top'><b>".$css['name'].":</b></td><td> ".($css['info'] ? $css['info'] : ($css['name'] == "style.css" ? TPVLAN_23 : TPVLAN_24))."</td></tr>\n"; 353 } 354 $text .= "</table><br />\n"; 355 } 356 } 357 358 if($mode == 1) 359 { 360 $text .= "<table cellspacing='3' style='width:97%'> 361 362 <tr> 363 <td style='vertical-align:top; width:50%;'><b>".TPVLAN_30."</b></td><td style='vertical-align:top width:50%;'> 364 <input type='radio' name='image_preload' value='1'".($pref['image_preload'] ? " checked='checked'" : "")." /> ".TPVLAN_28." 365 <input type='radio' name='image_preload' value='0'".(!$pref['image_preload'] ? " checked='checked'" : "")." /> ".TPVLAN_29." 366 </td> 367 </tr> 368 <tr> 369 <td colspan='2' class='center'> 370 <input class='button' type='submit' name='submit_style' value='".TPVLAN_35."' /> ".$selectadminbutton." 371 </td></tr></table>"; 372 } 373 374 if($mode == 2) 375 { 376 377 $astext = ""; 378 require_once(e_HANDLER."file_class.php"); 379 $file = new e_file; 380 381 $adminstyles = $file -> get_files(e_ADMIN."includes"); 382 383 $astext = "<select id='mode2' name='adminstyle' class='tbox'>\n"; 384 385 foreach($adminstyles as $as) 386 { 387 $style = str_replace(".php", "", $as['fname']); 388 $astext .= "<option".($pref['adminstyle'] == $style ? " selected='selected'" : "").">".$style."</option>\n"; 389 } 390 $astext .= "</select>"; 391 392 $text .= "<br /><br /><table cellspacing='3' style='width:97%'> 393 <tr><td style='vertical-align:top; width:50%;'><b>".TPVLAN_41.":</b></td><td style='vertical-align:top width:50%;'>$astext</td></tr> 394 <tr><td colspan='2' class='center'> 395 <input class='button' type='submit' name='submit_adminstyle' value='".TPVLAN_42."' /> ".$selectmainbutton." 396 </td></tr></table>\n"; 397 } 398 399 if($theme['xhtmlcompliant'] || $theme['xhtmlcompliant']) 400 { 401 $text .= "<table cellspacing='3' style='width:97%'><tr><td >"; 402 $text .= ($theme['xhtmlcompliant']) ? "<img src='".e_IMAGE."generic/valid-xhtml11_small.png' alt='' style='border: 0px;' /> ": ""; 403 $text .= ($theme['csscompliant']) ? "<img src='".e_IMAGE."generic/vcss_small.png' alt='' style='border: 0px;' /> " : ""; 404 $text .= "</td></tr></table>"; 405 } 406 407 $text .= "</td></tr></table></div>\n"; 408 return $text; 409 410 } 411 412 function themePreview() 413 { 414 echo "<script type='text/javascript'>document.location.href='".e_BASE."news.php?themepreview.".$this -> id."'</script>\n"; 415 exit; 416 } 417 418 function showPreview() 419 { 420 @include_once(e_LANGUAGE."admin/lan_theme.php"); 421 @include_once(e_LANGUAGEDIR.e_LANGUAGE."/admin/lan_theme.php"); 422 $text = "<br /><div class='indent'>".TPVLAN_1.".</div><br />"; 423 global $ns; 424 $ns->tablerender(TPVLAN_2, $text); 425 } 426 427 function setTheme() 428 { 429 global $pref, $e107cache, $ns; 430 $themeArray = $this -> getThemes("id"); 431 $pref['sitetheme'] = $themeArray[$this -> id]; 432 $pref['themecss'] ='style.css'; 433 $e107cache->clear(); 434 save_prefs(); 435 $ns->tablerender("Admin Message", "<br /><div style='text-align:center;'>".TPVLAN_3." <b>'".$themeArray[$this -> id]."'</b>.</div><br />"); 436 } 437 438 function setAdminTheme() 439 { 440 global $pref, $e107cache, $ns; 441 $themeArray = $this -> getThemes("id"); 442 $pref['admintheme'] = $themeArray[$this -> id]; 443 $pref['admincss'] = file_exists(THEME.'admin_style.css') ? 'admin_style.css' : 'style.css'; 444 $e107cache->clear(); 445 save_prefs(); 446 $ns->tablerender("Admin Message", "<br /><div style='text-align:center;'>".TPVLAN_40." <b>'".$themeArray[$this -> id]."'</b>.</div><br />"); 447 } 448 449 function setStyle() 450 { 451 global $pref, $e107cache, $ns; 452 $pref['themecss'] = $_POST['themecss']; 453 $pref['image_preload'] = $_POST['image_preload']; 454 $e107cache->clear(); 455 save_prefs(); 456 $ns->tablerender(TPVLAN_36, "<br /><div style='text-align:center;'>".TPVLAN_37.".</div><br />"); 457 } 458 459 function setAdminStyle() 460 { 461 global $pref, $e107cache, $ns; 462 $pref['admincss'] = $_POST['admincss']; 463 $pref['adminstyle'] = $_POST['adminstyle']; 464 $e107cache->clear(); 465 save_prefs(); 466 $ns->tablerender(TPVLAN_36, "<br /><div style='text-align:center;'>".TPVLAN_43.".</div><br />"); 467 } 468 469 } 470 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sun Apr 1 01:23:32 2007 | par Balluche grâce à PHPXref 0.7 |