[ Index ]
 

Code source de CMS made simple 1.0.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/ -> content.functions.php (source)

   1  <?php
   2  #CMS - CMS Made Simple
   3  #(c)2004 by Ted Kulp (wishy@users.sf.net)
   4  #This project's homepage is: http://cmsmadesimple.sf.net
   5  #
   6  #This program is free software; you can redistribute it and/or modify
   7  #it under the terms of the GNU General Public License as published by
   8  #the Free Software Foundation; either version 2 of the License, or
   9  #(at your option) any later version.
  10  #
  11  #This program is distributed in the hope that it will be useful,
  12  #but WITHOUT ANY WARRANTY; without even the implied warranty of
  13  #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14  #GNU General Public License for more details.
  15  #You should have received a copy of the GNU General Public License
  16  #along with this program; if not, write to the Free Software
  17  #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18  #
  19  #$Id: content.functions.php 3820 2007-03-06 23:14:27Z wishy $
  20  
  21  /**
  22   * Handles content related functions
  23   *
  24   * @package CMS
  25   */
  26  $sorted_sections = array();
  27  $sorted_content = array();
  28  
  29  /**
  30   * Extends the Smarty class for content.
  31   *
  32   * Extends the Smarty class for checking timestamps and rendering
  33   * content to the browser.
  34   *
  35   * @since 0.1
  36   */
  37  class Smarty_CMS extends Smarty {
  38      
  39  	function Smarty_CMS(&$config)
  40      {
  41          $this->Smarty();
  42  
  43          $this->template_dir = $config["root_path"].'/tmp/templates/';
  44          $this->compile_dir = TMP_TEMPLATES_C_LOCATION;
  45          $this->config_dir = $config["root_path"].'/tmp/configs/';
  46          $this->cache_dir = TMP_CACHE_LOCATION;
  47          #$this->plugins_dir = array($config["root_path"].'/lib/smarty/plugins',$config["root_path"].'/plugins',$config["root_path"].'/plugins/cache');
  48          $this->plugins_dir = array($config["root_path"].'/lib/smarty/plugins',$config["root_path"].'/plugins');
  49  
  50          $this->compiler_file = 'CMS_Compiler.class.php';
  51          $this->compiler_class = 'CMS_Compiler';
  52  
  53          //use_sub_dirs doesn't work in safe mode
  54          //if (ini_get("safe_mode") != "1")
  55          //    $this->use_sub_dirs = true;
  56          //$this->caching = false;
  57          //$this->compile_check = true;
  58          $this->assign('app_name','CMS');
  59          //$this->debugging = false;
  60          //$this->force_compile = false;
  61          $this->cache_plugins = false;
  62  
  63          if ($config["debug"] == true)
  64          {
  65              //$this->caching = false;
  66              $this->force_compile = true;
  67              $this->debugging = true;
  68          }
  69  
  70          if (get_site_preference('enablesitedownmessage') == "1")
  71          {
  72              $this->caching = false;
  73              $this->force_compile = true;
  74          }
  75  
  76          global $CMS_ADMIN_PAGE;
  77          if (isset($CMS_ADMIN_PAGE) && $CMS_ADMIN_PAGE == 1)
  78          {
  79              $this->caching = false;
  80              $this->force_compile = true;
  81          }
  82  
  83          load_plugins($this);
  84  
  85          $this->register_resource("db", array(&$this, "template_get_template",
  86                                 "template_get_timestamp",
  87                                 "db_get_secure",
  88                                 "db_get_trusted"));
  89          $this->register_resource("print", array(&$this, "template_get_template",
  90                                 "template_get_timestamp",
  91                                 "db_get_secure",
  92                                 "db_get_trusted"));
  93          $this->register_resource("template", array(&$this, "template_get_template",
  94                                 "template_get_timestamp",
  95                                 "db_get_secure",
  96                                 "db_get_trusted"));
  97          $this->register_resource("htmlblob", array(&$this, "global_content_get_template",
  98                                 "global_content_get_timestamp",
  99                                 "db_get_secure",
 100                                 "db_get_trusted"));
 101          $this->register_resource("globalcontent", array(&$this, "global_content_get_template",
 102                                 "global_content_get_timestamp",
 103                                 "db_get_secure",
 104                                 "db_get_trusted"));
 105          $this->register_resource("preview", array(&$this, "preview_get_template",
 106                                 "preview_get_timestamp",
 107                                 "db_get_secure",
 108                                 "db_get_trusted"));
 109          $this->register_resource("content", array(&$this, "content_get_template",
 110                                 "content_get_timestamp",
 111                                 "db_get_secure",
 112                                 "db_get_trusted"));
 113          $this->register_resource("module", array(&$this, "module_get_template",
 114                                 "module_get_timestamp",
 115                                 "db_get_secure",
 116                                 "db_get_trusted"));
 117          $this->register_resource("module_db_tpl", array(&$this, "module_db_template",
 118                                 "module_db_timestamp",
 119                                 "db_get_secure",
 120                                 "db_get_trusted"));
 121          $this->register_resource("module_file_tpl", array(&$this, "module_file_template",
 122                                 "module_file_timestamp",
 123                                 "db_get_secure",
 124                                 "db_get_trusted"));
 125      }
 126  
 127      /**
 128       * wrapper for include() retaining $this
 129       * @return mixed
 130       */
 131      function _include($filename, $once=false, $params=null)
 132      {
 133          if ($filename != '')
 134          {
 135              if ($once) {
 136                  return include_once($filename);
 137              } else {
 138                  return include($filename);
 139              }
 140          }
 141      }
 142  
 143      function trigger_error($error_msg, $error_type = E_USER_WARNING)
 144      {   
 145          var_dump("Smarty error: $error_msg");
 146      }
 147  
 148  	function module_file_template($tpl_name, &$tpl_source, &$smarty_obj)
 149      {
 150          $params = split(';', $tpl_name);
 151          if (count($params) == 2 && file_exists(dirname(dirname(__FILE__)) . '/modules/' . $params[0] . '/templates/' . $params[1]))
 152          {   
 153              $tpl_source = @file_get_contents(dirname(dirname(__FILE__)) . '/modules/' . $params[0] . '/templates/' . $params[1]);
 154              return true;
 155          }
 156          return false;
 157      }
 158  
 159  	function module_file_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj)
 160      {
 161          $params = split(';', $tpl_name);
 162          if (count($params) == 2 && file_exists(dirname(dirname(__FILE__)) . '/modules/' . $params[0] . '/templates/' . $params[1]))
 163          {
 164              $tpl_timestamp = filemtime(dirname(dirname(__FILE__)) . '/modules/' . $params[0] . '/templates/' . $params[1]);
 165              return true;
 166          }
 167          return false;
 168      }
 169  
 170      function module_db_template($tpl_name, &$tpl_source, &$smarty_obj)
 171      {   
 172          global $gCms;
 173  
 174          $db = &$gCms->GetDb();
 175          $config = $gCms->config;
 176  
 177          $query = "SELECT content from ".cms_db_prefix()."module_templates WHERE module_name = ? and template_name = ?";
 178          $row = $db->GetRow($query, split(';', $tpl_name));
 179  
 180          if ($row)
 181          {
 182              $tpl_source = $row['content'];
 183              return true;
 184          }
 185  
 186          return false;
 187      }
 188  
 189  	function module_db_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj)
 190      {
 191          global $gCms;
 192  
 193          $db = &$gCms->GetDb();
 194          $config = $gCms->config;
 195  
 196          $query = "SELECT modified_date from ".cms_db_prefix()."module_templates WHERE module_name = ? and template_name = ?";
 197          $row = $db->GetRow($query, split(';', $tpl_name));
 198          if ($row)
 199          {
 200              $tpl_timestamp = $db->UnixTimeStamp($row['modified_date']);
 201              return true;
 202          }
 203  
 204          return false;
 205      }
 206  
 207  	function global_content_get_template($tpl_name, &$tpl_source, &$smarty_obj)
 208      {
 209          debug_buffer('start global_content_get_template');
 210          global $gCms;
 211          $config =& $gCms->config;
 212          $gcbops =& $gCms->GetGlobalContentOperations();
 213  
 214          $oneblob = $gcbops->LoadHtmlBlobByName($tpl_name);
 215          if ($oneblob)
 216          {
 217              $text = $oneblob->content;
 218  
 219              #Perform the content htmlblob callback
 220              /*
 221              reset($gCms->modules);
 222              while (list($key) = each($gCms->modules))
 223              {
 224                  $value =& $gCms->modules[$key];
 225                  if ($gCms->modules[$key]['installed'] == true &&
 226                      $gCms->modules[$key]['active'] == true)
 227                  {
 228                      $gCms->modules[$key]['object']->ContentHtmlBlob($text);
 229                  }
 230              }
 231              */
 232  
 233              $tpl_source = $text;
 234  
 235              #So no one can do anything nasty, take out the php smarty tags.  Use a user
 236              #defined plugin instead.
 237              if (!(isset($config["use_smarty_php_tags"]) && $config["use_smarty_php_tags"] == true))
 238              {
 239                  $tpl_source = ereg_replace("\{\/?php\}", "", $tpl_source);
 240              }
 241          }
 242          else
 243          {
 244              $tpl_source = "<!-- Html blob '" . $tpl_name . "' does not exist  -->";
 245          }
 246          debug_buffer('end global_content_get_template');
 247          return true;
 248      }
 249  
 250  	function global_content_get_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj)
 251      {
 252          debug_buffer('start global_content_get_timestamp');
 253          global $gCms;
 254          $gcbops =& $gCms->GetGlobalContentOperations();
 255          $oneblob = $gcbops->LoadHtmlBlobByName($tpl_name);
 256          if ($oneblob)
 257          {
 258              $tpl_timestamp = $oneblob->modified_date;
 259              debug_buffer('end global_content_get_timestamp');
 260              return true;
 261          }
 262          else
 263          {
 264              return false;
 265          }
 266      }
 267  
 268  	function preview_get_template ($tpl_name, &$tpl_source, &$smarty_obj)
 269      {
 270          global $gCms;
 271          $config = $gCms->config;
 272  
 273          $fname = '';
 274          if (is_writable($config["previews_path"]))
 275          {
 276              $fname = cms_join_path($config["previews_path"] , $tpl_name);
 277          }
 278          else
 279          {
 280              $fname = cms_join_path(TMP_CACHE_LOCATION , $tpl_name);
 281          }
 282          if (true == file_exists($fname))
 283          {
 284              $handle = fopen($fname, "r");
 285              $data = unserialize(fread($handle, filesize($fname)));
 286              fclose($handle);
 287              unlink($fname);
 288      
 289              $tpl_source = $data["template"];
 290          }
 291          else
 292          {
 293              $tpl_source = 'Error: Cache file: '.$tpl_name.' does not exist.';
 294          }
 295          #Perform the content template callback
 296          reset($gCms->modules);
 297          while (list($key) = each($gCms->modules))
 298          {
 299              $value =& $gCms->modules[$key];
 300              if ($gCms->modules[$key]['installed'] == true &&
 301                  $gCms->modules[$key]['active'] == true)
 302              {
 303                  $gCms->modules[$key]['object']->ContentTemplate($tpl_source);
 304              }
 305          }
 306          
 307          Events::SendEvent('Core', 'ContentTemplate', array('template' => &$tpl_source));
 308  
 309          $gCms->variables['page'] = $data['content_id'];
 310          $gCms->variables['page_id'] = $data['content_id'];
 311          $gCms->variables['content_id'] = $data['content_id'];
 312          $gCms->variables['page_name'] = $data['title'];
 313          $gCms->variables['position'] = $data['hierarchy'];
 314          $pageinfo = new StdClass();
 315          $pageinfo->template_id =  $data['template_id'];
 316          $pageinfo->content_title = $data['title'];
 317          $gCms->variables['pageinfo'] = $pageinfo;
 318          header("Content-Type: text/html; charset=" . (isset($data['encoding']) && $data['encoding'] != ''?$data['encoding']:get_encoding()));
 319  
 320          $content = $data["content"];
 321           
 322          reset($gCms->modules);
 323          while (list($key) = each($gCms->modules))
 324          {
 325              $value =& $gCms->modules[$key];
 326              if ($gCms->modules[$key]['installed'] == true &&
 327                  $gCms->modules[$key]['active'] == true)
 328              {
 329                  $gCms->modules[$key]['object']->ContentPreCompile($content);
 330              }
 331          }
 332          
 333          Events::SendEvent('Core', 'ContentPreCompile', array('content' => &$content));
 334  
 335          $tpl_source = eregi_replace("\{content\}", $content, $tpl_source);
 336  
 337          $title = $data['title'];
 338          $menutext = $data['menutext'];
 339  
 340          #Perform the content title callback
 341          /*
 342          reset($gCms->modules);
 343          while (list($key) = each($gCms->modules))
 344          {
 345              $value =& $gCms->modules[$key];
 346              if ($gCms->modules[$key]['installed'] == true &&
 347                  $gCms->modules[$key]['active'] == true)
 348              {
 349                  $gCms->modules[$key]['object']->ContentTitle($title);
 350              }
 351          }
 352          */
 353  
 354          $tpl_source = ereg_replace("\{title\}", $title, $tpl_source);
 355          $tpl_source = ereg_replace("\{menutext\}", $menutext, $tpl_source);
 356  
 357          #So no one can do anything nasty, take out the php smarty tags.  Use a user
 358          #defined plugin instead.
 359          if (!(isset($config["use_smarty_php_tags"]) && $config["use_smarty_php_tags"] == true))
 360          {
 361              $tpl_source = ereg_replace("\{\/?php\}", "", $tpl_source);
 362          }
 363  
 364          return true;
 365      }
 366  
 367  	function preview_get_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj)
 368      {
 369          $tpl_timestamp = time();
 370          return true;
 371      }
 372  
 373  	function template_get_template($tpl_name, &$tpl_source, &$smarty_obj)
 374      {
 375          global $gCms;
 376          $config =& $gCms->GetConfig();
 377  
 378          if (get_site_preference('enablesitedownmessage') == "1")
 379          {
 380              $tpl_source = get_site_preference('sitedownmessage');
 381              return true;
 382          }
 383          else
 384          {
 385              $pageinfo = $gCms->variables['pageinfo'];
 386  
 387              if ($tpl_name == 'notemplate')
 388              {
 389                  $tpl_source = '{content}';
 390  
 391                  return true;
 392              }
 393              else if (isset($_GET["print"]))
 394              {
 395                  $script = '';
 396  
 397                  if (isset($_GET["js"]) and $_GET["js"] == 1)
 398                      $script = '<script type="text/javascript">window.print();</script>';
 399  
 400                  if (isset($_GET["goback"]) and $_GET["goback"] == 0)
 401                  {
 402                      $tpl_source = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'."\n".'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'.'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'.'<head><title>{title}</title><meta name="robots" content="noindex"></meta>{metadata}{stylesheet}{literal}<style type="text/css" media="print">#back {display: none;}</style>{/literal}</head><body style="background-color: white; color: black; background-image: none; text-align: left;">{content}'.$script.'</body></html>';
 403                  }
 404                  else
 405                  {
 406                    $hm =& $gCms->GetHierarchyManager();
 407                    if (true == $config['assume_mod_rewrite'])
 408                      {
 409                        $curnode =& $hm->getNodeByAlias($tpl_name);
 410                      }
 411                    else
 412                      {
 413                        $curnode =& $hm->getNodeById($tpl_name);
 414                      }
 415                    $curcontent =& $curnode->GetContent();
 416                    $page_url = $curcontent->GetURL();
 417                    
 418                    $tpl_source = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'."\n".'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'.'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'.'<head><title>{title}</title><meta name="robots" content="noindex"></meta>{metadata}{stylesheet}{literal}<style type="text/css" media="print">#back {display: none;}</style>{/literal}</head><body style="background-color: white; color: black; background-image: none; text-align: left;"><p><a id="back" href="'.$page_url.'">&laquo; Go Back</a></p>{content}'.$script.'</body></html>';
 419                  }
 420  
 421                  return true;
 422              }
 423              else
 424              {
 425                  global $gCms;
 426                  $templateops =& $gCms->GetTemplateOperations();
 427                  $templateobj =& $templateops->LoadTemplateByID($pageinfo->template_id);
 428                  if (isset($templateobj) && $templateobj !== FALSE)
 429                  {
 430                      $tpl_source = $templateobj->content;
 431  
 432                      #So no one can do anything nasty, take out the php smarty tags.  Use a user
 433                      #defined plugin instead.
 434                      if (!(isset($config["use_smarty_php_tags"]) && $config["use_smarty_php_tags"] == true))
 435                      {
 436                          $tpl_source = ereg_replace("\{\/?php\}", "", $tpl_source);
 437                      }
 438                      
 439                      //do_cross_reference($pageinfo->template_id, 'template', $tpl_source);
 440  
 441                      return true;
 442                  }
 443              }
 444              return false;
 445          }
 446      }
 447  
 448  	function template_get_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj)
 449      {
 450          global $gCms;
 451  
 452          if (get_site_preference('enablesitedownmessage') == "1" || $tpl_name == 'notemplate')
 453          {
 454              $tpl_timestamp = time();
 455              return true;
 456          }
 457          else if (isset($_GET['id']) && isset($_GET[$_GET['id'].'showtemplate']) && $_GET[$_GET['id'].'showtemplate'] == 'false')
 458          {
 459              $tpl_timestamp = time();
 460              return true;
 461          }
 462          else if (isset($_GET['print']))
 463          {
 464              $tpl_timestamp = time();
 465              return true;
 466          }
 467          else
 468          {
 469              $pageinfo = &$gCms->variables['pageinfo'];
 470  
 471              $tpl_timestamp = $pageinfo->template_modified_date;
 472              return true;
 473          }
 474      }
 475  
 476  	function content_get_template($tpl_name, &$tpl_source, &$smarty_obj)
 477      {
 478          global $gCms;
 479          $config =& $gCms->GetConfig();
 480          $pageinfo = &$gCms->variables['pageinfo'];
 481  
 482          if (isset($pageinfo) && $pageinfo->content_id == -1)
 483          {
 484              #We've a custom error message...  return it here
 485              header("HTTP/1.0 404 Not Found");
 486              header("Status: 404 Not Found");
 487              if ($tpl_name == 'content_en')
 488                  $tpl_source = get_site_preference('custom404');
 489              else
 490                  $tpl_source = '';
 491              return true;
 492          }
 493          else
 494          {
 495              $manager =& $gCms->GetHierarchyManager();
 496              $node =& $manager->sureGetNodeById($pageinfo->content_id);
 497              $contentobj =& $node->GetContent();
 498  
 499              if (isset($contentobj) && $contentobj !== FALSE)
 500              {
 501                  if ($tpl_name != 'content_en')
 502                  {
 503                      //TODO: Fix Me.  This is a super hack.
 504                      $contentobj->GetAdditionalContentBlocks();
 505                  }
 506  
 507                  $tpl_source = $contentobj->Show($tpl_name);
 508  
 509                  #Perform the content data callback
 510                  #This needs to go...
 511                  /*
 512                  reset($gCms->modules);
 513                  while (list($key) = each($gCms->modules))
 514                  {
 515                      $value =& $gCms->modules[$key];
 516                      if ($gCms->modules[$key]['installed'] == true &&
 517                          $gCms->modules[$key]['active'] == true)
 518                      {
 519                          $gCms->modules[$key]['object']->ContentData($tpl_source);
 520                      }
 521                  }
 522                  */
 523  
 524                  #Perform the content prerender callback
 525                  /*
 526                  reset($gCms->modules);
 527                  while (list($key) = each($gCms->modules))
 528                  {
 529                      $value =& $gCms->modules[$key];
 530                      if ($gCms->modules[$key]['installed'] == true &&
 531                          $gCms->modules[$key]['active'] == true)
 532                      {
 533                          $gCms->modules[$key]['object']->ContentPreRender($tpl_source);
 534                      }
 535                  }
 536                  */
 537  
 538                  #So no one can do anything nasty, take out the php smarty tags.  Use a user
 539                  #defined plugin instead.
 540                  if (!(isset($config["use_smarty_php_tags"]) && $config["use_smarty_php_tags"] == true))
 541                  {
 542                      $tpl_source = ereg_replace("\{\/?php\}", "", $tpl_source);
 543                  }
 544                  
 545                  //do_cross_reference($pageinfo->content_id, 'content', $tpl_source);
 546  
 547                  return true;
 548              }
 549          }
 550          return false;
 551      }
 552  
 553  	function content_get_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj)
 554      {
 555          global $gCms;
 556  
 557          $pageinfo =& $gCms->variables['pageinfo'];
 558  
 559          if (isset($pageinfo) && $pageinfo->content_id == -1)
 560          {
 561              #We've a custom error message...  set a current timestamp
 562              $tpl_timestamp = time();
 563          }
 564          else
 565          {
 566              if ($pageinfo->cachable)
 567              {
 568                  $tpl_timestamp = $pageinfo->content_modified_date;
 569              }
 570              else
 571              {
 572                  $tpl_timestamp = time();
 573              }
 574          }
 575          return true;
 576      }
 577      
 578  	function module_get_template ($tpl_name, &$tpl_source, &$smarty_obj)
 579      {
 580          global $gCms;
 581          $pageinfo =& $gCms->variables['pageinfo'];
 582          $config = $gCms->config;
 583  
 584          #Run the execute_user function and replace {content} with it's output 
 585          if (isset($gCms->modules[$tpl_name]))
 586          {
 587              @ob_start();
 588  
 589              $id = $smarty_obj->id;
 590  
 591              $params = GetModuleParameters($id);
 592              $action = 'default';
 593              if (isset($params['action']))
 594              {
 595                  $action = $params['action'];
 596              }
 597              echo $gCms->modules[$tpl_name]['object']->DoActionBase($action, $id, $params, isset($pageinfo)?$pageinfo->content_id:'');
 598              $modoutput = @ob_get_contents();
 599              @ob_end_clean();
 600  
 601              $tpl_source = $modoutput;
 602          }
 603          
 604          header("Content-Type: ".$gCms->variables['content-type']."; charset=" . (isset($line['encoding']) && $line['encoding'] != ''?$line['encoding']:get_encoding()));
 605          if (isset($gCms->variables['content-filename']) && $gCms->variables['content-filename'] != '')
 606          {
 607              header('Content-Disposition: attachment; filename="'.$gCms->variables['content-filename'].'"');
 608              header("Pragma: public");
 609          }
 610  
 611          #So no one can do anything nasty, take out the php smarty tags.  Use a user
 612          #defined plugin instead.
 613          if (!(isset($config["use_smarty_php_tags"]) && $config["use_smarty_php_tags"] == true))
 614          {
 615              $tpl_source = ereg_replace("\{\/?php\}", "", $tpl_source);
 616          }
 617  
 618          return true;
 619      }
 620  
 621  	function module_get_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj)
 622      {
 623          $tpl_timestamp = time();
 624          return true;
 625      }
 626  
 627  	function db_get_secure($tpl_name, &$smarty_obj)
 628      {
 629          // assume all templates are secure
 630          return true;
 631      }
 632  
 633  	function db_get_trusted($tpl_name, &$smarty_obj)
 634      {
 635          // not used for templates
 636      }
 637  }
 638  
 639  /**
 640   * Loads all plugins into the system
 641   *
 642   * @since 0.5
 643   */
 644  function load_plugins(&$smarty)
 645  {
 646      global $gCms;
 647      $plugins = &$gCms->cmsplugins;
 648      $userplugins = &$gCms->userplugins;
 649      $userpluginfunctions = &$gCms->userpluginfunctions;
 650      $db = &$gCms->GetDb();
 651      if (isset($db))
 652      {
 653          #if (@is_dir(dirname(dirname(__FILE__))."/plugins/cache"))
 654          #{
 655          #    search_plugins($smarty, $plugins, dirname(dirname(__FILE__))."/plugins/cache", true);
 656          #}
 657          search_plugins($smarty, $plugins, dirname(dirname(__FILE__))."/plugins", false);
 658  
 659          $query = "SELECT * FROM ".cms_db_prefix()."userplugins";
 660          $result = &$db->Execute($query);
 661          while ($result && !$result->EOF)
 662          {
 663              if (!in_array($result->fields['userplugin_name'], $plugins))
 664              {
 665                  $plugins[] =& $result->fields['userplugin_name'];
 666                  $userplugins[$result->fields['userplugin_name']] = $result->fields['userplugin_id'];
 667                  $functionname = "cms_tmp_".$result->fields['userplugin_name']."_userplugin_function";
 668                  //Only register valid code
 669                  if (!(@eval('function '.$functionname.'($params, &$smarty) {'.$result->fields['code'].'}') === FALSE))
 670                  {
 671                      $smarty->register_function($result->fields['userplugin_name'], $functionname, false);
 672  
 673                      //Register the function in a hash so that we can call it from other places by name
 674                      $userpluginfunctions[$result->fields['userplugin_name']] = $functionname;
 675                  }
 676              }
 677              $result->MoveNext();
 678          }
 679          sort($plugins);
 680      }
 681  }
 682  
 683  function search_plugins(&$smarty, &$plugins, $dir, $caching)
 684  {
 685      global $CMS_LOAD_ALL_PLUGINS;
 686  
 687      $types=array('function','compiler','prefilter','postfilter','outputfilter','modifier','block');
 688      $handle=opendir($dir);
 689      while ($file = readdir($handle))
 690      {
 691          // This hides the dummy function.summarize.php
 692          // (function.summarize.php was renamed to modifier.summarize.php in 1.0.3)
 693          // This code can be deleted once the dummy is removed from the distribution
 694          // TODO: DELETE
 695          if (
 696              $file == 'function.summarize.php' &&
 697              substr(file_get_contents(cms_join_path($dir, $file)), 9, 9) == '__DUMMY__'
 698          )
 699          {
 700                  continue;
 701          }
 702          // END TODO: DELETE
 703  
 704          $path_parts = pathinfo($file);
 705          if (isset($path_parts['extension']) && $path_parts['extension'] == 'php')
 706          {
 707              //Valid plugins will always have a 3 part filename
 708              $filearray = explode('.', $path_parts['basename']);
 709              if (count($filearray == 3))
 710              {
 711                  $filename = cms_join_path($dir, $file);
 712                  //The part we care about is the middle one...
 713                  $file = $filearray[1];
 714                  if (!isset($plugins[$file]) && in_array($filearray[0],$types))
 715                  {
 716                      $key=array_search($filearray[0],$types);
 717                      $load=true;
 718                      switch ($key)
 719                      {
 720                          case 0:
 721                                  if (isset($CMS_LOAD_ALL_PLUGINS))
 722                                      $smarty->register_function($file, "smarty_cms_function_" . $file, $caching);
 723                                  else $load=false;
 724                                  break;
 725                          case 1:
 726                                  $smarty->register_compiler_function($file, "smarty_cms_compiler_" .  $file, $caching);
 727                                  break;
 728                          case 2:
 729                                  $smarty->register_prefilter("smarty_cms_prefilter_" . $file);
 730                                  break;
 731                          case 3:
 732                                  $smarty->register_postfilter("smarty_cms_postfilter_" . $file);
 733                                  break;
 734                          case 4:
 735                                  $smarty->register_outputfilter("smarty_cms_outputfilter_" . $file);
 736                                  break;
 737                          case 5:
 738                                  $smarty->register_modifier($file, "smarty_cms_modifier_" . $file);
 739                                  break;
 740                          case 6:
 741                                  $smarty->register_block($file, "smarty_cms_block_" . $file);
 742                                  break;
 743                      }
 744                      if ($load){ $plugins[]=$file;
 745                          require_once($filename);}
 746                  }
 747              }
 748          }
 749      }
 750      closedir($handle);
 751  }
 752  
 753  function do_cross_reference($parent_id, $parent_type, $content)
 754  {
 755      global $gCms;
 756      $db =& $gCms->GetDb();
 757      
 758      //Delete old ones from the database
 759      $query = 'DELETE FROM '.cms_db_prefix().'crossref WHERE parent_id = ? AND parent_type = ?';
 760      $db->Execute($query, array($parent_id, $parent_type));
 761      
 762      //Do global content blocks
 763      $matches = array();
 764      preg_match_all('/\{(?:html_blob|global_content).*?name=["\']([^"]+)["\'].*?\}/', $content, $matches);
 765      if (isset($matches[1]))
 766      {
 767          $selquery = 'SELECT htmlblob_id FROM '.cms_db_prefix().'htmlblobs WHERE htmlblob_name = ?';
 768          $insquery = 'INSERT INTO '.cms_db_prefix().'crossref (parent_id, parent_type, child_id, child_type, create_date, modified_date)
 769                          VALUES (?,?,?,\'global_content\','.$db->DBTimeStamp(time()).','.$db->DBTimeStamp(time()).')';
 770          foreach ($matches[1] as $name)
 771          {
 772              $result = &$db->Execute($selquery, array($name));
 773              while ($result && !$result->EOF)
 774              {
 775                  $db->Execute($insquery, array($parent_id, $parent_type, $result->fields['htmlblob_id']));
 776                  $result->MoveNext();
 777              }
 778              if ($result) $result->Close();
 779          }
 780      }
 781  }
 782  
 783  function remove_cross_references($parent_id, $parent_type)
 784  {
 785      global $gCms;
 786      $db =& $gCms->GetDb();
 787      
 788      //Delete old ones from the database
 789      $query = 'DELETE FROM '.cms_db_prefix().'crossref WHERE parent_id = ? AND parent_type = ?';
 790      $db->Execute($query, array($parent_id, $parent_type));
 791  }
 792  
 793  function remove_cross_references_by_child($child_id, $child_type)
 794  {
 795      global $gCms;
 796      $db =& $gCms->GetDb();
 797      
 798      //Delete old ones from the database
 799      $query = 'DELETE FROM '.cms_db_prefix().'crossref WHERE child_id = ? AND child_type = ?';
 800      $db->Execute($query, array($child_id, $child_type));
 801  }
 802  
 803  function global_content_regex_callback($matches)
 804  {
 805      global $gCms;
 806      if (isset($matches[1]))
 807      {
 808          $gcbops =& $gCms->GetGlobalContentOperations();
 809          $oneblob = $gcbops->LoadHtmlBlobByName($matches[1]);
 810          if ($oneblob)
 811          {
 812              $text = $oneblob->content;
 813  
 814              #Perform the content htmlblob callback
 815              reset($gCms->modules);
 816              while (list($key) = each($gCms->modules))
 817              {
 818                  $value =& $gCms->modules[$key];
 819                  if ($gCms->modules[$key]['installed'] == true &&
 820                      $gCms->modules[$key]['active'] == true)
 821                  {
 822                      $gCms->modules[$key]['object']->GlobalContentPreCompile($text);
 823                  }
 824              }
 825              
 826              Events::SendEvent('Core', 'GlobalContentPreCompile', array('content' => &$text));
 827  
 828              return $text;
 829          }
 830          else
 831          {
 832              return "<!-- Html blob '" . $matches[1] . "' does not exist  -->";
 833          }
 834      }
 835      else
 836      {
 837          return "<!-- Html blob has no name parameter -->";
 838      }
 839  }
 840  
 841  # vim:ts=4 sw=4 noet
 842  ?>


Généré le : Tue Apr 3 18:50:37 2007 par Balluche grâce à PHPXref 0.7