aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzotlabs <mike@macgirvin.com>2017-09-16 01:06:44 -0700
committerzotlabs <mike@macgirvin.com>2017-09-16 01:06:44 -0700
commit991db806466d114b4ec179af9930e859bb21843b (patch)
treef3d8a5f09ba9c5b36c9bc8e0176b3d11cba732cf
parentb1876ac14fc4f9b7e39989ef7e69c8135a25c13f (diff)
parentcb3fb0049f64a92668bc94746dc55cc905683699 (diff)
downloadvolse-hubzilla-991db806466d114b4ec179af9930e859bb21843b.tar.gz
volse-hubzilla-991db806466d114b4ec179af9930e859bb21843b.tar.bz2
volse-hubzilla-991db806466d114b4ec179af9930e859bb21843b.zip
Merge branch 'dev' of https://github.com/redmatrix/hubzilla into dev_merge
-rw-r--r--Zotlabs/Lib/NativeWiki.php66
-rw-r--r--Zotlabs/Lib/NativeWikiPage.php6
-rw-r--r--Zotlabs/Module/Wiki.php90
-rw-r--r--Zotlabs/Widget/Wiki_pages.php3
-rwxr-xr-xboot.php2
-rw-r--r--include/channel.php12
-rw-r--r--include/photo/photo_driver.php30
-rw-r--r--view/css/mod_wiki.css10
-rw-r--r--view/js/main.js8
-rw-r--r--view/tpl/wiki.tpl1
-rw-r--r--view/tpl/wiki_page_list.tpl4
-rw-r--r--view/tpl/wikilist.tpl37
12 files changed, 240 insertions, 29 deletions
diff --git a/Zotlabs/Lib/NativeWiki.php b/Zotlabs/Lib/NativeWiki.php
index 4301feaa0..390b83958 100644
--- a/Zotlabs/Lib/NativeWiki.php
+++ b/Zotlabs/Lib/NativeWiki.php
@@ -18,11 +18,18 @@ class NativeWiki {
if($wikis) {
foreach($wikis as &$w) {
+
+ $w['json_allow_cid'] = acl2json($w['allow_cid']);
+ $w['json_allow_gid'] = acl2json($w['allow_gid']);
+ $w['json_deny_cid'] = acl2json($w['deny_cid']);
+ $w['json_deny_gid'] = acl2json($w['deny_gid']);
+
$w['rawName'] = get_iconfig($w, 'wiki', 'rawName');
$w['htmlName'] = escape_tags($w['rawName']);
$w['urlName'] = urlencode(urlencode($w['rawName']));
$w['mimeType'] = get_iconfig($w, 'wiki', 'mimeType');
- $w['lock'] = (($w['item_private'] || $w['allow_cid'] || $w['allow_gid'] || $w['deny_cid'] || $w['deny_gid']) ? true : false);
+ $w['typelock'] = get_iconfig($w, 'wiki', 'typelock');
+ $w['lockstate'] = (($w['allow_cid'] || $w['allow_gid'] || $w['deny_cid'] || $w['deny_gid']) ? 'lock' : 'unlock');
}
}
// TODO: query db for wikis the observer can access. Return with two lists, for read and write access
@@ -84,7 +91,9 @@ class NativeWiki {
if(! set_iconfig($arr, 'wiki', 'mimeType', $wiki['mimeType'], true)) {
return array('item' => null, 'success' => false);
}
-
+
+ set_iconfig($arr,'wiki','typelock',$wiki['typelock'],true);
+
$post = item_store($arr);
$item_id = $post['item_id'];
@@ -98,6 +107,49 @@ class NativeWiki {
}
}
+ function update_wiki($channel_id, $observer_hash, $arr, $acl) {
+
+ $w = self::get_wiki($channel_id, $observer_hash, $arr['resource_id']);
+ $item = $w['wiki'];
+
+ if(! $item) {
+ return array('item' => null, 'success' => false);
+ }
+
+ $x = $acl->get();
+
+ $item['allow_cid'] = $x['allow_cid'];
+ $item['allow_gid'] = $x['allow_gid'];
+ $item['deny_cid'] = $x['deny_cid'];
+ $item['deny_gid'] = $x['deny_gid'];
+ $item['item_private'] = intval($acl->is_private());
+
+ $update_title = false;
+
+ if($item['title'] !== $arr['updateRawName']) {
+ $update_title = true;
+ $item['title'] = $arr['updateRawName'];
+ }
+
+ $update = item_store_update($item);
+
+ $item_id = $update['item_id'];
+
+ if($update['item_id']) {
+ info( t('Wiki updated successfully'));
+ if($update_title) {
+ // Update the wiki name information using iconfig.
+ if(! set_iconfig($update['item_id'], 'wiki', 'rawName', $arr['updateRawName'], true)) {
+ return array('item' => null, 'success' => false);
+ }
+ }
+ return array('item' => $update['item'], 'item_id' => $update['item_id'], 'success' => $update['success']);
+ }
+ else {
+ return array('item' => null, 'success' => false);
+ }
+ }
+
static public function sync_a_wiki_item($uid,$id,$resource_id) {
@@ -150,13 +202,15 @@ class NativeWiki {
// Get wiki metadata
$rawName = get_iconfig($w, 'wiki', 'rawName');
$mimeType = get_iconfig($w, 'wiki', 'mimeType');
+ $typelock = get_iconfig($w, 'wiki', 'typelock');
return array(
- 'wiki' => $w,
- 'rawName' => $rawName,
+ 'wiki' => $w,
+ 'rawName' => $rawName,
'htmlName' => escape_tags($rawName),
- 'urlName' => urlencode(urlencode($rawName)),
- 'mimeType' => $mimeType
+ 'urlName' => urlencode(urlencode($rawName)),
+ 'mimeType' => $mimeType,
+ 'typelock' => $typelock
);
}
}
diff --git a/Zotlabs/Lib/NativeWikiPage.php b/Zotlabs/Lib/NativeWikiPage.php
index 558a70a3c..4b637781e 100644
--- a/Zotlabs/Lib/NativeWikiPage.php
+++ b/Zotlabs/Lib/NativeWikiPage.php
@@ -607,11 +607,11 @@ class NativeWikiPage {
}
static public function get_file_ext($arr) {
- if($arr['mimeType'] === 'text/bbcode')
+ if($arr['mimetype'] === 'text/bbcode')
return '.bb';
- elseif($arr['mimeType'] === 'text/markdown')
+ elseif($arr['mimetype'] === 'text/markdown')
return '.md';
- elseif($arr['mimeType'] === 'text/plain')
+ elseif($arr['mimetype'] === 'text/plain')
return '.txt';
}
diff --git a/Zotlabs/Module/Wiki.php b/Zotlabs/Module/Wiki.php
index 1eb600f51..6055b0b38 100644
--- a/Zotlabs/Module/Wiki.php
+++ b/Zotlabs/Module/Wiki.php
@@ -113,12 +113,13 @@ class Wiki extends \Zotlabs\Web\Controller {
$o = '';
// Download a wiki
-/*
+
if((argc() > 3) && (argv(2) === 'download') && (argv(3) === 'wiki')) {
$resource_id = argv(4);
+ $w = Zlib\NativeWiki::get_wiki($owner['channel_id'],$observer_hash,$resource_id);
- $w = Zlib\NativeWiki::get_wiki($owner,$observer_hash,$resource_id);
+// $w = Zlib\NativeWiki::get_wiki($owner,$observer_hash,$resource_id);
if(! $w['htmlName']) {
notice(t('Error retrieving wiki') . EOL);
}
@@ -133,8 +134,35 @@ class Wiki extends \Zotlabs\Web\Controller {
$zip_filename = $w['urlName'];
$zip_filepath = '/tmp/' . $zip_folder_name . '/' . $zip_filename;
+
// Generate the zip file
- ZLib\ExtendedZip::zipTree($w['path'], $zip_filepath, \ZipArchive::CREATE);
+
+ $zip = new \ZipArchive;
+ $r = $zip->open($zip_filepath, \ZipArchive::CREATE);
+ if($r === true) {
+ $i = q("select * from item where resource_type = 'nwikipage' and resource_id = '%s'",
+ dbesc($resource_id)
+ );
+ if($i) {
+ foreach($i as $iv) {
+ if($iv['mimetype'] === 'text/plain') {
+ $content = html_entity_decode($iv['body'],ENT_COMPAT,'UTF-8');
+ }
+ elseif($iv['mimetype'] === 'text/bbcode') {
+ $content = html_entity_decode($iv['body'],ENT_COMPAT,'UTF-8');
+ }
+ elseif($iv['mimetype'] === 'text/markdown') {
+ $content = html_entity_decode(Zlib\MarkdownSoap::unescape($iv['body']),ENT_COMPAT,'UTF-8');
+ }
+ $fname = get_iconfig($iv['id'],'nwikipage','pagetitle') . Zlib\NativeWikiPage::get_file_ext($iv);
+ $zip->addFromString($fname,$content);
+ }
+
+
+ }
+
+ }
+ $zip->close();
// Output the file for download
@@ -153,10 +181,11 @@ class Wiki extends \Zotlabs\Web\Controller {
killme();
}
-*/
+
switch(argc()) {
case 2:
$wikis = Zlib\NativeWiki::listwikis($owner, get_observer_hash());
+
if($wikis) {
$o .= replace_macros(get_markup_template('wikilist.tpl'), array(
'$header' => t('Wikis'),
@@ -173,12 +202,14 @@ class Wiki extends \Zotlabs\Web\Controller {
'$mimeType' => array('mimeType', t('Content type'), '', '', ['text/markdown' => t('Markdown'), 'text/bbcode' => t('BBcode'), 'text/plain' => t('Text') ]),
'$name' => t('Name'),
'$type' => t('Type'),
+ '$unlocked' => t('Any&nbsp;type'),
'$lockstate' => $x['lockstate'],
'$acl' => $x['acl'],
'$allow_cid' => $x['allow_cid'],
'$allow_gid' => $x['allow_gid'],
'$deny_cid' => $x['deny_cid'],
'$deny_gid' => $x['deny_gid'],
+ '$typelock' => array('typelock', t('Lock content type'), '', '', array(t('No'), t('Yes'))),
'$notify' => array('postVisible', t('Create a status post for this wiki'), '', '', array(t('No'), t('Yes')))
));
@@ -295,6 +326,9 @@ class Wiki extends \Zotlabs\Web\Controller {
'$cancel' => t('Cancel')
));
+ $types = [ 'text/bbcode' => t('BBcode'), 'text/markdown' => t('Markdown'), 'text/plain' => 'Text' ];
+ $currenttype = $types[$mimeType];
+
$placeholder = t('Short description of your changes (optional)');
$o .= replace_macros(get_markup_template('wiki.tpl'),array(
@@ -309,6 +343,7 @@ class Wiki extends \Zotlabs\Web\Controller {
'$resource_id' => $resource_id,
'$page' => $pageUrlName,
'$mimeType' => $mimeType,
+ '$typename' => $currenttype,
'$content' => $content,
'$renderedContent' => $renderedContent,
'$pageRename' => array('pageRename', t('New page name'), '', ''),
@@ -394,6 +429,7 @@ class Wiki extends \Zotlabs\Web\Controller {
$wiki['htmlName'] = escape_tags($_POST['wikiName']);
$wiki['urlName'] = urlencode(urlencode($_POST['wikiName']));
$wiki['mimeType'] = $_POST['mimeType'];
+ $wiki['typelock'] = $_POST['typelock'];
if($wiki['urlName'] === '') {
notice( t('Error creating wiki. Invalid name.') . EOL);
@@ -428,6 +464,52 @@ class Wiki extends \Zotlabs\Web\Controller {
}
}
+ // Update a wiki
+ // /wiki/channel/update/wiki
+ if ((argc() > 3) && (argv(2) === 'update') && (argv(3) === 'wiki')) {
+ // Only the channel owner can update a wiki, at least until we create a
+ // more detail permissions framework
+
+ if (local_channel() !== intval($owner['channel_id'])) {
+ goaway('/' . argv(0) . '/' . $nick . '/');
+ }
+
+ $arr = [];
+
+ $arr['urlName'] = urlencode(urlencode($_POST['origRawName']));
+
+ if($_POST['updateRawName'])
+ $arr['updateRawName'] = $_POST['updateRawName'];
+
+ if(($arr['urlName'] || $arr['updateRawName']) === '') {
+ notice( t('Error updating wiki. Invalid name.') . EOL);
+ goaway('/wiki');
+ return; //not reached
+ }
+
+ $wiki = Zlib\NativeWiki::exists_by_name($owner['channel_id'], $arr['urlName']);
+
+ if($wiki['resource_id']) {
+
+ $arr['resource_id'] = $wiki['resource_id'];
+
+ $acl = new \Zotlabs\Access\AccessList($owner);
+ $acl->set_from_array($_POST);
+
+ $r = Zlib\NativeWiki::update_wiki($owner['channel_id'], $observer_hash, $arr, $acl);
+ if($r['success']) {
+ Zlib\NativeWiki::sync_a_wiki_item($owner['channel_id'],$r['item_id'],$r['item']['resource_id']);
+ goaway(z_root() . '/wiki/' . $nick);
+ }
+ else {
+ notice( t('Error updating wiki'));
+ goaway(z_root() . '/wiki');
+ }
+
+ }
+ goaway(z_root() . '/wiki');
+ }
+
// Delete a wiki
if ((argc() > 3) && (argv(2) === 'delete') && (argv(3) === 'wiki')) {
diff --git a/Zotlabs/Widget/Wiki_pages.php b/Zotlabs/Widget/Wiki_pages.php
index 3999d9858..f98081da0 100644
--- a/Zotlabs/Widget/Wiki_pages.php
+++ b/Zotlabs/Widget/Wiki_pages.php
@@ -35,6 +35,7 @@ class Wiki_pages {
if (!$wikiname) {
$wikiname = '';
}
+ $typelock = $w['typelock'];
}
$can_create = perm_is_allowed(\App::$profile['uid'],get_observer_hash(),'write_wiki');
@@ -50,6 +51,8 @@ class Wiki_pages {
'$canadd' => $can_create,
'$candel' => $can_delete,
'$addnew' => t('Add new page'),
+ '$typelock' => $typelock,
+ '$lockedtype' => $w['mimeType'],
'$mimetype' => mimetype_select(0,$w['mimeType'], [ 'text/markdown','text/bbcode', 'text/plain' ]),
'$pageName' => array('pageName', t('Page name')),
'$refresh' => $arr['refresh']
diff --git a/boot.php b/boot.php
index a344384db..aeb3ec8b6 100755
--- a/boot.php
+++ b/boot.php
@@ -49,7 +49,7 @@ require_once('include/hubloc.php');
require_once('include/attach.php');
define ( 'PLATFORM_NAME', 'hubzilla' );
-define ( 'STD_VERSION', '2.7.2' );
+define ( 'STD_VERSION', '2.7.3' );
define ( 'ZOT_REVISION', '1.3' );
define ( 'DB_UPDATE_VERSION', 1195 );
diff --git a/include/channel.php b/include/channel.php
index 213676f52..7072bb4ce 100644
--- a/include/channel.php
+++ b/include/channel.php
@@ -7,6 +7,7 @@ require_once('include/zot.php');
require_once('include/crypto.php');
require_once('include/menu.php');
require_once('include/perm_upgrade.php');
+require_once('include/photo/photo_driver.php');
/**
* @brief Called when creating a new channel.
@@ -273,6 +274,17 @@ function create_identity($arr) {
return $ret;
}
+ $a = q("select * from account where account_id = %d",
+ intval($arr['account_id'])
+ );
+
+ $z = [ 'account' => $a[0], 'channel' => $r[0], 'photo_url' => '' ];
+ call_hooks('create_channel_photo',$z);
+
+ if($z['photo_url']) {
+ import_channel_photo_from_url($z['photo_url'],$arr['account_id'],$r[0]['channel_id']);
+ }
+
if($role_permissions && array_key_exists('limits',$role_permissions))
$perm_limits = $role_permissions['limits'];
else
diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php
index 94d0faa94..c6c023147 100644
--- a/include/photo/photo_driver.php
+++ b/include/photo/photo_driver.php
@@ -637,6 +637,36 @@ function import_xchan_photo($photo,$xchan,$thing = false) {
}
+function import_channel_photo_from_url($photo,$aid,$uid) {
+
+ if($photo) {
+ $filename = basename($photo);
+
+ $result = z_fetch_url($photo,true);
+
+ if($result['success']) {
+ $img_str = $result['body'];
+ $type = guess_image_type($photo, $result['header']);
+
+ $h = explode("\n",$result['header']);
+ if($h) {
+ foreach($h as $hl) {
+ if(stristr($hl,'content-type:')) {
+ if(! stristr($hl,'image/')) {
+ $photo_failure = true;
+ }
+ }
+ }
+ }
+ }
+ }
+ else {
+ $photo_failure = true;
+ }
+
+ import_channel_photo($img_str,$type,$aid,$uid);
+
+}
function import_channel_photo($photo,$type,$aid,$uid) {
diff --git a/view/css/mod_wiki.css b/view/css/mod_wiki.css
index b44ec4fd8..a16ab47c5 100644
--- a/view/css/mod_wiki.css
+++ b/view/css/mod_wiki.css
@@ -38,14 +38,8 @@
padding: 7px 3px 7px 10px;
}
-#wikis-index th:nth-child(3),
-#wikis-index td:nth-child(3){
- padding: 7px 10px 7px 7px;
- white-space: nowrap;
-}
-
-#wikis-index th:nth-child(4),
-#wikis-index td:nth-child(4){
+#wikis-index th:nth-child(6),
+#wikis-index td:nth-child(6){
padding: 7px 10px 7px 7px;
}
diff --git a/view/js/main.js b/view/js/main.js
index cdba8a25d..919eb282a 100644
--- a/view/js/main.js
+++ b/view/js/main.js
@@ -262,6 +262,14 @@ function openClose(theID) {
}
}
+function openCloseTR(theID) {
+ if(document.getElementById(theID).style.display == "table-row") {
+ document.getElementById(theID).style.display = "none";
+ } else {
+ document.getElementById(theID).style.display = "table-row";
+ }
+}
+
function closeOpen(theID) {
if(document.getElementById(theID).style.display == "none") {
document.getElementById(theID).style.display = "block";
diff --git a/view/tpl/wiki.tpl b/view/tpl/wiki.tpl
index 7995b7bb1..70a13806d 100644
--- a/view/tpl/wiki.tpl
+++ b/view/tpl/wiki.tpl
@@ -1,6 +1,7 @@
<div class="generic-content-wrapper" {{if $hideEditor}}style="display: none;"{{/if}}>
<div class="section-title-wrapper">
<div class="pull-right">
+ <span class="wiki-typename">[{{$typename}}]&nbsp;</span>
{{if $showPageControls}}
<div id="page-tools" class="btn-group" style="display: none;">
<button type="button" class="btn btn-outline-secondary btn-sm dropdown-toggle" data-toggle="dropdown">
diff --git a/view/tpl/wiki_page_list.tpl b/view/tpl/wiki_page_list.tpl
index 2e7fb8b9e..3d38a0b81 100644
--- a/view/tpl/wiki_page_list.tpl
+++ b/view/tpl/wiki_page_list.tpl
@@ -21,7 +21,11 @@
<div id="new-page-form-wrapper" class="sub-menu" style="display:none;">
<form id="new-page-form" action="wiki/{{$channel_address}}/create/page" method="post" >
<input type="hidden" name="resource_id" value="{{$resource_id}}">
+ {{if $typelock}}
+ <input type="hidden" name="mimetype" value="{{$lockedtype}}">
+ {{else}}
{{$mimetype}}
+ {{/if}}
{{include file="field_input.tpl" field=$pageName}}
<button id="new-page-submit" class="btn btn-primary" type="submit" name="submit" >Submit</button>
</form>
diff --git a/view/tpl/wikilist.tpl b/view/tpl/wikilist.tpl
index 2deec76c0..dfd7f553d 100644
--- a/view/tpl/wikilist.tpl
+++ b/view/tpl/wikilist.tpl
@@ -10,6 +10,7 @@
<form id="new-wiki-form" action="wiki/{{$channel}}/create/wiki" method="post" class="acl-form" data-form_id="new-wiki-form" data-allow_cid='{{$allow_cid}}' data-allow_gid='{{$allow_gid}}' data-deny_cid='{{$deny_cid}}' data-deny_gid='{{$deny_gid}}'>
{{include file="field_input.tpl" field=$wikiName}}
{{include file="field_select.tpl" field=$mimeType}}
+ {{include file="field_checkbox.tpl" field=$typelock}}
{{include file="field_checkbox.tpl" field=$notify}}
<div>
<div class="btn-group pull-right">
@@ -20,7 +21,6 @@
</div>
</div>
</form>
- {{$acl}}
<div class="clear"></div>
</div>
{{/if}}
@@ -30,7 +30,10 @@
<th width="96%">{{$name}}</th>
<th width="1%">{{$type}}</th>
<th width="1%" class="wikis-index-tool"></th>
- <!-- th width="1%" class="wikis-index-tool"></th -->
+ {{if $owner}}
+ <th width="1%" class="wikis-index-tool"></th>
+ {{/if}}
+ <th width="1%" class="wikis-index-tool"></th>
{{if $owner}}
<th width="1%"></th>
{{/if}}
@@ -38,22 +41,42 @@
{{foreach $wikis as $wiki}}
<tr class="wikis-index-row">
<td><a href="/wiki/{{$channel}}/{{$wiki.urlName}}/Home" title="{{$view}}"{{if $wiki.active}} class="active"{{/if}}>{{$wiki.title}}</a></td>
- <td>{{$wiki.mimeType}}</td>
- <td class="wiki-index-tool dropdown">
- {{if $wiki.lock}}
- <i class="fa fa-lock lockview" data-toggle="dropdown" onclick="lockview('item',{{$wiki.id}});"></i></button>
+ <td>{{if $wiki.typelock}}{{$wiki.mimeType}}{{else}}{{$unlocked}}{{/if}}</td>
+ {{if $owner}}
+ <td class="wikis-index-tool"><i class="fa fa-pencil" onclick="openCloseTR('wikis-index-edit-{{$wiki.id}}')"></i></td>
+ {{/if}}
+ <td class="wikis-index-tool dropdown">
+ {{if $wiki.lockstate == 'lock'}}
+ <i class="fa fa-lock lockview" data-toggle="dropdown" onclick="lockview('item',{{$wiki.id}});"></i>
<ul id="panel-{{$wiki.id}}" class="lockview-panel dropdown-menu dropdown-menu-right"></ul>
{{/if}}
</td>
- <!-- td class="wiki-index-tool"><i class="fa fa-download fakelink" onclick="wiki_download_wiki('{{$wiki.resource_id}}'); return false;"></i></td -->
+ <td class="wikis-index-tool"><i class="fa fa-download" onclick="wiki_download_wiki('{{$wiki.resource_id}}'); return false;"></i></td>
{{if $owner}}
<td><i class="fa fa-trash-o drop-icons" onclick="wiki_delete_wiki('{{$wiki.title}}', '{{$wiki.resource_id}}'); return false;"></i></td>
{{/if}}
</tr>
+ {{if $owner}}
+ <tr id="wikis-index-edit-{{$wiki.id}}" style="display:none">
+ <td colspan="6">
+ <form id="edit-wiki-form-{{$wiki.id}}" method="post" action="wiki/{{$channel}}/update/wiki" class="acl-form" data-form_id="edit-wiki-form-{{$wiki.id}}" data-allow_cid='{{$wiki.json_allow_cid}}' data-allow_gid='{{$wiki.json_allow_gid}}' data-deny_cid='{{$wiki.json_deny_cid}}' data-deny_gid='{{$wiki.json_deny_gid}}'>
+ <input type="hidden" name="origRawName" value="{{$wiki.title}}">
+ {{include file="field_input.tpl" field=['updateRawName', 'Edit Wiki Name', $wiki.title]}}
+ <div class="btn-group float-right">
+ <button class="btn btn-outline-secondary btn-sm" data-toggle="modal" data-target="#aclModal" type="button">
+ <i class="jot-perms-icon fa fa-{{$wiki.lockstate}}"></i>
+ </button>
+ <button class="btn btn-primary btn-sm" type="submit" value="edit">Submit</button>
+ </div>
+ </form>
+ </td>
+ </tr>
+ {{/if}}
{{/foreach}}
</table>
</div>
</div>
+{{$acl}}
<script>
{{if $owner}}
function wiki_delete_wiki(wikiHtmlName, resource_id) {