Migrate to MySQLi
parent
5bbda67f19
commit
2d156cc6f3
|
@ -32,6 +32,7 @@ New features in this version compared to the original 0.5
|
||||||
* Very simple CSS-based mobile view
|
* Very simple CSS-based mobile view
|
||||||
* Tables are using InnoDB, UTF-8 encoding, and foreign keys
|
* Tables are using InnoDB, UTF-8 encoding, and foreign keys
|
||||||
* Code is cleaned of PHP warnings/notices and compatible with PHP 5.4+
|
* Code is cleaned of PHP warnings/notices and compatible with PHP 5.4+
|
||||||
|
* PHP mysqli extension is used instead of deprecated mysql
|
||||||
|
|
||||||
TODO
|
TODO
|
||||||
----
|
----
|
||||||
|
@ -45,7 +46,7 @@ Requirements
|
||||||
------------
|
------------
|
||||||
|
|
||||||
* A web server running PHP 5 or later (nginx + php5-fpm or Apache).
|
* A web server running PHP 5 or later (nginx + php5-fpm or Apache).
|
||||||
* PHP extensions: mysql/mysqlnd, XML, PCRE, cURL, Zlib, mbstring, iconv.
|
* PHP extensions: mysqli/mysqlnd, XML, PCRE, cURL, Zlib, mbstring, iconv.
|
||||||
* MariaDB/MySQL 5 or later. MariaDB 5.5 or later with Barracuda storage format
|
* MariaDB/MySQL 5 or later. MariaDB 5.5 or later with Barracuda storage format
|
||||||
(innodb_file_format = barracuda) is recommended.
|
(innodb_file_format = barracuda) is recommended.
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ class FoF_Prefs
|
||||||
$this->user_id = $user_id;
|
$this->user_id = $user_id;
|
||||||
|
|
||||||
$result = fof_safe_query("select user_prefs from $FOF_USER_TABLE where user_id = %d", $user_id);
|
$result = fof_safe_query("select user_prefs from $FOF_USER_TABLE where user_id = %d", $user_id);
|
||||||
$row = mysql_fetch_array($result);
|
$row = fof_db_get_row($result);
|
||||||
$prefs = unserialize($row['user_prefs']);
|
$prefs = unserialize($row['user_prefs']);
|
||||||
if(!is_array($prefs))
|
if(!is_array($prefs))
|
||||||
$prefs = array();
|
$prefs = array();
|
||||||
|
@ -34,7 +34,7 @@ class FoF_Prefs
|
||||||
if($user_id != 1)
|
if($user_id != 1)
|
||||||
{
|
{
|
||||||
$result = fof_safe_query("select user_prefs from $FOF_USER_TABLE where user_id = 1");
|
$result = fof_safe_query("select user_prefs from $FOF_USER_TABLE where user_id = 1");
|
||||||
$row = mysql_fetch_array($result);
|
$row = fof_db_get_row($result);
|
||||||
$admin_prefs = unserialize($row['user_prefs']);
|
$admin_prefs = unserialize($row['user_prefs']);
|
||||||
if(!is_array($admin_prefs)) $admin_prefs = array();
|
if(!is_array($admin_prefs)) $admin_prefs = array();
|
||||||
$this->admin_prefs = $admin_prefs;
|
$this->admin_prefs = $admin_prefs;
|
||||||
|
|
142
fof-db.php
142
fof-db.php
|
@ -24,9 +24,8 @@ $FOF_USER_TABLE = FOF_USER_TABLE;
|
||||||
function fof_db_connect()
|
function fof_db_connect()
|
||||||
{
|
{
|
||||||
global $fof_connection;
|
global $fof_connection;
|
||||||
|
$fof_connection = mysqli_connect('p:'.FOF_DB_HOST, FOF_DB_USER, FOF_DB_PASS, FOF_DB_DBNAME)
|
||||||
$fof_connection = mysql_pconnect(FOF_DB_HOST, FOF_DB_USER, FOF_DB_PASS) or die("<br><br>Cannot connect to database. Please update configuration in <b>fof-config.php</b>. Mysql says: <i>" . mysql_error() . "</i>");
|
or die("<br><br>Cannot connect to database. Please update configuration in <b>fof-config.php</b>. MySQL says: <i>" . mysqli_connect_error() . "</i>");
|
||||||
mysql_select_db(FOF_DB_DBNAME, $fof_connection) or die("<br><br>Cannot select database. Please update configuration in <b>fof-config.php</b>. Mysql says: <i>" . mysql_error() . "</i>");
|
|
||||||
fof_db_query("SET NAMES utf8");
|
fof_db_query("SET NAMES utf8");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,12 +38,14 @@ function fof_db_optimize()
|
||||||
|
|
||||||
function fof_safe_query(/* $query, [$args...]*/)
|
function fof_safe_query(/* $query, [$args...]*/)
|
||||||
{
|
{
|
||||||
$args = func_get_args();
|
global $fof_connection;
|
||||||
|
$args = func_get_args();
|
||||||
$query = array_shift($args);
|
$query = array_shift($args);
|
||||||
if(isset($args[0]) && is_array($args[0])) $args = $args[0];
|
if (isset($args[0]) && is_array($args[0]))
|
||||||
$args = array_map('mysql_real_escape_string', $args);
|
$args = $args[0];
|
||||||
|
foreach ($args as &$a)
|
||||||
|
$a = $fof_connection->real_escape_string($a);
|
||||||
$query = vsprintf($query, $args);
|
$query = vsprintf($query, $args);
|
||||||
|
|
||||||
return fof_db_query($query);
|
return fof_db_query($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,11 +56,13 @@ function fof_db_query($sql, $live=0)
|
||||||
list($usec, $sec) = explode(" ", microtime());
|
list($usec, $sec) = explode(" ", microtime());
|
||||||
$t1 = (float)$sec + (float)$usec;
|
$t1 = (float)$sec + (float)$usec;
|
||||||
|
|
||||||
$result = mysql_query($sql, $fof_connection);
|
$result = $fof_connection->query($sql);
|
||||||
|
|
||||||
$num = $affected = 0;
|
$num = $affected = 0;
|
||||||
if(is_resource($result)) $num = mysql_num_rows($result);
|
if (is_object($result))
|
||||||
if($result) $affected = mysql_affected_rows($fof_connection);
|
$num = $result->num_rows;
|
||||||
|
if ($result)
|
||||||
|
$affected = $fof_connection->affected_rows;
|
||||||
|
|
||||||
list($usec, $sec) = explode(" ", microtime());
|
list($usec, $sec) = explode(" ", microtime());
|
||||||
$t2 = (float)$sec + (float)$usec;
|
$t2 = (float)$sec + (float)$usec;
|
||||||
|
@ -67,18 +70,29 @@ function fof_db_query($sql, $live=0)
|
||||||
$logmessage = sprintf("%.3f: [%s] (%d / %d)", $elapsed, $sql, $num, $affected);
|
$logmessage = sprintf("%.3f: [%s] (%d / %d)", $elapsed, $sql, $num, $affected);
|
||||||
fof_log($logmessage, "query");
|
fof_log($logmessage, "query");
|
||||||
|
|
||||||
if($live)
|
if ($live)
|
||||||
{
|
{
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(mysql_errno($fof_connection))
|
if ($fof_connection->errno)
|
||||||
fof_die_mysql_error("Cannot run query '$sql': ".mysql_errno($fof_connection).": ".mysql_error($fof_connection));
|
fof_die_mysql_error("Cannot run query '$sql': ".$fof_connection->errno.": ".$fof_connection->error);
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function fof_num_rows($result)
|
||||||
|
{
|
||||||
|
return $result ? $result->num_rows : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function fof_insert_id()
|
||||||
|
{
|
||||||
|
global $fof_connection;
|
||||||
|
return $fof_connection->insert_id;
|
||||||
|
}
|
||||||
|
|
||||||
function fof_die_mysql_error($error)
|
function fof_die_mysql_error($error)
|
||||||
{
|
{
|
||||||
ob_start();
|
ob_start();
|
||||||
|
@ -93,7 +107,7 @@ function fof_die_mysql_error($error)
|
||||||
|
|
||||||
function fof_db_get_row($result)
|
function fof_db_get_row($result)
|
||||||
{
|
{
|
||||||
return mysql_fetch_array($result);
|
return $result->fetch_assoc();
|
||||||
}
|
}
|
||||||
|
|
||||||
function fof_db_get_value($sql)
|
function fof_db_get_value($sql)
|
||||||
|
@ -101,7 +115,7 @@ function fof_db_get_value($sql)
|
||||||
if (!($result = fof_db_query($sql)) ||
|
if (!($result = fof_db_query($sql)) ||
|
||||||
!($row = fof_db_get_row($result)))
|
!($row = fof_db_get_row($result)))
|
||||||
return NULL;
|
return NULL;
|
||||||
return $row[0];
|
return reset($row);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -214,10 +228,8 @@ function fof_db_is_subscribed($user_id, $feed_url)
|
||||||
|
|
||||||
$result = fof_safe_query("select $FOF_SUBSCRIPTION_TABLE.feed_id from $FOF_FEED_TABLE, $FOF_SUBSCRIPTION_TABLE where feed_url='%s' and $FOF_SUBSCRIPTION_TABLE.feed_id = $FOF_FEED_TABLE.feed_id and $FOF_SUBSCRIPTION_TABLE.user_id = %d", $feed_url, $user_id);
|
$result = fof_safe_query("select $FOF_SUBSCRIPTION_TABLE.feed_id from $FOF_FEED_TABLE, $FOF_SUBSCRIPTION_TABLE where feed_url='%s' and $FOF_SUBSCRIPTION_TABLE.feed_id = $FOF_FEED_TABLE.feed_id and $FOF_SUBSCRIPTION_TABLE.user_id = %d", $feed_url, $user_id);
|
||||||
|
|
||||||
if(mysql_num_rows($result) == 0)
|
if (fof_num_rows($result) == 0)
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -228,12 +240,7 @@ function fof_db_get_feed_by_url($feed_url)
|
||||||
|
|
||||||
$result = fof_safe_query("select * from $FOF_FEED_TABLE where feed_url='%s'", $feed_url);
|
$result = fof_safe_query("select * from $FOF_FEED_TABLE where feed_url='%s'", $feed_url);
|
||||||
|
|
||||||
if (mysql_num_rows($result) == 0)
|
return fof_db_get_row($result);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
$row = mysql_fetch_array($result);
|
|
||||||
|
|
||||||
return $row;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function fof_db_get_feed_by_id($feed_id, $user_id = false)
|
function fof_db_get_feed_by_id($feed_id, $user_id = false)
|
||||||
|
@ -245,12 +252,7 @@ function fof_db_get_feed_by_id($feed_id, $user_id = false)
|
||||||
$j = "JOIN $FOF_SUBSCRIPTION_TABLE s ON s.user_id=".intval($user_id)." AND s.feed_id=s.feed_id";
|
$j = "JOIN $FOF_SUBSCRIPTION_TABLE s ON s.user_id=".intval($user_id)." AND s.feed_id=s.feed_id";
|
||||||
$result = fof_safe_query("select * from $FOF_FEED_TABLE f $j where f.feed_id=%d", $feed_id);
|
$result = fof_safe_query("select * from $FOF_FEED_TABLE f $j where f.feed_id=%d", $feed_id);
|
||||||
|
|
||||||
if (mysql_num_rows($result) == 0)
|
return fof_db_get_row($result);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
$row = mysql_fetch_array($result);
|
|
||||||
|
|
||||||
return $row;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function fof_db_add_feed($url, $title, $link, $description)
|
function fof_db_add_feed($url, $title, $link, $description)
|
||||||
|
@ -259,7 +261,7 @@ function fof_db_add_feed($url, $title, $link, $description)
|
||||||
|
|
||||||
fof_safe_query("insert into $FOF_FEED_TABLE (feed_url,feed_title,feed_link,feed_description) values ('%s', '%s', '%s', '%s')", $url, $title, $link, $description);
|
fof_safe_query("insert into $FOF_FEED_TABLE (feed_url,feed_title,feed_link,feed_description) values ('%s', '%s', '%s', '%s')", $url, $title, $link, $description);
|
||||||
|
|
||||||
return mysql_insert_id($fof_connection);
|
return fof_insert_id();
|
||||||
}
|
}
|
||||||
|
|
||||||
function fof_db_add_subscription($user_id, $feed_id)
|
function fof_db_add_subscription($user_id, $feed_id)
|
||||||
|
@ -298,12 +300,9 @@ function fof_db_find_item($feed_id, $item_guid)
|
||||||
global $FOF_FEED_TABLE, $FOF_ITEM_TABLE, $FOF_SUBSCRIPTION_TABLE, $fof_connection;
|
global $FOF_FEED_TABLE, $FOF_ITEM_TABLE, $FOF_SUBSCRIPTION_TABLE, $fof_connection;
|
||||||
|
|
||||||
$result = fof_safe_query("select item_id from $FOF_ITEM_TABLE where feed_id=%d and item_guid='%s'", $feed_id, $item_guid);
|
$result = fof_safe_query("select item_id from $FOF_ITEM_TABLE where feed_id=%d and item_guid='%s'", $feed_id, $item_guid);
|
||||||
$row = mysql_fetch_array($result);
|
$row = fof_db_get_row($result);
|
||||||
|
|
||||||
if (mysql_num_rows($result) == 0)
|
return $row ? $row['item_id'] : NULL;
|
||||||
return NULL;
|
|
||||||
else
|
|
||||||
return($row['item_id']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$fof_db_item_fields = array('item_guid', 'item_link', 'item_title', 'item_author', 'item_content', 'item_cached', 'item_published', 'item_updated');
|
$fof_db_item_fields = array('item_guid', 'item_link', 'item_title', 'item_author', 'item_content', 'item_cached', 'item_published', 'item_updated');
|
||||||
|
@ -311,13 +310,17 @@ function fof_db_add_item($feed_id, $item)
|
||||||
{
|
{
|
||||||
global $FOF_FEED_TABLE, $FOF_ITEM_TABLE, $FOF_SUBSCRIPTION_TABLE, $fof_connection, $fof_db_item_fields;
|
global $FOF_FEED_TABLE, $FOF_ITEM_TABLE, $FOF_SUBSCRIPTION_TABLE, $fof_connection, $fof_db_item_fields;
|
||||||
|
|
||||||
|
$args = array();
|
||||||
$sql = "insert into $FOF_ITEM_TABLE (feed_id, ".implode(",", $fof_db_item_fields).") values (".intval($feed_id);
|
$sql = "insert into $FOF_ITEM_TABLE (feed_id, ".implode(",", $fof_db_item_fields).") values (".intval($feed_id);
|
||||||
foreach ($fof_db_item_fields as $k)
|
foreach ($fof_db_item_fields as $k)
|
||||||
$sql .= ", '".mysql_real_escape_string($item[$k])."'";
|
{
|
||||||
|
$sql .= ", '%s'";
|
||||||
|
$args[] = $item[$k];
|
||||||
|
}
|
||||||
$sql .= ")";
|
$sql .= ")";
|
||||||
fof_db_query($sql);
|
fof_safe_query($sql, $args);
|
||||||
|
|
||||||
return mysql_insert_id($fof_connection);
|
return fof_insert_id();
|
||||||
}
|
}
|
||||||
|
|
||||||
function fof_db_get_items($user_id = 1, $feed = NULL, $what = "unread",
|
function fof_db_get_items($user_id = 1, $feed = NULL, $what = "unread",
|
||||||
|
@ -409,10 +412,10 @@ function fof_db_get_items($user_id = 1, $feed = NULL, $what = "unread",
|
||||||
|
|
||||||
$query = "$select FROM $from $where $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 (fof_num_rows($result) == 0)
|
||||||
return array();
|
return array();
|
||||||
|
|
||||||
while ($row = mysql_fetch_assoc($result))
|
while ($row = fof_db_get_row($result))
|
||||||
{
|
{
|
||||||
$row['prefs'] = unserialize($row['subscription_prefs']);
|
$row['prefs'] = unserialize($row['subscription_prefs']);
|
||||||
$array[] = $row;
|
$array[] = $row;
|
||||||
|
@ -452,7 +455,7 @@ function fof_db_get_item($user_id, $item_id)
|
||||||
|
|
||||||
$result = fof_safe_query($query, $item_id);
|
$result = fof_safe_query($query, $item_id);
|
||||||
|
|
||||||
$item = mysql_fetch_assoc($result);
|
$item = fof_db_get_row($result);
|
||||||
$item['tags'] = array();
|
$item['tags'] = array();
|
||||||
if ($user_id)
|
if ($user_id)
|
||||||
{
|
{
|
||||||
|
@ -575,7 +578,7 @@ function fof_db_item_has_tags($item_id)
|
||||||
global $FOF_ITEM_TAG_TABLE;
|
global $FOF_ITEM_TAG_TABLE;
|
||||||
|
|
||||||
$result = fof_safe_query("select count(*) as \"count\" from $FOF_ITEM_TAG_TABLE where item_id=%d and tag_id > 2", $item_id);
|
$result = fof_safe_query("select count(*) as \"count\" from $FOF_ITEM_TAG_TABLE where item_id=%d and tag_id > 2", $item_id);
|
||||||
$row = mysql_fetch_array($result);
|
$row = fof_db_get_row($result);
|
||||||
|
|
||||||
return $row["count"];
|
return $row["count"];
|
||||||
}
|
}
|
||||||
|
@ -585,7 +588,7 @@ function fof_db_get_unread_count($user_id)
|
||||||
global $FOF_ITEM_TAG_TABLE;
|
global $FOF_ITEM_TAG_TABLE;
|
||||||
|
|
||||||
$result = fof_safe_query("select count(*) as \"count\" from $FOF_ITEM_TAG_TABLE where tag_id = 1 and user_id = %d", $user_id);
|
$result = fof_safe_query("select count(*) as \"count\" from $FOF_ITEM_TAG_TABLE where tag_id = 1 and user_id = %d", $user_id);
|
||||||
$row = mysql_fetch_array($result);
|
$row = fof_db_get_row($result);
|
||||||
|
|
||||||
return $row["count"];
|
return $row["count"];
|
||||||
}
|
}
|
||||||
|
@ -600,10 +603,8 @@ function fof_db_get_tag_unread($user_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
$counts = array();
|
$counts = array();
|
||||||
while($row = fof_db_get_row($result))
|
while ($row = fof_db_get_row($result))
|
||||||
{
|
|
||||||
$counts[$row['tag_id']] = $row['count'];
|
$counts[$row['tag_id']] = $row['count'];
|
||||||
}
|
|
||||||
|
|
||||||
return $counts;
|
return $counts;
|
||||||
}
|
}
|
||||||
|
@ -614,9 +615,7 @@ function fof_db_get_tags($user_id)
|
||||||
|
|
||||||
static $cache = array();
|
static $cache = array();
|
||||||
if (isset($cache[$user_id]))
|
if (isset($cache[$user_id]))
|
||||||
{
|
|
||||||
return $cache[$user_id];
|
return $cache[$user_id];
|
||||||
}
|
|
||||||
|
|
||||||
$sql = "SELECT $FOF_TAG_TABLE.tag_id, $FOF_TAG_TABLE.tag_name, count($FOF_ITEM_TAG_TABLE.item_id) as count
|
$sql = "SELECT $FOF_TAG_TABLE.tag_id, $FOF_TAG_TABLE.tag_name, count($FOF_ITEM_TAG_TABLE.item_id) as count
|
||||||
FROM $FOF_TAG_TABLE
|
FROM $FOF_TAG_TABLE
|
||||||
|
@ -627,12 +626,9 @@ function fof_db_get_tags($user_id)
|
||||||
$result = fof_safe_query($sql, $user_id);
|
$result = fof_safe_query($sql, $user_id);
|
||||||
$tags = array();
|
$tags = array();
|
||||||
while ($row = fof_db_get_row($result))
|
while ($row = fof_db_get_row($result))
|
||||||
{
|
|
||||||
$tags[$row['tag_id']] = $row;
|
$tags[$row['tag_id']] = $row;
|
||||||
}
|
|
||||||
|
|
||||||
$cache[$user_id] = $tags;
|
$cache[$user_id] = $tags;
|
||||||
|
|
||||||
return $tags;
|
return $tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -640,16 +636,11 @@ function fof_db_get_tag_id_map()
|
||||||
{
|
{
|
||||||
global $FOF_TAG_TABLE;
|
global $FOF_TAG_TABLE;
|
||||||
|
|
||||||
$sql = "select * from $FOF_TAG_TABLE";
|
$result = fof_safe_query("select * from $FOF_TAG_TABLE");
|
||||||
|
|
||||||
$result = fof_safe_query($sql);
|
|
||||||
|
|
||||||
$tags = array();
|
$tags = array();
|
||||||
|
while ($row = fof_db_get_row($result))
|
||||||
while($row = fof_db_get_row($result))
|
|
||||||
{
|
|
||||||
$tags[$row['tag_id']] = $row['tag_name'];
|
$tags[$row['tag_id']] = $row['tag_name'];
|
||||||
}
|
|
||||||
|
|
||||||
return $tags;
|
return $tags;
|
||||||
}
|
}
|
||||||
|
@ -660,7 +651,7 @@ function fof_db_create_tag($user_id, $tag)
|
||||||
|
|
||||||
fof_safe_query("insert into $FOF_TAG_TABLE (tag_name) values ('%s')", $tag);
|
fof_safe_query("insert into $FOF_TAG_TABLE (tag_name) values ('%s')", $tag);
|
||||||
|
|
||||||
return(mysql_insert_id($fof_connection));
|
return fof_insert_id();
|
||||||
}
|
}
|
||||||
|
|
||||||
function fof_db_get_tag_by_name($user_id, $tag)
|
function fof_db_get_tag_by_name($user_id, $tag)
|
||||||
|
@ -669,14 +660,9 @@ function fof_db_get_tag_by_name($user_id, $tag)
|
||||||
|
|
||||||
$result = fof_safe_query("select $FOF_TAG_TABLE.tag_id from $FOF_TAG_TABLE where $FOF_TAG_TABLE.tag_name = '%s'", $tag);
|
$result = fof_safe_query("select $FOF_TAG_TABLE.tag_id from $FOF_TAG_TABLE where $FOF_TAG_TABLE.tag_name = '%s'", $tag);
|
||||||
|
|
||||||
if(mysql_num_rows($result) == 0)
|
$row = fof_db_get_row($result);
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
$row = mysql_fetch_array($result);
|
return $row ? $row['tag_id'] : NULL;
|
||||||
|
|
||||||
return $row['tag_id'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function fof_db_mark_unread($user_id, $items)
|
function fof_db_mark_unread($user_id, $items)
|
||||||
|
@ -807,7 +793,7 @@ function fof_db_get_user($username, $userid = NULL)
|
||||||
$result = fof_safe_query("select * from $FOF_USER_TABLE where user_id = %d", $userid);
|
$result = fof_safe_query("select * from $FOF_USER_TABLE where user_id = %d", $userid);
|
||||||
else
|
else
|
||||||
$result = fof_safe_query("select * from $FOF_USER_TABLE where user_name = '%s'", $username);
|
$result = fof_safe_query("select * from $FOF_USER_TABLE where user_name = '%s'", $username);
|
||||||
$row = mysql_fetch_array($result);
|
$row = fof_db_get_row($result);
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -864,10 +850,10 @@ function fof_db_authenticate($user_name, $user_password_hash)
|
||||||
|
|
||||||
$result = fof_safe_query("select * from $FOF_USER_TABLE where user_name = '%s' and user_password_hash = '%s'", $user_name, $user_password_hash);
|
$result = fof_safe_query("select * from $FOF_USER_TABLE where user_name = '%s' and user_password_hash = '%s'", $user_name, $user_password_hash);
|
||||||
|
|
||||||
if (mysql_num_rows($result) == 0)
|
if (fof_num_rows($result) == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
$row = mysql_fetch_array($result);
|
$row = fof_db_get_row($result);
|
||||||
|
|
||||||
fof_set_current_user($row);
|
fof_set_current_user($row);
|
||||||
|
|
||||||
|
@ -889,8 +875,8 @@ function fof_db_get_is_duplicate_item($item_id, $item_guid, $content_md5)
|
||||||
" WHERE item_id IN (".join(",",$dups).") AND $FOF_SUBSCRIPTION_TABLE.feed_id=$FOF_ITEM_TABLE.feed_id"
|
" WHERE item_id IN (".join(",",$dups).") AND $FOF_SUBSCRIPTION_TABLE.feed_id=$FOF_ITEM_TABLE.feed_id"
|
||||||
);
|
);
|
||||||
$users = array();
|
$users = array();
|
||||||
while ($row = mysql_fetch_row($result))
|
while ($row = fof_db_get_row($result))
|
||||||
$users[] = $row[0];
|
$users[] = reset($row);
|
||||||
return $users;
|
return $users;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -921,7 +907,7 @@ function fof_db_get_top_readers($days, $count = NULL)
|
||||||
group by u.user_id order by posts desc
|
group by u.user_id order by posts desc
|
||||||
".(!is_null($count) ? "limit $count" : ""));
|
".(!is_null($count) ? "limit $count" : ""));
|
||||||
$readers = array();
|
$readers = array();
|
||||||
while ($row = mysql_fetch_assoc($result))
|
while ($row = fof_db_get_row($result))
|
||||||
$readers[] = $row;
|
$readers[] = $row;
|
||||||
return $readers;
|
return $readers;
|
||||||
}
|
}
|
||||||
|
@ -936,7 +922,7 @@ function fof_db_get_most_popular_feeds($count = NULL)
|
||||||
group by f.feed_id having readers>1 order by readers desc
|
group by f.feed_id having readers>1 order by readers desc
|
||||||
".(!is_null($count) ? "limit $count" : ""));
|
".(!is_null($count) ? "limit $count" : ""));
|
||||||
$feeds = array();
|
$feeds = array();
|
||||||
while ($row = mysql_fetch_assoc($result))
|
while ($row = fof_db_get_row($result))
|
||||||
$feeds[] = $row;
|
$feeds[] = $row;
|
||||||
return $feeds;
|
return $feeds;
|
||||||
}
|
}
|
||||||
|
@ -944,11 +930,11 @@ function fof_db_get_most_popular_feeds($count = NULL)
|
||||||
function fof_db_get_feed_single_user($id)
|
function fof_db_get_feed_single_user($id)
|
||||||
{
|
{
|
||||||
global $FOF_SUBSCRIPTION_TABLE;
|
global $FOF_SUBSCRIPTION_TABLE;
|
||||||
$result = fof_safe_query("SELECT user_id, COUNT(user_id) FROM $FOF_SUBSCRIPTION_TABLE WHERE feed_id=%d GROUP BY feed_id", $id);
|
$result = fof_safe_query("SELECT user_id, COUNT(user_id) n FROM $FOF_SUBSCRIPTION_TABLE WHERE feed_id=%d GROUP BY feed_id", $id);
|
||||||
$row = mysql_fetch_row($result);
|
$row = fof_db_get_row($result);
|
||||||
if (!$row || $row[1] > 1)
|
if (!$row || $row['n'] > 1)
|
||||||
return NULL;
|
return NULL;
|
||||||
return $row[0];
|
return $row['user_id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
function fof_cache_fn($key)
|
function fof_cache_fn($key)
|
||||||
|
|
|
@ -476,7 +476,7 @@ function fof_delete_subscription($user_id, $feed_id)
|
||||||
{
|
{
|
||||||
fof_db_delete_subscription($user_id, $feed_id);
|
fof_db_delete_subscription($user_id, $feed_id);
|
||||||
|
|
||||||
if(mysql_num_rows(fof_db_get_subscribed_users($feed_id)) == 0)
|
if (fof_num_rows(fof_db_get_subscribed_users($feed_id)) == 0)
|
||||||
{
|
{
|
||||||
fof_db_delete_feed($feed_id);
|
fof_db_delete_feed($feed_id);
|
||||||
}
|
}
|
||||||
|
|
98
install.php
98
install.php
|
@ -34,7 +34,7 @@ function get_curl_version()
|
||||||
$php_ok = (function_exists('version_compare') && version_compare(phpversion(), '4.3.2', '>='));
|
$php_ok = (function_exists('version_compare') && version_compare(phpversion(), '4.3.2', '>='));
|
||||||
$xml_ok = extension_loaded('xml');
|
$xml_ok = extension_loaded('xml');
|
||||||
$pcre_ok = extension_loaded('pcre');
|
$pcre_ok = extension_loaded('pcre');
|
||||||
$mysql_ok = extension_loaded('mysql');
|
$mysql_ok = extension_loaded('mysqli');
|
||||||
|
|
||||||
$curl_ok = (extension_loaded('curl') && version_compare(get_curl_version(), '7.10.5', '>='));
|
$curl_ok = (extension_loaded('curl') && version_compare(get_curl_version(), '7.10.5', '>='));
|
||||||
$zlib_ok = extension_loaded('zlib');
|
$zlib_ok = extension_loaded('zlib');
|
||||||
|
@ -126,7 +126,7 @@ else
|
||||||
if($mysql_ok) echo "<span class='pass'>MySQL ok...</span> ";
|
if($mysql_ok) echo "<span class='pass'>MySQL ok...</span> ";
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
echo "<br><span class='fail'>Your PHP installation is missing the MySQL extension!</span> This is required by Feed on Feeds. Sorry!";
|
echo "<br><span class='fail'>Your PHP installation is missing the MySQLi extension!</span> This is required by Feed on Feeds. Sorry!";
|
||||||
echo "</div></body></html>";
|
echo "</div></body></html>";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
@ -248,8 +248,7 @@ CREATE TABLE IF NOT EXISTS `$FOF_SUBSCRIPTION_TABLE` (
|
||||||
EOQ;
|
EOQ;
|
||||||
|
|
||||||
foreach($tables as $table)
|
foreach($tables as $table)
|
||||||
if(!fof_db_query($table, 1))
|
fof_db_query($table, 1);
|
||||||
exit("Can't create table. MySQL says: <b>" . mysql_error() . "</b><br>");
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
Tables exist.<hr>
|
Tables exist.<hr>
|
||||||
|
@ -259,87 +258,82 @@ Upgrading schema...
|
||||||
|
|
||||||
function add_fk($show_create_table, $table, $column, $ref_table, $action = 'on delete cascade on update cascade')
|
function add_fk($show_create_table, $table, $column, $ref_table, $action = 'on delete cascade on update cascade')
|
||||||
{
|
{
|
||||||
if (!strpos($show_create_table, "FOREIGN KEY (`$column`)") &&
|
if (!strpos($show_create_table, "FOREIGN KEY (`$column`)"))
|
||||||
!fof_db_query("alter table $table add foreign key ($column) references $ref_table ($column) $action"))
|
fof_db_query("alter table $table add foreign key ($column) references $ref_table ($column) $action");
|
||||||
exit("Can't add foreign key on $table.$column. MySQL says: <b>" . mysql_error() . "</b><br>");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = fof_db_query("show table status");
|
$r = fof_db_query("show table status");
|
||||||
while ($row = mysql_fetch_assoc($r))
|
while ($row = fof_db_get_row($r))
|
||||||
{
|
{
|
||||||
$table = $row['Name'];
|
$table = $row['Name'];
|
||||||
$alter = array();
|
$alter = array();
|
||||||
if (strtolower($row['Engine']) === 'myisam')
|
if (strtolower($row['Engine']) === 'myisam')
|
||||||
{
|
|
||||||
$alter[] = 'engine=innodb';
|
$alter[] = 'engine=innodb';
|
||||||
}
|
|
||||||
if (strpos($row['Collation'], 'utf8') === false)
|
if (strpos($row['Collation'], 'utf8') === false)
|
||||||
{
|
|
||||||
$alter[] = 'convert to character set utf8 collate utf8_unicode_ci';
|
$alter[] = 'convert to character set utf8 collate utf8_unicode_ci';
|
||||||
}
|
|
||||||
$r2 = fof_db_query("desc $table");
|
$r2 = fof_db_query("desc $table");
|
||||||
while ($row2 = mysql_fetch_assoc($r2))
|
while ($row2 = fof_db_get_row($r2))
|
||||||
{
|
|
||||||
if (strtolower($row2['Type']) == 'mediumtext')
|
if (strtolower($row2['Type']) == 'mediumtext')
|
||||||
{
|
|
||||||
$alter[] = 'change '.$row2['Field'].' '.$row2['Field'].' text'.(strtolower($row2['Null']) == 'no' ? ' not null' : '');
|
$alter[] = 'change '.$row2['Field'].' '.$row2['Field'].' text'.(strtolower($row2['Null']) == 'no' ? ' not null' : '');
|
||||||
}
|
if ($alter)
|
||||||
}
|
fof_db_query("alter table $table ".implode(', ', $alter));
|
||||||
if ($alter && !fof_db_query("alter table $table ".implode(', ', $alter)))
|
|
||||||
{
|
|
||||||
exit("Can't change engine or encoding of $table. MySQL says: <b>" . mysql_error() . "</b><br>");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mysql_num_rows(fof_db_query("show columns from $FOF_FEED_TABLE like 'feed_image_cache_date'")) &&
|
if (!fof_num_rows(fof_db_query("show columns from $FOF_FEED_TABLE like 'feed_image_cache_date'")))
|
||||||
!fof_db_query("ALTER TABLE $FOF_FEED_TABLE ADD `feed_image_cache_date` INT( 11 ) DEFAULT '0' AFTER `feed_image`;"))
|
fof_db_query("ALTER TABLE $FOF_FEED_TABLE ADD `feed_image_cache_date` INT( 11 ) DEFAULT '0' AFTER `feed_image`;");
|
||||||
exit("Can't add column feed_image_cache_date to table $FOF_FEED_TABLE. MySQL says: <b>" . mysql_error() . "</b><br>");
|
|
||||||
|
|
||||||
if (!mysql_num_rows(fof_db_query("show columns from $FOF_USER_TABLE like 'user_password_hash'")) &&
|
if (!fof_num_rows(fof_db_query("show columns from $FOF_USER_TABLE like 'user_password_hash'")))
|
||||||
(!fof_db_query("ALTER TABLE $FOF_USER_TABLE CHANGE `user_password` `user_password_hash` VARCHAR( 32 ) NOT NULL") ||
|
{
|
||||||
!fof_db_query("update $FOF_USER_TABLE set user_password_hash = md5(concat(user_password_hash, user_name))")))
|
fof_db_query("ALTER TABLE $FOF_USER_TABLE CHANGE `user_password` `user_password_hash` VARCHAR( 32 ) NOT NULL");
|
||||||
exit("Can't change column user_password to user_password_hash. MySQL says: <b>" . mysql_error() . "</b><br>");
|
fof_db_query("update $FOF_USER_TABLE set user_password_hash = md5(concat(user_password_hash, user_name))");
|
||||||
|
}
|
||||||
|
|
||||||
if (!mysql_num_rows(fof_db_query("show columns from $FOF_FEED_TABLE like 'feed_cache_attempt_date'")) &&
|
if (!fof_num_rows(fof_db_query("show columns from $FOF_FEED_TABLE like 'feed_cache_attempt_date'")))
|
||||||
!fof_db_query("ALTER TABLE $FOF_FEED_TABLE ADD `feed_cache_attempt_date` INT( 11 ) DEFAULT '0' AFTER `feed_cache_date`;"))
|
fof_db_query("ALTER TABLE $FOF_FEED_TABLE ADD `feed_cache_attempt_date` INT( 11 ) DEFAULT '0' AFTER `feed_cache_date`;");
|
||||||
exit("Can't add column feed_cache_attempt_date to table $FOF_FEED_TABLE. MySQL says: <b>" . mysql_error() . "</b><br>");
|
|
||||||
|
|
||||||
if (!mysql_num_rows(fof_db_query("show columns from $FOF_ITEM_TABLE like 'item_author'")) &&
|
if (!fof_num_rows(fof_db_query("show columns from $FOF_ITEM_TABLE like 'item_author'")))
|
||||||
!fof_db_query("ALTER TABLE $FOF_ITEM_TABLE ADD `item_author` text NOT NULL AFTER `item_title`;"))
|
fof_db_query("ALTER TABLE $FOF_ITEM_TABLE ADD `item_author` text NOT NULL AFTER `item_title`;");
|
||||||
exit("Can't add column item_author to table $FOF_ITEM_TABLE. MySQL says: <b>" . mysql_error() . "</b><br>");
|
|
||||||
|
|
||||||
$check = mysql_fetch_row(fof_db_query("show create table $FOF_ITEM_TABLE"));
|
$check = fof_db_get_row(fof_db_query("show create table $FOF_ITEM_TABLE"));
|
||||||
if (strpos($check[1], 'KEY `feed_id`') !== false &&
|
if (strpos($check[1], 'KEY `feed_id`') !== false)
|
||||||
!fof_db_query("alter table $FOF_ITEM_TABLE drop key feed_id, add key item_published (item_published)"))
|
fof_db_query("alter table $FOF_ITEM_TABLE drop key feed_id, add key item_published (item_published)");
|
||||||
exit("Can't drop key feed id / add key item_published to table $FOF_ITEM_TABLE. MySQL says: <b>" . mysql_error() . "</b><br>");
|
|
||||||
|
|
||||||
add_fk($check[1], $FOF_ITEM_TABLE, 'feed_id', $FOF_FEED_TABLE, 'on update cascade');
|
add_fk($check[1], $FOF_ITEM_TABLE, 'feed_id', $FOF_FEED_TABLE, 'on update cascade');
|
||||||
|
|
||||||
$check = mysql_fetch_row(fof_db_query("show create table $FOF_ITEM_TAG_TABLE"));
|
$check = fof_db_get_row(fof_db_query("show create table $FOF_ITEM_TAG_TABLE"));
|
||||||
|
|
||||||
add_fk($check[1], $FOF_ITEM_TAG_TABLE, 'tag_id', $FOF_TAG_TABLE);
|
add_fk($check[1], $FOF_ITEM_TAG_TABLE, 'tag_id', $FOF_TAG_TABLE);
|
||||||
add_fk($check[1], $FOF_ITEM_TAG_TABLE, 'user_id', $FOF_USER_TABLE);
|
add_fk($check[1], $FOF_ITEM_TAG_TABLE, 'user_id', $FOF_USER_TABLE);
|
||||||
add_fk($check[1], $FOF_ITEM_TAG_TABLE, 'item_id', $FOF_ITEM_TABLE);
|
add_fk($check[1], $FOF_ITEM_TAG_TABLE, 'item_id', $FOF_ITEM_TABLE);
|
||||||
|
|
||||||
if (strpos($check[1], 'PRIMARY KEY (`user_id`,`item_id`,`tag_id`)') !== false &&
|
if (strpos($check[1], 'PRIMARY KEY (`user_id`,`item_id`,`tag_id`)') !== false)
|
||||||
!fof_db_query("alter table $FOF_ITEM_TAG_TABLE add key user_id (user_id),".
|
{
|
||||||
|
fof_db_query(
|
||||||
|
"alter table $FOF_ITEM_TAG_TABLE add key user_id (user_id),".
|
||||||
" add key item_id_user_id_tag_id (item_id, user_id, tag_id), drop primary key,".
|
" add key item_id_user_id_tag_id (item_id, user_id, tag_id), drop primary key,".
|
||||||
" add primary key (tag_id, user_id, item_id), drop key tag_id, drop key item_id"))
|
" add primary key (tag_id, user_id, item_id), drop key tag_id, drop key item_id"
|
||||||
exit("Can't change indexes on table $FOF_ITEM_TAG_TABLE. MySQL says: <b>" . mysql_error() . "</b><br>");
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (!strpos($check[1], '`item_published`') &&
|
if (!strpos($check[1], '`item_published`'))
|
||||||
!fof_db_query("alter table $FOF_ITEM_TAG_TABLE add item_published int not null default '0',".
|
{
|
||||||
|
fof_db_query(
|
||||||
|
"alter table $FOF_ITEM_TAG_TABLE add item_published int not null default '0',".
|
||||||
" add feed_id int not null default 0,".
|
" add feed_id int not null default 0,".
|
||||||
" add key tag_id_user_id_item_published_item_id (tag_id, user_id, item_published, item_id),".
|
" add key tag_id_user_id_item_published_item_id (tag_id, user_id, item_published, item_id),".
|
||||||
" add key tag_id_user_id_feed_id (tag_id, user_id, feed_id),".
|
" add key tag_id_user_id_feed_id (tag_id, user_id, feed_id),".
|
||||||
" add key feed_id (feed_id)"))
|
" add key feed_id (feed_id)"
|
||||||
exit("Can't add item_published and feed_id columns to table $FOF_ITEM_TAG_TABLE. MySQL says: <b>" . mysql_error() . "</b><br>");
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (mysql_num_rows(fof_db_query("select count(*) from $FOF_ITEM_TAG_TABLE where feed_id=0")) &&
|
if (fof_num_rows(fof_db_query("select count(*) from $FOF_ITEM_TAG_TABLE where feed_id=0")))
|
||||||
!fof_db_query("update $FOF_ITEM_TAG_TABLE it, $FOF_ITEM_TABLE i".
|
{
|
||||||
|
fof_db_query(
|
||||||
|
"update $FOF_ITEM_TAG_TABLE it, $FOF_ITEM_TABLE i".
|
||||||
" set it.item_published=i.item_published, it.feed_id=i.feed_id".
|
" set it.item_published=i.item_published, it.feed_id=i.feed_id".
|
||||||
" where it.feed_id=0 and it.item_id=i.item_id"))
|
" where it.feed_id=0 and it.item_id=i.item_id"
|
||||||
exit("Can't copy item_published and feed_id from $FOF_ITEM_TABLE to $FOF_ITEM_TAG_TABLE. MySQL says: <b>" . mysql_error() . "</b><br>");
|
);
|
||||||
|
}
|
||||||
|
|
||||||
add_fk($check[1], $FOF_ITEM_TAG_TABLE, 'feed_id', $FOF_FEED_TABLE);
|
add_fk($check[1], $FOF_ITEM_TAG_TABLE, 'feed_id', $FOF_FEED_TABLE);
|
||||||
|
|
||||||
|
@ -379,7 +373,7 @@ Cache directory exists and is writable.<hr>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
$result = fof_db_query("select * from $FOF_USER_TABLE where user_name = 'admin'");
|
$result = fof_db_query("select * from $FOF_USER_TABLE where user_name = 'admin'");
|
||||||
if(mysql_num_rows($result) == 0) {
|
if (fof_num_rows($result) == 0) {
|
||||||
?>
|
?>
|
||||||
You now need to choose an initial password for the 'admin' account:<br>
|
You now need to choose an initial password for the 'admin' account:<br>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue