Ejemplo n.º 1
0
 /**
  * 打开一张图像
  * @param  string $imgname 图像路径
  * @throws \Exception
  */
 public function open($imgname)
 {
     //检测图像文件
     if (!is_file($imgname)) {
         throw new \Exception(_('The image file does not exist'));
     }
     //获取图像信息
     $info = getimagesize($imgname);
     //检测图像合法性
     if (false === $info || IMAGETYPE_GIF === $info[2] && empty($info['bits'])) {
         throw new \Exception(_('Illegal image file'));
     }
     //设置图像信息
     $this->info = array('width' => $info[0], 'height' => $info[1], 'type' => image_type_to_extension($info[2], false), 'mime' => $info['mime']);
     //销毁已存在的图像
     empty($this->img) || imagedestroy($this->img);
     //打开图像
     if ('gif' == $this->info['type']) {
         c_lib()->load('image/GIF');
         $class = 'CLib\\Image\\GIF';
         $this->gif = new $class($imgname);
         $this->img = imagecreatefromstring($this->gif->image());
     } else {
         $fun = "imagecreatefrom{$this->info['type']}";
         $this->img = $fun($imgname);
     }
 }
Ejemplo n.º 2
0
 /**
  * @param string $drive_name
  * @throws \Exception
  */
 function __construct($drive_name = 'Local')
 {
     c_lib()->load('session/' . $drive_name);
     $drive_name = "CLib\\Session\\" . $drive_name;
     if (!class_exists($drive_name)) {
         throw new \Exception(_("Session Drive Not Found"));
     }
     $this->drive = new $drive_name();
 }
Ejemplo n.º 3
0
 function __construct()
 {
     c_lib()->load('sql');
     $this->driver = new Sql(cfg()->get('database'));
     if (!$this->driver->status()) {
         define('HAS_RUN_ERROR', true);
         cfg()->set('HAS_RUN_ERROR', $this->driver->ex_message());
     }
 }
Ejemplo n.º 4
0
 /**
  * 构造
  * @param bool $encode
  */
 public function __construct($encode = false)
 {
     $this->encode = $encode;
     if ($encode) {
         if (!class_exists('Safe')) {
             c_lib()->load('safe');
         }
         hook()->add('Request_cookie', array($this, 'de'));
         hook()->add('Cookie_set', array($this, 'en'));
     }
 }
Ejemplo n.º 5
0
 /**
  * 构造
  * @param bool   $encode
  * @param string $key
  */
 public function __construct($encode = false, $key = '')
 {
     $this->encode = $encode;
     if ($encode) {
         c_lib()->load('safe');
         $this->safe = new Safe();
         hook()->add('Request_cookie', array($this, 'de'));
         hook()->add('Cookie_set', array($this, 'en'));
     }
     $this->setKey($key);
 }
Ejemplo n.º 6
0
 function __construct($drive = 'Mcrypt')
 {
     if ($drive == 'Mcrypt' && !function_exists('mcrypt_create_iv')) {
         $drive = "Simple";
     }
     c_lib()->load('safe/' . $drive);
     $drive_name = "CLib\\Safe\\" . $drive;
     if (!class_exists($drive_name)) {
         throw new \Exception(_("Safe Drive Not Found"));
     }
     $this->drive = new $drive_name();
 }
Ejemplo n.º 7
0
 /**
  * 添加钩子,并初始化部分信息
  */
 public function add()
 {
     if (!db()->status()) {
         hook()->add('UriInfo_process', array($this, 'sql_error'));
     } else {
         c_lib()->load('cookie')->add('cookie', new \CLib\Cookie(cfg()->get('cookie', 'encode')));
         lib()->load('setting', 'user', 'plugin', 'version_hook')->add('setting', new Setting());
         lib()->add('user', new User(true));
         lib()->add("version_hook", new Version_Hook());
         l_h('theme.php');
         hook()->add('UriInfo_process', array($this, 'router'));
         lib()->add('plugin', new Plugin(_BasePath_ . "/ex/plugin"));
     }
 }
