mirror of
https://github.com/friendica/friendica
synced 2025-04-26 15:10:11 +00:00
Merge develop into 1404_reworked_autocomplete
Conflicts: include/text.php view/templates/head.tpl view/theme/duepuntozero/style.css view/theme/vier/style.css
This commit is contained in:
commit
01b02dbcaa
723 changed files with 40077 additions and 44824 deletions
|
@ -129,7 +129,7 @@ function terminate_friendship($user,$self,$contact) {
|
|||
}
|
||||
elseif($contact['network'] === NETWORK_DIASPORA) {
|
||||
require_once('include/diaspora.php');
|
||||
diaspora_unshare($user,$contact);
|
||||
diaspora::send_unshare($user,$contact);
|
||||
}
|
||||
elseif($contact['network'] === NETWORK_DFRN) {
|
||||
require_once('include/dfrn.php');
|
||||
|
@ -555,60 +555,6 @@ function posts_from_gcontact($a, $gcontact_id) {
|
|||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief set the gcontact-id in all item entries
|
||||
*
|
||||
* This job has to be started multiple times until all entries are set.
|
||||
* It isn't started in the update function since it would consume too much time and can be done in the background.
|
||||
*/
|
||||
function item_set_gcontact() {
|
||||
define ('POST_UPDATE_VERSION', 1192);
|
||||
|
||||
// Was the script completed?
|
||||
if (get_config("system", "post_update_version") >= POST_UPDATE_VERSION)
|
||||
return;
|
||||
|
||||
// Check if the first step is done (Setting "gcontact-id" in the item table)
|
||||
$r = q("SELECT `author-link`, `author-name`, `author-avatar`, `uid`, `network` FROM `item` WHERE `gcontact-id` = 0 LIMIT 1000");
|
||||
if (!$r) {
|
||||
// Are there unfinished entries in the thread table?
|
||||
$r = q("SELECT COUNT(*) AS `total` FROM `thread`
|
||||
INNER JOIN `item` ON `item`.`id` =`thread`.`iid`
|
||||
WHERE `thread`.`gcontact-id` = 0 AND
|
||||
(`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)");
|
||||
|
||||
if ($r AND ($r[0]["total"] == 0)) {
|
||||
set_config("system", "post_update_version", POST_UPDATE_VERSION);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Update the thread table from the item table
|
||||
q("UPDATE `thread` INNER JOIN `item` ON `item`.`id`=`thread`.`iid`
|
||||
SET `thread`.`gcontact-id` = `item`.`gcontact-id`
|
||||
WHERE `thread`.`gcontact-id` = 0 AND
|
||||
(`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$item_arr = array();
|
||||
foreach ($r AS $item) {
|
||||
$index = $item["author-link"]."-".$item["uid"];
|
||||
$item_arr[$index] = array("author-link" => $item["author-link"],
|
||||
"uid" => $item["uid"],
|
||||
"network" => $item["network"]);
|
||||
}
|
||||
|
||||
// Set the "gcontact-id" in the item table and add a new gcontact entry if needed
|
||||
foreach($item_arr AS $item) {
|
||||
$gcontact_id = get_gcontact_id(array("url" => $item['author-link'], "network" => $item['network'],
|
||||
"photo" => $item['author-avatar'], "name" => $item['author-name']));
|
||||
q("UPDATE `item` SET `gcontact-id` = %d WHERE `uid` = %d AND `author-link` = '%s' AND `gcontact-id` = 0",
|
||||
intval($gcontact_id), intval($item["uid"]), dbesc($item["author-link"]));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns posts from a given contact
|
||||
*
|
||||
|
|
190
include/ForumManager.php
Normal file
190
include/ForumManager.php
Normal file
|
@ -0,0 +1,190 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file include/ForumManager.php
|
||||
* @brief ForumManager class with its methods related to forum functionality *
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief This class handles metheods related to the forum functionality
|
||||
*/
|
||||
class ForumManager {
|
||||
|
||||
/**
|
||||
* @brief Function to list all forums a user is connected with
|
||||
*
|
||||
* @param int $uid of the profile owner
|
||||
* @param boolean $showhidden
|
||||
* Show frorums which are not hidden
|
||||
* @param boolean $lastitem
|
||||
* Sort by lastitem
|
||||
* @param boolean $showprivate
|
||||
* Show private groups
|
||||
*
|
||||
* @returns array
|
||||
* 'url' => forum url
|
||||
* 'name' => forum name
|
||||
* 'id' => number of the key from the array
|
||||
* 'micro' => contact photo in format micro
|
||||
*/
|
||||
public static function get_list($uid, $showhidden = true, $lastitem, $showprivate = false) {
|
||||
|
||||
$forumlist = array();
|
||||
|
||||
$order = (($showhidden) ? '' : ' AND NOT `hidden` ');
|
||||
$order .= (($lastitem) ? ' ORDER BY `last-item` DESC ' : ' ORDER BY `name` ASC ');
|
||||
$select = '`forum` ';
|
||||
if ($showprivate) {
|
||||
$select = '(`forum` OR `prv`)';
|
||||
}
|
||||
|
||||
$contacts = q("SELECT `contact`.`id`, `contact`.`url`, `contact`.`name`, `contact`.`micro` FROM `contact`
|
||||
WHERE `network`= 'dfrn' AND $select AND `uid` = %d
|
||||
AND NOT `blocked` AND NOT `hidden` AND NOT `pending` AND NOT `archive`
|
||||
AND `success_update` > `failure_update`
|
||||
$order ",
|
||||
intval($uid)
|
||||
);
|
||||
|
||||
if (!$contacts)
|
||||
return($forumlist);
|
||||
|
||||
foreach($contacts as $contact) {
|
||||
$forumlist[] = array(
|
||||
'url' => $contact['url'],
|
||||
'name' => $contact['name'],
|
||||
'id' => $contact['id'],
|
||||
'micro' => $contact['micro'],
|
||||
);
|
||||
}
|
||||
return($forumlist);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Forumlist widget
|
||||
*
|
||||
* Sidebar widget to show subcribed friendica forums. If activated
|
||||
* in the settings, it appears at the notwork page sidebar
|
||||
*
|
||||
* @param int $uid The ID of the User
|
||||
* @param int $cid
|
||||
* The contact id which is used to mark a forum as "selected"
|
||||
* @return string
|
||||
*/
|
||||
public static function widget($uid,$cid = 0) {
|
||||
|
||||
if(! intval(feature_enabled(local_user(),'forumlist_widget')))
|
||||
return;
|
||||
|
||||
$o = '';
|
||||
|
||||
//sort by last updated item
|
||||
$lastitem = true;
|
||||
|
||||
$contacts = self::get_list($uid,true,$lastitem, true);
|
||||
$total = count($contacts);
|
||||
$visible_forums = 10;
|
||||
|
||||
if(count($contacts)) {
|
||||
|
||||
$id = 0;
|
||||
|
||||
foreach($contacts as $contact) {
|
||||
|
||||
$selected = (($cid == $contact['id']) ? ' forum-selected' : '');
|
||||
|
||||
$entry = array(
|
||||
'url' => 'network?f=&cid=' . $contact['id'],
|
||||
'external_url' => 'redir/' . $contact['id'],
|
||||
'name' => $contact['name'],
|
||||
'cid' => $contact['id'],
|
||||
'selected' => $selected,
|
||||
'micro' => App::remove_baseurl(proxy_url($contact['micro'], false, PROXY_SIZE_MICRO)),
|
||||
'id' => ++$id,
|
||||
);
|
||||
$entries[] = $entry;
|
||||
}
|
||||
|
||||
$tpl = get_markup_template('widget_forumlist.tpl');
|
||||
|
||||
$o .= replace_macros($tpl,array(
|
||||
'$title' => t('Forums'),
|
||||
'$forums' => $entries,
|
||||
'$link_desc' => t('External link to forum'),
|
||||
'$total' => $total,
|
||||
'$visible_forums' => $visible_forums,
|
||||
'$showmore' => t('show more'),
|
||||
));
|
||||
}
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Format forumlist as contact block
|
||||
*
|
||||
* This function is used to show the forumlist in
|
||||
* the advanced profile.
|
||||
*
|
||||
* @param int $uid The ID of the User
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
public static function profile_advanced($uid) {
|
||||
|
||||
$profile = intval(feature_enabled($uid,'forumlist_profile'));
|
||||
if(! $profile)
|
||||
return;
|
||||
|
||||
$o = '';
|
||||
|
||||
// place holder in case somebody wants configurability
|
||||
$show_total = 9999;
|
||||
|
||||
//don't sort by last updated item
|
||||
$lastitem = false;
|
||||
|
||||
$contacts = self::get_list($uid,false,$lastitem,false);
|
||||
|
||||
$total_shown = 0;
|
||||
|
||||
foreach($contacts as $contact) {
|
||||
$forumlist .= micropro($contact,false,'forumlist-profile-advanced');
|
||||
$total_shown ++;
|
||||
if($total_shown == $show_total)
|
||||
break;
|
||||
}
|
||||
|
||||
if(count($contacts) > 0)
|
||||
$o .= $forumlist;
|
||||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief count unread forum items
|
||||
*
|
||||
* Count unread items of connected forums and private groups
|
||||
*
|
||||
* @return array
|
||||
* 'id' => contact id
|
||||
* 'name' => contact/forum name
|
||||
* 'count' => counted unseen forum items
|
||||
*
|
||||
*/
|
||||
public static function count_unseen_items() {
|
||||
$r = q("SELECT `contact`.`id`, `contact`.`name`, COUNT(*) AS `count` FROM `item`
|
||||
INNER JOIN `contact` ON `item`.`contact-id` = `contact`.`id`
|
||||
WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` AND `item`.`unseen`
|
||||
AND `contact`.`network`= 'dfrn' AND (`contact`.`forum` OR `contact`.`prv`)
|
||||
AND NOT `contact`.`blocked` AND NOT `contact`.`hidden`
|
||||
AND NOT `contact`.`pending` AND NOT `contact`.`archive`
|
||||
AND `contact`.`success_update` > `failure_update`
|
||||
GROUP BY `contact`.`id` ",
|
||||
intval(local_user())
|
||||
);
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
}
|
136
include/NotificationsManager.php
Normal file
136
include/NotificationsManager.php
Normal file
|
@ -0,0 +1,136 @@
|
|||
<?php
|
||||
/**
|
||||
* @file include/NotificationsManager.php
|
||||
*/
|
||||
require_once('include/html2plain.php');
|
||||
require_once("include/datetime.php");
|
||||
require_once("include/bbcode.php");
|
||||
|
||||
/**
|
||||
* @brief Read and write notifications from/to database
|
||||
*/
|
||||
class NotificationsManager {
|
||||
private $a;
|
||||
|
||||
public function __construct() {
|
||||
$this->a = get_app();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief set some extra note properties
|
||||
*
|
||||
* @param array $notes array of note arrays from db
|
||||
* @return array Copy of input array with added properties
|
||||
*
|
||||
* Set some extra properties to note array from db:
|
||||
* - timestamp as int in default TZ
|
||||
* - date_rel : relative date string
|
||||
* - msg_html: message as html string
|
||||
* - msg_plain: message as plain text string
|
||||
*/
|
||||
private function _set_extra($notes) {
|
||||
$rets = array();
|
||||
foreach($notes as $n) {
|
||||
$local_time = datetime_convert('UTC',date_default_timezone_get(),$n['date']);
|
||||
$n['timestamp'] = strtotime($local_time);
|
||||
$n['date_rel'] = relative_date($n['date']);
|
||||
$n['msg_html'] = bbcode($n['msg'], false, false, false, false);
|
||||
$n['msg_plain'] = explode("\n",trim(html2plain($n['msg_html'], 0)))[0];
|
||||
|
||||
$rets[] = $n;
|
||||
}
|
||||
return $rets;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get all notifications for local_user()
|
||||
*
|
||||
* @param array $filter optional Array "column name"=>value: filter query by columns values
|
||||
* @param string $order optional Space separated list of column to sort by. prepend name with "+" to sort ASC, "-" to sort DESC. Default to "-date"
|
||||
* @param string $limit optional Query limits
|
||||
*
|
||||
* @return array of results or false on errors
|
||||
*/
|
||||
public function getAll($filter = array(), $order="-date", $limit="") {
|
||||
$filter_str = array();
|
||||
$filter_sql = "";
|
||||
foreach($filter as $column => $value) {
|
||||
$filter_str[] = sprintf("`%s` = '%s'", $column, dbesc($value));
|
||||
}
|
||||
if (count($filter_str)>0) {
|
||||
$filter_sql = "AND ".implode(" AND ", $filter_str);
|
||||
}
|
||||
|
||||
$aOrder = explode(" ", $order);
|
||||
$asOrder = array();
|
||||
foreach($aOrder as $o) {
|
||||
$dir = "asc";
|
||||
if ($o[0]==="-") {
|
||||
$dir = "desc";
|
||||
$o = substr($o,1);
|
||||
}
|
||||
if ($o[0]==="+") {
|
||||
$dir = "asc";
|
||||
$o = substr($o,1);
|
||||
}
|
||||
$asOrder[] = "$o $dir";
|
||||
}
|
||||
$order_sql = implode(", ", $asOrder);
|
||||
|
||||
if ($limit!="") $limit = " LIMIT ".$limit;
|
||||
|
||||
$r = q("SELECT * FROM `notify` WHERE `uid` = %d $filter_sql ORDER BY $order_sql $limit",
|
||||
intval(local_user())
|
||||
);
|
||||
if ($r!==false && count($r)>0) return $this->_set_extra($r);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get one note for local_user() by $id value
|
||||
*
|
||||
* @param int $id
|
||||
* @return array note values or null if not found
|
||||
*/
|
||||
public function getByID($id) {
|
||||
$r = q("SELECT * FROM `notify` WHERE `id` = %d AND `uid` = %d LIMIT 1",
|
||||
intval($id),
|
||||
intval(local_user())
|
||||
);
|
||||
if($r!==false && count($r)>0) {
|
||||
return $this->_set_extra($r)[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief set seen state of $note of local_user()
|
||||
*
|
||||
* @param array $note
|
||||
* @param bool $seen optional true or false, default true
|
||||
* @return bool true on success, false on errors
|
||||
*/
|
||||
public function setSeen($note, $seen = true) {
|
||||
return q("UPDATE `notify` SET `seen` = %d WHERE ( `link` = '%s' OR ( `parent` != 0 AND `parent` = %d AND `otype` = '%s' )) AND `uid` = %d",
|
||||
intval($seen),
|
||||
dbesc($note['link']),
|
||||
intval($note['parent']),
|
||||
dbesc($note['otype']),
|
||||
intval(local_user())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief set seen state of all notifications of local_user()
|
||||
*
|
||||
* @param bool $seen optional true or false. default true
|
||||
* @return bool true on success, false on error
|
||||
*/
|
||||
public function setAllSeen($seen = true) {
|
||||
return q("UPDATE `notify` SET `seen` = %d WHERE `uid` = %d",
|
||||
intval($seen),
|
||||
intval(local_user())
|
||||
);
|
||||
}
|
||||
}
|
|
@ -726,10 +726,11 @@ function guess_image_type($filename, $fromcurl=false) {
|
|||
* @param string $avatar Link to avatar picture
|
||||
* @param int $uid User id of contact owner
|
||||
* @param int $cid Contact id
|
||||
* @param bool $force force picture update
|
||||
*
|
||||
* @return array Returns array of the different avatar sizes
|
||||
*/
|
||||
function update_contact_avatar($avatar,$uid,$cid) {
|
||||
function update_contact_avatar($avatar,$uid,$cid, $force = false) {
|
||||
|
||||
$r = q("SELECT `avatar`, `photo`, `thumb`, `micro` FROM `contact` WHERE `id` = %d LIMIT 1", intval($cid));
|
||||
if (!$r)
|
||||
|
@ -737,7 +738,7 @@ function update_contact_avatar($avatar,$uid,$cid) {
|
|||
else
|
||||
$data = array($r[0]["photo"], $r[0]["thumb"], $r[0]["micro"]);
|
||||
|
||||
if ($r[0]["avatar"] != $avatar) {
|
||||
if (($r[0]["avatar"] != $avatar) OR $force) {
|
||||
$photos = import_profile_photo($avatar,$uid,$cid, true);
|
||||
|
||||
if ($photos) {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
require_once('library/HTML5/Parser.php');
|
||||
require_once('include/crypto.php');
|
||||
require_once('include/feed.php');
|
||||
|
||||
if(! function_exists('scrape_dfrn')) {
|
||||
function scrape_dfrn($url, $dont_probe = false) {
|
||||
|
@ -12,9 +13,25 @@ function scrape_dfrn($url, $dont_probe = false) {
|
|||
|
||||
logger('scrape_dfrn: url=' . $url);
|
||||
|
||||
// Try to fetch the data from noscrape. This is faster than parsing the HTML
|
||||
$noscrape = str_replace("/hcard/", "/noscrape/", $url);
|
||||
$noscrapejson = fetch_url($noscrape);
|
||||
$noscrapedata = array();
|
||||
if ($noscrapejson) {
|
||||
$noscrapedata = json_decode($noscrapejson, true);
|
||||
|
||||
if (is_array($noscrapedata)) {
|
||||
if ($noscrapedata["nick"] != "")
|
||||
return($noscrapedata);
|
||||
else
|
||||
unset($noscrapedata["nick"]);
|
||||
} else
|
||||
$noscrapedata = array();
|
||||
}
|
||||
|
||||
$s = fetch_url($url);
|
||||
|
||||
if(! $s)
|
||||
if (!$s)
|
||||
return $ret;
|
||||
|
||||
if (!$dont_probe) {
|
||||
|
@ -91,8 +108,7 @@ function scrape_dfrn($url, $dont_probe = false) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
return array_merge($ret, $noscrapedata);
|
||||
}}
|
||||
|
||||
|
||||
|
@ -342,7 +358,7 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
|
|||
|
||||
$result = array();
|
||||
|
||||
if(! $url)
|
||||
if (!$url)
|
||||
return $result;
|
||||
|
||||
$result = Cache::get("probe_url:".$mode.":".$url);
|
||||
|
@ -351,6 +367,7 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
|
|||
return $result;
|
||||
}
|
||||
|
||||
$original_url = $url;
|
||||
$network = null;
|
||||
$diaspora = false;
|
||||
$diaspora_base = '';
|
||||
|
@ -366,8 +383,6 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
|
|||
$network = NETWORK_TWITTER;
|
||||
}
|
||||
|
||||
// Twitter is deactivated since twitter closed its old API
|
||||
//$twitter = ((strpos($url,'twitter.com') !== false) ? true : false);
|
||||
$lastfm = ((strpos($url,'last.fm/user') !== false) ? true : false);
|
||||
|
||||
$at_addr = ((strpos($url,'@') !== false) ? true : false);
|
||||
|
@ -381,7 +396,12 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
|
|||
else
|
||||
$links = lrdd($url);
|
||||
|
||||
if(count($links)) {
|
||||
if ((count($links) == 0) AND strstr($url, "/index.php")) {
|
||||
$url = str_replace("/index.php", "", $url);
|
||||
$links = lrdd($url);
|
||||
}
|
||||
|
||||
if (count($links)) {
|
||||
$has_lrdd = true;
|
||||
|
||||
logger('probe_url: found lrdd links: ' . print_r($links,true), LOGGER_DATA);
|
||||
|
@ -428,12 +448,21 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
|
|||
// aliases, let's hope we're lucky and get one that matches the feed author-uri because
|
||||
// otherwise we're screwed.
|
||||
|
||||
$backup_alias = "";
|
||||
|
||||
foreach($links as $link) {
|
||||
if($link['@attributes']['rel'] === 'alias') {
|
||||
if(strpos($link['@attributes']['href'],'@') === false) {
|
||||
if(isset($profile)) {
|
||||
if($link['@attributes']['href'] !== $profile)
|
||||
$alias = unamp($link['@attributes']['href']);
|
||||
$alias_url = $link['@attributes']['href'];
|
||||
|
||||
if(($alias_url !== $profile) AND ($backup_alias == "") AND
|
||||
($alias_url !== str_replace("/index.php", "", $profile)))
|
||||
$backup_alias = $alias_url;
|
||||
|
||||
if(($alias_url !== $profile) AND !strstr($alias_url, "index.php") AND
|
||||
($alias_url !== str_replace("/index.php", "", $profile)))
|
||||
$alias = $alias_url;
|
||||
}
|
||||
else
|
||||
$profile = unamp($link['@attributes']['href']);
|
||||
|
@ -441,6 +470,9 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
|
|||
}
|
||||
}
|
||||
|
||||
if ($alias == "")
|
||||
$alias = $backup_alias;
|
||||
|
||||
// If the profile is different from the url then the url is abviously an alias
|
||||
if (($alias == "") AND ($profile != "") AND !$at_addr AND (normalise_link($profile) != normalise_link($url)))
|
||||
$alias = $url;
|
||||
|
@ -604,21 +636,6 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
|
|||
$vcard['nick'] = $addr_parts[0];
|
||||
}
|
||||
|
||||
/* if($twitter) {
|
||||
logger('twitter: setup');
|
||||
$tid = basename($url);
|
||||
$tapi = 'https://api.twitter.com/1/statuses/user_timeline.rss';
|
||||
if(intval($tid))
|
||||
$poll = $tapi . '?user_id=' . $tid;
|
||||
else
|
||||
$poll = $tapi . '?screen_name=' . $tid;
|
||||
$profile = 'http://twitter.com/#!/' . $tid;
|
||||
//$vcard['photo'] = 'https://api.twitter.com/1/users/profile_image/' . $tid;
|
||||
$vcard['photo'] = 'https://api.twitter.com/1/users/profile_image?screen_name=' . $tid . '&size=bigger';
|
||||
$vcard['nick'] = $tid;
|
||||
$vcard['fn'] = $tid;
|
||||
} */
|
||||
|
||||
if($lastfm) {
|
||||
$profile = $url;
|
||||
$poll = str_replace(array('www.','last.fm/'),array('','ws.audioscrobbler.com/1.0/'),$url) . '/recenttracks.rss';
|
||||
|
@ -662,85 +679,41 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
|
|||
|
||||
if(x($feedret,'photo') && (! x($vcard,'photo')))
|
||||
$vcard['photo'] = $feedret['photo'];
|
||||
require_once('library/simplepie/simplepie.inc');
|
||||
$feed = new SimplePie();
|
||||
|
||||
$cookiejar = tempnam(get_temppath(), 'cookiejar-scrape-feed-');
|
||||
$xml = fetch_url($poll, false, $redirects, 0, Null, $cookiejar);
|
||||
unlink($cookiejar);
|
||||
|
||||
logger('probe_url: fetch feed: ' . $poll . ' returns: ' . $xml, LOGGER_DATA);
|
||||
$a = get_app();
|
||||
|
||||
logger('probe_url: scrape_feed: headers: ' . $a->get_curl_headers(), LOGGER_DATA);
|
||||
|
||||
// Don't try and parse an empty string
|
||||
$feed->set_raw_data(($xml) ? $xml : '<?xml version="1.0" encoding="utf-8" ?><xml></xml>');
|
||||
|
||||
$feed->init();
|
||||
if($feed->error()) {
|
||||
logger('probe_url: scrape_feed: Error parsing XML: ' . $feed->error());
|
||||
if ($xml == "") {
|
||||
logger("scrape_feed: XML is empty for feed ".$poll);
|
||||
$network = NETWORK_PHANTOM;
|
||||
}
|
||||
} else {
|
||||
$data = feed_import($xml,$dummy1,$dummy2, $dummy3, true);
|
||||
|
||||
if(! x($vcard,'photo'))
|
||||
$vcard['photo'] = $feed->get_image_url();
|
||||
$author = $feed->get_author();
|
||||
if (!is_array($data)) {
|
||||
logger("scrape_feed: This doesn't seem to be a feed: ".$poll);
|
||||
$network = NETWORK_PHANTOM;
|
||||
} else {
|
||||
if (($vcard["photo"] == "") AND ($data["header"]["author-avatar"] != ""))
|
||||
$vcard["photo"] = $data["header"]["author-avatar"];
|
||||
|
||||
if($author) {
|
||||
$vcard['fn'] = unxmlify(trim($author->get_name()));
|
||||
if(! $vcard['fn'])
|
||||
$vcard['fn'] = trim(unxmlify($author->get_email()));
|
||||
if(strpos($vcard['fn'],'@') !== false)
|
||||
$vcard['fn'] = substr($vcard['fn'],0,strpos($vcard['fn'],'@'));
|
||||
if (($vcard["fn"] == "") AND ($data["header"]["author-name"] != ""))
|
||||
$vcard["fn"] = $data["header"]["author-name"];
|
||||
|
||||
$email = unxmlify($author->get_email());
|
||||
if(! $profile && $author->get_link())
|
||||
$profile = trim(unxmlify($author->get_link()));
|
||||
if(! $vcard['photo']) {
|
||||
$rawtags = $feed->get_feed_tags( SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
|
||||
if($rawtags) {
|
||||
$elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10];
|
||||
if((x($elems,'link')) && ($elems['link'][0]['attribs']['']['rel'] === 'photo'))
|
||||
$vcard['photo'] = $elems['link'][0]['attribs']['']['href'];
|
||||
}
|
||||
}
|
||||
// Fetch fullname via poco:displayName
|
||||
$pocotags = $feed->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
|
||||
if ($pocotags) {
|
||||
$elems = $pocotags[0]['child']['http://portablecontacts.net/spec/1.0'];
|
||||
if (isset($elems["displayName"]))
|
||||
$vcard['fn'] = $elems["displayName"][0]["data"];
|
||||
if (isset($elems["preferredUsername"]))
|
||||
$vcard['nick'] = $elems["preferredUsername"][0]["data"];
|
||||
}
|
||||
}
|
||||
else {
|
||||
$item = $feed->get_item(0);
|
||||
if($item) {
|
||||
$author = $item->get_author();
|
||||
if($author) {
|
||||
$vcard['fn'] = trim(unxmlify($author->get_name()));
|
||||
if(! $vcard['fn'])
|
||||
$vcard['fn'] = trim(unxmlify($author->get_email()));
|
||||
if(strpos($vcard['fn'],'@') !== false)
|
||||
$vcard['fn'] = substr($vcard['fn'],0,strpos($vcard['fn'],'@'));
|
||||
$email = unxmlify($author->get_email());
|
||||
if(! $profile && $author->get_link())
|
||||
$profile = trim(unxmlify($author->get_link()));
|
||||
}
|
||||
if(! $vcard['photo']) {
|
||||
$rawmedia = $item->get_item_tags('http://search.yahoo.com/mrss/','thumbnail');
|
||||
if($rawmedia && $rawmedia[0]['attribs']['']['url'])
|
||||
$vcard['photo'] = unxmlify($rawmedia[0]['attribs']['']['url']);
|
||||
}
|
||||
if(! $vcard['photo']) {
|
||||
$rawtags = $item->get_item_tags( SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
|
||||
if($rawtags) {
|
||||
$elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10];
|
||||
if((x($elems,'link')) && ($elems['link'][0]['attribs']['']['rel'] === 'photo'))
|
||||
$vcard['photo'] = $elems['link'][0]['attribs']['']['href'];
|
||||
}
|
||||
}
|
||||
if (($vcard["nick"] == "") AND ($data["header"]["author-nick"] != ""))
|
||||
$vcard["nick"] = $data["header"]["author-nick"];
|
||||
|
||||
if ($network == NETWORK_OSTATUS) {
|
||||
if ($data["header"]["author-id"] != "")
|
||||
$alias = $data["header"]["author-id"];
|
||||
|
||||
if ($data["header"]["author-link"] != "")
|
||||
$profile = $data["header"]["author-link"];
|
||||
|
||||
} elseif(!$profile AND ($data["header"]["author-link"] != "") AND !in_array($network, array("", NETWORK_FEED)))
|
||||
$profile = $data["header"]["author-link"];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -783,27 +756,9 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
|
|||
}
|
||||
}
|
||||
|
||||
if((! $vcard['photo']) && strlen($email))
|
||||
$vcard['photo'] = avatar_img($email);
|
||||
if($poll === $profile)
|
||||
$lnk = $feed->get_permalink();
|
||||
if(isset($lnk) && strlen($lnk))
|
||||
$profile = $lnk;
|
||||
|
||||
if(! $network) {
|
||||
if(! $network)
|
||||
$network = NETWORK_FEED;
|
||||
// If it is a feed, don't take the author name as feed name
|
||||
unset($vcard['fn']);
|
||||
}
|
||||
if(! (x($vcard,'fn')))
|
||||
$vcard['fn'] = notags($feed->get_title());
|
||||
if(! (x($vcard,'fn')))
|
||||
$vcard['fn'] = notags($feed->get_description());
|
||||
|
||||
if(strpos($vcard['fn'],'Twitter / ') !== false) {
|
||||
$vcard['fn'] = substr($vcard['fn'],strpos($vcard['fn'],'/')+1);
|
||||
$vcard['fn'] = trim($vcard['fn']);
|
||||
}
|
||||
if(! x($vcard,'nick')) {
|
||||
$vcard['nick'] = strtolower(notags(unxmlify($vcard['fn'])));
|
||||
if(strpos($vcard['nick'],' '))
|
||||
|
@ -816,7 +771,7 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
|
|||
|
||||
if(! x($vcard,'photo')) {
|
||||
$a = get_app();
|
||||
$vcard['photo'] = $a->get_baseurl() . '/images/person-175.jpg' ;
|
||||
$vcard['photo'] = App::get_baseurl() . '/images/person-175.jpg' ;
|
||||
}
|
||||
|
||||
if(! $profile)
|
||||
|
@ -828,18 +783,21 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
|
|||
$vcard['fn'] = $url;
|
||||
|
||||
if (($notify != "") AND ($poll != "")) {
|
||||
$baseurl = matching(normalise_link($notify), normalise_link($poll));
|
||||
$baseurl = matching_url(normalise_link($notify), normalise_link($poll));
|
||||
|
||||
$baseurl2 = matching($baseurl, normalise_link($profile));
|
||||
$baseurl2 = matching_url($baseurl, normalise_link($profile));
|
||||
if ($baseurl2 != "")
|
||||
$baseurl = $baseurl2;
|
||||
}
|
||||
|
||||
if (($baseurl == "") AND ($notify != ""))
|
||||
$baseurl = matching(normalise_link($profile), normalise_link($notify));
|
||||
$baseurl = matching_url(normalise_link($profile), normalise_link($notify));
|
||||
|
||||
if (($baseurl == "") AND ($poll != ""))
|
||||
$baseurl = matching(normalise_link($profile), normalise_link($poll));
|
||||
$baseurl = matching_url(normalise_link($profile), normalise_link($poll));
|
||||
|
||||
if (substr($baseurl, -10) == "/index.php")
|
||||
$baseurl = str_replace("/index.php", "", $baseurl);
|
||||
|
||||
$baseurl = rtrim($baseurl, "/");
|
||||
|
||||
|
@ -888,25 +846,82 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
|
|||
}
|
||||
|
||||
// Only store into the cache if the value seems to be valid
|
||||
if ($result['network'] != NETWORK_PHANTOM)
|
||||
Cache::set("probe_url:".$mode.":".$url,serialize($result), CACHE_DAY);
|
||||
if ($result['network'] != NETWORK_PHANTOM) {
|
||||
Cache::set("probe_url:".$mode.":".$original_url,serialize($result), CACHE_DAY);
|
||||
|
||||
/// @todo temporary fix - we need a real contact update function that updates only changing fields
|
||||
/// The biggest problem is the avatar picture that could have a reduced image size.
|
||||
/// It should only be updated if the existing picture isn't existing anymore.
|
||||
if (($result['network'] != NETWORK_FEED) AND ($mode == PROBE_NORMAL) AND
|
||||
$result["name"] AND $result["nick"] AND $result["url"] AND $result["addr"] AND $result["poll"])
|
||||
q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `url` = '%s', `addr` = '%s',
|
||||
`notify` = '%s', `poll` = '%s', `alias` = '%s', `success_update` = '%s'
|
||||
WHERE `nurl` = '%s' AND NOT `self` AND `uid` = 0",
|
||||
dbesc($result["name"]),
|
||||
dbesc($result["nick"]),
|
||||
dbesc($result["url"]),
|
||||
dbesc($result["addr"]),
|
||||
dbesc($result["notify"]),
|
||||
dbesc($result["poll"]),
|
||||
dbesc($result["alias"]),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc(normalise_link($result['url']))
|
||||
);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function matching($part1, $part2) {
|
||||
$len = min(strlen($part1), strlen($part2));
|
||||
/**
|
||||
* @brief Find the matching part between two url
|
||||
*
|
||||
* @param string $url1
|
||||
* @param string $url2
|
||||
* @return string The matching part
|
||||
*/
|
||||
function matching_url($url1, $url2) {
|
||||
|
||||
if (($url1 == "") OR ($url2 == ""))
|
||||
return "";
|
||||
|
||||
$url1 = normalise_link($url1);
|
||||
$url2 = normalise_link($url2);
|
||||
|
||||
$parts1 = parse_url($url1);
|
||||
$parts2 = parse_url($url2);
|
||||
|
||||
if (!isset($parts1["host"]) OR !isset($parts2["host"]))
|
||||
return "";
|
||||
|
||||
if ($parts1["scheme"] != $parts2["scheme"])
|
||||
return "";
|
||||
|
||||
if ($parts1["host"] != $parts2["host"])
|
||||
return "";
|
||||
|
||||
if ($parts1["port"] != $parts2["port"])
|
||||
return "";
|
||||
|
||||
$match = $parts1["scheme"]."://".$parts1["host"];
|
||||
|
||||
if ($parts1["port"])
|
||||
$match .= ":".$parts1["port"];
|
||||
|
||||
$pathparts1 = explode("/", $parts1["path"]);
|
||||
$pathparts2 = explode("/", $parts2["path"]);
|
||||
|
||||
$match = "";
|
||||
$matching = true;
|
||||
$i = 0;
|
||||
while (($i <= $len) AND $matching) {
|
||||
if (substr($part1, $i, 1) == substr($part2, $i, 1))
|
||||
$match .= substr($part1, $i, 1);
|
||||
else
|
||||
$matching = false;
|
||||
$path = "";
|
||||
do {
|
||||
$path1 = $pathparts1[$i];
|
||||
$path2 = $pathparts2[$i];
|
||||
|
||||
$i++;
|
||||
}
|
||||
return($match);
|
||||
if ($path1 == $path2)
|
||||
$path .= $path1."/";
|
||||
|
||||
} while (($path1 == $path2) AND ($i++ <= count($pathparts1)));
|
||||
|
||||
$match .= $path;
|
||||
|
||||
return normalise_link($match);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file include/smilies.php
|
||||
* @file include/Smilies.php
|
||||
* @brief This file contains the Smilies class which contains functions to handle smiles
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -63,41 +64,41 @@ class Smilies {
|
|||
);
|
||||
|
||||
$icons = array(
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-heart.gif" alt="<3" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-brokenheart.gif" alt="</3" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-brokenheart.gif" alt="<\\3" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-smile.gif" alt=":-)" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-wink.gif" alt=";-)" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-frown.gif" alt=":-(" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-tongue-out.gif" alt=":-P" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-tongue-out.gif" alt=":-p" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-kiss.gif" alt=":-\"" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-kiss.gif" alt=":-\"" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-kiss.gif" alt=":-x" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-kiss.gif" alt=":-X" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-laughing.gif" alt=":-D" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-surprised.gif" alt="8-|" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-surprised.gif" alt="8-O" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-surprised.gif" alt=":-O" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-thumbsup.gif" alt="\\o/" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-Oo.gif" alt="o.O" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-Oo.gif" alt="O.o" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-Oo.gif" alt="o_O" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-Oo.gif" alt="O_o" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-cry.gif" alt=":\'(" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-foot-in-mouth.gif" alt=":-!" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-undecided.gif" alt=":-/" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-embarassed.gif" alt=":-[" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-cool.gif" alt="8-)" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/beer_mug.gif" alt=":beer" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/beer_mug.gif" alt=":homebrew" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/coffee.gif" alt=":coffee" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-facepalm.gif" alt=":facepalm" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/like.gif" alt=":like" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/dislike.gif" alt=":dislike" />',
|
||||
'<a href="http://friendica.com">~friendica <img class="smiley" src="' . app::get_baseurl() . '/images/friendica-16.png" alt="~friendica" /></a>',
|
||||
'<a href="http://redmatrix.me/">red<img class="smiley" src="' . app::get_baseurl() . '/images/rm-16.png" alt="red" />matrix</a>',
|
||||
'<a href="http://redmatrix.me/">red<img class="smiley" src="' . app::get_baseurl() . '/images/rm-16.png" alt="red" />matrix</a>'
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-heart.gif" alt="<3" title="<3" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-brokenheart.gif" alt="</3" title="</3" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-brokenheart.gif" alt="<\\3" title="<\\3" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-smile.gif" alt=":-)" title=":-)" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-wink.gif" alt=";-)" title=";-)" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-frown.gif" alt=":-(" title=":-(" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-tongue-out.gif" alt=":-P" title=":-P" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-tongue-out.gif" alt=":-p" title=":-P" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-kiss.gif" alt=":-\" title=":-\" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-kiss.gif" alt=":-\" title=":-\" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-kiss.gif" alt=":-x" title=":-x" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-kiss.gif" alt=":-X" title=":-X" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-laughing.gif" alt=":-D" title=":-D" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-surprised.gif" alt="8-|" title="8-|" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-surprised.gif" alt="8-O" title="8-O" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-surprised.gif" alt=":-O" title="8-O" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-thumbsup.gif" alt="\\o/" title="\\o/" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-Oo.gif" alt="o.O" title="o.O" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-Oo.gif" alt="O.o" title="O.o" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-Oo.gif" alt="o_O" title="o_O" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-Oo.gif" alt="O_o" title="O_o" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-cry.gif" alt=":\'(" title=":\'("/>',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-foot-in-mouth.gif" alt=":-!" title=":-!" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-undecided.gif" alt=":-/" title=":-/" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-embarassed.gif" alt=":-[" title=":-[" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-cool.gif" alt="8-)" title="8-)" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/beer_mug.gif" alt=":beer" title=":beer" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/beer_mug.gif" alt=":homebrew" title=":homebrew" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/coffee.gif" alt=":coffee" title=":coffee" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-facepalm.gif" alt=":facepalm" title=":facepalm" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/like.gif" alt=":like" title=":like" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/dislike.gif" alt=":dislike" title=":dislike" />',
|
||||
'<a href="http://friendica.com">~friendica <img class="smiley" src="' . app::get_baseurl() . '/images/friendica-16.png" alt="~friendica" title="~friendica" /></a>',
|
||||
'<a href="http://redmatrix.me/">red<img class="smiley" src="' . app::get_baseurl() . '/images/rm-16.png" alt="red#" title="red#" />matrix</a>',
|
||||
'<a href="http://redmatrix.me/">red<img class="smiley" src="' . app::get_baseurl() . '/images/rm-16.png" alt="red#matrix" title="red#matrix" />matrix</a>'
|
||||
);
|
||||
|
||||
$params = array('texts' => $texts, 'icons' => $icons);
|
||||
|
|
170
include/api.php
170
include/api.php
|
@ -23,6 +23,7 @@
|
|||
require_once('include/message.php');
|
||||
require_once('include/group.php');
|
||||
require_once('include/like.php');
|
||||
require_once('include/NotificationsManager.php');
|
||||
|
||||
|
||||
define('API_METHOD_ANY','*');
|
||||
|
@ -160,10 +161,7 @@
|
|||
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
||||
logger('API_login: ' . print_r($_SERVER,true), LOGGER_DEBUG);
|
||||
header('WWW-Authenticate: Basic realm="Friendica"');
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
die((api_error($a, 'json', "This api requires login")));
|
||||
|
||||
//die('This api requires login');
|
||||
throw new UnauthorizedException("This API requires login");
|
||||
}
|
||||
|
||||
$user = $_SERVER['PHP_AUTH_USER'];
|
||||
|
@ -215,8 +213,9 @@
|
|||
if((! $record) || (! count($record))) {
|
||||
logger('API_login failure: ' . print_r($_SERVER,true), LOGGER_DEBUG);
|
||||
header('WWW-Authenticate: Basic realm="Friendica"');
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
die('This api requires login');
|
||||
#header('HTTP/1.0 401 Unauthorized');
|
||||
#die('This api requires login');
|
||||
throw new UnauthorizedException("This API requires login");
|
||||
}
|
||||
|
||||
authenticate_success($record); $_SESSION["allow_api"] = true;
|
||||
|
@ -250,7 +249,7 @@
|
|||
*/
|
||||
function api_call(&$a){
|
||||
GLOBAL $API, $called_api;
|
||||
|
||||
|
||||
$type="json";
|
||||
if (strpos($a->query_string, ".xml")>0) $type="xml";
|
||||
if (strpos($a->query_string, ".json")>0) $type="json";
|
||||
|
@ -330,7 +329,8 @@
|
|||
*
|
||||
* @param Api $a
|
||||
* @param string $type Return type (xml, json, rss, as)
|
||||
* @param string $error Error message
|
||||
* @param HTTPException $error Error object
|
||||
* @return strin error message formatted as $type
|
||||
*/
|
||||
function api_error(&$a, $type, $e) {
|
||||
$error = ($e->getMessage()!==""?$e->getMessage():$e->httpdesc);
|
||||
|
@ -680,6 +680,34 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief transform $data array in xml without a template
|
||||
*
|
||||
* @param array $data
|
||||
* @return string xml string
|
||||
*/
|
||||
function api_array_to_xml($data, $ename="") {
|
||||
$attrs="";
|
||||
$childs="";
|
||||
if (count($data)==1 && !is_array($data[0])) {
|
||||
$ename = array_keys($data)[0];
|
||||
$v = $data[$ename];
|
||||
return "<$ename>$v</$ename>";
|
||||
}
|
||||
foreach($data as $k=>$v) {
|
||||
$k=trim($k,'$');
|
||||
if (!is_array($v)) {
|
||||
$attrs .= sprintf('%s="%s" ', $k, $v);
|
||||
} else {
|
||||
if (is_numeric($k)) $k=trim($ename,'s');
|
||||
$childs.=api_array_to_xml($v, $k);
|
||||
}
|
||||
}
|
||||
$res = $childs;
|
||||
if ($ename!="") $res = "<$ename $attrs>$res</$ename>";
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* load api $templatename for $type and replace $data array
|
||||
*/
|
||||
|
@ -692,13 +720,17 @@
|
|||
case "rss":
|
||||
case "xml":
|
||||
$data = array_xmlify($data);
|
||||
$tpl = get_markup_template("api_".$templatename."_".$type.".tpl");
|
||||
if(! $tpl) {
|
||||
header ("Content-Type: text/xml");
|
||||
echo '<?xml version="1.0" encoding="UTF-8"?>'."\n".'<status><error>not implemented</error></status>';
|
||||
killme();
|
||||
if ($templatename==="<auto>") {
|
||||
$ret = api_array_to_xml($data);
|
||||
} else {
|
||||
$tpl = get_markup_template("api_".$templatename."_".$type.".tpl");
|
||||
if(! $tpl) {
|
||||
header ("Content-Type: text/xml");
|
||||
echo '<?xml version="1.0" encoding="UTF-8"?>'."\n".'<status><error>not implemented</error></status>';
|
||||
killme();
|
||||
}
|
||||
$ret = replace_macros($tpl, $data);
|
||||
}
|
||||
$ret = replace_macros($tpl, $data);
|
||||
break;
|
||||
case "json":
|
||||
$ret = $data;
|
||||
|
@ -781,8 +813,6 @@
|
|||
|
||||
if((strpos($txt,'<') !== false) || (strpos($txt,'>') !== false)) {
|
||||
|
||||
require_once('library/HTMLPurifier.auto.php');
|
||||
|
||||
$txt = html2bb_video($txt);
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$config->set('Cache.DefinitionImpl', null);
|
||||
|
@ -822,9 +852,6 @@
|
|||
if(requestdata('htmlstatus')) {
|
||||
$txt = requestdata('htmlstatus');
|
||||
if((strpos($txt,'<') !== false) || (strpos($txt,'>') !== false)) {
|
||||
|
||||
require_once('library/HTMLPurifier.auto.php');
|
||||
|
||||
$txt = html2bb_video($txt);
|
||||
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
|
@ -875,7 +902,8 @@
|
|||
|
||||
if ($posts_day > $throttle_day) {
|
||||
logger('Daily posting limit reached for user '.api_user(), LOGGER_DEBUG);
|
||||
die(api_error($a, $type, sprintf(t("Daily posting limit of %d posts reached. The post was rejected."), $throttle_day)));
|
||||
#die(api_error($a, $type, sprintf(t("Daily posting limit of %d posts reached. The post was rejected."), $throttle_day)));
|
||||
throw new TooManyRequestsException(sprintf(t("Daily posting limit of %d posts reached. The post was rejected."), $throttle_day));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -894,7 +922,9 @@
|
|||
|
||||
if ($posts_week > $throttle_week) {
|
||||
logger('Weekly posting limit reached for user '.api_user(), LOGGER_DEBUG);
|
||||
die(api_error($a, $type, sprintf(t("Weekly posting limit of %d posts reached. The post was rejected."), $throttle_week)));
|
||||
#die(api_error($a, $type, sprintf(t("Weekly posting limit of %d posts reached. The post was rejected."), $throttle_week)));
|
||||
throw new TooManyRequestsException(sprintf(t("Weekly posting limit of %d posts reached. The post was rejected."), $throttle_week));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -913,7 +943,8 @@
|
|||
|
||||
if ($posts_month > $throttle_month) {
|
||||
logger('Monthly posting limit reached for user '.api_user(), LOGGER_DEBUG);
|
||||
die(api_error($a, $type, sprintf(t("Monthly posting limit of %d posts reached. The post was rejected."), $throttle_month)));
|
||||
#die(api_error($a, $type, sprintf(t("Monthly posting limit of %d posts reached. The post was rejected."), $throttle_month)));
|
||||
throw new TooManyRequestsException(sprintf(t("Monthly posting limit of %d posts reached. The post was rejected."), $throttle_month));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1493,15 +1524,21 @@
|
|||
if ($max_id > 0)
|
||||
$sql_extra = ' AND `item`.`id` <= '.intval($max_id);
|
||||
|
||||
// Not sure why this query was so complicated. We should keep it here for a while,
|
||||
// just to make sure that we really don't need it.
|
||||
// FROM `item` INNER JOIN (SELECT `uri`,`parent` FROM `item` WHERE `id` = %d) AS `temp1`
|
||||
// ON (`item`.`thr-parent` = `temp1`.`uri` AND `item`.`parent` = `temp1`.`parent`)
|
||||
|
||||
$r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
|
||||
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
|
||||
`contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
|
||||
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
|
||||
FROM `item` INNER JOIN (SELECT `uri`,`parent` FROM `item` WHERE `id` = %d) AS `temp1`
|
||||
ON (`item`.`thr-parent` = `temp1`.`uri` AND `item`.`parent` = `temp1`.`parent`), `contact`
|
||||
WHERE `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
|
||||
AND `item`.`uid` = %d AND `item`.`verb` = '%s' AND `contact`.`id` = `item`.`contact-id`
|
||||
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
|
||||
FROM `item`
|
||||
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
|
||||
WHERE `item`.`parent` = %d AND `item`.`visible`
|
||||
AND NOT `item`.`moderated` AND NOT `item`.`deleted`
|
||||
AND `item`.`uid` = %d AND `item`.`verb` = '%s'
|
||||
AND NOT `contact`.`blocked` AND NOT `contact`.`pending`
|
||||
AND `item`.`id`>%d $sql_extra
|
||||
ORDER BY `item`.`id` DESC LIMIT %d ,%d",
|
||||
intval($id), intval(api_user()),
|
||||
|
@ -1519,6 +1556,7 @@
|
|||
return api_apply_template("timeline", $type, $data);
|
||||
}
|
||||
api_register_func('api/conversation/show','api_conversation_show', true);
|
||||
api_register_func('api/statusnet/conversation','api_conversation_show', true);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -1660,13 +1698,13 @@
|
|||
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
|
||||
`contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
|
||||
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
|
||||
FROM `item`, `contact`
|
||||
FROM `item` FORCE INDEX (`uid_id`), `contact`
|
||||
WHERE `item`.`uid` = %d AND `verb` = '%s'
|
||||
AND NOT (`item`.`author-link` IN ('https://%s', 'http://%s'))
|
||||
AND `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
|
||||
AND `item`.`visible` AND NOT `item`.`moderated` AND NOT `item`.`deleted`
|
||||
AND `contact`.`id` = `item`.`contact-id`
|
||||
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
|
||||
AND `item`.`parent` IN (SELECT `iid` from thread where uid = %d AND `mention` AND !`ignored`)
|
||||
AND NOT `contact`.`blocked` AND NOT `contact`.`pending`
|
||||
AND `item`.`parent` IN (SELECT `iid` FROM `thread` WHERE `uid` = %d AND `mention` AND !`ignored`)
|
||||
$sql_extra
|
||||
AND `item`.`id`>%d
|
||||
ORDER BY `item`.`id` DESC LIMIT %d ,%d ",
|
||||
|
@ -1781,7 +1819,7 @@
|
|||
$action_argv_id=2;
|
||||
if ($a->argv[1]=="1.1") $action_argv_id=3;
|
||||
|
||||
if ($a->argc<=$action_argv_id) die(api_error($a, $type, t("Invalid request.")));
|
||||
if ($a->argc<=$action_argv_id) throw new BadRequestException("Invalid request.");
|
||||
$action = str_replace(".".$type,"",$a->argv[$action_argv_id]);
|
||||
if ($a->argc==$action_argv_id+2) {
|
||||
$itemid = intval($a->argv[$action_argv_id+1]);
|
||||
|
@ -2027,6 +2065,16 @@
|
|||
|
||||
$statushtml = trim(bbcode($body, false, false));
|
||||
|
||||
$search = array("<br>", "<blockquote>", "</blockquote>",
|
||||
"<h1>", "</h1>", "<h2>", "</h2>",
|
||||
"<h3>", "</h3>", "<h4>", "</h4>",
|
||||
"<h5>", "</h5>", "<h6>", "</h6>");
|
||||
$replace = array("<br>\n", "\n<blockquote>", "</blockquote>\n",
|
||||
"\n<h1>", "</h1>\n", "\n<h2>", "</h2>\n",
|
||||
"\n<h3>", "</h3>\n", "\n<h4>", "</h4>\n",
|
||||
"\n<h5>", "</h5>\n", "\n<h6>", "</h6>\n");
|
||||
$statushtml = str_replace($search, $replace, $statushtml);
|
||||
|
||||
if ($item['title'] != "")
|
||||
$statushtml = "<h4>".bbcode($item['title'])."</h4>\n".$statushtml;
|
||||
|
||||
|
@ -3386,6 +3434,64 @@
|
|||
api_register_func('api/friendica/activity/unattendno', 'api_friendica_activity', true, API_METHOD_POST);
|
||||
api_register_func('api/friendica/activity/unattendmaybe', 'api_friendica_activity', true, API_METHOD_POST);
|
||||
|
||||
/**
|
||||
* @brief Returns notifications
|
||||
*
|
||||
* @param App $a
|
||||
* @param string $type Known types are 'atom', 'rss', 'xml' and 'json'
|
||||
* @return string
|
||||
*/
|
||||
function api_friendica_notification(&$a, $type) {
|
||||
if (api_user()===false) throw new ForbiddenException();
|
||||
if ($a->argc!==3) throw new BadRequestException("Invalid argument count");
|
||||
$nm = new NotificationsManager();
|
||||
|
||||
$notes = $nm->getAll(array(), "+seen -date", 50);
|
||||
return api_apply_template("<auto>", $type, array('$notes' => $notes));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set notification as seen and returns associated item (if possible)
|
||||
*
|
||||
* POST request with 'id' param as notification id
|
||||
*
|
||||
* @param App $a
|
||||
* @param string $type Known types are 'atom', 'rss', 'xml' and 'json'
|
||||
* @return string
|
||||
*/
|
||||
function api_friendica_notification_seen(&$a, $type){
|
||||
if (api_user()===false) throw new ForbiddenException();
|
||||
if ($a->argc!==4) throw new BadRequestException("Invalid argument count");
|
||||
|
||||
$id = (x($_REQUEST, 'id') ? intval($_REQUEST['id']) : 0);
|
||||
|
||||
$nm = new NotificationsManager();
|
||||
$note = $nm->getByID($id);
|
||||
if (is_null($note)) throw new BadRequestException("Invalid argument");
|
||||
|
||||
$nm->setSeen($note);
|
||||
if ($note['otype']=='item') {
|
||||
// would be really better with an ItemsManager and $im->getByID() :-P
|
||||
$r = q("SELECT * FROM `item` WHERE `id`=%d AND `uid`=%d",
|
||||
intval($note['iid']),
|
||||
intval(local_user())
|
||||
);
|
||||
if ($r!==false) {
|
||||
// we found the item, return it to the user
|
||||
$user_info = api_get_user($a);
|
||||
$ret = api_format_items($r,$user_info);
|
||||
$data = array('$statuses' => $ret);
|
||||
return api_apply_template("timeline", $type, $data);
|
||||
}
|
||||
// the item can't be found, but we set the note as seen, so we count this as a success
|
||||
}
|
||||
return api_apply_template('<auto>', $type, array('status' => "success"));
|
||||
}
|
||||
|
||||
api_register_func('api/friendica/notification/seen', 'api_friendica_notification_seen', true, API_METHOD_POST);
|
||||
api_register_func('api/friendica/notification', 'api_friendica_notification', true, API_METHOD_GET);
|
||||
|
||||
|
||||
/*
|
||||
To.Do:
|
||||
[pagename] => api/1.1/statuses/lookup.json
|
||||
|
|
|
@ -5,35 +5,14 @@ require_once('include/security.php');
|
|||
require_once('include/datetime.php');
|
||||
|
||||
function nuke_session() {
|
||||
if (get_config('system', 'disable_database_session')) {
|
||||
session_unset();
|
||||
return;
|
||||
}
|
||||
|
||||
new_cookie(0); // make sure cookie is deleted on browser close, as a security measure
|
||||
|
||||
unset($_SESSION['authenticated']);
|
||||
unset($_SESSION['uid']);
|
||||
unset($_SESSION['visitor_id']);
|
||||
unset($_SESSION['administrator']);
|
||||
unset($_SESSION['cid']);
|
||||
unset($_SESSION['theme']);
|
||||
unset($_SESSION['mobile-theme']);
|
||||
unset($_SESSION['page_flags']);
|
||||
unset($_SESSION['submanage']);
|
||||
unset($_SESSION['my_url']);
|
||||
unset($_SESSION['my_address']);
|
||||
unset($_SESSION['addr']);
|
||||
unset($_SESSION['return_url']);
|
||||
|
||||
session_unset();
|
||||
}
|
||||
|
||||
|
||||
// login/logout
|
||||
|
||||
|
||||
|
||||
|
||||
if((isset($_SESSION)) && (x($_SESSION,'authenticated')) && ((! (x($_POST,'auth-params'))) || ($_POST['auth-params'] !== 'login'))) {
|
||||
|
||||
if(((x($_POST,'auth-params')) && ($_POST['auth-params'] === 'logout')) || ($a->module === 'logout')) {
|
||||
|
@ -41,6 +20,7 @@ if((isset($_SESSION)) && (x($_SESSION,'authenticated')) && ((! (x($_POST,'auth-p
|
|||
// process logout request
|
||||
call_hooks("logging_out");
|
||||
nuke_session();
|
||||
new_cookie(-1);
|
||||
info( t('Logged out.') . EOL);
|
||||
goaway(z_root());
|
||||
}
|
||||
|
@ -90,8 +70,7 @@ if((isset($_SESSION)) && (x($_SESSION,'authenticated')) && ((! (x($_POST,'auth-p
|
|||
}
|
||||
authenticate_success($r[0], false, false, $login_refresh);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
|
||||
if(isset($_SESSION)) {
|
||||
nuke_session();
|
||||
|
@ -209,13 +188,11 @@ else {
|
|||
}
|
||||
|
||||
function new_cookie($time) {
|
||||
if (!get_config('system', 'disable_database_session'))
|
||||
$old_sid = session_id();
|
||||
|
||||
session_set_cookie_params($time);
|
||||
if ($time != 0)
|
||||
$time = $time + time();
|
||||
|
||||
if (!get_config('system', 'disable_database_session')) {
|
||||
session_regenerate_id(false);
|
||||
q("UPDATE session SET sid = '%s' WHERE sid = '%s'", dbesc(session_id()), dbesc($old_sid));
|
||||
}
|
||||
$params = session_get_cookie_params();
|
||||
setcookie(session_name(), session_id(), $time, $params['path'], $params['domain'], $params['secure'], isset($params['httponly']));
|
||||
return;
|
||||
}
|
||||
|
|
69
include/autoloader.php
Normal file
69
include/autoloader.php
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
/**
|
||||
* @file include/autoloader.php
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief composer-derived autoloader init
|
||||
**/
|
||||
class FriendicaAutoloaderInit
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
public static function loadClassLoader($class)
|
||||
{
|
||||
if ('Composer\Autoload\ClassLoader' === $class) {
|
||||
require __DIR__ . '/autoloader/ClassLoader.php';
|
||||
}
|
||||
}
|
||||
|
||||
public static function getLoader()
|
||||
{
|
||||
if (null !== self::$loader) {
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('FriendicaAutoloaderInit', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
|
||||
spl_autoload_unregister(array('FriendicaAutoloaderInit', 'loadClassLoader'));
|
||||
|
||||
// library
|
||||
$map = require __DIR__ . '/autoloader/autoload_namespaces.php';
|
||||
foreach ($map as $namespace => $path) {
|
||||
$loader->set($namespace, $path);
|
||||
}
|
||||
|
||||
$map = require __DIR__ . '/autoloader/autoload_psr4.php';
|
||||
foreach ($map as $namespace => $path) {
|
||||
$loader->setPsr4($namespace, $path);
|
||||
}
|
||||
|
||||
$classMap = require __DIR__ . '/autoloader/autoload_classmap.php';
|
||||
if ($classMap) {
|
||||
$loader->addClassMap($classMap);
|
||||
}
|
||||
|
||||
$loader->register(true);
|
||||
|
||||
$includeFiles = require __DIR__ . '/autoloader/autoload_files.php';
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
friendicaRequire($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
|
||||
return $loader;
|
||||
}
|
||||
}
|
||||
|
||||
function friendicaRequire($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
require $file;
|
||||
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return FriendicaAutoloaderInit::getLoader();
|
413
include/autoloader/ClassLoader.php
Normal file
413
include/autoloader/ClassLoader.php
Normal file
|
@ -0,0 +1,413 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Composer.
|
||||
*
|
||||
* (c) Nils Adermann <naderman@naderman.de>
|
||||
* Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE.composer
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
/**
|
||||
* ClassLoader implements a PSR-0 class loader
|
||||
*
|
||||
* See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
|
||||
*
|
||||
* $loader = new \Composer\Autoload\ClassLoader();
|
||||
*
|
||||
* // register classes with namespaces
|
||||
* $loader->add('Symfony\Component', __DIR__.'/component');
|
||||
* $loader->add('Symfony', __DIR__.'/framework');
|
||||
*
|
||||
* // activate the autoloader
|
||||
* $loader->register();
|
||||
*
|
||||
* // to enable searching the include path (eg. for PEAR packages)
|
||||
* $loader->setUseIncludePath(true);
|
||||
*
|
||||
* In this example, if you try to use a class in the Symfony\Component
|
||||
* namespace or one of its children (Symfony\Component\Console for instance),
|
||||
* the autoloader will first look for the class under the component/
|
||||
* directory, and it will then fallback to the framework/ directory if not
|
||||
* found before giving up.
|
||||
*
|
||||
* This class is loosely based on the Symfony UniversalClassLoader.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
*/
|
||||
class ClassLoader
|
||||
{
|
||||
// PSR-4
|
||||
private $prefixLengthsPsr4 = array();
|
||||
private $prefixDirsPsr4 = array();
|
||||
private $fallbackDirsPsr4 = array();
|
||||
|
||||
// PSR-0
|
||||
private $prefixesPsr0 = array();
|
||||
private $fallbackDirsPsr0 = array();
|
||||
|
||||
private $useIncludePath = false;
|
||||
private $classMap = array();
|
||||
|
||||
private $classMapAuthoritative = false;
|
||||
|
||||
public function getPrefixes()
|
||||
{
|
||||
if (!empty($this->prefixesPsr0)) {
|
||||
return call_user_func_array('array_merge', $this->prefixesPsr0);
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
public function getPrefixesPsr4()
|
||||
{
|
||||
return $this->prefixDirsPsr4;
|
||||
}
|
||||
|
||||
public function getFallbackDirs()
|
||||
{
|
||||
return $this->fallbackDirsPsr0;
|
||||
}
|
||||
|
||||
public function getFallbackDirsPsr4()
|
||||
{
|
||||
return $this->fallbackDirsPsr4;
|
||||
}
|
||||
|
||||
public function getClassMap()
|
||||
{
|
||||
return $this->classMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $classMap Class to filename map
|
||||
*/
|
||||
public function addClassMap(array $classMap)
|
||||
{
|
||||
if ($this->classMap) {
|
||||
$this->classMap = array_merge($this->classMap, $classMap);
|
||||
} else {
|
||||
$this->classMap = $classMap;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-0 directories for a given prefix, either
|
||||
* appending or prepending to the ones previously set for this prefix.
|
||||
*
|
||||
* @param string $prefix The prefix
|
||||
* @param array|string $paths The PSR-0 root directories
|
||||
* @param bool $prepend Whether to prepend the directories
|
||||
*/
|
||||
public function add($prefix, $paths, $prepend = false)
|
||||
{
|
||||
if (!$prefix) {
|
||||
if ($prepend) {
|
||||
$this->fallbackDirsPsr0 = array_merge(
|
||||
(array) $paths,
|
||||
$this->fallbackDirsPsr0
|
||||
);
|
||||
} else {
|
||||
$this->fallbackDirsPsr0 = array_merge(
|
||||
$this->fallbackDirsPsr0,
|
||||
(array) $paths
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$first = $prefix[0];
|
||||
if (!isset($this->prefixesPsr0[$first][$prefix])) {
|
||||
$this->prefixesPsr0[$first][$prefix] = (array) $paths;
|
||||
|
||||
return;
|
||||
}
|
||||
if ($prepend) {
|
||||
$this->prefixesPsr0[$first][$prefix] = array_merge(
|
||||
(array) $paths,
|
||||
$this->prefixesPsr0[$first][$prefix]
|
||||
);
|
||||
} else {
|
||||
$this->prefixesPsr0[$first][$prefix] = array_merge(
|
||||
$this->prefixesPsr0[$first][$prefix],
|
||||
(array) $paths
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-4 directories for a given namespace, either
|
||||
* appending or prepending to the ones previously set for this namespace.
|
||||
*
|
||||
* @param string $prefix The prefix/namespace, with trailing '\\'
|
||||
* @param array|string $paths The PSR-0 base directories
|
||||
* @param bool $prepend Whether to prepend the directories
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function addPsr4($prefix, $paths, $prepend = false)
|
||||
{
|
||||
if (!$prefix) {
|
||||
// Register directories for the root namespace.
|
||||
if ($prepend) {
|
||||
$this->fallbackDirsPsr4 = array_merge(
|
||||
(array) $paths,
|
||||
$this->fallbackDirsPsr4
|
||||
);
|
||||
} else {
|
||||
$this->fallbackDirsPsr4 = array_merge(
|
||||
$this->fallbackDirsPsr4,
|
||||
(array) $paths
|
||||
);
|
||||
}
|
||||
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
|
||||
// Register directories for a new namespace.
|
||||
$length = strlen($prefix);
|
||||
if ('\\' !== $prefix[$length - 1]) {
|
||||
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
|
||||
}
|
||||
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
|
||||
$this->prefixDirsPsr4[$prefix] = (array) $paths;
|
||||
} elseif ($prepend) {
|
||||
// Prepend directories for an already registered namespace.
|
||||
$this->prefixDirsPsr4[$prefix] = array_merge(
|
||||
(array) $paths,
|
||||
$this->prefixDirsPsr4[$prefix]
|
||||
);
|
||||
} else {
|
||||
// Append directories for an already registered namespace.
|
||||
$this->prefixDirsPsr4[$prefix] = array_merge(
|
||||
$this->prefixDirsPsr4[$prefix],
|
||||
(array) $paths
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-0 directories for a given prefix,
|
||||
* replacing any others previously set for this prefix.
|
||||
*
|
||||
* @param string $prefix The prefix
|
||||
* @param array|string $paths The PSR-0 base directories
|
||||
*/
|
||||
public function set($prefix, $paths)
|
||||
{
|
||||
if (!$prefix) {
|
||||
$this->fallbackDirsPsr0 = (array) $paths;
|
||||
} else {
|
||||
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of PSR-4 directories for a given namespace,
|
||||
* replacing any others previously set for this namespace.
|
||||
*
|
||||
* @param string $prefix The prefix/namespace, with trailing '\\'
|
||||
* @param array|string $paths The PSR-4 base directories
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function setPsr4($prefix, $paths)
|
||||
{
|
||||
if (!$prefix) {
|
||||
$this->fallbackDirsPsr4 = (array) $paths;
|
||||
} else {
|
||||
$length = strlen($prefix);
|
||||
if ('\\' !== $prefix[$length - 1]) {
|
||||
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
|
||||
}
|
||||
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
|
||||
$this->prefixDirsPsr4[$prefix] = (array) $paths;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns on searching the include path for class files.
|
||||
*
|
||||
* @param bool $useIncludePath
|
||||
*/
|
||||
public function setUseIncludePath($useIncludePath)
|
||||
{
|
||||
$this->useIncludePath = $useIncludePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used to check if the autoloader uses the include path to check
|
||||
* for classes.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getUseIncludePath()
|
||||
{
|
||||
return $this->useIncludePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns off searching the prefix and fallback directories for classes
|
||||
* that have not been registered with the class map.
|
||||
*
|
||||
* @param bool $classMapAuthoritative
|
||||
*/
|
||||
public function setClassMapAuthoritative($classMapAuthoritative)
|
||||
{
|
||||
$this->classMapAuthoritative = $classMapAuthoritative;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should class lookup fail if not found in the current class map?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isClassMapAuthoritative()
|
||||
{
|
||||
return $this->classMapAuthoritative;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers this instance as an autoloader.
|
||||
*
|
||||
* @param bool $prepend Whether to prepend the autoloader or not
|
||||
*/
|
||||
public function register($prepend = false)
|
||||
{
|
||||
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters this instance as an autoloader.
|
||||
*/
|
||||
public function unregister()
|
||||
{
|
||||
spl_autoload_unregister(array($this, 'loadClass'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the given class or interface.
|
||||
*
|
||||
* @param string $class The name of the class
|
||||
* @return bool|null True if loaded, null otherwise
|
||||
*/
|
||||
public function loadClass($class)
|
||||
{
|
||||
if ($file = $this->findFile($class)) {
|
||||
includeFile($file);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the path to the file where the class is defined.
|
||||
*
|
||||
* @param string $class The name of the class
|
||||
*
|
||||
* @return string|false The path if found, false otherwise
|
||||
*/
|
||||
public function findFile($class)
|
||||
{
|
||||
// work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731
|
||||
if ('\\' == $class[0]) {
|
||||
$class = substr($class, 1);
|
||||
}
|
||||
|
||||
// class map lookup
|
||||
if (isset($this->classMap[$class])) {
|
||||
return $this->classMap[$class];
|
||||
}
|
||||
if ($this->classMapAuthoritative) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$file = $this->findFileWithExtension($class, '.php');
|
||||
|
||||
// Search for Hack files if we are running on HHVM
|
||||
if ($file === null && defined('HHVM_VERSION')) {
|
||||
$file = $this->findFileWithExtension($class, '.hh');
|
||||
}
|
||||
|
||||
if ($file === null) {
|
||||
// Remember that this class does not exist.
|
||||
return $this->classMap[$class] = false;
|
||||
}
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
||||
private function findFileWithExtension($class, $ext)
|
||||
{
|
||||
// PSR-4 lookup
|
||||
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
|
||||
|
||||
$first = $class[0];
|
||||
if (isset($this->prefixLengthsPsr4[$first])) {
|
||||
foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) {
|
||||
if (0 === strpos($class, $prefix)) {
|
||||
foreach ($this->prefixDirsPsr4[$prefix] as $dir) {
|
||||
if (is_file($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-4 fallback dirs
|
||||
foreach ($this->fallbackDirsPsr4 as $dir) {
|
||||
if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-0 lookup
|
||||
if (false !== $pos = strrpos($class, '\\')) {
|
||||
// namespaced class name
|
||||
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
|
||||
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
|
||||
} else {
|
||||
// PEAR-like class name
|
||||
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
|
||||
}
|
||||
|
||||
if (isset($this->prefixesPsr0[$first])) {
|
||||
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
|
||||
if (0 === strpos($class, $prefix)) {
|
||||
foreach ($dirs as $dir) {
|
||||
if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-0 fallback dirs
|
||||
foreach ($this->fallbackDirsPsr0 as $dir) {
|
||||
if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
// PSR-0 include paths.
|
||||
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope isolated include.
|
||||
*
|
||||
* Prevents access to $this/self from included files.
|
||||
*/
|
||||
function includeFile($file)
|
||||
{
|
||||
include $file;
|
||||
}
|
19
include/autoloader/LICENSE.composer
Normal file
19
include/autoloader/LICENSE.composer
Normal file
|
@ -0,0 +1,19 @@
|
|||
Copyright (c) 2015 Nils Adermann, Jordi Boggiano
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the Software), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, andor sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
9
include/autoloader/autoload_classmap.php
Normal file
9
include/autoloader/autoload_classmap.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
// autoload_classmap.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(dirname(dirname(__FILE__)))."/library";
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
);
|
10
include/autoloader/autoload_files.php
Normal file
10
include/autoloader/autoload_files.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
// autoload_files.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(dirname(dirname(__FILE__)))."/library";
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
'2cffec82183ee1cea088009cef9a6fc3' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier.composer.php',
|
||||
);
|
10
include/autoloader/autoload_namespaces.php
Normal file
10
include/autoloader/autoload_namespaces.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
// autoload_namespaces.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(dirname(dirname(__FILE__)))."/library";
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
'HTMLPurifier' => array($vendorDir . '/ezyang/htmlpurifier/library'),
|
||||
);
|
9
include/autoloader/autoload_psr4.php
Normal file
9
include/autoloader/autoload_psr4.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
// autoload_psr4.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(dirname(dirname(__FILE__)))."/library";
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
);
|
|
@ -311,6 +311,9 @@ function tryoembed($match){
|
|||
|
||||
$o = oembed_fetch_url($url);
|
||||
|
||||
if (!is_object($o))
|
||||
return $match[0];
|
||||
|
||||
if (isset($match[2]))
|
||||
$o->title = $match[2];
|
||||
|
||||
|
@ -858,6 +861,8 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
|
|||
$Text = preg_replace_callback("/\[nobb\](.*?)\[\/nobb\]/ism", 'bb_spacefy',$Text);
|
||||
$Text = preg_replace_callback("/\[pre\](.*?)\[\/pre\]/ism", 'bb_spacefy',$Text);
|
||||
|
||||
// Remove the abstract element. It is a non visible element.
|
||||
$Text = remove_abstract($Text);
|
||||
|
||||
// Move all spaces out of the tags
|
||||
$Text = preg_replace("/\[(\w*)\](\s*)/ism", '$2[$1]', $Text);
|
||||
|
@ -1300,4 +1305,43 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
|
|||
|
||||
return trim($Text);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Removes the "abstract" element from the text
|
||||
*
|
||||
* @param string $text The text with BBCode
|
||||
* @return string The same text - but without "abstract" element
|
||||
*/
|
||||
function remove_abstract($text) {
|
||||
$text = preg_replace("/[\s|\n]*\[abstract\].*?\[\/abstract\][\s|\n]*/ism", '', $text);
|
||||
$text = preg_replace("/[\s|\n]*\[abstract=.*?\].*?\[\/abstract][\s|\n]*/ism", '', $text);
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the value of the "abstract" element
|
||||
*
|
||||
* @param string $text The text that maybe contains the element
|
||||
* @param string $addon The addon for which the abstract is meant for
|
||||
* @return string The abstract
|
||||
*/
|
||||
function fetch_abstract($text, $addon = "") {
|
||||
$abstract = "";
|
||||
$abstracts = array();
|
||||
$addon = strtolower($addon);
|
||||
|
||||
if (preg_match_all("/\[abstract=(.*?)\](.*?)\[\/abstract\]/ism",$text, $results, PREG_SET_ORDER))
|
||||
foreach ($results AS $result)
|
||||
$abstracts[strtolower($result[1])] = $result[2];
|
||||
|
||||
if (isset($abstracts[$addon]))
|
||||
$abstract = $abstracts[$addon];
|
||||
|
||||
if ($abstract == "")
|
||||
if (preg_match("/\[abstract\](.*?)\[\/abstract\]/ism",$text, $result))
|
||||
$abstract = $result[1];
|
||||
|
||||
return $abstract;
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -99,8 +99,16 @@ function network_to_name($s, $profile = "") {
|
|||
|
||||
$networkname = str_replace($search,$replace,$s);
|
||||
|
||||
if (($s == NETWORK_DIASPORA) AND ($profile != "") AND diaspora_is_redmatrix($profile))
|
||||
$networkname = t("Redmatrix");
|
||||
if (($s == NETWORK_DIASPORA) AND ($profile != "") AND diaspora::is_redmatrix($profile)) {
|
||||
$networkname = t("Hubzilla/Redmatrix");
|
||||
|
||||
$r = q("SELECT `gserver`.`platform` FROM `gcontact`
|
||||
INNER JOIN `gserver` ON `gserver`.`nurl` = `gcontact`.`server_url`
|
||||
WHERE `gcontact`.`nurl` = '%s' AND `platform` != ''",
|
||||
dbesc(normalise_link($profile)));
|
||||
if ($r)
|
||||
$networkname = $r[0]["platform"];
|
||||
}
|
||||
|
||||
return $networkname;
|
||||
}
|
||||
|
|
|
@ -614,7 +614,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
|
|||
if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
|
||||
$profile_avatar = $a->contacts[$normalised]['thumb'];
|
||||
else
|
||||
$profile_avatar = ((strlen($item['author-avatar'])) ? $a->get_cached_avatar_image($item['author-avatar']) : $item['thumb']);
|
||||
$profile_avatar = $a->remove_baseurl(((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']));
|
||||
|
||||
$locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
|
||||
call_hooks('render_location',$locate);
|
||||
|
@ -707,8 +707,8 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
|
|||
'like' => '',
|
||||
'dislike' => '',
|
||||
'comment' => '',
|
||||
//'conv' => (($preview) ? '' : array('href'=> $a->get_baseurl($ssl_state) . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
|
||||
'conv' => (($preview) ? '' : array('href'=> $a->get_baseurl($ssl_state) . '/display/'.$item['guid'], 'title'=> t('View in context'))),
|
||||
//'conv' => (($preview) ? '' : array('href'=> 'display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
|
||||
'conv' => (($preview) ? '' : array('href'=> 'display/'.$item['guid'], 'title'=> t('View in context'))),
|
||||
'previewing' => $previewing,
|
||||
'wait' => t('Please wait'),
|
||||
'thread_level' => 1,
|
||||
|
@ -868,7 +868,7 @@ function item_photo_menu($item){
|
|||
$status_link = $profile_link . "?url=status";
|
||||
$photos_link = $profile_link . "?url=photos";
|
||||
$profile_link = $profile_link . "?url=profile";
|
||||
$pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
|
||||
$pm_url = 'message/new/' . $cid;
|
||||
$zurl = '';
|
||||
}
|
||||
else {
|
||||
|
@ -882,23 +882,23 @@ function item_photo_menu($item){
|
|||
$cid = $r[0]["id"];
|
||||
|
||||
if ($r[0]["network"] == NETWORK_DIASPORA)
|
||||
$pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
|
||||
$pm_url = 'message/new/' . $cid;
|
||||
|
||||
} else
|
||||
$cid = 0;
|
||||
}
|
||||
}
|
||||
if(($cid) && (! $item['self'])) {
|
||||
$poke_link = $a->get_baseurl($ssl_state) . '/poke/?f=&c=' . $cid;
|
||||
$contact_url = $a->get_baseurl($ssl_state) . '/contacts/' . $cid;
|
||||
$posts_link = $a->get_baseurl($ssl_state) . '/contacts/' . $cid . '/posts';
|
||||
$poke_link = 'poke/?f=&c=' . $cid;
|
||||
$contact_url = 'contacts/' . $cid;
|
||||
$posts_link = 'contacts/' . $cid . '/posts';
|
||||
|
||||
$clean_url = normalise_link($item['author-link']);
|
||||
|
||||
if((local_user()) && (local_user() == $item['uid'])) {
|
||||
if(isset($a->contacts) && x($a->contacts,$clean_url)) {
|
||||
if($a->contacts[$clean_url]['network'] === NETWORK_DIASPORA) {
|
||||
$pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
|
||||
$pm_url = 'message/new/' . $cid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -921,7 +921,7 @@ function item_photo_menu($item){
|
|||
|
||||
if ((($cid == 0) OR ($a->contacts[$clean_url]['rel'] == CONTACT_IS_FOLLOWER)) AND
|
||||
in_array($item['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)))
|
||||
$menu[t("Connect/Follow")] = $a->get_baseurl($ssl_state)."/follow?url=".urlencode($item['author-link']);
|
||||
$menu[t("Connect/Follow")] = "follow?url=".urlencode($item['author-link']);
|
||||
} else
|
||||
$menu = array(t("View Profile") => $item['author-link']);
|
||||
|
||||
|
@ -980,7 +980,7 @@ function builtin_activity_puller($item, &$conv_responses) {
|
|||
if((activity_match($item['verb'], $verb)) && ($item['id'] != $item['parent'])) {
|
||||
$url = $item['author-link'];
|
||||
if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === NETWORK_DFRN) && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
|
||||
$url = z_root(true) . '/redir/' . $item['contact-id'];
|
||||
$url = 'redir/' . $item['contact-id'];
|
||||
$sparkle = ' class="sparkle" ';
|
||||
}
|
||||
else
|
||||
|
@ -1178,7 +1178,7 @@ function status_editor($a,$x, $notes_cid = 0, $popup=false) {
|
|||
|
||||
$o .= replace_macros($tpl,array(
|
||||
'$return_path' => $query_str,
|
||||
'$action' => $a->get_baseurl(true) . '/item',
|
||||
'$action' => 'item',
|
||||
'$share' => (x($x,'button') ? $x['button'] : t('Share')),
|
||||
'$upload' => t('Upload photo'),
|
||||
'$shortupload' => t('upload photo'),
|
||||
|
|
|
@ -34,22 +34,18 @@ function cron_run(&$argv, &$argc){
|
|||
require_once('include/Contact.php');
|
||||
require_once('include/email.php');
|
||||
require_once('include/socgraph.php');
|
||||
require_once('include/pidfile.php');
|
||||
require_once('mod/nodeinfo.php');
|
||||
require_once('include/post_update.php');
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
|
||||
$maxsysload = intval(get_config('system','maxloadavg'));
|
||||
if($maxsysload < 1)
|
||||
$maxsysload = 50;
|
||||
|
||||
$load = current_load();
|
||||
if($load) {
|
||||
if(intval($load) > $maxsysload) {
|
||||
logger('system: load ' . $load . ' too high. cron deferred to next scheduled run.');
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run") {
|
||||
if (App::maxload_reached())
|
||||
return;
|
||||
if (App::is_already_running('cron', 'include/cron.php', 540))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$last = get_config('system','last_cron');
|
||||
|
@ -66,23 +62,6 @@ function cron_run(&$argv, &$argc){
|
|||
}
|
||||
}
|
||||
|
||||
$lockpath = get_lockpath();
|
||||
if ($lockpath != '') {
|
||||
$pidfile = new pidfile($lockpath, 'cron');
|
||||
if($pidfile->is_already_running()) {
|
||||
logger("cron: Already running");
|
||||
if ($pidfile->running_time() > 9*60) {
|
||||
$pidfile->kill();
|
||||
logger("cron: killed stale process");
|
||||
// Calling a new instance
|
||||
proc_run('php','include/cron.php');
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
load_hooks();
|
||||
|
@ -93,10 +72,6 @@ function cron_run(&$argv, &$argc){
|
|||
|
||||
proc_run('php',"include/queue.php");
|
||||
|
||||
// run diaspora photo queue process in the background
|
||||
|
||||
proc_run('php',"include/dsprphotoq.php");
|
||||
|
||||
// run the process to discover global contacts in the background
|
||||
|
||||
proc_run('php',"include/discover_poco.php");
|
||||
|
@ -127,13 +102,14 @@ function cron_run(&$argv, &$argc){
|
|||
|
||||
// Check OStatus conversations
|
||||
// Check only conversations with mentions (for a longer time)
|
||||
check_conversations(true);
|
||||
ostatus::check_conversations(true);
|
||||
|
||||
// Check every conversation
|
||||
check_conversations(false);
|
||||
ostatus::check_conversations(false);
|
||||
|
||||
// Set the gcontact-id in the item table if missing
|
||||
item_set_gcontact();
|
||||
// Call possible post update functions
|
||||
// see include/post_update.php for more details
|
||||
post_update();
|
||||
|
||||
// update nodeinfo data
|
||||
nodeinfo_cron();
|
||||
|
@ -361,35 +337,37 @@ function cron_clear_cache(&$a) {
|
|||
if ($max_tablesize == 0)
|
||||
$max_tablesize = 100 * 1000000; // Default are 100 MB
|
||||
|
||||
// Minimum fragmentation level in percent
|
||||
$fragmentation_level = intval(get_config('system','optimize_fragmentation')) / 100;
|
||||
if ($fragmentation_level == 0)
|
||||
$fragmentation_level = 0.3; // Default value is 30%
|
||||
if ($max_tablesize > 0) {
|
||||
// Minimum fragmentation level in percent
|
||||
$fragmentation_level = intval(get_config('system','optimize_fragmentation')) / 100;
|
||||
if ($fragmentation_level == 0)
|
||||
$fragmentation_level = 0.3; // Default value is 30%
|
||||
|
||||
// Optimize some tables that need to be optimized
|
||||
$r = q("SHOW TABLE STATUS");
|
||||
foreach($r as $table) {
|
||||
// Optimize some tables that need to be optimized
|
||||
$r = q("SHOW TABLE STATUS");
|
||||
foreach($r as $table) {
|
||||
|
||||
// Don't optimize tables that are too large
|
||||
if ($table["Data_length"] > $max_tablesize)
|
||||
continue;
|
||||
// Don't optimize tables that are too large
|
||||
if ($table["Data_length"] > $max_tablesize)
|
||||
continue;
|
||||
|
||||
// Don't optimize empty tables
|
||||
if ($table["Data_length"] == 0)
|
||||
continue;
|
||||
// Don't optimize empty tables
|
||||
if ($table["Data_length"] == 0)
|
||||
continue;
|
||||
|
||||
// Calculate fragmentation
|
||||
$fragmentation = $table["Data_free"] / $table["Data_length"];
|
||||
// Calculate fragmentation
|
||||
$fragmentation = $table["Data_free"] / ($table["Data_length"] + $table["Index_length"]);
|
||||
|
||||
logger("Table ".$table["Name"]." - Fragmentation level: ".round($fragmentation * 100, 2), LOGGER_DEBUG);
|
||||
logger("Table ".$table["Name"]." - Fragmentation level: ".round($fragmentation * 100, 2), LOGGER_DEBUG);
|
||||
|
||||
// Don't optimize tables that needn't to be optimized
|
||||
if ($fragmentation < $fragmentation_level)
|
||||
continue;
|
||||
// Don't optimize tables that needn't to be optimized
|
||||
if ($fragmentation < $fragmentation_level)
|
||||
continue;
|
||||
|
||||
// So optimize it
|
||||
logger("Optimize Table ".$table["Name"], LOGGER_DEBUG);
|
||||
q("OPTIMIZE TABLE `%s`", dbesc($table["Name"]));
|
||||
// So optimize it
|
||||
logger("Optimize Table ".$table["Name"], LOGGER_DEBUG);
|
||||
q("OPTIMIZE TABLE `%s`", dbesc($table["Name"]));
|
||||
}
|
||||
}
|
||||
|
||||
set_config('system','cache_last_cleared', time());
|
||||
|
@ -429,6 +407,9 @@ function cron_repair_database() {
|
|||
// This call is very "cheap" so we can do it at any time without a problem
|
||||
q("UPDATE `item` INNER JOIN `item` AS `parent` ON `parent`.`uri` = `item`.`parent-uri` AND `parent`.`uid` = `item`.`uid` SET `item`.`parent` = `parent`.`id` WHERE `item`.`parent` = 0");
|
||||
|
||||
// There was an issue where the nick vanishes from the contact table
|
||||
q("UPDATE `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid` SET `nick` = `nickname` WHERE `self` AND `nick`=''");
|
||||
|
||||
/// @todo
|
||||
/// - remove thread entries without item
|
||||
/// - remove sign entries without item
|
||||
|
|
|
@ -19,21 +19,16 @@ function cronhooks_run(&$argv, &$argc){
|
|||
|
||||
require_once('include/session.php');
|
||||
require_once('include/datetime.php');
|
||||
require_once('include/pidfile.php');
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
|
||||
$maxsysload = intval(get_config('system','maxloadavg'));
|
||||
if($maxsysload < 1)
|
||||
$maxsysload = 50;
|
||||
|
||||
$load = current_load();
|
||||
if($load) {
|
||||
if(intval($load) > $maxsysload) {
|
||||
logger('system: load ' . $load . ' too high. Cronhooks deferred to next scheduled run.');
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run") {
|
||||
if (App::maxload_reached())
|
||||
return;
|
||||
if (App::is_already_running('cronhooks', 'include/cronhooks.php', 1140))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$last = get_config('system','last_cronhook');
|
||||
|
@ -50,21 +45,6 @@ function cronhooks_run(&$argv, &$argc){
|
|||
}
|
||||
}
|
||||
|
||||
$lockpath = get_lockpath();
|
||||
if ($lockpath != '') {
|
||||
$pidfile = new pidfile($lockpath, 'cronhooks');
|
||||
if($pidfile->is_already_running()) {
|
||||
logger("cronhooks: Already running");
|
||||
if ($pidfile->running_time() > 19*60) {
|
||||
$pidfile->kill();
|
||||
logger("cronhooks: killed stale process");
|
||||
// Calling a new instance
|
||||
proc_run('php','include/cronhooks.php');
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
load_hooks();
|
||||
|
|
|
@ -1,8 +1,17 @@
|
|||
<?php
|
||||
/**
|
||||
* @file include/datetime.php
|
||||
* @brief Some functions for date and time related tasks.
|
||||
*/
|
||||
|
||||
// two-level sort for timezones.
|
||||
|
||||
if(! function_exists('timezone_cmp')) {
|
||||
/**
|
||||
* @brief Two-level sort for timezones.
|
||||
*
|
||||
* @param string $a
|
||||
* @param string $b
|
||||
* @return int
|
||||
*/
|
||||
function timezone_cmp($a, $b) {
|
||||
if(strstr($a,'/') && strstr($b,'/')) {
|
||||
if ( t($a) == t($b)) return 0;
|
||||
|
@ -11,11 +20,16 @@ function timezone_cmp($a, $b) {
|
|||
if(strstr($a,'/')) return -1;
|
||||
if(strstr($b,'/')) return 1;
|
||||
if ( t($a) == t($b)) return 0;
|
||||
return ( t($a) < t($b)) ? -1 : 1;
|
||||
}}
|
||||
|
||||
// emit a timezone selector grouped (primarily) by continent
|
||||
if(! function_exists('select_timezone')) {
|
||||
return ( t($a) < t($b)) ? -1 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Emit a timezone selector grouped (primarily) by continent
|
||||
*
|
||||
* @param string $current Timezone
|
||||
* @return string Parsed HTML output
|
||||
*/
|
||||
function select_timezone($current = 'America/Los_Angeles') {
|
||||
|
||||
$timezone_identifiers = DateTimeZone::listIdentifiers();
|
||||
|
@ -52,13 +66,25 @@ function select_timezone($current = 'America/Los_Angeles') {
|
|||
}
|
||||
$o .= '</optgroup></select>';
|
||||
return $o;
|
||||
}}
|
||||
}
|
||||
|
||||
// return a select using 'field_select_raw' template, with timezones
|
||||
// groupped (primarily) by continent
|
||||
// arguments follow convetion as other field_* template array:
|
||||
// 'name', 'label', $value, 'help'
|
||||
if (!function_exists('field_timezone')){
|
||||
|
||||
|
||||
/**
|
||||
* @brief Generating a Timezone selector
|
||||
*
|
||||
* Return a select using 'field_select_raw' template, with timezones
|
||||
* groupped (primarily) by continent
|
||||
* arguments follow convetion as other field_* template array:
|
||||
* 'name', 'label', $value, 'help'
|
||||
*
|
||||
* @param string $name Name of the selector
|
||||
* @param string $label Label for the selector
|
||||
* @param string $current Timezone
|
||||
* @param string $help Help text
|
||||
*
|
||||
* @return string Parsed HTML
|
||||
*/
|
||||
function field_timezone($name='timezone', $label='', $current = 'America/Los_Angeles', $help){
|
||||
$options = select_timezone($current);
|
||||
$options = str_replace('<select id="timezone_select" name="timezone">','', $options);
|
||||
|
@ -69,15 +95,19 @@ function field_timezone($name='timezone', $label='', $current = 'America/Los_Ang
|
|||
'$field' => array($name, $label, $current, $help, $options),
|
||||
));
|
||||
|
||||
}}
|
||||
}
|
||||
|
||||
// General purpose date parse/convert function.
|
||||
// $from = source timezone
|
||||
// $to = dest timezone
|
||||
// $s = some parseable date/time string
|
||||
// $fmt = output format
|
||||
|
||||
if(! function_exists('datetime_convert')) {
|
||||
/**
|
||||
* @brief General purpose date parse/convert function.
|
||||
*
|
||||
* @param string $from Source timezone
|
||||
* @param string $to Dest timezone
|
||||
* @param string $s Some parseable date/time string
|
||||
* @param string $fmt Output format recognised from php's DateTime class
|
||||
* http://www.php.net/manual/en/datetime.format.php
|
||||
*
|
||||
* @return string Formatted date according to given format
|
||||
*/
|
||||
function datetime_convert($from = 'UTC', $to = 'UTC', $s = 'now', $fmt = "Y-m-d H:i:s") {
|
||||
|
||||
// Defaults to UTC if nothing is set, but throws an exception if set to empty string.
|
||||
|
@ -123,14 +153,20 @@ function datetime_convert($from = 'UTC', $to = 'UTC', $s = 'now', $fmt = "Y-m-d
|
|||
}
|
||||
|
||||
$d->setTimeZone($to_obj);
|
||||
|
||||
return($d->format($fmt));
|
||||
}}
|
||||
}
|
||||
|
||||
|
||||
// wrapper for date selector, tailored for use in birthday fields
|
||||
|
||||
/**
|
||||
* @brief Wrapper for date selector, tailored for use in birthday fields.
|
||||
*
|
||||
* @param string $dob Date of Birth
|
||||
* @return string
|
||||
*/
|
||||
function dob($dob) {
|
||||
list($year,$month,$day) = sscanf($dob,'%4d-%2d-%2d');
|
||||
|
||||
$f = get_config('system','birthday_input_format');
|
||||
if(! $f)
|
||||
$f = 'ymd';
|
||||
|
@ -138,62 +174,69 @@ function dob($dob) {
|
|||
$value = '';
|
||||
else
|
||||
$value = (($year) ? datetime_convert('UTC','UTC',$dob,'Y-m-d') : datetime_convert('UTC','UTC',$dob,'m-d'));
|
||||
|
||||
$o = '<input type="text" name="dob" value="' . $value . '" placeholder="' . t('YYYY-MM-DD or MM-DD') . '" />';
|
||||
|
||||
// if ($dob && $dob != '0000-00-00')
|
||||
// $o = datesel($f,mktime(0,0,0,0,0,1900),mktime(),mktime(0,0,0,$month,$day,$year),'dob');
|
||||
// else
|
||||
// $o = datesel($f,mktime(0,0,0,0,0,1900),mktime(),false,'dob');
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a date selector
|
||||
* @param $format
|
||||
* format string, e.g. 'ymd' or 'mdy'. Not currently supported
|
||||
* @param $min
|
||||
* unix timestamp of minimum date
|
||||
* @param $max
|
||||
* unix timestap of maximum date
|
||||
* @param $default
|
||||
* unix timestamp of default date
|
||||
* @param $id
|
||||
* id and name of datetimepicker (defaults to "datetimepicker")
|
||||
* @brief Returns a date selector
|
||||
*
|
||||
* @param string $format
|
||||
* Format string, e.g. 'ymd' or 'mdy'. Not currently supported
|
||||
* @param string $min
|
||||
* Unix timestamp of minimum date
|
||||
* @param string $max
|
||||
* Unix timestap of maximum date
|
||||
* @param string $default
|
||||
* Unix timestamp of default date
|
||||
* @param string $id
|
||||
* ID and name of datetimepicker (defaults to "datetimepicker")
|
||||
*
|
||||
* @return string Parsed HTML output.
|
||||
*/
|
||||
if(! function_exists('datesel')) {
|
||||
function datesel($format, $min, $max, $default, $id = 'datepicker') {
|
||||
return datetimesel($format,$min,$max,$default,$id,true,false, '','');
|
||||
}}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a time selector
|
||||
* @param $format
|
||||
* format string, e.g. 'ymd' or 'mdy'. Not currently supported
|
||||
* @brief Returns a time selector
|
||||
*
|
||||
* @param string $format
|
||||
* Format string, e.g. 'ymd' or 'mdy'. Not currently supported
|
||||
* @param $h
|
||||
* already selected hour
|
||||
* Already selected hour
|
||||
* @param $m
|
||||
* already selected minute
|
||||
* @param $id
|
||||
* id and name of datetimepicker (defaults to "timepicker")
|
||||
* Already selected minute
|
||||
* @param string $id
|
||||
* ID and name of datetimepicker (defaults to "timepicker")
|
||||
*
|
||||
* @return string Parsed HTML output.
|
||||
*/
|
||||
if(! function_exists('timesel')) {
|
||||
function timesel($format, $h, $m, $id='timepicker') {
|
||||
return datetimesel($format,new DateTime(),new DateTime(),new DateTime("$h:$m"),$id,false,true);
|
||||
}}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns a datetime selector.
|
||||
*
|
||||
* @param $format
|
||||
* @param string $format
|
||||
* format string, e.g. 'ymd' or 'mdy'. Not currently supported
|
||||
* @param $min
|
||||
* @param string $min
|
||||
* unix timestamp of minimum date
|
||||
* @param $max
|
||||
* @param string $max
|
||||
* unix timestap of maximum date
|
||||
* @param $default
|
||||
* @param string $default
|
||||
* unix timestamp of default date
|
||||
* @param string $id
|
||||
* id and name of datetimepicker (defaults to "datetimepicker")
|
||||
* @param boolean $pickdate
|
||||
* @param bool $pickdate
|
||||
* true to show date picker (default)
|
||||
* @param boolean $picktime
|
||||
* true to show time picker (default)
|
||||
|
@ -201,17 +244,15 @@ function timesel($format, $h, $m, $id='timepicker') {
|
|||
* set minimum date from picker with id $minfrom (none by default)
|
||||
* @param $maxfrom
|
||||
* set maximum date from picker with id $maxfrom (none by default)
|
||||
* @param boolean $required default false
|
||||
* @param bool $required default false
|
||||
*
|
||||
* @return string Parsed HTML output.
|
||||
*
|
||||
* @todo Once browser support is better this could probably be replaced with
|
||||
* native HTML5 date picker.
|
||||
*/
|
||||
if(! function_exists('datetimesel')) {
|
||||
function datetimesel($format, $min, $max, $default, $id = 'datetimepicker', $pickdate = true, $picktime = true, $minfrom = '', $maxfrom = '', $required = false) {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
// First day of the week (0 = Sunday)
|
||||
$firstDay = get_pconfig(local_user(),'system','first_day_of_week');
|
||||
if ($firstDay === false) $firstDay=0;
|
||||
|
@ -224,43 +265,58 @@ function datetimesel($format, $min, $max, $default, $id = 'datetimepicker', $pic
|
|||
|
||||
$o = '';
|
||||
$dateformat = '';
|
||||
|
||||
if($pickdate) $dateformat .= 'Y-m-d';
|
||||
if($pickdate && $picktime) $dateformat .= ' ';
|
||||
if($picktime) $dateformat .= 'H:i';
|
||||
|
||||
$minjs = $min ? ",minDate: new Date({$min->getTimestamp()}*1000), yearStart: " . $min->format('Y') : '';
|
||||
$maxjs = $max ? ",maxDate: new Date({$max->getTimestamp()}*1000), yearEnd: " . $max->format('Y') : '';
|
||||
|
||||
$input_text = $default ? 'value="' . date($dateformat, $default->getTimestamp()) . '"' : '';
|
||||
$defaultdatejs = $default ? ",defaultDate: new Date({$default->getTimestamp()}*1000)" : '';
|
||||
|
||||
$pickers = '';
|
||||
if(!$pickdate) $pickers .= ',datepicker: false';
|
||||
if(!$picktime) $pickers .= ',timepicker: false';
|
||||
|
||||
$extra_js = '';
|
||||
$pickers .= ",dayOfWeekStart: ".$firstDay.",lang:'".$lang."'";
|
||||
if($minfrom != '')
|
||||
$extra_js .= "\$('#$minfrom').data('xdsoft_datetimepicker').setOptions({onChangeDateTime: function (currentDateTime) { \$('#$id').data('xdsoft_datetimepicker').setOptions({minDate: currentDateTime})}})";
|
||||
if($maxfrom != '')
|
||||
$extra_js .= "\$('#$maxfrom').data('xdsoft_datetimepicker').setOptions({onChangeDateTime: function (currentDateTime) { \$('#$id').data('xdsoft_datetimepicker').setOptions({maxDate: currentDateTime})}})";
|
||||
|
||||
$readable_format = $dateformat;
|
||||
$readable_format = str_replace('Y','yyyy',$readable_format);
|
||||
$readable_format = str_replace('m','mm',$readable_format);
|
||||
$readable_format = str_replace('d','dd',$readable_format);
|
||||
$readable_format = str_replace('H','HH',$readable_format);
|
||||
$readable_format = str_replace('i','MM',$readable_format);
|
||||
|
||||
$o .= "<div class='date'><input type='text' placeholder='$readable_format' name='$id' id='$id' $input_text />";
|
||||
$o .= '</div>';
|
||||
$o .= "<script type='text/javascript'>";
|
||||
$o .= "\$(function () {var picker = \$('#$id').datetimepicker({step:5,format:'$dateformat' $minjs $maxjs $pickers $defaultdatejs}); $extra_js})";
|
||||
$o .= "</script>";
|
||||
|
||||
return $o;
|
||||
}}
|
||||
}
|
||||
|
||||
// implements "3 seconds ago" etc.
|
||||
// based on $posted_date, (UTC).
|
||||
// Results relative to current timezone
|
||||
// Limited to range of timestamps
|
||||
|
||||
if(! function_exists('relative_date')) {
|
||||
/**
|
||||
* @brief Returns a relative date string.
|
||||
*
|
||||
* Implements "3 seconds ago" etc.
|
||||
* Based on $posted_date, (UTC).
|
||||
* Results relative to current timezone.
|
||||
* Limited to range of timestamps.
|
||||
*
|
||||
* @param string $posted_date
|
||||
* @param string $format (optional) Parsed with sprintf()
|
||||
* <tt>%1$d %2$s ago</tt>, e.g. 22 hours ago, 1 minute ago
|
||||
*
|
||||
* @return string with relative date
|
||||
*/
|
||||
function relative_date($posted_date,$format = null) {
|
||||
|
||||
$localtime = datetime_convert('UTC',date_default_timezone_get(),$posted_date);
|
||||
|
@ -300,23 +356,33 @@ function relative_date($posted_date,$format = null) {
|
|||
// translators - e.g. 22 hours ago, 1 minute ago
|
||||
if(! $format)
|
||||
$format = t('%1$d %2$s ago');
|
||||
|
||||
return sprintf( $format,$r, (($r == 1) ? $str[0] : $str[1]));
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
|
||||
|
||||
// Returns age in years, given a date of birth,
|
||||
// the timezone of the person whose date of birth is provided,
|
||||
// and the timezone of the person viewing the result.
|
||||
// Why? Bear with me. Let's say I live in Mittagong, Australia, and my
|
||||
// birthday is on New Year's. You live in San Bruno, California.
|
||||
// When exactly are you going to see my age increase?
|
||||
// A: 5:00 AM Dec 31 San Bruno time. That's precisely when I start
|
||||
// celebrating and become a year older. If you wish me happy birthday
|
||||
// on January 1 (San Bruno time), you'll be a day late.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns timezone correct age in years.
|
||||
*
|
||||
* Returns the age in years, given a date of birth, the timezone of the person
|
||||
* whose date of birth is provided, and the timezone of the person viewing the
|
||||
* result.
|
||||
*
|
||||
* Why? Bear with me. Let's say I live in Mittagong, Australia, and my birthday
|
||||
* is on New Year's. You live in San Bruno, California.
|
||||
* When exactly are you going to see my age increase?
|
||||
*
|
||||
* A: 5:00 AM Dec 31 San Bruno time. That's precisely when I start celebrating
|
||||
* and become a year older. If you wish me happy birthday on January 1
|
||||
* (San Bruno time), you'll be a day late.
|
||||
*
|
||||
* @param string $dob Date of Birth
|
||||
* @param string $owner_tz (optional) Timezone of the person of interest
|
||||
* @param string $viewer_tz (optional) Timezone of the person viewing
|
||||
*
|
||||
* @return int Age in years
|
||||
*/
|
||||
function age($dob,$owner_tz = '',$viewer_tz = '') {
|
||||
if(! intval($dob))
|
||||
return 0;
|
||||
|
@ -333,64 +399,79 @@ function age($dob,$owner_tz = '',$viewer_tz = '') {
|
|||
|
||||
if(($curr_month < $month) || (($curr_month == $month) && ($curr_day < $day)))
|
||||
$year_diff--;
|
||||
|
||||
return $year_diff;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Get days in month
|
||||
// get_dim($year, $month);
|
||||
// returns number of days.
|
||||
// $month[1] = 'January';
|
||||
// to match human usage.
|
||||
|
||||
if(! function_exists('get_dim')) {
|
||||
/**
|
||||
* @brief Get days of a month in a given year.
|
||||
*
|
||||
* Returns number of days in the month of the given year.
|
||||
* $m = 1 is 'January' to match human usage.
|
||||
*
|
||||
* @param int $y Year
|
||||
* @param int $m Month (1=January, 12=December)
|
||||
*
|
||||
* @return int Number of days in the given month
|
||||
*/
|
||||
function get_dim($y,$m) {
|
||||
|
||||
$dim = array( 0,
|
||||
31, 28, 31, 30, 31, 30,
|
||||
31, 31, 30, 31, 30, 31);
|
||||
|
||||
if($m != 2)
|
||||
return $dim[$m];
|
||||
if(((($y % 4) == 0) && (($y % 100) != 0)) || (($y % 400) == 0))
|
||||
return 29;
|
||||
return $dim[2];
|
||||
}}
|
||||
$dim = array( 0,
|
||||
31, 28, 31, 30, 31, 30,
|
||||
31, 31, 30, 31, 30, 31);
|
||||
|
||||
if($m != 2)
|
||||
return $dim[$m];
|
||||
|
||||
// Returns the first day in month for a given month, year
|
||||
// get_first_dim($year,$month)
|
||||
// returns 0 = Sunday through 6 = Saturday
|
||||
// Months start at 1.
|
||||
if(((($y % 4) == 0) && (($y % 100) != 0)) || (($y % 400) == 0))
|
||||
return 29;
|
||||
|
||||
if(! function_exists('get_first_dim')) {
|
||||
return $dim[2];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the first day in month for a given month, year.
|
||||
*
|
||||
* Months start at 1.
|
||||
*
|
||||
* @param int $y Year
|
||||
* @param int $m Month (1=January, 12=December)
|
||||
*
|
||||
* @return string day 0 = Sunday through 6 = Saturday
|
||||
*/
|
||||
function get_first_dim($y,$m) {
|
||||
$d = sprintf('%04d-%02d-01 00:00', intval($y), intval($m));
|
||||
return datetime_convert('UTC','UTC',$d,'w');
|
||||
}}
|
||||
$d = sprintf('%04d-%02d-01 00:00', intval($y), intval($m));
|
||||
|
||||
// output a calendar for the given month, year.
|
||||
// if $links are provided (array), e.g. $links[12] => 'http://mylink' ,
|
||||
// date 12 will be linked appropriately. Today's date is also noted by
|
||||
// altering td class.
|
||||
// Months count from 1.
|
||||
return datetime_convert('UTC','UTC',$d,'w');
|
||||
}
|
||||
|
||||
|
||||
/// @TODO Provide (prev,next) links, define class variations for different size calendars
|
||||
|
||||
|
||||
if(! function_exists('cal')) {
|
||||
/**
|
||||
* @brief Output a calendar for the given month, year.
|
||||
*
|
||||
* If $links are provided (array), e.g. $links[12] => 'http://mylink' ,
|
||||
* date 12 will be linked appropriately. Today's date is also noted by
|
||||
* altering td class.
|
||||
* Months count from 1.
|
||||
*
|
||||
* @param int $y Year
|
||||
* @param int $m Month
|
||||
* @param bool $links (default false)
|
||||
* @param string $class
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @todo Provide (prev,next) links, define class variations for different size calendars
|
||||
*/
|
||||
function cal($y = 0,$m = 0, $links = false, $class='') {
|
||||
|
||||
|
||||
// month table - start at 1 to match human usage.
|
||||
|
||||
$mtab = array(' ',
|
||||
'January','February','March',
|
||||
'April','May','June',
|
||||
'July','August','September',
|
||||
'October','November','December'
|
||||
'January','February','March',
|
||||
'April','May','June',
|
||||
'July','August','September',
|
||||
'October','November','December'
|
||||
);
|
||||
|
||||
$thisyear = datetime_convert('UTC',date_default_timezone_get(),'now','Y');
|
||||
|
@ -400,54 +481,63 @@ function cal($y = 0,$m = 0, $links = false, $class='') {
|
|||
if(! $m)
|
||||
$m = intval($thismonth);
|
||||
|
||||
$dn = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
|
||||
$f = get_first_dim($y,$m);
|
||||
$l = get_dim($y,$m);
|
||||
$d = 1;
|
||||
$dow = 0;
|
||||
$started = false;
|
||||
$dn = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
|
||||
$f = get_first_dim($y,$m);
|
||||
$l = get_dim($y,$m);
|
||||
$d = 1;
|
||||
$dow = 0;
|
||||
$started = false;
|
||||
|
||||
if(($y == $thisyear) && ($m == $thismonth))
|
||||
$tddate = intval(datetime_convert('UTC',date_default_timezone_get(),'now','j'));
|
||||
if(($y == $thisyear) && ($m == $thismonth))
|
||||
$tddate = intval(datetime_convert('UTC',date_default_timezone_get(),'now','j'));
|
||||
|
||||
$str_month = day_translate($mtab[$m]);
|
||||
$o = '<table class="calendar' . $class . '">';
|
||||
$o .= "<caption>$str_month $y</caption><tr>";
|
||||
for($a = 0; $a < 7; $a ++)
|
||||
$o .= '<th>' . mb_substr(day_translate($dn[$a]),0,3,'UTF-8') . '</th>';
|
||||
$o .= '</tr><tr>';
|
||||
$o = '<table class="calendar' . $class . '">';
|
||||
$o .= "<caption>$str_month $y</caption><tr>";
|
||||
for($a = 0; $a < 7; $a ++)
|
||||
$o .= '<th>' . mb_substr(day_translate($dn[$a]),0,3,'UTF-8') . '</th>';
|
||||
|
||||
while($d <= $l) {
|
||||
if(($dow == $f) && (! $started))
|
||||
$started = true;
|
||||
$today = (((isset($tddate)) && ($tddate == $d)) ? "class=\"today\" " : '');
|
||||
$o .= "<td $today>";
|
||||
$day = str_replace(' ',' ',sprintf('%2.2d', $d));
|
||||
if($started) {
|
||||
if(is_array($links) && isset($links[$d]))
|
||||
$o .= "<a href=\"{$links[$d]}\">$day</a>";
|
||||
else
|
||||
$o .= $day;
|
||||
$d ++;
|
||||
}
|
||||
else
|
||||
$o .= ' ';
|
||||
$o .= '</td>';
|
||||
$dow ++;
|
||||
if(($dow == 7) && ($d <= $l)) {
|
||||
$dow = 0;
|
||||
$o .= '</tr><tr>';
|
||||
}
|
||||
}
|
||||
if($dow)
|
||||
for($a = $dow; $a < 7; $a ++)
|
||||
$o .= '<td> </td>';
|
||||
$o .= '</tr></table>'."\r\n";
|
||||
$o .= '</tr><tr>';
|
||||
|
||||
return $o;
|
||||
}}
|
||||
while($d <= $l) {
|
||||
if(($dow == $f) && (! $started))
|
||||
$started = true;
|
||||
|
||||
$today = (((isset($tddate)) && ($tddate == $d)) ? "class=\"today\" " : '');
|
||||
$o .= "<td $today>";
|
||||
$day = str_replace(' ',' ',sprintf('%2.2d', $d));
|
||||
if($started) {
|
||||
if(is_array($links) && isset($links[$d]))
|
||||
$o .= "<a href=\"{$links[$d]}\">$day</a>";
|
||||
else
|
||||
$o .= $day;
|
||||
|
||||
$d ++;
|
||||
} else {
|
||||
$o .= ' ';
|
||||
}
|
||||
|
||||
$o .= '</td>';
|
||||
$dow ++;
|
||||
if(($dow == 7) && ($d <= $l)) {
|
||||
$dow = 0;
|
||||
$o .= '</tr><tr>';
|
||||
}
|
||||
}
|
||||
if($dow)
|
||||
for($a = $dow; $a < 7; $a ++)
|
||||
$o .= '<td> </td>';
|
||||
|
||||
$o .= '</tr></table>'."\r\n";
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Create a birthday event.
|
||||
*
|
||||
* Update the year and the birthday.
|
||||
*/
|
||||
function update_contact_birthdays() {
|
||||
|
||||
// This only handles foreign or alien networks where a birthday has been provided.
|
||||
|
@ -474,8 +564,6 @@ function update_contact_birthdays() {
|
|||
$bdtext = sprintf( t('%s\'s birthday'), $rr['name']);
|
||||
$bdtext2 = sprintf( t('Happy Birthday %s'), ' [url=' . $rr['url'] . ']' . $rr['name'] . '[/url]') ;
|
||||
|
||||
|
||||
|
||||
$r = q("INSERT INTO `event` (`uid`,`cid`,`created`,`edited`,`start`,`finish`,`summary`,`desc`,`type`,`adjust`)
|
||||
VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d' ) ",
|
||||
intval($rr['uid']),
|
||||
|
|
|
@ -537,17 +537,6 @@ function db_definition() {
|
|||
"PRIMARY" => array("id"),
|
||||
)
|
||||
);
|
||||
$database["dsprphotoq"] = array(
|
||||
"fields" => array(
|
||||
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
|
||||
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
|
||||
"msg" => array("type" => "mediumtext", "not null" => "1"),
|
||||
"attempt" => array("type" => "tinyint(4)", "not null" => "1", "default" => "0"),
|
||||
),
|
||||
"indexes" => array(
|
||||
"PRIMARY" => array("id"),
|
||||
)
|
||||
);
|
||||
$database["event"] = array(
|
||||
"fields" => array(
|
||||
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
|
||||
|
@ -748,21 +737,6 @@ function db_definition() {
|
|||
"nurl" => array("nurl"),
|
||||
)
|
||||
);
|
||||
$database["guid"] = array(
|
||||
"fields" => array(
|
||||
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
|
||||
"guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
|
||||
"plink" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
|
||||
"uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
|
||||
"network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
|
||||
),
|
||||
"indexes" => array(
|
||||
"PRIMARY" => array("id"),
|
||||
"guid" => array("guid"),
|
||||
"plink" => array("plink"),
|
||||
"uri" => array("uri"),
|
||||
)
|
||||
);
|
||||
$database["hook"] = array(
|
||||
"fields" => array(
|
||||
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
|
||||
|
@ -1261,7 +1235,6 @@ function db_definition() {
|
|||
"fields" => array(
|
||||
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
|
||||
"iid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
|
||||
"retract_iid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
|
||||
"signed_text" => array("type" => "mediumtext", "not null" => "1"),
|
||||
"signature" => array("type" => "text", "not null" => "1"),
|
||||
"signer" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
|
||||
|
@ -1269,7 +1242,6 @@ function db_definition() {
|
|||
"indexes" => array(
|
||||
"PRIMARY" => array("id"),
|
||||
"iid" => array("iid"),
|
||||
"retract_iid" => array("retract_iid"),
|
||||
)
|
||||
);
|
||||
$database["spam"] = array(
|
||||
|
|
|
@ -10,11 +10,11 @@ require_once("include/dfrn.php");
|
|||
function delivery_run(&$argv, &$argc){
|
||||
global $a, $db;
|
||||
|
||||
if(is_null($a)){
|
||||
if (is_null($a)){
|
||||
$a = new App;
|
||||
}
|
||||
|
||||
if(is_null($db)) {
|
||||
if (is_null($db)) {
|
||||
@include(".htconfig.php");
|
||||
require_once("include/dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
|
@ -32,12 +32,12 @@ function delivery_run(&$argv, &$argc){
|
|||
|
||||
load_hooks();
|
||||
|
||||
if($argc < 3)
|
||||
if ($argc < 3)
|
||||
return;
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
logger('delivery: invoked: ' . print_r($argv,true), LOGGER_DEBUG);
|
||||
logger('delivery: invoked: '. print_r($argv,true), LOGGER_DEBUG);
|
||||
|
||||
$cmd = $argv[1];
|
||||
$item_id = intval($argv[2]);
|
||||
|
@ -53,21 +53,12 @@ function delivery_run(&$argv, &$argc){
|
|||
dbesc($item_id),
|
||||
dbesc($contact_id)
|
||||
);
|
||||
if(! count($r)) {
|
||||
if (!count($r)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$maxsysload = intval(get_config('system','maxloadavg'));
|
||||
if($maxsysload < 1)
|
||||
$maxsysload = 50;
|
||||
|
||||
$load = current_load();
|
||||
if($load) {
|
||||
if(intval($load) > $maxsysload) {
|
||||
logger('system: load ' . $load . ' too high. Delivery deferred to next queue run.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (App::maxload_reached())
|
||||
return;
|
||||
|
||||
// It's ours to deliver. Remove it from the queue.
|
||||
|
||||
|
@ -77,7 +68,7 @@ function delivery_run(&$argv, &$argc){
|
|||
dbesc($contact_id)
|
||||
);
|
||||
|
||||
if((! $item_id) || (! $contact_id))
|
||||
if (!$item_id || !$contact_id)
|
||||
continue;
|
||||
|
||||
$expire = false;
|
||||
|
@ -93,20 +84,20 @@ function delivery_run(&$argv, &$argc){
|
|||
|
||||
$recipients[] = $contact_id;
|
||||
|
||||
if($cmd === 'mail') {
|
||||
if ($cmd === 'mail') {
|
||||
$normal_mode = false;
|
||||
$mail = true;
|
||||
$message = q("SELECT * FROM `mail` WHERE `id` = %d LIMIT 1",
|
||||
intval($item_id)
|
||||
);
|
||||
if(! count($message)){
|
||||
if (!count($message)){
|
||||
return;
|
||||
}
|
||||
$uid = $message[0]['uid'];
|
||||
$recipients[] = $message[0]['contact-id'];
|
||||
$item = $message[0];
|
||||
}
|
||||
elseif($cmd === 'expire') {
|
||||
elseif ($cmd === 'expire') {
|
||||
$normal_mode = false;
|
||||
$expire = true;
|
||||
$items = q("SELECT * FROM `item` WHERE `uid` = %d AND `wall` = 1
|
||||
|
@ -115,22 +106,22 @@ function delivery_run(&$argv, &$argc){
|
|||
);
|
||||
$uid = $item_id;
|
||||
$item_id = 0;
|
||||
if(! count($items))
|
||||
if (!count($items))
|
||||
continue;
|
||||
}
|
||||
elseif($cmd === 'suggest') {
|
||||
elseif ($cmd === 'suggest') {
|
||||
$normal_mode = false;
|
||||
$fsuggest = true;
|
||||
|
||||
$suggest = q("SELECT * FROM `fsuggest` WHERE `id` = %d LIMIT 1",
|
||||
intval($item_id)
|
||||
);
|
||||
if(! count($suggest))
|
||||
if (!count($suggest))
|
||||
return;
|
||||
$uid = $suggest[0]['uid'];
|
||||
$recipients[] = $suggest[0]['cid'];
|
||||
$item = $suggest[0];
|
||||
} elseif($cmd === 'relocate') {
|
||||
} elseif ($cmd === 'relocate') {
|
||||
$normal_mode = false;
|
||||
$relocate = true;
|
||||
$uid = $item_id;
|
||||
|
@ -140,7 +131,7 @@ function delivery_run(&$argv, &$argc){
|
|||
intval($item_id)
|
||||
);
|
||||
|
||||
if((! count($r)) || (! intval($r[0]['parent']))) {
|
||||
if ((!count($r)) || (!intval($r[0]['parent']))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -154,32 +145,32 @@ function delivery_run(&$argv, &$argc){
|
|||
intval($parent_id)
|
||||
);
|
||||
|
||||
if(! count($items)) {
|
||||
if (!count($items)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$icontacts = null;
|
||||
$contacts_arr = array();
|
||||
foreach($items as $item)
|
||||
if(! in_array($item['contact-id'],$contacts_arr))
|
||||
if (!in_array($item['contact-id'],$contacts_arr))
|
||||
$contacts_arr[] = intval($item['contact-id']);
|
||||
if(count($contacts_arr)) {
|
||||
if (count($contacts_arr)) {
|
||||
$str_contacts = implode(',',$contacts_arr);
|
||||
$icontacts = q("SELECT * FROM `contact`
|
||||
WHERE `id` IN ( $str_contacts ) "
|
||||
);
|
||||
}
|
||||
if( ! ($icontacts && count($icontacts)))
|
||||
if ( !($icontacts && count($icontacts)))
|
||||
continue;
|
||||
|
||||
// avoid race condition with deleting entries
|
||||
|
||||
if($items[0]['deleted']) {
|
||||
if ($items[0]['deleted']) {
|
||||
foreach($items as $item)
|
||||
$item['deleted'] = 1;
|
||||
}
|
||||
|
||||
if((count($items) == 1) && ($items[0]['uri'] === $items[0]['parent-uri'])) {
|
||||
if ((count($items) == 1) && ($items[0]['uri'] === $items[0]['parent-uri'])) {
|
||||
logger('delivery: top level post');
|
||||
$top_level = true;
|
||||
}
|
||||
|
@ -193,7 +184,7 @@ function delivery_run(&$argv, &$argc){
|
|||
intval($uid)
|
||||
);
|
||||
|
||||
if(! count($r))
|
||||
if (!count($r))
|
||||
continue;
|
||||
|
||||
$owner = $r[0];
|
||||
|
@ -202,7 +193,7 @@ function delivery_run(&$argv, &$argc){
|
|||
|
||||
$public_message = true;
|
||||
|
||||
if(! ($mail || $fsuggest || $relocate)) {
|
||||
if (!($mail || $fsuggest || $relocate)) {
|
||||
require_once('include/group.php');
|
||||
|
||||
$parent = $items[0];
|
||||
|
@ -226,7 +217,7 @@ function delivery_run(&$argv, &$argc){
|
|||
|
||||
|
||||
$localhost = $a->get_hostname();
|
||||
if(strpos($localhost,':'))
|
||||
if (strpos($localhost,':'))
|
||||
$localhost = substr($localhost,0,strpos($localhost,':'));
|
||||
|
||||
/**
|
||||
|
@ -239,20 +230,21 @@ function delivery_run(&$argv, &$argc){
|
|||
|
||||
$relay_to_owner = false;
|
||||
|
||||
if((! $top_level) && ($parent['wall'] == 0) && (! $expire) && (stristr($target_item['uri'],$localhost))) {
|
||||
if (!$top_level && ($parent['wall'] == 0) && !$expire && stristr($target_item['uri'],$localhost)) {
|
||||
$relay_to_owner = true;
|
||||
}
|
||||
|
||||
if($relay_to_owner) {
|
||||
if ($relay_to_owner) {
|
||||
logger('followup '.$target_item["guid"], LOGGER_DEBUG);
|
||||
// local followup to remote post
|
||||
$followup = true;
|
||||
}
|
||||
|
||||
if((strlen($parent['allow_cid']))
|
||||
if ((strlen($parent['allow_cid']))
|
||||
|| (strlen($parent['allow_gid']))
|
||||
|| (strlen($parent['deny_cid']))
|
||||
|| (strlen($parent['deny_gid']))) {
|
||||
|| (strlen($parent['deny_gid']))
|
||||
|| $parent["private"]) {
|
||||
$public_message = false; // private recipients, not public
|
||||
}
|
||||
|
||||
|
@ -262,10 +254,10 @@ function delivery_run(&$argv, &$argc){
|
|||
intval($contact_id)
|
||||
);
|
||||
|
||||
if(count($r))
|
||||
if (count($r))
|
||||
$contact = $r[0];
|
||||
|
||||
if($contact['self'])
|
||||
if ($contact['self'])
|
||||
continue;
|
||||
|
||||
$deliver_status = 0;
|
||||
|
@ -275,7 +267,7 @@ function delivery_run(&$argv, &$argc){
|
|||
switch($contact['network']) {
|
||||
|
||||
case NETWORK_DFRN:
|
||||
logger('notifier: '.$target_item["guid"].' dfrndelivery: ' . $contact['name']);
|
||||
logger('notifier: '.$target_item["guid"].' dfrndelivery: '.$contact['name']);
|
||||
|
||||
if ($mail) {
|
||||
$item['body'] = fix_private_photos($item['body'],$owner['uid'],null,$message[0]['contact-id']);
|
||||
|
@ -285,13 +277,13 @@ function delivery_run(&$argv, &$argc){
|
|||
q("DELETE FROM `fsuggest` WHERE `id` = %d LIMIT 1", intval($item['id']));
|
||||
} elseif ($relocate)
|
||||
$atom = dfrn::relocate($owner, $uid);
|
||||
elseif($followup) {
|
||||
elseif ($followup) {
|
||||
$msgitems = array();
|
||||
foreach($items as $item) { // there is only one item
|
||||
if(!$item['parent'])
|
||||
if (!$item['parent'])
|
||||
continue;
|
||||
if($item['id'] == $item_id) {
|
||||
logger('followup: item: ' . print_r($item,true), LOGGER_DATA);
|
||||
if ($item['id'] == $item_id) {
|
||||
logger('followup: item: '. print_r($item,true), LOGGER_DATA);
|
||||
$msgitems[] = $item;
|
||||
}
|
||||
}
|
||||
|
@ -299,19 +291,19 @@ function delivery_run(&$argv, &$argc){
|
|||
} else {
|
||||
$msgitems = array();
|
||||
foreach($items as $item) {
|
||||
if(!$item['parent'])
|
||||
if (!$item['parent'])
|
||||
continue;
|
||||
|
||||
// private emails may be in included in public conversations. Filter them.
|
||||
if(($public_message) && $item['private'])
|
||||
if ($public_message && $item['private'])
|
||||
continue;
|
||||
|
||||
$item_contact = get_item_contact($item,$icontacts);
|
||||
if(!$item_contact)
|
||||
if (!$item_contact)
|
||||
continue;
|
||||
|
||||
if($normal_mode) {
|
||||
if($item_id == $item['id'] || $item['id'] == $item['parent']) {
|
||||
if ($normal_mode) {
|
||||
if ($item_id == $item['id'] || $item['id'] == $item['parent']) {
|
||||
$item["entry:comment-allow"] = true;
|
||||
$item["entry:cid"] = (($top_level) ? $contact['id'] : 0);
|
||||
$msgitems[] = $item;
|
||||
|
@ -326,15 +318,15 @@ function delivery_run(&$argv, &$argc){
|
|||
|
||||
logger('notifier entry: '.$contact["url"].' '.$target_item["guid"].' entry: '.$atom, LOGGER_DEBUG);
|
||||
|
||||
logger('notifier: ' . $atom, LOGGER_DATA);
|
||||
logger('notifier: '.$atom, LOGGER_DATA);
|
||||
$basepath = implode('/', array_slice(explode('/',$contact['url']),0,3));
|
||||
|
||||
// perform local delivery if we are on the same site
|
||||
|
||||
if(link_compare($basepath,$a->get_baseurl())) {
|
||||
if (link_compare($basepath,$a->get_baseurl())) {
|
||||
|
||||
$nickname = basename($contact['url']);
|
||||
if($contact['issued-id'])
|
||||
if ($contact['issued-id'])
|
||||
$sql_extra = sprintf(" AND `dfrn-id` = '%s' ", dbesc($contact['issued-id']));
|
||||
else
|
||||
$sql_extra = sprintf(" AND `issued-id` = '%s' ", dbesc($contact['dfrn-id']));
|
||||
|
@ -356,10 +348,10 @@ function delivery_run(&$argv, &$argc){
|
|||
dbesc($nickname)
|
||||
);
|
||||
|
||||
if($x && count($x)) {
|
||||
if ($x && count($x)) {
|
||||
$write_flag = ((($x[0]['rel']) && ($x[0]['rel'] != CONTACT_IS_SHARING)) ? true : false);
|
||||
if((($owner['page-flags'] == PAGE_COMMUNITY) || ($write_flag)) && (! $x[0]['writable'])) {
|
||||
q("update contact set writable = 1 where id = %d",
|
||||
if ((($owner['page-flags'] == PAGE_COMMUNITY) || $write_flag) && !$x[0]['writable']) {
|
||||
q("UPDATE `contact` SET `writable` = 1 WHERE `id` = %d",
|
||||
intval($x[0]['id'])
|
||||
);
|
||||
$x[0]['writable'] = 1;
|
||||
|
@ -374,19 +366,19 @@ function delivery_run(&$argv, &$argc){
|
|||
break;
|
||||
|
||||
logger('mod-delivery: local delivery');
|
||||
local_delivery($x[0],$atom);
|
||||
dfrn::import($atom, $x[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(! was_recently_delayed($contact['id']))
|
||||
if (!was_recently_delayed($contact['id']))
|
||||
$deliver_status = dfrn::deliver($owner,$contact,$atom);
|
||||
else
|
||||
$deliver_status = (-1);
|
||||
|
||||
logger('notifier: dfrn_delivery to '.$contact["url"].' with guid '.$target_item["guid"].' returns '.$deliver_status);
|
||||
|
||||
if($deliver_status == (-1)) {
|
||||
if ($deliver_status == (-1)) {
|
||||
logger('notifier: delivery failed: queuing message');
|
||||
add_to_queue($contact['id'],NETWORK_DFRN,$atom);
|
||||
}
|
||||
|
@ -394,9 +386,9 @@ function delivery_run(&$argv, &$argc){
|
|||
|
||||
case NETWORK_OSTATUS:
|
||||
// Do not send to otatus if we are not configured to send to public networks
|
||||
if($owner['prvnets'])
|
||||
if ($owner['prvnets'])
|
||||
break;
|
||||
if(get_config('system','ostatus_disabled') || get_config('system','dfrn_only'))
|
||||
if (get_config('system','ostatus_disabled') || get_config('system','dfrn_only'))
|
||||
break;
|
||||
|
||||
// There is currently no code here to distribute anything to OStatus.
|
||||
|
@ -406,67 +398,67 @@ function delivery_run(&$argv, &$argc){
|
|||
case NETWORK_MAIL:
|
||||
case NETWORK_MAIL2:
|
||||
|
||||
if(get_config('system','dfrn_only'))
|
||||
if (get_config('system','dfrn_only'))
|
||||
break;
|
||||
// WARNING: does not currently convert to RFC2047 header encodings, etc.
|
||||
|
||||
$addr = $contact['addr'];
|
||||
if(! strlen($addr))
|
||||
if (!strlen($addr))
|
||||
break;
|
||||
|
||||
if($cmd === 'wall-new' || $cmd === 'comment-new') {
|
||||
if ($cmd === 'wall-new' || $cmd === 'comment-new') {
|
||||
|
||||
$it = null;
|
||||
if($cmd === 'wall-new')
|
||||
if ($cmd === 'wall-new')
|
||||
$it = $items[0];
|
||||
else {
|
||||
$r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
|
||||
intval($argv[2]),
|
||||
intval($uid)
|
||||
);
|
||||
if(count($r))
|
||||
if (count($r))
|
||||
$it = $r[0];
|
||||
}
|
||||
if(! $it)
|
||||
if (!$it)
|
||||
break;
|
||||
|
||||
|
||||
$local_user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
|
||||
intval($uid)
|
||||
);
|
||||
if(! count($local_user))
|
||||
if (!count($local_user))
|
||||
break;
|
||||
|
||||
$reply_to = '';
|
||||
$r1 = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
|
||||
intval($uid)
|
||||
);
|
||||
if($r1 && $r1[0]['reply_to'])
|
||||
if ($r1 && $r1[0]['reply_to'])
|
||||
$reply_to = $r1[0]['reply_to'];
|
||||
|
||||
$subject = (($it['title']) ? email_header_encode($it['title'],'UTF-8') : t("\x28no subject\x29")) ;
|
||||
|
||||
// only expose our real email address to true friends
|
||||
|
||||
if(($contact['rel'] == CONTACT_IS_FRIEND) && (! $contact['blocked'])) {
|
||||
if($reply_to) {
|
||||
if (($contact['rel'] == CONTACT_IS_FRIEND) && !$contact['blocked']) {
|
||||
if ($reply_to) {
|
||||
$headers = 'From: '.email_header_encode($local_user[0]['username'],'UTF-8').' <'.$reply_to.'>'."\n";
|
||||
$headers .= 'Sender: '.$local_user[0]['email']."\n";
|
||||
} else
|
||||
$headers = 'From: '.email_header_encode($local_user[0]['username'],'UTF-8').' <'.$local_user[0]['email'].'>'."\n";
|
||||
} else
|
||||
$headers = 'From: ' . email_header_encode($local_user[0]['username'],'UTF-8') . ' <' . t('noreply') . '@' . $a->get_hostname() . '>' . "\n";
|
||||
$headers = 'From: '. email_header_encode($local_user[0]['username'],'UTF-8') .' <'. t('noreply') .'@'.$a->get_hostname() .'>'. "\n";
|
||||
|
||||
//if($reply_to)
|
||||
// $headers .= 'Reply-to: ' . $reply_to . "\n";
|
||||
//if ($reply_to)
|
||||
// $headers .= 'Reply-to: '.$reply_to . "\n";
|
||||
|
||||
$headers .= 'Message-Id: <' . iri2msgid($it['uri']). '>' . "\n";
|
||||
$headers .= 'Message-Id: <'. iri2msgid($it['uri']).'>'. "\n";
|
||||
|
||||
//logger("Mail: uri: ".$it['uri']." parent-uri ".$it['parent-uri'], LOGGER_DEBUG);
|
||||
//logger("Mail: Data: ".print_r($it, true), LOGGER_DEBUG);
|
||||
//logger("Mail: Data: ".print_r($it, true), LOGGER_DATA);
|
||||
|
||||
if($it['uri'] !== $it['parent-uri']) {
|
||||
if ($it['uri'] !== $it['parent-uri']) {
|
||||
$headers .= "References: <".iri2msgid($it["parent-uri"]).">";
|
||||
|
||||
// If Threading is enabled, write down the correct parent
|
||||
|
@ -474,23 +466,23 @@ function delivery_run(&$argv, &$argc){
|
|||
$headers .= " <".iri2msgid($it["thr-parent"]).">";
|
||||
$headers .= "\n";
|
||||
|
||||
if(!$it['title']) {
|
||||
if (!$it['title']) {
|
||||
$r = q("SELECT `title` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
|
||||
dbesc($it['parent-uri']),
|
||||
intval($uid));
|
||||
|
||||
if(count($r) AND ($r[0]['title'] != ''))
|
||||
if (count($r) AND ($r[0]['title'] != ''))
|
||||
$subject = $r[0]['title'];
|
||||
else {
|
||||
$r = q("SELECT `title` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d LIMIT 1",
|
||||
dbesc($it['parent-uri']),
|
||||
intval($uid));
|
||||
|
||||
if(count($r) AND ($r[0]['title'] != ''))
|
||||
if (count($r) AND ($r[0]['title'] != ''))
|
||||
$subject = $r[0]['title'];
|
||||
}
|
||||
}
|
||||
if(strncasecmp($subject,'RE:',3))
|
||||
if (strncasecmp($subject,'RE:',3))
|
||||
$subject = 'Re: '.$subject;
|
||||
}
|
||||
email_send($addr, $subject, $headers, $it);
|
||||
|
@ -498,60 +490,59 @@ function delivery_run(&$argv, &$argc){
|
|||
break;
|
||||
|
||||
case NETWORK_DIASPORA:
|
||||
if($public_message)
|
||||
$loc = 'public batch ' . $contact['batch'];
|
||||
if ($public_message)
|
||||
$loc = 'public batch '.$contact['batch'];
|
||||
else
|
||||
$loc = $contact['name'];
|
||||
|
||||
logger('delivery: diaspora batch deliver: ' . $loc);
|
||||
logger('delivery: diaspora batch deliver: '.$loc);
|
||||
|
||||
if(get_config('system','dfrn_only') || (!get_config('system','diaspora_enabled')))
|
||||
if (get_config('system','dfrn_only') || (!get_config('system','diaspora_enabled')))
|
||||
break;
|
||||
|
||||
if($mail) {
|
||||
diaspora_send_mail($item,$owner,$contact);
|
||||
if ($mail) {
|
||||
diaspora::send_mail($item,$owner,$contact);
|
||||
break;
|
||||
}
|
||||
|
||||
if(!$normal_mode)
|
||||
if (!$normal_mode)
|
||||
break;
|
||||
|
||||
if((! $contact['pubkey']) && (! $public_message))
|
||||
if (!$contact['pubkey'] && !$public_message)
|
||||
break;
|
||||
|
||||
$unsupported_activities = array(ACTIVITY_DISLIKE, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE);
|
||||
|
||||
//don't transmit activities which are not supported by diaspora
|
||||
foreach($unsupported_activities as $act) {
|
||||
if(activity_match($target_item['verb'],$act)) {
|
||||
if (activity_match($target_item['verb'],$act)) {
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
|
||||
if(($target_item['deleted']) && (($target_item['uri'] === $target_item['parent-uri']) || $followup)) {
|
||||
if (($target_item['deleted']) && (($target_item['uri'] === $target_item['parent-uri']) || $followup)) {
|
||||
// top-level retraction
|
||||
logger('delivery: diaspora retract: ' . $loc);
|
||||
|
||||
diaspora_send_retraction($target_item,$owner,$contact,$public_message);
|
||||
logger('diaspora retract: '.$loc);
|
||||
diaspora::send_retraction($target_item,$owner,$contact,$public_message);
|
||||
break;
|
||||
} elseif($followup) {
|
||||
} elseif ($followup) {
|
||||
// send comments and likes to owner to relay
|
||||
diaspora_send_followup($target_item,$owner,$contact,$public_message);
|
||||
logger('diaspora followup: '.$loc);
|
||||
diaspora::send_followup($target_item,$owner,$contact,$public_message);
|
||||
break;
|
||||
} elseif($target_item['uri'] !== $target_item['parent-uri']) {
|
||||
} elseif ($target_item['uri'] !== $target_item['parent-uri']) {
|
||||
// we are the relay - send comments, likes and relayable_retractions to our conversants
|
||||
logger('delivery: diaspora relay: ' . $loc);
|
||||
|
||||
diaspora_send_relay($target_item,$owner,$contact,$public_message);
|
||||
logger('diaspora relay: '.$loc);
|
||||
diaspora::send_relay($target_item,$owner,$contact,$public_message);
|
||||
break;
|
||||
} elseif(($top_level) && (! $walltowall)) {
|
||||
} elseif ($top_level && !$walltowall) {
|
||||
// currently no workable solution for sending walltowall
|
||||
logger('delivery: diaspora status: ' . $loc);
|
||||
diaspora_send_status($target_item,$owner,$contact,$public_message);
|
||||
logger('diaspora status: '.$loc);
|
||||
diaspora::send_status($target_item,$owner,$contact,$public_message);
|
||||
break;
|
||||
}
|
||||
|
||||
logger('delivery: diaspora unknown mode: ' . $contact['name']);
|
||||
logger('delivery: diaspora unknown mode: '.$contact['name']);
|
||||
|
||||
break;
|
||||
|
||||
|
|
1666
include/dfrn.php
1666
include/dfrn.php
File diff suppressed because it is too large
Load diff
5922
include/diaspora.php
5922
include/diaspora.php
File diff suppressed because it is too large
Load diff
|
@ -20,22 +20,14 @@ function discover_poco_run(&$argv, &$argc){
|
|||
|
||||
require_once('include/session.php');
|
||||
require_once('include/datetime.php');
|
||||
require_once('include/pidfile.php');
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
|
||||
$maxsysload = intval(get_config('system','maxloadavg'));
|
||||
if($maxsysload < 1)
|
||||
$maxsysload = 50;
|
||||
|
||||
$load = current_load();
|
||||
if($load) {
|
||||
if(intval($load) > $maxsysload) {
|
||||
logger('system: load ' . $load . ' too high. discover_poco deferred to next scheduled run.');
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run")
|
||||
if (App::maxload_reached())
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(($argc > 2) && ($argv[1] == "dirsearch")) {
|
||||
$search = urldecode($argv[2]);
|
||||
|
@ -50,21 +42,10 @@ function discover_poco_run(&$argv, &$argc){
|
|||
} else
|
||||
die("Unknown or missing parameter ".$argv[1]."\n");
|
||||
|
||||
$lockpath = get_lockpath();
|
||||
if ($lockpath != '') {
|
||||
$pidfile = new pidfile($lockpath, 'discover_poco'.$mode.urlencode($search));
|
||||
if($pidfile->is_already_running()) {
|
||||
logger("discover_poco: Already running");
|
||||
if ($pidfile->running_time() > 19*60) {
|
||||
$pidfile->kill();
|
||||
logger("discover_poco: killed stale process");
|
||||
// Calling a new instance
|
||||
if ($mode == 0)
|
||||
proc_run('php','include/discover_poco.php');
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run")
|
||||
if (App::is_already_running('discover_poco'.$mode.urlencode($search), 'include/discover_poco.php', 1140))
|
||||
return;
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
<?php
|
||||
require_once("boot.php");
|
||||
require_once('include/diaspora.php');
|
||||
|
||||
function dsprphotoq_run($argv, $argc){
|
||||
global $a, $db;
|
||||
|
||||
if(is_null($a)){
|
||||
$a = new App;
|
||||
}
|
||||
|
||||
if(is_null($db)){
|
||||
@include(".htconfig.php");
|
||||
require_once("include/dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
};
|
||||
|
||||
logger("diaspora photo queue: running", LOGGER_DEBUG);
|
||||
|
||||
$r = q("SELECT * FROM dsprphotoq");
|
||||
if(!$r)
|
||||
return;
|
||||
|
||||
$dphotos = $r;
|
||||
|
||||
logger("diaspora photo queue: processing " . count($dphotos) . " photos");
|
||||
|
||||
foreach($dphotos as $dphoto) {
|
||||
|
||||
$r = array();
|
||||
|
||||
if ($dphoto['uid'] == 0)
|
||||
$r[0] = array("uid" => 0, "page-flags" => PAGE_FREELOVE);
|
||||
else
|
||||
$r = q("SELECT * FROM user WHERE uid = %d",
|
||||
intval($dphoto['uid']));
|
||||
|
||||
if(!$r) {
|
||||
logger("diaspora photo queue: user " . $dphoto['uid'] . " not found");
|
||||
return;
|
||||
}
|
||||
|
||||
$ret = diaspora_dispatch($r[0],unserialize($dphoto['msg']),$dphoto['attempt']);
|
||||
q("DELETE FROM dsprphotoq WHERE id = %d",
|
||||
intval($dphoto['id'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
dsprphotoq_run($_SERVER["argv"],$_SERVER["argc"]);
|
||||
killme();
|
||||
}
|
|
@ -76,7 +76,6 @@ function format_event_html($ev, $simple = false) {
|
|||
function parse_event($h) {
|
||||
|
||||
require_once('include/Scrape.php');
|
||||
require_once('library/HTMLPurifier.auto.php');
|
||||
require_once('include/html2bbcode');
|
||||
|
||||
$h = '<html><body>' . $h . '</body></html>';
|
||||
|
|
116
include/feed.php
116
include/feed.php
|
@ -2,7 +2,18 @@
|
|||
require_once("include/html2bbcode.php");
|
||||
require_once("include/items.php");
|
||||
|
||||
function feed_import($xml,$importer,&$contact, &$hub) {
|
||||
/**
|
||||
* @brief Read a RSS/RDF/Atom feed and create an item entry for it
|
||||
*
|
||||
* @param string $xml The feed data
|
||||
* @param array $importer The user record of the importer
|
||||
* @param array $contact The contact record of the feed
|
||||
* @param string $hub Unused dummy value for compatibility reasons
|
||||
* @param bool $simulate If enabled, no data is imported
|
||||
*
|
||||
* @return array In simulation mode it returns the header and the first item
|
||||
*/
|
||||
function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
|
@ -14,18 +25,19 @@ function feed_import($xml,$importer,&$contact, &$hub) {
|
|||
$doc = new DOMDocument();
|
||||
@$doc->loadXML($xml);
|
||||
$xpath = new DomXPath($doc);
|
||||
$xpath->registerNamespace('atom', "http://www.w3.org/2005/Atom");
|
||||
$xpath->registerNamespace('atom', NAMESPACE_ATOM1);
|
||||
$xpath->registerNamespace('dc', "http://purl.org/dc/elements/1.1/");
|
||||
$xpath->registerNamespace('content', "http://purl.org/rss/1.0/modules/content/");
|
||||
$xpath->registerNamespace('rdf', "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
|
||||
$xpath->registerNamespace('rss', "http://purl.org/rss/1.0/");
|
||||
$xpath->registerNamespace('media', "http://search.yahoo.com/mrss/");
|
||||
$xpath->registerNamespace('poco', NAMESPACE_POCO);
|
||||
|
||||
$author = array();
|
||||
|
||||
// Is it RDF?
|
||||
if ($xpath->query('/rdf:RDF/rss:channel')->length > 0) {
|
||||
//$author["author-link"] = $xpath->evaluate('/rdf:RDF/rss:channel/rss:link/text()')->item(0)->nodeValue;
|
||||
$author["author-link"] = $xpath->evaluate('/rdf:RDF/rss:channel/rss:link/text()')->item(0)->nodeValue;
|
||||
$author["author-name"] = $xpath->evaluate('/rdf:RDF/rss:channel/rss:title/text()')->item(0)->nodeValue;
|
||||
|
||||
if ($author["author-name"] == "")
|
||||
|
@ -36,19 +48,29 @@ function feed_import($xml,$importer,&$contact, &$hub) {
|
|||
|
||||
// Is it Atom?
|
||||
if ($xpath->query('/atom:feed/atom:entry')->length > 0) {
|
||||
//$self = $xpath->query("/atom:feed/atom:link[@rel='self']")->item(0)->attributes;
|
||||
//if (is_object($self))
|
||||
// foreach($self AS $attributes)
|
||||
// if ($attributes->name == "href")
|
||||
// $author["author-link"] = $attributes->textContent;
|
||||
$alternate = $xpath->query("atom:link[@rel='alternate']")->item(0)->attributes;
|
||||
if (is_object($alternate))
|
||||
foreach($alternate AS $attributes)
|
||||
if ($attributes->name == "href")
|
||||
$author["author-link"] = $attributes->textContent;
|
||||
|
||||
//if ($author["author-link"] == "") {
|
||||
// $alternate = $xpath->query("/atom:feed/atom:link[@rel='alternate']")->item(0)->attributes;
|
||||
// if (is_object($alternate))
|
||||
// foreach($alternate AS $attributes)
|
||||
// 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"];
|
||||
|
||||
if ($author["author-link"] == "") {
|
||||
$self = $xpath->query("atom:link[@rel='self']")->item(0)->attributes;
|
||||
if (is_object($self))
|
||||
foreach($self AS $attributes)
|
||||
if ($attributes->name == "href")
|
||||
$author["author-link"] = $attributes->textContent;
|
||||
}
|
||||
|
||||
if ($author["author-link"] == "")
|
||||
$author["author-link"] = $xpath->evaluate('/atom:feed/atom:id/text()')->item(0)->nodeValue;
|
||||
|
||||
$author["author-avatar"] = $xpath->evaluate('/atom:feed/atom:logo/text()')->item(0)->nodeValue;
|
||||
|
||||
$author["author-name"] = $xpath->evaluate('/atom:feed/atom:title/text()')->item(0)->nodeValue;
|
||||
|
||||
|
@ -58,7 +80,13 @@ function feed_import($xml,$importer,&$contact, &$hub) {
|
|||
if ($author["author-name"] == "")
|
||||
$author["author-name"] = $xpath->evaluate('/atom:feed/atom:author/atom:name/text()')->item(0)->nodeValue;
|
||||
|
||||
//$author["author-avatar"] = $xpath->evaluate('/atom:feed/atom:logo/text()')->item(0)->nodeValue;
|
||||
$value = $xpath->evaluate('atom:author/poco:displayName/text()')->item(0)->nodeValue;
|
||||
if ($value != "")
|
||||
$author["author-name"] = $value;
|
||||
|
||||
$value = $xpath->evaluate('atom:author/poco:preferredUsername/text()')->item(0)->nodeValue;
|
||||
if ($value != "")
|
||||
$author["author-nick"] = $value;
|
||||
|
||||
$author["edited"] = $author["created"] = $xpath->query('/atom:feed/atom:updated/text()')->item(0)->nodeValue;
|
||||
|
||||
|
@ -69,9 +97,10 @@ function feed_import($xml,$importer,&$contact, &$hub) {
|
|||
|
||||
// Is it RSS?
|
||||
if ($xpath->query('/rss/channel')->length > 0) {
|
||||
//$author["author-link"] = $xpath->evaluate('/rss/channel/link/text()')->item(0)->nodeValue;
|
||||
$author["author-link"] = $xpath->evaluate('/rss/channel/link/text()')->item(0)->nodeValue;
|
||||
|
||||
$author["author-name"] = $xpath->evaluate('/rss/channel/title/text()')->item(0)->nodeValue;
|
||||
//$author["author-avatar"] = $xpath->evaluate('/rss/channel/image/url/text()')->item(0)->nodeValue;
|
||||
$author["author-avatar"] = $xpath->evaluate('/rss/channel/image/url/text()')->item(0)->nodeValue;
|
||||
|
||||
if ($author["author-name"] == "")
|
||||
$author["author-name"] = $xpath->evaluate('/rss/channel/copyright/text()')->item(0)->nodeValue;
|
||||
|
@ -86,18 +115,22 @@ function feed_import($xml,$importer,&$contact, &$hub) {
|
|||
$entries = $xpath->query('/rss/channel/item');
|
||||
}
|
||||
|
||||
//if ($author["author-link"] == "")
|
||||
if (!$simulate) {
|
||||
$author["author-link"] = $contact["url"];
|
||||
|
||||
if ($author["author-name"] == "")
|
||||
$author["author-name"] = $contact["name"];
|
||||
if ($author["author-name"] == "")
|
||||
$author["author-name"] = $contact["name"];
|
||||
|
||||
//if ($author["author-avatar"] == "")
|
||||
$author["author-avatar"] = $contact["thumb"];
|
||||
|
||||
$author["owner-link"] = $contact["url"];
|
||||
$author["owner-name"] = $contact["name"];
|
||||
$author["owner-avatar"] = $contact["thumb"];
|
||||
$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();
|
||||
$header["uid"] = $importer["uid"];
|
||||
|
@ -120,6 +153,8 @@ function feed_import($xml,$importer,&$contact, &$hub) {
|
|||
if (!is_object($entries))
|
||||
return;
|
||||
|
||||
$items = array();
|
||||
|
||||
$entrylist = array();
|
||||
|
||||
foreach ($entries AS $entry)
|
||||
|
@ -201,13 +236,13 @@ function feed_import($xml,$importer,&$contact, &$hub) {
|
|||
if ($creator != "")
|
||||
$item["author-name"] = $creator;
|
||||
|
||||
//$item["object"] = $xml;
|
||||
|
||||
$r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s', '%s')",
|
||||
intval($importer["uid"]), dbesc($item["uri"]), dbesc(NETWORK_FEED), dbesc(NETWORK_DFRN));
|
||||
if ($r) {
|
||||
logger("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already existed under id ".$r[0]["id"], LOGGER_DEBUG);
|
||||
continue;
|
||||
if (!$simulate) {
|
||||
$r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s', '%s')",
|
||||
intval($importer["uid"]), dbesc($item["uri"]), dbesc(NETWORK_FEED), dbesc(NETWORK_DFRN));
|
||||
if ($r) {
|
||||
logger("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already existed under id ".$r[0]["id"], LOGGER_DEBUG);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/// @TODO ?
|
||||
|
@ -272,14 +307,21 @@ function feed_import($xml,$importer,&$contact, &$hub) {
|
|||
$item["body"] = html2bbcode($body);
|
||||
}
|
||||
|
||||
logger("Stored feed: ".print_r($item, true), LOGGER_DEBUG);
|
||||
if (!$simulate) {
|
||||
logger("Stored feed: ".print_r($item, true), LOGGER_DEBUG);
|
||||
|
||||
$notify = item_is_remote_self($contact, $item);
|
||||
$id = item_store($item, false, $notify);
|
||||
$notify = item_is_remote_self($contact, $item);
|
||||
$id = item_store($item, false, $notify);
|
||||
|
||||
//print_r($item);
|
||||
logger("Feed for contact ".$contact["url"]." stored under id ".$id);
|
||||
} else
|
||||
$items[] = $item;
|
||||
|
||||
logger("Feed for contact ".$contact["url"]." stored under id ".$id);
|
||||
if ($simulate)
|
||||
break;
|
||||
}
|
||||
|
||||
if ($simulate)
|
||||
return array("header" => $author, "items" => $items);
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
require_once("include/Scrape.php");
|
||||
require_once("include/socgraph.php");
|
||||
|
||||
function update_contact($id) {
|
||||
/*
|
||||
|
@ -43,6 +44,9 @@ function update_contact($id) {
|
|||
intval($id)
|
||||
);
|
||||
|
||||
// Update the corresponding gcontact entry
|
||||
poco_last_updated($ret["url"]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -254,12 +258,10 @@ function new_contact($uid,$url,$interactive = false) {
|
|||
$contact_id = $r[0]['id'];
|
||||
$result['cid'] = $contact_id;
|
||||
|
||||
$g = q("select def_gid from user where uid = %d limit 1",
|
||||
intval($uid)
|
||||
);
|
||||
if($g && intval($g[0]['def_gid'])) {
|
||||
$def_gid = get_default_group($uid, $contact["network"]);
|
||||
if (intval($def_gid)) {
|
||||
require_once('include/group.php');
|
||||
group_add_member($uid,'',$contact_id,$g[0]['def_gid']);
|
||||
group_add_member($uid, '', $contact_id, $def_gid);
|
||||
}
|
||||
|
||||
require_once("include/Photo.php");
|
||||
|
@ -301,8 +303,8 @@ function new_contact($uid,$url,$interactive = false) {
|
|||
}
|
||||
if($contact['network'] == NETWORK_DIASPORA) {
|
||||
require_once('include/diaspora.php');
|
||||
$ret = diaspora_share($a->user,$contact);
|
||||
logger('mod_follow: diaspora_share returns: ' . $ret);
|
||||
$ret = diaspora::send_share($a->user,$contact);
|
||||
logger('share returns: '.$ret);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,185 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file include/forums.php
|
||||
* @brief Functions related to forum functionality *
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function to list all forums a user is connected with
|
||||
*
|
||||
* @param int $uid of the profile owner
|
||||
* @param boolean $showhidden
|
||||
* Show frorums which are not hidden
|
||||
* @param boolean $lastitem
|
||||
* Sort by lastitem
|
||||
* @param boolean $showprivate
|
||||
* Show private groups
|
||||
*
|
||||
* @returns array
|
||||
* 'url' => forum url
|
||||
* 'name' => forum name
|
||||
* 'id' => number of the key from the array
|
||||
* 'micro' => contact photo in format micro
|
||||
*/
|
||||
function get_forumlist($uid, $showhidden = true, $lastitem, $showprivate = false) {
|
||||
|
||||
$forumlist = array();
|
||||
|
||||
$order = (($showhidden) ? '' : ' AND NOT `hidden` ');
|
||||
$order .= (($lastitem) ? ' ORDER BY `last-item` DESC ' : ' ORDER BY `name` ASC ');
|
||||
$select = '`forum` ';
|
||||
if ($showprivate) {
|
||||
$select = '(`forum` OR `prv`)';
|
||||
}
|
||||
|
||||
$contacts = q("SELECT `contact`.`id`, `contact`.`url`, `contact`.`name`, `contact`.`micro` FROM `contact`
|
||||
WHERE `network`= 'dfrn' AND $select AND `uid` = %d
|
||||
AND NOT `blocked` AND NOT `hidden` AND NOT `pending` AND NOT `archive`
|
||||
AND `success_update` > `failure_update`
|
||||
$order ",
|
||||
intval($uid)
|
||||
);
|
||||
|
||||
if (!$contacts)
|
||||
return($forumlist);
|
||||
|
||||
foreach($contacts as $contact) {
|
||||
$forumlist[] = array(
|
||||
'url' => $contact['url'],
|
||||
'name' => $contact['name'],
|
||||
'id' => $contact['id'],
|
||||
'micro' => $contact['micro'],
|
||||
);
|
||||
}
|
||||
return($forumlist);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Forumlist widget
|
||||
*
|
||||
* Sidebar widget to show subcribed friendica forums. If activated
|
||||
* in the settings, it appears at the notwork page sidebar
|
||||
*
|
||||
* @param int $uid
|
||||
* @param int $cid
|
||||
* The contact id which is used to mark a forum as "selected"
|
||||
* @return string
|
||||
*/
|
||||
function widget_forumlist($uid,$cid = 0) {
|
||||
|
||||
if(! intval(feature_enabled(local_user(),'forumlist_widget')))
|
||||
return;
|
||||
|
||||
$o = '';
|
||||
|
||||
//sort by last updated item
|
||||
$lastitem = true;
|
||||
|
||||
$contacts = get_forumlist($uid,true,$lastitem, true);
|
||||
$total = count($contacts);
|
||||
$visible_forums = 10;
|
||||
|
||||
if(count($contacts)) {
|
||||
|
||||
$id = 0;
|
||||
|
||||
foreach($contacts as $contact) {
|
||||
|
||||
$selected = (($cid == $contact['id']) ? ' forum-selected' : '');
|
||||
|
||||
$entry = array(
|
||||
'url' => z_root() . '/network?f=&cid=' . $contact['id'],
|
||||
'external_url' => z_root() . '/redir/' . $contact['id'],
|
||||
'name' => $contact['name'],
|
||||
'cid' => $contact['id'],
|
||||
'selected' => $selected,
|
||||
'micro' => proxy_url($contact['micro'], false, PROXY_SIZE_MICRO),
|
||||
'id' => ++$id,
|
||||
);
|
||||
$entries[] = $entry;
|
||||
}
|
||||
|
||||
$tpl = get_markup_template('widget_forumlist.tpl');
|
||||
|
||||
$o .= replace_macros($tpl,array(
|
||||
'$title' => t('Forums'),
|
||||
'$forums' => $entries,
|
||||
'$link_desc' => t('External link to forum'),
|
||||
'$total' => $total,
|
||||
'$visible_forums' => $visible_forums,
|
||||
'$showmore' => t('show more'),
|
||||
));
|
||||
}
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Format forumlist as contact block
|
||||
*
|
||||
* This function is used to show the forumlist in
|
||||
* the advanced profile.
|
||||
*
|
||||
* @param int $uid
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
function forumlist_profile_advanced($uid) {
|
||||
|
||||
$profile = intval(feature_enabled($uid,'forumlist_profile'));
|
||||
if(! $profile)
|
||||
return;
|
||||
|
||||
$o = '';
|
||||
|
||||
// place holder in case somebody wants configurability
|
||||
$show_total = 9999;
|
||||
|
||||
//don't sort by last updated item
|
||||
$lastitem = false;
|
||||
|
||||
$contacts = get_forumlist($uid,false,$lastitem,false);
|
||||
|
||||
$total_shown = 0;
|
||||
|
||||
foreach($contacts as $contact) {
|
||||
$forumlist .= micropro($contact,false,'forumlist-profile-advanced');
|
||||
$total_shown ++;
|
||||
if($total_shown == $show_total)
|
||||
break;
|
||||
}
|
||||
|
||||
if(count($contacts) > 0)
|
||||
$o .= $forumlist;
|
||||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief count unread forum items
|
||||
*
|
||||
* Count unread items of connected forums and private groups
|
||||
*
|
||||
* @return array
|
||||
* 'id' => contact id
|
||||
* 'name' => contact/forum name
|
||||
* 'count' => counted unseen forum items
|
||||
*
|
||||
*/
|
||||
|
||||
function forums_count_unseen() {
|
||||
$r = q("SELECT `contact`.`id`, `contact`.`name`, COUNT(*) AS `count` FROM `item`
|
||||
INNER JOIN `contact` ON `item`.`contact-id` = `contact`.`id`
|
||||
WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` AND `item`.`unseen`
|
||||
AND `contact`.`network`= 'dfrn' AND (`contact`.`forum` OR `contact`.`prv`)
|
||||
AND NOT `contact`.`blocked` AND NOT `contact`.`hidden`
|
||||
AND NOT `contact`.`pending` AND NOT `contact`.`archive`
|
||||
AND `contact`.`success_update` > `failure_update`
|
||||
GROUP BY `contact`.`id` ",
|
||||
intval(local_user())
|
||||
);
|
||||
|
||||
return $r;
|
||||
}
|
|
@ -60,6 +60,8 @@ class FriendicaSmartyEngine implements ITemplateEngine {
|
|||
$template = $s;
|
||||
$s = new FriendicaSmarty();
|
||||
}
|
||||
|
||||
$r['$APP'] = get_app();
|
||||
|
||||
// "middleware": inject variables into templates
|
||||
$arr = array(
|
||||
|
|
|
@ -188,7 +188,7 @@ function group_public_members($gid) {
|
|||
}
|
||||
|
||||
|
||||
function mini_group_select($uid,$gid = 0) {
|
||||
function mini_group_select($uid,$gid = 0, $label = "") {
|
||||
|
||||
$grps = array();
|
||||
$o = '';
|
||||
|
@ -205,8 +205,11 @@ function mini_group_select($uid,$gid = 0) {
|
|||
}
|
||||
logger('groups: ' . print_r($grps,true));
|
||||
|
||||
if ($label == "")
|
||||
$label = t('Default privacy group for new contacts');
|
||||
|
||||
$o = replace_macros(get_markup_template('group_selection.tpl'), array(
|
||||
'$label' => t('Default privacy group for new contacts'),
|
||||
'$label' => $label,
|
||||
'$groups' => $grps
|
||||
));
|
||||
return $o;
|
||||
|
@ -215,7 +218,7 @@ function mini_group_select($uid,$gid = 0) {
|
|||
|
||||
/**
|
||||
* @brief Create group sidebar widget
|
||||
*
|
||||
*
|
||||
* @param string $every
|
||||
* @param string $each
|
||||
* @param string $editmode
|
||||
|
@ -234,7 +237,7 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro
|
|||
return '';
|
||||
|
||||
$groups = array();
|
||||
|
||||
|
||||
$groups[] = array(
|
||||
'text' => t('Everybody'),
|
||||
'id' => 0,
|
||||
|
@ -255,7 +258,7 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro
|
|||
if(count($r)) {
|
||||
foreach($r as $rr) {
|
||||
$selected = (($group_id == $rr['id']) ? ' group-selected' : '');
|
||||
|
||||
|
||||
if ($editmode == "full") {
|
||||
$groupedit = array(
|
||||
'href' => "group/".$rr['id'],
|
||||
|
@ -264,7 +267,7 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro
|
|||
} else {
|
||||
$groupedit = null;
|
||||
}
|
||||
|
||||
|
||||
$groups[] = array(
|
||||
'id' => $rr['id'],
|
||||
'cid' => $cid,
|
||||
|
@ -362,17 +365,41 @@ function groups_containing($uid,$c) {
|
|||
*/
|
||||
function groups_count_unseen() {
|
||||
|
||||
$r = q("SELECT `group`.`id`, `group`.`name`, COUNT(`item`.`id`) AS `count` FROM `group`, `group_member`, `item`
|
||||
WHERE `group`.`uid` = %d
|
||||
AND `item`.`uid` = %d
|
||||
AND `item`.`unseen` AND `item`.`visible`
|
||||
AND NOT `item`.`deleted`
|
||||
AND `item`.`contact-id` = `group_member`.`contact-id`
|
||||
AND `group_member`.`gid` = `group`.`id`
|
||||
GROUP BY `group`.`id` ",
|
||||
$r = q("SELECT `group`.`id`, `group`.`name`,
|
||||
(SELECT COUNT(*) FROM `item`
|
||||
WHERE `uid` = %d AND `unseen` AND
|
||||
`contact-id` IN (SELECT `contact-id` FROM `group_member`
|
||||
WHERE `group_member`.`gid` = `group`.`id` AND `group_member`.`uid` = %d)) AS `count`
|
||||
FROM `group` WHERE `group`.`uid` = %d;",
|
||||
intval(local_user()),
|
||||
intval(local_user()),
|
||||
intval(local_user())
|
||||
);
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the default group for a given user and network
|
||||
*
|
||||
* @param int $uid User id
|
||||
* @param string $network network name
|
||||
*
|
||||
* @return int group id
|
||||
*/
|
||||
function get_default_group($uid, $network = "") {
|
||||
|
||||
$default_group = 0;
|
||||
|
||||
if ($network == NETWORK_OSTATUS)
|
||||
$default_group = get_pconfig($uid, "ostatus", "default_group");
|
||||
|
||||
if ($default_group != 0)
|
||||
return $default_group;
|
||||
|
||||
$g = q("SELECT `def_gid` FROM `user` WHERE `uid` = %d LIMIT 1", intval($uid));
|
||||
if($g && intval($g[0]["def_gid"]))
|
||||
$default_group = $g[0]["def_gid"];
|
||||
|
||||
return $default_group;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* @file include/identity.php
|
||||
*/
|
||||
|
||||
require_once('include/forums.php');
|
||||
require_once('include/ForumManager.php');
|
||||
require_once('include/bbcode.php');
|
||||
require_once("mod/proxy.php");
|
||||
|
||||
|
@ -237,6 +237,7 @@ function profile_sidebar($profile, $block = 0) {
|
|||
if ($connect AND ($profile['network'] != NETWORK_DFRN) AND !isset($profile['remoteconnect']))
|
||||
$connect = false;
|
||||
|
||||
$remoteconnect = NULL;
|
||||
if (isset($profile['remoteconnect']))
|
||||
$remoteconnect = $profile['remoteconnect'];
|
||||
|
||||
|
@ -292,9 +293,9 @@ function profile_sidebar($profile, $block = 0) {
|
|||
// check if profile is a forum
|
||||
if((intval($profile['page-flags']) == PAGE_COMMUNITY)
|
||||
|| (intval($profile['page-flags']) == PAGE_PRVGROUP)
|
||||
|| (intval($profile['forum']))
|
||||
|| (intval($profile['prv']))
|
||||
|| (intval($profile['community'])))
|
||||
|| (isset($profile['forum']) && intval($profile['forum']))
|
||||
|| (isset($profile['prv']) && intval($profile['prv']))
|
||||
|| (isset($profile['community']) && intval($profile['community'])))
|
||||
$account_type = t('Forum');
|
||||
else
|
||||
$account_type = "";
|
||||
|
@ -332,9 +333,9 @@ function profile_sidebar($profile, $block = 0) {
|
|||
'fullname' => $profile['name'],
|
||||
'firstname' => $firstname,
|
||||
'lastname' => $lastname,
|
||||
'photo300' => $a->get_cached_avatar_image($a->get_baseurl() . '/photo/custom/300/' . $profile['uid'] . '.jpg'),
|
||||
'photo100' => $a->get_cached_avatar_image($a->get_baseurl() . '/photo/custom/100/' . $profile['uid'] . '.jpg'),
|
||||
'photo50' => $a->get_cached_avatar_image($a->get_baseurl() . '/photo/custom/50/' . $profile['uid'] . '.jpg'),
|
||||
'photo300' => $a->get_baseurl() . '/photo/custom/300/' . $profile['uid'] . '.jpg',
|
||||
'photo100' => $a->get_baseurl() . '/photo/custom/100/' . $profile['uid'] . '.jpg',
|
||||
'photo50' => $a->get_baseurl() . '/photo/custom/50/' . $profile['uid'] . '.jpg',
|
||||
);
|
||||
|
||||
if (!$block){
|
||||
|
@ -655,7 +656,7 @@ function advanced_profile(&$a) {
|
|||
|
||||
//show subcribed forum if it is enabled in the usersettings
|
||||
if (feature_enabled($uid,'forumlist_profile')) {
|
||||
$profile['forumlist'] = array( t('Forums:'), forumlist_profile_advanced($uid));
|
||||
$profile['forumlist'] = array( t('Forums:'), ForumManager::profile_advanced($uid));
|
||||
}
|
||||
|
||||
if ($a->profile['uid'] == local_user())
|
||||
|
|
2283
include/items.php
2283
include/items.php
File diff suppressed because it is too large
Load diff
153
include/like.php
153
include/like.php
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
require_once("include/diaspora.php");
|
||||
|
||||
/**
|
||||
* @brief add/remove activity to an item
|
||||
|
@ -151,9 +152,6 @@ function do_like($item_id, $verb) {
|
|||
intval($like_item['id'])
|
||||
);
|
||||
|
||||
// Save the author information for the unlike in case we need to relay to Diaspora
|
||||
store_diaspora_like_retract_sig($activity, $item, $like_item, $contact);
|
||||
|
||||
$like_item_id = $like_item['id'];
|
||||
proc_run('php',"include/notifier.php","like","$like_item_id");
|
||||
|
||||
|
@ -196,6 +194,7 @@ EOT;
|
|||
|
||||
$arr = array();
|
||||
|
||||
$arr['guid'] = get_guid(32);
|
||||
$arr['uri'] = $uri;
|
||||
$arr['uid'] = $owner_uid;
|
||||
$arr['contact-id'] = $contact['id'];
|
||||
|
@ -240,7 +239,7 @@ EOT;
|
|||
|
||||
|
||||
// Save the author information for the like in case we need to relay to Diaspora
|
||||
store_diaspora_like_sig($activity, $post_type, $contact, $post_id);
|
||||
diaspora::store_like_signature($contact, $post_id);
|
||||
|
||||
$arr['id'] = $post_id;
|
||||
|
||||
|
@ -250,149 +249,3 @@ EOT;
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function store_diaspora_like_retract_sig($activity, $item, $like_item, $contact) {
|
||||
// Note that we can only create a signature for a user of the local server. We don't have
|
||||
// a key for remote users. That is ok, because if a remote user is "unlike"ing a post, it
|
||||
// means we are the relay, and for relayable_retractions, Diaspora
|
||||
// only checks the parent_author_signature if it doesn't have to relay further
|
||||
//
|
||||
// If $item['resource-id'] exists, it means the item is a photo. Diaspora doesn't support
|
||||
// likes on photos, so don't bother.
|
||||
|
||||
$enabled = intval(get_config('system','diaspora_enabled'));
|
||||
if(! $enabled) {
|
||||
logger('mod_like: diaspora support disabled, not storing like retraction signature', LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
|
||||
logger('mod_like: storing diaspora like retraction signature');
|
||||
|
||||
if(($activity === ACTIVITY_LIKE) && (! $item['resource-id'])) {
|
||||
$signed_text = $like_item['guid'] . ';' . 'Like';
|
||||
|
||||
// Only works for NETWORK_DFRN
|
||||
$contact_baseurl_start = strpos($contact['url'],'://') + 3;
|
||||
$contact_baseurl_length = strpos($contact['url'],'/profile') - $contact_baseurl_start;
|
||||
$contact_baseurl = substr($contact['url'], $contact_baseurl_start, $contact_baseurl_length);
|
||||
$diaspora_handle = $contact['nick'] . '@' . $contact_baseurl;
|
||||
|
||||
// This code could never had worked (the return values form the queries were used in a wrong way.
|
||||
// Additionally it is needlessly complicated. Either the contact is owner or not. And we have this data already.
|
||||
/*
|
||||
// Get contact's private key if he's a user of the local Friendica server
|
||||
$r = q("SELECT `contact`.`uid` FROM `contact` WHERE `url` = '%s' AND `self` = 1 LIMIT 1",
|
||||
dbesc($contact['url'])
|
||||
);
|
||||
|
||||
if( $r) {
|
||||
$contact_uid = $r['uid'];
|
||||
$r = q("SELECT prvkey FROM user WHERE uid = %d LIMIT 1",
|
||||
intval($contact_uid)
|
||||
);
|
||||
*/
|
||||
// Is the contact the owner? Then fetch the private key
|
||||
if ($contact['self'] AND ($contact['uid'] > 0)) {
|
||||
$r = q("SELECT prvkey FROM user WHERE uid = %d LIMIT 1",
|
||||
intval($contact['uid'])
|
||||
);
|
||||
|
||||
if($r)
|
||||
$authorsig = base64_encode(rsa_sign($signed_text,$r[0]['prvkey'],'sha256'));
|
||||
}
|
||||
|
||||
if(! isset($authorsig))
|
||||
$authorsig = '';
|
||||
|
||||
q("insert into sign (`retract_iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
|
||||
intval($like_item['id']),
|
||||
dbesc($signed_text),
|
||||
dbesc($authorsig),
|
||||
dbesc($diaspora_handle)
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
function store_diaspora_like_sig($activity, $post_type, $contact, $post_id) {
|
||||
// Note that we can only create a signature for a user of the local server. We don't have
|
||||
// a key for remote users. That is ok, because if a remote user is "unlike"ing a post, it
|
||||
// means we are the relay, and for relayable_retractions, Diaspora
|
||||
// only checks the parent_author_signature if it doesn't have to relay further
|
||||
|
||||
$enabled = intval(get_config('system','diaspora_enabled'));
|
||||
if(! $enabled) {
|
||||
logger('mod_like: diaspora support disabled, not storing like signature', LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
|
||||
logger('mod_like: storing diaspora like signature');
|
||||
|
||||
if(($activity === ACTIVITY_LIKE) && ($post_type === t('status'))) {
|
||||
// Only works for NETWORK_DFRN
|
||||
$contact_baseurl_start = strpos($contact['url'],'://') + 3;
|
||||
$contact_baseurl_length = strpos($contact['url'],'/profile') - $contact_baseurl_start;
|
||||
$contact_baseurl = substr($contact['url'], $contact_baseurl_start, $contact_baseurl_length);
|
||||
$diaspora_handle = $contact['nick'] . '@' . $contact_baseurl;
|
||||
|
||||
|
||||
// This code could never had worked (the return values form the queries were used in a wrong way.
|
||||
// Additionally it is needlessly complicated. Either the contact is owner or not. And we have this data already.
|
||||
/*
|
||||
// Get contact's private key if he's a user of the local Friendica server
|
||||
$r = q("SELECT `contact`.`uid` FROM `contact` WHERE `url` = '%s' AND `self` = 1 LIMIT 1",
|
||||
dbesc($contact['url'])
|
||||
);
|
||||
|
||||
if( $r) {
|
||||
$contact_uid = $r['uid'];
|
||||
$r = q("SELECT prvkey FROM user WHERE uid = %d LIMIT 1",
|
||||
intval($contact_uid)
|
||||
);
|
||||
|
||||
if( $r)
|
||||
$contact_uprvkey = $r['prvkey'];
|
||||
}
|
||||
*/
|
||||
|
||||
// Is the contact the owner? Then fetch the private key
|
||||
if ($contact['self'] AND ($contact['uid'] > 0)) {
|
||||
$r = q("SELECT prvkey FROM user WHERE uid = %d LIMIT 1",
|
||||
intval($contact['uid'])
|
||||
);
|
||||
|
||||
if($r)
|
||||
$contact_uprvkey = $r[0]['prvkey'];
|
||||
}
|
||||
|
||||
$r = q("SELECT guid, parent FROM `item` WHERE id = %d LIMIT 1",
|
||||
intval($post_id)
|
||||
);
|
||||
if( $r) {
|
||||
$p = q("SELECT guid FROM `item` WHERE id = %d AND parent = %d LIMIT 1",
|
||||
intval($r[0]['parent']),
|
||||
intval($r[0]['parent'])
|
||||
);
|
||||
if( $p) {
|
||||
$signed_text = 'true;'.$r[0]['guid'].';Post;'.$p[0]['guid'].';'.$diaspora_handle;
|
||||
|
||||
if(isset($contact_uprvkey))
|
||||
$authorsig = base64_encode(rsa_sign($signed_text,$contact_uprvkey,'sha256'));
|
||||
else
|
||||
$authorsig = '';
|
||||
|
||||
q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
|
||||
intval($post_id),
|
||||
dbesc($signed_text),
|
||||
dbesc($authorsig),
|
||||
dbesc($diaspora_handle)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ function nav_info(&$a) {
|
|||
// user info
|
||||
$r = q("SELECT micro FROM contact WHERE uid=%d AND self=1", intval($a->user['uid']));
|
||||
$userinfo = array(
|
||||
'icon' => (count($r) ? $a->get_cached_avatar_image($r[0]['micro']) : $a->get_baseurl($ssl_state)."/images/person-48.jpg"),
|
||||
'icon' => (count($r) ? $a->remove_baseurl($r[0]['micro']) : "images/person-48.jpg"),
|
||||
'name' => $a->user['username'],
|
||||
);
|
||||
|
||||
|
@ -110,7 +110,7 @@ function nav_info(&$a) {
|
|||
if(($a->config['register_policy'] == REGISTER_OPEN) && (! local_user()) && (! remote_user()))
|
||||
$nav['register'] = array('register',t('Register'), "", t('Create an account'));
|
||||
|
||||
$help_url = $a->get_baseurl($ssl_state) . '/help';
|
||||
$help_url = 'help';
|
||||
|
||||
if(! get_config('system','hide_help'))
|
||||
$nav['help'] = array($help_url, t('Help'), "", t('Help and documentation'));
|
||||
|
|
|
@ -862,64 +862,6 @@ function parse_xml_string($s,$strict = true) {
|
|||
return $x;
|
||||
}}
|
||||
|
||||
function add_fcontact($arr,$update = false) {
|
||||
|
||||
if($update) {
|
||||
$r = q("UPDATE `fcontact` SET
|
||||
`name` = '%s',
|
||||
`photo` = '%s',
|
||||
`request` = '%s',
|
||||
`nick` = '%s',
|
||||
`addr` = '%s',
|
||||
`batch` = '%s',
|
||||
`notify` = '%s',
|
||||
`poll` = '%s',
|
||||
`confirm` = '%s',
|
||||
`alias` = '%s',
|
||||
`pubkey` = '%s',
|
||||
`updated` = '%s'
|
||||
WHERE `url` = '%s' AND `network` = '%s'",
|
||||
dbesc($arr['name']),
|
||||
dbesc($arr['photo']),
|
||||
dbesc($arr['request']),
|
||||
dbesc($arr['nick']),
|
||||
dbesc($arr['addr']),
|
||||
dbesc($arr['batch']),
|
||||
dbesc($arr['notify']),
|
||||
dbesc($arr['poll']),
|
||||
dbesc($arr['confirm']),
|
||||
dbesc($arr['alias']),
|
||||
dbesc($arr['pubkey']),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($arr['url']),
|
||||
dbesc($arr['network'])
|
||||
);
|
||||
}
|
||||
else {
|
||||
$r = q("insert into fcontact ( `url`,`name`,`photo`,`request`,`nick`,`addr`,
|
||||
`batch`, `notify`,`poll`,`confirm`,`network`,`alias`,`pubkey`,`updated` )
|
||||
values('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",
|
||||
dbesc($arr['url']),
|
||||
dbesc($arr['name']),
|
||||
dbesc($arr['photo']),
|
||||
dbesc($arr['request']),
|
||||
dbesc($arr['nick']),
|
||||
dbesc($arr['addr']),
|
||||
dbesc($arr['batch']),
|
||||
dbesc($arr['notify']),
|
||||
dbesc($arr['poll']),
|
||||
dbesc($arr['confirm']),
|
||||
dbesc($arr['network']),
|
||||
dbesc($arr['alias']),
|
||||
dbesc($arr['pubkey']),
|
||||
dbesc(datetime_convert())
|
||||
);
|
||||
}
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
|
||||
function scale_external_images($srctext, $include_link = true, $scale_replace = false) {
|
||||
|
||||
// Suppress "view full size"
|
||||
|
|
|
@ -223,13 +223,13 @@ function notifier_run(&$argv, &$argc){
|
|||
|
||||
if(! ($mail || $fsuggest || $relocate)) {
|
||||
|
||||
$slap = ostatus_salmon($target_item,$owner);
|
||||
$slap = ostatus::salmon($target_item,$owner);
|
||||
|
||||
require_once('include/group.php');
|
||||
|
||||
$parent = $items[0];
|
||||
|
||||
$thr_parent = q("SELECT `network` FROM `item` WHERE `uri` = '%s' AND `uid` = %d",
|
||||
$thr_parent = q("SELECT `network`, `author-link`, `owner-link` FROM `item` WHERE `uri` = '%s' AND `uid` = %d",
|
||||
dbesc($target_item["thr-parent"]), intval($target_item["uid"]));
|
||||
|
||||
logger('Parent is '.$parent['network'].'. Thread parent is '.$thr_parent[0]['network'], LOGGER_DEBUG);
|
||||
|
@ -390,6 +390,20 @@ function notifier_run(&$argv, &$argc){
|
|||
|
||||
logger('Some parent is OStatus for '.$target_item["guid"], LOGGER_DEBUG);
|
||||
|
||||
// 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) {
|
||||
|
@ -536,7 +550,7 @@ function notifier_run(&$argv, &$argc){
|
|||
if($public_message) {
|
||||
|
||||
if (!$followup AND $top_level)
|
||||
$r0 = diaspora_fetch_relay();
|
||||
$r0 = diaspora::relay_list();
|
||||
else
|
||||
$r0 = array();
|
||||
|
||||
|
@ -628,13 +642,6 @@ function notifier_run(&$argv, &$argc){
|
|||
proc_run('php','include/pubsubpublish.php');
|
||||
}
|
||||
|
||||
// If the item was deleted, clean up the `sign` table
|
||||
if($target_item['deleted']) {
|
||||
$r = q("DELETE FROM sign where `retract_iid` = %d",
|
||||
intval($target_item['id'])
|
||||
);
|
||||
}
|
||||
|
||||
logger('notifier: calling hooks', LOGGER_DEBUG);
|
||||
|
||||
if($normal_mode)
|
||||
|
|
|
@ -31,7 +31,6 @@ function onepoll_run(&$argv, &$argc){
|
|||
require_once('include/Contact.php');
|
||||
require_once('include/email.php');
|
||||
require_once('include/socgraph.php');
|
||||
require_once('include/pidfile.php');
|
||||
require_once('include/queue_fn.php');
|
||||
|
||||
load_config('config');
|
||||
|
@ -60,18 +59,10 @@ function onepoll_run(&$argv, &$argc){
|
|||
return;
|
||||
}
|
||||
|
||||
$lockpath = get_lockpath();
|
||||
if ($lockpath != '') {
|
||||
$pidfile = new pidfile($lockpath, 'onepoll'.$contact_id);
|
||||
if ($pidfile->is_already_running()) {
|
||||
logger("onepoll: Already running for contact ".$contact_id);
|
||||
if ($pidfile->running_time() > 9*60) {
|
||||
$pidfile->kill();
|
||||
logger("killed stale process");
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run")
|
||||
if (App::is_already_running('onepoll'.$contact_id, '', 540))
|
||||
return;
|
||||
|
||||
$d = datetime_convert();
|
||||
|
||||
|
|
3166
include/ostatus.php
3166
include/ostatus.php
File diff suppressed because it is too large
Load diff
|
@ -132,7 +132,19 @@ function shortenmsg($msg, $limit, $twitter = false) {
|
|||
return($msg);
|
||||
}
|
||||
|
||||
function plaintext($a, $b, $limit = 0, $includedlinks = false, $htmlmode = 2) {
|
||||
/**
|
||||
* @brief Convert a message into plaintext for connectors to other networks
|
||||
*
|
||||
* @param App $a The application class
|
||||
* @param array $b The message array that is about to be posted
|
||||
* @param int $limit The maximum number of characters when posting to that network
|
||||
* @param bool $includedlinks Has an attached link to be included into the message?
|
||||
* @param int $htmlmode This triggers the behaviour of the bbcode conversion
|
||||
* @param string $target_network Name of the network where the post should go to.
|
||||
*
|
||||
* @return string The converted message
|
||||
*/
|
||||
function plaintext($a, $b, $limit = 0, $includedlinks = false, $htmlmode = 2, $target_network = "") {
|
||||
require_once("include/bbcode.php");
|
||||
require_once("include/html2plain.php");
|
||||
require_once("include/network.php");
|
||||
|
@ -144,6 +156,9 @@ function plaintext($a, $b, $limit = 0, $includedlinks = false, $htmlmode = 2) {
|
|||
// Add an URL element if the text contains a raw link
|
||||
$body = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1[url]$2[/url]', $body);
|
||||
|
||||
// Remove the abstract
|
||||
$body = remove_abstract($body);
|
||||
|
||||
// At first look at data that is attached via "type-..." stuff
|
||||
// This will hopefully replaced with a dedicated bbcode later
|
||||
//$post = get_attached_data($b["body"]);
|
||||
|
@ -154,6 +169,44 @@ function plaintext($a, $b, $limit = 0, $includedlinks = false, $htmlmode = 2) {
|
|||
elseif ($b["title"] != "")
|
||||
$post["text"] = trim($b["title"]);
|
||||
|
||||
$abstract = "";
|
||||
|
||||
// Fetch the abstract from the given target network
|
||||
if ($target_network != "") {
|
||||
$default_abstract = fetch_abstract($b["body"]);
|
||||
$abstract = fetch_abstract($b["body"], $target_network);
|
||||
|
||||
// If we post to a network with no limit we only fetch
|
||||
// an abstract exactly for this network
|
||||
if (($limit == 0) AND ($abstract == $default_abstract))
|
||||
$abstract = "";
|
||||
|
||||
} else // Try to guess the correct target network
|
||||
switch ($htmlmode) {
|
||||
case 8:
|
||||
$abstract = fetch_abstract($b["body"], NETWORK_TWITTER);
|
||||
break;
|
||||
case 7:
|
||||
$abstract = fetch_abstract($b["body"], NETWORK_STATUSNET);
|
||||
break;
|
||||
case 6:
|
||||
$abstract = fetch_abstract($b["body"], NETWORK_APPNET);
|
||||
break;
|
||||
default: // We don't know the exact target.
|
||||
// We fetch an abstract since there is a posting limit.
|
||||
if ($limit > 0)
|
||||
$abstract = fetch_abstract($b["body"]);
|
||||
}
|
||||
|
||||
if ($abstract != "") {
|
||||
$post["text"] = $abstract;
|
||||
|
||||
if ($post["type"] == "text") {
|
||||
$post["type"] = "link";
|
||||
$post["url"] = $b["plink"];
|
||||
}
|
||||
}
|
||||
|
||||
$html = bbcode($post["text"], false, false, $htmlmode);
|
||||
$msg = html2plain($html, 0, true);
|
||||
$msg = trim(html_entity_decode($msg,ENT_QUOTES,'UTF-8'));
|
||||
|
|
|
@ -26,17 +26,11 @@ function poller_run(&$argv, &$argc){
|
|||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
};
|
||||
|
||||
$load = current_load();
|
||||
if($load) {
|
||||
$maxsysload = intval(get_config('system','maxloadavg'));
|
||||
if($maxsysload < 1)
|
||||
$maxsysload = 50;
|
||||
if (poller_max_connections_reached())
|
||||
return;
|
||||
|
||||
if(intval($load) > $maxsysload) {
|
||||
logger('system: load ' . $load . ' too high. poller deferred to next scheduled run.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (App::maxload_reached())
|
||||
return;
|
||||
|
||||
// Checking the number of workers
|
||||
if (poller_too_much_workers(1)) {
|
||||
|
@ -65,6 +59,10 @@ function poller_run(&$argv, &$argc){
|
|||
|
||||
while ($r = q("SELECT * FROM `workerqueue` WHERE `executed` = '0000-00-00 00:00:00' ORDER BY `created` LIMIT 1")) {
|
||||
|
||||
// Constantly check the number of available database connections to let the frontend be accessible at any time
|
||||
if (poller_max_connections_reached())
|
||||
return;
|
||||
|
||||
// Count active workers and compare them with a maximum value that depends on the load
|
||||
if (poller_too_much_workers(3))
|
||||
return;
|
||||
|
@ -117,12 +115,93 @@ function poller_run(&$argv, &$argc){
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks if the number of database connections has reached a critical limit.
|
||||
*
|
||||
* @return bool Are more than 3/4 of the maximum connections used?
|
||||
*/
|
||||
function poller_max_connections_reached() {
|
||||
|
||||
// Fetch the max value from the config. This is needed when the system cannot detect the correct value by itself.
|
||||
$max = get_config("system", "max_connections");
|
||||
|
||||
if ($max == 0) {
|
||||
// the maximum number of possible user connections can be a system variable
|
||||
$r = q("SHOW VARIABLES WHERE `variable_name` = 'max_user_connections'");
|
||||
if ($r)
|
||||
$max = $r[0]["Value"];
|
||||
|
||||
// Or it can be granted. This overrides the system variable
|
||||
$r = q("SHOW GRANTS");
|
||||
if ($r)
|
||||
foreach ($r AS $grants) {
|
||||
$grant = array_pop($grants);
|
||||
if (stristr($grant, "GRANT USAGE ON"))
|
||||
if (preg_match("/WITH MAX_USER_CONNECTIONS (\d*)/", $grant, $match))
|
||||
$max = $match[1];
|
||||
}
|
||||
}
|
||||
|
||||
// If $max is set we will use the processlist to determine the current number of connections
|
||||
// The processlist only shows entries of the current user
|
||||
if ($max != 0) {
|
||||
$r = q("SHOW PROCESSLIST");
|
||||
if (!$r)
|
||||
return false;
|
||||
|
||||
$used = count($r);
|
||||
|
||||
logger("Connection usage (user values): ".$used."/".$max, LOGGER_DEBUG);
|
||||
|
||||
$level = $used / $max;
|
||||
|
||||
if ($level >= (3/4)) {
|
||||
logger("Maximum level (3/4) of user connections reached: ".$used."/".$max);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// We will now check for the system values.
|
||||
// This limit could be reached although the user limits are fine.
|
||||
$r = q("SHOW VARIABLES WHERE `variable_name` = 'max_connections'");
|
||||
if (!$r)
|
||||
return false;
|
||||
|
||||
$max = intval($r[0]["Value"]);
|
||||
if ($max == 0)
|
||||
return false;
|
||||
|
||||
$r = q("SHOW STATUS WHERE `variable_name` = 'Threads_connected'");
|
||||
if (!$r)
|
||||
return false;
|
||||
|
||||
$used = intval($r[0]["Value"]);
|
||||
if ($used == 0)
|
||||
return false;
|
||||
|
||||
logger("Connection usage (system values): ".$used."/".$max, LOGGER_DEBUG);
|
||||
|
||||
$level = $used / $max;
|
||||
|
||||
if ($level < (3/4))
|
||||
return false;
|
||||
|
||||
logger("Maximum level (3/4) of system connections reached: ".$used."/".$max);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief fix the queue entry if the worker process died
|
||||
*
|
||||
*/
|
||||
function poller_kill_stale_workers() {
|
||||
$r = q("SELECT `pid`, `executed` FROM `workerqueue` WHERE `executed` != '0000-00-00 00:00:00'");
|
||||
|
||||
if (!is_array($r) || count($r) == 0) {
|
||||
// No processing here needed
|
||||
return;
|
||||
}
|
||||
|
||||
foreach($r AS $pid)
|
||||
if (!posix_kill($pid["pid"], 0))
|
||||
q("UPDATE `workerqueue` SET `executed` = '0000-00-00 00:00:00', `pid` = 0 WHERE `pid` = %d",
|
||||
|
|
141
include/post_update.php
Normal file
141
include/post_update.php
Normal file
|
@ -0,0 +1,141 @@
|
|||
<?php
|
||||
/**
|
||||
* @file include/post_update.php
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Calls the post update functions
|
||||
*/
|
||||
function post_update() {
|
||||
|
||||
if (!post_update_1192())
|
||||
return;
|
||||
|
||||
if (!post_update_1194())
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief set the gcontact-id in all item entries
|
||||
*
|
||||
* This job has to be started multiple times until all entries are set.
|
||||
* It isn't started in the update function since it would consume too much time and can be done in the background.
|
||||
*
|
||||
* @return bool "true" when the job is done
|
||||
*/
|
||||
function post_update_1192() {
|
||||
|
||||
// Was the script completed?
|
||||
if (get_config("system", "post_update_version") >= 1192)
|
||||
return true;
|
||||
|
||||
// Check if the first step is done (Setting "gcontact-id" in the item table)
|
||||
$r = q("SELECT `author-link`, `author-name`, `author-avatar`, `uid`, `network` FROM `item` WHERE `gcontact-id` = 0 LIMIT 1000");
|
||||
if (!$r) {
|
||||
// Are there unfinished entries in the thread table?
|
||||
$r = q("SELECT COUNT(*) AS `total` FROM `thread`
|
||||
INNER JOIN `item` ON `item`.`id` =`thread`.`iid`
|
||||
WHERE `thread`.`gcontact-id` = 0 AND
|
||||
(`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)");
|
||||
|
||||
if ($r AND ($r[0]["total"] == 0)) {
|
||||
set_config("system", "post_update_version", 1192);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Update the thread table from the item table
|
||||
q("UPDATE `thread` INNER JOIN `item` ON `item`.`id`=`thread`.`iid`
|
||||
SET `thread`.`gcontact-id` = `item`.`gcontact-id`
|
||||
WHERE `thread`.`gcontact-id` = 0 AND
|
||||
(`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$item_arr = array();
|
||||
foreach ($r AS $item) {
|
||||
$index = $item["author-link"]."-".$item["uid"];
|
||||
$item_arr[$index] = array("author-link" => $item["author-link"],
|
||||
"uid" => $item["uid"],
|
||||
"network" => $item["network"]);
|
||||
}
|
||||
|
||||
// Set the "gcontact-id" in the item table and add a new gcontact entry if needed
|
||||
foreach($item_arr AS $item) {
|
||||
$gcontact_id = get_gcontact_id(array("url" => $item['author-link'], "network" => $item['network'],
|
||||
"photo" => $item['author-avatar'], "name" => $item['author-name']));
|
||||
q("UPDATE `item` SET `gcontact-id` = %d WHERE `uid` = %d AND `author-link` = '%s' AND `gcontact-id` = 0",
|
||||
intval($gcontact_id), intval($item["uid"]), dbesc($item["author-link"]));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Updates the "global" field in the item table
|
||||
*
|
||||
* @return bool "true" when the job is done
|
||||
*/
|
||||
function post_update_1194() {
|
||||
|
||||
// Was the script completed?
|
||||
if (get_config("system", "post_update_version") >= 1194)
|
||||
return true;
|
||||
|
||||
logger("Start", LOGGER_DEBUG);
|
||||
|
||||
$end_id = get_config("system", "post_update_1194_end");
|
||||
if (!$end_id) {
|
||||
$r = q("SELECT `id` FROM `item` WHERE `uid` != 0 ORDER BY `id` DESC LIMIT 1");
|
||||
if ($r) {
|
||||
set_config("system", "post_update_1194_end", $r[0]["id"]);
|
||||
$end_id = get_config("system", "post_update_1194_end");
|
||||
}
|
||||
}
|
||||
|
||||
logger("End ID: ".$end_id, LOGGER_DEBUG);
|
||||
|
||||
$start_id = get_config("system", "post_update_1194_start");
|
||||
|
||||
$query1 = "SELECT `item`.`id` FROM `item` ";
|
||||
|
||||
$query2 = "INNER JOIN `item` AS `shadow` ON `item`.`uri` = `shadow`.`uri` AND `shadow`.`uid` = 0 ";
|
||||
|
||||
$query3 = "WHERE `item`.`uid` != 0 AND `item`.`id` >= %d AND `item`.`id` <= %d
|
||||
AND `item`.`visible` AND NOT `item`.`private`
|
||||
AND NOT `item`.`deleted` AND NOT `item`.`moderated`
|
||||
AND `item`.`network` IN ('%s', '%s', '%s', '')
|
||||
AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
|
||||
AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
|
||||
AND NOT `item`.`global`";
|
||||
|
||||
$r = q($query1.$query2.$query3." ORDER BY `item`.`id` LIMIT 1",
|
||||
intval($start_id), intval($end_id),
|
||||
dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS));
|
||||
if (!$r) {
|
||||
set_config("system", "post_update_version", 1194);
|
||||
logger("Update is done", LOGGER_DEBUG);
|
||||
return true;
|
||||
} else {
|
||||
set_config("system", "post_update_1194_start", $r[0]["id"]);
|
||||
$start_id = get_config("system", "post_update_1194_start");
|
||||
}
|
||||
|
||||
logger("Start ID: ".$start_id, LOGGER_DEBUG);
|
||||
|
||||
$r = q($query1.$query2.$query3." ORDER BY `item`.`id` LIMIT 1000,1",
|
||||
intval($start_id), intval($end_id),
|
||||
dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS));
|
||||
if ($r)
|
||||
$pos_id = $r[0]["id"];
|
||||
else
|
||||
$pos_id = $end_id;
|
||||
|
||||
logger("Progress: Start: ".$start_id." position: ".$pos_id." end: ".$end_id, LOGGER_DEBUG);
|
||||
|
||||
$r = q("UPDATE `item` ".$query2." SET `item`.`global` = 1 ".$query3,
|
||||
intval($start_id), intval($pos_id),
|
||||
dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS));
|
||||
|
||||
logger("Done", LOGGER_DEBUG);
|
||||
}
|
||||
?>
|
|
@ -1,96 +1,6 @@
|
|||
<?php
|
||||
|
||||
require_once('include/datetime.php');
|
||||
require_once('include/diaspora.php');
|
||||
require_once('include/queue_fn.php');
|
||||
require_once('include/Contact.php');
|
||||
|
||||
function profile_change() {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
if(! local_user())
|
||||
return;
|
||||
|
||||
// $url = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
|
||||
// if($url && strlen(get_config('system','directory')))
|
||||
// proc_run('php',"include/directory.php","$url");
|
||||
|
||||
$recips = q("SELECT `id`,`name`,`network`,`pubkey`,`notify` FROM `contact` WHERE `network` = '%s'
|
||||
AND `uid` = %d AND `rel` != %d ",
|
||||
dbesc(NETWORK_DIASPORA),
|
||||
intval(local_user()),
|
||||
intval(CONTACT_IS_SHARING)
|
||||
);
|
||||
if(! count($recips))
|
||||
return;
|
||||
|
||||
$r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `user`.* FROM `profile`
|
||||
INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
|
||||
WHERE `user`.`uid` = %d AND `profile`.`is-default` = 1 LIMIT 1",
|
||||
intval(local_user())
|
||||
);
|
||||
|
||||
if(! count($r))
|
||||
return;
|
||||
$profile = $r[0];
|
||||
|
||||
$handle = xmlify($a->user['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3));
|
||||
$first = xmlify(((strpos($profile['name'],' '))
|
||||
? trim(substr($profile['name'],0,strpos($profile['name'],' '))) : $profile['name']));
|
||||
$last = xmlify((($first === $profile['name']) ? '' : trim(substr($profile['name'],strlen($first)))));
|
||||
$large = xmlify($a->get_baseurl() . '/photo/custom/300/' . $profile['uid'] . '.jpg');
|
||||
$medium = xmlify($a->get_baseurl() . '/photo/custom/100/' . $profile['uid'] . '.jpg');
|
||||
$small = xmlify($a->get_baseurl() . '/photo/custom/50/' . $profile['uid'] . '.jpg');
|
||||
$searchable = xmlify((($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' ));
|
||||
// $searchable = 'true';
|
||||
|
||||
if($searchable === 'true') {
|
||||
$dob = '1000-00-00';
|
||||
|
||||
if(($profile['dob']) && ($profile['dob'] != '0000-00-00'))
|
||||
$dob = ((intval($profile['dob'])) ? intval($profile['dob']) : '1000') . '-' . datetime_convert('UTC','UTC',$profile['dob'],'m-d');
|
||||
$gender = xmlify($profile['gender']);
|
||||
$about = xmlify($profile['about']);
|
||||
require_once('include/bbcode.php');
|
||||
$about = xmlify(strip_tags(bbcode($about)));
|
||||
$location = formatted_location($profile);
|
||||
$location = xmlify($location);
|
||||
$tags = '';
|
||||
if($profile['pub_keywords']) {
|
||||
$kw = str_replace(',',' ',$profile['pub_keywords']);
|
||||
$kw = str_replace(' ',' ',$kw);
|
||||
$arr = explode(' ',$profile['pub_keywords']);
|
||||
if(count($arr)) {
|
||||
for($x = 0; $x < 5; $x ++) {
|
||||
if(trim($arr[$x]))
|
||||
$tags .= '#' . trim($arr[$x]) . ' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
$tags = xmlify(trim($tags));
|
||||
}
|
||||
|
||||
$tpl = get_markup_template('diaspora_profile.tpl');
|
||||
|
||||
$msg = replace_macros($tpl,array(
|
||||
'$handle' => $handle,
|
||||
'$first' => $first,
|
||||
'$last' => $last,
|
||||
'$large' => $large,
|
||||
'$medium' => $medium,
|
||||
'$small' => $small,
|
||||
'$dob' => $dob,
|
||||
'$gender' => $gender,
|
||||
'$about' => $about,
|
||||
'$location' => $location,
|
||||
'$searchable' => $searchable,
|
||||
'$tags' => $tags
|
||||
));
|
||||
logger('profile_change: ' . $msg, LOGGER_ALL);
|
||||
|
||||
foreach($recips as $recip) {
|
||||
$msgtosend = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$a->user,$recip,$a->user['prvkey'],$recip['pubkey'],false)));
|
||||
add_to_queue($recip['id'],NETWORK_DIASPORA,$msgtosend,false);
|
||||
}
|
||||
diaspora::send_profile(local_user());
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ function handle_pubsubhubbub() {
|
|||
|
||||
logger("Generate feed for user ".$rr['nickname']." - last updated ".$rr['last_update'], LOGGER_DEBUG);
|
||||
|
||||
$params = ostatus_feed($a, $rr['nickname'], $rr['last_update']);
|
||||
$params = ostatus::feed($a, $rr['nickname'], $rr['last_update']);
|
||||
$hmac_sig = hash_hmac("sha1", $params, $rr['secret']);
|
||||
|
||||
$headers = array("Content-type: application/atom+xml",
|
||||
|
@ -74,25 +74,14 @@ function pubsubpublish_run(&$argv, &$argc){
|
|||
};
|
||||
|
||||
require_once('include/items.php');
|
||||
require_once('include/pidfile.php');
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
|
||||
$lockpath = get_lockpath();
|
||||
if ($lockpath != '') {
|
||||
$pidfile = new pidfile($lockpath, 'pubsubpublish');
|
||||
if($pidfile->is_already_running()) {
|
||||
logger("Already running");
|
||||
if ($pidfile->running_time() > 9*60) {
|
||||
$pidfile->kill();
|
||||
logger("killed stale process");
|
||||
// Calling a new instance
|
||||
proc_run('php',"include/pubsubpublish.php");
|
||||
}
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run")
|
||||
if (App::is_already_running("pubsubpublish", "include/pubsubpublish.php", 540))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
|
|
|
@ -22,26 +22,15 @@ function queue_run(&$argv, &$argc){
|
|||
require_once("include/datetime.php");
|
||||
require_once('include/items.php');
|
||||
require_once('include/bbcode.php');
|
||||
require_once('include/pidfile.php');
|
||||
require_once('include/socgraph.php');
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
|
||||
$lockpath = get_lockpath();
|
||||
if ($lockpath != '') {
|
||||
$pidfile = new pidfile($lockpath, 'queue');
|
||||
if($pidfile->is_already_running()) {
|
||||
logger("queue: Already running");
|
||||
if ($pidfile->running_time() > 9*60) {
|
||||
$pidfile->kill();
|
||||
logger("queue: killed stale process");
|
||||
// Calling a new instance
|
||||
proc_run('php',"include/queue.php");
|
||||
}
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run")
|
||||
if (App::is_already_running('queue', 'include/queue.php', 540))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
|
@ -204,7 +193,7 @@ function queue_run(&$argv, &$argc){
|
|||
case NETWORK_DIASPORA:
|
||||
if($contact['notify']) {
|
||||
logger('queue: diaspora_delivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
|
||||
$deliver_status = diaspora_transmit($owner,$contact,$data,$public,true);
|
||||
$deliver_status = diaspora::transmit($owner,$contact,$data,$public,true);
|
||||
|
||||
if($deliver_status == (-1)) {
|
||||
update_queue_time($q_item['id']);
|
||||
|
|
|
@ -69,7 +69,6 @@ function ref_session_destroy ($id) {
|
|||
if(! function_exists('ref_session_gc')) {
|
||||
function ref_session_gc($expire) {
|
||||
q("DELETE FROM `session` WHERE `expire` < %d", dbesc(time()));
|
||||
q("OPTIMIZE TABLE `sess_data`");
|
||||
return true;
|
||||
}}
|
||||
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
require_once('include/datetime.php');
|
||||
require_once("include/Scrape.php");
|
||||
require_once("include/html2bbcode.php");
|
||||
|
||||
require_once("include/Contact.php");
|
||||
require_once("include/Photo.php");
|
||||
|
||||
/*
|
||||
* poco_load
|
||||
|
@ -139,15 +140,16 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
|
|||
poco_check($profile_url, $name, $network, $profile_photo, $about, $location, $gender, $keywords, $connect_url, $updated, $generation, $cid, $uid, $zcid);
|
||||
|
||||
// Update the Friendica contacts. Diaspora is doing it via a message. (See include/diaspora.php)
|
||||
if (($location != "") OR ($about != "") OR ($keywords != "") OR ($gender != ""))
|
||||
q("UPDATE `contact` SET `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s'
|
||||
WHERE `nurl` = '%s' AND NOT `self` AND `network` = '%s'",
|
||||
dbesc($location),
|
||||
dbesc($about),
|
||||
dbesc($keywords),
|
||||
dbesc($gender),
|
||||
dbesc(normalise_link($profile_url)),
|
||||
dbesc(NETWORK_DFRN));
|
||||
// Deactivated because we now update Friendica contacts in dfrn.php
|
||||
//if (($location != "") OR ($about != "") OR ($keywords != "") OR ($gender != ""))
|
||||
// q("UPDATE `contact` SET `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s'
|
||||
// WHERE `nurl` = '%s' AND NOT `self` AND `network` = '%s'",
|
||||
// dbesc($location),
|
||||
// dbesc($about),
|
||||
// dbesc($keywords),
|
||||
// dbesc($gender),
|
||||
// dbesc(normalise_link($profile_url)),
|
||||
// dbesc(NETWORK_DFRN));
|
||||
}
|
||||
logger("poco_load: loaded $total entries",LOGGER_DEBUG);
|
||||
|
||||
|
@ -427,7 +429,7 @@ function poco_last_updated($profile, $force = false) {
|
|||
if (($gcontacts[0]["server_url"] != "") AND ($gcontacts[0]["nick"] != "")) {
|
||||
|
||||
// Use noscrape if possible
|
||||
$server = q("SELECT `noscrape` FROM `gserver` WHERE `nurl` = '%s' AND `noscrape` != ''", dbesc(normalise_link($gcontacts[0]["server_url"])));
|
||||
$server = q("SELECT `noscrape`, `network` FROM `gserver` WHERE `nurl` = '%s' AND `noscrape` != ''", dbesc(normalise_link($gcontacts[0]["server_url"])));
|
||||
|
||||
if ($server) {
|
||||
$noscraperet = z_fetch_url($server[0]["noscrape"]."/".$gcontacts[0]["nick"]);
|
||||
|
@ -436,69 +438,47 @@ function poco_last_updated($profile, $force = false) {
|
|||
|
||||
$noscrape = json_decode($noscraperet["body"], true);
|
||||
|
||||
if (($noscrape["fn"] != "") AND ($noscrape["fn"] != $gcontacts[0]["name"]))
|
||||
q("UPDATE `gcontact` SET `name` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc($noscrape["fn"]), dbesc(normalise_link($profile)));
|
||||
if (is_array($noscrape)) {
|
||||
$contact = array("url" => $profile,
|
||||
"network" => $server[0]["network"],
|
||||
"generation" => $gcontacts[0]["generation"]);
|
||||
|
||||
if (($noscrape["photo"] != "") AND ($noscrape["photo"] != $gcontacts[0]["photo"]))
|
||||
q("UPDATE `gcontact` SET `photo` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc($noscrape["photo"]), dbesc(normalise_link($profile)));
|
||||
$contact["name"] = $noscrape["fn"];
|
||||
$contact["community"] = $noscrape["comm"];
|
||||
|
||||
if (($noscrape["updated"] != "") AND ($noscrape["updated"] != $gcontacts[0]["updated"]))
|
||||
q("UPDATE `gcontact` SET `updated` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc($noscrape["updated"]), dbesc(normalise_link($profile)));
|
||||
if (isset($noscrape["tags"])) {
|
||||
$keywords = implode(" ", $noscrape["tags"]);
|
||||
if ($keywords != "")
|
||||
$contact["keywords"] = $keywords;
|
||||
}
|
||||
|
||||
if (($noscrape["gender"] != "") AND ($noscrape["gender"] != $gcontacts[0]["gender"]))
|
||||
q("UPDATE `gcontact` SET `gender` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc($noscrape["gender"]), dbesc(normalise_link($profile)));
|
||||
$location = formatted_location($noscrape);
|
||||
if ($location)
|
||||
$contact["location"] = $location;
|
||||
|
||||
if (($noscrape["pdesc"] != "") AND ($noscrape["pdesc"] != $gcontacts[0]["about"]))
|
||||
q("UPDATE `gcontact` SET `about` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc($noscrape["pdesc"]), dbesc(normalise_link($profile)));
|
||||
$contact["notify"] = $noscrape["dfrn-notify"];
|
||||
|
||||
if (($noscrape["about"] != "") AND ($noscrape["about"] != $gcontacts[0]["about"]))
|
||||
q("UPDATE `gcontact` SET `about` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc($noscrape["about"]), dbesc(normalise_link($profile)));
|
||||
// Remove all fields that are not present in the gcontact table
|
||||
unset($noscrape["fn"]);
|
||||
unset($noscrape["key"]);
|
||||
unset($noscrape["homepage"]);
|
||||
unset($noscrape["comm"]);
|
||||
unset($noscrape["tags"]);
|
||||
unset($noscrape["locality"]);
|
||||
unset($noscrape["region"]);
|
||||
unset($noscrape["country-name"]);
|
||||
unset($noscrape["contacts"]);
|
||||
unset($noscrape["dfrn-request"]);
|
||||
unset($noscrape["dfrn-confirm"]);
|
||||
unset($noscrape["dfrn-notify"]);
|
||||
unset($noscrape["dfrn-poll"]);
|
||||
|
||||
if (isset($noscrape["comm"]) AND ($noscrape["comm"] != $gcontacts[0]["community"]))
|
||||
q("UPDATE `gcontact` SET `community` = %d WHERE `nurl` = '%s'",
|
||||
intval($noscrape["comm"]), dbesc(normalise_link($profile)));
|
||||
$contact = array_merge($contact, $noscrape);
|
||||
|
||||
if (isset($noscrape["tags"]))
|
||||
$keywords = implode(" ", $noscrape["tags"]);
|
||||
else
|
||||
$keywords = "";
|
||||
update_gcontact($contact);
|
||||
|
||||
if (($keywords != "") AND ($keywords != $gcontacts[0]["keywords"]))
|
||||
q("UPDATE `gcontact` SET `keywords` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc($keywords), dbesc(normalise_link($profile)));
|
||||
|
||||
$location = $noscrape["locality"];
|
||||
|
||||
if ($noscrape["region"] != "") {
|
||||
if ($location != "")
|
||||
$location .= ", ";
|
||||
|
||||
$location .= $noscrape["region"];
|
||||
return $noscrape["updated"];
|
||||
}
|
||||
|
||||
if ($noscrape["country-name"] != "") {
|
||||
if ($location != "")
|
||||
$location .= ", ";
|
||||
|
||||
$location .= $noscrape["country-name"];
|
||||
}
|
||||
|
||||
if (($location != "") AND ($location != $gcontacts[0]["location"]))
|
||||
q("UPDATE `gcontact` SET `location` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc($location), dbesc(normalise_link($profile)));
|
||||
|
||||
// If we got data from noscrape then mark the contact as reachable
|
||||
if (is_array($noscrape) AND count($noscrape))
|
||||
q("UPDATE `gcontact` SET `last_contact` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc(datetime_convert()), dbesc(normalise_link($profile)));
|
||||
|
||||
return $noscrape["updated"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -533,25 +513,22 @@ function poco_last_updated($profile, $force = false) {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (($data["name"] != "") AND ($data["name"] != $gcontacts[0]["name"]))
|
||||
q("UPDATE `gcontact` SET `name` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc($data["name"]), dbesc(normalise_link($profile)));
|
||||
$contact = array("generation" => $gcontacts[0]["generation"]);
|
||||
|
||||
if (($data["nick"] != "") AND ($data["nick"] != $gcontacts[0]["nick"]))
|
||||
q("UPDATE `gcontact` SET `nick` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc($data["nick"]), dbesc(normalise_link($profile)));
|
||||
$contact = array_merge($contact, $data);
|
||||
|
||||
if (($data["addr"] != "") AND ($data["addr"] != $gcontacts[0]["connect"]))
|
||||
q("UPDATE `gcontact` SET `connect` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc($data["addr"]), dbesc(normalise_link($profile)));
|
||||
$contact["server_url"] = $data["baseurl"];
|
||||
|
||||
if (($data["photo"] != "") AND ($data["photo"] != $gcontacts[0]["photo"]))
|
||||
q("UPDATE `gcontact` SET `photo` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc($data["photo"]), dbesc(normalise_link($profile)));
|
||||
unset($contact["batch"]);
|
||||
unset($contact["poll"]);
|
||||
unset($contact["request"]);
|
||||
unset($contact["confirm"]);
|
||||
unset($contact["poco"]);
|
||||
unset($contact["priority"]);
|
||||
unset($contact["pubkey"]);
|
||||
unset($contact["baseurl"]);
|
||||
|
||||
if (($data["baseurl"] != "") AND ($data["baseurl"] != $gcontacts[0]["server_url"]))
|
||||
q("UPDATE `gcontact` SET `server_url` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc($data["baseurl"]), dbesc(normalise_link($profile)));
|
||||
update_gcontact($contact);
|
||||
|
||||
$feedret = z_fetch_url($data["poll"]);
|
||||
|
||||
|
@ -745,7 +722,8 @@ function poco_check_server($server_url, $network = "", $force = false) {
|
|||
// Will also return data for Friendica and GNU Social - but it will be overwritten later
|
||||
// The "not implemented" is a special treatment for really, really old Friendica versions
|
||||
$serverret = z_fetch_url($server_url."/api/statusnet/version.json");
|
||||
if ($serverret["success"] AND ($serverret["body"] != '{"error":"not implemented"}') AND ($serverret["body"] != '') AND (strlen($serverret["body"]) < 250)) {
|
||||
if ($serverret["success"] AND ($serverret["body"] != '{"error":"not implemented"}') AND
|
||||
($serverret["body"] != '') AND (strlen($serverret["body"]) < 30)) {
|
||||
$platform = "StatusNet";
|
||||
$version = trim($serverret["body"], '"');
|
||||
$network = NETWORK_OSTATUS;
|
||||
|
@ -753,7 +731,8 @@ function poco_check_server($server_url, $network = "", $force = false) {
|
|||
|
||||
// Test for GNU Social
|
||||
$serverret = z_fetch_url($server_url."/api/gnusocial/version.json");
|
||||
if ($serverret["success"] AND ($serverret["body"] != '{"error":"not implemented"}') AND ($serverret["body"] != '') AND (strlen($serverret["body"]) < 250)) {
|
||||
if ($serverret["success"] AND ($serverret["body"] != '{"error":"not implemented"}') AND
|
||||
($serverret["body"] != '') AND (strlen($serverret["body"]) < 30)) {
|
||||
$platform = "GNU Social";
|
||||
$version = trim($serverret["body"], '"');
|
||||
$network = NETWORK_OSTATUS;
|
||||
|
@ -880,6 +859,11 @@ function poco_check_server($server_url, $network = "", $force = false) {
|
|||
// Check again if the server exists
|
||||
$servers = q("SELECT `nurl` FROM `gserver` WHERE `nurl` = '%s'", dbesc(normalise_link($server_url)));
|
||||
|
||||
$version = strip_tags($version);
|
||||
$site_name = strip_tags($site_name);
|
||||
$info = strip_tags($info);
|
||||
$platform = strip_tags($platform);
|
||||
|
||||
if ($servers)
|
||||
q("UPDATE `gserver` SET `url` = '%s', `version` = '%s', `site_name` = '%s', `info` = '%s', `register_policy` = %d, `poco` = '%s', `noscrape` = '%s',
|
||||
`network` = '%s', `platform` = '%s', `last_contact` = '%s', `last_failure` = '%s' WHERE `nurl` = '%s'",
|
||||
|
@ -920,88 +904,6 @@ function poco_check_server($server_url, $network = "", $force = false) {
|
|||
return !$failure;
|
||||
}
|
||||
|
||||
function poco_contact_from_body($body, $created, $cid, $uid) {
|
||||
preg_replace_callback("/\[share(.*?)\].*?\[\/share\]/ism",
|
||||
function ($match) use ($created, $cid, $uid){
|
||||
return(sub_poco_from_share($match, $created, $cid, $uid));
|
||||
}, $body);
|
||||
}
|
||||
|
||||
function sub_poco_from_share($share, $created, $cid, $uid) {
|
||||
$profile = "";
|
||||
preg_match("/profile='(.*?)'/ism", $share[1], $matches);
|
||||
if ($matches[1] != "")
|
||||
$profile = $matches[1];
|
||||
|
||||
preg_match('/profile="(.*?)"/ism', $share[1], $matches);
|
||||
if ($matches[1] != "")
|
||||
$profile = $matches[1];
|
||||
|
||||
if ($profile == "")
|
||||
return;
|
||||
|
||||
logger("prepare poco_check for profile ".$profile, LOGGER_DEBUG);
|
||||
poco_check($profile, "", "", "", "", "", "", "", "", $created, 3, $cid, $uid);
|
||||
}
|
||||
|
||||
function poco_store($item) {
|
||||
|
||||
// Isn't it public?
|
||||
if ($item['private'])
|
||||
return;
|
||||
|
||||
// Or is it from a network where we don't store the global contacts?
|
||||
if (!in_array($item["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, NETWORK_STATUSNET, "")))
|
||||
return;
|
||||
|
||||
// Is it a global copy?
|
||||
$store_gcontact = ($item["uid"] == 0);
|
||||
|
||||
// Is it a comment on a global copy?
|
||||
if (!$store_gcontact AND ($item["uri"] != $item["parent-uri"])) {
|
||||
$q = q("SELECT `id` FROM `item` WHERE `uri`='%s' AND `uid` = 0", $item["parent-uri"]);
|
||||
$store_gcontact = count($q);
|
||||
}
|
||||
|
||||
if (!$store_gcontact)
|
||||
return;
|
||||
|
||||
// "3" means: We don't know this contact directly (Maybe a reshared item)
|
||||
$generation = 3;
|
||||
$network = "";
|
||||
$profile_url = $item["author-link"];
|
||||
|
||||
// Is it a user from our server?
|
||||
$q = q("SELECT `id` FROM `contact` WHERE `self` AND `nurl` = '%s' LIMIT 1",
|
||||
dbesc(normalise_link($item["author-link"])));
|
||||
if (count($q)) {
|
||||
logger("Our user (generation 1): ".$item["author-link"], LOGGER_DEBUG);
|
||||
$generation = 1;
|
||||
$network = NETWORK_DFRN;
|
||||
} else { // Is it a contact from a user on our server?
|
||||
$q = q("SELECT `network`, `url` FROM `contact` WHERE `uid` != 0 AND `network` != ''
|
||||
AND (`nurl` = '%s' OR `alias` IN ('%s', '%s')) AND `network` != '%s' LIMIT 1",
|
||||
dbesc(normalise_link($item["author-link"])),
|
||||
dbesc(normalise_link($item["author-link"])),
|
||||
dbesc($item["author-link"]),
|
||||
dbesc(NETWORK_STATUSNET));
|
||||
if (count($q)) {
|
||||
$generation = 2;
|
||||
$network = $q[0]["network"];
|
||||
$profile_url = $q[0]["url"];
|
||||
logger("Known contact (generation 2): ".$profile_url, LOGGER_DEBUG);
|
||||
}
|
||||
}
|
||||
|
||||
if ($generation == 3)
|
||||
logger("Unknown contact (generation 3): ".$item["author-link"], LOGGER_DEBUG);
|
||||
|
||||
poco_check($profile_url, $item["author-name"], $network, $item["author-avatar"], "", "", "", "", "", $item["received"], $generation, $item["contact-id"], $item["uid"]);
|
||||
|
||||
// Maybe its a body with a shared item? Then extract a global contact from it.
|
||||
poco_contact_from_body($item["body"], $item["received"], $item["contact-id"], $item["uid"]);
|
||||
}
|
||||
|
||||
function count_common_friends($uid,$cid) {
|
||||
|
||||
$r = q("SELECT count(*) as `total`
|
||||
|
@ -1530,9 +1432,17 @@ function update_gcontact($contact) {
|
|||
unset($fields["url"]);
|
||||
unset($fields["updated"]);
|
||||
|
||||
// Bugfix: We had an error in the storing of keywords which lead to the "0"
|
||||
// This value is still transmitted via poco.
|
||||
if ($contact["keywords"] == "0")
|
||||
unset($contact["keywords"]);
|
||||
|
||||
if ($r[0]["keywords"] == "0")
|
||||
$r[0]["keywords"] = "";
|
||||
|
||||
// assign all unassigned fields from the database entry
|
||||
foreach ($fields AS $field => $data)
|
||||
if (!isset($contact[$field]))
|
||||
if (!isset($contact[$field]) OR ($contact[$field] == ""))
|
||||
$contact[$field] = $r[0][$field];
|
||||
|
||||
if ($contact["network"] == NETWORK_STATUSNET)
|
||||
|
@ -1541,20 +1451,50 @@ function update_gcontact($contact) {
|
|||
if (!isset($contact["updated"]))
|
||||
$contact["updated"] = datetime_convert();
|
||||
|
||||
if ($contact["server_url"] == "") {
|
||||
$server_url = $contact["url"];
|
||||
|
||||
$server_url = matching_url($server_url, $contact["alias"]);
|
||||
if ($server_url != "")
|
||||
$contact["server_url"] = $server_url;
|
||||
|
||||
$server_url = matching_url($server_url, $contact["photo"]);
|
||||
if ($server_url != "")
|
||||
$contact["server_url"] = $server_url;
|
||||
|
||||
$server_url = matching_url($server_url, $contact["notify"]);
|
||||
if ($server_url != "")
|
||||
$contact["server_url"] = $server_url;
|
||||
} else
|
||||
$contact["server_url"] = normalise_link($contact["server_url"]);
|
||||
|
||||
if (($contact["addr"] == "") AND ($contact["server_url"] != "") AND ($contact["nick"] != "")) {
|
||||
$hostname = str_replace("http://", "", $contact["server_url"]);
|
||||
$contact["addr"] = $contact["nick"]."@".$hostname;
|
||||
}
|
||||
|
||||
// Check if any field changed
|
||||
$update = false;
|
||||
unset($fields["generation"]);
|
||||
|
||||
foreach ($fields AS $field => $data)
|
||||
if ($contact[$field] != $r[0][$field])
|
||||
$update = true;
|
||||
if ((($contact["generation"] > 0) AND ($contact["generation"] <= $r[0]["generation"])) OR ($r[0]["generation"] == 0)) {
|
||||
foreach ($fields AS $field => $data)
|
||||
if ($contact[$field] != $r[0][$field]) {
|
||||
logger("Difference for contact ".$contact["url"]." in field '".$field."'. New value: '".$contact[$field]."', old value '".$r[0][$field]."'", LOGGER_DEBUG);
|
||||
$update = true;
|
||||
}
|
||||
|
||||
if ($contact["generation"] < $r[0]["generation"])
|
||||
$update = true;
|
||||
if ($contact["generation"] < $r[0]["generation"]) {
|
||||
logger("Difference for contact ".$contact["url"]." in field 'generation'. new value: '".$contact["generation"]."', old value '".$r[0]["generation"]."'", LOGGER_DEBUG);
|
||||
$update = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($update) {
|
||||
logger("Update gcontact for ".$contact["url"]." Callstack: ".App::callstack(), LOGGER_DEBUG);
|
||||
|
||||
q("UPDATE `gcontact` SET `photo` = '%s', `name` = '%s', `nick` = '%s', `addr` = '%s', `network` = '%s',
|
||||
`birthday` = '%s', `gender` = '%s', `keywords` = %d, `hide` = %d, `nsfw` = %d,
|
||||
`birthday` = '%s', `gender` = '%s', `keywords` = '%s', `hide` = %d, `nsfw` = %d,
|
||||
`alias` = '%s', `notify` = '%s', `url` = '%s',
|
||||
`location` = '%s', `about` = '%s', `generation` = %d, `updated` = '%s',
|
||||
`server_url` = '%s', `connect` = '%s'
|
||||
|
@ -1567,6 +1507,28 @@ function update_gcontact($contact) {
|
|||
intval($contact["generation"]), dbesc($contact["updated"]),
|
||||
dbesc($contact["server_url"]), dbesc($contact["connect"]),
|
||||
dbesc(normalise_link($contact["url"])), intval($contact["generation"]));
|
||||
|
||||
|
||||
// Now update the contact entry with the user id "0" as well.
|
||||
// This is used for the shadow copies of public items.
|
||||
$r = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = 0 ORDER BY `id` LIMIT 1",
|
||||
dbesc(normalise_link($contact["url"])));
|
||||
|
||||
if ($r) {
|
||||
logger("Update shadow contact ".$r[0]["id"], LOGGER_DEBUG);
|
||||
|
||||
update_contact_avatar($contact["photo"], 0, $r[0]["id"]);
|
||||
|
||||
q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `addr` = '%s',
|
||||
`network` = '%s', `bd` = '%s', `gender` = '%s',
|
||||
`keywords` = '%s', `alias` = '%s', `url` = '%s',
|
||||
`location` = '%s', `about` = '%s'
|
||||
WHERE `id` = %d",
|
||||
dbesc($contact["name"]), dbesc($contact["nick"]), dbesc($contact["addr"]),
|
||||
dbesc($contact["network"]), dbesc($contact["birthday"]), dbesc($contact["gender"]),
|
||||
dbesc($contact["keywords"]), dbesc($contact["alias"]), dbesc($contact["url"]),
|
||||
dbesc($contact["location"]), dbesc($contact["about"]), intval($r[0]["id"]));
|
||||
}
|
||||
}
|
||||
|
||||
return $gcontact_id;
|
||||
|
@ -1580,8 +1542,10 @@ function update_gcontact($contact) {
|
|||
function update_gcontact_from_probe($url) {
|
||||
$data = probe_url($url);
|
||||
|
||||
if ($data["network"] != NETWORK_PHANTOM)
|
||||
update_gcontact($data);
|
||||
if ($data["network"] == NETWORK_PHANTOM)
|
||||
return;
|
||||
|
||||
update_gcontact($data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,7 +23,7 @@ function replace_macros($s,$r) {
|
|||
$a = get_app();
|
||||
|
||||
// pass $baseurl to all templates
|
||||
$r['$baseurl'] = z_root();
|
||||
$r['$baseurl'] = $a->get_baseurl();
|
||||
|
||||
|
||||
$t = $a->template_engine();
|
||||
|
@ -286,7 +286,7 @@ function paginate_data(&$a, $count=null) {
|
|||
if (($a->page_offset != "") AND !preg_match('/[?&].offset=/', $stripped))
|
||||
$stripped .= "&offset=".urlencode($a->page_offset);
|
||||
|
||||
$url = z_root() . '/' . $stripped;
|
||||
$url = $stripped;
|
||||
|
||||
$data = array();
|
||||
function _l(&$d, $name, $url, $text, $class="") {
|
||||
|
@ -924,7 +924,7 @@ function micropro($contact, $redirect = false, $class = '', $textmode = false) {
|
|||
|
||||
if($redirect) {
|
||||
$a = get_app();
|
||||
$redirect_url = z_root() . '/redir/' . $contact['id'];
|
||||
$redirect_url = 'redir/' . $contact['id'];
|
||||
if(local_user() && ($contact['uid'] == local_user()) && ($contact['network'] === NETWORK_DFRN)) {
|
||||
$redir = true;
|
||||
$url = $redirect_url;
|
||||
|
@ -965,13 +965,13 @@ if(! function_exists('search')) {
|
|||
* @param string $url search url
|
||||
* @param boolean $savedsearch show save search button
|
||||
*/
|
||||
function search($s,$id='search-box',$url='/search',$save = false, $aside = true) {
|
||||
function search($s,$id='search-box',$url='search',$save = false, $aside = true) {
|
||||
$a = get_app();
|
||||
|
||||
$values = array(
|
||||
'$s' => $s,
|
||||
'$id' => $id,
|
||||
'$action_url' => $a->get_baseurl((stristr($url,'network')) ? true : false) . $url,
|
||||
'$action_url' => $url,
|
||||
'$search_label' => t('Search'),
|
||||
'$save_label' => t('Save'),
|
||||
'$savedsearch' => feature_enabled(local_user(),'savedsearch'),
|
||||
|
@ -1152,7 +1152,7 @@ function redir_private_images($a, &$item) {
|
|||
|
||||
if((local_user() == $item['uid']) && ($item['private'] != 0) && ($item['contact-id'] != $a->contact['id']) && ($item['network'] == NETWORK_DFRN)) {
|
||||
//logger("redir_private_images: redir");
|
||||
$img_url = z_root() . '/redir?f=1&quiet=1&url=' . $mtch[1] . '&conurl=' . $item['author-link'];
|
||||
$img_url = 'redir?f=1&quiet=1&url=' . $mtch[1] . '&conurl=' . $item['author-link'];
|
||||
$item['body'] = str_replace($mtch[0], "[img]".$img_url."[/img]", $item['body']);
|
||||
}
|
||||
}
|
||||
|
@ -1268,7 +1268,7 @@ function prepare_body(&$item,$attach = false, $preview = false) {
|
|||
$mime = $mtch[3];
|
||||
|
||||
if((local_user() == $item['uid']) && ($item['contact-id'] != $a->contact['id']) && ($item['network'] == NETWORK_DFRN))
|
||||
$the_url = z_root() . '/redir/' . $item['contact-id'] . '?f=1&url=' . $mtch[1];
|
||||
$the_url = 'redir/' . $item['contact-id'] . '?f=1&url=' . $mtch[1];
|
||||
else
|
||||
$the_url = $mtch[1];
|
||||
|
||||
|
@ -1443,7 +1443,7 @@ function get_cats_and_terms($item) {
|
|||
$categories[] = array(
|
||||
'name' => xmlify(file_tag_decode($mtch[1])),
|
||||
'url' => "#",
|
||||
'removeurl' => ((local_user() == $item['uid'])?z_root() . '/filerm/' . $item['id'] . '?f=&cat=' . xmlify(file_tag_decode($mtch[1])):""),
|
||||
'removeurl' => ((local_user() == $item['uid'])?'filerm/' . $item['id'] . '?f=&cat=' . xmlify(file_tag_decode($mtch[1])):""),
|
||||
'first' => $first,
|
||||
'last' => false
|
||||
);
|
||||
|
@ -1461,7 +1461,7 @@ function get_cats_and_terms($item) {
|
|||
$folders[] = array(
|
||||
'name' => xmlify(file_tag_decode($mtch[1])),
|
||||
'url' => "#",
|
||||
'removeurl' => ((local_user() == $item['uid'])?z_root() . '/filerm/' . $item['id'] . '?f=&term=' . xmlify(file_tag_decode($mtch[1])):""),
|
||||
'removeurl' => ((local_user() == $item['uid'])?'filerm/' . $item['id'] . '?f=&term=' . xmlify(file_tag_decode($mtch[1])):""),
|
||||
'first' => $first,
|
||||
'last' => false
|
||||
);
|
||||
|
@ -1486,15 +1486,15 @@ function get_plink($item) {
|
|||
|
||||
if ($a->user['nickname'] != "") {
|
||||
$ret = array(
|
||||
//'href' => z_root()."/display/".$a->user['nickname']."/".$item['id'],
|
||||
'href' => z_root()."/display/".$item['guid'],
|
||||
'orig' => z_root()."/display/".$item['guid'],
|
||||
//'href' => "display/".$a->user['nickname']."/".$item['id'],
|
||||
'href' => "display/".$item['guid'],
|
||||
'orig' => "display/".$item['guid'],
|
||||
'title' => t('View on separate page'),
|
||||
'orig_title' => t('view on separate page'),
|
||||
);
|
||||
|
||||
if (x($item,'plink')) {
|
||||
$ret["href"] = $item['plink'];
|
||||
$ret["href"] = $a->remove_baseurl($item['plink']);
|
||||
$ret["title"] = t('link to source');
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ function update_gcontact_run(&$argv, &$argc){
|
|||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
};
|
||||
|
||||
require_once('include/pidfile.php');
|
||||
require_once('include/Scrape.php');
|
||||
require_once("include/socgraph.php");
|
||||
|
||||
|
@ -37,18 +36,10 @@ function update_gcontact_run(&$argv, &$argc){
|
|||
return;
|
||||
}
|
||||
|
||||
$lockpath = get_lockpath();
|
||||
if ($lockpath != '') {
|
||||
$pidfile = new pidfile($lockpath, 'update_gcontact'.$contact_id);
|
||||
if ($pidfile->is_already_running()) {
|
||||
logger("update_gcontact: Already running for contact ".$contact_id);
|
||||
if ($pidfile->running_time() > 9*60) {
|
||||
$pidfile->kill();
|
||||
logger("killed stale process");
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run")
|
||||
if (App::is_already_running('update_gcontact'.$contact_id, '', 540))
|
||||
return;
|
||||
|
||||
$r = q("SELECT * FROM `gcontact` WHERE `id` = %d", intval($contact_id));
|
||||
|
||||
|
|
131
include/xml.php
Normal file
131
include/xml.php
Normal file
|
@ -0,0 +1,131 @@
|
|||
<?php
|
||||
/**
|
||||
* @file include/xml.php
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief This class contain functions to work with XML data
|
||||
*
|
||||
*/
|
||||
class xml {
|
||||
/**
|
||||
* @brief Creates an XML structure out of a given array
|
||||
*
|
||||
* @param array $array The array of the XML structure that will be generated
|
||||
* @param object $xml The createdXML will be returned by reference
|
||||
* @param bool $remove_header Should the XML header be removed or not?
|
||||
* @param array $namespaces List of namespaces
|
||||
* @param bool $root - interally used parameter. Mustn't be used from outside.
|
||||
*
|
||||
* @return string The created XML
|
||||
*/
|
||||
public static function from_array($array, &$xml, $remove_header = false, $namespaces = array(), $root = true) {
|
||||
|
||||
if ($root) {
|
||||
foreach($array as $key => $value) {
|
||||
foreach ($namespaces AS $nskey => $nsvalue)
|
||||
$key .= " xmlns".($nskey == "" ? "":":").$nskey.'="'.$nsvalue.'"';
|
||||
|
||||
$root = new SimpleXMLElement("<".$key."/>");
|
||||
self::from_array($value, $root, $remove_header, $namespaces, false);
|
||||
|
||||
$dom = dom_import_simplexml($root)->ownerDocument;
|
||||
$dom->formatOutput = true;
|
||||
$xml = $dom;
|
||||
|
||||
$xml_text = $dom->saveXML();
|
||||
|
||||
if ($remove_header)
|
||||
$xml_text = trim(substr($xml_text, 21));
|
||||
|
||||
return $xml_text;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($array as $key => $value) {
|
||||
if ($key == "@attributes") {
|
||||
if (!isset($element) OR !is_array($value))
|
||||
continue;
|
||||
|
||||
foreach ($value as $attr_key => $attr_value) {
|
||||
$element_parts = explode(":", $attr_key);
|
||||
if ((count($element_parts) > 1) AND isset($namespaces[$element_parts[0]]))
|
||||
$namespace = $namespaces[$element_parts[0]];
|
||||
else
|
||||
$namespace = NULL;
|
||||
|
||||
$element->addAttribute ($attr_key, $attr_value, $namespace);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$element_parts = explode(":", $key);
|
||||
if ((count($element_parts) > 1) AND isset($namespaces[$element_parts[0]]))
|
||||
$namespace = $namespaces[$element_parts[0]];
|
||||
else
|
||||
$namespace = NULL;
|
||||
|
||||
if (!is_array($value))
|
||||
$element = $xml->addChild($key, xmlify($value), $namespace);
|
||||
elseif (is_array($value)) {
|
||||
$element = $xml->addChild($key, NULL, $namespace);
|
||||
self::from_array($value, $element, $remove_header, $namespaces, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Copies an XML object
|
||||
*
|
||||
* @param object $source The XML source
|
||||
* @param object $target The XML target
|
||||
* @param string $elementname Name of the XML element of the target
|
||||
*/
|
||||
public static function copy(&$source, &$target, $elementname) {
|
||||
if (count($source->children()) == 0)
|
||||
$target->addChild($elementname, xmlify($source));
|
||||
else {
|
||||
$child = $target->addChild($elementname);
|
||||
foreach ($source->children() AS $childfield => $childentry)
|
||||
self::copy($childentry, $child, $childfield);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Create an XML element
|
||||
*
|
||||
* @param object $doc XML root
|
||||
* @param string $element XML element name
|
||||
* @param string $value XML value
|
||||
* @param array $attributes array containing the attributes
|
||||
*
|
||||
* @return object XML element object
|
||||
*/
|
||||
public static function create_element($doc, $element, $value = "", $attributes = array()) {
|
||||
$element = $doc->createElement($element, xmlify($value));
|
||||
|
||||
foreach ($attributes AS $key => $value) {
|
||||
$attribute = $doc->createAttribute($key);
|
||||
$attribute->value = xmlify($value);
|
||||
$element->appendChild($attribute);
|
||||
}
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Create an XML and append it to the parent object
|
||||
*
|
||||
* @param object $doc XML root
|
||||
* @param object $parent parent object
|
||||
* @param string $element XML element name
|
||||
* @param string $value XML value
|
||||
* @param array $attributes array containing the attributes
|
||||
*/
|
||||
public static function add_element($doc, $parent, $element, $value = "", $attributes = array()) {
|
||||
$element = self::create_element($doc, $element, $value, $attributes);
|
||||
$parent->appendChild($element);
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue