[ Index ]

PHP Cross Reference of MyBB 1.8.12

title

Body

[close]

/ -> syndication.php (source)

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


2005 - 2016 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref 0.7.1