aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2016-06-16 10:26:47 +0200
committerMario Vavti <mario@mariovavti.com>2016-06-16 10:26:47 +0200
commit28a7458e48d45bfa1e0a3df9ba0a5f7c13b3809b (patch)
tree7b13533527f03baee8d9cc4b339b535462ae7ada /include
parent05ed20d336c505520fde94e44789d817d136c6f4 (diff)
parentd457f11717da40f44d98eeba5b88e6f1e5636247 (diff)
downloadvolse-hubzilla-28a7458e48d45bfa1e0a3df9ba0a5f7c13b3809b.tar.gz
volse-hubzilla-28a7458e48d45bfa1e0a3df9ba0a5f7c13b3809b.tar.bz2
volse-hubzilla-28a7458e48d45bfa1e0a3df9ba0a5f7c13b3809b.zip
Merge branch 'dev' into sabre32
Diffstat (limited to 'include')
-rw-r--r--include/bbcode.php15
-rw-r--r--include/network.php16
-rw-r--r--include/text.php40
-rw-r--r--include/wiki.php55
4 files changed, 114 insertions, 12 deletions
diff --git a/include/bbcode.php b/include/bbcode.php
index 63a475779..b720355af 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -491,6 +491,12 @@ function bb_code($match) {
return '<code class="inline-code">' . trim($match[1]) . '</code>';
}
+function bb_highlight($match) {
+ if(in_array(strtolower($match[1]),['php','css','mysql','sql','abap','diff','html','perl','ruby',
+ 'vbscript','avrc','dtd','java','xml','cpp','python','javascript','js','sh']))
+ return text_highlight($match[2],strtolower($match[1]));
+ return $match[0];
+}
// BBcode 2 HTML was written by WAY2WEB.net
@@ -566,6 +572,15 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false)
$Text = str_replace(">", "&gt;", $Text);
+ // Check for [code] text here, before the linefeeds are messed with.
+ // The highlighter will unescape and re-escape the content.
+
+ if (strpos($Text,'[code=') !== false) {
+ $Text = preg_replace_callback("/\[code=(.*?)\](.*?)\[\/code\]/ism", 'bb_highlight', $Text);
+ }
+
+
+
// Convert new line chars to html <br /> tags
// nlbr seems to be hopelessly messed up
diff --git a/include/network.php b/include/network.php
index 0dd10e29b..a595a03d1 100644
--- a/include/network.php
+++ b/include/network.php
@@ -21,15 +21,16 @@ function get_capath() {
* TRUE if asked to return binary results (file download)
* @param int $redirects default 0
* internal use, recursion counter
- * @param array $opts (optional parameters) assoziative array with:
+ * @param array $opts (optional parameters) associative array with:
* * \b accept_content => supply Accept: header with 'accept_content' as the value
* * \b timeout => int seconds, default system config value or 60 seconds
* * \b http_auth => username:password
* * \b novalidate => do not validate SSL certs, default is to validate using our CA list
* * \b nobody => only return the header
* * \b filep => stream resource to write body to. header and body are not returned when using this option.
+ * * \b custom => custom request method: e.g. 'PUT', 'DELETE'
*
- * @return array an assoziative array with:
+ * @return array an associative array with:
* * \e int \b return_code => HTTP return code or 0 if timeout or failure
* * \e boolean \b success => boolean true (if HTTP 2xx result) or false
* * \e string \b header => HTTP headers
@@ -65,6 +66,9 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) {
if(x($opts,'nobody'))
@curl_setopt($ch, CURLOPT_NOBODY, $opts['nobody']);
+ if(x($opts,'custom'))
+ @curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $opts['custom']);
+
if(x($opts,'timeout') && intval($opts['timeout'])) {
@curl_setopt($ch, CURLOPT_TIMEOUT, $opts['timeout']);
}
@@ -165,7 +169,9 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) {
* 'http_auth' => username:password
* 'novalidate' => do not validate SSL certs, default is to validate using our CA list
* 'filep' => stream resource to write body to. header and body are not returned when using this option.
- * @return array an assoziative array with:
+ * 'custom' => custom request method: e.g. 'PUT', 'DELETE'
+ *
+ * @return array an associative array with:
* * \e int \b return_code => HTTP return code or 0 if timeout or failure
* * \e boolean \b success => boolean true (if HTTP 2xx result) or false
* * \e string \b header => HTTP headers
@@ -205,6 +211,10 @@ logger('headers: ' . print_r($opts['headers'],true) . 'redir: ' . $redirects);
if(x($opts,'nobody'))
@curl_setopt($ch, CURLOPT_NOBODY, $opts['nobody']);
+ if(x($opts,'custom'))
+ @curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $opts['custom']);
+
+
if(x($opts,'timeout') && intval($opts['timeout'])) {
@curl_setopt($ch, CURLOPT_TIMEOUT, $opts['timeout']);
}
diff --git a/include/text.php b/include/text.php
index bd59aa732..59190a9ca 100644
--- a/include/text.php
+++ b/include/text.php
@@ -2881,3 +2881,43 @@ function flatten_array_recursive($arr) {
}
return($ret);
}
+
+function text_highlight($s,$lang) {
+
+ if($lang === 'js')
+ $lang = 'javascript';
+
+ if(! strpos('Text_Highlighter',get_include_path())) {
+ set_include_path(get_include_path() . PATH_SEPARATOR . 'library/Text_Highlighter');
+ }
+ require_once('library/Text_Highlighter/Text/Highlighter.php');
+ require_once('library/Text_Highlighter/Text/Highlighter/Renderer/Html.php');
+ $options = array(
+ 'numbers' => HL_NUMBERS_LI,
+ 'tabsize' => 4,
+ );
+ $tag_added = false;
+ $s = trim(html_entity_decode($s,ENT_COMPAT));
+ $s = str_replace(" ","\t",$s);
+ if($lang === 'php') {
+ if(strpos('<?php',$s) !== 0) {
+ $s = '<?php' . "\n" . $s;
+ $tag_added = true;
+ }
+
+ }
+ $renderer = new Text_Highlighter_Renderer_HTML($options);
+ $hl = Text_Highlighter::factory($lang);
+ $hl->setRenderer($renderer);
+ $o = $hl->highlight($s);
+ $o = str_replace([" ","\n"],["&nbsp;&nbsp;&nbsp;&nbsp;",''],$o);
+
+ if($tag_added) {
+ $b = substr($o,0,strpos($o,'<li>'));
+ $e = substr($o,strpos($o,'</li>'));
+ $o = $b . $e;
+ }
+
+ return('<code>' . $o . '</code>');
+}
+
diff --git a/include/wiki.php b/include/wiki.php
index 4aa3fc1b4..d60f4a3a7 100644
--- a/include/wiki.php
+++ b/include/wiki.php
@@ -231,6 +231,34 @@ function wiki_create_page($name, $resource_id) {
}
+function wiki_rename_page($arr) {
+ $pageUrlName = ((array_key_exists('pageUrlName',$arr)) ? $arr['pageUrlName'] : '');
+ $pageNewName = ((array_key_exists('pageNewName',$arr)) ? $arr['pageNewName'] : '');
+ $resource_id = ((array_key_exists('resource_id',$arr)) ? $arr['resource_id'] : '');
+ $w = wiki_get_wiki($resource_id);
+ if (!$w['path']) {
+ return array('message' => 'Wiki not found.', 'success' => false);
+ }
+ $page_path_old = $w['path'].'/'.$pageUrlName.'.md';
+ logger('$page_path_old: ' . $page_path_old);
+ if (!is_readable($page_path_old) === true) {
+ return array('message' => 'Cannot read wiki page: ' . $page_path_old, 'success' => false);
+ }
+ $page = array('rawName' => $pageNewName, 'htmlName' => escape_tags($pageNewName), 'urlName' => urlencode(escape_tags($pageNewName)), 'fileName' => urlencode(escape_tags($pageNewName)).'.md');
+ $page_path_new = $w['path'] . '/' . $page['fileName'] ;
+ logger('$page_path_new: ' . $page_path_new);
+ if (is_file($page_path_new)) {
+ return array('message' => 'Page already exists.', 'success' => false);
+ }
+ // Rename the page file in the wiki repo
+ if(!rename($page_path_old, $page_path_new)) {
+ return array('message' => 'Error renaming page file.', 'success' => false);
+ } else {
+ return array('page' => $page, 'message' => '', 'success' => true);
+ }
+
+}
+
function wiki_get_page_content($arr) {
$pageUrlName = ((array_key_exists('pageUrlName',$arr)) ? $arr['pageUrlName'] : '');
$resource_id = ((array_key_exists('resource_id',$arr)) ? $arr['resource_id'] : '');
@@ -342,7 +370,7 @@ function wiki_revert_page($arr) {
}
}
} catch (\PHPGit\Exception\GitException $e) {
- json_return_and_die(array('content' => $content, 'message' => 'GitRepo error thrown', 'success' => false));
+ return array('content' => $content, 'message' => 'GitRepo error thrown', 'success' => false);
}
return array('content' => $content, 'message' => '', 'success' => true);
} else {
@@ -352,9 +380,18 @@ function wiki_revert_page($arr) {
function wiki_git_commit($arr) {
$files = ((array_key_exists('files', $arr)) ? $arr['files'] : null);
+ $all = ((array_key_exists('all', $arr)) ? $arr['all'] : false);
$commit_msg = ((array_key_exists('commit_msg', $arr)) ? $arr['commit_msg'] : 'Repo updated');
- $resource_id = ((array_key_exists('resource_id', $arr)) ? $arr['resource_id'] : json_return_and_die(array('message' => 'Wiki resource_id required for git commit', 'success' => false)));
- $observer = ((array_key_exists('observer', $arr)) ? $arr['observer'] : json_return_and_die(array('message' => 'Observer required for git commit', 'success' => false)));
+ if(array_key_exists('resource_id', $arr)) {
+ $resource_id = $arr['resource_id'];
+ } else {
+ return array('message' => 'Wiki resource_id required for git commit', 'success' => false);
+ }
+ if(array_key_exists('observer', $arr)) {
+ $observer = $arr['observer'];
+ } else {
+ return array('message' => 'Observer required for git commit', 'success' => false);
+ }
$w = wiki_get_wiki($resource_id);
if (!$w['path']) {
return array('message' => 'Error reading wiki', 'success' => false);
@@ -369,23 +406,23 @@ function wiki_git_commit($arr) {
if ($files === null) {
$options = array('all' => true); // git commit option to include all changes
} else {
- $options = array(); // git commit options
+ $options = array('all' => $all); // git commit options\
foreach ($files as $file) {
if (!$git->git->add($file)) { // add specified files to the git repo stage
if (!$git->git->reset->hard()) {
- json_return_and_die(array('message' => 'Error adding file to git stage: ' . $file . '. Error resetting git repo.', 'success' => false));
+ return array('message' => 'Error adding file to git stage: ' . $file . '. Error resetting git repo.', 'success' => false);
}
- json_return_and_die(array('message' => 'Error adding file to git stage: ' . $file, 'success' => false));
+ return array('message' => 'Error adding file to git stage: ' . $file, 'success' => false);
}
}
}
if ($git->commit($commit_msg, $options)) {
- json_return_and_die(array('message' => 'Wiki repo commit succeeded', 'success' => true));
+ return array('message' => 'Wiki repo commit succeeded', 'success' => true);
} else {
- json_return_and_die(array('message' => 'Wiki repo commit failed', 'success' => false));
+ return array('message' => 'Wiki repo commit failed', 'success' => false);
}
} catch (\PHPGit\Exception\GitException $e) {
- json_return_and_die(array('message' => 'GitRepo error thrown', 'success' => false));
+ return array('message' => 'GitRepo error thrown', 'success' => false);
}
}