• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP photo_factory函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: files1

 private static function files1($rr)
 {
     $ph = photo_factory('');
     $types = $ph->supportedTypes();
     $ext = $types[$rr['type']];
     $filename_e = $rr['filename'];
     return array(z_root() . '/photo/' . $rr['resource_id'] . '-' . $rr['hiq'] . '.' . $ext, $filename_e, z_root() . '/photo/' . $rr['resource_id'] . '-' . $rr['loq'] . '.' . $ext);
 }
开发者ID:BlaBlaNet,项目名称:hubzilla,代码行数:8,代码来源:Fbrowser.php


示例2: files1

 function files1($rr)
 {
     global $a;
     $ph = photo_factory('');
     $types = $ph->supportedTypes();
     $ext = $types[$rr['type']];
     $filename_e = $rr['filename'];
     return array($a->get_baseurl() . '/photo/' . $rr['resource_id'] . '-' . $rr['hiq'] . '.' . $ext, $filename_e, $a->get_baseurl() . '/photo/' . $rr['resource_id'] . '-' . $rr['loq'] . '.' . $ext);
 }
开发者ID:msooon,项目名称:hubzilla,代码行数:9,代码来源:fbrowser.php


示例3: files1

 function files1($rr)
 {
     global $a;
     $ph = photo_factory('');
     $types = $ph->supportedTypes();
     $ext = $types[$rr['type']];
     if ($a->get_template_engine() === 'internal') {
         $filename_e = template_escape($rr['filename']);
     } else {
         $filename_e = $rr['filename'];
     }
     return array($a->get_baseurl() . '/photo/' . $rr['resource_id'] . '-' . $rr['hiq'] . '.' . $ext, $filename_e, $a->get_baseurl() . '/photo/' . $rr['resource_id'] . '-' . $rr['loq'] . '.' . $ext);
 }
开发者ID:redmatrix,项目名称:red,代码行数:13,代码来源:fbrowser.php


示例4: scale_external_images

function scale_external_images($s, $include_link = true, $scale_replace = false)
{
    $a = get_app();
    // Picture addresses can contain special characters
    $s = htmlspecialchars_decode($s, ENT_COMPAT);
    $matches = null;
    $c = preg_match_all('/\\[([zi])mg(.*?)\\](.*?)\\[\\/[zi]mg\\]/ism', $s, $matches, PREG_SET_ORDER);
    if ($c) {
        require_once 'include/photo/photo_driver.php';
        foreach ($matches as $mtch) {
            logger('scale_external_image: ' . $mtch[2] . ' ' . $mtch[3]);
            if (substr($mtch[1], 0, 1) == '=') {
                $owidth = intval(substr($mtch[2], 1));
                if (intval($owidth) > 0 && intval($owidth) < 1024) {
                    continue;
                }
            }
            $hostname = str_replace('www.', '', substr($a->get_baseurl(), strpos($a->get_baseurl(), '://') + 3));
            if (stristr($mtch[3], $hostname)) {
                continue;
            }
            // $scale_replace, if passed, is an array of two elements. The
            // first is the name of the full-size image. The second is the
            // name of a remote, scaled-down version of the full size image.
            // This allows Friendica to display the smaller remote image if
            // one exists, while still linking to the full-size image
            if ($scale_replace) {
                $scaled = str_replace($scale_replace[0], $scale_replace[1], $mtch[3]);
            } else {
                $scaled = $mtch[3];
            }
            $i = z_fetch_url($scaled, true);
            $cache = get_config('system', 'itemcache');
            if ($cache != '' and is_dir($cache)) {
                $cachefile = $cache . "/" . hash("md5", $scaled);
                file_put_contents($cachefile, $i['body']);
            }
            // guess mimetype from headers or filename
            $type = guess_image_type($mtch[3], $i['header']);
            if (strpos($type, 'image') === false) {
                continue;
            }
            if ($i['success']) {
                $ph = photo_factory($i['body'], $type);
                if ($ph->is_valid()) {
                    $orig_width = $ph->getWidth();
                    $orig_height = $ph->getHeight();
                    if ($orig_width > 1024 || $orig_height > 1024) {
                        $tag = $match[1] == 'z' ? 'zmg' : 'img';
                        $ph->scaleImage(1024);
                        $new_width = $ph->getWidth();
                        $new_height = $ph->getHeight();
                        logger('scale_external_images: ' . $orig_width . '->' . $new_width . 'w ' . $orig_height . '->' . $new_height . 'h' . ' match: ' . $mtch[0], LOGGER_DEBUG);
                        $s = str_replace($mtch[0], '[' . $tag . '=' . $new_width . 'x' . $new_height . ']' . $scaled . '[/' . $tag . ']' . "\n" . ($include_link ? '[zrl=' . $mtch[2] . ']' . t('view full size') . '[/zrl]' . "\n" : ''), $s);
                        logger('scale_external_images: new string: ' . $s, LOGGER_DEBUG);
                    }
                }
            }
        }
    }
    // replace the special char encoding
    $s = htmlspecialchars($s, ENT_COMPAT, 'UTF-8');
    return $s;
}
开发者ID:bashrc,项目名称:hubzilla,代码行数:64,代码来源:network.php


示例5: init


//.........这里部分代码省略.........
             } else {
                 // Does the picture exist? It may be a remote person with no credentials,
                 // but who should otherwise be able to view it. Show a default image to let
                 // them know permissions was denied. It may be possible to view the image
                 // through an authenticated profile visit.
                 // There won't be many completely unauthorised people seeing this because
                 // they won't have the photo link, so there's a reasonable chance that the person
                 // might be able to obtain permission to view it.
                 $r = q("SELECT * FROM `photo` WHERE `resource_id` = '%s' AND `imgscale` = %d LIMIT 1", dbesc($photo), intval($resolution));
                 if ($r) {
                     logger('mod_photo: forbidden. ' . \App::$query_string);
                     $observer = \App::get_observer();
                     logger('mod_photo: observer = ' . ($observer ? $observer['xchan_addr'] : '(not authenticated)'));
                     $data = file_get_contents('images/nosign.png');
                     $mimetype = 'image/png';
                     $prvcachecontrol = true;
                 }
             }
         }
     }
     if (!isset($data)) {
         if (isset($resolution)) {
             switch ($resolution) {
                 case 4:
                     $data = file_get_contents(get_default_profile_photo());
                     $mimetype = 'image/png';
                     break;
                 case 5:
                     $data = file_get_contents(get_default_profile_photo(80));
                     $mimetype = 'image/png';
                     break;
                 case 6:
                     $data = file_get_contents(get_default_profile_photo(48));
                     $mimetype = 'image/png';
                     break;
                 default:
                     killme();
                     // NOTREACHED
                     break;
             }
         }
     }
     if (isset($res) && intval($res) && $res < 500) {
         $ph = photo_factory($data, $mimetype);
         if ($ph->is_valid()) {
             $ph->scaleImageSquare($res);
             $data = $ph->imageString();
             $mimetype = $ph->getType();
         }
     }
     // Writing in cachefile
     if (isset($cachefile) && $cachefile != '') {
         file_put_contents($cachefile, $data);
     }
     if (function_exists('header_remove')) {
         header_remove('Pragma');
         header_remove('pragma');
     }
     header("Content-type: " . $mimetype);
     if ($prvcachecontrol) {
         // it is a private photo that they have no permission to view.
         // tell the browser not to cache it, in case they authenticate
         // and subsequently have permission to see it
         header("Cache-Control: no-store, no-cache, must-revalidate");
     } else {
         // The photo cache default is 1 day to provide a privacy trade-off,
         // as somebody reducing photo permissions on a photo that is already
         // "in the wild" won't be able to stop the photo from being viewed
         // for this amount amount of time once it is in the browser cache.
         // The privacy expectations of your site members and their perception
         // of privacy where it affects the entire project may be affected.
         // This has performance considerations but we highly recommend you
         // leave it alone.
         $cache = get_config('system', 'photo_cache_time');
         if (!$cache) {
             $cache = 3600 * 24;
         }
         // 1 day
         header("Expires: " . gmdate("D, d M Y H:i:s", time() + $cache) . " GMT");
         header("Cache-Control: max-age=" . $cache);
     }
     // If it's a file resource, stream it.
     if ($streaming && $channel) {
         if (strpos($streaming, 'store') !== false) {
             $istream = fopen($streaming, 'rb');
         } else {
             $istream = fopen('store/' . $channel['channel_address'] . '/' . $streaming, 'rb');
         }
         $ostream = fopen('php://output', 'wb');
         if ($istream && $ostream) {
             pipe_streams($istream, $ostream);
             fclose($istream);
             fclose($ostream);
         }
     } else {
         echo $data;
     }
     killme();
     // NOTREACHED
 }
