aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/channel.php15
-rwxr-xr-xinclude/items.php10
-rwxr-xr-xinclude/oembed.php6
-rw-r--r--include/photo/photo_driver.php31
-rw-r--r--include/photo/photo_imagick.php10
-rw-r--r--include/text.php45
6 files changed, 89 insertions, 28 deletions
diff --git a/include/channel.php b/include/channel.php
index 1e5570f6b..95a3f96cf 100644
--- a/include/channel.php
+++ b/include/channel.php
@@ -2333,6 +2333,21 @@ function channelx_by_hash($hash) {
return(($r) ? $r[0] : false);
}
+
+/**
+ * @brief Get a channel array by a channel_hash.
+ *
+ * @param string $hash
+ * @return array|boolean false if channel ID not found, otherwise the channel array
+ */
+function channelx_by_portid($hash) {
+ $r = q("SELECT * FROM channel left join xchan on channel_portable_id = xchan_hash WHERE channel_portable_id = '%s' and channel_removed = 0 LIMIT 1",
+ dbesc($hash)
+ );
+
+ return(($r) ? $r[0] : false);
+}
+
/**
* @brief Get a channel array by a channel ID.
*
diff --git a/include/items.php b/include/items.php
index 2cee376d0..0cbca23fc 100755
--- a/include/items.php
+++ b/include/items.php
@@ -420,7 +420,7 @@ function post_activity_item($arr, $allow_code = false, $deliver = true) {
$arr['comment_policy'] = map_scope(PermissionLimits::Get($channel['channel_id'],'post_comments'));
if ((! $arr['plink']) && (intval($arr['item_thread_top']))) {
- $arr['plink'] = substr(z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . urlencode($arr['mid']),0,190);
+ $arr['plink'] = substr(z_root() . '/channel/' . $channel['channel_address'] . '/' . (filter_var($arr['mid'], FILTER_VALIDATE_URL) === false ? '?f=&mid=' : '') . urlencode($arr['mid']),0,190);
}
@@ -4629,10 +4629,10 @@ function fix_attached_photo_permissions($uid,$xchan_hash,$body,
if(! stristr($image,z_root() . '/photo/'))
continue;
$image_uri = substr($image,strrpos($image,'/') + 1);
- if(strpos($image_uri,'-') !== false)
- $image_uri = substr($image_uri,0, strpos($image_uri,'-'));
- if(strpos($image_uri,'.') !== false)
- $image_uri = substr($image_uri,0, strpos($image_uri,'.'));
+ if(strrpos($image_uri,'-') !== false)
+ $image_uri = substr($image_uri,0, strrpos($image_uri,'-'));
+ if(strrpos($image_uri,'.') !== false)
+ $image_uri = substr($image_uri,0, strrpos($image_uri,'.'));
if(! strlen($image_uri))
continue;
$srch = '<' . $xchan_hash . '>';
diff --git a/include/oembed.php b/include/oembed.php
index e5557dc11..426197c5f 100755
--- a/include/oembed.php
+++ b/include/oembed.php
@@ -221,7 +221,11 @@ function oembed_fetch_url($embedurl){
if(strpos(strtolower($embedurl),'.pdf') !== false) {
$action = 'allow';
- $j = [ 'html' => '<object data="' . $embedurl . '" type="application/pdf" width="500" height="720">' . '<a href="' . $embedurl . '">' . t('View PDF') . '</a></object>', 'width' => 500, 'height' => 720, 'type' => 'pdf' ];
+ $j = [
+ 'html' => '<object data="' . $embedurl . '" type="application/pdf" style="width: 100%; height: 300px;"></object>',
+ 'title' => t('View PDF'),
+ 'type' => 'pdf'
+ ];
}
diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php
index b70a13622..9aeb2ef17 100644
--- a/include/photo/photo_driver.php
+++ b/include/photo/photo_driver.php
@@ -112,7 +112,7 @@ abstract class photo_driver {
public function saveImage($path) {
if(!$this->is_valid())
return FALSE;
- file_put_contents($path, $this->imageString());
+ return (file_put_contents($path, $this->imageString()) ? true : false);
}
@@ -330,9 +330,9 @@ abstract class photo_driver {
}
- public function save($arr) {
+ public function save($arr, $skipcheck = false) {
- if(! $this->is_valid()) {
+ if(! ($skipcheck || $this->is_valid())) {
logger('attempt to store invalid photo.');
return false;
}
@@ -344,6 +344,7 @@ abstract class photo_driver {
$p['xchan'] = (($arr['xchan']) ? $arr['xchan'] : '');
$p['resource_id'] = (($arr['resource_id']) ? $arr['resource_id'] : '');
$p['filename'] = (($arr['filename']) ? $arr['filename'] : '');
+ $p['mimetype'] = (($arr['mimetype']) ? $arr['mimetype'] : $this->getType());
$p['album'] = (($arr['album']) ? $arr['album'] : '');
$p['imgscale'] = ((intval($arr['imgscale'])) ? intval($arr['imgscale']) : 0);
$p['allow_cid'] = (($arr['allow_cid']) ? $arr['allow_cid'] : '');
@@ -360,6 +361,7 @@ abstract class photo_driver {
$p['display_path'] = (($arr['display_path']) ? $arr['display_path'] : '');
$p['width'] = (($arr['width']) ? $arr['width'] : $this->getWidth());
$p['height'] = (($arr['height']) ? $arr['height'] : $this->getHeight());
+ $p['expires'] = (($arr['expires']) ? $arr['expires'] : gmdate('Y-m-d H:i:s', time() + get_config('system','photo_cache_time', 86400)));
if(! intval($p['imgscale']))
logger('save: ' . print_r($arr,true), LOGGER_DATA);
@@ -397,17 +399,18 @@ abstract class photo_driver {
allow_cid = '%s',
allow_gid = '%s',
deny_cid = '%s',
- deny_gid = '%s'
+ deny_gid = '%s',
+ expires = '%s'
where id = %d",
intval($p['aid']),
intval($p['uid']),
dbesc($p['xchan']),
dbesc($p['resource_id']),
- dbesc($p['created']),
- dbesc($p['edited']),
+ dbescdate($p['created']),
+ dbescdate($p['edited']),
dbesc(basename($p['filename'])),
- dbesc($this->getType()),
+ dbesc($p['mimetype']),
dbesc($p['album']),
intval($p['height']),
intval($p['width']),
@@ -424,22 +427,23 @@ abstract class photo_driver {
dbesc($p['allow_gid']),
dbesc($p['deny_cid']),
dbesc($p['deny_gid']),
+ dbescdate($p['expires']),
intval($x[0]['id'])
);
}
else {
$p['created'] = (($arr['created']) ? $arr['created'] : $p['edited']);
$r = q("INSERT INTO photo
- ( aid, uid, xchan, resource_id, created, edited, filename, mimetype, album, height, width, content, os_storage, filesize, imgscale, photo_usage, title, description, os_path, display_path, allow_cid, allow_gid, deny_cid, deny_gid )
- VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )",
+ ( aid, uid, xchan, resource_id, created, edited, filename, mimetype, album, height, width, content, os_storage, filesize, imgscale, photo_usage, title, description, os_path, display_path, allow_cid, allow_gid, deny_cid, deny_gid, expires )
+ VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )",
intval($p['aid']),
intval($p['uid']),
dbesc($p['xchan']),
dbesc($p['resource_id']),
- dbesc($p['created']),
- dbesc($p['edited']),
+ dbescdate($p['created']),
+ dbescdate($p['edited']),
dbesc(basename($p['filename'])),
- dbesc($this->getType()),
+ dbesc($p['mimetype']),
dbesc($p['album']),
intval($p['height']),
intval($p['width']),
@@ -455,7 +459,8 @@ abstract class photo_driver {
dbesc($p['allow_cid']),
dbesc($p['allow_gid']),
dbesc($p['deny_cid']),
- dbesc($p['deny_gid'])
+ dbesc($p['deny_gid']),
+ dbescdate($p['expires'])
);
}
logger('photo save ' . $p['imgscale'] . ' returned ' . intval($r));
diff --git a/include/photo/photo_imagick.php b/include/photo/photo_imagick.php
index 89577e71e..f04c00245 100644
--- a/include/photo/photo_imagick.php
+++ b/include/photo/photo_imagick.php
@@ -31,8 +31,12 @@ class photo_imagick extends photo_driver {
if(! $data)
return;
- $this->image->readImageBlob($data);
-
+ try {
+ $this->image->readImageBlob($data);
+ }
+ catch (Exception $e) {
+ logger('imagick readImageBlob() exception:' . print_r($e,true));
+ }
/**
* Setup the image to the format it will be saved to
@@ -205,4 +209,4 @@ class photo_imagick extends photo_driver {
-} \ No newline at end of file
+}
diff --git a/include/text.php b/include/text.php
index 646bfe749..bd0d8048d 100644
--- a/include/text.php
+++ b/include/text.php
@@ -1105,23 +1105,33 @@ function linkify($s, $me = false) {
* to a local redirector which uses https and which redirects to the selected content
*
* @param string $s
+ * @param int $uid
* @returns string
*/
function sslify($s) {
+
+ // Local photo cache
+ $str = array(
+ 'body' => $s,
+ 'uid' => local_channel()
+ );
+ call_hooks('cache_body_hook', $str);
+
+ $s = $str['body'];
+
if (strpos(z_root(),'https:') === false)
return $s;
-
+
// By default we'll only sslify img tags because media files will probably choke.
// You can set sslify_everything if you want - but it will likely white-screen if it hits your php memory limit.
// The downside is that http: media files will likely be blocked by your browser
// Complain to your browser maker
$allow = get_config('system','sslify_everything');
-
- $pattern = (($allow) ? "/\<(.*?)src=\"(http\:.*?)\"(.*?)\>/" : "/\<img(.*?)src=\"(http\:.*?)\"(.*?)\>/" );
+ $pattern = (($allow) ? "/\<(.*?)src=[\"|'](http\:.*?)[\"|'](.*?)\>/" : "/\<img(.*?)src=[\"|'](http\:.*?)[\"|'](.*?)\>/" );
$matches = null;
- $cnt = preg_match_all($pattern,$s,$matches,PREG_SET_ORDER);
+ $cnt = preg_match_all($pattern, $s, $matches, PREG_SET_ORDER);
if ($cnt) {
foreach ($matches as $match) {
$filename = basename( parse_url($match[2], PHP_URL_PATH) );
@@ -3295,7 +3305,7 @@ function cleanup_bbcode($body) {
$body = preg_replace('/\[\/code\]\s*\[code\]/ism',"\n",$body);
- $body = scale_external_images($body,false);
+ $body = scale_external_images($body, false);
return $body;
}
@@ -3411,7 +3421,7 @@ function get_forum_channels($uid) {
$sql_extra = (($xf) ? " and ( xchan_hash in (" . $xf . ") or xchan_pubforum = 1 ) " : " and xchan_pubforum = 1 ");
- $r = q("select abook_id, xchan_hash, xchan_name, xchan_url, xchan_photo_s from abook left join xchan on abook_xchan = xchan_hash where xchan_deleted = 0 and abook_channel = %d and abook_pending = 0 and abook_ignored = 0 and abook_blocked = 0 and abook_archived = 0 $sql_extra order by xchan_name",
+ $r = q("select abook_id, xchan_hash, xchan_name, xchan_url, xchan_addr, xchan_photo_s from abook left join xchan on abook_xchan = xchan_hash where xchan_deleted = 0 and abook_channel = %d and abook_pending = 0 and abook_ignored = 0 and abook_blocked = 0 and abook_archived = 0 $sql_extra order by xchan_name",
intval($uid)
);
@@ -3467,6 +3477,28 @@ function print_val($v) {
}
+function array_path_exists($str,$arr) {
+
+ $ptr = $arr;
+ $search = explode('/', $str);
+
+ if($search) {
+ foreach($search as $s) {
+ if(array_key_exists($s,$ptr)) {
+ $ptr = $ptr[$s];
+ }
+ else {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ return false;
+
+}
+
+
/**
* @brief Generate a unique ID.
*
@@ -3482,3 +3514,4 @@ function new_uuid() {
return $hash;
}
+