[ Index ]

PHP Cross Reference of MyBB 1.4.13

title

Body

[close]

/ -> syndication.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.4
   4   * Copyright © 2008 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://www.mybboard.net
   7   * License: http://www.mybboard.net/about/license
   8   *
   9   * $Id: syndication.php 4847 2010-03-30 01:41:16Z RyanGordon $
  10   */
  11  
  12  define("IN_MYBB", 1);
  13  define("IGNORE_CLEAN_VARS", "fid");
  14  define("NO_ONLINE", 1);
  15  define('THIS_SCRIPT', 'syndication.php');
  16  
  17  require_once  "./global.php";
  18  
  19  // Load global language phrases
  20  $lang->load("syndication");
  21  
  22  // Load syndication class.
  23  require_once  MYBB_ROOT."inc/class_feedgeneration.php";
  24  $feedgenerator = new FeedGenerator();
  25  
  26  // Load the post parser
  27  require_once  MYBB_ROOT."inc/class_parser.php";
  28  $parser = new postParser;
  29  
  30  // Find out the thread limit.
  31  $thread_limit = intval($mybb->input['limit']);
  32  if($thread_limit > 50)
  33  {
  34      $thread_limit = 50;
  35  }
  36  else if(!$thread_limit || $thread_limit < 0)
  37  {
  38      $thread_limit = 20;
  39  }
  40  
  41  // Syndicate a specific forum or all viewable?
  42  if(isset($mybb->input['fid']))
  43  {
  44      $forumlist = $mybb->input['fid'];
  45      $forumlist = explode(',', $forumlist);
  46  }
  47  else
  48  {
  49      $forumlist = "";
  50  }
  51  
  52  // Get the forums the user is not allowed to see.
  53  $unviewableforums = get_unviewable_forums(true);
  54  $inactiveforums = get_inactive_forums();
  55  
  56  $unviewable = '';
  57  
  58  // If there are any, add SQL to exclude them.
  59  if($unviewableforums)
  60  {
  61      $unviewable .= " AND fid NOT IN($unviewableforums)";
  62  }
  63  
  64  if($inactiveforums)
  65  {
  66      $unviewable .= " AND fid NOT IN($inactiveforums)";
  67  }
  68  
  69  // If there are no forums to syndicate, syndicate all viewable.
  70  if(!empty($forumlist))
  71  {
  72      $forum_ids = "'-1'";
  73      foreach($forumlist as $fid)
  74      {
  75          $forum_ids .= ",'".intval($fid)."'";
  76      }
  77      $forumlist = "AND fid IN ($forum_ids) $unviewable";
  78  }
  79  else
  80  {
  81      $forumlist = $unviewable;
  82      $all_forums = 1;
  83  }
  84  
  85  // Find out which title to add to the feed.
  86  $title = $mybb->settings['bbname'];
  87  $query = $db->simple_select("forums", "name, fid, allowhtml, allowmycode, allowsmilies, allowimgcode", "1=1 ".$forumlist);
  88  $comma = " - ";
  89  while($forum = $db->fetch_array($query))
  90  {
  91      $title .= $comma.$forum['name'];
  92      $forumcache[$forum['fid']] = $forum;
  93      $comma = ", ";
  94  }
  95  
  96  // If syndicating all forums then cut the title back to "All Forums"
  97  if($all_forums)
  98  {
  99      $title = $mybb->settings['bbname']." - ".$lang->all_forums;
 100  }
 101  
 102  // Set the feed type.
 103  $feedgenerator->set_feed_format($mybb->input['type']);
 104  
 105  // Set the channel header.
 106  $channel = array(
 107      "title" => $title,
 108      "link" => $mybb->settings['bburl']."/",
 109      "date" => time(),
 110      "description" => $mybb->settings['bbname']." - ".$mybb->settings['bburl']
 111  );
 112  $feedgenerator->set_channel($channel);
 113  
 114  // Get the threads to syndicate.
 115  $query = $db->simple_select("threads", "subject, tid, dateline, firstpost", "visible='1' AND closed NOT LIKE 'moved|%' ".$forumlist, array('order_by' => 'dateline', 'order_dir' => 'DESC', 'limit' => $thread_limit));
 116  // Loop through all the threads.
 117  while($thread = $db->fetch_array($query))
 118  {
 119      $items[$thread['tid']] = array(
 120          "title" => $thread['subject'],
 121          "link" => $channel['link'].get_thread_link($thread['tid']),        
 122          "date" => $thread['dateline'],
 123      );
 124      
 125      $firstposts[] = $thread['firstpost'];
 126  }
 127  
 128  if(!empty($firstposts))
 129  {
 130      $firstpostlist = "pid IN(".$db->escape_string(implode(',', $firstposts)).")";
 131      $query = $db->simple_select("posts", "message, edittime, tid, fid, pid", $firstpostlist, array('order_by' => 'dateline', 'order_dir' => 'desc'));    
 132      while($post = $db->fetch_array($query))
 133      {        
 134          $parser_options = array(
 135              "allow_html" => $forumcache[$post['fid']]['allowhtml'],
 136              "allow_mycode" => $forumcache[$post['fid']]['allowmycode'],
 137              "allow_smilies" => $forumcache[$post['fid']]['allowsmilies'],
 138              "allow_imgcode" => $forumcache[$post['fid']]['allowimgcode'],
 139              "filter_badwords" => 1
 140          );
 141          
 142          $parsed_message = $parser->parse_message($post['message'], $parser_options);
 143  
 144          $query2 = $db->simple_select("attachments", "*", "pid=".$post['pid']);
 145          while($attachment = $db->fetch_array($query2))
 146          {
 147              $ext = get_extension($attachment['filename']);
 148              $attachment['icon'] = get_attachment_icon($ext);
 149              if($ext == "jpeg" || $ext == "gif" || $ext == "bmp" || $ext == "png" || $ext == "jpg")
 150              {
 151                  if(stripos($parsed_message, "[attachment=".$attachment['aid']."]") !== false)
 152                  {
 153                      eval("\$attbit = \"".$templates->get("postbit_attachments_thumbnails_thumbnail")."\";");
 154                      
 155                      $parsed_message = preg_replace("#\[attachment=".$attachment['aid']."]#si", $attbit, $parsed_message);
 156                  }
 157              }
 158              else
 159              {
 160                  if(stripos($parsed_message, "[attachment=".$attachment['aid']."]") !== false)
 161                  {
 162                      eval("\$attbit = \"".$templates->get("postbit_attachments_attachment")."\";");
 163                      
 164                      $parsed_message = preg_replace("#\[attachment=".$attachment['aid']."]#si", $attbit, $parsed_message);
 165                  }
 166              }    
 167          }
 168          
 169          $items[$post['tid']]['description'] = $parsed_message;
 170          $items[$post['tid']]['updated'] = $post['edittime'];
 171          $feedgenerator->add_item($items[$post['tid']]);
 172      }
 173  }
 174  
 175  // Then output the feed XML.
 176  $feedgenerator->output_feed();
 177  ?>


Generated: Mon Apr 19 19:52:21 2010 Cross-referenced by PHPXref 0.7