From aa55ba8b625009af4b2f4307c90a884add6f3716 Mon Sep 17 00:00:00 2001 From: zyzzc Date: Thu, 15 May 2014 12:25:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=AF=E8=AF=BB=E6=80=A7=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Action.php | 43 +++++- Mysql.sql | 18 +-- Plugin.php | 343 +++++++++++++++++++++++++++++++-------------- SQLite.sql | 14 +- manage-gallery.php | 21 ++- 5 files changed, 318 insertions(+), 121 deletions(-) diff --git a/Action.php b/Action.php index 45d74c3..a7b1844 100644 --- a/Action.php +++ b/Action.php @@ -1,5 +1,6 @@ validate()) { $this->response->goBack(); } + $gallery = $this->request->from('thumb','image','description','sort','name'); $gallery['order'] = $this->db->fetchObject($this->db->select(array('MAX(order)'=>'maxOrder'))->from($this->prefix.'gallery'))->maxOrder+1; $gallery['gid'] = $this->db->query($this->db->insert($this->prefix.'gallery')->rows($gallery)); + //返回原页并提示信息 $this->widget('Widget_Notice')->highlight('gallery-'.$gallery['gid']); $this->widget('Widget_Notice')->set(_t('相册组%s: 图片%s 添加成功', $gallery['sort'],$gallery['name']),NULL,'success'); + $this->response->redirect(Typecho_Common::url('extending.php?panel=HighSlide%2Fmanage-gallery.php&group='.$gallery['sort'],$this->options->adminUrl)); } @@ -38,12 +42,15 @@ public function updategallery() if (HighSlide_Plugin::form('update')->validate()) { $this->response->goBack(); } + $gallery = $this->request->from('gid','thumb','image','description','sort','name'); - $this->db->query($this->db->update($this->prefix.'gallery')->rows($gallery)->where('gid = ?',$gallery['gid'])); + $this->db->query($this->db->update($this->prefix.'gallery')->rows($gallery)->where('gid=?',$gallery['gid'])); + //返回原页并提示信息 $this->widget('Widget_Notice')->highlight('gallery-'.$gallery['gid']); $this->widget('Widget_Notice')->set(_t('相册组%s: 图片%s 更新成功', $gallery['sort'],$gallery['name']),NULL,'success'); + $this->response->redirect(Typecho_Common::url('extending.php?panel=HighSlide%2Fmanage-gallery.php&group='.$gallery['sort'],$this->options->adminUrl)); } @@ -56,6 +63,7 @@ public function updategallery() public function deletegallery() { $gids = $this->request->filter('int')->gid; + $deletecount = 0; if ($gids && is_array($gids)) { foreach ($gids as $gid) { @@ -64,9 +72,11 @@ public function deletegallery() } } } + //返回原页并提示信息 $this->widget('Widget_Notice')->set($deletecount>0?_t('图片已从相册移除'):_t('没有图片被移除'),NULL, $deletecount>0?'success':'notice'); + $this->response->goBack(); } @@ -79,11 +89,13 @@ public function deletegallery() public function sortgallery() { $galleries = $this->request->filter('int')->gid; + if ($galleries && is_array($galleries)) { - foreach ($galleries as $sort => $gid) { + foreach ($galleries as $sort=>$gid) { $this->db->query($this->db->update($this->prefix.'gallery')->rows(array('order'=>$sort+1))->where('gid=?',$gid)); } } + //返回原页并提示信息 if (!$this->request->isAjax()) { $this->response->goBack(); @@ -104,6 +116,7 @@ public function uploadimage() $file = array_pop($_FILES); if (0==$file['error']&&is_uploaded_file($file['tmp_name'])) { $result = HighSlide_Plugin::uploadhandle($file); + if (false!==$result) { //拖拽上传输出json信息 if ($this->request->isAjax()) { @@ -112,6 +125,7 @@ public function uploadimage() 'title'=>$result['title'], 'bytes'=>number_format(ceil($result['size']/1024)).' Kb' ))); + //默认上传返回原页并提示成功 } else { $this->widget('Widget_Notice')->set(_t('图片 %s 上传成功',$result['title']),NULL,'success'); @@ -120,8 +134,10 @@ public function uploadimage() } } } + if ($this->request->isAjax()) { $this->response->throwJson(false); + //默认上传返回原页并提示失败 } else { $val = function_exists('ini_get')?trim(ini_get('upload_max_filesize')):0; @@ -136,6 +152,7 @@ public function uploadimage() } $val = number_format(ceil($val/(1024*1024))); $this->widget('Widget_Notice')->set(_t('上传失败,请确认为图片大小未超过%s并且gallery目录可写入',''.$val.'Mb'),NULL,'error'); + $this->response->goBack(); } } @@ -149,12 +166,15 @@ public function uploadimage() public function removeimage() { $imgname = $this->request->from('imgname'); + //获取附件源参数 $path = $this->request->from('path'); $url = $this->request->from('url'); + if ($imgname) { HighSlide_Plugin::removehandle($imgname['imgname'],$path['path'],$url['url']); } + $this->response->throwJson(false); } @@ -171,9 +191,11 @@ public function cropthumbnail() $h = $this->request->from('h'); $x1 = $this->request->from('x1'); $y1 = $this->request->from('y1'); + //获取附件源参数 $path = $this->request->from('path'); $url = $this->request->from('url'); + if ($imgname) { $result = HighSlide_Plugin::crophandle($imgname['imgname'],$w['w'],$h['h'],$x1['x1'],$y1['y1'],$path['path'],$url['url']); //输出json信息 @@ -181,6 +203,7 @@ public function cropthumbnail() 'bytes'=>number_format(ceil($result/1024)).' Kb' )); } + $this->response->throwJson(false); } @@ -197,6 +220,7 @@ public function syncsettings() $this->request->from('fixedheight'), $this->request->from('fixedratio') ); + $validator = new Typecho_Validate(); $validator->addRule('fixedwidth','isInteger',_t('固定宽度请输入整数数字')); $validator->addRule('fixedheight','isInteger',_t('固定高度请输入整数数字')); @@ -204,10 +228,12 @@ public function syncsettings() $validator->addRule('fixedwidth','required',_t('固定宽度不能为空')); $validator->addRule('fixedheight','required',_t('固定高度不能为空')); $validator->addRule('fixedratio','required',_t('固定比例不能为空')); + if ($error = $validator->run($requests)) { $this->widget('Widget_Notice')->set($error,'error'); $this->response->goBack(); } + //构建同步数组 $syncsets = array('qiniubucket','qiniudomain','qiniuaccesskey','qiniusecretkey','qiniuprefix', 'upyunbucket','upyundomain','upyunuser','upyunpwd','upyunkey','upyunprefix', @@ -217,9 +243,11 @@ public function syncsettings() $result = $this->request->from($syncset); $datas[$syncset] = $result[$syncset]; } + //返回原页并提示信息 Widget_Plugins_Edit::configPlugin('HighSlide',$datas); $this->widget('Widget_Notice')->set(_t('相册设置已保存'),NULL,'success'); + $this->response->goBack(); } @@ -232,26 +260,32 @@ public function syncsettings() public function postpreview() { $cid = $this->request->filter('int')->cid; + //调用对象 if ($cid) { Typecho_Widget::widget('Widget_Contents_Attachment_Related','parentId='.$cid)->to($attachment); } else { Typecho_Widget::widget('Widget_Contents_Attachment_Unattached')->to($attachment); } + //还原为数组 while ($attachment->next()) { $datas[] = unserialize($attachment->attachment); } + foreach ($datas as $data) { if (!$data['isImage']) { return false; } + $name = basename($data['path']); $prefix = dirname($data['url']); $thumb = $prefix.'/thumb_'.$name; + //直接验证缩略图 $headers = @get_headers($thumb,true); $open = (@fopen($thumb,'r'))?1:0; + $parse[] = array('title'=>$data['name'], 'name'=>$name, 'url'=>$data['url'], @@ -262,8 +296,10 @@ public function postpreview() 'tsize'=>number_format(ceil($headers['Content-Length']/1024)).' KB', 'tstat'=>$open); } + //输出json信息 $parse = json_encode($parse); + $this->response->throwJson($parse); } @@ -278,6 +314,7 @@ public function action() $this->db = Typecho_Db::get(); $this->prefix = $this->db->getPrefix(); $this->options = Typecho_Widget::widget('Widget_Options'); + $this->on($this->request->is('do=insert'))->insertgallery(); $this->on($this->request->is('do=update'))->updategallery(); $this->on($this->request->is('do=delete'))->deletegallery(); @@ -287,6 +324,8 @@ public function action() $this->on($this->request->is('do=crop'))->cropthumbnail(); $this->on($this->request->is('do=sync'))->syncsettings(); $this->on($this->request->is('do=preview'))->postpreview(); + $this->response->redirect($this->options->adminUrl); } + } \ No newline at end of file diff --git a/Mysql.sql b/Mysql.sql index 41f0ace..dd001f9 100644 --- a/Mysql.sql +++ b/Mysql.sql @@ -1,10 +1,10 @@ CREATE TABLE `typecho_gallery` ( - `gid` int(10) unsigned NOT NULL auto_increment COMMENT 'gallery表主键', - `thumb` varchar(200) default NULL COMMENT '缩略图', - `image` varchar(200) default NULL COMMENT '原图', - `sort` int(10) default '0' COMMENT '相册组', - `name` varchar(200) default NULL COMMENT '图片名称', - `description` varchar(200) default NULL COMMENT '图片描述', - `order` int(10) unsigned default '0' COMMENT '图片排序', - PRIMARY KEY (`gid`) -) ENGINE=MYISAM DEFAULT CHARSET=%charset%; + `gid` int(10) unsigned NOT NULL auto_increment COMMENT 'gallery表主键', + `thumb` varchar(200) default NULL COMMENT '缩略图', + `image` varchar(200) default NULL COMMENT '原图', + `sort` int(10) default '0' COMMENT '相册组', + `name` varchar(200) default NULL COMMENT '图片名称', + `description` varchar(200) default NULL COMMENT '图片描述', + `order` int(10) unsigned default '0' COMMENT '图片排序', + PRIMARY KEY (`gid`) +) ENGINE=MYISAM DEFAULT CHARSET=%charset%; diff --git a/Plugin.php b/Plugin.php index d301171..e650299 100644 --- a/Plugin.php +++ b/Plugin.php @@ -1,5 +1,6 @@ (HighSlide全功能版核心支持)'),'administrator'); Helper::addAction('gallery-edit','HighSlide_Action'); + Typecho_Plugin::factory('Widget_Archive')->header = array('HighSlide_Plugin','headlink'); Typecho_Plugin::factory('Widget_Archive')->footer = array('HighSlide_Plugin','footlink'); + Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = array('HighSlide_Plugin','autohighslide'); Typecho_Plugin::factory('Widget_Abstract_Contents')->excerptEx = array('HighSlide_Plugin','autohighslide'); + Typecho_Plugin::factory('admin/write-post.php')->bottom = array('HighSlide_Plugin','jshelper'); Typecho_Plugin::factory('admin/write-page.php')->bottom = array('HighSlide_Plugin','jshelper'); Typecho_Plugin::factory('admin/write-post.php')->option = array('HighSlide_Plugin','uploadpanel'); + return _t($info); } @@ -70,11 +76,11 @@ public static function config(Typecho_Widget_Helper_Form $form) } full.click(function() { adv.attr('style','color:#467B96;font-weight:bold'); - option.removeAttr('style'); + option.removeAttr('style'); }); basic.click(function() { adv.attr('style','color:#999;font-weight:bold'); - option.attr('style','color:#999'); + option.attr('style','color:#999'); }); }); @@ -82,120 +88,116 @@ 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); + $rpmode = new Typecho_Widget_Helper_Form_Element_Radio('rpmode', array('ahref'=>_t('链接图片'),'imgsrc'=>_t('所有图片')),'ahref',_t('应用模式'),NULL); $form->addInput($rpmode); + $rplist = new Typecho_Widget_Helper_Form_Element_Checkbox('rplist', array('index'=>_t('首页'),'post'=>_t('文章页'),'page'=>_t('独立页'),'archive'=>_t('索引页')),array('index','post','page','archive'),_t('应用范围'),NULL); $form->addInput($rplist); + $lang = new Typecho_Widget_Helper_Form_Element_Radio('lang', array('chs'=>_t('中文'),'eng'=>_t('英文')),'chs',_t('提示语言')); $form->addInput($lang); + $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); + $butn = new Typecho_Widget_Helper_Form_Element_Radio('butn', array('false'=>_t('不显示'),'true'=>_t('显示')),'false',_t('关闭按钮')); $form->addInput($butn); + $ltext = new Typecho_Widget_Helper_Form_Element_Text('ltext', NULL,'© '.$_SERVER['HTTP_HOST'].'',_t('角标文字'),_t('弹窗logo文字与显示位置,留空则不显示')); $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->removeAttribute('class','typecho-label'); $lpos->input->setAttribute('style','position:absolute;bottom:42px;left:165px;'); $lpos->setAttribute('style','list-style:none;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('例: <a href="http://xx.jpg" title="图片说明写这"><img src="http://xxx.jpg" alt="或者写这显示"/></a>

