aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Module
diff options
context:
space:
mode:
Diffstat (limited to 'Zotlabs/Module')
-rw-r--r--Zotlabs/Module/Achievements.php2
-rw-r--r--Zotlabs/Module/Acl.php28
-rw-r--r--Zotlabs/Module/Admin.php2
-rw-r--r--Zotlabs/Module/Block.php10
-rw-r--r--Zotlabs/Module/Blocks.php15
-rw-r--r--Zotlabs/Module/Cal.php2
-rw-r--r--Zotlabs/Module/Channel.php2
-rw-r--r--Zotlabs/Module/Chat.php2
-rw-r--r--Zotlabs/Module/Cloud.php2
-rw-r--r--Zotlabs/Module/Common.php2
-rw-r--r--Zotlabs/Module/Connect.php2
-rw-r--r--Zotlabs/Module/Connedit.php26
-rw-r--r--Zotlabs/Module/Cover_photo.php6
-rw-r--r--Zotlabs/Module/Dav.php2
-rw-r--r--Zotlabs/Module/Display.php5
-rw-r--r--Zotlabs/Module/Editblock.php6
-rw-r--r--Zotlabs/Module/Editlayout.php7
-rw-r--r--Zotlabs/Module/Editwebpage.php6
-rw-r--r--Zotlabs/Module/Embedphotos.php180
-rw-r--r--Zotlabs/Module/Follow.php2
-rw-r--r--Zotlabs/Module/Hcard.php2
-rw-r--r--Zotlabs/Module/Id.php2
-rw-r--r--Zotlabs/Module/Impel.php26
-rw-r--r--Zotlabs/Module/Import.php9
-rw-r--r--Zotlabs/Module/Import_items.php4
-rw-r--r--Zotlabs/Module/Item.php34
-rw-r--r--Zotlabs/Module/Layouts.php22
-rw-r--r--Zotlabs/Module/Page.php22
-rw-r--r--Zotlabs/Module/Pdledit.php10
-rw-r--r--Zotlabs/Module/Photo.php4
-rw-r--r--Zotlabs/Module/Photos.php2
-rw-r--r--Zotlabs/Module/Profile.php2
-rw-r--r--Zotlabs/Module/Profile_photo.php124
-rw-r--r--Zotlabs/Module/Profiles.php4
-rw-r--r--Zotlabs/Module/Profperm.php4
-rw-r--r--Zotlabs/Module/README.md80
-rw-r--r--Zotlabs/Module/Rmagic.php8
-rw-r--r--Zotlabs/Module/Siteinfo.php27
-rw-r--r--Zotlabs/Module/Thing.php4
-rw-r--r--Zotlabs/Module/Uexport.php2
-rw-r--r--Zotlabs/Module/Viewconnections.php2
-rw-r--r--Zotlabs/Module/Webpages.php20
-rw-r--r--Zotlabs/Module/Wiki.php515
43 files changed, 1017 insertions, 221 deletions
diff --git a/Zotlabs/Module/Achievements.php b/Zotlabs/Module/Achievements.php
index 8ddefb3e5..1529448d3 100644
--- a/Zotlabs/Module/Achievements.php
+++ b/Zotlabs/Module/Achievements.php
@@ -18,7 +18,7 @@ class Achievements extends \Zotlabs\Web\Controller {
$profile = 0;
$profile = argv(1);
- profile_load($a,$which,$profile);
+ profile_load($which,$profile);
$r = q("select channel_id from channel where channel_address = '%s'",
dbesc($which)
diff --git a/Zotlabs/Module/Acl.php b/Zotlabs/Module/Acl.php
index 7bc197a93..2bc4ba62d 100644
--- a/Zotlabs/Module/Acl.php
+++ b/Zotlabs/Module/Acl.php
@@ -65,18 +65,20 @@ class Acl extends \Zotlabs\Web\Controller {
intval($count),
intval($start)
);
-
- foreach($r as $g){
- // logger('acl: group: ' . $g['gname'] . ' members: ' . group_get_members_xchan($g['id']));
- $groups[] = array(
- "type" => "g",
- "photo" => "images/twopeople.png",
- "name" => $g['gname'],
- "id" => $g['id'],
- "xid" => $g['hash'],
- "uids" => group_get_members_xchan($g['id']),
- "link" => ''
- );
+
+ if($r) {
+ foreach($r as $g){
+ // logger('acl: group: ' . $g['gname'] . ' members: ' . group_get_members_xchan($g['id']));
+ $groups[] = array(
+ "type" => "g",
+ "photo" => "images/twopeople.png",
+ "name" => $g['gname'],
+ "id" => $g['id'],
+ "xid" => $g['hash'],
+ "uids" => group_get_members_xchan($g['id']),
+ "link" => ''
+ );
+ }
}
}
@@ -204,7 +206,7 @@ class Acl extends \Zotlabs\Web\Controller {
else
$r = array();
- if(count($r)) {
+ if($r) {
foreach($r as $g){
// remove RSS feeds from ACLs - they are inaccessible
diff --git a/Zotlabs/Module/Admin.php b/Zotlabs/Module/Admin.php
index 21ab7f6a7..085d13fd7 100644
--- a/Zotlabs/Module/Admin.php
+++ b/Zotlabs/Module/Admin.php
@@ -1738,7 +1738,7 @@ class Admin extends \Zotlabs\Web\Controller {
// name, label, value, help string, extra data...
'$debugging' => array('debugging', t("Debugging"),get_config('system','debugging'), ""),
- '$logfile' => array('logfile', t("Log file"), get_config('system','logfile'), t("Must be writable by web server. Relative to your Red top-level directory.")),
+ '$logfile' => array('logfile', t("Log file"), get_config('system','logfile'), t("Must be writable by web server. Relative to your top-level webserver directory.")),
'$loglevel' => array('loglevel', t("Log level"), get_config('system','loglevel'), "", $log_choices),
'$form_security_token' => get_form_security_token('admin_logs'),
diff --git a/Zotlabs/Module/Block.php b/Zotlabs/Module/Block.php
index 062befdb5..e671730f6 100644
--- a/Zotlabs/Module/Block.php
+++ b/Zotlabs/Module/Block.php
@@ -12,7 +12,7 @@ class Block extends \Zotlabs\Web\Controller {
$which = argv(1);
$profile = 0;
- profile_load($a,$which,$profile);
+ profile_load($which,$profile);
if(\App::$profile['profile_uid'])
head_set_icon(\App::$profile['thumb']);
@@ -52,8 +52,8 @@ class Block extends \Zotlabs\Web\Controller {
require_once('include/security.php');
$sql_options = item_permissions_sql($u[0]['channel_id']);
- $r = q("select item.* from item left join item_id on item.id = item_id.iid
- where item.uid = %d and sid = '%s' and service = 'BUILDBLOCK' and
+ $r = q("select item.* from item left join iconfig on item.id = iconfig.iid
+ where item.uid = %d and iconfig.cat = 'system' and iconfig.v = '%s' and iconfig.k = 'BUILDBLOCK' and
item_type = %d $sql_options $revision limit 1",
intval($u[0]['channel_id']),
dbesc($page_id),
@@ -64,8 +64,8 @@ class Block extends \Zotlabs\Web\Controller {
// Check again with no permissions clause to see if it is a permissions issue
- $x = q("select item.* from item left join item_id on item.id = item_id.iid
- where item.uid = %d and sid = '%s' and service = 'BUILDBLOCK' and
+ $x = q("select item.* from item left join iconfig on item.id = iconfig.iid
+ where item.uid = %d and iconfig.cat = 'system' and iconfig.v = '%s' and iconfig.k = 'BUILDBLOCK' and
item_type = %d $revision limit 1",
intval($u[0]['channel_id']),
dbesc($page_id),
diff --git a/Zotlabs/Module/Blocks.php b/Zotlabs/Module/Blocks.php
index 32650a090..e6a97794d 100644
--- a/Zotlabs/Module/Blocks.php
+++ b/Zotlabs/Module/Blocks.php
@@ -22,12 +22,12 @@ class Blocks extends \Zotlabs\Web\Controller {
else
return;
- profile_load($a,$which);
+ profile_load($which);
}
- function get() {
+ function get() {
if(! \App::$profile) {
notice( t('Requested profile is not available.') . EOL );
@@ -111,8 +111,11 @@ class Blocks extends \Zotlabs\Web\Controller {
$editor = status_editor($a,$x);
- $r = q("select iid, sid, mid, title, body, mimetype, created, edited from item_id left join item on item_id.iid = item.id
- where item_id.uid = %d and service = 'BUILDBLOCK' and item_type = %d order by item.created desc",
+
+ $r = q("select iconfig.iid, iconfig.k, iconfig.v, mid, title, body, mimetype, created, edited from iconfig
+ left join item on iconfig.iid = item.id
+ where uid = %d and iconfig.cat = 'system' and iconfig.k = 'BUILDBLOCK'
+ and item_type = %d order by item.created desc",
intval($owner),
intval(ITEM_TYPE_BLOCK)
);
@@ -129,12 +132,12 @@ class Blocks extends \Zotlabs\Web\Controller {
'created' => $rr['created'],
'edited' => $rr['edited'],
'mimetype' => $rr['mimetype'],
- 'pagetitle' => $rr['sid'],
+ 'pagetitle' => $rr['v'],
'mid' => $rr['mid']
);
$pages[$rr['iid']][] = array(
'url' => $rr['iid'],
- 'name' => $rr['sid'],
+ 'name' => $rr['v'],
'title' => $rr['title'],
'created' => $rr['created'],
'edited' => $rr['edited'],
diff --git a/Zotlabs/Module/Cal.php b/Zotlabs/Module/Cal.php
index 1da42684d..fd4169e68 100644
--- a/Zotlabs/Module/Cal.php
+++ b/Zotlabs/Module/Cal.php
@@ -20,7 +20,7 @@ class Cal extends \Zotlabs\Web\Controller {
if(argc() > 1) {
$nick = argv(1);
- profile_load($a,$nick);
+ profile_load($nick);
$channelx = channelx_by_nick($nick);
diff --git a/Zotlabs/Module/Channel.php b/Zotlabs/Module/Channel.php
index 29bfcbc3c..d09388901 100644
--- a/Zotlabs/Module/Channel.php
+++ b/Zotlabs/Module/Channel.php
@@ -48,7 +48,7 @@ class Channel extends \Zotlabs\Web\Controller {
// Run profile_load() here to make sure the theme is set before
// we start loading content
- profile_load($a,$which,$profile);
+ profile_load($which,$profile);
}
diff --git a/Zotlabs/Module/Chat.php b/Zotlabs/Module/Chat.php
index 026e8369a..ff55a9319 100644
--- a/Zotlabs/Module/Chat.php
+++ b/Zotlabs/Module/Chat.php
@@ -39,7 +39,7 @@ class Chat extends \Zotlabs\Web\Controller {
// Run profile_load() here to make sure the theme is set before
// we start loading content
- profile_load($a,$which,$profile);
+ profile_load($which,$profile);
}
diff --git a/Zotlabs/Module/Cloud.php b/Zotlabs/Module/Cloud.php
index b691475ce..833b1b493 100644
--- a/Zotlabs/Module/Cloud.php
+++ b/Zotlabs/Module/Cloud.php
@@ -37,7 +37,7 @@ class Cloud extends \Zotlabs\Web\Controller {
\App::$page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . z_root() . '/feed/' . $which . '" />' . "\r\n";
if ($which)
- profile_load($a, $which, $profile);
+ profile_load( $which, $profile);
$auth = new \Zotlabs\Storage\BasicAuth();
diff --git a/Zotlabs/Module/Common.php b/Zotlabs/Module/Common.php
index 1c428d256..2f3c57267 100644
--- a/Zotlabs/Module/Common.php
+++ b/Zotlabs/Module/Common.php
@@ -21,7 +21,7 @@ class Common extends \Zotlabs\Web\Controller {
);
if($x)
- profile_load($a,$x[0]['channel_address'],0);
+ profile_load($x[0]['channel_address'],0);
}
diff --git a/Zotlabs/Module/Connect.php b/Zotlabs/Module/Connect.php
index f68e0baac..962c05cce 100644
--- a/Zotlabs/Module/Connect.php
+++ b/Zotlabs/Module/Connect.php
@@ -26,7 +26,7 @@ class Connect extends \Zotlabs\Web\Controller {
if($r)
\App::$data['channel'] = $r[0];
- profile_load($a,$which,'');
+ profile_load($which,'');
}
function post() {
diff --git a/Zotlabs/Module/Connedit.php b/Zotlabs/Module/Connedit.php
index 33deac4c8..feed9cb1a 100644
--- a/Zotlabs/Module/Connedit.php
+++ b/Zotlabs/Module/Connedit.php
@@ -16,14 +16,14 @@ require_once('include/zot.php');
require_once('include/widgets.php');
require_once('include/photos.php');
-/* @brief Initialize the connection-editor
- *
- *
- */
-
class Connedit extends \Zotlabs\Web\Controller {
+ /* @brief Initialize the connection-editor
+ *
+ *
+ */
+
function init() {
if(! local_channel())
@@ -51,7 +51,7 @@ class Connedit extends \Zotlabs\Web\Controller {
*
*/
- function post() {
+ function post() {
if(! local_channel())
return;
@@ -219,7 +219,7 @@ class Connedit extends \Zotlabs\Web\Controller {
//Update profile photo permissions
logger('A new profile was assigned - updating profile photos');
- profile_photo_set_profile_perms($profile_id);
+ profile_photo_set_profile_perms(local_channel(),$profile_id);
}
@@ -345,7 +345,7 @@ class Connedit extends \Zotlabs\Web\Controller {
unset($clone['abook_account']);
unset($clone['abook_channel']);
- $abconfig = load_abconfig($channel['channel_hash'],$clone['abook_xchan']);
+ $abconfig = load_abconfig($channel['channel_id'],$clone['abook_xchan']);
if($abconfig)
$clone['abconfig'] = $abconfig;
@@ -357,7 +357,7 @@ class Connedit extends \Zotlabs\Web\Controller {
*
*/
- function get() {
+ function get() {
$sort_type = 0;
$o = '';
@@ -418,7 +418,13 @@ class Connedit extends \Zotlabs\Web\Controller {
goaway(z_root() . '/connedit/' . $contact_id);
}
-
+ if($cmd === 'resetphoto') {
+ q("update xchan set xchan_photo_date = '2001-01-01 00:00:00' where xchan_hash = '%s' limit 1",
+ dbesc($orig_record[0]['xchan_hash'])
+ );
+ $cmd = 'refresh';
+ }
+
if($cmd === 'refresh') {
if($orig_record[0]['xchan_network'] === 'zot') {
if(! zot_refresh($orig_record[0],\App::get_channel()))
diff --git a/Zotlabs/Module/Cover_photo.php b/Zotlabs/Module/Cover_photo.php
index a72c3389f..9887b8203 100644
--- a/Zotlabs/Module/Cover_photo.php
+++ b/Zotlabs/Module/Cover_photo.php
@@ -29,7 +29,7 @@ class Cover_photo extends \Zotlabs\Web\Controller {
}
$channel = \App::get_channel();
- profile_load($a,$channel['channel_address']);
+ profile_load($channel['channel_address']);
}
@@ -40,7 +40,7 @@ class Cover_photo extends \Zotlabs\Web\Controller {
*
*/
- function post() {
+ function post() {
if(! local_channel()) {
return;
@@ -271,7 +271,7 @@ class Cover_photo extends \Zotlabs\Web\Controller {
*/
- function get() {
+ function get() {
if(! local_channel()) {
notice( t('Permission denied.') . EOL );
diff --git a/Zotlabs/Module/Dav.php b/Zotlabs/Module/Dav.php
index 2fddabe19..6528e0271 100644
--- a/Zotlabs/Module/Dav.php
+++ b/Zotlabs/Module/Dav.php
@@ -58,7 +58,7 @@ class Dav extends \Zotlabs\Web\Controller {
\App::$page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . z_root() . '/feed/' . $which . '" />' . "\r\n";
if ($which)
- profile_load($a, $which, $profile);
+ profile_load( $which, $profile);
diff --git a/Zotlabs/Module/Display.php b/Zotlabs/Module/Display.php
index c1a0d84bc..d1d4edc7d 100644
--- a/Zotlabs/Module/Display.php
+++ b/Zotlabs/Module/Display.php
@@ -106,12 +106,13 @@ class Display extends \Zotlabs\Web\Controller {
$x = q("select * from channel where channel_id = %d limit 1",
intval($target_item['uid'])
);
- $y = q("select * from item_id where uid = %d and service = 'WEBPAGE' and iid = %d limit 1",
+ $y = q("select * from iconfig left join item on iconfig.iid = item.id
+ where item.uid = %d and iconfig.cat = 'system' and iconfig.k = 'WEBPAGE' and item.id = %d limit 1",
intval($target_item['uid']),
intval($target_item['id'])
);
if($x && $y) {
- goaway(z_root() . '/page/' . $x[0]['channel_address'] . '/' . $y[0]['sid']);
+ goaway(z_root() . '/page/' . $x[0]['channel_address'] . '/' . $y[0]['v']);
}
else {
notice( t('Page not found.') . EOL);
diff --git a/Zotlabs/Module/Editblock.php b/Zotlabs/Module/Editblock.php
index fb86557f2..6a9fa5f2d 100644
--- a/Zotlabs/Module/Editblock.php
+++ b/Zotlabs/Module/Editblock.php
@@ -21,7 +21,7 @@ class Editblock extends \Zotlabs\Web\Controller {
else
return;
- profile_load($a,$which);
+ profile_load($which);
}
@@ -85,11 +85,11 @@ class Editblock extends \Zotlabs\Web\Controller {
intval($owner)
);
if($itm) {
- $item_id = q("select * from item_id where service = 'BUILDBLOCK' and iid = %d limit 1",
+ $item_id = q("select * from iconfig where cat = 'system' and k = 'BUILDBLOCK' and iid = %d limit 1",
intval($itm[0]['id'])
);
if($item_id)
- $block_title = $item_id[0]['sid'];
+ $block_title = $item_id[0]['v'];
}
else {
notice( t('Item not found') . EOL);
diff --git a/Zotlabs/Module/Editlayout.php b/Zotlabs/Module/Editlayout.php
index 5028882d2..26732dc77 100644
--- a/Zotlabs/Module/Editlayout.php
+++ b/Zotlabs/Module/Editlayout.php
@@ -21,7 +21,7 @@ class Editlayout extends \Zotlabs\Web\Controller {
else
return;
- profile_load($a,$which);
+ profile_load($which);
}
@@ -96,11 +96,12 @@ class Editlayout extends \Zotlabs\Web\Controller {
intval($owner)
);
- $item_id = q("select * from item_id where service = 'PDL' and iid = %d limit 1",
+ $item_id = q("select * from iconfig where cat = 'system' and k = 'PDL' and iid = %d limit 1",
intval($itm[0]['id'])
);
if($item_id)
- $layout_title = $item_id[0]['sid'];
+ $layout_title = $item_id[0]['v'];
+
$rp = 'layouts/' . $which;
diff --git a/Zotlabs/Module/Editwebpage.php b/Zotlabs/Module/Editwebpage.php
index 1b5c320a0..5cd409e1e 100644
--- a/Zotlabs/Module/Editwebpage.php
+++ b/Zotlabs/Module/Editwebpage.php
@@ -23,7 +23,7 @@ class Editwebpage extends \Zotlabs\Web\Controller {
else
return;
- profile_load($a,$which);
+ profile_load($which);
}
@@ -114,11 +114,11 @@ class Editwebpage extends \Zotlabs\Web\Controller {
$itm[0]['body'] = crypto_unencapsulate(json_decode_plus($itm[0]['body']),$key);
}
- $item_id = q("select * from item_id where service = 'WEBPAGE' and iid = %d limit 1",
+ $item_id = q("select * from iconfig where cat = 'system' and k = 'WEBPAGE' and iid = %d limit 1",
intval($itm[0]['id'])
);
if($item_id)
- $page_title = $item_id[0]['sid'];
+ $page_title = $item_id[0]['v'];
$mimetype = $itm[0]['mimetype'];
diff --git a/Zotlabs/Module/Embedphotos.php b/Zotlabs/Module/Embedphotos.php
new file mode 100644
index 000000000..2cd420664
--- /dev/null
+++ b/Zotlabs/Module/Embedphotos.php
@@ -0,0 +1,180 @@
+<?php
+namespace Zotlabs\Module;
+
+/**
+ *
+ * This is the POST destination for the embedphotos button
+ *
+ */
+
+
+class Embedphotos extends \Zotlabs\Web\Controller {
+
+ function get() {
+
+ }
+
+ function post() {
+
+ if (argc() > 1 && argv(1) === 'album') {
+ // API: /embedphotos/album
+ $name = (x($_POST,'name') ? $_POST['name'] : null );
+ if (!$name) {
+ json_return_and_die(array('errormsg' => 'Error retrieving album', 'status' => false));
+ }
+ $album = $this->embedphotos_widget_album(array('channel' => \App::get_channel(), 'album' => $name));
+ json_return_and_die(array('status' => true, 'content' => $album));
+
+ }
+ if (argc() > 1 && argv(1) === 'albumlist') {
+ // API: /embedphotos/albumlist
+ $album_list = $this->embedphotos_album_list($a);
+ json_return_and_die(array('status' => true, 'albumlist' => $album_list));
+
+ }
+ if (argc() > 1 && argv(1) === 'photolink') {
+ // API: /embedphotos/photolink
+ $href = (x($_POST,'href') ? $_POST['href'] : null );
+ if (!$href) {
+ json_return_and_die(array('errormsg' => 'Error retrieving link ' . $href, 'status' => false));
+ }
+ $resource_id = array_pop(explode("/", $href));
+ $r = q("SELECT obj from item where resource_type = 'photo' and resource_id = '%s' limit 1",
+ dbesc($resource_id)
+ );
+ if(!$r) {
+ json_return_and_die(array('errormsg' => 'Error retrieving resource ' . $resource_id, 'status' => false));
+ }
+ $obj = json_decode($r[0]['obj'], true);
+ if(x($obj,'body')) {
+ $photolink = $obj['body'];
+ } elseif (x($obj,'bbcode')) {
+ $photolink = $obj['bbcode'];
+ } else {
+ json_return_and_die(array('errormsg' => 'Error retrieving resource ' . $resource_id, 'status' => false));
+ }
+ json_return_and_die(array('status' => true, 'photolink' => $photolink));
+
+ }
+ }
+
+
+/**
+ * Copied from include/widgets.php::widget_album() with a modification to get the profile_uid from
+ * the input array as in widget_item()
+ * @param type $name
+ * @return string
+ */
+function embedphotos_widget_album($args) {
+
+ $channel_id = 0;
+ if(array_key_exists('channel',$args))
+ $channel = $args['channel'];
+ $channel_id = intval($channel['channel_id']);
+ if(! $channel_id)
+ $channel_id = \App::$profile_uid;
+ if(! $channel_id)
+ return '';
+ $owner_uid = $channel_id;
+ require_once('include/security.php');
+ $sql_extra = permissions_sql($channel_id);
+
+ if(! perm_is_allowed($channel_id,get_observer_hash(),'view_storage'))
+ return '';
+
+ if($args['album'])
+ $album = $args['album'];
+ if($args['title'])
+ $title = $args['title'];
+
+ /**
+ * This may return incorrect permissions if you have multiple directories of the same name.
+ * It is a limitation of the photo table using a name for a photo album instead of a folder hash
+ */
+
+ if($album) {
+ $x = q("select hash from attach where filename = '%s' and uid = %d limit 1",
+ dbesc($album),
+ intval($owner_uid)
+ );
+ if($x) {
+ $y = attach_can_view_folder($owner_uid,get_observer_hash(),$x[0]['hash']);
+ if(! $y)
+ return '';
+ }
+ }
+
+ $order = 'DESC';
+
+ $r = q("SELECT p.resource_id, p.id, p.filename, p.mimetype, p.imgscale, p.description, p.created FROM photo p INNER JOIN
+ (SELECT resource_id, max(imgscale) imgscale FROM photo WHERE uid = %d AND album = '%s' AND imgscale <= 4 AND photo_usage IN ( %d, %d ) $sql_extra GROUP BY resource_id) ph
+ ON (p.resource_id = ph.resource_id AND p.imgscale = ph.imgscale)
+ ORDER BY created $order",
+ intval($owner_uid),
+ dbesc($album),
+ intval(PHOTO_NORMAL),
+ intval(PHOTO_PROFILE)
+ );
+
+ $photos = array();
+ if(count($r)) {
+ $twist = 'rotright';
+ foreach($r as $rr) {
+
+ if($twist == 'rotright')
+ $twist = 'rotleft';
+ else
+ $twist = 'rotright';
+
+ $ext = $phototypes[$rr['mimetype']];
+
+ $imgalt_e = $rr['filename'];
+ $desc_e = $rr['description'];
+
+ $imagelink = (z_root() . '/photos/' . \App::$data['channel']['channel_address'] . '/image/' . $rr['resource_id']
+ . (($_GET['order'] === 'posted') ? '?f=&order=posted' : ''));
+
+ $photos[] = array(
+ 'id' => $rr['id'],
+ 'twist' => ' ' . $twist . rand(2,4),
+ 'link' => $imagelink,
+ 'title' => t('View Photo'),
+ 'src' => z_root() . '/photo/' . $rr['resource_id'] . '-' . $rr['imgscale'] . '.' .$ext,
+ 'alt' => $imgalt_e,
+ 'desc'=> $desc_e,
+ 'ext' => $ext,
+ 'hash'=> $rr['resource_id'],
+ 'unknown' => t('Unknown')
+ );
+ }
+ }
+
+ $tpl = get_markup_template('photo_album.tpl');
+ $o .= replace_macros($tpl, array(
+ '$photos' => $photos,
+ '$album' => (($title) ? $title : $album),
+ '$album_id' => rand(),
+ '$album_edit' => array(t('Edit Album'), $album_edit),
+ '$can_post' => false,
+ '$upload' => array(t('Upload'), z_root() . '/photos/' . \App::$profile['channel_address'] . '/upload/' . bin2hex($album)),
+ '$order' => false,
+ '$upload_form' => $upload_form,
+ '$usage' => $usage_message
+ ));
+
+ return $o;
+}
+
+
+function embedphotos_album_list($a) {
+ $o = '';
+ require_once('include/photos.php');
+ $p = photos_albums_list(\App::get_channel(), \App::get_observer());
+ if ($p['success']) {
+ return $p['albums'];
+ } else {
+ return null;
+ }
+}
+
+}
diff --git a/Zotlabs/Module/Follow.php b/Zotlabs/Module/Follow.php
index 1df382a89..3641330c9 100644
--- a/Zotlabs/Module/Follow.php
+++ b/Zotlabs/Module/Follow.php
@@ -43,7 +43,7 @@ class Follow extends \Zotlabs\Web\Controller {
unset($clone['abook_account']);
unset($clone['abook_channel']);
- $abconfig = load_abconfig($channel['channel_hash'],$clone['abook_xchan']);
+ $abconfig = load_abconfig($channel['channel_id'],$clone['abook_xchan']);
if($abconfig)
$clone['abconfig'] = $abconfig;
diff --git a/Zotlabs/Module/Hcard.php b/Zotlabs/Module/Hcard.php
index 2636e676b..93c8d3ece 100644
--- a/Zotlabs/Module/Hcard.php
+++ b/Zotlabs/Module/Hcard.php
@@ -40,7 +40,7 @@ class Hcard extends \Zotlabs\Web\Controller {
}
}
- profile_load($a,$which,$profile);
+ profile_load($which,$profile);
}
diff --git a/Zotlabs/Module/Id.php b/Zotlabs/Module/Id.php
index 6a94b57f5..e053bf99c 100644
--- a/Zotlabs/Module/Id.php
+++ b/Zotlabs/Module/Id.php
@@ -57,7 +57,7 @@ class Id extends \Zotlabs\Web\Controller {
$profile = '';
$channel = \App::get_channel();
- profile_load($a,$which,$profile);
+ profile_load($which,$profile);
$op = new MysqlProvider;
$op->server();
diff --git a/Zotlabs/Module/Impel.php b/Zotlabs/Module/Impel.php
index e326f7818..735c311d0 100644
--- a/Zotlabs/Module/Impel.php
+++ b/Zotlabs/Module/Impel.php
@@ -137,9 +137,7 @@ class Impel extends \Zotlabs\Web\Controller {
require_once('library/urlify/URLify.php');
$pagetitle = strtolower(\URLify::transliterate($j['pagetitle']));
}
-
-
-
+
// Verify ability to use html or php!!!
$execflag = false;
@@ -154,21 +152,14 @@ class Impel extends \Zotlabs\Web\Controller {
}
}
- $remote_id = 0;
-
- $z = q("select * from item_id where sid = '%s' and service = '%s' and uid = %d limit 1",
- dbesc($pagetitle),
- dbesc($namespace),
- intval(local_channel())
- );
-
$i = q("select id, edited, item_deleted from item where mid = '%s' and uid = %d limit 1",
dbesc($arr['mid']),
intval(local_channel())
);
+
+ \Zotlabs\Lib\IConfig::Set($arr,'system',$namespace,(($pagetitle) ? $pagetitle : substr($arr['mid'],0,16)),true);
- if($z && $i) {
- $remote_id = $z[0]['id'];
+ if($i) {
$arr['id'] = $i[0]['id'];
// don't update if it has the same timestamp as the original
if($arr['edited'] > $i[0]['edited'])
@@ -182,12 +173,12 @@ class Impel extends \Zotlabs\Web\Controller {
intval(local_channel())
);
}
- $x = item_store($arr,$execflag);
+ else
+ $x = item_store($arr,$execflag);
}
- if($x['success']) {
+ if($x && $x['success']) {
$item_id = $x['item_id'];
- update_remote_id($channel,$item_id,$arr['item_type'],$pagetitle,$namespace,$remote_id,$arr['mid']);
}
}
@@ -199,7 +190,8 @@ class Impel extends \Zotlabs\Web\Controller {
notice( sprintf( t('%s element installation failed'), $installed_type));
}
- //??? should perhaps return ret?
+ //??? should perhaps return ret?
+
json_return_and_die(true);
}
diff --git a/Zotlabs/Module/Import.php b/Zotlabs/Module/Import.php
index 122e27e90..e34f5e49e 100644
--- a/Zotlabs/Module/Import.php
+++ b/Zotlabs/Module/Import.php
@@ -131,6 +131,8 @@ class Import extends \Zotlabs\Web\Controller {
// import channel
+ $relocate = ((array_key_exists('relocate',$data)) ? $data['relocate'] : null);
+
if(array_key_exists('channel',$data)) {
if($completed < 1) {
@@ -387,8 +389,7 @@ class Import extends \Zotlabs\Web\Controller {
if($abconfig) {
// @fixme does not handle sync of del_abconfig
foreach($abconfig as $abc) {
- if($abc['chan'] === $channel['channel_hash'])
- set_abconfig($abc['chan'],$abc['xchan'],$abc['cat'],$abc['k'],$abc['v']);
+ set_abconfig($channel['channel_id'],$abc['xchan'],$abc['cat'],$abc['k'],$abc['v']);
}
}
@@ -475,7 +476,7 @@ class Import extends \Zotlabs\Web\Controller {
import_events($channel,$data['event']);
if(is_array($data['event_item']))
- import_items($channel,$data['event_item']);
+ import_items($channel,$data['event_item'],false,$relocate);
if(is_array($data['menu']))
import_menus($channel,$data['menu']);
@@ -486,7 +487,7 @@ class Import extends \Zotlabs\Web\Controller {
$saved_notification_flags = notifications_off($channel['channel_id']);
if($import_posts && array_key_exists('item',$data) && $data['item'])
- import_items($channel,$data['item']);
+ import_items($channel,$data['item'],false,$relocate);
notifications_on($channel['channel_id'],$saved_notification_flags);
diff --git a/Zotlabs/Module/Import_items.php b/Zotlabs/Module/Import_items.php
index a862836c5..07b1c620c 100644
--- a/Zotlabs/Module/Import_items.php
+++ b/Zotlabs/Module/Import_items.php
@@ -92,7 +92,7 @@ class Import_items extends \Zotlabs\Web\Controller {
if(array_key_exists('item',$data) && $data['item']) {
- import_items($channel,$data['item']);
+ import_items($channel,$data['item'],false,((array_key_exists('relocate',$data)) ? $data['relocate'] : null));
}
if(array_key_exists('item_id',$data) && $data['item_id']) {
@@ -106,7 +106,7 @@ class Import_items extends \Zotlabs\Web\Controller {
- function get() {
+ function get() {
if(! local_channel()) {
notice( t('Permission denied') . EOL);
diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php
index 2601feb0a..369dd3948 100644
--- a/Zotlabs/Module/Item.php
+++ b/Zotlabs/Module/Item.php
@@ -1,4 +1,5 @@
<?php
+
namespace Zotlabs\Module;
/**
@@ -229,7 +230,7 @@ class Item extends \Zotlabs\Web\Controller {
if($namespace && $remote_id) {
// It wasn't an internally generated post - see if we've got an item matching this remote service id
- $i = q("select iid from item_id where service = '%s' and sid = '%s' limit 1",
+ $i = q("select iid from iconfig where cat = 'system' and k = '%s' and v = '%s' limit 1",
dbesc($namespace),
dbesc($remote_id)
);
@@ -880,13 +881,21 @@ class Item extends \Zotlabs\Web\Controller {
}
}
+ if($webpage) {
+ Zlib\IConfig::Set($datarray,'system', webpage_to_namespace($webpage),
+ (($pagetitle) ? $pagetitle : substr($datarray['mid'],0,16)),true);
+ }
+ elseif($namespace) {
+ Zlib\IConfig::Set($datarray,'system', $namespace,
+ (($remote_id) ? $remote_id : substr($datarray['mid'],0,16)),true);
+ }
+
+
if($orig_post) {
$datarray['id'] = $post_id;
- item_store_update($datarray,$execflag);
-
- update_remote_id($channel,$post_id,$webpage,$pagetitle,$namespace,$remote_id,$mid);
-
+ $x = item_store_update($datarray,$execflag);
+
if(! $parent) {
$r = q("select * from item where id = %d",
intval($post_id)
@@ -894,10 +903,7 @@ class Item extends \Zotlabs\Web\Controller {
if($r) {
xchan_query($r);
$sync_item = fetch_post_tags($r);
- $rid = q("select * from item_id where iid = %d",
- intval($post_id)
- );
- build_sync_packet($uid,array('item' => array(encode_item($sync_item[0],true)),'item_id' => $rid));
+ build_sync_packet($uid,array('item' => array(encode_item($sync_item[0],true))));
}
}
if(! $nopush)
@@ -978,10 +984,7 @@ class Item extends \Zotlabs\Web\Controller {
goaway(z_root() . "/" . $return_path );
// NOTREACHED
}
-
-
- update_remote_id($channel,$post_id,$webpage,$pagetitle,$namespace,$remote_id,$mid);
-
+
if(($parent) && ($parent != $post_id)) {
// Store the comment signature information in case we need to relay to Diaspora
//$ditem = $datarray;
@@ -995,10 +998,7 @@ class Item extends \Zotlabs\Web\Controller {
if($r) {
xchan_query($r);
$sync_item = fetch_post_tags($r);
- $rid = q("select * from item_id where iid = %d",
- intval($post_id)
- );
- build_sync_packet($uid,array('item' => array(encode_item($sync_item[0],true)),'item_id' => $rid));
+ build_sync_packet($uid,array('item' => array(encode_item($sync_item[0],true))));
}
}
diff --git a/Zotlabs/Module/Layouts.php b/Zotlabs/Module/Layouts.php
index 9b9fc22f3..c07f65ce1 100644
--- a/Zotlabs/Module/Layouts.php
+++ b/Zotlabs/Module/Layouts.php
@@ -21,7 +21,7 @@ class Layouts extends \Zotlabs\Web\Controller {
else
return;
- profile_load($a,$which);
+ profile_load($which);
}
@@ -90,13 +90,14 @@ class Layouts extends \Zotlabs\Web\Controller {
return;
}
- //This feature is not exposed in redbasic ui since it is not clear why one would want to
- //download a json encoded pdl file - we dont have a possibility to import it.
- //Use the buildin share/install feature instead.
+ // This feature is not exposed in redbasic ui since it is not clear why one would want to
+ // download a json encoded pdl file - we dont have a possibility to import it.
+ // Use the buildin share/install feature instead.
+
if((argc() > 3) && (argv(2) === 'share') && (argv(3))) {
- $r = q("select sid, service, mimetype, title, body from item_id
- left join item on item.id = item_id.iid
- where item_id.uid = %d and item.mid = '%s' and service = 'PDL' order by sid asc",
+ $r = q("select iconfig.v, iconfig.k, mimetype, title, body from iconfig
+ left join item on item.id = iconfig.iid
+ where uid = %d and mid = '%s' and iconfig.cat = 'system' and iconfig.k = 'PDL' order by iconfig.v asc",
intval($owner),
dbesc(argv(3))
);
@@ -141,8 +142,9 @@ class Layouts extends \Zotlabs\Web\Controller {
$editor = status_editor($a,$x);
- $r = q("select iid, sid, mid, title, body, mimetype, created, edited, item_type from item_id left join item on item_id.iid = item.id
- where item_id.uid = %d and service = 'PDL' and item_type = %d order by item.created desc",
+ $r = q("select iconfig.iid, iconfig.v, mid, title, body, mimetype, created, edited, item_type from iconfig
+ left join item on iconfig.iid = item.id
+ where uid = %d and iconfig.cat = 'system' and iconfig.k = 'PDL' and item_type = %d order by item.created desc",
intval($owner),
intval(ITEM_TYPE_PDL)
);
@@ -164,7 +166,7 @@ class Layouts extends \Zotlabs\Web\Controller {
);
$pages[$rr['iid']][] = array(
'url' => $rr['iid'],
- 'title' => $rr['sid'],
+ 'title' => $rr['v'],
'descr' => $rr['title'],
'mid' => $rr['mid'],
'created' => $rr['created'],
diff --git a/Zotlabs/Module/Page.php b/Zotlabs/Module/Page.php
index 14273614c..6ef285dd0 100644
--- a/Zotlabs/Module/Page.php
+++ b/Zotlabs/Module/Page.php
@@ -13,7 +13,7 @@ class Page extends \Zotlabs\Web\Controller {
$which = argv(1);
$profile = 0;
- profile_load($a,$which,$profile);
+ profile_load($which,$profile);
@@ -65,9 +65,10 @@ class Page extends \Zotlabs\Web\Controller {
require_once('include/security.php');
$sql_options = item_permissions_sql($u[0]['channel_id']);
- $r = q("select item.* from item left join item_id on item.id = item_id.iid
- where item.uid = %d and sid = '%s' and item.item_delayed = 0 and (( service = 'WEBPAGE' and item_type = %d )
- OR ( service = 'PDL' AND item_type = %d )) $sql_options $revision limit 1",
+ $r = q("select item.* from item left join iconfig on item.id = iconfig.iid
+ where item.uid = %d and iconfig.cat = 'system' and iconfig.v = '%s' and item.item_delayed = 0
+ and (( iconfig.k = 'WEBPAGE' and item_type = %d )
+ OR ( iconfig.k = 'PDL' AND item_type = %d )) $sql_options $revision limit 1",
intval($u[0]['channel_id']),
dbesc($page_id),
intval(ITEM_TYPE_WEBPAGE),
@@ -77,9 +78,9 @@ class Page extends \Zotlabs\Web\Controller {
// Check again with no permissions clause to see if it is a permissions issue
- $x = q("select item.* from item left join item_id on item.id = item_id.iid
- where item.uid = %d and sid = '%s' and item.item_delayed = 0 and service = 'WEBPAGE' and
- item_type = %d $revision limit 1",
+ $x = q("select item.* from item left join iconfig on item.id = iconfig.iid
+ where item.uid = %d and iconfig.cat = 'system' and iconfig.v = '%s' and item.item_delayed = 0
+ and iconfig.k = 'WEBPAGE' and item_type = %d $revision limit 1",
intval($u[0]['channel_id']),
dbesc($page_id),
intval(ITEM_TYPE_WEBPAGE)
@@ -119,11 +120,8 @@ class Page extends \Zotlabs\Web\Controller {
\App::$data['webpage'] = $r;
}
-
-
-
-
- function get() {
+
+ function get() {
$r = \App::$data['webpage'];
if(! $r)
diff --git a/Zotlabs/Module/Pdledit.php b/Zotlabs/Module/Pdledit.php
index accfb6fa1..5cb00f165 100644
--- a/Zotlabs/Module/Pdledit.php
+++ b/Zotlabs/Module/Pdledit.php
@@ -20,7 +20,7 @@ class Pdledit extends \Zotlabs\Web\Controller {
}
- function get() {
+ function get() {
if(! local_channel()) {
notice( t('Permission denied.') . EOL);
@@ -32,18 +32,18 @@ class Pdledit extends \Zotlabs\Web\Controller {
else {
$o .= '<div class="generic-content-wrapper-styled">';
$o .= '<h1>' . t('Edit System Page Description') . '</h1>';
- $files = glob('mod/*');
+ $files = glob('Zotlabs/Module/*.php');
if($files) {
foreach($files as $f) {
- $name = basename($f,'.php');
+ $name = lcfirst(basename($f,'.php'));
$x = theme_include('mod_' . $name . '.pdl');
if($x) {
$o .= '<a href="pdledit/' . $name . '" >' . $name . '</a><br />';
}
}
}
-
- $o .= '</div>';
+
+ $o .= '</div>';
// list module pdl files
return $o;
diff --git a/Zotlabs/Module/Photo.php b/Zotlabs/Module/Photo.php
index 92c9ac3c0..5148c4a94 100644
--- a/Zotlabs/Module/Photo.php
+++ b/Zotlabs/Module/Photo.php
@@ -62,7 +62,7 @@ class Photo extends \Zotlabs\Web\Controller {
intval($uid),
intval(PHOTO_PROFILE)
);
- if(count($r)) {
+ if($r) {
$data = dbunescbin($r[0]['content']);
$mimetype = $r[0]['mimetype'];
}
@@ -79,7 +79,7 @@ class Photo extends \Zotlabs\Web\Controller {
* Other photos
*/
- /* Check for a cookie to indicate display pixel density, in order to detect high-resolution
+ /* Check for a cookie to indicate display pixel density, in order to detect high-resolution
displays. This procedure was derived from the "Retina Images" by Jeremey Worboys,
used in accordance with the Creative Commons Attribution 3.0 Unported License.
Project link: https://github.com/Retina-Images/Retina-Images
diff --git a/Zotlabs/Module/Photos.php b/Zotlabs/Module/Photos.php
index 1bdc23897..1633e08ef 100644
--- a/Zotlabs/Module/Photos.php
+++ b/Zotlabs/Module/Photos.php
@@ -27,7 +27,7 @@ class Photos extends \Zotlabs\Web\Controller {
if(argc() > 1) {
$nick = argv(1);
- profile_load($a,$nick);
+ profile_load($nick);
$channelx = channelx_by_nick($nick);
diff --git a/Zotlabs/Module/Profile.php b/Zotlabs/Module/Profile.php
index 8bf358bc8..9e868db92 100644
--- a/Zotlabs/Module/Profile.php
+++ b/Zotlabs/Module/Profile.php
@@ -48,7 +48,7 @@ class Profile extends \Zotlabs\Web\Controller {
}
}
- profile_load($a,$which,$profile);
+ profile_load($which,$profile);
}
diff --git a/Zotlabs/Module/Profile_photo.php b/Zotlabs/Module/Profile_photo.php
index 6129a7492..62c5e99ae 100644
--- a/Zotlabs/Module/Profile_photo.php
+++ b/Zotlabs/Module/Profile_photo.php
@@ -23,19 +23,18 @@ class Profile_photo extends \Zotlabs\Web\Controller {
/* @brief Initalize the profile-photo edit view
*
- * @param $a Current application
* @return void
*
*/
- function init() {
+ function init() {
if(! local_channel()) {
return;
}
$channel = \App::get_channel();
- profile_load($a,$channel['channel_address']);
+ profile_load($channel['channel_address']);
}
@@ -46,7 +45,7 @@ class Profile_photo extends \Zotlabs\Web\Controller {
*
*/
- function post() {
+ function post() {
if(! local_channel()) {
return;
@@ -54,8 +53,23 @@ class Profile_photo extends \Zotlabs\Web\Controller {
check_form_security_token_redirectOnErr('/profile_photo', 'profile_photo');
- if((x($_POST,'cropfinal')) && ($_POST['cropfinal'] == 1)) {
+ if((array_key_exists('postfinal',$_POST)) && (intval($_POST['cropfinal']) == 1)) {
+
+ // phase 2 - we have finished cropping
+ if(argc() != 2) {
+ notice( t('Image uploaded but image cropping failed.') . EOL );
+ return;
+ }
+
+ $image_id = argv(1);
+
+ if(substr($image_id,-2,1) == '-') {
+ $scale = substr($image_id,-1,1);
+ $image_id = substr($image_id,0,-2);
+ }
+
+
// unless proven otherwise
$is_default_profile = 1;
@@ -70,23 +84,7 @@ class Profile_photo extends \Zotlabs\Web\Controller {
$is_default_profile = 0;
}
}
-
-
-
- // phase 2 - we have finished cropping
-
- if(argc() != 2) {
- notice( t('Image uploaded but image cropping failed.') . EOL );
- return;
- }
-
- $image_id = argv(1);
-
- if(substr($image_id,-2,1) == '-') {
- $scale = substr($image_id,-1,1);
- $image_id = substr($image_id,0,-2);
- }
-
+
$srcX = $_POST['xstart'];
$srcY = $_POST['ystart'];
@@ -110,30 +108,38 @@ class Profile_photo extends \Zotlabs\Web\Controller {
$aid = get_account_id();
- $p = array('aid' => $aid, 'uid' => local_channel(), 'resource_id' => $base_image['resource_id'],
- 'filename' => $base_image['filename'], 'album' => t('Profile Photos'));
+ $p = [
+ 'aid' => $aid,
+ 'uid' => local_channel(),
+ 'resource_id' => $base_image['resource_id'],
+ 'filename' => $base_image['filename'],
+ 'album' => t('Profile Photos')
+ ];
- $p['imgscale'] = 4;
+ $p['imgscale'] = PHOTO_RES_PROFILE_300;
$p['photo_usage'] = (($is_default_profile) ? PHOTO_PROFILE : PHOTO_NORMAL);
$r1 = $im->save($p);
$im->scaleImage(80);
- $p['imgscale'] = 5;
+ $p['imgscale'] = PHOTO_RES_PROFILE_80;
$r2 = $im->save($p);
$im->scaleImage(48);
- $p['imgscale'] = 6;
+ $p['imgscale'] = PHOTO_RES_PROFILE_48;
$r3 = $im->save($p);
if($r1 === false || $r2 === false || $r3 === false) {
// if one failed, delete them all so we can start over.
notice( t('Image resize failed.') . EOL );
- $x = q("delete from photo where resource_id = '%s' and uid = %d and imgscale >= 4 ",
+ $x = q("delete from photo where resource_id = '%s' and uid = %d and imgscale in ( %d, %d, %d ) ",
dbesc($base_image['resource_id']),
- local_channel()
+ local_channel(),
+ intval(PHOTO_RES_PROFILE_300),
+ intval(PHOTO_RES_PROFILE_80),
+ intval(PHOTO_RES_PROFILE_48)
);
return;
}
@@ -183,10 +189,7 @@ class Profile_photo extends \Zotlabs\Web\Controller {
// Now copy profile-permissions to pictures, to prevent privacyleaks by automatically created folder 'Profile Pictures'
- profile_photo_set_profile_perms($_REQUEST['profile']);
-
-
-
+ profile_photo_set_profile_perms(local_channel(),$_REQUEST['profile']);
}
else
notice( t('Unable to process image') . EOL);
@@ -196,7 +199,9 @@ class Profile_photo extends \Zotlabs\Web\Controller {
return; // NOTREACHED
}
-
+ // A new photo was uploaded. Store it and save some important details
+ // in App::$data for use in the cropping function
+
$hash = photo_new_resource();
$smallest = 0;
@@ -220,7 +225,7 @@ class Profile_photo extends \Zotlabs\Web\Controller {
$os_storage = false;
foreach($i as $ii) {
- if(intval($ii['imgscale']) < 2) {
+ if(intval($ii['imgscale']) < PHOTO_RES_640) {
$smallest = intval($ii['imgscale']);
$os_storage = intval($ii['os_storage']);
$imagedata = $ii['content'];
@@ -238,7 +243,10 @@ class Profile_photo extends \Zotlabs\Web\Controller {
}
return $this->profile_photo_crop_ui_head($a, $ph, $hash, $smallest);
-
+
+ // This will "fall through" to the get() method, and since
+ // App::$data['imagecrop'] is set, it will proceed to cropping
+ // rather than present the upload form
}
@@ -269,11 +277,19 @@ class Profile_photo extends \Zotlabs\Web\Controller {
notice( t('Permission denied.') . EOL );
return;
};
-
- // check_form_security_token_redirectOnErr('/profile_photo', 'profile_photo');
-
+
$resource_id = argv(2);
+ // When using an existing photo, we don't have a dialogue to offer a choice of profiles,
+ // so it gets attached to the default
+
+ $p = q("select id from profile where is_default = 1 and uid = %d",
+ intval(local_channel())
+ );
+ if($p) {
+ $_REQUEST['profile'] = $p[0]['id'];
+ }
+
$r = q("SELECT id, album, imgscale FROM photo WHERE uid = %d AND resource_id = '%s' ORDER BY imgscale ASC",
intval(local_channel()),
@@ -285,11 +301,11 @@ class Profile_photo extends \Zotlabs\Web\Controller {
}
$havescale = false;
foreach($r as $rr) {
- if($rr['imgscale'] == 5)
+ if($rr['imgscale'] == PHOTO_RES_PROFILE_80)
$havescale = true;
}
- // set an already loaded photo as profile photo
+ // set an already loaded and cropped photo as profile photo
if(($r[0]['album'] == t('Profile Photos')) && ($havescale)) {
// unset any existing profile photos
@@ -310,7 +326,7 @@ class Profile_photo extends \Zotlabs\Web\Controller {
dbesc($channel['xchan_hash'])
);
- profile_photo_set_profile_perms(); //Reset default photo permissions to public
+ profile_photo_set_profile_perms(local_channel()); // Reset default photo permissions to public
\Zotlabs\Daemon\Master::Summon(array('Directory',local_channel()));
goaway(z_root() . '/profiles');
}
@@ -342,17 +358,22 @@ class Profile_photo extends \Zotlabs\Web\Controller {
if($i) {
$hash = $i[0]['resource_id'];
foreach($i as $ii) {
- if(intval($ii['imgscale']) < 2) {
+ if(intval($ii['imgscale']) < PHOTO_RES_640) {
$smallest = intval($ii['imgscale']);
}
}
}
}
- profile_photo_crop_ui_head($a, $ph, $hash, $smallest);
+ $this->profile_photo_crop_ui_head($a, $ph, $hash, $smallest);
+
+ // falls through with App::$data['imagecrop'] set so we go straight to the cropping section
}
- $profiles = q("select id, profile_name as name, is_default from profile where uid = %d",
+
+ // present an upload form
+
+ $profiles = q("select id, profile_name as name, is_default from profile where uid = %d order by id asc",
intval(local_channel())
);
@@ -379,6 +400,9 @@ class Profile_photo extends \Zotlabs\Web\Controller {
return $o;
}
else {
+
+ // present a cropping form
+
$filename = \App::$data['imagecrop'] . '-' . \App::$data['imagecrop_resolution'];
$resolution = \App::$data['imagecrop_resolution'];
$tpl = get_markup_template("cropbody.tpl");
@@ -416,13 +440,13 @@ class Profile_photo extends \Zotlabs\Web\Controller {
if($max_length > 0)
$ph->scaleImage($max_length);
- $width = $ph->getWidth();
- $height = $ph->getHeight();
+ \App::$data['width'] = $ph->getWidth();
+ \App::$data['height'] = $ph->getHeight();
- if($width < 500 || $height < 500) {
+ if(\App::$data['width'] < 500 || \App::$data['height'] < 500) {
$ph->scaleImageUp(400);
- $width = $ph->getWidth();
- $height = $ph->getHeight();
+ \App::$data['width'] = $ph->getWidth();
+ \App::$data['height'] = $ph->getHeight();
}
diff --git a/Zotlabs/Module/Profiles.php b/Zotlabs/Module/Profiles.php
index 06e5cfd7b..899c79b15 100644
--- a/Zotlabs/Module/Profiles.php
+++ b/Zotlabs/Module/Profiles.php
@@ -193,7 +193,7 @@ class Profiles extends \Zotlabs\Web\Controller {
$chan = \App::get_channel();
- profile_load($a,$chan['channel_address'],$r[0]['id']);
+ profile_load($chan['channel_address'],$r[0]['id']);
}
}
@@ -584,7 +584,7 @@ class Profiles extends \Zotlabs\Web\Controller {
if($is_default) {
// reload the info for the sidebar widget - why does this not work?
- profile_load($a,$channel['channel_address']);
+ profile_load($channel['channel_address']);
\Zotlabs\Daemon\Master::Summon(array('Directory',local_channel()));
}
}
diff --git a/Zotlabs/Module/Profperm.php b/Zotlabs/Module/Profperm.php
index 33e9d1ece..b1da147c1 100644
--- a/Zotlabs/Module/Profperm.php
+++ b/Zotlabs/Module/Profperm.php
@@ -17,7 +17,7 @@ class Profperm extends \Zotlabs\Web\Controller {
$profile = \App::$argv[1];
- profile_load($a,$which,$profile);
+ profile_load($which,$profile);
}
@@ -97,7 +97,7 @@ class Profperm extends \Zotlabs\Web\Controller {
//Time to update the permissions on the profile-pictures as well
- profile_photo_set_profile_perms($profile['id']);
+ profile_photo_set_profile_perms(local_channel(),$profile['id']);
$r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d AND abook_profile = '%s'",
intval(local_channel()),
diff --git a/Zotlabs/Module/README.md b/Zotlabs/Module/README.md
new file mode 100644
index 000000000..3b870dd7b
--- /dev/null
+++ b/Zotlabs/Module/README.md
@@ -0,0 +1,80 @@
+Zotlabs/Module
+==============
+
+
+This directory contains controller modules for handling web requests. The
+lowercase class name indicates the head of the URL path which this module
+handles. There are other methods of attaching (routing) URL paths to
+controllers, but this is the primary method used in this project.
+
+Module controllers MUST reside in this directory and namespace to be
+autoloaded (unless other specific routing methods are employed). They
+typically use and extend the class definition in Zotlabs/Web/Controller
+as a template.
+
+Template:
+
+ <?php
+
+ namespace Zotlabs\Web;
+
+
+ class Controller {
+
+ function init() {}
+ function post() {}
+ function get() {}
+
+ }
+
+
+Typical Module declaration for the '/foo' URL route:
+
+
+ <?php
+ namespace Zotlabs\Module;
+
+ class Foo extends \Zotlabs\Web\Controller {
+
+ function init() {
+ // init() handler goes here
+ }
+
+ function post() {
+ // post handler goes here
+ }
+
+ function get() {
+ return 'Hello world.' . EOL;
+ }
+
+ }
+
+This model provides callbacks for public functions named init(), post(),
+and get(). init() is always called. post() is called if $_POST variables
+are present, and get() is called if none of the prior functions terminated
+the handler. The get() method typically retuns a string which represents
+the contents of the content region of the resulting page. Modules which emit
+json, xml or other machine-readable formats typically emit their contents
+inside the init() function and call 'killme()' to terminate the Module.
+
+Modules are passed the URL path as argc,argv arguments. For a path such as
+
+ https://mysite.something/foo/bar/baz
+
+The app will typically invoke the Module class 'Foo' and pass it
+
+ $x = argc(); // $x = 3
+
+ $x = argv(0); // $x = 'foo'
+ $x = argv(1); // $x = 'bar'
+ $x = argv(2); // $x = 'baz'
+
+These are handled in a similar fashion to their counterparts in the Unix shell
+or C/C++ languages. Do not confuse the argc(),argv() functions with the
+global variables $argc,$argv which are passed to command line programs. These
+are handled separately by command line and Zotlabs/Daemon class functions.
+
+
+
+ \ No newline at end of file
diff --git a/Zotlabs/Module/Rmagic.php b/Zotlabs/Module/Rmagic.php
index bcdbf6c90..26b0c46a6 100644
--- a/Zotlabs/Module/Rmagic.php
+++ b/Zotlabs/Module/Rmagic.php
@@ -24,7 +24,7 @@ class Rmagic extends \Zotlabs\Web\Controller {
}
}
- function post() {
+ function post() {
$address = trim($_REQUEST['address']);
@@ -34,13 +34,13 @@ class Rmagic extends \Zotlabs\Web\Controller {
try {
require_once('library/openid/openid.php');
- $openid = new LightOpenID(z_root());
+ $openid = new \LightOpenID(z_root());
$openid->identity = $address;
$openid->returnUrl = z_root() . '/openid';
$openid->required = array('namePerson/friendly', 'namePerson');
$openid->optional = array('namePerson/first','media/image/aspect11','media/image/default');
goaway($openid->authUrl());
- } catch (Exception $e) {
+ } catch (\Exception $e) {
notice( t('We encountered a problem while logging in with the OpenID you provided. Please check the correct spelling of the ID.').'<br /><br >'. t('The error message was:').' '.$e->getMessage());
}
@@ -82,7 +82,7 @@ class Rmagic extends \Zotlabs\Web\Controller {
}
- function get() {
+ function get() {
$o = replace_macros(get_markup_template('rmagic.tpl'),array(
'$title' => t('Remote Authentication'),
diff --git a/Zotlabs/Module/Siteinfo.php b/Zotlabs/Module/Siteinfo.php
index 41f6e9f0b..a15e2896d 100644
--- a/Zotlabs/Module/Siteinfo.php
+++ b/Zotlabs/Module/Siteinfo.php
@@ -27,28 +27,11 @@ class Siteinfo extends \Zotlabs\Web\Controller {
else {
$version = $commit = '';
}
- $visible_plugins = array();
- if(is_array(\App::$plugins) && count(\App::$plugins)) {
- $r = q("select * from addon where hidden = 0");
- if(count($r))
- foreach($r as $rr)
- $visible_plugins[] = $rr['name'];
- }
-
- $plugins_list = '';
- if(count($visible_plugins)) {
- $plugins_text = t('Installed plugins/addons/apps:');
- $sorted = $visible_plugins;
- $s = '';
- sort($sorted);
- foreach($sorted as $p) {
- if(strlen($p)) {
- if(strlen($s)) $s .= ', ';
- $s .= $p;
- }
- }
- $plugins_list .= $s;
- }
+
+ $plugins_list = implode(', ',visible_plugin_list());
+
+ if($plugins_list)
+ $plugins_text = t('Installed plugins/addons/apps:');
else
$plugins_text = t('No installed plugins/addons/apps');
diff --git a/Zotlabs/Module/Thing.php b/Zotlabs/Module/Thing.php
index e23cce565..65fc0588e 100644
--- a/Zotlabs/Module/Thing.php
+++ b/Zotlabs/Module/Thing.php
@@ -26,7 +26,7 @@ class Thing extends \Zotlabs\Web\Controller {
$verb = escape_tags($_REQUEST['verb']);
$activity = intval($_REQUEST['activity']);
$profile_guid = escape_tags($_REQUEST['profile_assign']);
- $url = $_REQUEST['link'];
+ $url = $_REQUEST['url'];
$photo = $_REQUEST['img'];
$hash = random_string();
@@ -235,7 +235,7 @@ class Thing extends \Zotlabs\Web\Controller {
}
- function get() {
+ function get() {
// @FIXME one problem with things is we can't share them unless we provide the channel in the url
// so we can definitively lookup the owner.
diff --git a/Zotlabs/Module/Uexport.php b/Zotlabs/Module/Uexport.php
index d48f96d76..f36d77174 100644
--- a/Zotlabs/Module/Uexport.php
+++ b/Zotlabs/Module/Uexport.php
@@ -44,7 +44,7 @@ class Uexport extends \Zotlabs\Web\Controller {
}
}
- function get() {
+ function get() {
$y = datetime_convert('UTC',date_default_timezone_get(),'now','Y');
diff --git a/Zotlabs/Module/Viewconnections.php b/Zotlabs/Module/Viewconnections.php
index ea478f92a..7523c259b 100644
--- a/Zotlabs/Module/Viewconnections.php
+++ b/Zotlabs/Module/Viewconnections.php
@@ -11,7 +11,7 @@ class Viewconnections extends \Zotlabs\Web\Controller {
return;
}
if(argc() > 1)
- profile_load($a,argv(1));
+ profile_load(argv(1));
}
function get() {
diff --git a/Zotlabs/Module/Webpages.php b/Zotlabs/Module/Webpages.php
index bb8d454c8..bb8d9c6ed 100644
--- a/Zotlabs/Module/Webpages.php
+++ b/Zotlabs/Module/Webpages.php
@@ -23,12 +23,12 @@ class Webpages extends \Zotlabs\Web\Controller {
else
return;
- profile_load($a,$which);
+ profile_load($which);
}
- function get() {
+ function get() {
if(! \App::$profile) {
notice( t('Requested profile is not available.') . EOL );
@@ -138,11 +138,19 @@ class Webpages extends \Zotlabs\Web\Controller {
$sql_extra = item_permissions_sql($owner);
- $r = q("select * from item_id left join item on item_id.iid = item.id
- where item_id.uid = %d and service = 'WEBPAGE' and item_type = %d $sql_extra order by item.created desc",
+
+ $r = q("select * from iconfig left join item on iconfig.iid = item.id
+ where item.uid = %d and iconfig.cat = 'system' and iconfig.k = 'WEBPAGE' and item_type = %d
+ $sql_extra order by item.created desc",
intval($owner),
intval(ITEM_TYPE_WEBPAGE)
);
+
+// $r = q("select * from item_id left join item on item_id.iid = item.id
+// where item_id.uid = %d and service = 'WEBPAGE' and item_type = %d $sql_extra order by item.created desc",
+// intval($owner),
+// intval(ITEM_TYPE_WEBPAGE)
+// );
$pages = null;
@@ -160,13 +168,13 @@ class Webpages extends \Zotlabs\Web\Controller {
'created' => $rr['created'],
'edited' => $rr['edited'],
'mimetype' => $rr['mimetype'],
- 'pagetitle' => $rr['sid'],
+ 'pagetitle' => $rr['v'],
'mid' => $rr['mid'],
'layout_mid' => $rr['layout_mid']
);
$pages[$rr['iid']][] = array(
'url' => $rr['iid'],
- 'pagetitle' => $rr['sid'],
+ 'pagetitle' => $rr['v'],
'title' => $rr['title'],
'created' => datetime_convert('UTC',date_default_timezone_get(),$rr['created']),
'edited' => datetime_convert('UTC',date_default_timezone_get(),$rr['edited']),
diff --git a/Zotlabs/Module/Wiki.php b/Zotlabs/Module/Wiki.php
new file mode 100644
index 000000000..38b49effc
--- /dev/null
+++ b/Zotlabs/Module/Wiki.php
@@ -0,0 +1,515 @@
+<?php /** @file */
+
+namespace Zotlabs\Module;
+
+class Wiki extends \Zotlabs\Web\Controller {
+
+ function init() {
+ // Determine which channel's wikis to display to the observer
+ $nick = null;
+ if (argc() > 1)
+ $nick = argv(1); // if the channel name is in the URL, use that
+ if (!$nick && local_channel()) { // if no channel name was provided, assume the current logged in channel
+ $channel = \App::get_channel();
+ if ($channel && $channel['channel_address']) {
+ $nick = $channel['channel_address'];
+ goaway(z_root() . '/wiki/' . $nick);
+ }
+ }
+ if (!$nick) {
+ notice(t('You must be logged in to see this page.') . EOL);
+ goaway('/login');
+ }
+ profile_load($nick);
+
+ }
+
+ function get() {
+ require_once('include/wiki.php');
+ require_once('include/acl_selectors.php');
+ // TODO: Combine the interface configuration into a unified object
+ // Something like $interface = array('new_page_button' => false, 'new_wiki_button' => false, ...)
+ $wiki_owner = false;
+ $showNewWikiButton = false;
+ $showCommitMsg = false;
+ $hidePageHistory = false;
+ $pageHistory = array();
+ $local_observer = null;
+ $resource_id = '';
+
+ // init() should have forced the URL to redirect to /wiki/channel so assume argc() > 1
+ $nick = argv(1);
+ $channel = get_channel_by_nick($nick); // The channel who owns the wikis being viewed
+ if(! $channel) {
+ notice('Invalid channel' . EOL);
+ goaway('/' . argv(0));
+ }
+ // Determine if the observer is the channel owner so the ACL dialog can be populated
+ if (local_channel() === intval($channel['channel_id'])) {
+ $local_observer = \App::get_channel();
+ $wiki_owner = true;
+
+ // Obtain the default permission settings of the channel
+ $channel_acl = array(
+ 'allow_cid' => $local_observer['channel_allow_cid'],
+ 'allow_gid' => $local_observer['channel_allow_gid'],
+ 'deny_cid' => $local_observer['channel_deny_cid'],
+ 'deny_gid' => $local_observer['channel_deny_gid']
+ );
+ // Initialize the ACL to the channel default permissions
+ $x = array(
+ 'lockstate' => (( $local_observer['channel_allow_cid'] ||
+ $local_observer['channel_allow_gid'] ||
+ $local_observer['channel_deny_cid'] ||
+ $local_observer['channel_deny_gid'])
+ ? 'lock' : 'unlock'),
+ 'acl' => populate_acl($channel_acl),
+ 'bang' => ''
+ );
+ } else {
+ // Not the channel owner
+ $channel_acl = $x = array();
+ }
+
+ switch (argc()) {
+ case 2:
+ // Configure page template
+ $wikiheaderName = t('Wiki');
+ $wikiheaderPage = t('Sandbox');
+ require_once('library/markdown.php');
+ $content = t('"# Wiki Sandbox\n\nContent you **edit** and **preview** here *will not be saved*."');
+ $renderedContent = Markdown(json_decode($content));
+ $hide_editor = false;
+ $showPageControls = false;
+ $showNewWikiButton = $wiki_owner;
+ $showNewPageButton = false;
+ $hidePageHistory = true;
+ $showCommitMsg = false;
+ break;
+ case 3:
+ // /wiki/channel/wiki -> No page was specified, so redirect to Home.md
+ $wikiUrlName = urlencode(argv(2));
+ goaway('/'.argv(0).'/'.argv(1).'/'.$wikiUrlName.'/Home');
+ case 4:
+ // GET /wiki/channel/wiki/page
+ // Fetch the wiki info and determine observer permissions
+ $wikiUrlName = urlencode(argv(2));
+ $pageUrlName = urlencode(argv(3));
+ $w = wiki_exists_by_name($channel['channel_id'], $wikiUrlName);
+ if(!$w['resource_id']) {
+ notice('Wiki not found' . EOL);
+ goaway('/'.argv(0).'/'.argv(1));
+ }
+ $resource_id = $w['resource_id'];
+
+ if (!$wiki_owner) {
+ // Check for observer permissions
+ $observer_hash = get_observer_hash();
+ $perms = wiki_get_permissions($resource_id, intval($channel['channel_id']), $observer_hash);
+ if(!$perms['read']) {
+ notice('Permission denied.' . EOL);
+ goaway('/'.argv(0).'/'.argv(1));
+ }
+ if($perms['write']) {
+ $wiki_editor = true;
+ } else {
+ $wiki_editor = false;
+ }
+ } else {
+ $wiki_editor = true;
+ }
+ $wikiheaderName = urldecode($wikiUrlName);
+ $wikiheaderPage = urldecode($pageUrlName);
+ $p = wiki_get_page_content(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
+ if(!$p['success']) {
+ notice('Error retrieving page content' . EOL);
+ goaway('/'.argv(0).'/'.argv(1).'/'.$wikiUrlName);
+ }
+ $content = ($p['content'] !== '' ? htmlspecialchars_decode($p['content'],ENT_COMPAT) : '"# New page\n"');
+ // Render the Markdown-formatted page content in HTML
+ require_once('library/markdown.php');
+ $renderedContent = wiki_convert_links(Markdown(json_decode($content)),argv(0).'/'.argv(1).'/'.$wikiUrlName);
+ $hide_editor = false;
+ $showPageControls = $wiki_editor;
+ $showNewWikiButton = $wiki_owner;
+ $showNewPageButton = $wiki_editor;
+ $hidePageHistory = false;
+ $showCommitMsg = true;
+ $pageHistory = wiki_page_history(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
+ break;
+ default: // Strip the extraneous URL components
+ goaway('/'.argv(0).'/'.argv(1).'/'.$wikiUrlName.'/'.$pageUrlName);
+ }
+
+ $wikiModalID = random_string(3);
+ $wikiModal = replace_macros(
+ get_markup_template('generic_modal.tpl'), array(
+ '$id' => $wikiModalID,
+ '$title' => t('Revision Comparison'),
+ '$ok' => t('Revert'),
+ '$cancel' => t('Cancel')
+ )
+ );
+
+ $o .= replace_macros(get_markup_template('wiki.tpl'),array(
+ '$wikiheaderName' => $wikiheaderName,
+ '$wikiheaderPage' => $wikiheaderPage,
+ '$hideEditor' => $hide_editor,
+ '$showPageControls' => $showPageControls,
+ '$showNewWikiButton'=> $showNewWikiButton,
+ '$showNewPageButton'=> $showNewPageButton,
+ '$hidePageHistory' => $hidePageHistory,
+ '$showCommitMsg' => $showCommitMsg,
+ '$channel' => $channel['channel_address'],
+ '$resource_id' => $resource_id,
+ '$page' => $pageUrlName,
+ '$lockstate' => $x['lockstate'],
+ '$acl' => $x['acl'],
+ '$bang' => $x['bang'],
+ '$content' => $content,
+ '$renderedContent' => $renderedContent,
+ '$wikiName' => array('wikiName', t('Enter the name of your new wiki:'), '', ''),
+ '$pageName' => array('pageName', t('Enter the name of the new page:'), '', ''),
+ '$pageRename' => array('pageRename', t('Enter the new name:'), '', ''),
+ '$commitMsg' => array('commitMsg', '', '', '', '', 'placeholder="(optional) Enter a custom message when saving the page..."'),
+ '$pageHistory' => $pageHistory['history'],
+ '$wikiModal' => $wikiModal,
+ '$wikiModalID' => $wikiModalID,
+ '$commit' => 'HEAD',
+ '$embedPhotos' => t('Embed image from photo albums'),
+ '$embedPhotosModalTitle' => t('Embed an image from your albums'),
+ '$embedPhotosModalCancel' => t('Cancel'),
+ '$embedPhotosModalOK' => t('OK'),
+ '$modalchooseimages' => t('Choose images to embed'),
+ '$modalchoosealbum' => t('Choose an album'),
+ '$modaldiffalbum' => t('Choose a different album...'),
+ '$modalerrorlist' => t('Error getting album list'),
+ '$modalerrorlink' => t('Error getting photo link'),
+ '$modalerroralbum' => t('Error getting album'),
+ ));
+ head_add_js('library/ace/ace.js'); // Ace Code Editor
+ return $o;
+ }
+
+ function post() {
+ require_once('include/wiki.php');
+
+ // /wiki/channel/preview
+ // Render mardown-formatted text in HTML for preview
+ if((argc() > 2) && (argv(2) === 'preview')) {
+ $content = $_POST['content'];
+ $resource_id = $_POST['resource_id'];
+ require_once('library/markdown.php');
+ $html = purify_html(Markdown($content));
+ $w = wiki_get_wiki($resource_id);
+ $wikiURL = argv(0).'/'.argv(1).'/'.$w['urlName'];
+ $html = wiki_convert_links($html,$wikiURL);
+ json_return_and_die(array('html' => $html, 'success' => true));
+ }
+
+ // Create a new wiki
+ // /wiki/channel/create/wiki
+ if ((argc() > 3) && (argv(2) === 'create') && (argv(3) === 'wiki')) {
+ $nick = argv(1);
+ $channel = get_channel_by_nick($nick);
+ // Determine if observer has permission to create wiki
+ $observer_hash = get_observer_hash();
+ // Only the channel owner can create a wiki, at least until we create a
+ // more detail permissions framework
+ if (local_channel() !== intval($channel['channel_id'])) {
+ goaway('/'.argv(0).'/'.$nick.'/');
+ }
+ $wiki = array();
+ // Generate new wiki info from input name
+ $wiki['postVisible'] = ((intval($_POST['postVisible']) === 0) ? 0 : 1);
+ $wiki['rawName'] = $_POST['wikiName'];
+ $wiki['htmlName'] = escape_tags($_POST['wikiName']);
+ $wiki['urlName'] = urlencode($_POST['wikiName']);
+ if($wiki['urlName'] === '') {
+ notice('Error creating wiki. Invalid name.');
+ goaway('/wiki');
+ }
+ // Get ACL for permissions
+ $acl = new \Zotlabs\Access\AccessList($channel);
+ $acl->set_from_array($_POST);
+ $r = wiki_create_wiki($channel, $observer_hash, $wiki, $acl);
+ if ($r['success']) {
+ $homePage = wiki_create_page('Home', $r['item']['resource_id']);
+ if(!$homePage['success']) {
+ notice('Wiki created, but error creating Home page.');
+ goaway('/wiki/'.$nick.'/'.$wiki['urlName']);
+ }
+ goaway('/wiki/'.$nick.'/'.$wiki['urlName'].'/'.$homePage['page']['urlName']);
+ } else {
+ notice('Error creating wiki');
+ goaway('/wiki');
+ }
+ }
+
+ // Delete a wiki
+ if ((argc() > 3) && (argv(2) === 'delete') && (argv(3) === 'wiki')) {
+ $nick = argv(1);
+ $channel = get_channel_by_nick($nick);
+ // Only the channel owner can delete a wiki, at least until we create a
+ // more detail permissions framework
+ if (local_channel() !== intval($channel['channel_id'])) {
+ logger('Wiki delete permission denied.' . EOL);
+ json_return_and_die(array('message' => 'Wiki delete permission denied.', 'success' => false));
+ }
+ $resource_id = $_POST['resource_id'];
+ $deleted = wiki_delete_wiki($resource_id);
+ if ($deleted['success']) {
+ json_return_and_die(array('message' => '', 'success' => true));
+ } else {
+ logger('Error deleting wiki: ' . $resource_id);
+ json_return_and_die(array('message' => 'Error deleting wiki', 'success' => false));
+ }
+ }
+
+ // Create a page
+ if ((argc() === 4) && (argv(2) === 'create') && (argv(3) === 'page')) {
+ $nick = argv(1);
+ $resource_id = $_POST['resource_id'];
+ // Determine if observer has permission to create a page
+ $channel = get_channel_by_nick($nick);
+ if (local_channel() !== intval($channel['channel_id'])) {
+ $observer_hash = get_observer_hash();
+ $perms = wiki_get_permissions($resource_id, intval($channel['channel_id']), $observer_hash);
+ if(!$perms['write']) {
+ logger('Wiki write permission denied. ' . EOL);
+ json_return_and_die(array('success' => false));
+ }
+ }
+ $name = $_POST['name']; //Get new page name
+ if(urlencode(escape_tags($_POST['name'])) === '') {
+ json_return_and_die(array('message' => 'Error creating page. Invalid name.', 'success' => false));
+ }
+ $page = wiki_create_page($name, $resource_id);
+ if ($page['success']) {
+ json_return_and_die(array('url' => '/'.argv(0).'/'.argv(1).'/'.$page['wiki']['urlName'].'/'.urlencode($page['page']['urlName']), 'success' => true));
+ } else {
+ logger('Error creating page');
+ json_return_and_die(array('message' => 'Error creating page.', 'success' => false));
+ }
+ }
+
+ // Fetch page list for a wiki
+ if ((argc() === 5) && (argv(2) === 'get') && (argv(3) === 'page') && (argv(4) === 'list')) {
+ $resource_id = $_POST['resource_id']; // resource_id for wiki in db
+ $channel = get_channel_by_nick(argv(1));
+ $observer_hash = get_observer_hash();
+ if (local_channel() !== intval($channel['channel_id'])) {
+ $perms = wiki_get_permissions($resource_id, intval($channel['channel_id']), $observer_hash);
+ if(!$perms['read']) {
+ logger('Wiki read permission denied.' . EOL);
+ json_return_and_die(array('pages' => null, 'message' => 'Permission denied.', 'success' => false));
+ }
+ }
+ $page_list_html = widget_wiki_pages(array(
+ 'resource_id' => $resource_id,
+ 'refresh' => true,
+ 'channel' => argv(1)));
+ json_return_and_die(array('pages' => $page_list_html, 'message' => '', 'success' => true));
+ }
+
+ // Save a page
+ if ((argc() === 4) && (argv(2) === 'save') && (argv(3) === 'page')) {
+
+ $resource_id = $_POST['resource_id'];
+ $pageUrlName = $_POST['name'];
+ $pageHtmlName = escape_tags($_POST['name']);
+ $content = $_POST['content']; //Get new content
+ $commitMsg = $_POST['commitMsg'];
+ if ($commitMsg === '') {
+ $commitMsg = 'Updated ' . $pageHtmlName;
+ }
+ $nick = argv(1);
+ $channel = get_channel_by_nick($nick);
+ // Determine if observer has permission to save content
+ if (local_channel() !== intval($channel['channel_id'])) {
+ $observer_hash = get_observer_hash();
+ $perms = wiki_get_permissions($resource_id, intval($channel['channel_id']), $observer_hash);
+ if(!$perms['write']) {
+ logger('Wiki write permission denied. ' . EOL);
+ json_return_and_die(array('success' => false));
+ }
+ }
+
+ $saved = wiki_save_page(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName, 'content' => $content));
+ if($saved['success']) {
+ $ob = \App::get_observer();
+ $commit = wiki_git_commit(array(
+ 'commit_msg' => $commitMsg,
+ 'resource_id' => $resource_id,
+ 'observer' => $ob,
+ 'files' => array($pageUrlName.'.md')
+ ));
+ if($commit['success']) {
+ json_return_and_die(array('message' => 'Wiki git repo commit made', 'success' => true));
+ } else {
+ json_return_and_die(array('message' => 'Error making git commit','success' => false));
+ }
+ } else {
+ json_return_and_die(array('message' => 'Error saving page', 'success' => false));
+ }
+ }
+
+ // Update page history
+ // /wiki/channel/history/page
+ if ((argc() === 4) && (argv(2) === 'history') && (argv(3) === 'page')) {
+
+ $resource_id = $_POST['resource_id'];
+ $pageUrlName = $_POST['name'];
+
+ $nick = argv(1);
+ $channel = get_channel_by_nick($nick);
+ // Determine if observer has permission to read content
+ if (local_channel() !== intval($channel['channel_id'])) {
+ $observer_hash = get_observer_hash();
+ $perms = wiki_get_permissions($resource_id, intval($channel['channel_id']), $observer_hash);
+ if(!$perms['read']) {
+ logger('Wiki read permission denied.' . EOL);
+ json_return_and_die(array('historyHTML' => '', 'message' => 'Permission denied.', 'success' => false));
+ }
+ }
+ $historyHTML = widget_wiki_page_history(array(
+ 'resource_id' => $resource_id,
+ 'pageUrlName' => $pageUrlName
+ ));
+ json_return_and_die(array('historyHTML' => $historyHTML, 'message' => '', 'success' => true));
+ }
+
+ // Delete a page
+ if ((argc() === 4) && (argv(2) === 'delete') && (argv(3) === 'page')) {
+ $resource_id = $_POST['resource_id'];
+ $pageUrlName = $_POST['name'];
+ if ($pageUrlName === 'Home') {
+ json_return_and_die(array('message' => 'Cannot delete Home','success' => false));
+ }
+ // Determine if observer has permission to delete pages
+ $nick = argv(1);
+ $channel = get_channel_by_nick($nick);
+ if (local_channel() !== intval($channel['channel_id'])) {
+ $observer_hash = get_observer_hash();
+ $perms = wiki_get_permissions($resource_id, intval($channel['channel_id']), $observer_hash);
+ if(!$perms['write']) {
+ logger('Wiki write permission denied. ' . EOL);
+ json_return_and_die(array('success' => false));
+ }
+ }
+ $deleted = wiki_delete_page(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
+ if($deleted['success']) {
+ $ob = \App::get_observer();
+ $commit = wiki_git_commit(array(
+ 'commit_msg' => 'Deleted ' . $pageUrlName,
+ 'resource_id' => $resource_id,
+ 'observer' => $ob,
+ 'files' => null
+ ));
+ if($commit['success']) {
+ json_return_and_die(array('message' => 'Wiki git repo commit made', 'success' => true));
+ } else {
+ json_return_and_die(array('message' => 'Error making git commit','success' => false));
+ }
+ } else {
+ json_return_and_die(array('message' => 'Error deleting page', 'success' => false));
+ }
+ }
+
+ // Revert a page
+ if ((argc() === 4) && (argv(2) === 'revert') && (argv(3) === 'page')) {
+ $resource_id = $_POST['resource_id'];
+ $pageUrlName = $_POST['name'];
+ $commitHash = $_POST['commitHash'];
+ // Determine if observer has permission to revert pages
+ $nick = argv(1);
+ $channel = get_channel_by_nick($nick);
+ if (local_channel() !== intval($channel['channel_id'])) {
+ $observer_hash = get_observer_hash();
+ $perms = wiki_get_permissions($resource_id, intval($channel['channel_id']), $observer_hash);
+ if(!$perms['write']) {
+ logger('Wiki write permission denied.' . EOL);
+ json_return_and_die(array('success' => false));
+ }
+ }
+ $reverted = wiki_revert_page(array('commitHash' => $commitHash, 'resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
+ if($reverted['success']) {
+ json_return_and_die(array('content' => $reverted['content'], 'message' => '', 'success' => true));
+ } else {
+ json_return_and_die(array('content' => '', 'message' => 'Error reverting page', 'success' => false));
+ }
+ }
+
+ // Compare page revisions
+ if ((argc() === 4) && (argv(2) === 'compare') && (argv(3) === 'page')) {
+ $resource_id = $_POST['resource_id'];
+ $pageUrlName = $_POST['name'];
+ $compareCommit = $_POST['compareCommit'];
+ $currentCommit = $_POST['currentCommit'];
+ // Determine if observer has permission to revert pages
+ $nick = argv(1);
+ $channel = get_channel_by_nick($nick);
+ if (local_channel() !== intval($channel['channel_id'])) {
+ $observer_hash = get_observer_hash();
+ $perms = wiki_get_permissions($resource_id, intval($channel['channel_id']), $observer_hash);
+ if(!$perms['read']) {
+ logger('Wiki read permission denied.' . EOL);
+ json_return_and_die(array('success' => false));
+ }
+ }
+ $compare = wiki_compare_page(array('currentCommit' => $currentCommit, 'compareCommit' => $compareCommit, 'resource_id' => $resource_id, 'pageUrlName' => $pageUrlName));
+ if($compare['success']) {
+ $diffHTML = '<table class="text-center" width="100%"><tr><td class="lead" width="50%">Current Revision</td><td class="lead" width="50%">Selected Revision</td></tr></table>' . $compare['diff'];
+ json_return_and_die(array('diff' => $diffHTML, 'message' => '', 'success' => true));
+ } else {
+ json_return_and_die(array('diff' => '', 'message' => 'Error comparing page', 'success' => false));
+ }
+ }
+
+ // Rename a page
+ if ((argc() === 4) && (argv(2) === 'rename') && (argv(3) === 'page')) {
+ $resource_id = $_POST['resource_id'];
+ $pageUrlName = $_POST['oldName'];
+ $pageNewName = $_POST['newName'];
+ if ($pageUrlName === 'Home') {
+ json_return_and_die(array('message' => 'Cannot rename Home','success' => false));
+ }
+ if(urlencode(escape_tags($pageNewName)) === '') {
+ json_return_and_die(array('message' => 'Error renaming page. Invalid name.', 'success' => false));
+ }
+ // Determine if observer has permission to rename pages
+ $nick = argv(1);
+ $channel = get_channel_by_nick($nick);
+ if (local_channel() !== intval($channel['channel_id'])) {
+ $observer_hash = get_observer_hash();
+ $perms = wiki_get_permissions($resource_id, intval($channel['channel_id']), $observer_hash);
+ if(!$perms['write']) {
+ logger('Wiki write permission denied. ' . EOL);
+ json_return_and_die(array('success' => false));
+ }
+ }
+ $renamed = wiki_rename_page(array('resource_id' => $resource_id, 'pageUrlName' => $pageUrlName, 'pageNewName' => $pageNewName));
+ if($renamed['success']) {
+ $ob = \App::get_observer();
+ $commit = wiki_git_commit(array(
+ 'commit_msg' => 'Renamed ' . urldecode($pageUrlName) . ' to ' . $renamed['page']['htmlName'],
+ 'resource_id' => $resource_id,
+ 'observer' => $ob,
+ 'files' => array($pageUrlName . '.md', $renamed['page']['fileName']),
+ 'all' => true
+ ));
+ if($commit['success']) {
+ json_return_and_die(array('name' => $renamed['page'], 'message' => 'Wiki git repo commit made', 'success' => true));
+ } else {
+ json_return_and_die(array('message' => 'Error making git commit','success' => false));
+ }
+ } else {
+ json_return_and_die(array('message' => 'Error renaming page', 'success' => false));
+ }
+ }
+
+ //notice('You must be authenticated.');
+ json_return_and_die(array('message' => 'You must be authenticated.', 'success' => false));
+
+ }
+}