开发者ID:phellmes,项目名称:hubzilla,代码行数:101,代码来源:Photo.php


示例6: openclipatar_content

function openclipatar_content(&$a)
{
    if (!local_channel()) {
        return;
    }
    $o = '';
    if (argc() == 3 && argv(1) == 'use') {
        $id = argv(2);
        $chan = $a->get_channel();
        $x = z_fetch_url('https://openclipart.org/image/250px/svg_to_png/' . $id . '/' . $id . '.png', true);
        if ($x['success']) {
            $imagedata = $x['body'];
        }
        $ph = photo_factory($imagedata, 'image/png');
        if (!$ph->is_valid()) {
            return t('Unknown error. Please try again later.');
        }
        // create a unique resource_id
        $hash = photo_new_resource();
        // save an original or "scale 0" image
        $p = array('aid' => get_account_id(), 'uid' => local_channel(), 'resource_id' => $hash, 'filename' => $id . '.png', 'album' => t('Profile Photos'), 'scale' => 0);
        $r = $ph->save($p);
        if ($r) {
            // scale 0 success, continue 4, 5, 6
            // we'll skip scales 1,2 (640, 320 rectangular formats as these images are all less than this)
            // ensure squareness at first, subsequent scales keep ratio
            $ph->scaleImageSquare(175);
            $p['scale'] = 4;
            $r = $ph->save($p);
            if ($r === false) {
                $photo_failure = true;
            }
            $ph->scaleImage(80);
            $p['scale'] = 5;
            $r = $ph->save($p);
            if ($r === false) {
                $photo_failure = true;
            }
            $ph->scaleImage(48);
            $p['scale'] = 6;
            $r = $ph->save($p);
            if ($r === false) {
                $photo_failure = true;
            }
        }
        $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;
            }
        }
        if ($is_default_profile) {
            // unset any existing profile photos
            $r = q("UPDATE photo SET profile = 0 WHERE profile = 1 AND uid = %d", intval(local_channel()));
            $r = q("UPDATE photo SET photo_flags = (photo_flags & ~%d ) WHERE (photo_flags & %d )>0 AND uid = %d", intval(PHOTO_PROFILE), intval(PHOTO_PROFILE), intval(local_channel()));
            // 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_channel()), dbesc($hash));
            $r = q("UPDATE photo SET photo_flags = ( photo_flags | %d ) WHERE uid = %d AND resource_id = '%s'", intval(PHOTO_PROFILE), intval(local_channel()), dbesc($hash));
            require_once 'mod/profile_photo.php';
            profile_photo_set_profile_perms();
            //Reset default profile photo permissions to public
            // only the default needs reload since it uses canonical url -- despite the slightly ambiguous message, left it so as to re-use translations
            info(t('Shift-reload the page or clear browser cache if the new photo does not display immediately.') . EOL);
        } else {
            // not the default profile, set the path in the correct entry in the profile DB
            $r = q("update profile set photo = '%s', thumb = '%s' where id = %d and uid = %d", dbesc(get_app()->get_baseurl() . '/photo/' . $hash . '-4'), dbesc(get_app()->get_baseurl() . '/photo/' . $hash . '-5'), intval($_REQUEST['profile']), intval(local_channel()));
            info(t('Profile photo updated successfully.') . EOL);
        }
        // set a new photo_date on our xchan so that we can tell everybody to update their cached copy
        $r = q("UPDATE xchan set xchan_photo_date = '%s' where xchan_hash = '%s'", dbesc(datetime_convert()), dbesc($chan['xchan_hash']));
        // tell everybody
        proc_run('php', 'include/directory.php', local_channel());
        $returnafter = get_config('openclipatar', 'returnafter');
        $returnafter_urls = array(0 => $a->get_baseurl() . '/profile/' . ($_REQUEST['profile'] ? $_REQUEST['profile'] . '/view' : $chan['channel_address']), 1 => $a->get_baseurl() . '/profiles/' . ($_REQUEST['profile'] ? $_REQUEST['profile'] : $a->profile_uid), 2 => $a->get_baseurl() . '/profiles');
        goaway($returnafter_urls[$returnafter]);
    } else {
        //invoked as module, we place in content pane the same as we would for the end of the profile photo page. Also handles json for endless scroll for either invokation.
        openclipatar_profile_photo_content_end($a, $o);
    }
    return $o;
}
开发者ID:einervonvielen,项目名称:redmatrix-addons,代码行数:82,代码来源:openclipatar.php


