[ Index ]
 

Code source de CMS made simple 1.0.5

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

title

Body

[fermer]

/modules/News/ -> contenttype.news.php (source)

   1  <?php
   2  #CMS - CMS Made Simple
   3  #(c)2004=6 by Ted Kulp (ted@cmsmadesimple.org)
   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$
  20  
  21  class NewsModule extends CMSModuleContentType
  22  {
  23  	function SetProperties()
  24      {
  25          $this->mProperties->Add('string', 'start', '');
  26          $this->mProperties->Add('string', 'number', '');
  27          $this->mProperties->Add('string', 'dateformat', 'F j, Y, g:i a');
  28          $this->mProperties->Add('string', 'category');
  29          $this->mProperties->Add('string', 'moretext', 'more...');
  30          $this->mProperties->Add('bool', 'sortasc', 0);
  31  
  32          #Turn on preview
  33          $this->mPreview = true;
  34  
  35          #Turn off caching
  36          $this->mCachable = false;
  37      }
  38  
  39  	function EditAsArray($adding = false)
  40      {
  41          global $gCms;
  42          $config =& $gCms->GetConfig();
  43          $templateops =& $gCms->GetTemplateOperations();
  44  
  45          $ret = array();
  46  
  47          $ret[]= array(lang('title').':','<input type="text" name="title" value="'.$this->mName.'">');
  48          $ret[]= array(lang('menutext').':','<input type="text" name="menutext" value="'.$this->mMenuText.'">');
  49          $ret[]= array(lang('pagealias').':','<input type="text" name="alias" value="'.$this->mAlias.'">');
  50          $ret[]= array(lang('template').':',$templateops->TemplateDropdown('template_id', $this->mTemplateId));
  51          $ret[]= array($this->Lang('numbertodisplay').':','<input type="text" name="number" value="'.$this->GetPropertyValue('number').'" />');
  52          $ret[]= array($this->Lang('startoffset').':','<input type="text" name="start" value="'.$this->GetPropertyValue('start').'" />');
  53          $ret[]= array($this->Lang('category').':','<input type="text" name="category" value="'.$this->GetPropertyValue('category').'" />');
  54          $ret[]= array($this->Lang('moretext').':','<input type="text" name="moretext" value="'.$this->GetPropertyValue('moretext').'" />');
  55          $ret[]= array($this->Lang('sortascending').':','<input type="checkbox" name="sortasc" '.($this->GetPropertyValue('sortasc') == 1?' checked="true"':'').' />');
  56          $ret[]= array(lang('active').':','<input type="checkbox" name="active"'.($this->mActive?' checked="true"':'').'>');
  57          $ret[]= array(lang('showinmenu').':','<input type="checkbox" name="showinmenu"'.($this->mShowInMenu?' checked="true"':'').'>');
  58          $contentops =& $gCms->GetContentOperations();
  59          $ret[]= array(lang('parent').':',$contentops->CreateHierarchyDropdown($this->mId, $this->mParentId));
  60  
  61          return $ret;
  62      }
  63  
  64  
  65  	function Edit($adding = false)
  66      {
  67          global $gCms;
  68          $config =& $gCms->GetConfig();
  69          $templateops =& $gCms->GetTemplateOperations();
  70  
  71          $text = '';
  72  
  73          $text .= '<tr><td>'.lang('title').':</td><td><input type="text" name="title" value="'.$this->mName.'"></td></tr>';
  74          $text .= '<tr><td>'.lang('menutext').':</td><td><input type="text" name="menutext" value="'.$this->mMenuText.'"></td></tr>';
  75          $text .= '<tr><td>'.lang('pagealias').':</td><td><input type="text" name="alias" value="'.$this->mAlias.'"></td></tr>';
  76          $text .= '<tr><td>'.lang('template').':</td><td>'.$templateops->TemplateDropdown('template_id', $this->mTemplateId).'</td></tr>';
  77          $text .= '<tr><td>'.$this->Lang('numbertodisplay').':</td><td><input type="text" name="number" value="'.$this->GetPropertyValue('number').'" /></td></tr>';
  78          $text .= '<tr><td>'.$this->Lang('startoffset').':</td><td><input type="text" name="start" value="'.$this->GetPropertyValue('start').'" /></td></tr>';
  79          $text .= '<tr><td>'.$this->Lang('category').':</td><td><input type="text" name="category" value="'.$this->GetPropertyValue('category').'" /></td></tr>';
  80          $text .= '<tr><td>'.$this->Lang('moretext').':</td><td><input type="text" name="moretext" value="'.$this->GetPropertyValue('moretext').'" /></td></tr>';
  81          $text .= '<tr><td>'.$this->Lang('sortascending').':</td><td><input type="checkbox" name="sortasc" '.($this->GetPropertyValue('sortasc')?' checked="true"':'').' /></td></tr>';
  82          $text .= '<tr><td>'.lang('active').':</td><td><input type="checkbox" name="active"'.($this->mActive?' checked="true"':'').'></td></tr>';
  83          $text .= '<tr><td>'.lang('showinmenu').':</td><td><input type="checkbox" name="showinmenu"'.($this->mShowInMenu?' checked="true"':'').'></td></tr>';
  84          $contentops =& $gCms->GetContentOperations();
  85          $text .= '<tr><td>'.lang('parent').':</td><td>'.$contentops->CreateHierarchyDropdown($this->mId, $this->mParentId).'</td></tr>';
  86  
  87          return $text;
  88      }
  89  
  90  	function FillParams(&$params)
  91      {
  92          global $gCms;
  93          $config = $gCms->config;
  94  
  95          if (isset($params))
  96          {
  97              $parameters = array('start', 'number', 'category', 'moretext');
  98              foreach ($parameters as $oneparam)
  99              {
 100                  if (isset($params[$oneparam]))
 101                  {
 102                      $this->SetPropertyValue($oneparam, $params[$oneparam]);
 103                  }
 104              }
 105              if (isset($params['sortasc']))
 106              {
 107                  $this->SetPropertyValue('sortasc', 1);
 108              }
 109              else
 110              {
 111                  $this->SetPropertyValue('sortasc', 0);
 112              }
 113              if (isset($params['title']))
 114              {
 115                  $this->mName = $params['title'];
 116              }
 117              if (isset($params['menutext']))
 118              {
 119                  $this->mMenuText = $params['menutext'];
 120              }
 121              if (isset($params['template_id']))
 122              {
 123                  $this->mTemplateId = $params['template_id'];
 124              }
 125              if (isset($params['alias']))
 126              {
 127                  $this->SetAlias($params['alias']);
 128              }
 129              else
 130              {
 131                  $this->SetAlias('');
 132              }
 133              if (isset($params['parent_id']))
 134              {
 135                  if ($this->mParentId != $params['parent_id'])
 136                  {
 137                      $this->mHierarchy = '';
 138                      $this->mItemOrder = -1;
 139                  }
 140                  $this->mParentId = $params['parent_id'];
 141              }
 142              if (isset($params['active']))
 143              {
 144                  $this->mActive = true;
 145              }
 146              else
 147              {
 148                  $this->mActive = false;
 149              }
 150              if (isset($params['showinmenu']))
 151              {
 152                  $this->mShowInMenu = true;
 153              }
 154              else
 155              {
 156                  $this->mShowInMenu = false;
 157              }
 158          }
 159      }
 160  
 161  	function Show($param = 'content_en')
 162      {
 163          if ($param == 'content_en')
 164          {
 165              global $gCms;
 166              $variables = &$gCms->variables;
 167  
 168              $params = array();
 169  
 170              if (strlen($this->GetPropertyValue('number')) > 0)
 171              {
 172                  $params['number'] = $this->GetPropertyValue('number');
 173              }
 174  
 175              if (strlen($this->GetPropertyValue('start')) > 0)
 176              {
 177                  $params['start'] = $this->GetPropertyValue('start');
 178              }
 179  
 180              if (strlen($this->GetPropertyValue('category')) > 0)
 181              {
 182                  $params['category'] = $this->GetPropertyValue('category');
 183              }
 184  
 185              $params['moretext'] = $this->GetPropertyValue('moretext');
 186              $params['sortasc'] = $this->GetPropertyValue('sortasc');
 187  
 188              $newnews = new News();
 189  
 190              //Buffer all this crap spit out by the News module and return it
 191              @ob_start();
 192              $newnews->DoAction('default', 'newsmodule', $params, $variables['content_id']);
 193              $text = @ob_get_contents();
 194              @ob_end_clean();
 195              #return $text;
 196              return '{literal}'.$text.'{/literal}';
 197          }
 198          else
 199          {
 200              return '';
 201          }
 202      }
 203  
 204  	function GetURL()
 205      {
 206          global $gCms;
 207          $config = $gCms->config;
 208  
 209          $url = "";
 210  
 211          if ($config["assume_mod_rewrite"])
 212          {
 213              // we could use $this->mId instead of mAlias but i think it's better
 214              $url = $config["root_url"]."/".$this->mAlias . $config["page_extension"];
 215          }
 216          else 
 217          {
 218              $url = $config["root_url"]."/index.php?".$config["query_var"]."=". $this->mAlias;
 219          }
 220  
 221          return $url;
 222      }
 223  
 224      function FriendlyName()
 225      {
 226          return 'News';
 227      }
 228  
 229  	function ModuleName()
 230      {
 231          return 'News';
 232      }
 233  
 234  	function IsDefaultPossible()
 235      {
 236          return TRUE;
 237      }
 238  	function ValidateData()
 239      {
 240          $errors = array();
 241  
 242          if ($this->mName == '')
 243          {
 244            if ($this->mMenuText != '')
 245              {
 246                $this->mName = $this->mMenuText;
 247              }
 248            else
 249              {
 250                $errors[]= lang('nofieldgiven',array(lang('title')));
 251                $result = false;
 252              }
 253          }
 254  
 255          if ($this->mMenuText == '')
 256          {
 257            if ($this->mName != '')
 258              {
 259                $this->mMenuText = $this->mName;
 260              }
 261            else
 262              {
 263                    $errors[]=lang('nofieldgiven',array(lang('menutext')));
 264              $result = false;
 265              }
 266          }
 267          if ($this->mAlias != $this->mOldAlias || $this->mAlias == '') #Should only be empty if auto alias is false
 268          {
 269              global $gCms;
 270              $contentops =& $gCms->GetContentOperations();
 271              $error = $contentops->CheckAliasError($this->mAlias, $this->mId);
 272              if ($error !== FALSE)
 273              {
 274                  $errors[]= $error;
 275                  $result = false;
 276              }
 277          }
 278          if ($this->mTemplateId == '')
 279          {
 280              $errors[]= lang('nofieldgiven',array(lang('template')));
 281              $result = false;
 282          }
 283                  return (count($errors) > 0?$errors:FALSE);
 284      }
 285  }
 286  
 287  ?>


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