aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorAndrew Manning <tamanning@zoho.com>2016-05-27 22:19:05 -0400
committerAndrew Manning <tamanning@zoho.com>2016-05-27 22:19:05 -0400
commit4691c3ec01eda972e7b4cae4ec940c8c24d51b5a (patch)
treeb088f7c8464f02a01d52078c9a8c390b83c75c21 /include
parentca78ebce6d254f244b4c1fbe25eb3aca40b26952 (diff)
downloadvolse-hubzilla-4691c3ec01eda972e7b4cae4ec940c8c24d51b5a.tar.gz
volse-hubzilla-4691c3ec01eda972e7b4cae4ec940c8c24d51b5a.tar.bz2
volse-hubzilla-4691c3ec01eda972e7b4cae4ec940c8c24d51b5a.zip
Add new page to wiki and redirect to editor page.
Diffstat (limited to 'include')
-rw-r--r--include/wiki.php55
1 files changed, 49 insertions, 6 deletions
diff --git a/include/wiki.php b/include/wiki.php
index 90b30d492..317db1239 100644
--- a/include/wiki.php
+++ b/include/wiki.php
@@ -125,15 +125,58 @@ function wiki_delete_wiki($resource_id) {
}
}
-function wiki_exists_by_name($name) {
- $item = q("SELECT id FROM item WHERE resource_type = '%s' AND title = '%s' AND item_deleted = 0 limit 1",
+function wiki_exists_by_name($uid, $name) {
+ $item = q("SELECT id,resource_id FROM item WHERE resource_type = '%s' AND title = '%s' AND uid = '%s' AND item_deleted = 0 limit 1",
dbesc(WIKI_ITEM_RESOURCE_TYPE),
- dbesc($name)
+ dbesc($name),
+ dbesc($uid)
);
if (!$item) {
- return array('id' => null);
+ return array('id' => null, 'resource_id' => null);
} else {
- return array('id' => $item[0]['id']);
+ return array('id' => $item[0]['id'], 'resource_id' => $item[0]['resource_id']);
}
-} \ No newline at end of file
+}
+
+function wiki_get_permissions($resource_id, $owner_id, $observer_hash) {
+ // TODO: For now, only the owner can edit
+ $sql_extra = item_permissions_sql($owner_id, $observer_hash);
+ $r = q("SELECT * FROM item WHERE resource_type = '%s' AND resource_id = '%s' $sql_extra LIMIT 1",
+ dbesc(WIKI_ITEM_RESOURCE_TYPE),
+ dbesc($resource_id)
+ );
+ if(!$r) {
+ return array('read' => false, 'write' => false, 'success' => false);
+ } else {
+ return array('read' => true, 'write' => false, 'success' => true);
+ }
+}
+
+function wiki_create_page($name, $resource_id) {
+ $item = q("SELECT id,title,object FROM item WHERE resource_type = '%s' AND resource_id = '%s' AND item_deleted = 0 limit 1",
+ dbesc(WIKI_ITEM_RESOURCE_TYPE),
+ dbesc($resource_id)
+ );
+ if (!$item) {
+ return array('page' => null, 'message' => 'Wiki item not found.', 'success' => false);
+ }
+ $object = json_decode($item[0]['object'], true);
+ $wikiname = $item[0]['title'];
+ if (!realpath(__DIR__ . '/../' . $object['path'])) {
+ return array('page' => null, 'message' => 'Wiki directory does not exist.', 'success' => false);
+ }
+ // Path to wiki exists
+ $abs_path = realpath(__DIR__ . '/../' . $object['path']);
+ $page_path = $abs_path . '/' . $name;
+ if (is_file($page_path)) {
+ return array('page' => null, 'message' => 'Page already exists.', 'success' => false);
+ }
+ // Create file called $name in the path
+ if(!touch($page_path)) {
+ return array('page' => null, 'message' => 'Page file cannot be created.', 'success' => false);
+ } else {
+ return array('wiki' => $wikiname, 'message' => '', 'success' => true);
+ }
+
+}