CSR changes, split dbclean in separate processes if worker is active

This commit is contained in:
Michael Vogel 2016-10-22 10:14:41 +00:00
parent 31409e2ca1
commit b429b85680
10 changed files with 592 additions and 589 deletions

View File

@ -126,8 +126,15 @@ function cron_run(&$argv, &$argc){
proc_run(PRIORITY_LOW,'include/expire.php');
if (get_config("system", "worker")) {
proc_run(PRIORITY_LOW,'include/dbclean.php', 1);
proc_run(PRIORITY_LOW,'include/dbclean.php', 2);
proc_run(PRIORITY_LOW,'include/dbclean.php', 3);
proc_run(PRIORITY_LOW,'include/dbclean.php', 4);
} else {
proc_run(PRIORITY_LOW,'include/dbclean.php');
}
}
// Clear cache entries
cron_clear_cache($a);

View File

@ -66,10 +66,10 @@ class dba {
if (! mysqli_connect_errno()) {
$this->connected = true;
}
if (isset($a->config["system"]["db_charset"]))
if (isset($a->config["system"]["db_charset"])) {
$this->db->set_charset($a->config["system"]["db_charset"]);
}
else {
} else {
$this->mysqli = false;
$this->db = mysql_connect($server,$user,$pass);
if ($this->db && mysql_select_db($db,$this->db)) {
@ -111,7 +111,7 @@ class dba {
/**
* @brief Returns the number of rows
*
* @return string
* @return integer
*/
public function num_rows() {
if (!$this->result)
@ -134,11 +134,11 @@ class dba {
$this->error = '';
// Check the connection (This can reconnect the connection - if configured)
if ($this->mysqli)
if ($this->mysqli) {
$connected = $this->db->ping();
else
} else {
$connected = mysql_ping($this->db);
}
$connstr = ($connected ? "Connected": "Disonnected");
$stamp1 = microtime(true);
@ -149,11 +149,11 @@ class dba {
$sql = "/*".$a->callstack()." */ ".$sql;
}
if($this->mysqli)
if ($this->mysqli) {
$result = @$this->db->query($sql);
else
} else {
$result = @mysql_query($sql,$this->db);
}
$stamp2 = microtime(true);
$duration = (float)($stamp2-$stamp1);
@ -191,16 +191,17 @@ class dba {
$mesg = '';
if($result === false)
if ($result === false) {
$mesg = 'false';
elseif($result === true)
} elseif ($result === true) {
$mesg = 'true';
else {
if($this->mysqli)
} else {
if ($this->mysqli) {
$mesg = $result->num_rows . ' results' . EOL;
else
} else {
$mesg = mysql_num_rows($result) . ' results' . EOL;
}
}
$str = 'SQL = ' . printable($sql) . EOL . 'SQL returned ' . $mesg
. (($this->error) ? ' error: ' . $this->error : '')
@ -236,8 +237,7 @@ class dba {
$r[] = $x;
$result->free_result();
}
}
else {
} else {
if (mysql_num_rows($result)) {
while($x = mysql_fetch_array($result, MYSQL_ASSOC))
$r[] = $x;
@ -282,29 +282,32 @@ class dba {
public function escape($str) {
if ($this->db && $this->connected) {
if($this->mysqli)
if ($this->mysqli) {
return @$this->db->real_escape_string($str);
else
} else {
return @mysql_real_escape_string($str,$this->db);
}
}
}
function connected() {
if ($this->mysqli)
if ($this->mysqli) {
$connected = $this->db->ping();
else
} else {
$connected = mysql_ping($this->db);
}
return $connected;
}
function __destruct() {
if ($this->db)
if($this->mysqli)
if ($this->db) {
if ($this->mysqli) {
$this->db->close();
else
} else {
mysql_close($this->db);
}
}
}
}}
if (! function_exists('printable')) {
@ -327,10 +330,11 @@ function dbg($state) {
if (! function_exists('dbesc')) {
function dbesc($str) {
global $db;
if($db && $db->connected)
if ($db && $db->connected) {
return($db->escape($str));
else
} else {
return(str_replace("'","\\'",$str));
}
}}
@ -412,10 +416,11 @@ if(! function_exists('dbq')) {
function dbq($sql) {
global $db;
if($db && $db->connected)
if ($db && $db->connected) {
$ret = $db->q($sql);
else
} else {
$ret = false;
}
return $ret;
}}

View File

@ -21,51 +21,68 @@ function dbclean_run(&$argv, &$argc) {
load_config('config');
load_config('system');
remove_orphans();
if ($argc == 2) {
$stage = intval($argv[1]);
} else {
$stage = 0;
}
remove_orphans($stage);
killme();
}
/**
* @brief Remove orphaned database entries
*/
function remove_orphans() {
function remove_orphans($stage = 0) {
global $db;
if (($stage == 1) OR ($stage == 0)) {
logger("Deleting orphaned data from thread table");
if ($db->q("SELECT `iid` FROM `thread` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`parent` = `thread`.`iid`)", true)) {
logger("found thread orphans: ".$db->num_rows());
while ($orphan = $db->qfetch())
while ($orphan = $db->qfetch()) {
q("DELETE FROM `thread` WHERE `iid` = %d", intval($orphan["iid"]));
}
}
$db->qclose();
}
if (($stage == 2) OR ($stage == 0)) {
logger("Deleting orphaned data from notify table");
if ($db->q("SELECT `iid` FROM `notify` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`id` = `notify`.`iid`)", true)) {
logger("found notify orphans: ".$db->num_rows());
while ($orphan = $db->qfetch())
while ($orphan = $db->qfetch()) {
q("DELETE FROM `notify` WHERE `iid` = %d", intval($orphan["iid"]));
}
}
$db->qclose();
}
if (($stage == 3) OR ($stage == 0)) {
logger("Deleting orphaned data from sign table");
if ($db->q("SELECT `iid` FROM `sign` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`id` = `sign`.`iid`)", true)) {
logger("found sign orphans: ".$db->num_rows());
while ($orphan = $db->qfetch())
while ($orphan = $db->qfetch()) {
q("DELETE FROM `sign` WHERE `iid` = %d", intval($orphan["iid"]));
}
}
$db->qclose();
}
if (($stage == 4) OR ($stage == 0)) {
logger("Deleting orphaned data from term table");
if ($db->q("SELECT `oid` FROM `term` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`id` = `term`.`oid`)", true)) {
logger("found term orphans: ".$db->num_rows());
while ($orphan = $db->qfetch())
while ($orphan = $db->qfetch()) {
q("DELETE FROM `term` WHERE `oid` = %d", intval($orphan["oid"]));
}
}
$db->qclose();
}
/// @todo Based on the following query we should remove some more data
// SELECT `id`, `received`, `created`, `guid` FROM `item` WHERE `uid` = 0 AND NOT EXISTS (SELECT `guid` FROM `item` AS `i` WHERE `item`.`guid` = `i`.`guid` AND `i`.`uid` != 0) LIMIT 1;
logger("Done deleting orphaned data from tables");

View File

@ -44,9 +44,9 @@ class dbm {
*/
public static function is_result($array) {
// It could be a return value from an update statement
if (is_bool($array))
if (is_bool($array)) {
return $array;
}
return (is_array($array) && count($array) > 0);
}
}

View File

@ -69,15 +69,13 @@ function limit_body_size($body) {
$new_body = $new_body . substr($orig_body, 0, $maxlen - $textlen);
$textlen = $maxlen;
}
}
else {
} else {
$new_body = $new_body . substr($orig_body, 0, $img_start);
$textlen += $img_start;
}
$new_body = $new_body . substr($orig_body, $img_start, $img_end - $img_start);
}
else {
} else {
if ( ($textlen + $img_end) > $maxlen ) {
if ($textlen < $maxlen) {
@ -85,8 +83,7 @@ function limit_body_size($body) {
$new_body = $new_body . substr($orig_body, 0, $maxlen - $textlen);
$textlen = $maxlen;
}
}
else {
} else {
$new_body = $new_body . substr($orig_body, 0, $img_end);
$textlen += $img_end;
}
@ -107,16 +104,14 @@ function limit_body_size($body) {
$new_body = $new_body . substr($orig_body, 0, $maxlen - $textlen);
$textlen = $maxlen;
}
}
else {
} else {
logger('limit_body_size: the text size with embedded images extracted did not violate the limit', LOGGER_DEBUG);
$new_body = $new_body . $orig_body;
$textlen += strlen($orig_body);
}
return $new_body;
}
else
} else
return $body;
}}
@ -319,9 +314,7 @@ function item_add_language_opt(&$arr) {
return;
}
$postopts = $arr['postopts'];
}
else
{
} else {
$postopts = "";
}
@ -614,8 +607,7 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
$deny_cid = $arr['deny_cid'];
$deny_gid = $arr['deny_gid'];
$notify_type = 'wall-new';
}
else {
} else {
// find the parent and snarf the item id and ACLs
// and anything else we need to inherit
@ -689,8 +681,7 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
$parent_id = 0;
$arr['parent-uri'] = $arr['uri'];
$arr['gravity'] = 0;
}
else {
} else {
logger('item_store: item parent '.$arr['parent-uri'].' for '.$arr['uid'].' was not found - ignoring item');
return 0;
}
@ -931,17 +922,18 @@ function item_set_last_item($arr) {
if (!$update AND ($arr["network"] == NETWORK_DFRN) AND ($arr["parent-uri"] === $arr["uri"])) {
$isforum = q("SELECT `forum` FROM `contact` WHERE `id` = %d AND `forum`",
intval($arr['contact-id']));
if ($isforum)
if ($isforum) {
$update = true;
}
}
if ($update)
if ($update) {
q("UPDATE `contact` SET `success_update` = '%s', `last-item` = '%s' WHERE `id` = %d",
dbesc($arr['received']),
dbesc($arr['received']),
intval($arr['contact-id'])
);
}
// Now do the same for the system wide contacts with uid=0
if (!$arr['private']) {
q("UPDATE `contact` SET `success_update` = '%s', `last-item` = '%s' WHERE `id` = %d",
@ -950,7 +942,7 @@ function item_set_last_item($arr) {
intval($arr['owner-id'])
);
if ($arr['owner-id'] != $arr['author-id'])
if ($arr['owner-id'] != $arr['author-id']) {
q("UPDATE `contact` SET `success_update` = '%s', `last-item` = '%s' WHERE `id` = %d",
dbesc($arr['received']),
dbesc($arr['received']),
@ -958,6 +950,7 @@ function item_set_last_item($arr) {
);
}
}
}
function item_body_set_hashtags(&$item) {
@ -1506,8 +1499,7 @@ function lose_follower($importer,$contact,$datarray = array(),$item = "") {
intval(CONTACT_IS_SHARING),
intval($contact['id'])
);
}
else {
} else {
contact_remove($contact['id']);
}
}
@ -1519,8 +1511,7 @@ function lose_sharer($importer,$contact,$datarray = array(),$item = "") {
intval(CONTACT_IS_FOLLOWER),
intval($contact['id'])
);
}
else {
} else {
contact_remove($contact['id']);
}
}
@ -1622,8 +1613,7 @@ function fix_private_photos($s, $uid, $item = null, $cid = 0) {
if (in_array($cid, $recips)) {
$replace = true;
}
}
elseif($item) {
} elseif ($item) {
if (compare_permissions($item,$r[0]))
$replace = true;
}
@ -2011,8 +2001,7 @@ function drop_item($id,$interactive = true) {
create_files_from_itemuri($item['parent-uri'], $item['uid']);
delete_thread_uri($item['parent-uri'], $item['uid']);
// ignore the result
}
else {
} else {
// ensure that last-child is set in case the comment that had it just got wiped.
q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d ",
dbesc(datetime_convert()),
@ -2041,8 +2030,7 @@ function drop_item($id,$interactive = true) {
return $owner;
goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
//NOTREACHED
}
else {
} else {
if (! $interactive)
return 0;
notice( t('Permission denied.') . EOL);

View File

@ -8,18 +8,19 @@
*/
function post_update() {
if (!post_update_1192())
if (!post_update_1192()) {
return;
if (!post_update_1194())
}
if (!post_update_1194()) {
return;
if (!post_update_1198())
}
if (!post_update_1198()) {
return;
if (!post_update_1206())
}
if (!post_update_1206()) {
return;
}
}
/**
* @brief set the gcontact-id in all item entries
@ -242,15 +243,16 @@ function post_update_1206() {
FROM `user`
INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`");
if (!dbm::is_result($r))
if (!dbm::is_result($r)) {
return false;
}
foreach ($r AS $user) {
if (!empty($user["lastitem_date"]) AND ($user["lastitem_date"] > $user["last-item"]))
if (!empty($user["lastitem_date"]) AND ($user["lastitem_date"] > $user["last-item"])) {
q("UPDATE `contact` SET `last-item` = '%s' WHERE `id` = %d",
dbesc($user["lastitem_date"]),
intval($user["id"]));
}
}
set_config("system", "post_update_version", 1206);
logger("Done", LOGGER_DEBUG);

View File

@ -19,7 +19,7 @@ function display_init(&$a) {
$r = qu("SELECT `id`, `parent`, `author-name`, `author-link`, `author-avatar`, `network`, `body`, `uid`, `owner-link` FROM `item`
WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
AND `guid` = '%s' AND `uid` = %d", dbesc($a->argv[1]), local_user());
if (count($r)) {
if (dbm::isresult($r)) {
$nick = $a->user["nickname"];
$itemuid = local_user();
}
@ -35,7 +35,7 @@ function display_init(&$a) {
AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
AND NOT `item`.`private` AND NOT `user`.`hidewall`
AND `item`.`guid` = '%s'", dbesc($a->argv[1]));
if (count($r)) {
if (dbm::isresult($r)) {
$nick = $r[0]["nickname"];
$itemuid = $r[0]["uid"];
}
@ -51,12 +51,12 @@ function display_init(&$a) {
AND NOT `item`.`private` AND `item`.`uid` = 0
AND `item`.`guid` = '%s'", dbesc($a->argv[1]));
}
if (count($r)) {
if ($r[0]["id"] != $r[0]["parent"])
if (dbm::isresult($r)) {
if ($r[0]["id"] != $r[0]["parent"]) {
$r = qu("SELECT `id`, `author-name`, `author-link`, `author-avatar`, `network`, `body`, `uid`, `owner-link` FROM `item`
WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
AND `id` = %d", $r[0]["parent"]);
}
if (($itemuid != local_user()) AND local_user()) {
// Do we know this contact but we haven't got this item?
// Copy the wohle thread to our local storage so that we can interact.
@ -66,9 +66,9 @@ function display_init(&$a) {
$items = qu("SELECT * FROM `item` WHERE `parent` = %d ORDER BY `id`", intval($r[0]["id"]));
foreach ($items AS $item) {
$itemcontactid = get_contact($item['owner-link'], local_user());
if (!$itemcontactid)
if (!$itemcontactid) {
$itemcontactid = $contactid;
}
unset($item['id']);
$item['uid'] = local_user();
$item['origin'] = 0;
@ -90,13 +90,14 @@ function display_init(&$a) {
WHERE `user`.`nickname` = '%s' AND `profile`.`is-default` AND `contact`.`self` LIMIT 1",
dbesc($nickname)
);
if (count($r))
if (dbm::isresult($r)) {
$profiledata = $r[0];
}
$profiledata["network"] = NETWORK_DFRN;
} else
} else {
$profiledata = array();
}
}
} else {
$a->error = 404;
notice(t('Item not found.') . EOL);
@ -127,48 +128,49 @@ function display_fetchauthor($a, $item) {
// Skip if it isn't a pure repeated messages
// Does it start with a share?
if (!$skip AND strpos($body, "[share") > 0)
if (!$skip AND strpos($body, "[share") > 0) }
$skip = true;
}
// Does it end with a share?
if (!$skip AND (strlen($body) > (strrpos($body, "[/share]") + 8)))
if (!$skip AND (strlen($body) > (strrpos($body, "[/share]") + 8))) {
$skip = true;
}
if (!$skip) {
$attributes = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","$1",$body);
// Skip if there is no shared message in there
if ($body == $attributes)
if ($body == $attributes) {
$skip = true;
}
}
if (!$skip) {
$author = "";
preg_match("/author='(.*?)'/ism", $attributes, $matches);
if ($matches[1] != "")
if ($matches[1] != "") {
$profiledata["name"] = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
}
preg_match('/author="(.*?)"/ism', $attributes, $matches);
if ($matches[1] != "")
if ($matches[1] != "") {
$profiledata["name"] = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
}
$profile = "";
preg_match("/profile='(.*?)'/ism", $attributes, $matches);
if ($matches[1] != "")
if ($matches[1] != "") {
$profiledata["url"] = $matches[1];
}
preg_match('/profile="(.*?)"/ism', $attributes, $matches);
if ($matches[1] != "")
if ($matches[1] != "") {
$profiledata["url"] = $matches[1];
}
$avatar = "";
preg_match("/avatar='(.*?)'/ism", $attributes, $matches);
if ($matches[1] != "")
if ($matches[1] != "") {
$profiledata["photo"] = $matches[1];
}
preg_match('/avatar="(.*?)"/ism', $attributes, $matches);
if ($matches[1] != "")
if ($matches[1] != "") {
$profiledata["photo"] = $matches[1];
}
$profiledata["nickname"] = $profiledata["name"];
$profiledata["network"] = GetProfileUsername($profiledata["url"], "", false, true);
@ -181,8 +183,9 @@ function display_fetchauthor($a, $item) {
$profiledata["photo"] = App::remove_baseurl($profiledata["photo"]);
if (local_user()) {
if (in_array($profiledata["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS)))
if (in_array($profiledata["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) {
$profiledata["remoteconnect"] = $a->get_baseurl()."/follow?url=".urlencode($profiledata["url"]);
}
} elseif ($profiledata["network"] == NETWORK_DFRN) {
$connect = str_replace("/profile/", "/dfrn_request/", $profiledata["url"]);
$profiledata["remoteconnect"] = $connect;
@ -210,16 +213,14 @@ function display_content(&$a, $update = 0) {
if ($update) {
$nick = $_REQUEST['nick'];
}
else {
} else {
$nick = (($a->argc > 1) ? $a->argv[1] : '');
}
if ($update) {
$item_id = $_REQUEST['item_id'];
$a->profile = array('uid' => intval($update), 'profile_uid' => intval($update));
}
else {
} else {
$item_id = (($a->argc > 2) ? $a->argv[2] : 0);
if ($a->argc == 2) {
@ -229,7 +230,7 @@ function display_content(&$a, $update = 0) {
$r = qu("SELECT `id` FROM `item`
WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
AND `guid` = '%s' AND `uid` = %d", dbesc($a->argv[1]), local_user());
if (count($r)) {
if (dbm::isresult($r)) {
$item_id = $r[0]["id"];
$nick = $a->user["nickname"];
}
@ -243,7 +244,7 @@ function display_content(&$a, $update = 0) {
AND NOT `item`.`private` AND NOT `user`.`hidewall`
AND `item`.`guid` = '%s'", dbesc($a->argv[1]));
// AND NOT `item`.`private` AND `item`.`wall`
if (count($r)) {
if (dbm::isresult($r)) {
$item_id = $r[0]["id"];
$nick = $r[0]["nickname"];
}
@ -256,7 +257,7 @@ function display_content(&$a, $update = 0) {
AND NOT `item`.`private` AND `item`.`uid` = 0
AND `item`.`guid` = '%s'", dbesc($a->argv[1]));
// AND NOT `item`.`private` AND `item`.`wall`
if (count($r)) {
if (dbm::isresult($r)) {
$item_id = $r[0]["id"];
}
}
@ -266,11 +267,12 @@ function display_content(&$a, $update = 0) {
if ($item_id AND !is_numeric($item_id)) {
$r = qu("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($item_id), intval($a->profile['uid']));
if ($r)
if (dbm::is_result($r)) {
$item_id = $r[0]["id"];
else
} else {
$item_id = false;
}
}
if (!$item_id) {
$a->error = 404;
@ -301,7 +303,7 @@ function display_content(&$a, $update = 0) {
intval($contact_id),
intval($a->profile['uid'])
);
if(count($r)) {
if (dbm::isresult($r)) {
$contact = $r[0];
$remote_contact = true;
}
@ -317,9 +319,9 @@ function display_content(&$a, $update = 0) {
$r = qu("SELECT * FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1",
intval($a->profile['uid'])
);
if(count($r))
if (dbm::isresult($r)) {
$a->page_contact = $r[0];
}
$is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
if ($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) {
@ -356,9 +358,10 @@ function display_content(&$a, $update = 0) {
intval($item_id)
);
if(!$r)
if (!$r) {
return '';
}
}
$r = qu(item_query()." AND `item`.`uid` = %d
AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `id` = %d)
@ -377,7 +380,7 @@ function display_content(&$a, $update = 0) {
intval($item_id),
dbesc($item_id)
);
if($r) {
if (dbm::is_result($r)) {
$item_uri = $r[0]['uri'];
$r = qu(item_query()." AND `item`.`uid` = %d
@ -396,17 +399,18 @@ function display_content(&$a, $update = 0) {
$unseen = q("SELECT `id` FROM `item` WHERE `unseen` AND `parent` = %d",
intval($r[0]['parent']));
if ($unseen)
q("UPDATE `item` SET `unseen` = 0
WHERE `parent` = %d AND `unseen`",
if ($unseen) {
q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d AND `unseen`",
intval($r[0]['parent'])
);
}
}
$items = conv_sort($r,"`commented`");
if(!$update)
if (!$update) {
$o .= "<script> var netargs = '?f=&nick=" . $nick . "&item_id=" . $item_id . "'; </script>";
}
$o .= conversation($a,$items,'display', $update);
// Preparing the meta header
@ -418,9 +422,9 @@ function display_content(&$a, $update = 0) {
$image = $a->remove_baseurl($r[0]["thumb"]);
if ($title == "")
if ($title == "") {
$title = $author_name;
}
$description = htmlspecialchars($description, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
$title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
$author_name = htmlspecialchars($author_name, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
@ -467,12 +471,10 @@ function display_content(&$a, $update = 0) {
if ($r) {
if ($r[0]['deleted']) {
notice(t('Item has been removed.') . EOL );
}
else {
} else {
notice(t('Permission denied.') . EOL );
}
}
else {
} else {
notice(t('Item not found.') . EOL );
}

View File

@ -217,7 +217,6 @@ function nodeinfo_cron() {
set_config('nodeinfo','active_users_monthly', $active_users_monthly);
}
//$posts = qu("SELECT COUNT(*) AS local_posts FROM `item` WHERE `wall` AND `uid` != 0 AND `id` = `parent` AND left(body, 6) != '[share'");
$posts = qu("SELECT COUNT(*) AS `local_posts` FROM `item`
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
WHERE `contact`.`self` and `item`.`id` = `item`.`parent` AND left(body, 6) != '[share' AND `item`.`network` IN ('%s', '%s', '%s')",

View File

@ -53,7 +53,7 @@ function photos_init(&$a) {
$sql_extra = permissions_sql($a->data['user']['uid']);
$albums = q("SELECT count(distinct `resource-id`) AS `total`, `album` FROM `photo` USE INDEX (`uid_album_created`) WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
$albums = qu("SELECT count(distinct `resource-id`) AS `total`, `album` FROM `photo` USE INDEX (`uid_album_created`) WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
$sql_extra GROUP BY `album` ORDER BY `created` DESC",
intval($a->data['user']['uid']),
dbesc('Contact Photos'),
@ -157,7 +157,7 @@ function photos_post(&$a) {
intval($cid),
intval($page_owner_uid)
);
if(count($r)) {
if (dbm::is_result($r)) {
$can_post = true;
$visitor = $cid;
}
@ -258,19 +258,17 @@ function photos_post(&$a) {
intval($page_owner_uid),
dbesc($album)
);
}
else {
} else {
$r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
intval(local_user()),
dbesc($album)
);
}
if(count($r)) {
if (dbm::is_result($r)) {
foreach ($r as $rr) {
$res[] = "'" . dbesc($rr['rid']) . "'" ;
}
}
else {
} else {
goaway($_SESSION['photo_return']);
return; // NOTREACHED
}
@ -288,7 +286,7 @@ function photos_post(&$a) {
$r = q("SELECT `parent-uri` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
intval($page_owner_uid)
);
if(count($r)) {
if (dbm::is_result($r)) {
foreach ($r as $rr) {
q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
dbesc(datetime_convert()),
@ -343,14 +341,13 @@ function photos_post(&$a) {
intval($page_owner_uid),
dbesc($a->argv[2])
);
}
else {
} else {
$r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
intval(local_user()),
dbesc($a->argv[2])
);
}
if(count($r)) {
if (dbm::is_result($r)) {
q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
intval($page_owner_uid),
dbesc($r[0]['resource-id'])
@ -406,7 +403,7 @@ function photos_post(&$a) {
dbesc($resource_id),
intval($page_owner_uid)
);
if(count($r)) {
if (dbm::is_result($r)) {
$ph = new Photo($r[0]['data'], $r[0]['type']);
if ($ph->is_valid()) {
$rotate_deg = ( (intval($_POST['rotate']) == 1) ? 270 : 90 );
@ -523,7 +520,7 @@ function photos_post(&$a) {
intval($page_owner_uid)
);
}
if(count($r)) {
if (dbm::is_result($r)) {
$old_tag = $r[0]['tag'];
$old_inform = $r[0]['inform'];
}
@ -564,8 +561,7 @@ function photos_post(&$a) {
}
}
$taginfo[] = array($newname,$profile,$salmon);
}
else {
} else {
$newname = $name;
$alias = '';
$tagcid = 0;
@ -577,8 +573,7 @@ function photos_post(&$a) {
intval($tagcid),
intval($profile_uid)
);
}
else {
} else {
$newname = str_replace('_',' ',$name);
//select someone from this user's contacts by name
@ -602,15 +597,14 @@ function photos_post(&$a) {
dbesc($newname),
intval($page_owner_uid)
);
}
else {
} else {
$r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
dbesc($name),
dbesc($name),
intval($page_owner_uid)
);
}*/
if(count($r)) {
if (dbm::is_result($r)) {
$newname = $r[0]['name'];
$profile = $r[0]['url'];
$notify = 'cid:' . $r[0]['id'];
@ -786,8 +780,7 @@ function photos_post(&$a) {
$filename = $ret['filename'];
$filesize = $ret['filesize'];
$type = $ret['type'];
}
else {
} else {
$src = $_FILES['userfile']['tmp_name'];
$filename = basename($_FILES['userfile']['name']);
$filesize = intval($_FILES['userfile']['size']);
@ -983,8 +976,7 @@ function photos_content(&$a) {
if ($a->argc > 3) {
$datatype = $a->argv[2];
$datum = $a->argv[3];
}
elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
} elseif (($a->argc > 2) && ($a->argv[2] === 'upload'))
$datatype = 'upload';
else
$datatype = 'summary';
@ -1026,7 +1018,7 @@ function photos_content(&$a) {
intval($contact_id),
intval($owner_uid)
);
if(count($r)) {
if (dbm::is_result($r)) {
$can_post = true;
$contact = $r[0];
$remote_contact = true;
@ -1054,7 +1046,7 @@ function photos_content(&$a) {
intval($contact_id),
intval($owner_uid)
);
if(count($r)) {
if (dbm::is_result($r)) {
$contact = $r[0];
$remote_contact = true;
}
@ -1157,8 +1149,7 @@ function photos_content(&$a) {
if ($a->theme['template_engine'] === 'internal') {
$albumselect_e = template_escape($albumselect);
$aclselect_e = (($visitor) ? '' : template_escape(populate_acl($a->user)));
}
else {
} else {
$albumselect_e = $albumselect;
$aclselect_e = (($visitor) ? '' : populate_acl($a->user));
}
@ -1207,7 +1198,7 @@ function photos_content(&$a) {
intval($owner_uid),
dbesc($album)
);
if(count($r)) {
if (dbm::is_result($r)) {
$a->set_pager_total(count($r));
$a->set_pager_itemspage(20);
}
@ -1233,8 +1224,7 @@ function photos_content(&$a) {
if ($a->theme['template_engine'] === 'internal') {
$album_e = template_escape($album);
}
else {
} else {
$album_e = $album;
}
@ -1248,8 +1238,7 @@ function photos_content(&$a) {
));
}
}
}
else {
} else {
if (($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
if ($can_post) {
$edit = array(t('Edit Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit');
@ -1264,7 +1253,7 @@ function photos_content(&$a) {
$photos = array();
if(count($r))
if (dbm::is_result($r))
$twist = 'rotright';
foreach ($r as $rr) {
if ($twist == 'rotright')
@ -1277,8 +1266,7 @@ function photos_content(&$a) {
if ($a->theme['template_engine'] === 'internal') {
$imgalt_e = template_escape($rr['filename']);
$desc_e = template_escape($rr['desc']);
}
else {
} else {
$imgalt_e = $rr['filename'];
$desc_e = $rr['desc'];
}
@ -1379,8 +1367,7 @@ function photos_content(&$a) {
if ($ph[1]['scale'] == 2) {
// original is 640 or less, we can display it directly
$hires = $lores = $ph[0];
}
else {
} else {
$hires = $ph[0];
$lores = $ph[1];
}
@ -1458,7 +1445,7 @@ function photos_content(&$a) {
);
if(count($r))
if (dbm::is_result($r))
$a->set_pager_total($r[0]['total']);
@ -1538,8 +1525,7 @@ function photos_content(&$a) {
$album_e = template_escape($ph[0]['album']);
$caption_e = template_escape($ph[0]['desc']);
$aclselect_e = template_escape(populate_acl($ph[0]));
}
else {
} else {
$album_e = $ph[0]['album'];
$caption_e = $ph[0]['desc'];
$aclselect_e = populate_acl($ph[0]);
@ -1635,7 +1621,7 @@ function photos_content(&$a) {
// display comments
if(count($r)) {
if (dbm::is_result($r)) {
foreach ($r as $item) {
builtin_activity_puller($item, $conv_responses);
@ -1684,8 +1670,7 @@ function photos_content(&$a) {
&& ($item['network'] == NETWORK_DFRN) && (! $item['self'] )) {
$profile_url = $redirect_url;
$sparkle = ' sparkle';
}
else {
} else {
$profile_url = $item['url'];
$sparkle = '';
}
@ -1712,8 +1697,7 @@ function photos_content(&$a) {
$name_e = template_escape($profile_name);
$title_e = template_escape($item['title']);
$body_e = template_escape(bbcode($item['body']));
}
else {
} else {
$name_e = $profile_name;
$title_e = $item['title'];
$body_e = bbcode($item['body']);
@ -1774,8 +1758,7 @@ function photos_content(&$a) {
$tags_e = template_escape($tags);
$like_e = template_escape($like);
$dislike_e = template_escape($dislike);
}
else {
} else {
$album_e = array($album_link,$ph[0]['album']);
$tags_e = $tags;
$like_e = $like;
@ -1821,7 +1804,7 @@ function photos_content(&$a) {
dbesc('Contact Photos'),
dbesc( t('Contact Photos'))
);
if(count($r)) {
if (dbm::is_result($r)) {
$a->set_pager_total(count($r));
$a->set_pager_itemspage(20);
}
@ -1839,7 +1822,7 @@ function photos_content(&$a) {
$photos = array();
if(count($r)) {
if (dbm::is_result($r)) {
$twist = 'rotright';
foreach ($r as $rr) {
//hide profile photos to others
@ -1850,13 +1833,13 @@ function photos_content(&$a) {
$twist = 'rotleft';
else
$twist = 'rotright';
$ext = $phototypes[$rr['type']];
if ($a->theme['template_engine'] === 'internal') {
$alt_e = template_escape($rr['filename']);
$name_e = template_escape($rr['album']);
}
else {
} else {
$alt_e = $rr['filename'];
$name_e = $rr['album'];
}