1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 04:38:27 +01:00

Newsfeed Plugin: Added SEF URLs. PHP7 compatibility fix.

This commit is contained in:
Cameron 2016-04-21 10:39:00 -07:00
parent 12151013ea
commit 6c4c5bd6e3
6 changed files with 99 additions and 22 deletions

View File

@ -81,7 +81,7 @@ class newsfeed_ui extends e_admin_ui
'newsfeed_id' => array ( 'title' => LAN_ID, 'data' => 'int', 'width' => '5%', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left', ),
'newsfeed_name' => array ( 'title' => LAN_TITLE, 'type' => 'text', 'data' => 'str', 'required'=>true, 'width' => 'auto', 'inline' => true, 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left', ),
'newsfeed_url' => array ( 'title' => LAN_URL, 'type' => 'url', 'data' => 'str', 'required'=>true, 'inline'=>true, 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => array('size'=>'xxlarge'), 'class' => 'left', 'thclass' => 'left', ),
'newsfeed_data' => array ( 'title' => 'Data', 'type' => 'hidden', 'data' => false, 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left', ),
'newsfeed_data' => array ( 'title' => 'Data', 'type' => 'hidden', 'noedit'=>true, 'data' => false, 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left', ),
'newsfeed_timestamp' => array ( 'title' => 'Timestamp', 'type' => 'hidden', 'data' => 'int', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left', ),
'newsfeed_description' => array ( 'title' => LAN_DESCRIPTION, 'type' => 'textarea', 'data' => 'str', 'width' => '40%', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left', ),
'newsfeed_image' => array ( 'title' => NFLAN_11, 'type' => 'method', 'data' => 'str', 'width' => 'auto', 'help' => LAN_OPTIONAL, 'readParms' => 'thumb=80x80', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left', ),
@ -124,6 +124,8 @@ class newsfeed_ui extends e_admin_ui
$new_data['newsfeed_image'] = e107::getParser()->toDB($new_data['newsfeed_image'])."::".intval($new_data['newsfeed_showmenu'])."::".intval($new_data['newsfeed_showmain']);
}
$new_data['newsfeed_timestamp'] = 0;
return $new_data;
}
@ -147,8 +149,12 @@ class newsfeed_ui extends e_admin_ui
if(isset($new_data['newsfeed_showmenu']))
{
$new_data['newsfeed_image'] = e107::getParser()->toDB($new_data['newsfeed_image'])."::".intval($new_data['newsfeed_showmenu'])."::".intval($new_data['newsfeed_showmain']);
}
$new_data['newsfeed_timestamp'] = 0; // reset so the feed data refreshes.
return $new_data;
}

View File

@ -0,0 +1,50 @@
<?php
/*
* e107 Bootstrap CMS
*
* Copyright (C) 2008-2015 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* IMPORTANT: Make sure the redirect script uses the following code to load class2.php:
*
* if (!defined('e107_INIT'))
* {
* require_once("../../class2.php");
* }
*
*/
if (!defined('e107_INIT')) { exit; }
// v2.x Standard - Simple mod-rewrite module.
class newsfeed_url // plugin-folder + '_url'
{
function config()
{
$config = array();
$config['source'] = array(
'alias' => 'newsfeed',
'regex' => '^{alias}/(\d*)/(.*)', // matched against url, and if true, redirected to 'redirect' below.
'sef' => '{alias}/{newsfeed_id}/{newsfeed_sef}', // used by e107::url(); to create a url from the db table.
'redirect' => '{e_PLUGIN}newsfeed/newsfeed.php?id=$1', // file-path of what to load when the regex returns true.
);
$config['index'] = array(
'alias' => 'newsfeed',
'regex' => '^{alias}/?', // matched against url, and if true, redirected to 'redirect' below.
'sef' => '{alias}', // used by e107::url(); to create a url from the db table.
'redirect' => '{e_PLUGIN}newsfeed/newsfeed.php', // file-path of what to load when the regex returns true.
);
return $config;
}
}

View File

@ -35,16 +35,30 @@ if (!is_object($newsFeed))
{
$newsFeed = new newsfeedClass;
}
e107::css('inline', "
.newsfeed ul { max-width:100% }
.newsfeed img { max-width:100% }
");
require_once(HEADERF);
/* get template */
if (file_exists(THEME."newsfeed_template.php"))
if(file_exists(THEME."templates/newsfeed/newsfeed_template.php"))
{
require_once(THEME."newsfeed_template.php");
include(THEME."templates/newsfeed/newsfeed_template.php");
}
elseif (file_exists(THEME."newsfeed_template.php"))
{
include(THEME."newsfeed_template.php");
}
else if(!varset($NEWSFEED_LIST_START, FALSE))
{
require_once(e_PLUGIN."newsfeed/templates/newsfeed_template.php");
include(e_PLUGIN."newsfeed/templates/newsfeed_template.php");
}
$action = FALSE;
@ -55,12 +69,18 @@ if(e_QUERY)
$id = intval(varset($qs[1], 0));
}
if(!empty($_GET['id'])) //v2.x
{
$id = intval($_GET['id']);
$action = 'show';
}
if($action == "show")
{
/* 'show' action - show feed */
$data = $newsFeed->newsfeedInfo($id == 0 ? 'all' : $id, 'main');
$ns->tablerender($data['title'], $data['text']);
$ns->tablerender($data['title'], $data['text']);
require_once(FOOTERF);
exit;
}
@ -68,6 +88,7 @@ if($action == "show")
/* no action - display feed list ... */
$newsFeed->readFeedList();
$vars = array();
if (count($newsFeed->feedList))
{
$data = "";
@ -75,10 +96,15 @@ if (count($newsFeed->feedList))
{
if (($feed['newsfeed_active'] == 2) || ($feed['newsfeed_active'] == 3))
{
$FEEDNAME = "<a href='".e_SELF."?show.{$feed['newsfeed_id']}'>{$feed['newsfeed_name']}</a>";
$FEEDDESCRIPTION = ((!$feed['newsfeed_description'] || $feed['newsfeed_description'] == "default") ? "&nbsp;" : $feed['newsfeed_description']);
$feed['newsfeed_sef'] = eHelper::title2sef($feed['newsfeed_name'], 'dashl');
$url = e107::url('newsfeed', 'source', $feed); // e_SELF."?show.{$feed['newsfeed_id']}
$vars['FEEDNAME'] = "<a href='".$url."'>{$feed['newsfeed_name']}</a>";
$vars['FEEDDESCRIPTION'] = ((!$feed['newsfeed_description'] || $feed['newsfeed_description'] == "default") ? "&nbsp;" : $feed['newsfeed_description']);
// $FEEDIMAGE = $feed['newsfeed_image']; // This needs splitting up. Not used ATM anyway, so disable for now
$data .= preg_replace("/\{(.*?)\}/e", '$\1', $NEWSFEED_LIST);
$data .= $tp->simpleParse($NEWSFEED_LIST, $vars);
}
}
}
@ -87,4 +113,3 @@ $text = $NEWSFEED_LIST_START . vartrue($data) . $NEWSFEED_LIST_END;
$ns->tablerender(NFLAN_29, $text);
require_once(FOOTERF);
?>

View File

@ -120,20 +120,18 @@ class newsfeedClass
$this->readFeedList(); // Make sure we've got the feed data.
// $force = true;
if (!isset($this->feedList[$feedID]))
{
if (NEWSFEED_DEBUG) echo "Invalid feed number: {$feedID}<br />";
return FALSE;
}
if(strpos($this->newsList[$feedID]['newsfeed_data'],'MagpieRSS')) //BC Fix to update newsfeed_data from v1 to v2 spec.
if(empty($this->newsList[$feedID]['newsfeed_timestamp']) || empty($this->newsList[$feedID]['newsfeed_data']) || strpos($this->newsList[$feedID]['newsfeed_data'],'MagpieRSS')) //BC Fix to update newsfeed_data from v1 to v2 spec.
{
$force = true;
}
if ($force || !isset($this->newsList[$feedID]['newsfeed_data']) || !$this->newsList[$feedID]['newsfeed_data']) // No data already in memory
if($force) // No data already in memory
{
if ($force || !($this->newsList[$feedID]['newsfeed_data'] = e107::getCache()->retrieve(NEWSFEED_NEWS_CACHE_TAG.$feedID, $this->feedList[$feedID]['newsfeed_updateint']/60)))
{ // Need to re-read from source - either no cached data yet, or cache expired

View File

@ -8,8 +8,6 @@
<link url='admin_config.php' description='Configure Newsfeeds' icon='images/newsfeed_32.png' iconSmall='images/newsfeed_16.png' primary='true' >Configure Newsfeeds</link>
</adminLinks>
<siteLinks>
<link url="{e_PLUGIN}newsfeed/newsfeed.php" >Newsfeeds</link>
<link url="{e_PLUGIN}newsfeed/newsfeed.php" sef="index" >LAN_PLUGIN_NEWSFEEDS_NAME</link>
</siteLinks>
<pluginPrefs>
</pluginPrefs>
</e107Plugin>

View File

@ -20,7 +20,7 @@ if (!defined('e107_INIT')) { exit; }
$NEWSFEED_MAIN_CAPTION = NFLAN_38;
$NEWSFEED_LIST_START = "
<table style='width: 100%;' class='table fborder'>\n";
<table style='width: 100%;' class='newsfeed-list table fborder'>\n";
$NEWSFEED_LIST = "
<tr>
@ -32,16 +32,16 @@ $NEWSFEED_LIST_END = "
</table>\n";
$NEWSFEED_MAIN_START = "
<table style='width: 100%;' class='table fborder'>
<table style='width: 100%;' class='newsfeed table fborder'>
<tr>
<td class='forumheader'>{FEEDIMAGE} {FEEDTITLE}</td>
<td class='forumheader'><h3>{FEEDIMAGE} {FEEDTITLE}</h3></td>
</tr>
<tr>
<td class='forumheader3'>
<ul>\n";
$NEWSFEED_MAIN = "
<li><b>{FEEDITEMLINK}</b> <span class='smalltext'>{FEEDITEMCREATOR}</span><br />{FEEDITEMTEXT}<br /><br /></li>\n";
<li><h4>{FEEDITEMLINK}</h4><small class='smalltext'>{FEEDITEMCREATOR}</small><div>{FEEDITEMTEXT}</div></li>\n";
$NEWSFEED_MAIN_END = "