Ejemplo n.º 8
0
/**
 * 取得缓存对象的实例
 * @return \CLib\PCache
 */
function pcache()
{
    static $cache = NULL;
    if ($cache !== NULL) {
        return $cache;
    }
    $lib = c_lib();
    $cache = $lib->using('cache');
    if ($cache === false) {
        $lib->load('pcache')->add("pcache", new \CLib\PCache(cfg()->get('pcache', 'drive')));
        $cache = $lib->using('pcache');
    }
    return $cache;
}
Ejemplo n.º 9
0
 function __construct()
 {
     $this->c_router = c_lib()->load('router')->add('router', new \CLib\Router());
     //对路由信息反序列化
     $router = @unserialize(cfg()->get('option', 'router_list'));
     foreach (array_keys($router) as $c) {
         if (empty($router[$c])) {
             unset($router[$c]);
         }
     }
     $this->router_list = $this->defaultRouter();
     if (is_array($router)) {
         $this->router_list = array_merge($this->router_list, $router);
     }
 }
Ejemplo n.º 10
0
 /**
  * 构造方法
  * @param string $drive_name   驱动名称
  * @param array  $drive_config 驱动构造配置文件
  * @throws \Exception 抛出驱动未找到的异常
  */
 function __construct($drive_name = 'File', $drive_config = [])
 {
     if (hook()->apply("PCache_set", true)) {
         //只有当缓存启用时才调用页面缓存
         $this->status = true;
         if (empty($drive_name)) {
             $drive_name = "File";
         }
         c_lib()->load('pcache/' . $drive_name);
         $drive_name = "CLib\\PCache\\" . $drive_name;
         if (!class_exists($drive_name)) {
             throw new \Exception(_("Page Cache Drive Not Found"));
         }
         $this->drive = new $drive_name($drive_config);
         hook()->add("Uri_load_begin", [$this, 'hook_begin']);
         hook()->add("Uri_load_end", [$this, 'hook_end']);
     } else {
         $this->status = false;
     }
 }
Ejemplo n.º 11
0
 /**
  * 构造方法,用于实例化一个图片处理对象
  * @param int  $type
  * @param null $imgname 初始名称
  * @throws \Exception
  */
 public function __construct($type = self::IMAGE_GD, $imgname = NULL)
 {
     /* 判断调用库的类型 */
     switch ($type) {
         case self::IMAGE_GD:
             $class = 'Gd';
             break;
         case self::IMAGE_IMAGICK:
             $class = 'Imagick';
             break;
         default:
             throw new \Exception(_("Unknown type Exception"));
     }
     /* 引入处理库,实例化图片处理对象 */
     c_lib()->load('image/' . $class);
     $class = "CLib\\Image\\{$class}";
     if (!class_exists($class)) {
         throw new \Exception(_("Image interface class error."));
     }
     $this->img = new $class($imgname);
 }
Ejemplo n.º 12
0
<?php

// +----------------------------------------------------------------------
// | TOPThink [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2010 http://topthink.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <*****@*****.**> <http://www.zjzit.cn>
// +----------------------------------------------------------------------
// | ImageImagick.class.php 2013-03-06
// +----------------------------------------------------------------------
namespace CLib\Image;

