当前位置: 首页>>代码示例>>PHP>>正文


PHP dbunescbin函数代码示例

本文整理汇总了PHP中dbunescbin函数的典型用法代码示例。如果您正苦于以下问题:PHP dbunescbin函数的具体用法?PHP dbunescbin怎么用?PHP dbunescbin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了dbunescbin函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: post

 function post()
 {
     $hash = $_POST['hash'];
     $time = $_POST['time'];
     $sig = $_POST['signature'];
     $resource = $_POST['resource'];
     $revision = intval($_POST['revision']);
     if (!$hash) {
         killme();
     }
     $channel = channelx_by_hash($hash);
     if (!$channel || !$time || !$sig) {
         killme();
     }
     $slop = intval(get_pconfig($channel['channel_id'], 'system', 'getfile_time_slop'));
     if ($slop < 1) {
         $slop = 3;
     }
     $d1 = datetime_convert('UTC', 'UTC', "now + {$slop} minutes");
     $d2 = datetime_convert('UTC', 'UTC', "now - {$slop} minutes");
     if ($time > $d1 || $time < $d2) {
         logger('time outside allowable range');
         killme();
     }
     if (!rsa_verify($hash . '.' . $time, base64url_decode($sig), $channel['channel_pubkey'])) {
         logger('verify failed.');
         killme();
     }
     $r = attach_by_hash($resource, $revision);
     if (!$r['success']) {
         notice($r['message'] . EOL);
         return;
     }
     $unsafe_types = array('text/html', 'text/css', 'application/javascript');
     if (in_array($r['data']['filetype'], $unsafe_types)) {
         header('Content-type: text/plain');
     } else {
         header('Content-type: ' . $r['data']['filetype']);
     }
     header('Content-disposition: attachment; filename="' . $r['data']['filename'] . '"');
     if (intval($r['data']['os_storage'])) {
         $fname = dbunescbin($r['data']['data']);
         if (strpos($fname, 'store') !== false) {
             $istream = fopen($fname, 'rb');
         } else {
             $istream = fopen('store/' . $channel['channel_address'] . '/' . $fname, 'rb');
         }
         $ostream = fopen('php://output', 'wb');
         if ($istream && $ostream) {
             pipe_streams($istream, $ostream);
             fclose($istream);
             fclose($ostream);
         }
     } else {
         echo dbunescbin($r['data']['data']);
     }
     killme();
 }
开发者ID:anmol26s,项目名称:hubzilla-yunohost,代码行数:58,代码来源:Getfile.php

示例2: attach_init

function attach_init(&$a)
{
    if (argc() < 2) {
        notice(t('Item not available.') . EOL);
        return;
    }
    $r = attach_by_hash(argv(1), argc() > 2 ? intval(argv(2)) : 0);
    if (!$r['success']) {
        notice($r['message'] . EOL);
        return;
    }
    $c = q("select channel_address from channel where channel_id = %d limit 1", intval($r['data']['uid']));
    if (!$c) {
        return;
    }
    $unsafe_types = array('text/html', 'text/css', 'application/javascript');
    if (in_array($r['data']['filetype'], $unsafe_types)) {
        header('Content-type: text/plain');
    } else {
        header('Content-type: ' . $r['data']['filetype']);
    }
    header('Content-disposition: attachment; filename="' . $r['data']['filename'] . '"');
    if (intval($r['data']['os_storage'])) {
        $fname = dbunescbin($r['data']['data']);
        if (strpos($fname, 'store') !== false) {
            $istream = fopen($fname, 'rb');
        } else {
            $istream = fopen('store/' . $c[0]['channel_address'] . '/' . $fname, 'rb');
        }
        $ostream = fopen('php://output', 'wb');
        if ($istream && $ostream) {
            pipe_streams($istream, $ostream);
            fclose($istream);
            fclose($ostream);
        }
    } else {
        echo dbunescbin($r['data']['data']);
    }
    killme();
}
开发者ID:msooon,项目名称:hubzilla,代码行数:40,代码来源:attach.php

示例3: api_photo_detail

