aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2021-11-25 07:44:31 +0000
committerMario <mario@mariovavti.com>2021-11-25 07:44:31 +0000
commita6f65aa9c5a97d76b0c89d3251faf6df3372121c (patch)
treee64b4d0cf46e81efdcc315713afcb0e5e1fa0a97
parentae9a7727d67b7e9f234834e1729a99c97909e8a3 (diff)
downloadvolse-hubzilla-a6f65aa9c5a97d76b0c89d3251faf6df3372121c.tar.gz
volse-hubzilla-a6f65aa9c5a97d76b0c89d3251faf6df3372121c.tar.bz2
volse-hubzilla-a6f65aa9c5a97d76b0c89d3251faf6df3372121c.zip
add source option so that the right makros will be used in attach_store()
-rw-r--r--Zotlabs/Module/Profile_photo.php217
1 files changed, 107 insertions, 110 deletions
diff --git a/Zotlabs/Module/Profile_photo.php b/Zotlabs/Module/Profile_photo.php
index d6c80b653..6681cdcf9 100644
--- a/Zotlabs/Module/Profile_photo.php
+++ b/Zotlabs/Module/Profile_photo.php
@@ -23,79 +23,79 @@ require_once('include/channel.php');
class Profile_photo extends \Zotlabs\Web\Controller {
-
+
/* @brief Initalize the profile-photo edit view
*
* @return void
*
*/
-
+
function init() {
-
+
if(! local_channel()) {
return;
}
-
+
$channel = \App::get_channel();
profile_load($channel['channel_address']);
-
+
}
-
+
/* @brief Evaluate posted values
*
* @param $a Current application
* @return void
*
*/
-
+
function post() {
-
+
if(! local_channel()) {
return;
}
-
+
$channel = \App::get_channel();
-
+
check_form_security_token_redirectOnErr('/profile_photo', 'profile_photo');
-
+
// Remove cover photo
if(isset($_POST['remove'])) {
-
+
$r = q("SELECT resource_id FROM photo WHERE photo_usage = %d AND uid = %d LIMIT 1",
intval(PHOTO_PROFILE),
intval(local_channel())
);
-
+
if($r) {
q("update photo set photo_usage = %d where photo_usage = %d and uid = %d",
intval(PHOTO_NORMAL),
intval(PHOTO_PROFILE),
intval(local_channel())
);
-
+
$sync = attach_export_data($channel,$r[0]['resource_id']);
if($sync)
Libsync:: build_sync_packet($channel['channel_id'],array('file' => array($sync)));
}
-
+
$_SESSION['reload_avatar'] = true;
-
+
goaway(z_root() . '/profiles');
}
-
+
if((array_key_exists('cropfinal',$_POST)) && (intval($_POST['cropfinal']) == 1)) {
-
+
// logger('crop: ' . print_r($_POST,true));
// phase 2 - we have finished cropping
-
+
if(argc() != 2) {
notice( t('Image uploaded but image cropping failed.') . EOL );
return;
}
-
+
$image_id = argv(1);
-
+
if(substr($image_id,-2,1) == '-') {
$scale = substr($image_id,-1,1);
$image_id = substr($image_id,0,-2);
@@ -104,7 +104,7 @@ class Profile_photo extends \Zotlabs\Web\Controller {
// unless proven otherwise
$is_default_profile = 1;
-
+
if($_REQUEST['profile']) {
$r = q("select id, profile_guid, is_default, gender from profile where id = %d and uid = %d limit 1",
intval($_REQUEST['profile']),
@@ -115,9 +115,9 @@ class Profile_photo extends \Zotlabs\Web\Controller {
if(! intval($profile['is_default']))
$is_default_profile = 0;
}
- }
+ }
+
-
$srcX = intval($_POST['xstart']);
$srcY = intval($_POST['ystart']);
$srcW = intval($_POST['xfinal']) - $srcX;
@@ -128,36 +128,36 @@ class Profile_photo extends \Zotlabs\Web\Controller {
dbesc(local_channel()),
intval($scale));
if($r) {
-
+
$base_image = $r[0];
$base_image['content'] = (($r[0]['os_storage']) ? @file_get_contents(dbunescbin($base_image['content'])) : dbunescbin($base_image['content']));
-
+
$im = photo_factory($base_image['content'], $base_image['mimetype']);
if($im->is_valid()) {
-
+
$im->cropImage(300,$srcX,$srcY,$srcW,$srcH);
-
+
$aid = get_account_id();
-
- $p = [
- 'aid' => $aid,
- 'uid' => local_channel(),
+
+ $p = [
+ 'aid' => $aid,
+ 'uid' => local_channel(),
'resource_id' => $base_image['resource_id'],
- 'filename' => $base_image['filename'],
+ 'filename' => $base_image['filename'],
'album' => t('Profile Photos'),
'os_path' => $base_image['os_path'],
'display_path' => $base_image['display_path'],
'photo_usage' => PHOTO_PROFILE,
'edited' => dbescdate($base_image['edited'])
];
-
+
$p['photo_usage'] = (($is_default_profile) ? PHOTO_PROFILE : PHOTO_NORMAL);
-
+
$r1 = $im->storeThumbnail($p, PHOTO_RES_PROFILE_300);
-
+
$im->scaleImage(80);
$r2 = $im->storeThumbnail($p, PHOTO_RES_PROFILE_80);
-
+
$im->scaleImage(48);
$r3 = $im->storeThumbnail($p, PHOTO_RES_PROFILE_48);
@@ -184,12 +184,12 @@ class Profile_photo extends \Zotlabs\Web\Controller {
@unlink(dbunescbin($xx['content']));
}
}
-
+
return;
}
-
+
// If setting for the default profile, unset the profile photo flag from any other photos I own
-
+
if($is_default_profile) {
$r = q("update profile set photo = '%s', thumb = '%s' where is_default = 1 and uid = %d",
@@ -206,10 +206,10 @@ class Profile_photo extends \Zotlabs\Web\Controller {
dbesc($base_image['resource_id']),
intval(local_channel())
);
-
+
send_profile_photo_activity($channel,$base_image,$profile);
-
+
}
else {
$r = q("update profile set photo = '%s', thumb = '%s' where id = %d and uid = %d",
@@ -219,19 +219,19 @@ class Profile_photo extends \Zotlabs\Web\Controller {
intval(local_channel())
);
}
-
+
// set $send to false in profiles_build_sync() to return the data
- // so that we only send one sync packet.
+ // so that we only send one sync packet.
$sync_profiles = profiles_build_sync(local_channel(),false);
-
+
// We'll set the updated profile-photo timestamp even if it isn't the default profile,
// so that browsers will do a cache update unconditionally
// Also set links back to site-specific profile photo url in case it was
- // changed to a generic URL by a clone operation. Otherwise the new photo may
+ // changed to a generic URL by a clone operation. Otherwise the new photo may
// not get pushed to other sites correctly.
-
- $r = q("UPDATE xchan set xchan_photo_mimetype = '%s', xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s'
+
+ $r = q("UPDATE xchan set xchan_photo_mimetype = '%s', xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s'
where xchan_hash = '%s'",
dbesc($im->getType()),
dbescdate($base_image['edited']),
@@ -250,29 +250,29 @@ class Profile_photo extends \Zotlabs\Web\Controller {
// Similarly, tell the nav bar to bypass the cache and update the avatar image.
$_SESSION['reload_avatar'] = true;
-
+
info( t('Shift-reload the page or clear browser cache if the new photo does not display immediately.') . EOL);
-
+
// Update directory in background
\Zotlabs\Daemon\Master::Summon(array('Directory',$channel['channel_id']));
-
+
}
else
notice( t('Unable to process image') . EOL);
}
-
+
goaway(z_root() . '/profiles');
return; // NOTREACHED
}
-
+
// A new photo was uploaded. Store it and save some important details
// in App::$data for use in the cropping function
-
-
+
+
$hash = photo_new_resource();
$importing = false;
$smallest = 0;
-
+
if($_REQUEST['importfile']) {
$hash = $_REQUEST['importfile'];
@@ -280,24 +280,21 @@ class Profile_photo extends \Zotlabs\Web\Controller {
}
else {
require_once('include/attach.php');
-
- $res = attach_store(\App::get_channel(), get_observer_hash(), '', array('album' => t('Profile Photos'), 'hash' => $hash, 'nosync' => true));
-
- logger('attach_store: ' . print_r($res,true));
+ $res = attach_store(\App::get_channel(), get_observer_hash(), '', array('album' => t('Profile Photos'), 'hash' => $hash, 'nosync' => true, 'source' => 'photos'));
}
-
+
if(($res && intval($res['data']['is_photo'])) || $importing) {
$i = q("select * from photo where resource_id = '%s' and uid = %d order by imgscale",
dbesc($hash),
intval(local_channel())
);
-
+
if(! $i) {
notice( t('Image upload failed.') . EOL );
return;
}
$os_storage = false;
-
+
foreach($i as $ii) {
if(intval($ii['imgscale']) < PHOTO_RES_640) {
$smallest = intval($ii['imgscale']);
@@ -307,53 +304,53 @@ class Profile_photo extends \Zotlabs\Web\Controller {
}
}
}
-
+
$imagedata = (($os_storage) ? @file_get_contents(dbunescbin($imagedata)) : dbunescbin($imagedata));
$ph = photo_factory($imagedata, $filetype);
-
+
if(! $ph->is_valid()) {
notice( t('Unable to process image.') . EOL );
return;
}
-
+
return $this->profile_photo_crop_ui_head($a, $ph, $hash, $smallest);
// This will "fall through" to the get() method, and since
- // App::$data['imagecrop'] is set, it will proceed to cropping
- // rather than present the upload form
+ // App::$data['imagecrop'] is set, it will proceed to cropping
+ // rather than present the upload form
}
-
-
+
+
/* @brief Generate content of profile-photo view
*
* @param $a Current application
* @return void
*
*/
-
-
+
+
function get() {
-
+
if(! local_channel()) {
notice( t('Permission denied.') . EOL );
return;
}
-
+
$channel = \App::get_channel();
$pf = 0;
$newuser = false;
-
+
if(argc() == 2 && argv(1) === 'new')
$newuser = true;
-
+
if(argv(1) === 'use') {
if (argc() < 3) {
notice( t('Permission denied.') . EOL );
return;
};
-
+
$resource_id = argv(2);
-
+
$pf = (($_REQUEST['pf']) ? intval($_REQUEST['pf']) : 0);
@@ -384,9 +381,9 @@ class Profile_photo extends \Zotlabs\Web\Controller {
if($rr['imgscale'] == PHOTO_RES_PROFILE_80)
$havescale = true;
}
-
+
// set an already loaded and cropped photo as profile photo
-
+
if($havescale) {
// unset any existing profile photos
$x = q("UPDATE photo SET photo_usage = %d WHERE photo_usage = %d AND uid = %d",
@@ -396,19 +393,19 @@ class Profile_photo extends \Zotlabs\Web\Controller {
);
$edited = datetime_convert();
-
+
$x = q("UPDATE photo SET photo_usage = %d, edited = '%s' WHERE uid = %d AND resource_id = '%s' AND imgscale > 0",
intval(PHOTO_PROFILE),
dbescdate($edited),
intval(local_channel()),
dbesc($resource_id)
);
-
+
$x = q("UPDATE xchan SET xchan_photo_date = '%s' WHERE xchan_hash = '%s'",
dbescdate($edited),
dbesc($channel['xchan_hash'])
);
-
+
photo_profile_setperms(local_channel(),$resource_id,$_REQUEST['profile']);
$sync = attach_export_data($channel,$resource_id);
@@ -418,25 +415,25 @@ class Profile_photo extends \Zotlabs\Web\Controller {
$_SESSION['reload_avatar'] = true;
\Zotlabs\Daemon\Master::Summon(array('Directory',local_channel()));
-
+
goaway(z_root() . '/profiles');
}
-
+
$r = q("SELECT content, mimetype, resource_id, os_storage FROM photo WHERE id = %d and uid = %d limit 1",
intval($r[0]['id']),
intval(local_channel())
-
+
);
if(! $r) {
notice( t('Photo not available.') . EOL );
return;
}
-
+
if(intval($r[0]['os_storage']))
$data = @file_get_contents(dbunescbin($r[0]['content']));
else
- $data = dbunescbin($r[0]['content']);
-
+ $data = dbunescbin($r[0]['content']);
+
$ph = photo_factory($data, $r[0]['mimetype']);
$smallest = 0;
if($ph->is_valid()) {
@@ -445,7 +442,7 @@ class Profile_photo extends \Zotlabs\Web\Controller {
dbesc($r[0]['resource_id']),
intval(local_channel())
);
-
+
if($i) {
$hash = $i[0]['resource_id'];
foreach($i as $ii) {
@@ -455,7 +452,7 @@ class Profile_photo extends \Zotlabs\Web\Controller {
}
}
}
-
+
if($multi_profiles) {
\App::$data['importfile'] = $resource_id;
}
@@ -466,7 +463,7 @@ class Profile_photo extends \Zotlabs\Web\Controller {
// falls through with App::$data['imagecrop'] set so we go straight to the cropping section
}
-
+
// present an upload form
@@ -485,14 +482,14 @@ class Profile_photo extends \Zotlabs\Web\Controller {
}
$importing = ((array_key_exists('importfile',\App::$data)) ? true : false);
-
+
if(! x(\App::$data,'imagecrop')) {
-
+
$tpl = get_markup_template('profile_photo.tpl');
-
+
$o .= replace_macros($tpl,array(
'$user' => \App::$channel['channel_address'],
- '$info' => ((count($profiles) > 1) ? t('Your default profile photo is visible to anybody on the internet. Profile photos for alternate profiles will inherit the permissions of the profile') : t('Your profile photo is visible to anybody on the internet and may be distributed to other websites.')),
+ '$info' => ((count($profiles) > 1) ? t('Your default profile photo is visible to anybody on the internet. Profile photos for alternate profiles will inherit the permissions of the profile') : t('Your profile photo is visible to anybody on the internet and may be distributed to other websites.')),
'$importfile' => (($importing) ? \App::$data['importfile'] : ''),
'$lbl_upfile' => t('Upload File:'),
'$lbl_profiles' => t('Select a profile:'),
@@ -515,9 +512,9 @@ class Profile_photo extends \Zotlabs\Web\Controller {
'$form_security_token' => get_form_security_token("profile_photo"),
'$select' => t('Select existing photo'),
));
-
+
call_hooks('profile_photo_content_end', $o);
-
+
return $o;
}
else {
@@ -539,10 +536,10 @@ class Profile_photo extends \Zotlabs\Web\Controller {
));
return $o;
}
-
+
return; // NOTREACHED
}
-
+
/* @brief Generate the UI for photo-cropping
*
* @param $a Current application
@@ -550,32 +547,32 @@ class Profile_photo extends \Zotlabs\Web\Controller {
* @return void
*
*/
-
-
-
+
+
+
function profile_photo_crop_ui_head(&$a, $ph, $hash, $smallest){
-
+
$max_length = get_config('system','max_image_length');
if(! $max_length)
$max_length = MAX_IMAGE_LENGTH;
if($max_length > 0)
$ph->scaleImage($max_length);
-
+
\App::$data['width'] = $ph->getWidth();
\App::$data['height'] = $ph->getHeight();
-
+
if(\App::$data['width'] < 500 || \App::$data['height'] < 500) {
$ph->scaleImageUp(400);
\App::$data['width'] = $ph->getWidth();
\App::$data['height'] = $ph->getHeight();
}
-
-
+
+
\App::$data['imagecrop'] = $hash;
\App::$data['imagecrop_resolution'] = $smallest;
\App::$page['htmlhead'] .= replace_macros(get_markup_template("crophead.tpl"), array());
return;
}
-
-
+
+
}