示例7: openclipatar_content

function openclipatar_content(&$a)
{
    if (!local_channel()) {
        return;
    }
    $o = '';
    if (argc() == 3 && argv(1) == 'use') {
        $id = argv(2);
        $chan = App::get_channel();
        $x = z_fetch_url('https://openclipart.org/image/250px/svg_to_png/' . $id . '/' . $id . '.png', true);
        if ($x['success']) {
            $imagedata = $x['body'];
        }
        $ph = photo_factory($imagedata, 'image/png');
        if (!$ph->is_valid()) {
            return t('Unknown error. Please try again later.');
        }
        // create a unique resource_id
        $hash = photo_new_resource();
        $width = $ph->getWidth();
        $height = $ph->getHeight();
        // save an original or "scale 0" image
        $p = array('aid' => get_account_id(), 'uid' => local_channel(), 'resource_id' => $hash, 'filename' => $id . '.png', 'album' => t('Profile Photos'), 'imgscale' => 0);
        $r = $ph->save($p);
        if ($r) {
            if (($width > 1024 || $height > 1024) && !$errors) {
                $ph->scaleImage(1024);
            }
            $p['imgscale'] = 1;
            $r1 = $ph->save($p);
            if (($width > 640 || $height > 640) && !$errors) {
                $ph->scaleImage(640);
            }
            $p['imgscale'] = 2;
            $r2 = $ph->save($p);
            if (($width > 320 || $height > 320) && !$errors) {
                $ph->scaleImage(320);
            }
            $p['imgscale'] = 3;
            $r3 = $ph->save($p);
            // ensure squareness at first, subsequent scales keep ratio
            $ph->scaleImageSquare(175);
            $p['imgscale'] = 4;
            $r = $ph->save($p);
            if ($r === false) {
                $photo_failure = true;
            }
            $ph->scaleImage(80);
            $p['imgscale'] = 5;
            $r = $ph->save($p);
            if ($r === false) {
                $photo_failure = true;
            }
            $ph->scaleImage(48);
            $p['imgscale'] = 6;
            $r = $ph->save($p);
            if ($r === false) {
                $photo_failure = true;
            }
        }
        $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;
            }
        }
        if ($is_default_profile) {
            // 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()));
            // set all sizes of this one as profile photos
            $r = q("UPDATE photo SET photo_usage = %d WHERE uid = %d AND resource_id = '%s'", intval(PHOTO_PROFILE), intval(local_channel()), dbesc($hash));
            require_once 'include/photos.php';
            profile_photo_set_profile_perms(local_channel());
            //Reset default profile photo permissions to public
            // only the default needs reload since it uses canonical url -- despite the slightly ambiguous message, left it so as to re-use translations
            info(t('Shift-reload the page or clear browser cache if the new photo does not display immediately.') . EOL);
        } else {
            // not the default profile, set the path in the correct entry in the profile DB
            $r = q("update profile set photo = '%s', thumb = '%s' where id = %d and uid = %d", dbesc(z_root() . '/photo/' . $hash . '-4'), dbesc(z_root() . '/photo/' . $hash . '-5'), intval($_REQUEST['profile']), intval(local_channel()));
            info(t('Profile photo updated successfully.') . EOL);
        }
        // set a new photo_date on our xchan so that we can tell everybody to update their cached copy
        $r = q("UPDATE xchan set xchan_photo_date = '%s' where xchan_hash = '%s'", dbesc(datetime_convert()), dbesc($chan['xchan_hash']));
        // Similarly, tell the nav bar to bypass the cache and update the avater image.
        $_SESSION['reload_avatar'] = true;
        // tell everybody
        Zotlabs\Daemon\Master::Summon(array('Directory', local_channel()));
        $returnafter = get_config('openclipatar', 'returnafter');
        $returnafter_urls = array(0 => z_root() . '/profile/' . ($_REQUEST['profile'] ? $_REQUEST['profile'] . '/view' : $chan['channel_address']), 1 => z_root() . '/profiles/' . ($_REQUEST['profile'] ? $_REQUEST['profile'] : App::$profile_uid), 2 => z_root() . '/profiles');
        goaway($returnafter_urls[$returnafter]);
    } else {
        //invoked as module, we place in content pane the same as we would for the end of the profile photo page. Also handles json for endless scroll for either invokation.
        openclipatar_profile_photo_content_end($a, $o);
    }
    return $o;
}
开发者ID:phellmes,项目名称:hubzilla-addons,代码行数:97,代码来源:openclipatar.php


