Специалист
Join Date: Jun 2007
Location: Одинцово Московская область
Награды в конкурсах:
Posts: 610
Версия vB: 3.8.4
Reputation:
Professional 629
Репутация в разделе: 495
|
Интеграция с Subdreamer - нужен хак.
0
В принципе, Subdreamer очень неплохо интегрируется с VB, но, по понятным причинам, интеграция эта однонаправленная - Subdreamer способен вытаскивать новости из Vbulletin, но не наоборот.
Что нужно - возможность вставить в HEADER заголовки (и ссылки, естественно) последних 10 статей, написанных в Subdreamer
Как реализовать - в Subdreamer есть плагин p3_latestnews, который как раз делает именно то, что нужно - выдает список последних 10 новостей.
Кто-нибудь сможет адаптировать?
PHP Code:
<?php
if(!defined('IN_SUBDREAMER')) die('Hacking attempt!');
// ################################ LATEST NEWS ################################
function p3_LatestNews() { global $DB, $categoryid, $sdurl;
$p2_articlebitfield = array('useglobalsettings' => 1, 'displayonline' => 2, 'displaytitle' => 4, 'displayauthor' => 8, 'displaycreateddate' => 16, 'displayupdateddate' => 32, 'displayprintarticlelink' => 64, 'displayemailarticlelink' => 128, 'displaydescription' => 256, 'displaysmilies' => 512, 'displaycomments' => 1024, 'displayviews' => 2048, 'displaymainpage' => 4096, 'displaysticky' => 8192);
$language = GetLanguage(3);
// get latest news settings $settings = GetPluginSettings(3); $p2_settings = GetPluginSettings(2, 'Article Display Settings');
$limit = $settings['Limit']; // how many news articles to display (default 10) $targeting = $settings['Category Targeting']; // only display news from the current category (default no)? $includeids = $settings['Include Categories']; // the ID of the categories you want to include (only works if targeting is set to off) $matchingids = $settings['Matching Categories']; // combined with $includeids if this field has values. // if the value in $includeids is '1 3' and the matchingids is '2 6', then in category 1 (homepage) the latest news from category 2 will be displayed. // and if the plugin is placed in category 3, then latest news from category 6 will be displayed. $sorting = $settings['Sorting']; // sort by author, title, newest first, oldest first etc (see the news plugin) $showcategoryname = $settings['Display Category Name']; // display categoryname to the right of each news article (default no)? $showdescription = $settings['Display Description']; // display description (default no)? //$descriptionlimit = $settings['Description Limit']; // decide how many characters to display from description (0 = disabled) $showauthor = $settings['Display Author']; // display authorname (default no)? $showdate = $settings['Display Creation Date']; // display creation date (default no)? $showupdatedate = $settings['Display Updated Date']; // display update date (default no)? $showprintlink = $settings['Display Print Article Option']; // display print link for each news article in the list (default no)? $showemaillink = $settings['Display Email Article Option']; // display email link for each news article in the list (default no)? $showreadmore = $settings['Read More']; // display read more link (default no) $boldtitle = $settings['Bold Title']; // convert news title to link (default yes)? $titletolink = $settings['Title Link']; // convert news title to link (default yes)? $grouping = $settings['Grouping']; // group the news article list by category, date, author or nothing (default nothing)? $categorytolink = $settings['Category Link']; // convert category name to link (default yes)? $groupseparator = $settings['Group Separator']; // separator between each group, will not work if grouping is set to "nothing" $grouparticleseparator = $settings['Group/Article Separator']; // separator between the group header and the news articles, will only work if grouping is used $articleseparator = $settings['News Article Separator']; // separator between each news article
// create global settings $globalsettings = 0; $globalsettings += $p2_settings['Display Title'] == 1 ? 4 : 0; $globalsettings += $p2_settings['Display Author'] == 1 ? 8 : 0; $globalsettings += $p2_settings['Display Creation Date'] == 1 ? 16 : 0; $globalsettings += $p2_settings['Display Updated Date'] == 1 ? 32 : 0; $globalsettings += $p2_settings['Display Print Article Link'] == 1 ? 64 : 0; $globalsettings += $p2_settings['Display Email Article Link'] == 1 ? 128 : 0; $globalsettings += $p2_settings['Display Description Inside Article'] == 1 ? 256 : 0; $globalsettings += $p2_settings['Display Smilie Images'] == 1 ? 512 : 0; $globalsettings += $p2_settings['Display User Comments'] == 1 ? 1024 : 0; $globalsettings += $p2_settings['Display Views Count'] == 1 ? 2048 : 0; $globalsettings += $p2_settings['Display on main page listing'] == 1 ? 4096 : 0; $globalsettings += $p2_settings['Display as Sticky'] == 1 ? 8192 : 0;
$includeidsarray = explode(',', $includeids); $matchingidsarray = explode(',', $matchingids);
$extraquery = ''; $tempgroup = null;
if(strlen($matchingids) > 0) // match $includeids and $matchingids to create an associative array { if(count($includeidsarray) != count($matchingidsarray)) //don't do matching if not the same number of values in both fields { if(strlen($includeids) > 0) // select news only from the $includeids { $extraquery = "AND p2_news.categoryid IN ($includeids)"; } } else // do matching { for($i = 0; $i < count($includeidsarray); $i++) { $includeidsarray[$i] = intval($includeidsarray[$i]); $matchingidsarray[$i] = intval($matchingidsarray[$i]); $matching[$includeidsarray[$i]] = $matchingidsarray[$i]; }
$extraquery = strlen($matching[$categoryid]) ? "AND p2_news.categoryid = $matching[$categoryid]" : ''; } }
// select news from the $includeids if no extraquery was made earlier if(strlen($includeids) AND $extraquery == '') { $extraquery = "AND p2_news.categoryid IN ($includeids)"; }
if($targeting) { $extraquery = "AND p2_news.categoryid = '$categoryid'"; }
// If we have elected to hide articles by default, search for those which are online if(($globalsettings & $p2_articlebitfield['displaymainpage']) == 0) { $extraquery .= " AND settings & 4096"; } // Else exclude all global articles else { $extraquery .= " AND ((settings & 1) OR settings & 4096)"; }
// sorting articles switch($sorting) { case 'alphaAZ': $sort = 'p2_news.title ASC'; break;
case 'alphaZA': $sort = 'p2_news.title DESC'; break;
case 'authornameAZ': $sort = 'p2_news.author ASC'; break;
case 'authornameZA': $sort = 'p2_news.author DESC'; break;
case 'oldest': $sort = 'IF ( p2_news.dateupdated = 0, p2_news.datecreated, p2_news.dateupdated ) ASC'; break;
default: $sort = 'IF ( p2_news.dateupdated = 0, p2_news.datecreated, p2_news.dateupdated ) DESC'; }
// grouping articles switch($grouping) { case 'category': $group = 'p2_news.name ASC, '; break;
case 'author': $group = 'p2_news.author ASC, '; break;
case 'date': $group = 'IF ( p2_news.dateupdated = 0, p2_news.datecreated, p2_news.dateupdated ) DESC, '; break;
default: $group = ''; }
// bold title? $boldtitlestart = $boldtitle ? '<b>' : ''; $boldtitleend = $boldtitle ? '</b>' : '';
$articleflag = 0; $groupflag = 0; $articlecounter = 0;
if(($grouping != 'nothing') OR ($sorting !='newest')) // create temporary table for grouping/sorting of selected articles { $DB->query("CREATE TEMPORARY TABLE {p3_news_temp} AS SELECT p2_news.*, categories.name FROM {p2_news} p2_news, {categories} categories WHERE (p2_news.settings & 2) AND (datestart = 0 OR datestart < '" . time() . "') AND (dateend = 0 OR dateend > '" . time() . "') AND p2_news.categoryid = categories.categoryid $extraquery ORDER BY IF (p2_news.dateupdated = 0, p2_news.datecreated, p2_news.dateupdated) DESC LIMIT 0, $limit");
$getarticles = $DB->query("SELECT articleid, categoryid, title, description, datecreated, author FROM {p3_news_temp} p2_news ORDER BY $group $sort");
$numberofarticles = mysql_num_rows($getarticles); } else // no grouping ('nothing') and default sorting ('newest'), not necessary to create temporary table { $getarticles = $DB->query("SELECT * FROM {p2_news} p2_news WHERE (settings & 2) AND (datestart = 0 OR datestart < '" . time() . "') AND (dateend = 0 OR dateend > '" . time() . "') $extraquery ORDER BY IF (dateupdated = 0, datecreated, dateupdated) DESC LIMIT 0, $limit");
$numberofarticles = mysql_num_rows($getarticles); }
$previousarticle = '';
while($article = $DB->fetch_array($getarticles)) { $subtitle = ''; $printlink = ''; $emaillink = '';
if($previousarticle != $article['title']) { // does category exist? if($category = $DB->query_first("SELECT name FROM {categories} WHERE categoryid = %d", $article['categoryid']) ) { // does the news plugin exist in that category? if($newsplugin = $DB->query_first("SELECT displayorder FROM {pagesort} WHERE categoryid = %d AND pluginid = '2'", $article['categoryid']) ) { $articlecounter++;
// display category name to the right of each news article if($showcategoryname) { $categoryname = $categorytolink ? ' (<a href="' . RewriteLink('index.php?categoryid='. $article['categoryid']) . '">' . $category['name'] . '</a>)' :' (' . $category['name'] . ')'; } else { $categoryname = ''; }
// group news by category, author or creation date? if($grouping != 'nothing' ) { if($grouping == 'category' AND ($category['name'] != $tempgroup)) // group by category { if($groupflag) { echo $groupseparator; }
$groupflag = 1;
if($categorytolink) // convert category to link? { echo '<a href="' . RewriteLink('index.php?categoryid=' . $article['categoryid']) . '"><b>' . $category['name'] . '</b></a>'; } else { echo '<b>' . $category['name'] . '</b>'; }
echo $grouparticleseparator; }
if($grouping == 'author' AND ($article['author'] != $tempgroup)) // group by author { if($groupflag) { echo $groupseparator; }
$groupflag = 1;
echo '<b>' . $article['author'] . '</b>' . $grouparticleseparator; }
if( ($grouping == 'date') AND (iif($article['datestart'] != 0, DisplayDate($article['datestart']), DisplayDate($article['datecreated'])) != $tempgroup) ) // group by date { if($groupflag) { echo $groupseparator; }
$groupflag = 1;
echo '<b>' . iif($article['datestart'] != 0, DisplayDate($article['datestart']), DisplayDate($article['datecreated'])) . '</b>' . $grouparticleseparator; }
} else // no grouping, print articleseparator, but not before the first article { if($articleflag) { echo $articleseparator; }
$articleflag = 1; }
if($showauthor) { $subtitle = '<br />' . $language['by'] . ' ' . $article['author']; }
if($showdate) { if($showauthor) { $subtitle .= ' - ' . $language['published'] . ' ' . iif($article['datestart'] != 0, DisplayDate($article['datestart']), DisplayDate($article['datecreated'])); } else { $subtitle .= '<br />' . $language['published'] . ' ' . iif($article['datestart'] != 0, DisplayDate($article['datestart']), DisplayDate($article['datecreated'])); } }
if($showupdatedate && $article['dateupdated'] != 0) { if($showauthor && !$showdate) { $subtitle .= ' - ' . $language['updated'] . ' ' . DisplayDate($article['dateupdated']); } else { $subtitle .= '<br />' . $language['updated'] . ' ' . DisplayDate($article['dateupdated']); } }
if($showprintlink) $printlink = '<a href="' . $sdurl . 'plugins/p2_news/printarticle.php?p2_articleid=' . $article['articleid'] . '" target="_blank"><img alt="' . strip_tags($language['print']) . '" src="' . $sdurl . 'plugins/p2_news/print.gif" /> ' . $language['print'] . '</a> ';
if($showemaillink) { $emaillink = '<a href="' . RewriteLink('index.php?categoryid=' . $article['categoryid'] . '&p2_articleid=' . $article['articleid'] . '&p2_action=emailarticle') . '"><img alt="' . strip_tags($language['email']) . '" src="' . $sdurl . 'plugins/p2_news/email.gif" /> ' . $language['email'] . '</a><br />'; } else if($showprintlink) { $printlink .= '<br />'; }
// convert title to link? $titlelinkstart = $titletolink ? '<a href="' . RewriteLink('index.php?categoryid=' . $article['categoryid'] . '&p2_articleid=' . $article['articleid']) . '">' : ''; $titlelinkend = $titletolink ? '</a>' : '';
// start printing the articles echo '<table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td>';
$articledescription = $showdescription ? '<br />' . $article['description'] : '';
if(strlen($article['description']) AND $showdescription) { echo $titlelinkstart . $boldtitlestart . $article['title'] . $boldtitleend . $titlelinkend . $categoryname . $subtitle . '<br />' . $printlink . $emaillink . $articledescription;
if($showreadmore) { echo ' <a href="' . RewriteLink('index.php?categoryid=' . $article['categoryid'] . '&p2_articleid=' . $article['articleid']) . '">' . $language['read_more'] . '</a><br />'; } } else { echo '<a href="' . RewriteLink('index.php?categoryid=' . $article['categoryid'] . '&p2_articleid=' . $article['articleid']) . '">' . $boldtitlestart . $article['title'] . $boldtitleend . '</a>' . $categoryname . $subtitle . '<br />' . $printlink . $emaillink; }
echo ' </td> </tr> </table>';
if($articlecounter < $numberofarticles AND $showdescription) { echo iif($grouping == 'nothing', '<br /><hr />', '<br /><hr /><br />'); }
// used for checking group by category if($grouping == 'category') $tempgroup = $category['name'];
// used for checking group by author if($grouping == 'author') $tempgroup = $article['author'];
// used for checking group by date if($grouping == 'date') $tempgroup = iif($article['datestart'] != 0, DisplayDate($article['datestart']), DisplayDate($article['datecreated'])); } } }
$previousarticle = $article['title']; }
}
p3_LatestNews();
?>
|