Exemple #1
0
 function profile_photo_content(&$a)
 {
     if (!local_user()) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     $newuser = false;
     if ($a->argc == 2 && $a->argv[1] === 'new') {
         $newuser = true;
     }
     if ($a->argv[1] == 'use') {
         if ($a->argc < 3) {
             notice(t('Permission denied.') . EOL);
             return;
         }
         //		check_form_security_token_redirectOnErr('/profile_photo', 'profile_photo');
         $resource_id = $a->argv[2];
         //die(":".local_user());
         $r = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' ORDER BY `scale` ASC", intval(local_user()), dbesc($resource_id));
         if (!count($r)) {
             notice(t('Permission denied.') . EOL);
             return;
         }
         $havescale = false;
         foreach ($r as $rr) {
             if ($rr['scale'] == 5) {
                 $havescale = true;
             }
         }
         // set an already uloaded photo as profile photo
         // if photo is in 'Profile Photos', change it in db
         if ($r[0]['album'] == t('Profile Photos') && $havescale) {
             $r = q("UPDATE `photo` SET `profile`=0 WHERE `profile`=1 AND `uid`=%d", intval(local_user()));
             $r = q("UPDATE `photo` SET `profile`=1 WHERE `uid` = %d AND `resource-id` = '%s'", intval(local_user()), dbesc($resource_id));
             $r = q("UPDATE `contact` SET `avatar-date` = '%s' WHERE `self` = 1 AND `uid` = %d", dbesc(datetime_convert()), intval(local_user()));
             // Update global directory in background
             $url = $_SESSION['my_url'];
             if ($url && strlen(get_config('system', 'directory'))) {
                 proc_run('php', "include/directory.php", "{$url}");
             }
             goaway($a->get_baseurl() . '/profiles');
             return;
             // NOTREACHED
         }
         $ph = new Photo($r[0]['data'], $r[0]['type']);
         profile_photo_crop_ui_head($a, $ph);
         // go ahead as we have jus uploaded a new photo to crop
     }
     $profiles = q("select `id`,`profile-name` as `name`,`is-default` as `default` from profile where uid = %d", intval(local_user()));
     if (!x($a->config, 'imagecrop')) {
         $tpl = get_markup_template('profile_photo.tpl');
         $o .= replace_macros($tpl, array('$user' => $a->user['nickname'], '$lbl_upfile' => t('Upload File:'), '$lbl_profiles' => t('Select a profile:'), '$title' => t('Upload Profile Photo'), '$submit' => t('Upload'), '$profiles' => $profiles, '$form_security_token' => get_form_security_token("profile_photo"), '$select' => sprintf('%s %s', t('or'), $newuser ? '<a href="' . $a->get_baseurl() . '">' . t('skip this step') . '</a>' : '<a href="' . $a->get_baseurl() . '/photos/' . $a->user['nickname'] . '">' . t('select a photo from your photo albums') . '</a>')));
         return $o;
     } else {
         $filename = $a->config['imagecrop'] . '-' . $a->config['imagecrop_resolution'] . '.' . $a->config['imagecrop_ext'];
         $resolution = $a->config['imagecrop_resolution'];
         $tpl = get_markup_template("cropbody.tpl");
         $o .= replace_macros($tpl, array('$filename' => $filename, '$profile' => intval($_REQUEST['profile']), '$resource' => $a->config['imagecrop'] . '-' . $a->config['imagecrop_resolution'], '$image_url' => $a->get_baseurl() . '/photo/' . $filename, '$title' => t('Crop Image'), '$desc' => t('Please adjust the image cropping for optimum viewing.'), '$form_security_token' => get_form_security_token("profile_photo"), '$done' => t('Done Editing')));
         return $o;
     }
     return;
     // NOTREACHED
 }