示例8: 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


示例9: photo_init


//.........这里部分代码省略.........
        $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 scale = %d LIMIT 1", dbesc($photo), intval($resolution));
            if (!$r) {
                $resolution = 2;
            }
        }
        $r = q("SELECT uid FROM photo WHERE resource_id = '%s' AND scale = %d LIMIT 1", dbesc($photo), intval($resolution));
        if ($r) {
            $allowed = $r[0]['uid'] ? perm_is_allowed($r[0]['uid'], $observer_xchan, 'view_photos') : true;
            $sql_extra = permissions_sql($r[0]['uid']);
            // Now we'll see if we can access the photo
            $r = q("SELECT * FROM photo WHERE resource_id = '%s' AND scale = %d {$sql_extra} LIMIT 1", dbesc($photo), intval($resolution));
            if ($r && $allowed) {
                $data = $r[0]['data'];
                $mimetype = $r[0]['type'];
            } else {
                // Does the picture exist? It may be a remote person with no credentials,
                // but who should otherwise be able to view it. Show a default image to let
                // them know permissions was denied. It may be possible to view the image
                // through an authenticated profile visit.
                // There won't be many completely unauthorised people seeing this because
                // they won't have the photo link, so there's a reasonable chance that the person
                // might be able to obtain permission to view it.
                $r = q("SELECT * FROM `photo` WHERE `resource_id` = '%s' AND `scale` = %d LIMIT 1", dbesc($photo), intval($resolution));
                if ($r) {
                    logger('mod_photo: forbidden. ' . $a->query_string);
                    $observer = $a->get_observer();
                    logger('mod_photo: observer = ' . ($observer ? $observer['xchan_addr'] : '(not authenticated)'));
                    $data = file_get_contents('images/nosign.png');
                    $mimetype = 'image/png';
                    $prvcachecontrol = true;
                }
            }
        }
    }
    if (!isset($data)) {
        if (isset($resolution)) {
            switch ($resolution) {
                case 4:
                    $data = file_get_contents(get_default_profile_photo());
                    $mimetype = 'image/jpeg';
                    break;
                case 5:
                    $data = file_get_contents(get_default_profile_photo(80));
                    $mimetype = 'image/jpeg';
                    break;
                case 6:
                    $data = file_get_contents(get_default_profile_photo(48));
                    $mimetype = 'image/jpeg';
                    break;
                default:
                    killme();
                    // NOTREACHED
                    break;
            }
        }
    }
    if (isset($res) && intval($res) && $res < 500) {
        $ph = photo_factory($data, $mimetype);
        if ($ph->is_valid()) {
            $ph->scaleImageSquare($res);
            $data = $ph->imageString();
            $mimetype = $ph->getType();
        }
    }
    // Writing in cachefile
    if (isset($cachefile) && $cachefile != '') {
        file_put_contents($cachefile, $data);
    }
    if (function_exists('header_remove')) {
        header_remove('Pragma');
        header_remove('pragma');
    }
    header("Content-type: " . $mimetype);
    if ($prvcachecontrol) {
        // it is a private photo that they have no permission to view.
        // tell the browser not to cache it, in case they authenticate
        // and subsequently have permission to see it
        header("Cache-Control: no-store, no-cache, must-revalidate");
    } else {
        header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600 * 24) . " GMT");
        header("Cache-Control: max-age=" . 3600 * 24);
    }
    echo $data;
    killme();
    // NOTREACHED
}
开发者ID:Mauru,项目名称:red,代码行数:101,代码来源:photo.php


