Merge branch '1.8RC'
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
<?php /** @file */
|
||||
|
||||
if(class_exists('BaseObject'))
|
||||
return;
|
||||
|
||||
require_once('boot.php');
|
||||
|
||||
/**
|
||||
* Basic object
|
||||
*
|
||||
* Contains what is usefull to any object
|
||||
*/
|
||||
class BaseObject {
|
||||
private static $app = null;
|
||||
|
||||
/**
|
||||
* Get the app
|
||||
*
|
||||
* Same as get_app from boot.php
|
||||
*/
|
||||
public function get_app() {
|
||||
if(self::$app)
|
||||
return self::$app;
|
||||
|
||||
global $a;
|
||||
self::$app = $a;
|
||||
|
||||
return self::$app;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the app
|
||||
*/
|
||||
public static function set_app($app) {
|
||||
self::$app = $app;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,225 +0,0 @@
|
||||
<?php /** @file */
|
||||
|
||||
if(class_exists('Conversation'))
|
||||
return;
|
||||
|
||||
require_once('boot.php');
|
||||
require_once('include/BaseObject.php');
|
||||
require_once('include/ItemObject.php');
|
||||
require_once('include/text.php');
|
||||
require_once('include/items.php');
|
||||
|
||||
/**
|
||||
* A list of threads
|
||||
*
|
||||
*/
|
||||
|
||||
class Conversation extends BaseObject {
|
||||
|
||||
private $threads = array();
|
||||
private $mode = null;
|
||||
private $observer = null;
|
||||
private $writable = false;
|
||||
private $commentable = false;
|
||||
private $profile_owner = 0;
|
||||
private $preview = false;
|
||||
private $prepared_item = '';
|
||||
private $cipher = 'aes256';
|
||||
|
||||
// $prepared_item is for use by alternate conversation structures such as photos
|
||||
// wherein we've already prepared a top level item which doesn't look anything like
|
||||
// a normal "post" item
|
||||
|
||||
public function __construct($mode, $preview, $prepared_item = '') {
|
||||
$this->set_mode($mode);
|
||||
$this->preview = $preview;
|
||||
$this->prepared_item = $prepared_item;
|
||||
$c = ((local_channel()) ? get_pconfig(local_channel(),'system','default_cipher') : '');
|
||||
if($c)
|
||||
$this->cipher = $c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the mode we'll be displayed on
|
||||
*/
|
||||
private function set_mode($mode) {
|
||||
if($this->get_mode() == $mode)
|
||||
return;
|
||||
|
||||
$a = $this->get_app();
|
||||
|
||||
$this->observer = App::get_observer();
|
||||
$ob_hash = (($this->observer) ? $this->observer['xchan_hash'] : '');
|
||||
|
||||
switch($mode) {
|
||||
case 'network':
|
||||
$this->profile_owner = local_channel();
|
||||
$this->writable = true;
|
||||
break;
|
||||
case 'channel':
|
||||
$this->profile_owner = App::$profile['profile_uid'];
|
||||
$this->writable = perm_is_allowed($this->profile_owner,$ob_hash,'post_comments');
|
||||
break;
|
||||
case 'display':
|
||||
// in this mode we set profile_owner after initialisation (from conversation()) and then
|
||||
// pull some trickery which allows us to re-invoke this function afterward
|
||||
// it's an ugly hack so FIXME
|
||||
$this->writable = perm_is_allowed($this->profile_owner,$ob_hash,'post_comments');
|
||||
break;
|
||||
case 'page':
|
||||
$this->profile_owner = App::$profile['uid'];
|
||||
$this->writable = perm_is_allowed($this->profile_owner,$ob_hash,'post_comments');
|
||||
break;
|
||||
default:
|
||||
logger('[ERROR] Conversation::set_mode : Unhandled mode ('. $mode .').', LOGGER_DEBUG);
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
$this->mode = $mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mode
|
||||
*/
|
||||
public function get_mode() {
|
||||
return $this->mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if page is writable
|
||||
*/
|
||||
public function is_writable() {
|
||||
return $this->writable;
|
||||
}
|
||||
|
||||
public function is_commentable() {
|
||||
return $this->commentable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if page is a preview
|
||||
*/
|
||||
public function is_preview() {
|
||||
return $this->preview;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get profile owner
|
||||
*/
|
||||
public function get_profile_owner() {
|
||||
return $this->profile_owner;
|
||||
}
|
||||
|
||||
public function set_profile_owner($uid) {
|
||||
$this->profile_owner = $uid;
|
||||
$mode = $this->get_mode();
|
||||
$this->mode = null;
|
||||
$this->set_mode($mode);
|
||||
}
|
||||
|
||||
public function get_observer() {
|
||||
return $this->observer;
|
||||
}
|
||||
|
||||
public function get_cipher() {
|
||||
return $this->cipher;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a thread to the conversation
|
||||
*
|
||||
* Returns:
|
||||
* _ The inserted item on success
|
||||
* _ false on failure
|
||||
*/
|
||||
public function add_thread($item) {
|
||||
$item_id = $item->get_id();
|
||||
if(!$item_id) {
|
||||
logger('Item has no ID!!', LOGGER_DEBUG, LOG_ERR);
|
||||
return false;
|
||||
}
|
||||
if($this->get_thread($item->get_id())) {
|
||||
logger('Thread already exists ('. $item->get_id() .').', LOGGER_DEBUG, LOG_WARNING);
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Only add things that will be displayed
|
||||
*/
|
||||
|
||||
|
||||
if(($item->get_data_value('id') != $item->get_data_value('parent')) && (activity_match($item->get_data_value('verb'),ACTIVITY_LIKE) || activity_match($item->get_data_value('verb'),ACTIVITY_DISLIKE))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$item->set_commentable(false);
|
||||
$ob_hash = (($this->observer) ? $this->observer['xchan_hash'] : '');
|
||||
|
||||
if(! comments_are_now_closed($item->get_data())) {
|
||||
if(($item->get_data_value('author_xchan') === $ob_hash) || ($item->get_data_value('owner_xchan') === $ob_hash))
|
||||
$item->set_commentable(true);
|
||||
|
||||
if(intval($item->get_data_value('item_nocomment'))) {
|
||||
$item->set_commentable(false);
|
||||
}
|
||||
elseif(($this->observer) && (! $item->is_commentable())) {
|
||||
if((array_key_exists('owner',$item->data)) && intval($item->data['owner']['abook_self']))
|
||||
$item->set_commentable(perm_is_allowed($this->profile_owner,$this->observer['xchan_hash'],'post_comments'));
|
||||
else
|
||||
$item->set_commentable(can_comment_on_post($this->observer['xchan_hash'],$item->data));
|
||||
}
|
||||
}
|
||||
require_once('include/identity.php');
|
||||
|
||||
$item->set_conversation($this);
|
||||
$this->threads[] = $item;
|
||||
return end($this->threads);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data in a form usable by a conversation template
|
||||
*
|
||||
* We should find a way to avoid using those arguments (at least most of them)
|
||||
*
|
||||
* Returns:
|
||||
* _ The data requested on success
|
||||
* _ false on failure
|
||||
*/
|
||||
public function get_template_data($conv_responses) {
|
||||
$result = array();
|
||||
|
||||
foreach($this->threads as $item) {
|
||||
|
||||
if(($item->get_data_value('id') == $item->get_data_value('parent')) && $this->prepared_item) {
|
||||
$item_data = $this->prepared_item;
|
||||
}
|
||||
else {
|
||||
$item_data = $item->get_template_data($conv_responses);
|
||||
}
|
||||
if(!$item_data) {
|
||||
logger('Failed to get item template data ('. $item->get_id() .').', LOGGER_DEBUG, LOG_ERR);
|
||||
return false;
|
||||
}
|
||||
$result[] = $item_data;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a thread based on its item id
|
||||
*
|
||||
* Returns:
|
||||
* _ The found item on success
|
||||
* _ false on failure
|
||||
*/
|
||||
private function get_thread($id) {
|
||||
foreach($this->threads as $item) {
|
||||
if($item->get_id() == $id)
|
||||
return $item;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
require_once 'boot.php';
|
||||
|
||||
/**
|
||||
* @brief Interface for template engines.
|
||||
*/
|
||||
interface ITemplateEngine {
|
||||
public function replace_macros($s, $v);
|
||||
public function get_markup_template($file, $root='');
|
||||
}
|
||||
@@ -6,7 +6,6 @@ require_once('include/follow.php');
|
||||
require_once('include/photo/photo_driver.php');
|
||||
|
||||
function import_diaspora($data) {
|
||||
$a = get_app();
|
||||
|
||||
$account = App::get_account();
|
||||
if(! $account)
|
||||
|
||||
@@ -1,773 +0,0 @@
|
||||
<?php /** @file */
|
||||
|
||||
if(class_exists('Item'))
|
||||
return;
|
||||
|
||||
require_once('include/BaseObject.php');
|
||||
require_once('include/text.php');
|
||||
require_once('boot.php');
|
||||
|
||||
/**
|
||||
* An item
|
||||
*/
|
||||
|
||||
class Item extends BaseObject {
|
||||
public $data = array();
|
||||
private $template = 'conv_item.tpl';
|
||||
private $comment_box_template = 'comment_item.tpl';
|
||||
private $commentable = false;
|
||||
private $toplevel = false;
|
||||
private $children = array();
|
||||
private $parent = null;
|
||||
private $conversation = null;
|
||||
private $redirect_url = null;
|
||||
private $owner_url = '';
|
||||
private $owner_photo = '';
|
||||
private $owner_name = '';
|
||||
private $wall_to_wall = false;
|
||||
private $threaded = false;
|
||||
private $visiting = false;
|
||||
private $channel = null;
|
||||
private $display_mode = 'normal';
|
||||
|
||||
|
||||
public function __construct($data) {
|
||||
$a = $this->get_app();
|
||||
|
||||
$this->data = $data;
|
||||
$this->toplevel = ($this->get_id() == $this->get_data_value('parent'));
|
||||
|
||||
// Prepare the children
|
||||
if(count($data['children'])) {
|
||||
foreach($data['children'] as $item) {
|
||||
|
||||
/*
|
||||
* Only add those that will be displayed
|
||||
*/
|
||||
|
||||
if((! visible_activity($item)) || array_key_exists('author_blocked',$item)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$child = new Item($item);
|
||||
$this->add_child($child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data in a form usable by a conversation template
|
||||
*
|
||||
* Returns:
|
||||
* _ The data requested on success
|
||||
* _ false on failure
|
||||
*/
|
||||
|
||||
public function get_template_data($conv_responses, $thread_level=1) {
|
||||
|
||||
$result = array();
|
||||
|
||||
$a = $this->get_app();
|
||||
$item = $this->get_data();
|
||||
|
||||
$commentww = '';
|
||||
$sparkle = '';
|
||||
$buttons = '';
|
||||
$dropping = false;
|
||||
$star = false;
|
||||
$isstarred = "unstarred fa-star-o";
|
||||
$indent = '';
|
||||
$osparkle = '';
|
||||
$total_children = $this->count_descendants();
|
||||
$unseen_comments = (($item['real_uid']) ? 0 : $this->count_unseen_descendants());
|
||||
|
||||
$conv = $this->get_conversation();
|
||||
$observer = $conv->get_observer();
|
||||
|
||||
$lock = ((($item['item_private'] == 1) || (($item['uid'] == local_channel()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
|
||||
|| strlen($item['deny_cid']) || strlen($item['deny_gid']))))
|
||||
? t('Private Message')
|
||||
: false);
|
||||
$shareable = ((($conv->get_profile_owner() == local_channel() && local_channel()) && ($item['item_private'] != 1)) ? true : false);
|
||||
|
||||
// allow an exemption for sharing stuff from your private feeds
|
||||
if($item['author']['xchan_network'] === 'rss')
|
||||
$shareable = true;
|
||||
|
||||
$mode = $conv->get_mode();
|
||||
|
||||
if(local_channel() && $observer['xchan_hash'] === $item['author_xchan'])
|
||||
$edpost = array(z_root()."/editpost/".$item['id'], t("Edit"));
|
||||
else
|
||||
$edpost = false;
|
||||
|
||||
|
||||
if($observer['xchan_hash'] == $this->get_data_value('author_xchan')
|
||||
|| $observer['xchan_hash'] == $this->get_data_value('owner_xchan')
|
||||
|| $this->get_data_value('uid') == local_channel())
|
||||
$dropping = true;
|
||||
|
||||
|
||||
if(array_key_exists('real_uid',$item)) {
|
||||
$edpost = false;
|
||||
$dropping = false;
|
||||
}
|
||||
|
||||
|
||||
if($dropping) {
|
||||
$drop = array(
|
||||
'dropping' => $dropping,
|
||||
'delete' => t('Delete'),
|
||||
);
|
||||
}
|
||||
// FIXME
|
||||
if($observer_is_pageowner) {
|
||||
$multidrop = array(
|
||||
'select' => t('Select'),
|
||||
);
|
||||
}
|
||||
|
||||
$filer = ((($conv->get_profile_owner() == local_channel()) && (! array_key_exists('real_uid',$item))) ? t("Save to Folder") : false);
|
||||
|
||||
$profile_avatar = $item['author']['xchan_photo_m'];
|
||||
$profile_link = chanlink_url($item['author']['xchan_url']);
|
||||
$profile_name = $item['author']['xchan_name'];
|
||||
|
||||
$location = format_location($item);
|
||||
$isevent = false;
|
||||
$attend = null;
|
||||
$canvote = false;
|
||||
|
||||
// process action responses - e.g. like/dislike/attend/agree/whatever
|
||||
$response_verbs = array('like');
|
||||
if(feature_enabled($conv->get_profile_owner(),'dislike'))
|
||||
$response_verbs[] = 'dislike';
|
||||
if($item['obj_type'] === ACTIVITY_OBJ_EVENT) {
|
||||
$response_verbs[] = 'attendyes';
|
||||
$response_verbs[] = 'attendno';
|
||||
$response_verbs[] = 'attendmaybe';
|
||||
if($this->is_commentable()) {
|
||||
$isevent = true;
|
||||
$attend = array( t('I will attend'), t('I will not attend'), t('I might attend'));
|
||||
}
|
||||
}
|
||||
|
||||
$consensus = (intval($item['item_consensus']) ? true : false);
|
||||
if($consensus) {
|
||||
$response_verbs[] = 'agree';
|
||||
$response_verbs[] = 'disagree';
|
||||
$response_verbs[] = 'abstain';
|
||||
if($this->is_commentable()) {
|
||||
$conlabels = array( t('I agree'), t('I disagree'), t('I abstain'));
|
||||
$canvote = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(! feature_enabled($conv->get_profile_owner(),'dislike'))
|
||||
unset($conv_responses['dislike']);
|
||||
|
||||
$responses = get_responses($conv_responses,$response_verbs,$this,$item);
|
||||
|
||||
$like_count = ((x($conv_responses['like'],$item['mid'])) ? $conv_responses['like'][$item['mid']] : '');
|
||||
$like_list = ((x($conv_responses['like'],$item['mid'])) ? $conv_responses['like'][$item['mid'] . '-l'] : '');
|
||||
if (count($like_list) > MAX_LIKERS) {
|
||||
$like_list_part = array_slice($like_list, 0, MAX_LIKERS);
|
||||
array_push($like_list_part, '<a href="#" data-toggle="modal" data-target="#likeModal-' . $this->get_id() . '"><b>' . t('View all') . '</b></a>');
|
||||
} else {
|
||||
$like_list_part = '';
|
||||
}
|
||||
$like_button_label = tt('Like','Likes',$like_count,'noun');
|
||||
|
||||
if (feature_enabled($conv->get_profile_owner(),'dislike')) {
|
||||
$dislike_count = ((x($conv_responses['dislike'],$item['mid'])) ? $conv_responses['dislike'][$item['mid']] : '');
|
||||
$dislike_list = ((x($conv_responses['dislike'],$item['mid'])) ? $conv_responses['dislike'][$item['mid'] . '-l'] : '');
|
||||
$dislike_button_label = tt('Dislike','Dislikes',$dislike_count,'noun');
|
||||
if (count($dislike_list) > MAX_LIKERS) {
|
||||
$dislike_list_part = array_slice($dislike_list, 0, MAX_LIKERS);
|
||||
array_push($dislike_list_part, '<a href="#" data-toggle="modal" data-target="#dislikeModal-' . $this->get_id() . '"><b>' . t('View all') . '</b></a>');
|
||||
} else {
|
||||
$dislike_list_part = '';
|
||||
}
|
||||
}
|
||||
|
||||
$showlike = ((x($conv_responses['like'],$item['mid'])) ? format_like($conv_responses['like'][$item['mid']],$conv_responses['like'][$item['mid'] . '-l'],'like',$item['mid']) : '');
|
||||
$showdislike = ((x($conv_responses['dislike'],$item['mid']) && feature_enabled($conv->get_profile_owner(),'dislike'))
|
||||
? format_like($conv_responses['dislike'][$item['mid']],$conv_responses['dislike'][$item['mid'] . '-l'],'dislike',$item['mid']) : '');
|
||||
|
||||
/*
|
||||
* We should avoid doing this all the time, but it depends on the conversation mode
|
||||
* And the conv mode may change when we change the conv, or it changes its mode
|
||||
* Maybe we should establish a way to be notified about conversation changes
|
||||
*/
|
||||
|
||||
$this->check_wall_to_wall();
|
||||
|
||||
if($this->is_toplevel()) {
|
||||
// FIXME check this permission
|
||||
if(($conv->get_profile_owner() == local_channel()) && (! array_key_exists('real_uid',$item))) {
|
||||
|
||||
// FIXME we don't need all this stuff, some can be done in the template
|
||||
|
||||
$star = array(
|
||||
'do' => t("Add Star"),
|
||||
'undo' => t("Remove Star"),
|
||||
'toggle' => t("Toggle Star Status"),
|
||||
'classdo' => (intval($item['item_starred']) ? "hidden" : ""),
|
||||
'classundo' => (intval($item['item_starred']) ? "" : "hidden"),
|
||||
'isstarred' => (intval($item['item_starred']) ? "starred fa-star" : "unstarred fa-star-o"),
|
||||
'starred' => t('starred'),
|
||||
);
|
||||
|
||||
}
|
||||
} else {
|
||||
$indent = 'comment';
|
||||
}
|
||||
|
||||
|
||||
$verified = (intval($item['item_verified']) ? t('Message signature validated') : '');
|
||||
$forged = ((($item['sig']) && (! intval($item['item_verified']))) ? t('Message signature incorrect') : '');
|
||||
$unverified = '' ; // (($this->is_wall_to_wall() && (! intval($item['item_verified']))) ? t('Message cannot be verified') : '');
|
||||
|
||||
|
||||
|
||||
// FIXME - check this permission
|
||||
if($conv->get_profile_owner() == local_channel()) {
|
||||
$tagger = array(
|
||||
'tagit' => t("Add Tag"),
|
||||
'classtagger' => "",
|
||||
);
|
||||
}
|
||||
|
||||
$has_bookmarks = false;
|
||||
if(is_array($item['term'])) {
|
||||
foreach($item['term'] as $t) {
|
||||
if(!UNO && $t['type'] == TERM_BOOKMARK)
|
||||
$has_bookmarks = true;
|
||||
}
|
||||
}
|
||||
|
||||
$has_event = false;
|
||||
if(($item['obj_type'] === ACTIVITY_OBJ_EVENT) && $conv->get_profile_owner() == local_channel())
|
||||
$has_event = true;
|
||||
|
||||
if($this->is_commentable()) {
|
||||
$like = array( t("I like this \x28toggle\x29"), t("like"));
|
||||
$dislike = array( t("I don't like this \x28toggle\x29"), t("dislike"));
|
||||
}
|
||||
|
||||
if ($shareable)
|
||||
$share = array( t('Share This'), t('share'));
|
||||
|
||||
$dreport = '';
|
||||
|
||||
$keep_reports = intval(get_config('system','expire_delivery_reports'));
|
||||
if($keep_reports === 0)
|
||||
$keep_reports = 30;
|
||||
|
||||
if((! get_config('system','disable_dreport')) && strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC',"now - $keep_reports days")) > 0)
|
||||
$dreport = t('Delivery Report');
|
||||
|
||||
if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
|
||||
$indent .= ' shiny';
|
||||
|
||||
|
||||
localize_item($item);
|
||||
|
||||
$body = prepare_body($item,true);
|
||||
|
||||
// $viewthread (below) is only valid in list mode. If this is a channel page, build the thread viewing link
|
||||
// since we can't depend on llink or plink pointing to the right local location.
|
||||
|
||||
$owner_address = substr($item['owner']['xchan_addr'],0,strpos($item['owner']['xchan_addr'],'@'));
|
||||
$viewthread = $item['llink'];
|
||||
if($conv->get_mode() === 'channel')
|
||||
$viewthread = z_root() . '/channel/' . $owner_address . '?f=&mid=' . $item['mid'];
|
||||
|
||||
$comment_count_txt = sprintf( tt('%d comment','%d comments',$total_children),$total_children );
|
||||
$list_unseen_txt = (($unseen_comments) ? sprintf('%d unseen',$unseen_comments) : '');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$children = $this->get_children();
|
||||
|
||||
$has_tags = (($body['tags'] || $body['categories'] || $body['mentions'] || $body['attachments'] || $body['folders']) ? true : false);
|
||||
|
||||
$tmp_item = array(
|
||||
'template' => $this->get_template(),
|
||||
'mode' => $mode,
|
||||
'type' => implode("",array_slice(explode("/",$item['verb']),-1)),
|
||||
'body' => $body['html'],
|
||||
'tags' => $body['tags'],
|
||||
'categories' => $body['categories'],
|
||||
'mentions' => $body['mentions'],
|
||||
'attachments' => $body['attachments'],
|
||||
'folders' => $body['folders'],
|
||||
'text' => strip_tags($body['html']),
|
||||
'id' => $this->get_id(),
|
||||
'mid' => $item['mid'],
|
||||
'isevent' => $isevent,
|
||||
'attend' => $attend,
|
||||
'consensus' => $consensus,
|
||||
'conlabels' => $conlabels,
|
||||
'canvote' => $canvote,
|
||||
'linktitle' => sprintf( t('View %s\'s profile - %s'), $profile_name, $item['author']['xchan_addr']),
|
||||
'olinktitle' => sprintf( t('View %s\'s profile - %s'), $this->get_owner_name(), $item['owner']['xchan_addr']),
|
||||
'llink' => $item['llink'],
|
||||
'viewthread' => $viewthread,
|
||||
'to' => t('to'),
|
||||
'via' => t('via'),
|
||||
'wall' => t('Wall-to-Wall'),
|
||||
'vwall' => t('via Wall-To-Wall:'),
|
||||
'profile_url' => $profile_link,
|
||||
'item_photo_menu' => item_photo_menu($item),
|
||||
'dreport' => $dreport,
|
||||
'name' => $profile_name,
|
||||
'thumb' => $profile_avatar,
|
||||
'osparkle' => $osparkle,
|
||||
'sparkle' => $sparkle,
|
||||
'title' => $item['title'],
|
||||
'title_tosource' => get_pconfig($conv->get_profile_owner(),'system','title_tosource'),
|
||||
'ago' => relative_date($item['created']),
|
||||
'app' => $item['app'],
|
||||
'str_app' => sprintf( t('from %s'), $item['app']),
|
||||
'isotime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'c'),
|
||||
'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'),
|
||||
'editedtime' => (($item['edited'] != $item['created']) ? sprintf( t('last edited: %s'), datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r')) : ''),
|
||||
'expiretime' => (($item['expires'] !== NULL_DATE) ? sprintf( t('Expires: %s'), datetime_convert('UTC', date_default_timezone_get(), $item['expires'], 'r')):''),
|
||||
'lock' => $lock,
|
||||
'verified' => $verified,
|
||||
'unverified' => $unverified,
|
||||
'forged' => $forged,
|
||||
'location' => $location,
|
||||
'indent' => $indent,
|
||||
'owner_url' => $this->get_owner_url(),
|
||||
'owner_photo' => $this->get_owner_photo(),
|
||||
'owner_name' => $this->get_owner_name(),
|
||||
'photo' => $body['photo'],
|
||||
'event' => $body['event'],
|
||||
'has_tags' => $has_tags,
|
||||
|
||||
// Item toolbar buttons
|
||||
'like' => $like,
|
||||
'dislike' => ((feature_enabled($conv->get_profile_owner(),'dislike')) ? $dislike : ''),
|
||||
'share' => $share,
|
||||
'rawmid' => $item['mid'],
|
||||
'plink' => get_plink($item),
|
||||
'edpost' => $edpost, // ((feature_enabled($conv->get_profile_owner(),'edit_posts')) ? $edpost : ''),
|
||||
'star' => ((feature_enabled($conv->get_profile_owner(),'star_posts')) ? $star : ''),
|
||||
'tagger' => ((feature_enabled($conv->get_profile_owner(),'commtag')) ? $tagger : ''),
|
||||
'filer' => ((feature_enabled($conv->get_profile_owner(),'filing')) ? $filer : ''),
|
||||
'bookmark' => (($conv->get_profile_owner() == local_channel() && local_channel() && $has_bookmarks) ? t('Save Bookmarks') : ''),
|
||||
'addtocal' => (($has_event) ? t('Add to Calendar') : ''),
|
||||
'drop' => $drop,
|
||||
'multidrop' => ((feature_enabled($conv->get_profile_owner(),'multi_delete')) ? $multidrop : ''),
|
||||
// end toolbar buttons
|
||||
|
||||
'unseen_comments' => $unseen_comments,
|
||||
'comment_count' => $total_children,
|
||||
'comment_count_txt' => $comment_count_txt,
|
||||
'list_unseen_txt' => $list_unseen_txt,
|
||||
'markseen' => t('Mark all seen'),
|
||||
'responses' => $responses,
|
||||
'like_count' => $like_count,
|
||||
'like_list' => $like_list,
|
||||
'like_list_part' => $like_list_part,
|
||||
'like_button_label' => $like_button_label,
|
||||
'like_modal_title' => t('Likes','noun'),
|
||||
'dislike_modal_title' => t('Dislikes','noun'),
|
||||
'dislike_count' => ((feature_enabled($conv->get_profile_owner(),'dislike')) ? $dislike_count : ''),
|
||||
'dislike_list' => ((feature_enabled($conv->get_profile_owner(),'dislike')) ? $dislike_list : ''),
|
||||
'dislike_list_part' => ((feature_enabled($conv->get_profile_owner(),'dislike')) ? $dislike_list_part : ''),
|
||||
'dislike_button_label' => ((feature_enabled($conv->get_profile_owner(),'dislike')) ? $dislike_button_label : ''),
|
||||
'modal_dismiss' => t('Close'),
|
||||
'showlike' => $showlike,
|
||||
'showdislike' => $showdislike,
|
||||
'comment' => $this->get_comment_box($indent),
|
||||
'previewing' => ($conv->is_preview() ? ' preview ' : ''),
|
||||
'wait' => t('Please wait'),
|
||||
'thread_level' => $thread_level
|
||||
);
|
||||
|
||||
$arr = array('item' => $item, 'output' => $tmp_item);
|
||||
call_hooks('display_item', $arr);
|
||||
|
||||
$result = $arr['output'];
|
||||
|
||||
$result['children'] = array();
|
||||
$nb_children = count($children);
|
||||
|
||||
$visible_comments = get_config('system','expanded_comments');
|
||||
if($visible_comments === false)
|
||||
$visible_comments = 3;
|
||||
|
||||
if(($this->get_display_mode() === 'normal') && ($nb_children > 0)) {
|
||||
foreach($children as $child) {
|
||||
$result['children'][] = $child->get_template_data($conv_responses, $thread_level + 1);
|
||||
}
|
||||
// Collapse
|
||||
if(($nb_children > $visible_comments) || ($thread_level > 1)) {
|
||||
$result['children'][0]['comment_firstcollapsed'] = true;
|
||||
$result['children'][0]['num_comments'] = $comment_count_txt;
|
||||
$result['children'][0]['hide_text'] = t('[+] show all');
|
||||
if($thread_level > 1) {
|
||||
$result['children'][$nb_children - 1]['comment_lastcollapsed'] = true;
|
||||
}
|
||||
else {
|
||||
$result['children'][$nb_children - ($visible_comments + 1)]['comment_lastcollapsed'] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result['private'] = $item['item_private'];
|
||||
$result['toplevel'] = ($this->is_toplevel() ? 'toplevel_item' : '');
|
||||
|
||||
if($this->is_threaded()) {
|
||||
$result['flatten'] = false;
|
||||
$result['threaded'] = true;
|
||||
}
|
||||
else {
|
||||
$result['flatten'] = true;
|
||||
$result['threaded'] = false;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function get_id() {
|
||||
return $this->get_data_value('id');
|
||||
}
|
||||
|
||||
public function get_display_mode() {
|
||||
return $this->display_mode;
|
||||
}
|
||||
|
||||
public function set_display_mode($mode) {
|
||||
$this->display_mode = $mode;
|
||||
}
|
||||
|
||||
public function is_threaded() {
|
||||
return $this->threaded;
|
||||
}
|
||||
|
||||
public function set_commentable($val) {
|
||||
$this->commentable = $val;
|
||||
foreach($this->get_children() as $child)
|
||||
$child->set_commentable($val);
|
||||
}
|
||||
|
||||
public function is_commentable() {
|
||||
return $this->commentable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a child item
|
||||
*/
|
||||
public function add_child($item) {
|
||||
$item_id = $item->get_id();
|
||||
if(!$item_id) {
|
||||
logger('[ERROR] Item::add_child : Item has no ID!!', LOGGER_DEBUG);
|
||||
return false;
|
||||
}
|
||||
if($this->get_child($item->get_id())) {
|
||||
logger('[WARN] Item::add_child : Item already exists ('. $item->get_id() .').', LOGGER_DEBUG);
|
||||
return false;
|
||||
}
|
||||
/*
|
||||
* Only add what will be displayed
|
||||
*/
|
||||
|
||||
if(activity_match($item->get_data_value('verb'),ACTIVITY_LIKE) || activity_match($item->get_data_value('verb'),ACTIVITY_DISLIKE)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$item->set_parent($this);
|
||||
$this->children[] = $item;
|
||||
return end($this->children);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a child by its ID
|
||||
*/
|
||||
public function get_child($id) {
|
||||
foreach($this->get_children() as $child) {
|
||||
if($child->get_id() == $id)
|
||||
return $child;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all our children
|
||||
*/
|
||||
public function get_children() {
|
||||
return $this->children;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set our parent
|
||||
*/
|
||||
protected function set_parent($item) {
|
||||
$parent = $this->get_parent();
|
||||
if($parent) {
|
||||
$parent->remove_child($this);
|
||||
}
|
||||
$this->parent = $item;
|
||||
$this->set_conversation($item->get_conversation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove our parent
|
||||
*/
|
||||
protected function remove_parent() {
|
||||
$this->parent = null;
|
||||
$this->conversation = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a child
|
||||
*/
|
||||
public function remove_child($item) {
|
||||
$id = $item->get_id();
|
||||
foreach($this->get_children() as $key => $child) {
|
||||
if($child->get_id() == $id) {
|
||||
$child->remove_parent();
|
||||
unset($this->children[$key]);
|
||||
// Reindex the array, in order to make sure there won't be any trouble on loops using count()
|
||||
$this->children = array_values($this->children);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
logger('[WARN] Item::remove_child : Item is not a child ('. $id .').', LOGGER_DEBUG);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get parent item
|
||||
*/
|
||||
protected function get_parent() {
|
||||
return $this->parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* set conversation
|
||||
*/
|
||||
public function set_conversation($conv) {
|
||||
$previous_mode = ($this->conversation ? $this->conversation->get_mode() : '');
|
||||
|
||||
$this->conversation = $conv;
|
||||
|
||||
// Set it on our children too
|
||||
foreach($this->get_children() as $child)
|
||||
$child->set_conversation($conv);
|
||||
}
|
||||
|
||||
/**
|
||||
* get conversation
|
||||
*/
|
||||
public function get_conversation() {
|
||||
return $this->conversation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get raw data
|
||||
*
|
||||
* We shouldn't need this
|
||||
*/
|
||||
public function get_data() {
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a data value
|
||||
*
|
||||
* Returns:
|
||||
* _ value on success
|
||||
* _ false on failure
|
||||
*/
|
||||
public function get_data_value($name) {
|
||||
if(!isset($this->data[$name])) {
|
||||
// logger('[ERROR] Item::get_data_value : Item has no value name "'. $name .'".', LOGGER_DEBUG);
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->data[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get template
|
||||
*/
|
||||
public function get_template() {
|
||||
return $this->template;
|
||||
}
|
||||
|
||||
|
||||
public function set_template($t) {
|
||||
$this->template = $t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this is a toplevel post
|
||||
*/
|
||||
private function is_toplevel() {
|
||||
return $this->toplevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the total of our descendants
|
||||
*/
|
||||
private function count_descendants() {
|
||||
$children = $this->get_children();
|
||||
$total = count($children);
|
||||
if($total > 0) {
|
||||
foreach($children as $child) {
|
||||
$total += $child->count_descendants();
|
||||
}
|
||||
}
|
||||
return $total;
|
||||
}
|
||||
|
||||
private function count_unseen_descendants() {
|
||||
$children = $this->get_children();
|
||||
$total = count($children);
|
||||
if($total > 0) {
|
||||
$total = 0;
|
||||
foreach($children as $child) {
|
||||
if((! visible_activity($child->data)) || array_key_exists('author_blocked',$child->data)) {
|
||||
continue;
|
||||
}
|
||||
if(intval($child->data['item_unseen']))
|
||||
$total ++;
|
||||
}
|
||||
}
|
||||
return $total;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the template for the comment box
|
||||
*/
|
||||
private function get_comment_box_template() {
|
||||
return $this->comment_box_template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the comment box
|
||||
*
|
||||
* Returns:
|
||||
* _ The comment box string (empty if no comment box)
|
||||
* _ false on failure
|
||||
*/
|
||||
private function get_comment_box($indent) {
|
||||
|
||||
if(!$this->is_toplevel() && !get_config('system','thread_allow')) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$comment_box = '';
|
||||
$conv = $this->get_conversation();
|
||||
|
||||
// logger('Commentable conv: ' . $conv->is_commentable());
|
||||
|
||||
if(! $this->is_commentable())
|
||||
return;
|
||||
|
||||
$template = get_markup_template($this->get_comment_box_template());
|
||||
|
||||
$a = $this->get_app();
|
||||
$observer = $conv->get_observer();
|
||||
|
||||
$qc = ((local_channel()) ? get_pconfig(local_channel(),'system','qcomment') : null);
|
||||
$qcomment = (($qc) ? explode("\n",$qc) : null);
|
||||
|
||||
$arr = array('comment_buttons' => '','id' => $this->get_id());
|
||||
call_hooks('comment_buttons',$arr);
|
||||
$comment_buttons = $arr['comment_buttons'];
|
||||
|
||||
|
||||
$comment_box = replace_macros($template,array(
|
||||
'$return_path' => '',
|
||||
'$threaded' => $this->is_threaded(),
|
||||
'$jsreload' => '', //(($conv->get_mode() === 'display') ? $_SESSION['return_url'] : ''),
|
||||
'$type' => (($conv->get_mode() === 'channel') ? 'wall-comment' : 'net-comment'),
|
||||
'$id' => $this->get_id(),
|
||||
'$parent' => $this->get_id(),
|
||||
'$qcomment' => $qcomment,
|
||||
'$comment_buttons' => $comment_buttons,
|
||||
'$profile_uid' => $conv->get_profile_owner(),
|
||||
'$mylink' => $observer['xchan_url'],
|
||||
'$mytitle' => t('This is you'),
|
||||
'$myphoto' => $observer['xchan_photo_s'],
|
||||
'$comment' => t('Comment'),
|
||||
'$submit' => t('Submit'),
|
||||
'$edbold' => t('Bold'),
|
||||
'$editalic' => t('Italic'),
|
||||
'$eduline' => t('Underline'),
|
||||
'$edquote' => t('Quote'),
|
||||
'$edcode' => t('Code'),
|
||||
'$edimg' => t('Image'),
|
||||
'$edurl' => t('Insert Link'),
|
||||
'$edvideo' => t('Video'),
|
||||
'$preview' => t('Preview'), // ((feature_enabled($conv->get_profile_owner(),'preview')) ? t('Preview') : ''),
|
||||
'$indent' => $indent,
|
||||
'$feature_encrypt' => ((feature_enabled($conv->get_profile_owner(),'content_encrypt')) ? true : false),
|
||||
'$encrypt' => t('Encrypt text'),
|
||||
'$cipher' => $conv->get_cipher(),
|
||||
'$sourceapp' => App::$sourcename
|
||||
|
||||
));
|
||||
|
||||
return $comment_box;
|
||||
}
|
||||
|
||||
private function get_redirect_url() {
|
||||
return $this->redirect_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we are a wall to wall item and set the relevant properties
|
||||
*/
|
||||
protected function check_wall_to_wall() {
|
||||
$conv = $this->get_conversation();
|
||||
$this->wall_to_wall = false;
|
||||
$this->owner_url = '';
|
||||
$this->owner_photo = '';
|
||||
$this->owner_name = '';
|
||||
|
||||
if($conv->get_mode() === 'channel')
|
||||
return;
|
||||
|
||||
if($this->is_toplevel() && ($this->get_data_value('author_xchan') != $this->get_data_value('owner_xchan'))) {
|
||||
$this->owner_url = chanlink_url($this->data['owner']['xchan_url']);
|
||||
$this->owner_photo = $this->data['owner']['xchan_photo_m'];
|
||||
$this->owner_name = $this->data['owner']['xchan_name'];
|
||||
$this->wall_to_wall = true;
|
||||
}
|
||||
}
|
||||
|
||||
private function is_wall_to_wall() {
|
||||
return $this->wall_to_wall;
|
||||
}
|
||||
|
||||
private function get_owner_url() {
|
||||
return $this->owner_url;
|
||||
}
|
||||
|
||||
private function get_owner_photo() {
|
||||
return $this->owner_photo;
|
||||
}
|
||||
|
||||
private function get_owner_name() {
|
||||
return $this->owner_name;
|
||||
}
|
||||
|
||||
private function is_visiting() {
|
||||
return $this->visiting;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -117,11 +117,7 @@ class PermissionDescription {
|
||||
case PERMS_NETWORK: return t('Anybody in the $Projectname network');
|
||||
case PERMS_SITE: return sprintf(t('Any account on %s'), \App::get_hostname());
|
||||
case PERMS_CONTACTS: return t('Any of my connections');
|
||||
case PERMS_SPECIFIC:
|
||||
// Because we're describing the permissions of an item with an empty ACL,
|
||||
// the owner will be the only person able to see it if the permissions are
|
||||
// set to "only specified connections".
|
||||
return t('Only me (only specified contacts and me)');
|
||||
case PERMS_SPECIFIC: return t('Only connections I specifically allow');
|
||||
case PERMS_AUTHED: return t('Anybody authenticated (could include visitors from other networks)');
|
||||
case PERMS_PENDING: return t('Any connections including those who haven\'t yet been approved');
|
||||
default: return $this->fallback_description;
|
||||
@@ -143,11 +139,7 @@ class PermissionDescription {
|
||||
case PERMS_NETWORK: return 'fa-share-alt-square'; // fa-share-alt-square is very similiar to the hubzilla logo, but we should create our own logo class to use
|
||||
case PERMS_SITE: return 'fa-sitemap';
|
||||
case PERMS_CONTACTS: return 'fa-group';
|
||||
case PERMS_SPECIFIC:
|
||||
// Because we're describing the permissions of an item with an empty ACL,
|
||||
// the owner will be the only person able to see it if the permissions are
|
||||
// set to "only specified connections".
|
||||
return 'fa-eye-slash';
|
||||
case PERMS_SPECIFIC: return 'fa-list';
|
||||
case PERMS_AUTHED: return '';
|
||||
case PERMS_PENDING: return '';
|
||||
default: return '';
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
<?php /** @file */
|
||||
|
||||
/*
|
||||
* Abstraction class for dealing with alternate networks (which of course do not exist, hence the abstraction)
|
||||
*/
|
||||
|
||||
|
||||
abstract class ProtoDriver {
|
||||
abstract protected function discover($channel,$location);
|
||||
abstract protected function deliver($item,$channel,$recipients);
|
||||
abstract protected function collect($channel,$connection);
|
||||
abstract protected function change_permissions($permissions,$channel,$recipient);
|
||||
abstract protected function acknowledge_permissions($permissions,$channel,$recipient);
|
||||
abstract protected function deliver_private($item,$channel,$recipients);
|
||||
abstract protected function collect_private($channel,$connection);
|
||||
|
||||
}
|
||||
|
||||
class ZotDriver extends ProtoDriver {
|
||||
|
||||
protected function discover($channel,$location) {
|
||||
|
||||
}
|
||||
protected function deliver($item,$channel,$recipients) {
|
||||
|
||||
}
|
||||
protected function collect($channel,$connection) {
|
||||
|
||||
}
|
||||
protected function change_permissions($permissions,$channel,$recipient) {
|
||||
|
||||
}
|
||||
protected function acknowledge_permissions($permissions,$channel,$recipient) {
|
||||
|
||||
}
|
||||
protected function deliver_private($item,$channel,$recipients) {
|
||||
|
||||
}
|
||||
protected function collect_private($channel,$connection) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,7 +11,7 @@ require_once('include/text.php');
|
||||
require_once('include/language.php');
|
||||
require_once('include/datetime.php');
|
||||
require_once('include/crypto.php');
|
||||
require_once('include/identity.php');
|
||||
require_once('include/channel.php');
|
||||
|
||||
|
||||
function check_account_email($email) {
|
||||
@@ -229,7 +229,7 @@ function verify_email_address($arr) {
|
||||
|
||||
$hash = random_string();
|
||||
|
||||
$r = q("INSERT INTO register ( hash, created, uid, password, language ) VALUES ( '%s', '%s', %d, '%s', '%s' ) ",
|
||||
$r = q("INSERT INTO register ( hash, created, uid, password, lang ) VALUES ( '%s', '%s', %d, '%s', '%s' ) ",
|
||||
dbesc($hash),
|
||||
dbesc(datetime_convert()),
|
||||
intval($arr['account']['account_id']),
|
||||
@@ -283,7 +283,7 @@ function send_reg_approval_email($arr) {
|
||||
|
||||
$hash = random_string();
|
||||
|
||||
$r = q("INSERT INTO register ( hash, created, uid, password, language ) VALUES ( '%s', '%s', %d, '%s', '%s' ) ",
|
||||
$r = q("INSERT INTO register ( hash, created, uid, password, lang ) VALUES ( '%s', '%s', %d, '%s', '%s' ) ",
|
||||
dbesc($hash),
|
||||
dbesc(datetime_convert()),
|
||||
intval($arr['account']['account_id']),
|
||||
@@ -387,7 +387,7 @@ function account_allow($hash) {
|
||||
intval($register[0]['uid'])
|
||||
);
|
||||
|
||||
push_lang($register[0]['language']);
|
||||
push_lang($register[0]['lang']);
|
||||
|
||||
$email_tpl = get_intltext_template("register_open_eml.tpl");
|
||||
$email_tpl = replace_macros($email_tpl, array(
|
||||
@@ -656,7 +656,8 @@ function account_service_class_allows($aid, $property, $usage = false) {
|
||||
* @todo Should we merge this with account_service_class_fetch()?
|
||||
*/
|
||||
function service_class_fetch($uid, $property) {
|
||||
$a = get_app();
|
||||
|
||||
|
||||
if($uid == local_channel()) {
|
||||
$service_class = App::$account['account_service_class'];
|
||||
}
|
||||
|
||||
@@ -11,13 +11,11 @@ require_once("include/PermissionDescription.php");
|
||||
|
||||
function group_select($selname,$selclass,$preselected = false,$size = 4) {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
$o = '';
|
||||
|
||||
$o .= "<select name=\"{$selname}[]\" id=\"$selclass\" class=\"$selclass\" multiple=\"multiple\" size=\"$size\" >\r\n";
|
||||
|
||||
$r = q("SELECT * FROM `groups` WHERE `deleted` = 0 AND `uid` = %d ORDER BY `name` ASC",
|
||||
$r = q("SELECT * FROM `groups` WHERE `deleted` = 0 AND `uid` = %d ORDER BY `gname` ASC",
|
||||
intval(local_channel())
|
||||
);
|
||||
|
||||
@@ -34,7 +32,7 @@ function group_select($selname,$selclass,$preselected = false,$size = 4) {
|
||||
$selected = " selected=\"selected\" ";
|
||||
else
|
||||
$selected = '';
|
||||
$trimmed = mb_substr($rr['name'],0,12);
|
||||
$trimmed = mb_substr($rr['gname'],0,12);
|
||||
|
||||
$o .= "<option value=\"{$rr['id']}\" $selected title=\"{$rr['name']}\" >$trimmed</option>\r\n";
|
||||
}
|
||||
@@ -51,7 +49,6 @@ function group_select($selname,$selclass,$preselected = false,$size = 4) {
|
||||
/* MicMee 20130114 function contact_selector no longer in use, sql table contact does no longer exist
|
||||
function contact_selector($selname, $selclass, $preselected = false, $options) {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
$mutual = false;
|
||||
$networks = null;
|
||||
@@ -157,7 +154,6 @@ function contact_selector($selname, $selclass, $preselected = false, $options) {
|
||||
|
||||
function contact_select($selname, $selclass, $preselected = false, $size = 4, $privmail = false, $celeb = false, $privatenet = false, $tabindex = null) {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
$o = '';
|
||||
|
||||
@@ -230,14 +226,14 @@ function populate_acl($defaults = null,$show_jotnets = true, $emptyACL_descripti
|
||||
$allow_cid = $allow_gid = $deny_cid = $deny_gid = false;
|
||||
$showall_origin = '';
|
||||
$showall_icon = 'fa-globe';
|
||||
|
||||
$role = get_pconfig(local_channel(),'system','permissions_role');
|
||||
|
||||
if(! $emptyACL_description) {
|
||||
$showall_caption = t('Visible to your default audience');
|
||||
|
||||
} else if (is_a($emptyACL_description, 'PermissionDescription')) {
|
||||
$showall_caption = $emptyACL_description->get_permission_description();
|
||||
$showall_origin = $emptyACL_description->get_permission_origin_description();
|
||||
$showall_origin = (($role === 'custom') ? $emptyACL_description->get_permission_origin_description() : '');
|
||||
$showall_icon = $emptyACL_description->get_permission_icon();
|
||||
|
||||
} else {
|
||||
@@ -269,9 +265,11 @@ function populate_acl($defaults = null,$show_jotnets = true, $emptyACL_descripti
|
||||
$tpl = get_markup_template("acl_selector.tpl");
|
||||
$o = replace_macros($tpl, array(
|
||||
'$showall' => $showall_caption,
|
||||
'$onlyme' => t('Only me'),
|
||||
'$showallOrigin' => $showall_origin,
|
||||
'$showallIcon' => $showall_icon,
|
||||
'$showlimited' => t("Limit access:"),
|
||||
'$select_label' => t('Who can see this?'),
|
||||
'$showlimited' => t('Custom selection'),
|
||||
'$showlimitedDesc' => t('Select "Show" to allow viewing. "Don\'t show" lets you override and limit the scope of "Show".'),
|
||||
'$show' => t("Show"),
|
||||
'$hide' => t("Don't show"),
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?php /** @file */
|
||||
|
||||
function profile_activity($changed, $value) {
|
||||
$a = get_app();
|
||||
|
||||
if(! local_channel() || ! is_array($changed) || ! count($changed))
|
||||
return;
|
||||
@@ -89,7 +88,7 @@ function profile_activity($changed, $value) {
|
||||
|
||||
if($i) {
|
||||
// FIXME - limit delivery in notifier.php to those specificed in the perms argument
|
||||
proc_run('php',"include/notifier.php","activity","$i", 'PERMS_R_PROFILE');
|
||||
Zotlabs\Daemon\Master::Summon(array('Notifier','activity', $i, 'PERMS_R_PROFILE'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -368,7 +368,7 @@ require_once('include/api_auth.php');
|
||||
else
|
||||
$redirect = trim($_REQUEST['redirect_uris']);
|
||||
$icon = trim($_REQUEST['logo_uri']);
|
||||
$r = q("INSERT INTO clients (client_id, pw, name, redirect_uri, icon, uid)
|
||||
$r = q("INSERT INTO clients (client_id, pw, clname, redirect_uri, icon, uid)
|
||||
VALUES ('%s','%s','%s','%s','%s',%d)",
|
||||
dbesc($key),
|
||||
dbesc($secret),
|
||||
@@ -451,8 +451,6 @@ require_once('include/api_auth.php');
|
||||
*/
|
||||
function api_apply_template($templatename, $type, $data){
|
||||
|
||||
$a = get_app();
|
||||
|
||||
switch($type){
|
||||
case "atom":
|
||||
case "rss":
|
||||
@@ -486,7 +484,7 @@ require_once('include/api_auth.php');
|
||||
|
||||
function api_account_logout(&$a, $type){
|
||||
require_once('include/auth.php');
|
||||
\Zotlabs\Web\Session::nuke();
|
||||
App::$session->nuke();
|
||||
return api_apply_template("user", $type, array('$user' => null));
|
||||
|
||||
}
|
||||
@@ -514,7 +512,7 @@ require_once('include/api_auth.php');
|
||||
return false;
|
||||
}
|
||||
|
||||
require_once('include/identity.php');
|
||||
require_once('include/channel.php');
|
||||
|
||||
json_return_and_die(identity_basic_export(api_user(),(($_REQUEST['posts']) ? intval($_REQUEST['posts']) : 0 )));
|
||||
}
|
||||
@@ -556,7 +554,7 @@ require_once('include/api_auth.php');
|
||||
dbesc($_REQUEST['file_id'])
|
||||
);
|
||||
if($r) {
|
||||
unset($r[0]['data']);
|
||||
unset($r[0]['content']);
|
||||
$ret = array('attach' => $r[0]);
|
||||
json_return_and_die($ret);
|
||||
}
|
||||
@@ -582,21 +580,21 @@ require_once('include/api_auth.php');
|
||||
$length = intval($ptr['filesize']);
|
||||
|
||||
if($ptr['is_dir'])
|
||||
$ptr['data'] = '';
|
||||
$ptr['content'] = '';
|
||||
elseif(! intval($r[0]['os_storage'])) {
|
||||
$ptr['start'] = $start;
|
||||
$x = substr(dbunescbin($ptr['data'],$start,$length));
|
||||
$x = substr(dbunescbin($ptr['content'],$start,$length));
|
||||
$ptr['length'] = strlen($x);
|
||||
$ptr['data'] = base64_encode($x);
|
||||
$ptr['content'] = base64_encode($x);
|
||||
}
|
||||
else {
|
||||
$fp = fopen(dbunescbin($ptr['data']),'r');
|
||||
$fp = fopen(dbunescbin($ptr['content']),'r');
|
||||
if($fp) {
|
||||
$seek = fseek($fp,$start,SEEK_SET);
|
||||
$x = fread($fp,$length);
|
||||
$ptr['start'] = $start;
|
||||
$ptr['length'] = strlen($x);
|
||||
$ptr['data'] = base64_encode($x);
|
||||
$ptr['content'] = base64_encode($x);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -619,11 +617,11 @@ require_once('include/api_auth.php');
|
||||
);
|
||||
if($r) {
|
||||
if($r[0]['is_dir'])
|
||||
$r[0]['data'] = '';
|
||||
$r[0]['content'] = '';
|
||||
elseif(intval($r[0]['os_storage']))
|
||||
$r[0]['data'] = base64_encode(file_get_contents(dbunescbin($r[0]['data'])));
|
||||
$r[0]['content'] = base64_encode(file_get_contents(dbunescbin($r[0]['content'])));
|
||||
else
|
||||
$r[0]['data'] = base64_encode(dbunescbin($r[0]['data']));
|
||||
$r[0]['content'] = base64_encode(dbunescbin($r[0]['content']));
|
||||
|
||||
$ret = array('attach' => $r[0]);
|
||||
json_return_and_die($ret);
|
||||
@@ -649,16 +647,16 @@ require_once('include/api_auth.php');
|
||||
if (api_user()===false) return false;
|
||||
if(! $_REQUEST['photo_id']) return false;
|
||||
$scale = ((array_key_exists('scale',$_REQUEST)) ? intval($_REQUEST['scale']) : 0);
|
||||
$r = q("select * from photo where uid = %d and resource_id = '%s' and scale = %d limit 1",
|
||||
$r = q("select * from photo where uid = %d and resource_id = '%s' and imgscale = %d limit 1",
|
||||
intval(local_channel()),
|
||||
dbesc($_REQUEST['photo_id']),
|
||||
intval($scale)
|
||||
);
|
||||
if($r) {
|
||||
$data = dbunescbin($r[0]['data']);
|
||||
$data = dbunescbin($r[0]['content']);
|
||||
if(array_key_exists('os_storage',$r[0]) && intval($r[0]['os_storage']))
|
||||
$data = file_get_contents($data);
|
||||
$r[0]['data'] = base64_encode($data);
|
||||
$r[0]['content'] = base64_encode($data);
|
||||
$ret = array('photo' => $r[0]);
|
||||
$i = q("select id from item where uid = %d and resource_type = 'photo' and resource_id = '%s' limit 1",
|
||||
intval(local_channel()),
|
||||
@@ -1904,13 +1902,17 @@ require_once('include/api_auth.php');
|
||||
|
||||
//logger('api_format_items: ' . print_r($user_info,true));
|
||||
|
||||
$a = get_app();
|
||||
$ret = array();
|
||||
|
||||
$x = array('items' => $r,'api_user' => api_user(),'user_info' => $user_info);
|
||||
call_hooks('api_format_items',$x);
|
||||
$r = $x['items'];
|
||||
|
||||
if(! $r)
|
||||
return $ret;
|
||||
|
||||
foreach($r as $item) {
|
||||
|
||||
localize_item($item);
|
||||
|
||||
$status_user = (($item['author_xchan']==$user_info['guid'])?$user_info: api_item_get_user($a,$item));
|
||||
@@ -2107,10 +2109,10 @@ require_once('include/api_auth.php');
|
||||
'private' => $private, 'textlimit' => $textlimit, 'sslserver' => $sslserver, 'ssl' => $ssl,
|
||||
'shorturllength' => '30',
|
||||
'hubzilla' => array(
|
||||
'PLATFORM_NAME' => Zotlabs\Project\System::get_platform_name(),
|
||||
'STD_VERSION' => Zotlabs\Project\System::get_project_version(),
|
||||
'PLATFORM_NAME' => Zotlabs\Lib\System::get_platform_name(),
|
||||
'STD_VERSION' => Zotlabs\Lib\System::get_project_version(),
|
||||
'ZOT_REVISION' => ZOT_REVISION,
|
||||
'DB_UPDATE_VERSION' => Zotlabs\Project\System::get_update_version()
|
||||
'DB_UPDATE_VERSION' => Zotlabs\Lib\System::get_update_version()
|
||||
)
|
||||
));
|
||||
|
||||
@@ -2143,12 +2145,12 @@ require_once('include/api_auth.php');
|
||||
|
||||
if($type === 'xml') {
|
||||
header("Content-type: application/xml");
|
||||
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n" . '<version>' . Zotlabs\Project\System::get_project_version() . '</version>' . "\r\n";
|
||||
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n" . '<version>' . Zotlabs\Lib\System::get_project_version() . '</version>' . "\r\n";
|
||||
killme();
|
||||
}
|
||||
elseif($type === 'json') {
|
||||
header("Content-type: application/json");
|
||||
echo '"' . Zotlabs\Project\System::get_project_version() . '"';
|
||||
echo '"' . Zotlabs\Lib\System::get_project_version() . '"';
|
||||
killme();
|
||||
}
|
||||
}
|
||||
|
||||
658
include/apps.php
658
include/apps.php
@@ -1,658 +0,0 @@
|
||||
<?php /** @file */
|
||||
|
||||
/**
|
||||
* apps
|
||||
*
|
||||
*/
|
||||
|
||||
require_once('include/plugin.php');
|
||||
require_once('include/identity.php');
|
||||
|
||||
function get_system_apps($translate = true) {
|
||||
|
||||
$ret = array();
|
||||
if(is_dir('apps'))
|
||||
$files = glob('apps/*.apd');
|
||||
else
|
||||
$files = glob('app/*.apd');
|
||||
if($files) {
|
||||
foreach($files as $f) {
|
||||
$x = parse_app_description($f,$translate);
|
||||
if($x) {
|
||||
$ret[] = $x;
|
||||
}
|
||||
}
|
||||
}
|
||||
$files = glob('addon/*/*.apd');
|
||||
if($files) {
|
||||
foreach($files as $f) {
|
||||
$n = basename($f,'.apd');
|
||||
if(plugin_is_installed($n)) {
|
||||
$x = parse_app_description($f,$translate);
|
||||
if($x) {
|
||||
$ret[] = $x;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function import_system_apps() {
|
||||
if(! local_channel())
|
||||
return;
|
||||
|
||||
// Eventually we want to look at modification dates and update system apps.
|
||||
|
||||
$installed = get_pconfig(local_channel(),'system','apps_installed');
|
||||
if($installed)
|
||||
return;
|
||||
$apps = get_system_apps(false);
|
||||
if($apps) {
|
||||
foreach($apps as $app) {
|
||||
$app['uid'] = local_channel();
|
||||
$app['guid'] = hash('whirlpool',$app['name']);
|
||||
$app['system'] = 1;
|
||||
app_install(local_channel(),$app);
|
||||
}
|
||||
}
|
||||
set_pconfig(local_channel(),'system','apps_installed',1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function app_name_compare($a,$b) {
|
||||
return strcmp($a['name'],$b['name']);
|
||||
}
|
||||
|
||||
|
||||
function parse_app_description($f,$translate = true) {
|
||||
$ret = array();
|
||||
|
||||
$baseurl = z_root();
|
||||
$channel = App::get_channel();
|
||||
$address = (($channel) ? $channel['channel_address'] : '');
|
||||
|
||||
//future expansion
|
||||
|
||||
$observer = App::get_observer();
|
||||
|
||||
|
||||
$lines = @file($f);
|
||||
if($lines) {
|
||||
foreach($lines as $x) {
|
||||
if(preg_match('/^([a-zA-Z].*?):(.*?)$/ism',$x,$matches)) {
|
||||
$ret[$matches[1]] = trim(str_replace(array('$baseurl','$nick'),array($baseurl,$address),$matches[2]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(! $ret['photo'])
|
||||
$ret['photo'] = $baseurl . '/' . get_default_profile_photo(80);
|
||||
|
||||
$ret['type'] = 'system';
|
||||
|
||||
foreach($ret as $k => $v) {
|
||||
if(strpos($v,'http') === 0)
|
||||
$ret[$k] = zid($v);
|
||||
}
|
||||
|
||||
if(array_key_exists('desc',$ret))
|
||||
$ret['desc'] = str_replace(array('\'','"'),array(''','&dquot;'),$ret['desc']);
|
||||
|
||||
if(array_key_exists('target',$ret))
|
||||
$ret['target'] = str_replace(array('\'','"'),array(''','&dquot;'),$ret['target']);
|
||||
|
||||
if(array_key_exists('requires',$ret)) {
|
||||
$requires = explode(',',$ret['requires']);
|
||||
foreach($requires as $require) {
|
||||
$require = trim(strtolower($require));
|
||||
switch($require) {
|
||||
case 'nologin':
|
||||
if(local_channel())
|
||||
unset($ret);
|
||||
break;
|
||||
case 'admin':
|
||||
if(! is_site_admin())
|
||||
unset($ret);
|
||||
break;
|
||||
case 'local_channel':
|
||||
if(! local_channel())
|
||||
unset($ret);
|
||||
break;
|
||||
case 'public_profile':
|
||||
if(! is_public_profile())
|
||||
unset($ret);
|
||||
break;
|
||||
case 'observer':
|
||||
if(! $observer)
|
||||
unset($ret);
|
||||
break;
|
||||
default:
|
||||
if(! (local_channel() && feature_enabled(local_channel(),$require)))
|
||||
unset($ret);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if($ret) {
|
||||
if($translate)
|
||||
translate_system_apps($ret);
|
||||
return $ret;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function translate_system_apps(&$arr) {
|
||||
$apps = array(
|
||||
'Site Admin' => t('Site Admin'),
|
||||
'Bug Report' => t('Bug Report'),
|
||||
'View Bookmarks' => t('View Bookmarks'),
|
||||
'My Chatrooms' => t('My Chatrooms'),
|
||||
'Connections' => t('Connections'),
|
||||
'Firefox Share' => t('Firefox Share'),
|
||||
'Remote Diagnostics' => t('Remote Diagnostics'),
|
||||
'Suggest Channels' => t('Suggest Channels'),
|
||||
'Login' => t('Login'),
|
||||
'Channel Manager' => t('Channel Manager'),
|
||||
'Grid' => t('Grid'),
|
||||
'Settings' => t('Settings'),
|
||||
'Files' => t('Files'),
|
||||
'Webpages' => t('Webpages'),
|
||||
'Channel Home' => t('Channel Home'),
|
||||
'View Profile' => t('View Profile'),
|
||||
'Photos' => t('Photos'),
|
||||
'Events' => t('Events'),
|
||||
'Directory' => t('Directory'),
|
||||
'Help' => t('Help'),
|
||||
'Mail' => t('Mail'),
|
||||
'Mood' => t('Mood'),
|
||||
'Poke' => t('Poke'),
|
||||
'Chat' => t('Chat'),
|
||||
'Search' => t('Search'),
|
||||
'Probe' => t('Probe'),
|
||||
'Suggest' => t('Suggest'),
|
||||
'Random Channel' => t('Random Channel'),
|
||||
'Invite' => t('Invite'),
|
||||
'Features' => t('Features'),
|
||||
'Language' => t('Language'),
|
||||
'Post' => t('Post'),
|
||||
'Profile Photo' => t('Profile Photo')
|
||||
);
|
||||
|
||||
if(array_key_exists($arr['name'],$apps))
|
||||
$arr['name'] = $apps[$arr['name']];
|
||||
|
||||
}
|
||||
|
||||
|
||||
// papp is a portable app
|
||||
|
||||
function app_render($papp,$mode = 'view') {
|
||||
|
||||
/**
|
||||
* modes:
|
||||
* view: normal mode for viewing an app via bbcode from a conversation or page
|
||||
* provides install/update button if you're logged in locally
|
||||
* list: normal mode for viewing an app on the app page
|
||||
* no buttons are shown
|
||||
* edit: viewing the app page in editing mode provides a delete button
|
||||
*/
|
||||
|
||||
$installed = false;
|
||||
|
||||
if(! $papp)
|
||||
return;
|
||||
|
||||
if(! $papp['photo'])
|
||||
$papp['photo'] = z_root() . '/' . get_default_profile_photo(80);
|
||||
|
||||
|
||||
|
||||
$papp['papp'] = papp_encode($papp);
|
||||
|
||||
if(! strstr($papp['url'],'://'))
|
||||
$papp['url'] = z_root() . ((strpos($papp['url'],'/') === 0) ? '' : '/') . $papp['url'];
|
||||
|
||||
foreach($papp as $k => $v) {
|
||||
if(strpos($v,'http') === 0 && $k != 'papp')
|
||||
$papp[$k] = zid($v);
|
||||
if($k === 'desc')
|
||||
$papp['desc'] = str_replace(array('\'','"'),array(''','&dquot;'),$papp['desc']);
|
||||
|
||||
if($k === 'requires') {
|
||||
$requires = explode(',',$v);
|
||||
foreach($requires as $require) {
|
||||
$require = trim(strtolower($require));
|
||||
switch($require) {
|
||||
case 'nologin':
|
||||
if(local_channel())
|
||||
return '';
|
||||
break;
|
||||
case 'admin':
|
||||
if(! is_site_admin())
|
||||
return '';
|
||||
break;
|
||||
case 'local_channel':
|
||||
if(! local_channel())
|
||||
return '';
|
||||
break;
|
||||
case 'public_profile':
|
||||
if(! is_public_profile())
|
||||
return '';
|
||||
break;
|
||||
case 'observer':
|
||||
$observer = App::get_observer();
|
||||
if(! $observer)
|
||||
return '';
|
||||
break;
|
||||
default:
|
||||
if(! (local_channel() && feature_enabled(local_channel(),$require)))
|
||||
return '';
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$hosturl = '';
|
||||
|
||||
if(local_channel()) {
|
||||
$installed = app_installed(local_channel(),$papp);
|
||||
$hosturl = z_root() . '/';
|
||||
}
|
||||
elseif(remote_channel()) {
|
||||
$observer = App::get_observer();
|
||||
if($observer && $observer['xchan_network'] === 'zot') {
|
||||
// some folks might have xchan_url redirected offsite, use the connurl
|
||||
$x = parse_url($observer['xchan_connurl']);
|
||||
if($x) {
|
||||
$hosturl = $x['scheme'] . '://' . $x['host'] . '/';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$install_action = (($installed) ? t('Update') : t('Install'));
|
||||
|
||||
return replace_macros(get_markup_template('app.tpl'),array(
|
||||
'$app' => $papp,
|
||||
'$hosturl' => $hosturl,
|
||||
'$purchase' => (($papp['page'] && (! $installed)) ? t('Purchase') : ''),
|
||||
'$install' => (($hosturl && $mode == 'view') ? $install_action : ''),
|
||||
'$edit' => ((local_channel() && $installed && $mode == 'edit') ? t('Edit') : ''),
|
||||
'$delete' => ((local_channel() && $installed && $mode == 'edit') ? t('Delete') : '')
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
function app_install($uid,$app) {
|
||||
$app['uid'] = $uid;
|
||||
|
||||
if(app_installed($uid,$app))
|
||||
$x = app_update($app);
|
||||
else
|
||||
$x = app_store($app);
|
||||
|
||||
if($x['success']) {
|
||||
$r = q("select * from app where app_id = '%s' and app_channel = %d limit 1",
|
||||
dbesc($x['app_id']),
|
||||
intval($uid)
|
||||
);
|
||||
if($r) {
|
||||
if(! $r[0]['app_system']) {
|
||||
if($app['categories'] && (! $app['term'])) {
|
||||
$r[0]['term'] = q("select * from term where otype = %d and oid = d",
|
||||
intval(TERM_OBJ_APP),
|
||||
intval($r[0]['id'])
|
||||
);
|
||||
build_sync_packet($uid,array('app' => $r[0]));
|
||||
}
|
||||
}
|
||||
}
|
||||
return $x['app_id'];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function app_destroy($uid,$app) {
|
||||
|
||||
|
||||
if($uid && $app['guid']) {
|
||||
|
||||
$x = q("select * from app where app_id = '%s' and app_channel = %d limit 1",
|
||||
dbesc($app['guid']),
|
||||
intval($uid)
|
||||
);
|
||||
if($x) {
|
||||
$x[0]['app_deleted'] = 1;
|
||||
q("delete from term where otype = %d and oid = %d",
|
||||
intval(TERM_OBJ_APP),
|
||||
intval($x[0]['id'])
|
||||
);
|
||||
if($x[0]['app_system']) {
|
||||
$r = q("update app set app_deleted = 1 where app_id = '%s' and app_channel = %d",
|
||||
dbesc($app['guid']),
|
||||
intval($uid)
|
||||
);
|
||||
}
|
||||
else {
|
||||
$r = q("delete from app where app_id = '%s' and app_channel = %d",
|
||||
dbesc($app['guid']),
|
||||
intval($uid)
|
||||
);
|
||||
|
||||
// we don't sync system apps - they may be completely different on the other system
|
||||
build_sync_packet($uid,array('app' => $x));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function app_installed($uid,$app) {
|
||||
|
||||
$r = q("select id from app where app_id = '%s' and app_version = '%s' and app_channel = %d limit 1",
|
||||
dbesc((array_key_exists('guid',$app)) ? $app['guid'] : ''),
|
||||
dbesc((array_key_exists('version',$app)) ? $app['version'] : ''),
|
||||
intval($uid)
|
||||
);
|
||||
return(($r) ? true : false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function app_list($uid, $deleted = false, $cat = '') {
|
||||
if($deleted)
|
||||
$sql_extra = " and app_deleted = 1 ";
|
||||
else
|
||||
$sql_extra = " and app_deleted = 0 ";
|
||||
|
||||
if($cat) {
|
||||
$r = q("select oid from term where otype = %d and term = '%s'",
|
||||
intval(TERM_OBJ_APP),
|
||||
dbesc($cat)
|
||||
);
|
||||
if(! $r)
|
||||
return $r;
|
||||
$sql_extra .= " and app.id in ( ";
|
||||
$s = '';
|
||||
foreach($r as $rr) {
|
||||
if($s)
|
||||
$s .= ',';
|
||||
$s .= intval($rr['oid']);
|
||||
}
|
||||
$sql_extra .= $s . ') ';
|
||||
}
|
||||
|
||||
$r = q("select * from app where app_channel = %d $sql_extra order by app_name asc",
|
||||
intval($uid)
|
||||
);
|
||||
if($r) {
|
||||
for($x = 0; $x < count($r); $x ++) {
|
||||
if(! $r[$x]['app_system'])
|
||||
$r[$x]['type'] = 'personal';
|
||||
$r[$x]['term'] = q("select * from term where otype = %d and oid = %d",
|
||||
intval(TERM_OBJ_APP),
|
||||
intval($r[$x]['id'])
|
||||
);
|
||||
}
|
||||
}
|
||||
return($r);
|
||||
}
|
||||
|
||||
|
||||
function app_decode($s) {
|
||||
$x = base64_decode(str_replace(array('<br />',"\r","\n",' '),array('','','',''),$s));
|
||||
return json_decode($x,true);
|
||||
}
|
||||
|
||||
|
||||
function app_store($arr) {
|
||||
|
||||
// logger('app_store: ' . print_r($arr,true));
|
||||
|
||||
$darray = array();
|
||||
$ret = array('success' => false);
|
||||
|
||||
$darray['app_url'] = ((x($arr,'url')) ? $arr['url'] : '');
|
||||
$darray['app_channel'] = ((x($arr,'uid')) ? $arr['uid'] : 0);
|
||||
|
||||
if((! $darray['app_url']) || (! $darray['app_channel']))
|
||||
return $ret;
|
||||
|
||||
if($arr['photo'] && ! strstr($arr['photo'],z_root())) {
|
||||
$x = import_xchan_photo($arr['photo'],get_observer_hash(),true);
|
||||
$arr['photo'] = $x[1];
|
||||
}
|
||||
|
||||
|
||||
$darray['app_id'] = ((x($arr,'guid')) ? $arr['guid'] : random_string(). '.' . App::get_hostname());
|
||||
$darray['app_sig'] = ((x($arr,'sig')) ? $arr['sig'] : '');
|
||||
$darray['app_author'] = ((x($arr,'author')) ? $arr['author'] : get_observer_hash());
|
||||
$darray['app_name'] = ((x($arr,'name')) ? escape_tags($arr['name']) : t('Unknown'));
|
||||
$darray['app_desc'] = ((x($arr,'desc')) ? escape_tags($arr['desc']) : '');
|
||||
$darray['app_photo'] = ((x($arr,'photo')) ? $arr['photo'] : z_root() . '/' . get_default_profile_photo(80));
|
||||
$darray['app_version'] = ((x($arr,'version')) ? escape_tags($arr['version']) : '');
|
||||
$darray['app_addr'] = ((x($arr,'addr')) ? escape_tags($arr['addr']) : '');
|
||||
$darray['app_price'] = ((x($arr,'price')) ? escape_tags($arr['price']) : '');
|
||||
$darray['app_page'] = ((x($arr,'page')) ? escape_tags($arr['page']) : '');
|
||||
$darray['app_requires'] = ((x($arr,'requires')) ? escape_tags($arr['requires']) : '');
|
||||
$darray['app_system'] = ((x($arr,'system')) ? intval($arr['system']) : 0);
|
||||
$darray['app_deleted'] = ((x($arr,'deleted')) ? intval($arr['deleted']) : 0);
|
||||
|
||||
$created = datetime_convert();
|
||||
|
||||
$r = q("insert into app ( app_id, app_sig, app_author, app_name, app_desc, app_url, app_photo, app_version, app_channel, app_addr, app_price, app_page, app_requires, app_created, app_edited, app_system, app_deleted ) values ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d )",
|
||||
dbesc($darray['app_id']),
|
||||
dbesc($darray['app_sig']),
|
||||
dbesc($darray['app_author']),
|
||||
dbesc($darray['app_name']),
|
||||
dbesc($darray['app_desc']),
|
||||
dbesc($darray['app_url']),
|
||||
dbesc($darray['app_photo']),
|
||||
dbesc($darray['app_version']),
|
||||
intval($darray['app_channel']),
|
||||
dbesc($darray['app_addr']),
|
||||
dbesc($darray['app_price']),
|
||||
dbesc($darray['app_page']),
|
||||
dbesc($darray['app_requires']),
|
||||
dbesc($created),
|
||||
dbesc($created),
|
||||
intval($darray['app_system']),
|
||||
intval($darray['app_deleted'])
|
||||
);
|
||||
if($r) {
|
||||
$ret['success'] = true;
|
||||
$ret['app_id'] = $darray['app_id'];
|
||||
}
|
||||
if($arr['categories']) {
|
||||
$x = q("select id from app where app_id = '%s' and app_channel = %d limit 1",
|
||||
dbesc($darray['app_id']),
|
||||
intval($darray['app_channel'])
|
||||
);
|
||||
$y = explode(',',$arr['categories']);
|
||||
if($y) {
|
||||
foreach($y as $t) {
|
||||
$t = trim($t);
|
||||
if($t) {
|
||||
store_item_tag($darray['app_channel'],$x[0]['id'],TERM_OBJ_APP,TERM_CATEGORY,escape_tags($t),escape_tags(z_root() . '/apps/?f=&cat=' . escape_tags($t)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
function app_update($arr) {
|
||||
|
||||
$darray = array();
|
||||
$ret = array('success' => false);
|
||||
|
||||
$darray['app_url'] = ((x($arr,'url')) ? $arr['url'] : '');
|
||||
$darray['app_channel'] = ((x($arr,'uid')) ? $arr['uid'] : 0);
|
||||
$darray['app_id'] = ((x($arr,'guid')) ? $arr['guid'] : 0);
|
||||
|
||||
if((! $darray['app_url']) || (! $darray['app_channel']) || (! $darray['app_id']))
|
||||
return $ret;
|
||||
|
||||
if($arr['photo'] && ! strstr($arr['photo'],z_root())) {
|
||||
$x = import_xchan_photo($arr['photo'],get_observer_hash(),true);
|
||||
$arr['photo'] = $x[1];
|
||||
}
|
||||
|
||||
$darray['app_sig'] = ((x($arr,'sig')) ? $arr['sig'] : '');
|
||||
$darray['app_author'] = ((x($arr,'author')) ? $arr['author'] : get_observer_hash());
|
||||
$darray['app_name'] = ((x($arr,'name')) ? escape_tags($arr['name']) : t('Unknown'));
|
||||
$darray['app_desc'] = ((x($arr,'desc')) ? escape_tags($arr['desc']) : '');
|
||||
$darray['app_photo'] = ((x($arr,'photo')) ? $arr['photo'] : z_root() . '/' . get_default_profile_photo(80));
|
||||
$darray['app_version'] = ((x($arr,'version')) ? escape_tags($arr['version']) : '');
|
||||
$darray['app_addr'] = ((x($arr,'addr')) ? escape_tags($arr['addr']) : '');
|
||||
$darray['app_price'] = ((x($arr,'price')) ? escape_tags($arr['price']) : '');
|
||||
$darray['app_page'] = ((x($arr,'page')) ? escape_tags($arr['page']) : '');
|
||||
$darray['app_requires'] = ((x($arr,'requires')) ? escape_tags($arr['requires']) : '');
|
||||
$darray['app_system'] = ((x($arr,'system')) ? intval($arr['system']) : 0);
|
||||
$darray['app_deleted'] = ((x($arr,'deleted')) ? intval($arr['deleted']) : 0);
|
||||
|
||||
$edited = datetime_convert();
|
||||
|
||||
$r = q("update app set app_sig = '%s', app_author = '%s', app_name = '%s', app_desc = '%s', app_url = '%s', app_photo = '%s', app_version = '%s', app_addr = '%s', app_price = '%s', app_page = '%s', app_requires = '%s', app_edited = '%s', app_system = %d, app_deleted = %d where app_id = '%s' and app_channel = %d",
|
||||
dbesc($darray['app_sig']),
|
||||
dbesc($darray['app_author']),
|
||||
dbesc($darray['app_name']),
|
||||
dbesc($darray['app_desc']),
|
||||
dbesc($darray['app_url']),
|
||||
dbesc($darray['app_photo']),
|
||||
dbesc($darray['app_version']),
|
||||
dbesc($darray['app_addr']),
|
||||
dbesc($darray['app_price']),
|
||||
dbesc($darray['app_page']),
|
||||
dbesc($darray['app_requires']),
|
||||
dbesc($edited),
|
||||
intval($darray['app_system']),
|
||||
intval($darray['app_deleted']),
|
||||
dbesc($darray['app_id']),
|
||||
intval($darray['app_channel'])
|
||||
);
|
||||
if($r) {
|
||||
$ret['success'] = true;
|
||||
$ret['app_id'] = $darray['app_id'];
|
||||
}
|
||||
|
||||
$x = q("select id from app where app_id = '%s' and app_channel = %d limit 1",
|
||||
dbesc($darray['app_id']),
|
||||
intval($darray['app_channel'])
|
||||
);
|
||||
if($x) {
|
||||
q("delete from term where otype = %d and oid = %d",
|
||||
intval(TERM_OBJ_APP),
|
||||
intval($x[0]['id'])
|
||||
);
|
||||
if($arr['categories']) {
|
||||
$y = explode(',',$arr['categories']);
|
||||
if($y) {
|
||||
foreach($y as $t) {
|
||||
$t = trim($t);
|
||||
if($t) {
|
||||
store_item_tag($darray['app_channel'],$x[0]['id'],TERM_OBJ_APP,TERM_CATEGORY,escape_tags($t),escape_tags(z_root() . '/apps/?f=&cat=' . escape_tags($t)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function app_encode($app,$embed = false) {
|
||||
|
||||
$ret = array();
|
||||
|
||||
$ret['type'] = 'personal';
|
||||
|
||||
if($app['app_id'])
|
||||
$ret['guid'] = $app['app_id'];
|
||||
|
||||
if($app['app_id'])
|
||||
$ret['guid'] = $app['app_id'];
|
||||
|
||||
if($app['app_sig'])
|
||||
$ret['sig'] = $app['app_sig'];
|
||||
|
||||
if($app['app_author'])
|
||||
$ret['author'] = $app['app_author'];
|
||||
|
||||
if($app['app_name'])
|
||||
$ret['name'] = $app['app_name'];
|
||||
|
||||
if($app['app_desc'])
|
||||
$ret['desc'] = $app['app_desc'];
|
||||
|
||||
if($app['app_url'])
|
||||
$ret['url'] = $app['app_url'];
|
||||
|
||||
if($app['app_photo'])
|
||||
$ret['photo'] = $app['app_photo'];
|
||||
|
||||
if($app['app_version'])
|
||||
$ret['version'] = $app['app_version'];
|
||||
|
||||
if($app['app_addr'])
|
||||
$ret['addr'] = $app['app_addr'];
|
||||
|
||||
if($app['app_price'])
|
||||
$ret['price'] = $app['app_price'];
|
||||
|
||||
if($app['app_page'])
|
||||
$ret['page'] = $app['app_page'];
|
||||
|
||||
if($app['app_requires'])
|
||||
$ret['requires'] = $app['app_requires'];
|
||||
|
||||
if($app['app_system'])
|
||||
$ret['system'] = $app['app_system'];
|
||||
|
||||
if($app['app_deleted'])
|
||||
$ret['deleted'] = $app['app_deleted'];
|
||||
|
||||
if($app['term']) {
|
||||
$s = '';
|
||||
foreach($app['term'] as $t) {
|
||||
if($s)
|
||||
$s .= ',';
|
||||
$s .= $t['term'];
|
||||
}
|
||||
$ret['categories'] = $s;
|
||||
}
|
||||
|
||||
|
||||
if(! $embed)
|
||||
return $ret;
|
||||
|
||||
if(array_key_exists('categories',$ret))
|
||||
unset($ret['categories']);
|
||||
|
||||
$j = json_encode($ret);
|
||||
return '[app]' . chunk_split(base64_encode($j),72,"\n") . '[/app]';
|
||||
|
||||
}
|
||||
|
||||
|
||||
function papp_encode($papp) {
|
||||
return chunk_split(base64_encode(json_encode($papp)),72,"\n");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -720,7 +720,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
|
||||
$edited = $created;
|
||||
|
||||
if($options === 'replace') {
|
||||
$r = q("update attach set filename = '%s', filetype = '%s', folder = '%s', filesize = %d, os_storage = %d, is_photo = %d, data = '%s', edited = '%s' where id = %d and uid = %d",
|
||||
$r = q("update attach set filename = '%s', filetype = '%s', folder = '%s', filesize = %d, os_storage = %d, is_photo = %d, content = '%s', edited = '%s' where id = %d and uid = %d",
|
||||
dbesc($filename),
|
||||
dbesc($mimetype),
|
||||
dbesc($folder_hash),
|
||||
@@ -734,7 +734,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
|
||||
);
|
||||
}
|
||||
elseif($options === 'revise') {
|
||||
$r = q("insert into attach ( aid, uid, hash, creator, filename, filetype, folder, filesize, revision, os_storage, is_photo, data, created, edited, allow_cid, allow_gid, deny_cid, deny_gid )
|
||||
$r = q("insert into attach ( aid, uid, hash, creator, filename, filetype, folder, filesize, revision, os_storage, is_photo, content, created, edited, allow_cid, allow_gid, deny_cid, deny_gid )
|
||||
VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
|
||||
intval($x[0]['aid']),
|
||||
intval($channel_id),
|
||||
@@ -775,7 +775,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
|
||||
}
|
||||
else {
|
||||
|
||||
$r = q("INSERT INTO attach ( aid, uid, hash, creator, filename, filetype, folder, filesize, revision, os_storage, is_photo, data, created, edited, allow_cid, allow_gid,deny_cid, deny_gid )
|
||||
$r = q("INSERT INTO attach ( aid, uid, hash, creator, filename, filetype, folder, filesize, revision, os_storage, is_photo, content, created, edited, allow_cid, allow_gid,deny_cid, deny_gid )
|
||||
VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
|
||||
intval($channel['channel_account_id']),
|
||||
intval($channel_id),
|
||||
@@ -1032,7 +1032,7 @@ function attach_mkdir($channel, $observer_hash, $arr = null) {
|
||||
|
||||
$created = datetime_convert();
|
||||
|
||||
$r = q("INSERT INTO attach ( aid, uid, hash, creator, filename, filetype, filesize, revision, folder, os_storage, is_dir, data, created, edited, allow_cid, allow_gid, deny_cid, deny_gid )
|
||||
$r = q("INSERT INTO attach ( aid, uid, hash, creator, filename, filetype, filesize, revision, folder, os_storage, is_dir, content, created, edited, allow_cid, allow_gid, deny_cid, deny_gid )
|
||||
VALUES ( %d, %d, '%s', '%s', '%s', '%s', %d, %d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
|
||||
intval($channel['channel_account_id']),
|
||||
intval($channel_id),
|
||||
@@ -1275,16 +1275,16 @@ function attach_delete($channel_id, $resource, $is_photo = 0) {
|
||||
|
||||
// delete a file from filesystem
|
||||
if(intval($r[0]['os_storage'])) {
|
||||
$y = q("SELECT data FROM attach WHERE hash = '%s' AND uid = %d LIMIT 1",
|
||||
$y = q("SELECT content FROM attach WHERE hash = '%s' AND uid = %d LIMIT 1",
|
||||
dbesc($resource),
|
||||
intval($channel_id)
|
||||
);
|
||||
|
||||
if($y) {
|
||||
if(strpos($y[0]['data'],'store') === false)
|
||||
$f = 'store/' . $channel_address . '/' . $y[0]['data'];
|
||||
if(strpos($y[0]['content'],'store') === false)
|
||||
$f = 'store/' . $channel_address . '/' . $y[0]['content'];
|
||||
else
|
||||
$f = $y[0]['data'];
|
||||
$f = $y[0]['content'];
|
||||
|
||||
if(is_dir($f))
|
||||
@rmdir($f);
|
||||
@@ -1585,13 +1585,13 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid,
|
||||
$arr['deny_gid'] = perms2str($u_arr_deny_gid);
|
||||
$arr['item_private'] = $private;
|
||||
$arr['verb'] = ACTIVITY_UPDATE;
|
||||
$arr['object'] = $u_jsonobject;
|
||||
$arr['obj'] = $u_jsonobject;
|
||||
$arr['body'] = '';
|
||||
|
||||
$post = item_store($arr);
|
||||
$item_id = $post['item_id'];
|
||||
if($item_id) {
|
||||
proc_run('php',"include/notifier.php","activity",$item_id);
|
||||
Zotlabs\Daemon\Master::Summon(array('Notifier','activity',$item_id));
|
||||
}
|
||||
|
||||
call_hooks('post_local_end', $arr);
|
||||
@@ -1620,14 +1620,14 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid,
|
||||
$arr['deny_gid'] = perms2str($arr_deny_gid);
|
||||
$arr['item_private'] = $private;
|
||||
$arr['verb'] = (($update) ? ACTIVITY_UPDATE : ACTIVITY_POST);
|
||||
$arr['object'] = (($update) ? $u_jsonobject : $jsonobject);
|
||||
$arr['obj'] = (($update) ? $u_jsonobject : $jsonobject);
|
||||
$arr['body'] = '';
|
||||
|
||||
$post = item_store($arr);
|
||||
$item_id = $post['item_id'];
|
||||
|
||||
if($item_id) {
|
||||
proc_run('php',"include/notifier.php","activity",$item_id);
|
||||
Zotlabs\Daemon\Master::Summon(array('Notifier','activity',$item_id));
|
||||
}
|
||||
|
||||
call_hooks('post_local_end', $arr);
|
||||
@@ -1854,21 +1854,19 @@ function attach_export_data($channel, $resource_id, $deleted = false) {
|
||||
} while($hash_ptr);
|
||||
|
||||
|
||||
|
||||
|
||||
$paths = array_reverse($paths);
|
||||
|
||||
$ret['attach'] = $paths;
|
||||
|
||||
|
||||
if($attach_ptr['is_photo']) {
|
||||
$r = q("select * from photo where resource_id = '%s' and uid = %d order by scale asc",
|
||||
$r = q("select * from photo where resource_id = '%s' and uid = %d order by imgscale asc",
|
||||
dbesc($resource_id),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
if($r) {
|
||||
for($x = 0; $x < count($r); $x ++) {
|
||||
$r[$x]['data'] = base64_encode($r[$x]['data']);
|
||||
$r[$x]['content'] = base64_encode($r[$x]['content']);
|
||||
}
|
||||
$ret['photo'] = $r;
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ if((isset($_SESSION)) && (x($_SESSION, 'authenticated')) &&
|
||||
// process logout request
|
||||
$args = array('channel_id' => local_channel());
|
||||
call_hooks('logging_out', $args);
|
||||
\Zotlabs\Web\Session::nuke();
|
||||
App::$session->nuke();
|
||||
info( t('Logged out.') . EOL);
|
||||
goaway(z_root());
|
||||
}
|
||||
@@ -117,7 +117,7 @@ if((isset($_SESSION)) && (x($_SESSION, 'authenticated')) &&
|
||||
intval(ACCOUNT_ROLE_ADMIN)
|
||||
);
|
||||
if($x) {
|
||||
\Zotlabs\Web\Session::new_cookie(60 * 60 * 24); // one day
|
||||
App::$session->new_cookie(60 * 60 * 24); // one day
|
||||
$_SESSION['last_login_date'] = datetime_convert();
|
||||
unset($_SESSION['visitor_id']); // no longer a visitor
|
||||
authenticate_success($x[0], true, true);
|
||||
@@ -141,7 +141,7 @@ if((isset($_SESSION)) && (x($_SESSION, 'authenticated')) &&
|
||||
|
||||
if(x($_SESSION, 'uid') || x($_SESSION, 'account_id')) {
|
||||
|
||||
Zotlabs\Web\Session::return_check();
|
||||
App::$session->return_check();
|
||||
|
||||
$r = q("select * from account where account_id = %d limit 1",
|
||||
intval($_SESSION['account_id'])
|
||||
@@ -155,14 +155,14 @@ if((isset($_SESSION)) && (x($_SESSION, 'authenticated')) &&
|
||||
}
|
||||
if(strcmp(datetime_convert('UTC','UTC','now - 12 hours'), $_SESSION['last_login_date']) > 0 ) {
|
||||
$_SESSION['last_login_date'] = datetime_convert();
|
||||
Zotlabs\Web\Session::extend_cookie();
|
||||
App::$session->extend_cookie();
|
||||
$login_refresh = true;
|
||||
}
|
||||
authenticate_success($r[0], false, false, false, $login_refresh);
|
||||
}
|
||||
else {
|
||||
$_SESSION['account_id'] = 0;
|
||||
\Zotlabs\Web\Session::nuke();
|
||||
App::$session->nuke();
|
||||
goaway(z_root());
|
||||
}
|
||||
} // end logged in user returning
|
||||
@@ -170,7 +170,7 @@ if((isset($_SESSION)) && (x($_SESSION, 'authenticated')) &&
|
||||
else {
|
||||
|
||||
if(isset($_SESSION)) {
|
||||
\Zotlabs\Web\Session::nuke();
|
||||
App::$session->nuke();
|
||||
}
|
||||
|
||||
// handle a fresh login request
|
||||
@@ -242,11 +242,11 @@ else {
|
||||
|
||||
if($_POST['remember_me']) {
|
||||
$_SESSION['remember_me'] = 1;
|
||||
\Zotlabs\Web\Session::new_cookie(31449600); // one year
|
||||
App::$session->new_cookie(31449600); // one year
|
||||
}
|
||||
else {
|
||||
$_SESSION['remember_me'] = 0;
|
||||
\Zotlabs\Web\Session::new_cookie(0); // 0 means delete on browser exit
|
||||
App::$session->new_cookie(0); // 0 means delete on browser exit
|
||||
}
|
||||
|
||||
// if we haven't failed up this point, log them in.
|
||||
|
||||
@@ -479,8 +479,6 @@ function unescape_underscores_in_links($m) {
|
||||
|
||||
function format_event_diaspora($ev) {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
if(! ((is_array($ev)) && count($ev)))
|
||||
return '';
|
||||
|
||||
|
||||
@@ -165,11 +165,10 @@ function bb_parse_crypt($match) {
|
||||
}
|
||||
|
||||
function bb_parse_app($match) {
|
||||
require_once('include/apps.php');
|
||||
|
||||
$app = app_decode($match[1]);
|
||||
$app = Zotlabs\Lib\Apps::app_decode($match[1]);
|
||||
if ($app)
|
||||
return app_render($app);
|
||||
return Zotlabs\Lib\Apps::app_render($app);
|
||||
}
|
||||
|
||||
function bb_parse_element($match) {
|
||||
@@ -276,7 +275,6 @@ function bb_location($match) {
|
||||
* @return string HTML iframe with content of $match[1]
|
||||
*/
|
||||
function bb_iframe($match) {
|
||||
$a = get_app();
|
||||
|
||||
$sandbox = ((strpos($match[1], App::get_hostname())) ? ' sandbox="allow-scripts" ' : '');
|
||||
|
||||
@@ -450,8 +448,6 @@ function bb_sanitize_style($input) {
|
||||
|
||||
function bb_observer($Text) {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
$observer = App::get_observer();
|
||||
|
||||
if ((strpos($Text,'[/observer]') !== false) || (strpos($Text,'[/rpost]') !== false)) {
|
||||
@@ -481,9 +477,12 @@ function bb_observer($Text) {
|
||||
return $Text;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function bb_code($match) {
|
||||
if(strpos($match[0], "<br />"))
|
||||
return '<code>' . trim($match[1]) . '</code>';
|
||||
else
|
||||
return '<code class="inline-code">' . trim($match[1]) . '</code>';
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -789,12 +788,9 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false)
|
||||
$Text = preg_replace("/\[font=(.*?)\](.*?)\[\/font\]/sm", "<span style=\"font-family: $1;\">$2</span>", $Text);
|
||||
}
|
||||
|
||||
// Declare the format for [code] layout
|
||||
$CodeLayout = '<code>$1</code>';
|
||||
|
||||
// Check for [code] text
|
||||
if (strpos($Text,'[code]') !== false) {
|
||||
$Text = preg_replace("/\[code\](.*?)\[\/code\]/ism", "$CodeLayout", $Text);
|
||||
$Text = preg_replace_callback("/\[code\](.*?)\[\/code\]/ism", 'bb_code', $Text);
|
||||
}
|
||||
|
||||
// Check for [spoiler] text
|
||||
@@ -985,6 +981,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false)
|
||||
$Text = preg_replace("/\[event\-summary\](.*?)\[\/event\-summary\]/ism",'',$Text);
|
||||
$Text = preg_replace("/\[event\-description\](.*?)\[\/event\-description\]/ism",'',$Text);
|
||||
$Text = preg_replace("/\[event\-finish\](.*?)\[\/event\-finish\]/ism",'',$Text);
|
||||
$Text = preg_replace("/\[event\-id\](.*?)\[\/event\-id\]/ism",'',$Text);
|
||||
$Text = preg_replace("/\[event\-location\](.*?)\[\/event\-location\]/ism",'',$Text);
|
||||
$Text = preg_replace("/\[event\-adjust\](.*?)\[\/event\-adjust\]/ism",'',$Text);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* @file include/identity.php
|
||||
* @file include/channel.php
|
||||
*/
|
||||
|
||||
require_once('include/zot.php');
|
||||
@@ -337,7 +337,7 @@ function create_identity($arr) {
|
||||
// Not checking return value.
|
||||
// It's ok for this to fail if it's an imported channel, and therefore the hash is a duplicate
|
||||
|
||||
$r = q("INSERT INTO profile ( aid, uid, profile_guid, profile_name, is_default, publish, name, photo, thumb)
|
||||
$r = q("INSERT INTO profile ( aid, uid, profile_guid, profile_name, is_default, publish, fullname, photo, thumb)
|
||||
VALUES ( %d, %d, '%s', '%s', %d, %d, '%s', '%s', '%s') ",
|
||||
intval($ret['channel']['channel_account_id']),
|
||||
intval($newuid),
|
||||
@@ -392,7 +392,7 @@ function create_identity($arr) {
|
||||
// if our role_permissions indicate that we're using a default collection ACL, add it.
|
||||
|
||||
if(is_array($role_permissions) && $role_permissions['default_collection']) {
|
||||
$r = q("select hash from groups where uid = %d and name = '%s' limit 1",
|
||||
$r = q("select hash from groups where uid = %d and gname = '%s' limit 1",
|
||||
intval($newuid),
|
||||
dbesc( t('Friends') )
|
||||
);
|
||||
@@ -436,7 +436,7 @@ function create_identity($arr) {
|
||||
|
||||
call_hooks('create_identity', $newuid);
|
||||
|
||||
proc_run('php','include/directory.php', $ret['channel']['channel_id']);
|
||||
Zotlabs\Daemon\Master::Summon(array('Directory', $ret['channel']['channel_id']));
|
||||
}
|
||||
|
||||
$ret['success'] = true;
|
||||
@@ -491,7 +491,7 @@ function identity_basic_export($channel_id, $items = false) {
|
||||
|
||||
// use constants here as otherwise we will have no idea if we can import from a site
|
||||
// with a non-standard platform and version.
|
||||
$ret['compatibility'] = array('project' => PLATFORM_NAME, 'version' => STD_VERSION, 'database' => DB_UPDATE_VERSION, 'server_role' => Zotlabs\Project\System::get_server_role());
|
||||
$ret['compatibility'] = array('project' => PLATFORM_NAME, 'version' => STD_VERSION, 'database' => DB_UPDATE_VERSION, 'server_role' => Zotlabs\Lib\System::get_server_role());
|
||||
|
||||
$r = q("select * from channel where channel_id = %d limit 1",
|
||||
intval($channel_id)
|
||||
@@ -550,18 +550,18 @@ function identity_basic_export($channel_id, $items = false) {
|
||||
if($r)
|
||||
$ret['config'] = $r;
|
||||
|
||||
$r = q("select type, data, os_storage from photo where scale = 4 and photo_usage = %d and uid = %d limit 1",
|
||||
$r = q("select mimetype, content, os_storage from photo where imgscale = 4 and photo_usage = %d and uid = %d limit 1",
|
||||
intval(PHOTO_PROFILE),
|
||||
intval($channel_id)
|
||||
);
|
||||
|
||||
if($r) {
|
||||
$ret['photo'] = array('type' => $r[0]['type'], 'data' => (($r[0]['os_storage']) ? base64url_encode(file_get_contents($r[0]['data'])) : base64url_encode($r[0]['data'])));
|
||||
$ret['photo'] = array('type' => $r[0]['mimetype'], 'data' => (($r[0]['os_storage']) ? base64url_encode(file_get_contents($r[0]['content'])) : base64url_encode($r[0]['content'])));
|
||||
}
|
||||
|
||||
// All other term types will be included in items, if requested.
|
||||
|
||||
$r = q("select * from term where type in (%d,%d) and uid = %d",
|
||||
$r = q("select * from term where ttype in (%d,%d) and uid = %d",
|
||||
intval(TERM_SAVEDSEARCH),
|
||||
intval(TERM_THING),
|
||||
intval($channel_id)
|
||||
@@ -847,7 +847,7 @@ function profile_load(&$a, $nickname, $profile = '') {
|
||||
|
||||
$extra_fields = array();
|
||||
|
||||
require_once('include/identity.php');
|
||||
require_once('include/channel.php');
|
||||
$profile_fields_basic = get_profile_fields_basic();
|
||||
$profile_fields_advanced = get_profile_fields_advanced();
|
||||
|
||||
@@ -1004,8 +1004,6 @@ function profile_sidebar($profile, $block = 0, $show_connect = true, $zcard = fa
|
||||
|
||||
call_hooks('profile_sidebar_enter', $profile);
|
||||
|
||||
require_once('include/Contact.php');
|
||||
|
||||
if($show_connect) {
|
||||
|
||||
// This will return an empty string if we're already connected.
|
||||
@@ -1110,156 +1108,12 @@ function profile_sidebar($profile, $block = 0, $show_connect = true, $zcard = fa
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @FIXME or remove
|
||||
*/
|
||||
function get_birthdays() {
|
||||
|
||||
$o = '';
|
||||
|
||||
if(! local_channel())
|
||||
return $o;
|
||||
|
||||
$bd_format = t('g A l F d') ; // 8 AM Friday January 18
|
||||
$bd_short = t('F d');
|
||||
|
||||
$r = q("SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event`
|
||||
LEFT JOIN `contact` ON `contact`.`id` = `event`.`cid`
|
||||
WHERE `event`.`uid` = %d AND `type` = 'birthday' AND `start` < '%s' AND `finish` > '%s'
|
||||
ORDER BY `start` ASC ",
|
||||
intval(local_channel()),
|
||||
dbesc(datetime_convert('UTC','UTC','now + 6 days')),
|
||||
dbesc(datetime_convert('UTC','UTC','now'))
|
||||
);
|
||||
|
||||
if($r && count($r)) {
|
||||
$total = 0;
|
||||
$now = strtotime('now');
|
||||
$cids = array();
|
||||
|
||||
$istoday = false;
|
||||
foreach($r as $rr) {
|
||||
if(strlen($rr['name']))
|
||||
$total ++;
|
||||
if((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now))
|
||||
$istoday = true;
|
||||
}
|
||||
$classtoday = $istoday ? ' birthday-today ' : '';
|
||||
if($total) {
|
||||
foreach($r as &$rr) {
|
||||
if(! strlen($rr['name']))
|
||||
continue;
|
||||
|
||||
// avoid duplicates
|
||||
|
||||
if(in_array($rr['cid'],$cids))
|
||||
continue;
|
||||
$cids[] = $rr['cid'];
|
||||
|
||||
$today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
|
||||
$sparkle = '';
|
||||
$url = $rr['url'];
|
||||
if($rr['network'] === NETWORK_DFRN) {
|
||||
$sparkle = " sparkle";
|
||||
$url = z_root() . '/redir/' . $rr['cid'];
|
||||
}
|
||||
|
||||
$rr['link'] = $url;
|
||||
$rr['title'] = $rr['name'];
|
||||
$rr['date'] = day_translate(datetime_convert('UTC', App::$timezone, $rr['start'], $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ? ' ' . t('[today]') : '');
|
||||
$rr['startime'] = Null;
|
||||
$rr['today'] = $today;
|
||||
}
|
||||
}
|
||||
}
|
||||
$tpl = get_markup_template("birthdays_reminder.tpl");
|
||||
return replace_macros($tpl, array(
|
||||
'$baseurl' => z_root(),
|
||||
'$classtoday' => $classtoday,
|
||||
'$count' => $total,
|
||||
'$event_reminders' => t('Birthday Reminders'),
|
||||
'$event_title' => t('Birthdays this week:'),
|
||||
'$events' => $r,
|
||||
'$lbr' => '{', // raw brackets mess up if/endif macro processing
|
||||
'$rbr' => '}'
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @FIXME
|
||||
*/
|
||||
function get_events() {
|
||||
|
||||
require_once('include/bbcode.php');
|
||||
|
||||
if(! local_channel())
|
||||
return $o;
|
||||
|
||||
$bd_format = t('g A l F d') ; // 8 AM Friday January 18
|
||||
$bd_short = t('F d');
|
||||
|
||||
$r = q("SELECT `event`.* FROM `event`
|
||||
WHERE `event`.`uid` = %d AND `type` != 'birthday' AND `start` < '%s' AND `start` > '%s'
|
||||
ORDER BY `start` ASC ",
|
||||
intval(local_channel()),
|
||||
dbesc(datetime_convert('UTC','UTC','now + 6 days')),
|
||||
dbesc(datetime_convert('UTC','UTC','now - 1 days'))
|
||||
);
|
||||
|
||||
if($r && count($r)) {
|
||||
$now = strtotime('now');
|
||||
$istoday = false;
|
||||
foreach($r as $rr) {
|
||||
if(strlen($rr['name']))
|
||||
$total ++;
|
||||
|
||||
$strt = datetime_convert('UTC',$rr['convert'] ? App::$timezone : 'UTC',$rr['start'],'Y-m-d');
|
||||
if($strt === datetime_convert('UTC',App::$timezone,'now','Y-m-d'))
|
||||
$istoday = true;
|
||||
}
|
||||
$classtoday = (($istoday) ? 'event-today' : '');
|
||||
|
||||
foreach($r as &$rr) {
|
||||
if($rr['adjust'])
|
||||
$md = datetime_convert('UTC',App::$timezone,$rr['start'],'Y/m');
|
||||
else
|
||||
$md = datetime_convert('UTC','UTC',$rr['start'],'Y/m');
|
||||
$md .= "/#link-".$rr['id'];
|
||||
|
||||
$title = substr(strip_tags(bbcode($rr['desc'])),0,32) . '... ';
|
||||
if(! $title)
|
||||
$title = t('[No description]');
|
||||
|
||||
$strt = datetime_convert('UTC',$rr['convert'] ? App::$timezone : 'UTC',$rr['start']);
|
||||
$today = ((substr($strt,0,10) === datetime_convert('UTC',App::$timezone,'now','Y-m-d')) ? true : false);
|
||||
|
||||
$rr['link'] = $md;
|
||||
$rr['title'] = $title;
|
||||
$rr['date'] = day_translate(datetime_convert('UTC', $rr['adjust'] ? App::$timezone : 'UTC', $rr['start'], $bd_format)) . (($today) ? ' ' . t('[today]') : '');
|
||||
$rr['startime'] = $strt;
|
||||
$rr['today'] = $today;
|
||||
}
|
||||
}
|
||||
|
||||
$tpl = get_markup_template("events_reminder.tpl");
|
||||
return replace_macros($tpl, array(
|
||||
'$baseurl' => z_root(),
|
||||
'$classtoday' => $classtoday,
|
||||
'$count' => count($r),
|
||||
'$event_reminders' => t('Event Reminders'),
|
||||
'$event_title' => t('Events this week:'),
|
||||
'$events' => $r,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
function advanced_profile(&$a) {
|
||||
require_once('include/text.php');
|
||||
if(! perm_is_allowed(App::$profile['profile_uid'],get_observer_hash(),'view_profile'))
|
||||
return '';
|
||||
|
||||
if(App::$profile['name']) {
|
||||
if(App::$profile['fullname']) {
|
||||
|
||||
$profile_fields_basic = get_profile_fields_basic();
|
||||
$profile_fields_advanced = get_profile_fields_advanced();
|
||||
@@ -1283,7 +1137,7 @@ function advanced_profile(&$a) {
|
||||
|
||||
$profile = array();
|
||||
|
||||
$profile['fullname'] = array( t('Full Name:'), App::$profile['name'] ) ;
|
||||
$profile['fullname'] = array( t('Full Name:'), App::$profile['fullname'] ) ;
|
||||
|
||||
if(App::$profile['gender']) $profile['gender'] = array( t('Gender:'), App::$profile['gender'] );
|
||||
|
||||
@@ -1331,8 +1185,8 @@ function advanced_profile(&$a) {
|
||||
if(App::$profile['marital'])
|
||||
$profile['marital'] = array( t('Status:'), App::$profile['marital']);
|
||||
|
||||
if(App::$profile['with'])
|
||||
$profile['marital']['with'] = bbcode(App::$profile['with']);
|
||||
if(App::$profile['partner'])
|
||||
$profile['marital']['partner'] = bbcode(App::$profile['partner']);
|
||||
|
||||
if(strlen(App::$profile['howlong']) && App::$profile['howlong'] !== NULL_DATE) {
|
||||
$profile['howlong'] = relative_date(App::$profile['howlong'], t('for %1$d %2$s'));
|
||||
@@ -1372,7 +1226,7 @@ function advanced_profile(&$a) {
|
||||
|
||||
if($txt = prepare_text(App::$profile['romance'])) $profile['romance'] = array( t('Love/Romance:'), $txt);
|
||||
|
||||
if($txt = prepare_text(App::$profile['work'])) $profile['work'] = array( t('Work/employment:'), $txt);
|
||||
if($txt = prepare_text(App::$profile['employment'])) $profile['employment'] = array( t('Work/employment:'), $txt);
|
||||
|
||||
if($txt = prepare_text(App::$profile['education'])) $profile['education'] = array( t('School/education:'), $txt );
|
||||
|
||||
@@ -1439,7 +1293,7 @@ function get_my_address() {
|
||||
function zid_init(&$a) {
|
||||
$tmp_str = get_my_address();
|
||||
if(validate_email($tmp_str)) {
|
||||
proc_run('php','include/gprobe.php',bin2hex($tmp_str));
|
||||
Zotlabs\Daemon\Master::Summon(array('Gprobe',bin2hex($tmp_str)));
|
||||
$arr = array('zid' => $tmp_str, 'url' => App::$cmd);
|
||||
call_hooks('zid_init',$arr);
|
||||
if(! local_channel()) {
|
||||
@@ -1569,7 +1423,7 @@ function get_online_status($nick) {
|
||||
|
||||
$ret = array('result' => false);
|
||||
|
||||
if(get_config('system','block_public') && ! local_channel() && ! remote_channel())
|
||||
if(observer_prohibited())
|
||||
return $ret;
|
||||
|
||||
$r = q("select channel_id, channel_hash from channel where channel_address = '%s' limit 1",
|
||||
@@ -1660,7 +1514,7 @@ function get_profile_fields_basic($filter = 0) {
|
||||
|
||||
$profile_fields_basic = (($filter == 0) ? get_config('system','profile_fields_basic') : null);
|
||||
if(! $profile_fields_basic)
|
||||
$profile_fields_basic = array('name','pdesc','chandesc','gender','dob','dob_tz','address','locality','region','postal_code','country_name','marital','sexual','homepage','hometown','keywords','about','contact');
|
||||
$profile_fields_basic = array('fullname','pdesc','chandesc','gender','dob','dob_tz','address','locality','region','postal_code','country_name','marital','sexual','homepage','hometown','keywords','about','contact');
|
||||
|
||||
$x = array();
|
||||
if($profile_fields_basic)
|
||||
@@ -1675,7 +1529,7 @@ function get_profile_fields_advanced($filter = 0) {
|
||||
$basic = get_profile_fields_basic($filter);
|
||||
$profile_fields_advanced = (($filter == 0) ? get_config('system','profile_fields_advanced') : null);
|
||||
if(! $profile_fields_advanced)
|
||||
$profile_fields_advanced = array('with','howlong','politic','religion','likes','dislikes','interest','channels','music','book','film','tv','romance','work','education');
|
||||
$profile_fields_advanced = array('partner','howlong','politic','religion','likes','dislikes','interest','channels','music','book','film','tv','romance','employment','education');
|
||||
|
||||
$x = array();
|
||||
if($basic)
|
||||
@@ -1787,7 +1641,7 @@ function auto_channel_create($account_id) {
|
||||
|
||||
function get_cover_photo($channel_id,$format = 'bbcode', $res = PHOTO_RES_COVER_1200) {
|
||||
|
||||
$r = q("select height, width, resource_id, type from photo where uid = %d and scale = %d and photo_usage = %d",
|
||||
$r = q("select height, width, resource_id, mimetype from photo where uid = %d and imgscale = %d and photo_usage = %d",
|
||||
intval($channel_id),
|
||||
intval($res),
|
||||
intval(PHOTO_COVER)
|
||||
@@ -1810,8 +1664,8 @@ function get_cover_photo($channel_id,$format = 'bbcode', $res = PHOTO_RES_COVER_
|
||||
default:
|
||||
$output = array(
|
||||
'width' => $r[0]['width'],
|
||||
'height' => $r[0]['type'],
|
||||
'type' => $r[0]['type'],
|
||||
'height' => $r[0]['height'],
|
||||
'type' => $r[0]['mimetype'],
|
||||
'url' => $url
|
||||
);
|
||||
break;
|
||||
@@ -1836,19 +1690,19 @@ function get_zcard($channel,$observer_hash = '',$args = array()) {
|
||||
$width = 425;
|
||||
$size = 'hz_small';
|
||||
$cover_size = PHOTO_RES_COVER_425;
|
||||
$pphoto = array('type' => $channel['xchan_photo_mimetype'], 'width' => 80 , 'height' => 80, 'href' => $channel['xchan_photo_m']);
|
||||
$pphoto = array('mimetype' => $channel['xchan_photo_mimetype'], 'width' => 80 , 'height' => 80, 'href' => $channel['xchan_photo_m']);
|
||||
}
|
||||
elseif($maxwidth <= 900) {
|
||||
$width = 900;
|
||||
$size = 'hz_medium';
|
||||
$cover_size = PHOTO_RES_COVER_850;
|
||||
$pphoto = array('type' => $channel['xchan_photo_mimetype'], 'width' => 160 , 'height' => 160, 'href' => $channel['xchan_photo_l']);
|
||||
$pphoto = array('mimetype' => $channel['xchan_photo_mimetype'], 'width' => 160 , 'height' => 160, 'href' => $channel['xchan_photo_l']);
|
||||
}
|
||||
elseif($maxwidth <= 1200) {
|
||||
$width = 1200;
|
||||
$size = 'hz_large';
|
||||
$cover_size = PHOTO_RES_COVER_1200;
|
||||
$pphoto = array('type' => $channel['xchan_photo_mimetype'], 'width' => 300 , 'height' => 300, 'href' => $channel['xchan_photo_l']);
|
||||
$pphoto = array('mimetype' => $channel['xchan_photo_mimetype'], 'width' => 300 , 'height' => 300, 'href' => $channel['xchan_photo_l']);
|
||||
}
|
||||
|
||||
// $scale = (float) $maxwidth / $width;
|
||||
@@ -1858,7 +1712,7 @@ function get_zcard($channel,$observer_hash = '',$args = array()) {
|
||||
$channel['channel_addr'] = $channel['channel_address'] . '@' . App::get_hostname();
|
||||
$zcard = array('chan' => $channel);
|
||||
|
||||
$r = q("select height, width, resource_id, scale, type from photo where uid = %d and scale = %d and photo_usage = %d",
|
||||
$r = q("select height, width, resource_id, imgscale, mimetype from photo where uid = %d and imgscale = %d and photo_usage = %d",
|
||||
intval($channel['channel_id']),
|
||||
intval($cover_size),
|
||||
intval(PHOTO_COVER)
|
||||
@@ -1866,7 +1720,7 @@ function get_zcard($channel,$observer_hash = '',$args = array()) {
|
||||
|
||||
if($r) {
|
||||
$cover = $r[0];
|
||||
$cover['href'] = z_root() . '/photo/' . $r[0]['resource_id'] . '-' . $r[0]['scale'];
|
||||
$cover['href'] = z_root() . '/photo/' . $r[0]['resource_id'] . '-' . $r[0]['imgscale'];
|
||||
}
|
||||
else {
|
||||
$cover = $pphoto;
|
||||
@@ -1902,25 +1756,25 @@ function get_zcard_embed($channel,$observer_hash = '',$args = array()) {
|
||||
$width = 425;
|
||||
$size = 'hz_small';
|
||||
$cover_size = PHOTO_RES_COVER_425;
|
||||
$pphoto = array('type' => $channel['xchan_photo_mimetype'], 'width' => 80 , 'height' => 80, 'href' => $channel['xchan_photo_m']);
|
||||
$pphoto = array('mimetype' => $channel['xchan_photo_mimetype'], 'width' => 80 , 'height' => 80, 'href' => $channel['xchan_photo_m']);
|
||||
}
|
||||
elseif($maxwidth <= 900) {
|
||||
$width = 900;
|
||||
$size = 'hz_medium';
|
||||
$cover_size = PHOTO_RES_COVER_850;
|
||||
$pphoto = array('type' => $channel['xchan_photo_mimetype'], 'width' => 160 , 'height' => 160, 'href' => $channel['xchan_photo_l']);
|
||||
$pphoto = array('mimetype' => $channel['xchan_photo_mimetype'], 'width' => 160 , 'height' => 160, 'href' => $channel['xchan_photo_l']);
|
||||
}
|
||||
elseif($maxwidth <= 1200) {
|
||||
$width = 1200;
|
||||
$size = 'hz_large';
|
||||
$cover_size = PHOTO_RES_COVER_1200;
|
||||
$pphoto = array('type' => $channel['xchan_photo_mimetype'], 'width' => 300 , 'height' => 300, 'href' => $channel['xchan_photo_l']);
|
||||
$pphoto = array('mimetype' => $channel['xchan_photo_mimetype'], 'width' => 300 , 'height' => 300, 'href' => $channel['xchan_photo_l']);
|
||||
}
|
||||
|
||||
$channel['channel_addr'] = $channel['channel_address'] . '@' . App::get_hostname();
|
||||
$zcard = array('chan' => $channel);
|
||||
|
||||
$r = q("select height, width, resource_id, scale, type from photo where uid = %d and scale = %d and photo_usage = %d",
|
||||
$r = q("select height, width, resource_id, imgscale, mimetype from photo where uid = %d and imgscale = %d and photo_usage = %d",
|
||||
intval($channel['channel_id']),
|
||||
intval($cover_size),
|
||||
intval(PHOTO_COVER)
|
||||
@@ -1928,7 +1782,7 @@ function get_zcard_embed($channel,$observer_hash = '',$args = array()) {
|
||||
|
||||
if($r) {
|
||||
$cover = $r[0];
|
||||
$cover['href'] = z_root() . '/photo/' . $r[0]['resource_id'] . '-' . $r[0]['scale'];
|
||||
$cover['href'] = z_root() . '/photo/' . $r[0]['resource_id'] . '-' . $r[0]['imgscale'];
|
||||
}
|
||||
else {
|
||||
$cover = $pphoto;
|
||||
@@ -1947,3 +1801,26 @@ function get_zcard_embed($channel,$observer_hash = '',$args = array()) {
|
||||
return $o;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function channelx_by_nick($nick) {
|
||||
$r = q("SELECT * FROM channel left join xchan on channel_hash = xchan_hash WHERE channel_address = '%s' and channel_removed = 0 LIMIT 1",
|
||||
dbesc($nick)
|
||||
);
|
||||
return(($r) ? $r[0] : false);
|
||||
}
|
||||
|
||||
function channelx_by_hash($hash) {
|
||||
$r = q("SELECT * FROM channel left join xchan on channel_hash = xchan_hash WHERE channel_hash = '%s' and channel_removed = 0 LIMIT 1",
|
||||
dbesc($hash)
|
||||
);
|
||||
return(($r) ? $r[0] : false);
|
||||
}
|
||||
|
||||
function channelx_by_n($id) {
|
||||
$r = q("SELECT * FROM channel left join xchan on channel_hash = xchan_hash WHERE channel_id = %d and channel_removed = 0 LIMIT 1",
|
||||
dbesc($id)
|
||||
);
|
||||
return(($r) ? $r[0] : false);
|
||||
}
|
||||
|
||||
262
include/chat.php
262
include/chat.php
@@ -1,262 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @file include/chat.php
|
||||
* @brief Chat related functions.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Creates a chatroom.
|
||||
*
|
||||
* @param array $channel
|
||||
* @param array $arr
|
||||
* @return An associative array containing:
|
||||
* - success: A boolean
|
||||
* - message: (optional) A string
|
||||
*/
|
||||
function chatroom_create($channel, $arr) {
|
||||
|
||||
$ret = array('success' => false);
|
||||
|
||||
$name = trim($arr['name']);
|
||||
if(! $name) {
|
||||
$ret['message'] = t('Missing room name');
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$r = q("select cr_id from chatroom where cr_uid = %d and cr_name = '%s' limit 1",
|
||||
intval($channel['channel_id']),
|
||||
dbesc($name)
|
||||
);
|
||||
if($r) {
|
||||
$ret['message'] = t('Duplicate room name');
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$r = q("select count(cr_id) as total from chatroom where cr_aid = %d",
|
||||
intval($channel['channel_account_id'])
|
||||
);
|
||||
if($r)
|
||||
$limit = service_class_fetch($channel['channel_id'], 'chatrooms');
|
||||
|
||||
if(($r) && ($limit !== false) && ($r[0]['total'] >= $limit)) {
|
||||
$ret['message'] = upgrade_message();
|
||||
return $ret;
|
||||
}
|
||||
|
||||
if(! array_key_exists('expire', $arr))
|
||||
$arr['expire'] = 120; // minutes, e.g. 2 hours
|
||||
|
||||
$created = datetime_convert();
|
||||
|
||||
$x = q("insert into chatroom ( cr_aid, cr_uid, cr_name, cr_created, cr_edited, cr_expire, allow_cid, allow_gid, deny_cid, deny_gid )
|
||||
values ( %d, %d , '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s' ) ",
|
||||
intval($channel['channel_account_id']),
|
||||
intval($channel['channel_id']),
|
||||
dbesc($name),
|
||||
dbesc($created),
|
||||
dbesc($created),
|
||||
intval($arr['expire']),
|
||||
dbesc($arr['allow_cid']),
|
||||
dbesc($arr['allow_gid']),
|
||||
dbesc($arr['deny_cid']),
|
||||
dbesc($arr['deny_gid'])
|
||||
);
|
||||
|
||||
if($x)
|
||||
$ret['success'] = true;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
function chatroom_destroy($channel,$arr) {
|
||||
|
||||
$ret = array('success' => false);
|
||||
|
||||
if(intval($arr['cr_id']))
|
||||
$sql_extra = " and cr_id = " . intval($arr['cr_id']) . " ";
|
||||
elseif(trim($arr['cr_name']))
|
||||
$sql_extra = " and cr_name = '" . protect_sprintf(dbesc(trim($arr['cr_name']))) . "' ";
|
||||
else {
|
||||
$ret['message'] = t('Invalid room specifier.');
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$r = q("select * from chatroom where cr_uid = %d $sql_extra limit 1",
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
if(! $r) {
|
||||
$ret['message'] = t('Invalid room specifier.');
|
||||
return $ret;
|
||||
}
|
||||
|
||||
build_sync_packet($channel['channel_id'],array('chatroom' => $r));
|
||||
|
||||
q("delete from chatroom where cr_id = %d",
|
||||
intval($r[0]['cr_id'])
|
||||
);
|
||||
if($r[0]['cr_id']) {
|
||||
q("delete from chatpresence where cp_room = %d",
|
||||
intval($r[0]['cr_id'])
|
||||
);
|
||||
q("delete from chat where chat_room = %d",
|
||||
intval($r[0]['cr_id'])
|
||||
);
|
||||
}
|
||||
|
||||
$ret['success'] = true;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
function chatroom_enter($observer_xchan, $room_id, $status, $client) {
|
||||
|
||||
if(! $room_id || ! $observer_xchan)
|
||||
return;
|
||||
|
||||
$r = q("select * from chatroom where cr_id = %d limit 1",
|
||||
intval($room_id)
|
||||
);
|
||||
if(! $r) {
|
||||
notice( t('Room not found.') . EOL);
|
||||
return false;
|
||||
}
|
||||
require_once('include/security.php');
|
||||
$sql_extra = permissions_sql($r[0]['cr_uid']);
|
||||
|
||||
$x = q("select * from chatroom where cr_id = %d and cr_uid = %d $sql_extra limit 1",
|
||||
intval($room_id),
|
||||
intval($r[0]['cr_uid'])
|
||||
);
|
||||
if(! $x) {
|
||||
notice( t('Permission denied.') . EOL);
|
||||
return false;
|
||||
}
|
||||
|
||||
$limit = service_class_fetch($r[0]['cr_uid'], 'chatters_inroom');
|
||||
if($limit !== false) {
|
||||
$y = q("select count(*) as total from chatpresence where cp_room = %d",
|
||||
intval($room_id)
|
||||
);
|
||||
if($y && $y[0]['total'] > $limit) {
|
||||
notice( t('Room is full') . EOL);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(intval($x[0]['cr_expire'])) {
|
||||
$r = q("delete from chat where created < %s - INTERVAL %s and chat_room = %d",
|
||||
db_utcnow(),
|
||||
db_quoteinterval( intval($x[0]['cr_expire']) . ' MINUTE' ),
|
||||
intval($x[0]['cr_id'])
|
||||
);
|
||||
}
|
||||
|
||||
$r = q("select * from chatpresence where cp_xchan = '%s' and cp_room = %d limit 1",
|
||||
dbesc($observer_xchan),
|
||||
intval($room_id)
|
||||
);
|
||||
if($r) {
|
||||
q("update chatpresence set cp_last = '%s' where cp_id = %d and cp_client = '%s'",
|
||||
dbesc(datetime_convert()),
|
||||
intval($r[0]['cp_id']),
|
||||
dbesc($client)
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
$r = q("insert into chatpresence ( cp_room, cp_xchan, cp_last, cp_status, cp_client )
|
||||
values ( %d, '%s', '%s', '%s', '%s' )",
|
||||
intval($room_id),
|
||||
dbesc($observer_xchan),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($status),
|
||||
dbesc($client)
|
||||
);
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
|
||||
function chatroom_leave($observer_xchan, $room_id, $client) {
|
||||
if(! $room_id || ! $observer_xchan)
|
||||
return;
|
||||
|
||||
$r = q("select * from chatpresence where cp_xchan = '%s' and cp_room = %d and cp_client = '%s' limit 1",
|
||||
dbesc($observer_xchan),
|
||||
intval($room_id),
|
||||
dbesc($client)
|
||||
);
|
||||
if($r) {
|
||||
q("delete from chatpresence where cp_id = %d",
|
||||
intval($r[0]['cp_id'])
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function chatroom_list($uid) {
|
||||
require_once('include/security.php');
|
||||
$sql_extra = permissions_sql($uid);
|
||||
|
||||
$r = q("select allow_cid, allow_gid, deny_cid, deny_gid, cr_name, cr_expire, cr_id, count(cp_id) as cr_inroom from chatroom left join chatpresence on cr_id = cp_room where cr_uid = %d $sql_extra group by cr_name, cr_id order by cr_name",
|
||||
intval($uid)
|
||||
);
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
function chatroom_list_count($uid) {
|
||||
require_once('include/security.php');
|
||||
$sql_extra = permissions_sql($uid);
|
||||
|
||||
$r = q("select count(*) as total from chatroom where cr_uid = %d $sql_extra",
|
||||
intval($uid)
|
||||
);
|
||||
|
||||
return $r[0]['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* create a chat message via API.
|
||||
* It is the caller's responsibility to enter the room.
|
||||
*/
|
||||
|
||||
function chat_message($uid, $room_id, $xchan, $text) {
|
||||
|
||||
$ret = array('success' => false);
|
||||
|
||||
if(! $text)
|
||||
return;
|
||||
|
||||
$sql_extra = permissions_sql($uid);
|
||||
|
||||
$r = q("select * from chatroom where cr_uid = %d and cr_id = %d $sql_extra",
|
||||
intval($uid),
|
||||
intval($room_id)
|
||||
);
|
||||
if(! $r)
|
||||
return $ret;
|
||||
|
||||
$arr = array(
|
||||
'chat_room' => $room_id,
|
||||
'chat_xchan' => $xchan,
|
||||
'chat_text' => $text
|
||||
);
|
||||
|
||||
call_hooks('chat_message', $arr);
|
||||
|
||||
$x = q("insert into chat ( chat_room, chat_xchan, created, chat_text )
|
||||
values( %d, '%s', '%s', '%s' )",
|
||||
intval($room_id),
|
||||
dbesc($xchan),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($arr['chat_text'])
|
||||
);
|
||||
|
||||
$ret['success'] = true;
|
||||
return $ret;
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
<?php /** @file */
|
||||
|
||||
require_once('boot.php');
|
||||
require_once('include/cli_startup.php');
|
||||
require_once('include/zot.php');
|
||||
require_once('include/hubloc.php');
|
||||
|
||||
|
||||
|
||||
function checksites_run($argv, $argc){
|
||||
|
||||
|
||||
cli_startup();
|
||||
$a = get_app();
|
||||
|
||||
logger('checksites: start');
|
||||
|
||||
if(($argc > 1) && ($argv[1]))
|
||||
$site_id = $argv[1];
|
||||
|
||||
if($site_id)
|
||||
$sql_options = " and site_url = '" . dbesc($argv[1]) . "' ";
|
||||
|
||||
$days = intval(get_config('system','sitecheckdays'));
|
||||
if($days < 1)
|
||||
$days = 30;
|
||||
|
||||
$r = q("select * from site where site_dead = 0 and site_update < %s - INTERVAL %s and site_type = %d $sql_options ",
|
||||
db_utcnow(), db_quoteinterval($days . ' DAY'),
|
||||
intval(SITE_TYPE_ZOT)
|
||||
);
|
||||
|
||||
if(! $r)
|
||||
return;
|
||||
|
||||
foreach($r as $rr) {
|
||||
if(! strcasecmp($rr['site_url'],z_root()))
|
||||
continue;
|
||||
|
||||
$x = ping_site($rr['site_url']);
|
||||
if($x['success']) {
|
||||
logger('checksites: ' . $rr['site_url']);
|
||||
q("update site set site_update = '%s' where site_url = '%s' ",
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($rr['site_url'])
|
||||
);
|
||||
}
|
||||
else {
|
||||
logger('marking dead site: ' . $x['message']);
|
||||
q("update site set site_dead = 1 where site_url = '%s' ",
|
||||
dbesc($rr['site_url'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
checksites_run($argv,$argc);
|
||||
killme();
|
||||
}
|
||||
@@ -6,36 +6,7 @@ require_once('boot.php');
|
||||
|
||||
function cli_startup() {
|
||||
|
||||
global $a, $db, $default_timezone;
|
||||
|
||||
if(is_null($a)) {
|
||||
$a = new miniApp;
|
||||
}
|
||||
|
||||
App::init();
|
||||
|
||||
if(is_null($db)) {
|
||||
@include(".htconfig.php");
|
||||
|
||||
$a->convert();
|
||||
|
||||
if(! defined('UNO'))
|
||||
define('UNO', 0);
|
||||
|
||||
App::$timezone = ((x($default_timezone)) ? $default_timezone : 'UTC');
|
||||
date_default_timezone_set(App::$timezone);
|
||||
|
||||
require_once('include/dba/dba_driver.php');
|
||||
$db = dba_factory($db_host, $db_port, $db_user, $db_pass, $db_data, $db_type);
|
||||
unset($db_host, $db_port, $db_user, $db_pass, $db_data, $db_type);
|
||||
};
|
||||
|
||||
\Zotlabs\Web\Session::init();
|
||||
|
||||
load_config('system');
|
||||
|
||||
sys_boot();
|
||||
App::set_baseurl(get_config('system','baseurl'));
|
||||
|
||||
load_hooks();
|
||||
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
<?php /** @file */
|
||||
|
||||
require_once('boot.php');
|
||||
require_once('include/cli_startup.php');
|
||||
require_once('include/socgraph.php');
|
||||
|
||||
|
||||
function cli_suggest_run($argv, $argc){
|
||||
|
||||
cli_startup();
|
||||
|
||||
$a = get_app();
|
||||
|
||||
update_suggestions();
|
||||
|
||||
}
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
cli_suggest_run($argv,$argc);
|
||||
killme();
|
||||
}
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file include/config.php
|
||||
* @brief Arbitrary configuration storage.
|
||||
*
|
||||
* @note Please do not store booleans - convert to 0/1 integer values.
|
||||
* The get_?config() functions return boolean false for keys that are unset,
|
||||
* and this could lead to subtle bugs.
|
||||
*
|
||||
* Arrays get stored as serialize strings.
|
||||
*
|
||||
* @todo There are a few places in the code (such as the admin panel) where
|
||||
* boolean configurations need to be fixed as of 10/08/2011.
|
||||
* Arrays get stored as serialized strings.
|
||||
* Booleans are stored as integer 0/1.
|
||||
*
|
||||
|
||||
* - <b>config</b> is used for hub specific configurations. It overrides the
|
||||
* configurations from .htconfig file. The storage is of size TEXT.
|
||||
* - <b>pconfig</b> is used for channel specific configurations and takes a
|
||||
@@ -34,751 +30,102 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Loads the hub's configuration from database to a cached storage.
|
||||
*
|
||||
* Retrieve a category ($family) of config variables from database to a cached
|
||||
* storage in the global App::$config[$family].
|
||||
*
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
*/
|
||||
|
||||
use Zotlabs\Lib as Zlib;
|
||||
|
||||
function load_config($family) {
|
||||
global $a;
|
||||
|
||||
if(! array_key_exists($family, App::$config))
|
||||
App::$config[$family] = array();
|
||||
|
||||
if(! array_key_exists('config_loaded', App::$config[$family])) {
|
||||
$r = q("SELECT * FROM config WHERE cat = '%s'", dbesc($family));
|
||||
if($r !== false) {
|
||||
if($r) {
|
||||
foreach($r as $rr) {
|
||||
$k = $rr['k'];
|
||||
App::$config[$family][$k] = $rr['v'];
|
||||
}
|
||||
}
|
||||
App::$config[$family]['config_loaded'] = true;
|
||||
}
|
||||
}
|
||||
Zlib\Config::Load($family);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get a particular config variable given the category name ($family)
|
||||
* and a key.
|
||||
*
|
||||
* Get a particular config variable from the given category ($family) and the
|
||||
* $key from a cached storage in App::$config[$family]. If a key is found in the
|
||||
* DB but does not exist in local config cache, pull it into the cache so we
|
||||
* do not have to hit the DB again for this item.
|
||||
*
|
||||
* Returns false if not set.
|
||||
*
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to query
|
||||
* @return mixed Return value or false on error or if not set
|
||||
*/
|
||||
function get_config($family, $key) {
|
||||
global $a;
|
||||
|
||||
if((! array_key_exists($family, App::$config)) || (! array_key_exists('config_loaded', App::$config[$family])))
|
||||
load_config($family);
|
||||
|
||||
if(array_key_exists('config_loaded', App::$config[$family])) {
|
||||
if(! array_key_exists($key, App::$config[$family])) {
|
||||
return false;
|
||||
}
|
||||
return ((! is_array(App::$config[$family][$key])) && (preg_match('|^a:[0-9]+:{.*}$|s', App::$config[$family][$key]))
|
||||
? unserialize(App::$config[$family][$key])
|
||||
: App::$config[$family][$key]
|
||||
);
|
||||
}
|
||||
return false;
|
||||
return Zlib\Config::Get($family,$key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns a value directly from the database configuration storage.
|
||||
*
|
||||
* This function queries directly the database and bypasses the chached storage
|
||||
* from get_config($family, $key).
|
||||
*
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to query
|
||||
* @return mixed
|
||||
*/
|
||||
function get_config_from_storage($family, $key) {
|
||||
$ret = q("SELECT * FROM config WHERE cat = '%s' AND k = '%s' LIMIT 1",
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets a configuration value for the hub.
|
||||
*
|
||||
* Stores a config value ($value) in the category ($family) under the key ($key).
|
||||
*
|
||||
* @note Please do not store booleans - convert to 0/1 integer values!
|
||||
*
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to set
|
||||
* @param mixed $value
|
||||
* The value to store in the configuration
|
||||
* @return mixed
|
||||
* Return the set value, or false if the database update failed
|
||||
*/
|
||||
function set_config($family, $key, $value) {
|
||||
global $a;
|
||||
|
||||
// manage array value
|
||||
$dbvalue = ((is_array($value)) ? serialize($value) : $value);
|
||||
$dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
|
||||
|
||||
if(get_config($family, $key) === false || (! get_config_from_storage($family, $key))) {
|
||||
$ret = q("INSERT INTO config ( cat, k, v ) VALUES ( '%s', '%s', '%s' ) ",
|
||||
dbesc($family),
|
||||
dbesc($key),
|
||||
dbesc($dbvalue)
|
||||
);
|
||||
if($ret) {
|
||||
App::$config[$family][$key] = $value;
|
||||
$ret = $value;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$ret = q("UPDATE config SET v = '%s' WHERE cat = '%s' AND k = '%s'",
|
||||
dbesc($dbvalue),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
|
||||
if($ret) {
|
||||
App::$config[$family][$key] = $value;
|
||||
$ret = $value;
|
||||
}
|
||||
return $ret;
|
||||
return Zlib\Config::Set($family,$key,$value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deletes the given key from the hub's configuration database.
|
||||
*
|
||||
* Removes the configured value from the stored cache in App::$config[$family]
|
||||
* and removes it from the database.
|
||||
*
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to delete
|
||||
* @return mixed
|
||||
*/
|
||||
function del_config($family, $key) {
|
||||
global $a;
|
||||
$ret = false;
|
||||
|
||||
if(array_key_exists($family, App::$config) && array_key_exists($key, App::$config[$family]))
|
||||
unset(App::$config[$family][$key]);
|
||||
$ret = q("DELETE FROM config WHERE cat = '%s' AND k = '%s'",
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
return $ret;
|
||||
return Zlib\Config::Delete($family,$key);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Loads all configuration values of a channel into a cached storage.
|
||||
*
|
||||
* All configuration values of the given channel are stored in global cache
|
||||
* which is available under the global variable App::$config[$uid].
|
||||
*
|
||||
* @param string $uid
|
||||
* The channel_id
|
||||
* @return void|false Nothing or false if $uid is false
|
||||
*/
|
||||
function load_pconfig($uid) {
|
||||
global $a;
|
||||
|
||||
if($uid === false)
|
||||
return false;
|
||||
|
||||
if(! array_key_exists($uid, App::$config))
|
||||
App::$config[$uid] = array();
|
||||
|
||||
$r = q("SELECT * FROM pconfig WHERE uid = %d",
|
||||
intval($uid)
|
||||
);
|
||||
|
||||
if($r) {
|
||||
foreach($r as $rr) {
|
||||
$k = $rr['k'];
|
||||
$c = $rr['cat'];
|
||||
if(! array_key_exists($c, App::$config[$uid])) {
|
||||
App::$config[$uid][$c] = array();
|
||||
App::$config[$uid][$c]['config_loaded'] = true;
|
||||
}
|
||||
App::$config[$uid][$c][$k] = $rr['v'];
|
||||
}
|
||||
}
|
||||
Zlib\PConfig::Load($uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get a particular channel's config variable given the category name
|
||||
* ($family) and a key.
|
||||
*
|
||||
* Get a particular channel's config value from the given category ($family)
|
||||
* and the $key from a cached storage in App::$config[$uid].
|
||||
*
|
||||
* Returns false if not set.
|
||||
*
|
||||
* @param string $uid
|
||||
* The channel_id
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to query
|
||||
* @param boolean $instore (deprecated, without function)
|
||||
* @return mixed Stored value or false if it does not exist
|
||||
*/
|
||||
function get_pconfig($uid, $family, $key, $instore = false) {
|
||||
// logger('include/config.php: get_pconfig() deprecated instore param used', LOGGER_DEBUG);
|
||||
global $a;
|
||||
|
||||
if($uid === false)
|
||||
return false;
|
||||
|
||||
if(! array_key_exists($uid, App::$config))
|
||||
load_pconfig($uid);
|
||||
|
||||
if((! array_key_exists($family, App::$config[$uid])) || (! array_key_exists($key, App::$config[$uid][$family])))
|
||||
return false;
|
||||
|
||||
return ((! is_array(App::$config[$uid][$family][$key])) && (preg_match('|^a:[0-9]+:{.*}$|s', App::$config[$uid][$family][$key]))
|
||||
? unserialize(App::$config[$uid][$family][$key])
|
||||
: App::$config[$uid][$family][$key]
|
||||
);
|
||||
return Zlib\PConfig::Get($uid,$family,$key,$instore = false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets a configuration value for a channel.
|
||||
*
|
||||
* Stores a config value ($value) in the category ($family) under the key ($key)
|
||||
* for the channel_id $uid.
|
||||
*
|
||||
* @note Please do not store booleans - convert to 0/1 integer values!
|
||||
*
|
||||
* @param string $uid
|
||||
* The channel_id
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to set
|
||||
* @param string $value
|
||||
* The value to store
|
||||
* @return mixed Stored $value or false
|
||||
*/
|
||||
function set_pconfig($uid, $family, $key, $value) {
|
||||
global $a;
|
||||
|
||||
// this catches subtle errors where this function has been called
|
||||
// with local_channel() when not logged in (which returns false)
|
||||
// and throws an error in array_key_exists below.
|
||||
// we provide a function backtrace in the logs so that we can find
|
||||
// and fix the calling function.
|
||||
|
||||
if($uid === false) {
|
||||
btlogger('UID is FALSE!', LOGGER_NORMAL, LOG_ERR);
|
||||
return;
|
||||
}
|
||||
|
||||
// manage array value
|
||||
$dbvalue = ((is_array($value)) ? serialize($value) : $value);
|
||||
$dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
|
||||
|
||||
if(get_pconfig($uid, $family, $key) === false) {
|
||||
if(! array_key_exists($uid, App::$config))
|
||||
App::$config[$uid] = array();
|
||||
if(! array_key_exists($family, App::$config[$uid]))
|
||||
App::$config[$uid][$family] = array();
|
||||
|
||||
// keep a separate copy for all variables which were
|
||||
// set in the life of this page. We need this to
|
||||
// synchronise channel clones.
|
||||
|
||||
if(! array_key_exists('transient', App::$config[$uid]))
|
||||
App::$config[$uid]['transient'] = array();
|
||||
if(! array_key_exists($family, App::$config[$uid]['transient']))
|
||||
App::$config[$uid]['transient'][$family] = array();
|
||||
|
||||
App::$config[$uid][$family][$key] = $value;
|
||||
App::$config[$uid]['transient'][$family][$key] = $value;
|
||||
|
||||
$ret = q("INSERT INTO pconfig ( uid, cat, k, v ) VALUES ( %d, '%s', '%s', '%s' ) ",
|
||||
intval($uid),
|
||||
dbesc($family),
|
||||
dbesc($key),
|
||||
dbesc($dbvalue)
|
||||
);
|
||||
if($ret)
|
||||
return $value;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$ret = q("UPDATE pconfig SET v = '%s' WHERE uid = %d and cat = '%s' AND k = '%s'",
|
||||
dbesc($dbvalue),
|
||||
intval($uid),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
|
||||
// keep a separate copy for all variables which were
|
||||
// set in the life of this page. We need this to
|
||||
// synchronise channel clones.
|
||||
|
||||
if(! array_key_exists('transient', App::$config[$uid]))
|
||||
App::$config[$uid]['transient'] = array();
|
||||
if(! array_key_exists($family, App::$config[$uid]['transient']))
|
||||
App::$config[$uid]['transient'][$family] = array();
|
||||
|
||||
App::$config[$uid][$family][$key] = $value;
|
||||
App::$config[$uid]['transient'][$family][$key] = $value;
|
||||
|
||||
if($ret)
|
||||
return $value;
|
||||
|
||||
return $ret;
|
||||
return Zlib\PConfig::Set($uid,$family,$key,$value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deletes the given key from the channel's configuration.
|
||||
*
|
||||
* Removes the configured value from the stored cache in App::$config[$uid]
|
||||
* and removes it from the database.
|
||||
*
|
||||
* @param string $uid
|
||||
* The channel_id
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to delete
|
||||
* @return mixed
|
||||
*/
|
||||
function del_pconfig($uid, $family, $key) {
|
||||
global $a;
|
||||
$ret = false;
|
||||
|
||||
if (x(App::$config[$uid][$family], $key))
|
||||
unset(App::$config[$uid][$family][$key]);
|
||||
$ret = q("DELETE FROM pconfig WHERE uid = %d AND cat = '%s' AND k = '%s'",
|
||||
intval($uid),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
|
||||
return $ret;
|
||||
return Zlib\PConfig::Delete($uid,$family,$key);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Loads a full xchan's configuration into a cached storage.
|
||||
*
|
||||
* All configuration values of the given observer hash are stored in global
|
||||
* cache which is available under the global variable App::$config[$xchan].
|
||||
*
|
||||
* @param string $xchan
|
||||
* The observer's hash
|
||||
* @return void|false Returns false if xchan is not set
|
||||
*/
|
||||
function load_xconfig($xchan) {
|
||||
global $a;
|
||||
|
||||
if(! $xchan)
|
||||
return false;
|
||||
|
||||
if(! array_key_exists($xchan, App::$config))
|
||||
App::$config[$xchan] = array();
|
||||
|
||||
$r = q("SELECT * FROM xconfig WHERE xchan = '%s'",
|
||||
dbesc($xchan)
|
||||
);
|
||||
|
||||
if($r) {
|
||||
foreach($r as $rr) {
|
||||
$k = $rr['k'];
|
||||
$c = $rr['cat'];
|
||||
if(! array_key_exists($c, App::$config[$xchan])) {
|
||||
App::$config[$xchan][$c] = array();
|
||||
App::$config[$xchan][$c]['config_loaded'] = true;
|
||||
}
|
||||
App::$config[$xchan][$c][$k] = $rr['v'];
|
||||
}
|
||||
}
|
||||
Zlib\XConfig::Load($xchan);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get a particular observer's config variable given the category
|
||||
* name ($family) and a key.
|
||||
*
|
||||
* Get a particular observer's config value from the given category ($family)
|
||||
* and the $key from a cached storage in App::$config[$xchan].
|
||||
*
|
||||
* Returns false if not set.
|
||||
*
|
||||
* @param string $xchan
|
||||
* The observer's hash
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to query
|
||||
* @return mixed Stored $value or false if it does not exist
|
||||
*/
|
||||
function get_xconfig($xchan, $family, $key) {
|
||||
global $a;
|
||||
|
||||
if(! $xchan)
|
||||
return false;
|
||||
|
||||
if(! array_key_exists($xchan, App::$config))
|
||||
load_xconfig($xchan);
|
||||
|
||||
if((! array_key_exists($family, App::$config[$xchan])) || (! array_key_exists($key, App::$config[$xchan][$family])))
|
||||
return false;
|
||||
|
||||
return ((! is_array(App::$config[$xchan][$family][$key])) && (preg_match('|^a:[0-9]+:{.*}$|s', App::$config[$xchan][$family][$key]))
|
||||
? unserialize(App::$config[$xchan][$family][$key])
|
||||
: App::$config[$xchan][$family][$key]
|
||||
);
|
||||
return Zlib\XConfig::Get($xchan,$family,$key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets a configuration value for an observer.
|
||||
*
|
||||
* Stores a config value ($value) in the category ($family) under the key ($key)
|
||||
* for the observer's $xchan hash.
|
||||
*
|
||||
* @note Please do not store booleans - convert to 0/1 integer values!
|
||||
*
|
||||
* @param string $xchan
|
||||
* The observer's hash
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to set
|
||||
* @param string $value
|
||||
* The value to store
|
||||
* @return mixed Stored $value or false
|
||||
*/
|
||||
function set_xconfig($xchan, $family, $key, $value) {
|
||||
global $a;
|
||||
|
||||
// manage array value
|
||||
$dbvalue = ((is_array($value)) ? serialize($value) : $value);
|
||||
$dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
|
||||
|
||||
if(get_xconfig($xchan, $family, $key) === false) {
|
||||
if(! array_key_exists($xchan, App::$config))
|
||||
App::$config[$xchan] = array();
|
||||
if(! array_key_exists($family, App::$config[$xchan]))
|
||||
App::$config[$xchan][$family] = array();
|
||||
|
||||
App::$config[$xchan][$family][$key] = $value;
|
||||
$ret = q("INSERT INTO xconfig ( xchan, cat, k, v ) VALUES ( '%s', '%s', '%s', '%s' ) ",
|
||||
dbesc($xchan),
|
||||
dbesc($family),
|
||||
dbesc($key),
|
||||
dbesc($dbvalue)
|
||||
);
|
||||
if($ret)
|
||||
return $value;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$ret = q("UPDATE xconfig SET v = '%s' WHERE xchan = '%s' and cat = '%s' AND k = '%s'",
|
||||
dbesc($dbvalue),
|
||||
dbesc($xchan),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
|
||||
App::$config[$xchan][$family][$key] = $value;
|
||||
|
||||
if($ret)
|
||||
return $value;
|
||||
return $ret;
|
||||
return Zlib\XConfig::Set($xchan,$family,$key,$value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deletes the given key from the observer's config.
|
||||
*
|
||||
* Removes the configured value from the stored cache in App::$config[$xchan]
|
||||
* and removes it from the database.
|
||||
*
|
||||
* @param string $xchan
|
||||
* The observer's hash
|
||||
* @param string $family
|
||||
* The category of the configuration value
|
||||
* @param string $key
|
||||
* The configuration key to delete
|
||||
* @return mixed
|
||||
*/
|
||||
function del_xconfig($xchan, $family, $key) {
|
||||
global $a;
|
||||
$ret = false;
|
||||
|
||||
if(x(App::$config[$xchan][$family], $key))
|
||||
unset(App::$config[$xchan][$family][$key]);
|
||||
$ret = q("DELETE FROM xconfig WHERE xchan = '%s' AND cat = '%s' AND k = '%s'",
|
||||
dbesc($xchan),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
return $ret;
|
||||
return Zlib\XConfig::Delete($xchan,$family,$key);
|
||||
}
|
||||
|
||||
|
||||
// account configuration storage is built on top of the under-utilised xconfig
|
||||
|
||||
function load_aconfig($account_id) {
|
||||
load_xconfig('a_' . $account_id);
|
||||
Zlib\AConfig::Load($account_id);
|
||||
}
|
||||
|
||||
function get_aconfig($account_id, $family, $key) {
|
||||
return get_xconfig('a_' . $account_id, $family, $key);
|
||||
return Zlib\AConfig::Get($account_id, $family, $key);
|
||||
}
|
||||
|
||||
function set_aconfig($account_id, $family, $key, $value) {
|
||||
return set_xconfig('a_' . $account_id, $family, $key, $value);
|
||||
return Zlib\AConfig::Set($account_id, $family, $key, $value);
|
||||
}
|
||||
|
||||
function del_aconfig($account_id, $family, $key) {
|
||||
return del_xconfig('a_' . $account_id, $family, $key);
|
||||
return Zlib\AConfig::Delete($account_id, $family, $key);
|
||||
}
|
||||
|
||||
|
||||
function load_abconfig($chash,$xhash) {
|
||||
$r = q("select * from abconfig where chan = '%s' and xchan = '%s'",
|
||||
dbesc($chash),
|
||||
dbesc($xhash)
|
||||
);
|
||||
return $r;
|
||||
Zlib\AbConfig::Load($chash,$xhash);
|
||||
}
|
||||
|
||||
function get_abconfig($chash,$xhash,$family,$key) {
|
||||
$r = q("select * from abconfig where chan = '%s' and xchan = '%s' and cat = '%s' and k = '%s' limit 1",
|
||||
dbesc($chash),
|
||||
dbesc($xhash),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
if($r) {
|
||||
return ((preg_match('|^a:[0-9]+:{.*}$|s', $r[0]['v'])) ? unserialize($r[0]['v']) : $r[0]['v']);
|
||||
}
|
||||
return false;
|
||||
return Zlib\AbConfig::Get($chash,$xhash,$family,$key);
|
||||
}
|
||||
|
||||
|
||||
function set_abconfig($chash,$xhash,$family,$key,$value) {
|
||||
|
||||
$dbvalue = ((is_array($value)) ? serialize($value) : $value);
|
||||
$dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
|
||||
|
||||
if(get_abconfig($chash,$xhash,$family,$key) === false) {
|
||||
$r = q("insert into abconfig ( chan, xchan, cat, k, v ) values ( '%s', '%s', '%s', '%s', '%s' ) ",
|
||||
dbesc($chash),
|
||||
dbesc($xhash),
|
||||
dbesc($family),
|
||||
dbesc($key),
|
||||
dbesc($dbvalue)
|
||||
);
|
||||
}
|
||||
else {
|
||||
$r = q("update abconfig set v = '%s' where chan = '%s' and xchan = '%s' and cat = '%s' and k = '%s' ",
|
||||
dbesc($dbvalue),
|
||||
dbesc($chash),
|
||||
dbesc($xhash),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
}
|
||||
if($r)
|
||||
return $value;
|
||||
return false;
|
||||
return Zlib\AbConfig::Set($chash,$xhash,$family,$key,$value);
|
||||
}
|
||||
|
||||
|
||||
function del_abconfig($chash,$xhash,$family,$key) {
|
||||
|
||||
$r = q("delete from abconfig where chan = '%s' and xchan = '%s' and cat = '%s' and k = '%s' ",
|
||||
dbesc($chash),
|
||||
dbesc($xhash),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
|
||||
return $r;
|
||||
return Zlib\AbConfig::Delete($chash,$xhash,$family,$key);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function load_iconfig(&$item) {
|
||||
Zlib\IConfig::Load($item);
|
||||
}
|
||||
|
||||
function get_iconfig(&$item, $family, $key) {
|
||||
|
||||
$is_item = false;
|
||||
if(is_array($item)) {
|
||||
$is_item = true;
|
||||
if((! array_key_exists('iconfig',$item)) || (! is_array($item['iconfig'])))
|
||||
$item['iconfig'] = array();
|
||||
|
||||
if(array_key_exists('item_id',$item))
|
||||
$iid = $item['item_id'];
|
||||
else
|
||||
$iid = $item['id'];
|
||||
}
|
||||
elseif(intval($item))
|
||||
$iid = $item;
|
||||
|
||||
if(! $iid)
|
||||
return false;
|
||||
|
||||
if(is_array($item) && array_key_exists('iconfig',$item) && is_array($item['iconfig'])) {
|
||||
foreach($item['iconfig'] as $c) {
|
||||
if($c['iid'] == $iid && $c['cat'] == $family && $c['k'] == $key)
|
||||
return $c['v'];
|
||||
}
|
||||
}
|
||||
|
||||
$r = q("select * from iconfig where iid = %d and cat = '%s' and k = '%s' limit 1",
|
||||
intval($iid),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
if($r) {
|
||||
$r[0]['v'] = ((preg_match('|^a:[0-9]+:{.*}$|s',$r[0]['v'])) ? unserialize($r[0]['v']) : $r[0]['v']);
|
||||
if($is_item)
|
||||
$item['iconfig'][] = $r[0];
|
||||
return $r[0]['v'];
|
||||
}
|
||||
return false;
|
||||
|
||||
return Zlib\IConfig::Get($item, $family, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* set_iconfig(&$item, $family, $key, $value, $sharing = false);
|
||||
*
|
||||
* $item - item array or item id. If passed an array the iconfig meta information is
|
||||
* added to the item structure (which will need to be saved with item_store eventually).
|
||||
* If passed an id, the DB is updated, but may not be federated and/or cloned.
|
||||
* $family - namespace of meta variable
|
||||
* $key - key of meta variable
|
||||
* $value - value of meta variable
|
||||
* $sharing - boolean (default false); if true the meta information is propagated with the item
|
||||
* to other sites/channels, mostly useful when $item is an array and has not yet been stored/delivered.
|
||||
* If the meta information is added after delivery and you wish it to be shared, it may be necessary to
|
||||
* alter the item edited timestamp and invoke the delivery process on the updated item. The edited
|
||||
* timestamp needs to be altered in order to trigger an item_store_update() at the receiving end.
|
||||
*/
|
||||
|
||||
|
||||
function set_iconfig(&$item, $family, $key, $value, $sharing = false) {
|
||||
|
||||
$dbvalue = ((is_array($value)) ? serialize($value) : $value);
|
||||
$dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
|
||||
|
||||
$is_item = false;
|
||||
$idx = null;
|
||||
|
||||
if(is_array($item)) {
|
||||
$is_item = true;
|
||||
if((! array_key_exists('iconfig',$item)) || (! is_array($item['iconfig'])))
|
||||
$item['iconfig'] = array();
|
||||
elseif($item['iconfig']) {
|
||||
for($x = 0; $x < count($item['iconfig']); $x ++) {
|
||||
if($item['iconfig'][$x]['cat'] == $family && $item['iconfig'][$x]['k'] == $key) {
|
||||
$idx = $x;
|
||||
}
|
||||
}
|
||||
}
|
||||
$entry = array('cat' => $family, 'k' => $key, 'v' => $value, 'sharing' => $sharing);
|
||||
|
||||
if(is_null($idx))
|
||||
$item['iconfig'][] = $entry;
|
||||
else
|
||||
$item['iconfig'][$idx] = $entry;
|
||||
return $value;
|
||||
}
|
||||
|
||||
if(intval($item))
|
||||
$iid = intval($item);
|
||||
|
||||
if(! $iid)
|
||||
return false;
|
||||
|
||||
if(get_iconfig($item, $family, $key) === false) {
|
||||
$r = q("insert into iconfig( iid, cat, k, v, sharing ) values ( %d, '%s', '%s', '%s', %d ) ",
|
||||
intval($iid),
|
||||
dbesc($family),
|
||||
dbesc($key),
|
||||
dbesc($dbvalue),
|
||||
intval($sharing)
|
||||
);
|
||||
}
|
||||
else {
|
||||
$r = q("update iconfig set v = '%s', sharing = %d where iid = %d and cat = '%s' and k = '%s' ",
|
||||
dbesc($dbvalue),
|
||||
intval($sharing),
|
||||
intval($iid),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
}
|
||||
|
||||
if(! $r)
|
||||
return false;
|
||||
|
||||
return $value;
|
||||
return Zlib\IConfig::Set($item, $family, $key, $value, $sharing);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function del_iconfig(&$item, $family, $key) {
|
||||
|
||||
|
||||
$is_item = false;
|
||||
$idx = null;
|
||||
|
||||
if(is_array($item)) {
|
||||
$is_item = true;
|
||||
if(is_array($item['iconfig'])) {
|
||||
for($x = 0; $x < count($item['iconfig']); $x ++) {
|
||||
if($item['iconfig'][$x]['cat'] == $family && $item['iconfig'][$x]['k'] == $key) {
|
||||
unset($item['iconfig'][$x]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if(intval($item))
|
||||
$iid = intval($item);
|
||||
|
||||
if(! $iid)
|
||||
return false;
|
||||
|
||||
return q("delete from iconfig where iid = %d and cat = '%s' and k = '%s' ",
|
||||
intval($iid),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
|
||||
return Zlib\IConfig::Delete($item, $family, $key);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,32 +48,9 @@ function abook_self($channel_id) {
|
||||
return(($r) ? $r[0] : array());
|
||||
}
|
||||
|
||||
function channelx_by_nick($nick) {
|
||||
$r = q("SELECT * FROM channel left join xchan on channel_hash = xchan_hash WHERE channel_address = '%s' and channel_removed = 0 LIMIT 1",
|
||||
dbesc($nick)
|
||||
);
|
||||
return(($r) ? $r[0] : false);
|
||||
}
|
||||
|
||||
function channelx_by_hash($hash) {
|
||||
$r = q("SELECT * FROM channel left join xchan on channel_hash = xchan_hash WHERE channel_hash = '%s' and channel_removed = 0 LIMIT 1",
|
||||
dbesc($hash)
|
||||
);
|
||||
return(($r) ? $r[0] : false);
|
||||
}
|
||||
|
||||
function channelx_by_n($id) {
|
||||
$r = q("SELECT * FROM channel left join xchan on channel_hash = xchan_hash WHERE channel_id = %d and channel_removed = 0 LIMIT 1",
|
||||
dbesc($id)
|
||||
);
|
||||
return(($r) ? $r[0] : false);
|
||||
}
|
||||
|
||||
|
||||
function vcard_from_xchan($xchan, $observer = null, $mode = '') {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
if(! $xchan) {
|
||||
if(App::$poi) {
|
||||
$xchan = App::$poi;
|
||||
@@ -198,7 +175,7 @@ function account_remove($account_id,$local = true,$unset_session=true) {
|
||||
|
||||
// Don't let anybody nuke the only admin account.
|
||||
|
||||
$r = q("select account_id from account where (account_roles & %d)>0",
|
||||
$r = q("select account_id from account where (account_roles & %d) > 0",
|
||||
intval(ACCOUNT_ROLE_ADMIN)
|
||||
);
|
||||
|
||||
@@ -267,7 +244,7 @@ function channel_remove($channel_id, $local = true, $unset_session=false) {
|
||||
|
||||
if(! $channel_id)
|
||||
return;
|
||||
$a = get_app();
|
||||
|
||||
logger('Removing channel: ' . $channel_id);
|
||||
logger('channel_remove: local only: ' . intval($local));
|
||||
|
||||
@@ -303,8 +280,7 @@ function channel_remove($channel_id, $local = true, $unset_session=false) {
|
||||
dbesc($channel['channel_hash'])
|
||||
);
|
||||
|
||||
proc_run('php','include/notifier.php','purge_all',$channel_id);
|
||||
|
||||
Zotlabs\Daemon\Master::Summon(array('Notifier','purge_all',$channel_id));
|
||||
}
|
||||
|
||||
q("DELETE FROM `groups` WHERE `uid` = %d", intval($channel_id));
|
||||
@@ -386,10 +362,10 @@ function channel_remove($channel_id, $local = true, $unset_session=false) {
|
||||
@rrmdir($f);
|
||||
}
|
||||
|
||||
proc_run('php','include/directory.php',$channel_id);
|
||||
Zotlabs\Daemon\Master::Summon(array('Directory',$channel_id));
|
||||
|
||||
if($channel_id == local_channel() && $unset_session) {
|
||||
\Zotlabs\Web\Session::nuke();
|
||||
App::$session->nuke();
|
||||
goaway(z_root());
|
||||
}
|
||||
|
||||
@@ -614,7 +590,8 @@ function random_profile() {
|
||||
|
||||
for($i = 0; $i < $retryrandom; $i++) {
|
||||
|
||||
$r = q("select xchan_url from xchan left join hubloc on hubloc_hash = xchan_hash where hubloc_connected > %s - interval %s order by $randfunc limit 1",
|
||||
$r = q("select xchan_url from xchan left join hubloc on hubloc_hash = xchan_hash where xchan_addr not like '%s' and hubloc_connected > %s - interval %s order by $randfunc limit 1",
|
||||
dbesc('sys@%'),
|
||||
db_utcnow(), db_quoteinterval('30 day')
|
||||
);
|
||||
|
||||
@@ -1,97 +0,0 @@
|
||||
<?php /** @file */
|
||||
|
||||
|
||||
function contact_profile_assign($current) {
|
||||
|
||||
$o = '';
|
||||
|
||||
$o .= "<select id=\"contact-profile-selector\" name=\"profile_assign\" class=\"form-control\"/>\r\n";
|
||||
|
||||
$r = q("SELECT profile_guid, profile_name FROM `profile` WHERE `uid` = %d",
|
||||
intval($_SESSION['uid']));
|
||||
|
||||
if($r) {
|
||||
foreach($r as $rr) {
|
||||
$selected = (($rr['profile_guid'] == $current) ? " selected=\"selected\" " : "");
|
||||
$o .= "<option value=\"{$rr['profile_guid']}\" $selected >{$rr['profile_name']}</option>\r\n";
|
||||
}
|
||||
}
|
||||
$o .= "</select>\r\n";
|
||||
return $o;
|
||||
}
|
||||
|
||||
/* unused currently
|
||||
|
||||
function contact_reputation($current) {
|
||||
|
||||
$o = '';
|
||||
$o .= "<select id=\"contact-reputation-selector\" name=\"reputation\" />\r\n";
|
||||
|
||||
$rep = array(
|
||||
0 => t('Unknown | Not categorized'),
|
||||
1 => t('Block immediately'),
|
||||
2 => t('Shady, spammer, self-marketer'),
|
||||
3 => t('Known to me, but no opinion'),
|
||||
4 => t('OK, probably harmless'),
|
||||
5 => t('Reputable, has my trust')
|
||||
);
|
||||
|
||||
foreach($rep as $k => $v) {
|
||||
$selected = (($k == $current) ? " selected=\"selected\" " : "");
|
||||
$o .= "<option value=\"$k\" $selected >$v</option>\r\n";
|
||||
}
|
||||
$o .= "</select>\r\n";
|
||||
return $o;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
function contact_poll_interval($current, $disabled = false) {
|
||||
|
||||
$dis = (($disabled) ? ' disabled="disabled" ' : '');
|
||||
$o = '';
|
||||
$o .= "<select id=\"contact-poll-interval\" name=\"poll\" $dis />" . "\r\n";
|
||||
|
||||
$rep = array(
|
||||
0 => t('Frequently'),
|
||||
1 => t('Hourly'),
|
||||
2 => t('Twice daily'),
|
||||
3 => t('Daily'),
|
||||
4 => t('Weekly'),
|
||||
5 => t('Monthly')
|
||||
);
|
||||
|
||||
foreach($rep as $k => $v) {
|
||||
$selected = (($k == $current) ? " selected=\"selected\" " : "");
|
||||
$o .= "<option value=\"$k\" $selected >$v</option>\r\n";
|
||||
}
|
||||
$o .= "</select>\r\n";
|
||||
return $o;
|
||||
}
|
||||
|
||||
|
||||
function network_to_name($s) {
|
||||
|
||||
$nets = array(
|
||||
NETWORK_DFRN => t('Friendica'),
|
||||
NETWORK_FRND => t('Friendica'),
|
||||
NETWORK_OSTATUS => t('OStatus'),
|
||||
NETWORK_GNUSOCIAL => t('GNU-Social'),
|
||||
NETWORK_FEED => t('RSS/Atom'),
|
||||
NETWORK_MAIL => t('Email'),
|
||||
NETWORK_DIASPORA => t('Diaspora'),
|
||||
NETWORK_FACEBOOK => t('Facebook'),
|
||||
NETWORK_ZOT => t('Zot'),
|
||||
NETWORK_LINKEDIN => t('LinkedIn'),
|
||||
NETWORK_XMPP => t('XMPP/IM'),
|
||||
NETWORK_MYSPACE => t('MySpace'),
|
||||
);
|
||||
|
||||
call_hooks('network_to_name', $nets);
|
||||
|
||||
$search = array_keys($nets);
|
||||
$replace = array_values($nets);
|
||||
|
||||
return str_replace($search,$replace,$s);
|
||||
|
||||
}
|
||||
@@ -3,9 +3,6 @@
|
||||
|
||||
|
||||
function findpeople_widget() {
|
||||
require_once('include/Contact.php');
|
||||
|
||||
$a = get_app();
|
||||
|
||||
if(get_config('system','invitation_only')) {
|
||||
$x = get_pconfig(local_channel(),'system','invites_remaining');
|
||||
@@ -37,13 +34,12 @@ function findpeople_widget() {
|
||||
|
||||
|
||||
function fileas_widget($baseurl,$selected = '') {
|
||||
$a = get_app();
|
||||
|
||||
if(! local_channel())
|
||||
return '';
|
||||
|
||||
$terms = array();
|
||||
$r = q("select distinct(term) from term where uid = %d and type = %d order by term asc",
|
||||
$r = q("select distinct(term) from term where uid = %d and ttype = %d order by term asc",
|
||||
intval(local_channel()),
|
||||
intval(TERM_FILE)
|
||||
);
|
||||
@@ -65,8 +61,6 @@ function fileas_widget($baseurl,$selected = '') {
|
||||
}
|
||||
|
||||
function categories_widget($baseurl,$selected = '') {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
if(! feature_enabled(App::$profile['profile_uid'],'categories'))
|
||||
return '';
|
||||
@@ -78,7 +72,7 @@ function categories_widget($baseurl,$selected = '') {
|
||||
from term join item on term.oid = item.id
|
||||
where item.uid = %d
|
||||
and term.uid = item.uid
|
||||
and term.type = %d
|
||||
and term.ttype = %d
|
||||
and term.otype = %d
|
||||
and item.owner_xchan = '%s'
|
||||
and item.item_wall = 1
|
||||
@@ -108,8 +102,6 @@ function categories_widget($baseurl,$selected = '') {
|
||||
|
||||
function common_friends_visitor_widget($profile_uid) {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
if(local_channel() == $profile_uid)
|
||||
return;
|
||||
|
||||
|
||||
@@ -93,15 +93,15 @@ function localize_item(&$item){
|
||||
|
||||
if (activity_match($item['verb'],ACTIVITY_LIKE) || activity_match($item['verb'],ACTIVITY_DISLIKE)){
|
||||
|
||||
if(! $item['object'])
|
||||
if(! $item['obj'])
|
||||
return;
|
||||
|
||||
if(intval($item['item_thread_top']))
|
||||
return;
|
||||
|
||||
$obj = json_decode_plus($item['object']);
|
||||
if((! $obj) && ($item['object'])) {
|
||||
logger('localize_item: failed to decode object: ' . print_r($item['object'],true));
|
||||
$obj = json_decode_plus($item['obj']);
|
||||
if((! $obj) && ($item['obj'])) {
|
||||
logger('localize_item: failed to decode object: ' . print_r($item['obj'],true));
|
||||
}
|
||||
|
||||
if($obj['author'] && $obj['author']['link'])
|
||||
@@ -186,7 +186,7 @@ function localize_item(&$item){
|
||||
$Alink = $item['author']['xchan_url'];
|
||||
|
||||
|
||||
$obj= json_decode_plus($item['object']);
|
||||
$obj= json_decode_plus($item['obj']);
|
||||
|
||||
$Blink = $Bphoto = '';
|
||||
|
||||
@@ -219,7 +219,7 @@ function localize_item(&$item){
|
||||
$Aname = $item['author']['xchan_name'];
|
||||
$Alink = $item['author']['xchan_url'];
|
||||
|
||||
$obj= json_decode_plus($item['object']);
|
||||
$obj= json_decode_plus($item['obj']);
|
||||
|
||||
$Blink = $Bphoto = '';
|
||||
|
||||
@@ -299,7 +299,7 @@ function localize_item(&$item){
|
||||
}
|
||||
$plink = '[zrl=' . $obj['plink'] . ']' . $post_type . '[/zrl]';
|
||||
|
||||
$parsedobj = parse_xml_string($xmlhead.$item['object']);
|
||||
$parsedobj = parse_xml_string($xmlhead.$item['obj']);
|
||||
|
||||
$tag = sprintf('#[zrl=%s]%s[/zrl]', $parsedobj->id, $parsedobj->content);
|
||||
$item['body'] = sprintf( t('%1$s tagged %2$s\'s %3$s with %4$s'), $author, $objauthor, $plink, $tag );
|
||||
@@ -316,7 +316,7 @@ function localize_item(&$item){
|
||||
|
||||
$xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
|
||||
|
||||
$obj = parse_xml_string($xmlhead.$item['object']);
|
||||
$obj = parse_xml_string($xmlhead.$item['obj']);
|
||||
if(strlen($obj->id)) {
|
||||
$r = q("select * from item where mid = '%s' and uid = %d limit 1",
|
||||
dbesc($obj->id),
|
||||
@@ -754,10 +754,7 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $
|
||||
// Normal View
|
||||
// logger('conv: items: ' . print_r($items,true));
|
||||
|
||||
require_once('include/ConversationObject.php');
|
||||
require_once('include/ItemObject.php');
|
||||
|
||||
$conv = new Conversation($mode, $preview, $prepared_item);
|
||||
$conv = new Zotlabs\Lib\ThreadStream($mode, $preview, $prepared_item);
|
||||
|
||||
// In the display mode we don't have a profile owner.
|
||||
|
||||
@@ -806,7 +803,7 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $
|
||||
|
||||
if($item['id'] == $item['parent']) {
|
||||
|
||||
$item_object = new Item($item);
|
||||
$item_object = new Zotlabs\Lib\ThreadItem($item);
|
||||
$conv->add_thread($item_object);
|
||||
if($page_mode === 'list') {
|
||||
$item_object->set_template('conv_list.tpl');
|
||||
@@ -861,8 +858,6 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $
|
||||
|
||||
function best_link_url($item) {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
$best_url = '';
|
||||
$sparkle = false;
|
||||
|
||||
@@ -891,7 +886,7 @@ function best_link_url($item) {
|
||||
|
||||
|
||||
function item_photo_menu($item){
|
||||
$a = get_app();
|
||||
|
||||
$contact = null;
|
||||
|
||||
$ssl_state = false;
|
||||
@@ -1110,7 +1105,6 @@ function status_editor($a, $x, $popup = false) {
|
||||
|
||||
$o = '';
|
||||
|
||||
require_once('include/Contact.php');
|
||||
$c = channelx_by_n($x['profile_uid']);
|
||||
if($c && $c['channel_moved'])
|
||||
return $o;
|
||||
@@ -1163,7 +1157,7 @@ function status_editor($a, $x, $popup = false) {
|
||||
$layoutselect = '<input type="hidden" name="layout_mid" value="' . $layout . '" />';
|
||||
|
||||
if(array_key_exists('channel_select',$x) && $x['channel_select']) {
|
||||
require_once('include/identity.php');
|
||||
require_once('include/channel.php');
|
||||
$id_select = identity_selector();
|
||||
}
|
||||
else
|
||||
@@ -1412,7 +1406,7 @@ function render_location_default($item) {
|
||||
|
||||
|
||||
function prepare_page($item) {
|
||||
$a = get_app();
|
||||
|
||||
$naked = 1;
|
||||
// $naked = ((get_pconfig($item['uid'],'system','nakedpage')) ? 1 : 0);
|
||||
$observer = App::get_observer();
|
||||
@@ -1446,7 +1440,7 @@ function prepare_page($item) {
|
||||
|
||||
|
||||
function network_tabs() {
|
||||
$a = get_app();
|
||||
|
||||
$no_active='';
|
||||
$starred_active = '';
|
||||
$new_active = '';
|
||||
@@ -1662,8 +1656,7 @@ function profile_tabs($a, $is_owner = false, $nickname = null){
|
||||
|
||||
|
||||
if ($p['chat'] && feature_enabled($uid,'ajaxchat')) {
|
||||
require_once('include/chat.php');
|
||||
$has_chats = chatroom_list_count($uid);
|
||||
$has_chats = Zotlabs\Lib\Chatroom::list_count($uid);
|
||||
if ($has_chats) {
|
||||
$tabs[] = array(
|
||||
'label' => t('Chatrooms'),
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
<?php /** @file */
|
||||
|
||||
require_once('boot.php');
|
||||
require_once('include/cli_startup.php');
|
||||
|
||||
|
||||
function cronhooks_run($argv, $argc){
|
||||
|
||||
cli_startup();
|
||||
|
||||
logger('cronhooks: start');
|
||||
|
||||
$d = datetime_convert();
|
||||
|
||||
call_hooks('cron', $d);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
cronhooks_run($argv,$argc);
|
||||
killme();
|
||||
}
|
||||
@@ -46,27 +46,15 @@ function pkcs5_unpad($text)
|
||||
}
|
||||
|
||||
function AES256CBC_encrypt($data,$key,$iv) {
|
||||
if(get_config('system','openssl_encrypt')) {
|
||||
return openssl_encrypt($data,'aes-256-cbc',str_pad($key,32,"\0"),OPENSSL_RAW_DATA,str_pad($iv,16,"\0"));
|
||||
}
|
||||
return mcrypt_encrypt(
|
||||
MCRYPT_RIJNDAEL_128,
|
||||
str_pad($key,32,"\0"),
|
||||
pkcs5_pad($data,16),
|
||||
MCRYPT_MODE_CBC,
|
||||
str_pad($iv,16,"\0"));
|
||||
|
||||
return openssl_encrypt($data,'aes-256-cbc',str_pad($key,32,"\0"),OPENSSL_RAW_DATA,str_pad($iv,16,"\0"));
|
||||
|
||||
}
|
||||
|
||||
function AES256CBC_decrypt($data,$key,$iv) {
|
||||
if(get_config('system','openssl_encrypt')) {
|
||||
return openssl_decrypt($data,'aes-256-cbc',str_pad($key,32,"\0"),OPENSSL_RAW_DATA,str_pad($iv,16,"\0"));
|
||||
}
|
||||
return pkcs5_unpad(mcrypt_decrypt(
|
||||
MCRYPT_RIJNDAEL_128,
|
||||
str_pad($key,32,"\0"),
|
||||
$data,
|
||||
MCRYPT_MODE_CBC,
|
||||
str_pad($iv,16,"\0")));
|
||||
|
||||
return openssl_decrypt($data,'aes-256-cbc',str_pad($key,32,"\0"),OPENSSL_RAW_DATA,str_pad($iv,16,"\0"));
|
||||
|
||||
}
|
||||
|
||||
function crypto_encapsulate($data,$pubkey,$alg='aes256cbc') {
|
||||
|
||||
@@ -119,7 +119,6 @@ function datetime_convert($from = 'UTC', $to = 'UTC', $s = 'now', $fmt = "Y-m-d
|
||||
* @return string
|
||||
*/
|
||||
function dob($dob) {
|
||||
$a = get_app();
|
||||
|
||||
list($year, $month, $day) = sscanf($dob, '%4d-%2d-%2d');
|
||||
$f = get_config('system', 'birthday_input_format');
|
||||
|
||||
@@ -1,50 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* @file dba_driver.php
|
||||
* @brief some database related functions and abstract driver class.
|
||||
*
|
||||
* This file contains the abstract database driver class dba_driver and some
|
||||
* functions for working with databases.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Returns the database driver object.
|
||||
*
|
||||
* If available it will use PHP's mysqli otherwise mysql driver.
|
||||
*
|
||||
* @param string $server DB server name
|
||||
* @param string $port DB port
|
||||
* @param string $user DB username
|
||||
* @param string $pass DB password
|
||||
* @param string $db database name
|
||||
* @param string $dbtype 0 for mysql, 1 for postgres
|
||||
* @param bool $install Defaults to false
|
||||
* @return null|dba_driver A database driver object (dba_mysql|dba_mysqli) or null if no driver found.
|
||||
*/
|
||||
function dba_factory($server, $port,$user,$pass,$db,$dbtype,$install = false) {
|
||||
$dba = null;
|
||||
class DBA {
|
||||
|
||||
$dbtype = intval($dbtype);
|
||||
/**
|
||||
* @file dba_driver.php
|
||||
* @brief some database related functions and abstract driver class.
|
||||
*
|
||||
* This file contains the abstract database driver class dba_driver and some
|
||||
* functions for working with databases.
|
||||
*/
|
||||
|
||||
if($dbtype == DBTYPE_POSTGRES) {
|
||||
require_once('include/dba/dba_postgres.php');
|
||||
if(is_null($port)) $port = 5432;
|
||||
$dba = new dba_postgres($server, $port, $user, $pass, $db, $install);
|
||||
} else {
|
||||
if(class_exists('mysqli')) {
|
||||
if (is_null($port)) $port = ini_get("mysqli.default_port");
|
||||
require_once('include/dba/dba_mysqli.php');
|
||||
$dba = new dba_mysqli($server, $port,$user,$pass,$db,$install);
|
||||
} else {
|
||||
if (is_null($port)) $port = "3306";
|
||||
require_once('include/dba/dba_mysql.php');
|
||||
$dba = new dba_mysql($server, $port,$user,$pass,$db,$install);
|
||||
static public $dba = null;
|
||||
static public $dbtype = null;
|
||||
static public $logging = false;
|
||||
|
||||
/**
|
||||
* @brief Returns the database driver object.
|
||||
*
|
||||
* If available it will use PHP's mysqli otherwise mysql driver.
|
||||
*
|
||||
* @param string $server DB server name
|
||||
* @param string $port DB port
|
||||
* @param string $user DB username
|
||||
* @param string $pass DB password
|
||||
* @param string $db database name
|
||||
* @param string $dbtype 0 for mysql, 1 for postgres
|
||||
* @param bool $install Defaults to false
|
||||
* @return null|dba_driver A database driver object (dba_mysql|dba_mysqli) or null if no driver found.
|
||||
*/
|
||||
|
||||
static public function dba_factory($server, $port,$user,$pass,$db,$dbtype,$install = false) {
|
||||
|
||||
self::$dba = null;
|
||||
|
||||
self::$dbtype = intval($dbtype);
|
||||
$set_port = $port;
|
||||
|
||||
if(self::$dbtype == DBTYPE_POSTGRES) {
|
||||
require_once('include/dba/dba_postgres.php');
|
||||
if(is_null($port)) $set_port = 5432;
|
||||
self::$dba = new dba_postgres($server, $set_port, $user, $pass, $db, $install);
|
||||
}
|
||||
else {
|
||||
|
||||
// Highly experimental at the present time.
|
||||
// require_once('include/dba/dba_pdo.php');
|
||||
// self::$dba = new dba_pdo($server, $set_port,$user,$pass,$db,$install);
|
||||
// }
|
||||
|
||||
if(class_exists('mysqli')) {
|
||||
if (is_null($port)) $set_port = ini_get("mysqli.default_port");
|
||||
require_once('include/dba/dba_mysqli.php');
|
||||
self::$dba = new dba_mysqli($server, $set_port,$user,$pass,$db,$install);
|
||||
}
|
||||
}
|
||||
|
||||
// Until we have a proper PDO driver, store the DB connection parameters for
|
||||
// plugins/addons which use PDO natively (such as cdav). This is wasteful as
|
||||
// it opens a separate connection to the DB, but saves a lot of effort re-writing
|
||||
// third-party interfaces that are working and well tested.
|
||||
|
||||
|
||||
if(is_object(self::$dba) && self::$dba->connected) {
|
||||
$dns = ((self::$dbtype == DBTYPE_POSTGRES) ? 'postgres' : 'mysql')
|
||||
. ':host=' . $server . (is_null($port) ? '' : ';port=' . $port)
|
||||
. ';dbname=' . $db;
|
||||
self::$dba->pdo_set(array($dns,$user,$pass));
|
||||
}
|
||||
|
||||
define('NULL_DATE', self::$dba->get_null_date());
|
||||
define('ACTIVE_DBTYPE', self::$dbtype);
|
||||
return self::$dba;
|
||||
}
|
||||
|
||||
define('NULL_DATE', $dba->get_null_date());
|
||||
define('ACTIVE_DBTYPE', $dbtype);
|
||||
return $dba;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,6 +88,7 @@ abstract class dba_driver {
|
||||
const UTC_NOW = 'UTC_TIMESTAMP()';
|
||||
|
||||
protected $db;
|
||||
protected $pdo = array();
|
||||
|
||||
public $debug = 0;
|
||||
public $connected = false;
|
||||
@@ -183,6 +212,15 @@ abstract class dba_driver {
|
||||
function unescapebin($str) {
|
||||
return $str;
|
||||
}
|
||||
|
||||
function pdo_set($x) {
|
||||
$this->pdo = $x;
|
||||
}
|
||||
|
||||
function pdo_get() {
|
||||
return $this->pdo;
|
||||
}
|
||||
|
||||
} // end abstract dba_driver class
|
||||
|
||||
|
||||
@@ -206,8 +244,8 @@ function printable($s) {
|
||||
function dbg($state) {
|
||||
global $db;
|
||||
|
||||
if($db)
|
||||
$db->dbg($state);
|
||||
if(\DBA::$dba)
|
||||
\DBA::$dba->dbg($state);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -221,21 +259,18 @@ function dbg($state) {
|
||||
* @return Return an escaped string of the value to pass to a DB query.
|
||||
*/
|
||||
function dbesc($str) {
|
||||
global $db;
|
||||
|
||||
if($db && $db->connected)
|
||||
return($db->escape($str));
|
||||
if(\DBA::$dba && \DBA::$dba->connected)
|
||||
return(\DBA::$dba->escape($str));
|
||||
else
|
||||
return(str_replace("'", "\\'", $str));
|
||||
}
|
||||
function dbescbin($str) {
|
||||
global $db;
|
||||
return $db->escapebin($str);
|
||||
return \DBA::$dba->escapebin($str);
|
||||
}
|
||||
|
||||
function dbunescbin($str) {
|
||||
global $db;
|
||||
return $db->unescapebin($str);
|
||||
return \DBA::$dba->unescapebin($str);
|
||||
}
|
||||
|
||||
function dbescdate($date) {
|
||||
@@ -248,36 +283,25 @@ function dbescdate($date) {
|
||||
}
|
||||
|
||||
function db_quoteinterval($txt) {
|
||||
global $db;
|
||||
return $db->quote_interval($txt);
|
||||
return \DBA::$dba->quote_interval($txt);
|
||||
}
|
||||
|
||||
function dbesc_identifier($str) {
|
||||
global $db;
|
||||
return $db->escape_identifier($str);
|
||||
return \DBA::$dba->escape_identifier($str);
|
||||
}
|
||||
|
||||
function db_utcnow() {
|
||||
global $db;
|
||||
return $db->utcnow();
|
||||
return \DBA::$dba->utcnow();
|
||||
}
|
||||
|
||||
function db_optimizetable($table) {
|
||||
global $db;
|
||||
$db->optimize_table($table);
|
||||
\DBA::$dba->optimize_table($table);
|
||||
}
|
||||
|
||||
function db_concat($fld, $sep) {
|
||||
global $db;
|
||||
return $db->concat($fld, $sep);
|
||||
return \DBA::$dba->concat($fld, $sep);
|
||||
}
|
||||
|
||||
// Function: q($sql,$args);
|
||||
// Description: execute SQL query with printf style args.
|
||||
// Example: $r = q("SELECT * FROM `%s` WHERE `uid` = %d",
|
||||
// 'user', 1);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Execute a SQL query with printf style args.
|
||||
*
|
||||
@@ -293,13 +317,13 @@ function db_concat($fld, $sep) {
|
||||
* @param string $sql The SQL query to execute
|
||||
* @return bool|array
|
||||
*/
|
||||
|
||||
function q($sql) {
|
||||
global $db;
|
||||
|
||||
$args = func_get_args();
|
||||
unset($args[0]);
|
||||
|
||||
if($db && $db->connected) {
|
||||
if(\DBA::$dba && \DBA::$dba->connected) {
|
||||
$stmt = vsprintf($sql, $args);
|
||||
if($stmt === false) {
|
||||
if(version_compare(PHP_VERSION, '5.4.0') >= 0)
|
||||
@@ -308,13 +332,14 @@ function q($sql) {
|
||||
else
|
||||
db_logger('dba: vsprintf error: ' . print_r(debug_backtrace(), true),LOGGER_NORMAL,LOG_CRIT);
|
||||
}
|
||||
return $db->q($stmt);
|
||||
return \DBA::$dba->q($stmt);
|
||||
}
|
||||
|
||||
/*
|
||||
* This will happen occasionally trying to store the
|
||||
* session data after abnormal program termination
|
||||
*/
|
||||
|
||||
db_logger('dba: no database: ' . print_r($args,true),LOGGER_NORMAL,LOG_CRIT);
|
||||
|
||||
return false;
|
||||
@@ -328,10 +353,9 @@ function q($sql) {
|
||||
* @param string $sql The SQL query to execute
|
||||
*/
|
||||
function dbq($sql) {
|
||||
global $db;
|
||||
|
||||
if($db && $db->connected)
|
||||
$ret = $db->q($sql);
|
||||
if(\DBA::$dba && \DBA::$dba->connected)
|
||||
$ret = \DBA::$dba->q($sql);
|
||||
else
|
||||
$ret = false;
|
||||
|
||||
@@ -392,13 +416,18 @@ function db_getfunc($f) {
|
||||
|
||||
// The logger function may make DB calls internally to query the system logging parameters.
|
||||
// This can cause a recursion if database debugging is enabled.
|
||||
// So this function preserves the current database debugging state and then turns it off while
|
||||
// doing the logger() call
|
||||
// So this function preserves the current database debugging state and then turns it off
|
||||
// temporarily while doing the logger() call
|
||||
|
||||
function db_logger($s,$level = LOGGER_NORMAL,$syslog = LOG_INFO) {
|
||||
global $db;
|
||||
$saved = $db->debug;
|
||||
$db->debug = false;
|
||||
|
||||
if(\DBA::$logging)
|
||||
return;
|
||||
|
||||
$saved = \DBA::$dba->debug;
|
||||
\DBA::$dba->debug = false;
|
||||
\DBA::$logging = true;
|
||||
logger($s,$level,$syslog);
|
||||
$db->debug = $saved;
|
||||
\DBA::$logging = false;
|
||||
\DBA::$dba->debug = $saved;
|
||||
}
|
||||
95
include/dba/dba_pdo.php
Executable file
95
include/dba/dba_pdo.php
Executable file
@@ -0,0 +1,95 @@
|
||||
<?php /** @file */
|
||||
|
||||
require_once('include/dba/dba_driver.php');
|
||||
|
||||
class dba_pdo extends dba_driver {
|
||||
|
||||
|
||||
public $driver_dbtype = null;
|
||||
|
||||
function connect($server,$port,$user,$pass,$db) {
|
||||
|
||||
$this->driver_dbtype = 'mysql'; // (($dbtype == DBTYPE_POSTGRES) ? 'postgres' : 'mysql');
|
||||
$dns = $this->driver_dbtype
|
||||
. ':host=' . $server . (is_null($port) ? '' : ';port=' . $port)
|
||||
. ';dbname=' . $db;
|
||||
|
||||
|
||||
try {
|
||||
$this->db = new PDO($dns,$user,$pass);
|
||||
$this->db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
|
||||
}
|
||||
catch(PDOException $e) {
|
||||
if(file_exists('dbfail.out')) {
|
||||
file_put_contents('dbfail.out', datetime_convert() . "\nConnect: " . $e->getMessage() . "\n", FILE_APPEND);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->connected = true;
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
function q($sql) {
|
||||
if((! $this->db) || (! $this->connected))
|
||||
return false;
|
||||
|
||||
$this->error = '';
|
||||
$select = ((stripos($sql,'select') === 0) ? true : false);
|
||||
|
||||
try {
|
||||
$result = $this->db->query($sql);
|
||||
}
|
||||
catch(PDOException $e) {
|
||||
|
||||
$this->error = $e->getMessage();
|
||||
if($this->error) {
|
||||
db_logger('dba_mysqli: ERROR: ' . printable($sql) . "\n" . $this->error, LOGGER_NORMAL, LOG_ERR);
|
||||
if(file_exists('dbfail.out')) {
|
||||
file_put_contents('dbfail.out', datetime_convert() . "\n" . printable($sql) . "\n" . $this->error . "\n", FILE_APPEND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!($select)) {
|
||||
if($this->debug) {
|
||||
db_logger('dba_mysqli: DEBUG: ' . printable($sql) . ' returns ' . (($result) ? 'true' : 'false'), LOGGER_NORMAL,(($result) ? LOG_INFO : LOG_ERR));
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
if($this->debug) {
|
||||
db_logger('dba_mysqli: DEBUG: ' . printable($sql) . ' returned ' . count($result) . ' results.', LOGGER_NORMAL, LOG_INFO);
|
||||
}
|
||||
|
||||
$r = array();
|
||||
if($result) {
|
||||
foreach($result as $x) {
|
||||
$r[] = $x;
|
||||
}
|
||||
if($this->debug) {
|
||||
db_logger('dba_pdo: ' . printable(print_r($r,true)), LOGGER_NORMAL, LOG_INFO);
|
||||
}
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
|
||||
function escape($str) {
|
||||
if($this->db && $this->connected) {
|
||||
return substr(substr(@$this->db->quote($str),1),0,-1);
|
||||
}
|
||||
}
|
||||
|
||||
function close() {
|
||||
if($this->db)
|
||||
$this->db = null;
|
||||
$this->connected = false;
|
||||
}
|
||||
|
||||
function getdriver() {
|
||||
return 'pdo';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
<?php /** @file */
|
||||
|
||||
require_once('include/cli_startup.php');
|
||||
require_once('include/zot.php');
|
||||
require_once('include/queue_fn.php');
|
||||
|
||||
|
||||
function deliver_run($argv, $argc) {
|
||||
|
||||
cli_startup();
|
||||
|
||||
$a = get_app();
|
||||
|
||||
if($argc < 2)
|
||||
return;
|
||||
|
||||
logger('deliver: invoked: ' . print_r($argv,true), LOGGER_DATA);
|
||||
|
||||
for($x = 1; $x < $argc; $x ++) {
|
||||
|
||||
$dresult = null;
|
||||
$r = q("select * from outq where outq_hash = '%s' limit 1",
|
||||
dbesc($argv[$x])
|
||||
);
|
||||
if($r) {
|
||||
|
||||
$notify = json_decode($r[0]['outq_notify'],true);
|
||||
|
||||
// Messages without an outq_msg will need to go via the web, even if it's a
|
||||
// local delivery. This includes conversation requests and refresh packets.
|
||||
|
||||
if(($r[0]['outq_posturl'] === z_root() . '/post') && ($r[0]['outq_msg'])) {
|
||||
logger('deliver: local delivery', LOGGER_DEBUG);
|
||||
|
||||
// local delivery
|
||||
// we should probably batch these and save a few delivery processes
|
||||
|
||||
if($r[0]['outq_msg']) {
|
||||
$m = json_decode($r[0]['outq_msg'],true);
|
||||
if(array_key_exists('message_list',$m)) {
|
||||
foreach($m['message_list'] as $mm) {
|
||||
$msg = array('body' => json_encode(array('success' => true, 'pickup' => array(array('notify' => $notify,'message' => $mm)))));
|
||||
zot_import($msg,z_root());
|
||||
}
|
||||
}
|
||||
else {
|
||||
$msg = array('body' => json_encode(array('success' => true, 'pickup' => array(array('notify' => $notify,'message' => $m)))));
|
||||
$dresult = zot_import($msg,z_root());
|
||||
}
|
||||
|
||||
remove_queue_item($r[0]['outq_hash']);
|
||||
|
||||
if($dresult && is_array($dresult)) {
|
||||
foreach($dresult as $xx) {
|
||||
if(is_array($xx) && array_key_exists('message_id',$xx)) {
|
||||
if(delivery_report_is_storable($xx)) {
|
||||
q("insert into dreport ( dreport_mid, dreport_site, dreport_recip, dreport_result, dreport_time, dreport_xchan ) values ( '%s', '%s','%s','%s','%s','%s' ) ",
|
||||
dbesc($xx['message_id']),
|
||||
dbesc($xx['location']),
|
||||
dbesc($xx['recipient']),
|
||||
dbesc($xx['status']),
|
||||
dbesc(datetime_convert($xx['date'])),
|
||||
dbesc($xx['sender'])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
q("delete from dreport where dreport_queue = '%s'",
|
||||
dbesc($argv[$x])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// otherwise it's a remote delivery - call queue_deliver() with the $immediate flag
|
||||
|
||||
queue_deliver($r[0],true);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
deliver_run($argv,$argc);
|
||||
killme();
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
require_once('include/cli_startup.php');
|
||||
require_once('include/zot.php');
|
||||
|
||||
|
||||
function deliver_hooks_run($argv, $argc) {
|
||||
|
||||
cli_startup();
|
||||
|
||||
$a = get_app();
|
||||
|
||||
if($argc < 2)
|
||||
return;
|
||||
|
||||
|
||||
$r = q("select * from item where id = '%d'",
|
||||
intval($argv[1])
|
||||
);
|
||||
if($r)
|
||||
call_hooks('notifier_normal',$r[0]);
|
||||
|
||||
}
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
deliver_hooks_run($argv,$argc);
|
||||
killme();
|
||||
}
|
||||
@@ -69,9 +69,8 @@ function check_upstream_directory() {
|
||||
if ($directory) {
|
||||
$h = parse_url($directory);
|
||||
if ($h) {
|
||||
$x = zot_finger('[system]@' . $h['host']);
|
||||
if ($x['success']) {
|
||||
$j = json_decode($x['body'], true);
|
||||
$j = Zotlabs\Zot\Finger::run('[system]@' . $h['host']);
|
||||
if ($j['success']) {
|
||||
if (array_key_exists('site', $j) && array_key_exists('directory_mode', $j['site'])) {
|
||||
if ($j['site']['directory_mode'] === 'normal') {
|
||||
$isadir = false;
|
||||
@@ -95,6 +94,9 @@ function get_directory_setting($observer, $setting) {
|
||||
if($ret === false)
|
||||
$ret = get_config('directory', $setting);
|
||||
|
||||
|
||||
// 'safemode' is the default if there is no observer or no established preference.
|
||||
|
||||
if($setting == 'safemode' && $ret === false)
|
||||
$ret = 1;
|
||||
|
||||
|
||||
@@ -1,113 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @file include/directory.php
|
||||
* @brief executes directory_run()
|
||||
*/
|
||||
|
||||
require_once('boot.php');
|
||||
require_once('include/zot.php');
|
||||
require_once('include/cli_startup.php');
|
||||
require_once('include/dir_fns.php');
|
||||
require_once('include/queue_fn.php');
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param array $argv
|
||||
* @param array $argc
|
||||
*/
|
||||
function directory_run($argv, $argc){
|
||||
|
||||
cli_startup();
|
||||
|
||||
if($argc < 2)
|
||||
return;
|
||||
|
||||
$force = false;
|
||||
$pushall = true;
|
||||
|
||||
if($argc > 2) {
|
||||
if($argv[2] === 'force')
|
||||
$force = true;
|
||||
if($argv[2] === 'nopush')
|
||||
$pushall = false;
|
||||
}
|
||||
|
||||
logger('directory update', LOGGER_DEBUG);
|
||||
|
||||
$dirmode = get_config('system','directory_mode');
|
||||
if($dirmode === false)
|
||||
$dirmode = DIRECTORY_MODE_NORMAL;
|
||||
|
||||
$x = q("select * from channel where channel_id = %d limit 1",
|
||||
intval($argv[1])
|
||||
);
|
||||
if(! $x)
|
||||
return;
|
||||
|
||||
$channel = $x[0];
|
||||
|
||||
if($dirmode != DIRECTORY_MODE_NORMAL) {
|
||||
|
||||
// this is an in-memory update and we don't need to send a network packet.
|
||||
|
||||
local_dir_update($argv[1],$force);
|
||||
|
||||
q("update channel set channel_dirdate = '%s' where channel_id = %d",
|
||||
dbesc(datetime_convert()),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
|
||||
// Now update all the connections
|
||||
if($pushall)
|
||||
proc_run('php','include/notifier.php','refresh_all',$channel['channel_id']);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// otherwise send the changes upstream
|
||||
|
||||
$directory = find_upstream_directory($dirmode);
|
||||
$url = $directory['url'] . '/post';
|
||||
|
||||
// ensure the upstream directory is updated
|
||||
|
||||
$packet = zot_build_packet($channel,(($force) ? 'force_refresh' : 'refresh'));
|
||||
$z = zot_zot($url,$packet);
|
||||
|
||||
// re-queue if unsuccessful
|
||||
|
||||
if(! $z['success']) {
|
||||
|
||||
/** @FIXME we aren't updating channel_dirdate if we have to queue
|
||||
* the directory packet. That means we'll try again on the next poll run.
|
||||
*/
|
||||
|
||||
$hash = random_string();
|
||||
|
||||
queue_insert(array(
|
||||
'hash' => $hash,
|
||||
'account_id' => $channel['channel_account_id'],
|
||||
'channel_id' => $channel['channel_id'],
|
||||
'posturl' => $url,
|
||||
'notify' => $packet,
|
||||
));
|
||||
|
||||
}
|
||||
else {
|
||||
q("update channel set channel_dirdate = '%s' where channel_id = %d",
|
||||
dbesc(datetime_convert()),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
}
|
||||
|
||||
// Now update all the connections
|
||||
if($pushall)
|
||||
proc_run('php','include/notifier.php','refresh_all',$channel['channel_id']);
|
||||
|
||||
}
|
||||
|
||||
if (array_search(__file__, get_included_files()) === 0) {
|
||||
directory_run($argv, $argc);
|
||||
killme();
|
||||
}
|
||||
@@ -1,652 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @file include/enotify.php
|
||||
*
|
||||
* @brief File with functions and a class for email notifications.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param array $params an assoziative array with:
|
||||
* * \e string \b from_xchan sender xchan hash
|
||||
* * \e string \b to_xchan recipient xchan hash
|
||||
* * \e array \b item an assoziative array
|
||||
* * \e int \b type one of the NOTIFY_* constants from boot.php
|
||||
* * \e string \b link
|
||||
* * \e string \b parent_mid
|
||||
* * \e string \b otype
|
||||
* * \e string \b verb
|
||||
* * \e string \b activity
|
||||
*/
|
||||
function notification($params) {
|
||||
|
||||
logger('notification: entry', LOGGER_DEBUG);
|
||||
|
||||
// throw a small amount of entropy into the system to breakup duplicates arriving at the same precise instant.
|
||||
usleep(mt_rand(0, 10000));
|
||||
|
||||
$a = get_app();
|
||||
|
||||
|
||||
if ($params['from_xchan']) {
|
||||
$x = q("select * from xchan where xchan_hash = '%s' limit 1",
|
||||
dbesc($params['from_xchan'])
|
||||
);
|
||||
}
|
||||
if ($params['to_xchan']) {
|
||||
$y = q("select channel.*, account.* from channel left join account on channel_account_id = account_id
|
||||
where channel_hash = '%s' and channel_removed = 0 limit 1",
|
||||
dbesc($params['to_xchan'])
|
||||
);
|
||||
}
|
||||
if ($x & $y) {
|
||||
$sender = $x[0];
|
||||
$recip = $y[0];
|
||||
} else {
|
||||
logger('notification: no sender or recipient.');
|
||||
logger('sender: ' . $params['from_xchan']);
|
||||
logger('recip: ' . $params['to_xchan']);
|
||||
return;
|
||||
}
|
||||
|
||||
// from here on everything is in the recipients language
|
||||
|
||||
push_lang($recip['account_language']); // should probably have a channel language
|
||||
|
||||
$banner = t('$Projectname Notification');
|
||||
$product = t('$projectname'); // PLATFORM_NAME;
|
||||
$siteurl = z_root();
|
||||
$thanks = t('Thank You,');
|
||||
$sitename = get_config('system','sitename');
|
||||
$site_admin = sprintf( t('%s Administrator'), $sitename);
|
||||
|
||||
$sender_name = $product;
|
||||
$hostname = App::get_hostname();
|
||||
if(strpos($hostname,':'))
|
||||
$hostname = substr($hostname,0,strpos($hostname,':'));
|
||||
|
||||
// Do not translate 'noreply' as it must be a legal 7-bit email address
|
||||
$sender_email = 'noreply' . '@' . $hostname;
|
||||
|
||||
$additional_mail_header = "";
|
||||
|
||||
if (array_key_exists('item', $params)) {
|
||||
require_once('include/conversation.php');
|
||||
// if it's a normal item...
|
||||
if (array_key_exists('verb', $params['item'])) {
|
||||
// localize_item() alters the original item so make a copy first
|
||||
$i = $params['item'];
|
||||
logger('calling localize');
|
||||
localize_item($i);
|
||||
$title = $i['title'];
|
||||
$body = $i['body'];
|
||||
$private = (($i['item_private']) || intval($i['item_obscured']));
|
||||
}
|
||||
else {
|
||||
$title = $params['item']['title'];
|
||||
$body = $params['item']['body'];
|
||||
}
|
||||
} else {
|
||||
$title = $body = '';
|
||||
}
|
||||
|
||||
|
||||
// e.g. "your post", "David's photo", etc.
|
||||
$possess_desc = t('%s <!item_type!>');
|
||||
|
||||
if ($params['type'] == NOTIFY_MAIL) {
|
||||
logger('notification: mail');
|
||||
$subject = sprintf( t('[Hubzilla:Notify] New mail received at %s'),$sitename);
|
||||
|
||||
$preamble = sprintf( t('%1$s, %2$s sent you a new private message at %3$s.'),$recip['channel_name'], $sender['xchan_name'],$sitename);
|
||||
$epreamble = sprintf( t('%1$s sent you %2$s.'),'[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', '[zrl=$itemlink]' . t('a private message') . '[/zrl]');
|
||||
$sitelink = t('Please visit %s to view and/or reply to your private messages.');
|
||||
$tsitelink = sprintf( $sitelink, $siteurl . '/mail/' . $params['item']['id'] );
|
||||
$hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '/mail/' . $params['item']['id'] . '">' . $sitename . '</a>');
|
||||
$itemlink = $siteurl . '/mail/' . $params['item']['id'];
|
||||
}
|
||||
|
||||
if ($params['type'] == NOTIFY_COMMENT) {
|
||||
// logger("notification: params = " . print_r($params, true), LOGGER_DEBUG);
|
||||
|
||||
$itemlink = $params['link'];
|
||||
|
||||
// ignore like/unlike activity on posts - they probably require a sepearate notification preference
|
||||
|
||||
if (array_key_exists('item',$params) && (! visible_activity($params['item'])))
|
||||
return;
|
||||
|
||||
$parent_mid = $params['parent_mid'];
|
||||
|
||||
// Check to see if there was already a notify for this post.
|
||||
// If so don't create a second notification
|
||||
|
||||
$p = null;
|
||||
$p = q("select id from notify where link = '%s' and uid = %d limit 1",
|
||||
dbesc($params['link']),
|
||||
intval($recip['channel_id'])
|
||||
);
|
||||
if ($p) {
|
||||
logger('notification: comment already notified');
|
||||
pop_lang();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// if it's a post figure out who's post it is.
|
||||
|
||||
$p = null;
|
||||
|
||||
if($params['otype'] === 'item' && $parent_mid) {
|
||||
$p = q("select * from item where mid = '%s' and uid = %d limit 1",
|
||||
dbesc($parent_mid),
|
||||
intval($recip['channel_id'])
|
||||
);
|
||||
}
|
||||
|
||||
xchan_query($p);
|
||||
|
||||
|
||||
$item_post_type = item_post_type($p[0]);
|
||||
// $private = $p[0]['item_private'];
|
||||
$parent_id = $p[0]['id'];
|
||||
|
||||
$parent_item = $p[0];
|
||||
|
||||
//$possess_desc = str_replace('<!item_type!>',$possess_desc);
|
||||
|
||||
// "a post"
|
||||
$dest_str = sprintf(t('%1$s, %2$s commented on [zrl=%3$s]a %4$s[/zrl]'),
|
||||
$recip['channel_name'],
|
||||
'[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]',
|
||||
$itemlink,
|
||||
$item_post_type);
|
||||
|
||||
// "George Bull's post"
|
||||
if($p)
|
||||
$dest_str = sprintf(t('%1$s, %2$s commented on [zrl=%3$s]%4$s\'s %5$s[/zrl]'),
|
||||
$recip['channel_name'],
|
||||
'[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]',
|
||||
$itemlink,
|
||||
$p[0]['author']['xchan_name'],
|
||||
$item_post_type);
|
||||
|
||||
// "your post"
|
||||
if($p[0]['owner']['xchan_name'] == $p[0]['author']['xchan_name'] && intval($p[0]['item_wall']))
|
||||
$dest_str = sprintf(t('%1$s, %2$s commented on [zrl=%3$s]your %4$s[/zrl]'),
|
||||
$recip['channel_name'],
|
||||
'[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]',
|
||||
$itemlink,
|
||||
$item_post_type);
|
||||
|
||||
// Some mail softwares relies on subject field for threading.
|
||||
// So, we cannot have different subjects for notifications of the same thread.
|
||||
// Before this we have the name of the replier on the subject rendering
|
||||
// differents subjects for messages on the same thread.
|
||||
|
||||
$subject = sprintf( t('[Hubzilla:Notify] Comment to conversation #%1$d by %2$s'), $parent_id, $sender['xchan_name']);
|
||||
$preamble = sprintf( t('%1$s, %2$s commented on an item/conversation you have been following.'), $recip['channel_name'], $sender['xchan_name']);
|
||||
$epreamble = $dest_str;
|
||||
|
||||
$sitelink = t('Please visit %s to view and/or reply to the conversation.');
|
||||
$tsitelink = sprintf( $sitelink, $siteurl );
|
||||
$hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
|
||||
}
|
||||
|
||||
if($params['type'] == NOTIFY_WALL) {
|
||||
$subject = sprintf( t('[Hubzilla:Notify] %s posted to your profile wall') , $sender['xchan_name']);
|
||||
|
||||
$preamble = sprintf( t('%1$s, %2$s posted to your profile wall at %3$s') , $recip['channel_name'], $sender['xchan_name'], $sitename);
|
||||
|
||||
$epreamble = sprintf( t('%1$s, %2$s posted to [zrl=%3$s]your wall[/zrl]') ,
|
||||
$recip['channel_name'],
|
||||
'[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]',
|
||||
$params['link']);
|
||||
|
||||
$sitelink = t('Please visit %s to view and/or reply to the conversation.');
|
||||
$tsitelink = sprintf( $sitelink, $siteurl );
|
||||
$hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
|
||||
$itemlink = $params['link'];
|
||||
}
|
||||
|
||||
if ($params['type'] == NOTIFY_TAGSELF) {
|
||||
|
||||
$p = null;
|
||||
$p = q("select id from notify where link = '%s' and uid = %d limit 1",
|
||||
dbesc($params['link']),
|
||||
intval($recip['channel_id'])
|
||||
);
|
||||
if ($p) {
|
||||
logger('enotify: tag: already notified about this post');
|
||||
pop_lang();
|
||||
return;
|
||||
}
|
||||
|
||||
$subject = sprintf( t('[Hubzilla:Notify] %s tagged you') , $sender['xchan_name']);
|
||||
$preamble = sprintf( t('%1$s, %2$s tagged you at %3$s') , $recip['channel_name'], $sender['xchan_name'], $sitename);
|
||||
$epreamble = sprintf( t('%1$s, %2$s [zrl=%3$s]tagged you[/zrl].') ,
|
||||
$recip['channel_name'],
|
||||
'[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]',
|
||||
$params['link']);
|
||||
|
||||
$sitelink = t('Please visit %s to view and/or reply to the conversation.');
|
||||
$tsitelink = sprintf( $sitelink, $siteurl );
|
||||
$hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
|
||||
$itemlink = $params['link'];
|
||||
}
|
||||
|
||||
if ($params['type'] == NOTIFY_POKE) {
|
||||
$subject = sprintf( t('[Hubzilla:Notify] %1$s poked you') , $sender['xchan_name']);
|
||||
$preamble = sprintf( t('%1$s, %2$s poked you at %3$s') , $recip['channel_name'], $sender['xchan_name'], $sitename);
|
||||
$epreamble = sprintf( t('%1$s, %2$s [zrl=%2$s]poked you[/zrl].') ,
|
||||
$recip['channel_name'],
|
||||
'[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]',
|
||||
$params['link']);
|
||||
|
||||
$subject = str_replace('poked', t($params['activity']), $subject);
|
||||
$preamble = str_replace('poked', t($params['activity']), $preamble);
|
||||
$epreamble = str_replace('poked', t($params['activity']), $epreamble);
|
||||
|
||||
$sitelink = t('Please visit %s to view and/or reply to the conversation.');
|
||||
$tsitelink = sprintf( $sitelink, $siteurl );
|
||||
$hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
|
||||
$itemlink = $params['link'];
|
||||
}
|
||||
|
||||
if ($params['type'] == NOTIFY_TAGSHARE) {
|
||||
$subject = sprintf( t('[Hubzilla:Notify] %s tagged your post') , $sender['xchan_name']);
|
||||
$preamble = sprintf( t('%1$s, %2$s tagged your post at %3$s') , $recip['channel_name'],$sender['xchan_name'], $sitename);
|
||||
$epreamble = sprintf( t('%1$s, %2$s tagged [zrl=%3$s]your post[/zrl]') ,
|
||||
$recip['channel_name'],
|
||||
'[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]',
|
||||
$itemlink);
|
||||
|
||||
$sitelink = t('Please visit %s to view and/or reply to the conversation.');
|
||||
$tsitelink = sprintf( $sitelink, $siteurl );
|
||||
$hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
|
||||
$itemlink = $params['link'];
|
||||
}
|
||||
|
||||
if ($params['type'] == NOTIFY_INTRO) {
|
||||
$subject = sprintf( t('[Hubzilla:Notify] Introduction received'));
|
||||
$preamble = sprintf( t('%1$s, you\'ve received an new connection request from \'%2$s\' at %3$s'), $recip['channel_name'], $sender['xchan_name'], $sitename);
|
||||
$epreamble = sprintf( t('%1$s, you\'ve received [zrl=%2$s]a new connection request[/zrl] from %3$s.'),
|
||||
$recip['channel_name'],
|
||||
$siteurl . '/connections/ifpending',
|
||||
'[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]');
|
||||
$body = sprintf( t('You may visit their profile at %s'),$sender['xchan_url']);
|
||||
|
||||
$sitelink = t('Please visit %s to approve or reject the connection request.');
|
||||
$tsitelink = sprintf( $sitelink, $siteurl . '/connections/ifpending');
|
||||
$hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '/connections/ifpending">' . $sitename . '</a>');
|
||||
$itemlink = $params['link'];
|
||||
}
|
||||
|
||||
if ($params['type'] == NOTIFY_SUGGEST) {
|
||||
$subject = sprintf( t('[Hubzilla:Notify] Friend suggestion received'));
|
||||
$preamble = sprintf( t('%1$s, you\'ve received a friend suggestion from \'%2$s\' at %3$s'), $recip['channel_name'], $sender['xchan_name'], $sitename);
|
||||
$epreamble = sprintf( t('%1$s, you\'ve received [zrl=%2$s]a friend suggestion[/zrl] for %3$s from %4$s.'),
|
||||
$recip['channel_name'],
|
||||
$itemlink,
|
||||
'[zrl=' . $params['item']['url'] . ']' . $params['item']['name'] . '[/zrl]',
|
||||
'[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]');
|
||||
|
||||
$body = t('Name:') . ' ' . $params['item']['name'] . "\n";
|
||||
$body .= t('Photo:') . ' ' . $params['item']['photo'] . "\n";
|
||||
$body .= sprintf( t('You may visit their profile at %s'),$params['item']['url']);
|
||||
|
||||
$sitelink = t('Please visit %s to approve or reject the suggestion.');
|
||||
$tsitelink = sprintf( $sitelink, $siteurl );
|
||||
$hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
|
||||
$itemlink = $params['link'];
|
||||
}
|
||||
|
||||
if ($params['type'] == NOTIFY_CONFIRM) {
|
||||
// ?
|
||||
}
|
||||
|
||||
if ($params['type'] == NOTIFY_SYSTEM) {
|
||||
// ?
|
||||
}
|
||||
|
||||
$h = array(
|
||||
'params' => $params,
|
||||
'subject' => $subject,
|
||||
'preamble' => $preamble,
|
||||
'epreamble' => $epreamble,
|
||||
'body' => $body,
|
||||
'sitelink' => $sitelink,
|
||||
'sitename' => $sitename,
|
||||
'tsitelink' => $tsitelink,
|
||||
'hsitelink' => $hsitelink,
|
||||
'itemlink' => $itemlink,
|
||||
'sender' => $sender,
|
||||
'recipient' => $recip
|
||||
);
|
||||
|
||||
call_hooks('enotify', $h);
|
||||
|
||||
$subject = $h['subject'];
|
||||
$preamble = $h['preamble'];
|
||||
$epreamble = $h['epreamble'];
|
||||
$body = $h['body'];
|
||||
$sitelink = $h['sitelink'];
|
||||
$tsitelink = $h['tsitelink'];
|
||||
$hsitelink = $h['hsitelink'];
|
||||
$itemlink = $h['itemlink'];
|
||||
|
||||
|
||||
require_once('include/html2bbcode.php');
|
||||
|
||||
do {
|
||||
$dups = false;
|
||||
$hash = random_string();
|
||||
$r = q("SELECT `id` FROM `notify` WHERE `hash` = '%s' LIMIT 1",
|
||||
dbesc($hash));
|
||||
if (count($r))
|
||||
$dups = true;
|
||||
} while ($dups === true);
|
||||
|
||||
|
||||
$datarray = array();
|
||||
$datarray['hash'] = $hash;
|
||||
$datarray['sender_hash'] = $sender['xchan_hash'];
|
||||
$datarray['name'] = $sender['xchan_name'];
|
||||
$datarray['url'] = $sender['xchan_url'];
|
||||
$datarray['photo'] = $sender['xchan_photo_s'];
|
||||
$datarray['date'] = datetime_convert();
|
||||
$datarray['aid'] = $recip['channel_account_id'];
|
||||
$datarray['uid'] = $recip['channel_id'];
|
||||
$datarray['link'] = $itemlink;
|
||||
$datarray['parent'] = $parent_mid;
|
||||
$datarray['parent_item'] = $parent_item;
|
||||
$datarray['type'] = $params['type'];
|
||||
$datarray['verb'] = $params['verb'];
|
||||
$datarray['otype'] = $params['otype'];
|
||||
$datarray['abort'] = false;
|
||||
|
||||
$datarray['item'] = $params['item'];
|
||||
|
||||
call_hooks('enotify_store', $datarray);
|
||||
|
||||
if ($datarray['abort']) {
|
||||
pop_lang();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// create notification entry in DB
|
||||
$seen = 0;
|
||||
|
||||
// Mark some notifications as seen right away
|
||||
// Note! The notification have to be created, because they are used to send emails
|
||||
// So easiest solution to hide them from Notices is to mark them as seen right away.
|
||||
// Another option would be to not add them to the DB, and change how emails are handled (probably would be better that way)
|
||||
$always_show_in_notices = get_pconfig($recip['channel_id'],'system','always_show_in_notices');
|
||||
if (!$always_show_in_notices) {
|
||||
if (($params['type'] == NOTIFY_WALL) || ($params['type'] == NOTIFY_MAIL) || ($params['type'] == NOTIFY_INTRO)) {
|
||||
$seen = 1;
|
||||
}
|
||||
}
|
||||
|
||||
$r = q("insert into notify (hash,name,url,photo,date,aid,uid,link,parent,seen,type,verb,otype)
|
||||
values('%s','%s','%s','%s','%s',%d,%d,'%s','%s',%d,%d,'%s','%s')",
|
||||
dbesc($datarray['hash']),
|
||||
dbesc($datarray['name']),
|
||||
dbesc($datarray['url']),
|
||||
dbesc($datarray['photo']),
|
||||
dbesc($datarray['date']),
|
||||
intval($datarray['aid']),
|
||||
intval($datarray['uid']),
|
||||
dbesc($datarray['link']),
|
||||
dbesc($datarray['parent']),
|
||||
intval($seen),
|
||||
intval($datarray['type']),
|
||||
dbesc($datarray['verb']),
|
||||
dbesc($datarray['otype'])
|
||||
);
|
||||
|
||||
$r = q("select id from notify where hash = '%s' and uid = %d limit 1",
|
||||
dbesc($hash),
|
||||
intval($recip['channel_id'])
|
||||
);
|
||||
if ($r) {
|
||||
$notify_id = $r[0]['id'];
|
||||
} else {
|
||||
logger('notification not found.');
|
||||
pop_lang();
|
||||
return;
|
||||
}
|
||||
|
||||
$itemlink = z_root() . '/notify/view/' . $notify_id;
|
||||
$msg = str_replace('$itemlink',$itemlink,$epreamble);
|
||||
|
||||
// wretched hack, but we don't want to duplicate all the preamble variations and we also don't want to screw up a translation
|
||||
|
||||
if ((App::$language === 'en' || (! App::$language)) && strpos($msg,', '))
|
||||
$msg = substr($msg,strpos($msg,', ')+1);
|
||||
|
||||
$r = q("update notify set msg = '%s' where id = %d and uid = %d",
|
||||
dbesc($msg),
|
||||
intval($notify_id),
|
||||
intval($datarray['uid'])
|
||||
);
|
||||
|
||||
// send email notification if notification preferences permit
|
||||
|
||||
require_once('bbcode.php');
|
||||
if ((intval($recip['channel_notifyflags']) & intval($params['type'])) || $params['type'] == NOTIFY_SYSTEM) {
|
||||
|
||||
logger('notification: sending notification email');
|
||||
|
||||
$hn = get_pconfig($recip['channel_id'],'system','email_notify_host');
|
||||
if($hn && (! stristr(App::get_hostname(),$hn))) {
|
||||
// this isn't the email notification host
|
||||
pop_lang();
|
||||
return;
|
||||
}
|
||||
|
||||
$textversion = strip_tags(html_entity_decode(bbcode(stripslashes(str_replace(array("\\r", "\\n"), array( "", "\n"), $body))),ENT_QUOTES,'UTF-8'));
|
||||
|
||||
$htmlversion = bbcode(stripslashes(str_replace(array("\\r","\\n"), array("","<br />\n"),$body)));
|
||||
|
||||
|
||||
// use $_SESSION['zid_override'] to force zid() to use
|
||||
// the recipient address instead of the current observer
|
||||
|
||||
$_SESSION['zid_override'] = $recip['channel_address'] . '@' . App::get_hostname();
|
||||
$_SESSION['zrl_override'] = z_root() . '/channel/' . $recip['channel_address'];
|
||||
|
||||
$textversion = zidify_links($textversion);
|
||||
$htmlversion = zidify_links($htmlversion);
|
||||
|
||||
// unset when done to revert to normal behaviour
|
||||
|
||||
unset($_SESSION['zid_override']);
|
||||
unset($_SESSION['zrl_override']);
|
||||
|
||||
$datarray = array();
|
||||
$datarray['banner'] = $banner;
|
||||
$datarray['product'] = $product;
|
||||
$datarray['preamble'] = $preamble;
|
||||
$datarray['sitename'] = $sitename;
|
||||
$datarray['siteurl'] = $siteurl;
|
||||
$datarray['type'] = $params['type'];
|
||||
$datarray['parent'] = $params['parent_mid'];
|
||||
$datarray['source_name'] = $sender['xchan_name'];
|
||||
$datarray['source_link'] = $sender['xchan_url'];
|
||||
$datarray['source_photo'] = $sender['xchan_photo_s'];
|
||||
$datarray['uid'] = $recip['channel_id'];
|
||||
$datarray['username'] = $recip['channel_name'];
|
||||
$datarray['hsitelink'] = $hsitelink;
|
||||
$datarray['tsitelink'] = $tsitelink;
|
||||
$datarray['hitemlink'] = '<a href="' . $itemlink . '">' . $itemlink . '</a>';
|
||||
$datarray['titemlink'] = $itemlink;
|
||||
$datarray['thanks'] = $thanks;
|
||||
$datarray['site_admin'] = $site_admin;
|
||||
$datarray['title'] = stripslashes($title);
|
||||
$datarray['htmlversion'] = $htmlversion;
|
||||
$datarray['textversion'] = $textversion;
|
||||
$datarray['subject'] = $subject;
|
||||
$datarray['headers'] = $additional_mail_header;
|
||||
$datarray['email_secure'] = false;
|
||||
|
||||
call_hooks('enotify_mail', $datarray);
|
||||
|
||||
// Default to private - don't disclose message contents over insecure channels (such as email)
|
||||
// Might be interesting to use GPG,PGP,S/MIME encryption instead
|
||||
// but we'll save that for a clever plugin developer to implement
|
||||
|
||||
$private_activity = false;
|
||||
|
||||
if (! $datarray['email_secure']) {
|
||||
switch ($params['type']) {
|
||||
case NOTIFY_WALL:
|
||||
case NOTIFY_TAGSELF:
|
||||
case NOTIFY_POKE:
|
||||
case NOTIFY_COMMENT:
|
||||
if (! $private)
|
||||
break;
|
||||
$private_activity = true;
|
||||
case NOTIFY_MAIL:
|
||||
$datarray['textversion'] = $datarray['htmlversion'] = $datarray['title'] = '';
|
||||
$datarray['subject'] = preg_replace('/' . preg_quote(t('[Hubzilla:Notify]')) . '/','$0*',$datarray['subject']);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($private_activity
|
||||
&& intval(get_pconfig($datarray['uid'], 'system', 'ignore_private_notifications'))) {
|
||||
|
||||
pop_lang();
|
||||
return;
|
||||
}
|
||||
|
||||
// load the template for private message notifications
|
||||
$tpl = get_markup_template('email_notify_html.tpl');
|
||||
$email_html_body = replace_macros($tpl,array(
|
||||
'$banner' => $datarray['banner'],
|
||||
'$notify_icon' => Zotlabs\Project\System::get_notify_icon(),
|
||||
'$product' => $datarray['product'],
|
||||
'$preamble' => $datarray['preamble'],
|
||||
'$sitename' => $datarray['sitename'],
|
||||
'$siteurl' => $datarray['siteurl'],
|
||||
'$source_name' => $datarray['source_name'],
|
||||
'$source_link' => $datarray['source_link'],
|
||||
'$source_photo' => $datarray['source_photo'],
|
||||
'$username' => $datarray['to_name'],
|
||||
'$hsitelink' => $datarray['hsitelink'],
|
||||
'$hitemlink' => $datarray['hitemlink'],
|
||||
'$thanks' => $datarray['thanks'],
|
||||
'$site_admin' => $datarray['site_admin'],
|
||||
'$title' => $datarray['title'],
|
||||
'$htmlversion' => $datarray['htmlversion'],
|
||||
));
|
||||
|
||||
// load the template for private message notifications
|
||||
$tpl = get_markup_template('email_notify_text.tpl');
|
||||
$email_text_body = replace_macros($tpl, array(
|
||||
'$banner' => $datarray['banner'],
|
||||
'$product' => $datarray['product'],
|
||||
'$preamble' => $datarray['preamble'],
|
||||
'$sitename' => $datarray['sitename'],
|
||||
'$siteurl' => $datarray['siteurl'],
|
||||
'$source_name' => $datarray['source_name'],
|
||||
'$source_link' => $datarray['source_link'],
|
||||
'$source_photo' => $datarray['source_photo'],
|
||||
'$username' => $datarray['to_name'],
|
||||
'$tsitelink' => $datarray['tsitelink'],
|
||||
'$titemlink' => $datarray['titemlink'],
|
||||
'$thanks' => $datarray['thanks'],
|
||||
'$site_admin' => $datarray['site_admin'],
|
||||
'$title' => $datarray['title'],
|
||||
'$textversion' => $datarray['textversion'],
|
||||
));
|
||||
|
||||
// logger('text: ' . $email_text_body);
|
||||
|
||||
// use the EmailNotification library to send the message
|
||||
|
||||
enotify::send(array(
|
||||
'fromName' => $sender_name,
|
||||
'fromEmail' => $sender_email,
|
||||
'replyTo' => $sender_email,
|
||||
'toEmail' => $recip['account_email'],
|
||||
'messageSubject' => $datarray['subject'],
|
||||
'htmlVersion' => $email_html_body,
|
||||
'textVersion' => $email_text_body,
|
||||
'additionalMailHeader' => $datarray['headers'],
|
||||
));
|
||||
}
|
||||
|
||||
pop_lang();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief A class for sending email notifications.
|
||||
*
|
||||
* @fixme Class names start mostly with capital letter to distinguish them easier.
|
||||
*/
|
||||
class enotify {
|
||||
/**
|
||||
* @brief Send a multipart/alternative message with Text and HTML versions.
|
||||
*
|
||||
* @param array $params an assoziative array with:
|
||||
* * \e string \b fromName name of the sender
|
||||
* * \e string \b fromEmail email of the sender
|
||||
* * \e string \b replyTo replyTo address to direct responses
|
||||
* * \e string \b toEmail destination email address
|
||||
* * \e string \b messageSubject subject of the message
|
||||
* * \e string \b htmlVersion html version of the message
|
||||
* * \e string \b textVersion text only version of the message
|
||||
* * \e string \b additionalMailHeader additions to the smtp mail header
|
||||
*/
|
||||
static public function send($params) {
|
||||
|
||||
$fromName = email_header_encode(html_entity_decode($params['fromName'],ENT_QUOTES,'UTF-8'),'UTF-8');
|
||||
$messageSubject = email_header_encode(html_entity_decode($params['messageSubject'],ENT_QUOTES,'UTF-8'),'UTF-8');
|
||||
|
||||
// generate a mime boundary
|
||||
$mimeBoundary = rand(0, 9) . "-"
|
||||
.rand(10000000000, 9999999999) . "-"
|
||||
.rand(10000000000, 9999999999) . "=:"
|
||||
.rand(10000, 99999);
|
||||
|
||||
// generate a multipart/alternative message header
|
||||
$messageHeader =
|
||||
$params['additionalMailHeader'] .
|
||||
"From: $fromName <{$params['fromEmail']}>\n" .
|
||||
"Reply-To: $fromName <{$params['replyTo']}>\n" .
|
||||
"MIME-Version: 1.0\n" .
|
||||
"Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\"";
|
||||
|
||||
// assemble the final multipart message body with the text and html types included
|
||||
$textBody = chunk_split(base64_encode($params['textVersion']));
|
||||
$htmlBody = chunk_split(base64_encode($params['htmlVersion']));
|
||||
|
||||
$multipartMessageBody =
|
||||
"--" . $mimeBoundary . "\n" . // plain text section
|
||||
"Content-Type: text/plain; charset=UTF-8\n" .
|
||||
"Content-Transfer-Encoding: base64\n\n" .
|
||||
$textBody . "\n" .
|
||||
"--" . $mimeBoundary . "\n" . // text/html section
|
||||
"Content-Type: text/html; charset=UTF-8\n" .
|
||||
"Content-Transfer-Encoding: base64\n\n" .
|
||||
$htmlBody . "\n" .
|
||||
"--" . $mimeBoundary . "--\n"; // message ending
|
||||
|
||||
// send the message
|
||||
$res = mail(
|
||||
$params['toEmail'], // send to address
|
||||
$messageSubject, // subject
|
||||
$multipartMessageBody, // message body
|
||||
$messageHeader // message headers
|
||||
);
|
||||
logger("notification: enotify::send returns " . $res, LOGGER_DEBUG);
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,8 @@ function phpiniSizeToBytes($val) {
|
||||
$val *= 1024;
|
||||
case 'k':
|
||||
$val *= 1024;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return (int)$val;
|
||||
|
||||
@@ -28,22 +28,22 @@ function format_event_html($ev) {
|
||||
$o .= '<div class="event-title"><h3><i class="fa fa-calendar"></i> ' . bbcode($ev['summary']) . '</h3></div>' . "\r\n";
|
||||
|
||||
$o .= '<div class="event-start"><span class="event-label">' . t('Starts:') . '</span> <span class="dtstart" title="'
|
||||
. datetime_convert('UTC', 'UTC', $ev['start'], (($ev['adjust']) ? ATOM_TIME : 'Y-m-d\TH:i:s' ))
|
||||
. datetime_convert('UTC', 'UTC', $ev['dtstart'], (($ev['adjust']) ? ATOM_TIME : 'Y-m-d\TH:i:s' ))
|
||||
. '" >'
|
||||
. (($ev['adjust']) ? day_translate(datetime_convert('UTC', date_default_timezone_get(),
|
||||
$ev['start'] , $bd_format ))
|
||||
$ev['dtstart'] , $bd_format ))
|
||||
: day_translate(datetime_convert('UTC', 'UTC',
|
||||
$ev['start'] , $bd_format)))
|
||||
$ev['dtstart'] , $bd_format)))
|
||||
. '</span></div>' . "\r\n";
|
||||
|
||||
if(! $ev['nofinish'])
|
||||
$o .= '<div class="event-end" ><span class="event-label">' . t('Finishes:') . '</span> <span class="dtend" title="'
|
||||
. datetime_convert('UTC','UTC',$ev['finish'], (($ev['adjust']) ? ATOM_TIME : 'Y-m-d\TH:i:s' ))
|
||||
. datetime_convert('UTC','UTC',$ev['dtend'], (($ev['adjust']) ? ATOM_TIME : 'Y-m-d\TH:i:s' ))
|
||||
. '" >'
|
||||
. (($ev['adjust']) ? day_translate(datetime_convert('UTC', date_default_timezone_get(),
|
||||
$ev['finish'] , $bd_format ))
|
||||
$ev['dtend'] , $bd_format ))
|
||||
: day_translate(datetime_convert('UTC', 'UTC',
|
||||
$ev['finish'] , $bd_format )))
|
||||
$ev['dtend'] , $bd_format )))
|
||||
. '</span></div>' . "\r\n";
|
||||
|
||||
$o .= '<div class="event-description">' . bbcode($ev['description']) . '</div>' . "\r\n";
|
||||
@@ -58,6 +58,37 @@ function format_event_html($ev) {
|
||||
return $o;
|
||||
}
|
||||
|
||||
function format_event_obj($jobject) {
|
||||
$event = array();
|
||||
|
||||
$object = json_decode($jobject,true);
|
||||
|
||||
//ensure compatibility with older items - this check can be removed at a later point
|
||||
if(array_key_exists('description', $object)) {
|
||||
|
||||
$bd_format = t('l F d, Y \@ g:i A'); // Friday January 18, 2011 @ 8:01 AM
|
||||
|
||||
$event['header'] = replace_macros(get_markup_template('event_item_header.tpl'),array(
|
||||
'$title' => bbcode($object['title']),
|
||||
'$dtstart_label' => t('Starts:'),
|
||||
'$dtstart_title' => datetime_convert('UTC', 'UTC', $object['dtstart'], (($object['adjust']) ? ATOM_TIME : 'Y-m-d\TH:i:s' )),
|
||||
'$dtstart_dt' => (($object['adjust']) ? day_translate(datetime_convert('UTC', date_default_timezone_get(), $object['dtstart'] , $bd_format )) : day_translate(datetime_convert('UTC', 'UTC', $object['dtstart'] , $bd_format))),
|
||||
'$finish' => (($object['nofinish']) ? false : true),
|
||||
'$dtend_label' => t('Finishes:'),
|
||||
'$dtend_title' => datetime_convert('UTC','UTC',$object['dtend'], (($object['adjust']) ? ATOM_TIME : 'Y-m-d\TH:i:s' )),
|
||||
'$dtend_dt' => (($object['adjust']) ? day_translate(datetime_convert('UTC', date_default_timezone_get(), $object['dtend'] , $bd_format )) : day_translate(datetime_convert('UTC', 'UTC', $object['dtend'] , $bd_format )))
|
||||
));
|
||||
|
||||
$event['content'] = replace_macros(get_markup_template('event_item_content.tpl'),array(
|
||||
'$description' => bbcode($object['description']),
|
||||
'$location_label' => t('Location:'),
|
||||
'$location' => bbcode($object['location'])
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
function ical_wrapper($ev) {
|
||||
|
||||
@@ -67,8 +98,8 @@ function ical_wrapper($ev) {
|
||||
$o .= "BEGIN:VCALENDAR";
|
||||
$o .= "\r\nVERSION:2.0";
|
||||
$o .= "\r\nMETHOD:PUBLISH";
|
||||
$o .= "\r\nPRODID:-//" . get_config('system','sitename') . "//" . Zotlabs\Project\System::get_platform_name() . "//" . strtoupper(App::$language). "\r\n";
|
||||
if(array_key_exists('start', $ev))
|
||||
$o .= "\r\nPRODID:-//" . get_config('system','sitename') . "//" . Zotlabs\Lib\System::get_platform_name() . "//" . strtoupper(App::$language). "\r\n";
|
||||
if(array_key_exists('dtstart', $ev))
|
||||
$o .= format_event_ical($ev);
|
||||
else {
|
||||
foreach($ev as $e) {
|
||||
@@ -82,7 +113,7 @@ function ical_wrapper($ev) {
|
||||
|
||||
function format_event_ical($ev) {
|
||||
|
||||
if($ev['type'] === 'task')
|
||||
if($ev['etype'] === 'task')
|
||||
return format_todo_ical($ev);
|
||||
|
||||
$o = '';
|
||||
@@ -92,10 +123,10 @@ function format_event_ical($ev) {
|
||||
$o .= "\r\nCREATED:" . datetime_convert('UTC','UTC', $ev['created'],'Ymd\\THis\\Z');
|
||||
$o .= "\r\nLAST-MODIFIED:" . datetime_convert('UTC','UTC', $ev['edited'],'Ymd\\THis\\Z');
|
||||
$o .= "\r\nDTSTAMP:" . datetime_convert('UTC','UTC', $ev['edited'],'Ymd\\THis\\Z');
|
||||
if($ev['start'])
|
||||
$o .= "\r\nDTSTART:" . datetime_convert('UTC','UTC', $ev['start'],'Ymd\\THis' . (($ev['adjust']) ? '\\Z' : ''));
|
||||
if($ev['finish'] && ! $ev['nofinish'])
|
||||
$o .= "\r\nDTEND:" . datetime_convert('UTC','UTC', $ev['finish'],'Ymd\\THis' . (($ev['adjust']) ? '\\Z' : ''));
|
||||
if($ev['dtstart'])
|
||||
$o .= "\r\nDTSTART:" . datetime_convert('UTC','UTC', $ev['dtstart'],'Ymd\\THis' . (($ev['adjust']) ? '\\Z' : ''));
|
||||
if($ev['dtend'] && ! $ev['nofinish'])
|
||||
$o .= "\r\nDTEND:" . datetime_convert('UTC','UTC', $ev['dtend'],'Ymd\\THis' . (($ev['adjust']) ? '\\Z' : ''));
|
||||
if($ev['summary'])
|
||||
$o .= "\r\nSUMMARY:" . format_ical_text($ev['summary']);
|
||||
if($ev['location'])
|
||||
@@ -119,10 +150,10 @@ function format_todo_ical($ev) {
|
||||
$o .= "\r\nCREATED:" . datetime_convert('UTC','UTC', $ev['created'],'Ymd\\THis\\Z');
|
||||
$o .= "\r\nLAST-MODIFIED:" . datetime_convert('UTC','UTC', $ev['edited'],'Ymd\\THis\\Z');
|
||||
$o .= "\r\nDTSTAMP:" . datetime_convert('UTC','UTC', $ev['edited'],'Ymd\\THis\\Z');
|
||||
if($ev['start'])
|
||||
$o .= "\r\nDTSTART:" . datetime_convert('UTC','UTC', $ev['start'],'Ymd\\THis' . (($ev['adjust']) ? '\\Z' : ''));
|
||||
if($ev['finish'] && ! $ev['nofinish'])
|
||||
$o .= "\r\nDUE:" . datetime_convert('UTC','UTC', $ev['finish'],'Ymd\\THis' . (($ev['adjust']) ? '\\Z' : ''));
|
||||
if($ev['dtstart'])
|
||||
$o .= "\r\nDTSTART:" . datetime_convert('UTC','UTC', $ev['dtstart'],'Ymd\\THis' . (($ev['adjust']) ? '\\Z' : ''));
|
||||
if($ev['dtend'] && ! $ev['nofinish'])
|
||||
$o .= "\r\nDUE:" . datetime_convert('UTC','UTC', $ev['dtend'],'Ymd\\THis' . (($ev['adjust']) ? '\\Z' : ''));
|
||||
if($ev['summary'])
|
||||
$o .= "\r\nSUMMARY:" . format_ical_text($ev['summary']);
|
||||
if($ev['event_status']) {
|
||||
@@ -166,15 +197,18 @@ function format_event_bbcode($ev) {
|
||||
if($ev['description'])
|
||||
$o .= '[event-description]' . $ev['description'] . '[/event-description]';
|
||||
|
||||
if($ev['start'])
|
||||
$o .= '[event-start]' . $ev['start'] . '[/event-start]';
|
||||
if($ev['dtstart'])
|
||||
$o .= '[event-start]' . $ev['dtstart'] . '[/event-start]';
|
||||
|
||||
if(($ev['finish']) && (! $ev['nofinish']))
|
||||
$o .= '[event-finish]' . $ev['finish'] . '[/event-finish]';
|
||||
if(($ev['dtend']) && (! $ev['nofinish']))
|
||||
$o .= '[event-finish]' . $ev['dtend'] . '[/event-finish]';
|
||||
|
||||
if($ev['location'])
|
||||
$o .= '[event-location]' . $ev['location'] . '[/event-location]';
|
||||
|
||||
if($ev['event_hash'])
|
||||
$o .= '[event-id]' . $ev['event_hash'] . '[/event-id]';
|
||||
|
||||
if($ev['adjust'])
|
||||
$o .= '[event-adjust]' . $ev['adjust'] . '[/event-adjust]';
|
||||
|
||||
@@ -204,21 +238,24 @@ function bbtoevent($s) {
|
||||
$ev['description'] = $match[1];
|
||||
$match = '';
|
||||
if(preg_match("/\[event\-start\](.*?)\[\/event\-start\]/is",$s,$match))
|
||||
$ev['start'] = $match[1];
|
||||
$ev['dtstart'] = $match[1];
|
||||
$match = '';
|
||||
if(preg_match("/\[event\-finish\](.*?)\[\/event\-finish\]/is",$s,$match))
|
||||
$ev['finish'] = $match[1];
|
||||
$ev['dtend'] = $match[1];
|
||||
$match = '';
|
||||
if(preg_match("/\[event\-location\](.*?)\[\/event\-location\]/is",$s,$match))
|
||||
$ev['location'] = $match[1];
|
||||
$match = '';
|
||||
if(preg_match("/\[event\-id\](.*?)\[\/event\-id\]/is",$s,$match))
|
||||
$ev['event_hash'] = $match[1];
|
||||
$match = '';
|
||||
if(preg_match("/\[event\-adjust\](.*?)\[\/event\-adjust\]/is",$s,$match))
|
||||
$ev['adjust'] = $match[1];
|
||||
if(array_key_exists('start',$ev)) {
|
||||
if(array_key_exists('finish',$ev)) {
|
||||
if($ev['finish'] === $ev['start'])
|
||||
if(array_key_exists('dtstart',$ev)) {
|
||||
if(array_key_exists('dtend',$ev)) {
|
||||
if($ev['dtend'] === $ev['dtstart'])
|
||||
$ev['nofinish'] = 1;
|
||||
elseif($ev['finish'])
|
||||
elseif($ev['dtend'])
|
||||
$ev['nofinish'] = 0;
|
||||
else
|
||||
$ev['nofinish'] = 1;
|
||||
@@ -254,8 +291,8 @@ function sort_by_date($arr) {
|
||||
*/
|
||||
function ev_compare($a, $b) {
|
||||
|
||||
$date_a = (($a['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$a['start']) : $a['start']);
|
||||
$date_b = (($b['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$b['start']) : $b['start']);
|
||||
$date_a = (($a['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$a['dtstart']) : $a['dtstart']);
|
||||
$date_b = (($b['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$b['dtstart']) : $b['dtstart']);
|
||||
|
||||
if ($date_a === $date_b)
|
||||
return strcasecmp($a['description'], $b['description']);
|
||||
@@ -268,7 +305,7 @@ function event_store_event($arr) {
|
||||
|
||||
$arr['created'] = (($arr['created']) ? $arr['created'] : datetime_convert());
|
||||
$arr['edited'] = (($arr['edited']) ? $arr['edited'] : datetime_convert());
|
||||
$arr['type'] = (($arr['type']) ? $arr['type'] : 'event' );
|
||||
$arr['etype'] = (($arr['etype']) ? $arr['etype'] : 'event' );
|
||||
$arr['event_xchan'] = (($arr['event_xchan']) ? $arr['event_xchan'] : '');
|
||||
$arr['event_priority'] = (($arr['event_priority']) ? $arr['event_priority'] : 0);
|
||||
|
||||
@@ -278,45 +315,52 @@ function event_store_event($arr) {
|
||||
else
|
||||
$arr['event_status_date'] = NULL_DATE;
|
||||
|
||||
// Existing event being modified
|
||||
|
||||
if($arr['id'] || $arr['event_hash']) {
|
||||
$existing_event = null;
|
||||
|
||||
// has the event actually changed?
|
||||
if($arr['event_hash']) {
|
||||
$r = q("SELECT * FROM event WHERE event_hash = '%s' AND uid = %d LIMIT 1",
|
||||
dbesc($arr['event_hash']),
|
||||
intval($arr['uid'])
|
||||
);
|
||||
if($r) {
|
||||
$existing_event = $r[0];
|
||||
}
|
||||
}
|
||||
|
||||
if($arr['event_hash']) {
|
||||
$r = q("SELECT * FROM event WHERE event_hash = '%s' AND uid = %d LIMIT 1",
|
||||
dbesc($arr['event_hash']),
|
||||
intval($arr['uid'])
|
||||
);
|
||||
if($arr['id']) {
|
||||
$r = q("SELECT * FROM event WHERE id = %d AND uid = %d LIMIT 1",
|
||||
intval($arr['id']),
|
||||
intval($arr['uid'])
|
||||
);
|
||||
if($r) {
|
||||
$existing_event = $r[0];
|
||||
}
|
||||
else {
|
||||
$r = q("SELECT * FROM event WHERE id = %d AND uid = %d LIMIT 1",
|
||||
intval($arr['id']),
|
||||
intval($arr['uid'])
|
||||
);
|
||||
}
|
||||
|
||||
if(! $r)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if($r[0]['edited'] === $arr['edited']) {
|
||||
// Nothing has changed. Return the ID.
|
||||
return $r[0];
|
||||
|
||||
if($existing_event) {
|
||||
|
||||
if($existing_event['edited'] >= $arr['edited']) {
|
||||
// Nothing has changed.
|
||||
return $existing_event;
|
||||
}
|
||||
|
||||
$hash = $r[0]['event_hash'];
|
||||
$hash = $existing_event['event_hash'];
|
||||
|
||||
// The event changed. Update it.
|
||||
|
||||
$r = q("UPDATE `event` SET
|
||||
`edited` = '%s',
|
||||
`start` = '%s',
|
||||
`finish` = '%s',
|
||||
`dtstart` = '%s',
|
||||
`dtend` = '%s',
|
||||
`summary` = '%s',
|
||||
`description` = '%s',
|
||||
`location` = '%s',
|
||||
`type` = '%s',
|
||||
`etype` = '%s',
|
||||
`adjust` = %d,
|
||||
`nofinish` = %d,
|
||||
`event_status` = '%s',
|
||||
@@ -332,12 +376,12 @@ function event_store_event($arr) {
|
||||
WHERE `id` = %d AND `uid` = %d",
|
||||
|
||||
dbesc($arr['edited']),
|
||||
dbesc($arr['start']),
|
||||
dbesc($arr['finish']),
|
||||
dbesc($arr['dtstart']),
|
||||
dbesc($arr['dtend']),
|
||||
dbesc($arr['summary']),
|
||||
dbesc($arr['description']),
|
||||
dbesc($arr['location']),
|
||||
dbesc($arr['type']),
|
||||
dbesc($arr['etype']),
|
||||
intval($arr['adjust']),
|
||||
intval($arr['nofinish']),
|
||||
dbesc($arr['event_status']),
|
||||
@@ -350,7 +394,7 @@ function event_store_event($arr) {
|
||||
dbesc($arr['allow_gid']),
|
||||
dbesc($arr['deny_cid']),
|
||||
dbesc($arr['deny_gid']),
|
||||
intval($r[0]['id']),
|
||||
intval($existing_event['id']),
|
||||
intval($arr['uid'])
|
||||
);
|
||||
} else {
|
||||
@@ -360,10 +404,12 @@ function event_store_event($arr) {
|
||||
|
||||
if(array_key_exists('external_id',$arr))
|
||||
$hash = $arr['external_id'];
|
||||
elseif(array_key_exists('event_hash',$arr))
|
||||
$hash = $arr['event_hash'];
|
||||
else
|
||||
$hash = random_string() . '@' . App::get_hostname();
|
||||
|
||||
$r = q("INSERT INTO event ( uid,aid,event_xchan,event_hash,created,edited,start,finish,summary,description,location,type,
|
||||
$r = q("INSERT INTO event ( uid,aid,event_xchan,event_hash,created,edited,dtstart,dtend,summary,description,location,etype,
|
||||
adjust,nofinish, event_status, event_status_date, event_percent, event_repeat, event_sequence, event_priority, allow_cid,allow_gid,deny_cid,deny_gid)
|
||||
VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', %d, '%s', %d, %d, '%s', '%s', '%s', '%s' ) ",
|
||||
intval($arr['uid']),
|
||||
@@ -372,12 +418,12 @@ function event_store_event($arr) {
|
||||
dbesc($hash),
|
||||
dbesc($arr['created']),
|
||||
dbesc($arr['edited']),
|
||||
dbesc($arr['start']),
|
||||
dbesc($arr['finish']),
|
||||
dbesc($arr['dtstart']),
|
||||
dbesc($arr['dtend']),
|
||||
dbesc($arr['summary']),
|
||||
dbesc($arr['description']),
|
||||
dbesc($arr['location']),
|
||||
dbesc($arr['type']),
|
||||
dbesc($arr['etype']),
|
||||
intval($arr['adjust']),
|
||||
intval($arr['nofinish']),
|
||||
dbesc($arr['event_status']),
|
||||
@@ -426,7 +472,7 @@ function event_addtocal($item_id, $uid) {
|
||||
|
||||
$ev = bbtoevent($r[0]['body']);
|
||||
|
||||
if(x($ev,'summary') && x($ev,'start')) {
|
||||
if(x($ev,'summary') && x($ev,'dtstart')) {
|
||||
$ev['event_xchan'] = $item['author_xchan'];
|
||||
$ev['uid'] = $channel['channel_id'];
|
||||
$ev['account'] = $channel['channel_account_id'];
|
||||
@@ -436,7 +482,7 @@ function event_addtocal($item_id, $uid) {
|
||||
|
||||
// is this an edit?
|
||||
|
||||
if($item['resource_type'] === 'event') {
|
||||
if($item['resource_type'] === 'event' && (! $ev['event_hash'])) {
|
||||
$ev['event_hash'] = $item['resource_id'];
|
||||
}
|
||||
|
||||
@@ -472,7 +518,6 @@ function event_addtocal($item_id, $uid) {
|
||||
if($z) {
|
||||
build_sync_packet($channel['channel_id'],array('event_item' => array(encode_item($sync_item[0],true)),'event' => $z));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -540,20 +585,20 @@ function event_import_ical($ical, $uid) {
|
||||
|
||||
// logger('dtstart: ' . var_export($dtstart,true));
|
||||
|
||||
$ev['start'] = datetime_convert((($ev['adjust']) ? 'UTC' : date_default_timezone_get()),'UTC',
|
||||
$ev['dtstart'] = datetime_convert((($ev['adjust']) ? 'UTC' : date_default_timezone_get()),'UTC',
|
||||
$dtstart->format(\DateTime::W3C));
|
||||
|
||||
|
||||
if(isset($ical->DTEND)) {
|
||||
$dtend = $ical->DTEND->getDateTime();
|
||||
$ev['finish'] = datetime_convert((($ev['adjust']) ? 'UTC' : date_default_timezone_get()),'UTC',
|
||||
$ev['dtend'] = datetime_convert((($ev['adjust']) ? 'UTC' : date_default_timezone_get()),'UTC',
|
||||
$dtend->format(\DateTime::W3C));
|
||||
}
|
||||
else
|
||||
$ev['nofinish'] = 1;
|
||||
|
||||
|
||||
if($ev['start'] === $ev['finish'])
|
||||
if($ev['dtstart'] === $ev['dtend'])
|
||||
$ev['nofinish'] = 1;
|
||||
|
||||
if(isset($ical->CREATED)) {
|
||||
@@ -587,7 +632,7 @@ function event_import_ical($ical, $uid) {
|
||||
$ev['external_id'] = $evuid;
|
||||
}
|
||||
|
||||
if($ev['summary'] && $ev['start']) {
|
||||
if($ev['summary'] && $ev['dtstart']) {
|
||||
$ev['event_xchan'] = $channel['channel_hash'];
|
||||
$ev['uid'] = $channel['channel_id'];
|
||||
$ev['account'] = $channel['channel_account_id'];
|
||||
@@ -626,29 +671,24 @@ function event_import_ical_task($ical, $uid) {
|
||||
|
||||
$dtstart = $ical->DTSTART->getDateTime();
|
||||
|
||||
$ev['adjust'] = (($ical->DTSTART->isFloating()) ? 1 : 0);
|
||||
|
||||
// logger('dtstart: ' . var_export($dtstart,true));
|
||||
|
||||
if(($dtstart->timezone_type == 2) || (($dtstart->timezone_type == 3) && ($dtstart->timezone === 'UTC'))) {
|
||||
$ev['adjust'] = 1;
|
||||
}
|
||||
else {
|
||||
$ev['adjust'] = 0;
|
||||
}
|
||||
|
||||
$ev['start'] = datetime_convert((($ev['adjust']) ? 'UTC' : date_default_timezone_get()),'UTC',
|
||||
$ev['dtstart'] = datetime_convert((($ev['adjust']) ? 'UTC' : date_default_timezone_get()),'UTC',
|
||||
$dtstart->format(\DateTime::W3C));
|
||||
|
||||
|
||||
if(isset($ical->DUE)) {
|
||||
$dtend = $ical->DUE->getDateTime();
|
||||
$ev['finish'] = datetime_convert((($ev['adjust']) ? 'UTC' : date_default_timezone_get()),'UTC',
|
||||
$ev['dtend'] = datetime_convert((($ev['adjust']) ? 'UTC' : date_default_timezone_get()),'UTC',
|
||||
$dtend->format(\DateTime::W3C));
|
||||
}
|
||||
else
|
||||
$ev['nofinish'] = 1;
|
||||
|
||||
|
||||
if($ev['start'] === $ev['finish'])
|
||||
if($ev['dtstart'] === $ev['dtend'])
|
||||
$ev['nofinish'] = 1;
|
||||
|
||||
if(isset($ical->CREATED)) {
|
||||
@@ -713,9 +753,9 @@ function event_import_ical_task($ical, $uid) {
|
||||
$ev['event_percent'] = (string) $ical->{'PERCENT-COMPLETE'} ;
|
||||
}
|
||||
|
||||
$ev['type'] = 'task';
|
||||
$ev['etype'] = 'task';
|
||||
|
||||
if($ev['summary'] && $ev['start']) {
|
||||
if($ev['summary'] && $ev['dtstart']) {
|
||||
$ev['event_xchan'] = $channel['channel_hash'];
|
||||
$ev['uid'] = $channel['channel_id'];
|
||||
$ev['account'] = $channel['channel_account_id'];
|
||||
@@ -764,7 +804,10 @@ function event_store_item($arr, $event) {
|
||||
$prefix = '';
|
||||
// $birthday = false;
|
||||
|
||||
if($event['type'] === 'birthday') {
|
||||
if(($event) && array_key_exists('event_hash',$event) && (! array_key_exists('event_hash',$arr)))
|
||||
$arr['event_hash'] = $event['event_hash'];
|
||||
|
||||
if($event['etype'] === 'birthday') {
|
||||
if(! is_sys_channel($arr['uid']))
|
||||
$prefix = t('This event has been added to your calendar.');
|
||||
// $birthday = true;
|
||||
@@ -788,21 +831,22 @@ function event_store_item($arr, $event) {
|
||||
'type' => ACTIVITY_OBJ_EVENT,
|
||||
'id' => z_root() . '/event/' . $r[0]['resource_id'],
|
||||
'title' => $arr['summary'],
|
||||
'start' => $arr['start'],
|
||||
'finish' => $arr['finish'],
|
||||
'dtstart' => $arr['dtstart'],
|
||||
'dtend' => $arr['dtend'],
|
||||
'nofinish' => $arr['nofinish'],
|
||||
'description' => $arr['description'],
|
||||
'location' => $arr['location'],
|
||||
'adjust' => $arr['adjust'],
|
||||
'content' => format_event_bbcode($arr),
|
||||
'author' => array(
|
||||
'name' => $r[0]['xchan_name'],
|
||||
'address' => $r[0]['xchan_addr'],
|
||||
'guid' => $r[0]['xchan_guid'],
|
||||
'guid_sig' => $r[0]['xchan_guid_sig'],
|
||||
'link' => array(
|
||||
array('rel' => 'alternate', 'type' => 'text/html', 'href' => $r[0]['xchan_url']),
|
||||
array('rel' => 'photo', 'type' => $r[0]['xchan_photo_mimetype'], 'href' => $r[0]['xchan_photo_m'])),
|
||||
'name' => $r[0]['xchan_name'],
|
||||
'address' => $r[0]['xchan_addr'],
|
||||
'guid' => $r[0]['xchan_guid'],
|
||||
'guid_sig' => $r[0]['xchan_guid_sig'],
|
||||
'link' => array(
|
||||
array('rel' => 'alternate', 'type' => 'text/html', 'href' => $r[0]['xchan_url']),
|
||||
array('rel' => 'photo', 'type' => $r[0]['xchan_photo_mimetype'], 'href' => $r[0]['xchan_photo_m'])
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
@@ -813,7 +857,7 @@ function event_store_item($arr, $event) {
|
||||
|
||||
$sig = '';
|
||||
|
||||
q("UPDATE item SET title = '%s', body = '%s', object = '%s', allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s', edited = '%s', sig = '%s', item_flags = %d, item_private = %d, obj_type = '%s' WHERE id = %d AND uid = %d",
|
||||
q("UPDATE item SET title = '%s', body = '%s', obj = '%s', allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s', edited = '%s', sig = '%s', item_flags = %d, item_private = %d, obj_type = '%s' WHERE id = %d AND uid = %d",
|
||||
dbesc($arr['summary']),
|
||||
dbesc($prefix . format_event_bbcode($arr)),
|
||||
dbesc($object),
|
||||
@@ -837,12 +881,12 @@ function event_store_item($arr, $event) {
|
||||
|
||||
if(($arr['term']) && (is_array($arr['term']))) {
|
||||
foreach($arr['term'] as $t) {
|
||||
q("insert into term (uid,oid,otype,type,term,url)
|
||||
q("insert into term (uid,oid,otype,ttype,term,url)
|
||||
values(%d,%d,%d,%d,'%s','%s') ",
|
||||
intval($arr['uid']),
|
||||
intval($r[0]['id']),
|
||||
intval(TERM_OBJ_POST),
|
||||
intval($t['type']),
|
||||
intval($t['ttype']),
|
||||
dbesc($t['term']),
|
||||
dbesc($t['url'])
|
||||
);
|
||||
@@ -929,12 +973,12 @@ function event_store_item($arr, $event) {
|
||||
dbesc($arr['event_xchan'])
|
||||
);
|
||||
if($x) {
|
||||
$item_arr['object'] = json_encode(array(
|
||||
$item_arr['obj'] = json_encode(array(
|
||||
'type' => ACTIVITY_OBJ_EVENT,
|
||||
'id' => z_root() . '/event/' . $event['event_hash'],
|
||||
'title' => $arr['summary'],
|
||||
'start' => $arr['start'],
|
||||
'finish' => $arr['finish'],
|
||||
'dtstart' => $arr['dtstart'],
|
||||
'dtend' => $arr['dtend'],
|
||||
'nofinish' => $arr['nofinish'],
|
||||
'description' => $arr['description'],
|
||||
'location' => $arr['location'],
|
||||
@@ -984,7 +1028,7 @@ function tasks_fetch($arr) {
|
||||
if($arr && $arr['all'] == 1)
|
||||
$sql_extra = '';
|
||||
|
||||
$r = q("select * from event where type = 'task' and uid = %d $sql_extra order by created desc",
|
||||
$r = q("select * from event where etype = 'task' and uid = %d $sql_extra order by created desc",
|
||||
intval(local_channel())
|
||||
);
|
||||
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @file include/expire.php
|
||||
*/
|
||||
|
||||
require_once('boot.php');
|
||||
require_once('include/cli_startup.php');
|
||||
|
||||
function expire_run($argv, $argc){
|
||||
|
||||
cli_startup();
|
||||
|
||||
// perform final cleanup on previously delete items
|
||||
|
||||
$r = q("select id from item where item_deleted = 1 and item_pending_remove = 0 and changed < %s - INTERVAL %s",
|
||||
db_utcnow(), db_quoteinterval('10 DAY')
|
||||
);
|
||||
if ($r) {
|
||||
foreach ($r as $rr) {
|
||||
drop_item($rr['id'], false, DROPITEM_PHASE2);
|
||||
}
|
||||
}
|
||||
|
||||
// physically remove anything that has been deleted for more than two months
|
||||
/** @FIXME - this is a wretchedly inefficient query */
|
||||
|
||||
$r = q("delete from item where item_pending_remove = 1 and changed < %s - INTERVAL %s",
|
||||
db_utcnow(), db_quoteinterval('36 DAY')
|
||||
);
|
||||
|
||||
/** @FIXME make this optional as it could have a performance impact on large sites */
|
||||
|
||||
if (intval(get_config('system', 'optimize_items')))
|
||||
q("optimize table item");
|
||||
|
||||
logger('expire: start', LOGGER_DEBUG);
|
||||
|
||||
$site_expire = get_config('system', 'default_expire_days');
|
||||
|
||||
logger('site_expire: ' . $site_expire);
|
||||
|
||||
$r = q("SELECT channel_id, channel_address, channel_pageflags, channel_expire_days from channel where true");
|
||||
|
||||
if ($r) {
|
||||
foreach ($r as $rr) {
|
||||
|
||||
// expire the sys channel separately
|
||||
if (intval($rr['channel_system']))
|
||||
continue;
|
||||
|
||||
// service class default (if non-zero) over-rides the site default
|
||||
|
||||
$service_class_expire = service_class_fetch($rr['channel_id'], 'expire_days');
|
||||
if (intval($service_class_expire))
|
||||
$channel_expire = $service_class_expire;
|
||||
else
|
||||
$channel_expire = $site_expire;
|
||||
|
||||
if (intval($channel_expire) && (intval($channel_expire) < intval($rr['channel_expire_days'])) ||
|
||||
intval($rr['channel_expire_days'] == 0)) {
|
||||
$expire_days = $channel_expire;
|
||||
} else {
|
||||
$expire_days = $rr['channel_expire_days'];
|
||||
}
|
||||
|
||||
// if the site or service class expiration is non-zero and less than person expiration, use that
|
||||
logger('Expire: ' . $rr['channel_address'] . ' interval: ' . $expire_days, LOGGER_DEBUG);
|
||||
item_expire($rr['channel_id'], $expire_days);
|
||||
}
|
||||
}
|
||||
|
||||
$x = get_sys_channel();
|
||||
if ($x) {
|
||||
|
||||
// this should probably just fetch the channel_expire_days from the sys channel,
|
||||
// but there's no convenient way to set it.
|
||||
|
||||
$expire_days = get_config('system', 'sys_expire_days');
|
||||
if ($expire_days === false)
|
||||
$expire_days = 30;
|
||||
|
||||
if (intval($site_expire) && (intval($site_expire) < intval($expire_days))) {
|
||||
$expire_days = $site_expire;
|
||||
}
|
||||
|
||||
logger('Expire: sys interval: ' . $expire_days, LOGGER_DEBUG);
|
||||
|
||||
if ($expire_days)
|
||||
item_expire($x['channel_id'], $expire_days);
|
||||
|
||||
logger('Expire: sys: done', LOGGER_DEBUG);
|
||||
}
|
||||
}
|
||||
|
||||
if (array_search(__file__, get_included_files()) === 0){
|
||||
expire_run($argv, $argc);
|
||||
killme();
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
<?php /** @file */
|
||||
|
||||
require_once('boot.php');
|
||||
require_once('include/cli_startup.php');
|
||||
require_once('include/zot.php');
|
||||
require_once('include/identity.php');
|
||||
|
||||
function externals_run($argv, $argc){
|
||||
|
||||
cli_startup();
|
||||
$a = get_app();
|
||||
|
||||
|
||||
$total = 0;
|
||||
$attempts = 0;
|
||||
|
||||
logger('externals: startup', LOGGER_DEBUG);
|
||||
|
||||
// pull in some public posts
|
||||
|
||||
|
||||
while($total == 0 && $attempts < 3) {
|
||||
$arr = array('url' => '');
|
||||
call_hooks('externals_url_select',$arr);
|
||||
|
||||
if($arr['url']) {
|
||||
$url = $arr['url'];
|
||||
}
|
||||
else {
|
||||
$randfunc = db_getfunc('RAND');
|
||||
|
||||
// fixme this query does not deal with directory realms.
|
||||
|
||||
$r = q("select site_url, site_pull from site where site_url != '%s' and site_flags != %d and site_type = %d and site_dead = 0 order by $randfunc limit 1",
|
||||
dbesc(z_root()),
|
||||
intval(DIRECTORY_MODE_STANDALONE),
|
||||
intval(SITE_TYPE_ZOT)
|
||||
);
|
||||
if($r)
|
||||
$url = $r[0]['site_url'];
|
||||
}
|
||||
|
||||
$blacklisted = false;
|
||||
|
||||
if(! check_siteallowed($url)) {
|
||||
logger('blacklisted site: ' . $url);
|
||||
$blacklisted = true;
|
||||
}
|
||||
|
||||
$attempts ++;
|
||||
|
||||
// make sure we can eventually break out if somebody blacklists all known sites
|
||||
|
||||
if($blacklisted) {
|
||||
if($attempts > 20)
|
||||
break;
|
||||
$attempts --;
|
||||
continue;
|
||||
}
|
||||
|
||||
if($url) {
|
||||
if($r[0]['site_pull'] !== NULL_DATE)
|
||||
$mindate = urlencode(datetime_convert('','',$r[0]['site_pull'] . ' - 1 day'));
|
||||
else {
|
||||
$days = get_config('externals','since_days');
|
||||
if($days === false)
|
||||
$days = 15;
|
||||
$mindate = urlencode(datetime_convert('','','now - ' . intval($days) . ' days'));
|
||||
}
|
||||
|
||||
$feedurl = $url . '/zotfeed?f=&mindate=' . $mindate;
|
||||
|
||||
logger('externals: pulling public content from ' . $feedurl, LOGGER_DEBUG);
|
||||
|
||||
$x = z_fetch_url($feedurl);
|
||||
if(($x) && ($x['success'])) {
|
||||
|
||||
q("update site set site_pull = '%s' where site_url = '%s'",
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($url)
|
||||
);
|
||||
|
||||
$j = json_decode($x['body'],true);
|
||||
if($j['success'] && $j['messages']) {
|
||||
$sys = get_sys_channel();
|
||||
foreach($j['messages'] as $message) {
|
||||
// on these posts, clear any route info.
|
||||
$message['route'] = '';
|
||||
$results = process_delivery(array('hash' => 'undefined'), get_item_elements($message),
|
||||
array(array('hash' => $sys['xchan_hash'])), false, true);
|
||||
$total ++;
|
||||
}
|
||||
logger('externals: import_public_posts: ' . $total . ' messages imported', LOGGER_DEBUG);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
externals_run($argv,$argc);
|
||||
killme();
|
||||
}
|
||||
@@ -94,6 +94,7 @@ function get_features($filtered = true) {
|
||||
t('Post/Comment Tools'),
|
||||
array('commtag', t('Community Tagging'), t('Ability to tag existing posts'),false,get_config('feature_lock','commtag')),
|
||||
array('categories', t('Post Categories'), t('Add categories to your posts'),false,get_config('feature_lock','categories')),
|
||||
array('emojis', t('Emoji Reactions'), t('Add emoji reaction ability to posts'),true,get_config('feature_lock','emojis')),
|
||||
array('filing', t('Saved Folders'), t('Ability to file posts under folders'),false,get_config('feature_lock','filing')),
|
||||
array('dislike', t('Dislike Posts'), t('Ability to dislike posts/comments'),false,get_config('feature_lock','dislike')),
|
||||
array('star_posts', t('Star Posts'), t('Ability to mark special posts with a star indicator'),false,get_config('feature_lock','star_posts')),
|
||||
|
||||
1315
include/feedutils.php
Normal file
1315
include/feedutils.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -17,7 +17,6 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
||||
|
||||
$result = array('success' => false,'message' => '');
|
||||
|
||||
$a = get_app();
|
||||
$is_red = false;
|
||||
$is_http = ((strpos($url,'://') !== false) ? true : false);
|
||||
|
||||
@@ -56,11 +55,11 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
||||
if($arr['channel']['success'])
|
||||
$ret = $arr['channel'];
|
||||
elseif(! $is_http)
|
||||
$ret = zot_finger($url,$channel);
|
||||
$ret = Zotlabs\Zot\Finger::run($url,$channel);
|
||||
|
||||
if($ret && $ret['success']) {
|
||||
if($ret && is_array($ret) && $ret['success']) {
|
||||
$is_red = true;
|
||||
$j = json_decode($ret['body'],true);
|
||||
$j = $ret;
|
||||
}
|
||||
|
||||
$my_perms = get_channel_default_perms($uid);
|
||||
@@ -269,14 +268,14 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
||||
|
||||
if($r) {
|
||||
$result['abook'] = $r[0];
|
||||
proc_run('php', 'include/notifier.php', 'permission_create', $result['abook']['abook_id']);
|
||||
Zotlabs\Daemon\Master::Summon(array('Notifier', 'permission_create', $result['abook']['abook_id']));
|
||||
}
|
||||
|
||||
$arr = array('channel_id' => $uid, 'channel' => $channel, 'abook' => $result['abook']);
|
||||
|
||||
call_hooks('follow', $arr);
|
||||
|
||||
/** If there is a default group for this channel, add this member to it */
|
||||
/** If there is a default group for this channel, add this connection to it */
|
||||
|
||||
if($default_group) {
|
||||
require_once('include/group.php');
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
<?php /** @file */
|
||||
|
||||
require_once('include/cli_startup.php');
|
||||
require_once('include/zot.php');
|
||||
|
||||
function gprobe_run($argv, $argc){
|
||||
|
||||
cli_startup();
|
||||
|
||||
$a = get_app();
|
||||
|
||||
if($argc != 2)
|
||||
return;
|
||||
|
||||
$url = hex2bin($argv[1]);
|
||||
|
||||
if(! strpos($url,'@'))
|
||||
return;
|
||||
|
||||
$r = q("select * from xchan where xchan_addr = '%s' limit 1",
|
||||
dbesc($url)
|
||||
);
|
||||
|
||||
if(! $r) {
|
||||
$x = zot_finger($url,null);
|
||||
if($x['success']) {
|
||||
$j = json_decode($x['body'],true);
|
||||
$y = import_xchan($j);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
gprobe_run($argv,$argc);
|
||||
killme();
|
||||
}
|
||||
@@ -18,7 +18,7 @@ function group_add($uid,$name,$public = 0) {
|
||||
intval($r)
|
||||
);
|
||||
if(count($z) && $z[0]['deleted']) {
|
||||
/*$r = q("UPDATE `groups` SET `deleted` = 0 WHERE `uid` = %d AND `name` = '%s' LIMIT 1",
|
||||
/*$r = q("UPDATE `groups` SET `deleted` = 0 WHERE `uid` = %d AND `gname` = '%s' LIMIT 1",
|
||||
intval($uid),
|
||||
dbesc($name)
|
||||
);*/
|
||||
@@ -38,7 +38,7 @@ function group_add($uid,$name,$public = 0) {
|
||||
} while($dups == true);
|
||||
|
||||
|
||||
$r = q("INSERT INTO `groups` ( hash, uid, visible, name )
|
||||
$r = q("INSERT INTO `groups` ( hash, uid, visible, gname )
|
||||
VALUES( '%s', %d, %d, '%s' ) ",
|
||||
dbesc($hash),
|
||||
intval($uid),
|
||||
@@ -57,7 +57,7 @@ function group_add($uid,$name,$public = 0) {
|
||||
function group_rmv($uid,$name) {
|
||||
$ret = false;
|
||||
if(x($uid) && x($name)) {
|
||||
$r = q("SELECT id, hash FROM `groups` WHERE `uid` = %d AND `name` = '%s' LIMIT 1",
|
||||
$r = q("SELECT id, hash FROM `groups` WHERE `uid` = %d AND `gname` = '%s' LIMIT 1",
|
||||
intval($uid),
|
||||
dbesc($name)
|
||||
);
|
||||
@@ -108,7 +108,7 @@ function group_rmv($uid,$name) {
|
||||
);
|
||||
|
||||
// remove group
|
||||
$r = q("UPDATE `groups` SET `deleted` = 1 WHERE `uid` = %d AND `name` = '%s'",
|
||||
$r = q("UPDATE `groups` SET `deleted` = 1 WHERE `uid` = %d AND `gname` = '%s'",
|
||||
intval($uid),
|
||||
dbesc($name)
|
||||
);
|
||||
@@ -125,7 +125,7 @@ function group_rmv($uid,$name) {
|
||||
function group_byname($uid,$name) {
|
||||
if((! $uid) || (! strlen($name)))
|
||||
return false;
|
||||
$r = q("SELECT * FROM `groups` WHERE `uid` = %d AND `name` = '%s' LIMIT 1",
|
||||
$r = q("SELECT * FROM `groups` WHERE `uid` = %d AND `gname` = '%s' LIMIT 1",
|
||||
intval($uid),
|
||||
dbesc($name)
|
||||
);
|
||||
@@ -232,13 +232,13 @@ function mini_group_select($uid,$group = '') {
|
||||
$grps = array();
|
||||
$o = '';
|
||||
|
||||
$r = q("SELECT * FROM `groups` WHERE `deleted` = 0 AND `uid` = %d ORDER BY `name` ASC",
|
||||
$r = q("SELECT * FROM `groups` WHERE `deleted` = 0 AND `uid` = %d ORDER BY `gname` ASC",
|
||||
intval($uid)
|
||||
);
|
||||
$grps[] = array('name' => '', 'hash' => '0', 'selected' => '');
|
||||
if(count($r)) {
|
||||
foreach($r as $rr) {
|
||||
$grps[] = array('name' => $rr['name'], 'id' => $rr['hash'], 'selected' => (($group == $rr['hash']) ? 'true' : ''));
|
||||
$grps[] = array('name' => $rr['gname'], 'id' => $rr['hash'], 'selected' => (($group == $rr['hash']) ? 'true' : ''));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -271,7 +271,7 @@ function group_side($every="connections",$each="group",$edit = false, $group_id
|
||||
);
|
||||
|
||||
|
||||
$r = q("SELECT * FROM `groups` WHERE `deleted` = 0 AND `uid` = %d ORDER BY `name` ASC",
|
||||
$r = q("SELECT * FROM `groups` WHERE `deleted` = 0 AND `uid` = %d ORDER BY `gname` ASC",
|
||||
intval($_SESSION['uid'])
|
||||
);
|
||||
$member_of = array();
|
||||
@@ -296,7 +296,7 @@ function group_side($every="connections",$each="group",$edit = false, $group_id
|
||||
'id' => $rr['id'],
|
||||
'enc_cid' => base64url_encode($cid),
|
||||
'cid' => $cid,
|
||||
'text' => $rr['name'],
|
||||
'text' => $rr['gname'],
|
||||
'selected' => $selected,
|
||||
'href' => (($mode == 0) ? $each.'?f=&gid='.$rr['id'] : $each."/".$rr['id']) . ((x($_GET,'new')) ? '&new=' . $_GET['new'] : '') . ((x($_GET,'order')) ? '&order=' . $_GET['order'] : ''),
|
||||
'edit' => $groupedit,
|
||||
@@ -340,7 +340,7 @@ function expand_groups($a) {
|
||||
|
||||
function member_of($c) {
|
||||
|
||||
$r = q("SELECT `groups`.`name`, `groups`.`id` FROM `groups` LEFT JOIN `group_member` ON `group_member`.`gid` = `groups`.`id` WHERE `group_member`.`xchan` = '%s' AND `groups`.`deleted` = 0 ORDER BY `groups`.`name` ASC ",
|
||||
$r = q("SELECT `groups`.`gname`, `groups`.`id` FROM `groups` LEFT JOIN `group_member` ON `group_member`.`gid` = `groups`.`id` WHERE `group_member`.`xchan` = '%s' AND `groups`.`deleted` = 0 ORDER BY `groups`.`gname` ASC ",
|
||||
dbesc($c)
|
||||
);
|
||||
|
||||
|
||||
@@ -24,8 +24,6 @@ function find_doc_file($s) {
|
||||
|
||||
function search_doc_files($s) {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
$itemspage = get_pconfig(local_channel(),'system','itemspage');
|
||||
\App::set_pager_itemspage(((intval($itemspage)) ? $itemspage : 20));
|
||||
$pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(\App::$pager['itemspage']), intval(\App::$pager['start']));
|
||||
|
||||
@@ -106,7 +106,7 @@ function remove_obsolete_hublocs() {
|
||||
dbesc($rr['hubloc_hash'])
|
||||
);
|
||||
if($x) {
|
||||
proc_run('php','include/notifier.php','location',$x[0]['channel_id']);
|
||||
Zotlabs\Daemon\Master::Summon(array('Notifier','location',$x[0]['channel_id']));
|
||||
if($interval)
|
||||
@time_sleep_until(microtime(true) + (float) $interval);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ function import_channel($channel, $account_id, $seize) {
|
||||
dbesc($channel['channel_hash']),
|
||||
dbesc($channel['channel_address'])
|
||||
);
|
||||
if($r && $r[0]['channel_guid'] == $channel['channel_guid'] && $r[0]['channel_pubkey'] === $channel['channel_pubkey'] && $r[0]['channel_hash'] === $channel['channel_hash'])
|
||||
return $r[0];
|
||||
|
||||
if(($r) || (check_webbie(array($channel['channel_address'])) !== $channel['channel_address'])) {
|
||||
if($r[0]['channel_guid'] === $channel['channel_guid'] || $r[0]['channel_hash'] === $channel['channel_hash']) {
|
||||
@@ -120,6 +122,11 @@ function import_profiles($channel,$profiles) {
|
||||
$profile['aid'] = get_account_id();
|
||||
$profile['uid'] = $channel['channel_id'];
|
||||
|
||||
convert_oldfields($profile,'name','fullname');
|
||||
convert_oldfields($profile,'with','partner');
|
||||
convert_oldfields($profile,'work','employment');
|
||||
|
||||
|
||||
// we are going to reset all profile photos to the original
|
||||
// somebody will have to fix this later and put all the applicable photos into the export
|
||||
|
||||
@@ -330,7 +337,9 @@ function import_apps($channel,$apps) {
|
||||
);
|
||||
if($x) {
|
||||
foreach($term as $t) {
|
||||
store_item_tag($channel['channel_id'],$x[0]['id'],TERM_OBJ_APP,$t['type'],escape_tags($t['term']),escape_tags($t['url']));
|
||||
if(array_key_exists('type',$t))
|
||||
$t['ttype'] = $t['type'];
|
||||
store_item_tag($channel['channel_id'],$x[0]['id'],TERM_OBJ_APP,$t['ttype'],escape_tags($t['term']),escape_tags($t['url']));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -398,7 +407,9 @@ function sync_apps($channel,$apps) {
|
||||
|
||||
if($exists && $term) {
|
||||
foreach($term as $t) {
|
||||
store_item_tag($channel['channel_id'],$exists['id'],TERM_OBJ_APP,$t['type'],escape_tags($t['term']),escape_tags($t['url']));
|
||||
if(array_key_exists('type',$t))
|
||||
$t['ttype'] = $t['type'];
|
||||
store_item_tag($channel['channel_id'],$exists['id'],TERM_OBJ_APP,$t['ttype'],escape_tags($t['term']),escape_tags($t['url']));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -434,7 +445,9 @@ function sync_apps($channel,$apps) {
|
||||
);
|
||||
if($x) {
|
||||
foreach($term as $t) {
|
||||
store_item_tag($channel['channel_id'],$x[0]['id'],TERM_OBJ_APP,$t['type'],escape_tags($t['term']),escape_tags($t['url']));
|
||||
if(array_key_exists('type',$t))
|
||||
$t['ttype'] = $t['type'];
|
||||
store_item_tag($channel['channel_id'],$x[0]['id'],TERM_OBJ_APP,$t['ttype'],escape_tags($t['term']),escape_tags($t['url']));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -574,7 +587,7 @@ function import_items($channel,$items,$sync = false) {
|
||||
if($sync && $item['item_wall']) {
|
||||
// deliver singletons if we have any
|
||||
if($item_result && $item_result['success']) {
|
||||
proc_run('php','include/notifier.php','single_activity',$item_result['item_id']);
|
||||
Zotlabs\Daemon\Master::Summon(array('Notifier','single_activity',$item_result['item_id']));
|
||||
}
|
||||
}
|
||||
continue;
|
||||
@@ -588,7 +601,7 @@ function import_items($channel,$items,$sync = false) {
|
||||
if($sync && $item['item_wall']) {
|
||||
// deliver singletons if we have any
|
||||
if($item_result && $item_result['success']) {
|
||||
proc_run('php','include/notifier.php','single_activity',$item_result['item_id']);
|
||||
Zotlabs\Daemon\Master::Summon(array('Notifier','single_activity',$item_result['item_id']));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -636,6 +649,10 @@ function import_events($channel,$events) {
|
||||
unset($event['id']);
|
||||
$event['aid'] = $channel['channel_account_id'];
|
||||
$event['uid'] = $channel['channel_id'];
|
||||
convert_oldfields($event,'start','dtstart');
|
||||
convert_oldfields($event,'finish','dtend');
|
||||
convert_oldfields($event,'type','etype');
|
||||
convert_oldfields($event,'ignore','dismissed');
|
||||
|
||||
dbesc_array($event);
|
||||
$r = dbq("INSERT INTO event (`"
|
||||
@@ -669,6 +686,12 @@ function sync_events($channel,$events) {
|
||||
$event['aid'] = $channel['channel_account_id'];
|
||||
$event['uid'] = $channel['channel_id'];
|
||||
|
||||
convert_oldfields($event,'start','dtstart');
|
||||
convert_oldfields($event,'finish','dtend');
|
||||
convert_oldfields($event,'type','etype');
|
||||
convert_oldfields($event,'ignore','dismissed');
|
||||
|
||||
|
||||
$exists = false;
|
||||
|
||||
$x = q("select * from event where event_hash = '%s' and uid = %d limit 1",
|
||||
@@ -936,7 +959,7 @@ function import_mail($channel,$mails,$sync = false) {
|
||||
$m['uid'] = $channel['channel_id'];
|
||||
$mail_id = mail_store($m);
|
||||
if($sync && $mail_id) {
|
||||
proc_run('php','include/notifier.php','single_mail',$mail_id);
|
||||
Zotlabs\Daemon\Master::Summon(array('Notifier','single_mail',$mail_id));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -966,6 +989,8 @@ function sync_files($channel,$files) {
|
||||
$attachment_stored = false;
|
||||
foreach($f['attach'] as $att) {
|
||||
|
||||
convert_oldfields($att,'data','content');
|
||||
|
||||
if($att['deleted']) {
|
||||
attach_delete($channel,$att['hash']);
|
||||
continue;
|
||||
@@ -973,8 +998,11 @@ function sync_files($channel,$files) {
|
||||
|
||||
$attach_exists = false;
|
||||
$x = attach_by_hash($att['hash']);
|
||||
logger('sync_files duplicate check: attach_exists=' . $attach_exists, LOGGER_DEBUG);
|
||||
logger('sync_files duplicate check: att=' . print_r($att,true), LOGGER_DEBUG);
|
||||
logger('sync_files duplicate check: attach_by_hash() returned ' . print_r($x,true), LOGGER_DEBUG);
|
||||
|
||||
if($x) {
|
||||
if($x['success']) {
|
||||
$attach_exists = true;
|
||||
$attach_id = $x[0]['id'];
|
||||
}
|
||||
@@ -1032,7 +1060,7 @@ function sync_files($channel,$files) {
|
||||
|
||||
// @fixme - update attachment structures if they are modified rather than created
|
||||
|
||||
$att['data'] = $newfname;
|
||||
$att['content'] = $newfname;
|
||||
|
||||
// Note: we use $att['hash'] below after it has been escaped to
|
||||
// fetch the file contents.
|
||||
@@ -1043,15 +1071,17 @@ function sync_files($channel,$files) {
|
||||
|
||||
|
||||
if($attach_exists) {
|
||||
$str = '';
|
||||
foreach($att as $k => $v) {
|
||||
if($str)
|
||||
$str .= ",";
|
||||
$str .= " `" . $k . "` = '" . $v . "' ";
|
||||
}
|
||||
$r = dbq("update `attach` set " . $str . " where id = " . intval($attach_id) );
|
||||
logger('sync_files attach exists: ' . print_r($att,true), LOGGER_DEBUG);
|
||||
$str = '';
|
||||
foreach($att as $k => $v) {
|
||||
if($str)
|
||||
$str .= ",";
|
||||
$str .= " `" . $k . "` = '" . $v . "' ";
|
||||
}
|
||||
$r = dbq("update `attach` set " . $str . " where id = " . intval($attach_id) );
|
||||
}
|
||||
else {
|
||||
logger('sync_files attach does not exists: ' . print_r($att,true), LOGGER_DEBUG);
|
||||
$r = dbq("INSERT INTO attach (`"
|
||||
. implode("`, `", array_keys($att))
|
||||
. "`) VALUES ('"
|
||||
@@ -1064,6 +1094,7 @@ function sync_files($channel,$files) {
|
||||
|
||||
if($att['filetype'] === 'multipart/mixed' && $att['is_dir']) {
|
||||
os_mkdir($newfname, STORAGE_DEFAULT_PERMISSIONS,true);
|
||||
$attachment_stored = true;
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
@@ -1111,6 +1142,11 @@ function sync_files($channel,$files) {
|
||||
$p['aid'] = $channel['channel_account_id'];
|
||||
$p['uid'] = $channel['channel_id'];
|
||||
|
||||
convert_oldfields($p,'data','content');
|
||||
convert_oldfields($p,'scale','imgscale');
|
||||
convert_oldfields($p,'size','filesize');
|
||||
convert_oldfields($p,'type','mimetype');
|
||||
|
||||
// if this is a profile photo, undo the profile photo bit
|
||||
// for any other photo which previously held it.
|
||||
|
||||
@@ -1136,15 +1172,15 @@ function sync_files($channel,$files) {
|
||||
);
|
||||
}
|
||||
|
||||
if($p['scale'] === 0 && $p['os_storage'])
|
||||
$p['data'] = $store_path;
|
||||
if($p['imgscale'] === 0 && $p['os_storage'])
|
||||
$p['content'] = $store_path;
|
||||
else
|
||||
$p['data'] = base64_decode($p['data']);
|
||||
$p['content'] = base64_decode($p['content']);
|
||||
|
||||
|
||||
$exists = q("select * from photo where resource_id = '%s' and scale = %d and uid = %d limit 1",
|
||||
$exists = q("select * from photo where resource_id = '%s' and imgscale = %d and uid = %d limit 1",
|
||||
dbesc($p['resource_id']),
|
||||
intval($p['scale']),
|
||||
intval($p['imgscale']),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
|
||||
@@ -1200,3 +1236,9 @@ function sync_files($channel,$files) {
|
||||
}
|
||||
|
||||
|
||||
function convert_oldfields(&$arr,$old,$new) {
|
||||
if(array_key_exists($old,$arr)) {
|
||||
$arr[$new] = $arr[$old];
|
||||
unset($arr[$old]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
require_once('include/cli_startup.php');
|
||||
|
||||
|
||||
function importdoc_run($argv, $argc){
|
||||
|
||||
cli_startup();
|
||||
|
||||
require_once('include/help.php');
|
||||
|
||||
|
||||
update_docs_dir('doc/*');
|
||||
|
||||
}
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
importdoc_run($argv,$argc);
|
||||
killme();
|
||||
}
|
||||
|
||||
function update_docs_dir($s) {
|
||||
$f = basename($s);
|
||||
$d = dirname($s);
|
||||
if($s === 'doc/html')
|
||||
return;
|
||||
$files = glob("$d/$f");
|
||||
if($files) {
|
||||
foreach($files as $fi) {
|
||||
if($fi === 'doc/html')
|
||||
continue;
|
||||
if(is_dir($fi))
|
||||
update_docs_dir("$fi/*");
|
||||
else
|
||||
store_doc_file($fi);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
1469
include/items.php
1469
include/items.php
File diff suppressed because it is too large
Load Diff
@@ -82,13 +82,11 @@ function get_best_language() {
|
||||
if($arr['preferred'] !== 'unset')
|
||||
return $arr['preferred'];
|
||||
|
||||
$a = get_app();
|
||||
return ((isset(App::$config['system']['language'])) ? App::$config['system']['language'] : 'en');
|
||||
}
|
||||
|
||||
|
||||
function push_lang($language) {
|
||||
global $a;
|
||||
|
||||
App::$langsave = App::$language;
|
||||
|
||||
@@ -104,7 +102,6 @@ function push_lang($language) {
|
||||
}
|
||||
|
||||
function pop_lang() {
|
||||
global $a;
|
||||
|
||||
if(App::$language === App::$langsave)
|
||||
return;
|
||||
@@ -124,7 +121,6 @@ function pop_lang() {
|
||||
* @param boolean $install (optional) default false
|
||||
*/
|
||||
function load_translation_table($lang, $install = false) {
|
||||
global $a;
|
||||
|
||||
App::$strings = array();
|
||||
|
||||
@@ -136,10 +132,10 @@ function load_translation_table($lang, $install = false) {
|
||||
}
|
||||
|
||||
if(! $install) {
|
||||
$plugins = q("SELECT name FROM addon WHERE installed=1;");
|
||||
$plugins = q("SELECT aname FROM addon WHERE installed=1;");
|
||||
if ($plugins !== false) {
|
||||
foreach($plugins as $p) {
|
||||
$name = $p['name'];
|
||||
$name = $p['aname'];
|
||||
if(file_exists("addon/$name/lang/$lang/hstrings.php")) {
|
||||
include("addon/$name/lang/$lang/hstrings.php");
|
||||
}
|
||||
@@ -170,7 +166,6 @@ function load_translation_table($lang, $install = false) {
|
||||
*
|
||||
*/
|
||||
function t($s, $ctx = '') {
|
||||
global $a;
|
||||
|
||||
$cs = $ctx ? '__ctx:' . $ctx . '__ ' . $s : $s;
|
||||
if (x(App::$strings, $cs)) {
|
||||
@@ -189,7 +184,7 @@ function t($s, $ctx = '') {
|
||||
|
||||
function translate_projectname($s) {
|
||||
|
||||
return str_replace(array('$projectname','$Projectname'),array(Zotlabs\Project\System::get_platform_name(),ucfirst(Zotlabs\Project\System::get_platform_name())),$s);
|
||||
return str_replace(array('$projectname','$Projectname'),array(Zotlabs\Lib\System::get_platform_name(),ucfirst(Zotlabs\Lib\System::get_platform_name())),$s);
|
||||
|
||||
}
|
||||
|
||||
@@ -205,7 +200,6 @@ function translate_projectname($s) {
|
||||
* @return string
|
||||
*/
|
||||
function tt($singular, $plural, $count, $ctx = ''){
|
||||
$a = get_app();
|
||||
|
||||
$cs = $ctx ? "__ctx:" . $ctx . "__ " . $singular : $singular;
|
||||
if (x(App::$strings,$cs)) {
|
||||
|
||||
@@ -257,7 +257,7 @@ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto='
|
||||
}
|
||||
}
|
||||
|
||||
proc_run('php','include/notifier.php','mail',$post_id);
|
||||
Zotlabs\Daemon\Master::Summon(array('Notifier','mail',$post_id));
|
||||
|
||||
$ret['success'] = true;
|
||||
$ret['message_item'] = intval($post_id);
|
||||
|
||||
@@ -595,8 +595,6 @@ function parse_xml_string($s,$strict = true) {
|
||||
|
||||
function scale_external_images($s, $include_link = true, $scale_replace = false) {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
// Picture addresses can contain special characters
|
||||
$s = htmlspecialchars_decode($s, ENT_COMPAT);
|
||||
|
||||
@@ -1168,6 +1166,10 @@ function discover_by_webbie($webbie) {
|
||||
if(! $x)
|
||||
$probe_old = true;
|
||||
|
||||
|
||||
if((! $dfrn) && (! $has_salmon))
|
||||
$probe_old = true;
|
||||
|
||||
if($probe_old) {
|
||||
$y = old_webfinger($webbie);
|
||||
if($y) {
|
||||
@@ -1614,8 +1616,6 @@ function fetch_xrd_links($url) {
|
||||
|
||||
function scrape_vcard($url) {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
$ret = array();
|
||||
|
||||
logger('scrape_vcard: url=' . $url);
|
||||
@@ -1695,8 +1695,6 @@ function scrape_vcard($url) {
|
||||
|
||||
function scrape_feed($url) {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
$ret = array();
|
||||
$level = 0;
|
||||
$x = z_fetch_url($url,false,$level,array('novalidate' => true));
|
||||
@@ -1815,8 +1813,6 @@ function service_plink($contact, $guid) {
|
||||
|
||||
function format_and_send_email($sender,$xchan,$item) {
|
||||
|
||||
require_once('include/enotify.php');
|
||||
|
||||
$title = $item['title'];
|
||||
$body = $item['body'];
|
||||
|
||||
@@ -1835,7 +1831,7 @@ function format_and_send_email($sender,$xchan,$item) {
|
||||
$tpl = get_markup_template('email_notify_html.tpl');
|
||||
$email_html_body = replace_macros($tpl,array(
|
||||
'$banner' => $banner,
|
||||
'$notify_icon' => Zotlabs\Project\System::get_notify_icon(),
|
||||
'$notify_icon' => Zotlabs\Lib\System::get_notify_icon(),
|
||||
'$product' => $product,
|
||||
'$preamble' => '',
|
||||
'$sitename' => $sitename,
|
||||
@@ -1881,7 +1877,7 @@ function format_and_send_email($sender,$xchan,$item) {
|
||||
|
||||
// use the EmailNotification library to send the message
|
||||
|
||||
enotify::send(array(
|
||||
Zotlabs\Lib\Enotify::send(array(
|
||||
'fromName' => $product,
|
||||
'fromEmail' => $sender_email,
|
||||
'replyTo' => $sender_email,
|
||||
@@ -1912,10 +1908,13 @@ function do_delivery($deliveries) {
|
||||
$deliver = array();
|
||||
foreach($deliveries as $d) {
|
||||
|
||||
if(! $d)
|
||||
continue;
|
||||
|
||||
$deliver[] = $d;
|
||||
|
||||
if(count($deliver) >= $deliveries_per_process) {
|
||||
proc_run('php','include/deliver.php',$deliver);
|
||||
Zotlabs\Daemon\Master::Summon(array('Deliver',$deliver));
|
||||
$deliver = array();
|
||||
if($interval)
|
||||
@time_sleep_until(microtime(true) + (float) $interval);
|
||||
@@ -1925,7 +1924,7 @@ function do_delivery($deliveries) {
|
||||
// catch any stragglers
|
||||
|
||||
if($deliver)
|
||||
proc_run('php','include/deliver.php',$deliver);
|
||||
Zotlabs\Daemon\Master::Summon(array('Deliver',$deliver));
|
||||
|
||||
|
||||
}
|
||||
@@ -1933,9 +1932,6 @@ function do_delivery($deliveries) {
|
||||
|
||||
function get_site_info() {
|
||||
|
||||
global $db;
|
||||
global $a;
|
||||
|
||||
$register_policy = Array('REGISTER_CLOSED', 'REGISTER_APPROVE', 'REGISTER_OPEN');
|
||||
$directory_mode = Array('DIRECTORY_MODE_NORMAL', 'DIRECTORY_MODE_PRIMARY', 'DIRECTORY_MODE_SECONDARY', 256 => 'DIRECTORY_MODE_STANDALONE');
|
||||
|
||||
@@ -1971,7 +1967,7 @@ function get_site_info() {
|
||||
$r = q("select * from addon where hidden = 0");
|
||||
if(count($r))
|
||||
foreach($r as $rr)
|
||||
$visible_plugins[] = $rr['name'];
|
||||
$visible_plugins[] = $rr['aname'];
|
||||
}
|
||||
sort($visible_plugins);
|
||||
|
||||
@@ -1983,8 +1979,8 @@ function get_site_info() {
|
||||
$site_info = get_config('system','info');
|
||||
$site_name = get_config('system','sitename');
|
||||
if(! get_config('system','hidden_version_siteinfo')) {
|
||||
$version = Zotlabs\Project\System::get_project_version();
|
||||
$tag = Zotlabs\Project\System::get_std_version();
|
||||
$version = Zotlabs\Lib\System::get_project_version();
|
||||
$tag = Zotlabs\Lib\System::get_std_version();
|
||||
|
||||
if(@is_dir('.git') && function_exists('shell_exec')) {
|
||||
$commit = trim( @shell_exec('git log -1 --format="%h"'));
|
||||
@@ -2020,7 +2016,7 @@ function get_site_info() {
|
||||
$data = Array(
|
||||
'version' => $version,
|
||||
'version_tag' => $tag,
|
||||
'server_role' => Zotlabs\Project\System::get_server_role(),
|
||||
'server_role' => Zotlabs\Lib\System::get_server_role(),
|
||||
'commit' => $commit,
|
||||
'url' => z_root(),
|
||||
'plugins' => $visible_plugins,
|
||||
@@ -2034,8 +2030,8 @@ function get_site_info() {
|
||||
'locked_features' => $locked_features,
|
||||
'admin' => $admin,
|
||||
'site_name' => (($site_name) ? $site_name : ''),
|
||||
'platform' => Zotlabs\Project\System::get_platform_name(),
|
||||
'dbdriver' => $db->getdriver(),
|
||||
'platform' => Zotlabs\Lib\System::get_platform_name(),
|
||||
'dbdriver' => DBA::$dba->getdriver(),
|
||||
'lastpoll' => get_config('system','lastpoll'),
|
||||
'info' => (($site_info) ? $site_info : ''),
|
||||
'channels_total' => $channels_total_stat,
|
||||
@@ -2143,3 +2139,29 @@ function get_repository_version($branch = 'master') {
|
||||
return '?.?';
|
||||
|
||||
}
|
||||
|
||||
function network_to_name($s) {
|
||||
|
||||
$nets = array(
|
||||
NETWORK_DFRN => t('Friendica'),
|
||||
NETWORK_FRND => t('Friendica'),
|
||||
NETWORK_OSTATUS => t('OStatus'),
|
||||
NETWORK_GNUSOCIAL => t('GNU-Social'),
|
||||
NETWORK_FEED => t('RSS/Atom'),
|
||||
NETWORK_MAIL => t('Email'),
|
||||
NETWORK_DIASPORA => t('Diaspora'),
|
||||
NETWORK_FACEBOOK => t('Facebook'),
|
||||
NETWORK_ZOT => t('Zot'),
|
||||
NETWORK_LINKEDIN => t('LinkedIn'),
|
||||
NETWORK_XMPP => t('XMPP/IM'),
|
||||
NETWORK_MYSPACE => t('MySpace'),
|
||||
);
|
||||
|
||||
call_hooks('network_to_name', $nets);
|
||||
|
||||
$search = array_keys($nets);
|
||||
$replace = array_values($nets);
|
||||
|
||||
return str_replace($search,$replace,$s);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,664 +0,0 @@
|
||||
<?php /** @file */
|
||||
|
||||
require_once("boot.php");
|
||||
require_once('include/queue_fn.php');
|
||||
require_once('include/html2plain.php');
|
||||
|
||||
/*
|
||||
* This file was at one time responsible for doing all deliveries, but this caused
|
||||
* big problems on shared hosting systems, where the process might get killed by the
|
||||
* hosting provider and nothing would get delivered.
|
||||
* It now only delivers one message under certain cases, and invokes a queued
|
||||
* delivery mechanism (include/deliver.php) to deliver individual contacts at
|
||||
* controlled intervals.
|
||||
* This has a much better chance of surviving random processes getting killed
|
||||
* by the hosting provider.
|
||||
*
|
||||
* The basic flow is:
|
||||
* Identify the type of message
|
||||
* Collect any information that needs to be sent
|
||||
* Convert it into a suitable generic format for sending
|
||||
* Figure out who the recipients are and if we need to relay
|
||||
* through a conversation owner
|
||||
* Once we know what recipients are involved, collect a list of
|
||||
* destination sites
|
||||
* Build and store a queue item for each unique site and invoke
|
||||
* a delivery process for each site or a small number of sites (1-3)
|
||||
* and add a slight delay between each delivery invocation if desired (usually)
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* The notifier is typically called with:
|
||||
*
|
||||
* proc_run('php', "include/notifier.php", COMMAND, ITEM_ID);
|
||||
*
|
||||
* where COMMAND is one of the following:
|
||||
*
|
||||
* activity (in diaspora.php, dfrn_confirm.php, profiles.php)
|
||||
* comment-import (in diaspora.php, items.php)
|
||||
* comment-new (in item.php)
|
||||
* drop (in diaspora.php, items.php, photos.php)
|
||||
* edit_post (in item.php)
|
||||
* event (in events.php)
|
||||
* expire (in items.php)
|
||||
* like (in like.php, poke.php)
|
||||
* mail (in message.php)
|
||||
* tag (in photos.php, poke.php, tagger.php)
|
||||
* tgroup (in items.php)
|
||||
* wall-new (in photos.php, item.php)
|
||||
*
|
||||
* and ITEM_ID is the id of the item in the database that needs to be sent to others.
|
||||
*
|
||||
* ZOT
|
||||
* permission_create abook_id
|
||||
* permission_update abook_id
|
||||
* refresh_all channel_id
|
||||
* purge_all channel_id
|
||||
* expire channel_id
|
||||
* relay item_id (item was relayed to owner, we will deliver it as owner)
|
||||
* single_activity item_id (deliver to a singleton network from the appropriate clone)
|
||||
* single_mail mail_id (deliver to a singleton network from the appropriate clone)
|
||||
* location channel_id
|
||||
* request channel_id xchan_hash message_id
|
||||
* rating xlink_id
|
||||
*
|
||||
*/
|
||||
|
||||
require_once('include/cli_startup.php');
|
||||
require_once('include/zot.php');
|
||||
require_once('include/queue_fn.php');
|
||||
require_once('include/datetime.php');
|
||||
require_once('include/items.php');
|
||||
require_once('include/bbcode.php');
|
||||
require_once('include/identity.php');
|
||||
require_once('include/Contact.php');
|
||||
|
||||
function notifier_run($argv, $argc){
|
||||
|
||||
cli_startup();
|
||||
|
||||
$a = get_app();
|
||||
|
||||
|
||||
if($argc < 3)
|
||||
return;
|
||||
|
||||
logger('notifier: invoked: ' . print_r($argv,true), LOGGER_DEBUG);
|
||||
|
||||
$cmd = $argv[1];
|
||||
|
||||
$item_id = $argv[2];
|
||||
|
||||
$extra = (($argc > 3) ? $argv[3] : null);
|
||||
|
||||
if(! $item_id)
|
||||
return;
|
||||
|
||||
$sys = get_sys_channel();
|
||||
|
||||
$deliveries = array();
|
||||
|
||||
$dead_hubs = array();
|
||||
|
||||
$dh = q("select site_url from site where site_dead = 1");
|
||||
if($dh) {
|
||||
foreach($dh as $dead) {
|
||||
$dead_hubs[] = $dead['site_url'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$request = false;
|
||||
$mail = false;
|
||||
$top_level = false;
|
||||
$location = false;
|
||||
$recipients = array();
|
||||
$url_recipients = array();
|
||||
$normal_mode = true;
|
||||
$packet_type = 'undefined';
|
||||
|
||||
if($cmd === 'mail' || $cmd === 'single_mail') {
|
||||
$normal_mode = false;
|
||||
$mail = true;
|
||||
$private = true;
|
||||
$message = q("SELECT * FROM `mail` WHERE `id` = %d LIMIT 1",
|
||||
intval($item_id)
|
||||
);
|
||||
if(! $message) {
|
||||
return;
|
||||
}
|
||||
xchan_mail_query($message[0]);
|
||||
$uid = $message[0]['channel_id'];
|
||||
$recipients[] = $message[0]['from_xchan']; // include clones
|
||||
$recipients[] = $message[0]['to_xchan'];
|
||||
$item = $message[0];
|
||||
|
||||
$encoded_item = encode_mail($item);
|
||||
|
||||
$s = q("select * from channel where channel_id = %d limit 1",
|
||||
intval($item['channel_id'])
|
||||
);
|
||||
if($s)
|
||||
$channel = $s[0];
|
||||
|
||||
}
|
||||
elseif($cmd === 'request') {
|
||||
$channel_id = $item_id;
|
||||
$xchan = $argv[3];
|
||||
$request_message_id = $argv[4];
|
||||
|
||||
$s = q("select * from channel where channel_id = %d limit 1",
|
||||
intval($channel_id)
|
||||
);
|
||||
if($s)
|
||||
$channel = $s[0];
|
||||
|
||||
$private = true;
|
||||
$recipients[] = $xchan;
|
||||
$packet_type = 'request';
|
||||
$normal_mode = false;
|
||||
}
|
||||
elseif($cmd == 'permission_update' || $cmd == 'permission_create') {
|
||||
// Get the (single) recipient
|
||||
$r = q("select * from abook left join xchan on abook_xchan = xchan_hash where abook_id = %d and abook_self = 0",
|
||||
intval($item_id)
|
||||
);
|
||||
if($r) {
|
||||
$uid = $r[0]['abook_channel'];
|
||||
// Get the sender
|
||||
$channel = channelx_by_n($uid);
|
||||
if($channel) {
|
||||
$perm_update = array('sender' => $channel, 'recipient' => $r[0], 'success' => false, 'deliveries' => '');
|
||||
|
||||
if($cmd == 'permission_create')
|
||||
call_hooks('permissions_create',$perm_update);
|
||||
else
|
||||
call_hooks('permissions_update',$perm_update);
|
||||
|
||||
if($perm_update['success']) {
|
||||
if($perm_update['deliveries']) {
|
||||
$deliveries[] = $perm_update['deliveries'];
|
||||
do_delivery($deliveries);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else {
|
||||
$recipients[] = $r[0]['abook_xchan'];
|
||||
$private = false;
|
||||
$packet_type = 'refresh';
|
||||
$packet_recips = array(array('guid' => $r[0]['xchan_guid'],'guid_sig' => $r[0]['xchan_guid_sig'],'hash' => $r[0]['xchan_hash']));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif($cmd === 'refresh_all') {
|
||||
logger('notifier: refresh_all: ' . $item_id);
|
||||
$uid = $item_id;
|
||||
$channel = channelx_by_n($item_id);
|
||||
$r = q("select abook_xchan from abook where abook_channel = %d",
|
||||
intval($item_id)
|
||||
);
|
||||
if($r) {
|
||||
foreach($r as $rr) {
|
||||
$recipients[] = $rr['abook_xchan'];
|
||||
}
|
||||
}
|
||||
$private = false;
|
||||
$packet_type = 'refresh';
|
||||
}
|
||||
elseif($cmd === 'location') {
|
||||
logger('notifier: location: ' . $item_id);
|
||||
$s = q("select * from channel where channel_id = %d limit 1",
|
||||
intval($item_id)
|
||||
);
|
||||
if($s)
|
||||
$channel = $s[0];
|
||||
$uid = $item_id;
|
||||
$recipients = array();
|
||||
$r = q("select abook_xchan from abook where abook_channel = %d",
|
||||
intval($item_id)
|
||||
);
|
||||
if($r) {
|
||||
foreach($r as $rr) {
|
||||
$recipients[] = $rr['abook_xchan'];
|
||||
}
|
||||
}
|
||||
|
||||
$encoded_item = array('locations' => zot_encode_locations($channel),'type' => 'location', 'encoding' => 'zot');
|
||||
$target_item = array('aid' => $channel['channel_account_id'],'uid' => $channel['channel_id']);
|
||||
$private = false;
|
||||
$packet_type = 'location';
|
||||
$location = true;
|
||||
}
|
||||
elseif($cmd === 'purge_all') {
|
||||
logger('notifier: purge_all: ' . $item_id);
|
||||
$s = q("select * from channel where channel_id = %d limit 1",
|
||||
intval($item_id)
|
||||
);
|
||||
if($s)
|
||||
$channel = $s[0];
|
||||
$uid = $item_id;
|
||||
$recipients = array();
|
||||
$r = q("select abook_xchan from abook where abook_channel = %d",
|
||||
intval($item_id)
|
||||
);
|
||||
if($r) {
|
||||
foreach($r as $rr) {
|
||||
$recipients[] = $rr['abook_xchan'];
|
||||
}
|
||||
}
|
||||
$private = false;
|
||||
$packet_type = 'purge';
|
||||
}
|
||||
else {
|
||||
|
||||
// Normal items
|
||||
|
||||
// Fetch the target item
|
||||
|
||||
$r = q("SELECT * FROM item WHERE id = %d and parent != 0 LIMIT 1",
|
||||
intval($item_id)
|
||||
);
|
||||
|
||||
if(! $r)
|
||||
return;
|
||||
|
||||
xchan_query($r);
|
||||
|
||||
$r = fetch_post_tags($r);
|
||||
|
||||
$target_item = $r[0];
|
||||
$deleted_item = false;
|
||||
|
||||
if(intval($target_item['item_deleted'])) {
|
||||
logger('notifier: target item ITEM_DELETED', LOGGER_DEBUG);
|
||||
$deleted_item = true;
|
||||
}
|
||||
|
||||
if(intval($target_item['item_type']) != ITEM_TYPE_POST) {
|
||||
logger('notifier: target item not forwardable: type ' . $target_item['item_type'], LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
if(intval($target_item['item_unpublished']) || intval($target_item['item_delayed']) || intval($target_item['item_hidden'])) {
|
||||
logger('notifier: target item not published, so not forwardable', LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
|
||||
if(strpos($target_item['postopts'],'nodeliver') !== false) {
|
||||
logger('notifier: target item is undeliverable', LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
|
||||
$s = q("select * from channel left join xchan on channel_hash = xchan_hash where channel_id = %d limit 1",
|
||||
intval($target_item['uid'])
|
||||
);
|
||||
if($s)
|
||||
$channel = $s[0];
|
||||
|
||||
if($channel['channel_hash'] !== $target_item['author_xchan'] && $channel['channel_hash'] !== $target_item['owner_xchan']) {
|
||||
logger("notifier: Sending channel {$channel['channel_hash']} is not owner {$target_item['owner_xchan']} or author {$target_item['author_xchan']}", LOGGER_NORMAL, LOG_WARNING);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if($target_item['id'] == $target_item['parent']) {
|
||||
$parent_item = $target_item;
|
||||
$top_level_post = true;
|
||||
}
|
||||
else {
|
||||
// fetch the parent item
|
||||
$r = q("SELECT * from item where id = %d order by id asc",
|
||||
intval($target_item['parent'])
|
||||
);
|
||||
|
||||
if(! $r)
|
||||
return;
|
||||
|
||||
if(strpos($r[0]['postopts'],'nodeliver') !== false) {
|
||||
logger('notifier: target item is undeliverable', LOGGER_DEBUG, LOG_NOTICE);
|
||||
return;
|
||||
}
|
||||
|
||||
xchan_query($r);
|
||||
$r = fetch_post_tags($r);
|
||||
|
||||
$parent_item = $r[0];
|
||||
$top_level_post = false;
|
||||
}
|
||||
|
||||
// avoid looping of discover items 12/4/2014
|
||||
|
||||
if($sys && $parent_item['uid'] == $sys['channel_id'])
|
||||
return;
|
||||
|
||||
$encoded_item = encode_item($target_item);
|
||||
|
||||
// Send comments to the owner to re-deliver to everybody in the conversation
|
||||
// We only do this if the item in question originated on this site. This prevents looping.
|
||||
// To clarify, a site accepting a new comment is responsible for sending it to the owner for relay.
|
||||
// Relaying should never be initiated on a post that arrived from elsewhere.
|
||||
|
||||
// We should normally be able to rely on ITEM_ORIGIN, but start_delivery_chain() incorrectly set this
|
||||
// flag on comments for an extended period. So we'll also call comment_local_origin() which looks at
|
||||
// the hostname in the message_id and provides a second (fallback) opinion.
|
||||
|
||||
$relay_to_owner = (((! $top_level_post) && (intval($target_item['item_origin'])) && comment_local_origin($target_item)) ? true : false);
|
||||
|
||||
|
||||
|
||||
$uplink = false;
|
||||
|
||||
// $cmd === 'relay' indicates the owner is sending it to the original recipients
|
||||
// don't allow the item in the relay command to relay to owner under any circumstances, it will loop
|
||||
|
||||
logger('notifier: relay_to_owner: ' . (($relay_to_owner) ? 'true' : 'false'), LOGGER_DATA, LOG_DEBUG);
|
||||
logger('notifier: top_level_post: ' . (($top_level_post) ? 'true' : 'false'), LOGGER_DATA, LOG_DEBUG);
|
||||
|
||||
// tag_deliver'd post which needs to be sent back to the original author
|
||||
|
||||
if(($cmd === 'uplink') && intval($parent_item['item_uplink']) && (! $top_level_post)) {
|
||||
logger('notifier: uplink');
|
||||
$uplink = true;
|
||||
}
|
||||
|
||||
if(($relay_to_owner || $uplink) && ($cmd !== 'relay')) {
|
||||
logger('notifier: followup relay', LOGGER_DEBUG);
|
||||
$recipients = array(($uplink) ? $parent_item['source_xchan'] : $parent_item['owner_xchan']);
|
||||
$private = true;
|
||||
if(! $encoded_item['flags'])
|
||||
$encoded_item['flags'] = array();
|
||||
$encoded_item['flags'][] = 'relay';
|
||||
}
|
||||
else {
|
||||
logger('notifier: normal distribution', LOGGER_DEBUG);
|
||||
if($cmd === 'relay')
|
||||
logger('notifier: owner relay');
|
||||
|
||||
// if our parent is a tag_delivery recipient, uplink to the original author causing
|
||||
// a delivery fork.
|
||||
|
||||
if(($parent_item) && intval($parent_item['item_uplink']) && (! $top_level_post) && ($cmd !== 'uplink')) {
|
||||
// don't uplink a relayed post to the relay owner
|
||||
if($parent_item['source_xchan'] !== $parent_item['owner_xchan']) {
|
||||
logger('notifier: uplinking this item');
|
||||
proc_run('php','include/notifier.php','uplink',$item_id);
|
||||
}
|
||||
}
|
||||
|
||||
$private = false;
|
||||
$recipients = collect_recipients($parent_item,$private);
|
||||
|
||||
// FIXME add any additional recipients such as mentions, etc.
|
||||
|
||||
// don't send deletions onward for other people's stuff
|
||||
// TODO verify this is needed - copied logic from same place in old code
|
||||
|
||||
if(intval($target_item['item_deleted']) && (! intval($target_item['item_wall']))) {
|
||||
logger('notifier: ignoring delete notification for non-wall item', LOGGER_NORMAL, LOG_NOTICE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$walltowall = (($top_level_post && $channel['xchan_hash'] === $target_item['author_xchan']) ? true : false);
|
||||
|
||||
// Generic delivery section, we have an encoded item and recipients
|
||||
// Now start the delivery process
|
||||
|
||||
$x = $encoded_item;
|
||||
$x['title'] = 'private';
|
||||
$x['body'] = 'private';
|
||||
logger('notifier: encoded item: ' . print_r($x,true), LOGGER_DATA, LOG_DEBUG);
|
||||
|
||||
stringify_array_elms($recipients);
|
||||
if(! $recipients)
|
||||
return;
|
||||
|
||||
// logger('notifier: recipients: ' . print_r($recipients,true), LOGGER_NORMAL, LOG_DEBUG);
|
||||
|
||||
$env_recips = (($private) ? array() : null);
|
||||
|
||||
$details = q("select xchan_hash, xchan_instance_url, xchan_network, xchan_addr, xchan_guid, xchan_guid_sig from xchan where xchan_hash in (" . implode(',',$recipients) . ")");
|
||||
|
||||
|
||||
$recip_list = array();
|
||||
|
||||
if($details) {
|
||||
foreach($details as $d) {
|
||||
|
||||
$recip_list[] = $d['xchan_addr'] . ' (' . $d['xchan_hash'] . ')';
|
||||
if($private)
|
||||
$env_recips[] = array('guid' => $d['xchan_guid'],'guid_sig' => $d['xchan_guid_sig'],'hash' => $d['xchan_hash']);
|
||||
|
||||
if($d['xchan_network'] === 'mail' && $normal_mode) {
|
||||
$delivery_options = get_xconfig($d['xchan_hash'],'system','delivery_mode');
|
||||
if(! $delivery_options)
|
||||
format_and_send_email($channel,$d,$target_item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$narr = array(
|
||||
'channel' => $channel,
|
||||
'env_recips' => $env_recips,
|
||||
'packet_recips' => $packet_recips,
|
||||
'recipients' => $recipients,
|
||||
'item' => $item,
|
||||
'target_item' => $target_item,
|
||||
'top_level_post' => $top_level_post,
|
||||
'private' => $private,
|
||||
'relay_to_owner' => $relay_to_owner,
|
||||
'uplink' => $uplink,
|
||||
'cmd' => $cmd,
|
||||
'mail' => $mail,
|
||||
'single' => (($cmd === 'single_mail' || $cmd === 'single_activity') ? true : false),
|
||||
'location' => $location,
|
||||
'request' => $request,
|
||||
'normal_mode' => $normal_mode,
|
||||
'packet_type' => $packet_type,
|
||||
'walltowall' => $walltowall,
|
||||
'queued' => array()
|
||||
);
|
||||
|
||||
call_hooks('notifier_process', $narr);
|
||||
if($narr['queued']) {
|
||||
foreach($narr['queued'] as $pq)
|
||||
$deliveries[] = $pq;
|
||||
}
|
||||
|
||||
// notifier_process can alter the recipient list
|
||||
|
||||
$recipients = $narr['recipients'];
|
||||
$env_recips = $narr['env_recips'];
|
||||
$packet_recips = $narr['packet_recips'];
|
||||
|
||||
if(($private) && (! $env_recips)) {
|
||||
// shouldn't happen
|
||||
logger('notifier: private message with no envelope recipients.' . print_r($argv,true), LOGGER_NORMAL, LOG_NOTICE);
|
||||
}
|
||||
|
||||
logger('notifier: recipients (may be delivered to more if public): ' . print_r($recip_list,true), LOGGER_DEBUG);
|
||||
|
||||
|
||||
// Now we have collected recipients (except for external mentions, FIXME)
|
||||
// Let's reduce this to a set of hubs.
|
||||
|
||||
$r = q("select * from hubloc where hubloc_hash in (" . implode(',',$recipients) . ")
|
||||
and hubloc_error = 0 and hubloc_deleted = 0"
|
||||
);
|
||||
|
||||
|
||||
if(! $r) {
|
||||
logger('notifier: no hubs', LOGGER_NORMAL, LOG_NOTICE);
|
||||
return;
|
||||
}
|
||||
|
||||
$hubs = $r;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Reduce the hubs to those that are unique. For zot hubs, we need to verify uniqueness by the sitekey, since it may have been
|
||||
* a re-install which has not yet been detected and pruned.
|
||||
* For other networks which don't have or require sitekeys, we'll have to use the URL
|
||||
*/
|
||||
|
||||
|
||||
$hublist = array(); // this provides an easily printable list for the logs
|
||||
$dhubs = array(); // delivery hubs where we store our resulting unique array
|
||||
$keys = array(); // array of keys to check uniquness for zot hubs
|
||||
$urls = array(); // array of urls to check uniqueness of hubs from other networks
|
||||
|
||||
|
||||
foreach($hubs as $hub) {
|
||||
if(in_array($hub['hubloc_url'],$dead_hubs)) {
|
||||
logger('skipping dead hub: ' . $hub['hubloc_url'], LOGGER_DEBUG, LOG_INFO);
|
||||
continue;
|
||||
}
|
||||
|
||||
if($hub['hubloc_network'] == 'zot') {
|
||||
if(! in_array($hub['hubloc_sitekey'],$keys)) {
|
||||
$hublist[] = $hub['hubloc_host'];
|
||||
$dhubs[] = $hub;
|
||||
$keys[] = $hub['hubloc_sitekey'];
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(! in_array($hub['hubloc_url'],$urls)) {
|
||||
$hublist[] = $hub['hubloc_host'];
|
||||
$dhubs[] = $hub;
|
||||
$urls[] = $hub['hubloc_url'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger('notifier: will notify/deliver to these hubs: ' . print_r($hublist,true), LOGGER_DEBUG, LOG_DEBUG);
|
||||
|
||||
|
||||
foreach($dhubs as $hub) {
|
||||
|
||||
if($hub['hubloc_network'] !== 'zot') {
|
||||
|
||||
$narr = array(
|
||||
'channel' => $channel,
|
||||
'env_recips' => $env_recips,
|
||||
'packet_recips' => $packet_recips,
|
||||
'recipients' => $recipients,
|
||||
'item' => $item,
|
||||
'target_item' => $target_item,
|
||||
'hub' => $hub,
|
||||
'top_level_post' => $top_level_post,
|
||||
'private' => $private,
|
||||
'relay_to_owner' => $relay_to_owner,
|
||||
'uplink' => $uplink,
|
||||
'cmd' => $cmd,
|
||||
'mail' => $mail,
|
||||
'single' => (($cmd === 'single_mail' || $cmd === 'single_activity') ? true : false),
|
||||
'location' => $location,
|
||||
'request' => $request,
|
||||
'normal_mode' => $normal_mode,
|
||||
'packet_type' => $packet_type,
|
||||
'walltowall' => $walltowall,
|
||||
'queued' => array()
|
||||
);
|
||||
|
||||
|
||||
call_hooks('notifier_hub',$narr);
|
||||
if($narr['queued']) {
|
||||
foreach($narr['queued'] as $pq)
|
||||
$deliveries[] = $pq;
|
||||
}
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
// singleton deliveries by definition 'not got zot'.
|
||||
// Single deliveries are other federated networks (plugins) and we're essentially
|
||||
// delivering only to those that have this site url in their abook_instance
|
||||
// and only from within a sync operation. This means if you post from a clone,
|
||||
// and a connection is connected to one of your other clones; assuming that hub
|
||||
// is running it will receive a sync packet. On receipt of this sync packet it
|
||||
// will invoke a delivery to those connections which are connected to just that
|
||||
// hub instance.
|
||||
|
||||
if($cmd === 'single_mail' || $cmd === 'single_activity') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// default: zot protocol
|
||||
|
||||
$hash = random_string();
|
||||
$packet = null;
|
||||
|
||||
if($packet_type === 'refresh' || $packet_type === 'purge') {
|
||||
$packet = zot_build_packet($channel,$packet_type,(($packet_recips) ? $packet_recips : null));
|
||||
}
|
||||
elseif($packet_type === 'request') {
|
||||
$packet = zot_build_packet($channel,$packet_type,$env_recips,$hub['hubloc_sitekey'],$hash,
|
||||
array('message_id' => $request_message_id)
|
||||
);
|
||||
}
|
||||
|
||||
if($packet) {
|
||||
queue_insert(array(
|
||||
'hash' => $hash,
|
||||
'account_id' => $channel['channel_account_id'],
|
||||
'channel_id' => $channel['channel_id'],
|
||||
'posturl' => $hub['hubloc_callback'],
|
||||
'notify' => $packet
|
||||
));
|
||||
}
|
||||
else {
|
||||
$packet = zot_build_packet($channel,'notify',$env_recips,(($private) ? $hub['hubloc_sitekey'] : null),$hash);
|
||||
queue_insert(array(
|
||||
'hash' => $hash,
|
||||
'account_id' => $target_item['aid'],
|
||||
'channel_id' => $target_item['uid'],
|
||||
'posturl' => $hub['hubloc_callback'],
|
||||
'notify' => $packet,
|
||||
'msg' => json_encode($encoded_item)
|
||||
));
|
||||
|
||||
// only create delivery reports for normal undeleted items
|
||||
if(is_array($target_item) && array_key_exists('postopts',$target_item) && (! $target_item['item_deleted']) && (! get_config('system','disable_dreport'))) {
|
||||
q("insert into dreport ( dreport_mid, dreport_site, dreport_recip, dreport_result, dreport_time, dreport_xchan, dreport_queue ) values ( '%s','%s','%s','%s','%s','%s','%s' ) ",
|
||||
dbesc($target_item['mid']),
|
||||
dbesc($hub['hubloc_host']),
|
||||
dbesc($hub['hubloc_host']),
|
||||
dbesc('queued'),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($channel['channel_hash']),
|
||||
dbesc($hash)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$deliveries[] = $hash;
|
||||
}
|
||||
|
||||
if($normal_mode) {
|
||||
$x = q("select * from hook where hook = 'notifier_normal'");
|
||||
if($x)
|
||||
proc_run('php','include/deliver_hooks.php', $target_item['id']);
|
||||
}
|
||||
|
||||
if($deliveries)
|
||||
do_delivery($deliveries);
|
||||
|
||||
logger('notifier: basic loop complete.', LOGGER_DEBUG);
|
||||
|
||||
call_hooks('notifier_end',$target_item);
|
||||
|
||||
logger('notifer: complete.');
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
notifier_run($argv,$argc);
|
||||
killme();
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
<?php /** @file */
|
||||
|
||||
|
||||
function format_notification($item) {
|
||||
|
||||
$ret = '';
|
||||
|
||||
require_once('include/conversation.php');
|
||||
|
||||
// Call localize_item with the "brief" flag to get a one line status for activities.
|
||||
// This should set $item['localized'] to indicate we have a brief summary.
|
||||
|
||||
localize_item($item);
|
||||
|
||||
if($item_localize) {
|
||||
$itemem_text = $item['localize'];
|
||||
}
|
||||
else {
|
||||
$itemem_text = (($item['item_thread_top'])
|
||||
? t('created a new post')
|
||||
: sprintf( t('commented on %s\'s post'), $item['owner']['xchan_name']));
|
||||
}
|
||||
|
||||
// convert this logic into a json array just like the system notifications
|
||||
|
||||
return array(
|
||||
'notify_link' => $item['llink'],
|
||||
'name' => $item['author']['xchan_name'],
|
||||
'url' => $item['author']['xchan_url'],
|
||||
'photo' => $item['author']['xchan_photo_s'],
|
||||
'when' => relative_date($item['created']),
|
||||
'class' => (intval($item['item_unseen']) ? 'notify-unseen' : 'notify-seen'),
|
||||
'message' => strip_tags(bbcode($itemem_text))
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ class ZotOAuth1DataStore extends OAuth1DataStore {
|
||||
|
||||
logger(__function__.":".$consumer.", ". $token_type.", ".$token, LOGGER_DEBUG);
|
||||
|
||||
$r = q("SELECT id, secret, scope, expires, uid FROM tokens WHERE client_id = '%s' AND scope = '%s' AND id = '%s'",
|
||||
$r = q("SELECT id, secret, auth_scope, expires, uid FROM tokens WHERE client_id = '%s' AND auth_scope = '%s' AND id = '%s'",
|
||||
dbesc($consumer->key),
|
||||
dbesc($token_type),
|
||||
dbesc($token)
|
||||
@@ -45,7 +45,7 @@ class ZotOAuth1DataStore extends OAuth1DataStore {
|
||||
|
||||
if (count($r)){
|
||||
$ot=new OAuth1Token($r[0]['id'],$r[0]['secret']);
|
||||
$ot->scope=$r[0]['scope'];
|
||||
$ot->scope=$r[0]['auth_scope'];
|
||||
$ot->expires = $r[0]['expires'];
|
||||
$ot->uid = $r[0]['uid'];
|
||||
return $ot;
|
||||
@@ -79,7 +79,7 @@ class ZotOAuth1DataStore extends OAuth1DataStore {
|
||||
$k = $consumer;
|
||||
}
|
||||
|
||||
$r = q("INSERT INTO tokens (id, secret, client_id, scope, expires) VALUES ('%s','%s','%s','%s', %d)",
|
||||
$r = q("INSERT INTO tokens (id, secret, client_id, auth_scope, expires) VALUES ('%s','%s','%s','%s', %d)",
|
||||
dbesc($key),
|
||||
dbesc($sec),
|
||||
dbesc($k),
|
||||
@@ -110,7 +110,7 @@ class ZotOAuth1DataStore extends OAuth1DataStore {
|
||||
$key = $this->gen_token();
|
||||
$sec = $this->gen_token();
|
||||
|
||||
$r = q("INSERT INTO tokens (id, secret, client_id, scope, expires, uid) VALUES ('%s','%s','%s','%s', %d, %d)",
|
||||
$r = q("INSERT INTO tokens (id, secret, client_id, auth_scope, expires, uid) VALUES ('%s','%s','%s','%s', %d, %d)",
|
||||
dbesc($key),
|
||||
dbesc($sec),
|
||||
dbesc($consumer->key),
|
||||
@@ -249,7 +249,7 @@ class FKOAuth2 extends OAuth2 {
|
||||
|
||||
|
||||
protected function getAuthCode($code) {
|
||||
$r = q("SELECT id, client_id, redirect_uri, expires, scope FROM auth_codes WHERE id = '%s'",
|
||||
$r = q("SELECT id, client_id, redirect_uri, expires, auth_scope FROM auth_codes WHERE id = '%s'",
|
||||
dbesc($code));
|
||||
|
||||
if (count($r))
|
||||
@@ -259,7 +259,7 @@ class FKOAuth2 extends OAuth2 {
|
||||
|
||||
protected function setAuthCode($code, $client_id, $redirect_uri, $expires, $scope = NULL) {
|
||||
$r = q("INSERT INTO auth_codes
|
||||
(id, client_id, redirect_uri, expires, scope) VALUES
|
||||
(id, client_id, redirect_uri, expires, auth_scope) VALUES
|
||||
('%s', '%s', '%s', %d, '%s')",
|
||||
dbesc($code),
|
||||
dbesc($client_id),
|
||||
|
||||
@@ -227,7 +227,7 @@ function oembed_fetch_url($embedurl){
|
||||
}
|
||||
|
||||
function oembed_format_object($j){
|
||||
$a = get_app();
|
||||
|
||||
$embedurl = $j->embedurl;
|
||||
|
||||
// logger('format: ' . print_r($j,true));
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
<?php /** @file */
|
||||
|
||||
require_once('boot.php');
|
||||
require_once('include/cli_startup.php');
|
||||
require_once('include/zot.php');
|
||||
require_once('include/dir_fns.php');
|
||||
|
||||
|
||||
function onedirsync_run($argv, $argc){
|
||||
|
||||
|
||||
cli_startup();
|
||||
$a = get_app();
|
||||
|
||||
logger('onedirsync: start ' . intval($argv[1]));
|
||||
|
||||
if(($argc > 1) && (intval($argv[1])))
|
||||
$update_id = intval($argv[1]);
|
||||
|
||||
if(! $update_id) {
|
||||
logger('onedirsync: no update');
|
||||
return;
|
||||
}
|
||||
|
||||
$r = q("select * from updates where ud_id = %d limit 1",
|
||||
intval($update_id)
|
||||
);
|
||||
|
||||
if(! $r)
|
||||
return;
|
||||
if(($r[0]['ud_flags'] & UPDATE_FLAGS_UPDATED) || (! $r[0]['ud_addr']))
|
||||
return;
|
||||
|
||||
// Have we probed this channel more recently than the other directory server
|
||||
// (where we received this update from) ?
|
||||
// If we have, we don't need to do anything except mark any older entries updated
|
||||
|
||||
$x = q("select * from updates where ud_addr = '%s' and ud_date > '%s' and ( ud_flags & %d )>0 order by ud_date desc limit 1",
|
||||
dbesc($r[0]['ud_addr']),
|
||||
dbesc($r[0]['ud_date']),
|
||||
intval(UPDATE_FLAGS_UPDATED)
|
||||
);
|
||||
if($x) {
|
||||
$y = q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and ( ud_flags & %d ) = 0 and ud_date != '%s'",
|
||||
intval(UPDATE_FLAGS_UPDATED),
|
||||
dbesc($r[0]['ud_addr']),
|
||||
intval(UPDATE_FLAGS_UPDATED),
|
||||
dbesc($x[0]['ud_date'])
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// ignore doing an update if this ud_addr refers to a known dead hubloc
|
||||
|
||||
$h = q("select * from hubloc where hubloc_addr = '%s' limit 1",
|
||||
dbesc($r[0]['ud_addr'])
|
||||
);
|
||||
if(($h) && ($h[0]['hubloc_status'] & HUBLOC_OFFLINE)) {
|
||||
$y = q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and ( ud_flags & %d ) = 0 ",
|
||||
intval(UPDATE_FLAGS_UPDATED),
|
||||
dbesc($r[0]['ud_addr']),
|
||||
intval(UPDATE_FLAGS_UPDATED)
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// we might have to pull this out some day, but for now update_directory_entry()
|
||||
// runs zot_finger() and is kind of zot specific
|
||||
|
||||
if($h && $h[0]['hubloc_network'] !== 'zot')
|
||||
return;
|
||||
|
||||
update_directory_entry($r[0]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
onedirsync_run($argv,$argc);
|
||||
killme();
|
||||
}
|
||||
@@ -1,159 +0,0 @@
|
||||
<?php /** @file */
|
||||
|
||||
require_once('boot.php');
|
||||
require_once('include/cli_startup.php');
|
||||
require_once('include/zot.php');
|
||||
require_once('include/socgraph.php');
|
||||
require_once('include/Contact.php');
|
||||
|
||||
|
||||
function onepoll_run($argv, $argc){
|
||||
|
||||
|
||||
cli_startup();
|
||||
$a = get_app();
|
||||
|
||||
logger('onepoll: start');
|
||||
|
||||
if(($argc > 1) && (intval($argv[1])))
|
||||
$contact_id = intval($argv[1]);
|
||||
|
||||
if(! $contact_id) {
|
||||
logger('onepoll: no contact');
|
||||
return;
|
||||
}
|
||||
|
||||
$d = datetime_convert();
|
||||
|
||||
$contacts = q("SELECT abook.*, xchan.*, account.*
|
||||
FROM abook LEFT JOIN account on abook_account = account_id left join xchan on xchan_hash = abook_xchan
|
||||
where abook_id = %d
|
||||
and abook_pending = 0 and abook_archived = 0 and abook_blocked = 0 and abook_ignored = 0
|
||||
AND (( account_flags = %d ) OR ( account_flags = %d )) limit 1",
|
||||
intval($contact_id),
|
||||
intval(ACCOUNT_OK),
|
||||
intval(ACCOUNT_UNVERIFIED)
|
||||
);
|
||||
|
||||
if(! $contacts) {
|
||||
logger('onepoll: abook_id not found: ' . $contact_id);
|
||||
return;
|
||||
}
|
||||
|
||||
$contact = $contacts[0];
|
||||
|
||||
$t = $contact['abook_updated'];
|
||||
|
||||
$importer_uid = $contact['abook_channel'];
|
||||
|
||||
$r = q("SELECT * from channel left join xchan on channel_hash = xchan_hash where channel_id = %d limit 1",
|
||||
intval($importer_uid)
|
||||
);
|
||||
|
||||
if(! $r)
|
||||
return;
|
||||
|
||||
$importer = $r[0];
|
||||
|
||||
logger("onepoll: poll: ({$contact['id']}) IMPORTER: {$importer['xchan_name']}, CONTACT: {$contact['xchan_name']}");
|
||||
|
||||
$last_update = ((($contact['abook_updated'] === $contact['abook_created']) || ($contact['abook_updated'] === NULL_DATE))
|
||||
? datetime_convert('UTC','UTC','now - 7 days')
|
||||
: datetime_convert('UTC','UTC',$contact['abook_updated'] . ' - 2 days')
|
||||
);
|
||||
|
||||
if($contact['xchan_network'] === 'rss') {
|
||||
logger('onepoll: processing feed ' . $contact['xchan_name'], LOGGER_DEBUG);
|
||||
handle_feed($importer['channel_id'],$contact_id,$contact['xchan_hash']);
|
||||
q("update abook set abook_connected = '%s' where abook_id = %d",
|
||||
dbesc(datetime_convert()),
|
||||
intval($contact['abook_id'])
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if($contact['xchan_network'] !== 'zot')
|
||||
return;
|
||||
|
||||
// update permissions
|
||||
|
||||
$x = zot_refresh($contact,$importer);
|
||||
|
||||
$responded = false;
|
||||
$updated = datetime_convert();
|
||||
$connected = datetime_convert();
|
||||
if(! $x) {
|
||||
// mark for death by not updating abook_connected, this is caught in include/poller.php
|
||||
q("update abook set abook_updated = '%s' where abook_id = %d",
|
||||
dbesc($updated),
|
||||
intval($contact['abook_id'])
|
||||
);
|
||||
}
|
||||
else {
|
||||
q("update abook set abook_updated = '%s', abook_connected = '%s' where abook_id = %d",
|
||||
dbesc($updated),
|
||||
dbesc($connected),
|
||||
intval($contact['abook_id'])
|
||||
);
|
||||
$responded = true;
|
||||
}
|
||||
|
||||
if(! $responded)
|
||||
return;
|
||||
|
||||
if($contact['xchan_connurl']) {
|
||||
$fetch_feed = true;
|
||||
$x = null;
|
||||
|
||||
if(! ($contact['abook_their_perms'] & PERMS_R_STREAM ))
|
||||
$fetch_feed = false;
|
||||
|
||||
if($fetch_feed) {
|
||||
|
||||
$feedurl = str_replace('/poco/','/zotfeed/',$contact['xchan_connurl']);
|
||||
$feedurl .= '?f=&mindate=' . urlencode($last_update);
|
||||
|
||||
$x = z_fetch_url($feedurl);
|
||||
|
||||
logger('feed_update: ' . print_r($x,true), LOGGER_DATA);
|
||||
|
||||
}
|
||||
|
||||
if(($x) && ($x['success'])) {
|
||||
$total = 0;
|
||||
logger('onepoll: feed update ' . $contact['xchan_name'] . ' ' . $feedurl);
|
||||
|
||||
$j = json_decode($x['body'],true);
|
||||
if($j['success'] && $j['messages']) {
|
||||
foreach($j['messages'] as $message) {
|
||||
$results = process_delivery(array('hash' => $contact['xchan_hash']), get_item_elements($message),
|
||||
array(array('hash' => $importer['xchan_hash'])), false);
|
||||
logger('onepoll: feed_update: process_delivery: ' . print_r($results,true), LOGGER_DATA);
|
||||
$total ++;
|
||||
}
|
||||
logger("onepoll: $total messages processed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// update the poco details for this connection
|
||||
|
||||
if($contact['xchan_connurl']) {
|
||||
$r = q("SELECT xlink_id from xlink
|
||||
where xlink_xchan = '%s' and xlink_updated > %s - INTERVAL %s and xlink_static = 0 limit 1",
|
||||
intval($contact['xchan_hash']),
|
||||
db_utcnow(), db_quoteinterval('1 DAY')
|
||||
);
|
||||
if(! $r) {
|
||||
poco_load($contact['xchan_hash'],$contact['xchan_connurl']);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
onepoll_run($argv,$argc);
|
||||
killme();
|
||||
}
|
||||
@@ -316,7 +316,7 @@ abstract class photo_driver {
|
||||
$p['resource_id'] = (($arr['resource_id']) ? $arr['resource_id'] : '');
|
||||
$p['filename'] = (($arr['filename']) ? $arr['filename'] : '');
|
||||
$p['album'] = (($arr['album']) ? $arr['album'] : '');
|
||||
$p['scale'] = ((intval($arr['scale'])) ? intval($arr['scale']) : 0);
|
||||
$p['imgscale'] = ((intval($arr['imgscale'])) ? intval($arr['imgscale']) : 0);
|
||||
$p['allow_cid'] = (($arr['allow_cid']) ? $arr['allow_cid'] : '');
|
||||
$p['allow_gid'] = (($arr['allow_gid']) ? $arr['allow_gid'] : '');
|
||||
$p['deny_cid'] = (($arr['deny_cid']) ? $arr['deny_cid'] : '');
|
||||
@@ -329,14 +329,14 @@ abstract class photo_driver {
|
||||
$p['os_storage'] = intval($arr['os_storage']);
|
||||
$p['os_path'] = $arr['os_path'];
|
||||
|
||||
if(! intval($p['scale']))
|
||||
logger('save: ' . print_r($arr,true));
|
||||
if(! intval($p['imgscale']))
|
||||
logger('save: ' . print_r($arr,true), LOGGER_DATA);
|
||||
|
||||
$x = q("select id from photo where resource_id = '%s' and uid = %d and xchan = '%s' and `scale` = %d limit 1",
|
||||
$x = q("select id from photo where resource_id = '%s' and uid = %d and xchan = '%s' and imgscale = %d limit 1",
|
||||
dbesc($p['resource_id']),
|
||||
intval($p['uid']),
|
||||
dbesc($p['xchan']),
|
||||
intval($p['scale'])
|
||||
intval($p['imgscale'])
|
||||
);
|
||||
if($x) {
|
||||
$r = q("UPDATE `photo` set
|
||||
@@ -347,14 +347,14 @@ abstract class photo_driver {
|
||||
`created` = '%s',
|
||||
`edited` = '%s',
|
||||
`filename` = '%s',
|
||||
`type` = '%s',
|
||||
`mimetype` = '%s',
|
||||
`album` = '%s',
|
||||
`height` = %d,
|
||||
`width` = %d,
|
||||
`data` = '%s',
|
||||
`content` = '%s',
|
||||
`os_storage` = %d,
|
||||
`size` = %d,
|
||||
`scale` = %d,
|
||||
`filesize` = %d,
|
||||
`imgscale` = %d,
|
||||
`photo_usage` = %d,
|
||||
`title` = '%s',
|
||||
`description` = '%s',
|
||||
@@ -378,7 +378,7 @@ abstract class photo_driver {
|
||||
(intval($p['os_storage']) ? dbesc($p['os_path']) : dbescbin($this->imageString())),
|
||||
intval($p['os_storage']),
|
||||
intval(strlen($this->imageString())),
|
||||
intval($p['scale']),
|
||||
intval($p['imgscale']),
|
||||
intval($p['photo_usage']),
|
||||
dbesc($p['title']),
|
||||
dbesc($p['description']),
|
||||
@@ -391,7 +391,7 @@ abstract class photo_driver {
|
||||
}
|
||||
else {
|
||||
$r = q("INSERT INTO `photo`
|
||||
( `aid`, `uid`, `xchan`, `resource_id`, `created`, `edited`, `filename`, type, `album`, `height`, `width`, `data`, `os_storage`, `size`, `scale`, `photo_usage`, `title`, `description`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` )
|
||||
( `aid`, `uid`, `xchan`, `resource_id`, `created`, `edited`, `filename`, mimetype, `album`, `height`, `width`, `content`, `os_storage`, `filesize`, `imgscale`, `photo_usage`, `title`, `description`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` )
|
||||
VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s' )",
|
||||
intval($p['aid']),
|
||||
intval($p['uid']),
|
||||
@@ -407,7 +407,7 @@ abstract class photo_driver {
|
||||
(intval($p['os_storage']) ? dbesc($p['os_path']) : dbescbin($this->imageString())),
|
||||
intval($p['os_storage']),
|
||||
intval(strlen($this->imageString())),
|
||||
intval($p['scale']),
|
||||
intval($p['imgscale']),
|
||||
intval($p['photo_usage']),
|
||||
dbesc($p['title']),
|
||||
dbesc($p['description']),
|
||||
@@ -422,7 +422,7 @@ abstract class photo_driver {
|
||||
|
||||
public function store($aid, $uid, $xchan, $rid, $filename, $album, $scale, $usage = PHOTO_NORMAL, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '') {
|
||||
|
||||
$x = q("select id from photo where `resource_id` = '%s' and uid = %d and `xchan` = '%s' and `scale` = %d limit 1",
|
||||
$x = q("select id from photo where `resource_id` = '%s' and uid = %d and `xchan` = '%s' and `imgscale` = %d limit 1",
|
||||
dbesc($rid),
|
||||
intval($uid),
|
||||
dbesc($xchan),
|
||||
@@ -437,13 +437,13 @@ abstract class photo_driver {
|
||||
`created` = '%s',
|
||||
`edited` = '%s',
|
||||
`filename` = '%s',
|
||||
`type` = '%s',
|
||||
`mimetype` = '%s',
|
||||
`album` = '%s',
|
||||
`height` = %d,
|
||||
`width` = %d,
|
||||
`data` = '%s',
|
||||
`size` = %d,
|
||||
`scale` = %d,
|
||||
`content` = '%s',
|
||||
`filesize` = %d,
|
||||
`imgscale` = %d,
|
||||
`photo_usage` = %d,
|
||||
`allow_cid` = '%s',
|
||||
`allow_gid` = '%s',
|
||||
@@ -475,7 +475,7 @@ abstract class photo_driver {
|
||||
}
|
||||
else {
|
||||
$r = q("INSERT INTO `photo`
|
||||
( `aid`, `uid`, `xchan`, `resource_id`, `created`, `edited`, `filename`, type, `album`, `height`, `width`, `data`, `size`, `scale`, `photo_usage`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` )
|
||||
( `aid`, `uid`, `xchan`, `resource_id`, `created`, `edited`, `filename`, mimetype, `album`, `height`, `width`, `content`, `filesize`, `imgscale`, `photo_usage`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` )
|
||||
VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s' )",
|
||||
intval($aid),
|
||||
intval($uid),
|
||||
@@ -521,7 +521,7 @@ function guess_image_type($filename, $headers = '') {
|
||||
logger('Photo: guess_image_type: '.$filename . ($headers?' from curl headers':''), LOGGER_DEBUG);
|
||||
$type = null;
|
||||
if ($headers) {
|
||||
$a = get_app();
|
||||
|
||||
$hdrs=array();
|
||||
$h = explode("\n",$headers);
|
||||
foreach ($h as $l) {
|
||||
@@ -580,8 +580,6 @@ function guess_image_type($filename, $headers = '') {
|
||||
|
||||
function import_xchan_photo($photo,$xchan,$thing = false) {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
$flags = (($thing) ? PHOTO_THING : PHOTO_XCHAN);
|
||||
$album = (($thing) ? 'Things' : 'Contact Photos');
|
||||
|
||||
@@ -590,7 +588,7 @@ function import_xchan_photo($photo,$xchan,$thing = false) {
|
||||
if($thing)
|
||||
$hash = photo_new_resource();
|
||||
else {
|
||||
$r = q("select resource_id from photo where xchan = '%s' and photo_usage = %d and scale = 4 limit 1",
|
||||
$r = q("select resource_id from photo where xchan = '%s' and photo_usage = %d and imgscale = 4 limit 1",
|
||||
dbesc($xchan),
|
||||
intval(PHOTO_XCHAN)
|
||||
);
|
||||
@@ -656,7 +654,7 @@ function import_xchan_photo($photo,$xchan,$thing = false) {
|
||||
else
|
||||
$photo_failure = true;
|
||||
|
||||
$p = array('xchan' => $xchan,'resource_id' => $hash, 'filename' => basename($photo), 'album' => $album, 'photo_usage' => $flags, 'scale' => 4);
|
||||
$p = array('xchan' => $xchan,'resource_id' => $hash, 'filename' => basename($photo), 'album' => $album, 'photo_usage' => $flags, 'imgscale' => 4);
|
||||
|
||||
$r = $img->save($p);
|
||||
|
||||
@@ -664,7 +662,7 @@ function import_xchan_photo($photo,$xchan,$thing = false) {
|
||||
$photo_failure = true;
|
||||
|
||||
$img->scaleImage(80);
|
||||
$p['scale'] = 5;
|
||||
$p['imgscale'] = 5;
|
||||
|
||||
$r = $img->save($p);
|
||||
|
||||
@@ -672,7 +670,7 @@ function import_xchan_photo($photo,$xchan,$thing = false) {
|
||||
$photo_failure = true;
|
||||
|
||||
$img->scaleImage(48);
|
||||
$p['scale'] = 6;
|
||||
$p['imgscale'] = 6;
|
||||
|
||||
$r = $img->save($p);
|
||||
|
||||
@@ -703,8 +701,6 @@ function import_xchan_photo($photo,$xchan,$thing = false) {
|
||||
|
||||
function import_channel_photo($photo,$type,$aid,$uid) {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
logger('import_channel_photo: importing channel photo for ' . $uid, LOGGER_DEBUG);
|
||||
|
||||
$hash = photo_new_resource();
|
||||
@@ -719,7 +715,7 @@ function import_channel_photo($photo,$type,$aid,$uid) {
|
||||
|
||||
$img->scaleImageSquare(300);
|
||||
|
||||
$p = array('aid' => $aid, 'uid' => $uid, 'resource_id' => $hash, 'filename' => $filename, 'album' => t('Profile Photos'), 'photo_usage' => PHOTO_PROFILE, 'scale' => 4);
|
||||
$p = array('aid' => $aid, 'uid' => $uid, 'resource_id' => $hash, 'filename' => $filename, 'album' => t('Profile Photos'), 'photo_usage' => PHOTO_PROFILE, 'imgscale' => 4);
|
||||
|
||||
$r = $img->save($p);
|
||||
|
||||
@@ -727,7 +723,7 @@ function import_channel_photo($photo,$type,$aid,$uid) {
|
||||
$photo_failure = true;
|
||||
|
||||
$img->scaleImage(80);
|
||||
$p['scale'] = 5;
|
||||
$p['imgscale'] = 5;
|
||||
|
||||
$r = $img->save($p);
|
||||
|
||||
@@ -735,7 +731,7 @@ function import_channel_photo($photo,$type,$aid,$uid) {
|
||||
$photo_failure = true;
|
||||
|
||||
$img->scaleImage(48);
|
||||
$p['scale'] = 6;
|
||||
$p['imgscale'] = 6;
|
||||
|
||||
$r = $img->save($p);
|
||||
|
||||
|
||||
@@ -19,8 +19,6 @@ require_once('include/text.php');
|
||||
*/
|
||||
function photo_upload($channel, $observer, $args) {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
$ret = array('success' => false);
|
||||
$channel_id = $channel['channel_id'];
|
||||
$account_id = $channel['channel_account_id'];
|
||||
@@ -73,17 +71,17 @@ function photo_upload($channel, $observer, $args) {
|
||||
$type = $args['getimagesize']['mime'];
|
||||
$os_storage = 1;
|
||||
}
|
||||
elseif ($args['data']) {
|
||||
elseif ($args['data'] || $args['content']) {
|
||||
|
||||
// allow an import from a binary string representing the image.
|
||||
// This bypasses the upload step and max size limit checking
|
||||
|
||||
$imagedata = $args['data'];
|
||||
$imagedata = (($args['content']) ? $args['content'] : $args['data']);
|
||||
$filename = $args['filename'];
|
||||
$filesize = strlen($imagedata);
|
||||
// this is going to be deleted if it exists
|
||||
$src = '/tmp/deletemenow';
|
||||
$type = $args['type'];
|
||||
$type = (($args['mimetype']) ? $args['mimetype'] : $args['type']);
|
||||
} else {
|
||||
$f = array('src' => '', 'filename' => '', 'filesize' => 0, 'type' => '');
|
||||
|
||||
@@ -127,7 +125,7 @@ function photo_upload($channel, $observer, $args) {
|
||||
$imagedata = @file_get_contents($src);
|
||||
}
|
||||
|
||||
$r = q("select sum(size) as total from photo where aid = %d and scale = 0 ",
|
||||
$r = q("select sum(filesize) as total from photo where aid = %d and imgscale = 0 ",
|
||||
intval($account_id)
|
||||
);
|
||||
|
||||
@@ -174,7 +172,7 @@ function photo_upload($channel, $observer, $args) {
|
||||
$errors = false;
|
||||
|
||||
$p = array('aid' => $account_id, 'uid' => $channel_id, 'xchan' => $visitor, 'resource_id' => $photo_hash,
|
||||
'filename' => $filename, 'album' => $album, 'scale' => 0, 'photo_usage' => PHOTO_NORMAL,
|
||||
'filename' => $filename, 'album' => $album, 'imgscale' => 0, 'photo_usage' => PHOTO_NORMAL,
|
||||
'allow_cid' => $ac['allow_cid'], 'allow_gid' => $ac['allow_gid'],
|
||||
'deny_cid' => $ac['deny_cid'], 'deny_gid' => $ac['deny_gid'],
|
||||
'os_storage' => $os_storage, 'os_path' => $args['os_path']
|
||||
@@ -207,7 +205,7 @@ function photo_upload($channel, $observer, $args) {
|
||||
if(($width > 1024 || $height > 1024) && (! $errors))
|
||||
$ph->scaleImage(1024);
|
||||
|
||||
$p['scale'] = 1;
|
||||
$p['imgscale'] = 1;
|
||||
$r1 = $ph->save($p);
|
||||
$link[1] = array(
|
||||
'rel' => 'alternate',
|
||||
@@ -222,7 +220,7 @@ function photo_upload($channel, $observer, $args) {
|
||||
if(($width > 640 || $height > 640) && (! $errors))
|
||||
$ph->scaleImage(640);
|
||||
|
||||
$p['scale'] = 2;
|
||||
$p['imgscale'] = 2;
|
||||
$r2 = $ph->save($p);
|
||||
$link[2] = array(
|
||||
'rel' => 'alternate',
|
||||
@@ -237,7 +235,7 @@ function photo_upload($channel, $observer, $args) {
|
||||
if(($width > 320 || $height > 320) && (! $errors))
|
||||
$ph->scaleImage(320);
|
||||
|
||||
$p['scale'] = 3;
|
||||
$p['imgscale'] = 3;
|
||||
$r3 = $ph->save($p);
|
||||
$link[3] = array(
|
||||
'rel' => 'alternate',
|
||||
@@ -334,7 +332,7 @@ function photo_upload($channel, $observer, $args) {
|
||||
|
||||
$item['body'] = $args['body'];
|
||||
$item['obj_type'] = ACTIVITY_OBJ_PHOTO;
|
||||
$item['object'] = json_encode($object);
|
||||
$item['obj'] = json_encode($object);
|
||||
|
||||
$item['tgt_type'] = ACTIVITY_OBJ_ALBUM;
|
||||
$item['target'] = json_encode($target);
|
||||
@@ -391,8 +389,8 @@ function photo_upload($channel, $observer, $args) {
|
||||
$arr['deny_cid'] = $ac['deny_cid'];
|
||||
$arr['deny_gid'] = $ac['deny_gid'];
|
||||
$arr['verb'] = ACTIVITY_POST;
|
||||
$arr['obj_type'] = ACTIVITY_OBJ_PHOTO;
|
||||
$arr['object'] = json_encode($object);
|
||||
$arr['obj_type'] = ACTIVITY_OBJ_PHOTO;
|
||||
$arr['obj'] = json_encode($object);
|
||||
$arr['tgt_type'] = ACTIVITY_OBJ_ALBUM;
|
||||
$arr['target'] = json_encode($target);
|
||||
$arr['item_wall'] = 1;
|
||||
@@ -420,7 +418,7 @@ function photo_upload($channel, $observer, $args) {
|
||||
$item_id = $result['item_id'];
|
||||
|
||||
if($visible)
|
||||
proc_run('php', "include/notifier.php", 'wall-new', $item_id);
|
||||
Zotlabs\Daemon\Master::Summon(array('Notifier', 'wall-new', $item_id));
|
||||
}
|
||||
|
||||
$ret['success'] = true;
|
||||
@@ -445,7 +443,7 @@ function photo_upload($channel, $observer, $args) {
|
||||
* * success (bool)
|
||||
* * albums (array)
|
||||
*/
|
||||
function photos_albums_list($channel, $observer) {
|
||||
function photos_albums_list($channel, $observer, $sort_key = 'album', $direction = 'asc') {
|
||||
|
||||
$channel_id = $channel['channel_id'];
|
||||
$observer_xchan = (($observer) ? $observer['xchan_hash'] : '');
|
||||
@@ -453,11 +451,15 @@ function photos_albums_list($channel, $observer) {
|
||||
if(! perm_is_allowed($channel_id, $observer_xchan, 'view_storage'))
|
||||
return false;
|
||||
|
||||
/** @FIXME create a permissions SQL which works on arbitrary observers and channels, regardless of login or web status */
|
||||
|
||||
$sql_extra = permissions_sql($channel_id);
|
||||
$sql_extra = permissions_sql($channel_id,$observer_xchan);
|
||||
|
||||
$albums = q("SELECT count( distinct resource_id ) as total, album from photo where uid = %d and photo_usage IN ( %d, %d ) $sql_extra group by album order by max(created) desc",
|
||||
$sort_key = dbesc($sort_key);
|
||||
$direction = dbesc($direction);
|
||||
|
||||
|
||||
|
||||
$albums = q("SELECT count( distinct resource_id ) as total, album from photo where uid = %d and photo_usage IN ( %d, %d ) $sql_extra group by album order by $sort_key $direction",
|
||||
intval($channel_id),
|
||||
intval(PHOTO_NORMAL),
|
||||
intval(PHOTO_PROFILE)
|
||||
@@ -485,20 +487,14 @@ function photos_albums_list($channel, $observer) {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function photos_album_widget($channelx,$observer,$albums = null) {
|
||||
function photos_album_widget($channelx,$observer,$sortkey = 'album',$direction = 'asc') {
|
||||
|
||||
$o = '';
|
||||
|
||||
// If we weren't passed an album list, see if the photos module
|
||||
// dropped one for us to find in App::$data['albums'].
|
||||
// If all else fails, load it.
|
||||
|
||||
if(! $albums) {
|
||||
if(array_key_exists('albums', App::$data))
|
||||
$albums = App::$data['albums'];
|
||||
else
|
||||
$albums = photos_albums_list($channelx,$observer);
|
||||
}
|
||||
if(array_key_exists('albums', App::$data))
|
||||
$albums = App::$data['albums'];
|
||||
else
|
||||
$albums = photos_albums_list($channelx,$observer,$sortkey,$direction);
|
||||
|
||||
if($albums['success']) {
|
||||
$o = replace_macros(get_markup_template('photo_albums.tpl'),array(
|
||||
@@ -537,7 +533,7 @@ function photos_list_photos($channel, $observer, $album = '') {
|
||||
|
||||
$ret = array('success' => false);
|
||||
|
||||
$r = q("select resource_id, created, edited, title, description, album, filename, type, height, width, size, scale, photo_usage, allow_cid, allow_gid, deny_cid, deny_gid from photo where uid = %d and photo_usage in ( %d, %d ) $sql_extra ",
|
||||
$r = q("select resource_id, created, edited, title, description, album, filename, mimetype, height, width, filesize, imgscale, photo_usage, allow_cid, allow_gid, deny_cid, deny_gid from photo where uid = %d and photo_usage in ( %d, %d ) $sql_extra ",
|
||||
intval($channel_id),
|
||||
intval(PHOTO_NORMAL),
|
||||
intval(PHOTO_PROFILE)
|
||||
@@ -545,7 +541,7 @@ function photos_list_photos($channel, $observer, $album = '') {
|
||||
|
||||
if($r) {
|
||||
for($x = 0; $x < count($r); $x ++) {
|
||||
$r[$x]['src'] = z_root() . '/photo/' . $r[$x]['resource_id'] . '-' . $r[$x]['scale'];
|
||||
$r[$x]['src'] = z_root() . '/photo/' . $r[$x]['resource_id'] . '-' . $r[$x]['imgscale'];
|
||||
}
|
||||
$ret['success'] = true;
|
||||
$ret['photos'] = $r;
|
||||
@@ -663,7 +659,7 @@ function photos_create_item($channel, $creator_hash, $photo, $visible = false) {
|
||||
$arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $arr['mid'];
|
||||
|
||||
$arr['body'] = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo['resource_id'] . ']'
|
||||
. '[zmg]' . z_root() . '/photo/' . $photo['resource_id'] . '-' . $photo['scale'] . '[/zmg]'
|
||||
. '[zmg]' . z_root() . '/photo/' . $photo['resource_id'] . '-' . $photo['imgscale'] . '[/zmg]'
|
||||
. '[/zrl]';
|
||||
|
||||
$result = item_store($arr);
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
* @brief Some functions to handle addons and themes.
|
||||
*/
|
||||
|
||||
require_once("include/smarty.php");
|
||||
|
||||
|
||||
/**
|
||||
* @brief unloads an addon.
|
||||
@@ -43,7 +41,7 @@ function uninstall_plugin($plugin) {
|
||||
$func();
|
||||
}
|
||||
|
||||
q("DELETE FROM `addon` WHERE `name` = '%s' ",
|
||||
q("DELETE FROM `addon` WHERE `aname` = '%s' ",
|
||||
dbesc($plugin)
|
||||
);
|
||||
}
|
||||
@@ -68,7 +66,7 @@ function install_plugin($plugin) {
|
||||
|
||||
$plugin_admin = (function_exists($plugin . '_plugin_admin') ? 1 : 0);
|
||||
|
||||
q("INSERT INTO `addon` (`name`, `installed`, `timestamp`, `plugin_admin`) VALUES ( '%s', 1, %d , %d ) ",
|
||||
q("INSERT INTO `addon` (`aname`, `installed`, `tstamp`, `plugin_admin`) VALUES ( '%s', 1, %d , %d ) ",
|
||||
dbesc($plugin),
|
||||
intval($t),
|
||||
$plugin_admin
|
||||
@@ -113,7 +111,7 @@ function load_plugin($plugin) {
|
||||
}
|
||||
|
||||
function plugin_is_installed($name) {
|
||||
$r = q("select name from addon where name = '%s' and installed = 1 limit 1",
|
||||
$r = q("select aname from addon where aname = '%s' and installed = 1 limit 1",
|
||||
dbesc($name)
|
||||
);
|
||||
if($r)
|
||||
@@ -145,8 +143,8 @@ function reload_plugins() {
|
||||
if(file_exists($fname)) {
|
||||
$t = @filemtime($fname);
|
||||
foreach($installed as $i) {
|
||||
if(($i['name'] == $pl) && ($i['timestamp'] != $t)) {
|
||||
logger('Reloading plugin: ' . $i['name']);
|
||||
if(($i['aname'] == $pl) && ($i['tstamp'] != $t)) {
|
||||
logger('Reloading plugin: ' . $i['aname']);
|
||||
@include_once($fname);
|
||||
|
||||
if(function_exists($pl . '_unload')) {
|
||||
@@ -157,7 +155,7 @@ function reload_plugins() {
|
||||
$func = $pl . '_load';
|
||||
$func();
|
||||
}
|
||||
q("UPDATE `addon` SET `timestamp` = %d WHERE `id` = %d",
|
||||
q("UPDATE `addon` SET `tstamp` = %d WHERE `id` = %d",
|
||||
intval($t),
|
||||
intval($i['id'])
|
||||
);
|
||||
@@ -180,7 +178,7 @@ function reload_plugins() {
|
||||
* @return mixed|bool
|
||||
*/
|
||||
function register_hook($hook, $file, $function, $priority = 0) {
|
||||
$r = q("SELECT * FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s' LIMIT 1",
|
||||
$r = q("SELECT * FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `fn` = '%s' LIMIT 1",
|
||||
dbesc($hook),
|
||||
dbesc($file),
|
||||
dbesc($function)
|
||||
@@ -188,7 +186,7 @@ function register_hook($hook, $file, $function, $priority = 0) {
|
||||
if($r)
|
||||
return true;
|
||||
|
||||
$r = q("INSERT INTO `hook` (`hook`, `file`, `function`, `priority`) VALUES ( '%s', '%s', '%s', '%s' )",
|
||||
$r = q("INSERT INTO `hook` (`hook`, `file`, `fn`, `priority`) VALUES ( '%s', '%s', '%s', '%s' )",
|
||||
dbesc($hook),
|
||||
dbesc($file),
|
||||
dbesc($function),
|
||||
@@ -208,7 +206,7 @@ function register_hook($hook, $file, $function, $priority = 0) {
|
||||
* @return array
|
||||
*/
|
||||
function unregister_hook($hook, $file, $function) {
|
||||
$r = q("DELETE FROM hook WHERE hook = '%s' AND `file` = '%s' AND `function` = '%s'",
|
||||
$r = q("DELETE FROM hook WHERE hook = '%s' AND `file` = '%s' AND `fn` = '%s'",
|
||||
dbesc($hook),
|
||||
dbesc($file),
|
||||
dbesc($function)
|
||||
@@ -235,7 +233,7 @@ function load_hooks() {
|
||||
if(! array_key_exists($rr['hook'],App::$hooks))
|
||||
App::$hooks[$rr['hook']] = array();
|
||||
|
||||
App::$hooks[$rr['hook']][] = array($rr['file'],$rr['function'],$rr['priority'],$rr['hook_version']);
|
||||
App::$hooks[$rr['hook']][] = array($rr['file'],$rr['fn'],$rr['priority'],$rr['hook_version']);
|
||||
}
|
||||
}
|
||||
//logger('hooks: ' . print_r(App::$hooks,true));
|
||||
@@ -302,12 +300,18 @@ function call_hooks($name, &$data = null) {
|
||||
$func($data);
|
||||
else
|
||||
$func($a, $data);
|
||||
} else {
|
||||
q("DELETE FROM hook WHERE hook = '%s' AND file = '%s' AND function = '%s'",
|
||||
dbesc($name),
|
||||
dbesc($hook[0]),
|
||||
dbesc($origfn)
|
||||
);
|
||||
}
|
||||
else {
|
||||
|
||||
// Don't do any DB write calls if we're currently logging a possibly failed DB call.
|
||||
if(! DBA::$logging) {
|
||||
// The hook should be removed so we don't process it.
|
||||
q("DELETE FROM hook WHERE hook = '%s' AND file = '%s' AND fn = '%s'",
|
||||
dbesc($name),
|
||||
dbesc($hook[0]),
|
||||
dbesc($origfn)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -502,7 +506,7 @@ function get_theme_info($theme){
|
||||
* @return string
|
||||
*/
|
||||
function get_theme_screenshot($theme) {
|
||||
$a = get_app();
|
||||
|
||||
$exts = array('.png', '.jpg');
|
||||
foreach($exts as $ext) {
|
||||
if(file_exists('view/theme/' . $theme . '/img/screenshot' . $ext))
|
||||
@@ -523,7 +527,7 @@ function head_add_css($src, $media = 'screen') {
|
||||
}
|
||||
|
||||
function head_remove_css($src, $media = 'screen') {
|
||||
$a = get_app();
|
||||
|
||||
$index = array_search(array($src, $media), App::$css_sources);
|
||||
if ($index !== false)
|
||||
unset(App::$css_sources[$index]);
|
||||
@@ -594,7 +598,7 @@ function head_add_js($src) {
|
||||
}
|
||||
|
||||
function head_remove_js($src) {
|
||||
$a = get_app();
|
||||
|
||||
$index = array_search($src, App::$js_sources);
|
||||
if($index !== false)
|
||||
unset(App::$js_sources[$index]);
|
||||
@@ -635,7 +639,6 @@ function format_js_if_exists($source) {
|
||||
|
||||
|
||||
function theme_include($file, $root = '') {
|
||||
$a = get_app();
|
||||
|
||||
// Make sure $root ends with a slash / if it's not blank
|
||||
if($root !== '' && $root[strlen($root)-1] !== '/')
|
||||
@@ -648,12 +651,13 @@ function theme_include($file, $root = '') {
|
||||
else
|
||||
$parent = 'NOPATH';
|
||||
|
||||
$theme = current_theme();
|
||||
$theme = Zotlabs\Render\Theme::current();
|
||||
$thname = $theme[0];
|
||||
|
||||
$ext = substr($file,strrpos($file,'.')+1);
|
||||
|
||||
$paths = array(
|
||||
"{$root}view/theme/$theme/$ext/$file",
|
||||
"{$root}view/theme/$thname/$ext/$file",
|
||||
"{$root}view/theme/$parent/$ext/$file",
|
||||
"{$root}view/site/$ext/$file",
|
||||
"{$root}view/$ext/$file",
|
||||
@@ -672,7 +676,7 @@ function theme_include($file, $root = '') {
|
||||
|
||||
|
||||
function get_intltext_template($s, $root = '') {
|
||||
$a = get_app();
|
||||
|
||||
$t = App::template_engine();
|
||||
|
||||
$template = $t->get_intltext_template($s, $root);
|
||||
@@ -681,7 +685,7 @@ function get_intltext_template($s, $root = '') {
|
||||
|
||||
|
||||
function get_markup_template($s, $root = '') {
|
||||
$a = get_app();
|
||||
|
||||
$t = App::template_engine();
|
||||
$template = $t->get_markup_template($s, $root);
|
||||
return $template;
|
||||
|
||||
@@ -1,445 +1,15 @@
|
||||
<?php /** @file */
|
||||
|
||||
require_once('boot.php');
|
||||
require_once('include/cli_startup.php');
|
||||
|
||||
|
||||
function poller_run($argv, $argc){
|
||||
function poller_run($argc,$argv){
|
||||
|
||||
cli_startup();
|
||||
\Zotlabs\Daemon\Master::Summon(array('Cron'));
|
||||
|
||||
$a = get_app();
|
||||
|
||||
$maxsysload = intval(get_config('system','maxloadavg'));
|
||||
if($maxsysload < 1)
|
||||
$maxsysload = 50;
|
||||
if(function_exists('sys_getloadavg')) {
|
||||
$load = sys_getloadavg();
|
||||
if(intval($load[0]) > $maxsysload) {
|
||||
logger('system: load ' . $load . ' too high. Poller deferred to next scheduled run.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$interval = intval(get_config('system','poll_interval'));
|
||||
if(! $interval)
|
||||
$interval = ((get_config('system','delivery_interval') === false) ? 3 : intval(get_config('system','delivery_interval')));
|
||||
|
||||
// Check for a lockfile. If it exists, but is over an hour old, it's stale. Ignore it.
|
||||
$lockfile = 'store/[data]/poller';
|
||||
if((file_exists($lockfile)) && (filemtime($lockfile) > (time() - 3600))
|
||||
&& (! get_config('system','override_poll_lockfile'))) {
|
||||
logger("poller: Already running");
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a lockfile. Needs two vars, but $x doesn't need to contain anything.
|
||||
file_put_contents($lockfile, $x);
|
||||
|
||||
logger('poller: start');
|
||||
|
||||
// run queue delivery process in the background
|
||||
|
||||
proc_run('php',"include/queue.php");
|
||||
|
||||
|
||||
// maintenance for mod sharedwithme - check for updated items and remove them
|
||||
|
||||
require_once('include/sharedwithme.php');
|
||||
apply_updates();
|
||||
|
||||
|
||||
// expire any expired mail
|
||||
|
||||
q("delete from mail where expires != '%s' and expires < %s ",
|
||||
dbesc(NULL_DATE),
|
||||
db_utcnow()
|
||||
);
|
||||
|
||||
// expire any expired items
|
||||
|
||||
$r = q("select id from item where expires != '%s' and expires < %s
|
||||
and item_deleted = 0 ",
|
||||
dbesc(NULL_DATE),
|
||||
db_utcnow()
|
||||
);
|
||||
if($r) {
|
||||
require_once('include/items.php');
|
||||
foreach($r as $rr)
|
||||
drop_item($rr['id'],false);
|
||||
}
|
||||
|
||||
|
||||
// Ensure that every channel pings a directory server once a month. This way we can discover
|
||||
// channels and sites that quietly vanished and prevent the directory from accumulating stale
|
||||
// or dead entries.
|
||||
|
||||
$r = q("select channel_id from channel where channel_dirdate < %s - INTERVAL %s",
|
||||
db_utcnow(),
|
||||
db_quoteinterval('30 DAY')
|
||||
);
|
||||
if($r) {
|
||||
foreach($r as $rr) {
|
||||
proc_run('php','include/directory.php',$rr['channel_id'],'force');
|
||||
if($interval)
|
||||
@time_sleep_until(microtime(true) + (float) $interval);
|
||||
}
|
||||
}
|
||||
|
||||
// publish any applicable items that were set to be published in the future
|
||||
// (time travel posts). Restrict to items that have come of age in the last
|
||||
// couple of days to limit the query to something reasonable.
|
||||
|
||||
$r = q("select id from item where item_delayed = 1 and created <= %s and created > '%s' ",
|
||||
db_utcnow(),
|
||||
dbesc(datetime_convert('UTC','UTC','now - 2 days'))
|
||||
);
|
||||
if($r) {
|
||||
foreach($r as $rr) {
|
||||
$x = q("update item set item_delayed = 0 where id = %d",
|
||||
intval($rr['id'])
|
||||
);
|
||||
if($x) {
|
||||
proc_run('php','include/notifier.php','wall-new',$rr['id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$abandon_days = intval(get_config('system','account_abandon_days'));
|
||||
if($abandon_days < 1)
|
||||
$abandon_days = 0;
|
||||
|
||||
|
||||
// once daily run birthday_updates and then expire in background
|
||||
|
||||
// FIXME: add birthday updates, both locally and for xprof for use
|
||||
// by directory servers
|
||||
|
||||
$d1 = intval(get_config('system','last_expire_day'));
|
||||
$d2 = intval(datetime_convert('UTC','UTC','now','d'));
|
||||
|
||||
// Allow somebody to staggger daily activities if they have more than one site on their server,
|
||||
// or if it happens at an inconvenient (busy) hour.
|
||||
|
||||
$h1 = intval(get_config('system','cron_hour'));
|
||||
$h2 = intval(datetime_convert('UTC','UTC','now','G'));
|
||||
|
||||
$dirmode = get_config('system','directory_mode');
|
||||
|
||||
/**
|
||||
* Cron Daily
|
||||
*
|
||||
* Actions in the following block are executed once per day, not on every poller run
|
||||
*
|
||||
*/
|
||||
|
||||
if(($d2 != $d1) && ($h1 == $h2)) {
|
||||
|
||||
require_once('include/dir_fns.php');
|
||||
check_upstream_directory();
|
||||
|
||||
call_hooks('cron_daily',datetime_convert());
|
||||
|
||||
|
||||
$d3 = intval(datetime_convert('UTC','UTC','now','N'));
|
||||
if($d3 == 7) {
|
||||
|
||||
/**
|
||||
* Cron Weekly
|
||||
*
|
||||
* Actions in the following block are executed once per day only on Sunday (once per week).
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
call_hooks('cron_weekly',datetime_convert());
|
||||
|
||||
|
||||
z_check_cert();
|
||||
|
||||
require_once('include/hubloc.php');
|
||||
prune_hub_reinstalls();
|
||||
|
||||
require_once('include/Contact.php');
|
||||
mark_orphan_hubsxchans();
|
||||
|
||||
|
||||
// get rid of really old poco records
|
||||
|
||||
q("delete from xlink where xlink_updated < %s - INTERVAL %s and xlink_static = 0 ",
|
||||
db_utcnow(), db_quoteinterval('14 DAY')
|
||||
);
|
||||
|
||||
$dirmode = intval(get_config('system','directory_mode'));
|
||||
if($dirmode === DIRECTORY_MODE_SECONDARY || $dirmode === DIRECTORY_MODE_PRIMARY) {
|
||||
logger('regdir: ' . print_r(z_fetch_url(get_directory_primary() . '/regdir?f=&url=' . urlencode(z_root()) . '&realm=' . urlencode(get_directory_realm())),true));
|
||||
}
|
||||
|
||||
// Check for dead sites
|
||||
proc_run('php', 'include/checksites.php');
|
||||
|
||||
// update searchable doc indexes
|
||||
proc_run('php', 'include/importdoc.php');
|
||||
|
||||
/**
|
||||
* End Cron Weekly
|
||||
*/
|
||||
}
|
||||
|
||||
update_birthdays();
|
||||
|
||||
//update statistics in config
|
||||
require_once('include/statistics_fns.php');
|
||||
update_channels_total_stat();
|
||||
update_channels_active_halfyear_stat();
|
||||
update_channels_active_monthly_stat();
|
||||
update_local_posts_stat();
|
||||
|
||||
// expire any read notifications over a month old
|
||||
|
||||
q("delete from notify where seen = 1 and date < %s - INTERVAL %s",
|
||||
db_utcnow(), db_quoteinterval('30 DAY')
|
||||
);
|
||||
|
||||
// expire old delivery reports
|
||||
|
||||
$keep_reports = intval(get_config('system','expire_delivery_reports'));
|
||||
if($keep_reports === 0)
|
||||
$keep_reports = 10;
|
||||
|
||||
q("delete from dreport where dreport_time < %s - INTERVAL %s",
|
||||
db_utcnow(),
|
||||
db_quoteinterval($keep_reports . ' DAY')
|
||||
);
|
||||
|
||||
// expire any expired accounts
|
||||
downgrade_accounts();
|
||||
|
||||
// If this is a directory server, request a sync with an upstream
|
||||
// directory at least once a day, up to once every poll interval.
|
||||
// Pull remote changes and push local changes.
|
||||
// potential issue: how do we keep from creating an endless update loop?
|
||||
|
||||
if($dirmode == DIRECTORY_MODE_SECONDARY || $dirmode == DIRECTORY_MODE_PRIMARY) {
|
||||
require_once('include/dir_fns.php');
|
||||
sync_directories($dirmode);
|
||||
}
|
||||
|
||||
set_config('system','last_expire_day',$d2);
|
||||
|
||||
proc_run('php','include/expire.php');
|
||||
proc_run('php','include/cli_suggest.php');
|
||||
|
||||
require_once('include/hubloc.php');
|
||||
remove_obsolete_hublocs();
|
||||
|
||||
/**
|
||||
* End Cron Daily
|
||||
*/
|
||||
}
|
||||
|
||||
// update any photos which didn't get imported properly
|
||||
// This should be rare
|
||||
|
||||
$r = q("select xchan_photo_l, xchan_hash from xchan where xchan_photo_l != '' and xchan_photo_m = ''
|
||||
and xchan_photo_date < %s - INTERVAL %s",
|
||||
db_utcnow(),
|
||||
db_quoteinterval('1 DAY')
|
||||
);
|
||||
if($r) {
|
||||
require_once('include/photo/photo_driver.php');
|
||||
foreach($r as $rr) {
|
||||
$photos = import_xchan_photo($rr['xchan_photo_l'],$rr['xchan_hash']);
|
||||
$x = q("update xchan set xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s'
|
||||
where xchan_hash = '%s'",
|
||||
dbesc($photos[0]),
|
||||
dbesc($photos[1]),
|
||||
dbesc($photos[2]),
|
||||
dbesc($photos[3]),
|
||||
dbesc($rr['xchan_hash'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// pull in some public posts
|
||||
|
||||
if(! get_config('system','disable_discover_tab'))
|
||||
proc_run('php','include/externals.php');
|
||||
|
||||
|
||||
$manual_id = 0;
|
||||
$generation = 0;
|
||||
|
||||
$force = false;
|
||||
$restart = false;
|
||||
|
||||
if(($argc > 1) && ($argv[1] == 'force'))
|
||||
$force = true;
|
||||
|
||||
if(($argc > 1) && ($argv[1] == 'restart')) {
|
||||
$restart = true;
|
||||
$generation = intval($argv[2]);
|
||||
if(! $generation)
|
||||
killme();
|
||||
}
|
||||
|
||||
if(($argc > 1) && intval($argv[1])) {
|
||||
$manual_id = intval($argv[1]);
|
||||
$force = true;
|
||||
}
|
||||
|
||||
|
||||
$sql_extra = (($manual_id) ? " AND abook_id = " . intval($manual_id) . " " : "");
|
||||
|
||||
reload_plugins();
|
||||
|
||||
$d = datetime_convert();
|
||||
|
||||
// TODO check to see if there are any cronhooks before wasting a process
|
||||
|
||||
if(! $restart)
|
||||
proc_run('php','include/cronhooks.php');
|
||||
|
||||
// Only poll from those with suitable relationships
|
||||
|
||||
$abandon_sql = (($abandon_days)
|
||||
? sprintf(" AND account_lastlog > %s - INTERVAL %s ", db_utcnow(), db_quoteinterval(intval($abandon_days).' DAY'))
|
||||
: ''
|
||||
);
|
||||
|
||||
$randfunc = db_getfunc('RAND');
|
||||
|
||||
$contacts = q("SELECT * FROM abook LEFT JOIN xchan on abook_xchan = xchan_hash
|
||||
LEFT JOIN account on abook_account = account_id
|
||||
where abook_self = 0
|
||||
$sql_extra
|
||||
AND (( account_flags = %d ) OR ( account_flags = %d )) $abandon_sql ORDER BY $randfunc",
|
||||
intval(ACCOUNT_OK),
|
||||
intval(ACCOUNT_UNVERIFIED) // FIXME
|
||||
|
||||
);
|
||||
|
||||
if($contacts) {
|
||||
|
||||
foreach($contacts as $contact) {
|
||||
|
||||
$update = false;
|
||||
|
||||
$t = $contact['abook_updated'];
|
||||
$c = $contact['abook_connected'];
|
||||
|
||||
if(intval($contact['abook_feed'])) {
|
||||
$min = service_class_fetch($contact['abook_channel'],'minimum_feedcheck_minutes');
|
||||
if(! $min)
|
||||
$min = intval(get_config('system','minimum_feedcheck_minutes'));
|
||||
if(! $min)
|
||||
$min = 60;
|
||||
$x = datetime_convert('UTC','UTC',"now - $min minutes");
|
||||
if($c < $x) {
|
||||
proc_run('php','include/onepoll.php',$contact['abook_id']);
|
||||
if($interval)
|
||||
@time_sleep_until(microtime(true) + (float) $interval);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if($contact['xchan_network'] !== 'zot')
|
||||
continue;
|
||||
|
||||
if($c == $t) {
|
||||
if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 day"))
|
||||
$update = true;
|
||||
}
|
||||
else {
|
||||
|
||||
// if we've never connected with them, start the mark for death countdown from now
|
||||
|
||||
if($c == NULL_DATE) {
|
||||
$r = q("update abook set abook_connected = '%s' where abook_id = %d",
|
||||
dbesc(datetime_convert()),
|
||||
intval($contact['abook_id'])
|
||||
);
|
||||
$c = datetime_convert();
|
||||
$update = true;
|
||||
}
|
||||
|
||||
// He's dead, Jim
|
||||
|
||||
if(strcmp(datetime_convert('UTC','UTC', 'now'),datetime_convert('UTC','UTC', $c . " + 30 day")) > 0) {
|
||||
$r = q("update abook set abook_archived = 1 where abook_id = %d",
|
||||
intval($contact['abook_id'])
|
||||
);
|
||||
$update = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(intval($contact['abook_archived'])) {
|
||||
$update = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
// might be dead, so maybe don't poll quite so often
|
||||
|
||||
// recently deceased, so keep up the regular schedule for 3 days
|
||||
|
||||
if((strcmp(datetime_convert('UTC','UTC', 'now'),datetime_convert('UTC','UTC', $c . " + 3 day")) > 0)
|
||||
&& (strcmp(datetime_convert('UTC','UTC', 'now'),datetime_convert('UTC','UTC', $t . " + 1 day")) > 0))
|
||||
$update = true;
|
||||
|
||||
// After that back off and put them on a morphine drip
|
||||
|
||||
if(strcmp(datetime_convert('UTC','UTC', 'now'),datetime_convert('UTC','UTC', $t . " + 2 day")) > 0) {
|
||||
$update = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(intval($contact['abook_pending']) || intval($contact['abook_archived']) || intval($contact['abook_ignored']) || intval($contact['abook_blocked']))
|
||||
continue;
|
||||
|
||||
if((! $update) && (! $force))
|
||||
continue;
|
||||
|
||||
proc_run('php','include/onepoll.php',$contact['abook_id']);
|
||||
if($interval)
|
||||
@time_sleep_until(microtime(true) + (float) $interval);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if($dirmode == DIRECTORY_MODE_SECONDARY || $dirmode == DIRECTORY_MODE_PRIMARY) {
|
||||
$r = q("SELECT u.ud_addr, u.ud_id, u.ud_last FROM updates AS u INNER JOIN (SELECT ud_addr, max(ud_id) AS ud_id FROM updates WHERE ( ud_flags & %d ) = 0 AND ud_addr != '' AND ( ud_last = '%s' OR ud_last > %s - INTERVAL %s ) GROUP BY ud_addr) AS s ON s.ud_id = u.ud_id ",
|
||||
intval(UPDATE_FLAGS_UPDATED),
|
||||
dbesc(NULL_DATE),
|
||||
db_utcnow(), db_quoteinterval('7 DAY')
|
||||
);
|
||||
if($r) {
|
||||
foreach($r as $rr) {
|
||||
|
||||
// If they didn't respond when we attempted before, back off to once a day
|
||||
// After 7 days we won't bother anymore
|
||||
|
||||
if($rr['ud_last'] != NULL_DATE)
|
||||
if($rr['ud_last'] > datetime_convert('UTC','UTC', 'now - 1 day'))
|
||||
continue;
|
||||
proc_run('php','include/onedirsync.php',$rr['ud_id']);
|
||||
if($interval)
|
||||
@time_sleep_until(microtime(true) + (float) $interval);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
set_config('system','lastpoll',datetime_convert());
|
||||
|
||||
//All done - clear the lockfile
|
||||
@unlink($lockfile);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
poller_run($argv,$argc);
|
||||
poller_run($argc,$argv);
|
||||
killme();
|
||||
}
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
<?php /** @file */
|
||||
require_once("boot.php");
|
||||
require_once('include/cli_startup.php');
|
||||
require_once('include/queue_fn.php');
|
||||
require_once('include/zot.php');
|
||||
|
||||
function queue_run($argv, $argc){
|
||||
|
||||
cli_startup();
|
||||
|
||||
global $a;
|
||||
|
||||
require_once('include/items.php');
|
||||
require_once('include/bbcode.php');
|
||||
|
||||
if(argc() > 1)
|
||||
$queue_id = argv(1);
|
||||
else
|
||||
$queue_id = 0;
|
||||
|
||||
logger('queue: start');
|
||||
|
||||
// delete all queue items more than 3 days old
|
||||
// but first mark these sites dead if we haven't heard from them in a month
|
||||
|
||||
$r = q("select outq_posturl from outq where outq_created < %s - INTERVAL %s",
|
||||
db_utcnow(), db_quoteinterval('3 DAY')
|
||||
);
|
||||
if($r) {
|
||||
foreach($r as $rr) {
|
||||
$site_url = '';
|
||||
$h = parse_url($rr['outq_posturl']);
|
||||
$desturl = $h['scheme'] . '://' . $h['host'] . (($h['port']) ? ':' . $h['port'] : '');
|
||||
q("update site set site_dead = 1 where site_dead = 0 and site_url = '%s' and site_update < %s - INTERVAL %s",
|
||||
dbesc($desturl),
|
||||
db_utcnow(), db_quoteinterval('1 MONTH')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$r = q("DELETE FROM outq WHERE outq_created < %s - INTERVAL %s",
|
||||
db_utcnow(), db_quoteinterval('3 DAY')
|
||||
);
|
||||
|
||||
if($queue_id) {
|
||||
$r = q("SELECT * FROM outq WHERE outq_hash = '%s' LIMIT 1",
|
||||
dbesc($queue_id)
|
||||
);
|
||||
}
|
||||
else {
|
||||
|
||||
// For the first 12 hours we'll try to deliver every 15 minutes
|
||||
// After that, we'll only attempt delivery once per hour.
|
||||
// This currently only handles the default queue drivers ('zot' or '') which we will group by posturl
|
||||
// so that we don't start off a thousand deliveries for a couple of dead hubs.
|
||||
// The zot driver will deliver everything destined for a single hub once contact is made (*if* contact is made).
|
||||
// Other drivers will have to do something different here and may need their own query.
|
||||
|
||||
// Note: this requires some tweaking as new posts to long dead hubs once a day will keep them in the
|
||||
// "every 15 minutes" category. We probably need to prioritise them when inserted into the queue
|
||||
// or just prior to this query based on recent and long-term delivery history. If we have good reason to believe
|
||||
// the site is permanently down, there's no reason to attempt delivery at all, or at most not more than once
|
||||
// or twice a day.
|
||||
|
||||
// FIXME: can we sort postgres on outq_priority and maintain the 'distinct' ?
|
||||
// The order by max(outq_priority) might be a dodgy query because of the group by.
|
||||
// The desired result is to return a sequence in the order most likely to be delivered in this run.
|
||||
// If a hub has already been sitting in the queue for a few days, they should be delivered last;
|
||||
// hence every failure should drop them further down the priority list.
|
||||
|
||||
if(ACTIVE_DBTYPE == DBTYPE_POSTGRES) {
|
||||
$prefix = 'DISTINCT ON (outq_posturl)';
|
||||
$suffix = 'ORDER BY outq_posturl';
|
||||
} else {
|
||||
$prefix = '';
|
||||
$suffix = 'GROUP BY outq_posturl ORDER BY max(outq_priority)';
|
||||
}
|
||||
$r = q("SELECT $prefix * FROM outq WHERE outq_delivered = 0 and (( outq_created > %s - INTERVAL %s and outq_updated < %s - INTERVAL %s ) OR ( outq_updated < %s - INTERVAL %s )) $suffix",
|
||||
db_utcnow(), db_quoteinterval('12 HOUR'),
|
||||
db_utcnow(), db_quoteinterval('15 MINUTE'),
|
||||
db_utcnow(), db_quoteinterval('1 HOUR')
|
||||
);
|
||||
}
|
||||
if(! $r)
|
||||
return;
|
||||
|
||||
foreach($r as $rr) {
|
||||
queue_deliver($rr);
|
||||
}
|
||||
}
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
queue_run($argv,$argc);
|
||||
killme();
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once('include/cli_startup.php');
|
||||
require_once('include/zot.php');
|
||||
require_once('include/queue_fn.php');
|
||||
|
||||
|
||||
function ratenotif_run($argv, $argc){
|
||||
|
||||
cli_startup();
|
||||
|
||||
$a = get_app();
|
||||
|
||||
require_once("datetime.php");
|
||||
require_once('include/items.php');
|
||||
require_once('include/Contact.php');
|
||||
|
||||
if($argc < 3)
|
||||
return;
|
||||
|
||||
|
||||
logger('ratenotif: invoked: ' . print_r($argv,true), LOGGER_DEBUG);
|
||||
|
||||
$cmd = $argv[1];
|
||||
|
||||
$item_id = $argv[2];
|
||||
|
||||
|
||||
if($cmd === 'rating') {
|
||||
$r = q("select * from xlink where xlink_id = %d and xlink_static = 1 limit 1",
|
||||
intval($item_id)
|
||||
);
|
||||
if(! $r) {
|
||||
logger('rating not found');
|
||||
return;
|
||||
}
|
||||
|
||||
$encoded_item = array(
|
||||
'type' => 'rating',
|
||||
'encoding' => 'zot',
|
||||
'target' => $r[0]['xlink_link'],
|
||||
'rating' => intval($r[0]['xlink_rating']),
|
||||
'rating_text' => $r[0]['xlink_rating_text'],
|
||||
'signature' => $r[0]['xlink_sig'],
|
||||
'edited' => $r[0]['xlink_updated']
|
||||
);
|
||||
}
|
||||
|
||||
$channel = channelx_by_hash($r[0]['xlink_xchan']);
|
||||
if(! $channel) {
|
||||
logger('no channel');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$primary = get_directory_primary();
|
||||
|
||||
if(! $primary)
|
||||
return;
|
||||
|
||||
|
||||
$interval = ((get_config('system','delivery_interval') !== false)
|
||||
? intval(get_config('system','delivery_interval')) : 2 );
|
||||
|
||||
$deliveries_per_process = intval(get_config('system','delivery_batch_count'));
|
||||
|
||||
if($deliveries_per_process <= 0)
|
||||
$deliveries_per_process = 1;
|
||||
|
||||
$deliver = array();
|
||||
|
||||
$x = z_fetch_url($primary . '/regdir');
|
||||
if($x['success']) {
|
||||
$j = json_decode($x['body'],true);
|
||||
if($j && $j['success'] && is_array($j['directories'])) {
|
||||
|
||||
foreach($j['directories'] as $h) {
|
||||
if($h == z_root())
|
||||
continue;
|
||||
|
||||
$hash = random_string();
|
||||
$n = zot_build_packet($channel,'notify',null,null,$hash);
|
||||
|
||||
queue_insert(array(
|
||||
'hash' => $hash,
|
||||
'account_id' => $channel['channel_account_id'],
|
||||
'channel_id' => $channel['channel_id'],
|
||||
'posturl' => $h . '/post',
|
||||
'notify' => $n,
|
||||
'msg' => json_encode($encoded_item)
|
||||
));
|
||||
|
||||
$deliver[] = $hash;
|
||||
|
||||
if(count($deliver) >= $deliveries_per_process) {
|
||||
proc_run('php','include/deliver.php',$deliver);
|
||||
$deliver = array();
|
||||
if($interval)
|
||||
@time_sleep_until(microtime(true) + (float) $interval);
|
||||
}
|
||||
}
|
||||
|
||||
// catch any stragglers
|
||||
|
||||
if(count($deliver)) {
|
||||
proc_run('php','include/deliver.php',$deliver);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger('ratenotif: complete.');
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
ratenotif_run($argv,$argc);
|
||||
killme();
|
||||
}
|
||||
@@ -1,6 +1,49 @@
|
||||
<?php /** @file */
|
||||
|
||||
|
||||
function contact_profile_assign($current) {
|
||||
|
||||
$o = '';
|
||||
|
||||
$o .= "<select id=\"contact-profile-selector\" name=\"profile_assign\" class=\"form-control\"/>\r\n";
|
||||
|
||||
$r = q("SELECT profile_guid, profile_name FROM `profile` WHERE `uid` = %d",
|
||||
intval($_SESSION['uid']));
|
||||
|
||||
if($r) {
|
||||
foreach($r as $rr) {
|
||||
$selected = (($rr['profile_guid'] == $current) ? " selected=\"selected\" " : "");
|
||||
$o .= "<option value=\"{$rr['profile_guid']}\" $selected >{$rr['profile_name']}</option>\r\n";
|
||||
}
|
||||
}
|
||||
$o .= "</select>\r\n";
|
||||
return $o;
|
||||
}
|
||||
|
||||
function contact_poll_interval($current, $disabled = false) {
|
||||
|
||||
$dis = (($disabled) ? ' disabled="disabled" ' : '');
|
||||
$o = '';
|
||||
$o .= "<select id=\"contact-poll-interval\" name=\"poll\" $dis />" . "\r\n";
|
||||
|
||||
$rep = array(
|
||||
0 => t('Frequently'),
|
||||
1 => t('Hourly'),
|
||||
2 => t('Twice daily'),
|
||||
3 => t('Daily'),
|
||||
4 => t('Weekly'),
|
||||
5 => t('Monthly')
|
||||
);
|
||||
|
||||
foreach($rep as $k => $v) {
|
||||
$selected = (($k == $current) ? " selected=\"selected\" " : "");
|
||||
$o .= "<option value=\"$k\" $selected >$v</option>\r\n";
|
||||
}
|
||||
$o .= "</select>\r\n";
|
||||
return $o;
|
||||
}
|
||||
|
||||
|
||||
function gender_selector($current="",$suffix="") {
|
||||
$o = '';
|
||||
$select = array('', t('Male'), t('Female'), t('Currently Male'), t('Currently Female'), t('Mostly Male'), t('Mostly Female'), t('Transgender'), t('Intersex'), t('Transsexual'), t('Hermaphrodite'), t('Neuter'), t('Non-specific'), t('Other'), t('Undecided'));
|
||||
@@ -108,3 +151,4 @@ function marital_selector_min($current="",$suffix="") {
|
||||
$o .= '</select>';
|
||||
return $o;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
function apply_updates() {
|
||||
|
||||
//check for updated items and remove them
|
||||
$x = q("SELECT mid, max(object) AS object FROM item WHERE verb = '%s' AND obj_type = '%s' GROUP BY mid",
|
||||
$x = q("SELECT mid, max(obj) AS obj FROM item WHERE verb = '%s' AND obj_type = '%s' GROUP BY mid",
|
||||
dbesc(ACTIVITY_UPDATE),
|
||||
dbesc(ACTIVITY_OBJ_FILE)
|
||||
);
|
||||
@@ -12,7 +12,7 @@ function apply_updates() {
|
||||
|
||||
foreach($x as $xx) {
|
||||
|
||||
$object = json_decode($xx['object'],true);
|
||||
$object = json_decode($xx['obj'],true);
|
||||
|
||||
$d_mid = $object['d_mid'];
|
||||
$u_mid = $xx['mid'];
|
||||
|
||||
@@ -1,114 +0,0 @@
|
||||
<?php /** @file */
|
||||
require_once 'include/ITemplateEngine.php';
|
||||
require_once("library/Smarty/libs/Smarty.class.php");
|
||||
|
||||
|
||||
class FriendicaSmarty extends Smarty {
|
||||
|
||||
public $filename;
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
$a = get_app();
|
||||
$theme = current_theme();
|
||||
|
||||
// setTemplateDir can be set to an array, which Smarty will parse in order.
|
||||
// The order is thus very important here
|
||||
$template_dirs = array('theme' => "view/theme/$theme/tpl/");
|
||||
if( x(App::$theme_info,"extends") )
|
||||
$template_dirs = $template_dirs + array('extends' => "view/theme/".App::$theme_info["extends"]."/tpl/");
|
||||
$template_dirs = $template_dirs + array('base' => 'view/tpl/');
|
||||
$this->setTemplateDir($template_dirs);
|
||||
|
||||
$basecompiledir = App::$config['system']['smarty3_folder'];
|
||||
|
||||
$this->setCompileDir($basecompiledir.'/compiled/');
|
||||
$this->setConfigDir($basecompiledir.'/config/');
|
||||
$this->setCacheDir($basecompiledir.'/cache/');
|
||||
|
||||
$this->left_delimiter = App::get_template_ldelim('smarty3');
|
||||
$this->right_delimiter = App::get_template_rdelim('smarty3');
|
||||
|
||||
// Don't report errors so verbosely
|
||||
$this->error_reporting = E_ALL & ~E_NOTICE;
|
||||
}
|
||||
|
||||
function parsed($template = '') {
|
||||
if($template) {
|
||||
return $this->fetch('string:' . $template);
|
||||
}
|
||||
return $this->fetch('file:' . $this->filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
class FriendicaSmartyEngine implements ITemplateEngine {
|
||||
static $name ="smarty3";
|
||||
|
||||
public function __construct(){
|
||||
$a = get_app();
|
||||
|
||||
// Cannot use get_config() here because it is called during installation when there is no DB.
|
||||
// FIXME: this may leak private information such as system pathnames.
|
||||
|
||||
$basecompiledir = ((array_key_exists('smarty3_folder',App::$config['system'])) ? App::$config['system']['smarty3_folder'] : '');
|
||||
if (!$basecompiledir) $basecompiledir = dirname(__dir__) . "/" . TEMPLATE_BUILD_PATH;
|
||||
if (!is_dir($basecompiledir)) {
|
||||
echo "<b>ERROR:</b> folder <tt>$basecompiledir</tt> does not exist."; killme();
|
||||
}
|
||||
if(!is_writable($basecompiledir)){
|
||||
echo "<b>ERROR:</b> folder <tt>$basecompiledir</tt> must be writable by webserver."; killme();
|
||||
}
|
||||
App::$config['system']['smarty3_folder'] = $basecompiledir;
|
||||
}
|
||||
|
||||
// ITemplateEngine interface
|
||||
public function replace_macros($s, $r) {
|
||||
$template = '';
|
||||
if(gettype($s) === 'string') {
|
||||
$template = $s;
|
||||
$s = new FriendicaSmarty();
|
||||
}
|
||||
foreach($r as $key=>$value) {
|
||||
if($key[0] === '$') {
|
||||
$key = substr($key, 1);
|
||||
}
|
||||
$s->assign($key, $value);
|
||||
}
|
||||
return $s->parsed($template);
|
||||
}
|
||||
|
||||
public function get_markup_template($file, $root=''){
|
||||
$template_file = theme_include($file, $root);
|
||||
if($template_file) {
|
||||
$template = new FriendicaSmarty();
|
||||
$template->filename = $template_file;
|
||||
|
||||
return $template;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public function get_intltext_template($file, $root='') {
|
||||
$a = get_app();
|
||||
|
||||
if(file_exists("view/{App::$language}/$file"))
|
||||
$template_file = "view/{App::$language}/$file";
|
||||
elseif(file_exists("view/en/$file"))
|
||||
$template_file = "view/en/$file";
|
||||
else
|
||||
$template_file = theme_include($file,$root);
|
||||
if($template_file) {
|
||||
$template = new FriendicaSmarty();
|
||||
$template->filename = $template_file;
|
||||
|
||||
return $template;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -152,11 +152,9 @@ function poco_load($xchan = '', $url = null) {
|
||||
if(($x !== false) && (! count($x))) {
|
||||
if($address) {
|
||||
if($network === 'zot') {
|
||||
$z = zot_finger($address,null);
|
||||
if($z['success']) {
|
||||
$j = json_decode($z['body'],true);
|
||||
if($j)
|
||||
import_xchan($j);
|
||||
$j = Zotlabs\Zot\Finger::run($address,null);
|
||||
if($j['success']) {
|
||||
import_xchan($j);
|
||||
}
|
||||
$x = q("select xchan_hash from xchan where xchan_hash = '%s' limit 1",
|
||||
dbesc($hash)
|
||||
@@ -404,7 +402,7 @@ function poco($a,$extended = false) {
|
||||
|
||||
$system_mode = false;
|
||||
|
||||
if(intval(get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) {
|
||||
if(observer_prohibited()) {
|
||||
logger('mod_poco: block_public');
|
||||
http_status_exit(401);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ function file_tag_file_query($table,$s,$type = 'file') {
|
||||
else
|
||||
$termtype = TERM_CATEGORY;
|
||||
|
||||
return sprintf(" AND " . (($table) ? dbesc($table) . '.' : '') . "id in (select term.oid from term where term.type = %d and term.term = '%s' and term.uid = " . (($table) ? dbesc($table) . '.' : '') . "uid ) ",
|
||||
return sprintf(" AND " . (($table) ? dbesc($table) . '.' : '') . "id in (select term.oid from term where term.ttype = %d and term.term = '%s' and term.uid = " . (($table) ? dbesc($table) . '.' : '') . "uid ) ",
|
||||
intval($termtype),
|
||||
protect_sprintf(dbesc($s))
|
||||
);
|
||||
@@ -29,14 +29,14 @@ function file_tag_file_query($table,$s,$type = 'file') {
|
||||
function term_query($table,$s,$type = TERM_UNKNOWN, $type2 = '') {
|
||||
|
||||
if($type2) {
|
||||
return sprintf(" AND " . (($table) ? dbesc($table) . '.' : '') . "id in (select term.oid from term where term.type in (%d, %d) and term.term = '%s' and term.uid = " . (($table) ? dbesc($table) . '.' : '') . "uid ) ",
|
||||
return sprintf(" AND " . (($table) ? dbesc($table) . '.' : '') . "id in (select term.oid from term where term.ttype in (%d, %d) and term.term = '%s' and term.uid = " . (($table) ? dbesc($table) . '.' : '') . "uid ) ",
|
||||
intval($type),
|
||||
intval($type2),
|
||||
protect_sprintf(dbesc($s))
|
||||
);
|
||||
}
|
||||
else {
|
||||
return sprintf(" AND " . (($table) ? dbesc($table) . '.' : '') . "id in (select term.oid from term where term.type = %d and term.term = '%s' and term.uid = " . (($table) ? dbesc($table) . '.' : '') . "uid ) ",
|
||||
return sprintf(" AND " . (($table) ? dbesc($table) . '.' : '') . "id in (select term.oid from term where term.ttype = %d and term.term = '%s' and term.uid = " . (($table) ? dbesc($table) . '.' : '') . "uid ) ",
|
||||
intval($type),
|
||||
protect_sprintf(dbesc($s))
|
||||
);
|
||||
@@ -49,7 +49,7 @@ function store_item_tag($uid,$iid,$otype,$type,$term,$url = '') {
|
||||
return false;
|
||||
|
||||
$r = q("select * from term
|
||||
where uid = %d and oid = %d and otype = %d and type = %d
|
||||
where uid = %d and oid = %d and otype = %d and ttype = %d
|
||||
and term = '%s' and url = '%s' ",
|
||||
intval($uid),
|
||||
intval($iid),
|
||||
@@ -61,7 +61,7 @@ function store_item_tag($uid,$iid,$otype,$type,$term,$url = '') {
|
||||
if($r)
|
||||
return false;
|
||||
|
||||
$r = q("insert into term (uid, oid, otype, type, term, url)
|
||||
$r = q("insert into term (uid, oid, otype, ttype, term, url)
|
||||
values( %d, %d, %d, %d, '%s', '%s') ",
|
||||
intval($uid),
|
||||
intval($iid),
|
||||
@@ -85,7 +85,7 @@ function get_terms_oftype($arr,$type) {
|
||||
|
||||
foreach($type as $t)
|
||||
foreach($arr as $x)
|
||||
if($x['type'] == $t)
|
||||
if($x['ttype'] == $t)
|
||||
$ret[] = $x;
|
||||
|
||||
return $ret;
|
||||
@@ -93,9 +93,9 @@ function get_terms_oftype($arr,$type) {
|
||||
|
||||
function format_term_for_display($term) {
|
||||
$s = '';
|
||||
if(($term['type'] == TERM_HASHTAG) || ($term['type'] == TERM_COMMUNITYTAG))
|
||||
if(($term['ttype'] == TERM_HASHTAG) || ($term['ttype'] == TERM_COMMUNITYTAG))
|
||||
$s .= '#';
|
||||
elseif($term['type'] == TERM_MENTION)
|
||||
elseif($term['ttype'] == TERM_MENTION)
|
||||
$s .= '@';
|
||||
else
|
||||
return $s;
|
||||
@@ -142,7 +142,7 @@ function tagadelic($uid, $count = 0, $authors = '', $owner = '', $flags = 0, $re
|
||||
|
||||
// Fetch tags
|
||||
$r = q("select term, count(term) as total from term left join item on term.oid = item.id
|
||||
where term.uid = %d and term.type = %d
|
||||
where term.uid = %d and term.ttype = %d
|
||||
and otype = %d and item_type = %d and item_private = 0
|
||||
$sql_options $item_normal
|
||||
group by term order by total desc %s",
|
||||
|
||||
@@ -1,307 +0,0 @@
|
||||
<?php
|
||||
require_once 'include/ITemplateEngine.php';
|
||||
|
||||
define ("KEY_NOT_EXISTS", '^R_key_not_Exists^');
|
||||
|
||||
class Template implements ITemplateEngine {
|
||||
static $name ="internal";
|
||||
|
||||
var $r;
|
||||
var $search;
|
||||
var $replace;
|
||||
var $stack = array();
|
||||
var $nodes = array();
|
||||
var $done = false;
|
||||
var $d = false;
|
||||
var $lang = null;
|
||||
var $debug=false;
|
||||
|
||||
private function _preg_error() {
|
||||
switch(preg_last_error()) {
|
||||
case PREG_INTERNAL_ERROR: echo('PREG_INTERNAL_ERROR'); break;
|
||||
case PREG_BACKTRACK_LIMIT_ERROR: echo('PREG_BACKTRACK_LIMIT_ERROR'); break;
|
||||
case PREG_RECURSION_LIMIT_ERROR: echo('PREG_RECURSION_LIMIT_ERROR'); break;
|
||||
case PREG_BAD_UTF8_ERROR: echo('PREG_BAD_UTF8_ERROR'); break;
|
||||
// This is only valid for php > 5.3, not certain how to code around it for unit tests
|
||||
// case PREG_BAD_UTF8_OFFSET_ERROR: echo('PREG_BAD_UTF8_OFFSET_ERROR'); break;
|
||||
default:
|
||||
//die("Unknown preg error.");
|
||||
return;
|
||||
}
|
||||
echo "<hr><pre>";
|
||||
debug_print_backtrace();
|
||||
die();
|
||||
}
|
||||
|
||||
private function _push_stack() {
|
||||
$this->stack[] = array($this->r, $this->nodes);
|
||||
}
|
||||
|
||||
private function _pop_stack(){
|
||||
list($this->r, $this->nodes) = array_pop($this->stack);
|
||||
}
|
||||
|
||||
private function _get_var($name, $retNoKey=false) {
|
||||
$keys = array_map('trim',explode(".",$name));
|
||||
if ($retNoKey && !array_key_exists($keys[0], $this->r))
|
||||
return KEY_NOT_EXISTS;
|
||||
|
||||
$val = $this->r;
|
||||
foreach($keys as $k) {
|
||||
$val = (isset($val[$k]) ? $val[$k] : null);
|
||||
}
|
||||
|
||||
return template_escape($val);
|
||||
}
|
||||
|
||||
/**
|
||||
* IF node
|
||||
* \code
|
||||
* {{ if <$var> }}...[{{ else }} ...] {{ endif }}
|
||||
* {{ if <$var>==<val|$var> }}...[{{ else }} ...]{{ endif }}
|
||||
* {{ if <$var>!=<val|$var> }}...[{{ else }} ...]{{ endif }}
|
||||
* \endcode
|
||||
*/
|
||||
private function _replcb_if($args) {
|
||||
if (strpos($args[2],"==")>0){
|
||||
list($a,$b) = array_map("trim",explode("==",$args[2]));
|
||||
$a = $this->_get_var($a);
|
||||
if ($b[0]=="$") $b = $this->_get_var($b);
|
||||
$val = ($a == $b);
|
||||
} else if (strpos($args[2],"!=")>0){
|
||||
list($a,$b) = array_map("trim", explode("!=",$args[2]));
|
||||
$a = $this->_get_var($a);
|
||||
if ($b[0]=="$") $b = $this->_get_var($b);
|
||||
$val = ($a != $b);
|
||||
} else {
|
||||
$val = $this->_get_var($args[2]);
|
||||
}
|
||||
$x = preg_split("|{{ *else *}}|", $args[3]);
|
||||
|
||||
return ( ($val) ? $x[0] : (isset($x[1]) ? $x[1] : ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* FOR node
|
||||
* \code
|
||||
* {{ for <$var> as $name }}...{{ endfor }}
|
||||
* {{ for <$var> as $key=>$name }}...{{ endfor }}
|
||||
* \endcode
|
||||
*/
|
||||
private function _replcb_for($args) {
|
||||
$m = array_map('trim', explode(" as ", $args[2]));
|
||||
$x = explode("=>",$m[1]);
|
||||
if (count($x) == 1) {
|
||||
$varname = $x[0];
|
||||
$keyname = "";
|
||||
} else {
|
||||
list($keyname, $varname) = $x;
|
||||
}
|
||||
if ($m[0]=="" || $varname=="" || is_null($varname)) die("template error: 'for ".$m[0]." as ".$varname."'") ;
|
||||
//$vals = $this->r[$m[0]];
|
||||
$vals = $this->_get_var($m[0]);
|
||||
$ret="";
|
||||
if (!is_array($vals)) return $ret;
|
||||
|
||||
foreach ($vals as $k=>$v){
|
||||
$this->_push_stack();
|
||||
$r = $this->r;
|
||||
$r[$varname] = $v;
|
||||
if ($keyname!='') $r[$keyname] = (($k === 0) ? '0' : $k);
|
||||
$ret .= $this->replace($args[3], $r);
|
||||
$this->_pop_stack();
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* INC node
|
||||
* \code
|
||||
* {{ inc <templatefile> [with $var1=$var2] }}{{ endinc }}
|
||||
* \endcode
|
||||
*/
|
||||
private function _replcb_inc($args) {
|
||||
if (strpos($args[2],"with")) {
|
||||
list($tplfile, $newctx) = array_map('trim', explode("with",$args[2]));
|
||||
} else {
|
||||
$tplfile = trim($args[2]);
|
||||
$newctx = null;
|
||||
}
|
||||
|
||||
if ($tplfile[0]=="$") $tplfile = $this->_get_var($tplfile);
|
||||
|
||||
$this->_push_stack();
|
||||
$r = $this->r;
|
||||
if (!is_null($newctx)) {
|
||||
list($a,$b) = array_map('trim', explode("=",$newctx));
|
||||
$r[$a] = $this->_get_var($b);
|
||||
}
|
||||
$this->nodes = Array();
|
||||
$tpl = get_markup_template($tplfile);
|
||||
$ret = $this->replace($tpl, $r);
|
||||
$this->_pop_stack();
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* DEBUG node
|
||||
* \code
|
||||
* {{ debug $var [$var [$var [...]]] }}{{ enddebug }}
|
||||
* \endcode
|
||||
* replace node with <pre>var_dump($var, $var, ...);</pre>
|
||||
*/
|
||||
private function _replcb_debug($args) {
|
||||
$vars = array_map('trim', explode(" ",$args[2]));
|
||||
$vars[] = $args[1];
|
||||
|
||||
$ret = "<pre>";
|
||||
foreach ($vars as $var){
|
||||
$ret .= htmlspecialchars(var_export( $this->_get_var($var), true ));
|
||||
$ret .= "\n";
|
||||
}
|
||||
$ret .= "</pre>";
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
private function _replcb_node($m) {
|
||||
$node = $this->nodes[$m[1]];
|
||||
if (method_exists($this, "_replcb_".$node[1])){
|
||||
$s = call_user_func(array($this, "_replcb_".$node[1]), $node);
|
||||
} else {
|
||||
$s = "";
|
||||
}
|
||||
$s = preg_replace_callback('/\|\|([0-9]+)\|\|/', array($this, "_replcb_node"), $s);
|
||||
|
||||
return $s;
|
||||
}
|
||||
|
||||
private function _replcb($m) {
|
||||
//var_dump(array_map('htmlspecialchars', $m));
|
||||
$this->done = false;
|
||||
$this->nodes[] = (array) $m;
|
||||
|
||||
return "||". (count($this->nodes)-1) ."||";
|
||||
}
|
||||
|
||||
private function _build_nodes($s) {
|
||||
$this->done = false;
|
||||
while (!$this->done) {
|
||||
$this->done=true;
|
||||
$s = preg_replace_callback('|{{ *([a-z]*) *([^}]*)}}([^{]*({{ *else *}}[^{]*)?){{ *end\1 *}}|', array($this, "_replcb"), $s);
|
||||
if ($s==Null) $this->_preg_error();
|
||||
}
|
||||
//({{ *else *}}[^{]*)?
|
||||
krsort($this->nodes);
|
||||
|
||||
return $s;
|
||||
}
|
||||
|
||||
private function var_replace($s) {
|
||||
$m = array();
|
||||
/** regexp:
|
||||
* \$ literal $
|
||||
* (\[)? optional open square bracket
|
||||
* ([a-zA-Z0-9-_]+\.?)+ var name, followed by optional
|
||||
* dot, repeated at least 1 time
|
||||
* (?(1)\]) if there was opened square bracket
|
||||
* (subgrup 1), match close bracket
|
||||
*/
|
||||
if (preg_match_all('/\$(\[)?([a-zA-Z0-9-_]+\.?)+(?(1)\])/', $s,$m)) {
|
||||
foreach ($m[0] as $var) {
|
||||
$exp = str_replace(array("[", "]"), array("", ""), $var);
|
||||
$exptks = explode("|", $exp);
|
||||
|
||||
$varn = $exptks[0];
|
||||
unset($exptks[0]);
|
||||
$val = $this->_get_var($varn, true);
|
||||
if ($val != KEY_NOT_EXISTS) {
|
||||
/* run filters */
|
||||
/*
|
||||
* Filter are in form of:
|
||||
* filtername:arg:arg:arg
|
||||
*
|
||||
* "filtername" is function name
|
||||
* "arg"s are optional, var value is appended to the end
|
||||
* if one "arg"==='x' , is replaced with var value
|
||||
*
|
||||
* examples:
|
||||
* $item.body|htmlspecialchars // escape html chars
|
||||
* $item.body|htmlspecialchars|strtoupper // escape html and uppercase result
|
||||
* $item.created|date:%Y %M %j // format date (created is a timestamp)
|
||||
* $item.body|str_replace:cat:dog // replace all "cat" with "dog"
|
||||
* $item.body|str_replace:cat:dog:x:1 // replace one "cat" with "dog"
|
||||
*/
|
||||
foreach ($exptks as $filterstr) {
|
||||
$filter = explode(":", $filterstr);
|
||||
$filtername = $filter[0];
|
||||
unset($filter[0]);
|
||||
$valkey = array_search("x", $filter);
|
||||
if ($valkey === false) {
|
||||
$filter[] = $val;
|
||||
} else {
|
||||
$filter[$valkey] = $val;
|
||||
}
|
||||
if (function_exists($filtername)) {
|
||||
$val = call_user_func_array($filtername, $filter);
|
||||
}
|
||||
}
|
||||
$s = str_replace($var, $val, $s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $s;
|
||||
}
|
||||
|
||||
private function replace($s, $r) {
|
||||
$this->replace_macros($s, $r);
|
||||
}
|
||||
|
||||
// TemplateEngine interface
|
||||
public function replace_macros($s, $r) {
|
||||
$this->r = $r;
|
||||
|
||||
$s = $this->_build_nodes($s);
|
||||
|
||||
$s = preg_replace_callback('/\|\|([0-9]+)\|\|/', array($this, "_replcb_node"), $s);
|
||||
if ($s == Null)
|
||||
$this->_preg_error();
|
||||
|
||||
// remove comments block
|
||||
$s = preg_replace('/{#[^#]*#}/', "" , $s);
|
||||
|
||||
//$t2 = dba_timer();
|
||||
|
||||
// replace strings recursively (limit to 10 loops)
|
||||
$os = "";
|
||||
$count=0;
|
||||
while (($os !== $s) && $count<10) {
|
||||
$os=$s;
|
||||
$count++;
|
||||
$s = $this->var_replace($s);
|
||||
}
|
||||
|
||||
return $s;
|
||||
}
|
||||
|
||||
public function get_markup_template($file, $root='') {
|
||||
$template_file = theme_include($file, $root);
|
||||
if ($template_file) {
|
||||
$content = file_get_contents($template_file);
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function template_escape($s) {
|
||||
return str_replace(array('$','{{'),array('!_Doll^Ars1Az_!','!_DoubLe^BraceS4Rw_!'),$s);
|
||||
}
|
||||
|
||||
function template_unescape($s) {
|
||||
return str_replace(array('!_Doll^Ars1Az_!','!_DoubLe^BraceS4Rw_!'),array('$','{{'),$s);
|
||||
}
|
||||
159
include/text.php
159
include/text.php
@@ -3,8 +3,6 @@
|
||||
* @file include/text.php
|
||||
*/
|
||||
|
||||
require_once("include/template_processor.php");
|
||||
require_once("include/smarty.php");
|
||||
require_once("include/bbcode.php");
|
||||
|
||||
// random string, there are 86 characters max in text mode, 128 for hex
|
||||
@@ -16,13 +14,12 @@ define('RANDOM_STRING_TEXT', 0x01 );
|
||||
/**
|
||||
* @brief This is our template processor.
|
||||
*
|
||||
* @param string|FriendicaSmarty $s the string requiring macro substitution,
|
||||
* or an instance of FriendicaSmarty
|
||||
* @param string|SmartyEngine $s the string requiring macro substitution,
|
||||
* or an instance of SmartyEngine
|
||||
* @param array $r key value pairs (search => replace)
|
||||
* @return string substituted string
|
||||
*/
|
||||
function replace_macros($s, $r) {
|
||||
$a = get_app();
|
||||
|
||||
$arr = array('template' => $s, 'params' => $r);
|
||||
call_hooks('replace_macros', $arr);
|
||||
@@ -98,7 +95,6 @@ function z_input_filter($channel_id,$s,$type = 'text/bbcode') {
|
||||
if($type == 'application/x-pdl')
|
||||
return escape_tags($s);
|
||||
|
||||
$a = get_app();
|
||||
if(App::$is_sys) {
|
||||
return $s;
|
||||
}
|
||||
@@ -326,6 +322,15 @@ function autoname($len) {
|
||||
function xmlify($str) {
|
||||
$buffer = '';
|
||||
|
||||
if(is_array($str)) {
|
||||
|
||||
// allow to fall through so we ge a PHP error, as the log statement will
|
||||
// probably get lost in the noise unless we're specifically looking for it.
|
||||
|
||||
btlogger('xmlify called with array: ' . print_r($str,true), LOGGER_NORMAL, LOG_WARNING);
|
||||
}
|
||||
|
||||
|
||||
$len = mb_strlen($str);
|
||||
for($x = 0; $x < $len; $x ++) {
|
||||
$char = mb_substr($str,$x,1);
|
||||
@@ -569,21 +574,25 @@ function attribute_contains($attr, $s) {
|
||||
*/
|
||||
|
||||
function logger($msg, $level = LOGGER_NORMAL, $priority = LOG_INFO) {
|
||||
// turn off logger in install mode
|
||||
global $a;
|
||||
global $db;
|
||||
|
||||
if((App::$module == 'install') || (! ($db && $db->connected)))
|
||||
return;
|
||||
|
||||
$debugging = get_config('system', 'debugging');
|
||||
$loglevel = intval(get_config('system', 'loglevel'));
|
||||
$logfile = get_config('system', 'logfile');
|
||||
if(App::$module == 'setup' && is_writable('install.log')) {
|
||||
$debugging = true;
|
||||
$logfile = 'install.log';
|
||||
$loglevel = LOGGER_ALL;
|
||||
}
|
||||
else {
|
||||
$debugging = get_config('system', 'debugging');
|
||||
$loglevel = intval(get_config('system', 'loglevel'));
|
||||
$logfile = get_config('system', 'logfile');
|
||||
}
|
||||
|
||||
if((! $debugging) || (! $logfile) || ($level > $loglevel))
|
||||
return;
|
||||
|
||||
$where = '';
|
||||
|
||||
// We require > 5.4 but leave the version check so that install issues (including version) can be logged
|
||||
|
||||
if(version_compare(PHP_VERSION, '5.4.0') >= 0) {
|
||||
$stack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
|
||||
$where = basename($stack[0]['file']) . ':' . $stack[0]['line'] . ':' . $stack[1]['function'] . ': ';
|
||||
@@ -592,7 +601,8 @@ function logger($msg, $level = LOGGER_NORMAL, $priority = LOG_INFO) {
|
||||
$s = datetime_convert() . ':' . log_priority_str($priority) . ':' . session_id() . ':' . $where . $msg . PHP_EOL;
|
||||
$pluginfo = array('filename' => $logfile, 'loglevel' => $level, 'message' => $s,'priority' => $priority, 'logged' => false);
|
||||
|
||||
call_hooks('logger',$pluginfo);
|
||||
if(! (App::$module == 'setup'))
|
||||
call_hooks('logger',$pluginfo);
|
||||
|
||||
if(! $pluginfo['logged'])
|
||||
@file_put_contents($pluginfo['filename'], $pluginfo['message'], FILE_APPEND);
|
||||
@@ -650,11 +660,10 @@ function log_priority_str($priority) {
|
||||
* @param int $level A log level.
|
||||
*/
|
||||
function dlogger($msg, $level = 0) {
|
||||
// turn off logger in install mode
|
||||
global $a;
|
||||
global $db;
|
||||
|
||||
if((App::$module == 'install') || (! ($db && $db->connected)))
|
||||
// turn off logger in install mode
|
||||
|
||||
if(App::$module == 'setup')
|
||||
return;
|
||||
|
||||
$debugging = get_config('system','debugging');
|
||||
@@ -725,6 +734,10 @@ function get_tags($s) {
|
||||
// '=' needs to be avoided because when the replacement is made (in handle_tag()) it has to be ignored there
|
||||
// Feel free to allow '=' if the issue with '=' is solved in handle_tag()
|
||||
// added / ? and [ to avoid issues with hashchars in url paths
|
||||
|
||||
// added ; to single word tags to allow emojis and other unicode character constructs in bbcode
|
||||
// (this would actually be &#xnnnnn; but the ampersand will have been escaped to & by the time we see it.)
|
||||
|
||||
if(preg_match_all('/(?<![a-zA-Z0-9=\/\?])(@[^ \x0D\x0A,:?\[]+ [^ \x0D\x0A@,:?\[]+)/',$s,$match)) {
|
||||
foreach($match[1] as $mtch) {
|
||||
if(substr($mtch,-1,1) === '.')
|
||||
@@ -737,7 +750,7 @@ function get_tags($s) {
|
||||
// Otherwise pull out single word tags. These can be @nickname, @first_last
|
||||
// and #hash tags.
|
||||
|
||||
if(preg_match_all('/(?<![a-zA-Z0-9=\/\?])([@#][^ \x0D\x0A,;:?\[]+)/',$s,$match)) {
|
||||
if(preg_match_all('/(?<![a-zA-Z0-9=\/\?\;])([@#][^ \x0D\x0A,;:?\[]+)/',$s,$match)) {
|
||||
foreach($match[1] as $mtch) {
|
||||
if(substr($mtch,-1,1) === '.')
|
||||
$mtch = substr($mtch,0,-1);
|
||||
@@ -801,7 +814,7 @@ function get_mentions($item,$tags) {
|
||||
return $o;
|
||||
|
||||
foreach($tags as $x) {
|
||||
if($x['type'] == TERM_MENTION) {
|
||||
if($x['ttype'] == TERM_MENTION) {
|
||||
$o .= "\t\t" . '<link rel="mentioned" href="' . $x['url'] . '" />' . "\r\n";
|
||||
$o .= "\t\t" . '<link rel="ostatus:attention" href="' . $x['url'] . '" />' . "\r\n";
|
||||
}
|
||||
@@ -812,7 +825,6 @@ function get_mentions($item,$tags) {
|
||||
|
||||
function contact_block() {
|
||||
$o = '';
|
||||
$a = get_app();
|
||||
|
||||
if(! App::$profile['uid'])
|
||||
return;
|
||||
@@ -925,7 +937,7 @@ function micropro($contact, $redirect = false, $class = '', $textmode = false) {
|
||||
|
||||
|
||||
function search($s,$id='search-box',$url='/search',$save = false) {
|
||||
$a = get_app();
|
||||
|
||||
return replace_macros(get_markup_template('searchbox.tpl'),array(
|
||||
'$s' => $s,
|
||||
'$id' => $id,
|
||||
@@ -1070,7 +1082,7 @@ function get_mood_verbs() {
|
||||
// Function to list all smilies, both internal and from addons
|
||||
// Returns array with keys 'texts' and 'icons'
|
||||
function list_smilies() {
|
||||
$a = get_app();
|
||||
|
||||
$texts = array(
|
||||
'<3',
|
||||
'</3',
|
||||
@@ -1104,9 +1116,7 @@ function list_smilies() {
|
||||
':facepalm',
|
||||
':like',
|
||||
':dislike',
|
||||
'red#matrix',
|
||||
'red#',
|
||||
'r#'
|
||||
':hubzilla'
|
||||
);
|
||||
|
||||
$icons = array(
|
||||
@@ -1142,12 +1152,24 @@ function list_smilies() {
|
||||
'<img class="smiley" src="' . z_root() . '/images/smiley-facepalm.gif" alt=":facepalm" />',
|
||||
'<img class="smiley" src="' . z_root() . '/images/like.gif" alt=":like" />',
|
||||
'<img class="smiley" src="' . z_root() . '/images/dislike.gif" alt=":dislike" />',
|
||||
'<a href="http://getzot.com"><strong>red<img class="smiley bb_rm-logo" src="' . z_root() . '/images/rm-32.png" alt="' . urlencode('red#matrix') . '" />matrix</strong></a>',
|
||||
'<a href="http://getzot.com"><strong>red<img class="smiley bb_rm-logo" src="' . z_root() . '/images/rm-32.png" alt="' . urlencode('red#') . '" />matrix</strong></a>',
|
||||
'<a href="http://getzot.com"><strong>red<img class="smiley bb_rm-logo" src="' . z_root() . '/images/rm-32.png" alt="r#" />matrix</strong></a>'
|
||||
'<img class="smiley" src="' . z_root() . '/images/hz-16.png" alt=":hubzilla" />',
|
||||
|
||||
);
|
||||
|
||||
$x = get_config('feature','emoji');
|
||||
if($x === false)
|
||||
$x = 1;
|
||||
if($x) {
|
||||
if(! App::$emojitab)
|
||||
App::$emojitab = json_decode(file_get_contents('library/emoji.json'),true);
|
||||
foreach(App::$emojitab as $e) {
|
||||
if(strpos($e['shortname'],':tone') === 0)
|
||||
continue;
|
||||
$texts[] = $e['shortname'];
|
||||
$icons[] = '<img class="smiley emoji" height="16" width="16" src="images/emoji/' . $e['unicode'] . '.png' . '" alt="' . $e['name'] . '" />';
|
||||
}
|
||||
}
|
||||
|
||||
$params = array('texts' => $texts, 'icons' => $icons);
|
||||
call_hooks('smilie', $params);
|
||||
|
||||
@@ -1215,7 +1237,7 @@ function smile_unshield($m) {
|
||||
* @param array $x
|
||||
*/
|
||||
function preg_heart($x) {
|
||||
$a = get_app();
|
||||
|
||||
if (strlen($x[1]) == 1)
|
||||
return $x[0];
|
||||
|
||||
@@ -1321,7 +1343,7 @@ function theme_attachments(&$item) {
|
||||
|
||||
$title = t('Size') . ' ' . (($r['length']) ? userReadableSize($r['length']) : t('unknown'));
|
||||
|
||||
require_once('include/identity.php');
|
||||
require_once('include/channel.php');
|
||||
if(is_foreigner($item['author_xchan']))
|
||||
$url = $r['href'];
|
||||
else
|
||||
@@ -1455,40 +1477,8 @@ function generate_named_map($location) {
|
||||
return (($arr['html']) ? $arr['html'] : $location);
|
||||
}
|
||||
|
||||
function format_event($jobject) {
|
||||
$event = array();
|
||||
|
||||
$object = json_decode($jobject,true);
|
||||
|
||||
//ensure compatibility with older items - this check can be removed at a later point
|
||||
if(array_key_exists('description', $object)) {
|
||||
|
||||
$bd_format = t('l F d, Y \@ g:i A'); // Friday January 18, 2011 @ 8:01 AM
|
||||
|
||||
$event['header'] = replace_macros(get_markup_template('event_item_header.tpl'),array(
|
||||
'$title' => bbcode($object['title']),
|
||||
'$dtstart_label' => t('Starts:'),
|
||||
'$dtstart_title' => datetime_convert('UTC', 'UTC', $object['start'], (($object['adjust']) ? ATOM_TIME : 'Y-m-d\TH:i:s' )),
|
||||
'$dtstart_dt' => (($object['adjust']) ? day_translate(datetime_convert('UTC', date_default_timezone_get(), $object['start'] , $bd_format )) : day_translate(datetime_convert('UTC', 'UTC', $object['start'] , $bd_format))),
|
||||
'$finish' => (($object['nofinish']) ? false : true),
|
||||
'$dtend_label' => t('Finishes:'),
|
||||
'$dtend_title' => datetime_convert('UTC','UTC',$object['finish'], (($object['adjust']) ? ATOM_TIME : 'Y-m-d\TH:i:s' )),
|
||||
'$dtend_dt' => (($object['adjust']) ? day_translate(datetime_convert('UTC', date_default_timezone_get(), $object['finish'] , $bd_format )) : day_translate(datetime_convert('UTC', 'UTC', $object['finish'] , $bd_format )))
|
||||
));
|
||||
|
||||
$event['content'] = replace_macros(get_markup_template('event_item_content.tpl'),array(
|
||||
'$description' => bbcode($object['description']),
|
||||
'$location_label' => t('Location:'),
|
||||
'$location' => bbcode($object['location'])
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
function prepare_body(&$item,$attach = false) {
|
||||
require_once('include/identity.php');
|
||||
|
||||
call_hooks('prepare_body_init', $item);
|
||||
|
||||
@@ -1498,7 +1488,7 @@ function prepare_body(&$item,$attach = false) {
|
||||
|
||||
if($is_photo) {
|
||||
|
||||
$object = json_decode($item['object'],true);
|
||||
$object = json_decode($item['obj'],true);
|
||||
|
||||
// if original photo width is <= 640px prepend it to item body
|
||||
if($object['link'][0]['width'] && $object['link'][0]['width'] <= 640) {
|
||||
@@ -1514,7 +1504,7 @@ function prepare_body(&$item,$attach = false) {
|
||||
|
||||
$s .= prepare_text($item['body'],$item['mimetype'], false);
|
||||
|
||||
$event = (($item['obj_type'] === ACTIVITY_OBJ_EVENT) ? format_event($item['object']) : false);
|
||||
$event = (($item['obj_type'] === ACTIVITY_OBJ_EVENT) ? format_event_obj($item['obj']) : false);
|
||||
|
||||
$prep_arr = array(
|
||||
'item' => $item,
|
||||
@@ -1718,7 +1708,6 @@ function feed_hublinks() {
|
||||
/* return atom link elements for salmon endpoints */
|
||||
|
||||
function feed_salmonlinks($nick) {
|
||||
$a = get_app();
|
||||
|
||||
$salmon = '<link rel="salmon" href="' . xmlify(z_root() . '/salmon/' . $nick) . '" />' . "\n" ;
|
||||
|
||||
@@ -1786,7 +1775,7 @@ function mimetype_select($channel_id, $current = 'text/bbcode') {
|
||||
'application/x-pdl'
|
||||
);
|
||||
|
||||
$a = get_app();
|
||||
|
||||
if(App::$is_sys) {
|
||||
$x[] = 'application/x-php';
|
||||
}
|
||||
@@ -1819,7 +1808,6 @@ function mimetype_select($channel_id, $current = 'text/bbcode') {
|
||||
|
||||
|
||||
function lang_selector() {
|
||||
global $a;
|
||||
|
||||
$langs = glob('view/*/hstrings.php');
|
||||
|
||||
@@ -2263,7 +2251,7 @@ function design_tools() {
|
||||
$sys = false;
|
||||
|
||||
if(App::$is_sys && is_site_admin()) {
|
||||
require_once('include/identity.php');
|
||||
require_once('include/channel.php');
|
||||
$channel = get_sys_channel();
|
||||
$sys = true;
|
||||
}
|
||||
@@ -2860,3 +2848,32 @@ function pdl_selector($uid, $current="") {
|
||||
return $o;
|
||||
}
|
||||
|
||||
/*
|
||||
* array flatten_array_recursive(array);
|
||||
* returns a one-dimensional array from a multi-dimensional array
|
||||
* empty values are discarded
|
||||
* example: print_r(flatten_array_recursive(array('foo','bar',array('baz','blip',array('zob','glob')),'','grip')));
|
||||
*
|
||||
* Array ( [0] => foo [1] => bar [2] => baz [3] => blip [4] => zob [5] => glob [6] => grip )
|
||||
*
|
||||
*/
|
||||
|
||||
function flatten_array_recursive($arr) {
|
||||
$ret = array();
|
||||
|
||||
if(! $arr)
|
||||
return $ret;
|
||||
|
||||
foreach($arr as $a) {
|
||||
if(is_array($a)) {
|
||||
$tmp = flatten_array_recursive($a);
|
||||
if($tmp) {
|
||||
$ret = array_merge($ret,$tmp);
|
||||
}
|
||||
}
|
||||
elseif($a) {
|
||||
$ret[] = $a;
|
||||
}
|
||||
}
|
||||
return($ret);
|
||||
}
|
||||
|
||||
@@ -8,17 +8,17 @@
|
||||
require_once('include/dir_fns.php');
|
||||
require_once('include/contact_widgets.php');
|
||||
require_once('include/attach.php');
|
||||
require_once('include/Contact.php');
|
||||
|
||||
|
||||
function widget_profile($args) {
|
||||
|
||||
$block = (((get_config('system', 'block_public')) && (! local_channel()) && (! remote_channel())) ? true : false);
|
||||
$block = observer_prohibited();
|
||||
return profile_sidebar(App::$profile, $block, true);
|
||||
}
|
||||
|
||||
function widget_zcard($args) {
|
||||
|
||||
$block = (((get_config('system', 'block_public')) && (! local_channel()) && (! remote_channel())) ? true : false);
|
||||
$block = observer_prohibited();
|
||||
$channel = channelx_by_n(App::$profile_uid);
|
||||
return get_zcard($channel,get_observer_hash(),array('width' => 875));
|
||||
}
|
||||
@@ -212,13 +212,13 @@ function widget_savedsearch($arr) {
|
||||
$search = ((x($_GET,'search')) ? $_GET['search'] : '');
|
||||
|
||||
if(x($_GET,'searchsave') && $search) {
|
||||
$r = q("select * from `term` where `uid` = %d and `type` = %d and `term` = '%s' limit 1",
|
||||
$r = q("select * from `term` where `uid` = %d and `ttype` = %d and `term` = '%s' limit 1",
|
||||
intval(local_channel()),
|
||||
intval(TERM_SAVEDSEARCH),
|
||||
dbesc($search)
|
||||
);
|
||||
if(! $r) {
|
||||
q("insert into `term` ( `uid`,`type`,`term` ) values ( %d, %d, '%s') ",
|
||||
q("insert into `term` ( `uid`,`ttype`,`term` ) values ( %d, %d, '%s') ",
|
||||
intval(local_channel()),
|
||||
intval(TERM_SAVEDSEARCH),
|
||||
dbesc($search)
|
||||
@@ -227,7 +227,7 @@ function widget_savedsearch($arr) {
|
||||
}
|
||||
|
||||
if(x($_GET,'searchremove') && $search) {
|
||||
q("delete from `term` where `uid` = %d and `type` = %d and `term` = '%s'",
|
||||
q("delete from `term` where `uid` = %d and `ttype` = %d and `term` = '%s'",
|
||||
intval(local_channel()),
|
||||
intval(TERM_SAVEDSEARCH),
|
||||
dbesc($search)
|
||||
@@ -254,7 +254,7 @@ function widget_savedsearch($arr) {
|
||||
|
||||
$o = '';
|
||||
|
||||
$r = q("select `tid`,`term` from `term` WHERE `uid` = %d and `type` = %d ",
|
||||
$r = q("select `tid`,`term` from `term` WHERE `uid` = %d and `ttype` = %d ",
|
||||
intval(local_channel()),
|
||||
intval(TERM_SAVEDSEARCH)
|
||||
);
|
||||
@@ -296,7 +296,7 @@ function widget_filer($arr) {
|
||||
$selected = ((x($_REQUEST,'file')) ? $_REQUEST['file'] : '');
|
||||
|
||||
$terms = array();
|
||||
$r = q("select distinct(term) from term where uid = %d and type = %d order by term asc",
|
||||
$r = q("select distinct(term) from term where uid = %d and ttype = %d order by term asc",
|
||||
intval(local_channel()),
|
||||
intval(TERM_FILE)
|
||||
);
|
||||
@@ -369,7 +369,7 @@ function widget_fullprofile($arr) {
|
||||
if(! App::$profile['profile_uid'])
|
||||
return;
|
||||
|
||||
$block = (((get_config('system', 'block_public')) && (! local_channel()) && (! remote_channel())) ? true : false);
|
||||
$block = observer_prohibited();
|
||||
|
||||
return profile_sidebar(App::$profile, $block);
|
||||
}
|
||||
@@ -379,7 +379,7 @@ function widget_shortprofile($arr) {
|
||||
if(! App::$profile['profile_uid'])
|
||||
return;
|
||||
|
||||
$block = (((get_config('system', 'block_public')) && (! local_channel()) && (! remote_channel())) ? true : false);
|
||||
$block = observer_prohibited();
|
||||
|
||||
return profile_sidebar(App::$profile, $block, true, true);
|
||||
}
|
||||
@@ -771,7 +771,6 @@ function widget_eventstools($arr) {
|
||||
}
|
||||
|
||||
function widget_design_tools($arr) {
|
||||
$a = get_app();
|
||||
|
||||
// mod menu doesn't load a profile. For any modules which load a profile, check it.
|
||||
// otherwise local_channel() is sufficient for permissions.
|
||||
@@ -800,13 +799,14 @@ function widget_photo_albums($arr) {
|
||||
if((! $channelx) || (! perm_is_allowed(App::$profile['profile_uid'], get_observer_hash(), 'view_storage')))
|
||||
return '';
|
||||
require_once('include/photos.php');
|
||||
$sortkey = ((array_key_exists('sortkey',$arr)) ? $arr['sortkey'] : 'album');
|
||||
$direction = ((array_key_exists('direction',$arr)) ? $arr['direction'] : 'asc');
|
||||
|
||||
return photos_album_widget($channelx, App::get_observer());
|
||||
return photos_album_widget($channelx, App::get_observer(),$sortkey,$direction);
|
||||
}
|
||||
|
||||
|
||||
function widget_vcard($arr) {
|
||||
require_once ('include/Contact.php');
|
||||
return vcard_from_xchan('', App::get_observer());
|
||||
}
|
||||
|
||||
@@ -835,8 +835,7 @@ function widget_menu_preview($arr) {
|
||||
function widget_chatroom_list($arr) {
|
||||
|
||||
|
||||
require_once("include/chat.php");
|
||||
$r = chatroom_list(App::$profile['profile_uid']);
|
||||
$r = Zotlabs\Lib\Chatroom::roomlist(App::$profile['profile_uid']);
|
||||
|
||||
if($r) {
|
||||
return replace_macros(get_markup_template('chatroomlist.tpl'), array(
|
||||
@@ -857,6 +856,78 @@ function widget_chatroom_members() {
|
||||
return $o;
|
||||
}
|
||||
|
||||
function widget_wiki_list($arr) {
|
||||
|
||||
require_once("include/wiki.php");
|
||||
$channel = null;
|
||||
if (argc() < 2 && local_channel()) {
|
||||
// This should not occur because /wiki should redirect to /wiki/channel ...
|
||||
$channel = \App::get_channel();
|
||||
} else {
|
||||
$channel = get_channel_by_nick(argv(1)); // Channel being viewed by observer
|
||||
}
|
||||
if (!$channel) {
|
||||
return '';
|
||||
}
|
||||
$wikis = wiki_list($channel, get_observer_hash());
|
||||
if ($wikis) {
|
||||
return replace_macros(get_markup_template('wikilist.tpl'), array(
|
||||
'$header' => t('Wiki List'),
|
||||
'$channel' => $channel['channel_address'],
|
||||
'$wikis' => $wikis['wikis'],
|
||||
// If the observer is the local channel owner, show the wiki controls
|
||||
'$showControls' => ((local_channel() === intval($channel['channel_id'])) ? true : false)
|
||||
));
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function widget_wiki_pages($arr) {
|
||||
|
||||
require_once("include/wiki.php");
|
||||
$channelname = ((array_key_exists('channel',$arr)) ? $arr['channel'] : '');
|
||||
$wikiname = '';
|
||||
if (array_key_exists('refresh', $arr)) {
|
||||
$not_refresh = (($arr['refresh']=== true) ? false : true);
|
||||
} else {
|
||||
$not_refresh = true;
|
||||
}
|
||||
$pages = array();
|
||||
if (!array_key_exists('resource_id', $arr)) {
|
||||
$hide = true;
|
||||
} else {
|
||||
$p = wiki_page_list($arr['resource_id']);
|
||||
if ($p['pages']) {
|
||||
$pages = $p['pages'];
|
||||
$w = $p['wiki'];
|
||||
// Wiki item record is $w['wiki']
|
||||
$wikiname = $w['urlName'];
|
||||
if (!$wikiname) {
|
||||
$wikiname = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
return replace_macros(get_markup_template('wiki_page_list.tpl'), array(
|
||||
'$hide' => $hide,
|
||||
'$not_refresh' => $not_refresh,
|
||||
'$header' => t('Wiki Pages'),
|
||||
'$channel' => $channelname,
|
||||
'$wikiname' => $wikiname,
|
||||
'$pages' => $pages
|
||||
));
|
||||
}
|
||||
|
||||
function widget_wiki_page_history($arr) {
|
||||
require_once("include/wiki.php");
|
||||
$pageUrlName = ((array_key_exists('pageUrlName', $arr)) ? $arr['pageUrlName'] : '');
|
||||
$resource_id = ((array_key_exists('resource_id', $arr)) ? $arr['resource_id'] : '');
|
||||
$pageHistory = wiki_page_history(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
|
||||
|
||||
return replace_macros(get_markup_template('wiki_page_history.tpl'), array(
|
||||
'$pageHistory' => $pageHistory['history']
|
||||
));
|
||||
}
|
||||
|
||||
function widget_bookmarkedchats($arr) {
|
||||
|
||||
if(! feature_enabled(App::$profile['profile_uid'],'ajaxchat'))
|
||||
@@ -1052,7 +1123,7 @@ function widget_photo($arr) {
|
||||
|
||||
function widget_cover_photo($arr) {
|
||||
|
||||
require_once('include/identity.php');
|
||||
require_once('include/channel.php');
|
||||
$o = '';
|
||||
|
||||
if(App::$module == 'channel' && $_REQUEST['mid'])
|
||||
@@ -1129,7 +1200,7 @@ function widget_photo_rand($arr) {
|
||||
$filtered = array();
|
||||
if($ret['success'] && $ret['photos'])
|
||||
foreach($ret['photos'] as $p)
|
||||
if($p['scale'] == $scale)
|
||||
if($p['imgscale'] == $scale)
|
||||
$filtered[] = $p['src'];
|
||||
|
||||
if($filtered) {
|
||||
@@ -1381,7 +1452,7 @@ function widget_admin($arr) {
|
||||
|
||||
$aside = array(
|
||||
'site' => array(z_root() . '/admin/site/', t('Site'), 'site'),
|
||||
'users' => array(z_root() . '/admin/users/', t('Accounts'), 'users', 'pending-update', t('Member registrations waiting for confirmation')),
|
||||
'accounts' => array(z_root() . '/admin/accounts/', t('Accounts'), 'accounts', 'pending-update', t('Member registrations waiting for confirmation')),
|
||||
'channels' => array(z_root() . '/admin/channels/', t('Channels'), 'channels'),
|
||||
'security' => array(z_root() . '/admin/security/', t('Security'), 'security'),
|
||||
'features' => array(z_root() . '/admin/features/', t('Features'), 'features'),
|
||||
@@ -1400,7 +1471,7 @@ function widget_admin($arr) {
|
||||
$plugins = array();
|
||||
if($r) {
|
||||
foreach ($r as $h){
|
||||
$plugin = $h['name'];
|
||||
$plugin = $h['aname'];
|
||||
$plugins[] = array(z_root() . '/admin/plugins/' . $plugin, $plugin, 'plugin');
|
||||
// temp plugins with admin
|
||||
App::$plugins_admin[] = $plugin;
|
||||
@@ -1462,9 +1533,9 @@ function widget_album($args) {
|
||||
|
||||
$order = 'DESC';
|
||||
|
||||
$r = q("SELECT p.resource_id, p.id, p.filename, p.type, p.scale, p.description, p.created FROM photo p INNER JOIN
|
||||
(SELECT resource_id, max(scale) scale FROM photo WHERE uid = %d AND album = '%s' AND scale <= 4 AND photo_usage IN ( %d, %d ) $sql_extra GROUP BY resource_id) ph
|
||||
ON (p.resource_id = ph.resource_id AND p.scale = ph.scale)
|
||||
$r = q("SELECT p.resource_id, p.id, p.filename, p.mimetype, p.imgscale, p.description, p.created FROM photo p INNER JOIN
|
||||
(SELECT resource_id, max(imgscale) imgscale FROM photo WHERE uid = %d AND album = '%s' AND imgscale <= 4 AND photo_usage IN ( %d, %d ) $sql_extra GROUP BY resource_id) ph
|
||||
ON (p.resource_id = ph.resource_id AND p.imgscale = ph.imgscale)
|
||||
ORDER BY created $order ",
|
||||
intval($owner_uid),
|
||||
dbesc($album),
|
||||
@@ -1485,7 +1556,7 @@ function widget_album($args) {
|
||||
else
|
||||
$twist = 'rotright';
|
||||
|
||||
$ext = $phototypes[$rr['type']];
|
||||
$ext = $phototypes[$rr['mimetype']];
|
||||
|
||||
$imgalt_e = $rr['filename'];
|
||||
$desc_e = $rr['description'];
|
||||
@@ -1498,7 +1569,7 @@ function widget_album($args) {
|
||||
'twist' => ' ' . $twist . rand(2,4),
|
||||
'link' => $imagelink,
|
||||
'title' => t('View Photo'),
|
||||
'src' => z_root() . '/photo/' . $rr['resource_id'] . '-' . $rr['scale'] . '.' .$ext,
|
||||
'src' => z_root() . '/photo/' . $rr['resource_id'] . '-' . $rr['imgscale'] . '.' .$ext,
|
||||
'alt' => $imgalt_e,
|
||||
'desc'=> $desc_e,
|
||||
'ext' => $ext,
|
||||
|
||||
399
include/wiki.php
Normal file
399
include/wiki.php
Normal file
@@ -0,0 +1,399 @@
|
||||
<?php
|
||||
/**
|
||||
* @file include/wiki.php
|
||||
* @brief Wiki related functions.
|
||||
*/
|
||||
|
||||
use \Zotlabs\Storage\GitRepo as GitRepo;
|
||||
define ( 'WIKI_ITEM_RESOURCE_TYPE', 'wiki' );
|
||||
|
||||
function wiki_list($channel, $observer_hash) {
|
||||
$sql_extra = item_permissions_sql($channel['channel_id'], $observer_hash);
|
||||
$wikis = q("SELECT * FROM item WHERE resource_type = '%s' AND mid = parent_mid AND uid = %d AND item_deleted = 0 $sql_extra",
|
||||
dbesc(WIKI_ITEM_RESOURCE_TYPE),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
foreach($wikis as &$w) {
|
||||
$w['rawName'] = get_iconfig($w, 'wiki', 'rawName');
|
||||
$w['htmlName'] = get_iconfig($w, 'wiki', 'htmlName');
|
||||
$w['urlName'] = get_iconfig($w, 'wiki', 'urlName');
|
||||
$w['path'] = get_iconfig($w, 'wiki', 'path');
|
||||
}
|
||||
// TODO: query db for wikis the observer can access. Return with two lists, for read and write access
|
||||
return array('wikis' => $wikis);
|
||||
}
|
||||
|
||||
function wiki_page_list($resource_id) {
|
||||
// TODO: Create item table records for pages so that metadata like title can be applied
|
||||
$w = wiki_get_wiki($resource_id);
|
||||
if (!$w['path']) {
|
||||
return array('pages' => null, 'wiki' => null);
|
||||
}
|
||||
$pages = array();
|
||||
if (is_dir($w['path']) === true) {
|
||||
$files = array_diff(scandir($w['path']), array('.', '..', '.git'));
|
||||
// TODO: Check that the files are all text files
|
||||
|
||||
foreach($files as $file) {
|
||||
// strip the .md file extension and unwrap URL encoding to leave HTML encoded name
|
||||
$pages[] = array('title' => urldecode(substr($file, 0, -3)), 'url' => urlencode(substr($file, 0, -3)));
|
||||
}
|
||||
}
|
||||
|
||||
return array('pages' => $pages, 'wiki' => $w);
|
||||
}
|
||||
|
||||
function wiki_init_wiki($channel, $wiki) {
|
||||
// Store the path as a relative path, but pass absolute path to mkdir
|
||||
$path = 'store/[data]/git/'.$channel['channel_address'].'/wiki/'.$wiki['urlName'];
|
||||
if (!os_mkdir(__DIR__ . '/../' . $path, 0770, true)) {
|
||||
logger('Error creating wiki path: ' . $path);
|
||||
return null;
|
||||
}
|
||||
// Create GitRepo object
|
||||
$git = new GitRepo($channel['channel_address'], null, false, $name, __DIR__ . '/../' . $path);
|
||||
if(!$git->initRepo()) {
|
||||
logger('Error creating new git repo in ' . $git->path);
|
||||
return null;
|
||||
}
|
||||
|
||||
return array('path' => $path);
|
||||
}
|
||||
|
||||
function wiki_create_wiki($channel, $observer_hash, $wiki, $acl) {
|
||||
$wikiinit = wiki_init_wiki($channel, $wiki);
|
||||
if (!$wikiinit['path']) {
|
||||
notice('Error creating wiki');
|
||||
return array('item' => null, 'success' => false);
|
||||
}
|
||||
$path = $wikiinit['path'];
|
||||
// Generate unique resource_id using the same method as item_message_id()
|
||||
do {
|
||||
$dups = false;
|
||||
$resource_id = random_string();
|
||||
$r = q("SELECT mid FROM item WHERE resource_id = '%s' AND resource_type = '%s' AND uid = %d LIMIT 1",
|
||||
dbesc($resource_id),
|
||||
dbesc(WIKI_ITEM_RESOURCE_TYPE),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
if (count($r))
|
||||
$dups = true;
|
||||
} while ($dups == true);
|
||||
$ac = $acl->get();
|
||||
$mid = item_message_id();
|
||||
$arr = array(); // Initialize the array of parameters for the post
|
||||
$item_hidden = 0; // TODO: Allow form creator to send post to ACL about new game automatically
|
||||
$wiki_url = z_root() . '/wiki/' . $channel['channel_address'] . '/' . $wiki['urlName'];
|
||||
$arr['aid'] = $channel['channel_account_id'];
|
||||
$arr['uid'] = $channel['channel_id'];
|
||||
$arr['mid'] = $mid;
|
||||
$arr['parent_mid'] = $mid;
|
||||
$arr['item_hidden'] = $item_hidden;
|
||||
$arr['resource_type'] = WIKI_ITEM_RESOURCE_TYPE;
|
||||
$arr['resource_id'] = $resource_id;
|
||||
$arr['owner_xchan'] = $channel['channel_hash'];
|
||||
$arr['author_xchan'] = $observer_hash;
|
||||
$arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $arr['mid'];
|
||||
$arr['llink'] = $arr['plink'];
|
||||
$arr['title'] = $wiki['htmlName']; // name of new wiki;
|
||||
$arr['allow_cid'] = $ac['allow_cid'];
|
||||
$arr['allow_gid'] = $ac['allow_gid'];
|
||||
$arr['deny_cid'] = $ac['deny_cid'];
|
||||
$arr['deny_gid'] = $ac['deny_gid'];
|
||||
$arr['item_wall'] = 1;
|
||||
$arr['item_origin'] = 1;
|
||||
$arr['item_thread_top'] = 1;
|
||||
$arr['item_private'] = intval($acl->is_private());
|
||||
$arr['verb'] = ACTIVITY_CREATE;
|
||||
$arr['obj_type'] = ACTIVITY_OBJ_WIKI;
|
||||
$arr['body'] = '[table][tr][td][h1]New Wiki[/h1][/td][/tr][tr][td][zrl=' . $wiki_url . ']' . $wiki['htmlName'] . '[/zrl][/td][/tr][/table]';
|
||||
// Save the path using iconfig. The file path should not be shared with other hubs
|
||||
if (!set_iconfig($arr, 'wiki', 'path', $path, false)) {
|
||||
return array('item' => null, 'success' => false);
|
||||
}
|
||||
// Save the wiki name information using iconfig. This is shareable.
|
||||
if (!set_iconfig($arr, 'wiki', 'rawName', $wiki['rawName'], true)) {
|
||||
return array('item' => null, 'success' => false);
|
||||
}
|
||||
if (!set_iconfig($arr, 'wiki', 'htmlName', $wiki['htmlName'], true)) {
|
||||
return array('item' => null, 'success' => false);
|
||||
}
|
||||
if (!set_iconfig($arr, 'wiki', 'urlName', $wiki['urlName'], true)) {
|
||||
return array('item' => null, 'success' => false);
|
||||
}
|
||||
$post = item_store($arr);
|
||||
$item_id = $post['item_id'];
|
||||
|
||||
if ($item_id) {
|
||||
proc_run('php', "include/notifier.php", "activity", $item_id);
|
||||
return array('item' => $arr, 'success' => true);
|
||||
} else {
|
||||
return array('item' => null, 'success' => false);
|
||||
}
|
||||
}
|
||||
|
||||
function wiki_delete_wiki($resource_id) {
|
||||
|
||||
$w = wiki_get_wiki($resource_id);
|
||||
$item = $w['wiki'];
|
||||
if (!$item || !$w['path']) {
|
||||
return array('item' => null, 'success' => false);
|
||||
} else {
|
||||
$drop = drop_item($item['id'], false, DROPITEM_NORMAL, true);
|
||||
$pathdel = rrmdir($w['path']);
|
||||
if ($pathdel) {
|
||||
info('Wiki files deleted successfully');
|
||||
}
|
||||
return array('item' => $item, 'success' => (($drop === 1 && $pathdel) ? true : false));
|
||||
}
|
||||
}
|
||||
|
||||
function wiki_get_wiki($resource_id) {
|
||||
$item = q("SELECT * FROM item WHERE resource_type = '%s' AND resource_id = '%s' AND item_deleted = 0 limit 1",
|
||||
dbesc(WIKI_ITEM_RESOURCE_TYPE),
|
||||
dbesc($resource_id)
|
||||
);
|
||||
if (!$item) {
|
||||
return array('wiki' => null, 'path' => null);
|
||||
} else {
|
||||
$w = $item[0]; // wiki item table record
|
||||
// Get wiki metadata
|
||||
$rawName = get_iconfig($w, 'wiki', 'rawName');
|
||||
$htmlName = get_iconfig($w, 'wiki', 'htmlName');
|
||||
$urlName = get_iconfig($w, 'wiki', 'urlName');
|
||||
$path = get_iconfig($w, 'wiki', 'path');
|
||||
if (!realpath(__DIR__ . '/../' . $path)) {
|
||||
return array('wiki' => null, 'path' => null);
|
||||
}
|
||||
// Path to wiki exists
|
||||
$abs_path = realpath(__DIR__ . '/../' . $path);
|
||||
return array( 'wiki' => $w,
|
||||
'path' => $abs_path,
|
||||
'rawName' => $rawName,
|
||||
'htmlName' => $htmlName,
|
||||
'urlName' => $urlName
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function wiki_exists_by_name($uid, $urlName) {
|
||||
$item = q("SELECT id,resource_id FROM item WHERE resource_type = '%s' AND title = '%s' AND uid = '%s' AND item_deleted = 0 limit 1",
|
||||
dbesc(WIKI_ITEM_RESOURCE_TYPE),
|
||||
dbesc(escape_tags(urldecode($urlName))),
|
||||
dbesc($uid)
|
||||
);
|
||||
if (!$item) {
|
||||
return array('id' => null, 'resource_id' => null);
|
||||
} else {
|
||||
return array('id' => $item[0]['id'], 'resource_id' => $item[0]['resource_id']);
|
||||
}
|
||||
}
|
||||
|
||||
function wiki_get_permissions($resource_id, $owner_id, $observer_hash) {
|
||||
// TODO: For now, only the owner can edit
|
||||
$sql_extra = item_permissions_sql($owner_id, $observer_hash);
|
||||
$r = q("SELECT * FROM item WHERE resource_type = '%s' AND resource_id = '%s' $sql_extra LIMIT 1",
|
||||
dbesc(WIKI_ITEM_RESOURCE_TYPE),
|
||||
dbesc($resource_id)
|
||||
);
|
||||
|
||||
if (!$r) {
|
||||
return array('read' => false, 'write' => false, 'success' => true);
|
||||
} else {
|
||||
$perms = get_all_perms($owner_id, $observer_hash);
|
||||
// TODO: Create a new permission setting for wiki analogous to webpages. Until
|
||||
// then, use webpage permissions
|
||||
if (!$perms['write_pages']) {
|
||||
$write = false;
|
||||
} else {
|
||||
$write = true;
|
||||
}
|
||||
return array('read' => true, 'write' => $write, 'success' => true);
|
||||
}
|
||||
}
|
||||
|
||||
function wiki_create_page($name, $resource_id) {
|
||||
$w = wiki_get_wiki($resource_id);
|
||||
if (!$w['path']) {
|
||||
return array('page' => null, 'wiki' => null, 'message' => 'Wiki not found.', 'success' => false);
|
||||
}
|
||||
$page = array('rawName' => $name, 'htmlName' => escape_tags($name), 'urlName' => urlencode(escape_tags($name)), 'fileName' => urlencode(escape_tags($name)).'.md');
|
||||
$page_path = $w['path'] . '/' . $page['fileName'];
|
||||
if (is_file($page_path)) {
|
||||
return array('page' => null, 'wiki' => null, 'message' => 'Page already exists.', 'success' => false);
|
||||
}
|
||||
// Create the page file in the wiki repo
|
||||
if(!touch($page_path)) {
|
||||
return array('page' => null, 'wiki' => null, 'message' => 'Page file cannot be created.', 'success' => false);
|
||||
} else {
|
||||
return array('page' => $page, 'wiki' => $w, 'message' => '', 'success' => true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function wiki_get_page_content($arr) {
|
||||
$pageUrlName = ((array_key_exists('pageUrlName',$arr)) ? $arr['pageUrlName'] : '');
|
||||
$resource_id = ((array_key_exists('resource_id',$arr)) ? $arr['resource_id'] : '');
|
||||
$w = wiki_get_wiki($resource_id);
|
||||
if (!$w['path']) {
|
||||
return array('content' => null, 'message' => 'Error reading wiki', 'success' => false);
|
||||
}
|
||||
$page_path = $w['path'].'/'.$pageUrlName.'.md';
|
||||
if (is_readable($page_path) === true) {
|
||||
if(filesize($page_path) === 0) {
|
||||
$content = '';
|
||||
} else {
|
||||
$content = file_get_contents($page_path);
|
||||
if(!$content) {
|
||||
return array('content' => null, 'message' => 'Error reading page content', 'success' => false);
|
||||
}
|
||||
}
|
||||
// TODO: Check that the files are all text files
|
||||
return array('content' => json_encode($content), 'message' => '', 'success' => true);
|
||||
}
|
||||
}
|
||||
|
||||
function wiki_page_history($arr) {
|
||||
$pageUrlName = ((array_key_exists('pageUrlName',$arr)) ? $arr['pageUrlName'] : '');
|
||||
$resource_id = ((array_key_exists('resource_id',$arr)) ? $arr['resource_id'] : '');
|
||||
$w = wiki_get_wiki($resource_id);
|
||||
if (!$w['path']) {
|
||||
return array('history' => null, 'message' => 'Error reading wiki', 'success' => false);
|
||||
}
|
||||
$page_path = $w['path'].'/'.$pageUrlName.'.md';
|
||||
if (!is_readable($page_path) === true) {
|
||||
return array('history' => null, 'message' => 'Cannot read wiki page: ' . $page_path, 'success' => false);
|
||||
}
|
||||
$reponame = ((array_key_exists('title', $w['wiki'])) ? $w['wiki']['title'] : 'repo');
|
||||
if($reponame === '') {
|
||||
$reponame = 'repo';
|
||||
}
|
||||
$git = new GitRepo('', null, false, $w['wiki']['title'], $w['path']);
|
||||
try {
|
||||
$gitlog = $git->git->log('', $page_path , array('limit' => 500));
|
||||
return array('history' => $gitlog, 'message' => '', 'success' => true);
|
||||
} catch (\PHPGit\Exception\GitException $e) {
|
||||
return array('history' => null, 'message' => 'GitRepo error thrown', 'success' => false);
|
||||
}
|
||||
}
|
||||
|
||||
function wiki_save_page($arr) {
|
||||
$pageUrlName = ((array_key_exists('pageUrlName',$arr)) ? $arr['pageUrlName'] : '');
|
||||
$content = ((array_key_exists('content',$arr)) ? purify_html($arr['content']) : '');
|
||||
$resource_id = ((array_key_exists('resource_id',$arr)) ? $arr['resource_id'] : '');
|
||||
$w = wiki_get_wiki($resource_id);
|
||||
if (!$w['path']) {
|
||||
return array('message' => 'Error reading wiki', 'success' => false);
|
||||
}
|
||||
$page_path = $w['path'].'/'.$pageUrlName.'.md';
|
||||
if (is_writable($page_path) === true) {
|
||||
if(!file_put_contents($page_path, $content)) {
|
||||
return array('message' => 'Error writing to page file', 'success' => false);
|
||||
}
|
||||
return array('message' => '', 'success' => true);
|
||||
} else {
|
||||
return array('message' => 'Page file not writable', 'success' => false);
|
||||
}
|
||||
}
|
||||
|
||||
function wiki_delete_page($arr) {
|
||||
$pageUrlName = ((array_key_exists('pageUrlName',$arr)) ? $arr['pageUrlName'] : '');
|
||||
$resource_id = ((array_key_exists('resource_id',$arr)) ? $arr['resource_id'] : '');
|
||||
$w = wiki_get_wiki($resource_id);
|
||||
if (!$w['path']) {
|
||||
return array('message' => 'Error reading wiki', 'success' => false);
|
||||
}
|
||||
$page_path = $w['path'].'/'.$pageUrlName.'.md';
|
||||
if (is_writable($page_path) === true) {
|
||||
if(!unlink($page_path)) {
|
||||
return array('message' => 'Error deleting page file', 'success' => false);
|
||||
}
|
||||
return array('message' => '', 'success' => true);
|
||||
} else {
|
||||
return array('message' => 'Page file not writable', 'success' => false);
|
||||
}
|
||||
}
|
||||
|
||||
function wiki_revert_page($arr) {
|
||||
$pageUrlName = ((array_key_exists('pageUrlName',$arr)) ? $arr['pageUrlName'] : '');
|
||||
$resource_id = ((array_key_exists('resource_id',$arr)) ? $arr['resource_id'] : '');
|
||||
$commitHash = ((array_key_exists('commitHash',$arr)) ? $arr['commitHash'] : null);
|
||||
if (! $commitHash) {
|
||||
return array('content' => $content, 'message' => 'No commit has provided', 'success' => false);
|
||||
}
|
||||
$w = wiki_get_wiki($resource_id);
|
||||
if (!$w['path']) {
|
||||
return array('content' => $content, 'message' => 'Error reading wiki', 'success' => false);
|
||||
}
|
||||
$page_path = $w['path'].'/'.$pageUrlName.'.md';
|
||||
if (is_writable($page_path) === true) {
|
||||
|
||||
$reponame = ((array_key_exists('title', $w['wiki'])) ? urlencode($w['wiki']['title']) : 'repo');
|
||||
if($reponame === '') {
|
||||
$reponame = 'repo';
|
||||
}
|
||||
$git = new GitRepo($observer['xchan_addr'], null, false, $w['wiki']['title'], $w['path']);
|
||||
$content = null;
|
||||
try {
|
||||
$git->setIdentity($observer['xchan_name'], $observer['xchan_addr']);
|
||||
foreach ($git->git->tree($commitHash) as $object) {
|
||||
if ($object['type'] == 'blob' && $object['file'] === $pageUrlName.'.md' ) {
|
||||
$content = $git->git->cat->blob($object['hash']);
|
||||
}
|
||||
}
|
||||
} catch (\PHPGit\Exception\GitException $e) {
|
||||
json_return_and_die(array('content' => $content, 'message' => 'GitRepo error thrown', 'success' => false));
|
||||
}
|
||||
return array('content' => $content, 'message' => '', 'success' => true);
|
||||
} else {
|
||||
return array('content' => $content, 'message' => 'Page file not writable', 'success' => false);
|
||||
}
|
||||
}
|
||||
|
||||
function wiki_git_commit($arr) {
|
||||
$files = ((array_key_exists('files', $arr)) ? $arr['files'] : null);
|
||||
$commit_msg = ((array_key_exists('commit_msg', $arr)) ? $arr['commit_msg'] : 'Repo updated');
|
||||
$resource_id = ((array_key_exists('resource_id', $arr)) ? $arr['resource_id'] : json_return_and_die(array('message' => 'Wiki resource_id required for git commit', 'success' => false)));
|
||||
$observer = ((array_key_exists('observer', $arr)) ? $arr['observer'] : json_return_and_die(array('message' => 'Observer required for git commit', 'success' => false)));
|
||||
$w = wiki_get_wiki($resource_id);
|
||||
if (!$w['path']) {
|
||||
return array('message' => 'Error reading wiki', 'success' => false);
|
||||
}
|
||||
$reponame = ((array_key_exists('title', $w['wiki'])) ? urlencode($w['wiki']['title']) : 'repo');
|
||||
if($reponame === '') {
|
||||
$reponame = 'repo';
|
||||
}
|
||||
$git = new GitRepo($observer['xchan_addr'], null, false, $w['wiki']['title'], $w['path']);
|
||||
try {
|
||||
$git->setIdentity($observer['xchan_name'], $observer['xchan_addr']);
|
||||
if ($files === null) {
|
||||
$options = array('all' => true); // git commit option to include all changes
|
||||
} else {
|
||||
$options = array(); // git commit options
|
||||
foreach ($files as $file) {
|
||||
if (!$git->git->add($file)) { // add specified files to the git repo stage
|
||||
if (!$git->git->reset->hard()) {
|
||||
json_return_and_die(array('message' => 'Error adding file to git stage: ' . $file . '. Error resetting git repo.', 'success' => false));
|
||||
}
|
||||
json_return_and_die(array('message' => 'Error adding file to git stage: ' . $file, 'success' => false));
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($git->commit($commit_msg, $options)) {
|
||||
json_return_and_die(array('message' => 'Wiki repo commit succeeded', 'success' => true));
|
||||
} else {
|
||||
json_return_and_die(array('message' => 'Wiki repo commit failed', 'success' => false));
|
||||
}
|
||||
} catch (\PHPGit\Exception\GitException $e) {
|
||||
json_return_and_die(array('message' => 'GitRepo error thrown', 'success' => false));
|
||||
}
|
||||
}
|
||||
|
||||
function wiki_generate_page_filename($name) {
|
||||
$file = urlencode(escape_tags($name));
|
||||
if( $file === '') {
|
||||
return null;
|
||||
} else {
|
||||
return $file . '.md';
|
||||
}
|
||||
}
|
||||
120
include/zot.php
120
include/zot.php
@@ -329,8 +329,12 @@ function zot_refresh($them, $channel = null, $force = false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$token = random_string();
|
||||
|
||||
$postvars = array();
|
||||
|
||||
$postvars['token'] = $token;
|
||||
|
||||
if($channel) {
|
||||
$postvars['target'] = $channel['channel_guid'];
|
||||
$postvars['target_sig'] = $channel['channel_guid_sig'];
|
||||
@@ -343,9 +347,9 @@ function zot_refresh($them, $channel = null, $force = false) {
|
||||
$postvars['guid_hash'] = $them['xchan_hash'];
|
||||
if (array_key_exists('xchan_guid',$them) && $them['xchan_guid']
|
||||
&& array_key_exists('xchan_guid_sig',$them) && $them['xchan_guid_sig']) {
|
||||
|
||||
$postvars['guid'] = $them['xchan_guid'];
|
||||
$postvars['guid_sig'] = $them['xchan_guid_sig'];
|
||||
|
||||
}
|
||||
|
||||
$rhs = '/.well-known/zot-info';
|
||||
@@ -363,6 +367,22 @@ function zot_refresh($them, $channel = null, $force = false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$signed_token = ((is_array($j) && array_key_exists('signed_token',$j)) ? $j['signed_token'] : null);
|
||||
if($signed_token) {
|
||||
$valid = rsa_verify('token.' . $token,base64url_decode($signed_token),$j['key']);
|
||||
if(! $valid) {
|
||||
logger('invalid signed token: ' . $url . $rhs, LOGGER_NORMAL, LOG_ERR);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
logger('No signed token from ' . $url . $rhs, LOGGER_NORMAL, LOG_WARNING);
|
||||
// after 2017-01-01 this will be a hard error unless you over-ride it.
|
||||
if((time() > 1483228800) && (! get_config('system','allow_unsigned_zotfinger'))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$x = import_xchan($j, (($force) ? UPDATE_FLAGS_FORCED : UPDATE_FLAGS_UPDATED));
|
||||
|
||||
if(! $x['success'])
|
||||
@@ -453,7 +473,7 @@ function zot_refresh($them, $channel = null, $force = false) {
|
||||
else {
|
||||
// if we were just granted read stream permission and didn't have it before, try to pull in some posts
|
||||
if((! ($r[0]['abook_their_perms'] & PERMS_R_STREAM)) && ($their_perms & PERMS_R_STREAM))
|
||||
proc_run('php','include/onepoll.php',$r[0]['abook_id']);
|
||||
Zotlabs\Daemon\Master::Summon(array('Onepoll',$r[0]['abook_id']));
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -504,9 +524,8 @@ function zot_refresh($them, $channel = null, $force = false) {
|
||||
|
||||
if($new_connection) {
|
||||
if($new_perms != $previous_perms)
|
||||
proc_run('php','include/notifier.php','permission_create',$new_connection[0]['abook_id']);
|
||||
require_once('include/enotify.php');
|
||||
notification(array(
|
||||
Zotlabs\Daemon\Master::Summon(array('Notifier','permission_create',$new_connection[0]['abook_id']));
|
||||
Zotlabs\Lib\Enotify::submit(array(
|
||||
'type' => NOTIFY_INTRO,
|
||||
'from_xchan' => $x['hash'],
|
||||
'to_xchan' => $channel['channel_hash'],
|
||||
@@ -516,7 +535,17 @@ function zot_refresh($them, $channel = null, $force = false) {
|
||||
if($their_perms & PERMS_R_STREAM) {
|
||||
if(($channel['channel_w_stream'] & PERMS_PENDING)
|
||||
|| (! intval($new_connection[0]['abook_pending'])) )
|
||||
proc_run('php','include/onepoll.php',$new_connection[0]['abook_id']);
|
||||
Zotlabs\Daemon\Master::Summon(array('Onepoll',$new_connection[0]['abook_id']));
|
||||
}
|
||||
|
||||
|
||||
/** If there is a default group for this channel, add this connection to it */
|
||||
$default_group = $channel['channel_default_group'];
|
||||
if($default_group) {
|
||||
require_once('include/group.php');
|
||||
$g = group_rec_byhash($channel['channel_id'],$default_group);
|
||||
if($g)
|
||||
group_add_member($channel['channel_id'],'',$x['hash'],$g['id']);
|
||||
}
|
||||
|
||||
unset($new_connection[0]['abook_id']);
|
||||
@@ -1027,8 +1056,9 @@ function zot_process_response($hub, $arr, $outq) {
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* We received a notification packet (in mod/post.php) that a message is waiting for us, and we've verified the sender.
|
||||
* Now send back a pickup message, using our message tracking ID ($arr['secret']), which we will sign with our site private key.
|
||||
* We received a notification packet (in mod_post) that a message is waiting for us, and we've verified the sender.
|
||||
* Now send back a pickup message, using our message tracking ID ($arr['secret']), which we will sign with our site
|
||||
* private key.
|
||||
* The entire pickup message is encrypted with the remote site's public key.
|
||||
* If everything checks out on the remote end, we will receive back a packet containing one or more messages,
|
||||
* which will be processed and delivered before this function ultimately returns.
|
||||
@@ -1102,6 +1132,7 @@ function zot_fetch($arr) {
|
||||
* * [1] => \e string $delivery_status
|
||||
* * [2] => \e string $address
|
||||
*/
|
||||
|
||||
function zot_import($arr, $sender_url) {
|
||||
|
||||
$data = json_decode($arr['body'], true);
|
||||
@@ -1332,7 +1363,7 @@ function zot_import($arr, $sender_url) {
|
||||
*/
|
||||
function public_recips($msg) {
|
||||
|
||||
require_once('include/identity.php');
|
||||
require_once('include/channel.php');
|
||||
|
||||
$check_mentions = false;
|
||||
$include_sys = false;
|
||||
@@ -1494,7 +1525,7 @@ function public_recips($msg) {
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* This is the second part of public_recipes().
|
||||
* This is the second part of public_recips().
|
||||
* We'll find all the channels willing to accept public posts from us, then
|
||||
* match them against the sender privacy scope and see who in that list that
|
||||
* the sender is allowing.
|
||||
@@ -1703,7 +1734,7 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $
|
||||
|
||||
if((! $relay) && (! $request) && (! $local_public)
|
||||
&& perm_is_allowed($channel['channel_id'],$sender['hash'],'send_stream')) {
|
||||
proc_run('php', 'include/notifier.php', 'request', $channel['channel_id'], $sender['hash'], $arr['parent_mid']);
|
||||
Zotlabs\Daemon\Master::Summon(array('Notifier', 'request', $channel['channel_id'], $sender['hash'], $arr['parent_mid']));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -1775,7 +1806,7 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $
|
||||
|
||||
if($relay && $item_id) {
|
||||
logger('process_delivery: invoking relay');
|
||||
proc_run('php','include/notifier.php','relay',intval($item_id));
|
||||
Zotlabs\Daemon\Master::Summon(array('Notifier','relay',intval($item_id)));
|
||||
$DR->update('relayed');
|
||||
$result[] = $DR->get();
|
||||
}
|
||||
@@ -1858,7 +1889,7 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $
|
||||
|
||||
if($relay && $item_id) {
|
||||
logger('process_delivery: invoking relay');
|
||||
proc_run('php','include/notifier.php','relay',intval($item_id));
|
||||
Zotlabs\Daemon\Master::Summon(array('Notifier','relay',intval($item_id)));
|
||||
$DR->addto_update('relayed');
|
||||
$result[] = $DR->get();
|
||||
}
|
||||
@@ -1932,7 +1963,7 @@ function remove_community_tag($sender, $arr, $uid) {
|
||||
return;
|
||||
}
|
||||
|
||||
q("delete from term where uid = %d and oid = %d and otype = %d and type in ( %d, %d ) and term = '%s' and url = '%s'",
|
||||
q("delete from term where uid = %d and oid = %d and otype = %d and ttype in ( %d, %d ) and term = '%s' and url = '%s'",
|
||||
intval($uid),
|
||||
intval($r[0]['id']),
|
||||
intval(TERM_OBJ_POST),
|
||||
@@ -2381,11 +2412,14 @@ function sync_locations($sender, $arr, $absolute = false) {
|
||||
|
||||
$current_site = false;
|
||||
|
||||
$t = datetime_convert('UTC','UTC','now - 15 minutes');
|
||||
|
||||
if(array_key_exists('site',$arr) && $location['url'] == $arr['site']['url']) {
|
||||
q("update hubloc set hubloc_connected = '%s', hubloc_updated = '%s' where hubloc_id = %d",
|
||||
q("update hubloc set hubloc_connected = '%s', hubloc_updated = '%s' where hubloc_id = %d and hubloc_connected < '%s'",
|
||||
dbesc(datetime_convert()),
|
||||
dbesc(datetime_convert()),
|
||||
intval($r[0]['hubloc_id'])
|
||||
intval($r[0]['hubloc_id']),
|
||||
dbesc($t)
|
||||
);
|
||||
$current_site = true;
|
||||
}
|
||||
@@ -2945,8 +2979,6 @@ function build_sync_packet($uid = 0, $packet = null, $groups_changed = false) {
|
||||
if(UNO)
|
||||
return;
|
||||
|
||||
$a = get_app();
|
||||
|
||||
logger('build_sync_packet');
|
||||
|
||||
if($packet)
|
||||
@@ -3029,7 +3061,7 @@ function build_sync_packet($uid = 0, $packet = null, $groups_changed = false) {
|
||||
}
|
||||
|
||||
if($groups_changed) {
|
||||
$r = q("select hash as collection, visible, deleted, name from groups where uid = %d",
|
||||
$r = q("select hash as collection, visible, deleted, gname as name from groups where uid = %d",
|
||||
intval($uid)
|
||||
);
|
||||
if($r)
|
||||
@@ -3060,7 +3092,7 @@ function build_sync_packet($uid = 0, $packet = null, $groups_changed = false) {
|
||||
'msg' => json_encode($info)
|
||||
));
|
||||
|
||||
proc_run('php', 'include/deliver.php', $hash);
|
||||
Zotlabs\Daemon\Master::Summon(array('Deliver', $hash));
|
||||
$total = $total - 1;
|
||||
|
||||
if($interval && $total)
|
||||
@@ -3222,7 +3254,6 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) {
|
||||
$clean = array();
|
||||
if($abook['abook_xchan'] && $abook['entry_deleted']) {
|
||||
logger('process_channel_sync_delivery: removing abook entry for ' . $abook['abook_xchan']);
|
||||
require_once('include/Contact.php');
|
||||
|
||||
$r = q("select abook_id, abook_feed from abook where abook_xchan = '%s' and abook_channel = %d and abook_self = 0 limit 1",
|
||||
dbesc($abook['abook_xchan']),
|
||||
@@ -3323,10 +3354,10 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) {
|
||||
}
|
||||
}
|
||||
if($found) {
|
||||
if(($y['name'] != $cl['name'])
|
||||
if(($y['gname'] != $cl['name'])
|
||||
|| ($y['visible'] != $cl['visible'])
|
||||
|| ($y['deleted'] != $cl['deleted'])) {
|
||||
q("update groups set name = '%s', visible = %d, deleted = %d where hash = '%s' and uid = %d",
|
||||
q("update groups set gname = '%s', visible = %d, deleted = %d where hash = '%s' and uid = %d",
|
||||
dbesc($cl['name']),
|
||||
intval($cl['visible']),
|
||||
intval($cl['deleted']),
|
||||
@@ -3342,7 +3373,7 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) {
|
||||
}
|
||||
}
|
||||
if(! $found) {
|
||||
$r = q("INSERT INTO `groups` ( hash, uid, visible, deleted, name )
|
||||
$r = q("INSERT INTO `groups` ( hash, uid, visible, deleted, gname )
|
||||
VALUES( '%s', %d, %d, %d, '%s' ) ",
|
||||
dbesc($cl['collection']),
|
||||
intval($channel['channel_id']),
|
||||
@@ -3449,7 +3480,7 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) {
|
||||
|
||||
if(array_key_exists('profile',$arr) && is_array($arr['profile']) && count($arr['profile'])) {
|
||||
|
||||
$disallowed = array('id','aid','uid');
|
||||
$disallowed = array('id','aid','uid','guid');
|
||||
|
||||
foreach($arr['profile'] as $profile) {
|
||||
$x = q("select * from profile where profile_guid = '%s' and uid = %d limit 1",
|
||||
@@ -3473,13 +3504,22 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) {
|
||||
foreach($profile as $k => $v) {
|
||||
if(in_array($k,$disallowed))
|
||||
continue;
|
||||
|
||||
if($k === 'name')
|
||||
$clean['fullname'] = $v;
|
||||
elseif($k === 'with')
|
||||
$clean['partner'] = $v;
|
||||
elseif($k === 'work')
|
||||
$clean['employment'] = $v;
|
||||
elseif(array_key_exists($k,$x[0]))
|
||||
$clean[$k] = $v;
|
||||
|
||||
$clean[$k] = $v;
|
||||
/**
|
||||
* @TODO check if these are allowed, otherwise we'll error
|
||||
* @TODO
|
||||
* We also need to import local photos if a custom photo is selected
|
||||
*/
|
||||
}
|
||||
|
||||
if(count($clean)) {
|
||||
foreach($clean as $k => $v) {
|
||||
$r = dbq("UPDATE profile set `" . dbesc($k) . "` = '" . dbesc($v)
|
||||
@@ -3652,7 +3692,7 @@ function zot_reply_message_request($data) {
|
||||
* invoke delivery to send out the notify packet
|
||||
*/
|
||||
|
||||
proc_run('php', 'include/deliver.php', $hash);
|
||||
Zotlabs\Daemon\Master::Summon(array('Deliver', $hash));
|
||||
}
|
||||
}
|
||||
$ret['success'] = true;
|
||||
@@ -3672,6 +3712,8 @@ function zotinfo($arr) {
|
||||
$zsig = ((x($arr,'target_sig')) ? $arr['target_sig'] : '');
|
||||
$zkey = ((x($arr,'key')) ? $arr['key'] : '');
|
||||
$mindate = ((x($arr,'mindate')) ? $arr['mindate'] : '');
|
||||
$token = ((x($arr,'token')) ? $arr['token'] : '');
|
||||
|
||||
$feed = ((x($arr,'feed')) ? intval($arr['feed']) : 0);
|
||||
|
||||
if($ztarget) {
|
||||
@@ -3816,6 +3858,10 @@ function zotinfo($arr) {
|
||||
|
||||
// Communication details
|
||||
|
||||
if($token)
|
||||
$ret['signed_token'] = base64url_encode(rsa_sign('token.' . $token,$e['channel_prvkey']));
|
||||
|
||||
|
||||
$ret['guid'] = $e['xchan_guid'];
|
||||
$ret['guid_sig'] = $e['xchan_guid_sig'];
|
||||
$ret['key'] = $e['xchan_pubkey'];
|
||||
@@ -3920,16 +3966,14 @@ function zotinfo($arr) {
|
||||
|
||||
$ret['site']['accounts'] = account_total();
|
||||
|
||||
require_once('include/identity.php');
|
||||
require_once('include/channel.php');
|
||||
$ret['site']['channels'] = channel_total();
|
||||
|
||||
|
||||
$ret['site']['version'] = Zotlabs\Project\System::get_platform_name() . ' ' . STD_VERSION . '[' . DB_UPDATE_VERSION . ']';
|
||||
$ret['site']['version'] = Zotlabs\Lib\System::get_platform_name() . ' ' . STD_VERSION . '[' . DB_UPDATE_VERSION . ']';
|
||||
|
||||
$ret['site']['admin'] = get_config('system','admin_email');
|
||||
|
||||
$a = get_app();
|
||||
|
||||
$visible_plugins = array();
|
||||
if(is_array(App::$plugins) && count(App::$plugins)) {
|
||||
$r = q("select * from addon where hidden = 0");
|
||||
@@ -3944,7 +3988,7 @@ function zotinfo($arr) {
|
||||
$ret['site']['sellpage'] = get_config('system','sellpage');
|
||||
$ret['site']['location'] = get_config('system','site_location');
|
||||
$ret['site']['realm'] = get_directory_realm();
|
||||
$ret['site']['project'] = Zotlabs\Project\System::get_platform_name();
|
||||
$ret['site']['project'] = Zotlabs\Lib\System::get_platform_name() . ' ' . Zotlabs\Lib\System::get_server_role();
|
||||
|
||||
}
|
||||
|
||||
@@ -4103,7 +4147,7 @@ function update_hub_connected($hub,$sitekey = '') {
|
||||
$sitekey = $hub['sitekey'];
|
||||
}
|
||||
|
||||
// $sender['sitekey'] is a new addition to the protcol to distinguish
|
||||
// $sender['sitekey'] is a new addition to the protocol to distinguish
|
||||
// hublocs coming from re-installed sites. Older sites will not provide
|
||||
// this field and we have to still mark them valid, since we can't tell
|
||||
// if this hubloc has the same sitekey as the packet we received.
|
||||
@@ -4112,10 +4156,13 @@ function update_hub_connected($hub,$sitekey = '') {
|
||||
// Update our DB to show when we last communicated successfully with this hub
|
||||
// This will allow us to prune dead hubs from using up resources
|
||||
|
||||
$r = q("update hubloc set hubloc_connected = '%s' where hubloc_id = %d and hubloc_sitekey = '%s' ",
|
||||
$t = datetime_convert('UTC','UTC','now - 15 minutes');
|
||||
|
||||
$r = q("update hubloc set hubloc_connected = '%s' where hubloc_id = %d and hubloc_sitekey = '%s' and hubloc_connected < '%s' ",
|
||||
dbesc(datetime_convert()),
|
||||
intval($hub['hubloc_id']),
|
||||
dbesc($sitekey)
|
||||
dbesc($sitekey),
|
||||
dbesc($t)
|
||||
);
|
||||
|
||||
// a dead hub came back to life - reset any tombstones we might have
|
||||
@@ -4415,7 +4462,6 @@ function zot_reply_purge($sender,$recipients) {
|
||||
$arr = $sender;
|
||||
$sender_hash = make_xchan_hash($arr['guid'],$arr['guid_sig']);
|
||||
|
||||
require_once('include/Contact.php');
|
||||
remove_all_xchan_resources($sender_hash);
|
||||
|
||||
$ret['success'] = true;
|
||||
|
||||
Reference in New Issue
Block a user