mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-19 21:35:13 +00:00
cover photo fetch and widget
This commit is contained in:
parent
be9442e7b3
commit
64753effd1
3 changed files with 82 additions and 0 deletions
15
boot.php
15
boot.php
|
@ -245,6 +245,21 @@ define ( 'PHOTO_COVER', 0x0010 );
|
|||
define ( 'PHOTO_ADULT', 0x0008 );
|
||||
define ( 'PHOTO_FLAG_OS', 0x4000 );
|
||||
|
||||
|
||||
define ( 'PHOTO_RES_ORIG', 0 );
|
||||
define ( 'PHOTO_RES_1024', 1 ); // rectangular 1024 max width or height, floating height if not (4:3)
|
||||
define ( 'PHOTO_RES_640', 2 ); // to accomodate SMBC vertical comic strips without scrunching the width
|
||||
define ( 'PHOTO_RES_320', 3 ); // accordingly
|
||||
|
||||
define ( 'PHOTO_RES_PROFILE_300', 4 ); // square 300 px
|
||||
define ( 'PHOTO_RES_PROFILE_80', 5 ); // square 80 px
|
||||
define ( 'PHOTO_RES_PROFILE_48', 6 ); // square 48 px
|
||||
|
||||
define ( 'PHOTO_RES_COVER_1200', 7 ); // 1200w x 435h (2.75:1)
|
||||
define ( 'PHOTO_RES_COVER_850', 8 ); // 850w x 310h
|
||||
define ( 'PHOTO_RES_COVER_425', 9 ); // 425w x 160h
|
||||
|
||||
|
||||
/**
|
||||
* Menu types
|
||||
*/
|
||||
|
|
|
@ -1737,3 +1737,38 @@ function auto_channel_create($account_id) {
|
|||
|
||||
}
|
||||
|
||||
function get_cover_photo($channel_id,$format = 'bbcode', $res = PHOTO_RES_COVER_1200) {
|
||||
|
||||
$r = q("select height, width, resource_id, type from photo where uid = %d and scale = %d and photo_usage = %d",
|
||||
intval($channel_id),
|
||||
intval($res),
|
||||
intval(PHOTO_COVER)
|
||||
);
|
||||
if(! $r)
|
||||
return false;
|
||||
|
||||
$output = false;
|
||||
|
||||
$url = z_root() . '/photo/' . $r[0]['resource_id'] . '-' . $res ;
|
||||
|
||||
switch($format) {
|
||||
case 'bbcode':
|
||||
$output = '[zrl=' . $r[0]['width'] . 'x' . $r[0]['height'] . ']' . $url . '[/zrl]';
|
||||
break;
|
||||
case 'html':
|
||||
$output = '<img class="zrl" width="' . $r[0]['width'] . '" height="' . $r[0]['height'] . '" src="' . $url . '" alt="' . t('cover photo') . '" />';
|
||||
break;
|
||||
case 'array':
|
||||
default:
|
||||
$output = array(
|
||||
'width' => $r[0]['width'],
|
||||
'height' => $r[0]['type'],
|
||||
'type' => $r[0]['type'],
|
||||
'url' => $url
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
|
@ -936,6 +936,38 @@ function widget_photo($arr) {
|
|||
}
|
||||
|
||||
|
||||
function widget_cover_photo($arr) {
|
||||
|
||||
require_once('include/identity.php');
|
||||
$o = '';
|
||||
|
||||
$channel_id = 0;
|
||||
if(array_key_exists('channel_id', $arr) && intval($arr['channel_id']))
|
||||
$channel_id = intval($arr['channel_id']);
|
||||
if(! $channel_id)
|
||||
$channel_id = get_app()->profile_uid;
|
||||
if(! $channel_id)
|
||||
return '';
|
||||
|
||||
if(array_key_exists('style', $arr) && isset($arr['style']))
|
||||
$style = $arr['style'];
|
||||
else
|
||||
$style = 'width:100%; padding-right: 10px; height: auto;';
|
||||
|
||||
// ensure they can't sneak in an eval(js) function
|
||||
|
||||
if(strpos($style,'(') !== false)
|
||||
return '';
|
||||
|
||||
$c = get_cover_photo($channel_id,'html');
|
||||
|
||||
if($c) {
|
||||
$o = '<div class="widget">' . (($style) ? str_replace('alt=',' style="' . $style . '" alt=',$c) : $c) . '</div>';
|
||||
}
|
||||
return $o;
|
||||
}
|
||||
|
||||
|
||||
function widget_photo_rand($arr) {
|
||||
|
||||
require_once('include/photos.php');
|
||||
|
|
Loading…
Reference in a new issue