示例10: fix_private_photos

function fix_private_photos($s, $uid, $item = null, $cid = 0)
{
    $a = get_app();
    logger('fix_private_photos', LOGGER_DEBUG);
    $site = substr($a->get_baseurl(), strpos($a->get_baseurl(), '://'));
    $orig_body = $s;
    $new_body = '';
    $img_start = strpos($orig_body, '[zmg');
    $img_st_close = $img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false;
    $img_len = $img_start !== false ? strpos(substr($orig_body, $img_start + $img_st_close + 1), '[/zmg]') : false;
    while ($img_st_close !== false && $img_len !== false) {
        $img_st_close++;
        // make it point to AFTER the closing bracket
        $image = substr($orig_body, $img_start + $img_st_close, $img_len);
        logger('fix_private_photos: found photo ' . $image, LOGGER_DEBUG);
        if (stristr($image, $site . '/photo/')) {
            // Only embed locally hosted photos
            $replace = false;
            $i = basename($image);
            $x = strpos($i, '-');
            if ($x) {
                $res = substr($i, $x + 1);
                $i = substr($i, 0, $x);
                $r = q("SELECT * FROM `photo` WHERE `resource_id` = '%s' AND `scale` = %d AND `uid` = %d", dbesc($i), intval($res), intval($uid));
                if (count($r)) {
                    // Check to see if we should replace this photo link with an embedded image
                    // 1. No need to do so if the photo is public
                    // 2. If there's a contact-id provided, see if they're in the access list
                    //    for the photo. If so, embed it.
                    // 3. Otherwise, if we have an item, see if the item permissions match the photo
                    //    permissions, regardless of order but first check to see if they're an exact
                    //    match to save some processing overhead.
                    if (has_permissions($r[0])) {
                        if ($cid) {
                            $recips = enumerate_permissions($r[0]);
                            if (in_array($cid, $recips)) {
                                $replace = true;
                            }
                        } elseif ($item) {
                            if (compare_permissions($item, $r[0])) {
                                $replace = true;
                            }
                        }
                    }
                    if ($replace) {
                        $data = $r[0]['data'];
                        $type = $r[0]['type'];
                        // If a custom width and height were specified, apply before embedding
                        if (preg_match("/\\[zmg\\=([0-9]*)x([0-9]*)\\]/is", substr($orig_body, $img_start, $img_st_close), $match)) {
                            logger('fix_private_photos: scaling photo', LOGGER_DEBUG);
                            $width = intval($match[1]);
                            $height = intval($match[2]);
                            $ph = photo_factory($data, $type);
                            if ($ph->is_valid()) {
                                $ph->scaleImage(max($width, $height));
                                $data = $ph->imageString();
                                $type = $ph->getType();
                            }
                        }
                        logger('fix_private_photos: replacing photo', LOGGER_DEBUG);
                        $image = 'data:' . $type . ';base64,' . base64_encode($data);
                        logger('fix_private_photos: replaced: ' . $image, LOGGER_DATA);
                    }
                }
            }
        }
        $new_body = $new_body . substr($orig_body, 0, $img_start + $img_st_close) . $image . '[/zmg]';
        $orig_body = substr($orig_body, $img_start + $img_st_close + $img_len + strlen('[/zmg]'));
        if ($orig_body === false) {
            $orig_body = '';
        }
        $img_start = strpos($orig_body, '[zmg');
        $img_st_close = $img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false;
        $img_len = $img_start !== false ? strpos(substr($orig_body, $img_start + $img_st_close + 1), '[/zmg]') : false;
    }
    $new_body = $new_body . $orig_body;
    return $new_body;
}
开发者ID:einervonvielen,项目名称:redmatrix,代码行数:78,代码来源:items.php


示例11: photos_content

