added 404-errorpage including template and image, changed some variables

in templates and pulled parts out in new templates, fixed some bugs and
typos from previous commits

moved new events, ratings and caches HTML code generation into separate
templates and changed templates accordingly to avoid redundant code

moved generation of HTML code for RSSParser into separate smarty
template and changed involved files accordingly

moved code that generates the "new" (cache, event, rating, forum, blog,
etc.) sections into separate class to avoid redundant code
This commit is contained in:
Nils Bohrs
2013-04-22 16:20:38 +02:00
committed by following
parent 7d190bdebb
commit ed1a383ee6
15 changed files with 711 additions and 204 deletions

View File

@@ -11,24 +11,22 @@ class RSSParser {
* @return string $item feeditems as HTML-string
*/
public static function parse($items,$url,$includetext) {
global $translate;
global $tpl;
if ($items <= 0)
return '';
// error
$error = false;
$rss = array();
// check $url
if(!preg_match('!^(http|https|ftp)\://([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&amp;%\$\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\?\'\\\+&amp;%\$#\=~_\-]+))*$!',$url)) {
if(!preg_match('!^(http|https|ftp)\://([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&amp;%\$\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(\:[0-9]+)*(/($|[a-zA-Z0-9\.\:\,\?\'\\\+&amp;%\$#\=~_\-]+))*$!',$url)) {
$error = true;
} else {
// output
$html = '<div class="buffer" style="width: 500px;height: 2px;">&nbsp;</div>'."\n";
$html .= '<div class="newsblock">';
if (!$includetext)
$html .= "<table class='narrowtable' style='margin-top:0'>\n";
$tpl->assign('includetext',$includetext);
// get xml-data
$data = @file_get_contents($url);
@@ -44,9 +42,9 @@ class RSSParser {
// get SimpleXML-object
$xml = new SimpleXMLElement($data);
// walk through items
$i=0;
$headlines = array();
// walk through items
foreach($xml->channel->item as $item) {
// check length
@@ -57,32 +55,31 @@ class RSSParser {
// add html
if ($includetext)
{
$html .= '<p class="content-title-noshade-size15" style="display: inline;">'."\n";
$html .= strftime('%e. %B %Y',strtotime($item->pubDate)).' - '. $item->title;
$html .= '</p> <p style="line-height: 1.6em;display: inline;">&emsp;[<b><a class="link" href="'.$item->link.'">mehr...</a></b>]</p>'."\n";
$html .= '<div class="rsstext">'.$item->description.'</div>'."\n";
// fill array
$rss[] = array(
'pubDate' => strftime('%e. %B %Y',strtotime($item->pubDate)),
'title' => $item->title,
'link' => $item->link,
'description' => $item->description
);
// increment counter
$i++;
}
else if (!in_array($item->title,$headlines) &&
strpos($item->title,'VERSCHOBEN') === FALSE) // hack to exclude forum thread-move messages
{
$html .= '<tr><td style="text-align:right">' . strftime('%e. %B %Y',strtotime($item->pubDate)).'</td>';
$html .= '<td><a class="links" href="'.$item->link.'">';
$html .= $item->title;
$html .= '</td></tr>';
// fill array
$rss[] = array(
'pubDate' => strftime('%e. %B %Y',strtotime($item->pubDate)),
'title' => $item->title,
'link' => $item->link
);
$headlines[] = "" . $item->title;
// increment counter
$i++;
}
}
}
// finish html
if (!$includetext)
$html .= "</table>";
$html .= "</div>";
$html .= '<div class="buffer" style="width: 500px;">&nbsp;</div>'."\n";
}
catch(Exception $e) {
$error = true;
@@ -90,12 +87,11 @@ class RSSParser {
}
}
// assign to template
$tpl->assign('rsserror',$error);
// return
if(!$error) {
return $html;
} else {
return '<p><em>' . $translate->t('currently not available','','',0) . '</em></p>';
}
return $rss;
}
}

328
htdocs/lib2/getNew.class.php Executable file
View File

@@ -0,0 +1,328 @@
<?php
/***************************************************************************
* For license information see doc/license.txt
*
* Unicode Reminder メモ
*
* summarize methods to get new events, caches, ratings, etc.
***************************************************************************/
class getNew {
// class variables
private $userCountry;
// getter/setter
public function get_userCountry() {
return $this->userCountry;
}
public function set_userCountry($userCountry) {
$this->userCountry = $userCountry;
}
/**
* constructor
* creates the object
*
* @param string $userCountry country of the loggedin user as parameter for the sql statements
* @return void
*/
public function __construct($userCountry) {
// set userCountry
$this->set_userCountry($userCountry);
}
/**
* rsForSmarty creates the result from database to use with smarty assign-rs method
* based on $this->type
*
* @param string $type type of the "new"-information, i.e. cache, event, rating, etc
* @param array $args numeric array containing the parameter for "sql_slave"
* @return object mysql result used by smarty assign_rs
*/
public function rsForSmarty($type,$args=null) {
// check type
if(method_exists($this,strtolower($type).'Rs')) {
return call_user_func(array($this,$type.'Rs'),$args);
}
}
/**
* feedForSmarty creates a HTML string to use with smarty assign method
* based on $this->type by using RSSParser class
*
* @param string $type type of the "new"-information, i.e. cache, event, rating, etc
* @param int $items number of feeditems to parse from feed (RSSParser)
* @param string $url url of the feed to parse (RSSParser)
* @param boolean $includetext ???following??? add table-tag?
* @return string HTML string used for smarty assign method
*/
public function feedForSmarty($type,$items=null,$url=null,$includetext=null) {
// check type
if(method_exists($this,strtolower($type).'Feed')) {
return call_user_func(array($this,$type.'Feed'),$items,$url,$includetext);
}
}
/**
* cacheRs executes the database statements for type "cache"
*
* @param array $args numeric array containing the parameter for "sql_slave"
* @return object mysql result used by smarty assign_rs
*/
private function cacheRs($args=null) {
// global
global $opt;
// check $args and set defaults
if(is_null($args) || !is_array($args)) {
$args = array($this->get_userCountry(), $opt['template']['locale'],10);
}
// execute sql
return sql_slave("SELECT `user`.`user_id` `user_id`,
`user`.`username` `username`,
`caches`.`cache_id` `cache_id`,
`caches`.`name` `name`,
`caches`.`date_created` `date_created`,
`caches`.`type`,
IFNULL(`sys_trans_text`.`text`,`cache_location`.`adm1`) AS `adm1`,
`cache_location`.`adm2`,
`cache_location`.`adm3`,
`cache_location`.`adm4`
FROM `caches`
INNER JOIN `user` ON `user`.`user_id`=`caches`.`user_id`
LEFT JOIN `cache_location` ON `caches`.`cache_id`=`cache_location`.`cache_id`
LEFT JOIN `countries` ON `countries`.`short`=`cache_location`.`code1`
LEFT JOIN `sys_trans_text` ON `sys_trans_text`.`trans_id`=`countries`.`trans_id` AND `sys_trans_text`.`lang`='&2'
WHERE `caches`.`country`='&1' AND
`caches`.`type` != 6 AND
`caches`.`status` = 1
ORDER BY `caches`.`date_created` DESC
LIMIT 0, &3",
$args);
}
/**
* eventRs executes the database statements for type "event"
*
* @param array $args numeric array containing the parameter for "sql_slave"
* @return object mysql result used by smarty assign_rs
*/
private function eventRs($args=null) {
// global
global $opt;
// check $args and set defaults
if(is_null($args) || !is_array($args)) {
$args = array($this->get_userCountry(), $opt['template']['locale'],10);
}
// execute sql
return sql_slave("SELECT `user`.`user_id` `user_id`,
`user`.`username` `username`,
`caches`.`cache_id` `cache_id`,
`caches`.`name` `name`,
`caches`.`date_hidden`,
IFNULL(`sys_trans_text`.`text`,`cache_location`.`adm1`) AS `adm1`,
`cache_location`.`adm2`,
`cache_location`.`adm3`,
`cache_location`.`adm4`
FROM `caches`
INNER JOIN `user` ON `user`.`user_id`=`caches`.`user_id`
LEFT JOIN `cache_location` ON `caches`.`cache_id`=`cache_location`.`cache_id`
LEFT JOIN `countries` ON `countries`.`short`=`cache_location`.`code1`
LEFT JOIN `sys_trans_text` ON `sys_trans_text`.`trans_id`=`countries`.`trans_id` AND `sys_trans_text`.`lang`='&2'
WHERE `caches`.`country`='&1' AND
`caches`.`date_hidden` >= curdate() AND
`caches`.`type` = 6 AND
`caches`.`status`=1
ORDER BY `date_hidden` ASC
LIMIT 0, &3",
$args);
}
/**
* ratingRs executes the database statements for type "rating"
*
* @param array $args numeric array containing the parameter for "sql_slave"
* @return object mysql result used by smarty assign_rs
*/
private function ratingRs($args=null) {
// global
global $opt;
// check $args and set defaults
if(is_null($args) || !is_array($args)) {
$args = array($this->get_userCountry(), $opt['template']['locale'],10);
}
// execute sql
// 2012-08-24 following
// optimized by adding rating_date field to cache_rating, so we don't need the log table.
return sql_slave("SELECT COUNT(`cache_rating`.`user_id`) AS `cRatings`,
MAX(`cache_rating`.`rating_date`) AS `dLastLog`,
`user`.`user_id` AS `user_id`,
`user`.`username` AS `username`,
`caches`.`cache_id` AS `cache_id`,
`caches`.`name` AS `name`,
`caches`.`type`,
IFNULL(`sys_trans_text`.`text`,`cache_location`.`adm1`) AS `adm1`,
`cache_location`.`adm2`,
`cache_location`.`adm3`,
`cache_location`.`adm4`
FROM `cache_rating`
INNER JOIN `caches` ON `caches`.`cache_id`=`cache_rating`.`cache_id`
INNER JOIN `user` ON `user`.`user_id`=`caches`.`user_id`
LEFT JOIN `cache_location` ON `cache_rating`.`cache_id`=`cache_location`.`cache_id`
LEFT JOIN `countries` ON `countries`.`short`=`cache_location`.`code1`
LEFT JOIN `sys_trans_text` ON `sys_trans_text`.`trans_id`=`countries`.`trans_id` AND `sys_trans_text`.`lang`='&2'
WHERE `caches`.`country`='&1' AND
`cache_rating`.`rating_date`>DATE_SUB(NOW(), INTERVAL 30 DAY) AND
`caches`.`type`!=6 AND
`caches`.`status`=1
GROUP BY `cache_rating`.`cache_id`
ORDER BY `cRatings` DESC,
`dLastLog` DESC,
`cache_id` DESC
LIMIT 0, &3",
$args);
}
/**
* blogFeed executes the RSSParser for type "blog"
*
* @param int $items number of feeditems to parse from feed (RSSParser)
* @param string $url url of the feed to parse (RSSParser)
* @param boolean $includetext ???following??? add table-tag?
* @return string HTML string used for smarty assign method
*/
private function blogFeed($items=null,$url=null,$includetext=null) {
// global
global $opt;
// check $items and set defaults
if(is_null($items) || !is_numeric($items)) {
$items = $opt['news']['count'];
}
// check $url and set defaults
if(is_null($url) || !is_string($url)) {
$url = $opt['news']['include'];
}
// check $includetext and set defaults
if(is_null($includetext) || !is_bool($includetext)) {
$includetext = false;
}
// execute RSSParser
return RSSParser::parse($items,$url,$includetext);
}
/**
* forumFeed executes the RSSParser for type "forum"
*
* @param int $items number of feeditems to parse from feed (RSSParser)
* @param string $url url of the feed to parse (RSSParser)
* @param boolean $includetext ???following??? add table-tag?
* @return string HTML string used for smarty assign method
*/
private function forumFeed($items=null,$url=null,$includetext=null) {
// global
global $opt;
// check $items and set defaults
if(is_null($items) || !is_numeric($items)) {
$items = $opt['forum']['count'];
}
// check $url and set defaults
if(is_null($url) || !is_string($url)) {
$url = $opt['forum']['url'];
}
// check $includetext and set defaults
if(is_null($includetext) || !is_bool($includetext)) {
$includetext = false;
}
// execute RSSParser
return RSSParser::parse($items,$url,$includetext);
}
/**
* wikiFeed executes the RSSParser for type "wiki"
*
* @param int $items number of feeditems to parse from feed (RSSParser)
* @param string $url url of the feed to parse (RSSParser)
* @param boolean $includetext ???following??? add table-tag?
* @return string HTML string used for smarty assign method
*/
private function wikiFeed($items=null,$url=null,$includetext=null) {
// global
global $opt;
// check $items and set defaults
if(is_null($items) || !is_numeric($items)) {
$items = 10;
}
// check $url and set defaults
if(is_null($url) || !is_string($url)) {
$url = 'http://wiki.opencaching.de/index.php/Spezial:Neue_Seiten?feed=rss';
}
// check $includetext and set defaults
if(is_null($includetext) || !is_bool($includetext)) {
$includetext = false;
}
// execute RSSParser
return RSSParser::parse($items,$url,$includetext);
}
}
?>