| [ Index ] |
PHP Cross Reference of MyBB 1.6.7 |
[Summary view] [Print] [Text view]
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: syndication.php 5297 2010-12-28 22:01:14Z Tomm $ 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, allowvideocode", "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 = $lang->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 $permsql = ""; 115 $onlyusfids = array(); 116 117 // Check group permissions if we can't view threads not started by us 118 $group_permissions = forum_permissions(); 119 foreach($group_permissions as $fid => $forum_permissions) 120 { 121 if($forum_permissions['canonlyviewownthreads'] == 1) 122 { 123 $onlyusfids[] = $fid; 124 } 125 } 126 if(!empty($onlyusfids)) 127 { 128 $permsql .= "AND (fid IN(".implode(',', $onlyusfids).") AND uid='{$mybb->user['uid']}')"; 129 } 130 131 // Get the threads to syndicate. 132 $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)); 133 // Loop through all the threads. 134 while($thread = $db->fetch_array($query)) 135 { 136 $items[$thread['tid']] = array( 137 "title" => $thread['subject'], 138 "link" => $channel['link'].get_thread_link($thread['tid']), 139 "date" => $thread['dateline'], 140 ); 141 142 $firstposts[] = $thread['firstpost']; 143 } 144 145 if(!empty($firstposts)) 146 { 147 $firstpostlist = "pid IN(".$db->escape_string(implode(',', $firstposts)).")"; 148 $query = $db->simple_select("posts", "message, edittime, tid, fid, pid", $firstpostlist, array('order_by' => 'dateline', 'order_dir' => 'desc')); 149 while($post = $db->fetch_array($query)) 150 { 151 $parser_options = array( 152 "allow_html" => $forumcache[$post['fid']]['allowhtml'], 153 "allow_mycode" => $forumcache[$post['fid']]['allowmycode'], 154 "allow_smilies" => $forumcache[$post['fid']]['allowsmilies'], 155 "allow_imgcode" => $forumcache[$post['fid']]['allowimgcode'], 156 "allow_videocode" => $forumcache[$post['fid']]['allowvideocode'], 157 "filter_badwords" => 1 158 ); 159 160 $parsed_message = $parser->parse_message($post['message'], $parser_options); 161 162 $query2 = $db->simple_select("attachments", "*", "pid=".$post['pid']); 163 while($attachment = $db->fetch_array($query2)) 164 { 165 $ext = get_extension($attachment['filename']); 166 $attachment['filename'] = htmlspecialchars_uni($attachment['filename']); 167 $attachment['filesize'] = get_friendly_size($attachment['filesize']); 168 $attachment['icon'] = get_attachment_icon($ext); 169 eval("\$attbit = \"".$templates->get("postbit_attachments_attachment")."\";"); 170 if(stripos($parsed_message, "[attachment=".$attachment['aid']."]") !== false) 171 { 172 $parsed_message = preg_replace("#\[attachment=".$attachment['aid']."]#si", $attbit, $parsed_message); 173 } 174 else 175 { 176 $parsed_message .= "<br />".$attbit; 177 } 178 } 179 180 $items[$post['tid']]['description'] = $parsed_message; 181 $items[$post['tid']]['updated'] = $post['edittime']; 182 $feedgenerator->add_item($items[$post['tid']]); 183 } 184 } 185 186 // Then output the feed XML. 187 $feedgenerator->output_feed(); 188 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat Mar 31 17:55:03 2012 | Cross-referenced by PHPXref 0.7.1 |