function profile_photo_content(&$a)
{
    if (!local_channel()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    $channel = App::get_channel();
    $newuser = false;
    if (argc() == 2 && argv(1) === 'new') {
        $newuser = true;
    }
    if (argv(1) === 'use') {
        if (argc() < 3) {
            notice(t('Permission denied.') . EOL);
            return;
        }
        //		check_form_security_token_redirectOnErr('/profile_photo', 'profile_photo');
        $resource_id = argv(2);
        $r = q("SELECT id, album, scale FROM photo WHERE uid = %d AND resource_id = '%s' ORDER BY scale ASC", intval(local_channel()), dbesc($resource_id));
        if (!$r) {
            notice(t('Photo not available.') . EOL);
            return;
        }
        $havescale = false;
        foreach ($r as $rr) {
            if ($rr['scale'] == 5) {
                $havescale = true;
            }
        }
        // set an already loaded photo as profile photo
        if ($r[0]['album'] == t('Profile Photos') && $havescale) {
            // unset any existing profile photos
            $r = q("UPDATE photo SET photo_usage = %d WHERE photo_usage = %d AND uid = %d", intval(PHOTO_NORMAL), intval(PHOTO_PROFILE), intval(local_channel()));
            $r = q("UPDATE photo SET photo_usage = %d WHERE uid = %d AND resource_id = '%s'", intval(PHOTO_PROFILE), intval(local_channel()), dbesc($resource_id));
            $r = q("UPDATE xchan set xchan_photo_date = '%s' \n\t\t\t\twhere xchan_hash = '%s'", dbesc(datetime_convert()), dbesc($channel['xchan_hash']));
            profile_photo_set_profile_perms();
            //Reset default photo permissions to public
            proc_run('php', 'include/directory.php', local_channel());
            goaway(z_root() . '/profiles');
        }
        $r = q("SELECT `data`, `type`, 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($r[0]['data']);
        } else {
            $data = dbunescbin($r[0]['data']);
        }
        $ph = photo_factory($data, $r[0]['type']);
        $smallest = 0;
        if ($ph->is_valid()) {
            // go ahead as if we have just uploaded a new photo to crop
            $i = q("select resource_id, scale from photo where resource_id = '%s' and uid = %d order by scale", dbesc($r[0]['resource_id']), intval(local_channel()));
            if ($i) {
                $hash = $i[0]['resource_id'];
                foreach ($i as $ii) {
                    if (intval($ii['scale']) < 2) {
                        $smallest = intval($ii['scale']);
                    }
                }
            }
        }
        profile_photo_crop_ui_head($a, $ph, $hash, $smallest);
    }
    $profiles = q("select id, profile_name as name, is_default from profile where uid = %d", intval(local_channel()));
    if (!x(App::$data, 'imagecrop')) {
        $tpl = get_markup_template('profile_photo.tpl');
        $o .= replace_macros($tpl, array('$user' => App::$channel['channel_address'], '$lbl_upfile' => t('Upload File:'), '$lbl_profiles' => t('Select a profile:'), '$title' => t('Upload Profile Photo'), '$submit' => t('Upload'), '$profiles' => $profiles, '$single' => count($profiles) == 1 ? true : false, '$profile0' => $profiles[0], '$form_security_token' => get_form_security_token("profile_photo"), '$select' => sprintf('%s %s', t('or'), $newuser ? '<a href="' . z_root() . '">' . t('skip this step') . '</a>' : '<a href="' . z_root() . '/photos/' . App::$channel['channel_address'] . '">' . t('select a photo from your photo albums') . '</a>')));
        call_hooks('profile_photo_content_end', $o);
        return $o;
    } else {
        $filename = App::$data['imagecrop'] . '-' . App::$data['imagecrop_resolution'];
        $resolution = App::$data['imagecrop_resolution'];
        $tpl = get_markup_template("cropbody.tpl");
        $o .= replace_macros($tpl, array('$filename' => $filename, '$profile' => intval($_REQUEST['profile']), '$resource' => App::$data['imagecrop'] . '-' . App::$data['imagecrop_resolution'], '$image_url' => z_root() . '/photo/' . $filename, '$title' => t('Crop Image'), '$desc' => t('Please adjust the image cropping for optimum viewing.'), '$form_security_token' => get_form_security_token("profile_photo"), '$done' => t('Done Editing')));
        return $o;
    }
    return;
    // NOTREACHED
}
Exemple #3
0
 function profile_photo_content(&$a)
 {
     if (!local_user()) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     $channel = $a->get_channel();
     $newuser = false;
     if (argc() == 2 && argv(1) === 'new') {
         $newuser = true;
     }
     if (argv(1) === 'use') {
         if (argc() < 3) {
             notice(t('Permission denied.') . EOL);
             return;
         }
         //		check_form_security_token_redirectOnErr('/profile_photo', 'profile_photo');
         $resource_id = argv(2);
         $r = q("SELECT id, album, scale FROM photo WHERE uid = %d AND resource_id = '%s' ORDER BY scale ASC", intval(local_user()), dbesc($resource_id));
         if (!$r) {
             notice(t('Photo not available.') . EOL);
             return;
         }
         $havescale = false;
         foreach ($r as $rr) {
             if ($rr['scale'] == 5) {
                 $havescale = true;
             }
         }
         // set an already loaded photo as profile photo
         if ($r[0]['album'] == t('Profile Photos') && $havescale) {
             // unset any existing profile photos
             $r = q("UPDATE photo SET profile = 0 WHERE profile = 1 AND uid = %d", intval(local_user()));
             $r = q("UPDATE photo SET photo_flags = (photo_flags ^ %d ) WHERE (photo_flags & %d ) AND uid = %d", intval(PHOTO_PROFILE), intval(PHOTO_PROFILE), intval(local_user()));
             // set all sizes of this one as profile photos
             $r = q("UPDATE photo SET profile = 1 WHERE uid = %d AND resource_id = '%s'", intval(local_user()), dbesc($resource_id));
             $r = q("UPDATE photo SET photo_flags = ( photo_flags | %d ) WHERE uid = %d AND resource_id = '%s'", intval(PHOTO_PROFILE), intval(local_user()), dbesc($resource_id));
             $r = q("UPDATE xchan set xchan_photo_date = '%s' \n\t\t\t\twhere xchan_hash = '%s' limit 1", dbesc(datetime_convert()), dbesc($channel['xchan_hash']));
             profile_photo_set_profile_perms();
             //Reset default photo permissions to public
             proc_run('php', 'include/directory.php', local_user());
             goaway($a->get_baseurl() . '/profiles');
         }
         $r = q("SELECT `data`, `type` FROM photo WHERE id = %d and uid = %d limit 1", intval($r[0]['id']), intval(local_user()));
         if (!$r) {
             notice(t('Photo not available.') . EOL);
             return;
         }
         $ph = photo_factory($r[0]['data'], $r[0]['type']);
         // go ahead as if we have just uploaded a new photo to crop
         profile_photo_crop_ui_head($a, $ph);
     }
     $profiles = q("select id, profile_name as name, is_default from profile where uid = %d", intval(local_user()));
     if (!x($a->data, 'imagecrop')) {
         $tpl = get_markup_template('profile_photo.tpl');
         $o .= replace_macros($tpl, array('$user' => $a->channel['channel_address'], '$lbl_upfile' => t('Upload File:'), '$lbl_profiles' => t('Select a profile:'), '$title' => t('Upload Profile Photo'), '$submit' => t('Upload'), '$profiles' => $profiles, '$form_security_token' => get_form_security_token("profile_photo"), '$select' => sprintf('%s %s', t('or'), $newuser ? '<a href="' . $a->get_baseurl() . '">' . t('skip this step') . '</a>' : '<a href="' . $a->get_baseurl() . '/photos/' . $a->channel['channel_address'] . '">' . t('select a photo from your photo albums') . '</a>')));
         return $o;
     } else {
         $filename = $a->data['imagecrop'] . '-' . $a->data['imagecrop_resolution'] . '.' . $a->data['imagecrop_ext'];
         $resolution = $a->data['imagecrop_resolution'];
         $tpl = get_markup_template("cropbody.tpl");
         $o .= replace_macros($tpl, array('$filename' => $filename, '$profile' => intval($_REQUEST['profile']), '$resource' => $a->data['imagecrop'] . '-' . $a->data['imagecrop_resolution'], '$image_url' => $a->get_baseurl() . '/photo/' . $filename, '$title' => t('Crop Image'), '$desc' => t('Please adjust the image cropping for optimum viewing.'), '$form_security_token' => get_form_security_token("profile_photo"), '$done' => t('Done Editing')));
         return $o;
     }
     return;
     // NOTREACHED
 }