本文整理汇总了PHP中Typecho_Common::subStr方法的典型用法代码示例。如果您正苦于以下问题:PHP Typecho_Common::subStr方法的具体用法?PHP Typecho_Common::subStr怎么用?PHP Typecho_Common::subStr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Typecho_Common
的用法示例。
在下文中一共展示了Typecho_Common::subStr方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPosts
/**
* 返回所有的文章
* news:
* count:
* articles:
* [
* author:
* title:
* time:
* excerp:
* ]
* @return {}
*/
public function getPosts()
{
$_cats = $this->db->fetchAll($this->db->select('slug, name, mid, count, description')->from('table.metas')->where('type = ?', 'category'));
$_cat_item = array();
$res = array();
foreach ($_cats as $key => $value) {
$_articles_db = $this->db->fetchAll($this->db->select('table.contents.slug, table.contents.cid, table.contents.text, table.contents.title, table.contents.created, table.users.screenName')->from('table.contents')->join('table.relationships', 'table.relationships.cid = table.contents.cid')->join('table.users', 'table.users.uid = table.contents.authorId')->where('table.contents.status = ?', 'publish')->where('table.contents.type = ?', 'post')->where('table.relationships.mid = ?', $value['mid']));
//$_articles = array();
foreach ($_articles_db as $key => $_value_article) {
//$_value_article['slug'] = $_value_article[];
//$_value_article['title'] = $_value_article[];
$_value_article['author'] = $_value_article['screenName'];
unset($_value_article['screenName']);
$_value_article['excerp'] = Typecho_Common::subStr(strip_tags($_value_article['text']), 0, 100, '...');
unset($_value_article['text']);
$_value_article['time'] = $_value_article['created'];
unset($_value_article['created']);
/* 最好在上面内联选择出来 */
$_value_article['banner'] = self::getBanner($_value_article['cid']);
$_articles_db[$key] = $_value_article;
//$_articles[] = $_value_article;
}
$_cat_item['articles'] = $_articles_db;
$_cat_item['count'] = $value['count'];
$_cat_item['name'] = $value['name'];
$_cat_item['description'] = $value['description'];
$res[$value['slug']] = $_cat_item;
}
return $res;
}
示例2: loadcomments
public function loadcomments()
{
$t = $this->request->filter('int')->t;
if (empty($t)) {
$this->response->throwJson(array('status' => 0));
}
$comments = $this->widget('Widget_Comments_List', 'desc=0&limit=1&last=' . $t);
$data = array();
if ($comments->have()) {
while ($comments->next()) {
$data[] = array('permalink' => $comments->permalink, 'authorAvatar' => $comments->poster->avatar, 'authorName' => $comments->poster->name, 'content' => Typecho_Common::subStr(strip_tags($comments->content), 0, 35));
}
}
if (empty($data)) {
$this->response->throwJson(array('status' => 0));
}
$this->response->throwJson(array('status' => 1, 'data' => $data, 'last' => $comments->created));
}
示例3: title
/**
* 输出标题
*
* @access public
* @param integer $length 标题截取长度
* @param string $trim 截取后缀
* @return void
*/
public function title($length = 0, $trim = '...')
{
$title = $this->pluginHandle()->trigger($plugged)->title($this->title, $this);
if (!$plugged) {
echo $length > 0 ? Typecho_Common::subStr($this->title, 0, $length, $trim) : $this->title;
}
}
示例4: pingbackPing
/**
* pingbackPing
*
* @param string $source
* @param string $target
* @access public
* @return void
*/
public function pingbackPing($source, $target)
{
/** 检查源地址是否存在*/
if (!($http = Typecho_Http_Client::get())) {
return new IXR_Error(16, _t('源地址服务器错误'));
}
try {
$http->setTimeout(5)->send($source);
$response = $http->getResponseBody();
if (200 == $http->getResponseStatus()) {
if (!$http->getResponseHeader('x-pingback')) {
preg_match_all("/<link[^>]*rel=[\"']([^\"']*)[\"'][^>]*href=[\"']([^\"']*)[\"'][^>]*>/i", $response, $out);
if (!isset($out[1]['pingback'])) {
return new IXR_Error(50, _t('源地址不支持PingBack'));
}
}
} else {
return new IXR_Error(16, _t('源地址服务器错误'));
}
} catch (Exception $e) {
return new IXR_Error(16, _t('源地址服务器错误'));
}
/** 检查目标地址是否正确*/
$pathInfo = Typecho_Common::url(substr($target, strlen($this->options->index)), '/');
$post = Typecho_Router::match($pathInfo);
/** 这样可以得到cid或者slug*/
if (!$post instanceof Widget_Archive || !$post->have() || !$post->is('single')) {
return new IXR_Error(33, _t('这个目标地址不存在'));
}
if ($post) {
/** 检查是否可以ping*/
if ($post->allowPing) {
/** 现在可以ping了,但是还得检查下这个pingback是否已经存在了*/
$pingNum = $this->db->fetchObject($this->db->select(array('COUNT(coid)' => 'num'))->from('table.comments')->where('table.comments.cid = ? AND table.comments.url = ? AND table.comments.type <> ?', $post->cid, $source, 'comment'))->num;
if ($pingNum <= 0) {
/** 现在开始插入以及邮件提示了 $response就是第一行请求时返回的数组*/
preg_match("/\\<title\\>([^<]*?)\\<\\/title\\>/is", $response, $matchTitle);
$finalTitle = Typecho_Common::removeXSS(trim(strip_tags($matchTitle[1])));
/** 干掉html tag,只留下<a>*/
$text = Typecho_Common::stripTags($response, '<a href="">');
/** 此处将$target quote,留着后面用*/
$pregLink = preg_quote($target);
/** 找出含有target链接的最长的一行作为$finalText*/
$finalText = '';
$lines = explode("\n", $text);
foreach ($lines as $line) {
$line = trim($line);
if (NULL != $line) {
if (preg_match("|<a[^>]*href=[\"']{$pregLink}[\"'][^>]*>(.*?)</a>|", $line)) {
if (strlen($line) > strlen($finalText)) {
/** <a>也要干掉,*/
$finalText = Typecho_Common::stripTags($line);
}
}
}
}
/** 截取一段字*/
if (NULL == trim($finalText)) {
return new IXR_Error('17', _t('源地址中不包括目标地址'));
}
$finalText = '[...]' . Typecho_Common::subStr($finalText, 0, 200, '') . '[...]';
$pingback = array('cid' => $post->cid, 'created' => $this->options->gmtTime, 'agent' => $this->request->getAgent(), 'ip' => $this->request->getIp(), 'author' => $finalTitle, 'url' => Typecho_Common::safeUrl($source), 'text' => $finalText, 'ownerId' => $post->author->uid, 'type' => 'pingback', 'status' => $this->options->commentsRequireModeration ? 'waiting' : 'approved');
/** 加入plugin */
$pingback = $this->pluginHandle()->pingback($pingback, $post);
/** 执行插入*/
$insertId = $this->singletonWidget('Widget_Abstract_Comments')->insert($pingback);
/** 评论完成接口 */
$this->pluginHandle()->finishPingback($this);
return $insertId;
/** todo:发送邮件提示*/
} else {
return new IXR_Error(48, _t('PingBack已经存在'));
}
} else {
return IXR_Error(49, _t('目标地址禁止Ping'));
}
} else {
return new IXR_Error(33, _t('这个目标地址不存在'));
}
}
示例5: excerpt
/**
* 输出评论摘要
*
* @access public
* @param integer $length 摘要截取长度
* @param string $trim 摘要后缀
* @return void
*/
public function excerpt($length = 100, $trim = '...')
{
echo Typecho_Common::subStr(strip_tags($this->content), 0, $length, $trim);
}
示例6: sqlData
private function sqlData($postObj, $data)
{
$_subMaxNum = Helper::options()->plugin('WeChatHelper')->subMaxNum;
$resultStr = "";
$num = 0;
$tmpPicUrl = "";
if ($data != null) {
foreach ($data as $val) {
$val = Typecho_Widget::widget('Widget_Abstract_Contents')->filter($val);
$content = Typecho_Common::subStr($this->deleteHtml($val['text']), 0, $_subMaxNum, '...');
$preg = "/<img\\ssrc=(\\'|\")(.*?)\\.(jpg|png)(\\'|\")/is";
preg_match($preg, $val['text'], $images);
if ($images == null) {
$tmpPicUrl = $this->_options->imageDefault;
} else {
$tmpPicUrl = $images[2] . '.' . $images[3];
}
$resultStr .= sprintf($this->_itemTpl, $val['title'], $content, $tmpPicUrl, $val['permalink']);
$num++;
}
} else {
$resultStr = "没有找到任何信息!";
}
$fromUsername = $postObj->FromUserName;
$toUsername = $postObj->ToUserName;
$time = time();
if ($data != null) {
$resultStr = sprintf($this->_imageTpl, $fromUsername, $toUsername, $time, $num, $resultStr);
} else {
$resultStr = sprintf($this->_textTpl, $fromUsername, $toUsername, $time, $resultStr);
}
return $resultStr;
}
示例7: _e
single<?php
}
?>
">
<!--[if lt IE 8]>
<div class="browsehappy" role="dialog"><?php
_e('当前网页 <strong>不支持</strong> 你正在使用的浏览器. 为了正常的访问, 请 <a href="http://browsehappy.com/">升级你的浏览器</a>');
?>
.</div>
<![endif]-->
<div id="nav">
<?php
if ($this->options->logoText) {
$logoText = mb_strlen($this->options->logoText) > 1 ? Typecho_Common::subStr($this->options->logoText, 0, 1, '') : $this->options->logoText;
} else {
$logoText = Typecho_Common::subStr($this->options->title, 0, 1, '');
}
?>
<nav class="nav-menu">
<a class="site-name<?php
if ($this->is('index')) {
?>
current<?php
}
?>
" href="<?php
$this->options->siteUrl();
?>
" title="<?php
$this->options->description();
?>
示例8: trackback
/**
* 引用处理函数
*
* @access private
* @return void
*/
private function trackback()
{
/** 如果不是POST方法 */
if (!$this->request->isPost() || $this->request->getReferer()) {
$this->response->redirect($this->_content->permalink);
}
/** 如果库中已经存在当前ip为spam的trackback则直接拒绝 */
if ($this->size($this->select()->where('status = ? AND ip = ?', 'spam', $this->request->getIp())) > 0) {
/** 使用404告诉机器人 */
throw new Typecho_Widget_Exception(_t('找不到内容'), 404);
}
$trackback = array('cid' => $this->_content->cid, 'created' => $this->options->gmtTime, 'agent' => $this->request->getAgent(), 'ip' => $this->request->getIp(), 'ownerId' => $this->_content->author->uid, 'type' => 'trackback', 'status' => $this->options->commentsRequireModeration ? 'waiting' : 'approved');
$trackback['author'] = $this->request->filter('trim')->blog_name;
$trackback['url'] = $this->request->filter('trim')->url;
$trackback['text'] = $this->request->excerpt;
//检验格式
$validator = new Typecho_Validate();
$validator->addRule('url', 'required', 'We require all Trackbacks to provide an url.')->addRule('url', 'url', 'Your url is not valid.')->addRule('url', 'maxLength', 'Your url is not valid.', 200)->addRule('text', 'required', 'We require all Trackbacks to provide an excerption.')->addRule('author', 'required', 'We require all Trackbacks to provide an blog name.')->addRule('author', 'xssCheck', 'Your blog name is not valid.')->addRule('author', 'maxLength', 'Your blog name is not valid.', 200);
$validator->setBreak();
if ($error = $validator->run($trackback)) {
$message = array('success' => 1, 'message' => current($error));
$this->response->throwXml($message);
}
/** 截取长度 */
$trackback['text'] = Typecho_Common::subStr($trackback['text'], 0, 100, '[...]');
/** 如果库中已经存在重复url则直接拒绝 */
if ($this->size($this->select()->where('cid = ? AND url = ? AND type <> ?', $this->_content->cid, $trackback['url'], 'comment')) > 0) {
/** 使用403告诉机器人 */
throw new Typecho_Widget_Exception(_t('禁止重复提交'), 403);
}
/** 生成过滤器 */
$trackback = $this->pluginHandle()->trackback($trackback, $this->_content);
/** 添加引用 */
$this->insert($trackback);
/** 评论完成接口 */
$this->pluginHandle()->finishTrackback($this);
/** 返回正确 */
$this->response->throwXml(array('success' => 0, 'message' => 'Trackback has registered.'));
}
示例9: SB_comment
function SB_comment($param)
{
$comments = Typecho_Widget::widget('Widget_Comments_Recent', 'ignoreAuthor=true&pageSize=' . (empty($param["max"]) ? "5" : $param["max"]));
if (!$comments->have()) {
return '';
}
$text = '<aside class="widget widget_minty_recentcomments clearfix"><h3 class="widget-title"><span>近期评论</span></h3><ul id="minty_recentcomments">';
while ($comments->next()) {
$url = !empty($comments->url) ? $comments->url : "#";
$text .= "<li><a href=\"" . $url . "\" target=\"_blank\" rel=\"external nofollow\" class=\"avatar\"><img alt=\"\" src=\"" . getAvatar(32, $comments->mail) . "\" class=\"avatar\" height=\"32\" width=\"32\" /></a><div class=\"bd\"><a href=\"" . $url . "\" rel=\"external nofollow\" class=\"url\">" . $comments->author . "</a><a href=\"" . $comments->permalink . "\" class=\"desc\" title=\"发表在 " . timesince($comments->created) . "\">" . Typecho_Common::subStr(strip_tags($comments->text), 0, 25, '...') . "</a></div></li>";
}
return $text . '</ul></aside>';
}
示例10: TsinaSync
/**
* 同步文章到新浪微博
*
* @access public
* @param $content $class
* @return status
*/
public static function TsinaSync($content, $class)
{
//获取插件的配置
$config = self::getWeiboSyncCfg();
//如果不是文章编辑(对象$class属于Widget_Abstract_Contents,是否等于对象的值Widget_Contents_Post_Edit,它继承Widget_Abstract_Contents对象),则直接返回内容
if (!is_a($class, 'Widget_Contents_Post_Edit')) {
return $content;
}
if ($config->sina_mode == '1') {
if (!$class->request->is("do=publish") || $class->request->is("do=publish") && !$class->have()) {
return $content;
}
} else {
if (!$class->request->is("do=publish") || $class->request->is("do=publish") && !empty($class->request->cid)) {
return $content;
}
}
$format = $config->sina_format ? $config->sina_format : '我在TypeCodes上发表了一篇文章《{title}》,链接地址{link}';
$title = $content['title'];
$link = self::SinaShortUrl($content['permalink']);
//如果插件配置中出现了{more}标签,即需要提取文章的摘要信息
if (strpos($format, '{more}') !== false) {
if (strpos($content['text'], '<!--more-->') !== false) {
$more_t = explode('<!--more-->', $content['text']);
list($more) = $more_t;
$more = Typecho_Common::fixHtml(Typecho_Common::cutParagraph($more));
$more = Typecho_Common::subStr(strip_tags($more), 0, 60, '...');
} else {
$more = $content['text'];
$more = Typecho_Common::fixHtml(Typecho_Common::cutParagraph($more));
$more = Typecho_Common::subStr(strip_tags($more), 0, 60, '...');
}
} else {
$more = "";
}
$search = array('{title}', '{link}', '{more}');
$replace = array($title, $link, $more);
$format = str_replace($search, $replace, $format);
$post_img = '';
if ($config->sina_imgflag) {
$content_substr = mb_substr($content['text'], 0, 900, 'utf-8');
if (preg_match('/!\\[[^\\]]*]\\((https):\\/\\/[^\\)]*\\.(png|jpg)(.*)\\)/i', $content_substr, $img_match)) {
if (preg_match('/(https:\\/\\/)[^>]*?\\.(png|jpg)/i', $img_match[0], $img_match_retult)) {
$post_img = $img_match_retult[0];
}
}
}
self::PostWeibo($format, $post_img);
return $content;
}