[ Index ]
 

Code source de GeekLog 1.4.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/system/ -> lib-story.php (source)

   1  <?php
   2  
   3  /* Reminder: always indent with 4 spaces (no tabs). */
   4  // +---------------------------------------------------------------------------+
   5  // | Geeklog 1.4                                                               |
   6  // +---------------------------------------------------------------------------+
   7  // | lib-story.php                                                             |
   8  // |                                                                           |
   9  // | Story-related functions needed in more than one place.                    |
  10  // +---------------------------------------------------------------------------+
  11  // | Copyright (C) 2000-2006 by the following authors:                         |
  12  // |                                                                           |
  13  // | Authors: Tony Bibbs        - tony AT tonybibbs DOT com                    |
  14  // |          Mark Limburg      - mlimburg AT users DOT sourceforge DOT net    |
  15  // |          Jason Whittenburg - jwhitten AT securitygeeks DOT com            |
  16  // |          Dirk Haun         - dirk AT haun-online DOT de                   |
  17  // |          Vincent Furia     - vinny01 AT users DOT sourceforge DOT net     |
  18  // +---------------------------------------------------------------------------+
  19  // |                                                                           |
  20  // | This program is free software; you can redistribute it and/or             |
  21  // | modify it under the terms of the GNU General Public License               |
  22  // | as published by the Free Software Foundation; either version 2            |
  23  // | of the License, or (at your option) any later version.                    |
  24  // |                                                                           |
  25  // | This program is distributed in the hope that it will be useful,           |
  26  // | but WITHOUT ANY WARRANTY; without even the implied warranty of            |
  27  // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             |
  28  // | GNU General Public License for more details.                              |
  29  // |                                                                           |
  30  // | You should have received a copy of the GNU General Public License         |
  31  // | along with this program; if not, write to the Free Software Foundation,   |
  32  // | Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           |
  33  // |                                                                           |
  34  // +---------------------------------------------------------------------------+
  35  //
  36  // $Id: lib-story.php,v 1.73 2006/11/09 09:57:28 dhaun Exp $
  37  
  38  if (strpos ($_SERVER['PHP_SELF'], 'lib-story.php') !== false) {
  39      die ('This file can not be used on its own!');
  40  }
  41  
  42  if( $_CONF['allow_user_photo'] )
  43  {
  44      // only needed for the USER_getPhoto function
  45      require_once ($_CONF['path_system'] . 'lib-user.php');
  46  }
  47  
  48  // Story Record Options for the STATUS Field
  49  if (!defined ('STORY_ARCHIVE_ON_EXPIRE')) {
  50      define ('STORY_ARCHIVE_ON_EXPIRE', '10');
  51      define ('STORY_DELETE_ON_EXPIRE',  '11');
  52  }
  53  
  54  /**
  55  * Returns the array (created from db record) passed to it as formated HTML
  56  *
  57  * Formats the given article data into HTML.  Called by index.php, article.php,
  58  * submit.php, and admin/story.php (when previewing)
  59  *
  60  * @param    array       $A      Data to display as an article (associative array from record from gl_stories)
  61  * @param    string      $index  whether or not this is the index page if 'n' then compact display for index page else display full article, also: 'p' = preview
  62  * @return   string      Article as formated HTML
  63  *
  64  * Note: Formerly named COM_article
  65  *
  66  */
  67  function STORY_renderArticle( $A, $index='', $storytpl='storytext.thtml', $query='' )
  68  {
  69      global $_CONF, $_TABLES, $_USER, $LANG01, $LANG05, $LANG11, $LANG_TRB,
  70             $_IMAGE_TYPE, $mode;
  71  
  72      static $storycounter = 0;
  73  
  74      if( empty( $storytpl ))
  75      {
  76          $storytpl = 'storytext.thtml';
  77      }
  78  
  79      $curtime = COM_getUserDateTimeFormat( $A['day'] );
  80      $shortdate = strftime( $_CONF['shortdate'], $A['day'] );
  81      $dateonly = strftime( $_CONF['dateonly'], $A['day'] );
  82      $A['day'] = $curtime[0];
  83  
  84      $introtext = stripslashes( $A['introtext'] );
  85      $bodytext = '';
  86      if( !empty( $A['bodytext'] ))
  87      {
  88          $bodytext  = stripslashes( $A['bodytext'] );
  89      }
  90  
  91      // If plain text then replace newlines with <br> tags
  92      if( $A['postmode'] == 'plaintext' )
  93      {
  94          $introtext = nl2br( $introtext );
  95          if( !empty( $bodytext )) {
  96              $bodytext  = nl2br( $bodytext );
  97          }
  98      }
  99  
 100      $introtext = str_replace( '$', '&#36;', $introtext );
 101      $introtext = str_replace( '{', '&#123;', $introtext );
 102      $introtext = str_replace( '}', '&#125;', $introtext );
 103  
 104     // Replace any plugin autolink tags
 105      $introtext = PLG_replaceTags( $introtext );
 106  
 107      if( !empty( $bodytext ))
 108      {
 109          $bodytext = str_replace( '$', '&#36;', $bodytext );
 110          $bodytext = str_replace( '{', '&#123;', $bodytext );
 111          $bodytext = str_replace( '}', '&#125;', $bodytext );
 112  
 113          $bodytext = PLG_replaceTags( $bodytext );
 114      }
 115  
 116      if( !empty( $query ))
 117      {
 118          $introtext = COM_highlightQuery( $introtext, $query );
 119          $bodytext  = COM_highlightQuery( $bodytext, $query );
 120      }
 121  
 122      $A['title'] = str_replace( '$', '&#36;', $A['title'] );
 123  
 124      $article = new Template( $_CONF['path_layout'] );
 125      $article->set_file( array(
 126              'article'          => $storytpl,
 127              'bodytext'         => 'storybodytext.thtml',
 128              'featuredarticle'  => 'featuredstorytext.thtml',
 129              'featuredbodytext' => 'featuredstorybodytext.thtml',
 130              'archivearticle'   => 'archivestorytext.thtml',
 131              'archivebodytext'  => 'archivestorybodytext.thtml'
 132              ));
 133  
 134      $article->set_var( 'layout_url', $_CONF['layout_url'] );
 135      $article->set_var( 'site_url', $_CONF['site_url'] );
 136      $article->set_var( 'story_date', $A['day'] );
 137      $article->set_var( 'story_date_short', $shortdate );
 138      $article->set_var( 'story_date_only', $dateonly );
 139      if( $_CONF['hideviewscount'] != 1 ) {
 140          $article->set_var( 'lang_views', $LANG01[106] );
 141          $article->set_var( 'story_hits', COM_NumberFormat( $A['hits'] ));
 142      }
 143      $article->set_var( 'story_id', $A['sid'] );
 144  
 145      if( $_CONF['contributedbyline'] == 1 )
 146      {
 147          $article->set_var( 'lang_contributed_by', $LANG01[1] );
 148          $article->set_var( 'contributedby_uid', $A['uid'] );
 149          $username = $A['username'];
 150          $fullname = $A['fullname'];
 151          $article->set_var( 'contributedby_user', $username );
 152          if (empty ($fullname)) {
 153              $article->set_var( 'contributedby_fullname', $username );
 154          } else {
 155              $article->set_var( 'contributedby_fullname', $fullname );
 156          }
 157  
 158          $authorname = COM_getDisplayName( $A['uid'], $username, $fullname );
 159          $article->set_var( 'contributedby_author', $authorname );
 160          $article->set_var( 'author', $authorname );
 161  
 162          if( $A['uid'] > 1 )
 163          {
 164              $profileUrl = $_CONF['site_url']
 165                          . '/users.php?mode=profile&amp;uid=' . $A['uid'];
 166              $article->set_var( 'start_contributedby_anchortag',
 167                      '<a class="storybyline" href="' . $profileUrl . '">' );
 168              $article->set_var( 'end_contributedby_anchortag', '</a>' );
 169              $article->set_var( 'contributedby_url', $profileUrl );
 170          }
 171  
 172          $photo = '';
 173          if( $_CONF['allow_user_photo'] == 1 )
 174          {
 175              if( isset( $A['photo'] ) && empty( $A['photo'] ))
 176              {
 177                  $A['photo'] = '(none)'; // user does not have a photo
 178              }
 179              if( isset( $A['email'] ))
 180              {
 181                  $photo = USER_getPhoto( $A['uid'], $A['photo'], $A['email'] );
 182              }
 183              else
 184              {
 185                  $photo = USER_getPhoto( $A['uid'], $A['photo'] );
 186              }
 187          }
 188          if( !empty( $photo ))
 189          {
 190              $article->set_var( 'contributedby_photo', $photo );
 191              $article->set_var( 'camera_icon', '<a href="' . $_CONF['site_url']
 192                      . '/users.php?mode=profile&amp;uid=' . $A['uid']
 193                      . '"><img src="' . $_CONF['layout_url']
 194                      . '/images/smallcamera.' . $_IMAGE_TYPE
 195                      . '" border="0" alt=""></a>' );
 196          }
 197          else
 198          {
 199              $article->set_var( 'contributedby_photo', '' );
 200              $article->set_var( 'camera_icon', '' );
 201          }
 202      }
 203  
 204      $topicname = htmlspecialchars( stripslashes( $A['topic'] ));
 205      $article->set_var( 'story_topic_id', $A['tid'] );
 206      $article->set_var( 'story_topic_name', $topicname );
 207  
 208      $topicurl = $_CONF['site_url'] . '/index.php?topic=' . $A['tid'];
 209      if(( !isset( $_USER['noicons'] ) OR ( $_USER['noicons'] != 1 )) AND
 210              $A['show_topic_icon'] == 1 )
 211      {
 212          if( !empty( $A['imageurl'] ))
 213          {
 214              $imageurl = COM_getTopicImageUrl( $A['imageurl'] );
 215              $topicimage = '<img align="' . $_CONF['article_image_align']
 216                          . '" src="' . $imageurl . '" alt="' . $topicname
 217                          . '" title="' . $topicname . '" border="0">';
 218              $article->set_var( 'story_anchortag_and_image', '<a href="'
 219                          . $topicurl . '" rel="category tag">' . $topicimage
 220                          . '</a>' );
 221              $article->set_var( 'story_topic_image', $topicimage );
 222          }
 223      }
 224      $article->set_var( 'story_topic_url', $topicurl );
 225  
 226      $recent_post_anchortag = '';
 227      $articleUrl = COM_buildUrl( $_CONF['site_url'] . '/article.php?story='
 228                                  . $A['sid'] );
 229      $article->set_var( 'story_title', stripslashes( $A['title'] ));
 230  
 231      $show_comments = true;
 232      if(( $index == 'n' ) || ( $index == 'p' ))
 233      {
 234          if( empty( $bodytext ))
 235          {
 236              $article->set_var( 'story_introtext', $introtext );
 237              $article->set_var( 'story_text_no_br', $introtext );
 238          }
 239          else
 240          {
 241              if(( $_CONF['allow_page_breaks'] == 1 ) and ( $index == 'n' ))
 242              {
 243                  $story_page = 1;
 244  
 245                  // page selector
 246                  if( is_numeric( $mode ))
 247                  {
 248                      $story_page = $mode;
 249                      if( $story_page <= 0 )
 250                      {
 251                          $story_page = 1;
 252                          $mode = 0;
 253                      }
 254                      elseif( $story_page > 1 )
 255                      {
 256                          $introtext = '';
 257                      }
 258                  }
 259                  $article_array = explode( '[page_break]', $bodytext );
 260                  $pagelinks = COM_printPageNavigation( $articleUrl, $story_page,
 261                                                        count( $article_array ),
 262                                                        'mode=',
 263                                                        $_CONF['url_rewrite'],
 264                                                        $LANG01[118]
 265                                                        );
 266                  if( count( $article_array ) > 1 )
 267                  {
 268                      $bodytext = $article_array[$story_page - 1];
 269                  }
 270                  $article->set_var( 'page_selector', $pagelinks );
 271  
 272                  if (
 273                       ( ($_CONF['page_break_comments'] == 'last')  and
 274                         ($story_page < count($article_array)) )
 275                      or
 276                       ( ($_CONF['page_break_comments'] == 'first')  and
 277                         ($story_page != 1) )
 278                     )
 279                  {
 280                      $show_comments = false;
 281                  }
 282                  $article->set_var( 'story_page', $story_page );
 283              }
 284  
 285              $article->set_var( 'story_introtext', $introtext . '<br><br>'
 286                                 . $bodytext );
 287              $article->set_var( 'story_text_no_br', $introtext . $bodytext );
 288          }
 289          $article->set_var( 'story_introtext_only', $introtext );
 290          $article->set_var( 'story_bodytext_only', $bodytext );
 291  
 292          if(( $_CONF['trackback_enabled'] || $_CONF['pingback_enabled'] ) &&
 293                  SEC_hasRights( 'story.ping' ))
 294          {
 295              $url = $_CONF['site_admin_url']
 296                   . '/trackback.php?mode=sendall&amp;id=' . $A['sid'];
 297              $article->set_var( 'send_trackback_link', '<a href="' . $url . '">'
 298                   . $LANG_TRB['send_trackback'] . '</a>' );
 299              $article->set_var( 'send_trackback_url', $url );
 300              $article->set_var( 'lang_send_trackback_text',
 301                                 $LANG_TRB['send_trackback'] );
 302          }
 303          $article->set_var( 'story_display',
 304                             ( $index == 'p' ) ? 'preview' : 'article' );
 305          $article->set_var( 'story_counter', 0 );
 306      }
 307      else
 308      {
 309          $article->set_var( 'story_introtext', $introtext );
 310          $article->set_var( 'story_introtext_only', $introtext );
 311          $article->set_var( 'story_text_no_br', $introtext );
 312  
 313          if( !empty( $bodytext ))
 314          {
 315              $article->set_var( 'lang_readmore', $LANG01[2] );
 316              $article->set_var( 'lang_readmore_words', $LANG01[62] );
 317              $numwords = COM_NumberFormat (sizeof( explode( ' ', strip_tags( $bodytext ))));
 318              $article->set_var( 'readmore_words', $numwords );
 319  
 320              $article->set_var( 'readmore_link', '<a href="' . $articleUrl
 321                      . '" class="story-read-more-link">' . $LANG01[2] . '</a> ('
 322                      . $numwords . ' ' . $LANG01[62] . ') ' );
 323              $article->set_var( 'start_readmore_anchortag', '<a href="'
 324                      . $articleUrl . '" class="story-read-more-link">' );
 325              $article->set_var( 'end_readmore_anchortag', '</a>' );
 326              $article->set_var( 'read_more_class', 'class="story-read-more"' );
 327          }
 328          $article->set_var( 'start_storylink_anchortag', '<a href="'
 329                  . $articleUrl . '" class="non-ul">' );
 330          $article->set_var( 'end_storylink_anchortag', '</a>' );
 331  
 332          if(( $A['commentcode'] >= 0 ) and ( $show_comments ))
 333          {
 334              $commentsUrl = COM_buildUrl( $_CONF['site_url']
 335                      . '/article.php?story=' . $A['sid'] ) . '#comments';
 336              $article->set_var( 'comments_url', $commentsUrl );
 337              $article->set_var( 'comments_text',
 338                      COM_numberFormat( $A['comments'] ) . ' ' . $LANG01[3] );
 339              $article->set_var( 'comments_count',
 340                      COM_numberFormat ( $A['comments'] ));
 341              $article->set_var( 'lang_comments', $LANG01[3] );
 342              $article->set_var( 'comments_with_count',
 343                      sprintf( $LANG01[121], COM_numberFormat( $A['comments'] )));
 344  
 345              if( $A['comments'] > 0 )
 346              {
 347                  $result = DB_query( "SELECT UNIX_TIMESTAMP(date) AS day,username,fullname,{$_TABLES['comments']}.uid as cuid FROM {$_TABLES['comments']},{$_TABLES['users']} WHERE {$_TABLES['users']}.uid = {$_TABLES['comments']}.uid AND sid = '{$A['sid']}' ORDER BY date desc LIMIT 1" );
 348                  $C = DB_fetchArray( $result );
 349  
 350                  $recent_post_anchortag = '<span class="storybyline">'
 351                          . $LANG01[27] . ': '
 352                          . strftime( $_CONF['daytime'], $C['day'] ) . ' '
 353                          . $LANG01[104] . ' ' . COM_getDisplayName ($C['cuid'],
 354                                                  $C['username'], $C['fullname'])
 355                          . '</span>';
 356                  $article->set_var( 'start_comments_anchortag', '<a href="'
 357                          . $commentsUrl . '">' );
 358                  $article->set_var( 'end_comments_anchortag', '</a>' );
 359              }
 360              else
 361              {
 362                  $recent_post_anchortag = ' <a href="' . $_CONF['site_url']
 363                          . '/comment.php?sid=' . $A['sid']
 364                          . '&amp;pid=0&amp;type=article">' . $LANG01[60] . '</a>';
 365              }
 366              $postCommentUrl = $_CONF['site_url'] . '/comment.php?sid='
 367                              . $A['sid'] . '&amp;pid=0&amp;type=article';
 368              $article->set_var( 'post_comment_link','<a href="'
 369                      . $postCommentUrl . '">' . $LANG01[60] . '</a>' );
 370              $article->set_var( 'lang_post_comment', $LANG01[60] );
 371              $article->set_var( 'start_post_comment_anchortag',
 372                                 '<a href="' . $postCommentUrl . '">' );
 373              $article->set_var( 'end_post_comment_anchortag', '</a>' );
 374          }
 375  
 376          if(( $_CONF['trackback_enabled'] || $_CONF['pingback_enabled'] ) &&
 377                  ( $A['trackbackcode'] >= 0 ) && ( $show_comments ))
 378          {
 379              $num_trackbacks = COM_numberFormat( $A['trackbacks'] );
 380              $trackbacksUrl = COM_buildUrl( $_CONF['site_url']
 381                      . '/article.php?story=' . $A['sid'] ) . '#trackback';
 382              $article->set_var( 'trackbacks_url', $trackbacksUrl );
 383              $article->set_var( 'trackbacks_text', $num_trackbacks . ' '
 384                                                    . $LANG_TRB['trackbacks'] );
 385              $article->set_var( 'trackbacks_count', $num_trackbacks );
 386              $article->set_var( 'lang_trackbacks', $LANG_TRB['trackbacks'] );
 387              $article->set_var( 'trackbacks_with_count',
 388                                 sprintf( $LANG01[122], $num_trackbacks ));
 389  
 390              if( $A['trackbacks'] > 0 )
 391              {
 392                  $article->set_var( 'start_trackbacks_anchortag', '<a href="'
 393                          . $trackbacksUrl . '">' );
 394                  $article->set_var( 'end_trackbacks_anchortag', '</a>' );
 395              }
 396          }
 397  
 398          if(( $_CONF['hideemailicon'] == 1 ) ||
 399             ( empty( $_USER['username'] ) &&
 400                  (( $_CONF['loginrequired'] == 1 ) ||
 401                   ( $_CONF['emailstoryloginrequired'] == 1 ))))
 402          {
 403              $article->set_var( 'email_icon', '' );
 404          }
 405          else
 406          {
 407              $emailUrl = $_CONF['site_url'] . '/profiles.php?sid=' . $A['sid']
 408                        . '&amp;what=emailstory';
 409              $article->set_var( 'email_icon', '<a href="' . $emailUrl . '">'
 410                  . '<img src="' . $_CONF['layout_url'] . '/images/mail.'
 411                  . $_IMAGE_TYPE . '" alt="' . $LANG01[64] . '" title="'
 412                  . $LANG11[2] . '" border="0"></a>' );
 413              $article->set_var( 'email_story_url', $emailUrl );
 414              $article->set_var( 'lang_email_story', $LANG11[2] );
 415              $article->set_var( 'lang_email_story_alt', $LANG01[64] );
 416          }
 417          $printUrl = COM_buildUrl( $_CONF['site_url'] . '/article.php?story='
 418                                    . $A['sid'] . '&amp;mode=print' );
 419          if( $_CONF['hideprintericon'] == 1 )
 420          {
 421              $article->set_var( 'print_icon', '' );
 422          }
 423          else
 424          {
 425              $article->set_var( 'print_icon', '<a href="' . $printUrl . '">'
 426                  . '<img border="0" src="' . $_CONF['layout_url']
 427                  . '/images/print.' . $_IMAGE_TYPE . '" alt="' . $LANG01[65]
 428                  . '" title="' . $LANG11[3] . '"></a>' );
 429              $article->set_var( 'print_story_url', $printUrl );
 430              $article->set_var( 'lang_print_story', $LANG11[3] );
 431              $article->set_var( 'lang_print_story_alt', $LANG01[65] );
 432          }
 433          if( $_CONF['pdf_enabled'] == 1 )
 434          {
 435              $pdfUrl = $_CONF['site_url'] . '/pdfgenerator.php?pageType=2&amp;'
 436                      . 'pageData=' . urlencode( $printUrl );
 437              $article->set_var( 'pdf_icon',
 438                  sprintf( '<a href="%s"><img border="0" src="%s/images/pdf.'
 439                           . $_IMAGE_TYPE . '" alt="%s" title="%s"></a>',
 440                           $pdfUrl, $_CONF['layout_url'], $LANG01[111], $LANG11[5] ));
 441              $article->set_var( 'pdf_story_url', $pdfUrl );
 442              $article->set_var( 'lang_pdf_story', $LANG11[5] );
 443              $article->set_var( 'lang_pdf_story_alt', $LANG01[111] );
 444          }
 445          else
 446          {
 447              $article->set_var( 'pdf_icon', '' );
 448          }
 449          $article->set_var( 'story_display', 'index' );
 450  
 451          $storycounter++;
 452          $article->set_var( 'story_counter', $storycounter );
 453      }
 454      $article->set_var( 'article_url', $articleUrl );
 455      $article->set_var( 'recent_post_anchortag', $recent_post_anchortag );
 456  
 457      if( SEC_hasAccess( $A['owner_id'], $A['group_id'], $A['perm_owner'], $A['perm_group'], $A['perm_members'], $A['perm_anon'] ) == 3 AND SEC_hasrights( 'story.edit' ) AND ( $index != 'p' ) AND SEC_hasTopicAccess( $A['tid'] ) == 3 )
 458      {
 459          $article->set_var( 'edit_link', '<a href="' . $_CONF['site_admin_url']
 460                  . '/story.php?mode=edit&amp;sid=' . $A['sid'] . '">'
 461                  . $LANG01[4] . '</a>' );
 462          $article->set_var( 'edit_url', $_CONF['site_admin_url']
 463                  . '/story.php?mode=edit&amp;sid=' . $A['sid'] );
 464          $article->set_var( 'lang_edit_text',  $LANG01[4] );
 465          $editicon = $_CONF['layout_url'] . '/images/edit.' . $_IMAGE_TYPE;
 466          $article->set_var( 'edit_icon', '<a href="' . $_CONF['site_admin_url']
 467                  . '/story.php?mode=edit&amp;sid=' . $A['sid'] . '"><img src="'
 468                  . $editicon . '" alt="' . $LANG01[4] . '" title="' . $LANG01[4]
 469                  . '" border="0"></a>' );
 470          $article->set_var( 'edit_image',  '<img src="' . $editicon . '" alt="'
 471                  . $LANG01[4] . '" title="' . $LANG01[4] . '" border="0">' );
 472      }
 473  
 474      if (empty ($A['expire'])) { // e.g. in a preview
 475          $archiveDateTime = time ();
 476      } else {
 477          // Need to convert text date/time to a timestamp
 478          $t = explode( ' ', $A['expire'] );
 479          $archiveDateTime = COM_convertDate2Timestamp( $t[0], $t[1] );
 480      }
 481      if( $A['featured'] == 1 )
 482      {
 483          $article->set_var( 'lang_todays_featured_article', $LANG05[4] );
 484          $article->parse( 'story_bodyhtml', 'featuredbodytext', true );
 485          PLG_templateSetVars( 'featuredstorytext', $article );
 486          $article->parse( 'finalstory', 'featuredarticle' );
 487      }
 488      else if(( $A['statuscode'] == STORY_ARCHIVE_ON_EXPIRE ) AND ( $archiveDateTime <= time()))
 489      {
 490          $article->parse( 'story_bodyhtml', 'archivestorybodytext', true );
 491          PLG_templateSetVars( 'archivestorytext', $article );
 492          $article->parse( 'finalstory', 'archivearticle' );
 493      }
 494      else
 495      {
 496          $article->parse( 'story_bodyhtml', 'bodytext', true );
 497          PLG_templateSetVars( 'storytext', $article );
 498          $article->parse( 'finalstory', 'article' );
 499      }
 500  
 501      return $article->finish( $article->get_var( 'finalstory' ));
 502  }
 503  
 504  /**
 505  * Extract links from an HTML-formatted text.
 506  *
 507  * Collects all the links in a story and returns them in an array.
 508  *
 509  * @param    string  $fulltext   the text to search for links
 510  * @param    int     $maxlength  max. length of text in a link (can be 0)
 511  * @return   array   an array of strings of form <a href="...">link</a>
 512  *
 513  */
 514  function STORY_extractLinks( $fulltext, $maxlength = 26 )
 515  {
 516      $rel = array();
 517  
 518      /* Only match anchor tags that contain 'href="<something>"'
 519       */
 520      preg_match_all( "/<a[^>]*href=[\"']([^\"']*)[\"'][^>]*>(.*?)<\/a>/i", $fulltext, $matches );
 521      for ( $i=0; $i< count( $matches[0] ); $i++ )
 522      {
 523          $matches[2][$i] = strip_tags( $matches[2][$i] );
 524          if ( !MBYTE_strlen( trim( $matches[2][$i] ) ) ) {
 525              $matches[2][$i] = strip_tags( $matches[1][$i] );
 526          }
 527  
 528          // if link is too long, shorten it and add ... at the end
 529          if ( ( $maxlength > 0 ) && ( MBYTE_strlen( $matches[2][$i] ) > $maxlength ) )
 530          {
 531              $matches[2][$i] = substr( $matches[2][$i], 0, $maxlength - 3 ) . '...';
 532          }
 533  
 534          $rel[] = '<a href="' . $matches[1][$i] . '">'
 535                 . str_replace ("/(\015\012)|(\015)|(\012)/", '', $matches[2][$i])
 536                 . '</a>';
 537      }
 538  
 539      return( $rel );
 540  }
 541  
 542  /**
 543  * Create "What's Related" links for a story
 544  *
 545  * Creates an HTML-formatted list of links to be used for the What's Related
 546  * block next to a story (in article view).
 547  *
 548  * @param        string      $related    contents of gl_stories 'related' field
 549  * @param        int         $uid        user id of the author
 550  * @param        int         $tid        topic id
 551  * @return       string      HTML-formatted list of links
 552  */
 553  
 554  function STORY_whatsRelated( $related, $uid, $tid )
 555  {
 556      global $_CONF, $_TABLES, $_USER, $LANG24;
 557  
 558      // get the links from the story text
 559      if (!empty ($related)) {
 560          $rel = explode ("\n", $related);
 561      } else {
 562          $rel = array ();
 563      }
 564  
 565      if( !empty( $_USER['username'] ) || (( $_CONF['loginrequired'] == 0 ) &&
 566             ( $_CONF['searchloginrequired'] == 0 ))) {
 567          // add a link to "search by author"
 568          if( $_CONF['contributedbyline'] == 1 )
 569          {
 570              $author = COM_getDisplayName( $uid );
 571              $rel[] = "<a href=\"{$_CONF['site_url']}/search.php?mode=search&amp;type=stories&amp;author=$uid\">{$LANG24[37]} $author</a>";
 572          }
 573  
 574          // add a link to "search by topic"
 575          $topic = DB_getItem( $_TABLES['topics'], 'topic', "tid = '$tid'" );
 576          $rel[] = '<a href="' . $_CONF['site_url']
 577                 . '/search.php?mode=search&amp;type=stories&amp;topic=' . $tid
 578                 . '">' . $LANG24[38] . ' ' . stripslashes( $topic ) . '</a>';
 579      }
 580  
 581      $related = '';
 582      if( sizeof( $rel ) > 0 )
 583      {
 584          $related = COM_checkWords( COM_makeList( $rel, 'list-whats-related' ));
 585      }
 586  
 587      return( $related );
 588  }
 589  
 590  /**
 591  * Delete one image from a story
 592  *
 593  * Deletes scaled and unscaled image, but does not update the database.
 594  *
 595  * @param    string  $image  file name of the image (without the path)
 596  *
 597  */
 598  function STORY_deleteImage ($image)
 599  {
 600      global $_CONF;
 601  
 602      if (empty ($image)) {
 603          return;
 604      }
 605  
 606      $filename = $_CONF['path_images'] . 'articles/' . $image;
 607      if (!@unlink ($filename)) {
 608          // log the problem but don't abort the script
 609          echo COM_errorLog ('Unable to remove the following image from the article: ' . $filename);
 610      }
 611  
 612      // remove unscaled image, if it exists
 613      $lFilename_large = substr_replace ($image, '_original.',
 614                                         strrpos ($image, '.'), 1);
 615      $lFilename_large_complete = $_CONF['path_images'] . 'articles/'
 616                                . $lFilename_large;
 617      if (file_exists ($lFilename_large_complete)) {
 618          if (!@unlink ($lFilename_large_complete)) {
 619              // again, log the problem but don't abort the script
 620              echo COM_errorLog ('Unable to remove the following image from the article: ' . $lFilename_large_complete);
 621          }
 622      }
 623  }
 624  
 625  /**
 626  * Delete all images from a story
 627  *
 628  * Deletes all scaled and unscaled images from the file system and the database.
 629  *
 630  * @param    string  $sid    story id
 631  *
 632  */
 633  function STORY_deleteImages ($sid)
 634  {
 635      global $_TABLES;
 636  
 637      $result = DB_query ("SELECT ai_filename FROM {$_TABLES['article_images']} WHERE ai_sid = '$sid'");
 638      $nrows = DB_numRows ($result);
 639      for ($i = 0; $i < $nrows; $i++) {
 640          $A = DB_fetchArray ($result);
 641          STORY_deleteImage ($A['ai_filename']);
 642      }
 643      DB_delete ($_TABLES['article_images'], 'ai_sid', $sid);
 644  }
 645  
 646  /**
 647  * Return information for a story
 648  *
 649  * This is the story equivalent of PLG_getItemInfo. See lib-plugins.php for
 650  * details.
 651  *
 652  * @param    string  $sid    story ID
 653  * @param    string  $what   comma-separated list of story properties
 654  * @return   mixed           string or array of strings with the information
 655  *
 656  */
 657  function STORY_getItemInfo ($sid, $what)
 658  {
 659      global $_CONF, $_TABLES;
 660  
 661      $properties = explode (',', $what);
 662      $fields = array ();
 663      foreach ($properties as $p) {
 664          switch ($p) {
 665              case 'description':
 666                  $fields[] = 'introtext';
 667                  $fields[] = 'bodytext';
 668                  break;
 669              case 'excerpt':
 670                  $fields[] = 'introtext';
 671                  break;
 672              case 'feed':
 673                  $fields[] = 'tid';
 674                  break;
 675              case 'title':
 676                  $fields[] = 'title';
 677                  break;
 678              default: // including 'url'
 679                  // nothing to do
 680                  break;
 681          }
 682      }
 683  
 684      if (count ($fields) > 0) {
 685          $result = DB_query ("SELECT " . implode (',', $fields)
 686                      . " FROM {$_TABLES['stories']} WHERE sid = '$sid'"
 687                      . COM_getPermSql ('AND') . COM_getTopicSql ('AND'));
 688          $A = DB_fetchArray ($result);
 689      } else {
 690          $A = array ();
 691      }
 692  
 693      $retval = array ();
 694      foreach ($properties as $p) {
 695          switch ($p) {
 696              case 'description':
 697                  $retval[] = trim (PLG_replaceTags (stripslashes ($A['introtext']) . ' ' . stripslashes ($A['bodytext'])));
 698                  break;
 699              case 'excerpt':
 700                  $excerpt = stripslashes ($A['introtext']);
 701                  if (!empty ($A['bodytext'])) {
 702                      $excerpt .= "\n\n" . stripslashes ($A['bodytext']);
 703                  }
 704                  $retval[] = trim (PLG_replaceTags ($excerpt));
 705                  break;
 706              case 'feed':
 707                  $feedfile = DB_getItem ($_TABLES['syndication'], 'filename',
 708                                          "topic = '::all'");
 709                  if (empty ($feedfile)) {
 710                      $feedfile = DB_getItem ($_TABLES['syndication'], 'filename',
 711                                              "topic = '{$A['tid']}'");
 712                  }
 713                  if (empty ($feedfile)) {
 714                      $retval[] = '';
 715                  } else {
 716                      $retval[] = SYND_getFeedUrl ($feedfile);
 717                  }
 718                  break;
 719              case 'title':
 720                  $retval[] = stripslashes ($A['title']);
 721                  break;
 722              case 'url':
 723                  $retval[] = COM_buildUrl ($_CONF['site_url']
 724                                            . '/article.php?story=' . $sid);
 725                  break;
 726              default:
 727                  $retval[] = ''; // return empty string for unknown properties
 728                  break;
 729          }
 730      }
 731  
 732      if (count ($retval) == 1) {
 733          $retval = $retval[0];
 734      }
 735  
 736      return $retval;
 737  }
 738  
 739  /**
 740  * This replaces all article image HTML in intro and body with
 741  * GL special syntax
 742  *
 743  * @param    string      $sid    ID for story to parse
 744  * @param    string      $intro  Intro text
 745  * @param    string      $body   Body text
 746  * @return   string      processed text
 747  *
 748  */
 749  function STORY_replace_images($sid, $intro, $body)
 750  {
 751      global $_CONF, $_TABLES, $LANG24;
 752  
 753      $stdImageLoc = true;
 754      if (!strstr($_CONF['path_images'], $_CONF['path_html'])) {
 755          $stdImageLoc = false;
 756      }
 757      $result = DB_query("SELECT ai_filename FROM {$_TABLES['article_images']} WHERE ai_sid = '$sid' ORDER BY ai_img_num");
 758      $nrows = DB_numRows($result);
 759      for ($i = 1; $i <= $nrows; $i++) {
 760          $A = DB_fetchArray($result);
 761  
 762          $imageX       = '[image' . $i . ']';
 763          $imageX_left  = '[image' . $i . '_left]';
 764          $imageX_right = '[image' . $i . '_right]';
 765  
 766          $sizeattributes = COM_getImgSizeAttributes ($_CONF['path_images'] . 'articles/' . $A['ai_filename']);
 767  
 768          $lLinkPrefix = '';
 769          $lLinkSuffix = '';
 770          if ($_CONF['keep_unscaled_image'] == 1) {
 771              $lFilename_large = substr_replace ($A['ai_filename'], '_original.',
 772                      strrpos ($A['ai_filename'], '.'), 1);
 773              $lFilename_large_complete = $_CONF['path_images'] . 'articles/'
 774                                        . $lFilename_large;
 775              if ($stdImageLoc) {
 776                  $imgpath = substr ($_CONF['path_images'],
 777                                     strlen ($_CONF['path_html']));
 778                  $lFilename_large_URL = $_CONF['site_url'] . '/' . $imgpath
 779                                       . 'articles/' . $lFilename_large;
 780              } else {
 781                  $lFilename_large_URL = $_CONF['site_url']
 782                      . '/getimage.php?mode=show&amp;image=' . $lFilename_large;
 783              }
 784              if (file_exists ($lFilename_large_complete)) {
 785                  $lLinkPrefix = '<a href="' . $lFilename_large_URL
 786                               . '" title="' . $LANG24[57] . '">';
 787                  $lLinkSuffix = '</a>';
 788              }
 789          }
 790  
 791          if ($stdImageLoc) {
 792              $imgpath = substr ($_CONF['path_images'],
 793                                 strlen ($_CONF['path_html']));
 794              $imgSrc = $_CONF['site_url'] . '/' . $imgpath . 'articles/'
 795                      . $A['ai_filename'];
 796          } else {
 797              $imgSrc = $_CONF['site_url']
 798                  . '/getimage.php?mode=articles&amp;image=' . $A['ai_filename'];
 799          }
 800          $norm = $lLinkPrefix . '<img ' . $sizeattributes . 'src="' . $imgSrc . '" alt="">' . $lLinkSuffix;
 801          $left = $lLinkPrefix . '<img ' . $sizeattributes . 'align="left" src="' . $imgSrc . '" alt="">' . $lLinkSuffix;
 802          $right = $lLinkPrefix . '<img ' . $sizeattributes . 'align="right" src="' . $imgSrc . '" alt="">' . $lLinkSuffix;
 803  
 804          $fulltext = $intro . ' ' . $body;
 805          $intro = str_replace ($norm,  $imageX,       $intro);
 806          $body  = str_replace ($norm,  $imageX,       $body);
 807          $intro = str_replace ($left,  $imageX_left,  $intro);
 808          $body  = str_replace ($left,  $imageX_left,  $body);
 809          $intro = str_replace ($right, $imageX_right, $intro);
 810          $body  = str_replace ($right, $imageX_right, $body);
 811  
 812          if (($_CONF['allow_user_scaling'] == 1) and
 813              ($_CONF['keep_unscaled_image'] == 1)){
 814  
 815              $unscaledX       = '[unscaled' . $i . ']';
 816              $unscaledX_left  = '[unscaled' . $i . '_left]';
 817              $unscaledX_right = '[unscaled' . $i . '_right]';
 818  
 819              if (file_exists ($lFilename_large_complete)) {
 820                      $sizeattributes = COM_getImgSizeAttributes($lFilename_large_complete);
 821                      $norm = '<img ' . $sizeattributes . 'src="' . $lFilename_large_URL . '" alt="">';
 822                      $left = '<img ' . $sizeattributes . 'align="left" src="' . $lFilename_large_URL . '" alt="">';
 823                      $right = '<img ' . $sizeattributes . 'align="right" src="' . $lFilename_large_URL . '" alt="">';
 824                  }
 825              $intro = str_replace ($norm,  $unscaledX,       $intro);
 826              $body  = str_replace ($norm,  $unscaledX,       $body);
 827              $intro = str_replace ($left,  $unscaledX_left,  $intro);
 828              $body  = str_replace ($left,  $unscaledX_left,  $body);
 829              $intro = str_replace ($right, $unscaledX_right, $intro);
 830              $body  = str_replace ($right, $unscaledX_right, $body);
 831          }
 832      }
 833  
 834      return array($intro, $body);
 835  }
 836  
 837  /**
 838  * Replaces simple image syntax with actual HTML in the intro and body.
 839  * If errors occur it will return all errors in $error
 840  *
 841  * @param    string      $sid    ID for story to parse
 842  * @param    string      $intro  Intro text
 843  * @param    string      $body   Body text
 844  * @param    string      $usage  'html' for normal use, 'email' for email use
 845  * @return   string      Processed text
 846  *
 847  */
 848  function STORY_insert_images($sid, $intro, $body, $usage='html')
 849  {
 850      global $_CONF, $_TABLES, $LANG24;
 851  
 852      $result = DB_query("SELECT ai_filename FROM {$_TABLES['article_images']} WHERE ai_sid = '$sid' ORDER BY ai_img_num");
 853      $nrows = DB_numRows($result);
 854      $errors = array();
 855      $stdImageLoc = true;
 856      if (!strstr($_CONF['path_images'], $_CONF['path_html'])) {
 857          $stdImageLoc = false;
 858      }
 859      for ($i = 1; $i <= $nrows; $i++) {
 860          $A = DB_fetchArray($result);
 861  
 862          $lLinkPrefix = '';
 863          $lLinkSuffix = '';
 864          if ($_CONF['keep_unscaled_image'] == 1) {
 865              $lFilename_large = substr_replace ($A['ai_filename'], '_original.',
 866                      strrpos ($A['ai_filename'], '.'), 1);
 867              $lFilename_large_complete = $_CONF['path_images'] . 'articles/'
 868                                        . $lFilename_large;
 869              if ($stdImageLoc) {
 870                  $imgpath = substr ($_CONF['path_images'],
 871                                     strlen ($_CONF['path_html']));
 872                  $lFilename_large_URL = $_CONF['site_url'] . '/' . $imgpath
 873                                       . 'articles/' . $lFilename_large;
 874              } else {
 875                  $lFilename_large_URL = $_CONF['site_url']
 876                      . '/getimage.php?mode=show&amp;image=' . $lFilename_large;
 877              }
 878              if (file_exists ($lFilename_large_complete)) {
 879                  $lLinkPrefix = '<a href="' . $lFilename_large_URL
 880                               . '" title="' . $LANG24[57] . '">';
 881                  $lLinkSuffix = '</a>';
 882              }
 883          }
 884  
 885          $sizeattributes = COM_getImgSizeAttributes ($_CONF['path_images'] . 'articles/' . $A['ai_filename']);
 886  
 887          $norm  = '[image' . $i . ']';
 888          $left  = '[image' . $i . '_left]';
 889          $right = '[image' . $i . '_right]';
 890  
 891          $unscalednorm  = '[unscaled' . $i . ']';
 892          $unscaledleft  = '[unscaled' . $i . '_left]';
 893          $unscaledright = '[unscaled' . $i . '_right]';
 894  
 895          $fulltext = $intro . ' ' . $body;
 896          $icount = substr_count($fulltext, $norm) + substr_count($fulltext, $left) + substr_count($fulltext, $right);
 897          $icount = $icount + substr_count($fulltext, $unscalednorm) + substr_count($fulltext, $unscaledleft) + substr_count($fulltext, $unscaledright);
 898          if ($icount == 0) {
 899              // There is an image that wasn't used, create an error
 900              $errors[] = $LANG24[48] . " #$i, {$A['ai_filename']}, " . $LANG24[53];
 901          } else {
 902              // Only parse if we haven't encountered any error to this point
 903              if (count($errors) == 0) {
 904                  if ($usage=='email') {  // image will be attached, no path necessary
 905                      $imgSrc = $A['ai_filename'];
 906                  } elseif ($stdImageLoc) {
 907                      $imgpath = substr ($_CONF['path_images'],
 908                                         strlen ($_CONF['path_html']));
 909                      $imgSrc = $_CONF['site_url'] . '/' . $imgpath . 'articles/'
 910                              . $A['ai_filename'];
 911                  } else {
 912                      $imgSrc = $_CONF['site_url'] . '/getimage.php?mode=articles&amp;image=' . $A['ai_filename'];
 913                  }
 914                  $intro = str_replace($norm, $lLinkPrefix . '<img ' . $sizeattributes . 'src="' . $imgSrc . '" alt="">' . $lLinkSuffix, $intro);
 915                  $body = str_replace($norm, $lLinkPrefix . '<img ' . $sizeattributes . 'src="' . $imgSrc . '" alt="">' . $lLinkSuffix, $body);
 916                  $intro = str_replace($left, $lLinkPrefix . '<img ' . $sizeattributes . 'align="left" src="' . $imgSrc . '" alt="">' . $lLinkSuffix, $intro);
 917                  $body = str_replace($left, $lLinkPrefix . '<img ' . $sizeattributes . 'align="left" src="' . $imgSrc . '" alt="">' . $lLinkSuffix, $body);
 918                  $intro = str_replace($right, $lLinkPrefix . '<img ' . $sizeattributes . 'align="right" src="' . $imgSrc . '" alt="">' . $lLinkSuffix, $intro);
 919                  $body = str_replace($right, $lLinkPrefix . '<img ' . $sizeattributes . 'align="right" src="' . $imgSrc . '" alt="">' . $lLinkSuffix, $body);
 920  
 921                  if (($_CONF['allow_user_scaling'] == 1) and
 922                      ($_CONF['keep_unscaled_image'] == 1)) {
 923  
 924                      if (file_exists ($lFilename_large_complete)) {
 925                          $imgSrc = $lFilename_large_URL;
 926                          $sizeattributes = COM_getImgSizeAttributes ($lFilename_large_complete);
 927                      }
 928                      $intro = str_replace($unscalednorm, '<img ' . $sizeattributes . 'src="' . $imgSrc . '" alt="">', $intro);
 929                      $body = str_replace($unscalednorm, '<img ' . $sizeattributes . 'src="' . $imgSrc . '" alt="">', $body);
 930                      $intro = str_replace($unscaledleft, '<img ' . $sizeattributes . 'align="left" src="' . $imgSrc . '" alt="">', $intro);
 931                      $body = str_replace($unscaledleft, '<img ' . $sizeattributes . 'align="left" src="' . $imgSrc . '" alt="">', $body);
 932                      $intro = str_replace($unscaledright, '<img ' . $sizeattributes . 'align="right" src="' . $imgSrc . '" alt="">', $intro);
 933                      $body = str_replace($unscaledright, '<img ' . $sizeattributes . 'align="right" src="' . $imgSrc . '" alt="">', $body);
 934                  }
 935  
 936              }
 937          }
 938      }
 939  
 940      return array($errors, $intro, $body);
 941  }
 942  
 943  /**
 944  * Delete a story.
 945  *
 946  * This is used to delete a story from the list of stories with the 'draft' flag
 947  * set (see function draftlist() above).
 948  *
 949  * @sid      string      ID of the story to delete
 950  *
 951  */
 952  function STORY_deleteStory($sid)
 953  {
 954      global $_CONF, $_TABLES, $_USER;
 955  
 956      $result = DB_query ("SELECT tid,owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon FROM {$_TABLES['stories']} WHERE sid = '$sid'");
 957      $A = DB_fetchArray ($result);
 958      $access = SEC_hasAccess ($A['owner_id'], $A['group_id'], $A['perm_owner'],
 959              $A['perm_group'], $A['perm_members'], $A['perm_anon']);
 960      $access = min ($access, SEC_hasTopicAccess ($A['tid']));
 961      if ($access < 3) {
 962          COM_accessLog ("User {$_USER['username']} tried to illegally delete story $sid.");
 963          return COM_refresh ($_CONF['site_admin_url'] . '/story.php');
 964      }
 965  
 966      STORY_deleteImages ($sid);
 967      DB_query("DELETE FROM {$_TABLES['comments']} WHERE sid = '$sid' AND type = 'article'");
 968      DB_delete ($_TABLES['stories'], 'sid', $sid);
 969  
 970      // delete Trackbacks
 971      DB_query ("DELETE FROM {$_TABLES['trackback']} WHERE sid = '$sid' AND type = 'article';");
 972  
 973      // update RSS feed and Older Stories block
 974      COM_rdfUpToDateCheck ();
 975      COM_olderStuff ();
 976  
 977      return COM_refresh ($_CONF['site_admin_url'] . '/story.php?msg=10');
 978  }
 979  
 980  
 981  ?>


Généré le : Wed Nov 21 12:27:40 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics