4images PHP Cross Reference Image Galleries

Source: /rss.php - 366 lines - 13533 bytes - Summary - Text - Print

   1  <?php
   2  /**************************************************************************
   3   *                                                                        *
   4   *    4images - A Web Based Image Gallery Management System               *
   5   *    ----------------------------------------------------------------    *
   6   *                                                                        *
   7   *             File: rss.php                                              *
   8   *        Copyright: (C) 2002-2012 Jan Sorgalla                           *
   9   *            Email: jan@4homepages.de                                    *
  10   *              Web: http://www.4homepages.de                             *
  11   *    Scriptversion: 1.7.11                                               *
  12   *                                                                        *
  13   *    Never released without support from: Nicky (http://www.nicky.net)   *
  14   *                                                                        *
  15   **************************************************************************
  16   *                                                                        *
  17   *    Dieses Script ist KEINE Freeware. Bitte lesen Sie die Lizenz-       *
  18   *    bedingungen (Lizenz.txt) für weitere Informationen.                 *
  19   *    ---------------------------------------------------------------     *
  20   *    This script is NOT freeware! Please read the Copyright Notice       *
  21   *    (Licence.txt) for further information.                              *
  22   *                                                                        *
  23   *************************************************************************/
  24  
  25  $main_template = 'rss';
  26  
  27  $nozip = 1;
  28  define('GET_CACHES', 1);
  29  define('ROOT_PATH', './');
  30  include (ROOT_PATH.'global.php');
  31  require (ROOT_PATH.'includes/sessions.php');
  32  $user_access = get_permission();
  33  include (ROOT_PATH.'includes/page_header.php');
  34  
  35  $site_template->template_extension = 'xml';
  36  
  37  @define('RSS_DEFAULT_ITEMS', 10);
  38  @define('RSS_MAX_ITEMS', 30);
  39  
  40  if (isset($HTTP_GET_VARS['items']) || isset($HTTP_POST_VARS['items'])) {
  41    $num_items = (isset($HTTP_POST_VARS['items'])) ? intval($HTTP_POST_VARS['items']) : intval($HTTP_GET_VARS['items']);
  42    if (!$num_items) {
  43      $num_items = RSS_DEFAULT_ITEMS;
  44    }
  45  
  46    if ($num_items > RSS_MAX_ITEMS) {
  47      $num_items = RSS_MAX_ITEMS;
  48    }
  49  }
  50  else {
  51    $num_items = RSS_DEFAULT_ITEMS;
  52  }
  53  
  54  if ($action == '') {
  55    $action = 'images';
  56  }
  57  
  58  function cut_at_word($text, $length, $suffix = '...') {
  59    if (strlen($text) <= $length) {
  60      return $text;
  61    }
  62  
  63    $delims = array(' ', '.', ',', '!', '?', '-', ':', '_', '/');
  64    $text = substr($text, 0, $length + 1);
  65  
  66    $positions = array();
  67  
  68    for ($i = 0; isset($delims[$i]); $i++) {
  69      $pos = strrpos($text, $delims[$i]);
  70      if ($pos) {
  71        $positions[] = $pos;
  72      }
  73    }
  74  
  75    if (sizeof($positions) > 0) {
  76      rsort($positions);
  77      $text = substr($text, 0, $positions[0]);
  78    }
  79  
  80    $text .= $suffix;
  81  
  82    return $text;
  83  }
  84  
  85  function format_rss_text($text) {
  86    $text = format_text(trim($text), 1, 0, 1);
  87    $text = strip_tags($text);
  88    $text = safe_htmlspecialchars($text);
  89  
  90    $text = cut_at_word($text, 250);
  91  
  92    return $text;
  93  }
  94  
  95  function format_rss_html($text) {
  96    $text = format_text(trim($text), 2, 0, 1);
  97  
  98    return $text;
  99  }
 100  
 101  function get_file_url($file_name, $image_type, $cat_id)
 102  {
 103      $url = get_file_path($file_name, $image_type, $cat_id, 0, 1);
 104  
 105      if (!is_remote($file_name)) {
 106          global $script_url;
 107          $url = $script_url.'/'.$url;
 108      }
 109  
 110      return str_replace('./', '', $url);
 111  }
 112  
 113  function get_rss_enclosure($file_name, $image_type, $cat_id) {
 114    if (!get_file_path($file_name, $image_type, $cat_id, 0, 0)) {
 115      return array();
 116    }
 117  
 118    $file = get_file_path($file_name, $image_type, $cat_id, 0, 1);
 119    $url = get_file_url($file_name, $image_type, $cat_id);
 120  
 121    return array(
 122      'url' => $url,
 123      'length' => @filesize($file),
 124      'type' => get_mime_content_type($file)
 125    );
 126  }
 127  
 128  $cache_id = create_cache_id(
 129    'page.rss',
 130    array(
 131      $user_info[$user_table_fields['user_id']],
 132      $action,
 133      $image_id,
 134      $cat_id,
 135      $num_items
 136    )
 137  );
 138  
 139  if (!$cache_page_rss || !$content = get_cache_file($cache_id)) {
 140    $old_session_mode = $site_sess->mode;
 141    $site_sess->mode = 'cookie';
 142  
 143  ob_start();
 144  
 145  $rss_title = format_rss_text($config['site_name']);
 146  $rss_link  = $site_sess->url($script_url);
 147  $rss_desc  = format_rss_text($config['site_name']);
 148  $rss_lang  = "";
 149  $rss_image = array();
 150  $rss_ttl   = $cache_page_rss ? $cache_lifetime : 0;
 151  $rss_cat   = array();
 152  $rss_items = array();
 153  
 154  switch ($action) {
 155    case 'comments':
 156      if (!$image_id) {
 157        exit;
 158      }
 159  
 160      $sql = "SELECT i.image_id, i.cat_id, i.user_id, i.image_name, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits, c.cat_name".get_user_table_field(", u.", "user_name").get_user_table_field(", u.", "user_email")."
 161              FROM (".IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c)
 162              LEFT JOIN ".USERS_TABLE." u ON (".get_user_table_field("u.", "user_id")." = i.user_id)
 163              WHERE i.image_id = $image_id AND c.cat_id = i.cat_id";
 164      $image_row = $site_db->query_firstrow($sql);
 165  
 166      if (!isset($image_row['image_id'])) {
 167        exit;
 168      }
 169  
 170      $cat_id = (isset($image_row['cat_id'])) ? $image_row['cat_id'] : 0;
 171  
 172      $rss_title .= " - " . format_rss_text($image_row['image_name']);
 173      $rss_link  = $site_sess->url($script_url."/details.php?".URL_IMAGE_ID."=".$image_id);
 174      $rss_desc  = format_rss_html($image_row['image_description']);
 175      if (get_file_path($image_row['image_thumb_file'], "thumb", $cat_id, 0, 0)) {
 176        $rss_image = array(
 177          'url' => get_file_url($image_row['image_thumb_file'], "thumb", $cat_id),
 178          'title' => format_rss_text($image_row['image_name']),
 179          'link' => $rss_link
 180        );
 181      }
 182  
 183      $rss_cat = array(
 184        'name' => format_rss_text($cat_cache[$cat_id]['cat_name']),
 185        'domain' => $site_sess->url($script_url."/categories.php?".URL_CAT_ID."=".$cat_id)
 186      );
 187  
 188      $image_allow_comments = (check_permission("auth_readcomment", $cat_id)) ? $image_row['image_allow_comments'] : 0;
 189  
 190      $sql = "SELECT c.comment_id, c.image_id, c.user_id, c.user_name AS comment_user_name, c.comment_headline, c.comment_text, c.comment_ip, c.comment_date".get_user_table_field(", u.", "user_level").get_user_table_field(", u.", "user_name").get_user_table_field(", u.", "user_email").get_user_table_field(", u.", "user_showemail").get_user_table_field(", u.", "user_invisible").get_user_table_field(", u.", "user_joindate").get_user_table_field(", u.", "user_lastaction").get_user_table_field(", u.", "user_comments").get_user_table_field(", u.", "user_homepage").get_user_table_field(", u.", "user_icq")."
 191              FROM ".COMMENTS_TABLE." c
 192              LEFT JOIN ".USERS_TABLE." u ON (".get_user_table_field("u.", "user_id")." = c.user_id)
 193              WHERE c.image_id = $image_id
 194              ORDER BY c.comment_date DESC
 195              LIMIT $num_items";
 196      $result = $site_db->query($sql);
 197  
 198      while ($row = $site_db->fetch_array($result)) {
 199        $user_name = format_rss_text($row['comment_user_name']);
 200        $user_email = "example@example.com";
 201  
 202        if (isset($row[$user_table_fields['user_name']]) && $row['user_id'] != GUEST) {
 203          $user_name = format_rss_text($row[$user_table_fields['user_name']]);
 204          if (!empty($row[$user_table_fields['user_email']]) && (!isset($row[$user_table_fields['user_showemail']]) || (isset($row[$user_table_fields['user_showemail']]) && $row[$user_table_fields['user_showemail']] == 1))) {
 205            $user_email = $row[$user_table_fields['user_email']];
 206          }
 207        }
 208  
 209        $rss_items[] = array(
 210          'title' => format_rss_text($row['comment_headline']),
 211          'link' => $site_sess->url($script_url."/details.php?".URL_IMAGE_ID."=".$image_id."#comment".$row['comment_id']),
 212          'pubDate' => $row['comment_date'],
 213          'desc' => format_rss_text($row['comment_text']),
 214          'category' => array(
 215            'name' => $rss_title,
 216            'domain' => $rss_link
 217          ),
 218          'author' => array(
 219            'name' => $user_name,
 220            'email' => $user_email
 221          ),
 222        );
 223      }
 224      break;
 225  
 226    case 'images':
 227    default:
 228      $cat_sql = "";
 229      if ($cat_id && isset($cat_cache[$cat_id])) {
 230        $rss_title .= " - " . format_rss_text($cat_cache[$cat_id]['cat_name']);
 231        $rss_link  = $site_sess->url($script_url."/categories.php?".URL_CAT_ID."=".$cat_id);
 232        $rss_desc  = format_rss_html($cat_cache[$cat_id]['cat_description']);
 233  
 234        $cat_sql = "AND i.cat_id = $cat_id";
 235      }
 236  
 237      $sql = "SELECT i.image_id, i.cat_id, i.user_id, i.image_name, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits, c.cat_name".get_user_table_field(", u.", "user_name")."
 238              FROM (".IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c)
 239              LEFT JOIN ".USERS_TABLE." u ON (".get_user_table_field("u.", "user_id")." = i.user_id)
 240              WHERE i.image_active = 1
 241                $cat_sql
 242                AND c.cat_id = i.cat_id
 243                AND i.cat_id NOT IN (".get_auth_cat_sql("auth_viewcat", "NOTIN").")
 244              ORDER BY i.image_date DESC, i.image_id DESC
 245              LIMIT $num_items";
 246      $result = $site_db->query($sql);
 247  
 248      while ($row = $site_db->fetch_array($result)) {
 249        $user_name = format_rss_text($lang['userlevel_guest']);
 250        $user_email = "example@example.com";
 251  
 252        if (isset($row[$user_table_fields['user_name']]) && $row['user_id'] != GUEST) {
 253          $user_name = format_rss_text($row[$user_table_fields['user_name']]);
 254          if (!empty($row[$user_table_fields['user_email']]) && (!isset($row[$user_table_fields['user_showemail']]) || (isset($row[$user_table_fields['user_showemail']]) && $row[$user_table_fields['user_showemail']] == 1))) {
 255            $user_email = $row[$user_table_fields['user_email']];
 256          }
 257        }
 258  
 259        $rss_items[] = array(
 260          'title' => format_rss_text($row['image_name']),
 261          'link' => $site_sess->url($script_url."/details.php?".URL_IMAGE_ID."=".$row['image_id']),
 262          'pubDate' => $row['image_date'],
 263          'desc' => format_rss_html($row['image_description']),
 264          'category' => array(
 265            'name' => format_rss_text($cat_cache[$row['cat_id']]['cat_name']),
 266            'domain' => $site_sess->url($script_url."/categories.php?".URL_CAT_ID."=".$row['cat_id'])
 267          ),
 268          'enclosure' => get_rss_enclosure($row['image_thumb_file'], "thumb", $row['cat_id']),
 269          'author' => array(
 270            'name' => $user_name,
 271            'email' => $user_email
 272          ),
 273          'comments' => $site_sess->url($script_url."/details.php?".URL_IMAGE_ID."=".$row['image_id']."#comments"),
 274        );
 275      }
 276      break;
 277  }
 278  
 279  $items = '';
 280  
 281  foreach ($rss_items as $item) {
 282    $tpl_vars = array(
 283      'item_title' => $item['title'],
 284      'item_link' => $item['link'],
 285      'item_pubdate' => gmdate('D, d M Y H:i:s', $item['pubDate']) . " GMT",
 286      'item_description' => $item['desc'],
 287      'item_category' => false,
 288      'item_category_domain' => '',
 289      'item_category_name' => '',
 290      'item_author' => false,
 291      'item_author_email' => '',
 292      'item_author_name' => '',
 293      'item_enclosure' => false,
 294      'item_enclosure_url' => '',
 295      'item_enclosure_length' => '',
 296      'item_enclosure_type' => '',
 297    );
 298  
 299    if (@count($item['category']) > 0) {
 300      $tpl_vars['item_category'] = true;
 301      $tpl_vars['item_category_domain'] = $item['category']['domain'];
 302      $tpl_vars['item_category_name'] = $item['category']['name'];
 303    }
 304  
 305    if (@count($item['author']) > 0) {
 306      $tpl_vars['item_author'] = true;
 307      $tpl_vars['item_author_email'] = $item['author']['email'];
 308      $tpl_vars['item_author_name'] = $item['author']['name'];
 309    }
 310  
 311    if (@count($item['enclosure']) > 0) {
 312      $tpl_vars['item_enclosure'] = true;
 313      $tpl_vars['item_enclosure_url'] = $item['enclosure']['url'];
 314      $tpl_vars['item_enclosure_length'] = $item['enclosure']['length'];
 315      $tpl_vars['item_enclosure_type'] = $item['enclosure']['type'];
 316    }
 317  
 318    $site_template->register_vars($tpl_vars);
 319    $items .= $site_template->parse_template("rss_item");
 320  }
 321  
 322  $tpl_vars = array(
 323    'channel_title' => $rss_title,
 324    'channel_link' => $rss_link,
 325    'channel_pubdate' => gmdate('D, d M Y H:i:s') . " GMT",
 326    'channel_description' => $rss_desc,
 327    'channel_image' => false,
 328    'channel_image_url' => '',
 329    'channel_image_title' => '',
 330    'channel_image_link' => '',
 331    'channel_ttl' => $rss_ttl,
 332    'items' => $items
 333  );
 334  
 335  if (count($rss_image) > 0) {
 336    $tpl_vars['channel_image'] = true;
 337    $tpl_vars['channel_image_url'] = $rss_image['url'];
 338    $tpl_vars['channel_image_title'] = $rss_image['title'];
 339    $tpl_vars['channel_image_link'] = $rss_image['link'];
 340  }
 341  
 342  $site_template->register_vars($tpl_vars);
 343  
 344  $site_template->print_template($site_template->parse_template($main_template));
 345  
 346  $content = ob_get_contents();
 347  ob_end_clean();
 348  
 349  // Reset session mode
 350  $site_sess->mode = $old_session_mode;
 351  
 352  if ($cache_page_rss) {
 353    save_cache_file($cache_id, $content, true);
 354  }
 355  
 356  } // end if get_cache_file()
 357  
 358  header('Content-Type: text/xml');
 359  header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
 360  header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
 361  header('Pragma: public');
 362  
 363  echo $content;
 364  
 365  
 366  ?>

title

Description

title

Description

title

Description

title

title

Body