Merge branch 'rewrites/dbm_is_result' of github.com:Quix0r/friendica into rewrites/dbm_is_result

Signed-off-by: Roland Häder <roland@mxchange.org>

Conflicts:
	include/Photo.php
	include/api.php
	include/cache.php
	include/dbstructure.php
	include/enotify.php
	include/items.php
	include/onepoll.php
	include/queue_fn.php
	include/session.php
	include/text.php
	mod/contacts.php
	mod/dfrn_request.php
	mod/display.php
	mod/events.php
	mod/item.php
	mod/message.php
	mod/msearch.php
	mod/photos.php
	mod/poco.php
	mod/profile.php
	mod/proxy.php
	mod/videos.php
	update.php
	view/theme/diabook/theme.php
	view/theme/vier/theme.php
This commit is contained in:
Roland Häder 2016-12-13 11:00:44 +01:00
commit 63610c7b73
33 changed files with 320 additions and 260 deletions

View File

@ -3943,7 +3943,6 @@
}
api_register_func('api/friendica/direct_messages_search', 'api_friendica_direct_messages_search', true);
/**
* @brief return data of all the profiles a user has to the client
*

View File

@ -433,7 +433,7 @@ function cron_repair_diaspora(&$a) {
$r = q("SELECT `id`, `url` FROM `contact`
WHERE `network` = '%s' AND (`batch` = '' OR `notify` = '' OR `poll` = '' OR pubkey = '')
ORDER BY RAND() LIMIT 50", dbesc(NETWORK_DIASPORA));
if ($r) {
if (dbm::is_result($r)) {
foreach ($r AS $contact) {
if (poco_reachable($contact["url"])) {
$data = probe_url($contact["url"]);
@ -463,7 +463,7 @@ function cron_repair_database() {
// Update the global contacts for local users
$r = q("SELECT `uid` FROM `user` WHERE `verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired`");
if ($r)
if (dbm::is_result($r))
foreach ($r AS $user)
update_gcontact_for_user($user["uid"]);

View File

@ -17,6 +17,14 @@ function update_fail($update_id, $error_message){
$admin_mail_list
);
// No valid result?
if (!dbm::is_result($adminlist)) {
logger(sprintf('Cannot notify administrators about update_id=%d, error_message=%s', $update_id, $error_message), LOGGER_WARNING);
// Don't continue
return;
}
// every admin could had different language
foreach ($adminlist as $admin) {
@ -73,7 +81,7 @@ function table_structure($table) {
$fielddata = array();
$indexdata = array();
if (is_array($indexes))
if (dbm::is_result($indexes))
foreach ($indexes AS $index) {
if ($index["Index_type"] == "FULLTEXT")
continue;
@ -93,7 +101,7 @@ function table_structure($table) {
$indexdata[$index["Key_name"]][] = $column;
}
if (is_array($structures)) {
if (dbm::is_result($structures)) {
foreach($structures AS $field) {
$fielddata[$field["Field"]]["type"] = $field["Type"];
if ($field["Null"] == "NO")
@ -151,6 +159,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
foreach ($tables AS $table) {
$table = current($table);
logger(sprintf('updating structure for table %s ...', $table), LOGGER_DEBUG);
$database[$table] = table_structure($table);
}
@ -179,7 +188,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
$sql3="";
if (!isset($database[$name])) {
$r = db_create_table($name, $structure["fields"], $charset, $verbose, $action, $structure['indexes']);
if(false === $r) {
if(!dbm::is_result($r)) {
$errors .= t('Errors encountered creating database tables.').$name.EOL;
}
$is_new_table = True;
@ -256,7 +265,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
if ($action) {
$r = @$db->q($sql3);
if(false === $r)
if(dbm::is_result($r))
$errors .= t('Errors encountered performing database changes.').$sql3.EOL;
}
}

View File

@ -1278,7 +1278,7 @@ class diaspora {
$r = q("SELECT `id` FROM `mail` WHERE `uri` = '%s' LIMIT 1",
dbesc($message_uri)
);
if($r) {
if(dbm::is_result($r)) {
logger("duplicate message already delivered.", LOGGER_DEBUG);
return false;
}
@ -2925,7 +2925,7 @@ class diaspora {
$p = q("SELECT `guid`, `uri`, `parent-uri` FROM `item` WHERE `uri` = '%s' LIMIT 1",
dbesc($item["thr-parent"]));
if(!$p)
if(!dbm::is_result($p))
return false;
$parent = $p[0];
@ -2956,7 +2956,7 @@ class diaspora {
intval($item["parent"])
);
if (!$p)
if (!dbm::is_result($p))
return false;
$parent = $p[0];
@ -3170,7 +3170,7 @@ class diaspora {
intval($item["uid"])
);
if (!$r) {
if (!dbm::is_result($r)) {
logger("conversation not found.");
return;
}

View File

@ -739,7 +739,7 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
$tags = q("SELECT `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` = %d AND `uid` = %d",
intval(TERM_OBJ_POST), intval($itemid), intval(TERM_MENTION), intval($uid));
if (count($tags)) {
if (dbm::is_result($tags)) {
foreach ($tags AS $tag) {
$r = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `notify_new_posts`",
normalise_link($tag["url"]), intval($uid));

View File

@ -59,6 +59,8 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
if ($attributes->name == "href")
$author["author-link"] = $attributes->textContent;
$author["author-id"] = $xpath->evaluate('/atom:feed/atom:author/atom:uri/text()')->item(0)->nodeValue;
if ($author["author-link"] == "")
$author["author-link"] = $author["author-id"];
@ -142,6 +144,10 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
$author["owner-link"] = $contact["url"];
$author["owner-name"] = $contact["name"];
$author["owner-avatar"] = $contact["thumb"];
// This is no field in the item table. So we have to unset it.
unset($author["author-nick"]);
unset($author["author-id"]);
}
$header = array();

View File

@ -1541,6 +1541,7 @@ function new_follower($importer,$contact,$datarray,$item,$sharing = false) {
intval($importer['uid'])
);
$a = get_app();
if(dbm::is_result($r) AND !in_array($r[0]['page-flags'], array(PAGE_SOAPBOX, PAGE_FREELOVE))) {
// create notification

View File

@ -338,7 +338,6 @@ function xml_status($st, $message = '') {
killme();
}
/**
* @brief Send HTTP status header and exit.
*
@ -348,6 +347,14 @@ function xml_status($st, $message = '') {
* 'description' => optional message
*/
/**
* @brief Send HTTP status header and exit.
*
* @param integer $val HTTP status result value
* @param array $description optional message
* 'title' => header title
* 'description' => optional message
*/
function http_status_exit($val, $description = array()) {
$err = '';
if($val >= 400) {
@ -381,19 +388,32 @@ function http_status_exit($val, $description = array()) {
* @return boolean True if it's a valid URL, fals if something wrong with it
*/
function validate_url(&$url) {
logger(sprintf('[%s:%d]: url=%s - CALLED!', __FUNCTION__, __LINE__, $url), LOGGER_TRACE);
if(get_config('system','disable_url_validation'))
logger(sprintf('[%s:%d]: URL validation disabled, returning TRUE - EXIT!', __FUNCTION__, __LINE__), LOGGER_TRACE);
return true;
// no naked subdomains (allow localhost for tests)
if(strpos($url,'.') === false && strpos($url,'/localhost/') === false)
logger(sprintf('[%s:%d]: URL is not complete, returning FALSE - EXIT!', __FUNCTION__, __LINE__), LOGGER_TRACE);
return false;
if(substr($url,0,4) != 'http')
if(substr($url,0,4) != 'http' && substr($url,0,5) != 'https')
$url = 'http://' . $url;
logger(sprintf('[%s:%d]: url=%s - before parse_url() ...', __FUNCTION__, __LINE__, $url), LOGGER_DEBUG);
$h = @parse_url($url);
if(($h) && (dns_get_record($h['host'], DNS_A + DNS_CNAME + DNS_PTR) || filter_var($h['host'], FILTER_VALIDATE_IP) )) {
logger(sprintf('[%s:%d]: h[]=%s', __FUNCTION__, __LINE__, gettype($h)), LOGGER_DEBUG);
if((is_array($h)) && (dns_get_record($h['host'], DNS_A + DNS_CNAME + DNS_PTR) || filter_var($h['host'], FILTER_VALIDATE_IP) )) {
logger(sprintf('[%s:%d]: URL %s validated. - EXIT!', __FUNCTION__, __LINE__, $url), LOGGER_TRACE);
return true;
}
logger(sprintf('[%s:%d]: URL %s maybe not valid - EXIT!', __FUNCTION__, __LINE__, $url), LOGGER_TRACE);
return false;
}

View File

@ -424,6 +424,20 @@ function notifier_run(&$argv, &$argc){
$url_recipients[$probed_contact["notify"]] = $probed_contact["notify"];
}
// Send a salmon to the parent author
$probed_contact = probe_url($thr_parent[0]['author-link']);
if ($probed_contact["notify"] != "") {
logger('Notify parent author '.$probed_contact["url"].': '.$probed_contact["notify"]);
$url_recipients[$probed_contact["notify"]] = $probed_contact["notify"];
}
// Send a salmon to the parent owner
$probed_contact = probe_url($thr_parent[0]['owner-link']);
if ($probed_contact["notify"] != "") {
logger('Notify parent owner '.$probed_contact["url"].': '.$probed_contact["notify"]);
$url_recipients[$probed_contact["notify"]] = $probed_contact["notify"];
}
// Send a salmon notification to every person we mentioned in the post
$arr = explode(',',$target_item['tag']);
foreach($arr as $x) {

View File

@ -24,7 +24,12 @@ function remove_queue_item($id) {
*/
function was_recently_delayed($cid) {
$was_delayed = false;
$r = q("SELECT `id` FROM `queue` WHERE `cid` = %d
and last > UTC_TIMESTAMP() - interval 15 minute limit 1",
intval($cid)
);
if(dbm::is_result($r))
return true;
// Are there queue entries that were recently added?
$r = q("SELECT `id` FROM `queue` WHERE `cid` = %d
@ -32,18 +37,7 @@ function was_recently_delayed($cid) {
intval($cid)
);
$was_delayed = dbm::is_result($r);
// We set "term-date" to a current date if the communication has problems.
// If the communication works again we reset this value.
if ($was_delayed) {
$r = q("SELECT `term-date` FROM `contact` WHERE `id` = %d AND `term-date` <= '1000-01-01' LIMIT 1",
intval($cid)
);
$was_delayed = !dbm::is_result($r);
}
return $was_delayed;
return (dbm::is_result($r));
}

View File

@ -901,13 +901,14 @@ function contact_block() {
dbesc(NETWORK_DIASPORA),
intval($shown)
);
if ($r) {
if(dbm::is_result($r)) {
$contacts = "";
foreach ($r AS $contact)
$contacts[] = $contact["id"];
$r = q("SELECT `id`, `uid`, `addr`, `url`, `name`, `thumb`, `network` FROM `contact` WHERE `id` IN (%s)",
dbesc(implode(",", $contacts)));
if(dbm::is_result($r)) {
$contacts = sprintf( tt('%d Contact','%d Contacts', $total),$total);
$micropro = Array();

View File

@ -174,7 +174,7 @@ function add_shadow_entry($itemid) {
function update_thread_uri($itemuri, $uid) {
$messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid));
if(count($messages))
if(dbm::is_result($messages))
foreach ($messages as $message)
update_thread($message["id"]);
}
@ -183,7 +183,7 @@ function update_thread($itemid, $setmention = false) {
$items = q("SELECT `uid`, `guid`, `title`, `body`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`, `moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`, `gcontact-id`,
`deleted`, `origin`, `forum_mode`, `network`, `rendered-html`, `rendered-hash` FROM `item` WHERE `id` = %d AND (`parent` = %d OR `parent` = 0) LIMIT 1", intval($itemid), intval($itemid));
if (!$items)
if (!dbm::is_result($items))
return;
$item = $items[0];

View File

@ -772,6 +772,8 @@ function contacts_content(&$a) {
$sql_extra3 = unavailable_networks();
$contacts = array();
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 $sql_extra3 ORDER BY `name` ASC LIMIT %d , %d ",
intval($_SESSION['uid']),
intval($a->pager['start']),

View File

@ -273,7 +273,7 @@ function dfrn_request_post(&$a) {
dbesc(datetime_convert('UTC','UTC','now - 24 hours')),
intval($uid)
);
if(dbm::is_result($r) > $maxreq) {
if(dbm::is_result($r) && count($r) > $maxreq) {
notice( sprintf( t('%s has received too many connection requests today.'), $a->profile['name']) . EOL);
notice( t('Spam protection measures have been invoked.') . EOL);
notice( t('Friends are advised to please try again in 24 hours.') . EOL);
@ -370,8 +370,8 @@ function dfrn_request_post(&$a) {
$r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
intval($uid)
);
if(! dbm::is_result($r)) {
if(! dbm::is_result($r)) {
notice( t('This account has not been configured for email. Request failed.') . EOL);
return;
}
@ -431,8 +431,8 @@ function dfrn_request_post(&$a) {
$hash = random_string();
$r = q("insert into intro ( uid, `contact-id`, knowyou, note, hash, datetime, blocked )
values( %d , %d, %d, '%s', '%s', '%s', %d ) ",
$r = q("INSERT INTO intro ( uid, `contact-id`, knowyou, note, hash, datetime, blocked )
VALUES( %d , %d, %d, '%s', '%s', '%s', %d ) ",
intval($uid),
intval($contact_id),
((x($_POST,'knowyou') && ($_POST['knowyou'] == 1)) ? 1 : 0),
@ -449,9 +449,13 @@ function dfrn_request_post(&$a) {
$data = probe_url($url);
$network = $data["network"];
logger('dfrn_request: url=' . $url . ',network=' . $network . ',hcard=' . $hcard . ' - BEFORE!', LOGGER_DEBUG);
// Canonicalise email-style profile locator
$url = Probe::webfinger_dfrn($url,$hcard);
logger('dfrn_request: url=' . $url . ',network=' . $network . ',hcard=' . $hcard . ' - AFTER!', LOGGER_DEBUG);
if (substr($url,0,5) === 'stat:') {
// Every time we detect the remote subscription we define this as OStatus.
@ -473,7 +477,7 @@ function dfrn_request_post(&$a) {
dbesc($url)
);
if(count($ret)) {
if(dbm::is_result($ret)) {
if(strlen($ret[0]['issued-id'])) {
notice( t('You have already introduced yourself here.') . EOL );
return;
@ -720,7 +724,9 @@ function dfrn_request_content(&$a) {
dbesc($_GET['confirm_key'])
);
if(count($intro)) {
if(dbm::is_result($intro)) {
$auto_confirm = false;
$r = q("SELECT `contact`.*, `user`.* FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
WHERE `contact`.`id` = %d LIMIT 1",

View File

@ -344,9 +344,10 @@ function events_content(&$a) {
$events=array();
// transform the event in a usable array
if(dbm::is_result($r))
if(dbm::is_result($r)) {
$r = sort_by_date($r);
$events = process_events($r);
}
if ($a->argv[1] === 'json'){
echo json_encode($events); killme();

View File

@ -309,18 +309,20 @@ function message_content(&$a) {
intval(local_user()),
intval($a->argv[2])
);
if(!$r) {
if(!dbm::is_result($r)) {
$r = q("SELECT `name`, `url`, `id` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' LIMIT 1",
intval(local_user()),
dbesc(normalise_link(base64_decode($a->argv[2])))
);
}
if(!$r) {
if(!dbm::is_result($r)) {
$r = q("SELECT `name`, `url`, `id` FROM `contact` WHERE `uid` = %d AND `addr` = '%s' LIMIT 1",
intval(local_user()),
dbesc(base64_decode($a->argv[2]))
);
}
if(dbm::is_result($r)) {
$prename = $r[0]['name'];
$preurl = $r[0]['url'];

View File

@ -13,9 +13,12 @@ function msearch_post(&$a) {
$r = q("SELECT COUNT(*) AS `total` FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` WHERE `is-default` = 1 AND `user`.`hidewall` = 0 AND MATCH `pub_keywords` AGAINST ('%s') ",
dbesc($search)
);
if(dbm::is_result($r))
$total = $r[0]['total'];
$results = array();
$r = q("SELECT `pub_keywords`, `username`, `nickname`, `user`.`uid` FROM `user` LEFT JOIN `profile` ON `user`.`uid` = `profile`.`uid` WHERE `is-default` = 1 AND `user`.`hidewall` = 0 AND MATCH `pub_keywords` AGAINST ('%s') LIMIT %d , %d ",
dbesc($search),
intval($startrec),
@ -23,6 +26,7 @@ function msearch_post(&$a) {
);
$results = array();
if(dbm::is_result($r)) {
foreach($r as $rr)
$results[] = array(

View File

@ -729,6 +729,8 @@ function network_content(&$a, $update = 0) {
intval($parents),
intval($max_comments + 1)
);
if (dbm::is_result($thread_items))
$items = array_merge($items, $thread_items);
}
$items = conv_sort($items,$ordering);

View File

@ -305,7 +305,6 @@ function notifications_content(&$a) {
$notif_nocontent = sprintf( t('No more %s notifications.'), $notifs['ident']);
}
$o .= replace_macros($notif_tpl, array(
'$notif_header' => $notif_header,
'$tabs' => $tabs,

View File

@ -48,7 +48,7 @@ function p_init($a){
$r = q("SELECT `user`.`prvkey`, `contact`.`addr`, `user`.`nickname`, `contact`.`nick` FROM `user`
INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid`
WHERE `user`.`uid` = %d", intval($item[0]["uid"]));
if (!$r) {
if (!dbm::is_result($r)) {
header($_SERVER["SERVER_PROTOCOL"].' 404 '.t('Not Found'));
killme();
}

View File

@ -117,7 +117,7 @@ function photo_init(&$a) {
intval($resolution)
);
$public = ($r[0]['allow_cid'] == '') AND ($r[0]['allow_gid'] == '') AND ($r[0]['deny_cid'] == '') AND ($r[0]['deny_gid'] == '');
$public = (dbm::is_result($r)) && ($r[0]['allow_cid'] == '') AND ($r[0]['allow_gid'] == '') AND ($r[0]['deny_cid'] == '') AND ($r[0]['deny_gid'] == '');
if(dbm::is_result($r)) {
$resolution = $r[0]['scale'];

View File

@ -173,7 +173,7 @@ function poco_init(&$a) {
}
if(is_array($r)) {
if(count($r) > 0) {
if(dbm::is_result($r)) {
foreach($r as $rr) {
if (!isset($rr['generation'])) {
if ($global)

View File

@ -209,7 +209,6 @@ function search_content(&$a) {
$sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
}
$r = q("SELECT %s
FROM `item` %s
WHERE %s AND (`item`.`uid` = 0 OR (`item`.`uid` = %s AND NOT `item`.`global`))

View File

@ -32,21 +32,21 @@
<!--[if IE]>
<script type="text/javascript" src="https://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script type="text/javascript" src="js/modernizr.js" ></script>
<script type="text/javascript" src="js/jquery.js" ></script>
<!-- <script type="text/javascript" src="js/jquery-migrate.js" ></script>-->
<script type="text/javascript" src="js/jquery-migrate.js" ></script>
<script type="text/javascript" src="js/jquery.textinputs.js" ></script>
<script type="text/javascript" src="library/jquery-textcomplete/jquery.textcomplete.min.js" ></script>
<script type="text/javascript" src="js/autocomplete.js" ></script>
<script type="text/javascript" src="library/colorbox/jquery.colorbox-min.js"></script>
<script type="text/javascript" src="library/jgrowl/jquery.jgrowl_minimized.js"></script>
<script type="text/javascript" src="library/datetimepicker/jquery.datetimepicker.js"></script>
<script type="text/javascript" src="library/tinymce/jscripts/tiny_mce/tiny_mce_src.js" ></script>
<script type="text/javascript" src="library/perfect-scrollbar/perfect-scrollbar.jquery.js" ></script>
<script type="text/javascript" src="js/acl.js" ></script>
<script type="text/javascript" src="js/webtoolkit.base64.js" ></script>
<script type="text/javascript" src="js/main.js" ></script>
<script type="text/javascript" src="{{$baseurl}}/js/modernizr.js" ></script>
<script type="text/javascript" src="{{$baseurl}}/js/jquery.js" ></script>
<!-- <script type="text/javascript" src="{{$baseurl}}/js/jquery-migrate.js" ></script>-->
<script type="text/javascript" src="{{$baseurl}}/js/jquery-migrate.js" ></script>
<script type="text/javascript" src="{{$baseurl}}/js/jquery.textinputs.js" ></script>
<script type="text/javascript" src="{{$baseurl}}/library/jquery-textcomplete/jquery.textcomplete.min.js" ></script>
<script type="text/javascript" src="{{$baseurl}}/js/autocomplete.js" ></script>
<script type="text/javascript" src="{{$baseurl}}/library/colorbox/jquery.colorbox-min.js"></script>
<script type="text/javascript" src="{{$baseurl}}/library/jgrowl/jquery.jgrowl_minimized.js"></script>
<script type="text/javascript" src="{{$baseurl}}/library/datetimepicker/jquery.datetimepicker.js"></script>
<script type="text/javascript" src="{{$baseurl}}/library/tinymce/jscripts/tiny_mce/tiny_mce_src.js" ></script>
<script type="text/javascript" src="{{$baseurl}}/library/perfect-scrollbar/perfect-scrollbar.jquery.js" ></script>
<script type="text/javascript" src="{{$baseurl}}/js/acl.js" ></script>
<script type="text/javascript" src="{{$baseurl}}/js/webtoolkit.base64.js" ></script>
<script type="text/javascript" src="{{$baseurl}}/js/main.js" ></script>
<script>
var updateInterval = {{$update_interval}};

View File

@ -170,12 +170,13 @@ function vier_community_info() {
$publish = (get_config('system','publish_all') ? '' : " AND `publish` = 1 ");
$order = " ORDER BY `register_date` DESC ";
$tpl = get_markup_template('ch_directory_item.tpl');
$r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $order LIMIT %d , %d ",
0, 9);
$tpl = get_markup_template('ch_directory_item.tpl');
if(dbm::is_result($r)) {
$aside['$lastusers_title'] = t('Last users');
@ -367,7 +368,7 @@ function vier_community_info() {
$tpl = get_markup_template('ch_connectors.tpl');
if(count($r)) {
if(dbm::is_result($r)) {
$con_services = array();
$con_services['title'] = Array("", t('Connect Services'), "", "");