From 961539258be90f5b7c989299db0e8c551d0d6c72 Mon Sep 17 00:00:00 2001 From: Andrew Manning Date: Fri, 17 Jun 2016 06:33:39 -0400 Subject: Wiki page revision comparison tool with diff displayed in modal dialog. Leverages Diff class from http://code.stephenmorley.org/php/diff-implementation with license CC0 1.0 universal http://creativecommons.org/publicdomain/zero/1.0/legalcode --- include/wiki.php | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/wiki.php b/include/wiki.php index d60f4a3a7..a89db3358 100644 --- a/include/wiki.php +++ b/include/wiki.php @@ -347,7 +347,7 @@ function wiki_revert_page($arr) { $resource_id = ((array_key_exists('resource_id',$arr)) ? $arr['resource_id'] : ''); $commitHash = ((array_key_exists('commitHash',$arr)) ? $arr['commitHash'] : null); if (! $commitHash) { - return array('content' => $content, 'message' => 'No commit has provided', 'success' => false); + return array('content' => $content, 'message' => 'No commit was provided', 'success' => false); } $w = wiki_get_wiki($resource_id); if (!$w['path']) { @@ -378,6 +378,48 @@ function wiki_revert_page($arr) { } } +function wiki_compare_page($arr) { + $pageUrlName = ((array_key_exists('pageUrlName',$arr)) ? $arr['pageUrlName'] : ''); + $resource_id = ((array_key_exists('resource_id',$arr)) ? $arr['resource_id'] : ''); + $currentCommit = ((array_key_exists('currentCommit',$arr)) ? $arr['currentCommit'] : 'HEAD'); + $compareCommit = ((array_key_exists('compareCommit',$arr)) ? $arr['compareCommit'] : null); + if (! $compareCommit) { + return array('message' => 'No compare commit was provided', 'success' => false); + } + $w = wiki_get_wiki($resource_id); + if (!$w['path']) { + return array('message' => 'Error reading wiki', 'success' => false); + } + $page_path = $w['path'].'/'.$pageUrlName.'.md'; + if (is_readable($page_path) === true) { + $reponame = ((array_key_exists('title', $w['wiki'])) ? urlencode($w['wiki']['title']) : 'repo'); + if($reponame === '') { + $reponame = 'repo'; + } + $git = new GitRepo('', null, false, $w['wiki']['title'], $w['path']); + $compareContent = $currentContent = ''; + try { + foreach ($git->git->tree($currentCommit) as $object) { + if ($object['type'] == 'blob' && $object['file'] === $pageUrlName.'.md' ) { + $currentContent = $git->git->cat->blob($object['hash']); + } + } + foreach ($git->git->tree($compareCommit) as $object) { + if ($object['type'] == 'blob' && $object['file'] === $pageUrlName.'.md' ) { + $compareContent = $git->git->cat->blob($object['hash']); + } + } + require_once('library/class.Diff.php'); + $diff = Diff::toTable(Diff::compare($currentContent, $compareContent)); + } catch (\PHPGit\Exception\GitException $e) { + return array('message' => 'GitRepo error thrown', 'success' => false); + } + return array('diff' => $diff, 'message' => '', 'success' => true); + } else { + return array('message' => 'Page file not writable', 'success' => false); + } +} + function wiki_git_commit($arr) { $files = ((array_key_exists('files', $arr)) ? $arr['files'] : null); $all = ((array_key_exists('all', $arr)) ? $arr['all'] : false); -- cgit v1.2.3 From 9c9d6363af22eeec7f38856302abb3251cb78a10 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Mon, 20 Jun 2016 19:39:12 -0700 Subject: update attach on import if exists --- include/attach.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/attach.php b/include/attach.php index 33545b12a..4961d7f91 100644 --- a/include/attach.php +++ b/include/attach.php @@ -618,7 +618,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) { ); if($r) { $overwrite = get_pconfig($channel_id,'system','overwrite_dup_files'); - if($overwrite) { + if(($overwrite) || ($options === 'import')) { $options = 'replace'; $existing_id = $x[0]['id']; $existing_size = intval($x[0]['filesize']); @@ -802,7 +802,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) { if($is_photo) { - $args = array( 'source' => $source, 'visible' => $visible, 'resource_id' => $hash, 'album' => basename($pathname), 'os_path' => $os_basepath . $os_relpath, 'filename' => $filename, 'getimagesize' => $gis, 'directory' => $direct); + $args = array( 'source' => $source, 'visible' => $visible, 'resource_id' => $hash, 'album' => basename($pathname), 'os_path' => $os_basepath . $os_relpath, 'filename' => $filename, 'getimagesize' => $gis, 'directory' => $direct, 'options' => $options ); if($arr['contact_allow']) $args['contact_allow'] = $arr['contact_allow']; if($arr['group_allow']) -- cgit v1.2.3 From ed166608670c5b5d237c43bd0d672502d5b624f5 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Mon, 20 Jun 2016 20:34:19 -0700 Subject: code optimisation --- include/network.php | 9 +-------- include/plugin.php | 6 ++++++ include/text.php | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/network.php b/include/network.php index 062f2c2bf..41d13a40e 100644 --- a/include/network.php +++ b/include/network.php @@ -1992,14 +1992,7 @@ function get_site_info() { else $service_class = false; - $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['aname']; - } - sort($visible_plugins); + $visible_plugins = visible_plugin_list(); if(@is_dir('.git') && function_exists('shell_exec')) $commit = trim(@shell_exec('git log -1 --format="%h"')); diff --git a/include/plugin.php b/include/plugin.php index 9b84039a6..c95f8cbf9 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -167,6 +167,12 @@ function reload_plugins() { } } +function visible_plugin_list() { + $r = q("select * from addon where hidden = 0 order by aname asc"); + return(($r) ? ids_to_array($r,'aname') : array()); +} + + /** * @brief registers a hook. diff --git a/include/text.php b/include/text.php index 22f4556a8..3754675d1 100644 --- a/include/text.php +++ b/include/text.php @@ -2050,7 +2050,7 @@ function ids_to_array($arr,$idx = 'id') { $t = array(); if($arr) { foreach($arr as $x) { - if(! in_array($x[$idx],$t)) { + if(strlen($x[$idx]) && (! in_array($x[$idx],$t))) { $t[] = $x[$idx]; } } -- cgit v1.2.3 From 63423c8ee1f750d855c75ed67205076d21eda4f1 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Mon, 20 Jun 2016 20:56:58 -0700 Subject: make sure the optimisations are reliable --- include/text.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/text.php b/include/text.php index 3754675d1..4f28c6dbc 100644 --- a/include/text.php +++ b/include/text.php @@ -2050,7 +2050,7 @@ function ids_to_array($arr,$idx = 'id') { $t = array(); if($arr) { foreach($arr as $x) { - if(strlen($x[$idx]) && (! in_array($x[$idx],$t))) { + if(array_key_exists($idx,$x) && strlen($x[$idx]) && (! in_array($x[$idx],$t))) { $t[] = $x[$idx]; } } -- cgit v1.2.3