示例#1
0
 /**
  * query 對 db 下 SQL query
  * 
  * @param mixed $sql 
  * @access protected
  * @return Mysqli result
  */
 public function query($sql, $table = null)
 {
     $short_sql = mb_strimwidth($sql, 0, 512, "...len=" . strlen($sql));
     if (Pix_Table::$_log_groups[Pix_Table::LOG_QUERY]) {
         Pix_Table::debug(sprintf("[%s]\t%40s", $this->_link->host_info, $short_sql));
     }
     // TODO 需要 log SQL Query 功能
     if ($comment = Pix_Table::getQueryComment()) {
         $sql = trim($sql, '; ') . ' #' . $comment;
     }
     $starttime = microtime(true);
     $res = $this->_link->query($sql);
     if ($t = Pix_Table::getLongQueryTime() and ($delta = microtime(true) - $starttime) > $t) {
         Pix_Table::debug(sprintf("[%s]\t%s\t%40s", $this->_link->host_info, $delta, $sql));
     }
     if ($res === false) {
         if ($errno = $this->_link->errno) {
             switch ($errno) {
                 case 1062:
                     throw new Pix_Table_DuplicateException($this->_link->error, $errno);
                 case 1406:
                     throw new Pix_Table_DataTooLongException($this->_link->error, $errno);
                 default:
                     throw new Exception("SQL Error: {$this->_link->error} SQL: {$sql}");
             }
         }
     }
     return $res;
 }
示例#2
0
 function widget($args, $instance)
 {
     extract($args);
     $user_id = $instance['user_id'];
     if (empty($user_id)) {
         if (is_author()) {
             $user_id = get_queried_object_id();
         } else {
             return;
         }
     }
     $title = apply_filters('widget_title', $title, $instance, $this->id_base);
     $title = sprintf($instance['title'], '<span class="display-name">' . get_the_author_meta('display_name', $user_id) . '</span>');
     $bio = get_the_author_meta('description', $user_id);
     if ($instance['strip_tags']) {
         $bio = strip_tags($bio);
     }
     if (function_exists('mb_strimwidth') && ($bio_length = $instance['bio_length'])) {
         $bio = mb_strimwidth($bio, 0, $bio_length);
     }
     echo $before_widget;
     if (!empty($title)) {
         echo $before_title . $title . $after_title;
     }
     echo '<div class="bio">' . wpautop($bio) . '</div>';
     echo $after_widget;
 }
示例#3
0
 public function index()
 {
     // 首页的标题,关键词,描述
     $siteInfo = M('enewspublic')->field('sitename, sitekey, siteintro')->find();
     $this->assign('siteInfo', $siteInfo);
     // 图片资讯 推1
     $picArticles = $this->getArticles('', 5, 1, 1);
     $this->assign('picArticles', $picArticles);
     // 热点推荐 推2
     $recommArticles = $this->getArticles('', 5, 0, 2);
     $recommContent = $this->formatArticleContent($recommArticles[0]['newstext']);
     $recommArticles[0]['newstext'] = mb_strimwidth(strip_tags($recommContent), 0, 150, '...', 'utf-8');
     $this->assign('recommArticles', $recommArticles);
     // 普通资讯 推3
     $normalArticles = $this->getArticles('', 1, 0, 3);
     $normalContent = $this->formatArticleContent($normalArticles['newstext']);
     $normalArticles['newstext'] = mb_strimwidth(strip_tags($normalContent), 0, 400, '...', 'utf-8');
     $normalArticles['wordcount'] = mb_strlen(strip_tags($normalContent));
     $this->assign('normalArticles', $normalArticles);
     // 滚动图片 推4
     $rollPics = $this->getArticles('', 16, 1, 4);
     $this->assign('rollPics', $rollPics);
     // 动作分类 科幻魔幻 情景喜剧 ...
     $classArticles = $this->classArticles();
     $this->assign('classArticles', $classArticles);
     // 文章归档
     $archives = $this->archives();
     $this->assign('archives', $archives);
     // 友情链接
     $friendlyLink = $this->friendlyLink();
     $this->assign('friendlyLink', $friendlyLink);
     $this->display();
 }
