Commit 17522737 authored by Mario's avatar Mario

appification of the gallery addon

parent 699554b6
......@@ -2,6 +2,9 @@
namespace Zotlabs\Module;
use App;
use Zotlabs\Lib\Apps;
class Gallery extends \Zotlabs\Web\Controller {
function init() {
......@@ -14,18 +17,18 @@ class Gallery extends \Zotlabs\Web\Controller {
$nick = argv(1);
profile_load($nick);
$channelx = channelx_by_nick($nick);
if(! $channelx)
return;
\App::$data['channel'] = $channelx;
App::$data['channel'] = $channelx;
$observer = \App::get_observer();
\App::$data['observer'] = $observer;
$observer = App::get_observer();
App::$data['observer'] = $observer;
\App::$page['htmlhead'] .= "<script> var profile_uid = " . ((\App::$data['channel']) ? \App::$data['channel']['channel_id'] : 0) . "; </script>" ;
App::$page['htmlhead'] .= "<script> var profile_uid = " . ((App::$data['channel']) ? App::$data['channel']['channel_id'] : 0) . "; </script>" ;
}
......@@ -34,12 +37,27 @@ class Gallery extends \Zotlabs\Web\Controller {
}
function post() {
$items = get_album_items($_POST);
$items = self::get_album_items($_POST);
json_return_and_die($items);
}
function get() {
if(! App::$profile) {
notice( t('Requested profile is not available.') . EOL );
App::$error = 404;
return;
}
if(! Apps::system_app_installed(App::$profile_uid, 'Gallery')) {
//Do not display any associated widgets at this point
App::$pdl = '';
$o = '<b>Gallery App (Not Installed):</b><br>';
$o .= t('A simple gallery for your photo albums');
return $o;
}
head_add_js('/addon/gallery/lib/photoswipe/dist/photoswipe.js');
head_add_js('/addon/gallery/lib/photoswipe/dist/photoswipe-ui-default.js');
......@@ -59,11 +77,11 @@ class Gallery extends \Zotlabs\Web\Controller {
$arr['album'] = $album_name;
$album_items = get_album_items($arr);
$album_items = self::get_album_items($arr);
$json_album = json_encode($album_items);
}
$owner_uid = \App::$data['channel']['channel_id'];
$owner_uid = App::$data['channel']['channel_id'];
$sql_extra = permissions_sql($owner_uid, get_observer_hash(), 'photo');
$unsafe = ((array_key_exists('unsafe', $_GET) && $_GET['unsafe']) ? 1 : 0);
......@@ -96,7 +114,7 @@ class Gallery extends \Zotlabs\Web\Controller {
$o = replace_macros($tpl, [
'$title' => t('Gallery'),
'$albums' => $items,
'$nick' => \App::$data['channel']['channel_address'],
'$nick' => App::$data['channel']['channel_address'],
'$unsafe' => $unsafe,
'$json_album' => $json_album
]);
......@@ -104,38 +122,38 @@ class Gallery extends \Zotlabs\Web\Controller {
return $o;
}
}
function get_album_items($arr) {
$owner_uid = App::$data['channel']['channel_id'];
function get_album_items($arr) {
$owner_uid = \App::$data['channel']['channel_id'];
$sql_extra = permissions_sql($owner_uid, get_observer_hash(), 'photo');
$unsafe = ((array_key_exists('unsafe', $arr) && $arr['unsafe']) ? 1 : 0);
$r = q("SELECT resource_id, width, height, description, display_path
FROM photo WHERE uid = %d AND album = '%s' AND photo_usage = %d
AND is_nsfw = %d AND imgscale = 1 $sql_extra
ORDER by created DESC",
intval($owner_uid),
dbesc($arr['album']),
intval(PHOTO_NORMAL),
intval($unsafe)
);
$i = 0;
foreach($r as $rr) {
$title = (($rr['description']) ? '<strong>' . $rr['description'] . '</strong><br>' . $rr['display_path'] : $rr['display_path']);
$items[$i]['resource_id'] = $rr['resource_id'];
$items[$i]['src'] = z_root() . '/photo/' . $rr['resource_id'] . '-1';
$items[$i]['msrc'] = z_root() . '/photo/' . $rr['resource_id'] . '-3';
$items[$i]['w'] = $rr['width'];
$items[$i]['h'] = $rr['height'];
$items[$i]['title'] = $title;
$i++;
}
$sql_extra = permissions_sql($owner_uid, get_observer_hash(), 'photo');
$unsafe = ((array_key_exists('unsafe', $arr) && $arr['unsafe']) ? 1 : 0);
return $items;
$r = q("SELECT resource_id, width, height, description, display_path
FROM photo WHERE uid = %d AND album = '%s' AND photo_usage = %d
AND is_nsfw = %d AND imgscale = 1 $sql_extra
ORDER by created DESC",
intval($owner_uid),
dbesc($arr['album']),
intval(PHOTO_NORMAL),
intval($unsafe)
);
$i = 0;
foreach($r as $rr) {
$title = (($rr['description']) ? '<strong>' . $rr['description'] . '</strong><br>' . $rr['display_path'] : $rr['display_path']);
$items[$i]['resource_id'] = $rr['resource_id'];
$items[$i]['src'] = z_root() . '/photo/' . $rr['resource_id'] . '-1';
$items[$i]['msrc'] = z_root() . '/photo/' . $rr['resource_id'] . '-3';
$items[$i]['w'] = $rr['width'];
$items[$i]['h'] = $rr['height'];
$items[$i]['title'] = $title;
$i++;
}
return $items;
}
}
......@@ -9,18 +9,22 @@
* Maintainer: Mario
*/
use App;
use Zotlabs\Lib\Apps;
use Zotlabs\Extend\Hook;
require_once('addon/gallery/Mod_Gallery.php');
function gallery_module() {}
function gallery_load() {
Zotlabs\Extend\Hook::register('load_pdl', 'addon/gallery/gallery.php', 'gallery_load_pdl');
Zotlabs\Extend\Hook::register('channel_apps', 'addon/gallery/gallery.php', 'gallery_channel_apps');
Hook::register('load_pdl', 'addon/gallery/gallery.php', 'gallery_load_pdl');
Hook::register('channel_apps', 'addon/gallery/gallery.php', 'gallery_channel_apps');
}
function gallery_unload() {
Zotlabs\Extend\Hook::unregister('load_pdl', 'addon/gallery/gallery.php', 'gallery_load_pdl');
Zotlabs\Extend\Hook::unregister('channel_apps', 'addon/gallery/gallery.php', 'gallery_channel_apps');
Hook::unregister('load_pdl', 'addon/gallery/gallery.php', 'gallery_load_pdl');
Hook::unregister('channel_apps', 'addon/gallery/gallery.php', 'gallery_channel_apps');
}
function gallery_load_pdl(&$b) {
......@@ -38,13 +42,15 @@ function gallery_load_pdl(&$b) {
}
function gallery_channel_apps(&$b) {
$b['tabs'][] = [
'label' => t('Gallery'),
'url' => z_root() . '/gallery/' . $b['nickname'],
'sel' => ((argv(0) == 'gallery') ? 'active' : ''),
'title' => t('Photo Gallery'),
'id' => 'gallery-tab',
'icon' => 'image'
];
if(Apps::system_app_installed(App::$profile_uid, 'Gallery')) {
$b['tabs'][] = [
'label' => t('Gallery'),
'url' => z_root() . '/gallery/' . $b['nickname'],
'sel' => ((argv(0) == 'gallery') ? 'active' : ''),
'title' => t('Photo Gallery'),
'id' => 'gallery-tab',
'icon' => 'image'
];
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment