Fix E_NOTICEs, slightly optimize loops in fof_get_feeds

master
Vitaliy Filippov 2014-12-09 01:29:47 +03:00
parent da20e67d1b
commit 8a69aff574
10 changed files with 88 additions and 143 deletions

View File

@ -12,7 +12,7 @@
*/ */
require_once('simplepie/simplepie.php'); require_once('simplepie/simplepie.php');
if(file_exists("./cache/" . $_GET[i] . ".spi")) if(file_exists("./cache/" . $_GET['i'] . ".spi"))
{ {
SimplePie_Misc::display_cached_file($_GET['i'], './cache', 'spi'); SimplePie_Misc::display_cached_file($_GET['i'], './cache', 'spi');
} }

View File

@ -41,7 +41,7 @@ function fof_safe_query(/* $query, [$args...]*/)
{ {
$args = func_get_args(); $args = func_get_args();
$query = array_shift($args); $query = array_shift($args);
if(is_array($args[0])) $args = $args[0]; if(isset($args[0]) && is_array($args[0])) $args = $args[0];
$args = array_map('mysql_real_escape_string', $args); $args = array_map('mysql_real_escape_string', $args);
$query = vsprintf($query, $args); $query = vsprintf($query, $args);
@ -57,6 +57,7 @@ function fof_db_query($sql, $live=0)
$result = mysql_query($sql, $fof_connection); $result = mysql_query($sql, $fof_connection);
$num = 0;
if(is_resource($result)) $num = mysql_num_rows($result); if(is_resource($result)) $num = mysql_num_rows($result);
if($result) $affected = mysql_affected_rows($fof_connection); if($result) $affected = mysql_affected_rows($fof_connection);
@ -150,8 +151,11 @@ function fof_db_feed_update_metadata($feed_id, $url, $title, $link, $description
function fof_db_get_latest_item_age($user_id) function fof_db_get_latest_item_age($user_id)
{ {
global $FOF_SUBSCRIPTION_TABLE, $FOF_ITEM_TABLE; global $FOF_SUBSCRIPTION_TABLE, $FOF_ITEM_TABLE;
$result = fof_safe_query(
$result = fof_db_query("SELECT max( item_cached ) AS \"max_date\", $FOF_ITEM_TABLE.feed_id as \"id\" FROM $FOF_ITEM_TABLE GROUP BY $FOF_ITEM_TABLE.feed_id"); "select max(i.item_cached) max_date, i.feed_id id".
" from $FOF_ITEM_TABLE i, $FOF_SUBSCRIPTION_TABLE s".
" where s.user_id=%d and s.feed_id=i.feed_id group by i.feed_id", $user_id
);
return $result; return $result;
} }
@ -324,7 +328,7 @@ function fof_db_get_items($user_id = 1, $feed = NULL, $what = "unread",
$user_id = intval($user_id); $user_id = intval($user_id);
$prefs = fof_prefs(); $prefs = fof_prefs();
$offset = $prefs['tzoffset']; $offset = $prefs['tzoffset'];
if ($prefs['dst']) if (!empty($prefs['dst']))
$offset += date('I'); $offset += date('I');
if (!is_null($when) && $when != "") if (!is_null($when) && $when != "")
@ -402,7 +406,7 @@ function fof_db_get_items($user_id = 1, $feed = NULL, $what = "unread",
$order_by = "order by $pubdate desc $limit_clause "; $order_by = "order by $pubdate desc $limit_clause ";
$query = "$select FROM $from $where $group $order_by"; $query = "$select FROM $from $where $order_by";
$result = fof_safe_query($query, $args); $result = fof_safe_query($query, $args);
if (mysql_num_rows($result) == 0) if (mysql_num_rows($result) == 0)
return array(); return array();

View File

@ -31,9 +31,9 @@ $fof_tag_prefilters = array();
fof_db_connect(); fof_db_connect();
if(!$fof_installer) if (empty($fof_installer))
{ {
if(!$fof_no_login) if (empty($fof_no_login))
{ {
require_user(); require_user();
$fof_prefs_obj = FoF_Prefs::instance(); $fof_prefs_obj = FoF_Prefs::instance();
@ -301,100 +301,76 @@ function fof_get_feeds($user_id, $order = 'feed_title', $direction = 'asc')
$result = fof_db_get_subscriptions($user_id); $result = fof_db_get_subscriptions($user_id);
$i = 0; while ($row = fof_db_get_row($result))
while($row = fof_db_get_row($result))
{ {
$id = $row['feed_id'];
$age = $row['feed_cache_date']; $age = $row['feed_cache_date'];
$feeds[$i]['prefs'] = unserialize($row['subscription_prefs']);
$feeds[$i]['feed_id'] = $id;
$feeds[$i]['feed_url'] = $row['feed_url'];
$feeds[$i]['feed_title'] = $row['feed_title'];
$feeds[$i]['feed_link'] = $row['feed_link'];
$feeds[$i]['feed_description'] = $row['feed_description'];
$feeds[$i]['feed_image'] = $row['feed_image'];
$feeds[$i]['feed_age'] = $age;
list($agestr, $agestrabbr) = fof_nice_time_stamp($age); list($agestr, $agestrabbr) = fof_nice_time_stamp($age);
$feeds[$row['feed_id']] = array(
$feeds[$i]['agestr'] = $agestr; 'prefs' => unserialize($row['subscription_prefs']),
$feeds[$i]['agestrabbr'] = $agestrabbr; 'feed_id' => $row['feed_id'],
'feed_url' => $row['feed_url'],
$i++; 'feed_title' => $row['feed_title'],
'feed_link' => $row['feed_link'],
'feed_description' => $row['feed_description'],
'feed_image' => $row['feed_image'],
'feed_age' => $age,
'agestr' => $agestr,
'agestrabbr' => $agestrabbr,
'feed_items' => 0,
'feed_read' => 0,
'feed_unread' => 0,
'feed_starred' => 0,
'max_date' => NULL,
'lateststr' => '',
'lateststrabbr' => '',
);
} }
$tags = fof_db_get_tag_id_map(); $tags = fof_db_get_tag_id_map();
for($i=0; $i<count($feeds); $i++) foreach ($feeds as &$feed)
{ {
$feeds[$i]['tags'] = array(); $feed['tags'] = array();
if(is_array($feeds[$i]['prefs']['tags'])) if (is_array($feed['prefs']['tags']))
{ {
foreach($feeds[$i]['prefs']['tags'] as $tag) foreach ($feed['prefs']['tags'] as $tag)
{ {
$feeds[$i]['tags'][] = $tags[$tag]; $feed['tags'][] = $tags[$tag];
} }
} }
} }
$result = fof_db_get_item_count($user_id); $result = fof_db_get_item_count($user_id);
while ($row = fof_db_get_row($result))
while($row = fof_db_get_row($result))
{ {
for($i=0; $i<count($feeds); $i++) $feeds[$row['id']]['feed_items'] = $row['count'];
{ $feeds[$row['id']]['feed_read'] = $row['count'];
if($feeds[$i]['feed_id'] == $row['id'])
{
$feeds[$i]['feed_items'] = $row['count'];
$feeds[$i]['feed_read'] = $row['count'];
$feeds[$i]['feed_unread'] = 0;
}
}
} }
$result = fof_db_get_tagged_item_count($user_id, 1); $result = fof_db_get_tagged_item_count($user_id, 1);
while ($row = fof_db_get_row($result))
while($row = fof_db_get_row($result))
for($i=0; $i<count($feeds); $i++)
if($feeds[$i]['feed_id'] == $row['id'])
$feeds[$i]['feed_unread'] = $row['count'];
foreach($feeds as $feed)
{ {
$feed['feed_starred'] = 0; $feeds[$row['id']]['feed_unread'] = $row['count'];
} }
$result = fof_db_get_tagged_item_count($user_id, 2); $result = fof_db_get_tagged_item_count($user_id, 2);
while ($row = fof_db_get_row($result))
while($row = fof_db_get_row($result))
{ {
for($i=0; $i<count($feeds); $i++) $feeds[$row['id']]['feed_starred'] = $row['count'];
{
if($feeds[$i]['feed_id'] == $row['id'])
{
$feeds[$i]['feed_starred'] = $row['count'];
}
}
} }
$result = fof_db_get_latest_item_age($user_id); $result = fof_db_get_latest_item_age($user_id);
while ($row = fof_db_get_row($result))
while($row = fof_db_get_row($result))
{ {
for($i=0; $i<count($feeds); $i++) if (!isset($feeds[$row['id']]))
{ {
if($feeds[$i]['feed_id'] == $row['id']) var_dump($row);
{ die();
$feeds[$i]['max_date'] = $row['max_date'];
list($agestr, $agestrabbr) = fof_nice_time_stamp($row['max_date']);
$feeds[$i]['lateststr'] = $agestr;
$feeds[$i]['lateststrabbr'] = $agestrabbr;
}
} }
$feeds[$row['id']]['max_date'] = $row['max_date'];
list($agestr, $agestrabbr) = fof_nice_time_stamp($row['max_date']);
$feeds[$row['id']]['lateststr'] = $agestr;
$feeds[$row['id']]['lateststrabbr'] = $agestrabbr;
} }
$feeds = fof_multi_sort($feeds, $order, $direction != "asc"); $feeds = fof_multi_sort($feeds, $order, $direction != "asc");
@ -408,9 +384,7 @@ function fof_feed_title($feed, $prefs = NULL)
$prefs = $feed['prefs']; $prefs = $feed['prefs'];
if (!$prefs) if (!$prefs)
$prefs = fof_db_get_subscription_prefs(fof_current_user(), $feed['feed_id']); $prefs = fof_db_get_subscription_prefs(fof_current_user(), $feed['feed_id']);
$t = $prefs['feed_title']; $t = !empty($prefs['feed_title']) ? $prefs['feed_title'] : $feed['feed_title'];
if (!$t)
$t = $feed['feed_title'];
return $t; return $t;
} }

View File

@ -57,11 +57,10 @@ function fof_render_item($item)
$item_title = $item['item_title']; $item_title = $item['item_title'];
$item_author = $item['item_author']; $item_author = $item['item_author'];
$item_content = $item['item_content']; $item_content = $item['item_content'];
$item_read = $item['item_read'];
$prefs = fof_prefs(); $prefs = fof_prefs();
$offset = $prefs['tzoffset']; $offset = $prefs['tzoffset'];
if ($prefs['dst']) if (!empty($prefs['dst']))
$offset += date('I'); $offset += date('I');
$item_published = gmdate("Y-n-d g:ia", $item['item_published'] + $offset*60*60); $item_published = gmdate("Y-n-d g:ia", $item['item_published'] + $offset*60*60);
@ -70,7 +69,7 @@ function fof_render_item($item)
if(!$item_title) $item_title = "[no title]"; if(!$item_title) $item_title = "[no title]";
if($_GET['search']) if(!empty($_GET['search']))
{ {
$item_content = do_highlight("<span>$item_content</span>", $_GET['search'], "highlight"); $item_content = do_highlight("<span>$item_content</span>", $_GET['search'], "highlight");
$item_title = do_highlight("<span>$item_title</span>", $_GET['search'], "highlight"); $item_title = do_highlight("<span>$item_title</span>", $_GET['search'], "highlight");

View File

@ -15,42 +15,31 @@
include_once("fof-main.php"); include_once("fof-main.php");
include_once("fof-render.php"); include_once("fof-render.php");
if (!isset($_GET['which'])) $which = !empty($_GET['which']) ? $_GET['which'] : 0;
$which = 0; $order = !empty($_GET['order']) ? $_GET['order'] : $fof_prefs_obj->get('order');
else $what = !empty($_GET['what']) ? $_GET['what'] : 'unread';
$which = $_GET['which'];
$order = $_GET['order']; $how = !empty($_GET['how']) ? $_GET['how'] : NULL;
$feed = !empty($_GET['feed']) ? $_GET['feed'] : NULL;
$when = !empty($_GET['when']) ? $_GET['when'] : NULL;
$howmany = !empty($_GET['howmany']) ? $_GET['howmany'] : $fof_prefs_obj->get('howmany');
$search = !empty($_GET['search']) ? $_GET['search'] : NULL;
if(!isset($_GET['what'])) $title = fof_view_title($feed, $what, $when, $which, $howmany, $search);
$what = "unread";
else
$what = $_GET['what'];
if(!isset($_GET['order']))
$order = $fof_prefs_obj->get("order");
$how = $_GET['how'];
$feed = $_GET['feed'];
$when = $_GET['when'];
$howmany = $_GET['howmany'];
$title = fof_view_title($_GET['feed'], $what, $_GET['when'], $which, $_GET['howmany'], $_GET['search']);
$noedit = $_GET['noedit'];
?> ?>
<p class="items-title"><?php echo $title?></p> <p class="items-title"><?php echo $title ?></p>
<ul id="item-display-controls" class="inline-list"> <ul id="item-display-controls" class="inline-list">
<li class="orderby"><?php <li class="orderby"><?php
echo ($order == "desc") ? '[new to old]' : "<a href=\".?feed=$feed&amp;what=$what&amp;when=$when&amp;how=$how&amp;howmany=$howmany&amp;order=desc\">[new to old]</a>" ; echo ($order == "desc") ? '[new to old]' : "<a href=\".?feed=$feed&amp;what=$what&amp;when=$when&amp;how=$how&amp;howmany=$howmany&amp;order=desc\">[new to old]</a>";
?></li> ?></li>
<li class="orderby"><?php <li class="orderby"><?php
echo ($order == "asc") ? '[old to new]' : "<a href=\".?feed=$feed&amp;what=$what&amp;when=$when&amp;how=$how&amp;howmany=$howmany&amp;order=asc\">[old to new]</a>" ; echo ($order == "asc") ? '[old to new]' : "<a href=\".?feed=$feed&amp;what=$what&amp;when=$when&amp;how=$how&amp;howmany=$howmany&amp;order=asc\">[old to new]</a>";
?></li> ?></li>
<li><a href="javascript:flag_all();mark_read()"><strong>Mark all read</strong></a></li> <li><a href="javascript:flag_all();mark_read()"><strong>Mark all read</strong></a></li>
@ -71,13 +60,13 @@ $noedit = $_GET['noedit'];
<input type="hidden" name="return" /> <input type="hidden" name="return" />
<?php <?php
$links = fof_get_nav_links($_GET['feed'], $what, $_GET['when'], $which, $_GET['howmany']); $links = fof_get_nav_links($feed, $what, $when, $which, $howmany);
if($links) { ?> if($links) { ?>
<center><?php echo $links ?></center><?php <center><?php echo $links ?></center><?php
} }
$result = fof_get_items(fof_current_user(), $_GET['feed'], $what, $_GET['when'], $which, $_GET['howmany'], $order, $_GET['search']); $result = fof_get_items(fof_current_user(), $feed, $what, $when, $which, $howmany, $order, $search);
$first = true; $first = true;
@ -86,7 +75,7 @@ foreach($result as $row)
$item_id = $row['item_id']; $item_id = $row['item_id'];
if($first) print "<script>firstItem = 'i$item_id'; </script>"; if($first) print "<script>firstItem = 'i$item_id'; </script>";
$first = false; $first = false;
print '<div class="item '.($row['prefs']['hide_content'] ? 'hidden' : 'shown').'" id="i' . $item_id . '" onclick="return itemClicked(event)">'; print '<div class="item '.(!empty($row['prefs']['hide_content']) ? 'hidden' : 'shown').'" id="i' . $item_id . '" onclick="return itemClicked(event)">';
fof_render_item($row); fof_render_item($row);
print '</div>'; print '</div>';
} }

View File

@ -41,7 +41,7 @@ function fof_balancetags($text) {
// clear the shifter // clear the shifter
$tagqueue = ''; $tagqueue = '';
// Pop or Push // Pop or Push
if ($regex[1][0] == "/") { // End Tag if ($regex[1] && $regex[1][0] == "/") { // End Tag
$tag = strtolower(substr($regex[1],1)); $tag = strtolower(substr($regex[1],1));
// if too many closing tags // if too many closing tags
if($stacksize <= 0) { if($stacksize <= 0) {

View File

@ -16,10 +16,10 @@ $fof_no_login = true;
include_once("fof-main.php"); include_once("fof-main.php");
include_once("fof-render.php"); include_once("fof-render.php");
$user = intval($_GET['user']); $user = !empty($_GET['user']) ? intval($_GET['user']) : 0;
if(!isset($user)) die; if(!$user) die;
$format = $_GET['format']; $format = !empty($_GET['format']) ? $_GET['format'] : '';
$prefs = new FoF_Prefs($user); $prefs = new FoF_Prefs($user);
$sharing = $prefs->get("sharing"); $sharing = $prefs->get("sharing");
@ -45,10 +45,10 @@ if(isset($_GET['feed']))
} }
$when = NULL; $when = NULL;
if(preg_match('#^\d+/\d+/\d+$#s', $_GET['when'])) if(isset($_GET['when']) && preg_match('#^\d+/\d+/\d+$#s', $_GET['when']))
$when = $_GET['when']; $when = $_GET['when'];
$offset = intval($_GET['offset']); $offset = isset($_GET['offset']) ? intval($_GET['offset']) : 0;
$result = fof_get_items($user, $feed, $what, $when, $offset, 101); $result = fof_get_items($user, $feed, $what, $when, $offset, 101);
if (count($result) > 100) if (count($result) > 100)
@ -200,7 +200,6 @@ foreach($result as $item)
$item_id = $item['item_id']; $item_id = $item['item_id'];
$item_title = $item['item_title']; $item_title = $item['item_title'];
$item_content = $item['item_content']; $item_content = $item['item_content'];
$item_read = $item['item_read'];
$item_published = gmdate("Y-n-d g:ia", $item['item_published'] + $offset*60*60); $item_published = gmdate("Y-n-d g:ia", $item['item_published'] + $offset*60*60);
$item_cached = gmdate("Y-n-d g:ia", $item['item_cached'] + $offset*60*60); $item_cached = gmdate("Y-n-d g:ia", $item['item_cached'] + $offset*60*60);

View File

@ -29,26 +29,17 @@ fof_set_content_type();
$order = $fof_prefs_obj->get('feed_order'); $order = $fof_prefs_obj->get('feed_order');
$direction = $fof_prefs_obj->get('feed_direction'); $direction = $fof_prefs_obj->get('feed_direction');
if(!isset($_GET['what'])) $what = !empty($_GET['what']) ? $_GET['what'] : 'unread';
{ $when = !empty($_GET['when']) ? $_GET['when'] : NULL;
$what = "unread"; $search = !empty($_GET['search']) ? $_GET['search'] : NULL;
}
else
{
$what = $_GET['what'];
}
$when = $_GET['when'];
$search = $_GET['search'];
echo "<script>what='$what'; when='$when';</script>"; echo "<script>what='$what'; when='$when';</script>";
$feeds = fof_get_feeds(fof_current_user(), $order, $direction); $feeds = fof_get_feeds(fof_current_user(), $order, $direction);
$unread = $starred = $total = 0;
foreach($feeds as $row) foreach($feeds as $row)
{ {
$n++;
$unread += $row['feed_unread']; $unread += $row['feed_unread'];
$starred += $row['feed_starred']; $starred += $row['feed_starred'];
$total += $row['feed_items']; $total += $row['feed_items'];
@ -90,7 +81,6 @@ echo "<script>starred = $starred;</script>";
$tags = fof_get_tags(fof_current_user()); $tags = fof_get_tags(fof_current_user());
$n = 0; $n = 0;
foreach($tags as $tag) foreach($tags as $tag)
{ {
$tag_id = $tag['tag_id']; $tag_id = $tag['tag_id'];
@ -111,6 +101,7 @@ if($n)
</tr> </tr>
<?php <?php
$t = 0;
foreach($tags as $tag) foreach($tags as $tag)
{ {
$tag_name = $tag['tag_name']; $tag_name = $tag['tag_name'];
@ -268,16 +259,3 @@ foreach($feeds as $row)
</div> </div>
</div> </div>
<?php
$order = $_GET['order'];
$direction = $_GET['direction'];
if(!isset($order))
$order = "title";
if(!isset($direction))
$direction = "asc";
?>

View File

@ -11800,7 +11800,7 @@ class SimplePie_IRI
function parse_iri($iri) function parse_iri($iri)
{ {
preg_match('/^(([^:\/?#]+):)?(\/\/(\/*[^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/', $iri, $match); preg_match('/^(([^:\/?#]+):)?(\/\/(\/*[^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/', $iri, $match);
return array('scheme' => $match[2], 'authority' => $match[4], 'path' => $match[5], 'query' => $match[7], 'fragment' => $match[9]); return array('scheme' => $match[2], 'authority' => $match[4], 'path' => $match[5], 'query' => isset($match[7]) ? $match[7] : '', 'fragment' => isset($match[9]) ? $match[9] : '');
} }
/** /**

View File

@ -1,5 +1,5 @@
--- simplepie.php.orig 2014-11-24 02:39:30.050372020 +0300 --- simplepie.php.orig 2014-12-09 01:45:22.705342569 +0300
+++ simplepie.php 2014-11-24 02:38:16.290370007 +0300 +++ simplepie.php 2014-12-09 01:45:29.873342765 +0300
@@ -43,6 +43,10 @@ @@ -43,6 +43,10 @@
* @todo phpDoc comments * @todo phpDoc comments
*/ */
@ -1292,7 +1292,7 @@
$target->set_scheme($base->get_scheme()); $target->set_scheme($base->get_scheme());
$target->set_userinfo($base->get_userinfo()); $target->set_userinfo($base->get_userinfo());
$target->set_host($base->get_host()); $target->set_host($base->get_host());
@@ -11769,11 +11799,7 @@ class SimplePie_IRI @@ -11769,12 +11799,8 @@ class SimplePie_IRI
*/ */
function parse_iri($iri) function parse_iri($iri)
{ {
@ -1301,10 +1301,12 @@
- { - {
- $match[$i] = ''; - $match[$i] = '';
- } - }
- return array('scheme' => $match[2], 'authority' => $match[4], 'path' => $match[5], 'query' => $match[7], 'fragment' => $match[9]);
+ preg_match('/^(([^:\/?#]+):)?(\/\/(\/*[^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/', $iri, $match); + preg_match('/^(([^:\/?#]+):)?(\/\/(\/*[^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/', $iri, $match);
return array('scheme' => $match[2], 'authority' => $match[4], 'path' => $match[5], 'query' => $match[7], 'fragment' => $match[9]); + return array('scheme' => $match[2], 'authority' => $match[4], 'path' => $match[5], 'query' => isset($match[7]) ? $match[7] : '', 'fragment' => isset($match[9]) ? $match[9] : '');
} }
/**
@@ -12056,7 +12082,7 @@ class SimplePie_IRI @@ -12056,7 +12082,7 @@ class SimplePie_IRI
} }
else else