示例#4
0
 public function query($sql)
 {
     $short_sql = mb_strimwidth($sql, 0, 512, "...len=" . strlen($sql));
     if (Pix_Table::$_log_groups[Pix_Table::LOG_QUERY]) {
         Pix_Table::debug(sprintf("[%s]\t%40s", $this->_path . $this->_name, $short_sql));
     }
     $starttime = microtime(true);
     $statement = $this->_pdo->prepare($sql);
     if (!$statement) {
         if ($errno = $this->_pdo->errorCode()) {
             $errorInfo = $this->_pdo->errorInfo();
         }
         if ($errorInfo[2] == 'PRIMARY KEY must be unique' or preg_match('/duplicate key value violates unique constraint/', $errorInfo[2])) {
             throw new Pix_Table_DuplicateException($errorInfo[2]);
         }
         throw new Exception("SQL Error: ({$errorInfo[0]}:{$errorInfo[1]}) {$errorInfo[2]} (SQL: {$short_sql})");
     }
     $res = $statement->execute();
     if ($t = Pix_Table::getLongQueryTime() and ($delta = microtime(true) - $starttime) > $t) {
         Pix_Table::debug(sprintf("[%s]\t%s\t%40s", $this->_pdo->getAttribute(PDO::ATTR_SERVER_INFO), $delta, $short_sql));
     }
     if ($res === false) {
         if ($errno = $statement->errorCode()) {
             $errorInfo = $statement->errorInfo();
         }
         if ($errorInfo[2] == 'PRIMARY KEY must be unique' or preg_match('/duplicate key value violates unique constraint/', $errorInfo[2])) {
             throw new Pix_Table_DuplicateException($errorInfo[2]);
         }
         throw new Exception("SQL Error: ({$errorInfo[0]}:{$errorInfo[1]}) {$errorInfo[2]} (SQL: {$short_sql})");
     }
     return new Pix_Table_Db_Adapter_PDO_Result($statement);
 }
示例#5
0
function substr_content($content)
{
    if (!is_singular()) {
        $content = mb_strimwidth(strip_tags($content), 0, 310);
    }
    return $content;
}
示例#6
0
 /**
  * Execute the command.
  *
  * @param  \Symfony\Component\Console\Input\InputInterface  $input
  * @param  \Symfony\Component\Console\Output\OutputInterface  $output
  * @return void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $client = new Client();
     $modname = $input->getArgument('modname');
     $modversion = $input->getArgument('modversion');
     $config = solder_config();
     $response = $client->get($config->api);
     $server = $response->json();
     $response = $client->get($config->api . '/mod/' . $modname . '/' . $modversion);
     $json = $response->json();
     if (isset($json['error'])) {
         throw new \Exception($json['error']);
     }
     $rows = array();
     foreach ($json as $key => $value) {
         if ($key == 'versions') {
             $rows[] = array("<info>{$key}</info>", implode($value, "\n"));
         } else {
             $rows[] = array("<info>{$key}</info>", mb_strimwidth($value, 0, 80, "..."));
         }
     }
     $output->writeln('<comment>Server:</comment>');
     $output->writeln(" <info>{$server['api']}</info> version {$server['version']}");
     $output->writeln(" {$api}");
     $output->writeln('');
     $output->writeln("<comment>Mod:</comment>");
     $table = new Table($output);
     $table->setRows($rows)->setStyle('compact')->render();
 }
示例#7
0
/**
 *  smarty modifier:文字列のwordwrap処理
 *
 *  sample:
 *  <code>
 *  {"あいうaえaおaかきaaaくけこ"|wordwrap_i18n:8}
 *  </code>
 *  <code>
 *  あいうa
 *  えaおaか
 *  きaaaく
 *  けこ
 *  </code>
 *
 *  @param  string  $string wordwrapする文字列
 *  @param  string  $break  改行文字
 *  @param  int     $width  wordwrap幅(半角$width文字でwordwrapする)
 *  @param  int     $indent インデント幅(半角$indent文字)
 *                          数値を指定するが、はじめの行はインデントされない
 *  @return string  wordwrap処理された文字列
 */
function smarty_modifier_wordwrap_i18n($string, $width, $break = "\n", $indent = 0)
{
    $ctl = Ethna_Controller::getInstance();
    $client_enc = $ctl->getClientEncoding();
    //    いわゆる半角を単位にしてwrapする位置を測るため、いったん
    //    EUC_JP に変換する
    $euc_string = mb_convert_encoding($string, 'EUC_JP', $client_enc);
    $r = "";
    $i = "{$break}" . str_repeat(" ", $indent);
    $tmp = $euc_string;
    do {
        $n = strpos($tmp, $break);
        if ($n !== false && $n < $width) {
            $s = substr($tmp, 0, $n);
            $r .= $s . $i;
            $tmp = substr($tmp, strlen($s) + strlen($break));
            continue;
        }
        $s = mb_strimwidth($tmp, 0, $width, "", 'EUC_JP');
        $tmp = substr($tmp, strlen($s));
        $r .= $s . (strlen($tmp) > 0 ? $i : '');
    } while (strlen($tmp) > 0);
    //    最後に、クライアントエンコーディングに変換
    $r = mb_convert_encoding($r, $client_enc, 'EUC_JP');
    return $r;
}
示例#8
0
 /**
  * Limit the number of characters in a string.
  *
  * @param string $value
  * @param int    $limit
  * @param string $end
  *
  * @return string
  */
 public static function limit(string $value, int $limit = 100, string $end = '...') : string
 {
     if (mb_strwidth($value, 'UTF-8') <= $limit) {
         return $value;
     }
     return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')) . $end;
 }
示例#9
0
 function endElement($parser, $tagName)
 {
     if ($tagName == "ITEM") {
         //if ($this->status) print "[$this->status] ";
         $title = trim($this->title);
         if (!empty($this->title_width) && function_exists('mb_strimwidth')) {
             $title = mb_strimwidth($title, 0, $this->title_width, '...', $this->charset);
         }
         $title = sprintf("<a href='%s' title='%s' target='_content'>%s</a>", trim($this->link), _html_escape($this->title), _html_escape($title));
         #printf("<p>%s</p>",
         #  _html_escape(trim($this->description)));
         if ($this->date) {
             $date = trim($this->date);
             $date[10] = " ";
             # 2003-07-11T12:08:33+09:00
             # http://www.w3.org/TR/NOTE-datetime
             $zone = str_replace(":", "", substr($date, 19));
             $time = strtotime(substr($date, 0, 19) . $zone);
             $date = date($this->date_fmt, $time);
         }
         echo '<li><span data-timestamp="' . $time . '" class="date">', $date, '</span> ', $title, '</li>', "\n";
         $this->title = "";
         $this->description = "";
         $this->link = "";
         $this->date = "";
         $this->status = "";
         $this->insideitem = false;
     }
 }
示例#10
0
 public function mini_content($length = 100)
 {
     if (!isset($this->content)) {
         return '';
     }
     return $length ? mb_strimwidth(remove_ckedit_tag($this->content), 0, $length, '…', 'UTF-8') : remove_ckedit_tag($this->content);
 }
示例#11
0
/**
 * 字符串截取,支持中文和其他编码
 * @static
 * @access public
 * @param string $str 需要转换的字符串
 * @param string $start 开始位置
 * @param string $length 截取长度
 * @param string $charset 编码格式
 * @param string $suffix 截断显示字符
 * @return string
 */
function msubstr($str, $start = 0, $length, $charset = "utf-8", $suffix = false)
{
    if (function_exists("mb_strimwidth")) {
        $slice = mb_strimwidth($str, $start, $length, '', $charset);
        // mb_strimwidth 截取字符串 中文算2个字节,英文算1个
    } elseif (function_exists('mb_substr')) {
        $slice = mb_substr($str, $start, $length, $charset);
    } elseif (function_exists("iconv_substr")) {
        $slice = iconv_substr($str, $start, $length, $charset);
    } else {
        $re['utf-8'] = "/[-]|[�-�][�-�]|[�-�][�-�]{2}|[�-�][�-�]{3}/";
        $re['gb2312'] = "/[-]|[�-�][�-�]/";
        $re['gbk'] = "/[-]|[�-�][@-�]/";
        $re['big5'] = "/[-]|[�-�]([@-~]|�-�])/";
        preg_match_all($re[$charset], $str, $match);
        $slice = join("", array_slice($match[0], $start, $length));
    }
    if ($suffix) {
        return mb_strwidth($slice, $charset) > $length ? $slice : $slice . '...';
        // mb_strwidth 计算字符串长度 中文算2个字节,英文算1个
    } else {
        return $slice;
    }
    //    return $suffix ? $slice.'...' : $slice;
}
 private function trimTitles($data)
 {
     foreach ($data as &$entry) {
         $entry['label'] = utf8_encode(mb_strimwidth(@$entry['label'], 0, 25, "..."));
     }
     return $data;
 }
示例#13
0
 public function mini_href($length = 80)
 {
     if (!isset($this->href)) {
         return '';
     }
     return $length ? mb_strimwidth(remove_ckedit_tag($this->href), 0, $length, '…', 'UTF-8') : remove_ckedit_tag($this->href);
 }
 /**
  * getDatatable
  * Gets the datatable for the index page
  *
  * @return mixed
  * @author  Vincent Sposato <*****@*****.**>
  * @version v1.0
  */
 public function getDatatable()
 {
     $assetMaintenances = AssetMaintenance::orderBy('created_at', 'DESC')->get();
     $actions = new \Chumper\Datatable\Columns\FunctionColumn('actions', function ($assetMaintenances) {
         return '<a href="' . route('update/asset_maintenance', $assetMaintenances->id) . '" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a><a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('delete/asset_maintenance', $assetMaintenances->id) . '" data-content="' . Lang::get('admin/asset_maintenances/message.delete.confirm') . '" data-title="' . Lang::get('general.delete') . ' ' . htmlspecialchars($assetMaintenances->title) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';
     });
     return Datatable::collection($assetMaintenances)->addColumn('asset', function ($assetMaintenances) {
         return link_to('/hardware/' . $assetMaintenances->asset_id . '/view', mb_strimwidth($assetMaintenances->asset->name, 0, 50, "..."));
     })->addColumn('supplier', function ($assetMaintenances) {
         return link_to('/admin/settings/suppliers/' . $assetMaintenances->supplier_id . '/view', mb_strimwidth($assetMaintenances->supplier->name, 0, 50, "..."));
     })->addColumn('asset_maintenance_type', function ($assetMaintenances) {
         return $assetMaintenances->asset_maintenance_type;
     })->addColumn('title', function ($assetMaintenances) {
         return link_to('/admin/asset_maintenances/' . $assetMaintenances->id . '/view', mb_strimwidth($assetMaintenances->title, 0, 50, "..."));
     })->addColumn('start_date', function ($assetMaintenances) {
         return $assetMaintenances->start_date;
     })->addColumn('completion_date', function ($assetMaintenances) {
         return $assetMaintenances->completion_date;
     })->addColumn('asset_maintenance_time', function ($assetMaintenances) {
         if (is_null($assetMaintenances->asset_maintenance_time)) {
             $assetMaintenances->asset_maintenance_time = Carbon::now()->diffInDays(Carbon::parse($assetMaintenances->start_date));
         }
         return intval($assetMaintenances->asset_maintenance_time);
     })->addColumn('cost', function ($assetMaintenances) {
         return sprintf(Lang::get('general.currency') . '%01.2f', $assetMaintenances->cost);
     })->addColumn($actions)->searchColumns('asset', 'supplier', 'asset_maintenance_type', 'title', 'start_date', 'completion_date', 'asset_maintenance_time', 'cost', 'actions')->orderColumns('asset', 'supplier', 'asset_maintenance_type', 'title', 'start_date', 'completion_date', 'asset_maintenance_time', 'cost', 'actions')->make();
 }
示例#15
0
 function str_limit($value, $limit = 100, $end = '...')
 {
     if (mb_strwidth($value, 'UTF-8') <= $limit) {
         return $value;
     }
     return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')) . $end;
 }
/**
 * Smarty truncate modifier plugin, 根据宽度输出字符
 *
 * 需要提前设置 mb_internal_encoding("UTF-8") 或 mb_internal_encoding("GBK")
 *
 *
 * Type:     modifier<br>
 * Name:     truncate<br>
 * Purpose:  Smary 自带的truncate只支持英文半角,这里是修改版本,去除了$break_word和middle最后两个参数,
 *           修改支持全角各类UTF或中文字符
 *           本函数主要是依赖字符宽度控制.
 *           如果是处理UTF-8,需要提前设置 mb_internal_encoding("UTF-8") .
 * @author   liut < Eagle.L at gmail dot com >
 * @param string $string
 * @param integer $length 需要限制输出的宽度
 * @param string $etc
 * @return string
 */
function smarty_modifier_truncate($string, $length = 80, $etc = '…')
{
    if ($length == 0) {
        return '';
    }
    return mb_strimwidth($string, 0, $length, $etc);
    /*
    		$strlen = mb_strlen($string);
    
    	    if ($strlen > $length || mb_strwidth($string) > $length) {
    	        $length -= mb_strwidth($etc);
    			$str     = "";
    			$count   = 0;
    			for ($i = 0; $i < $strlen; $i ++) {
    				$curr = mb_substr($string, $i, 1);
    				$str .= $curr;
    				$count ++;
    				if (mb_strwidth($curr) == 2){
    					$count ++;
    				}
    				if ($count >= $length){
    					break;
    				}
    			}
    			return $str.$etc;
    
    	    } else {
    	        return $string;
    	    }
    */
}
示例#17
0
 public function setMessage($str)
 {
     if ($this->maxMessageLength) {
         $message = mb_strimwidth($this->___message, 0, $this->maxMessageLength, "...", "UTF-8");
     }
     $this->__message = $str;
 }
