[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

/ -> syndication.php (source)

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


Generated: Tue Oct 8 19:19:50 2013 Cross-referenced by PHPXref 0.7.1