contentEx = array('HighSlide_Plugin','autohighslide'); Typecho_Plugin::factory('Widget_Abstract_Contents')->excerptEx = array('HighSlide_Plugin','autohighslide'); Typecho_Plugin::factory('Widget_Upload')->deleteHandle = array('HighSlide_Plugin','deleteHandle'); Typecho_Plugin::factory('Widget_Archive')->header = array('HighSlide_Plugin','headlink'); Typecho_Plugin::factory('Widget_Archive')->footer = array('HighSlide_Plugin','footlink'); Typecho_Plugin::factory('admin/write-post.php')->bottom = array('HighSlide_Plugin','attachpanel'); Typecho_Plugin::factory('admin/write-page.php')->bottom = array('HighSlide_Plugin','attachpanel'); return self::galleryinstall(); } /** * 禁用插件方法,如果禁用失败,直接抛出异常 * * @static * @access public * @return void * @throws Typecho_Plugin_Exception */ public static function deactivate() { Helper::removePanel(3,'HighSlide/manage-gallery.php'); Helper::removeAction('gallery-edit'); } /** * 获取插件配置面板 * * @access public * @param Typecho_Widget_Helper_Form $form 配置面板 * @return void */ public static function config(Typecho_Widget_Helper_Form $form) { $mode = new Typecho_Widget_Helper_Form_Element_Radio('mode', array('highslide.packed.js'=>_t('基础版 (25.2K)仅支持插图弹窗'),'highslide-full.packed.js'=>_t('全功能版 (46.8K)支持html弹窗/插图幻灯/页面相册等')),'highslide.packed.js',_t('核心选择')); $form->addInput($mode); $rpopt = new Typecho_Widget_Helper_Form_Element_Checkbox('rpopt', array('link'=>_t('链接至图片'),'img'=>_t('所有图片')),NULL,_t('弹窗模式'),_t('默认将目标为图片的超链接(包括文字)转化为弹窗效果,也可以选择将所有图片直接转化为原图弹窗')); $rpopt->input->setAttribute('disabled','true'); $form->addInput($rpopt); $rplist = new Typecho_Widget_Helper_Form_Element_Checkbox('rplist', array('index'=>_t('首页'),'post'=>_t('文章'),'page'=>_t('独立页面'),'archive'=>_t('归档页面')),array('index','post','page'),_t('应用范围'),_t('取消勾选的页面类型将不会加载插件脚本与替换效果, 归档页包括按时间/标签等索引的列表型页面')); $form->addInput($rplist); $outline= new Typecho_Widget_Helper_Form_Element_Radio('outline', array(''=>_t('无边框'),'rounded-white'=>_t('圆角白'),'rounded-black'=>_t('圆角黑'),'glossy-dark'=>_t('亮泽黑'),'outer-glow'=>_t('外发光'),'beveled'=>_t('半透明')),'',_t('边框风格')); $form->addInput($outline); $cbutton = new Typecho_Widget_Helper_Form_Element_Radio('cbutton', array(1=>_t('显示'),0=>_t('不显示')),0,_t('关闭按钮')); $form->addInput($cbutton); $ltext = new Typecho_Widget_Helper_Form_Element_Text('ltext', NULL,'© '.$_SERVER['HTTP_HOST'].'',_t('角标文字')); $ltext->input->setAttribute('class','mini'); $form->addInput($ltext); $lpos = new Typecho_Widget_Helper_Form_Element_Select('lpos', array('top left'=>_t('左上'),'top center'=>_t('中上'),'top right'=>_t('右上'),'bottom left'=>_t('左下'),'bottom center'=>_t('中下'),'bottom right'=>_t('右下')),'top left',''); $lpos->input->setAttribute('style','position:absolute;bottom:16px;left:173px;'); $lpos->setAttribute('style','position:relative'); $form->addInput($lpos); $capt = new Typecho_Widget_Helper_Form_Element_Radio('capt', array(''=>_t('不显示'),'this.a.title'=>_t('显示链接title'),'this.thumb.alt'=>_t('显示图片alt')),'',_t('图片说明'),_t('例:%s图片说明写这%s或者写这显示%s',' <a href="http://xx.jpg" title="','"><img src="http://xxx.jpg" alt="','"/></a>')); $form->addInput($capt); $lang = new Typecho_Widget_Helper_Form_Element_Radio('lang', array('en'=>_t('英文'),'cn'=>_t('中文')),'en',_t('提示语言'),'

'._t('全功能版设置').' ———————————————————————————————————————

'); $form->addInput($lang); $fullalign = new Typecho_Widget_Helper_Form_Element_Radio('fullalign', array('default'=>_t('触发位置'),'center'=>_t('页面居中')),'default',_t('弹窗定位')); $form->addInput($fullalign); $fullopac = new Typecho_Widget_Helper_Form_Element_Text('fullopac', NULL,'0.65',_t('背景遮罩'),_t('从透明至纯黑, 可填写0至1间的小数')); $fullopac->input->setAttribute('class','mini'); $form->addInput($fullopac->addRule('isFloat',_t('请填写数字'))); $fullslide = new Typecho_Widget_Helper_Form_Element_Radio('fullslide', array(1=>_t('开启'),0=>_t('关闭')),1,_t('幻灯面板')); $form->addInput($fullslide); $fullnextimg = new Typecho_Widget_Helper_Form_Element_Radio('fullnextimg', array(1=>_t('是'),0=>_t('否')),0,_t('自动翻页'),_t('点击图片不关闭弹窗而是显示下一张')); $form->addInput($fullnextimg); $fullcpos = new Typecho_Widget_Helper_Form_Element_Radio('fullcpos', array(''=>_t('不显示'),'caption'=>_t('底部显示'),'heading'=>_t('顶部显示')),'',_t('图片序数')); $form->addInput($fullcpos); $fullwrap = new Typecho_Widget_Helper_Form_Element_Checkbox('fullwrap', array('draggable-header'=>_t('显示标题栏%s如: %s标题%s',' ','<hs title="','">'),'no-footer'=>_t('禁用拉伸')),NULL,_t('html弹窗')); $form->addInput($fullwrap); //输出面板效果 ?> addInput($gallery); $thumbfix = new Typecho_Widget_Helper_Form_Element_Hidden('thumbfix', array('fixedwidth','fixedheight','fixedratio'),'fixedwidth'); $form->addInput($thumbfix); $fixedwidth = new Typecho_Widget_Helper_Form_Element_Hidden('fixedwidth',NULL,'200'); $form->addInput($fixedwidth); $fixedheight = new Typecho_Widget_Helper_Form_Element_Hidden('fixedheight',NULL,'100'); $form->addInput($fixedheight); $fixedratio = new Typecho_Widget_Helper_Form_Element_Hidden('fixedratio',NULL,'4:3'); $form->addInput($fixedratio); $thumbapi = new Typecho_Widget_Helper_Form_Element_Hidden('thumbapi', array(0,1),0); $form->addInput($thumbapi); $storage = new Typecho_Widget_Helper_Form_Element_Hidden('storage', array('local','qiniu','scs','nos','cos'),'local'); $form->addInput($storage); $path = new Typecho_Widget_Helper_Form_Element_Hidden('path',NULL,'/usr/uploads/HSgallery/'); $form->addInput($path); $cloudtoo = new Typecho_Widget_Helper_Form_Element_Hidden('cloudtoo', array(0,1),0); $form->addInput($cloudtoo); $qiniubucket = new Typecho_Widget_Helper_Form_Element_Hidden('qiniubucket',NULL,''); $form->addInput($qiniubucket); $qiniudomain = new Typecho_Widget_Helper_Form_Element_Hidden('qiniudomain',NULL,'http://'); $form->addInput($qiniudomain); $qiniuak = new Typecho_Widget_Helper_Form_Element_Hidden('qiniuak',NULL,''); $form->addInput($qiniuak); $qiniusk = new Typecho_Widget_Helper_Form_Element_Hidden('qiniusk',NULL,''); $form->addInput($qiniusk); $scsbucket = new Typecho_Widget_Helper_Form_Element_Hidden('scsbucket',NULL,''); $form->addInput($scsbucket); $scsdomain = new Typecho_Widget_Helper_Form_Element_Hidden('scsdomain',NULL,'http://'); $form->addInput($scsdomain); $scsimgx = new Typecho_Widget_Helper_Form_Element_Hidden('scsimgx',NULL,'http://*.applinzi.com|*'); $form->addInput($scsimgx); $scsak = new Typecho_Widget_Helper_Form_Element_Hidden('scsak',NULL,''); $form->addInput($scsak); $scssk = new Typecho_Widget_Helper_Form_Element_Hidden('scssk',NULL,''); $form->addInput($scssk); $nosbucket = new Typecho_Widget_Helper_Form_Element_Hidden('nosbucket',NULL,''); $form->addInput($nosbucket); $nosdomain = new Typecho_Widget_Helper_Form_Element_Hidden('nosdomain',NULL,'http://'); $form->addInput($nosdomain); $nosak = new Typecho_Widget_Helper_Form_Element_Hidden('nosak',NULL,''); $form->addInput($nosak); $nosas = new Typecho_Widget_Helper_Form_Element_Hidden('nosas',NULL,''); $form->addInput($nosas); $nosep = new Typecho_Widget_Helper_Form_Element_Hidden('nosep', array('nos-eastchina1.126.net'),'nos-eastchina1.126.net'); $form->addInput($nosep); $cosbucket = new Typecho_Widget_Helper_Form_Element_Hidden('cosbucket',NULL,''); $form->addInput($cosbucket); $cosdomain = new Typecho_Widget_Helper_Form_Element_Hidden('cosdomain',NULL,'http://*.image.myqcloud.com'); $form->addInput($cosdomain); $cosai = new Typecho_Widget_Helper_Form_Element_Hidden('cosai',NULL,''); $form->addInput($cosai); $cossi = new Typecho_Widget_Helper_Form_Element_Hidden('cossi',NULL,''); $form->addInput($cossi); $cossk = new Typecho_Widget_Helper_Form_Element_Hidden('cossk',NULL,''); $form->addInput($cossk); $cosrg = new Typecho_Widget_Helper_Form_Element_Hidden('cosrg',array('sh','gz','cd','tj','bj','sgp','hk','ca','ger'),'sh'); $form->addInput($cosrg); } /** * 个人用户的配置面板 * * @access public * @param Typecho_Widget_Helper_Form $form * @return void */ public static function personalConfig(Typecho_Widget_Helper_Form $form){} /** * 初始化数据表 * * @access public * @return string * @throws Typecho_Plugin_Exception */ public static function galleryinstall() { $installdb = Typecho_Db::get(); $type = array_pop(explode('_',$installdb->getAdapterName())); $prefix = $installdb->getPrefix(); $scripts = file_get_contents('usr/plugins/HighSlide/'.$type.'.sql'); $scripts = explode(';',str_replace('%charset%','utf8',str_replace('typecho_',$prefix,$scripts))); try { foreach ($scripts as $script) { $script = trim($script); if ($script) { $installdb->query($script,Typecho_Db::WRITE); } } return _t('建立页面相册数据表, 插件启用成功'); } catch (Typecho_Db_Exception $e) { $code = $e->getCode(); if (('Mysql'==$type && ('42S01'==$code || 1050==$code)) || ('SQLite'==$type && ('HY000'==$code || 1==$code))) { try { $script = 'SELECT `gid`,`name`,`thumb`,`sort`,`image`,`description`,`order` from `'.$prefix.'gallery`'; $installdb->query($script,Typecho_Db::READ); return _t('检测到页面相册数据表, 插件启用成功'); } catch (Typecho_Db_Exception $e) { $code = $e->getCode(); throw new Typecho_Plugin_Exception(_t('数据表检测失败, 插件启用失败. 错误号: '.$code)); } } else { throw new Typecho_Plugin_Exception(_t('数据表建立失败, 插件启用失败. 错误号: '.$code)); } } } /** * 调取七牛许可 * * @access public * @param string $key,$secret * @return Qiniu\Auth */ public static function qiniuset($key,$secret) { require_once('cloud/qiniu/autoload.php'); return new Qiniu\Auth($key,$secret); } /** * 调取新浪云SCS许可 * * @access public * @param string $key,$secret * @return SCS */ public static function scsset($key,$secret) { require_once('cloud/scs/SCS.php'); return new SCS($key,$secret); } /** * 调取网易云NOS许可 * * @access public * @param string $key,$secret,$endpoint * @return NOS\NosClient */ public static function nosset($key,$secret,$endpoint) { require_once('cloud/nos/autoload.php'); return new NOS\NosClient($key,$secret,$endpoint); } /** * 调取腾讯云COS许可 * * @access public * @param string $region * @return qcloudcos\Cosapi */ public static function cosset($region) { require_once('cloud/cos/include.php'); qcloudcos\Cosapi::setRegion($region); return new qcloudcos\Cosapi(); } /** * 输出路由参数 * * @access public * @param string $url 原图地址 * @param boolean $isatt 是否来自附件 * @return Typecho_Config */ public static function route($url=NULL,$isatt=false) { $options = Helper::options(); $settings = $options->plugin('HighSlide'); $localsite = $options->siteUrl; $qiniusite = $settings->qiniudomain; $qiniusite = $qiniusite=='http://' ? '' : $qiniusite; $scssite = $settings->scsdomain; $scssite = $scssite && $scssite!=='http://' ? $scssite : 'http://'.$settings->scsbucket.'.cdn.sinacloud.net'; $nossite = $settings->nosdomain; $nossite = $nossite=='http://' ? '' : $nossite; $cossite = $settings->cosdomain; $cossite = $cossite!=='http://*.image.myqcloud.com' && $cossite!=='http://' ? $cossite : ''; //获取路径前缀 $dname = ''; $durl = ''; if ($url) { $source = parse_url($url); $dname = dirname($url); $durl = 0===strpos($dname,$localsite) ? $localsite : $source['scheme'].'://'.$source['host']; } //按储存来源获取地址 switch (true) { case !$url && $settings->storage=='local' || 0===strpos($url,$localsite) : $site = $localsite; $from = 'local'; break; case !$url && $settings->storage=='qiniu' || $qiniusite && 0===strpos($url,$qiniusite) : $site = $qiniusite; $from = 'qiniu'; break; case !$url && $settings->storage=='scs' || 0===strpos($url,$scssite) : if ($url) { $dname = dirname(str_replace($scssite,'',$url)); //fix 子目录 } $site = $scssite; $from = 'scs'; break; case !$url && $settings->storage=='nos' || $nossite && 0===strpos($url,$nossite) : $site = $nossite; $from = 'nos'; break; case !$url && $settings->storage=='cos' || $cossite && 0===strpos($url,$cossite) : $site = $cossite; $from = 'cos'; break; default : $site = ''; $from = ''; } $filedir = $isatt ? str_replace($durl,'',$dname.'/') : $settings->path; $filedir = substr(Typecho_Common::url($filedir,''),1); //处理"/"号 $filedir = $filedir ? $filedir : ''; return new Typecho_Config(array( 'dir'=>$filedir, 'url'=>$url ? $url : Typecho_Common::url($filedir,$site), 'site'=>$site, 'from'=>$from //判断url来源 )); } /** * 构建相册表单 * * @access public * @param string $action,$render * @return Typecho_Widget_Helper_Form */ public static function form($action=NULL,$render='g') { $options = Helper::options(); $settings = $options->plugin('HighSlide'); $security = Helper::security(); //图片编辑表单 $gform = new Typecho_Widget_Helper_Form($security->getIndex('/action/gallery-edit'), Typecho_Widget_Helper_Form::POST_METHOD); $image = new Typecho_Widget_Helper_Form_Element_Text('image', NULL,NULL,_t('原图地址*')); $gform->addInput($image); $thumb = new Typecho_Widget_Helper_Form_Element_Text('thumb', NULL,NULL,_t('缩略图地址*')); $gform->addInput($thumb); $name = new Typecho_Widget_Helper_Form_Element_Text('name', NULL,NULL,_t('图片名称')); $name->input->setAttribute('class','mini'); $gform->addInput($name); $description = new Typecho_Widget_Helper_Form_Element_Textarea('description', NULL,NULL,_t('图片描述'),_t('推荐填写, 用于展示相册中图片的文字说明效果')); $gform->addInput($description); $sort = new Typecho_Widget_Helper_Form_Element_Text('sort', NULL,'1',_t('相册组*'),_t('输入数字, 对应标签[GALLERY-数字]在页面调用')); $sort->input->setAttribute('class','w-10'); $gform->addInput($sort); $do = new Typecho_Widget_Helper_Form_Element_Hidden('do'); $gform->addInput($do); $gid = new Typecho_Widget_Helper_Form_Element_Hidden('gid'); $gform->addInput($gid); $submit = new Typecho_Widget_Helper_Form_Element_Submit(); $submit->input->setAttribute('class','btn'); $gform->addItem($submit); //相册设置表单 $sform = new Typecho_Widget_Helper_Form($security->getIndex('/action/gallery-edit?do=sync'), Typecho_Widget_Helper_Form::POST_METHOD); $gallery = new Typecho_Widget_Helper_Form_Element_Select('gallery', array('gallery-horizontal-strip'=>_t('连环画册'),'gallery-thumbstrip-above'=>_t('黑色影夹'),'gallery-vertical-strip'=>_t('时光胶带'),'gallery-in-box'=>_t('纯白记忆'),'gallery-floating-thumbs'=>_t('往事片段'),'gallery-floating-caption'=>_t('沉默注脚'),'gallery-controls-in-heading'=>_t('岁月名片'),'gallery-in-page'=>_t('幻影橱窗(单相册)')),$settings->gallery,_t('相册风格')); $sform->addInput($gallery); $thumboptions = array( 'fixedwidth'=>_t('固定宽度 %s',' '), 'fixedheight'=>_t('固定高度 %s',' '), 'fixedratio'=>_t('固定比例 %s',' '), ); $thumbfix = new Typecho_Widget_Helper_Form_Element_Radio('thumbfix', $thumboptions,$settings->thumbfix,_t('缩略图规格'),_t('宽高单位px不用填写, 比例带“:”号, 同步影响正文附件缩略图')); $sform->addInput($thumbfix->multiMode()); $thumbapi = new Typecho_Widget_Helper_Form_Element_Radio('thumbapi', array(0=>_t('本地GD库渲染'),1=>_t('云端API演算')),$settings->thumbapi,_t('缩略图生成方式'),_t('API方式将按照原图url生成访问缓存, 不会占用额外储存空间')); $sform->addInput($thumbapi); $storage = new Typecho_Widget_Helper_Form_Element_Radio('storage', array('local'=>_t('本地'),'qiniu'=>_t('七牛'),'scs'=>_t('新浪云SCS'),'nos'=>_t('网易云NOS'),'cos'=>_t('腾讯云COS')),$settings->storage,_t('储存位置%s','')); $storage->setAttribute('style','position:relative;font-size:98%'); //fix IE换行 $sform->addInput($storage); $path = new Typecho_Widget_Helper_Form_Element_Text('path', NULL,$settings->path,_t('路径前缀'),_t('“/”号结尾, 本地路径请确保可写, 云端前缀将忽略开头的“/”号')); $sform->addInput($path); $qiniubucket = new Typecho_Widget_Helper_Form_Element_Text('qiniubucket', NULL,$settings->qiniubucket,_t('空间名称')); $sform->addInput($qiniubucket); $qiniudomain = new Typecho_Widget_Helper_Form_Element_Text('qiniudomain', NULL,$settings->qiniudomain,_t('访问域名')); $sform->addInput($qiniudomain); $qiniuak = new Typecho_Widget_Helper_Form_Element_Text('qiniuak', NULL,$settings->qiniuak,_t('AccessKey')); $sform->addInput($qiniuak); $qiniusk = new Typecho_Widget_Helper_Form_Element_Text('qiniusk', NULL,$settings->qiniusk,_t('SecretKey')); $sform->addInput($qiniusk); $scsbucket = new Typecho_Widget_Helper_Form_Element_Text('scsbucket', NULL,$settings->scsbucket,_t('Bucket名称')); $sform->addInput($scsbucket); $scsdomain = new Typecho_Widget_Helper_Form_Element_Text('scsdomain', NULL,$settings->scsdomain,_t('绑定域名'),_t('未申请域名绑定留空即可')); $sform->addInput($scsdomain); $scsimgx = new Typecho_Widget_Helper_Form_Element_Text('scsimgx', NULL,$settings->scsimgx,_t('图片处理服务 (新Imgxs)'),_t('填写服务实例域名和源站标识用|号隔开, 留空则使用原imgx免费子域名API')); $sform->addInput($scsimgx); $scsak = new Typecho_Widget_Helper_Form_Element_Text('scsak', NULL,$settings->scsak,_t('Access Key')); $sform->addInput($scsak); $scssk = new Typecho_Widget_Helper_Form_Element_Text('scssk', NULL,$settings->scssk,_t('Secret Key')); $sform->addInput($scssk); $nosbucket = new Typecho_Widget_Helper_Form_Element_Text('nosbucket', NULL,$settings->nosbucket,_t('桶名称')); $sform->addInput($nosbucket); $nosdomain = new Typecho_Widget_Helper_Form_Element_Text('nosdomain', NULL,$settings->nosdomain,_t('域名')); $sform->addInput($nosdomain); $nosak = new Typecho_Widget_Helper_Form_Element_Text('nosak', NULL,$settings->nosak,_t('Access Key')); $sform->addInput($nosak); $nosas = new Typecho_Widget_Helper_Form_Element_Text('nosas', NULL,$settings->nosas,_t('Access Secret')); $sform->addInput($nosas); $nosep = new Typecho_Widget_Helper_Form_Element_Radio('nosep', array('nos-eastchina1.126.net'=>_t('华东1')),$settings->nosep, _t('数据中心')); $sform->addInput($nosep); $cosbucket = new Typecho_Widget_Helper_Form_Element_Text('cosbucket', NULL,$settings->cosbucket,_t('Bucket名称')); $sform->addInput($cosbucket); $cosdomain = new Typecho_Widget_Helper_Form_Element_Text('cosdomain', NULL,$settings->cosdomain,_t('访问域名'),_t('使用API方式生成缩略图须填写%s万象优图%s的图片处理/加速域名','','')); $sform->addInput($cosdomain); $cosai = new Typecho_Widget_Helper_Form_Element_Text('cosai', NULL,$settings->cosai,_t('APPID'),_t('可通过%s腾讯云控制台%s【账号信息】查看','','')); $sform->addInput($cosai); $cossi = new Typecho_Widget_Helper_Form_Element_Text('cossi', NULL,$settings->cossi,_t('SecretId')); $sform->addInput($cossi); $cossk = new Typecho_Widget_Helper_Form_Element_Text('cossk', NULL,$settings->cossk,_t('SecretKey')); $sform->addInput($cossk); $cosrg = new Typecho_Widget_Helper_Form_Element_Select('cosrg', array('sh'=>_t('华东(上海)'),'gz'=>_t('华南(广州)'),'cd'=>_t('西南(成都)'),'tj'=>_t('华北(北京一区)'),'bj'=>_t('北京'),'sgp'=>_t('新加坡'),'hk'=>_t('香港'),'ca'=>_t('多伦多'),'ger'=>_t('法兰克福')),$settings->cosrg, _t('所属地区')); $sform->addInput($cosrg); $cloudtoo = new Typecho_Widget_Helper_Form_Element_Select('cloudtoo', array(0=>_t('否'),1=>_t('是')),$settings->cloudtoo,_t('正文附件缩略图也使用该云储存')); $cloudtoo->label->setAttribute('style','color:#999;font-weight:normal;font-size:.92857em;'); $cloudtoo->input->setAttribute('style','position:absolute;font-size:.92857em;height:24px;bottom:-2px;left:184px;'); $cloudtoo->setAttribute('style','position:relative'); $sform->addInput($cloudtoo); $sform->addItem($submit); $request = Typecho_Request::getInstance(); //修改图片模式 if (isset($request->gid) && $action!=='insert') { $db = Typecho_Db::get(); $gallery = $db->fetchRow($db->select()->from('table.gallery')->where('gid = ?',$request->filter('int')->gid)); if (!$gallery) { throw new Typecho_Widget_Exception(_t('修改图片不存在')); } $thumb->value($gallery['thumb']); $image->value($gallery['image']); $sort->value($gallery['sort']); $name->value($gallery['name']); $description->value($gallery['description']); $do->value('update'); $gid->value($gallery['gid']); $submit->value(_t('修改图片')); $_action = 'update'; //保存设置模式 } elseif ($action=='sync' && $render=='s') { $submit->value(_t('保存设置')); $_action = 'sync'; //添加图片模式 } else { $do->value('insert'); $submit->value(_t('添加图片')); $_action = 'insert'; } if (!$action) { $action = $_action; } //验证表单规则 if ($action=='insert' || $action=='update') { $thumb->addRule('required',_t('图片地址不能为空')); $image->addRule('required',_t('图片地址不能为空')); $sort->addRule('required',_t('相册组不能为空')); $thumb->addRule('url',_t('请填写合法的图片地址')); $image->addRule('url',_t('请填写合法的图片地址')); $sort->addRule('isInteger',_t('请填写整数数字')); } return $render=='g' ? $gform : $sform; } /** * 判断比例格式 * * @access public * @param string $ratio * @return boolean */ public static function ratioformat($ratio) { return preg_match('/^\d*:\d*$/',$ratio); } /** * 输出标签替换 * * @access public * @param string $content * @return string */ public static function autohighslide($content,$widget,$lastResult) { $content = empty($lastResult) ? $content : $lastResult; if ($widget instanceof Widget_Archive) { $options = Helper::options(); $settings = $options->plugin('HighSlide'); $type = self::replacelist(); //判断替换范围 if ($widget->is(''.$type['index'].'') || $widget->is(''.$type['archive'].'') || $widget->is(''.$type['post'].'') || $widget->is(''.$type['page'].'')) { $content = preg_replace('/(.*?)<\/a>/si' ,'$5',$content); //所有图片弹窗 if ($settings->rpopt) { $content = preg_replace('/(]+src\s*=\s*"?([^>"\s]+)"?[^>]*>)(?!<\/a>)/si' ,'$1',$content); } //兼容旧版附件 if (strpos($content,'/attachment/')) { $content = preg_replace_callback('//i',array('HighSlide_Plugin','linkparse'),$content); } } //相册标签替换 if ($settings->mode=='highslide-full.packed.js' && $widget->is('page')) { $content = preg_replace_callback('/\[GALLERY([\-\d|,]*?)\]/i',array('HighSlide_Plugin','galleryparse'),$content); } $version = explode('/',$options->version); $sign = ''; $pattern = '/<(hs)(.*?)>(.*?)<\/\\1>/si'; //markdown fix if ($version['1']=='17.10.30' && $widget->isMarkdown && !stripos($content,'')) { $sign = '</hs>'; $pattern = '/<(hs)(.*?)>(.*?)<\/\\1>/si'; } //html标签替换 if ($settings->mode=='highslide-full.packed.js' && false!==stripos($content,$sign)) { $content = preg_replace_callback($pattern,array('HighSlide_Plugin','htmlparse'),$content); } } return $content; } /** * 输出范围参数 * * @access private * @return array */ private static function replacelist() { $rplist = Helper::options()->plugin('HighSlide')->rplist; $rplists = array('index'=>'','archive'=>'','post'=>'','page'=>''); if ($rplist) { foreach ($rplist as $key=>$val) { $key = $val; $rplists[$key] = $val; } } return $rplists; } /** * 页面相册解析 * * @access public * @param array $match * @return string */ public static function galleryparse($match) { $output = ''._t('相册数据为空').''; $sort = self::defaultsort(); if ($sort) { $settings = Helper::options()->plugin('HighSlide'); $db = Typecho_Db::get(); $gallerys = array(); $coversets = array(); $cover = ''; $body = ''; //记录相册组ID $param = substr(trim($match['1']),1); $param = $param ? $param : $sort; static $count = 0; ++$count; self::$ids[] = $param; $sorts = array_filter(explode(',',$param)); foreach ($sorts as $sort) { $gallerys = $db->fetchAll($db->select()->from('table.gallery')->where('sort = ?',''.$sort.'')->order('table.gallery.order',Typecho_Db::SORT_ASC)); if ($gallerys) { //输出封面部分 $coversets = array(array_shift($gallerys)); foreach ($coversets as $coverset) { switch ($settings->gallery) { case 'gallery-in-page' : $cover .= ''.$coverset['description'].' '; break; case 'gallery-controls-in-heading' : $cover .= ''.$coverset['description'].'
'.$coverset['description'].'
'; break; case 'gallery-in-box' : $cover .= ''.$coverset['description'].'
'.$coverset['description'].'
'; break; default : $cover .= ''.$coverset['description'].' '; } } //输出列表部分 foreach ($gallerys as $gallery) { switch ($settings->gallery) { case 'gallery-in-page' : $body .= ''.$gallery['description'].''; break; case 'gallery-controls-in-heading' : $body .= ''.$gallery['description'].'
'.$gallery['description'].'
'; break; case 'gallery-in-box' : $body .= ''.$gallery['description'].'
'.$gallery['description'].'
'; break; default : $body .= ''.$gallery['description'].''; } } } } $output = $settings->gallery=='gallery-in-page' ? '' : ''; } return $output; } /** * 缺省相册分类 * * @access public * @return string */ public static function defaultsort() { $db = Typecho_Db::get(); $default = $db->fetchRow($db->select('sort')->from('table.gallery')->order('sort',Typecho_Db::SORT_ASC)); return $default ? $default['sort'] : ''; } /** * html弹窗解析 * * @access public * @param array $match * @return string */ public static function htmlparse($match) { $settings = Helper::options()->plugin('HighSlide'); $fullwrap = $settings->fullwrap; //准备默认设置 $id = 'highslide-html'; $text = 'text'; $title = ''; $href = '#'; $width = ''; $height = ''; $Movetext = 'Move'; $Movetitle = 'Move'; $Closetext = 'Close'; $Closetitle = 'Close (esc)'; $Resizetitle = 'Resize'; if ($settings->lang=='cn') { $Movetext = '移动'; $Movetitle = '移动'; $Closetext = '关闭'; $Closetitle = '关闭 (esc)'; $Resizetitle = '拉伸'; } $param = htmlspecialchars_decode(trim($match['2'])); //markdown fix //解析标签参数 if ($param) { if (preg_match('/id=["\']([\w-]*)["\']/i',$param,$out)) { $id = trim($out[1]) ? trim($out[1]) : $id; } if (preg_match('/text=["\'](.*?)["\']/si',$param,$out)) { $text = trim($out[1]) ? trim($out[1]) : $text; } if (preg_match('/title=["\'](.*?)["\']/si',$param,$out)) { $title = trim($out[1]) ? trim($out[1]) : $title; } if (preg_match('/ajax=["\'](.*?)["\']/i',$param,$out)) { $href = trim($out[1]) ? trim($out[1]) : $href; } if (preg_match('/width=["\']([\w-]*)["\']/i',$param,$out)) { $width = trim($out[1]) ? ',width:'.strtr(trim($out[1]),'px','') : $width; } if (preg_match('/height=["\']([\w-]*)["\']/i',$param,$out)) { $height = trim($out[1]) ? ',height:'.strtr(trim($out[1]),'px','') : $height; } } $output = ''.$text.''; $output .= '
'; $output .= '
'.trim($match['3']).'
'; return $output; } /** * 附件链接解析 * * @access public * @param array $match * @return string */ public static function linkparse($match) { $db = Typecho_Db::get(); $cid = $match['3']; $attach = $db->fetchRow($db->select()->from('table.contents')->where('type = ?','attachment')->where('cid = ?',$cid)); if ($attach) { $text = unserialize($attach['text']); $output = 'siteUrl).'" class="highslide" onclick="return hs.expand(this,{slideshowGroup:\'images\'})"'.$match['4'].'>'; return $output; } } /** * 内文附件脚本 * * @access public * @return void */ public static function attachpanel() { $options = Helper::options(); $settings = $options->plugin('HighSlide'); $security = Helper::security(); $request = Typecho_Request::getInstance(); $cid = !empty($request->cid) ? '?cid='.$request->filter('int')->cid : ''; ?> is(''.$type['index'].'') || $widget->is(''.$type['archive'].'') || $widget->is(''.$type['post'].'') || $widget->is(''.$type['page'].'')) { $options = Helper::options(); $settings = $options->plugin('HighSlide'); $hsurl = $options->pluginUrl.'/HighSlide/'; $cssurl = ' '; //页面相册样式 if ($settings->mode=='highslide-full.packed.js' && $widget->is('page')) { if ($settings->gallery=='gallery-in-page') { $cssurl .= ' '; } if ($settings->gallery=='gallery-vertical-strip') { $cssurl .= ' '; } } echo $cssurl; } } /** * 输出底部脚本 * * @access public * @return void */ public static function footlink() { $options = Helper::options(); $widget = Typecho_Widget::widget('Widget_Archive'); $type = self::replacelist(); //判断输出范围 if ($widget->is(''.$type['index'].'') || $widget->is(''.$type['archive'].'') || $widget->is(''.$type['post'].'') || $widget->is(''.$type['page'].'')) { $hsurl = $options->pluginUrl.'/HighSlide/'; $settings = $options->plugin('HighSlide'); $links = ' '; $links .= ' '; echo $links; } } /** * 图片上传处理 * * @access public * @param array $file 上传的文件 * @param boolean $thumb 是否为缩略图 * @return array */ public static function uploadhandle($file,$thumb=false) { $settings = Helper::options()->plugin('HighSlide'); //准备路径参数 if ($thumb) { $filepath = $file['file']; $imgpath = $file['path']; } else { if (!$file['name']) { return false; } $imgname = preg_split('(\/|\\|:)',$file['name']); $file['name'] = array_pop($imgname); //处理扩展名 $ext = self::getsafename($file['name']); if (!in_array($ext,array('gif','jpg','jpeg','png','tiff','bmp')) || Typecho_Common::isAppEngine()) { return false; } $path = self::route()->dir; $imgdir = __TYPECHO_ROOT_DIR__.'/'.$path; //生成文件目录 if ($settings->storage=='local' && !is_dir($imgdir)) { if (!self::makedir($imgdir)) { return false; } } //处理文件名 $imgname = sprintf('%u',crc32(uniqid())).'.'.$ext; $imgfile = $imgdir.$imgname; $imgpath = $path.$imgname; if (!isset($file['tmp_name'])) { return false; } $filepath = $file['tmp_name']; } //按储存上传 switch ($settings->storage) { case 'local' : if (!$thumb) { if (!@move_uploaded_file($filepath,$imgfile)) { if (isset($file['bytes'])) { if (!file_put_contents($imgfile, $file['bytes'])) { //直接写入 return false; } } else { return false; } } } break; case 'qiniu' : $qiniu = self::qiniuset($settings->qiniuak,$settings->qiniusk); $bucket = $settings->qiniubucket; if ($thumb) { $bmgr = new Qiniu\Storage\BucketManager($qiniu); $bmgr->delete($bucket,$imgpath); } $token = $qiniu->uploadToken($bucket); $umgr = new Qiniu\Storage\UploadManager(); $umgr->putFile($token,$imgpath,$filepath); break; case 'scs' : $scs = self::scsset($settings->scsak,$settings->scssk); $bucket = $settings->scsbucket; if ($thumb) { $scs->deleteObject($bucket,$imgpath); } $scs->putObjectFile($filepath,$bucket,$imgpath,SCS::ACL_PUBLIC_READ,array(),array('Content-Type'=>Typecho_Common::mimeContentType($filepath))); break; case 'nos' : $nos = self::nosset($settings->nosak,$settings->nosas,$settings->nosep); $bucket = $settings->nosbucket; if ($thumb && $nos->doesObjectExist($bucket,$imgpath)) { $nos->deleteObject($bucket,$imgpath); } $nos->uploadFile($bucket,$imgpath,$filepath); break; case 'cos' : $cos = self::cosset($settings->cosrg); $bucket = $settings->cosbucket; $stat = $cos->stat($bucket,$imgpath); if ($thumb && $stat['message']=='SUCCESS') { $cos->delFile($bucket,$imgpath); } $cos->upload($bucket,$filepath,$imgpath); $cos->update($bucket,$imgpath,'','eWPrivateRPublic',array('Content-Type' =>Typecho_Common::mimeContentType($filepath),'Content-Disposition'=>'inline')); } //返回文件数据 if (!$thumb) { return array( 'name'=>$imgname, 'title'=>$file['name'], 'size'=>$file['size'] ); } } /** * 图片删除处理 * * @access public * @param string $imgname 图片名称 * @param boolean $isatt 是否来自附件 * @param string $url 图片地址 * @param string $from 来源字段 * @return void */ public static function removehandle($imgname,$isatt=false,$url=NULL,$from=NULL) { $options = Helper::options(); $settings = $options->plugin('HighSlide'); $route = self::route($url); $dir = $route->dir; $from = $from ? $from : $route->from; $imgdir = $from=='local' ? __TYPECHO_ROOT_DIR__.'/'.$dir : $dir; $imgpath = $imgdir.$imgname; $thumbpath = $imgdir.'thumb_'.$imgname; //附件模式删除 if ($isatt) { $localpath = __TYPECHO_ROOT_DIR__.'/'.$imgname; $imgpath = $from=='local' ? $localpath : $imgname; if (file_exists($localpath)) { @unlink($localpath); } } //按储存来源删除 switch ($from) { case 'local' : if (file_exists($imgpath)) { @unlink($imgpath); } if (file_exists($thumbpath)) { @unlink($thumbpath); } break; case 'qiniu' : $qiniu = self::qiniuset($settings->qiniuak,$settings->qiniusk); $bucket = $settings->qiniubucket; $bmgr = new Qiniu\Storage\BucketManager($qiniu); $bmgr->delete($bucket,$imgpath); $bmgr->delete($bucket,$thumbpath); break; case 'scs' : $scs = self::scsset($settings->scsak,$settings->scssk); $bucket = $settings->scsbucket; $scs->deleteObject($bucket,$imgpath); $scs->deleteObject($bucket,$thumbpath); break; case 'nos' : $nos = self::nosset($settings->nosak,$settings->nosas,$settings->nosep); $bucket = $settings->nosbucket; $nos->deleteObject($bucket,$imgpath); if ($nos->doesObjectExist($bucket,$thumbpath)) { $nos->deleteObject($bucket,$thumbpath); } break; case 'cos' : $cos = self::cosset($settings->cosrg); $bucket = $settings->cosbucket; $cos->delFile($bucket,$imgpath); $cos->delFile($bucket,$thumbpath); } } /** * 图片缩略处理 * * @access public * @param $imagename 原图名称 * @param string $width,$height,$xset,$yset 裁切参数 * @param string $url 原图地址 * @param boolean $isatt 是否来自附件 * @return array */ public static function crophandle($imgname,$width,$height,$xset,$yset,$url=NULL,$isatt=false) { $options = Helper::options(); $settings = $options->plugin('HighSlide'); $route = self::route($url,$isatt); $dir = $route->dir; $imgdir = __TYPECHO_ROOT_DIR__.'/'.$dir; $thumb = 'thumb_'.$imgname; $thumbpath = $dir.$thumb; $aurl = ''; //删除本地缩略图 $localpath = $imgdir.$thumb; if (file_exists($localpath)) { @unlink($localpath); } //获取原图信息 $imgfile = $url && false===strpos($url,$options->siteUrl) ? $url : ($url || !$url && $settings->storage=='local' ? $imgdir : $route->url).$imgname; $info = getimagesize($imgfile); $sets = self::newsets($info['0'],$width,$height,$xset,$yset,$isatt); //调整参数 $imgtype = image_type_to_mime_type($info['2']); $thumime = $imgtype; //按云端API演算 if (!$isatt && $settings->thumbapi || $isatt && $settings->cloudtoo && $settings->thumbapi) { $imgpath = $dir.$imgname; $prefix = ''; $site = $route->site; //删除上传缩略图 self::removehandle($thumbpath,true); switch ($route->from) { case 'qiniu' : $postfix = '?imageMogr2/crop/!'.$sets['2'].'x'.$sets['3'].'a'.$sets['4'].'a'.$sets['5'].'/thumbnail/'.$sets['0'].'x'.$sets['1']; break; case 'scs' : $scsimgx = $settings->scsimgx; $scsimgx = $scsimgx ? $scsimgx : 'http://*.applinzi.com|*'; $scsdset = strpos($scsimgx,'|') && $scsimgx!=='http://*.applinzi.com|*' ? explode('|',$scsimgx) : array(); //开启imgx权限 self::scsset($settings->scsak,$settings->scssk)->setAccessControlPolicy($scsbucket,$imgpath,array('GRPS000000ANONYMOUSE'=>array('read'),'SINA000000000000IMGX'=>array('read','write'))); $prefix = 'c_crop,w_'.$sets['2'].',h_'.$sets['3'].',x_'.$sets['4'].',y_'.$sets['5'].'--c_thumb,w_'.$sets['0'].',h_'.$sets['1'].'/'; $postfix = ''; $site = 'http://'.$scsbucket.'.imgx.sinacloud.net'; //新Imgxs版API if ($scsdset) { $prefix = 'c_'.$sets['4'].'-'.$sets['5'].',w_'.$sets['2'].',h_'.$sets['3'].'|w_'.$sets['0'].',h_'.$sets['1'].'/'.$scsdset['1'].'/'.$scsbucket.'/'; $postfix = ''; $site = $scsdset['0']; } break; case 'nos' : $postfix = '?imageView&crop='.$sets['4'].'_'.$sets['5'].'_'.$sets['2'].'_'.$sets['3'].'&thumbnail='.$sets['0'].'x'.$sets['1']; break; case 'cos' : $postfix = '?imageMogr2/cut/'.$sets['2'].'x'.$sets['3'].'x'.$sets['4'].'x'.$sets['5'].'/thumbnail/'.$sets['0'].'x'.$sets['1']; } $thumbpath = $prefix.$imgpath.$postfix; $aurl = Typecho_Common::url($thumbpath,$site); $thumsize = strlen(file_get_contents($aurl)); //用本地GD库渲染 } else { //生成临时目录 $thumbdir = __TYPECHO_ROOT_DIR__.__TYPECHO_PLUGIN_DIR__.'/HighSlide/thumb/'; if (!is_dir($thumbdir)) { if (!self::makedir($thumbdir)) { return false; } } //GD库开始采样 switch ($imgtype) { case 'image/gif' : $source = imagecreatefromgif($imgfile); break; case 'image/pjpeg' : case 'image/jpeg' : case 'image/jpg' : $source = imagecreatefromjpeg($imgfile); break; case 'image/png' : case 'image/x-png' : $source = imagecreatefrompng($imgfile); } $newimg = imagecreatetruecolor($sets['0'],$sets['1']); //GD库开始渲染 imagecopyresampled($newimg,$source,0,0,$sets['4'],$sets['5'],$sets['0'],$sets['1'],$sets['2'],$sets['3']); imagefilter($newimg,IMG_FILTER_SMOOTH,-20); imageantialias($newimg,true); //优化效果 $thumbfile = $thumbdir.$thumb; switch ($imgtype) { case 'image/gif' : imagegif($newimg,$thumbfile); break; case 'image/pjpeg' : case 'image/jpeg' : case 'image/jpg' : imagejpeg($newimg,$thumbfile,80); //控制体积 break; case 'image/png' : case 'image/x-png' : imagepng($newimg,$thumbfile); } imagedestroy($newimg); //释放内存 @chmod($thumbfile,0777); $thumsize = filesize($thumbfile); //云储存上传后删除 if (!$isatt && $settings->storage!=='local' || $isatt && $settings->cloudtoo) { self::uploadhandle(array('file'=>$thumbfile,'path'=>$thumbpath),true); @unlink($thumbfile); //本地移动缩略图 } else { if (!is_dir($imgdir)) { //检查目录 if (!self::makedir($imgdir)) { return false; } } rename($thumbfile,$imgdir.$thumb); } } //返回文件数据 return $isatt ? array('name'=>$thumb,'path'=>$thumbpath,'size' =>$thumsize,'type' =>self::getSafeName($imgname),'mime' =>$thumime,'from'=>$route->from,'aurl'=>$aurl) : array('size'=>$thumsize,'aurl'=>$aurl); } /** * 修正缩略参数 * * @access private * @param string $imgwidth 原图宽度 * @param string $width,$height,$xset,$yset 裁切参数 * @param string $isatt 是否来自缩略图 * @return array */ private static function newsets($imgwidth,$width,$height,$xset,$yset,$isatt=false) { $options = Helper::options(); $settings = $options->plugin('HighSlide'); //适应预览比例 $scale = $imgwidth>433.4 ? $imgwidth/433.4 : 1; if ($isatt) { $scale = $imgwidth>248.4 ? $imgwidth/248.4 : 1; //附件面板 } $width *= $scale; $height *= $scale; $xset *= $scale; $yset *= $scale; //应用缩放规格 switch ($settings->thumbfix) { case 'fixedwidth': $scale = $settings->fixedwidth/$width; break; case 'fixedheight': $scale = $settings->fixedheight/$height; break; case 'fixedratio': $fix = explode(':',$settings->fixedratio); $scale = trim($fix['0'])/trim($fix['1']); } $newwidth = round($width*$scale); $newheight = round($height*$scale); return array($newwidth,$newheight,round($width),round($height),round($xset),round($yset)); } /** * 本地目录创建 * * @access private * @param string $path 路径 * @return boolean */ private static function makedir($path) { $path = preg_replace("/\\\+/", '/', $path); $current = rtrim($path, '/'); $last = $current; while (!is_dir($current) && false !== strpos($path, '/')) { $last = $current; $current = dirname($current); } if ($last == $current) { return true; } if (!@mkdir($last)) { return false; } $stat = @stat($last); $perms = $stat['mode'] & 0007777; @chmod($last, $perms); return self::makedir($path); } /** * 获取安全的文件名 * * @access private * @param string $name * @return string */ private static function getsafename(&$name) { $name = str_replace(array('"','<','>'),'',$name); $name = str_replace('\\','/',$name); $name = false===strpos($name,'/') ? 'a'.$name : str_replace('/','/a',$name); $info = pathinfo($name); $name = substr($info['basename'],1); return isset($info['extension']) ? $info['extension'] : ''; } /** * 附件删除处理 * * @access public * @param array $content 文件相关信息 * @return boolean */ public static function deleteHandle(array $content,$lastResult) { $attach = $content['attachment']; $path = $attach->path; $from = $attach->from; //按缩略字段删除 if ($from) { self::removehandle($path,true,NULL,$from); } //按储存设置删除 self::removehandle($path,true,NULL,Helper::options()->plugin('HighSlide')->storage); //按传统继承删除 return empty($lastResult) ? !Typecho_Common::isAppEngine() && @unlink(__TYPECHO_ROOT_DIR__ .'/'.$path) : $lastResult; } /** * 检测图片是否存在 * * @access public * @param string $img * @return string */ public static function ifexist($img) { $opts = array( 'http'=>array( 'method'=>'HEAD', 'timeout'=>1 )); @file_get_contents($img,false,stream_context_create($opts)); $code = $http_response_header['0']; return isset($code) && (strpos($code,'200') || strpos($code,'304')) ? $img : ''; } }