示例#18
0
function utf8_truncate($str, $size = 50)
{
    if (function_exists('mb_strimwidth')) {
        return mb_strimwidth($str, 0, $size, '', 'utf-8');
    }
    if ($size < 0) {
        return "";
    }
    $len = strlen($str);
    if ($len <= $size) {
        return $str;
    }
    # trying to truncate something that is already smaller
    $charlast = ord($str[$size]);
    while ($charlast > 0x7f) {
        if ($charlast < 0xbf) {
            break;
        }
        # starting another word
        $size++;
        if ($len <= $size) {
            return $str;
        }
        # UTF encoded is larger word-wise, but smaller character-wise
        $charlast = ord($str[$size]);
    }
    return substr($str, 0, $size);
}
示例#19
0
function wani_make_html_summary($sum, $max)
{
    $FLAG_STRIP_CONTROL = 1;
    $FLAG_STRIP_CRLF = 1;
    $FLAG_STRIP_STYLE = 1;
    $FLAG_STRIP_SPACE = 1;
    $FLAG_ADD_SPACE = 1;
    $FLAG_IMAGE_FORCE = 1;
    if ($FLAG_STRIP_CONTROL) {
        $sum = wani_strip_control_code($sum);
    }
    if ($FLAG_STRIP_CRLF) {
        $sum = wani_strip_crlf($sum);
    }
    if ($FLAG_STRIP_STYLE) {
        $sum = wani_strip_style_tag($sum);
    }
    if ($FLAG_ADD_SPACE) {
        $sum = wani_add_space($sum);
    }
    $sum = strip_tags($sum);
    if ($FLAG_STRIP_SPACE) {
        $sum = wani_strip_space($sum);
    }
    $sum = mb_strlen($sum) > $max ? mb_strimwidth($sum, 0, $max, " ...") : $sum;
    // sanitize
    $sum = wani_html_special_chars($sum);
    return $sum;
}
示例#20
0
function mirana_recent_comments($show_comments = 6)
{
    $my_email = get_bloginfo('admin_email');
    $i = 1;
    $comments = get_comments('number=50&status=approve&type=comment');
    foreach ($comments as $rc_comment) {
        if ($rc_comment->comment_author_email != $my_email) {
            ?>
				<li class="sidcomment">
					<a href="<?php 
            echo get_permalink($rc_comment->comment_post_ID);
            ?>
#comment-<?php 
            echo $rc_comment->comment_ID;
            ?>
" title="查看完整评论">
						<?php 
            echo get_avatar($rc_comment->comment_author_email, 28);
            ?>
						<?php 
            echo mb_strimwidth(strip_tags(apply_filters('the_content', convert_smilies($rc_comment->comment_content))), 0, 27, "...");
            ?>
					</a>
				</li>
				<?php 
            if ($i == $show_comments) {
                break;
            }
            $i++;
        }
    }
}
示例#21
0
function get_timespan_most_viewed($mode = '', $limit = 10, $days = 7, $display = true)
{
    global $wpdb, $post;
    $limit_date = current_time('timestamp') - $days * 26400;
    $limit_date = date("Y-m-d H:i:s", $limit_date);
    $where = '';
    $temp = '';
    if (!empty($mode) && $mode != 'both') {
        $where = "post_type = '{$mode}'";
    } else {
        $where = '1=1';
    }
    $most_viewed = $wpdb->get_results("SELECT {$wpdb->posts}.*, (meta_value+0) AS views FROM {$wpdb->posts} LEFT JOIN {$wpdb->postmeta} ON {$wpdb->postmeta}.post_id = {$wpdb->posts}.ID WHERE post_date < '" . current_time('mysql') . "' AND post_date > '" . $limit_date . "' AND {$where} AND post_status = 'publish' AND meta_key = 'views' AND post_password = '' ORDER  BY views DESC LIMIT {$limit}");
    if ($most_viewed) {
        $i = 1;
        foreach ($most_viewed as $post) {
            $post_title = mb_strimwidth(get_the_title(), 0, 35, '...');
            $post_views = intval($post->views);
            $post_views = number_format($post_views);
            $temp .= "<li><span class='li-icon li-icon-{$i}'>{$i}</span><a href=\"" . get_permalink() . "\">{$post_title}</a>" . __('', 'wp-postviews') . "</li>";
            $i++;
        }
    } else {
        $temp = '<li>' . __('N/A', 'wp-postviews') . '</li>' . "\n";
    }
    if ($display) {
        echo $temp;
    } else {
        return $temp;
    }
}
/**
 * Smarty truncate for cn modifier plugin
 *
 * Type:     modifier<br>
 * Name:     truncate<br>
 * Purpose:  Truncate a string to a certain length if necessary,
 *           optionally splitting in the middle of a word, and
 *           appending the $etc string or inserting $etc into the middle.
 * @link http://smarty.php.net/manual/en/language.modifier.truncate.php
 *          truncate (Smarty online manual)
 * @author   Monte Ohrt <monte at ohrt dot com>
 * @param string
 * @param integer
 * @param string
 * @param boolean
 * @param boolean
 * @return string
 */
function smarty_modifier_truncate_cn($string, $length = 80, $charset = 'UTF-8', $etc = '...')
{
    if (mb_strwidth($string, 'UTF-8') < $length) {
        return $string;
    }
    return mb_strimwidth($string, 0, $length, '', $charset) . $etc;
}
示例#23
0
/**
 * Compact a string to a maximum length
 *
 * @access public
 * @param string $str String to compact
 * @param integer $length Length to trim at
 * @return string Compact string; otherwise, original string
 */
function stringCompact($str, $length = 0)
{
    // mb_strwidth is better than using mb_strlen. See PHP docs for more details
    if ($length === 0 || mb_strwidth($str) <= $length) {
        return $str;
    }
    return mb_strimwidth($str, 0, $length, '...');
}
示例#24
0
 /**
  * Trims text to a certain number of characters.
  * This function can be useful for excerpt of the post
  * As opposed to wp_trim_words trims characters that makes text to
  * take the same amount of space in each post for example
  *
  * @since   1.2.0
  * @author  @CROSP
  * @param   string $text      Text to trim.
  * @param   int    $num_chars Number of characters. Default is 60.
  * @param   string|null $more      Optional. What to append if $text needs to be trimmed. Default '&hellip;'.
  * @return  string trimmed text.
  */
 public static function trim_characters($text, $num_chars = 60, $more = null)
 {
     if ($more === null) {
         $more = __('&hellip;');
     }
     $text = wp_strip_all_tags($text);
     $text = mb_strimwidth($text, 0, $num_chars, $more);
     return $text;
 }
示例#25
0
 /**
  * 按显示字符的宽度截取已经htmlspecialchars后的字符串
  * @param type $string
  * @param type $length
  * @param type $dot
  * @return type
  */
 public static function cnCutEncoded($string, $length, $dot = '...')
 {
     if (mb_strwidth($string) <= $length) {
         return $string;
     }
     $string = htmlspecialchars_decode($string, ENT_QUOTES);
     $string = mb_strimwidth($string, 0, $length, $dot);
     return htmlspecialchars($string, ENT_QUOTES);
 }
示例#26
0
 /**
  * get substr support chinese
  * return $str
  */
 static function getSubStr($str, $length, $postfix = '...', $encoding = 'UTF-8')
 {
     $realLen = mb_strwidth($str, $encoding);
     if (!is_numeric($length) or $length * 2 >= $realLen) {
         return htmlspecialchars($str, ENT_QUOTES, $encoding);
     }
     $str = mb_strimwidth($str, 0, $length * 2, $postfix, $encoding);
     return htmlspecialchars($str, ENT_QUOTES, $encoding);
 }
