WikyBlog PHP Cross Reference Collaborative Wikis

Source: /include/CLASStemplate.php - 865 lines - 26658 bytes - Summary - Text - Print

   1  <?php
   2  defined('WikyBlog') or die("Not an entry point...");
   3  
   4  
   5  
   6  //    test: template
   7  class CLASStemplate extends dbPage{
   8      // database values
   9      //var $objectType = 'template';
  10  
  11      
  12      //var $content; will contain the raw user data for $template
  13      //var $templateName; == title
  14      var $isTemplate = true;
  15      var $template;
  16      var $templateFileName;
  17      var $css1;
  18      var $css1FileName;
  19      var $css2 = false;
  20      var $css2FileName;
  21      var $tab_html = '';
  22      
  23      //var $keys = array('owner'=>1,'title'=>1);
  24      var $dbValues = array('owner'=>1,'title'=>1,'content'=>1,'tab_html'=>1);
  25      var $userValues = array('content'=>1,'css1'=>1,'css2'=>1,'keywords'=>1,'tab_html'=>1); //content is the raw user values
  26      var $files = array('templateFileName'=>1,'css1FileName'=>1,'css2FileName'=>1);
  27      
  28      //Translation
  29      var $translationArray = array();
  30      var $requiredVariables = array();
  31      var $oldTrans = array();
  32      var $toUser = array();
  33      var $toFile = array();
  34      
  35      
  36      var $varCharStart = '{{{';
  37      var $varCharEnd = '}}}';
  38      
  39  	function CLASStemplate($type){
  40          $this->objectType = $type;
  41          $this->setDbInfo();
  42          
  43          //    Translations can be much simpler once the user values are stored in the database..
  44          //    we'll no longer have the need to translate back to the user.. won't need the Commented Translations
  45          //
  46          
  47          /////////////////////////////////////////////////////////////////////////////////////
  48          //
  49          //        Commented Translations
  50          //        <!-- DisplayPage --> ... <!-- DisplayPage -->
  51          //        The PHP Value can be changed whenever without affecting the translation
  52          //        .. also opens door for hack by injecting php code... just use the translationArray[] oldTrans[] and
  53          //
  54          //
  55          //                ---User Value--      ---PHP Value--
  56          $this->newTranslation['Content'] = '<?php echo $page->displayPage() ?>';
  57          $this->newTranslation['ToolMenu'] = '<?php echo $page->displayActions(); ?>';
  58          $this->newTranslation['UserDir'] = '<?php echo "/userfiles/".toStorage($pageOwner["username"],true); ?>';
  59          $this->newTranslation['keywords'] = '<div id="WBkeywords"><?php getKeywords(); ?></div>';
  60          $this->newTranslation['UserMenu'] = '<div id="WBuserMenu"><?php getUserMenu(); ?></div>';
  61          $this->newTranslation['WBExtras'] = '<?php echo $page->extras; ?>';
  62          $this->newTranslation['PageFooter'] = '<?php echo $page->getFooter(); ?>';
  63          $this->newTranslation['WBSearch'] = '<?php echo $page->search(); ?>';
  64          
  65          //new values..
  66          //!!version V1.4.14
  67          $this->newTranslation['links'] = '<?php echo $page->getLinks(); ?>';
  68          $this->newTranslation['UserMenuNew'] = '<?php $page->userMenu(); ?>';
  69          $this->newTranslation['KeywordsNew'] = '<?php $page->getKeywords(); ?>';
  70          $this->newTranslation['NavBarNew'] = '<?php $page->getNavBar(); ?>';
  71          
  72          
  73                  
  74          /////////////////////////////////////////////////////////////////////////////////////
  75          //
  76          //        Simple Translations
  77          //
  78          // Some have to stay with the older/simpler translation
  79          $this->translationArray['PageOwner'] = '<?php echo toDisplay($pageOwner["username"]); ?>';
  80          $this->translationArray['PageTitle'] = '<?php echo $page->displayTitle; ?>';
  81          $this->translationArray['PageTitle2'] = '<?php echo $page->displayTitle2; ?>';
  82          $this->translationArray['ServerName1'] = '<?php echo $serverName1; ?>';
  83          $this->translationArray['ServerName2'] = '<?php echo $serverName2; ?>';
  84          $this->translationArray['ServerName3'] = '<?php echo $serverName3; ?>';
  85          $this->translationArray['linkPrefix'] = '<?php echo $GLOBALS["wbLinkPrefix"]; ?>';
  86          
  87          
  88          
  89          //--------------    replace        ------------------------    pattern        --------------------------------------
  90          
  91          //this needs to work for copying from package templates
  92          $this->toUser['[[specialLink:$1|$2]]'] = '#<\?php echo wbLinks::special\(\'([^\(\),]+)\',\'([^\(\),]+)\'\); \?>#';
  93          $this->toUser['[[localLink:$1|$2]]'] = '#<\?php echo wbLinks::local\(\'([^\(\),]*)\',\'([^\(\),]*)\'\); \?>#';
  94          $this->toUser['[[helpLink:$1|$2]]'] = '#<\?php echo wbLinks::help\(\'([^\(\),]+)\',\'([^\(\),]+)\'\); \?>#';
  95          $this->toUser['[[wbImage:$1]]'] = '#<\?php echo wbLinks::image\(\'([^\(\),]+)\'\); \?>#';
  96          
  97          
  98          //version ... phased out v1.1.5 2006-09-14
  99          //    this actually shouldn't pose a problem since we've been saving user displayable values in the database..
 100           $this->toUser['[[SpecialLink:$1|$2]]'] = '#<\?php echo specialLink\(\'([^\(\),]+)\',\'([^\(\),]+)\'\); \?>#'; 
 101           $this->toUser['[[LocalLink:$1|$2]]'] = '#<\?php echo localLink\(\'([^\(\),]+)\',\'([^\(\),]+)\'\); \?>#';
 102          
 103          /*--------------    replace        ------------------------    pattern        --------------------------------------
 104          */
 105          $this->toFile['formatTemplateLinks(\'$1\',\'$2\')'] = '#\[\[([a-z]*):([^\]]+?)\]\]#ie';
 106  
 107          
 108          
 109          // required
 110          $this->requiredVariables[] = 'Content';
 111          $this->requiredVariables[] = 'ToolMenu';
 112          //$this->requiredVariables[] = 'UserMenu';
 113          $this->requiredVariables[] = 'PageFooter';
 114          $this->requiredVariables[] = 'NavBarNew'; //used for map links
 115          $this->requiredVariables[] = 'WBExtras';
 116      }
 117      
 118  	function setKeys(&$pathArray){
 119          parent::setKeys($pathArray);
 120  /*
 121          if( is_numeric($this->title) ){
 122              message('numeric');
 123          }        
 124  */
 125          $this->setFileLocations();
 126      }
 127      
 128  	function setFileLocations(){
 129          // set file locations
 130          global $rootDir;
 131          $temp = $rootDir.'/templates/'.wbStrtolower($this->owner.'/'.$this->title);
 132          
 133          wbData::loadFileFunctions();
 134          if( !checkPath($temp,'templates') ){
 135              $this->editable = false;
 136              return;
 137          }
 138          
 139          $this->css1FileName = $temp.'/style1.css';
 140          $this->css2FileName = $temp.'/style2.css';
 141          $this->templateFileName = $temp.'/template.php';
 142      }
 143          
 144      
 145  	function setLinks(){
 146          global $page,$langA;
 147          
 148          $page->displayTitle = $langA['theme'].' > '.toDisplay($this->title);
 149          
 150          parent::setLinks();
 151          $page->regLink('?', $langA['theme']. '?en=Theme');
 152      }
 153      
 154  	function getStep1(&$pathArray){
 155          parent::getStep1($pathArray);
 156  
 157          
 158          $this->setFileLocations(); //because cmd=delete uses the file_id not the title
 159          
 160          if(!$this->exists){
 161              $this->isTemplate = false;
 162              return;
 163          }
 164          $this->setFromDisk();
 165      }
 166      
 167  	function setFromDisk(){
 168          //$_SESSION is not available here
 169          //$this->css1 = getContents($this->css1FileName);
 170          //$this->css2 = getContents($this->css2FileName);
 171          
 172          
 173          $this->template = getContents($this->templateFileName);
 174          $this->UpdateContent($this->template); //$this->template won't have any variables in user form at this state ... but we wan't it to be update so the check function doesn't report missing variables
 175          $this->UpdateContent($this->content);
 176          
 177          
 178          $this->css1 = getContents($this->css1FileName);
 179          
 180          $css2 = getContents($this->css2FileName);
 181          if( !empty($css2) ){
 182              $this->UpdateHead($this->content); //add rss feeds
 183              
 184              $this->css1 .= "\n".$css2;
 185              $this->css2 = true;
 186          }
 187          
 188      }
 189      
 190  	function setFromPost(){
 191          global $wbParser,$langA;
 192          initiateParser();
 193          //$_SESSION is available here
 194          
 195          // don't user parent::setFromPost() because we parseXML($template) right away... 
 196          //    but this might change with saving the raw user input in the database
 197          //
 198          //    parent::setFromPost();
 199          //         $this->setVariables( fromPost($_POST) , $this->userValues );
 200  
 201          globalFromPost();
 202          $this->setVariables($_POST , $this->userValues );
 203          
 204          //parseXML..
 205          //    should never have the 'safe' flag
 206          $this->template = $wbParser->parseXML($this->content,true,$this,true); //this is different for templates
 207          
 208          $this->getParserInfo();
 209          if( $wbParser && $wbParser->errors ){
 210              $link = wbLinks::local($this->uniqLink.'?cmd=viewErrors',$langA['syntax_error']);
 211          }
 212          
 213          $this->template =  $this->translateFromUser($this->template); //ok, which of these goes first!
 214          //$this->css1 =  $this->translateFromUser($this->css1);
 215          //$this->css2 =  $this->translateFromUser($this->css2);
 216          $this->css1 =  $this->translateFromUser($this->css1);
 217          
 218          
 219          // $this->validData = false;
 220          // message('To File: '.wbHtmlspecialchars($this->template));
 221          // message('To User: '.wbHtmlspecialchars($this->translateToUser($this->template)));
 222          
 223          if( $wbParser->errors ){
 224              $this->validData = false;
 225          }
 226      }
 227      
 228  	function checkData(){
 229          global $langA;
 230          if( !empty($this->tab_html) && !is_numeric($this->tab_html) ){
 231              message('Invalid tab_html');
 232              $this->validData = false;
 233              return false;
 234          }
 235          
 236          //already found to be bad by setFromPost
 237          if( $this->validData === false){
 238              
 239              $link = wbLinks::local($this->uniqLink.'?cmd=viewErrors',$langA['syntax_error']);
 240              message('THEME_SYNTAX_WARN');
 241              includeFile('tool/Errors.php');
 242              return;
 243          }
 244  
 245          $missing = array();
 246          $warn = false;
 247          
 248          foreach($this->requiredVariables as $variable){
 249              
 250              $variable = $this->varCharStart.$variable.$this->varCharEnd;
 251              
 252              if( strpos($this->template,$variable) === false){
 253                  $warn = true;
 254                  $missing[] = wbHtmlspecialchars($variable);
 255                  $this->validData = false;
 256              }
 257          }
 258          
 259          if( $warn ){
 260              message('THEME_MISSING_VARS',implode(', ',$missing));
 261              return;
 262          }
 263      }
 264      
 265  	function newPage(){
 266          global $page,$langA;
 267          parent::newPage();
 268          
 269          $field = $this->uniqLink;
 270          
 271          if( $this->editable ){
 272              $page->contentB[$field] = $langA['THEME_DEFAULT_CONTENT'];
 273              
 274              $page->contentB[$field] .='<blockquote>';
 275              foreach($this->requiredVariables as $var){
 276                  $var = $this->varCharStart.$var.$this->varCharEnd;
 277                  $page->contentB[$field] .= '<br/>'.$var;
 278              }
 279              $page->contentB[$field] .= '</blockquote>';
 280              
 281              
 282          }else{
 283              $page->contentB[$field] = $langA['DEFAULT_CONTENT_PROTECTED'];
 284          }
 285      }
 286      
 287      //
 288      //    When someone clicks "Create New Template", I want to give them a working template..
 289      //        -    The best way to do this would be to copy an existing (main/home).. but what if the site admin has added <script> tags and such..
 290      //        -    and, the user display version is in the database!.. does installation put it in the database?..no it doesn't
 291      //        ===>
 292      //            -    maybe the create package script should copy the template to a php file.. /include/
 293      //        
 294  	function copyPackageTheme(){
 295          global $page,$includeDir;
 296          $_POST += array('which'=>'');
 297          
 298          if( strpos($_POST['which'],'./') ){
 299              message('INVALID_THEME');
 300              return;
 301          }
 302              
 303          $dir = $includeDir.'/themes/'.$_POST['which'];
 304          if( !is_dir($dir)){
 305              message('INVALID_THEME');
 306              $page->userCmd = '';
 307              return;
 308          }
 309          
 310          $css1 = $dir.'/style1.css';
 311          //$css2 = $dir.'/style2.css';
 312          $template = dirname($dir).'/template.php';
 313          
 314          //for content negotiation
 315          $css1css = $css1.'.css';
 316          //$css2css = $css2.'.css';
 317          
 318          if( !is_file($template) ){
 319              message('INVALID_THEME');
 320              $page->userCmd = '';
 321              return;
 322          }
 323          
 324          
 325          if( is_file($css1) ){
 326              
 327              //$this->css1 = getContents($css1);
 328              //$this->css2 = getContents($css2);
 329              $this->css1 = getContents($css1);
 330  
 331          }elseif( is_file($css1css) ){
 332              
 333              //$this->css1 = getContents($css1css);
 334              //$this->css2 = getContents($css2css);
 335              $this->css1 = getContents($css1css);
 336                          
 337          }else{
 338              
 339              message('INVALID_THEME');
 340              $page->userCmd = '';
 341              return;
 342              
 343          }
 344          
 345          $this->template = getContents($template);
 346          $this->UpdateContent($this->template);
 347          
 348          
 349          //translate contents
 350          $this->content = $this->translateToUser($this->template);
 351          $this->translateCssUrls($this->css1);
 352          //$this->translateCssUrls($this->css2);
 353  
 354          $page->userCmd = 'edit';//'edit';
 355      }
 356      
 357      
 358  	function UpdateHead(&$text){
 359          global $pageOwner;
 360          // rss links
 361          //!! this won't work, it'll keep adding these links to the head over and over
 362          $htmlHead[] = '<link href="'.wbLinks::getUrl('/Special/'.$pageOwner['username'].'/atom?field=blog').'" rel="alternate" title="Blog Feed for '.$pageOwner['username'].'" type="application/rss+xml" />';
 363          $htmlHead[] = '<link href="'.wbLinks::getUrl('/Special/'.$pageOwner['username'].'/atom').'" rel="alternate" title="Recently Modified Feed for '.$pageOwner['username'].'" type="application/rss+xml" />'; //!!lang
 364          $htmlHead[] = '<link href="'.wbLinks::getUrl('/Special/'.$pageOwner['username'].'/atom?field=1').'" rel="alternate" title="Recently Posted Feed for '.$pageOwner['username'].'" type="application/rss+xml" />';
 365          $htmlHead = implode("\n",$htmlHead) . "\n\n</head";
 366          
 367          $text = str_replace('</head',$htmlHead,$text);
 368      }
 369          
 370      
 371      
 372      //Update old themes with new data
 373  	function UpdateContent(&$text){
 374          global $pageOwner;
 375          
 376          $text = str_replace('&NavBar&','&NavBarNew&',$text);
 377          
 378          $FromValues = array();
 379          $ToValues = array();
 380          
 381          foreach($this->newTranslation as $key => $value){
 382              $FromValues[] = '&'.$key.'&';
 383              $ToValues[] = $this->varCharStart.$key.$this->varCharEnd;
 384          }
 385          
 386          foreach($this->translationArray as $VarName => $VarValue){
 387              $FromValues[] = '&'.$VarName.'&';
 388              $ToValues[] = $this->varCharStart.$VarName.$this->varCharEnd;
 389          }
 390          $text = str_replace($FromValues,$ToValues,$text);
 391      }
 392      
 393          
 394          
 395          
 396      
 397      
 398      //    from    /plugins/default/blue/
 399      //    to        /templates/username/tname/
 400  	function translateCssUrls(&$css){
 401          global $rootDir;
 402          $matches = array();
 403          
 404          $full = '';
 405          preg_match_all('#url\(([^\)\(]*)\)#',$css,$matches,PREG_PATTERN_ORDER);
 406          $matches = array_unique($matches[1]);
 407  
 408          $pluginPath = array('include','themes');
 409          $pluginPath = array_merge( $pluginPath, explode('/',$_POST['which']));
 410          foreach($matches as $path){
 411              $replace = $path;
 412              $temp = $pluginPath;
 413              while( (strpos($path,'../') === 0) && (count($temp) > 0)){
 414                  $path = substr($path,3);
 415                  array_pop($temp);
 416              }
 417              if( count($temp) == 0){
 418                  $newPath = '../../../'.$path;
 419              }else{
 420                  $newPath = '../../../'.implode('/',$temp).'/'.$path;
 421              }
 422              
 423              //message('replace: '.$replace.' with '.$newPath);
 424              $css = str_replace('url('.$replace.')','url('.$newPath.')',$css);
 425          }
 426      }
 427      
 428  	function doActions(){
 429          global $page,$langA;
 430          
 431          
 432          switch( $page->userCmd ){
 433              case 'copydefault':
 434                  $this->copyPackageTheme();
 435              break;
 436  //             case 'editlinks':
 437  //                 $this->editLinks();
 438  //             break;
 439              
 440          }
 441          parent::doActions();
 442      }
 443          
 444      
 445      //this method would leave the links hard coded into the template, 
 446      //making things less than ideal for someone playing around with multiple templates
 447  	function editLinks(){
 448          //message('here: '.nl2br(htmlspecialchars($this->content)) );
 449          
 450          $regExp = '#<[dD][iI][vV][^<]*class="sideMenuArea".*?</[dD][iI][vV]>#msi';
 451          preg_match_all($regExp,$this->content,$matches,PREG_PATTERN_ORDER);
 452          
 453          message(showArray($matches));
 454      }
 455          
 456  
 457      
 458      
 459  	function toDB(){//aka save
 460          
 461          if( !$this->validData ){
 462              return false;
 463          }
 464          wbData::loadFileFunctions();
 465          
 466          $repl = '<'.'?php $page->htmlHead();';
 467          $repl .= ' ?'.'>';
 468          $repl .= "\n</head";
 469                          
 470          $template = '<'.'?php defined(\'WikyBlog\') or die(\'Not an entry point...\'); '."\n";
 471          
 472          $template .= 'global $wbTabHtml;'."\n";
 473          $template .= '$wbTabHtml = '.$this->tab_html.';';    //this has to be on it's own line!
 474          $template .= "\n";
 475          $template .= '?'.'>';
 476          $template .= "\n\n";
 477          $template .= str_replace('</head',$repl,$this->template);
 478  
 479          
 480          $bool = saveFile($this->css1FileName, $this->css1);
 481          //$bool = $bool && saveFile($this->css2FileName, $this->css2);
 482          $bool = $bool && saveFile($this->templateFileName, $template);
 483          
 484          
 485          //to delete the css2 file so it's not added over and over to the css1 file
 486          if( $this->css2 !== false ){
 487              $temp = '';
 488              saveFile($this->css2FileName, $temp);    //write empty
 489              @wbUnlink($this->css2FileName);            //try to delete it
 490          }
 491  
 492          
 493          if( !($bool) ){
 494              return false;
 495          }
 496          
 497          //so that the update will always change!.. 
 498          //    this breaks one of the checks to see if changes were made in toolSavePage.php
 499          return parent::toDB();
 500      }
 501  
 502      //called by preview and viewing page
 503      //    this is where css would be included in a page
 504  	function outputObj($field=true){
 505          global $page,$langA;
 506          static $notShown = true;
 507          static $i = 0;
 508          
 509          
 510          if( !$this->validData ){
 511              return false;
 512          }
 513          if( $field === true ){
 514              $field = $this->uniqLink;
 515          }
 516          
 517          $notShown = true;
 518          
 519          ob_start();
 520          echo '<div style="margin:2em 7em 2em 7em;">';
 521          
 522          
 523          if( isset($_SESSION['username']) ){
 524  
 525              echo '<h2>'.$langA['your_theme'].'</h2>';
 526              if( isset($_SESSION['template']) && (toStorage($_SESSION['template'],true) == toStorage($this->owner.'/'.$this->title,true)) ){
 527                  echo $langA['using_this_theme'];
 528                  
 529              }else{
 530                  if( isset($_SESSION['template']) ){
 531                      echo '<p>'.wbLang::text('CURRENT_THEME',$_SESSION['template']).'</p>';
 532                  }
 533                  echo '<p>'.wbLinks::special('Preferences?cmd=set&template='.$this->owner.'/'.$this->title,$langA['use_this_theme'],'',$_SESSION['username']).'</p>';
 534              }
 535  
 536              echo '<p>';
 537              echo $langA['MAKE_THEME'];
 538              echo '<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="text" size="20" value="" name="to" />';
 539              echo '<input type="submit" name="cmd" value="'.$langA['copy'].'" /> ';
 540              echo '</p>';
 541          }
 542          
 543          echo $langA['EDIT_THEME_TEXT'];
 544          echo '</div>';
 545          $page->contentB[$field] = wb::get_clean();
 546          $page->autoForm = true;
 547          return $field;
 548      }
 549      
 550  	function translateToUser($text){
 551          //echo preg_replace($pattern, $replacement, $string);
 552          //$this->newTranslation['new2'] = '<'.'?= $page->displayTitle ?'.'>';
 553          
 554          //
 555          // tabHtml
 556          //
 557          $lines = explode("\n",$text);
 558          foreach($lines as $i => $line){
 559              if(strpos($line,'?'.'>') !== false){
 560                  break;
 561              }
 562              if( strpos($line,'$wbTabHtml') === 0){
 563                  global $wbTabHtml;
 564                  $line = trim($line);
 565                  $len = strcspn($line,'1234567890');
 566                  $line = substr($line,$len);
 567                  $this->tab_html = (int)($line{0});
 568                  
 569                  // eval($line);
 570                  // $this->tab_html = $wbTabHtml;
 571                  break;
 572              }
 573          }
 574          
 575          //
 576          // links..
 577          //
 578          $search = array_keys($this->oldTrans);
 579          $replace = array_values($this->oldTrans);
 580          $text = str_replace($search,$replace,$text);
 581          
 582          $patt = array_values($this->toUser);
 583          $repl = array_keys($this->toUser);
 584          
 585          //build other pattern/replacemenst from $newTranslation
 586          foreach($this->newTranslation as $key => $value){
 587              $repl[] = $this->varCharStart.$key.$this->varCharEnd;
 588              $patt[] = '#<!-- '.$this->varCharStart.$key.$this->varCharEnd.' Start -->.*?<!-- '.$this->varCharStart.$key.$this->varCharEnd.' End -->#s';
 589          }
 590          
 591          $text = preg_replace($patt,$repl,$text);
 592          
 593          $FromValues = array();
 594          $ToValues = array();
 595          foreach($this->translationArray as $ToValue => $FromValue){
 596              $ToValue = $this->varCharStart.$ToValue.$this->varCharEnd;
 597              $FromValues[] = $FromValue;
 598              $ToValues[] = $ToValue;
 599          }
 600          $text = str_replace($FromValues,$ToValues,$text);
 601          
 602          //Get Rid of Any Left-Over PHP
 603          return preg_replace('#<\?.*?\?>#s','',$text);
 604      }
 605      
 606  	function translateFromUser($text){
 607          // values will be changed to php values..ie <!-- DisplayPage -->.. 
 608          //    .. it must be done after xmlParse
 609          $patt = array();
 610          $repl = array();
 611          
 612          $patt = array_values($this->toFile);
 613          $repl = array_keys($this->toFile);
 614          
 615          foreach($this->newTranslation as $key => $value){
 616              $patt[] = '#'.$this->varCharStart.$key.$this->varCharEnd.'#';
 617              $repl[] = '<!-- '.$this->varCharStart.$key.$this->varCharEnd.' Start -->'."\r\n\t".$value."\r\n\t".'<!-- '.$this->varCharStart.$key.$this->varCharEnd.' End -->';
 618          }
 619          $text = preg_replace($patt,$repl,$text);
 620          
 621          
 622          
 623          //version 0.9 added because the use of &linkPrefix& in a link is now 
 624          //    changed to &amp;linkPrefix&amp; by the xmlParser (html attributes are wbHtmlspecialchars'd)
 625          //    .. also for links rev="&PageOwner&" becomes rev="&pageowner&" ...
 626          $FromValues = array();
 627          $ToValues = array();
 628          foreach($this->translationArray as $FromValue => $ToValue){ 
 629              $FromValue = $this->varCharStart.$FromValue.$this->varCharEnd;
 630              $FromValues[] = $FromValue;
 631              $ToValues[] = $ToValue;
 632              
 633              
 634              $FromValues[] = wbHtmlspecialchars($FromValue);
 635              $ToValues[] = $ToValue;
 636              
 637              $FromValues[] = wbHtmlspecialchars(strtolower($FromValue));
 638              $ToValues[] = $ToValue;
 639          }
 640          
 641          
 642          return str_replace($FromValues,$ToValues,$text);
 643      }
 644      
 645  	function editValues(){
 646          global $page,$jsNum,$langA;
 647          $page->scripts[] = '/include/js/editing.js?'.$jsNum;
 648          $page->scripts[] = '/include/js/editingAll.js?'.$jsNum;
 649          $page->css2 = true;        
 650          
 651          if( ($page->userCmd == 'preview') || ($page->userCmd == 'save') ){
 652              $array['content'] =& $_POST['content'];
 653              //$array['CSS1'] = $this->translateToUser($_POST['css1']);
 654              //$array['CSS2'] = $this->translateToUser($_POST['css2']);
 655              $array['CSS1'] = $this->translateToUser($_POST['css1']);
 656              
 657          }else{
 658              //version 0.9.1 changed on June 02
 659              if( !empty($this->content)){
 660                  $array['content'] =& $this->content;
 661              }else{
 662                  $array['content'] = $this->translateToUser($this->template);
 663              }
 664              $array['CSS1'] =& $this->css1;
 665              //$array['CSS2'] =& $this->css2;
 666          }
 667  
 668          $editLink = $page->findLink($this->editLabel);
 669          $css1Link = $editLink.'#WBnoneCSS1';
 670          //$css2Link = $editLink.'#WBnoneCSS2';
 671          $saveLink = $editLink.'#WBnoneSave';
 672          
 673          $page->regLink('CSS',$css1Link);
 674          //$page->regLink('CSS2',$css2Link);
 675          $page->regLink($langA['save'],$saveLink);
 676          
 677          //make boxes
 678          $page->contentB[$editLink] = toEditArea($array['content'],false,'content');
 679          $page->contentB[$editLink] .= '<div style="text-align:right">'.$langA['back'].'.. &nbsp; ';
 680          $page->contentB[$editLink] .= wbLinks::local($css1Link,$langA['continue'].'...').' &nbsp; ';
 681          $page->contentB[$editLink] .= wbLinks::local($saveLink,$langA['save'].'...');
 682          $page->contentB[$editLink] .= '</div>';
 683          $page->contentB[$editLink] .= '<input type="hidden" name="tab_html" value="'.$this->tab_html.'" />';
 684          
 685          
 686          $page->contentB[$css1Link] = toEditArea($array['CSS1'],false,'css1');
 687          $page->contentB[$css1Link] .= '<div style="text-align:right">';
 688          $page->contentB[$css1Link] .= wbLinks::local($editLink,$langA['back'].'...').' &nbsp; ';
 689          //$page->contentB[$css1Link] .= wbLinks::local($css2Link,$langA['continue'].'...').' &nbsp; ';
 690          $page->contentB[$css1Link] .= wbLinks::local($saveLink,$langA['save'].'...');
 691          $page->contentB[$css1Link] .= '</div>';
 692          
 693          
 694  //         $page->contentB[$css2Link] = toEditArea($array['CSS2'],false,'css2');
 695  //         $page->contentB[$css2Link] .= '<div style="text-align:right">';
 696  //         $page->contentB[$css2Link] .= wbLinks::local($css1Link,$langA['back'].'..').' &nbsp; ';
 697  //         $page->contentB[$css2Link] .= wbLinks::local($saveLink,$langA['continue'].'...').' &nbsp; ';
 698  //         $page->contentB[$css2Link] .= wbLinks::local($saveLink,$langA['save'].'...');
 699  //         $page->contentB[$css2Link] .= '</div>';
 700          
 701          //
 702          //    Save Tab
 703          //
 704              
 705              if( empty($this->tab_html) ){
 706                  $this->tab_html = 0;
 707              }
 708              $temp[0] = '<a> -'.$langA['link_text'].'- </a>';
 709              $temp[2] = '<li><a>-'.$langA['link_text'].'-</a></li>';
 710              $temp[1] = '<a><span class="tabLeft">-'.$langA['link_text'].'-</span><span class="tabRight">&nbsp;</span></a>';
 711              
 712          
 713              $t =& $page->contentB[$saveLink];
 714              $t = '';
 715              $t .= '<table class="tableRows">';
 716              $t .= '<tr><th colspan="2">Tab Html</th></tr>';
 717              foreach($temp as $i => $tabHtml){
 718                  $t .= '<tr>';
 719                  $t .= '<td>';
 720                  if( $i == $this->tab_html ){
 721                      $t .= '<input name="tab_html" type="radio" value="'.$i.'" checked="checked"/>';
 722                  }else{
 723                      $t .= '<input name="tab_html" type="radio" value="'.$i.'" />';
 724                  }
 725                  $t .= '</td>';
 726                  $t .= '<td class="sm">'.wbHtmlspecialchars($tabHtml).'</td>';
 727                  $t .= '</tr>';
 728              }
 729              $t .= '</table>';
 730              $t .= '<br/>';
 731              $t .= saveBar(true,false);
 732              $t .= '<div style="text-align:right">';
 733              //$t .= wbLinks::local($css2Link,$langA['back'].'..');
 734              $t .= wbLinks::local($css1Link,$langA['back'].'..');
 735              $t .= ' &nbsp; '.$langA['continue'].'.. &nbsp; '.$langA['save'].'...</div>';
 736          
 737      }
 738      
 739  	function returnPageTemplate(){
 740          
 741          //css urls are not correct when the request uses the file_id: /Edit/theme/Main/8657?cmd=delete
 742          //so we need to change the paths
 743          $expected = wbStrtolower(wbLinks::getUrl($this->uniqLink));
 744          $actual = wbStrtolower($_SERVER['REQUEST_URI']);
 745          
 746          //get expected down to the relative path
 747          $pos = strpos($expected,'://');
 748          if( $pos > 0 ){
 749              $expected = substr($expected,$pos+3);
 750              $pos = strpos($expected,'/');
 751              $expected = substr($expected,$pos);
 752          }
 753          
 754          if( $expected != $actual ){
 755              $expected = explode('/',$expected);
 756              $actual = explode('/',$actual);
 757              do{
 758                  $currentActual = array_shift($actual);
 759                  $currentExpected = array_shift($expected);
 760                  if( $currentActual == $currentExpected ){
 761                      continue;
 762                      
 763                  }else{
 764                      array_unshift($actual,$currentActual);
 765                      array_unshift($expected,$currentExpected);
 766                      break;
 767                  }
 768              }while( (count($actual) > 0) && (count($expected) > 0) );
 769              
 770              $css = $this->CssPathsFromTo($this->css1,$expected,$actual);
 771          }else{
 772              $css = $this->css1;
 773          }
 774      
 775          //return str_replace('</head>',"\n<style>\n".$this->css1."\n".$this->css2."\n</style>\n</head>",$this->template);
 776          return str_replace('</head>',"\n<style>\n".$css."\n</style>\n</head>",$this->template);
 777      }
 778      
 779      
 780  	function CssPathsFromTo($css,$fromPathArray,$toPathArray){
 781          global $rootDir;
 782          $matches = array();
 783          
 784          $full = '';
 785          preg_match_all('#url\(([^\)\(]*)\)#',$css,$matches,PREG_PATTERN_ORDER);
 786          $matches = array_unique($matches[1]);
 787          
 788      
 789          foreach($matches as $path){
 790              $replace = $path;
 791              $tempFrom = $fromPathArray;
 792              $tempTo = $toPathArray;;
 793              
 794              while( (strpos($path,'../') === 0) && (count($tempFrom) > 0) && (count($tempTo) > 0) ){
 795                  array_pop($tempFrom);
 796                  array_pop($tempTo);
 797              }
 798              $newPath = '';
 799              foreach($tempTo as $level){
 800                  $newPath .= '../';
 801              }
 802              foreach($tempFrom as $level){
 803                  $newPath .= $level.'/';
 804              }
 805              $newPath .= $path;
 806              $css = str_replace('url('.$replace.')','url('.$newPath.')',$css);
 807          }
 808          return $css;
 809      }
 810          
 811      
 812      
 813  }
 814  
 815  //                TEMPLATE CLASS
 816  //
 817  //
 818  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 819  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 820  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 821  //
 822  //                 EXTRA FUNCTIONS
 823  //
 824  
 825  //use addslashes or addcslashes( $str,'"\\');
 826  //    to escape ' and \
 827  //    the " will be escaped by preg_replace
 828  //
 829  function formatTemplateLinks($arg1,$arg2){
 830      $arg2 = stripslashes($arg2); //don't escape "
 831      $arg2 = addcslashes($arg2,'\'\\'); //escape ' and \
 832      
 833      $pieces = wbExplode('|',$arg2);
 834      if( count($pieces) < 1){
 835          return '[['.$arg1.':'.$arg2.']]';
 836      }elseif(count($pieces) < 2){
 837          $pieces[1] = $pieces[0];
 838      }
 839      
 840      switch(wbStrtolower($arg1)){
 841          case 'speciallink':
 842          return '<?php echo wbLinks::special(\''.$pieces[0].'\',\''.$pieces[1].'\'); ?>';
 843          
 844          case 'locallink':
 845          return '<?php echo wbLinks::local(\''.$pieces[0].'\',\''.$pieces[1].'\'); ?>';
 846          
 847          case 'helplink':
 848          return '<?php echo wbLinks::help(\''.$pieces[0].'\',\''.$pieces[1].'\'); ?>';
 849          
 850          case 'wbimage':
 851          return '<?php echo wbLinks::image(\''.$pieces[0].'\'); ?>';
 852      }
 853      return '[['.$arg1.':'.$arg2.']]';
 854  }
 855  
 856  
 857  
 858  function getContents($fileName){
 859      if( is_readable($fileName) ){
 860          return @file_get_contents($fileName);
 861      }else{
 862          return '';
 863      }
 864  }
 865  

title

Description

title

Description

title

Description

title

title

Body