MyBB Community Forums

Full Version: Headlines 2 MYBB plugin help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Like this simply plugin....but....2 issues:

1) The dates are always wrong (likely because of the RSS)...is there a way to REMOVE the dates and center the messages?

2) It only shows on the Index page...how do I put it in another forum as well? I cannot find the plugin title in any templates. Any way to add this to the headers perhaps?

http://bringit2u.com/forum (to see the way the plugin looks)

PHP Code below for perusal:

<?php
// HL2MyBB
// Get the latest headlines of an RSS file to the top of the MyBB index page.
// By R. Kuiper - http://www.nofearcrew.net/script
// Version 1.2.1

if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

$plugins->add_hook("pre_output_page", "HL2MyBB");

function HL2MyBB_info()
{
global $lang;
HL2MyBB_load_language();

// Set plugin info.
return array(
"name" => $lang->HL2MyBB,
"description" => $lang->HL2MyBB_desc,
"website" => "http://www.nofearcrew.net/script/",
"author" => "R. Kuiper",
"authorsite" => "http://www.nofearcrew.net/script/",
"version" => "1.2.1",
"guid" => "",
"compatibility" => "16*",

"codename" => 'HL2MyBB',
);
}

// Language vars
function HL2MyBB_load_language()
{
global $lang;
if(!defined('RKUIPER_HL2MyBB_LANG_LOADED'))
{
$lang->load('HL2MyBB', false, true);

if(!isset($lang->HL2MyBB))
{
$lang->HL2MyBB = 'Headlines 2 MyBB';
$lang->HL2MyBB_desc = 'Get the latest entry(\'s) of an RSS file at the top of your index page. For MyBB 1.4.x';
}

define('RKUIPER_HL2MyBB_LANG_LOADED', 1);
}
}

// Run on activation of the plugin.
function HL2MyBB_activate()
{
global $db, $cache;
$info = HL2MyBB_info();

// Deactivate to remove any existing settings
HL2MyBB_deactivate();

// Admin settings group.
$setting_group_array = array(
'name' => str_replace(' ', '_', 'RKUIPER_'.strtolower($info['codename'])),
'title' => "$info[name]",
'description' => "Settings for the $info[name] plugin.",
'disporder' => 1,
'isdefault' => 0,
);
$db->insert_query('settinggroups', $setting_group_array);
$group = $db->insert_id();

// Admin settings.
$settings = array(
'HL2MyBB_text' => array('Default Text', 'The text before the news items.', 'text', 'Latest news:'),
'HL2MyBB_file' => array('RSS File?', 'Enter the url to the rss file.', 'text', ''),
'HL2MyBB_items' => array('How many items?', 'Enter how many items you want to show.', 'text', '1'),
'HL2MyBB_begin' => array('Beginning ID', 'The id of the first item, default is "1" ("0" is mostly the id of the RSS channel info.).', 'text', '1'),
'HL2MyBB_background' => array('Background color', 'Enter the color for the background.', 'text', '#FFF6BF'),
'HL2MyBB_border' => array('Border color', 'Enter the color for the borders.', 'text', '#FFD324'),
'HL2MyBB_borderpx' => array('Border pixels', 'Enter the pixels for the borders.', 'text', '2'),
);

// Inserting the settings.
$i = 1;
foreach($settings as $name => $sinfo)
{
$insert_array = array(
'name' => $name,
'title' => $db->escape_string($sinfo[0]),
'description' => $db->escape_string($sinfo[1]),
'optionscode' => $db->escape_string($sinfo[2]),
'value' => $db->escape_string($sinfo[3]),
'gid' => $group,
'disporder' => $i,
'isdefault' => 0,
);
$db->insert_query('settings', $insert_array);
$i++;
}
rebuild_settings();

$cache->update('HL2MyBB_errors', 0);
}

// On plugin deactivation.
function HL2MyBB_deactivate()
{
global $db, $cache;
$info = HL2MyBB_info();

// Select settingsgroup.
$result = $db->simple_select('settinggroups', 'gid', "name = '".str_replace(' ', '_', 'RKUIPER_'.strtolower($info['codename']))."'", array('limit' => 1));
$group = $db->fetch_array($result);

// Delete settings query's.
if(!empty($group['gid']))
{
$db->delete_query('settinggroups', "gid='{$group['gid']}'");
$db->delete_query('settings', "gid='{$group['gid']}'");
rebuild_settings();
}
$db->delete_query("datacache", "title='HL2MyBB_errors'");
}

function HL2MyBB($page)
{
global $mybb;

// Getting the settings.
$options = array(
"file" => $mybb->settings['HL2MyBB_file'],
"items" => $mybb->settings['HL2MyBB_items'],
"border" => $mybb->settings['HL2MyBB_border'],
"background" => $mybb->settings['HL2MyBB_background'],
"borderpx" => $mybb->settings['HL2MyBB_borderpx'],
"text" => $mybb->settings['HL2MyBB_text'],
"begin" => $mybb->settings['HL2MyBB_begin'],
"bburl" => $mybb->settings['bburl']
);

// Show only on the index page.
$url = "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
$bburl = $options['bburl']."/";
if($bburl == $url OR $bburl."index.php" == $url){
// Show headlines on screen.
$page = str_replace("<div id=\"content\">", "<div id=\"content\"><div style='border-top: ".$options['borderpx']."px solid ".$options['border']."; border-bottom: ".$options['borderpx']."px solid ".$options['border']."; background-color: ".$options['background']."'><p><table><tr><td style='vertical-align: middle;'><b>".$options['text']."</b></td><td style='vertical-align: top;'>".parse($options['file'], $options['items'], $options['begin'])."</td></tr></table><p /></div><br />", $page);
return $page;
}
}

// RSS parser function.
function Parse($rss, $items, $begin){
$xml_feed = file_get_contents($rss);
$xml_praser = xml_parser_create();

xml_parse_into_struct($xml_praser,$xml_feed,$xml_sleutel,$xml_index);
xml_parser_free($xml_praser);

$item = '';
for($i = $begin; $i<$items+$begin; $i++){
$date = date("d-m-Y, H:i:s", strtotime($xml_sleutel[$xml_index['PUBDATE'][$i]]['value']));
$item .= '<a href="'.str_replace("&", "&amp;", $xml_sleutel[$xml_index['LINK'][$i]]['value']).'">'.$xml_sleutel[$xml_index['TITLE'][$i]]['value'].'</a> ('.$date.')<br />';
}
return $item;
}
?>
Bump for help...
Anyone?
Down at the bottom of the file (if you have line numbers in your editor, it's line 162), find

$item .= '<a href="'.str_replace("&", "&amp;", $xml_sleutel[$xml_index['LINK'][$i]]['value']).'">'.$xml_sleutel[$xml_index['TITLE'][$i]]['value'].'</a> ('.$date.')<br />';

and change it to

$item .= '<a href="'.str_replace("&", "&amp;", $xml_sleutel[$xml_index['LINK'][$i]]['value']).'">'.$xml_sleutel[$xml_index['TITLE'][$i]]['value'].'</a><br />';

(IOW, chop off the ('.$date.') part.)