aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG7
-rw-r--r--Zotlabs/Module/Api.php16
-rw-r--r--Zotlabs/Module/Import.php50
-rw-r--r--Zotlabs/Module/Profiles.php6
-rw-r--r--include/api.php1291
-rw-r--r--include/api_zot.php336
-rw-r--r--include/bbcode.php4
-rwxr-xr-xinclude/dba/dba_driver.php9
-rw-r--r--include/dba/dba_postgres.php1
-rw-r--r--include/import.php112
-rwxr-xr-xinclude/items.php14
-rw-r--r--include/network.php19
-rw-r--r--include/photo/photo_driver.php100
-rw-r--r--include/text.php2
-rw-r--r--include/zot.php5
-rw-r--r--view/js/main.js1
-rw-r--r--view/js/mod_connections.js12
17 files changed, 957 insertions, 1028 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 9e06fb7a1..53d8a0f2e 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,4 +1,5 @@
-Hubzilla 1.14RC (2016-10-02)
+Hubzilla 1.14 (2016-10-13)
+ - New hook bbcode_filter
- Unify the various mail sending instance to enotify::send() and z_mail()
- Provide ability for admin to change account password
- Replace deprecated Sabre functions
@@ -38,6 +39,9 @@ Hubzilla 1.14RC (2016-10-02)
- Server roles (basic, standard and pro)
Bugfixes
+ - Fix connected time not shown on ajax loaded connections
+ - API issues
+ - Fix readmore.js collapsing on scrolldirection change in some mobile browsers
- Personalize Server Emails
- Audio player doesn't automatically show for m4a files
- Fix ajax page update with /channel?f=&mid=hash
@@ -65,6 +69,7 @@ Hubzilla 1.14RC (2016-10-02)
- Public forum check with custom/expert permissions
Plugins
+ - Standard Embed: update to convert old corporate bbcodes
- Cdav security: fix rw permission check
- Cdav: add partial support for recurring events in the browser client (editing/creating is not implemented)
- New plugin phpmailer: use phpmailer class instead of php's built-in mail() function
diff --git a/Zotlabs/Module/Api.php b/Zotlabs/Module/Api.php
index 4fd59acc4..0f2ca1e47 100644
--- a/Zotlabs/Module/Api.php
+++ b/Zotlabs/Module/Api.php
@@ -17,13 +17,13 @@ class Api extends \Zotlabs\Web\Controller {
function get() {
- if(\App::$cmd=='api/oauth/authorize'){
+ if(\App::$cmd === 'api/oauth/authorize'){
/*
* api/oauth/authorize interact with the user. return a standard page
*/
- \App::$page['template'] = "minimal";
+ \App::$page['template'] = 'minimal';
// get consumer/client from request token
try {
@@ -42,8 +42,8 @@ class Api extends \Zotlabs\Web\Controller {
$consumer = new OAuth1Consumer($app['client_id'], $app['pw'], $app['redirect_uri']);
- $verifier = md5($app['secret'].local_channel());
- set_config("oauth", $verifier, local_channel());
+ $verifier = md5($app['secret'] . local_channel());
+ set_config('oauth', $verifier, local_channel());
if($consumer->callback_url != null) {
@@ -78,11 +78,11 @@ class Api extends \Zotlabs\Web\Controller {
$tpl = get_markup_template('oauth_authorize.tpl');
$o = replace_macros($tpl, array(
- '$title' => t('Authorize application connection'),
- '$app' => $app,
+ '$title' => t('Authorize application connection'),
+ '$app' => $app,
'$authorize' => t('Do you want to authorize this application to access your posts and contacts, and/or create new posts for you?'),
- '$yes' => t('Yes'),
- '$no' => t('No'),
+ '$yes' => t('Yes'),
+ '$no' => t('No'),
));
//echo "<pre>"; var_dump($app); killme();
diff --git a/Zotlabs/Module/Import.php b/Zotlabs/Module/Import.php
index 9574de07c..bf47f2e4c 100644
--- a/Zotlabs/Module/Import.php
+++ b/Zotlabs/Module/Import.php
@@ -77,23 +77,27 @@ class Import extends \Zotlabs\Web\Controller {
$channelname = substr($old_address,0,strpos($old_address,'@'));
$servername = substr($old_address,strpos($old_address,'@')+1);
-
- $scheme = 'https://';
- $api_path = '/api/red/channel/export/basic?f=&channel=' . $channelname;
+
+ $api_path = probe_api_path($servername);
+ if(! $api_path) {
+ notice( t('Unable to download data from old server') . EOL);
+ return;
+ }
+
+ $api_path .= 'channel/export/basic?f=&channel=' . $channelname;
if($import_posts)
$api_path .= '&posts=1';
$binary = false;
$redirects = 0;
$opts = array('http_auth' => $email . ':' . $password);
- $url = $scheme . $servername . $api_path;
- $ret = z_fetch_url($url, $binary, $redirects, $opts);
- if(! $ret['success'])
- $ret = z_fetch_url('http://' . $servername . $api_path, $binary, $redirects, $opts);
- if($ret['success'])
+ $ret = z_fetch_url($api_path, $binary, $redirects, $opts);
+ if($ret['success']) {
$data = $ret['body'];
- else
+ }
+ else {
notice( t('Unable to download data from old server') . EOL);
-
+ return;
+ }
}
if(! $data) {
@@ -297,9 +301,9 @@ class Import extends \Zotlabs\Web\Controller {
dbesc_array($xchan);
- $r = dbq("INSERT INTO xchan (`"
- . implode("`, `", array_keys($xchan))
- . "`) VALUES ('"
+ $r = dbq("INSERT INTO xchan (" . TQUOT
+ . implode(TQUOT . ", " . TQUOT, array_keys($xchan))
+ . TQUOT . ") VALUES ('"
. implode("', '", array_values($xchan))
. "')" );
@@ -383,9 +387,9 @@ class Import extends \Zotlabs\Web\Controller {
}
dbesc_array($abook);
- $r = dbq("INSERT INTO abook (`"
- . implode("`, `", array_keys($abook))
- . "`) VALUES ('"
+ $r = dbq("INSERT INTO abook (" . TQUOT
+ . implode(TQUOT . ", " . TQUOT, array_keys($abook))
+ . TQUOT . ") VALUES ('"
. implode("', '", array_values($abook))
. "')" );
@@ -425,13 +429,13 @@ class Import extends \Zotlabs\Web\Controller {
unset($group['id']);
$group['uid'] = $channel['channel_id'];
dbesc_array($group);
- $r = dbq("INSERT INTO groups (`"
- . implode("`, `", array_keys($group))
- . "`) VALUES ('"
+ $r = dbq("INSERT INTO groups (" . TQUOT
+ . implode(TQUOT . ", " . TQUOT, array_keys($group))
+ . TQUOT . ") VALUES ('"
. implode("', '", array_values($group))
. "')" );
}
- $r = q("select * from `groups` where uid = %d",
+ $r = q("select * from groups where uid = %d",
intval($channel['channel_id'])
);
if($r) {
@@ -452,9 +456,9 @@ class Import extends \Zotlabs\Web\Controller {
$group_member['gid'] = $x['new'];
}
dbesc_array($group_member);
- $r = dbq("INSERT INTO group_member (`"
- . implode("`, `", array_keys($group_member))
- . "`) VALUES ('"
+ $r = dbq("INSERT INTO group_member (" . TQUOT
+ . implode(TQUOT . ", " . TQUOT, array_keys($group_member))
+ . TQUOT . ") VALUES ('"
. implode("', '", array_values($group_member))
. "')" );
}
diff --git a/Zotlabs/Module/Profiles.php b/Zotlabs/Module/Profiles.php
index 4cb8e7395..6f76cd1cf 100644
--- a/Zotlabs/Module/Profiles.php
+++ b/Zotlabs/Module/Profiles.php
@@ -119,9 +119,9 @@ class Profiles extends \Zotlabs\Web\Controller {
dbesc_array($r1[0]);
- $r2 = dbq("INSERT INTO profile (`"
- . implode("`, `", array_keys($r1[0]))
- . "`) VALUES ('"
+ $r2 = dbq("INSERT INTO profile (" . TQUOT
+ . implode(TQUOT . ", " . TQUOT, array_keys($r1[0]))
+ . TQUOT . ") VALUES ('"
. implode("', '", array_values($r1[0]))
. "')" );
diff --git a/include/api.php b/include/api.php
index a2ca587a1..53db2b2a3 100644
--- a/include/api.php
+++ b/include/api.php
@@ -10,6 +10,7 @@ require_once('include/photos.php');
require_once('include/items.php');
require_once('include/attach.php');
require_once('include/api_auth.php');
+require_once('include/api_zot.php');
/*
*
@@ -49,7 +50,7 @@ require_once('include/api_auth.php');
return false;
}
}
- if ($_SESSION["allow_api"])
+ if ($_SESSION['allow_api'])
return local_channel();
return false;
}
@@ -57,11 +58,11 @@ require_once('include/api_auth.php');
function api_date($str){
//Wed May 23 06:01:13 +0000 2007
- return datetime_convert('UTC', 'UTC', $str, "D M d H:i:s +0000 Y" );
+ return datetime_convert('UTC', 'UTC', $str, 'D M d H:i:s +0000 Y' );
}
- function api_register_func($path, $func, $auth=false) {
+ function api_register_func($path, $func, $auth = false) {
\Zotlabs\Lib\Api_router::register($path,$func,$auth);
}
@@ -90,7 +91,12 @@ require_once('include/api_auth.php');
$info = \Zotlabs\Lib\Api_router::find($p);
- logger('info: ' . $p . ' type: ' . $type . ' ' . print_r($info,true));
+ if(in_array($type, [ 'rss', 'atom', 'as' ])) {
+ // These types no longer supported.
+ $info = false;
+ }
+
+ logger('API info: ' . $p . ' type: ' . $type . ' ' . print_r($info,true), LOGGER_DEBUG,LOG_INFO);
if($info) {
@@ -111,96 +117,53 @@ require_once('include/api_auth.php');
return;
switch($type) {
- case "xml":
- $r = mb_convert_encoding($r, "UTF-8",mb_detect_encoding($r));
- header ("Content-Type: text/xml");
- return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
+ case 'xml':
+ header ('Content-Type: text/xml');
+ return $r;
break;
- case "json":
- header ("Content-Type: application/json");
- if($r) {
- foreach($r as $rv) {
- $json = json_encode($rv);
- }
- }
+ case 'json':
+ header ('Content-Type: application/json');
// Lookup JSONP to understand these lines. They provide cross-domain AJAX ability.
if ($_GET['callback'])
- $json = $_GET['callback'] . '(' . $json . ')' ;
- return $json;
- break;
- case "rss":
- header ("Content-Type: application/rss+xml");
- return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
- break;
- case "atom":
- header ("Content-Type: application/atom+xml");
- return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
- break;
- case "as":
- if($r) {
- foreach($r as $rv) {
- $json = json_encode($rv);
- }
- }
- return $json;
+ $r = $_GET['callback'] . '(' . $r . ')' ;
+ return $r;
break;
-
}
}
- header("HTTP/1.1 404 Not Found");
+ header('HTTP/1.1 404 Not Found');
logger('API call not implemented: ' . App::$query_string . ' - ' . print_r($_REQUEST,true));
$r = '<status><error>not implemented</error></status>';
switch($type){
- case "xml":
- header ("Content-Type: text/xml");
- return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
+ case 'xml':
+ header ('Content-Type: text/xml');
+ return '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . $r;
break;
case "json":
- header ("Content-Type: application/json");
+ header ('Content-Type: application/json');
return json_encode(array('error' => 'not implemented'));
break;
case "rss":
- header ("Content-Type: application/rss+xml");
- return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
+ header ('Content-Type: application/rss+xml');
+ return '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . $r;
break;
case "atom":
- header ("Content-Type: application/atom+xml");
- return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
+ header ('Content-Type: application/atom+xml');
+ return '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . $r;
break;
}
}
/**
- * RSS extra info
- */
-
- function api_rss_extra( $arr, $user_info){
- if (is_null($user_info)) $user_info = api_get_user($a);
- $arr['$user'] = $user_info;
- $arr['$rss'] = array(
- 'alternate' => $user_info['url'],
- 'self' => z_root(). "/". App::$query_string,
- 'base' => z_root(),
- 'updated' => api_date(null),
- 'atom_updated' => datetime_convert('UTC','UTC','now',ATOM_TIME),
- 'language' => $user_info['language'],
- 'logo' => z_root()."/images/rm-64.png",
- );
-
- return $arr;
- }
-
- /**
* Returns user info array.
*/
- function api_get_user( $contact_id = null, $contact_xchan = null){
+ function api_get_user($contact_id = null, $contact_xchan = null){
$user = null;
- $extra_query = "";
+ $extra_query = '';
if(! is_null($contact_xchan)) {
@@ -208,8 +171,8 @@ require_once('include/api_auth.php');
$extra_query = " and abook_xchan = '" . dbesc($contact_xchan) . "' ";
}
else {
- if(!is_null($contact_id)){
- $user=$contact_id;
+ if(! is_null($contact_id)){
+ $user = $contact_id;
$extra_query = " AND abook_id = %d ";
}
@@ -220,8 +183,8 @@ require_once('include/api_auth.php');
if(is_null($user) && x($_GET, 'screen_name')) {
$user = dbesc($_GET['screen_name']);
$extra_query = " AND xchan_addr like '%s@%%' ";
- if (api_user()!==false)
- $extra_query .= " AND abook_channel = ".intval(api_user());
+ if(api_user() !== false)
+ $extra_query .= " AND abook_channel = " . intval(api_user());
}
}
@@ -241,14 +204,15 @@ require_once('include/api_auth.php');
// user info
$uinfo = q("SELECT * from abook left join xchan on abook_xchan = xchan_hash
- WHERE 1
+ WHERE true
$extra_query",
$user
);
- if (count($uinfo)==0) {
- return False;
+ if (! $uinfo) {
+ return false;
}
+
$following = false;
if(intval($uinfo[0]['abook_self'])) {
@@ -265,49 +229,53 @@ require_once('include/api_auth.php');
$r = q("SELECT COUNT(id) as total FROM item
WHERE uid = %d
AND item_wall = 1 $item_normal
- AND allow_cid='' AND allow_gid='' AND deny_cid='' AND deny_gid=''
+ AND allow_cid = '' AND allow_gid = '' AND deny_cid = '' AND deny_gid = ''
AND item_private = 0 ",
intval($usr[0]['channel_id'])
);
- $countitms = $r[0]['total'];
- $following = true;
+ if($r) {
+ $countitms = $r[0]['total'];
+ $following = true;
+ }
}
else {
$r = q("SELECT COUNT(id) as total FROM item
WHERE author_xchan = '%s'
- AND allow_cid='' AND allow_gid='' AND deny_cid='' AND deny_gid=''
+ AND allow_cid = '' AND allow_gid = '' AND deny_cid = '' AND deny_gid = ''
AND item_private = 0 ",
intval($uinfo[0]['xchan_hash'])
);
- $countitms = $r[0]['total'];
-
+ if($r) {
+ $countitms = $r[0]['total'];
+ }
$following = ((get_abconfig($uinfo[0]['abook_channel'],$uinfo[0]['abook_xchan'],'my_perms','view_stream')) ? true : false );
}
-
// count friends
if($usr) {
$r = q("SELECT COUNT(abook_id) as total FROM abook
WHERE abook_channel = %d AND abook_self = 0 ",
intval($usr[0]['channel_id'])
);
- $countfriends = $r[0]['total'];
- $countfollowers = $r[0]['total'];
+ if($r) {
+ $countfriends = $r[0]['total'];
+ $countfollowers = $r[0]['total'];
+ }
}
$r = q("SELECT count(id) as total FROM item where item_starred = 1 and uid = %d " . item_normal(),
intval($uinfo[0]['channel_id'])
);
- $starred = $r[0]['total'];
+ if($r)
+ $starred = $r[0]['total'];
-
if(! intval($uinfo[0]['abook_self'])) {
$countfriends = 0;
$countfollowers = 0;
$starred = 0;
}
- $ret = Array(
+ $ret = array(
'id' => intval($uinfo[0]['abook_id']),
'self' => (intval($uinfo[0]['abook_self']) ? 1 : 0),
'uid' => intval($uinfo[0]['abook_channel']),
@@ -317,11 +285,11 @@ require_once('include/api_auth.php');
'location' => ($usr) ? $usr[0]['channel_location'] : '',
'profile_image_url' => $uinfo[0]['xchan_photo_l'],
'url' => $uinfo[0]['xchan_url'],
- 'contact_url' => z_root() . "/connections/".$uinfo[0]['abook_id'],
+ 'contact_url' => z_root() . '/connections/'.$uinfo[0]['abook_id'],
'protected' => false,
'friends_count' => intval($countfriends),
'created_at' => api_date($uinfo[0]['abook_created']),
- 'utc_offset' => "+00:00",
+ 'utc_offset' => '+00:00',
'time_zone' => 'UTC', //$uinfo[0]['timezone'],
'geo_enabled' => false,
'statuses_count' => intval($countitms), //#XXX: fix me
@@ -347,6 +315,7 @@ require_once('include/api_auth.php');
$x = api_get_status($uinfo[0]['xchan_hash']);
if($x)
$ret['status'] = $x;
+
// logger('api_get_user: ' . print_r($ret,true));
return $ret;
@@ -447,19 +416,23 @@ require_once('include/api_auth.php');
/**
* load api $templatename for $type and replace $data array
*/
+
function api_apply_template($templatename, $type, $data){
switch($type){
- case "atom":
- case "rss":
- case "xml":
- $data = array_xmlify($data);
- $tpl = get_markup_template("api_".$templatename."_".$type.".tpl");
- $ret = replace_macros($tpl, $data);
+ case 'xml':
+ if($data) {
+ foreach($data as $k => $v)
+ $ret = arrtoxml(str_replace('$','',$k),$v);
+ }
break;
- case "json":
+ case 'json':
default:
- $ret = $data;
+ if($data) {
+ foreach($data as $rv) {
+ $ret = json_encode($rv);
+ }
+ }
break;
}
@@ -472,22 +445,23 @@ require_once('include/api_auth.php');
* returns a 401 status code and an error message if not.
* http://developer.twitter.com/doc/get/account/verify_credentials
*/
- function api_account_verify_credentials( $type){
- if (api_user()===false) return false;
- $user_info = api_get_user($a);
- return api_apply_template("user", $type, array('$user' => $user_info));
-
+ function api_account_verify_credentials($type){
+ if(api_user()===false)
+ return false;
+ $user_info = api_get_user();
+ return api_apply_template('user', $type, array('user' => $user_info));
}
api_register_func('api/account/verify_credentials','api_account_verify_credentials', true);
+ api_register_func('api/1.1/account/verify_credentials','api_account_verify_credentials', true);
function api_account_logout( $type){
require_once('include/auth.php');
App::$session->nuke();
- return api_apply_template("user", $type, array('$user' => null));
-
+ return api_apply_template('user', $type, array('user' => null));
}
api_register_func('api/account/logout','api_account_logout', false);
+ api_register_func('api/1.1/account/logout','api_account_logout', false);
@@ -501,274 +475,13 @@ require_once('include/api_auth.php');
}
- /*
- * Red basic channel export
- */
-
- function api_export_basic( $type) {
- if(api_user() === false) {
- logger('api_export_basic: no user');
- return false;
- }
-
- require_once('include/channel.php');
-
- json_return_and_die(identity_basic_export(api_user(),(($_REQUEST['posts']) ? intval($_REQUEST['posts']) : 0 )));
- }
- api_register_func('api/export/basic','api_export_basic', true);
- api_register_func('api/red/channel/export/basic','api_export_basic', true);
- api_register_func('api/z/1.0/channel/export/basic','api_export_basic', true);
-
-
- function api_channel_stream( $type) {
- if(api_user() === false) {
- logger('api_channel_stream: no user');
- return false;
- }
-
- if($_SERVER['REQUEST_METHOD'] == 'POST') {
- json_return_and_die(post_activity_item($_REQUEST));
- }
- else {
- // fetch stream
-
- }
- }
- api_register_func('api/red/channel/stream','api_channel_stream', true);
- api_register_func('api/z/1.0/channel/stream','api_channel_stream', true);
-
- function api_attach_list($type) {
- logger('api_user: ' . api_user());
- json_return_and_die(attach_list_files(api_user(),get_observer_hash(),'','','','created asc'));
- }
- api_register_func('api/red/files','api_attach_list', true);
- api_register_func('api/z/1.0/files','api_attach_list', true);
-
-
- function api_file_meta($type) {
- if (api_user()===false) return false;
- if(! $_REQUEST['file_id']) return false;
- $r = q("select * from attach where uid = %d and hash = '%s' limit 1",
- intval(api_user()),
- dbesc($_REQUEST['file_id'])
- );
- if($r) {
- unset($r[0]['content']);
- $ret = array('attach' => $r[0]);
- json_return_and_die($ret);
- }
- killme();
- }
-
- api_register_func('api/red/filemeta', 'api_file_meta', true);
- api_register_func('api/z/1.0/filemeta', 'api_file_meta', true);
-
-
- function api_file_data($type) {
- if (api_user()===false) return false;
- if(! $_REQUEST['file_id']) return false;
- $start = (($_REQUEST['start']) ? intval($_REQUEST['start']) : 0);
- $length = (($_REQUEST['length']) ? intval($_REQUEST['length']) : 0);
-
- $r = q("select * from attach where uid = %d and hash = '%s' limit 1",
- intval(api_user()),
- dbesc($_REQUEST['file_id'])
- );
- if($r) {
- $ptr = $r[0];
- if($length === 0)
- $length = intval($ptr['filesize']);
-
- if($ptr['is_dir'])
- $ptr['content'] = '';
- elseif(! intval($r[0]['os_storage'])) {
- $ptr['start'] = $start;
- $x = substr(dbunescbin($ptr['content'],$start,$length));
- $ptr['length'] = strlen($x);
- $ptr['content'] = base64_encode($x);
- }
- else {
- $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['content'] = base64_encode($x);
- }
- }
-
- $ret = array('attach' => $ptr);
- json_return_and_die($ret);
- }
- killme();
- }
-
- api_register_func('api/red/filedata', 'api_file_data', true);
- api_register_func('api/z/1.0/filedata', 'api_file_data', true);
-
- function api_file_export($type) {
- if (api_user()===false) return false;
- if(! $_REQUEST['file_id']) return false;
-
- $ret = attach_export_data(api_user(),$_REQUEST['file_id']);
- if($ret) {
- json_return_and_die($ret);
- }
- killme();
- }
-
- api_register_func('api/red/file/export', 'api_file_export', true);
- api_register_func('api/z/1.0/file/export', 'api_file_export', true);
-
- function api_file_detail($type) {
- if (api_user()===false) return false;
- if(! $_REQUEST['file_id']) return false;
- $r = q("select * from attach where uid = %d and hash = '%s' limit 1",
- intval(api_user()),
- dbesc($_REQUEST['file_id'])
- );
- if($r) {
- if($r[0]['is_dir'])
- $r[0]['content'] = '';
- elseif(intval($r[0]['os_storage']))
- $r[0]['content'] = base64_encode(file_get_contents(dbunescbin($r[0]['content'])));
- else
- $r[0]['content'] = base64_encode(dbunescbin($r[0]['content']));
-
- $ret = array('attach' => $r[0]);
- json_return_and_die($ret);
- }
- killme();
- }
-
-
-
-
-
- api_register_func('api/red/file', 'api_file_detail', true);
- api_register_func('api/z/1.0/file', 'api_file_detail', true);
-
-
- function api_albums($type) {
- json_return_and_die(photos_albums_list(App::get_channel(),App::get_observer()));
- }
- api_register_func('api/red/albums','api_albums', true);
- api_register_func('api/z/1.0/albums','api_albums', true);
-
- function api_photos($type) {
- $album = $_REQUEST['album'];
- json_return_and_die(photos_list_photos(App::get_channel(),App::get_observer(),$album));
- }
- api_register_func('api/red/photos','api_photos', true);
- api_register_func('api/z/1.0/photos','api_photos', true);
-
- function api_photo_detail($type) {
- 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 imgscale = %d limit 1",
- intval(local_channel()),
- dbesc($_REQUEST['photo_id']),
- intval($scale)
- );
- if($r) {
- $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]['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()),
- dbesc($_REQUEST['photo_id'])
- );
- if($i) {
- $ii = q("select * from item where parent = %d order by id",
- intval($i[0]['id'])
- );
- if($ii) {
- xchan_query($ii,true,0);
- $ii = fetch_post_tags($ii,true);
- if($ii) {
- $ret['item'] = array();
- foreach($ii as $iii)
- $ret['item'][] = encode_item($iii,true);
- }
- }
- }
-
- json_return_and_die($ret);
- }
- killme();
- }
-
- api_register_func('api/red/photo', 'api_photo_detail', true);
- api_register_func('api/z/1.0/photo', 'api_photo_detail', true);
-
-
- function api_group_members($type) {
- if(api_user() === false)
- return false;
-
- if($_REQUEST['group_id']) {
- $r = q("select * from groups where uid = %d and id = %d limit 1",
- intval(api_user()),
- intval($_REQUEST['group_id'])
- );
- if($r) {
- $x = q("select * from group_member left join xchan on group_member.xchan = xchan.xchan_hash
- left join abook on abook_xchan = xchan_hash where gid = %d",
- intval($_REQUEST['group_id'])
- );
- json_return_and_die($x);
- }
- }
- }
-
- api_register_func('api/red/group_members','api_group_members', true);
- api_register_func('api/z/1.0/group_members','api_group_members', true);
-
-
-
-
- function api_group($type) {
- if(api_user() === false)
- return false;
-
- $r = q("select * from groups where uid = %d",
- intval(api_user())
- );
- json_return_and_die($r);
- }
- api_register_func('api/red/group','api_group', true);
- api_register_func('api/z/1.0/group','api_group', true);
-
-
- function api_red_xchan($type) {
- logger('api_xchan');
-
- if(api_user() === false)
- return false;
- logger('api_xchan');
- require_once('include/hubloc.php');
-
- if($_SERVER['REQUEST_METHOD'] === 'POST') {
- $r = xchan_store($_REQUEST);
- }
- $r = xchan_fetch($_REQUEST);
- json_return_and_die($r);
- };
-
- api_register_func('api/red/xchan','api_red_xchan',true);
- api_register_func('api/z/1.0/xchan','api_red_xchan',true);
-
function api_statuses_mediap( $type) {
if (api_user() === false) {
logger('api_statuses_update: no user');
return false;
}
- $user_info = api_get_user($a);
+ $user_info = api_get_user();
// logger('status_with_media: ' . print_r($_REQUEST,true), LOGGER_DEBUG);
@@ -799,7 +512,7 @@ require_once('include/api_auth.php');
$mod->post();
- $_REQUEST['body']=$txt."\n\n".$posted;
+ $_REQUEST['body']= $txt . "\n\n" . $posted;
$mod = new Zotlabs\Module\Item();
$mod->post();
@@ -807,7 +520,9 @@ require_once('include/api_auth.php');
// this should output the last post (the one we just posted).
return api_status_show($type);
}
+
api_register_func('api/statuses/mediap','api_statuses_mediap', true);
+ api_register_func('api/1.1/statuses/mediap','api_statuses_mediap', true);
function api_statuses_update( $type) {
if (api_user() === false) {
@@ -824,7 +539,7 @@ require_once('include/api_auth.php');
$_REQUEST['api_source'] = true;
- $user_info = api_get_user($a);
+ $user_info = api_get_user();
// convert $_POST array items to the form we use for web posts.
@@ -928,80 +643,8 @@ require_once('include/api_auth.php');
}
api_register_func('api/statuses/update_with_media','api_statuses_update', true);
api_register_func('api/statuses/update','api_statuses_update', true);
-
-
- function red_item_new( $type) {
-
- if (api_user() === false) {
- logger('api_red_item_new: no user');
- return false;
- }
-
- logger('api_red_item_new: REQUEST ' . print_r($_REQUEST,true));
- logger('api_red_item_new: FILES ' . print_r($_FILES,true));
-
-
- // set this so that the item_post() function is quiet and doesn't redirect or emit json
-
- $_REQUEST['api_source'] = true;
- $_REQUEST['profile_uid'] = api_user();
-
- if(x($_FILES,'media')) {
- $_FILES['userfile'] = $_FILES['media'];
- // upload the image if we have one
- $_REQUEST['silent']='1'; //tell wall_upload function to return img info instead of echo
- $mod = new Zotlabs\Module\Wall_upload();
- $media = $mod->post();
- if(strlen($media)>0)
- $_REQUEST['body'] .= "\n\n".$media;
- }
-
- $mod = new Zotlabs\Module\Item();
- $x = $mod->post();
- json_return_and_die($x);
- }
-
- api_register_func('api/red/item/new','red_item_new', true);
- api_register_func('api/z/1.0/item/new','red_item_new', true);
-
-
- function red_item( $type) {
-
- if (api_user() === false) {
- logger('api_red_item_full: no user');
- return false;
- }
-
- if($_REQUEST['mid']) {
- $arr = array('mid' => $_REQUEST['mid']);
- }
- elseif($_REQUEST['item_id']) {
- $arr = array('item_id' => $_REQUEST['item_id']);
- }
- else
- json_return_and_die(array());
-
- $arr['start'] = 0;
- $arr['records'] = 999999;
- $arr['item_type'] = '*';
-
- $i = items_fetch($arr,App::get_channel(),get_observer_hash());
-
- if(! $i)
- json_return_and_die(array());
-
- $ret = array();
- $tmp = array();
- foreach($i as $ii) {
- $tmp[] = encode_item($ii,true);
- }
- $ret['item'] = $tmp;
-
- json_return_and_die($ret);
- }
-
- api_register_func('api/red/item/full','red_item', true);
- api_register_func('api/z/1.0/item/full','red_item', true);
+ api_register_func('api/1.1/statuses/update_with_media','api_statuses_update', true);
+ api_register_func('api/1.1/statuses/update','api_statuses_update', true);
@@ -1068,7 +711,7 @@ require_once('include/api_auth.php');
}
function api_status_show( $type){
- $user_info = api_get_user($a);
+ $user_info = api_get_user();
// get last public message
@@ -1131,7 +774,7 @@ require_once('include/api_auth.php');
unset($status_info['user']['status']);
}
- return api_apply_template("status", $type, array('$status' => $status_info));
+ return api_apply_template('status', $type, array('$status' => $status_info));
}
@@ -1146,7 +789,7 @@ require_once('include/api_auth.php');
function api_users_show( $type){
- $user_info = api_get_user($a);
+ $user_info = api_get_user();
require_once('include/security.php');
$item_normal = item_normal();
@@ -1204,10 +847,12 @@ require_once('include/api_auth.php');
);
}
- return api_apply_template("user", $type, array('$user' => $user_info));
+ return api_apply_template('user', $type, array('$user' => $user_info));
}
+
api_register_func('api/users/show','api_users_show');
+ api_register_func('api/1.1/users/show','api_users_show');
/**
*
@@ -1221,27 +866,26 @@ require_once('include/api_auth.php');
if (api_user() === false)
return false;
- $user_info = api_get_user($a);
+ $user_info = api_get_user();
// get last network messages
// params
- $count = (x($_REQUEST,'count')?$_REQUEST['count']:20);
- $page = (x($_REQUEST,'page')?$_REQUEST['page']-1:0);
+ $count = (x($_REQUEST,'count') ? $_REQUEST['count'] : 20);
+ $page = (x($_REQUEST,'page') ? $_REQUEST['page']-1 : 0);
if($page < 0)
$page = 0;
- $since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
- $max_id = (x($_REQUEST,'max_id')?$_REQUEST['max_id']:0);
- $exclude_replies = (x($_REQUEST,'exclude_replies')?1:0);
- //$since_id = 0;//$since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
+ $since_id = (x($_REQUEST,'since_id') ? $_REQUEST['since_id'] : 0);
+ $max_id = (x($_REQUEST,'max_id') ? $_REQUEST['max_id'] : 0);
+ $exclude_replies = (x($_REQUEST,'exclude_replies') ? 1 : 0);
- $start = $page*$count;
+ $start = $page * $count;
//$include_entities = (x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:false);
$sql_extra = '';
if ($max_id > 0)
- $sql_extra .= ' AND item.id <= '.intval($max_id);
+ $sql_extra .= ' AND item.id <= ' . intval($max_id);
if ($exclude_replies > 0)
$sql_extra .= ' AND item.parent = item.id';
@@ -1250,7 +894,7 @@ require_once('include/api_auth.php');
require_once('include/permissions.php');
if(! perm_is_allowed($user_info['uid'],(($observer) ? $observer['xchan_hash'] : ''),'view_stream'))
return '';
- $sql_extra .= " and item_private = 0 ";
+ $sql_extra .= ' and item_private = 0 ';
}
$item_normal = item_normal();
@@ -1279,42 +923,32 @@ require_once('include/api_auth.php');
);
}
-
$data = array('$statuses' => $ret);
- switch($type){
- case "atom":
- case "rss":
- $data = api_rss_extra( $data, $user_info);
- break;
- case "as":
- $as = api_format_as( $ret, $user_info);
- $as['title'] = App::$config['sitename']." Home Timeline";
- $as['link']['url'] = z_root()."/".$user_info["screen_name"]."/all";
- return($as);
- break;
- }
-
- return api_apply_template("timeline", $type, $data);
+ return api_apply_template('timeline', $type, $data);
}
+
api_register_func('api/statuses/home_timeline','api_statuses_home_timeline', true);
api_register_func('api/statuses/friends_timeline','api_statuses_home_timeline', true);
+ api_register_func('api/1.1/statuses/home_timeline','api_statuses_home_timeline', true);
+ api_register_func('api/1.1/statuses/friends_timeline','api_statuses_home_timeline', true);
function api_statuses_public_timeline( $type){
- if (api_user()===false) return false;
+ if(api_user() === false)
+ return false;
- $user_info = api_get_user($a);
+ $user_info = api_get_user();
$sys = get_sys_channel();
// params
- $count = (x($_REQUEST,'count')?$_REQUEST['count']:20);
- $page = (x($_REQUEST,'page')?$_REQUEST['page']-1:0);
- if ($page<0) $page=0;
- $since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
- $max_id = (x($_REQUEST,'max_id')?$_REQUEST['max_id']:0);
- //$since_id = 0;//$since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
+ $count = (x($_REQUEST,'count') ? $_REQUEST['count'] : 20);
+ $page = (x($_REQUEST,'page') ? $_REQUEST['page']-1 : 0);
+ if($page < 0)
+ $page=0;
+ $since_id = (x($_REQUEST,'since_id') ? $_REQUEST['since_id'] : 0);
+ $max_id = (x($_REQUEST,'max_id') ? $_REQUEST['max_id'] : 0);
- $start = $page*$count;
+ $start = $page * $count;
//$include_entities = (x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:false);
@@ -1341,32 +975,20 @@ require_once('include/api_auth.php');
$ret = api_format_items($r,$user_info);
- $data = array('$statuses' => $ret);
- switch($type){
- case "atom":
- case "rss":
- $data = api_rss_extra( $data, $user_info);
- break;
- case "as":
- $as = api_format_as( $ret, $user_info);
- $as['title'] = App::$config['sitename']. " " . t('Public Timeline');
- $as['link']['url'] = z_root()."/";
- return($as);
- break;
- }
+ $data = array('statuses' => $ret);
- return api_apply_template("timeline", $type, $data);
+ return api_apply_template('timeline', $type, $data);
}
+
api_register_func('api/statuses/public_timeline','api_statuses_public_timeline', true);
+ api_register_func('api/1.1/statuses/public_timeline','api_statuses_public_timeline', true);
- /**
- *
- */
- function api_statuses_show( $type){
- if (api_user()===false) return false;
+ function api_statuses_show($type){
+ if(api_user()===false)
+ return false;
- $user_info = api_get_user($a);
+ $user_info = api_get_user();
// params
$id = intval(argv(3));
@@ -1375,8 +997,8 @@ require_once('include/api_auth.php');
logger('API: api_statuses_show: '.$id);
- //$include_entities = (x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:false);
- $conversation = (x($_REQUEST,'conversation')?1:0);
+ //$include_entities = (x($_REQUEST,'include_entities') ? $_REQUEST['include_entities'] : false);
+ $conversation = (x($_REQUEST,'conversation') ? 1 : 0);
$sql_extra = '';
if ($conversation)
@@ -1385,7 +1007,8 @@ require_once('include/api_auth.php');
$sql_extra .= " AND item.id = %d";
$item_normal = item_normal();
- $r = q("select * from item where true $item_normal $sql_extra",
+ $r = q("select * from item where uid = %d $item_normal $sql_extra",
+ intval(api_user()),
intval($id)
);
@@ -1395,35 +1018,33 @@ require_once('include/api_auth.php');
if ($conversation) {
- $data = array('$statuses' => $ret);
- return api_apply_template("timeline", $type, $data);
+ $data = array('statuses' => $ret);
+ return api_apply_template('timeline', $type, $data);
} else {
- $data = array('$status' => $ret[0]);
- /*switch($type){
- case "atom":
- case "rss":
- $data = api_rss_extra( $data, $user_info);
- }*/
- return api_apply_template("status", $type, $data);
+ $data = array('status' => $ret[0]);
+ return api_apply_template('status', $type, $data);
}
}
+
api_register_func('api/statuses/show','api_statuses_show', true);
+ api_register_func('api/1.1/statuses/show','api_statuses_show', true);
/**
*
*/
function api_statuses_repeat( $type){
- if (api_user()===false) return false;
+ if(api_user()===false)
+ return false;
- $user_info = api_get_user($a);
+ $user_info = api_get_user();
// params
$id = intval(argv(3));
- logger('API: api_statuses_repeat: '.$id);
+ logger('API: api_statuses_repeat: ' . $id);
- //$include_entities = (x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:false);
+ //$include_entities = (x($_REQUEST,'include_entities') ? $_REQUEST['include_entities'] : false);
$observer = App::get_observer();
@@ -1434,8 +1055,8 @@ require_once('include/api_auth.php');
);
if(perm_is_allowed($r[0]['uid'],$observer['xchan_hash'],'view_stream')) {
- if ($r[0]['body'] != "") {
- $_REQUEST['body'] = html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8')."[zrl=".$r[0]['reply_url']."]".$r[0]['reply_author']."[/zrl] \n".$r[0]['body'];
+ if ($r[0]['body'] != '') {
+ $_REQUEST['body'] = html_entity_decode('&#x2672; ', ENT_QUOTES, 'UTF-8') . '[zrl=' . $r[0]['reply_url'] . ']' . $r[0]['reply_author'] . '[/zrl] ' . "\n" . $r[0]['body'];
$_REQUEST['profile_uid'] = api_user();
$_REQUEST['type'] = 'wall';
$_REQUEST['api_source'] = true;
@@ -1447,22 +1068,25 @@ require_once('include/api_auth.php');
return false;
if ($type == 'xml')
- $ok = "true";
+ $ok = 'true';
else
- $ok = "ok";
+ $ok = 'ok';
return api_apply_template('test', $type, array('$ok' => $ok));
}
+
api_register_func('api/statuses/retweet','api_statuses_repeat', true);
+ api_register_func('api/1.1/statuses/retweet','api_statuses_repeat', true);
/**
*
*/
function api_statuses_destroy( $type){
- if (api_user()===false) return false;
+ if(api_user()===false)
+ return false;
- $user_info = api_get_user($a);
+ $user_info = api_get_user();
// params
$id = intval(argv(3));
@@ -1508,13 +1132,15 @@ require_once('include/api_auth.php');
if ($type == 'xml')
- $ok = "true";
+ $ok = 'true';
else
- $ok = "ok";
+ $ok = 'ok';
return api_apply_template('test', $type, array('$ok' => $ok));
}
+
api_register_func('api/statuses/destroy','api_statuses_destroy', true);
+ api_register_func('api/1.1/statuses/destroy','api_statuses_destroy', true);
/**
*
@@ -1526,27 +1152,22 @@ require_once('include/api_auth.php');
function api_statuses_mentions( $type){
if (api_user()===false) return false;
- $user_info = api_get_user($a);
+ $user_info = api_get_user();
// get last network messages
// params
- $count = (x($_REQUEST,'count')?$_REQUEST['count']:20);
- $page = (x($_REQUEST,'page')?$_REQUEST['page']-1:0);
- if ($page<0) $page=0;
- $since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
- $max_id = (x($_REQUEST,'max_id')?$_REQUEST['max_id']:0);
- //$since_id = 0;//$since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
+ $count = (x($_REQUEST,'count') ? $_REQUEST['count'] : 20);
+ $page = (x($_REQUEST,'page') ? $_REQUEST['page']-1 : 0);
+ if($page < 0)
+ $page=0;
+ $since_id = (x($_REQUEST,'since_id') ? $_REQUEST['since_id'] : 0);
+ $max_id = (x($_REQUEST,'max_id') ? $_REQUEST['max_id'] : 0);
- $start = $page*$count;
+ $start = $page * $count;
//$include_entities = (x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:false);
- $myurl = z_root() . '/channel/'. App::$user['nickname'];
- $myurl = substr($myurl,strpos($myurl,'://')+3);
- $myurl = str_replace(array('www.','.'),array('','\\.'),$myurl);
- $diasp_url = str_replace('/channel/','/u/',$myurl);
-
$sql_extra .= " AND item_mentionsme = 1 ";
if ($max_id > 0)
$sql_extra .= " AND item.id <= " . intval($max_id) . " ";
@@ -1565,85 +1186,57 @@ require_once('include/api_auth.php');
xchan_query($r,true);
-
$ret = api_format_items($r,$user_info);
+ $data = array('statuses' => $ret);
- $data = array('$statuses' => $ret);
- switch($type){
- case "atom":
- case "rss":
- $data = api_rss_extra( $data, $user_info);
- break;
- case "as":
- $as = api_format_as( $ret, $user_info);
- $as["title"] = App::$config['sitename']." Mentions";
- $as['link']['url'] = z_root()."/";
- return($as);
- break;
- }
-
- return api_apply_template("timeline", $type, $data);
+ return api_apply_template('timeline', $type, $data);
}
+
api_register_func('api/statuses/mentions','api_statuses_mentions', true);
// FIXME?? I don't think mentions and replies are congruent in this case
api_register_func('api/statuses/replies','api_statuses_mentions', true);
+ api_register_func('api/1.1/statuses/mentions','api_statuses_mentions', true);
+ api_register_func('api/1.1/statuses/replies','api_statuses_mentions', true);
+
function api_statuses_user_timeline( $type){
- if (api_user()===false) return false;
+ if(api_user() === false)
+ return false;
- $user_info = api_get_user($a);
- // get last network messages
+ $user_info = api_get_user();
+ // get last network messages
- logger("api_statuses_user_timeline: api_user: ". api_user() .
+ logger('api_statuses_user_timeline: api_user: '. api_user() .
"\nuser_info: ".print_r($user_info, true) .
"\n_REQUEST: ".print_r($_REQUEST, true),
LOGGER_DEBUG);
// params
- $count = (x($_REQUEST,'count')?$_REQUEST['count']:20);
- $page = (x($_REQUEST,'page')?$_REQUEST['page']-1:0);
- if ($page<0) $page=0;
- $since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
- $exclude_replies = (x($_REQUEST,'exclude_replies')?1:0);
- //$since_id = 0;//$since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
+ $count = (x($_REQUEST,'count') ? $_REQUEST['count'] : 20);
+ $page = (x($_REQUEST,'page') ? $_REQUEST['page']-1 : 0);
+ if($page < 0)
+ $page = 0;
+ $since_id = (x($_REQUEST,'since_id') ? $_REQUEST['since_id'] : 0);
+ $exclude_replies = (x($_REQUEST,'exclude_replies') ? 1 :0);
- $start = $page*$count;
+ $start = $page * $count;
$sql_extra = '';
- if ($user_info['self']==1) $sql_extra .= " AND item.wall = 1 ";
//FIXME - this isn't yet implemented
if ($exclude_replies > 0) $sql_extra .= ' AND item.parent = item.id';
-// $r = q("SELECT item.*, item.id AS item_id,
-// contact.name, contact.photo, contact.url, contact.rel,
-// contact.network, contact.thumb, contact.dfrn_id, contact.self,
-// contact.id AS cid, contact.uid AS contact-uid
-// FROM item, contact
-// WHERE item.uid = %d
-// AND item.contact-id = %d
-// AND item.visible = 1 and item.moderated = 0 AND item.deleted = 0
-// AND contact.id = item.contact-id
-// AND contact.blocked = 0 AND contact.pending = 0
-// $sql_extra
-// AND item.id>%d
-// ORDER BY item.received DESC LIMIT %d ,%d ",
-// intval(api_user()),
-// intval($user_info['id']),
-// intval($since_id),
-// intval($start), intval($count)
-// );
-
- $arr = array(
- 'uid' => api_user(),
- 'since_id' => $since_id,
- 'start' => $start,
- 'records' => $count);
+ $arr = [
+ 'uid' => api_user(),
+ 'since_id' => $since_id,
+ 'start' => $start,
+ 'records' => $count
+ ];
- if ($user_info['self']==1)
+ if ($user_info['self'] === 1)
$arr['wall'] = 1;
else
$arr['cid'] = $user_info['id'];
@@ -1653,18 +1246,12 @@ require_once('include/api_auth.php');
$ret = api_format_items($r,$user_info);
-
- $data = array('$statuses' => $ret);
- switch($type){
- case "atom":
- case "rss":
- $data = api_rss_extra( $data, $user_info);
- }
-
- return api_apply_template("timeline", $type, $data);
+ $data = array('statuses' => $ret);
+ return(api_apply_template('timeline', $type, $data));
}
api_register_func('api/statuses/user_timeline','api_statuses_user_timeline', true);
+ api_register_func('api/1.1/statuses/user_timeline','api_statuses_user_timeline', true);
@@ -1674,17 +1261,16 @@ require_once('include/api_auth.php');
*
* api v1 : https://web.archive.org/web/20131019055350/https://dev.twitter.com/docs/api/1/post/favorites/create/%3Aid
*/
- function api_favorites_create_destroy( $type){
+ function api_favorites_create_destroy($type){
- logger('favorites_create_destroy');
-
- if (api_user()===false)
+ if(api_user() === false)
return false;
- $action = str_replace(".".$type,"",argv(2));
+ $action = str_replace('.' . $type,'',argv(2));
if (argc() > 3) {
$itemid = intval(argv(3));
- } else {
+ }
+ else {
$itemid = intval($_REQUEST['id']);
}
@@ -1693,14 +1279,14 @@ require_once('include/api_auth.php');
intval(api_user())
);
- if (! $item)
+ if(! $item)
return false;
switch($action){
- case "create":
+ case 'create':
$flags = $item[0]['item_starred'] = 1;
break;
- case "destroy":
+ case 'destroy':
$flags = $item[0]['item_starred'] = 0;
break;
default:
@@ -1722,48 +1308,43 @@ require_once('include/api_auth.php');
xchan_query($item,true);
-
- $user_info = api_get_user($a);
+ $user_info = api_get_user();
$rets = api_format_items($item,$user_info);
$ret = $rets[0];
- $data = array('$status' => $ret);
- switch($type){
- case "atom":
- case "rss":
- $data = api_rss_extra( $data, $user_info);
- }
+ $data = array('status' => $ret);
- return api_apply_template("status", $type, $data);
+ return api_apply_template('status', $type, $data);
}
api_register_func('api/favorites/create', 'api_favorites_create_destroy', true);
api_register_func('api/favorites/destroy', 'api_favorites_create_destroy', true);
-
+ api_register_func('api/1.1/favorites/create', 'api_favorites_create_destroy', true);
+ api_register_func('api/1.1/favorites/destroy', 'api_favorites_create_destroy', true);
function api_favorites( $type){
- if (api_user()===false)
+ if(api_user()===false)
return false;
- $user_info = api_get_user($a);
+ $user_info = api_get_user();
// params
- $count = (x($_REQUEST,'count')?$_REQUEST['count']:20);
- $page = (x($_REQUEST,'page')?$_REQUEST['page']-1:0);
+ $count = (x($_REQUEST,'count') ? $_REQUEST['count'] : 20);
+ $page = (x($_REQUEST,'page') ? $_REQUEST['page']-1 : 0);
if($page < 0)
$page = 0;
- $since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
- $max_id = (x($_REQUEST,'max_id')?$_REQUEST['max_id']:0);
- $exclude_replies = (x($_REQUEST,'exclude_replies')?1:0);
+ $since_id = (x($_REQUEST,'since_id') ? $_REQUEST['since_id'] : 0);
+ $max_id = (x($_REQUEST,'max_id') ? $_REQUEST['max_id'] : 0);
+ $exclude_replies = (x($_REQUEST,'exclude_replies') ? 1 :0);
- $start = $page*$count;
+ $start = $page * $count;
- //$include_entities = (x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:false);
+ //$include_entities = (x($_REQUEST,'include_entities') ? $_REQUEST['include_entities'] : false);
$sql_extra = '';
if ($max_id > 0)
- $sql_extra .= ' AND item.id <= '.intval($max_id);
+ $sql_extra .= ' AND item.id <= ' . intval($max_id);
if ($exclude_replies > 0)
$sql_extra .= ' AND item.parent = item.id';
@@ -1772,7 +1353,7 @@ require_once('include/api_auth.php');
require_once('include/permissions.php');
if(! perm_is_allowed($user_info['uid'],(($observer) ? $observer['xchan_hash'] : ''),'view_stream'))
return '';
- $sql_extra .= " and item_private = 0 ";
+ $sql_extra .= ' and item_private = 0 ';
}
$item_normal = item_normal();
@@ -1791,94 +1372,15 @@ require_once('include/api_auth.php');
$ret = api_format_items($r,$user_info);
- $data = array('$statuses' => $ret);
- switch($type){
- case "atom":
- case "rss":
- $data = api_rss_extra( $data, $user_info);
- break;
- case "as":
- $as = api_format_as( $ret, $user_info);
- $as['title'] = App::$config['sitename']." Home Timeline";
- $as['link']['url'] = z_root()."/".$user_info["screen_name"]."/all";
- return($as);
- break;
- }
-
- return api_apply_template("timeline", $type, $data);
+ $data = array('statuses' => $ret);
+ return(api_apply_template('timeline', $type, $data));
}
api_register_func('api/favorites','api_favorites', true);
+ api_register_func('api/1.1/favorites','api_favorites', true);
-
-
- function api_format_as( $ret, $user_info) {
-
- $as = array();
- $as['title'] = App::$config['sitename']." Public Timeline";
- $items = array();
- foreach ($ret as $item) {
- $singleitem["actor"]["displayName"] = $item["user"]["name"];
- $singleitem["actor"]["id"] = $item["user"]["contact_url"];
- $avatar[0]["url"] = $item["user"]["profile_image_url"];
- $avatar[0]["rel"] = "avatar";
- $avatar[0]["type"] = "";
- $avatar[0]["width"] = 96;
- $avatar[0]["height"] = 96;
- $avatar[1]["url"] = $item["user"]["profile_image_url"];
- $avatar[1]["rel"] = "avatar";
- $avatar[1]["type"] = "";
- $avatar[1]["width"] = 48;
- $avatar[1]["height"] = 48;
- $avatar[2]["url"] = $item["user"]["profile_image_url"];
- $avatar[2]["rel"] = "avatar";
- $avatar[2]["type"] = "";
- $avatar[2]["width"] = 24;
- $avatar[2]["height"] = 24;
- $singleitem["actor"]["avatarLinks"] = $avatar;
-
- $singleitem["actor"]["image"]["url"] = $item["user"]["profile_image_url"];
- $singleitem["actor"]["image"]["rel"] = "avatar";
- $singleitem["actor"]["image"]["type"] = "";
- $singleitem["actor"]["image"]["width"] = 96;
- $singleitem["actor"]["image"]["height"] = 96;
- $singleitem["actor"]["type"] = "person";
- $singleitem["actor"]["url"] = $item["person"]["contact_url"];
- $singleitem["actor"]["statusnet:profile_info"]["local_id"] = $item["user"]["id"];
- $singleitem["actor"]["statusnet:profile_info"]["following"] = $item["user"]["following"] ? "true" : "false";
- $singleitem["actor"]["statusnet:profile_info"]["blocking"] = "false";
- $singleitem["actor"]["contact"]["preferredUsername"] = $item["user"]["screen_name"];
- $singleitem["actor"]["contact"]["displayName"] = $item["user"]["name"];
- $singleitem["actor"]["contact"]["addresses"] = "";
-
- $singleitem["body"] = $item["text"];
- $singleitem["object"]["displayName"] = $item["text"];
- $singleitem["object"]["id"] = $item["url"];
- $singleitem["object"]["type"] = "note";
- $singleitem["object"]["url"] = $item["url"];
- //$singleitem["context"] =;
- $singleitem["postedTime"] = date("c", strtotime($item["published"]));
- $singleitem["provider"]["objectType"] = "service";
- $singleitem["provider"]["displayName"] = "Test";
- $singleitem["provider"]["url"] = "http://test.tld";
- $singleitem["title"] = $item["text"];
- $singleitem["verb"] = "post";
- $singleitem["statusnet:notice_info"]["local_id"] = $item["id"];
- $singleitem["statusnet:notice_info"]["source"] = $item["source"];
- $singleitem["statusnet:notice_info"]["favorite"] = "false";
- $singleitem["statusnet:notice_info"]["repeated"] = "false";
- //$singleitem["original"] = $item;
- $items[] = $singleitem;
- }
- $as['items'] = $items;
- $as['link']['url'] = z_root()."/".$user_info["screen_name"]."/all";
- $as['link']['rel'] = "alternate";
- $as['link']['type'] = "text/html";
- return($as);
- }
-
function api_format_message($item, $recipient, $sender) {
// standard meta information
$ret = array(
@@ -1895,17 +1397,17 @@ require_once('include/api_auth.php');
//don't send title to regular StatusNET requests to avoid confusing these apps
if (x($_GET, 'getText')) {
$ret['title'] = $item['title'] ;
- if ($_GET["getText"] == "html") {
+ if ($_GET['getText'] === 'html') {
$ret['text'] = prepare_text($item['body'],$item['mimetype']);
}
- elseif ($_GET["getText"] == "plain") {
+ elseif ($_GET['getText'] === 'plain') {
$ret['text'] = html2plain(prepare_text($item['body'],$item['mimetype']), 0);
}
}
else {
- $ret['text'] = $item['title']."\n".html2plain(prepare_text($item['body'],$item['mimetype']), 0);
+ $ret['text'] = $item['title'] . "\n" . html2plain(prepare_text($item['body'],$item['mimetype']),0);
}
- if (isset($_GET["getUserObjects"]) && $_GET["getUserObjects"] == "false") {
+ if (isset($_GET['getUserObjects']) && $_GET['getUserObjects'] == 'false') {
unset($ret['sender']);
unset($ret['recipient']);
}
@@ -1964,12 +1466,12 @@ require_once('include/api_auth.php');
if (($statustitle != '') and (strpos($statusbody, $statustitle) !== false))
$statustext = trim($statusbody);
else
- $statustext = trim($statustitle."\n\n".$statusbody);
+ $statustext = trim($statustitle . "\n\n" . $statusbody);
$status = array(
'text' => $statustext,
- 'truncated' => False,
+ 'truncated' => false,
'created_at' => api_date($item['created']),
'in_reply_to_status_id' => $in_reply_to_status_id,
'source' => (($item['app']) ? $item['app'] : 'web'),
@@ -1998,8 +1500,8 @@ require_once('include/api_auth.php');
'entities' => '',
'objecttype' => (($item['obj_type']) ? $item['obj_type'] : ACTIVITY_OBJ_NOTE),
'verb' => (($item['verb']) ? $item['verb'] : ACTIVITY_POST),
- 'self' => z_root()."/api/statuses/show/".$item['id'].".".$type,
- 'edit' => z_root()."/api/statuses/show/".$item['id'].".".$type,
+ 'self' => z_root().'/api/statuses/show/'.$item['id'].'.'.$type,
+ 'edit' => z_root().'/api/statuses/show/'.$item['id'].'.'.$type,
);
$status = array_merge($status, $status2);
@@ -2019,25 +1521,29 @@ require_once('include/api_auth.php');
'hourly_limit' => (string) 150,
'reset_time' => datetime_convert('UTC','UTC','now + 1 hour',ATOM_TIME),
);
- if ($type == "xml")
+ if ($type == 'xml')
$hash['resettime_in_seconds'] = $hash['reset_time_in_seconds'];
return api_apply_template('ratelimit', $type, array('$hash' => $hash));
}
+
api_register_func('api/account/rate_limit_status','api_account_rate_limit_status',true);
+ api_register_func('api/1.1/account/rate_limit_status','api_account_rate_limit_status',true);
function api_help_test($type) {
if ($type == 'xml')
- $ok = "true";
+ $ok = 'true';
else
- $ok = "ok";
+ $ok = 'ok';
- return api_apply_template('test', $type, array('$ok' => $ok));
+ return api_apply_template('test', $type, array('ok' => $ok));
}
+
api_register_func('api/help/test','api_help_test',false);
+ api_register_func('api/1.1/help/test','api_help_test',false);
/**
* https://dev.twitter.com/docs/api/1/get/statuses/friends
@@ -2045,8 +1551,9 @@ require_once('include/api_auth.php');
* returns: json, xml
**/
function api_statuses_f( $type, $qtype) {
- if (api_user()===false) return false;
- $user_info = api_get_user($a);
+ if(api_user()===false)
+ return false;
+ $user_info = api_get_user();
// friends and followers only for self
@@ -2061,80 +1568,106 @@ require_once('include/api_auth.php');
*/
/*$ret=Array();
- return array('$users' => $ret);*/
+ return array('users' => $ret);*/
return false;
}
-// @fixme - update for hubzilla extensible perms using abconfig or find a better way to do it
- // For Red, the closest thing we can do to figure out if you're friends is if both of you are sending each other your streams.
- // This won't work if either of you send your stream to everybody on the network
- if($qtype == 'friends')
- $sql_extra = sprintf(" AND ( abook_their_perms & %d )>0 and ( abook_my_perms & %d )>0 ", intval(PERMS_W_STREAM), intval(PERMS_W_STREAM));
- if($qtype == 'followers')
- $sql_extra = sprintf(" AND ( abook_my_perms & %d )>0 and not ( abook_their_perms & %d )>0 ", intval(PERMS_W_STREAM), intval(PERMS_W_STREAM));
-
- $r = q("SELECT abook_id FROM abook where abook_self = 0 and abook_channel = %d $sql_extra",
- intval(api_user())
- );
+
+
+
+ if($qtype == 'friends') {
+ $r = q("select abook_id from abook left join abconfig on abook_xchan = xchan and abook_channel = chan
+ where chan = %d and abook_self = 0 and abook_pending = 0 and cat = 'my_perms' and k = 'view_stream' and v = '1' ",
+ intval(api_user())
+ );
+ }
+
+ if($qtype == 'followers') {
+ $r = q("select abook_id from abook left join abconfig on abook_xchan = xchan and abook_channel = chan
+ where chan = %d and abook_self = 0 and abook_pending = 0 and cat = 'their_perms' and k = 'view_stream' and v = '1' ",
+ intval(api_user())
+ );
+ }
$ret = array();
- foreach($r as $cid){
- $ret[] = api_get_user( $cid['abook_id']);
+
+ if($r) {
+ foreach($r as $cid) {
+ $ret[] = api_get_user($cid['abook_id']);
+ }
}
-
- return array('$users' => $ret);
+ return array('users' => $ret);
}
- function api_statuses_friends( $type){
- $data = api_statuses_f($type,"friends");
- if ($data===false) return false;
- return api_apply_template("friends", $type, $data);
+
+ function api_statuses_friends($type){
+ $data = api_statuses_f($type,'friends');
+ if($data === false)
+ return false;
+ return(api_apply_template('friends', $type, $data));
}
- function api_statuses_followers( $type){
- $data = api_statuses_f($type,"followers");
- if ($data===false) return false;
- return api_apply_template("friends", $type, $data);
+ function api_statuses_followers($type){
+ $data = api_statuses_f($type,'followers');
+ if ($data === false)
+ return false;
+ return(api_apply_template('friends', $type, $data));
}
+
api_register_func('api/statuses/friends','api_statuses_friends',true);
api_register_func('api/statuses/followers','api_statuses_followers',true);
-
-
-
-
+ api_register_func('api/1.1/statuses/friends','api_statuses_friends',true);
+ api_register_func('api/1.1/statuses/followers','api_statuses_followers',true);
function api_statusnet_config($type) {
- load_config('system');
-
- $name = get_config('system','sitename');
- $server = App::get_hostname();
- $logo = z_root() . '/images/rm-64.png';
- $email = get_config('system','admin_email');
- $closed = ((get_config('system','register_policy') == REGISTER_CLOSED) ? 'true' : 'false');
- $private = ((get_config('system','block_public')) ? 'true' : 'false');
- $textlimit = (string) ((get_config('system','max_import_size')) ? get_config('system','max_import_size') : 200000);
+ $name = get_config('system','sitename');
+ $server = App::get_hostname();
+ $logo = z_root() . '/images/hz-64.png';
+ $email = get_config('system','admin_email');
+ $closed = ((get_config('system','register_policy') == REGISTER_CLOSED) ? true : false);
+ $private = ((get_config('system','block_public')) ? true : false);
+ $textlimit = ((get_config('system','max_import_size')) ? get_config('system','max_import_size') : 200000);
if(get_config('system','api_import_size'))
- $texlimit = string(get_config('system','api_import_size'));
- $ssl = ((get_config('system','have_ssl')) ? 'true' : 'false');
- $sslserver = (($ssl === 'true') ? str_replace('http:','https:',z_root()) : '');
-
- $config = array(
- 'site' => array('name' => $name,'server' => $server, 'theme' => 'default', 'path' => '',
- 'logo' => $logo, 'fancy' => 'true', 'language' => 'en', 'email' => $email, 'broughtby' => '',
- 'broughtbyurl' => '', 'timezone' => 'UTC', 'closed' => $closed, 'inviteonly' => 'false',
- 'private' => $private, 'textlimit' => $textlimit, 'sslserver' => $sslserver, 'ssl' => $ssl,
- 'shorturllength' => '30',
- 'hubzilla' => array(
- 'PLATFORM_NAME' => Zotlabs\Lib\System::get_platform_name(),
- 'STD_VERSION' => Zotlabs\Lib\System::get_project_version(),
- 'ZOT_REVISION' => ZOT_REVISION,
- 'DB_UPDATE_VERSION' => Zotlabs\Lib\System::get_update_version()
- )
- ));
-
- return api_apply_template('config', $type, array('$config' => $config));
+ $texlimit = get_config('system','api_import_size');
+
+ $m = parse_url(z_root());
+
+ $ssl = (($m['scheme'] === 'https') ? true : false);
+ $sslserver = (($ssl) ? str_replace('http:','https:',z_root()) : '');
+
+ $config = [
+ 'site' => [
+ 'name' => $name,
+ 'server' => $server,
+ 'theme' => 'default',
+ 'path' => '',
+ 'logo' => $logo,
+ 'fancy' => true,
+ 'language' => 'en',
+ 'email' => $email,
+ 'broughtby' => '',
+ 'broughtbyurl' => '',
+ 'timezone' => 'UTC',
+ 'closed' => $closed,
+ 'inviteonly' => false,
+ 'private' => $private,
+ 'textlimit' => $textlimit,
+ 'sslserver' => $sslserver,
+ 'ssl' => $ssl,
+ 'shorturllength' => 30,
+
+ 'platform' => [
+ 'PLATFORM_NAME' => Zotlabs\Lib\System::get_platform_name(),
+ 'STD_VERSION' => Zotlabs\Lib\System::get_project_version(),
+ 'ZOT_REVISION' => ZOT_REVISION,
+ 'DB_UPDATE_VERSION' => Zotlabs\Lib\System::get_update_version()
+ ]
+ ]
+ ];
+
+ return api_apply_template('config', $type, array('config' => $config));
}
api_register_func('api/statusnet/config','api_statusnet_config',false);
@@ -2147,12 +1680,12 @@ require_once('include/api_auth.php');
// liar
if($type === 'xml') {
- header("Content-type: application/xml");
+ header('Content-type: application/xml');
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n" . '<version>0.9.7</version>' . "\r\n";
killme();
}
elseif($type === 'json') {
- header("Content-type: application/json");
+ header('Content-type: application/json');
echo '"0.9.7"';
killme();
}
@@ -2163,12 +1696,12 @@ require_once('include/api_auth.php');
function api_friendica_version($type) {
if($type === 'xml') {
- header("Content-type: application/xml");
+ header('Content-type: application/xml');
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");
+ header('Content-type: application/json');
echo '"' . Zotlabs\Lib\System::get_project_version() . '"';
killme();
}
@@ -2179,35 +1712,39 @@ require_once('include/api_auth.php');
function api_ff_ids($type,$qtype) {
+
if(! api_user())
return false;
+ if($qtype == 'friends') {
+ $r = q("select abook_id from abook left join abconfig on abook_xchan = xchan and abook_channel = chan
+ where chan = %d and abook_self = 0 and abook_pending = 0 and cat = 'my_perms' and k = 'view_stream' and v = '1' ",
+ intval(api_user())
+ );
+ }
- // For Red, the closest thing we can do to figure out if you're friends is if both of you are sending each other your streams.
- // This won't work if either of you send your stream to everybody on the network
-
- if($qtype == 'friends')
- $sql_extra = sprintf(" AND ( abook_their_perms & %d )>0 and ( abook_my_perms & %d )>0 ", intval(PERMS_W_STREAM), intval(PERMS_W_STREAM));
- if($qtype == 'followers')
- $sql_extra = sprintf(" AND ( abook_my_perms & %d )>0 and not ( abook_their_perms & %d )>0 ", intval(PERMS_W_STREAM), intval(PERMS_W_STREAM));
-
- $r = q("SELECT abook_id FROM abook where abook_self = 0 and abook_channel = %d $sql_extra",
- intval(api_user())
- );
+ if($qtype == 'followers') {
+ $r = q("select abook_id from abook left join abconfig on abook_xchan = xchan and abook_channel = chan
+ where chan = %d and abook_self = 0 and abook_pending = 0 and cat = 'their_perms' and k = 'view_stream' and v = '1' ",
+ intval(api_user())
+ );
+ }
- if(is_array($r)) {
+ if($r) {
if($type === 'xml') {
- header("Content-type: application/xml");
+ header('Content-type: application/xml');
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n" . '<ids>' . "\r\n";
- foreach($r as $rr)
- echo '<id>' . $rr['abook_id'] . '</id>' . "\r\n";
+ foreach($r as $rv)
+ echo '<id>' . $rv['abook_id'] . '</id>' . "\r\n";
echo '</ids>' . "\r\n";
killme();
}
elseif($type === 'json') {
$ret = array();
- header("Content-type: application/json");
- foreach($r as $rr) $ret[] = $rr['abook_id'];
+ header('Content-type: application/json');
+ foreach($r as $rv) {
+ $ret[] = $rv['abook_id'];
+ }
echo json_encode($ret);
killme();
}
@@ -2222,102 +1759,112 @@ require_once('include/api_auth.php');
}
api_register_func('api/friends/ids','api_friends_ids',true);
api_register_func('api/followers/ids','api_followers_ids',true);
+ api_register_func('api/1.1/friends/ids','api_friends_ids',true);
+ api_register_func('api/1.1/followers/ids','api_followers_ids',true);
function api_direct_messages_new( $type) {
if (api_user()===false) return false;
- if (!x($_POST, "text") || !x($_POST,"screen_name")) return;
+ if (!x($_POST, 'text') || !x($_POST,'screen_name')) return;
- $sender = api_get_user($a);
+ $sender = api_get_user();
- require_once("include/message.php");
+ require_once('include/message.php');
// in a decentralised world the screen name is ambiguous
- $r = q("SELECT abook_id FROM abook left join xchan on abook_xchan = xchan_hash WHERE abook_channel=%d and xchan_addr like '%s'",
- intval(api_user()),
- dbesc($_POST['screen_name'] . '@%')
+ $r = q("SELECT abook_id FROM abook left join xchan on abook_xchan = xchan_hash
+ WHERE abook_channel = %d and xchan_addr like '%s'",
+ intval(api_user()),
+ dbesc($_POST['screen_name'] . '@%')
);
- $recipient = api_get_user( $r[0]['abook_id']);
- $replyto = '';
- $sub = '';
- if (x($_REQUEST,'replyto')) {
+ $recipient = api_get_user($r[0]['abook_id']);
+ $replyto = '';
+ $sub = '';
+
+ if(array_key_exists('replyto',$_REQUEST) && $_REQUEST['replyto']) {
$r = q('SELECT parent_mid, title FROM mail WHERE uid=%d AND id=%d',
- intval(api_user()),
- intval($_REQUEST['replyto']));
- $replyto = $r[0]['parent_mid'];
- $sub = $r[0]['title'];
+ intval(api_user()),
+ intval($_REQUEST['replyto'])
+ );
+ if($r) {
+ $replyto = $r[0]['parent_mid'];
+ $sub = $r[0]['title'];
+ }
}
else {
- if (x($_REQUEST,'title')) {
+ if(x($_REQUEST,'title')) {
$sub = $_REQUEST['title'];
}
else {
- $sub = ((strlen($_POST['text'])>10)?substr($_POST['text'],0,10)."...":$_POST['text']);
+ $sub = ((strlen($_POST['text']) > 10) ? substr($_POST['text'],0,10) . '...' : $_POST['text']);
}
}
$id = send_message(api_user(),$recipient['guid'], $_POST['text'], $sub, $replyto);
- if ($id > (-1)) {
- $r = q("SELECT * FROM mail WHERE id = %d", intval($id));
- $ret = api_format_message($r[0], $recipient, $sender);
-
- } else {
- $ret = array("error"=>$id);
+ if($id > (-1)) {
+ $r = q("SELECT * FROM mail WHERE id = %d",
+ intval($id)
+ );
+ if(! $r)
+ return false;
+
+ $ret = api_format_message($r[0], $recipient, $sender);
+ }
+ else {
+ $ret = [ 'error' => $id ];
}
- $data = Array('$messages'=>$ret);
-
- switch($type){
- case "atom":
- case "rss":
- $data = api_rss_extra( $data, $user_info);
- }
-
- return api_apply_template("direct_messages", $type, $data);
+ $data = [ 'messages' => $ret ];
+ return(api_apply_template('direct_messages', $type, $data));
}
+
api_register_func('api/direct_messages/new','api_direct_messages_new',true);
+ api_register_func('api/1.1/direct_messages/new','api_direct_messages_new',true);
function api_direct_messages_box( $type, $box) {
- if (api_user()===false) return false;
+ if(api_user() === false)
+ return false;
- $user_info = api_get_user($a);
+ $user_info = api_get_user();
// params
- $count = (x($_GET,'count')?$_GET['count']:20);
- $page = (x($_REQUEST,'page')?$_REQUEST['page']-1:0);
- if ($page<0) $page=0;
+ $count = (x($_GET,'count') ? $_GET['count'] : 20);
+ $page = (x($_REQUEST,'page') ? $_REQUEST['page'] - 1 : 0);
+ if($page < 0)
+ $page=0;
- $start = $page*$count;
+ $start = $page * $count;
$channel = App::get_channel();
$profile_url = z_root() . '/channel/' . $channel['channel_address'];
- if ($box=="sentbox") {
- $sql_extra = "from_xchan = '".dbesc( $channel['channel_hash'] )."'";
+ if ($box === 'sentbox') {
+ $sql_extra = "from_xchan = '" . dbesc( $channel['channel_hash'] ) . "'";
}
- elseif ($box=="conversation") {
- $sql_extra = "parent_mid = '".dbesc( $_GET["uri"] ) ."'";
+ elseif($box === 'conversation') {
+ $sql_extra = "parent_mid = '" . dbesc($_GET['uri']) . "'";
}
- elseif ($box=="all") {
- $sql_extra = "true";
+ elseif($box === 'all') {
+ $sql_extra = 'true';
}
- elseif ($box=="inbox") {
- $sql_extra = "from_xchan != '".dbesc( $channel['channel_hash'] )."'";
+ elseif($box === 'inbox') {
+ $sql_extra = "from_xchan != '" . dbesc($channel['channel_hash']) . "'";
}
$r = q("SELECT * FROM mail WHERE channel_id = %d AND $sql_extra ORDER BY created DESC LIMIT %d OFFSET %d",
intval(api_user()),
- intval($count), intval($start)
+ intval($count),
+ intval($start)
);
- $ret = Array();
+ $ret = array();
if($r) {
foreach($r as $item) {
- if ($item['from_xchan'] == $channel['channel_hash']) {
+ if ($item['from_xchan'] === $channel['channel_hash']) {
$sender = $user_info;
$recipient = api_get_user( null, $item['to_xchan']);
}
@@ -2326,39 +1873,38 @@ require_once('include/api_auth.php');
$recipient = $user_info;
}
- $ret[]=api_format_message($item, $recipient, $sender);
+ $ret[] = api_format_message($item, $recipient, $sender);
}
}
-
- $data = array('$messages' => $ret);
- switch($type){
- case "atom":
- case "rss":
- $data = api_rss_extra( $data, $user_info);
- }
-
- return api_apply_template("direct_messages", $type, $data);
+ $data = array('messages' => $ret);
+ return(api_apply_template('direct_messages', $type, $data));
}
- function api_direct_messages_sentbox( $type){
- return api_direct_messages_box( $type, "sentbox");
+ function api_direct_messages_sentbox($type){
+ return api_direct_messages_box($type, 'sentbox');
}
- function api_direct_messages_inbox( $type){
- return api_direct_messages_box( $type, "inbox");
+ function api_direct_messages_inbox($type){
+ return api_direct_messages_box($type, 'inbox');
}
- function api_direct_messages_all( $type){
- return api_direct_messages_box( $type, "all");
+ function api_direct_messages_all($type){
+ return api_direct_messages_box($type, 'all');
}
- function api_direct_messages_conversation( $type){
- return api_direct_messages_box( $type, "conversation");
+ function api_direct_messages_conversation($type){
+ return api_direct_messages_box($type, 'conversation');
}
+
api_register_func('api/direct_messages/conversation','api_direct_messages_conversation',true);
api_register_func('api/direct_messages/all','api_direct_messages_all',true);
api_register_func('api/direct_messages/sent','api_direct_messages_sentbox',true);
api_register_func('api/direct_messages','api_direct_messages_inbox',true);
+ api_register_func('api/1.1/direct_messages/conversation','api_direct_messages_conversation',true);
+ api_register_func('api/1.1/direct_messages/all','api_direct_messages_all',true);
+ api_register_func('api/1.1/direct_messages/sent','api_direct_messages_sentbox',true);
+ api_register_func('api/1.1/direct_messages','api_direct_messages_inbox',true);
+
function api_oauth_request_token( $type){
try{
@@ -2368,7 +1914,7 @@ require_once('include/api_auth.php');
$r = $oauth->fetch_request_token($req);
}catch(Exception $e){
logger('oauth_exception: ' . print_r($e->getMessage(),true));
- echo "error=". OAuth1Util::urlencode_rfc3986($e->getMessage());
+ echo 'error=' . OAuth1Util::urlencode_rfc3986($e->getMessage());
killme();
}
echo $r;
@@ -2378,10 +1924,12 @@ require_once('include/api_auth.php');
function api_oauth_access_token( $type){
try{
$oauth = new ZotOAuth1();
- $req = OAuth1Request::from_request();
- $r = $oauth->fetch_access_token($req);
- }catch(Exception $e){
- echo "error=". OAuth1Util::urlencode_rfc3986($e->getMessage()); killme();
+ $req = OAuth1Request::from_request();
+ $r = $oauth->fetch_access_token($req);
+ }
+ catch(Exception $e) {
+ echo 'error=' . OAuth1Util::urlencode_rfc3986($e->getMessage());
+ killme();
}
echo $r;
killme();
@@ -2390,6 +1938,9 @@ require_once('include/api_auth.php');
api_register_func('api/oauth/request_token', 'api_oauth_request_token', false);
api_register_func('api/oauth/access_token', 'api_oauth_access_token', false);
+ api_register_func('api/1.1/oauth/request_token', 'api_oauth_request_token', false);
+ api_register_func('api/1.1/oauth/access_token', 'api_oauth_access_token', false);
+
/*
Not implemented by now:
diff --git a/include/api_zot.php b/include/api_zot.php
new file mode 100644
index 000000000..e91d82b0b
--- /dev/null
+++ b/include/api_zot.php
@@ -0,0 +1,336 @@
+<?php
+
+
+ /*
+ * Red basic channel export
+ */
+
+ function api_export_basic( $type) {
+ if(api_user() === false) {
+ logger('api_export_basic: no user');
+ return false;
+ }
+
+ require_once('include/channel.php');
+
+ json_return_and_die(identity_basic_export(api_user(),(($_REQUEST['posts']) ? intval($_REQUEST['posts']) : 0 )));
+ }
+ api_register_func('api/export/basic','api_export_basic', true);
+ api_register_func('api/red/channel/export/basic','api_export_basic', true);
+ api_register_func('api/z/1.0/channel/export/basic','api_export_basic', true);
+
+
+ function api_channel_stream( $type) {
+ if(api_user() === false) {
+ logger('api_channel_stream: no user');
+ return false;
+ }
+
+ if($_SERVER['REQUEST_METHOD'] == 'POST') {
+ json_return_and_die(post_activity_item($_REQUEST));
+ }
+ else {
+ // fetch stream
+
+ }
+ }
+ api_register_func('api/red/channel/stream','api_channel_stream', true);
+ api_register_func('api/z/1.0/channel/stream','api_channel_stream', true);
+
+ function api_attach_list($type) {
+ logger('api_user: ' . api_user());
+ json_return_and_die(attach_list_files(api_user(),get_observer_hash(),'','','','created asc'));
+ }
+ api_register_func('api/red/files','api_attach_list', true);
+ api_register_func('api/z/1.0/files','api_attach_list', true);
+
+
+ function api_file_meta($type) {
+ if (api_user()===false) return false;
+ if(! $_REQUEST['file_id']) return false;
+ $r = q("select * from attach where uid = %d and hash = '%s' limit 1",
+ intval(api_user()),
+ dbesc($_REQUEST['file_id'])
+ );
+ if($r) {
+ unset($r[0]['content']);
+ $ret = array('attach' => $r[0]);
+ json_return_and_die($ret);
+ }
+ killme();
+ }
+
+ api_register_func('api/red/filemeta', 'api_file_meta', true);
+ api_register_func('api/z/1.0/filemeta', 'api_file_meta', true);
+
+
+ function api_file_data($type) {
+ if (api_user()===false) return false;
+ if(! $_REQUEST['file_id']) return false;
+ $start = (($_REQUEST['start']) ? intval($_REQUEST['start']) : 0);
+ $length = (($_REQUEST['length']) ? intval($_REQUEST['length']) : 0);
+
+ $r = q("select * from attach where uid = %d and hash = '%s' limit 1",
+ intval(api_user()),
+ dbesc($_REQUEST['file_id'])
+ );
+ if($r) {
+ $ptr = $r[0];
+ if($length === 0)
+ $length = intval($ptr['filesize']);
+
+ if($ptr['is_dir'])
+ $ptr['content'] = '';
+ elseif(! intval($r[0]['os_storage'])) {
+ $ptr['start'] = $start;
+ $x = substr(dbunescbin($ptr['content'],$start,$length));
+ $ptr['length'] = strlen($x);
+ $ptr['content'] = base64_encode($x);
+ }
+ else {
+ $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['content'] = base64_encode($x);
+ }
+ }
+
+ $ret = array('attach' => $ptr);
+ json_return_and_die($ret);
+ }
+ killme();
+ }
+
+ api_register_func('api/red/filedata', 'api_file_data', true);
+ api_register_func('api/z/1.0/filedata', 'api_file_data', true);
+
+ function api_file_export($type) {
+ if (api_user()===false) return false;
+ if(! $_REQUEST['file_id']) return false;
+
+ $ret = attach_export_data(api_user(),$_REQUEST['file_id']);
+ if($ret) {
+ json_return_and_die($ret);
+ }
+ killme();
+ }
+
+ api_register_func('api/red/file/export', 'api_file_export', true);
+ api_register_func('api/z/1.0/file/export', 'api_file_export', true);
+
+ function api_file_detail($type) {
+ if (api_user()===false) return false;
+ if(! $_REQUEST['file_id']) return false;
+ $r = q("select * from attach where uid = %d and hash = '%s' limit 1",
+ intval(api_user()),
+ dbesc($_REQUEST['file_id'])
+ );
+ if($r) {
+ if($r[0]['is_dir'])
+ $r[0]['content'] = '';
+ elseif(intval($r[0]['os_storage']))
+ $r[0]['content'] = base64_encode(file_get_contents(dbunescbin($r[0]['content'])));
+ else
+ $r[0]['content'] = base64_encode(dbunescbin($r[0]['content']));
+
+ $ret = array('attach' => $r[0]);
+ json_return_and_die($ret);
+ }
+ killme();
+ }
+
+ api_register_func('api/red/file', 'api_file_detail', true);
+ api_register_func('api/z/1.0/file', 'api_file_detail', true);
+
+
+ function api_albums($type) {
+ json_return_and_die(photos_albums_list(App::get_channel(),App::get_observer()));
+ }
+ api_register_func('api/red/albums','api_albums', true);
+ api_register_func('api/z/1.0/albums','api_albums', true);
+
+ function api_photos($type) {
+ $album = $_REQUEST['album'];
+ json_return_and_die(photos_list_photos(App::get_channel(),App::get_observer(),$album));
+ }
+ api_register_func('api/red/photos','api_photos', true);
+ api_register_func('api/z/1.0/photos','api_photos', true);
+
+ function api_photo_detail($type) {
+ 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 imgscale = %d limit 1",
+ intval(local_channel()),
+ dbesc($_REQUEST['photo_id']),
+ intval($scale)
+ );
+ if($r) {
+ $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]['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()),
+ dbesc($_REQUEST['photo_id'])
+ );
+ if($i) {
+ $ii = q("select * from item where parent = %d order by id",
+ intval($i[0]['id'])
+ );
+ if($ii) {
+ xchan_query($ii,true,0);
+ $ii = fetch_post_tags($ii,true);
+ if($ii) {
+ $ret['item'] = array();
+ foreach($ii as $iii)
+ $ret['item'][] = encode_item($iii,true);
+ }
+ }
+ }
+
+ json_return_and_die($ret);
+ }
+ killme();
+ }
+
+ api_register_func('api/red/photo', 'api_photo_detail', true);
+ api_register_func('api/z/1.0/photo', 'api_photo_detail', true);
+
+
+ function api_group_members($type) {
+ if(api_user() === false)
+ return false;
+
+ if($_REQUEST['group_id']) {
+ $r = q("select * from groups where uid = %d and id = %d limit 1",
+ intval(api_user()),
+ intval($_REQUEST['group_id'])
+ );
+ if($r) {
+ $x = q("select * from group_member left join xchan on group_member.xchan = xchan.xchan_hash
+ left join abook on abook_xchan = xchan_hash where gid = %d",
+ intval($_REQUEST['group_id'])
+ );
+ json_return_and_die($x);
+ }
+ }
+ }
+
+ api_register_func('api/red/group_members','api_group_members', true);
+ api_register_func('api/z/1.0/group_members','api_group_members', true);
+
+
+
+
+ function api_group($type) {
+ if(api_user() === false)
+ return false;
+
+ $r = q("select * from groups where uid = %d",
+ intval(api_user())
+ );
+ json_return_and_die($r);
+ }
+ api_register_func('api/red/group','api_group', true);
+ api_register_func('api/z/1.0/group','api_group', true);
+
+
+ function api_red_xchan($type) {
+ logger('api_xchan');
+
+ if(api_user() === false)
+ return false;
+ logger('api_xchan');
+ require_once('include/hubloc.php');
+
+ if($_SERVER['REQUEST_METHOD'] === 'POST') {
+ $r = xchan_store($_REQUEST);
+ }
+ $r = xchan_fetch($_REQUEST);
+ json_return_and_die($r);
+ };
+
+ api_register_func('api/red/xchan','api_red_xchan',true);
+ api_register_func('api/z/1.0/xchan','api_red_xchan',true);
+
+
+
+ function red_item_new( $type) {
+
+ if (api_user() === false) {
+ logger('api_red_item_new: no user');
+ return false;
+ }
+
+ logger('api_red_item_new: REQUEST ' . print_r($_REQUEST,true));
+ logger('api_red_item_new: FILES ' . print_r($_FILES,true));
+
+
+ // set this so that the item_post() function is quiet and doesn't redirect or emit json
+
+ $_REQUEST['api_source'] = true;
+ $_REQUEST['profile_uid'] = api_user();
+
+ if(x($_FILES,'media')) {
+ $_FILES['userfile'] = $_FILES['media'];
+ // upload the image if we have one
+ $_REQUEST['silent']='1'; //tell wall_upload function to return img info instead of echo
+ $mod = new Zotlabs\Module\Wall_upload();
+ $media = $mod->post();
+ if(strlen($media)>0)
+ $_REQUEST['body'] .= "\n\n".$media;
+ }
+
+ $mod = new Zotlabs\Module\Item();
+ $x = $mod->post();
+ json_return_and_die($x);
+ }
+
+ api_register_func('api/red/item/new','red_item_new', true);
+ api_register_func('api/z/1.0/item/new','red_item_new', true);
+
+
+ function red_item( $type) {
+
+ if (api_user() === false) {
+ logger('api_red_item_full: no user');
+ return false;
+ }
+
+ if($_REQUEST['mid']) {
+ $arr = array('mid' => $_REQUEST['mid']);
+ }
+ elseif($_REQUEST['item_id']) {
+ $arr = array('item_id' => $_REQUEST['item_id']);
+ }
+ else
+ json_return_and_die(array());
+
+ $arr['start'] = 0;
+ $arr['records'] = 999999;
+ $arr['item_type'] = '*';
+
+ $i = items_fetch($arr,App::get_channel(),get_observer_hash());
+
+ if(! $i)
+ json_return_and_die(array());
+
+ $ret = array();
+ $tmp = array();
+ foreach($i as $ii) {
+ $tmp[] = encode_item($ii,true);
+ }
+ $ret['item'] = $tmp;
+
+ json_return_and_die($ret);
+ }
+
+ api_register_func('api/red/item/full','red_item', true);
+ api_register_func('api/z/1.0/item/full','red_item', true);
+
+
diff --git a/include/bbcode.php b/include/bbcode.php
index a82b658b1..c3041c6a6 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -784,6 +784,9 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false)
$Text = preg_replace("(\[footer\](.*?)\[\/footer\])ism", "<div class=\"wall-item-footer\">$1</div>", $Text);
}
// Check for list text
+
+ $Text = preg_replace("/<br \/>\[\*\]/ism",'[*]',$Text);
+
$Text = str_replace("[*]", "<li>", $Text);
$Text = str_replace("[]", "<li><input type=\"checkbox\" disabled=\"disabled\">", $Text);
$Text = str_replace("[x]", "<li><input type=\"checkbox\" checked=\"checked\" disabled=\"disabled\">", $Text);
@@ -807,6 +810,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false)
$Text = preg_replace("/\[checklist\](.*?)\[\/checklist\]/ism", '<ul class="checklist" style="list-style-type: none;">$1</ul>', $Text);
$Text = preg_replace("/\[ul\](.*?)\[\/ul\]/ism", '<ul class="listbullet" style="list-style-type: circle;">$1</ul>', $Text);
$Text = preg_replace("/\[ol\](.*?)\[\/ol\]/ism", '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>', $Text);
+ $Text = preg_replace("/\[\/li\]<br \/>\[li\]/ism",'[/li][li]',$Text);
$Text = preg_replace("/\[li\](.*?)\[\/li\]/ism", '<li>$1</li>', $Text);
// [dl] tags have an optional [dl terms="bi"] form where bold/italic/underline/mono/large
diff --git a/include/dba/dba_driver.php b/include/dba/dba_driver.php
index 852dc16af..36353354c 100755
--- a/include/dba/dba_driver.php
+++ b/include/dba/dba_driver.php
@@ -72,6 +72,7 @@ class DBA {
define('NULL_DATE', self::$dba->get_null_date());
define('ACTIVE_DBTYPE', self::$dbtype);
+ define('TQUOT', self::$dba->get_table_quote());
return self::$dba;
}
@@ -88,6 +89,7 @@ abstract class dba_driver {
const INSTALL_SCRIPT='install/schema_mysql.sql';
const NULL_DATE = '0001-01-01 00:00:00';
const UTC_NOW = 'UTC_TIMESTAMP()';
+ const TQUOT = "`";
protected $db;
protected $pdo = array();
@@ -157,6 +159,11 @@ abstract class dba_driver {
return static::INSTALL_SCRIPT;
}
+ function get_table_quote() {
+ return static::TQUOT;
+ }
+
+
function utcnow() {
return static::UTC_NOW;
}
@@ -313,7 +320,7 @@ function db_concat($fld, $sep) {
* queries return true if the command was successful or false if it wasn't.
*
* Example:
- * $r = q("SELECT * FROM `%s` WHERE `uid` = %d",
+ * $r = q("SELECT * FROM %s WHERE `uid` = %d",
* 'user', 1);
*
* @param string $sql The SQL query to execute
diff --git a/include/dba/dba_postgres.php b/include/dba/dba_postgres.php
index 03b29d703..ae3e5a76f 100644
--- a/include/dba/dba_postgres.php
+++ b/include/dba/dba_postgres.php
@@ -7,6 +7,7 @@ class dba_postgres extends dba_driver {
const INSTALL_SCRIPT='install/schema_postgres.sql';
const NULL_DATE = '0001-01-01 00:00:00';
const UTC_NOW = "now() at time zone 'UTC'";
+ const TQUOT = '"';
function connect($server,$port,$user,$pass,$db) {
if(!$port) $port = 5432;
diff --git a/include/import.php b/include/import.php
index 479e45cc2..370d3085e 100644
--- a/include/import.php
+++ b/include/import.php
@@ -84,9 +84,9 @@ function import_channel($channel, $account_id, $seize) {
if($clean) {
dbesc_array($clean);
- $r = dbq("INSERT INTO channel (`"
- . implode("`, `", array_keys($clean))
- . "`) VALUES ('"
+ $r = dbq("INSERT INTO channel (" . TQUOT
+ . implode(TQUOT . ", " . TQUOT, array_keys($clean))
+ . TQUOT . ") VALUES ('"
. implode("', '", array_values($clean))
. "')"
);
@@ -132,9 +132,9 @@ function import_config($channel,$configs) {
unset($config['id']);
$config['uid'] = $channel['channel_id'];
dbesc_array($config);
- $r = dbq("INSERT INTO pconfig (`"
- . implode("`, `", array_keys($config))
- . "`) VALUES ('"
+ $r = dbq("INSERT INTO pconfig (" . TQUOT
+ . implode(TQUOT . ", " . TQUOT, array_keys($config))
+ . TQUOT . ") VALUES ('"
. implode("', '", array_values($config))
. "')" );
}
@@ -163,9 +163,9 @@ function import_profiles($channel,$profiles) {
$profile['thumb'] = z_root() . '/photo/profile/m/' . $channel['channel_id'];
dbesc_array($profile);
- $r = dbq("INSERT INTO profile (`"
- . implode("`, `", array_keys($profile))
- . "`) VALUES ('"
+ $r = dbq("INSERT INTO profile (" . TQUOT
+ . implode(TQUOT . ", " . TQUOT, array_keys($profile))
+ . TQUOT . ") VALUES ('"
. implode("', '", array_values($profile))
. "')"
);
@@ -205,9 +205,9 @@ function import_hublocs($channel,$hublocs,$seize) {
unset($hubloc['hubloc_id']);
dbesc_array($hubloc);
- $r = dbq("INSERT INTO hubloc (`"
- . implode("`, `", array_keys($hubloc))
- . "`) VALUES ('"
+ $r = dbq("INSERT INTO hubloc (" . TQUOT
+ . implode(TQUOT . ", " . TQUOT, array_keys($hubloc))
+ . TQUOT . ") VALUES ('"
. implode("', '", array_values($hubloc))
. "')"
);
@@ -244,9 +244,9 @@ function import_objs($channel,$objs) {
dbesc_array($obj);
- $r = dbq("INSERT INTO obj (`"
- . implode("`, `", array_keys($obj))
- . "`) VALUES ('"
+ $r = dbq("INSERT INTO obj (" . TQUOT
+ . implode(TQUOT . ", " . TQUOT, array_keys($obj))
+ . TQUOT . ") VALUES ('"
. implode("', '", array_values($obj))
. "')"
);
@@ -304,7 +304,7 @@ function sync_objs($channel,$objs) {
if($exists) {
unset($obj['obj_obj']);
foreach($obj as $k => $v) {
- $r = q("UPDATE obj SET `%s` = '%s' WHERE obj_obj = '%s' AND obj_channel = %d",
+ $r = q("UPDATE obj SET " . TQUOT . "%s" . TQUOT . " = '%s' WHERE obj_obj = '%s' AND obj_channel = %d",
dbesc($k),
dbesc($v),
dbesc($hash),
@@ -316,9 +316,9 @@ function sync_objs($channel,$objs) {
dbesc_array($obj);
- $r = dbq("INSERT INTO obj (`"
- . implode("`, `", array_keys($obj))
- . "`) VALUES ('"
+ $r = dbq("INSERT INTO obj (" . TQUOT
+ . implode(TQUOT . ", " . TQUOT, array_keys($obj))
+ . TQUOT . ") VALUES ('"
. implode("', '", array_values($obj))
. "')"
);
@@ -352,9 +352,9 @@ function import_apps($channel,$apps) {
$hash = $app['app_id'];
dbesc_array($app);
- $r = dbq("INSERT INTO app (`"
- . implode("`, `", array_keys($app))
- . "`) VALUES ('"
+ $r = dbq("INSERT INTO app (" . TQUOT
+ . implode(TQUOT . ", " . TQUOT, array_keys($app))
+ . TQUOT . ") VALUES ('"
. implode("', '", array_values($app))
. "')"
);
@@ -451,7 +451,7 @@ function sync_apps($channel,$apps) {
if($exists) {
unset($app['app_id']);
foreach($app as $k => $v) {
- $r = q("UPDATE app SET `%s` = '%s' WHERE app_id = '%s' AND app_channel = %d",
+ $r = q("UPDATE app SET " . TQUOT . "%s" . TQUOT . " = '%s' WHERE app_id = '%s' AND app_channel = %d",
dbesc($k),
dbesc($v),
dbesc($hash),
@@ -461,9 +461,9 @@ function sync_apps($channel,$apps) {
}
else {
dbesc_array($app);
- $r = dbq("INSERT INTO app (`"
- . implode("`, `", array_keys($app))
- . "`) VALUES ('"
+ $r = dbq("INSERT INTO app (" . TQUOT
+ . implode(TQUOT . ", " . TQUOT, array_keys($app))
+ . TQUOT . ") VALUES ('"
. implode("', '", array_values($app))
. "')"
);
@@ -503,9 +503,9 @@ function import_chatrooms($channel,$chatrooms) {
$chatroom['cr_uid'] = $channel['channel_id'];
dbesc_array($chatroom);
- $r = dbq("INSERT INTO chatroom (`"
- . implode("`, `", array_keys($chatroom))
- . "`) VALUES ('"
+ $r = dbq("INSERT INTO chatroom (" . TQUOT
+ . implode(TQUOT . ", " . TQUOT, array_keys($chatroom))
+ . TQUOT . ") VALUES ('"
. implode("', '", array_values($chatroom))
. "')"
);
@@ -559,7 +559,7 @@ function sync_chatrooms($channel,$chatrooms) {
if($exists) {
foreach($chatroom as $k => $v) {
- $r = q("UPDATE chatroom SET `%s` = '%s' WHERE cr_name = '%s' AND cr_uid = %d",
+ $r = q("UPDATE chatroom SET " . TQUOT . "%s" . TQUOT . " = '%s' WHERE cr_name = '%s' AND cr_uid = %d",
dbesc($k),
dbesc($v),
dbesc($name),
@@ -569,9 +569,9 @@ function sync_chatrooms($channel,$chatrooms) {
}
else {
dbesc_array($chatroom);
- $r = dbq("INSERT INTO chatroom (`"
- . implode("`, `", array_keys($chatroom))
- . "`) VALUES ('"
+ $r = dbq("INSERT INTO chatroom (" . TQUOT
+ . implode(TQUOT . ", " . TQUOT, array_keys($chatroom))
+ . TQUOT . ") VALUES ('"
. implode("', '", array_values($chatroom))
. "')"
);
@@ -685,9 +685,9 @@ function import_events($channel,$events) {
convert_oldfields($event,'ignore','dismissed');
dbesc_array($event);
- $r = dbq("INSERT INTO event (`"
- . implode("`, `", array_keys($event))
- . "`) VALUES ('"
+ $r = dbq("INSERT INTO event (" . TQUOT
+ . implode(TQUOT . ", " . TQUOT, array_keys($event))
+ . TQUOT . ") VALUES ('"
. implode("', '", array_values($event))
. "')"
);
@@ -736,7 +736,7 @@ function sync_events($channel,$events) {
if($exists) {
foreach($event as $k => $v) {
- $r = q("UPDATE event SET `%s` = '%s' WHERE event_hash = '%s' AND uid = %d",
+ $r = q("UPDATE event SET " . TQUOT . "%s" . TQUOT . " = '%s' WHERE event_hash = '%s' AND uid = %d",
dbesc($k),
dbesc($v),
dbesc($event['event_hash']),
@@ -746,9 +746,9 @@ function sync_events($channel,$events) {
}
else {
dbesc_array($event);
- $r = dbq("INSERT INTO event (`"
- . implode("`, `", array_keys($event))
- . "`) VALUES ('"
+ $r = dbq("INSERT INTO event (" . TQUOT
+ . implode(TQUOT . ", " . TQUOT, array_keys($event))
+ . TQUOT . ") VALUES ('"
. implode("', '", array_values($event))
. "')"
);
@@ -928,9 +928,9 @@ function import_likes($channel,$likes) {
continue;
dbesc_array($like);
- $r = dbq("INSERT INTO likes (`"
- . implode("`, `", array_keys($like))
- . "`) VALUES ('"
+ $r = dbq("INSERT INTO likes (" . TQUOT
+ . implode(TQUOT . ", " . TQUOT, array_keys($like))
+ . TQUOT . ") VALUES ('"
. implode("', '", array_values($like))
. "')" );
}
@@ -961,9 +961,9 @@ function import_conv($channel,$convs) {
continue;
dbesc_array($conv);
- $r = dbq("INSERT INTO conv (`"
- . implode("`, `", array_keys($conv))
- . "`) VALUES ('"
+ $r = dbq("INSERT INTO conv (" . TQUOT
+ . implode(TQUOT . ", " . TQUOT, array_keys($conv))
+ . TQUOT . ") VALUES ('"
. implode("', '", array_values($conv))
. "')" );
}
@@ -1118,15 +1118,15 @@ function sync_files($channel,$files) {
foreach($att as $k => $v) {
if($str)
$str .= ",";
- $str .= " `" . $k . "` = '" . $v . "' ";
+ $str .= " " . TQUOT . $k . TQUOT . " = '" . $v . "' ";
}
- $r = dbq("update `attach` set " . $str . " where id = " . intval($attach_id) );
+ $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 ('"
+ $r = dbq("INSERT INTO attach (" . TQUOT
+ . implode(TQUOT . ", " . TQUOT, array_keys($att))
+ . TQUOT . ") VALUES ('"
. implode("', '", array_values($att))
. "')" );
}
@@ -1236,14 +1236,14 @@ function sync_files($channel,$files) {
foreach($p as $k => $v) {
if($str)
$str .= ",";
- $str .= " `" . $k . "` = '" . $v . "' ";
+ $str .= " " . TQUOT . $k . TQUOT . " = '" . $v . "' ";
}
- $r = dbq("update `photo` set " . $str . " where id = " . intval($exists[0]['id']) );
+ $r = dbq("update photo set " . $str . " where id = " . intval($exists[0]['id']) );
}
else {
- $r = dbq("INSERT INTO photo (`"
- . implode("`, `", array_keys($p))
- . "`) VALUES ('"
+ $r = dbq("INSERT INTO photo (" . TQUOT
+ . implode(TQUOT . ", " . TQUOT, array_keys($p))
+ . TQUOT . ") VALUES ('"
. implode("', '", array_values($p))
. "')" );
}
diff --git a/include/items.php b/include/items.php
index 333795827..b432748ee 100755
--- a/include/items.php
+++ b/include/items.php
@@ -1855,9 +1855,9 @@ function item_store($arr, $allow_exec = false, $deliver = true) {
dbesc_array($arr);
- $r = dbq("INSERT INTO `item` (`"
- . implode("`, `", array_keys($arr))
- . "`) VALUES ('"
+ $r = dbq("INSERT INTO " . TQUOT . 'item' . TQUOT . " (" . TQUOT
+ . implode(TQUOT . ', ' . TQUOT, array_keys($arr))
+ . TQUOT . ") VALUES ('"
. implode("', '", array_values($arr))
. "')" );
@@ -2174,7 +2174,7 @@ function item_store_update($arr,$allow_exec = false, $deliver = true) {
foreach($arr as $k => $v) {
if($str)
$str .= ",";
- $str .= " `" . $k . "` = '" . $v . "' ";
+ $str .= " " . TQUOT . $k . TQUOT . " = '" . $v . "' ";
}
$r = dbq("update item set " . $str . " where id = " . $orig_post_id );
@@ -3092,9 +3092,9 @@ function mail_store($arr) {
logger('mail_store: ' . print_r($arr,true), LOGGER_DATA);
- $r = dbq("INSERT INTO mail (`"
- . implode("`, `", array_keys($arr))
- . "`) VALUES ('"
+ $r = dbq("INSERT INTO mail (" . TQUOT
+ . implode(TQUOT . ', ' . TQUOT, array_keys($arr))
+ . TQUOT . ") VALUES ('"
. implode("', '", array_values($arr))
. "')" );
diff --git a/include/network.php b/include/network.php
index 7851f8976..97dca2b1a 100644
--- a/include/network.php
+++ b/include/network.php
@@ -2288,3 +2288,22 @@ function z_mail($params) {
logger('notification: z_mail returns ' . $res, LOGGER_DEBUG);
return $res;
}
+
+// discover the best API path available for redmatrix/hubzilla servers
+
+function probe_api_path($host) {
+
+ $schemes = ['https', 'http' ];
+ $paths = ['/api/z/1.0/version', '/api/red/version' ];
+
+ foreach($schemes as $scheme) {
+ foreach($paths as $path) {
+ $curpath = $scheme . '://' . $host . $path;
+ $x = z_fetch_url($curpath);
+ if($x['success'] && ! strlen($x['body'],'not implemented'))
+ return str_replace('version','',$curpath);
+ }
+ }
+
+ return '';
+} \ No newline at end of file
diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php
index 9b6d38cc1..87e4cbd0c 100644
--- a/include/photo/photo_driver.php
+++ b/include/photo/photo_driver.php
@@ -340,31 +340,31 @@ abstract class photo_driver {
intval($p['imgscale'])
);
if($x) {
- $r = q("UPDATE `photo` set
- `aid` = %d,
- `uid` = %d,
- `xchan` = '%s',
- `resource_id` = '%s',
- `created` = '%s',
- `edited` = '%s',
- `filename` = '%s',
- `mimetype` = '%s',
- `album` = '%s',
- `height` = %d,
- `width` = %d,
- `content` = '%s',
- `os_storage` = %d,
- `filesize` = %d,
- `imgscale` = %d,
- `photo_usage` = %d,
- `title` = '%s',
- `description` = '%s',
- `os_path` = '%s',
- `display_path` = '%s',
- `allow_cid` = '%s',
- `allow_gid` = '%s',
- `deny_cid` = '%s',
- `deny_gid` = '%s'
+ $r = q("UPDATE photo set
+ aid = %d,
+ uid = %d,
+ xchan = '%s',
+ resource_id = '%s',
+ created = '%s',
+ edited = '%s',
+ filename = '%s',
+ mimetype = '%s',
+ album = '%s',
+ height = %d,
+ width = %d,
+ content = '%s',
+ os_storage = %d,
+ filesize = %d,
+ imgscale = %d,
+ photo_usage = %d,
+ title = '%s',
+ description = '%s',
+ os_path = '%s',
+ display_path = '%s',
+ allow_cid = '%s',
+ allow_gid = '%s',
+ deny_cid = '%s',
+ deny_gid = '%s'
where id = %d",
intval($p['aid']),
@@ -395,8 +395,8 @@ abstract class photo_driver {
);
}
else {
- $r = q("INSERT INTO `photo`
- ( `aid`, `uid`, `xchan`, `resource_id`, `created`, `edited`, `filename`, mimetype, `album`, `height`, `width`, `content`, `os_storage`, `filesize`, `imgscale`, `photo_usage`, `title`, `description`, `os_path`, `display_path`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` )
+ $r = q("INSERT INTO photo
+ ( aid, uid, xchan, resource_id, created, edited, filename, mimetype, album, height, width, content, os_storage, filesize, imgscale, photo_usage, title, description, os_path, display_path, 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', '%s', '%s' )",
intval($p['aid']),
intval($p['uid']),
@@ -432,33 +432,33 @@ 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 `imgscale` = %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),
intval($scale)
);
if(count($x)) {
- $r = q("UPDATE `photo`
- set `aid` = %d,
- `uid` = %d,
- `xchan` = '%s',
- `resource_id` = '%s',
- `created` = '%s',
- `edited` = '%s',
- `filename` = '%s',
- `mimetype` = '%s',
- `album` = '%s',
- `height` = %d,
- `width` = %d,
- `content` = '%s',
- `filesize` = %d,
- `imgscale` = %d,
- `photo_usage` = %d,
- `allow_cid` = '%s',
- `allow_gid` = '%s',
- `deny_cid` = '%s',
- `deny_gid` = '%s'
+ $r = q("UPDATE photo
+ set aid = %d,
+ uid = %d,
+ xchan = '%s',
+ resource_id = '%s',
+ created = '%s',
+ edited = '%s',
+ filename = '%s',
+ mimetype = '%s',
+ album = '%s',
+ height = %d,
+ width = %d,
+ content = '%s',
+ filesize = %d,
+ imgscale = %d,
+ photo_usage = %d,
+ allow_cid = '%s',
+ allow_gid = '%s',
+ deny_cid = '%s',
+ deny_gid = '%s'
where id = %d",
intval($aid),
@@ -484,8 +484,8 @@ abstract class photo_driver {
);
}
else {
- $r = q("INSERT INTO `photo`
- ( `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` )
+ $r = q("INSERT INTO photo
+ ( 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),
diff --git a/include/text.php b/include/text.php
index 2f89d3d98..6d5b72f49 100644
--- a/include/text.php
+++ b/include/text.php
@@ -3005,7 +3005,7 @@ function text_highlight($s,$lang) {
// echo (($xml->asXML('data.xml')) ? 'Your XML file has been generated successfully!' : 'Error generating XML file!');
function arrtoxml($root_elem,$arr) {
- $xml = new SimpleXMLElement('<' . $root_elem . '/>');
+ $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><' . $root_elem . '></' . $root_elem . '>', null, false);
array2XML($xml,$arr);
return $xml->asXML();
}
diff --git a/include/zot.php b/include/zot.php
index a214a1b0c..2e02b96e7 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -3521,8 +3521,9 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) {
if(count($clean)) {
foreach($clean as $k => $v) {
- $r = dbq("UPDATE profile set `" . dbesc($k) . "` = '" . dbesc($v)
- . "' where profile_guid = '" . dbesc($profile['profile_guid']) . "' and uid = " . intval($channel['channel_id']));
+ $r = dbq("UPDATE profile set " . TQUOT . dbesc($k) . TQUOT . " = '" . dbesc($v)
+ . "' where profile_guid = '" . dbesc($profile['profile_guid'])
+ . "' and uid = " . intval($channel['channel_id']));
}
}
}
diff --git a/view/js/main.js b/view/js/main.js
index 0239fc1f8..5435dfd87 100644
--- a/view/js/main.js
+++ b/view/js/main.js
@@ -854,6 +854,7 @@ function pageUpdate() {
scroll_next = false;
updatePageItems(update_mode,data);
$("#page-spinner").spin(false);
+ $(".autotime").timeago();
in_progress = false;
});
}
diff --git a/view/js/mod_connections.js b/view/js/mod_connections.js
index 112204a5a..68add4eed 100644
--- a/view/js/mod_connections.js
+++ b/view/js/mod_connections.js
@@ -4,13 +4,13 @@ $(document).ready(function() {
});
$("#contacts-search").keyup(function(event){
- if(event.keyCode == 13){
- $("#contacts-search").click();
- }
+ if(event.keyCode == 13){
+ $("#contacts-search").click();
+ }
});
$(".autocomplete-w1 .selected").keyup(function(event){
- if(event.keyCode == 13){
- $("#contacts-search").click();
- }
+ if(event.keyCode == 13){
+ $("#contacts-search").click();
+ }
});