aboutsummaryrefslogtreecommitdiffstats
path: root/mod/impel.php
diff options
context:
space:
mode:
Diffstat (limited to 'mod/impel.php')
-rw-r--r--mod/impel.php30
1 files changed, 19 insertions, 11 deletions
diff --git a/mod/impel.php b/mod/impel.php
index 3c29d7cdb..1c7541bef 100644
--- a/mod/impel.php
+++ b/mod/impel.php
@@ -7,11 +7,13 @@ function impel_init(&$a) {
$ret = array('success' => false);
- if(! $local_user())
+ if(! local_user())
json_return_and_die($ret);
+ logger('impel: ' . print_r($_REQUEST,true), LOGGER_DATA);
+
$elm = $_REQUEST['element'];
- $x = base64_urldecode($elm);
+ $x = base64url_decode($elm);
if(! $x)
json_return_and_die($ret);
@@ -20,7 +22,7 @@ function impel_init(&$a) {
json_return_and_die($ret);
- $channel = get_channel();
+ $channel = $a->get_channel();
$arr = array();
@@ -28,14 +30,17 @@ function impel_init(&$a) {
case 'webpage':
$arr['item_restrict'] = ITEM_WEBPAGE;
$namespace = 'WEBPAGE';
+ $installed_type = t('webpage');
break;
case 'block':
$arr['item_restrict'] = ITEM_BUILDBLOCK;
$namespace = 'BUILDBLOCK';
+ $installed_type = t('block');
break;
case 'layout':
$arr['item_restrict'] = ITEM_PDL;
$namespace = 'PDL';
+ $installed_type = t('layout');
break;
default:
logger('mod_impel: unrecognised element type' . print_r($j,true));
@@ -46,8 +51,10 @@ function impel_init(&$a) {
$arr['title'] = $j['title'];
$arr['body'] = $j['body'];
$arr['term'] = $j['term'];
+ $arr['created'] = datetime_convert('UTC','UTC', $j['created']);
+ $arr['edited'] = datetime_convert('UTC','UTC',$j['edited']);
$arr['owner_xchan'] = get_observer_hash();
- $arr['author_xchan'] = (($j['author_xchan']) ? $j['author_xchan'] : $get_observer_hash());
+ $arr['author_xchan'] = (($j['author_xchan']) ? $j['author_xchan'] : get_observer_hash());
$arr['mimetype'] = (($j['mimetype']) ? $j['mimetype'] : 'text/bbcode');
if(! $j['mid'])
@@ -63,9 +70,6 @@ function impel_init(&$a) {
-
- $channel = get_channel();
-
// Verify ability to use html or php!!!
$execflag = false;
@@ -82,19 +86,21 @@ function impel_init(&$a) {
$remote_id = 0;
- $z = q("select * from item_id where $sid = '%s' and service = '%s' and uid = %d limit 1",
+ $z = q("select * from item_id where sid = '%s' and service = '%s' and uid = %d limit 1",
dbesc($pagetitle),
dbesc($namespace),
intval(local_user())
);
- $i = q("select id from item where mid = '%s' and $uid = %d limit 1",
+ $i = q("select id from item where mid = '%s' and uid = %d limit 1",
dbesc($arr['mid']),
intval(local_user())
);
if($z && $i) {
$remote_id = $z[0]['id'];
$arr['id'] = $i[0]['id'];
- $x = item_store_update($arr,$execflag);
+ // don't update if it has the same timestamp as the original
+ if($arr['edited'] > $i[0]['edited'])
+ $x = item_store_update($arr,$execflag);
}
else {
$x = item_store($arr,$execflag);
@@ -102,12 +108,14 @@ function impel_init(&$a) {
if($x['success'])
$item_id = $x['item_id'];
- $channel = get_channel();
update_remote_id($channel,$item_id,$arr['item_restrict'],$pagetitle,$namespace,$remote_id,$arr['mid']);
$ret['success'] = true;
+
+ info( sprintf( t('%s element installed'), $installed_type));
+
json_return_and_die(true);
} \ No newline at end of file