[ 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/ -> News.module.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: News.module.php 2114 2005-11-04 21:51:13Z wishy $
  20  
  21  class News extends CMSModule
  22  {
  23  	function GetName()
  24      {
  25          return 'News';
  26      }
  27  
  28  	function GetFriendlyName()
  29      {
  30          return $this->Lang('news');
  31      }
  32  
  33  	function IsPluginModule()
  34      {
  35          return true;
  36      }
  37  
  38  	function HasAdmin()
  39      {
  40          return true;
  41      }
  42  
  43  	function GetVersion()
  44      {
  45          return '2.2';
  46      }
  47  
  48  	function MinimumCMSVersion()
  49      {
  50          return '1.0-svn';
  51      }
  52  
  53  	function GetAdminDescription()
  54      {
  55          return $this->Lang('description');
  56      }
  57  
  58  	function GetAdminSection()
  59      {
  60          return 'content';
  61      }
  62  
  63  	function SetParameters()
  64      {
  65          $this->RegisterRoute('/[nN]ews\/(?P<articleid>[0-9]+)\/(?P<returnid>[0-9]+)\/d,(?P<detailtemplate>.*?)$/');
  66          $this->RegisterRoute('/[nN]ews\/(?P<articleid>[0-9]+)\/(?P<returnid>[0-9]+)$/');
  67          $this->RegisterRoute('/[nN]ews\/(?P<articleid>[0-9]+)$/');
  68          $this->RegisterRoute('/[nN]ews\/(?P<action>rss)\/(?P<category>.*?)$/', array('showtemplate'=>'false'));
  69          $this->RegisterRoute('/[nN]ews\/(?P<action>rss)$/', array('showtemplate'=>'false'));
  70  
  71          $this->CreateParameter('browsecat', 1, $this->lang('helpbrowsecat'));
  72          $this->CreateParameter('showarchive', 1, $this->lang('helpshowarchive'));
  73          $this->CreateParameter('sortasc', 'true', $this->lang('helpsortasc'));
  74          $this->CreateParameter('sortby', 'news_date', $this->lang('helpsortby'));
  75          $this->CreateParameter('detailpage', 'pagealias', $this->lang('helpdetailpage'));
  76          $this->CreateParameter('detailtemplate', 'sometemplate.tpl', $this->lang('helpdetailtemplate'));
  77          $this->CreateParameter('summarytemplate', 'sometemplate.tpl', $this->lang('helpsummarytemplate'));
  78          $this->CreateParameter('moretext', 'more...', $this->lang('helpmoretext'));
  79          $this->CreateParameter('category', 'category', $this->lang('helpcategory'));
  80          $this->CreateParameter('makerssbutton', 'true', $this->lang('helpmakerssbutton'));
  81          $this->CreateParameter('dateformat', '%b %d, %Y', $this->lang('helpdateformat'));
  82          $this->CreateParameter('number', '5', $this->lang('helpnumber'));
  83          $this->CreateParameter('start', '5', $this->lang('helpstart'));
  84          $this->mCachable = false;
  85          
  86          $this->RegisterContentType('NewsModule', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'contenttype.news.php', $this->GetFriendlyName());
  87      }
  88  
  89  	function ContentPostRender(&$content)
  90      {
  91          if ($this->GetPreference('showautodiscovery', 'yes') == 'yes')
  92          {
  93              #if (eregi('\{cms_module module=[\"\']?news[\"\']?', $content))
  94              if (strpos($content, '<!-- Displaying News Module -->') !== FALSE)
  95              {
  96                  global $gCms;
  97                  $config =& $gCms->GetConfig();
  98  
  99                  $matches = array();
 100                  $categories = '';
 101                  if (preg_match("/<!-- News Categories: '(.*?)' -->/", $content, $matches))
 102                      $categories = $matches[1];
 103  
 104                  $params = array("showtemplate"=>"false");
 105                  
 106                  $url = '';
 107                  if ($this->GetPreference('autodiscoverylink', '') == '')
 108                  {
 109                      if (($config['assume_mod_rewrite'] == true || $config['internal_pretty_urls'] == true) && $config['use_hierarchy'] == true)
 110                      {
 111                          if ($config['assume_mod_rewrite'] == true)
 112                              $url = $config['root_url'].'/News/rss/'.rawurlencode($categories);
 113                          else
 114                              $url = $config['root_url'].'/index.php/News/rss/'.rawurlencode($categories);
 115                      }
 116                      else
 117                          $url = $config['root_url'].'/index.php?mact=News,cntnt01,rss&amp;cntnt01showtemplate=false&amp;cntnt01category='.rawurlencode($categories).'&amp;cntnt01number=20&amp;cntnt01returnid='.$gCms->variables['content_id'];
 118                  }
 119                  else
 120                  {
 121                      $url = $this->GetPreference('autodiscoverylink', '');
 122                  }
 123      
 124                  $text = '<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="'.$url.'" />';
 125                  if (function_exists('str_ireplace'))
 126                  {
 127                      $content = str_ireplace('</head>', $text.'</head>', $content);
 128                  }
 129                  else
 130                  {
 131                      $content = eregi_replace('<\/head>', $text.'</head>', $content);
 132                  }
 133              }
 134          }
 135      }
 136  
 137      function VisibleToAdminUser()
 138      {
 139        return $this->CheckPermission('Modify News') || $this->CheckPermission('Modify Site Preferences') || $this->CheckPermission('Modify Templates');
 140      }
 141  
 142      /**
 143       * This function is not in the API!!!
 144       */
 145  	function GetSummaryHtmlTemplate()
 146      {
 147          return '<!-- Start News Display Template -->
 148  {foreach from=$items item=entry}
 149  <div class="NewsSummary">
 150  
 151  {if $entry->formatpostdate}
 152      <div class="NewsSummaryPostdate">
 153          {$entry->formatpostdate}
 154      </div>
 155  {/if}
 156  
 157  <div class="NewsSummaryLink">
 158      {$entry->titlelink}
 159  </div>
 160  
 161  <div class="NewsSummaryCategory">
 162      {$category_label} {$entry->category}
 163  </div>
 164  
 165  {if $entry->author}
 166      <div class="NewsSummaryAuthor">
 167          {$author_label} {$entry->author}
 168      </div>
 169  {/if}
 170  
 171  {if $entry->summary}
 172      <div class="NewsSummarySummary">
 173          {eval var=$entry->summary}
 174      </div>
 175  
 176      <div class="NewsSummaryMorelink">
 177          [{$entry->morelink}]
 178      </div>
 179  
 180  {else if $entry->content}
 181  
 182      <div class="NewsSummaryContent">
 183          {eval var=$entry->content}
 184      </div>
 185  {/if}
 186  
 187  </div>
 188  {/foreach}
 189  <!-- End News Display Template -->';
 190      }
 191  
 192      function GetDetailHtmlTemplate()
 193      {
 194          return '{if $entry->formatpostdate}
 195      <div id="NewsPostDetailDate">
 196          {$entry->formatpostdate}
 197      </div>
 198  {/if}
 199  <h3 id="NewsPostDetailTitle">{$entry->title}</h3>
 200  
 201  <hr id="NewsPostDetailHorizRule" />
 202  
 203  {if $entry->summary}
 204      <div id="NewsPostDetailSummary">
 205          <strong>
 206              {eval var=$entry->summary}
 207          </strong>
 208      </div>
 209  {/if}
 210  
 211  {if $entry->category}
 212      <div id="NewsPostDetailCategory">
 213          {$category_label} {$entry->category}
 214      </div>
 215  {/if}
 216  {if $entry->author}
 217      <div id="NewsPostDetailAuthor">
 218          {$author_label} {$entry->author}
 219      </div>
 220  {/if}
 221  
 222  <div id="NewsPostDetailContent">
 223      {eval var=$entry->content}
 224  </div>
 225  
 226  <div id="NewsPostDetailPrintLink">
 227      {$entry->printlink}
 228  </div>
 229  {if $return_url != ""}
 230  <div id="NewsPostDetailReturnLink">{$return_url}</div>
 231  {/if}';
 232      }
 233  
 234  	function InstallPostMessage()
 235      {
 236          return $this->Lang('postinstall');
 237      }
 238  
 239      function UpdateHierarchyPositions()
 240      {
 241          $db =& $this->GetDb();
 242  
 243          $query = "SELECT news_category_id, news_category_name FROM ".cms_db_prefix()."module_news_categories";
 244          $dbresult = $db->Execute($query);
 245          while ($dbresult && $row = $dbresult->FetchRow())
 246          {
 247              $current_hierarchy_position = "";
 248              $current_long_name = "";
 249              $content_id = $row['news_category_id'];
 250              $current_parent_id = $row['news_category_id'];
 251              $count = 0;
 252  
 253              while ($current_parent_id > -1)
 254              {
 255                  $query = "SELECT news_category_id, news_category_name, parent_id FROM ".cms_db_prefix()."module_news_categories WHERE news_category_id = ?";
 256                  $row2 = $db->GetRow($query, array($current_parent_id));
 257                  if ($row2)
 258                  {
 259                      $current_hierarchy_position = str_pad($row2['news_category_id'], 5, '0', STR_PAD_LEFT) . "." . $current_hierarchy_position;
 260                      $current_long_name = $row2['news_category_name'] . ' | ' . $current_long_name;
 261                      $current_parent_id = $row2['parent_id'];
 262                      $count++;
 263                  }
 264                  else
 265                  {
 266                      $current_parent_id = 0;
 267                  }
 268              }
 269  
 270              if (strlen($current_hierarchy_position) > 0)
 271              {
 272                  $current_hierarchy_position = substr($current_hierarchy_position, 0, strlen($current_hierarchy_position) - 1);
 273              }
 274  
 275              if (strlen($current_long_name) > 0)
 276              {
 277                  $current_long_name = substr($current_long_name, 0, strlen($current_long_name) - 3);
 278              }
 279  
 280              $query = "UPDATE ".cms_db_prefix()."module_news_categories SET hierarchy = ?, long_name = ? WHERE news_category_id = ?";
 281              $db->Execute($query, array($current_hierarchy_position, $current_long_name, $content_id));
 282          }
 283      }
 284  
 285      function CreateParentDropdown($id, $catid = -1, $selectedvalue = -1)
 286      {
 287          $db =& $this->GetDb();
 288  
 289          $longname = '';
 290  
 291          $items['(None)'] = '-1';
 292  
 293          $query = "SELECT hierarchy, long_name FROM ".cms_db_prefix()."module_news_categories WHERE news_category_id = ?";
 294          $dbresult = $db->Execute($query, array($catid));
 295          while ($dbresult && $row = $dbresult->FetchRow())
 296          {
 297              $longname = $row['hierarchy'] . '%';
 298          }
 299  
 300          $query = "SELECT news_category_id, news_category_name, hierarchy, long_name FROM ".cms_db_prefix()."module_news_categories WHERE hierarchy not like ? ORDER by hierarchy";
 301          $dbresult = $db->Execute($query, array($longname));
 302          while ($dbresult && $row = $dbresult->FetchRow())
 303          {
 304              $items[$row['long_name']] = $row['news_category_id'];
 305          }
 306  
 307          return $this->CreateInputDropdown($id, 'parent', $items, -1, $selectedvalue);
 308      }
 309  
 310  	function GetHelp($lang='en_US')
 311      {
 312          return $this->Lang('help');
 313      }
 314  
 315  	function GetAuthor()
 316      {
 317          return 'Ted Kulp';
 318      }
 319  
 320  	function GetAuthorEmail()
 321      {
 322          return 'wishy@cmsmadesimple.org';
 323      }
 324  
 325  	function GetChangeLog()
 326      {
 327          return $this->Lang('changelog');
 328      }
 329      
 330  	function GetEventDescription( $eventname )
 331      {
 332          return $this->lang('eventdesc-' . $eventname);
 333      }
 334  
 335  	function GetEventHelp( $eventname )
 336      {
 337          return $this->lang('eventhelp-' . $eventname);
 338      }
 339      
 340      function SearchResult($returnid, $articleid, $attr = '')
 341      {
 342          $result = array();
 343          
 344          if ($attr == 'article')
 345          {
 346              $db =& $this->GetDb();
 347              $q = "SELECT news_title FROM ".cms_db_prefix()."module_news WHERE
 348                    news_id = ?";
 349              $dbresult = $db->Execute( $q, array( $articleid ) );
 350              if ($dbresult)
 351              {
 352                  $row = $dbresult->FetchRow();
 353  
 354                  //0 position is the prefix displayed in the list results.
 355                  $result[0] = $this->GetFriendlyName();
 356          
 357                  //1 position is the title
 358                  $result[1] = $row['news_title'];
 359  
 360                  //2 position is the URL to the title.
 361                  $prettyurl = 'news/' . $articleid;
 362                  $result[2] = $this->CreateLink('cntnt01', 'detail', $returnid, '', array('articleid' => $articleid) ,'', true, false, '', true, $prettyurl);
 363              }
 364          }
 365          
 366          return $result;
 367      }
 368      
 369      function SearchReindex(&$module)
 370      {
 371          $db =& $this->GetDb();
 372          
 373          $query = 'SELECT * FROM '.cms_db_prefix().'module_news ORDER BY news_date';
 374          $result = &$db->Execute($query);
 375  
 376          while ($result && !$result->EOF)
 377          {
 378              if ($result->fields['status'] == 'published')
 379              {
 380                  $module->AddWords($this->GetName(), $result->fields['news_id'], 'article', $result->fields['news_data'] . ' ' . $result->fields['summary'] . ' ' . $result->fields['news_title'] . ' ' . $result->fields['news_title'], $result->fields['end_time'] != NULL ?  $db->UnixTimeStamp($result->fields['end_time']) : NULL);
 381              }
 382              $result->MoveNext();
 383          }
 384      }
 385  
 386      /**
 387      * An api function (callable from user tags) that allows the creation
 388      * of a new news article in a named category.
 389      *
 390      * AuthorID, is taken from the currently logged in ID, or is set at 0
 391      */
 392      function AddNewArticle( $category, $title, $summary, $text = null, $start_time = null, $end_time = null, $status = 'published', $icon = null )
 393      {
 394          $db =& $this->GetDb();
 395  
 396          // find the category id
 397          $q = "SELECT news_category_id AS id FROM ".cms_db_prefix()."module_news_categories
 398          WHERE news_category_name = ?";
 399          $dbresult = $db->Execute( $q, array( $category ) );
 400          if( !$dbresult || $dbresult->RecordCount() == 0 )
 401          {
 402              return array( FALSE, $this->Lang('error_api_nocategory') );
 403          }
 404          $row = $dbresult->FetchRow();
 405          $catid = $row['id'];
 406  
 407          // find the author id given a name
 408          $authorid = 0;
 409          if( get_userid() != false )
 410          {
 411              $authorid = get_userid();
 412          }
 413  
 414          // check the remaining params
 415          if( $summary == '' )
 416          {
 417              return array( FALSE, $this->Lang('error_api_nosummary') );
 418          }
 419  
 420          if( $start_time == null )
 421          {
 422              $start_time = trim($db->DBTimeStamp(time()), "'");
 423          }
 424  
 425          // get a new article id
 426          $newsid = $db->GenID(cms_db_prefix()."module_news_seq");
 427  
 428          // prepare the query
 429          $query = 'INSERT INTO '.cms_db_prefix().'module_news ( NEWS_ID, NEWS_CATEGORY_ID, AUTHOR_ID, NEWS_TITLE, NEWS_DATA, NEWS_DATE, SUMMARY, START_TIME, END_TIME, STATUS, ICON, CREATE_DATE, MODIFIED_DATE ) VALUES (?,?,?,?,?,?,?,?,?,?,?,'.$db->DBTimeStamp(time()).','.$db->DBTimeStamp(time()).')';
 430          $parms = array( $newsid, $catid, $authorid, $title, $text, 
 431              $start_time,
 432              $summary, $start_time, $end_time, $status, $icon);
 433  
 434          // and go
 435          $dbresult = $db->Execute( $query, $parms );
 436          if( !$dbresult )
 437          {
 438              return array( FALSE, $this->Lang('error_api_dberror') );
 439          }
 440          
 441          @$this->SendEvent('NewsArticleAdded', array('news_id' => $newsid, 'category_id' => $catid, 'title' => $title, 'content' => $text, 'summary' => $summary, 'status' => $status, 'start_time' => $start_time, 'end_time' => $end_time));
 442  
 443          return array( TRUE );
 444      }
 445  }
 446  
 447  # vim:ts=4 sw=4 noet
 448  ?>


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