function photos_content(&$a)
{
    // URLs:
    // photos/name
    // photos/name/upload
    // photos/name/upload/xxxxx (xxxxx is album name)
    // photos/name/album/xxxxx
    // photos/name/album/xxxxx/edit
    // photos/name/image/xxxxx
    // photos/name/image/xxxxx/edit
    if (get_config('system', 'block_public') && !local_user() && !remote_user()) {
        notice(t('Public access denied.') . EOL);
        return;
    }
    require_once 'include/bbcode.php';
    require_once 'include/security.php';
    require_once 'include/conversation.php';
    if (!x($a->data, 'channel')) {
        notice(t('No photos selected') . EOL);
        return;
    }
    $ph = photo_factory('');
    $phototypes = $ph->supportedTypes();
    $_SESSION['photo_return'] = $a->cmd;
    //
    // Parse arguments
    //
    $can_comment = perm_is_allowed($a->profile['profile_uid'], get_observer_hash(), 'post_comments');
    if (argc() > 3) {
        $datatype = argv(2);
        $datum = argv(3);
    } elseif (argc() > 2 && argv(2) === 'upload') {
        $datatype = 'upload';
    } else {
        $datatype = 'summary';
    }
    if (argc() > 4) {
        $cmd = argv(4);
    } else {
        $cmd = 'view';
    }
    //
    // Setup permissions structures
    //
    $can_post = false;
    $visitor = 0;
    $owner_uid = $a->data['channel']['channel_id'];
    $owner_aid = $a->data['channel']['channel_account_id'];
    $observer = $a->get_observer();
    $can_post = perm_is_allowed($owner_uid, $observer['xchan_hash'], 'post_photos');
    $can_view = perm_is_allowed($owner_uid, $observer['xchan_hash'], 'view_photos');
    if (!$can_view) {
        notice(t('Access to this item is restricted.') . EOL);
        return;
    }
    $sql_extra = permissions_sql($owner_uid);
    $o = "";
    $o .= "<script> var profile_uid = " . $a->profile['profile_uid'] . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
    // tabs
    $_is_owner = local_user() && local_user() == $owner_uid;
    $o .= profile_tabs($a, $_is_owner, $a->data['channel']['channel_address']);
    //
    // dispatch request
    //
    /**
     * Display upload form
     */
    if ($datatype === 'upload') {
        if (!$can_post) {
            notice(t('Permission denied.'));
            return;
        }
        if (array_key_exists('albums', $a->data)) {
            $albums = get_app()->data['albums'];
        } else {
            $albums = photos_albums_list($a->data['channel'], $a->data['observer']);
        }
        $selname = $datum ? hex2bin($datum) : '';
        $albumselect = '<select id="photos-upload-album-select" name="album" size="4">';
        $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>';
        if (count($albums['albums'])) {
            foreach ($albums['albums'] as $album) {
                if (!$album['text']) {
                    continue;
                }
                $selected = $selname === $album['text'] ? ' selected="selected" ' : '';
                $albumselect .= '<option value="' . $album['text'] . '"' . $selected . '>' . $album['text'] . '</option>';
            }
        }
        $albumselect .= '</select>';
        $uploader = '';
        $ret = array('post_url' => $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'], 'addon_text' => $uploader, 'default_upload' => true);
        call_hooks('photo_upload_form', $ret);
        $default_upload = '<input id="photos-upload-choose" type="file" name="userfile" /> 	<div class="photos-upload-submit-wrapper" >
		<input type="submit" name="submit" value="' . t('Submit') . '" id="photos-upload-submit" /> </div>';
        /* Show space usage */
        $r = q("select sum(size) as total from photo where aid = %d and scale = 0 ", intval($a->data['channel']['channel_account_id']));
        $limit = service_class_fetch($a->data['channel']['channel_id'], 'photo_upload_limit');
        if ($limit !== false) {
            $usage_message = sprintf(t("You have used %1\$.2f Mbytes of %2\$.2f Mbytes photo storage."), $r[0]['total'] / 1024000, $limit / 1024000);
//.........这里部分代码省略.........
开发者ID:Mauru,项目名称:red,代码行数:101,代码来源:photos.php


示例12: profile_photo_content

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


示例13: photo_upload

/**
 * @brief
 *
 * @param array $channel
 * @param array $observer
 * @param array $args
 * @return array
 */
function photo_upload($channel, $observer, $args)
{
    $ret = array('success' => false);
    $channel_id = $channel['channel_id'];
    $account_id = $channel['channel_account_id'];
    if (!perm_is_allowed($channel_id, $observer['xchan_hash'], 'post_photos')) {
        $ret['message'] = t('Permission denied.');
        return $ret;
    }
    call_hooks('photo_upload_begin', $args);
    /*
     * Determine the album to use
     */
    $album = $args['album'];
    $newalbum = $args['newalbum'];
    logger('photo_upload: album= ' . $album . ' newalbum= ' . $newalbum, LOGGER_DEBUG);
    if (!$album) {
        if ($newalbum) {
            $album = $newalbum;
        } else {
            $album = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y-m');
        }
    }
    if (intval($args['visible']) || $args['visible'] === 'true') {
        $visible = 1;
    } else {
        $visible = 0;
    }
    $str_group_allow = perms2str(is_array($args['group_allow']) ? $args['group_allow'] : explode(',', $args['group_allow']));
    $str_contact_allow = perms2str(is_array($args['contact_allow']) ? $args['contact_allow'] : explode(',', $args['contact_allow']));
    $str_group_deny = perms2str(is_array($args['group_deny']) ? $args['group_deny'] : explode(',', $args['group_deny']));
    $str_contact_deny = perms2str(is_array($args['contact_deny']) ? $args['contact_deny'] : explode(',', $args['contact_deny']));
    if ($args['data']) {
        // allow an import from a binary string representing the image.
        // This bypasses the upload step and max size limit checking
        $imagedata = $args['data'];
        $filename = $args['filename'];
        $filesize = strlen($imagedata);
        // this is going to be deleted if it exists
        $src = '/tmp/deletemenow';
        $type = $args['type'];
    } else {
        $f = array('src' => '', 'filename' => '', 'filesize' => 0, 'type' => '');
        call_hooks('photo_upload_file', $f);
        if (x($f, 'src') && x($f, 'filesize')) {
            $src = $f['src'];
            $filename = $f['filename'];
            $filesize = $f['filesize'];
            $type = $f['type'];
        } else {
            $src = $_FILES['userfile']['tmp_name'];
            $filename = basename($_FILES['userfile']['name']);
            $filesize = intval($_FILES['userfile']['size']);
            $type = $_FILES['userfile']['type'];
        }
        if (!$type) {
            $type = guess_image_type($filename);
        }
        logger('photo_upload: received file: ' . $filename . ' as ' . $src . ' (' . $type . ') ' . $filesize . ' bytes', LOGGER_DEBUG);
        $maximagesize = get_config('system', 'maximagesize');
        if ($maximagesize && $filesize > $maximagesize) {
            $ret['message'] = sprintf(t('Image exceeds website size limit of %lu bytes'), $maximagesize);
            @unlink($src);
            call_hooks('photo_upload_end', $ret);
            return $ret;
        }
        if (!$filesize) {
            $ret['message'] = t('Image file is empty.');
            @unlink($src);
            call_hooks('photo_post_end', $ret);
            return $ret;
        }
        logger('photo_upload: loading the contents of ' . $src, LOGGER_DEBUG);
        $imagedata = @file_get_contents($src);
    }
    $r = q("select sum(size) as total from photo where aid = %d and scale = 0 ", intval($account_id));
    $limit = service_class_fetch($channel_id, 'photo_upload_limit');
    if ($r && $limit !== false && $r[0]['total'] + strlen($imagedata) > $limit) {
        $ret['message'] = upgrade_message();
        @unlink($src);
        call_hooks('photo_post_end', $ret);
        return $ret;
    }
    $ph = photo_factory($imagedata, $type);
    if (!$ph->is_valid()) {
        $ret['message'] = t('Unable to process image');
        logger('photo_upload: unable to process image');
        @unlink($src);
        call_hooks('photo_upload_end', $ret);
        return $ret;
    }
    $exif = $ph->orient($src);
//.........这里部分代码省略.........
开发者ID:HaakonME,项目名称:redmatrix,代码行数:101,代码来源:photos.php


示例14: import_channel_photo


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP photo_new_resource函数代码示例发布时间:2022-05-15
下一篇:
PHP phorum_redirect_by_url函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap