public function __construct() { $this->db = Typecho_Db::get(); $this->prefix = $this->db->getPrefix(); $this->table = $this->prefix . 'access'; $this->config = Typecho_Widget::widget('Widget_Options')->plugin('Access'); $this->request = Typecho_Request::getInstance(); $this->pageSize = $this->config->pageSize; $this->isDrop = $this->config->isDrop; if ($this->pageSize == null || $this->isDrop == null) { throw new Typecho_Plugin_Exception('请先设置插件!'); } switch ($this->request->get('action')) { case 'logs': default: $this->action = 'logs'; $this->title = '访问日志'; $this->parseLogs(); break; case 'overview': $this->action = 'overview'; $this->title = '访问概览'; $this->parseOverview(); break; } }
/** * 获取插件配置面板 * * @access public * @param Typecho_Widget_Helper_Form $form 配置面板 * @return void */ public static function config(Typecho_Widget_Helper_Form $form) { $config_file = dirname(__FILE__) . '/config.xml'; //config.xml的绝对地址 $xml = simplexml_load_file($config_file); $tables = new Typecho_Widget_Helper_Form_Element_Text('tables', null, (string) $xml->tables, _t('需要备份的表'), _t('键入表名,用“,”隔开')); $form->addInput($tables); $circle = new Typecho_Widget_Helper_Form_Element_Text('circle', null, (string) $xml->circle, _t('更新周期(天)')); $form->addInput($circle->addRule('isInteger', _t('更新周期必须是纯数字'))); $ToMail = new Typecho_Widget_Helper_Form_Element_Checkbox('tomail', array('tomail' => _t('发送备份文件至邮箱')), $xml->tomail ? explode(',', (string) $xml->tomail) : null, null, _t('<strong>重要:如果选择此项,请认真填写以下表单</strong>')); $form->addInput($ToMail); $subject = new Typecho_Widget_Helper_Form_Element_Text('subject', null, (string) $xml->subject, _t('自定义邮件标题'), _t('格式:20100902-XXX-数据库备份文件(不填则XXX默认为博客标题)')); $form->addInput($subject); $mode = new Typecho_Widget_Helper_Form_Element_Radio('mode', array('smtp' => 'smtp', 'mail' => 'mail()', 'sendmail' => 'sendmail()'), (string) $xml->mode, '发信方式'); $form->addInput($mode); $host = new Typecho_Widget_Helper_Form_Element_Text('host', NULL, (string) $xml->host, _t('SMTP地址'), _t('请填写 SMTP 服务器地址')); $form->addInput($host); $port = new Typecho_Widget_Helper_Form_Element_Text('port', NULL, (string) $xml->port, _t('SMTP端口'), _t('SMTP服务端口,一般为25;gmail和qq的465。')); $port->input->setAttribute('class', 'mini'); $form->addInput($port->addRule('isInteger', _t('端口号必须是纯数字'))); $user = new Typecho_Widget_Helper_Form_Element_Text('user', NULL, (string) $xml->user, _t('SMTP用户'), _t('SMTP服务验证用户名,一般为邮箱名如:youname@domain.com')); $form->addInput($user); $pass = new Typecho_Widget_Helper_Form_Element_Password('pass', NULL, NULL, _t('SMTP密码')); $form->addInput($pass); $validate = new Typecho_Widget_Helper_Form_Element_Checkbox('validate', array('validate' => '服务器需要验证', 'ssl' => 'ssl加密'), $xml->validate ? explode(',', (string) $xml->validate) : null, 'SMTP验证'); $form->addInput($validate); $mail = new Typecho_Widget_Helper_Form_Element_Text('mail', NULL, (string) $xml->mail, _t('接收邮箱'), _t('接收邮件用的信箱,如为空则使用博客创建者个人设置中的邮箱!')); $form->addInput($mail->addRule('email', _t('请填写正确的邮箱!'))); $request = Typecho_Request::getInstance(); if ($request->isPost()) { /** * 更新配置文件 */ $xml->tables = $request->get('tables'); $xml->circle = $request->get('circle'); if (is_array($request->get('tomail'))) { $xml->tomail = implode(',', $request->get('tomail')); } $xml->subject = $request->get('subject'); $xml->mode = $request->get('mode'); $xml->host = $request->get('host'); $xml->port = $request->get('port'); $xml->user = $request->get('user'); if (is_array($request->get('validate'))) { $xml->validate = implode(',', $request->get('validate')); } $xml->mail = $request->get('mail'); $xml = $xml->asXML(); $fp = fopen($config_file, 'wb'); fwrite($fp, $xml); fclose($fp); } }
public function __construct() { $this->response = Typecho_Response::getInstance(); $this->request = Typecho_Request::getInstance(); }
/** * 评论过滤器 * * @access public * @param array $comment 评论结构 * @param Typecho_Widget $post 被评论的文章 * @param array $result 返回的结果上下文 * @param string $api api地址 * @return void */ public static function filter($comment, $post, $result) { $captchaCode = Typecho_Request::getInstance()->captcha_code; if (empty($captchaCode)) { throw new Typecho_Widget_Exception(_t('请输入验证码')); } require_once 'Captcha/securimage/securimage.php'; $img = new securimage(); if (!$img->check($captchaCode)) { throw new Typecho_Widget_Exception(_t('验证码错误, 请重新输入')); } return $comment; }
public static function form($action = NULL) { /** 构建表格 */ $options = Typecho_Widget::widget('Widget_Options'); $form = new Typecho_Widget_Helper_Form(Typecho_Common::url('/action/huifeng-members-edit', $options->index), Typecho_Widget_Helper_Form::POST_METHOD); $form->setAttribute('enctype', 'multipart/form-data'); // 表示可以上传数据 /* 添加隐藏域限制上传大小 */ $maxfilesize = new Typecho_Widget_Helper_Form_Element_Hidden('MAX_FILE_SIZE', NULL, '1000000', NULL, NULL); $form->addInput($maxfilesize); // 限制大小的隐藏域应在上传标签之前 /** 头像 */ $image_upload = new Typecho_Widget_Helper_Form_Element_Text('image_upload', NULL, NULL, _t('上传头像'), NULL); // 用于头像图片上传 $image_upload->input->setAttribute('type', 'file'); $image = new Typecho_Widget_Helper_Form_Element_Text('image', NULL, NULL, _t('头像'), NULL); // 获取数据库里的头像地址 $img_show = new Typecho_Widget_Helper_Layout('img', NULL); $img_src = '/usr/plugins/HuifengMembers/nopic.jpg'; if ($image->getAttribute('src' != '')) { $img_src = $image->getAttribute('src'); } $img_show->setAttribute('src', $img_src); $img_show->setAttribute('height', '180'); $img_show->setAttribute('style', 'margin-top: 4em;max-width: 180px;max-height: 180px;'); $form->addItem($img_show); $form->addInput($image_upload); $form->addInput($image); /** 会员名称 */ // Typecho_Widget_Helper_Form_Element_Text ($name=NULL, array $options=NULL, $value=NULL, $label=NULL, $categories=NULL) $name = new Typecho_Widget_Helper_Form_Element_Text('name', NULL, NULL, _t('会员名称*'), _t('请填写真实姓名')); $form->addInput($name); /** 所在部门 */ $position = new Typecho_Widget_Helper_Form_Element_Text('position', NULL, NULL, _t('所在部门*'), _t('请正确填写所在部门科室')); $form->addInput($position); /** 联系电话 */ $tel = new Typecho_Widget_Helper_Form_Element_Text('tel', NULL, NULL, _t('联系电话'), NULL); $form->addInput($tel); /** 分类 */ $categories = new Typecho_Widget_Helper_Form_Element_Text('categories', NULL, NULL, _t('分类')); $form->addInput($categories); /** 是否值班 */ $is_onduty = new Typecho_Widget_Helper_Form_Element_Radio('is_onduty', array('否' => _t('否'), '是' => _t('是')), '否', _t('是否值班')); $form->addInput($is_onduty); /** 自定义数据 */ $field = new Typecho_Widget_Helper_Form_Element_Text('field', NULL, NULL, _t('自定义数据'), _t('该项用于用户自定义数据扩展')); $form->addInput($field); /** 会员动作 */ $do = new Typecho_Widget_Helper_Form_Element_Hidden('do'); $form->addInput($do); /** 会员主键 */ $mid = new Typecho_Widget_Helper_Form_Element_Hidden('mid'); $form->addInput($mid); /** 提交按钮 */ $submit = new Typecho_Widget_Helper_Form_Element_Submit(); $submit->input->setAttribute('class', 'btn primary'); $form->addItem($submit); $request = Typecho_Request::getInstance(); if (isset($request->mid) && 'insert' != $action) { /** 更新模式 */ $db = Typecho_Db::get(); $prefix = $db->getPrefix(); $member = $db->fetchRow($db->select()->from($prefix . 'hf_members')->where('mid = ?', $request->mid)); if (!$member) { throw new Typecho_Widget_Exception(_t('会员不存在'), 404); } $name->value($member['name']); $position->value($member['position']); $tel->value($member['tel']); $image->value($member['image']); $categories->value($member['categories']); $is_onduty->value($member['is_onduty']); $field->value($member['field']); $do->value('update'); $mid->value($member['mid']); $submit->value(_t('编辑会员')); $_action = 'update'; } else { $do->value('insert'); $submit->value(_t('增加会员')); $_action = 'insert'; } if (empty($action)) { $action = $_action; } /** 给表单增加规则 */ if ('insert' == $action || 'update' == $action) { $name->addRule('required', _t('必须填写会员名称')); $name->addRule('xssCheck', _t('请勿在会员名称栏输入特殊字符')); $position->addRule('required', _t('必须填写所在部门')); $position->addRule('xssCheck', _t('请勿在所在部门栏输入特殊字符')); // $position->addRule('url', _t('不是一个合法的url')); // $image->addRule('image', _t('不是一个合法的图片地址')); $tel->addRule('required', _t('必须填写联系电话')); $tel->addRule('isInteger', _t('电话号码必须是无符号整数')); $tel->addRule('minLength', _t('电话号码不得小于6位'), 6); $tel->addRule('maxLength', _t('电话号码不得大于11位'), 12); // $image->addRule('required', _t('必须上传头像图片')); } if ('update' == $action) { $mid->addRule('required', _t('会员主键不存在')); $mid->addRule(array(new HuifengMembers_Plugin(), 'HuifengMembersExists'), _t('会员不存在')); } return $form; }
<?php header('Content-Type: text/html; charset=UTF-8'); $rootDir = strstr(dirname(__FILE__), 'usr', TRUE); require_once $rootDir . 'config.inc.php'; require_once $rootDir . 'var/Typecho/Common.php'; require_once $rootDir . 'var/Typecho/Request.php'; require_once $rootDir . 'var/Widget/Upload.php'; $fileInfo = Widget_Upload::uploadHandle($_FILES['upload']); if (false === $fileInfo) { echo '上传失败!'; } else { echo sprintf("<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction(1, '%s', '');</script>", Typecho_Request::getInstance()->getUrlPrefix() . $fileInfo['path']); }
/** * 评论过滤器 * * @access public * @param array $comment 评论结构 * @param Typecho_Widget $post 被评论的文章 * @param array $result 返回的结果上下文 * @param string $api api地址 * @return void */ public static function filter($comment, $post, $result, $api = 'comment-check') { $comment = empty($result) ? $comment : $result; $options = Typecho_Widget::widget('Widget_Options'); $url = $options->plugin('Akismet')->url; $key = $options->plugin('Akismet')->key; $allowedServerVars = 'comment-check' == $api ? array('SCRIPT_URI', 'HTTP_HOST', 'HTTP_USER_AGENT', 'HTTP_ACCEPT', 'HTTP_ACCEPT_LANGUAGE', 'HTTP_ACCEPT_ENCODING', 'HTTP_ACCEPT_CHARSET', 'HTTP_KEEP_ALIVE', 'HTTP_CONNECTION', 'HTTP_CACHE_CONTROL', 'HTTP_PRAGMA', 'HTTP_DATE', 'HTTP_EXPECT', 'HTTP_MAX_FORWARDS', 'HTTP_RANGE', 'CONTENT_TYPE', 'CONTENT_LENGTH', 'SERVER_SIGNATURE', 'SERVER_SOFTWARE', 'SERVER_NAME', 'SERVER_ADDR', 'SERVER_PORT', 'REMOTE_PORT', 'GATEWAY_INTERFACE', 'SERVER_PROTOCOL', 'REQUEST_METHOD', 'QUERY_STRING', 'REQUEST_URI', 'SCRIPT_NAME', 'REQUEST_TIME') : array(); $data = array('blog' => $options->siteUrl, 'user_ip' => $comment['ip'], 'user_agent' => $comment['agent'], 'referrer' => Typecho_Request::getInstance()->getReferer(), 'permalink' => $post->permalink, 'comment_type' => $comment['type'], 'comment_author' => $comment['author'], 'comment_author_email' => $comment['mail'], 'comment_author_url' => $comment['url'], 'comment_content' => $comment['text']); foreach ($allowedServerVars as $val) { if (array_key_exists($val, $_SERVER)) { $data[$val] = $_SERVER[$val]; } } try { $client = Typecho_Http_Client::get(); if (false != $client && $key) { $params = parse_url($url); $url = $params['scheme'] . '://' . $key . '.' . $params['host'] . (isset($params['path']) ? $params['path'] : NULL); $client->setHeader('User-Agent', $options->generator . ' | Akismet/1.1')->setTimeout(5)->setData($data)->send(Typecho_Common::url('/1.1/' . $api, $url)); if ('true' == $client->getResponseBody()) { $comment['status'] = 'spam'; } } } catch (Typecho_Http_Client_Exception $e) { //do nothing error_log($e->getMessage()); } return $comment; }
/** * 工厂方法,将类静态化放置到列表中 * * @access public * @param string $alias 组件别名 * @param mixed $params 传递的参数 * @param mixed $request 前端参数 * @param boolean $enableResponse 是否允许http回执 * @return object * @throws Typecho_Exception */ public static function widget($alias, $params = NULL, $request = NULL, $enableResponse = true) { $parts = explode('@', $alias); $className = $parts[0]; $alias = empty($parts[1]) ? $className : $parts[1]; if (isset(self::$_widgetAlias[$className])) { $className = self::$_widgetAlias[$className]; } if (!isset(self::$_widgetPool[$alias])) { /** 如果类不存在 */ if (!class_exists($className)) { throw new Typecho_Widget_Exception($className); } /** 初始化request */ if (!empty($request)) { $requestObject = new Typecho_Request(); $requestObject->setParams($request); } else { $requestObject = Typecho_Request::getInstance(); } /** 初始化response */ $responseObject = $enableResponse ? Typecho_Response::getInstance() : Typecho_Widget_Helper_Empty::getInstance(); /** 初始化组件 */ $widget = new $className($requestObject, $responseObject, $params); $widget->execute(); self::$_widgetPool[$alias] = $widget; } return self::$_widgetPool[$alias]; }
} else { $this.show().parent().find('.uninstall').hide(); if( result.error != '' ){ $.sticky(errorStr + ',' + result.error, setting); } } }); }); $('.plugin .uninstall').on('click', function(){ var $this = $(this); var deactivateUrl = $this.data('url'); $.ajax({ url: '<?php echo str_replace('/market', '/uninstall', Typecho_Request::getInstance()->getRequestUrl()); ?> ', dataType: 'json', data: { plugin: $this.parents('.plugin').data('name') } }).done(function(result) { if (result.status) { $this.hide().parent().find('.install').show(); $.sticky('卸载成功...', setting); }else { $.ajax({ url: deactivateUrl }).done(function(){ $this.click();
public function show() { $str = ""; if ($this->current_page > 1) { $firstPageUrl = $this->buildUrl(1); $prevPageUrl = $this->buildUrl($this->current_page - 1); $str .= '<li><a href="' . $prevPageUrl . '">«</a></li>'; } else { $str .= ''; } $a = $this->construct_num_Page(); for ($i = 0; $i < count($a); $i++) { $s = $a[$i]; if ($s == $this->current_page) { $url = Typecho_Request::getInstance()->getRequestUrl(); $str .= '<li class="current"><a href="' . $url . '">' . $s . '</a></li>'; } else { $url = $this->buildUrl($s); $str .= '<li><a href="' . $url . '">' . $s . '</a></li>'; } } if ($this->current_page < $this->pageNums) { $lastPageUrl = $this->buildUrl($this->pageNums); $nextPageUrl = $this->buildUrl($this->current_page + 1); $str .= '<li><a href="' . $nextPageUrl . '">»</a></li>'; } else { $str .= ''; } return $str; }
?> ')) { return false; } } else { if (! confirm('<?php echo _t('该插件该版本已经存在了!\\n确定继续安装吗?'); ?> ')) { return false; } } } $.ajax({ url: '<?php echo str_replace('/market', '/install', Typecho_Request::getInstance()->makeUriByRequest()); ?> ', dataType: 'json', data: { version: $version.val(), require: $version.data('require'), plugin: $card.data('name') }, beforeSend: function() { $this.attr('disabled', true).text('正在安装, 请稍后...'); } }).always(function() { $this.attr('disabled', false).text('安装'); }).fail(function() { alert('安装失败');
/** * 构建相册表单 * * @access public * @param string $action,$render * @return Typecho_Widget_Helper_Form */ 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(); $submit->input->setAttribute('class', 'btn'); $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', ' <input type="text" class="w-10 text-s mono" name="fixedwidth" value="' . $settings->fixedwidth . '" />'), 'fixedheight' => _t('固定高度 %s', ' <input type="text" class="w-10 text-s mono" name="fixedheight" value="' . $settings->fixedheight . '" />'), 'fixedratio' => _t('固定比例 %s', ' <input type="text" class="w-10 text-s mono" name="fixedratio" value="' . $settings->fixedratio . '" />')); $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); $qiniuaccesskey = new Typecho_Widget_Helper_Form_Element_Text('qiniuaccesskey', NULL, $settings->qiniuaccesskey, _t('AccessKey')); $form2->addInput($qiniuaccesskey); $qiniusecretkey = new Typecho_Widget_Helper_Form_Element_Text('qiniusecretkey', NULL, $settings->qiniusecretkey, _t('SecretKey')); $form2->addInput($qiniusecretkey); $qiniuprefix = new Typecho_Widget_Helper_Form_Element_Text('qiniuprefix', NULL, $settings->qiniuprefix, _t('路径前缀'), _t('注意开头不要加/号')); $form2->addInput($qiniuprefix); $upyunbucket = new Typecho_Widget_Helper_Form_Element_Text('upyunbucket', NULL, $settings->upyunbucket, _t('空间名称')); $form2->addInput($upyunbucket); $upyundomain = new Typecho_Widget_Helper_Form_Element_Text('upyundomain', NULL, $settings->upyundomain, _t('绑定域名')); $form2->addInput($upyundomain); $upyunuser = new Typecho_Widget_Helper_Form_Element_Text('upyunuser', NULL, $settings->upyunuser, _t('操作员')); $form2->addInput($upyunuser); $upyunpwd = new Typecho_Widget_Helper_Form_Element_Text('upyunpwd', NULL, $settings->upyunpwd, _t('密码')); $form2->addInput($upyunpwd); $upyunkey = new Typecho_Widget_Helper_Form_Element_Text('upyunkey', NULL, $settings->upyunkey, _t('密匙')); $form2->addInput($upyunkey); $upyunprefix = new Typecho_Widget_Helper_Form_Element_Text('upyunprefix', NULL, $settings->upyunprefix, _t('路径前缀')); $form2->addInput($upyunprefix); $bcsbucket = new Typecho_Widget_Helper_Form_Element_Text('bcsbucket', NULL, $settings->bcsbucket, _t('空间名称')); $form2->addInput($bcsbucket); $bcsapikey = new Typecho_Widget_Helper_Form_Element_Text('bcsapikey', NULL, $settings->bcsapikey, _t('APIKey')); $form2->addInput($bcsapikey); $bcssecretkey = new Typecho_Widget_Helper_Form_Element_Text('bcssecretkey', NULL, $settings->bcssecretkey, _t('SecretKey')); $form2->addInput($bcssecretkey); $bcsprefix = new Typecho_Widget_Helper_Form_Element_Text('bcsprefix', NULL, $settings->bcsprefix, _t('路径前缀')); $form2->addInput($bcsprefix); $form2->addItem($submit); //隐藏模式 switch ($settings->storage) { case 'local': $qiniubucket->setAttribute('style', 'display:none;'); $qiniudomain->setAttribute('style', 'display:none;'); $qiniuaccesskey->setAttribute('style', 'display:none;'); $qiniusecretkey->setAttribute('style', 'display:none;'); $qiniuprefix->setAttribute('style', 'display:none;'); $upyunbucket->setAttribute('style', 'display:none;'); $upyundomain->setAttribute('style', 'display:none;'); $upyunuser->setAttribute('style', 'display:none;'); $upyunpwd->setAttribute('style', 'display:none;'); $upyunkey->setAttribute('style', 'display:none;'); $upyunprefix->setAttribute('style', 'display:none;'); $bcsbucket->setAttribute('style', 'display:none;'); $bcsapikey->setAttribute('style', 'display:none;'); $bcssecretkey->setAttribute('style', 'display:none;'); $bcsprefix->setAttribute('style', 'display:none;'); break; case 'qiniu': $local->setAttribute('style', 'display:none;'); $upyunbucket->setAttribute('style', 'display:none;'); $upyundomain->setAttribute('style', 'display:none;'); $upyunuser->setAttribute('style', 'display:none;'); $upyunpwd->setAttribute('style', 'display:none;'); $upyunkey->setAttribute('style', 'display:none;'); $upyunprefix->setAttribute('style', 'display:none;'); $bcsbucket->setAttribute('style', 'display:none;'); $bcsapikey->setAttribute('style', 'display:none;'); $bcssecretkey->setAttribute('style', 'display:none;'); $bcsprefix->setAttribute('style', 'display:none;'); break; case 'upyun': $local->setAttribute('style', 'display:none;'); $qiniubucket->setAttribute('style', 'display:none;'); $qiniudomain->setAttribute('style', 'display:none;'); $qiniuaccesskey->setAttribute('style', 'display:none;'); $qiniusecretkey->setAttribute('style', 'display:none;'); $qiniuprefix->setAttribute('style', 'display:none;'); $bcsbucket->setAttribute('style', 'display:none;'); $bcsapikey->setAttribute('style', 'display:none;'); $bcssecretkey->setAttribute('style', 'display:none;'); $bcsprefix->setAttribute('style', 'display:none;'); break; case 'bcs': $local->setAttribute('style', 'display:none;'); $qiniubucket->setAttribute('style', 'display:none;'); $qiniudomain->setAttribute('style', 'display:none;'); $qiniuaccesskey->setAttribute('style', 'display:none;'); $qiniusecretkey->setAttribute('style', 'display:none;'); $qiniuprefix->setAttribute('style', 'display:none;'); $upyunbucket->setAttribute('style', 'display:none;'); $upyundomain->setAttribute('style', 'display:none;'); $upyunuser->setAttribute('style', 'display:none;'); $upyunpwd->setAttribute('style', 'display:none;'); $upyunkey->setAttribute('style', 'display:none;'); $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('保存设置')); $_action = 'sync'; } else { $do->value('insert'); $submit->value(_t('添加图片')); $_action = 'insert'; } if (empty($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('请输入一个整数数字')); } if ($action == 'update') { $gid->addRule('required', _t('图片主键不存在')); $gid->addRule(array(new HighSlide_Plugin(), 'galleryexists'), _t('图片不存在')); } $form = $render == '1' ? $form1 : $form2; return $form; }
/** * 评论过滤器 * * @access public * @param array $comment 评论结构 * @param Typecho_Widget $post 被评论的文章 * @param array $result 返回的结果上下文 * @param string $api api地址 * @return void */ public static function filter($comment, $post, $result, $api = 'comment-check') { $comment = empty($result) ? $comment : $result; $options = Typecho_Widget::widget('Widget_Options'); $hosts = $options->plugin('BlockComment')->hosts; $data = array('blog' => $options->siteUrl, 'user_ip' => $comment['ip'], 'user_agent' => $comment['agent'], 'referrer' => Typecho_Request::getInstance()->getReferer(), 'permalink' => $post->permalink, 'comment_type' => $comment['type'], 'comment_author' => $comment['author'], 'comment_author_email' => $comment['mail'], 'comment_author_url' => $comment['url'], 'comment_content' => $comment['text']); foreach (split("\n", $hosts) as $key => $value) { $value = trim($value); if (strlen($value)) { $regex = sprintf("/^%s/i", preg_quote($value)); // 如果提交者符合指定的 IP,则扔进垃圾评论中 if (preg_match($regex, $data['user_ip'])) { $comment['status'] = 'spam'; break; } } } return $comment; }
/** * 验证Upyun签名 * * @access public * * @return boolean */ public static function validate() { $host = Typecho_Request::getInstance()->upyunhost; $user = Typecho_Request::getInstance()->upyunuser; $pwd = Typecho_Request::getInstance()->upyunpwd; $hostUsage = 0; try { require_once 'SDK/upyun.class.php'; $upyun = new UpYun($host, $user, $pwd); $hostUsage = (int) $upyun->getFolderUsage('/'); } catch (Exception $e) { $hostUsage = -1; } return $hostUsage >= 0; }
/** * 工厂方法,将类静态化放置到列表中 * * @access public * @param string $alias 组件别名 * @param mixed $params 传递的参数 * @param mixed $request 前端参数 * @param boolean $enableResponse 是否允许http回执 * @return object * @throws Typecho_Exception */ public static function widget($alias, $params = NULL, $request = NULL, $enableResponse = true) { list($className) = explode('@', $alias); if (!isset(self::$_widgetPool[$alias])) { $fileName = str_replace('_', '/', $className) . '.php'; require_once $fileName; /** 如果类不存在 */ if (!class_exists($className)) { /** Typecho_Exception */ require_once 'Typecho/Widget/Exception.php'; throw new Typecho_Widget_Exception($className); } /** 初始化request */ if (!empty($request)) { $requestObject = new Typecho_Request(); $requestObject->setParams($request); } else { $requestObject = Typecho_Request::getInstance(); } /** 初始化response */ $responseObject = $enableResponse ? Typecho_Response::getInstance() : Typecho_Widget_Helper_Empty::getInstance(); /** 初始化组件 */ $widget = new $className($requestObject, $responseObject, $params); $widget->execute(); self::$_widgetPool[$alias] = $widget; } return self::$_widgetPool[$alias]; }
public static function start() { if (self::hasLogin()) { return; } $config = Typecho_Widget::widget('Widget_Options')->plugin('Access'); $request = Typecho_Request::getInstance(); $ip = $request->getIp(); $url = $_SERVER['REQUEST_URI']; if ($ip == null) { $ip = 'UnKnow'; } $options = Typecho_Widget::widget('Widget_Options'); $timeStamp = $options->gmtTime; $offset = $options->timezone - $options->serverTimezone; $gtime = $timeStamp + $offset; $db = Typecho_Db::get(); $rows = array('ua' => $request->getAgent(), 'url' => $url, 'ip' => $ip, 'date' => $gtime); $db->query($db->insert('table.access')->rows($rows)); }
<?php $fileInfo = Widget_Upload::uploadHandle($_FILES['upfile']); $retInfo = array("state" => "SUCCESS", "url" => Typecho_Request::getInstance()->getUrlPrefix() . $fileInfo['path'], "title" => $fileInfo['path'], "original" => $fileInfo['name'], "type" => $fileInfo['type'], "size" => $fileInfo['size']); return json_encode($retInfo);
public static function form($action = NULL) { /** 构建表格 */ $options = Typecho_Widget::widget('Widget_Options'); $form = new Typecho_Widget_Helper_Form(Typecho_Common::url('/action/links-edit', $options->index), Typecho_Widget_Helper_Form::POST_METHOD); /** 链接名称 */ $name = new Typecho_Widget_Helper_Form_Element_Text('name', NULL, NULL, _t('链接名称*')); $form->addInput($name); /** 链接地址 */ $url = new Typecho_Widget_Helper_Form_Element_Text('url', NULL, "http://", _t('链接地址*')); $form->addInput($url); /** 链接分类 */ $sort = new Typecho_Widget_Helper_Form_Element_Text('sort', NULL, NULL, _t('链接分类'), _t('建议以英文字母开头,只包含字母与数字')); $form->addInput($sort); /** 链接图片 */ $image = new Typecho_Widget_Helper_Form_Element_Text('image', NULL, NULL, _t('链接图片'), _t('需要以http://开头,留空表示没有链接图片')); $form->addInput($image); /** 链接描述 */ $description = new Typecho_Widget_Helper_Form_Element_Textarea('description', NULL, NULL, _t('链接描述')); $form->addInput($description); /** 自定义数据 */ $user = new Typecho_Widget_Helper_Form_Element_Text('user', NULL, NULL, _t('自定义数据'), _t('该项用于用户自定义数据扩展')); $form->addInput($user); /** 链接动作 */ $do = new Typecho_Widget_Helper_Form_Element_Hidden('do'); $form->addInput($do); /** 链接主键 */ $lid = new Typecho_Widget_Helper_Form_Element_Hidden('lid'); $form->addInput($lid); /** 提交按钮 */ $submit = new Typecho_Widget_Helper_Form_Element_Submit(); $form->addItem($submit); $request = Typecho_Request::getInstance(); if (isset($request->lid) && 'insert' != $action) { /** 更新模式 */ $db = Typecho_Db::get(); $prefix = $db->getPrefix(); $link = $db->fetchRow($db->select()->from($prefix . 'links')->where('lid = ?', $request->lid)); if (!$link) { throw new Typecho_Widget_Exception(_t('链接不存在'), 404); } $name->value($link['name']); $url->value($link['url']); $sort->value($link['sort']); $image->value($link['image']); $description->value($link['description']); $user->value($link['user']); $do->value('update'); $lid->value($link['lid']); $submit->value(_t('编辑链接')); $_action = 'update'; } else { $do->value('insert'); $submit->value(_t('增加链接')); $_action = 'insert'; } if (empty($action)) { $action = $_action; } /** 给表单增加规则 */ if ('insert' == $action || 'update' == $action) { $name->addRule('required', _t('必须填写链接名称')); $url->addRule('required', _t('必须填写链接地址')); $url->addRule('url', _t('不是一个合法的链接地址')); $image->addRule('url', _t('不是一个合法的图片地址')); } if ('update' == $action) { $lid->addRule('required', _t('链接主键不存在')); $lid->addRule(array(new Links_Plugin(), 'LinkExists'), _t('链接不存在')); } return $form; }
public static function form($action = NULL) { $request = Typecho_Request::getInstance(); /** 构建表格 */ $options = Typecho_Widget::widget('Widget_Options'); $form = new Typecho_Widget_Helper_Form(Typecho_Common::url('/action/DomainTheme-edit', $options->index), Typecho_Widget_Helper_Form::POST_METHOD); /** 名称 */ $name = new Typecho_Widget_Helper_Form_Element_Text(self::$FORM_PRE . 'name', NULL, NULL, _t('名称')); $form->addInput($name); /** 地址 */ $url = new Typecho_Widget_Helper_Form_Element_Text(self::$FORM_PRE . 'domain', NULL, "", _t('域名')); $form->addInput($url); /** 主题 */ self::$TEMP_THEME_NAME = isset($request->themename) ? $request->themename : 'default'; $themes = array_map('basename', glob(__TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__ . '/*')); $themes = array_combine($themes, $themes); $theme = new DomainTheme_Element_Select(self::$FORM_PRE . 'theme', $themes, self::$TEMP_THEME_NAME, _t('主题名称'), _t('模板名称')); $form->addInput($theme); /** 模板数据 **/ $template_data = array(); /** 链接动作 */ $do = new Typecho_Widget_Helper_Form_Element_Hidden(self::$FORM_PRE . 'do'); $form->addInput($do); /** 链接主键 */ $id = new Typecho_Widget_Helper_Form_Element_Hidden(self::$FORM_PRE . 'id'); $form->addInput($id); /** 提交按钮 */ $submit = new Typecho_Widget_Helper_Form_Element_Submit(); $submit->input->setAttribute('class', 'btn primary'); $name->value(isset($request->name) ? $request->name : null); $url->value(isset($request->domain) ? $request->domain : null); if (isset($request->id) && 'insert' != $action) { /** 更新模式 */ $db = Typecho_Db::get(); $prefix = $db->getPrefix(); $link = $db->fetchRow($db->select()->from($prefix . 'domaintheme')->where('id = ?', $request->id)); if (!$link) { throw new Typecho_Widget_Exception(_t('链接不存在'), 404); } $name->value(isset($request->name) ? $request->name : $link['name']); $url->value(isset($request->domain) ? $request->domain : $link['domain']); //$user->value($link['user']); $template_data = json_decode($link['user'], true); if (!isset($request->themename)) { self::$TEMP_THEME_NAME = $link['theme']; $theme->value($link['theme']); } $do->value('update'); $id->value($link['id']); $submit->value(_t('编辑')); $_action = 'update'; } else { $do->value('insert'); $submit->value(_t('增加')); $_action = 'insert'; } if (empty($action)) { $action = $_action; } /** 给表单增加规则 */ if ('insert' == $action || 'update' == $action) { $name->addRule('required', _t('必须填写名称')); $url->addRule('required', _t('必须填写域名地址')); $theme->addRule('required', _t('必须填写模板名称')); } if ('update' == $action) { $id->addRule('required', _t('链接主键不存在')); } /** 自定义数据 */ //$user = new Typecho_Widget_Helper_Form_Element_Textarea('user', NULL, NULL, _t('自定义数据'), _t('该项用于用户自定义数据扩展(json格式)')); //$form->addInput($user); self::configTheme($form, $template_data); $form->addItem($submit); return $form; }