Ejemplo n.º 1
0
<?php

namespace Plugins\Test;

require_once path_a('/Plugins/Plugin.class.php');
class TestPlugin extends \Plugins\Plugin
{
    protected $config = array('version' => '1.0', 'author' => '[PLUGIN_AUTHOR]', 'name' => '[PLUGIN_TITLE]', 'descr' => '[PLUGIN_DESCR]');
    //钩子默认的调用方法
    public function run($a = '', $b = '')
    {
        $this->assign('a', $a);
        $this->assign('b', $b);
        $this->display('content');
    }
    public function getConfig()
    {
        return $this->config;
    }
    public function install()
    {
        //向后台添加菜单,如果不添加的话直接返回真
        $data = array('title' => '测试插件', 'pid' => ADDONS_MENU, 'url' => 'Addons/plugin?pn=Test&pm=set', 'group' => '已装插件', 'type' => 'Test');
        //添加到数据库
        if (M('Menu')->add($data)) {
            return true;
        } else {
            return false;
        }
    }
    public function uninstall()
Ejemplo n.º 2
0
 function createthumb()
 {
     if (IS_POST) {
         $info = array('status' => 2, 'info' => '', 'url' => '');
         $arccatid = I('post.article_catid');
         $catid = I('post.category_d');
         //查询是否有没有处理完的图片
         $thumbpath = F('thumbpath');
         if (empty($thumbpath)) {
             //开始查询要处理的图片数据
             $temarr = array();
             $map['pic'] = array('neq', 0);
             if ($arccatid != 0) {
                 $map['category_id'] = $arccatid;
             }
             $list = M('Article')->where($map)->field('pic')->select();
             foreach ($list as $val) {
                 $temarr[] = $val['pic'];
             }
             if ($catid != 0) {
                 $map['category_id'] = $catid;
             }
             $list = M('goods')->where($map)->field('pic,xc')->select();
             foreach ($list as $val) {
                 $temarr[] = $val['pic'];
                 //拆分相册
                 $xcarr = explode('|', $val['xc']);
                 foreach ($xcarr as $val) {
                     $temarr[] = $val;
                 }
             }
             //把查到的数量保存到缓存中
             F('thumbpath', $temarr);
             $thumbpath = $temarr;
         }
         //开始生成图片
         $jishu = 0;
         //处理的总数量
         $sucstr = '';
         //成功字符串
         $failjishu = 0;
         //失败的数量
         $failstr = '';
         //错误字符串
         $num = count($thumbpath);
         $num = $num > 50 ? 50 : $num;
         //一次只处理50个数据
         $i = 0;
         for ($i; $i < $num; $i++) {
             if (count($thumbpath) > 0) {
                 $spath = get_picture($thumbpath[$i], 'path');
                 $thupath = str_replace('image/', 'image/thumb/', $spath);
                 $spath = path_a($spath);
                 $dpath = str_replace('image/', 'image/thumb/', $spath);
                 if (file_exists($spath)) {
                     //源文件存在
                     if (file_exists($dpath)) {
                         unlink($dpath);
                     }
                     $result = create_thumb($spath, $dpath, C('THUMB_WIDTH'), C('THUMB_HEIGHT'));
                     if ($result === true) {
                         M('Picture')->where("id={$thumbpath[$i]}")->save(array('thumbpath' => $thupath));
                         $jishu++;
                         $sucstr .= $spath . '->' . $dpath . '<br>';
                     } else {
                         $failjishu++;
                         $failstr .= $spath . '->' . $dpath . '<br>';
                     }
                 } else {
                     $failjishu++;
                     $failstr .= '<span style="color:red;">' . $spath . "此路径文件丢失数据库id为{$thumbpath[$i]}请联系管理员自行处理</span><br>";
                 }
                 unset($thumbpath[$i]);
             }
         }
         $tishistr = '全部完成';
         if (count($thumbpath) <= 0) {
             $info['status'] = 1;
         } else {
             $tishistr = '还剩' . count($thumbpath) . '个。继续生成中......';
         }
         F('thumbpath', array_values($thumbpath));
         $info['info'] = "成功生成{$jishu}个缩略图,失败{$failjishu}个,{$failstr},{$tishistr}";
         $this->ajaxreturn($info);
         exit;
     } else {
         //文章分类树
         $catelist = F('sys_category_tree');
         if (empty($catelist)) {
             $catelist = F_get_cate_list(true, 'article');
             F('sys_category_tree', $catelist);
         }
         $catelist[0] = '全部分类';
         $field = array(array('field' => 'arccat_catid', 'name' => 'arccat_catid', 'type' => 'select', 'title' => '文章分类', 'note' => '', 'extra' => $catelist, 'is_show' => 3));
         $this->assign('fieldarr1', $field);
         $this->display();
     }
 }
Ejemplo n.º 3
0
/**
 * 获取图片
 * @param int $id
 * @param string $field
 * @return 完整的数据  或者  指定的$field字段值
 * @author huajie <*****@*****.**>
 */
function get_picture($id = null, $field = null, $wh = null)
{
    $revalue = '';
    $id = trim($id);
    if (empty($id)) {
        $revalue = false;
    }
    if (is_numeric($id)) {
        $cakey = md5($id . '_' . $field . '_' . $wh);
        //$revalue=F('_picture/'.$cakey);
        $pkey = '_picture/' . $id % 100;
        $picarr = F($pkey);
        $revalue = $picarr[$cakey];
        if (empty($revalue) || APP_DEBUG) {
            $picture = M('Picture')->where(array('status' => 1))->getById($id);
            if (!empty($field) && !empty($wh)) {
                $wharr = explode('_', $wh);
                if (count($wharr == 2)) {
                    $revalue = str_replace('/Uploads/image/', IMAGE_CACHE_DIR, $picture['path']);
                    $revalue = substr($revalue, 0, strrpos($revalue, '.')) . '_' . $wh . substr($revalue, strrpos($revalue, '.'));
                    //判断之前是不是已经生成
                    if (!file_exists(path_a($revalue))) {
                        $result = create_thumb(path_a($picture['path']), path_a($revalue), $wharr[0], $wharr[1]);
                        if ($result !== true) {
                            $revalue = $picture['path'];
                        }
                    }
                }
            } else {
                if (!empty($field)) {
                    $revalue = $picture[$field];
                    if ($field == 'thumbpath') {
                        if (!file_exists(path_a($revalue))) {
                            $result = create_thumb(path_a($picture['path']), path_a($revalue), C('THUMB_WIDTH'), C('THUMB_HEIGHT'));
                            if ($result !== true) {
                                $revalue = $picture['path'];
                            }
                        }
                    }
                } else {
                    $revalue = $picture['path'];
                }
            }
            $picarr[$cakey] = $revalue;
            F($pkey, $picarr);
        }
    } else {
        $revalue = $id;
    }
    return empty($revalue) ? '' : path_r($revalue);
}
Ejemplo n.º 4
0
/**
 * 查找文件并返回路径
 * @param  string $filename [description]
 * @return [type]           [description]
 */
function find_file_path($filename = '')
{
    if (empty($filename)) {
        return '';
    }
    $dirarr = array(C('TMPL_PARSE_STRING.__JS__'), C('TMPL_PARSE_STRING.__CSS__'), C('TMPL_PARSE_STRING.__STATIC__') . '/js', C('TMPL_PARSE_STRING.__STATIC__') . '/css', __ROOT__ . '/Public/' . MODULE_NAME . '/' . C('DEFAULT_THEME'), C('TMPL_PARSE_STRING.__STATIC__'));
    foreach ($dirarr as $key => $value) {
        $filepath = $value . '/' . $filename;
        // \Think\Log::write($filepath, 'WARN');
        if (file_exists(path_a($filepath))) {
            return $filepath;
        }
    }
    return 'http://' . $filename;
}