全功能版设置 ———————————————————————————————————————

')); $form->addInput($capt); + $align = new Typecho_Widget_Helper_Form_Element_Radio('align', array('default'=>_t('默认'),'center'=>_t('居中')),'default',_t('弹窗位置')); $form->addInput($align); + $opac = new Typecho_Widget_Helper_Form_Element_Text('opac', NULL,'0.65',_t('背景遮罩'),_t('可填入0~1之间小数, 代表透明至纯黑')); $opac->input->setAttribute('class','mini'); $form->addInput($opac->addRule('isFloat',_t('请填写数字'))); + $slide = new Typecho_Widget_Helper_Form_Element_Radio('slide', array('false'=>_t('关闭'),'true'=>_t('开启')),'true',_t('幻灯按钮')); $form->addInput($slide); + $nextimg = new Typecho_Widget_Helper_Form_Element_Radio('nextimg', array('false'=>_t('否'),'true'=>_t('是')),'false',_t('自动翻页'),_t('开启后点击图片为显示下一张')); $form->addInput($nextimg); + $cpos = new Typecho_Widget_Helper_Form_Element_Radio('cpos', array(''=>_t('不显示'),'caption'=>_t('底部显示'),'heading'=>_t('顶部显示')),'',_t('图片序数')); $form->addInput($cpos); + $wrap = new Typecho_Widget_Helper_Form_Element_Checkbox('wrap', array('draggable-header'=>_t('标题栏 支持<hs title="标题">显示'),'no-footer'=>_t('无拉伸')),NULL,_t('html弹窗效果')); $form->addInput($wrap); - //相册同步设置 - $storage = new Typecho_Widget_Helper_Form_Element_Radio('storage', - array('local'=>_t('本地'),'qiniu'=>_t('七牛'),'upyun'=>_t('又拍云'),'bcs'=>_t('百度BCS')),'local',''); - $form->addInput($storage->setAttribute('style','display:none;')); - $local = new Typecho_Widget_Helper_Form_Element_Text('local', - NULL,'/usr/uploads/HSgallery/',''); - $form->addInput($local->setAttribute('style','display:none;')); - $qiniubucket = new Typecho_Widget_Helper_Form_Element_Text('qiniubucket', - NULL,'',''); - $form->addInput($qiniubucket->setAttribute('style','display:none;')); - $qiniudomain = new Typecho_Widget_Helper_Form_Element_Text('qiniudomain', - NULL,'http://',''); - $form->addInput($qiniudomain->setAttribute('style','display:none;')); - $qiniuaccesskey = new Typecho_Widget_Helper_Form_Element_Text('qiniuaccesskey', - NULL,'',''); - $form->addInput($qiniuaccesskey->setAttribute('style','display:none;')); - $qiniusecretkey = new Typecho_Widget_Helper_Form_Element_Text('qiniusecretkey', - NULL,'',''); - $form->addInput($qiniusecretkey->setAttribute('style','display:none;')); - $qiniuprefix = new Typecho_Widget_Helper_Form_Element_Text('qiniuprefix', - NULL,'usr/uploads/HSgallery/',''); - $form->addInput($qiniuprefix->setAttribute('style','display:none;')); - $upyunbucket = new Typecho_Widget_Helper_Form_Element_Text('upyunbucket', - NULL,'',''); - $form->addInput($upyunbucket->setAttribute('style','display:none;')); - $upyundomain = new Typecho_Widget_Helper_Form_Element_Text('upyundomain', - NULL,'http://',''); - $form->addInput($upyundomain->setAttribute('style','display:none;')); - $upyunuser = new Typecho_Widget_Helper_Form_Element_Text('upyunuser', - NULL,'',''); - $form->addInput($upyunuser->setAttribute('style','display:none;')); - $upyunpwd = new Typecho_Widget_Helper_Form_Element_Text('upyunpwd', - NULL,'',''); - $form->addInput($upyunpwd->setAttribute('style','display:none;')); - $upyunkey = new Typecho_Widget_Helper_Form_Element_Text('upyunkey', - NULL,'',''); - $form->addInput($upyunkey->setAttribute('style','display:none;')); - $upyunprefix = new Typecho_Widget_Helper_Form_Element_Text('upyunprefix', - NULL,'/usr/uploads/HSgallery/',''); - $form->addInput($upyunprefix->setAttribute('style','display:none;')); - $bcsbucket = new Typecho_Widget_Helper_Form_Element_Text('bcsbucket', - NULL,'',''); - $form->addInput($bcsbucket->setAttribute('style','display:none;')); - $bcsapikey = new Typecho_Widget_Helper_Form_Element_Text('bcsapikey', - NULL,'',''); - $form->addInput($bcsapikey->setAttribute('style','display:none;')); - $bcssecretkey = new Typecho_Widget_Helper_Form_Element_Text('bcssecretkey', - NULL,'',''); - $form->addInput($bcssecretkey->setAttribute('style','display:none;')); - $bcsprefix = new Typecho_Widget_Helper_Form_Element_Text('bcsprefix', - NULL,'/usr/uploads/HSgallery/',''); - $form->addInput($bcsprefix->setAttribute('style','display:none;')); - $thumbfix = new Typecho_Widget_Helper_Form_Element_Radio('thumbfix', - array('fixedwidth'=>_t('固定宽度'),'fixedheight'=>_t('固定高度'),'fixedratio'=>_t('固定比例')),'fixedwidth',''); - $form->addInput($thumbfix->setAttribute('style','display:none;')); - $fixedwidth = new Typecho_Widget_Helper_Form_Element_Text('fixedwidth', - NULL,'100',''); - $form->addInput($fixedwidth->setAttribute('style','display:none;')); - $fixedheight = new Typecho_Widget_Helper_Form_Element_Text('fixedheight', - NULL,'200',''); - $form->addInput($fixedheight->setAttribute('style','display:none;')); - $fixedratio = new Typecho_Widget_Helper_Form_Element_Text('fixedratio', - NULL,'4:3',''); - $form->addInput($fixedratio->setAttribute('style','display:none;')); - $gallery = new Typecho_Widget_Helper_Form_Element_Select('gallery', - array('gallery-horizontal-strip'=>'','gallery-thumbstrip-above'=>'','gallery-vertical-strip'=>'','gallery-in-box'=>'','gallery-floating-thumbs'=>'','gallery-floating-caption'=>'','gallery-controls-in-heading'=>'','gallery-in-page'=>''),'gallery-horizontal-strip',''); - $form->addInput($gallery->setAttribute('style','display:none;')); + + //相册设置隐藏域 + $storage = new Typecho_Widget_Helper_Form_Element_Hidden('storage', + array('local','qiniu','upyun','bcs'),'local'); + $form->addInput($storage); + $local = new Typecho_Widget_Helper_Form_Element_Hidden('local',NULL,'/usr/uploads/HSgallery/'); + $form->addInput($local); + $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); + $qiniuaccesskey = new Typecho_Widget_Helper_Form_Element_Hidden('qiniuaccesskey',NULL,''); + $form->addInput($qiniuaccesskey); + $qiniusecretkey = new Typecho_Widget_Helper_Form_Element_Hidden('qiniusecretkey',NULL,''); + $form->addInput($qiniusecretkey); + $qiniuprefix = new Typecho_Widget_Helper_Form_Element_Hidden('qiniuprefix',NULL,'usr/uploads/HSgallery/'); + $form->addInput($qiniuprefix); + $upyunbucket = new Typecho_Widget_Helper_Form_Element_Hidden('upyunbucket',NULL,''); + $form->addInput($upyunbucket); + $upyundomain = new Typecho_Widget_Helper_Form_Element_Hidden('upyundomain',NULL,'http://'); + $form->addInput($upyundomain); + $upyunuser = new Typecho_Widget_Helper_Form_Element_Hidden('upyunuser',NULL,''); + $form->addInput($upyunuser); + $upyunpwd = new Typecho_Widget_Helper_Form_Element_Hidden('upyunpwd',NULL,''); + $form->addInput($upyunpwd); + $upyunkey = new Typecho_Widget_Helper_Form_Element_Hidden('upyunkey',NULL,''); + $form->addInput($upyunkey); + $upyunprefix = new Typecho_Widget_Helper_Form_Element_Hidden('upyunprefix',NULL,'/usr/uploads/HSgallery/'); + $form->addInput($upyunprefix); + $bcsbucket = new Typecho_Widget_Helper_Form_Element_Hidden('bcsbucket',NULL,''); + $form->addInput($bcsbucket); + $bcsapikey = new Typecho_Widget_Helper_Form_Element_Hidden('bcsapikey',NULL,''); + $form->addInput($bcsapikey); + $bcssecretkey = new Typecho_Widget_Helper_Form_Element_Hidden('bcssecretkey',NULL,''); + $form->addInput($bcssecretkey); + $bcsprefix = new Typecho_Widget_Helper_Form_Element_Hidden('bcsprefix',NULL,'/usr/uploads/HSgallery/'); + $form->addInput($bcsprefix); + $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,'100'); + $form->addInput($fixedwidth); + $fixedheight = new Typecho_Widget_Helper_Form_Element_Hidden('fixedheight',NULL,'200'); + $form->addInput($fixedheight); + $fixedratio = new Typecho_Widget_Helper_Form_Element_Hidden('fixedratio',NULL,'4:3'); + $form->addInput($fixedratio); + $gallery = new Typecho_Widget_Helper_Form_Element_Hidden('gallery', + array('gallery-horizontal-strip','gallery-thumbstrip-above','gallery-vertical-strip','gallery-in-box','gallery-floating-thumbs','gallery-floating-caption','gallery-controls-in-heading','gallery-in-page'),'gallery-horizontal-strip'); + $form->addInput($gallery); } /** @@ -220,10 +222,12 @@ public static function galleryinstall() $type = explode('_',$installdb->getAdapterName()); $type = array_pop($type); $prefix = $installdb->getPrefix(); + $scripts = file_get_contents('usr/plugins/HighSlide/'.$type.'.sql'); $scripts = str_replace('typecho_',$prefix,$scripts); $scripts = str_replace('%charset%','utf8',$scripts); $scripts = explode(';',$scripts); + try { foreach ($scripts as $script) { $script = trim($script); @@ -302,6 +306,8 @@ public static function filedata($path = NULL,$url = NULL) { $options = Helper::options(); $settings = $options->plugin('HighSlide'); + + //判断本地附件源 if (strpos($url,$options->siteUrl)===false) { if ($settings->storage=='local') { $prefix = ($path)?$path:$settings->local; @@ -323,11 +329,11 @@ public static function filedata($path = NULL,$url = NULL) $fileurl = Typecho_Common::url($prefix,'http://bcs.duapp.com'); $filedir = Typecho_Common::url($prefix,''); } - //本地附件源删除 } else { $fileurl = Typecho_Common::url($path,$options->siteUrl); $filedir = Typecho_Common::url($path,__TYPECHO_ROOT_DIR__); } + return new Typecho_Config(array('url'=>$fileurl,'dir'=>$filedir)); } @@ -344,6 +350,7 @@ public static function filelist() $filedata = self::filedata(); $fileurl = $filedata->url; $filedir = $filedata->dir; + //获取对比数据 $urls = $db->fetchAll($db->select('image','thumb')->from('table.gallery')); $images = array(); @@ -352,6 +359,7 @@ public static function filelist() $images[] = $url['image']; $thumbs[] = $url['thumb']; } + //获取本地列表 if ($settings->storage=='local') { $lists = glob($filedir.'*[0-9].{gif,jpg,jpeg,png,tiff,bmp,GIF,JPG,JPEG,PNG,TIFF,BMP}',GLOB_BRACE|GLOB_NOSORT); @@ -359,6 +367,7 @@ public static function filelist() $datas[] = array('key'=>$list,'fsize'=>filesize($list)); } } + //获取七牛列表 if ($settings->storage=='qiniu') { self::qiniuset($settings->qiniuaccesskey,$settings->qiniusecretkey); @@ -368,6 +377,7 @@ public static function filelist() $datas = $result; } } + //获取又拍云列表 if ($settings->storage=='upyun') { $upyun = self::upyunset(); @@ -376,10 +386,11 @@ public static function filelist() $datas[] = array('key'=>$list['name'],'fsize'=>$list['size']); } } + //获取百度BCS列表 if ($settings->storage=='bcs') { $bcs = self::bcsset(); - $result = $bcs->list_object($settings->bcsbucket,array('prefix' =>$filedir)); + $result = $bcs->list_object($settings->bcsbucket,array('prefix'=>$filedir)); if ($result->isOK()) { $decode = json_decode($result->body,true); $lists = $decode['object_list']; @@ -388,6 +399,7 @@ public static function filelist() } } } + //重构处理排序 if (!empty($datas)) { foreach ($datas as $data) { @@ -400,6 +412,7 @@ public static function filelist() return false; } ksort($files); + $filelist = array(); $id=0; foreach ($files as $file) { @@ -410,6 +423,7 @@ public static function filelist() $filelist[] = array('id'=>$id++,'name'=>$filename,'size'=>$filesize); } } + return $filelist; } @@ -424,98 +438,129 @@ public static function form($action = NULL,$render = '1') { $options = Helper::options(); $settings = $options->plugin('HighSlide'); + //图片编辑表单 $form1 = new Typecho_Widget_Helper_Form(Typecho_Common::url('/action/gallery-edit',$options->index), Typecho_Widget_Helper_Form::POST_METHOD); + $image = new Typecho_Widget_Helper_Form_Element_Text('image', NULL,"http://",_t('原图地址*')); $form1->addInput($image); + $thumb = new Typecho_Widget_Helper_Form_Element_Text('thumb', NULL,"http://",_t('缩略图地址*')); $form1->addInput($thumb); + $name = new Typecho_Widget_Helper_Form_Element_Text('name', NULL,NULL,_t('图片名称')); $name->input->setAttribute('class','mini'); $form1->addInput($name); + $description = new Typecho_Widget_Helper_Form_Element_Textarea('description', NULL,NULL,_t('图片描述'),_t('推荐填写, 用于展示相册中图片的文字说明效果')); $form1->addInput($description); + $sort = new Typecho_Widget_Helper_Form_Element_Text('sort', NULL,"1",_t('相册组*'),_t('输入数字, 对应写入[GALLERY-数字]在页面调用')); $sort->input->setAttribute('class','w-10'); $form1->addInput($sort); + $do = new Typecho_Widget_Helper_Form_Element_Hidden('do'); $form1->addInput($do); + $gid = new Typecho_Widget_Helper_Form_Element_Hidden('gid'); $form1->addInput($gid); + $submit = new Typecho_Widget_Helper_Form_Element_Submit(); $form1->addItem($submit); + //相册设置表单 $form2 = new Typecho_Widget_Helper_Form(Typecho_Common::url('/action/gallery-edit?do=sync',$options->index), 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('相册风格'),_t('套装效果, 不受插件通用设置影响')); $form2->addInput($gallery); + $thumboptions = array( - 'fixedwidth' => _t('固定宽度 %s', ' '), - 'fixedheight' => _t('固定高度 %s', ' '), - 'fixedratio' => _t('固定比例 %s', ' '), + 'fixedwidth'=>_t('固定宽度 %s',' '), + 'fixedheight'=>_t('固定高度 %s',' '), + 'fixedratio'=>_t('固定比例 %s',' '), ); $thumbfix = new Typecho_Widget_Helper_Form_Element_Radio('thumbfix', $thumboptions,$settings->thumbfix,_t('缩略图规格'),_t('宽高单位px(无需填写), 比例注意使用半角冒号')); $form2->addInput($thumbfix->multiMode()); + $storage = new Typecho_Widget_Helper_Form_Element_Radio('storage', array('local'=>_t('本地'),'qiniu'=>_t('七牛'),'upyun'=>_t('又拍云'),'bcs'=>_t('百度BCS')),$settings->storage,_t('储存位置')); $form2->addInput($storage); + $local = new Typecho_Widget_Helper_Form_Element_Text('local', NULL,$settings->local,_t('本地路径'),_t('确保首层目录可写, 结尾带/号')); $form2->addInput($local); + $qiniubucket = new Typecho_Widget_Helper_Form_Element_Text('qiniubucket', NULL,$settings->qiniubucket,_t('空间名称')); $form2->addInput($qiniubucket); + $qiniudomain = new Typecho_Widget_Helper_Form_Element_Text('qiniudomain', NULL,$settings->qiniudomain,_t('空间域名')); - $form2->addInput($qiniudomain->setAttribute('style','display:block;')); + $form2->addInput($qiniudomain); + $qiniuaccesskey = new Typecho_Widget_Helper_Form_Element_Text('qiniuaccesskey', NULL,$settings->qiniuaccesskey,_t('AccessKey')); - $form2->addInput($qiniuaccesskey->setAttribute('style','display:block;')); + $form2->addInput($qiniuaccesskey); + $qiniusecretkey = new Typecho_Widget_Helper_Form_Element_Text('qiniusecretkey', NULL,$settings->qiniusecretkey,_t('SecretKey')); - $form2->addInput($qiniusecretkey->setAttribute('style','display:block;')); + $form2->addInput($qiniusecretkey); + $qiniuprefix = new Typecho_Widget_Helper_Form_Element_Text('qiniuprefix', NULL,$settings->qiniuprefix,_t('路径前缀'),_t('注意开头不要加/号')); - $form2->addInput($qiniuprefix->setAttribute('style','display:block;')); + $form2->addInput($qiniuprefix); + $upyunbucket = new Typecho_Widget_Helper_Form_Element_Text('upyunbucket', NULL,$settings->upyunbucket,_t('空间名称')); - $form2->addInput($upyunbucket->setAttribute('style','display:block;')); + $form2->addInput($upyunbucket); + $upyundomain = new Typecho_Widget_Helper_Form_Element_Text('upyundomain', NULL,$settings->upyundomain,_t('绑定域名')); - $form2->addInput($upyundomain->setAttribute('style','display:block;')); + $form2->addInput($upyundomain); + $upyunuser = new Typecho_Widget_Helper_Form_Element_Text('upyunuser', NULL,$settings->upyunuser,_t('操作员')); - $form2->addInput($upyunuser->setAttribute('style','display:block;')); + $form2->addInput($upyunuser); + $upyunpwd = new Typecho_Widget_Helper_Form_Element_Text('upyunpwd', NULL,$settings->upyunpwd,_t('密码')); - $form2->addInput($upyunpwd->setAttribute('style','display:block;')); + $form2->addInput($upyunpwd); + $upyunkey = new Typecho_Widget_Helper_Form_Element_Text('upyunkey', NULL,$settings->upyunkey,_t('密匙')); - $form2->addInput($upyunkey->setAttribute('style','display:block;')); + $form2->addInput($upyunkey); + $upyunprefix = new Typecho_Widget_Helper_Form_Element_Text('upyunprefix', NULL,$settings->upyunprefix,_t('路径前缀')); - $form2->addInput($upyunprefix->setAttribute('style','display:block;')); + $form2->addInput($upyunprefix); + $bcsbucket = new Typecho_Widget_Helper_Form_Element_Text('bcsbucket', NULL,$settings->bcsbucket,_t('空间名称')); - $form2->addInput($bcsbucket->setAttribute('style','display:block;')); + $form2->addInput($bcsbucket); + $bcsapikey = new Typecho_Widget_Helper_Form_Element_Text('bcsapikey', NULL,$settings->bcsapikey,_t('APIKey')); - $form2->addInput($bcsapikey->setAttribute('style','display:block;')); + $form2->addInput($bcsapikey); + $bcssecretkey = new Typecho_Widget_Helper_Form_Element_Text('bcssecretkey', NULL,$settings->bcssecretkey,_t('SecretKey')); - $form2->addInput($bcssecretkey->setAttribute('style','display:block;')); + $form2->addInput($bcssecretkey); + $bcsprefix = new Typecho_Widget_Helper_Form_Element_Text('bcsprefix', NULL,$settings->bcsprefix,_t('路径前缀')); - $form2->addInput($bcsprefix->setAttribute('style','display:block;')); + $form2->addInput($bcsprefix); + $form2->addItem($submit); + //隐藏模式 switch ($settings->storage) { case 'local': @@ -575,23 +620,29 @@ public static function form($action = NULL,$render = '1') $upyunprefix->setAttribute('style','display:none;'); break; } + //更新模式 $request = Typecho_Request::getInstance(); + if (isset($request->gid)&&$action!=='insert') { $db = Typecho_Db::get(); $prefix = $db->getPrefix(); + $gallery = $db->fetchRow($db->select()->from($prefix.'gallery')->where('gid=?',$request->gid)); if (!$gallery) { throw new Typecho_Widget_Exception(_t('图片不存在'),404); } + $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=='2') { $submit->value(_t('保存设置')); @@ -604,6 +655,7 @@ public static function form($action = NULL,$render = '1') if (empty($action)) { $action = $_action; } + //验证规则 if ($action=='insert'||$action=='update') { $thumb->addRule('required',_t('缩略图地址不能为空')); @@ -617,6 +669,7 @@ public static function form($action = NULL,$render = '1') $gid->addRule('required',_t('图片主键不存在')); $gid->addRule(array(new HighSlide_Plugin,'galleryexists'),_t('图片不存在')); } + $form = ($render=='1')?$form1:$form2; return $form; } @@ -660,28 +713,34 @@ public static function autohighslide($content,$widget,$lastResult) $content = empty($lastResult)?$content:$lastResult; $settings = Helper::options()->plugin('HighSlide'); $istype = self::replacelist(); + //替换范围 if ($widget->is(''.$istype->index.'')||$widget->is(''.$istype->archive.'')||$widget->is(''.$istype->post.'')||$widget->is(''.$istype->page.'')) { $pattern = '/(.*?)<\/a>/si'; $replacement = '$5'; $content = preg_replace($pattern,$replacement,$content); + //全图替换 if ($settings->rpmode=='imgsrc') { $pattern = '/(]+src\s*=\s*"?([^>"\s]+)"?[^>]*>)(?!<\/a>)/si'; $replacement = '$1'; $content = preg_replace($pattern,$replacement,$content); } + //附件链接替换 $content = preg_replace_callback('//i',array('HighSlide_Plugin','linkparse'),$content); } + //页面相册标签替换 if ($widget->is('page')&&$settings->mode=='highslide-full.packed.js') { $content = preg_replace_callback("/\[GALLERY([\-\d|\,]*?)\]/i",array('HighSlide_Plugin','galleryparse'),$content); } + //html弹窗标签替换 if ($settings->mode=='highslide-full.packed.js') { - $content = preg_replace_callback("/\s*<(hs)(\s*[^>]*)>(.*?)<\/\\1>\s*/si",array('HighSlide_Plugin','htmlparse'),$content); + $content = preg_replace_callback("/<(hs)([^>]*)>(.*?)<\/\\1>/si",array('HighSlide_Plugin','htmlparse'),$content); } + return $content; } @@ -695,12 +754,14 @@ private static function replacelist() { $rplist = Helper::options()->plugin('HighSlide')->rplist; $rplists = array(); + if ($rplist) { foreach ($rplist as $key=>$val) { $key = $val; $rplists[$key] = $val; } } + return new Typecho_Config($rplists); } @@ -718,11 +779,14 @@ public static function galleryparse($matches) $prefix = $db->getPrefix(); $tmp = ''; $cover = ''; + $param = substr(trim($matches[1]),1); $sorts = ($param)?explode(',',$param):array(self::defaultsort()); + foreach ($sorts as $sort) { $gallerys = $db->fetchAll($db->select()->from($prefix.'gallery')->where('sort=?',''.$sort.'')->order($prefix.'gallery.order',Typecho_Db::SORT_ASC)); if (!empty($gallerys)) { + //封面部分 $coversets = array(array_shift($gallerys)); foreach ($coversets as $coverset) { @@ -730,10 +794,12 @@ public static function galleryparse($matches) if ($settings->gallery=='gallery-in-page') { $cover.=''.$coverset['description'].' '; } + //岁月名片 elseif ($settings->gallery=='gallery-controls-in-heading') { $cover.=''.$coverset['description'].'
'.$coverset['description'].'
'; } + //纯白记忆 elseif ($settings->gallery=='gallery-in-box') { $cover.=''.$coverset['description'].'
'.$coverset['description'].'
'; @@ -741,16 +807,19 @@ public static function galleryparse($matches) $cover.=''.$coverset['description'].' '; } } + //列表部分 foreach ($gallerys as $gallery) { //幻影橱窗 if ($settings->gallery=='gallery-in-page') { $tmp.=''.$gallery['description'].''; } + //岁月名片 elseif ($settings->gallery=='gallery-controls-in-heading') { $tmp.=''.$gallery['description'].'
'.$gallery['description'].'
'; } + //纯白记忆 elseif ($settings->gallery=='gallery-in-box') { $tmp.=''.$gallery['description'].'
'.$gallery['description'].'
'; @@ -760,15 +829,17 @@ public static function galleryparse($matches) } } } - $container = '
'.$tmp.'
'; + //合并输出 + $container = '
'.$tmp.'
'; if ($settings->gallery=='gallery-in-page') { $output = ''; } else { $output = ''; } + return $output; - } + } /** * 缺省相册分类 @@ -795,6 +866,7 @@ public static function htmlparse($matches) { $settings = Helper::options()->plugin('HighSlide'); $param = trim($matches[2]); + $id = 'highslide-html'; $text = 'text'; $title = ''; @@ -807,6 +879,7 @@ public static function htmlparse($matches) $Closetext = 'Close'; $Closetitle = 'Close (esc)'; $Resizetitle = 'Resize'; + if ($settings->lang == 'chs') { $Movetext = '移动'; $Movetitle = '移动'; @@ -814,6 +887,7 @@ public static function htmlparse($matches) $Closetitle = '关闭 (esc)'; $Resizetitle = '拉伸'; } + //标签参数解析 if (!empty($param)) { if (preg_match("/id=[\"']([\w-]*)[\"']/i",$param,$out)) { @@ -825,7 +899,7 @@ public static function htmlparse($matches) if (preg_match("/title=[\"'](.*?)[\"']/si",$param,$out)) { $title = trim($out[1])==''?$title:trim($out[1]); } - if (preg_match("/ajax=[\"'](.*?)[\"']/si",$param,$out)) { + if (preg_match("/ajax=[\"'](.*?)[\"']/i",$param,$out)) { $ajax = trim($out[1])==''?$ajax:trim($out[1]); } if (preg_match("/width=[\"']([\w-]*)[\"']/i",$param,$out)) { @@ -835,13 +909,16 @@ public static function htmlparse($matches) $height = trim($out[1])==''?$height:',height:'.str_replace('px','',trim($out[1])); } } + //标题栏支持 if ($settings->wrap) { $addt = (in_array('draggable-header',$settings->wrap)&&$title)?',headingText:\''.$title.'\'':''; } + //ajax模式判断 $href = ($ajax)?$ajax:'#'; $shift = ($ajax)?'objectType:\'ajax\'':'contentId:\''.$id.'\''; + $output = ''.$text.''; $output .= '
'; $output .= '
  • '.$Movetext.'
  • '; @@ -850,6 +927,7 @@ public static function htmlparse($matches) $output .= ''; $output .= '
'; + return $output; } @@ -940,13 +1018,14 @@ function(data) { }); return false; }); + function iasEffectEvent(el) { var id = $(el).attr('id'); $('img#uploadimg-'+id+'',el).imgAreaSelect({ handles:true, instance:true, classPrefix:'ias-'+id+' ias', - aspectRatio:'', + aspectRatio:'', onSelectEnd:function(img,selection) { $('#x1',el).val(selection.x1); $('#y1',el).val(selection.y1); @@ -957,6 +1036,7 @@ classPrefix:'ias-'+id+' ias', } }); } + function thumbCropEvent(el) { $('.crop',el).click(function() { var pli = $(this).parents('li'), @@ -996,6 +1076,7 @@ function(data) { return false; }); } + function imageDeleteEvent(el) { $('.delete',el).click(function() { var pli = $(this).parents('li'), @@ -1014,6 +1095,7 @@ function() { return false; }); } + function imageAddtoEvent(el) { $('.addto',el).click(function() { var pli = $(this).parents('li'), @@ -1056,8 +1138,10 @@ public static function headlink() $settings = $options->plugin('HighSlide'); $widget = Typecho_Widget::widget('Widget_Archive'); $hsurl = $options->pluginUrl.'/HighSlide/'; + $istype = self::replacelist(); $cssurl = ''; + //输出范围 if ($widget->is(''.$istype->index.'')||$widget->is(''.$istype->archive.'')||$widget->is(''.$istype->post.'')||$widget->is(''.$istype->page.'')) { $cssurl = ' @@ -1085,6 +1169,7 @@ public static function headlink() '; } + //时光胶带 if ($settings->gallery == 'gallery-vertical-strip') { $cssurl.= '