[ Index ]
 

Code source de CMS made simple 1.0.5

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

title

Body

[fermer]

/lib/classes/contenttypes/ -> Content.inc.php (source)

   1  <?php
   2  # CMS - CMS Made Simple
   3  # (c)2004 by Ted Kulp (tedkulp@users.sf.net)
   4  # This project's homepage is: http://cmsmadesimple.org
   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.inc.php 3465 2006-10-09 14:04:47Z dittmann $
  20  
  21  class Content extends ContentBase
  22  {
  23      var $additionalContentBlocks;
  24      var $addtContentBlocksLoaded;
  25      
  26      function Content()
  27      {
  28      $this->ContentBase();
  29      $this->mProperties->SetAllowedPropertyNames(array('content_en'));
  30      $this->additionalContentBlocks = array();
  31      $this->addtContentBlocksLoaded = false;
  32      }
  33      
  34      function FriendlyName()
  35      {
  36      return 'Content';
  37      }
  38  
  39      function SetProperties()
  40      {
  41      $this->mProperties->Add("string", "content_en"); //For later language support
  42  
  43      #Turn on preview
  44      $this->mPreview = true;
  45      }
  46  
  47      /**
  48       * Use the ReadyForEdit callback to get the additional content blocks loaded.
  49       */
  50      function ReadyForEdit()
  51      {
  52      $this->GetAdditionalContentBlocks();
  53      }
  54  
  55      function GetTabDefinitions()
  56      {
  57      return array('Basic', 'Advanced');
  58      #return array();
  59      }
  60  
  61      function FillParams($params)
  62      {
  63      global $gCms;
  64      $config = $gCms->config;
  65  
  66      if (isset($params))
  67      {
  68          $parameters = array('content_en');
  69  
  70          //pick up the template id before we do parameters
  71          if (isset($params['template_id']))
  72          {
  73          if ($this->mTemplateId != $params['template_id'])
  74          {
  75              $this->addtContentBlocksLoaded = false;
  76          }
  77          $this->mTemplateId = $params['template_id'];
  78          }
  79  
  80          // add additional content blocks
  81          $this->GetAdditionalContentBlocks();
  82          foreach($this->additionalContentBlocks as $blockName => $blockNameId)
  83          {
  84          $parameters[] = $blockNameId['id'];
  85          }
  86              
  87          foreach ($parameters as $oneparam)
  88          {
  89          if (isset($params[$oneparam]))
  90          {
  91              $this->SetPropertyValue($oneparam, $params[$oneparam]);
  92          }
  93          }
  94          if (isset($params['title']))
  95          {
  96          $this->mName = $params['title'];
  97          }
  98          if (isset($params['metadata']))
  99          {
 100          $this->mMetadata = $params['metadata'];
 101          }
 102          if (isset($params['accesskey']))
 103          {
 104          $this->mAccessKey = $params['accesskey'];
 105          }
 106          if (isset($params['titleattribute']))
 107          {
 108          $this->mTitleAttribute = $params['titleattribute'];
 109          }
 110          if (isset($params['tabindex']))
 111          {
 112          $this->mTabIndex = $params['tabindex'];
 113          }
 114          if (isset($params['menutext']))
 115          {
 116          $this->mMenuText = $params['menutext'];
 117          }
 118          if (isset($params['alias']))
 119          {
 120          $this->SetAlias(trim($params['alias']));
 121          }
 122          if (isset($params['parent_id']))
 123          {
 124          if ($this->mParentId != $params['parent_id'])
 125          {
 126              $this->mHierarchy = '';
 127              $this->mItemOrder = -1;
 128          }
 129          $this->mParentId = $params['parent_id'];
 130          }
 131          if (isset($params['active']))
 132          {
 133          $this->mActive = true;
 134          }
 135          else
 136          {
 137          $this->mActive = false;
 138          }
 139          if (isset($params['showinmenu']))
 140          {
 141          $this->mShowInMenu = true;
 142          }
 143          else
 144          {
 145          $this->mShowInMenu = false;
 146          }
 147          if (isset($params['cachable']))
 148          {
 149          $this->mCachable = true;
 150          }
 151          else
 152          {
 153          $this->mCachable = false;
 154          }
 155      }
 156      }
 157  
 158      function Show($param = 'content_en')
 159      {
 160      // check for additional content blocks
 161      $this->GetAdditionalContentBlocks();
 162      
 163      return $this->GetPropertyValue($param);
 164      }
 165  
 166      function IsDefaultPossible()
 167      {
 168      return TRUE;
 169      }
 170  
 171      function TabNames()
 172      {
 173      return array(lang('main'), lang('options'));
 174      }
 175  
 176      function EditAsArray($adding = false, $tab = 0, $showadmin = false)
 177      {
 178      global $gCms;
 179      
 180      $config = $gCms->GetConfig();
 181      $templateops =& $gCms->GetTemplateOperations();
 182      $ret = array();
 183      $stylesheet = '';
 184      if ($this->TemplateId() > 0)
 185      {
 186          $stylesheet = '../stylesheet.php?templateid='.$this->TemplateId();
 187      }
 188      else
 189      {
 190          $defaulttemplate = $templateops->LoadDefaultTemplate();
 191          if (isset($defaulttemplate))
 192          {
 193          $this->mTemplateId = $defaulttemplate->id;
 194          $stylesheet = '../stylesheet.php?templateid='.$this->TemplateId();
 195          }
 196      }
 197      if ($tab == 0)
 198      {
 199          $ret[]= array(lang('title').':','<input type="text" name="title" value="'.cms_htmlentities($this->mName).'" />');
 200          $ret[]= array(lang('menutext').':','<input type="text" name="menutext" value="'.cms_htmlentities($this->mMenuText).'" />');
 201          if (check_permission(get_userid(), 'Modify Page Structure') || ($adding == true && check_permission(get_userid(), 'Add Pages')))
 202          {
 203              $contentops =& $gCms->GetContentOperations();
 204              $ret[]= array(lang('parent').':',$contentops->CreateHierarchyDropdown($this->mId, $this->mParentId));
 205          }
 206          $additionalcall = '';
 207          foreach($gCms->modules as $key=>$value)
 208          {
 209          if (get_preference(get_userid(), 'wysiwyg')!="" && 
 210              $gCms->modules[$key]['installed'] == true &&
 211              $gCms->modules[$key]['active'] == true &&
 212              $gCms->modules[$key]['object']->IsWYSIWYG() &&
 213              $gCms->modules[$key]['object']->GetName()==get_preference(get_userid(), 'wysiwyg'))
 214          {
 215              $additionalcall = $gCms->modules[$key]['object']->WYSIWYGPageFormSubmit();
 216          }
 217          }
 218              
 219          $ret[]= array(lang('template').':', $templateops->TemplateDropdown('template_id', $this->mTemplateId, 'onchange="document.contentform.submit()"'));
 220          $ret[]= array(lang('content').':',create_textarea(true, $this->GetPropertyValue('content_en'), 'content_en', '', 'content_en', '', $stylesheet));
 221  
 222          // add additional content blocks if required
 223          $this->GetAdditionalContentBlocks(); // this is needed as this is the first time we get a call to our class when editing.
 224          foreach($this->additionalContentBlocks as $blockName => $blockNameId)
 225          {
 226          if ($blockNameId['oneline'] == 'true')
 227          {
 228              $ret[]= array(ucwords($blockName).':','<input type="text" name="'.$blockNameId['id'].'" value="'.$this->GetPropertyValue($blockNameId['id']).'" />');
 229          }
 230          else
 231          {
 232              $ret[]= array(ucwords($blockName).':',create_textarea(($blockNameId['usewysiwyg'] == 'false'?false:true), $this->GetPropertyValue($blockNameId['id']), $blockNameId['id'], '', $blockNameId['id'], '', $stylesheet));
 233          }
 234          }
 235      }
 236      if ($tab == 1)
 237      {
 238          $ret[]= array(lang('active').':','<input class="pagecheckbox" type="checkbox" name="active"'.($this->mActive?' checked="checked"':'').' />');
 239          $ret[]= array(lang('showinmenu').':','<input class="pagecheckbox" type="checkbox" name="showinmenu"'.($this->mShowInMenu?' checked="checked"':'').' />');
 240          $ret[]= array(lang('cachable').':','<input class="pagecheckbox" type="checkbox" name="cachable"'.($this->mCachable?' checked="checked"':'').' />');
 241          $ret[]= array(lang('pagealias').':','<input type="text" name="alias" value="'.$this->mAlias.'" />');
 242          $ret[]= array(lang('metadata').':',create_textarea(false, $this->Metadata(), 'metadata', 'pagesmalltextarea', 'metadata', '', '', '80', '6'));
 243  
 244          $ret[]= array(lang('titleattribute').':','<input type="text" name="titleattribute" maxlength="255" size="80" value="'.cms_htmlentities($this->mTitleAttribute).'" />');
 245          $ret[]= array(lang('tabindex').':','<input type="text" name="tabindex" maxlength="10" value="'.cms_htmlentities($this->mTabIndex).'" />');
 246          $ret[]= array(lang('accesskey').':','<input type="text" name="accesskey" maxlength="5" value="'.cms_htmlentities($this->mAccessKey).'" />');
 247  
 248          if (!$adding && $showadmin)
 249          {
 250              $userops =& $gCms->GetUserOperations();
 251              $ret[]= array(lang('owner').':', $userops->GenerateDropdown($this->Owner()));
 252          }
 253  
 254          if ($adding || $showadmin)
 255          {
 256          $ret[]= $this->ShowAdditionalEditors();
 257          }
 258      }
 259      return $ret;
 260      }
 261  
 262  
 263      function ValidateData()
 264      {
 265      $errors = array();
 266  
 267      if ($this->mName == '')
 268      {
 269          if ($this->mMenuText != '')
 270          {
 271          $this->mName = $this->mMenuText;
 272          }
 273          else
 274          {
 275          $errors[]= lang('nofieldgiven',array(lang('title')));
 276          $result = false;
 277          }
 278      }
 279  
 280      if ($this->mMenuText == '')
 281      {
 282          if ($this->mName != '')
 283          {
 284          $this->mMenuText = $this->mName;
 285          }
 286          else
 287          {
 288          $errors[]=lang('nofieldgiven',array(lang('menutext')));
 289          $result = false;
 290          }
 291      }
 292          
 293      if ($this->mAlias != $this->mOldAlias || $this->mAlias == '') #Should only be empty if auto alias is false
 294      {
 295          global $gCms;
 296          $contentops =& $gCms->GetContentOperations();
 297          $error = $contentops->CheckAliasError($this->mAlias, $this->mId);
 298          if ($error !== FALSE)
 299          {
 300          $errors[]= $error;
 301          $result = false;
 302          }
 303      }
 304  
 305      if ($this->mTemplateId == '')
 306      {
 307          $errors[]= lang('nofieldgiven',array(lang('template')));
 308          $result = false;
 309      }
 310  
 311      if ($this->GetPropertyValue('content_en') == '')
 312      {
 313          $errors[]= lang('nofieldgiven',array(lang('content')));
 314          $result = false;
 315      }
 316  
 317      return (count($errors) > 0?$errors:FALSE);
 318      }
 319  
 320      function GetAdditionalContentBlocks()
 321      {
 322      $result = false;
 323      global $gCms;
 324      $templateops =& $gCms->GetTemplateOperations();
 325      if ($this->addtContentBlocksLoaded == false)
 326      {
 327          $this->additionalContentBlocks = array();
 328          if ($this->TemplateId() && $this->TemplateId() > -1)
 329          {
 330          $template = $templateops->LoadTemplateByID($this->TemplateId()); /* @var $template Template */
 331          }
 332          else
 333          {
 334          $template = $templateops->LoadDefaultTemplate();
 335          }
 336          if($template !== false)
 337          {
 338          $content = $template->content;
 339                  
 340          $pattern = '/{content([^}]*)}/';
 341          $pattern2 = '/([a-zA-z0-9]*)=["\']([^"\']+)["\']/';
 342          $matches = array();
 343          $result = preg_match_all($pattern, $content, $matches);
 344          if ($result && count($matches[1]) > 0)
 345          {
 346              foreach ($matches[1] as $wholetag)
 347              {
 348              $morematches = array();
 349              $result2 = preg_match_all($pattern2, $wholetag, $morematches);
 350              if ($result2)
 351              {
 352                  $keyval = array();
 353                  for ($i = 0; $i < count($morematches[1]); $i++)
 354                  {
 355                  $keyval[$morematches[1][$i]] = $morematches[2][$i];
 356                  }
 357  
 358                  $id = '';
 359                  $name = '';
 360                  $usewysiwyg = 'true';
 361                  $oneline = 'false';
 362  
 363                  foreach ($keyval as $key=>$val)
 364                  {
 365                  switch($key)
 366                  {
 367                      case 'block':
 368                      $id = str_replace(' ', '_', $val);
 369                      $name = $val;
 370  
 371                      if(!array_key_exists($val, $this->mProperties->mPropertyTypes))
 372                      {
 373                          $this->mProperties->Add("string", $id);
 374                      }
 375                      break;
 376                      case 'wysiwyg':
 377                      $usewysiwyg = $val;
 378                      break;
 379                      case 'oneline':
 380                      $oneline = $val;
 381                      break;
 382                      default:
 383                      break;
 384                  }
 385                  }
 386  
 387                  $this->additionalContentBlocks[$name]['id'] = $id;
 388                  $this->additionalContentBlocks[$name]['usewysiwyg'] = $usewysiwyg;
 389                  $this->additionalContentBlocks[$name]['oneline'] = $oneline;
 390                      
 391              }
 392              }
 393  
 394              // force a load 
 395              $this->mProperties->Load($this->mId);
 396  
 397              $result = true;
 398          }
 399          }
 400          $this->addtContentBlocksLoaded = true;
 401      }
 402      return $result;
 403      }
 404      
 405      function ContentPreRender($tpl_source)
 406      {
 407      // check for additional content blocks
 408      $this->GetAdditionalContentBlocks();
 409  
 410      return $tpl_source;
 411      }
 412  }
 413  
 414  # vim:ts=4 sw=4 noet
 415  ?>


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