require_once 'include/items.php';
require_once 'mod/share.php';
require_once 'include/enotify.php';
-require_once 'include/follow.php';
require_once 'include/api.php';
require_once 'mod/proxy.php';
$found = false;
if ($aliaslink != '') {
- $condition = array("`uid` = ? AND `alias` = ? AND `network` != ?",
- $importer["uid"], $aliaslink, NETWORK_STATUSNET);
- $r = dba::select('contact', array(), $condition, array('limit' => 1));
+ $condition = ["`uid` = ? AND `alias` = ? AND `network` != ?",
+ $importer["uid"], $aliaslink, NETWORK_STATUSNET];
+ $r = dba::selectFirst('contact', [], $condition);
if (DBM::is_result($r)) {
$found = true;
$aliaslink = $author["author-link"];
}
- $condition = array("`uid` = ? AND `nurl` IN (?, ?) AND `network` != ?", $importer["uid"],
- normalise_link($author["author-link"]), normalise_link($aliaslink), NETWORK_STATUSNET);
- $r = dba::select('contact', array(), $condition, array('limit' => 1));
+ $condition = ["`uid` = ? AND `nurl` IN (?, ?) AND `network` != ?", $importer["uid"],
+ normalise_link($author["author-link"]), normalise_link($aliaslink), NETWORK_STATUSNET];
+ $r = dba::selectFirst('contact', [], $condition);
if (DBM::is_result($r)) {
$found = true;
}
if (!$found && ($addr != "")) {
- $condition = array("`uid` = ? AND `addr` = ? AND `network` != ?",
- $importer["uid"], $addr, NETWORK_STATUSNET);
- $r = dba::select('contact', array(), $condition, array('limit' => 1));
+ $condition = ["`uid` = ? AND `addr` = ? AND `network` != ?",
+ $importer["uid"], $addr, NETWORK_STATUSNET];
+ $r = dba::selectFirst('contact', [], $condition);
if (DBM::is_result($r)) {
$found = true;
$cid = Contact::getIdForURL($aliaslink, 0);
if ($cid) {
- $fields = array('url', 'nurl', 'name', 'nick', 'alias', 'about', 'location');
- $old_contact = dba::select('contact', $fields, array('id' => $cid), array('limit' => 1));
+ $fields = ['url', 'nurl', 'name', 'nick', 'alias', 'about', 'location'];
+ $old_contact = dba::selectFirst('contact', $fields, ['id' => $cid]);
// Update it with the current values
$fields = array('url' => $author["author-link"], 'name' => $contact["name"],
*/
private static function deleteNotice($item)
{
- $condition = array('uid' => $item['uid'], 'author-link' => $item['author-link'], 'uri' => $item['uri']);
- $deleted = dba::select('item', array('id', 'parent-uri'), $condition, array('limit' => 1));
+ $condition = ['uid' => $item['uid'], 'author-link' => $item['author-link'], 'uri' => $item['uri']];
+ $deleted = dba::selectFirst('item', ['id', 'parent-uri'], $condition);
if (!DBM::is_result($deleted)) {
logger('Item from '.$item['author-link'].' with uri '.$item['uri'].' for user '.$item['uid']." wasn't found. We don't delete it. ");
return;
*/
private static function fetchRelated($related, $related_uri, $importer)
{
- $condition = array('`item-uri` = ? AND `protocol` IN (?, ?)', $related_uri, PROTOCOL_DFRN, PROTOCOL_OSTATUS_SALMON);
- $conversation = dba::select('conversation', array('source', 'protocol'), $condition, array('limit' => 1));
+ $condition = ['`item-uri` = ? AND `protocol` IN (?, ?)', $related_uri, PROTOCOL_DFRN, PROTOCOL_OSTATUS_SALMON];
+ $conversation = dba::selectFirst('conversation', ['source', 'protocol'], $condition);
if (DBM::is_result($conversation)) {
$stored = true;
$xml = $conversation['source'];
// Finally we take the data that we fetched from "ostatus:conversation"
if ($xml == '') {
- $condition = array('item-uri' => $related_uri, 'protocol' => PROTOCOL_SPLITTED_CONV);
- $conversation = dba::select('conversation', array('source'), $condition, array('limit' => 1));
+ $condition = ['item-uri' => $related_uri, 'protocol' => PROTOCOL_SPLITTED_CONV];
+ $conversation = dba::selectFirst('conversation', ['source'], $condition);
if (DBM::is_result($conversation)) {
$stored = true;
logger('Got cached XML from conversation for URI '.$related_uri, LOGGER_DEBUG);
/**
* @brief Adds the header elements to the XML document
*
- * @param object $doc XML document
- * @param array $owner Contact data of the poster
+ * @param object $doc XML document
+ * @param array $owner Contact data of the poster
+ * @param string $filter The related feed filter (activity, posts or comments)
*
* @return object header root element
*/
- private static function addHeader($doc, $owner, $type)
+ private static function addHeader($doc, $owner, $filter)
{
$a = get_app();
$root->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
$root->setAttribute("xmlns:mastodon", NAMESPACE_MASTODON);
- switch ($type) {
+ switch ($filter) {
case 'activity': $title = t('%s\'s timeline', $owner['name']); break;
case 'posts' : $title = t('%s\'s posts' , $owner['name']); break;
case 'comments': $title = t('%s\'s comments', $owner['name']); break;
* @param string $owner_nick Nickname of the feed owner
* @param string $last_update Date of the last update
* @param integer $max_items Number of maximum items to fetch
- * @param string $type Type of feed (posts, comments or activity)
- * @param boolean $nocache Wether to bypass the cache
+ * @param string $filter Feed items filter (activity, posts or comments)
+ * @param boolean $nocache Wether to bypass caching
*
* @return string XML feed
*/
- public static function feed($owner_nick, &$last_update, $max_items = 300, $type = 'activity', $nocache = false)
+ public static function feed($owner_nick, &$last_update, $max_items = 300, $filter = 'activity', $nocache = false)
{
$stamp = microtime(true);
- $cachekey = "ostatus:feed:" . $owner_nick . ":" . $type . ":" . $last_update;
+ $cachekey = "ostatus:feed:" . $owner_nick . ":" . $filter . ":" . $last_update;
$previous_created = $last_update;
$result = Cache::get($cachekey);
if (!$nocache && !is_null($result)) {
- logger('Feed duration: ' . number_format(microtime(true) - $stamp, 3) . ' - ' . $owner_nick . ' - ' . $type . ' - ' . $previous_created . ' (cached)', LOGGER_DEBUG);
+ logger('Feed duration: ' . number_format(microtime(true) - $stamp, 3) . ' - ' . $owner_nick . ' - ' . $filter . ' - ' . $previous_created . ' (cached)', LOGGER_DEBUG);
$last_update = $result['last_update'];
return $result['feed'];
}
$authorid = Contact::getIdForURL($owner["url"], 0);
$sql_extra = '';
- if ($type === 'posts') {
+ if ($filter === 'posts') {
$sql_extra .= ' AND `item`.`id` = `item`.`parent` ';
}
- if ($type === 'comments') {
+ if ($filter === 'comments') {
$sql_extra .= sprintf(" AND `item`.`object-type` = '%s' ", dbesc(ACTIVITY_OBJ_COMMENT));
}
$doc = new DOMDocument('1.0', 'utf-8');
$doc->formatOutput = true;
- $root = self::addHeader($doc, $owner, $type);
+ $root = self::addHeader($doc, $owner, $filter);
foreach ($items as $item) {
if (Config::get('system', 'ostatus_debug')) {
$msg = array('feed' => $feeddata, 'last_update' => $last_update);
Cache::set($cachekey, $msg, CACHE_QUARTER_HOUR);
- logger('Feed duration: ' . number_format(microtime(true) - $stamp, 3) . ' - ' . $owner_nick . ' - ' . $type . ' - ' . $previous_created, LOGGER_DEBUG);
+ logger('Feed duration: ' . number_format(microtime(true) - $stamp, 3) . ' - ' . $owner_nick . ' - ' . $filter . ' - ' . $previous_created, LOGGER_DEBUG);
return $feeddata;
}