示例#27
0
 public function index()
 {
     //バースデー用
     $birthday = $this->Session->read('birthday');
     if ($birthday) {
         $birthday_voice_data = $this->Voice->find('first', array('conditions' => array('Voice.system_name' => $birthday)));
         $birthday_data = $this->Birthday->find('first', array('conditions' => array('Birthday.voice_id' => $birthday_voice_data['Voice']['id'], 'Birthday.publish' => 1), 'order' => array('Birthday.id' => 'desc')));
         $birthday_top_image_name = $birthday_data['Birthday']['top_image_name'];
         $this->set(compact('birthday_voice_data', 'birthday_top_image_name'));
     }
     //TOPランダムコメント用
     $sister_comment = $this->SisterComment->find('all', array('conditions' => array('SisterComment.publish' => 1), 'order' => 'rand()', 'limit' => 1));
     $this->set('sister_comment', $sister_comment);
     //お知らせ用
     /* 最終更新日の取得ここから */
     $last_update = '2014-11-28';
     //サイト公開日を初期値に設定
     $contents = array('Information', 'Banner');
     //公開日を設定できるコンテンツ
     foreach ($contents as $content) {
         $last_data = $this->{$content}->find('first', array('conditions' => array($content . '.date_from <=' => date('Y-m-d'), $content . '.publish' => 1), 'order' => array($content . '.date_from' => 'desc')));
         if ($last_data) {
             if ($last_update <= $last_data[$content]['date_from']) {
                 $last_update = $last_data[$content]['date_from'];
             }
         }
     }
     $articles = array('Game', 'Diary', 'Product');
     //作成日で管理する記事
     foreach ($articles as $article) {
         $last_data = $this->{$article}->find('first', array('conditions' => array($article . '.created <=' => date('Y-m-d', strtotime('+1 day')), $article . '.publish' => 1), 'order' => array($article . '.created' => 'desc')));
         if ($last_data) {
             if ($last_update <= $last_data[$article]['created']) {
                 $last_update = $last_data[$article]['created'];
             }
         }
     }
     $last_update = mb_strimwidth($last_update, 0, 10);
     $this->set('last_update', $last_update);
     /* 最終更新部の取得ここまで */
     $information_lists = $this->Information->find('all', array('conditions' => array(array('or' => array('Information.date_from <=' => date('Y-m-d'), 'Information.date_from' => null)), array('or' => array('Information.date_to >=' => date('Y-m-d'), 'Information.date_to' => null)), 'Information.publish' => 1), 'order' => array('Information.id' => 'desc')));
     $this->set('information_lists', $information_lists);
     //バナー用
     $banner_lists = $this->Banner->find('all', array('conditions' => array(array('or' => array('Banner.date_from <=' => date('Y-m-d'), 'Banner.date_from' => null)), array('or' => array('Banner.date_to >=' => date('Y-m-d'), 'Banner.date_to' => null)), 'Banner.publish' => 1), 'order' => array('Banner.sort' => 'desc')));
     //バースデーバナー用
     if ($birthday) {
         $birthday_banner_lists = $this->Banner->find('all', array('conditions' => array('Banner.birthday_id' => $birthday_data['Birthday']['id'])));
         if ($birthday_banner_lists) {
             $banner_lists = $birthday_banner_lists;
         }
     }
     $this->set('banner_lists', $banner_lists);
     //メーカーバナー用
     $maker_lists = $this->Maker->find('all', array('conditions' => array('Maker.publish' => 1), 'order' => array('Maker.title' => 'asc')));
     $this->set('maker_lists', $maker_lists);
 }
示例#28
0
function my_the_excerpt($postContent)
{
    if (is_front_page() || is_archive()) {
        $postContent = mb_strimwidth($postContent, 0, 200, "<a href='" . get_permalink($post->ID) . "'> ...続きを読む</a>", "UTF-8");
        return $postContent;
    } else {
        $postContent = mb_strimwidth($postContent, 0, 400);
        return $postContent;
    }
}
示例#29
0
 /**
  * 截取字符串,并自动闭合html标签
  * @param $string
  * @param $start
  * @param $width
  * @param string $trimmarker
  * @param string $encode
  * @return string
  */
 public static function strimwidthWithTag($string, $start, $width, $trimmarker = '...', $encode = 'utf-8')
 {
     if (function_exists('mb_strimwidth')) {
         $string = mb_strimwidth($string, $start, $width, $trimmarker, $encode);
     } else {
         $string = self::dm_strimwidth($string, $start, $width, $trimmarker, $encode);
     }
     $string = HTMLPurifier::process($string);
     return $string;
 }
function sanitisePostedData($field, $maxlength)
{
    if (isset($_POST[$field])) {
        $value = $_POST[$field];
        $value = mb_strimwidth($value, 0, $maxlength, '', "UTF-8");
        return htmlspecialchars($value);
    } else {
        return '';
    }
}