c_lib()->load('image');
use CLib\Image;
use CLib\ImageInterface;
class Imagick implements ImageInterface
{
    /**
     * 图像资源对象
     * @var \Imagick
     */
    private $img;
    /**
     * 图像信息,包括width,height,type,mime,size
     * @var array
     */
    private $info;
    /**
Ejemplo n.º 13
0
<?php

/**
 * Created by PhpStorm.
 * User: hzy
 * Date: 14-2-8
 * Time: 下午10:07
 */
namespace CLib\Session;

c_lib()->load('session');
use CLib\SessionInterface;
/**
 * 使用自带的本地存储Session
 * Class Local
 * @package CLib\Session
 */
class Local implements SessionInterface
{
    private $flag = false;
    /**
     * 启动Session
     * @param array $cfg
     */
    public function __construct($cfg = [])
    {
        $config = ['lifetime' => 0, 'path' => NULL, 'domain' => NULL, 'secure' => false, 'httponly' => true];
        $config = array_merge($config, $cfg);
        session_set_cookie_params($config['lifetime'], $config['path'], $config['domain'], $config['secure'], $config['httponly']);
        if (session_status() === PHP_SESSION_DISABLED || session_id() === "") {
            //Session未启用
Ejemplo n.º 14
0
 /**
  * 插入评论内容
  * @param string $content
  * @param int    $parent
  * @param int    $parent_top
  * @param int    $user_id
  * @return int
  */
 private function insert_comment($content, $parent, $parent_top, $user_id)
 {
     c_lib()->load('input');
     $input = new Input();
     $ip = $input->getIp()->binIp();
     $ua = $input->getUA();
     $write = $this->db->getWriter();
     $write->pdo->beginTransaction();
     $info = ['users_id' => $user_id, 'comment_content' => $content, 'comment_time' => $input->time(), 'comment_parent' => $parent ? $parent : NULL, 'comment_parent_top' => $parent_top ? $parent_top : NULL, 'comment_ip' => $ip, 'comment_agent' => $ua];
     $info['comment_status'] = $this->get_comment_status($info);
     $comment_id = $write->insert("comments", $info);
     if ($comment_id < 1) {
         $write->pdo->rollBack();
         Log::write(implode(",", $write->error()), Log::SQL);
         $this->throwMsg(-5);
     }
     $has_flag = $write->insert($this->relation_table, ['comments_id' => $comment_id, $this->relation_field => $this->id, 'users_id' => $user_id, 'object_users_id' => $this->get_object_users_id()]);
     if ($has_flag < 0) {
         $write->pdo->rollBack();
         Log::write(implode(",", $write->error()), Log::SQL);
         $this->throwMsg(-6);
     }
     $write->pdo->commit();
     $rt = $this->comment_hook($content, $parent, $parent_top, $user_id);
     if ($parent != 0) {
         hook()->apply('Comment_reply', $rt, $this->comment_type, $this->id, $user_id, $parent, $parent_top, $content);
     }
     return $comment_id;
 }
Ejemplo n.º 15
0
<?php

/**
 * Created by PhpStorm.
 * User: hzy
 * Date: 14-2-6
 * Time: 上午11:21
 */
namespace ULib;

if (!class_exists('\\ULib\\UserCheck')) {
    lib()->load('UserCheck');
}
if (!class_exists('\\CLib\\Ip')) {
    c_lib()->load('ip');
}
use Core\Log;
use ULib\UserCheck;
use CLib\Ip;
/**
 * 用户注册类
 * Class UserRegister
 * @package ULib
 */
class UserRegister
{
    /**
     * 对应的激活信息
     * @var string
     */
    private $activation_msg = "Unknown";
Ejemplo n.º 16
0
<?php

namespace CLib\PCache;

c_lib()->load('pcache');
use CLib\PCacheInterface;
/**
 * 文件缓存驱动
 * Class File
 * @package CLib\Cache
 */
class File implements PCacheInterface
{
    function __construct($config)
    {
        if (!is_dir(_Cache_ . "/out/00")) {
            $this->mk_cache_dir();
        }
    }
    /**
     * 生成临时文件目录
     * @throws \Exception 抛出异常信息
     */
    private function mk_cache_dir()
    {
        if (!is_writable(_Cache_ . "/out/")) {
            throw new \Exception(_("Page cache path can't write!"));
        }
        for ($i = 0; $i < 0xff; $i++) {
            $x = dechex($i);
            if (strlen($x) == 1) {
Ejemplo n.º 17
0
 /**
  * 邮件发送
  * @param string      $name
  * @param string      $email
  * @param string|null $title
  * @param string|null $textContent
  * @param bool        $queue
  * @throws \Exception
  */
 public function mailSend($name, $email, $title = NULL, $textContent = NULL, $queue = true)
 {
     if (!hook()->apply("MailTemplate_mailSend", true)) {
         //是否取消所有邮件发送记录
         Log::write(_("Mail send is cancel.") . print_r(func_get_args(), true), Log::NOTICE);
         return;
     }
     if (!$this->is_set_values) {
         $this->setValues([]);
     }
     try {
         c_lib()->load('mail');
         $mail = new Mail();
         if ($title === NULL) {
             $title = $this->title;
         }
         $mail->Subject = $title;
         $mail->addAddress($email, $name);
         $mail->msgHTML($this->content);
         if ($textContent === NULL) {
             $mail->AltBody = $this->text;
         } else {
             $mail->AltBody = $textContent;
         }
         if (hook()->apply('MailTemplate_mailSend_noQueue', !$queue)) {
             $mail->send();
         } else {
             lib()->load('Queue');
             $queue = new Queue();
             $mail_call = new MailCallback($mail);
             $queue->add($mail_call, NULL, ['lib' => ['MailTemplate'], 'c_lib' => ['mail']]);
         }
     } catch (\Exception $ex) {
         throw new \Exception(_("Mail Send Error.") . debug(" :" . $ex->getMessage()));
     }
 }
Ejemplo n.º 18
0
<?php

$config = file_get_contents(_SysPath_ . "/config.php");
header("Content-Type: text/plain; charset=utf-8");
if (isset($_POST['_Debug_'])) {
    $config = preg_replace("/define\\('_Debug_',([a-z0-9_ ]+?)\\);/", "define('_Debug_', " . var_export($_POST['_Debug_'] == 1, true) . ");", $config);
}
if (isset($_POST['COOKIE_PREFIX'])) {
    $config = preg_replace("/define\\('COOKIE_PREFIX',([\\s\\S]+?)\\);/", "define('COOKIE_PREFIX', " . var_export($_POST['COOKIE_PREFIX'], true) . ");", $config);
}
if (isset($_POST['COOKIE_KEY']) && strlen($_POST['COOKIE_KEY']) > 5) {
    $config = preg_replace("/define\\('COOKIE_KEY',([\\s\\S]+?)\\);/", "define('COOKIE_KEY', " . var_export($_POST['COOKIE_KEY'], true) . ");", $config);
} else {
    die("Cookie密钥不合法");
}
file_put_contents(_SysPath_ . "/config.php", $config);
if (!rename(_BasePath_ . "/install.php", _RootPath_ . "/install/install.php")) {
    die("文件移动失败");
}
if (isset($_POST['INSTALL_REMOVE']) && $_POST['INSTALL_REMOVE'] == "1") {
    c_lib()->load('file');
    $f = new \CLib\File();
    $f->path_remove(_RootPath_ . "/install", true);
}
file_put_contents(_RootPath_ . "/config/install.lock", "");
echo "true";
Ejemplo n.º 19
0
/**
 * cookie类
 *
 * @return \CLib\Cookie
 */
function ck()
{
    return c_lib()->using('cookie');
}
Ejemplo n.º 20
0
<?php

namespace CLib;

use Core\Log;
if (!defined('_CorePath_')) {
    exit;
}
c_lib()->load('interface/SqlInterface', 'medoo');
/**
 * Class Sql
 * @package CLib
 */
class Sql implements SqlInterface
{
    /**
     * 数据库连接状态
     * @var bool
     */
    private $status = false;
    /**
     * 连接的异常信息
     * @var string
     */
    private $ex_message = "";
    /**
     * @var \medoo
     */
    private $_reader = NULL;
    /**
     * @var \medoo
Ejemplo n.º 21
0
 /**
  * 登录限制
  * @param null $rt
  * @param User $user
  * @return null
  */
 public function message_login_restrictions($rt, $user)
 {
     try {
         if (!$this->notice($user->getId(), 'message', 'login_restrictions')) {
             return $rt;
         }
         $mt = new MailTemplate("message_notice/login_restrictions.md");
         $mt->setUserInfo($user->getInfo());
         c_lib()->load('input');
         $input = new Input();
         $mt->setValues(['login_ip' => $input->getRealIP(), 'login_ua' => $input->getUA(), 'login_count' => $user->getErrorLoginCount()]);
         $this->message->addNoticeMsg($mt->getTitle(), $mt->getContent(), $user->getId());
     } catch (\Exception $ex) {
         Log::write(_("NoticeApply message_login_restrictions create a Exception.") . "EX:[" . $ex->getCode() . "]:" . $ex->getMessage(), Log::NOTICE);
     }
     return $rt;
 }
Ejemplo n.º 22
0
<?php

c_lib()->load('sql');
$sql = new \CLib\Sql(cfg()->get('sql', 'write'), cfg()->get('sql', 'read'));
c_lib()->add("sql", $sql);
$option_setting = "INSERT INTO `options` (`option_name`,`option_value`,`option_autoload`)\nVALUES\n('site_title', '{title}', '1'),\n('site_desc', '{desc}', '1'),\n('site_url', '{url}', '1'),\n('admin_email', '{email}', '1'),\n('allowed_register', 'yes', '1'),\n('allowed_comment', 'yes', '1'),\n('default_avatar', 'default', '1'),\n('email_notice', 'yes', '1'),\n('site_style', 'default', '1'),\n('login_captcha', 'no', '1'),\n('picture_server', 'local', '1'),\n('image_thumbnail_width', '400', '1'),\n('image_thumbnail_height', '300', '1'),\n('image_hd_width', '1600', '1'),\n('image_display_width', '900', '1'),\n('comment_one_page', '5', '1'),\n('comment_order_desc', 'yes', '1'),\n('comment_deep', '8', '1'),\n('router_list', 'a:0:{}', '1'),\n('site_static_url', '{static_url}', '1'),\n('cdn', '', '1');";
$req = req()->_escape();
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
$post = $req->post('s');
foreach (['title', 'desc', 'url', 'email', 'static_url'] as $v) {
    if (!isset($post[$v]) || empty($post[$v])) {
        die("系统设置有空字段:" . $v);
    }
}
$user = $req->post('u');
lib()->load('UserCheck');
if (!\ULib\UserCheck::CheckUsernameChar($user['name'])) {
    die("用户名称检测错误");
}
$user['pwd'] = \ULib\UserCheck::MakeHashChar($user['pwd']);
$user['email'] = $post['email'];
if (!\ULib\UserCheck::CheckEmailChar($user['email'])) {
    die("管理员邮箱格式不正确");
}
$option_setting = str_replace(['{title}', '{desc}', '{url}', '{email}', '{static_url}'], [$post['title'], $post['desc'], $post['url'], $post['email'], $post['static_url']], $option_setting);
$pdo = $sql->getWriter();
$pdo->exec("delete from `options` where `id` > 0");
$pdo->exec("alter table `options` auto_increment=1;");
$pdo->exec($option_setting);
lib()->load('UserRegister', 'UserCheck', 'User');
Ejemplo n.º 23
0
 /**
  * @param User $user
  */
 public function upload_avatar($user)
 {
     c_lib()->load('upload');
     $upload = new Upload(['root_path' => 'avatar', 'exts' => ['jpg', 'png'], 'sub_status' => false, 'name_callback' => [function ($param) {
         return $param;
     }, $user->getId()], 'replace' => true, 'max_size' => 500 * 1024, 'save_ext' => 'jpg'], 'Local');
     if (!isset($_FILES['avatar'])) {
         $this->throwMsg(-16);
     }
     $info = $upload->uploadOne($_FILES['avatar']);
     lib()->load('Avatar');
     $avatar = new Avatar();
     $avatar->process_avatar($info['save_name'], 400, 400);
 }
Ejemplo n.º 24
0
 /**
  * 对本地图片做缩略图处理
  * @param string $path
  * @param array  $server_meta
  * @return array
  */
 private function makeThumbnail($path, $server_meta)
 {
     $rt = [];
     if (isset($server_meta['server_root_path'])) {
         $root = $server_meta['server_root_path'];
         $img_path = $root . "/" . $path;
         if (is_file($img_path) && is_readable($img_path)) {
             try {
                 c_lib()->load('image');
                 $img = new Image(Image::IMAGE_GD, $img_path);
                 $img_w = $img->width();
                 $img_h = $img->height();
                 $x = $img_w / $img_h;
                 //创建高清图
                 if ($img_w > image_hd_width()) {
                     $img->thumb(image_hd_width(), image_hd_width() / $x, Image::IMAGE_THUMB_SCALE);
                     $t_path = "hd/" . dirname($path);
                     $this->createPath($root . "/" . $t_path);
                     $img->save($root . "/hd/" . $path);
                     $rt['pic_hd_path'] = "hd/" . $path;
                     $rt['pic_hd_width'] = $img->width();
                     $rt['pic_hd_height'] = $img->height();
                 } else {
                     $rt['pic_hd_path'] = $path;
                 }
                 //创建显示图
                 if ($img_w > image_display_width()) {
                     $img->thumb(image_display_width(), image_display_width() / $x, Image::IMAGE_THUMB_SCALE);
                     $t_path = "display/" . dirname($path);
                     $this->createPath($root . "/" . $t_path);
                     $img->save($root . "/display/" . $path);
                     $rt['pic_display_path'] = "display/" . $path;
                     $rt['pic_display_width'] = $img->width();
                     $rt['pic_display_height'] = $img->height();
                 } else {
                     $rt['pic_display_path'] = $path;
                 }
                 //创建缩略图
                 $img_w = $img->width();
                 $c_w = image_thumbnail_width();
                 $c_h = image_thumbnail_height();
                 $img_h = $img->height();
                 if ($img_w < $c_w) {
                     //目标图片宽度小于缩略图
                     $img_w = $c_w;
                     $img_h = $img_h * $c_w / $img_w;
                 }
                 if ($img_h < $c_h) {
                     //目标图片高度小于缩略图
                     $img_h = $c_h;
                     $img_w = $img_w * $c_h / $img_h;
                 }
                 //if($img_w / $img_h < $c_w / $c_h){
                 if ($img_w * $c_h < $c_w * $img_h) {
                     //化简表达
                     $x_w = $img_w;
                     $x_h = ceil($x_w * $c_h / $c_w);
                 } else {
                     $x_h = $img_h;
                     $x_w = ceil($x_h * $c_w / $c_h);
                 }
                 Log::write(print_r(get_defined_vars(), true));
                 $img->thumb($x_w, $x_h, Image::IMAGE_THUMB_CENTER);
                 Log::write(print_r(get_defined_vars(), true));
                 //$img->thumb($c_w, $c_h, Image::IMAGE_THUMB_SCALE);
                 $t_path = "thumbnail/" . dirname($path);
                 $this->createPath($root . "/" . $t_path);
                 $img->save($root . "/thumbnail/" . $path);
                 $rt['pic_thumbnails_path'] = "thumbnail/" . $path;
                 $rt['pic_thumbnails_width'] = $c_w;
                 $rt['pic_thumbnails_height'] = $c_h;
             } catch (\Exception $ex) {
                 return [];
             }
         }
     }
     return $rt;
 }
Ejemplo n.º 25
0
<?php

c_lib()->load('sql', 'char');
$sql = new \CLib\Sql(cfg()->get('sql', 'write'), cfg()->get('sql', 'read'));
$status = $sql->status();
$next = true;
if (include_once __DIR__ . "/check_system.php") {
    ?>
	<h2>第一步,配置数据库</h2>

	<?php 
    if ($status) {
        echo "<p class='well well-sm text-success'>" . (cfg()->get('sql', 'read') !== NULL ? "[Read]" : "") . "数据库已连接,请继续下一步。</p>";
    } else {
        $next = false;
        $err = $sql->ex_message();
        $err = \CLib\Char::Convert(\CLib\Char::GetCoding($err), "UTF-8", $err);
        echo "<p class='well text-danger'>" . (cfg()->get('sql', 'read') !== NULL ? "[Read]" : "") . "数据库连接失败,请检查配置文件,手动修改对应属性,请优先保证写数据库正常!<br />错误信息:{$err}</p>";
    }
    if (cfg()->get('sql', 'read') !== NULL) {
        if (!$sql->open_write()) {
            $next = false;
            $err = $sql->ex_message();
            $err = \CLib\Char::Convert(\CLib\Char::GetCoding($err), "UTF-8", $err);
            echo "<p class='well text-danger'>[Write]写数据库异常,请保证写数据库能正常连接!<br>错误信息:{$err}</p>";
        } else {
            echo "<p class='well well-sm text-success'>[Write]数据库已连接,请继续下一步。</p>";
        }
    }
    if ($next) {
        $session->set('install', ['number' => '2', 'list' => []]);
Ejemplo n.º 26
0
 /**
  * 执行回调
  * @param int    $id 队列的ID
  * @param string $callback
  * @param string $param
  * @param string $library
  * @throws \Exception
  */
 public function exec($id, $callback, $param, $library)
 {
     $lib = @unserialize($library);
     //首先加载反序列化所需的类库
     if (isset($lib['lib']) && is_array($lib['lib'])) {
         call_user_func_array([lib(), 'load'], $lib['lib']);
     }
     if (isset($lib['c_lib']) && is_array($lib['c_lib'])) {
         call_user_func_array([c_lib(), 'load'], $lib['c_lib']);
     }
     /**
      * 对回调函数反序列化
      * @var QueueCallback $call
      */
     $call = @unserialize($callback);
     if (!is_object($call)) {
         //初步判断是否为对象
         throw new \Exception(_("unserialize error"));
     }
     $ref = new \ReflectionClass($call);
     if (!in_array("ULib\\QueueCallback", $ref->getInterfaceNames())) {
         //检测是否为正确的实现了接口
         throw new \Exception(_("callback class error."));
     }
     //最后执行,并使用对应的参数
     @$call->run($id, @unserialize($param));
 }
Ejemplo n.º 27
0
 public function process_avatar($file, $width)
 {
     c_lib()->load('image');
     $image = new Image(Image::IMAGE_GD);
     $image->open(_BasePath_ . "/avatar/" . $file);
     $img_w = $image->width();
     $img_h = $image->height();
     $x = $img_h / $img_w;
     $x_h = $img_h < $img_w ? $width / $x : $width * $x;
     $image->thumb($x_h, $x_h, Image::IMAGE_THUMB_SCALE);
     $image->thumb($width, $width, Image::IMAGE_THUMB_CENTER);
     $image->save(_BasePath_ . "/avatar/" . $file, 'jpeg');
     $this->clearOtherAvatar($file);
 }
Ejemplo n.º 28
0
 /**
  * @param null $files
  * @throw \Exception
  * @return array
  */
 public function upload($files = NULL)
 {
     if (empty($files)) {
         $files = $_FILES;
     }
     if (empty($files)) {
         $this->throwMsg(-2);
     }
     if (!$this->uploader->checkRootPath($this->root_path)) {
         $this->throwMsg(1);
     }
     if (!$this->uploader->checkSavePath($this->save_path)) {
         $this->throwMsg(1);
     }
     /* 逐个检测并上传文件 */
     $info = array();
     if (function_exists('finfo_open')) {
         $finfo = finfo_open(FILEINFO_MIME_TYPE);
     }
     // 对上传文件数组信息处理
     $files = $this->dealFiles($files);
     foreach ($files as $key => $file) {
         if (!isset($file['key'])) {
             $file['key'] = $key;
         }
         /* 通过扩展获取文件类型,可解决FLASH上传$FILES数组返回文件类型错误的问题 */
         if (isset($finfo)) {
             $file['type'] = @finfo_file($finfo, $file['tmp_name']);
         }
         /* 获取上传文件后缀,允许上传无后缀文件 */
         $file['ext'] = pathinfo($file['name'], PATHINFO_EXTENSION);
         /* 文件上传检测 */
         if (!$this->check($file)) {
             continue;
         }
         /* 获取文件hash */
         if ($this->make_hash) {
             $file['md5'] = md5_file($file['tmp_name']);
             $file['sha1'] = sha1_file($file['tmp_name']);
         }
         /* 生成保存文件名 */
         $save_name = $this->getSaveName($file);
         if (false == $save_name) {
             continue;
         } else {
             $file['save_name'] = $save_name;
         }
         /* 检测并创建子目录 */
         $sub_path = $this->get_sub_path($file);
         if (false === $sub_path) {
             continue;
         } else {
             $file['save_path'] = $this->savePath . $sub_path;
         }
         /* 对图像文件进行严格检测 */
         $ext = strtolower($file['ext']);
         if (in_array($ext, array('gif', 'jpg', 'jpeg', 'bmp', 'png', 'swf'))) {
             $imginfo = getimagesize($file['tmp_name']);
             if (empty($imginfo) || $ext == 'gif' && empty($imginfo['bits'])) {
                 $this->error = _('Illegal image file!');
                 continue;
             }
             if ($this->image_info) {
                 $file['image'] = [];
                 c_lib()->load('image');
                 $image = new Image(Image::IMAGE_GD, $file['tmp_name']);
                 $file['image']['width'] = $image->width();
                 $file['image']['height'] = $image->height();
                 unset($image);
             }
         }
         /* 保存文件 并记录保存成功的文件 */
         if ($this->uploader->save($file, $this->replace)) {
             unset($file['error'], $file['tmp_name']);
             $info[$key] = $file;
         } else {
             $this->error = $this->uploader->getError();
         }
     }
     if (empty($info)) {
         $this->throwMsg(2);
     }
     return $info;
 }
Ejemplo n.º 29
0
<?php

/**
 * 参考ThinkPHP
 */
namespace CLib\Upload;

use CLib\UploadInterface;
c_lib()->load('upload');
class Qiniu implements UploadInterface
{
    /**
     * 上传文件根目录
     * @var string
     */
    private $rootPath;
    /**
     * 上传错误信息
     * @var string
     */
    private $error = '';
    private $config = array('secrectKey' => '', 'accessKey' => '', 'bucket' => '', 'domain' => '', 'timeout' => 300);
    public function checkPath($path)
    {
        return true;
    }
    /**
     * 构造函数,用于设置上传根路径
     * @param string $root_path
     * @param array  $config FTP配置
     */
Ejemplo n.º 30
0
/**
 * 获取SESSION对象实例
 * @return \CLib\Session
 */
function session_class()
{
    static $session = NULL;
    if ($session !== NULL) {
        return $session;
    }
    $lib = c_lib();
    $session = $lib->using('CSession');
    if ($session === false) {
        $lib->load('session')->add("CSession", new \CLib\Session());
        $session = $lib->using("CSession");
    }
    return $session;
}