aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Lib/NativeWiki.php
diff options
context:
space:
mode:
Diffstat (limited to 'Zotlabs/Lib/NativeWiki.php')
-rw-r--r--Zotlabs/Lib/NativeWiki.php49
1 files changed, 30 insertions, 19 deletions
diff --git a/Zotlabs/Lib/NativeWiki.php b/Zotlabs/Lib/NativeWiki.php
index 3ec032075..9e6a3ac85 100644
--- a/Zotlabs/Lib/NativeWiki.php
+++ b/Zotlabs/Lib/NativeWiki.php
@@ -9,7 +9,7 @@ define ( 'NWIKI_ITEM_RESOURCE_TYPE', 'nwiki' );
class NativeWiki {
- static public function listwikis($channel, $observer_hash) {
+ public static function listwikis($channel, $observer_hash) {
$sql_extra = item_permissions_sql($channel['channel_id'], $observer_hash);
$wikis = q("SELECT * FROM item
@@ -40,7 +40,7 @@ class NativeWiki {
}
- function create_wiki($channel, $observer_hash, $wiki, $acl) {
+ public static function create_wiki($channel, $observer_hash, $wiki, $acl) {
$resource_id = new_uuid();
$uuid = new_uuid();
@@ -101,7 +101,8 @@ class NativeWiki {
}
}
- function update_wiki($channel_id, $observer_hash, $arr, $acl) {
+
+ public static function update_wiki($channel_id, $observer_hash, $arr, $acl) {
$w = self::get_wiki($channel_id, $observer_hash, $arr['resource_id']);
$item = $w['wiki'];
@@ -156,8 +157,8 @@ class NativeWiki {
}
}
- static public function sync_a_wiki_item($uid,$id,$resource_id) {
+ public static function sync_a_wiki_item($uid,$id,$resource_id) {
$r = q("SELECT * from item WHERE uid = %d AND ( id = %d OR ( resource_type = '%s' and resource_id = '%s' )) ",
intval($uid),
@@ -165,8 +166,8 @@ class NativeWiki {
dbesc(NWIKI_ITEM_RESOURCE_TYPE),
dbesc($resource_id)
);
-
if($r) {
+
$q = q("select * from item where resource_type = 'nwikipage' and resource_id = '%s'",
dbesc($r[0]['resource_id'])
);
@@ -185,35 +186,42 @@ class NativeWiki {
}
}
- function delete_wiki($channel_id,$observer_hash,$resource_id) {
+
+ public static function delete_wiki($channel_id,$observer_hash,$resource_id) {
$w = self::get_wiki($channel_id,$observer_hash,$resource_id);
- $item = $w['wiki'];
- if(! $item) {
- return array('item' => null, 'success' => false);
- }
- else {
- $drop = drop_item($item['id'], false, DROPITEM_NORMAL);
+ if(! $w['wiki']) {
+ return [ 'success' => false ];
}
+ else {
+
+ $r = q("SELECT id FROM item WHERE uid = %s AND resource_id = '%s'",
+ intval($channel_id),
+ dbesc($resource_id)
+ );
+
+ $ids = array_column($r, 'id');
+ drop_items($ids, true, DROPITEM_PHASE1);
- info( t('Wiki files deleted successfully'));
+ info(t('Wiki files deleted successfully'));
- return array('item' => $item, 'item_id' => $item['id'], 'success' => (($drop === 1) ? true : false));
+ return [ 'success' => true ];
+ }
}
- static public function get_wiki($channel_id, $observer_hash, $resource_id) {
+ public static function get_wiki($channel_id, $observer_hash, $resource_id) {
$sql_extra = item_permissions_sql($channel_id,$observer_hash);
$item = q("SELECT * FROM item WHERE uid = %d AND resource_type = '%s' AND resource_id = '%s' AND item_deleted = 0
- $sql_extra limit 1",
+ $sql_extra ORDER BY id LIMIT 1",
intval($channel_id),
dbesc(NWIKI_ITEM_RESOURCE_TYPE),
dbesc($resource_id)
);
if(! $item) {
- return array('wiki' => null);
+ return [ 'wiki' => null ];
}
else {
@@ -236,7 +244,7 @@ class NativeWiki {
}
- static public function exists_by_name($uid, $urlName) {
+ public static function exists_by_name($uid, $urlName) {
$sql_extra = item_permissions_sql($uid);
@@ -258,7 +266,8 @@ class NativeWiki {
}
- static public function get_permissions($resource_id, $owner_id, $observer_hash) {
+ public static function get_permissions($resource_id, $owner_id, $observer_hash) {
+
// TODO: For now, only the owner can edit
$sql_extra = item_permissions_sql($owner_id, $observer_hash);
@@ -283,6 +292,7 @@ class NativeWiki {
}
}
+
public static function name_encode ($string) {
$string = html_entity_decode($string);
@@ -298,6 +308,7 @@ class NativeWiki {
return $ret;
}
+
public static function name_decode ($string) {
$encoding = mb_internal_encoding();