function api_photo_detail(&$a, $type)
{
    if (api_user() === false) {
        return false;
    }
    if (!$_REQUEST['photo_id']) {
        return false;
    }
    $scale = array_key_exists('scale', $_REQUEST) ? intval($_REQUEST['scale']) : 0;
    $r = q("select * from photo where uid = %d and resource_id = '%s' and scale = %d limit 1", intval(local_channel()), dbesc($_REQUEST['photo_id']), intval($scale));
    if ($r) {
        $data = dbunescbin($r[0]['data']);
        if (array_key_exists('os_storage', $r[0]) && intval($r[0]['os_storage'])) {
            $data = file_get_contents($data);
        }
        $r[0]['data'] = base64_encode($data);
        $ret = array('photo' => $r[0]);
        $i = q("select id from item where uid = %d and resource_type = 'photo' and resource_id = '%s' limit 1", intval(local_channel()), dbesc($_REQUEST['photo_id']));
        if ($i) {
            $ii = q("select * from item where parent = %d order by id", intval($i[0]['id']));
            if ($ii) {
                xchan_query($ii, true, 0);
                $ii = fetch_post_tags($ii, true);
                if ($ii) {
                    $ret['item'] = array();
                    foreach ($ii as $iii) {
                        $ret['item'][] = encode_item($iii, true);
                    }
                }
            }
        }
        json_return_and_die($ret);
    }
    killme();
}
开发者ID:msooon,项目名称:hubzilla,代码行数:35,代码来源:api.php

示例4: profile_photo_content

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
}
开发者ID:anmol26s,项目名称:hubzilla-yunohost,代码行数:82,代码来源:profile_photo.php

示例5: profile_photo_post

function profile_photo_post(&$a)
{
    if (!local_channel()) {
        return;
    }
    check_form_security_token_redirectOnErr('/profile_photo', 'profile_photo');
    if (x($_POST, 'cropfinal') && $_POST['cropfinal'] == 1) {
        // unless proven otherwise
        $is_default_profile = 1;
        if ($_REQUEST['profile']) {
            $r = q("select id, is_default from profile where id = %d and uid = %d limit 1", intval($_REQUEST['profile']), intval(local_channel()));
            if ($r && !intval($r[0]['is_default'])) {
                $is_default_profile = 0;
            }
        }
        // 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);
        }
        $srcX = $_POST['xstart'];
        $srcY = $_POST['ystart'];
        $srcW = $_POST['xfinal'] - $srcX;
        $srcH = $_POST['yfinal'] - $srcY;
        $r = q("SELECT * FROM photo WHERE resource_id = '%s' AND uid = %d AND scale = %d LIMIT 1", dbesc($image_id), dbesc(local_channel()), intval($scale));
        if ($r) {
            $base_image = $r[0];
            $base_image['data'] = dbunescbin($base_image['data']);
            $im = photo_factory($base_image['data'], $base_image['type']);
            if ($im->is_valid()) {
                $im->cropImage(175, $srcX, $srcY, $srcW, $srcH);
                $aid = get_account_id();
                $p = array('aid' => $aid, 'uid' => local_channel(), 'resource_id' => $base_image['resource_id'], 'filename' => $base_image['filename'], 'album' => t('Profile Photos'));
                $p['scale'] = 4;
                $p['photo_flags'] = $is_default_profile ? PHOTO_PROFILE : PHOTO_NORMAL;
                $r1 = $im->save($p);
                $im->scaleImage(80);
                $p['scale'] = 5;
                $r2 = $im->save($p);
                $im->scaleImage(48);
                $p['scale'] = 6;
                $r3 = $im->save($p);
                if ($r1 === false || $r2 === false || $r3 === false) {
                    // if one failed, delete them all so we can start over.
                    notice(t('Image resize failed.') . EOL);
                    $x = q("delete from photo where resource_id = '%s' and uid = %d and scale >= 4 ", dbesc($base_image['resource_id']), local_channel());
                    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 photo SET profile = 0 WHERE profile = 1 AND resource_id != '%s' AND `uid` = %d", dbesc($base_image['resource_id']), intval(local_channel()));
                    $r = q("UPDATE photo SET photo_flags = ( photo_flags & ~%d ) WHERE ( photo_flags & %d )>0 \n\t\t\t\t\t\tAND resource_id != '%s' AND `uid` = %d", intval(PHOTO_PROFILE), intval(PHOTO_PROFILE), dbesc($base_image['resource_id']), intval(local_channel()));
                } else {
                    $r = q("update profile set photo = '%s', thumb = '%s' where id = %d and uid = %d", dbesc($a->get_baseurl() . '/photo/' . $base_image['resource_id'] . '-4'), dbesc($a->get_baseurl() . '/photo/' . $base_image['resource_id'] . '-5'), intval($_REQUEST['profile']), intval(local_channel()));
                }
                // 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
                $channel = $a->get_channel();
                $r = q("UPDATE xchan set xchan_photo_mimetype = '%s', xchan_photo_date = '%s' \n\t\t\t\t\twhere xchan_hash = '%s'", dbesc($im->getType()), dbesc(datetime_convert()), dbesc($channel['xchan_hash']));
                info(t('Shift-reload the page or clear browser cache if the new photo does not display immediately.') . EOL);
                // Update directory in background
                proc_run('php', "include/directory.php", $channel['channel_id']);
                // Now copy profile-permissions to pictures, to prevent privacyleaks by automatically created folder 'Profile Pictures'
                profile_photo_set_profile_perms($_REQUEST['profile']);
            } else {
                notice(t('Unable to process image') . EOL);
            }
        }
        goaway($a->get_baseurl() . '/profiles');
        return;
        // NOTREACHED
    }
    $src = $_FILES['userfile']['tmp_name'];
    $filename = basename($_FILES['userfile']['name']);
    $filesize = intval($_FILES['userfile']['size']);
    $filetype = $_FILES['userfile']['type'];
    if ($filetype == "") {
        $filetype = guess_image_type($filename);
    }
    $maximagesize = get_config('system', 'maximagesize');
    if ($maximagesize && $filesize > $maximagesize) {
        notice(sprintf(t('Image exceeds size limit of %d'), $maximagesize) . EOL);
        @unlink($src);
        return;
    }
    $imagedata = @file_get_contents($src);
    $ph = photo_factory($imagedata, $filetype);
    if (!$ph->is_valid()) {
        notice(t('Unable to process image.') . EOL);
        @unlink($src);
        return;
    }
    $ph->orient($src);
    @unlink($src);
    return profile_photo_crop_ui_head($a, $ph);
