aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzotlabs <mike@macgirvin.com>2018-11-08 19:49:57 -0800
committerzotlabs <mike@macgirvin.com>2018-11-08 19:49:57 -0800
commitd56e1f6285fd2e4cc7b2f9cd88df88a26c5d2ad7 (patch)
treebecc824f9d7da04fb31c5ef00406cf27a929d34e
parent22b3ddab66f128ca05a42ebfccda0964bddd7509 (diff)
downloadvolse-hubzilla-d56e1f6285fd2e4cc7b2f9cd88df88a26c5d2ad7.tar.gz
volse-hubzilla-d56e1f6285fd2e4cc7b2f9cd88df88a26c5d2ad7.tar.bz2
volse-hubzilla-d56e1f6285fd2e4cc7b2f9cd88df88a26c5d2ad7.zip
begin native summary support
-rw-r--r--Zotlabs/Module/Item.php24
-rwxr-xr-xinclude/items.php15
-rw-r--r--include/text.php23
3 files changed, 57 insertions, 5 deletions
diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php
index 2ee639874..1e1df9d56 100644
--- a/Zotlabs/Module/Item.php
+++ b/Zotlabs/Module/Item.php
@@ -392,6 +392,7 @@ class Item extends \Zotlabs\Web\Controller {
$verb = $orig_post['verb'];
$app = $orig_post['app'];
$title = escape_tags(trim($_REQUEST['title']));
+ $summary = trim($_REQUEST['summary']);
$body = trim($_REQUEST['body']);
$item_flags = $orig_post['item_flags'];
@@ -454,6 +455,7 @@ class Item extends \Zotlabs\Web\Controller {
$coord = notags(trim($_REQUEST['coord']));
$verb = notags(trim($_REQUEST['verb']));
$title = escape_tags(trim($_REQUEST['title']));
+ $summary = trim($_REQUEST['summary']);
$body = trim($_REQUEST['body']);
$body .= trim($_REQUEST['attachment']);
$postopts = '';
@@ -505,12 +507,14 @@ class Item extends \Zotlabs\Web\Controller {
&& ($channel['channel_pageflags'] & PAGE_ALLOWCODE)) ? true : false);
if($preview) {
+ $summary = z_input_filter($summary,$mimetype,$execflag);
$body = z_input_filter($body,$mimetype,$execflag);
}
- $arr = [ 'profile_uid' => $profile_uid, 'content' => $body, 'mimetype' => $mimetype ];
+ $arr = [ 'profile_uid' => $profile_uid, 'summary' => $summary, 'content' => $body, 'mimetype' => $mimetype ];
call_hooks('post_content',$arr);
+ $summary = $arr['summary'];
$body = $arr['content'];
$mimetype = $arr['mimetype'];
@@ -531,9 +535,23 @@ class Item extends \Zotlabs\Web\Controller {
// we may need virtual or template classes to implement the possible alternatives
+ if(strpos($body,'[/summary]') !== false) {
+ $match = '';
+ $cnt = preg_match("/\[summary\](.*?)\[\/summary\]/ism",$body,$match);
+ if($cnt) {
+ $summary .= $match[1];
+ }
+ $body_content = preg_replace("/^(.*?)\[summary\](.*?)\[\/summary\](.*?)$/ism", '',$body);
+ $body = trim($body_content);
+ }
+
+ $summary = cleanup_bbcode($summary);
+
$body = cleanup_bbcode($body);
// Look for tags and linkify them
+
+ $results = linkify_tags($a, $summary, ($uid) ? $uid : $profile_uid);
$results = linkify_tags($a, $body, ($uid) ? $uid : $profile_uid);
if($results) {
@@ -579,6 +597,9 @@ class Item extends \Zotlabs\Web\Controller {
if(! $preview) {
fix_attached_photo_permissions($profile_uid,$owner_xchan['xchan_hash'],((strpos($body,'[/crypt]')) ? $_POST['media_str'] : $body),$str_contact_allow,$str_group_allow,$str_contact_deny,$str_group_deny);
+ fix_attached_photo_permissions($profile_uid,$owner_xchan['xchan_hash'],((strpos($summary,'[/crypt]')) ? $_POST['media_str'] : $summary),$str_contact_allow,$str_group_allow,$str_contact_deny,$str_group_deny);
+
+
fix_attached_file_permissions($channel,$observer['xchan_hash'],((strpos($body,'[/crypt]')) ? $_POST['media_str'] : $body),$str_contact_allow,$str_group_allow,$str_contact_deny,$str_group_deny);
}
@@ -778,6 +799,7 @@ class Item extends \Zotlabs\Web\Controller {
$datarray['parent_mid'] = $parent_mid;
$datarray['mimetype'] = $mimetype;
$datarray['title'] = $title;
+ $datarray['summary'] = $summary;
$datarray['body'] = $body;
$datarray['app'] = $app;
$datarray['location'] = $location;
diff --git a/include/items.php b/include/items.php
index cae380b01..24f1be84f 100755
--- a/include/items.php
+++ b/include/items.php
@@ -597,6 +597,7 @@ function get_item_elements($x,$allow_code = false) {
$arr = array();
$arr['body'] = $x['body'];
+ $arr['summary'] = $x['summary'];
$maxlen = get_max_import_size();
@@ -605,6 +606,11 @@ function get_item_elements($x,$allow_code = false) {
logger('get_item_elements: message length exceeds max_import_size: truncated');
}
+ if($maxlen && mb_strlen($arr['summary']) > $maxlen) {
+ $arr['summary'] = mb_substr($arr['summary'],0,$maxlen,'UTF-8');
+ logger('get_item_elements: message summary length exceeds max_import_size: truncated');
+ }
+
$arr['created'] = datetime_convert('UTC','UTC',$x['created']);
$arr['edited'] = datetime_convert('UTC','UTC',$x['edited']);
@@ -749,9 +755,10 @@ function get_item_elements($x,$allow_code = false) {
// Do this after signature checking as the original signature
// was generated on the escaped content.
- if($arr['mimetype'] === 'text/markdown')
+ if($arr['mimetype'] === 'text/markdown') {
+ $arr['summary'] = MarkdownSoap::unescape($arr['summary']);
$arr['body'] = MarkdownSoap::unescape($arr['body']);
-
+ }
if(array_key_exists('revision',$x)) {
// extended export encoding
@@ -1073,6 +1080,7 @@ function encode_item($item,$mirror = false) {
$x['commented'] = $item['commented'];
$x['mimetype'] = $item['mimetype'];
$x['title'] = $item['title'];
+ $x['summary'] = $item['summary'];
$x['body'] = $item['body'];
$x['app'] = $item['app'];
$x['verb'] = $item['verb'];
@@ -1631,6 +1639,7 @@ function item_store($arr, $allow_exec = false, $deliver = true) {
}
$arr['title'] = ((array_key_exists('title',$arr) && strlen($arr['title'])) ? trim($arr['title']) : '');
+ $arr['summary'] = ((array_key_exists('summary',$arr) && strlen($arr['summary'])) ? trim($arr['summary']) : '');
$arr['body'] = ((array_key_exists('body',$arr) && strlen($arr['body'])) ? trim($arr['body']) : '');
$arr['allow_cid'] = ((x($arr,'allow_cid')) ? trim($arr['allow_cid']) : '');
@@ -1651,6 +1660,7 @@ function item_store($arr, $allow_exec = false, $deliver = true) {
// apply the input filter here
+ $arr['summary'] = trim(z_input_filter($arr['summary'],$arr['mimetype'],$allow_exec));
$arr['body'] = trim(z_input_filter($arr['body'],$arr['mimetype'],$allow_exec));
item_sign($arr);
@@ -2096,6 +2106,7 @@ function item_store_update($arr, $allow_exec = false, $deliver = true) {
// apply the input filter here
+ $arr['summary'] = trim(z_input_filter($arr['summary'],$arr['mimetype'],$allow_exec));
$arr['body'] = trim(z_input_filter($arr['body'],$arr['mimetype'],$allow_exec));
item_sign($arr);
diff --git a/include/text.php b/include/text.php
index 15cc0ca8a..3d351f7dc 100644
--- a/include/text.php
+++ b/include/text.php
@@ -3,8 +3,11 @@
* @file include/text.php
*/
-use \Zotlabs\Lib as Zlib;
-use \Michelf\MarkdownExtra;
+use Zotlabs\Lib as Zlib;
+
+use Michelf\MarkdownExtra;
+use Ramsey\Uuid\Uuid;
+use Ramsey\Uuid\Exception\UnsatisfiedDependencyException;
require_once("include/bbcode.php");
@@ -3467,3 +3470,19 @@ function print_val($v) {
return $v;
}
+
+/**
+ * @brief Generate a unique ID.
+ *
+ * @return string
+ */
+function new_uuid() {
+
+ try {
+ $hash = Uuid::uuid4()->toString();
+ } catch (UnsatisfiedDependencyException $e) {
+ $hash = random_string(48);
+ }
+
+ return $hash;
+}