//.........这里部分代码省略.........
开发者ID:redmatrix,项目名称:red,代码行数:101,代码来源:profile_photo.php

示例6: update_r1159

function update_r1159()
{
    $r = q("select attach.id, attach.data, attach.hash, channel_address from attach left join channel on attach.uid = channel_id where os_storage = 1 ");
    if ($r) {
        foreach ($r as $rr) {
            $x = dbunescbin($rr['data']);
            $has_slash = $x === 'store/' . $rr['channel_address'] . '/' ? true : false;
            if ($x === 'store/' . $rr['channel_address'] || $has_slash) {
                q("update attach set data = '%s' where id = %d", dbesc('store/' . $rr['channel_address'] . ($has_slash ? '' : '/' . $rr['hash'])), dbesc($rr['id']));
            }
        }
    }
    return UPDATE_SUCCESS;
}
开发者ID:BlaBlaNet,项目名称:hubzilla,代码行数:14,代码来源:update.php

示例7: photos_post


//.........这里部分代码省略.........
            				dbesc($r[0]['resource_id'])
            			);
            			*/
            attach_delete($page_owner_uid, $r[0]['resource_id'], 1);
            /* this happens in attach_delete
            			$i = q("SELECT * FROM `item` WHERE `resource_id` = '%s' AND resource_type = 'photo' and `uid` = %d LIMIT 1",
            				dbesc($r[0]['resource_id']),
            				intval($page_owner_uid)
            			);
            			if(count($i)) {
            				drop_item($i[0]['id'],true,DROPITEM_PHASE1);
            				$url = $a->get_baseurl();
            			}
            			*/
        }
        goaway($a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/album/' . $_SESSION['album_return']);
    }
    if ($a->argc > 2 && (x($_POST, 'desc') !== false || x($_POST, 'newtag') !== false) || x($_POST, 'albname') !== false) {
        $desc = x($_POST, 'desc') ? notags(trim($_POST['desc'])) : '';
        $rawtags = x($_POST, 'newtag') ? notags(trim($_POST['newtag'])) : '';
        $item_id = x($_POST, 'item_id') ? intval($_POST['item_id']) : 0;
        $albname = x($_POST, 'albname') ? notags(trim($_POST['albname'])) : '';
        $is_nsfw = x($_POST, 'adult') ? intval($_POST['adult']) : 0;
        $acl->set_from_array($_POST);
        $perm = $acl->get();
        $resource_id = $a->argv[2];
        if (!strlen($albname)) {
            $albname = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y');
        }
        if (x($_POST, 'rotate') !== false && (intval($_POST['rotate']) == 1 || intval($_POST['rotate']) == 2)) {
            logger('rotate');
            $r = q("select * from photo where `resource_id` = '%s' and uid = %d and scale = 0 limit 1", dbesc($resource_id), intval($page_owner_uid));
            if (count($r)) {
                $d = $r[0]['os_storage'] ? @file_get_contents($r[0]['data']) : dbunescbin($r[0]['data']);
                $ph = photo_factory($d, $r[0]['type']);
                if ($ph->is_valid()) {
                    $rotate_deg = intval($_POST['rotate']) == 1 ? 270 : 90;
                    $ph->rotate($rotate_deg);
                    $width = $ph->getWidth();
                    $height = $ph->getHeight();
                    if (intval($r[0]['os_storage'])) {
                        @file_put_contents($r[0]['data'], $ph->imageString());
                        $data = $r[0]['data'];
                        $fsize = @filesize($r[0]['data']);
                        q("update attach set filesize = %d where hash = '%s' and uid = %d limit 1", intval($fsize), dbesc($resource_id), intval($page_owner_uid));
                    } else {
                        $data = $ph->imageString();
                        $fsize = strlen($data);
                    }
                    $x = q("update photo set data = '%s', `size` = %d, height = %d, width = %d where `resource_id` = '%s' and uid = %d and scale = 0", dbescbin($data), intval($fsize), intval($height), intval($width), dbesc($resource_id), intval($page_owner_uid));
                    if ($width > 1024 || $height > 1024) {
                        $ph->scaleImage(1024);
                    }
                    $width = $ph->getWidth();
                    $height = $ph->getHeight();
                    $x = q("update photo set data = '%s', height = %d, width = %d where `resource_id` = '%s' and uid = %d and scale = 1", dbescbin($ph->imageString()), intval($height), intval($width), dbesc($resource_id), intval($page_owner_uid));
                    if ($width > 640 || $height > 640) {
                        $ph->scaleImage(640);
                    }
                    $width = $ph->getWidth();
                    $height = $ph->getHeight();
                    $x = q("update photo set data = '%s', height = %d, width = %d where `resource_id` = '%s' and uid = %d and scale = 2", dbescbin($ph->imageString()), intval($height), intval($width), dbesc($resource_id), intval($page_owner_uid));
                    if ($width > 320 || $height > 320) {
                        $ph->scaleImage(320);
                    }
                    $width = $ph->getWidth();
开发者ID:spthaolt,项目名称:hubzilla,代码行数:67,代码来源:photos.php

示例8: get

 /**
  * @brief Returns the raw data.
  *
  * @return string
  */
 public function get()
 {
     logger('get file ' . basename($this->name), LOGGER_DEBUG);
     logger('os_path: ' . $this->os_path, LOGGER_DATA);
     $r = q("SELECT data, flags, os_storage, filename, filetype FROM attach WHERE hash = '%s' AND uid = %d LIMIT 1", dbesc($this->data['hash']), intval($this->data['uid']));
     if ($r) {
         // @todo this should be a global definition
         $unsafe_types = array('text/html', 'text/css', 'application/javascript');
         if (in_array($r[0]['filetype'], $unsafe_types)) {
             header('Content-disposition: attachment; filename="' . $r[0]['filename'] . '"');
             header('Content-type: text/plain');
         }
         if (intval($r[0]['os_storage'])) {
             $f = 'store/' . $this->auth->owner_nick . '/' . ($this->os_path ? $this->os_path . '/' : '') . dbunescbin($r[0]['data']);
             return fopen($f, 'rb');
         }
         return dbunescbin($r[0]['data']);
     }
 }
开发者ID:kenrestivo,项目名称:hubzilla,代码行数:24,代码来源:RedFile.php

示例9: init

 function init()
 {
     $prvcachecontrol = false;
     $streaming = null;
     $channel = null;
     switch (argc()) {
         case 4:
             $person = argv(3);
             $res = argv(2);
             $type = argv(1);
             break;
         case 2:
             $photo = argv(1);
             break;
         case 1:
         default:
             killme();
             // NOTREACHED
     }
     $observer_xchan = get_observer_hash();
     $default = get_default_profile_photo();
     if (isset($type)) {
         /**
          * Profile photos - Access controls on default profile photos are not honoured since they need to be exchanged with remote sites.
          * 
          */
         if ($type === 'profile') {
             switch ($res) {
                 case 'm':
                     $resolution = 5;
                     $default = get_default_profile_photo(80);
                     break;
                 case 's':
                     $resolution = 6;
                     $default = get_default_profile_photo(48);
                     break;
                 case 'l':
                 default:
                     $resolution = 4;
                     break;
             }
         }
         $uid = $person;
         $d = ['imgscale' => $resolution, 'channel_id' => $uid, 'default' => $default, 'data' => '', 'mimetype' => ''];
         call_hooks('get_profile_photo', $d);
         $resolution = $d['imgscale'];
         $uid = $d['channel_id'];
         $default = $d['default'];
         $data = $d['data'];
         $mimetype = $d['mimetype'];
         if (!$data) {
             $r = q("SELECT * FROM photo WHERE imgscale = %d AND uid = %d AND photo_usage = %d LIMIT 1", intval($resolution), intval($uid), intval(PHOTO_PROFILE));
             if ($r) {
                 $data = dbunescbin($r[0]['content']);
                 $mimetype = $r[0]['mimetype'];
             }
             if (intval($r[0]['os_storage'])) {
                 $data = file_get_contents($data);
             }
         }
         if (!$data) {
             $data = file_get_contents($default);
         }
         if (!$mimetype) {
             $mimetype = 'image/png';
         }
     } else {
         /**
          * Other photos
          */
         /* Check for a cookie to indicate display pixel density, in order to detect high-resolution
         			   displays. This procedure was derived from the "Retina Images" by Jeremey Worboys,
         			   used in accordance with the Creative Commons Attribution 3.0 Unported License.
         			   Project link: https://github.com/Retina-Images/Retina-Images
         			   License link: http://creativecommons.org/licenses/by/3.0/
         			*/
         $cookie_value = false;
         if (isset($_COOKIE['devicePixelRatio'])) {
             $cookie_value = intval($_COOKIE['devicePixelRatio']);
         } else {
             // Force revalidation of cache on next request
             $cache_directive = 'no-cache';
             $status = 'no cookie';
         }
         $resolution = 0;
         if (strpos($photo, '.') !== false) {
             $photo = substr($photo, 0, strpos($photo, '.'));
         }
         if (substr($photo, -2, 1) == '-') {
             $resolution = intval(substr($photo, -1, 1));
             $photo = substr($photo, 0, -2);
             // If viewing on a high-res screen, attempt to serve a higher resolution image:
             if ($resolution == 2 && $cookie_value > 1) {
                 $resolution = 1;
             }
         }
         // If using resolution 1, make sure it exists before proceeding:
         if ($resolution == 1) {
             $r = q("SELECT uid FROM photo WHERE resource_id = '%s' AND imgscale = %d LIMIT 1", dbesc($photo), intval($resolution));
             if (!$r) {
//.........这里部分代码省略.........
开发者ID:phellmes,项目名称:hubzilla,代码行数:101,代码来源:Photo.php

示例10: cover_photo_content

function cover_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('/cover_photo', 'cover_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'] == 7) {
                $havescale = true;
            }
        }
        $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 and scale = 0", dbesc($r[0]['resource_id']), intval(local_channel()));
            if ($i) {
                $hash = $i[0]['resource_id'];
                foreach ($i as $ii) {
                    $smallest = intval($ii['scale']);
                }
            }
        }
        cover_photo_crop_ui_head($a, $ph, $hash, $smallest);
    }
    if (!x(App::$data, 'imagecrop')) {
        $tpl = get_markup_template('cover_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 Cover Photo'), '$submit' => t('Upload'), '$profiles' => $profiles, '$form_security_token' => get_form_security_token("cover_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('cover_photo_content_end', $o);
        return $o;
    } else {
        $filename = App::$data['imagecrop'] . '-3';
        $resolution = 3;
        $tpl = get_markup_template("cropcover.tpl");
        $o .= replace_macros($tpl, array('$filename' => $filename, '$profile' => intval($_REQUEST['profile']), '$resource' => App::$data['imagecrop'] . '-3', '$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("cover_photo"), '$done' => t('Done Editing')));
        return $o;
    }
    return;
    // NOTREACHED
}
开发者ID:anmol26s,项目名称:hubzilla-yunohost,代码行数:68,代码来源:cover_photo.php

示例11: post


//.........这里部分代码省略.........
             goaway(z_root() . '/' . $_SESSION['photo_return']);
         }
         $r = q("SELECT `id`, `resource_id` FROM `photo` WHERE ( xchan = '%s' or `uid` = %d ) AND `resource_id` = '%s' LIMIT 1", dbesc($ob_hash), intval(local_channel()), dbesc(\App::$argv[2]));
         if ($r) {
             attach_delete($page_owner_uid, $r[0]['resource_id'], 1);
             $sync = attach_export_data(\App::$data['channel'], $r[0]['resource_id'], true);
             if ($sync) {
                 build_sync_packet($page_owner_uid, array('file' => array($sync)));
             }
         }
         goaway(z_root() . '/photos/' . \App::$data['channel']['channel_address'] . '/album/' . $_SESSION['album_return']);
     }
     if (argc() > 2 && array_key_exists('move_to_album', $_POST)) {
         $m = q("select folder from attach where hash = '%s' and uid = %d limit 1", dbesc(argv(2)), intval($page_owner_uid));
         if ($m && $m[0]['folder'] != $_POST['move_to_album']) {
             attach_move($page_owner_uid, argv(2), $_POST['move_to_album']);
             if (!($_POST['desc'] && $_POST['newtag'])) {
                 goaway(z_root() . '/' . $_SESSION['photo_return']);
             }
         }
     }
     if (argc() > 2 && (x($_POST, 'desc') !== false || x($_POST, 'newtag') !== false)) {
         $desc = x($_POST, 'desc') ? notags(trim($_POST['desc'])) : '';
         $rawtags = x($_POST, 'newtag') ? notags(trim($_POST['newtag'])) : '';
         $item_id = x($_POST, 'item_id') ? intval($_POST['item_id']) : 0;
         $is_nsfw = x($_POST, 'adult') ? intval($_POST['adult']) : 0;
         $acl->set_from_array($_POST);
         $perm = $acl->get();
         $resource_id = argv(2);
         if (x($_POST, 'rotate') !== false && (intval($_POST['rotate']) == 1 || intval($_POST['rotate']) == 2)) {
             logger('rotate');
             $r = q("select * from photo where `resource_id` = '%s' and uid = %d and imgscale = 0 limit 1", dbesc($resource_id), intval($page_owner_uid));
             if (count($r)) {
                 $d = $r[0]['os_storage'] ? @file_get_contents($r[0]['content']) : dbunescbin($r[0]['content']);
                 $ph = photo_factory($d, $r[0]['mimetype']);
                 if ($ph->is_valid()) {
                     $rotate_deg = intval($_POST['rotate']) == 1 ? 270 : 90;
                     $ph->rotate($rotate_deg);
                     $width = $ph->getWidth();
                     $height = $ph->getHeight();
                     if (intval($r[0]['os_storage'])) {
                         @file_put_contents($r[0]['content'], $ph->imageString());
                         $data = $r[0]['content'];
                         $fsize = @filesize($r[0]['content']);
                         q("update attach set filesize = %d where hash = '%s' and uid = %d limit 1", intval($fsize), dbesc($resource_id), intval($page_owner_uid));
                     } else {
                         $data = $ph->imageString();
                         $fsize = strlen($data);
                     }
                     $x = q("update photo set content = '%s', filesize = %d, height = %d, width = %d where `resource_id` = '%s' and uid = %d and imgscale = 0", dbescbin($data), intval($fsize), intval($height), intval($width), dbesc($resource_id), intval($page_owner_uid));
                     if ($width > 1024 || $height > 1024) {
                         $ph->scaleImage(1024);
                     }
                     $width = $ph->getWidth();
                     $height = $ph->getHeight();
                     $x = q("update photo set content = '%s', height = %d, width = %d where `resource_id` = '%s' and uid = %d and imgscale = 1", dbescbin($ph->imageString()), intval($height), intval($width), dbesc($resource_id), intval($page_owner_uid));
                     if ($width > 640 || $height > 640) {
                         $ph->scaleImage(640);
                     }
                     $width = $ph->getWidth();
                     $height = $ph->getHeight();
                     $x = q("update photo set content = '%s', height = %d, width = %d where `resource_id` = '%s' and uid = %d and imgscale = 2", dbescbin($ph->imageString()), intval($height), intval($width), dbesc($resource_id), intval($page_owner_uid));
                     if ($width > 320 || $height > 320) {
                         $ph->scaleImage(320);
                     }
                     $width = $ph->getWidth();
开发者ID:phellmes,项目名称:hubzilla,代码行数:67,代码来源:Photos.php

示例12: get

 function get()
 {
     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;
         }
         $resource_id = argv(2);
         // When using an existing photo, we don't have a dialogue to offer a choice of profiles,
         // so it gets attached to the default
         $p = q("select id from profile where is_default = 1 and uid = %d", intval(local_channel()));
         if ($p) {
             $_REQUEST['profile'] = $p[0]['id'];
         }
         $r = q("SELECT id, album, imgscale FROM photo WHERE uid = %d AND resource_id = '%s' ORDER BY imgscale ASC", intval(local_channel()), dbesc($resource_id));
         if (!$r) {
             notice(t('Photo not available.') . EOL);
             return;
         }
         $havescale = false;
         foreach ($r as $rr) {
             if ($rr['imgscale'] == PHOTO_RES_PROFILE_80) {
                 $havescale = true;
             }
         }
         // set an already loaded and cropped 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\t\twhere xchan_hash = '%s'", dbesc(datetime_convert()), dbesc($channel['xchan_hash']));
             profile_photo_set_profile_perms(local_channel());
             // Reset default photo permissions to public
             \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($r[0]['content']);
         } else {
             $data = dbunescbin($r[0]['content']);
         }
         $ph = photo_factory($data, $r[0]['mimetype']);
         $smallest = 0;
         if ($ph->is_valid()) {
             // go ahead as if we have just uploaded a new photo to crop
             $i = q("select resource_id, imgscale from photo where resource_id = '%s' and uid = %d order by imgscale", dbesc($r[0]['resource_id']), intval(local_channel()));
             if ($i) {
                 $hash = $i[0]['resource_id'];
                 foreach ($i as $ii) {
                     if (intval($ii['imgscale']) < PHOTO_RES_640) {
                         $smallest = intval($ii['imgscale']);
                     }
                 }
             }
         }
         $this->profile_photo_crop_ui_head($a, $ph, $hash, $smallest);
         // falls through with App::$data['imagecrop'] set so we go straight to the cropping section
     }
     // present an upload form
     $profiles = q("select id, profile_name as name, is_default from profile where uid = %d order by id asc", 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 {
         // present a cropping form
         $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
 }
开发者ID:BlaBlaNet,项目名称:hubzilla,代码行数:90,代码来源:Profile_photo.php


注:本文中的dbunescbin函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。