Example #1
0
 public function test_strings()
 {
     $sentence = 'пользователь должен быть у Вас в друзьях а Вы у него';
     $testcase = ['tHe QUIcK bRoWn' => 'QUI', 'frànçAIS' => 'çAI', 'über-åwesome' => '-åw'];
     foreach ((array) $testcase as $input => $output) {
         $this->assertEquals(_substr($input, 4, 3), $output);
     }
     $this->assertEquals(_truncate($sentence, 10), 'пользовате');
     $this->assertEquals(_truncate($sentence, 15, true), 'пользователь');
     $this->assertEquals(_truncate($sentence, 15, true, true), 'пользовател...');
 }
Example #2
0
/**
 * HTMLタグのパラメータを配列に変換する
 *
 * @param string	$param	「name1="value1" name2="value2" ...」形式の文字列
 * @return array	連想配列
 */
function tagparam2array($param)
{
    $ret = array();
    while ($param != '' && mb_ereg('^.*?([^\\t  ]+?)=(?:(\'|")(.*?)\\2|([^\\t  \'"][^\\t  ]*))', $param, $m)) {
        $ret[$m[1]] = $m[3] . $m[4];
        //$m[3]と$m[4]のどちらかは空文字列なので、これでヒットしたほうを取得できる
        $param = _substr($param, strlen($m[0]));
    }
    return $ret;
}
Example #3
0
 function getChunkedAnnotation()
 {
     if (!$this->loaded) {
         $this->load();
     }
     return array('short' => $short = close_dangling_tags(trim(_substr($this->data['description'], 400))), 'html' => $this->data['description']);
 }
Example #4
0
 function processBio($fullHtml)
 {
     $body = '';
     $short = '';
     $body = strip_tags($fullHtml, '<p><strong><i><em><b>');
     $body = str_replace('<strong>', '<b>', $body);
     $body = str_replace('</strong>', '</b>', $body);
     $body = str_replace('<i>', '<em>', $body);
     $body = str_replace('</i>', '</em>', $body);
     $short = close_dangling_tags(trim(_substr($body, 900)));
     return array($body, $short);
 }
Example #5
0
 public static function substr($str, $offset, $length = NULL)
 {
     if (UTF8::$server_utf8) {
         return $length === NULL ? mb_substr($str, $offset, mb_strlen($str), JsonApiApplication::$charset) : mb_substr($str, $offset, $length, JsonApiApplication::$charset);
     }
     if (!isset(UTF8::$called[__FUNCTION__])) {
         require JsonApiApplication::find_file("utf8", __FUNCTION__);
         // Function has been called
         UTF8::$called[__FUNCTION__] = TRUE;
     }
     return _substr($str, $offset, $length);
 }
Example #6
0
$__view__data__0__ = $data;
if (is_array($__view__data__0__)) {
    foreach ($__view__data__0__ as $list) {
        ?>
	<tr>
		<td align="left">&nbsp;<?php 
        echo $list[VariableName];
        ?>
</td>
		<td>&nbsp;<?php 
        echo $list[VariableDescribe];
        ?>
</td>
		<td align="left"><?php 
        if ($list[VariableType] == 0) {
            echo _substr($list[VariableValue], 80);
        } else {
            ?>
(数组数据不提供预览)<?php 
        }
        ?>
</td>
		<td align="left">&nbsp; <a
			href="<?php 
        echo UrlRewriteSimple('GlobalCfgs', 'Lists', true);
        ?>
&VariableName=<?php 
        echo $list[VariableName];
        ?>
">修改</a>
		&nbsp; | &nbsp;<a href="javascript:;"
Example #7
0
            echo '" class="thumbnail-wrapper">';
            the_post_thumbnail();
            echo '</a>';
        } else {
            echo '<a href="';
            the_permalink();
            echo '" class="thumbnail-wrapper">';
            echo '<img src="';
            echo catch_that_image();
            echo '" alt="" />';
            echo '</a>';
        }
        ?>
											</div>
											<?php 
        echo _substr(wp_trim_excerpt(), 300, get_permalink());
        ?>
											<div><a class="more-link" href="<?php 
        the_permalink();
        ?>
"> Nhấn vào để đọc thêm</a></div>
										<div class="clearFix"></div>
									</div>
									</div>
									<div class="subFooting">
									<div class="tags-and-categories">
										<?php 
        the_tags();
        ?>
			
									</div>
Example #8
0
 /**
  * Returns part of a UTF-8 string
  *
  * This is a UTF8-aware version of [substr](http://php.net/substr).
  *
  * Example:
  * ~~~
  * $sub = UTF8::substr($str, $offset);
  * ~~~
  *
  * @author  Chris Smith <*****@*****.**>
  *
  * @param   string   $str     Input string
  * @param   integer  $offset  Offset
  * @param   integer  $length  Length limit [Optional]
  *
  * @return  string
  *
  * @uses    UTF8::$server_utf8
  * @uses    Kohana::$charset
  * @uses    Kohana::find_file
  */
 public static function substr($str, $offset, $length = NULL)
 {
     if (self::$server_utf8) {
         return is_null($length) ? mb_substr($str, $offset, mb_strlen($str), Kohana::$charset) : mb_substr($str, $offset, $length, Kohana::$charset);
     }
     UTF8::_load(__FUNCTION__);
     return _substr($str, $offset, $length);
 }
Example #9
0
function viewcat($array_subcat, $array_cat, $items)
{
    global $module_info, $global_array_cat, $global_config, $module_name, $module_file, $lang_module, $numsubcat, $showcatimage, $numinsub;
    $xtpl = new XTemplate("viewcat.tpl", NV_ROOTDIR . "/themes/" . $module_info['template'] . "/modules/" . $module_file);
    $xtpl->assign('LANG', $lang_module);
    $width = round(100 / $numsubcat, 0);
    $xtpl->assign("W", $width);
    foreach ($array_cat as $array_cat_i) {
        $xtpl->assign('CAT', $array_cat_i);
        if (!empty($array_cat_i['description'])) {
            $xtpl->parse('main.cat.showdes');
        }
        $xtpl->parse('main.cat');
    }
    if (!empty($array_subcat)) {
        $a = 1;
        foreach ($array_subcat as $array_subcat_i) {
            $xtpl->assign('SUB', $array_subcat_i);
            if ($showcatimage == 1 and !empty($array_subcat_i['catimage'])) {
                if (file_exists(NV_UPLOADS_REAL_DIR . NV_UPLOADS_DIR . "/" . $array_subcat_i['catimage']) && $array_subcat_i['catimage'] != "") {
                    $xtpl->assign("IMG", "" . NV_BASE_SITEURL . "/" . $array_subcat_i['catimage'] . "");
                }
            } else {
                $xtpl->assign("IMG", "" . NV_BASE_SITEURL . "themes/" . $module_info['template'] . "/images/" . $module_file . "/no_image.gif");
            }
            $numinsub == 1 ? $xtpl->parse('main.sub.loop.count_link') : "";
            $xtpl->assign("FLOAT", $a % $numsubcat == false ? "fr" : "fl");
            $a % $numsubcat == false ? $xtpl->parse('main.sub.loop.clear') : "";
            $xtpl->parse('main.sub.loop');
            $a++;
        }
        $xtpl->parse('main.sub');
    }
    if (!empty($items)) {
        foreach ($items as $items_i) {
            $items_i['add_time'] = nv_date("H:i l - d/m/Y", $items_i['add_time']);
            $items_i['description'] = strip_tags($items_i['description']);
            $items_i['description'] = _substr($items_i['description'], 200);
            if (!empty($items_i['urlimg'])) {
                if (!nv_is_url($items_i['urlimg'])) {
                    $items_i['urlimg'] = NV_BASE_SITEURL . NV_UPLOADS_DIR . "/" . $items_i['urlimg'];
                }
                $xtpl->assign('IMG', $items_i['urlimg']);
            } else {
                $xtpl->assign('IMG', "" . NV_BASE_SITEURL . "themes/" . $module_info['template'] . "/images/" . $module_file . "/no_image.gif");
            }
            $items_i['url'] = nv_clean60($items_i['url'], 70) . "...";
            $xtpl->assign('ITEM', $items_i);
            if (defined('NV_IS_ADMIN')) {
                $xtpl->assign('ADMIN_LINK', adminlink($items_i['id']));
            }
            $xtpl->parse('main.items.loop');
        }
        $xtpl->parse('main.items');
    }
    $xtpl->parse('main');
    return $xtpl->text('main');
}
Example #10
0
function getTextBetweenTags($text, $tag)
{
    $StartTag = "<{$tag}";
    $EndTag = "</{$tag}";
    $StartPosTemp = _strpos($text, $StartTag);
    $StartPos = _strpos($text, '>', $StartPosTemp);
    $StartPos = $StartPos + 1;
    $EndPos = _strpos($text, $EndTag);
    $StartAttr = $StartPosTemp + _strlen($StartTag) + 1;
    $EndAttr = $StartPos;
    if ($EndAttr > $StartAttr) {
        $attribute = _substr($text, $StartAttr, $EndAttr - $StartAttr - 1);
        $datas = explode(' ', $attribute);
        for ($i = 0; $i < sizeof($datas); $i++) {
            if (preg_match('/^([a-zA-Z:]+)=["\'](.*)["\']/', $datas[$i], $match)) {
                $items[$match[1]] = $match[2];
            }
        }
    }
    $text = _substr($text, $StartPos, $EndPos - $StartPos);
    if (_strpos($text, '[CDATA[') == false) {
        $text = str_replace('&lt;', '<', $text);
        $text = str_replace('&gt;', '>', $text);
        $text = str_replace('&amp;', '&', $text);
        $text = str_replace('&quot;', '"', $text);
    } else {
        $text = str_replace('<![CDATA[', '', $text);
        $text = str_replace(']]>', '', $text);
    }
    $items['data'] = trim($text);
    return $items;
}
Example #11
0
 /**
  * Returns part of a UTF-8 string. This is a UTF8-aware version
  * of [substr](http://php.net/substr).
  *
  *     $sub = UTF8::substr($str, $offset);
  *
  * @author  Chris Smith <*****@*****.**>
  * @param   string  $str    input string
  * @param   integer $offset offset
  * @param   integer $length length limit
  * @return  string
  * @uses    UTF8::$server_utf8
  * @uses    Kohana::$charset
  */
 public static function substr($str, $offset, $length = NULL)
 {
     if (UTF8::$server_utf8) {
         return $length === NULL ? mb_substr($str, $offset, mb_strlen($str), Kohana::$charset) : mb_substr($str, $offset, $length, Kohana::$charset);
     }
     if (!isset(self::$called[__FUNCTION__])) {
         require Kohana::find_file('utf8', __FUNCTION__);
         // Function has been called
         self::$called[__FUNCTION__] = TRUE;
     }
     return _substr($str, $offset, $length);
 }
function get_the_content_with_formatting($more_link_text = 'Read more', $stripteaser = 0, $more_file = '')
{
    global $data;
    if ($data['wm_blog_words_count'] > 0) {
        $word_cnt = $data['wm_blog_words_count'];
    } else {
        $word_cnt = 600;
    }
    $content = get_the_content('', $stripteaser, $more_file);
    $content = strip_shortcodes($content);
    $content = str_replace(']]>', ']]&gt;', $content);
    $content = '<p>' . _substr(strip_tags($content), $word_cnt) . '</p>';
    $content .= '<a class="read_more" href="' . get_permalink() . '" title="' . get_the_title() . '">' . $more_link_text . '</a><!-- Read more link -->';
    return $content;
}
function get_the_content_with_formatting($chars = 560, $stripteaser = 0, $more_file = '')
{
    $content = get_the_content('', $stripteaser, $more_file);
    $content = strip_shortcodes($content);
    $content = str_replace(']]>', ']]&gt;', $content);
    $content = _substr(strip_tags(strip_shortcodes($content)), $chars);
    $content .= '<br/><br/><a href="' . get_the_permalink() . '">' . _e('Continue Reading', THEMEDOMAIN) . '</a><br/><br/>';
    return $content;
}
 * 		Latest Ban
 *
 */
$latest_ban = mysql_query("SELECT player_id, player_nick, ban_reason, ban_created, ban_length, ban_type FROM " . $config->db_prefix . "_bans ORDER BY ban_created DESC LIMIT 1") or die(mysql_error());
while ($lb = mysql_fetch_object($latest_ban)) {
    if ($lb->ban_length == 0) {
        $ban_length = 0;
    } else {
        $ban_length = $lb->ban_created + $lb->ban_length * 60;
    }
    if ($lb->ban_type == "SI") {
        $steamid = "SI";
    } else {
        $steamid = $lb->player_id;
    }
    $last_ban_arr = array("steamid" => $steamid, "nickname" => htmlspecialchars(_substr($lb->player_nick, 15)), "reason" => htmlspecialchars(_substr($lb->ban_reason, 15)), "created" => $lb->ban_created, "length" => $ban_length, "time" => time());
}
/*
 *
 * 		Template parsing
 *
 */
// Header
$title = "_TITLEVIEW";
// Section
$section = "live";
// Parsing
$smarty = new dynamicPage();
$smarty->assign("meta", "");
$smarty->assign("title", $title);
$smarty->assign("section", $section);
Example #15
0
 public static function start(array $controllers = [], $fn = '')
 {
     $requestUri = self::$_env['request_uri'];
     self::$_env['request_method'] = self::getServer('REQUEST_METHOD', 'GET');
     // 自定义的 控制器
     foreach ($controllers as $controller) {
         if (!_startWith($requestUri, '/' . $controller)) {
             continue;
         }
         if ($requestUri == '/' . $controller) {
             self::$_env['controller'] = $controller;
             self::$_env['action'] = 'index';
             //加载初始化文件
             $initFile = self::$_env['controllersDir'] . '/' . $controller . '/__init__.php';
             if (file_exists($initFile)) {
                 include_once $initFile;
             }
             //加载自定义
             self::__loadControllerAction(self::$_env['controller'], $fn);
         } else {
             if ($_actionUri = _substr($requestUri, $controller)) {
                 $_action_uri = explode('/', $_actionUri, 3);
                 if (sizeof($_action_uri) == 2 && !file_exists(self::$_env['controllersDir'] . '/' . $controller . '/' . $_action_uri[1] . '.php')) {
                     self::$_env['controller'] = $controller . '/index';
                     self::$_env['action'] = self::getArrayValue($_action_uri, 1, 'index');
                 } else {
                     self::$_env['controller'] = $controller . '/' . self::getArrayValue($_action_uri, 1, 'index');
                     self::$_env['action'] = self::getArrayValue($_action_uri, 2, 'index');
                 }
                 //加载初始化文件
                 $initFile = self::$_env['controllersDir'] . '/' . $controller . '/__init__.php';
                 if (file_exists($initFile)) {
                     include_once $initFile;
                 }
                 //加载自定义
                 self::__loadControllerAction(self::$_env['controller'], $fn);
             }
         }
     }
     //-- end
     $_requestUri = explode('/', $requestUri, 3);
     self::$_env['controller'] = self::getArrayValue($_requestUri, 1, 'index');
     self::$_env['action'] = self::getArrayValue($_requestUri, 2, 'index');
     self::__loadControllerAction(self::$_env['controller'], $fn);
 }
Example #16
0
 /**
  * Get related content
  *
  * @exmaple
  *	$data = common()->related_content(array(
  *		'action'		=> 'fetch', // Action: sql, fetch, stpl
  *		'source_array'	=> $post_info, // array to analyze title and text from
  *		'table_name'	=> db('blog_posts'), // database table name to query
  *		'fields_return'	=> 'id, user_id, add_date, title, text, privacy', // array or string of fields to return in resultset
  *		'field_id'		=> 'id',
  *		'field_date'	=> 'add_date',
  *		'field_title'	=> 'title',
  *		'field_text'	=> 'text',
  *		'where'			=> 'user_id='.intval($post_info['user_id']), // custom WHERE condition will be added to query
  *	));
  *
  */
 function _process($params = [])
 {
     // THESE ARE REQUIRED!
     $SOURCE_ARRAY = $params['source_array'];
     $TABLE_NAME = $params['table_name'];
     // Missing required params
     if (!$SOURCE_ARRAY) {
         trigger_error('RELATED: empty params[source_array]', E_USER_WARNING);
         return false;
     }
     $WHAT_TO_RETURN = $params['action'] && in_array($params['action'], ['sql', 'fetch', 'stpl']) ? $params['action'] : $this->DEF_PARAMS['WHAT_TO_RETURN'];
     $FIELD_ID = $params['field_id'] ? _es($params['field_id']) : $this->DEF_PARAMS['FIELD_ID'];
     $FIELD_DATE = $params['field_date'] ? _es($params['field_date']) : $this->DEF_PARAMS['FIELD_DATE'];
     $FIELD_USER = $params['field_user'] ? _es($params['field_user']) : $this->DEF_PARAMS['FIELD_USER'];
     $FIELD_TITLE = $params['field_title'] ? _es($params['field_title']) : $this->DEF_PARAMS['FIELD_TITLE'];
     $FIELD_TEXT = $params['field_text'] ? _es($params['field_text']) : $this->DEF_PARAMS['FIELD_TEXT'];
     $FIELD_SCORE = $params['field_score'] ? _es($params['field_score']) : $this->DEF_PARAMS['FIELD_SCORE'];
     // Additional fields for fulltext searching
     $FIELD_ADD_1 = $params['field_add_1'] ? _es($params['field_add_1']) : $this->DEF_PARAMS['FIELD_ADD_1'];
     $FIELD_ADD_2 = $params['field_add_2'] ? _es($params['field_add_2']) : $this->DEF_PARAMS['FIELD_ADD_2'];
     // Title or text is required
     if ((!$FIELD_TITLE || $FIELD_TITLE == -1) && (!$FIELD_TEXT || $FIELD_TEXT == -1)) {
         trigger_error('RELATED: no title and text fields specified', E_USER_WARNING);
         return false;
     }
     $FIELDS_RETURN = $params['fields_return'] ? $this->_prepare_fields_param($params['fields_return']) : '';
     if (!$FIELDS_RETURN) {
         $FIELDS_RETURN[] = $FIELD_ID;
         if ($FIELD_DATE && $FIELD_DATE != -1) {
             $FIELDS_RETURN[] = $FIELD_DATE;
         }
         if ($FIELD_USER && $FIELD_USER != -1) {
             $FIELDS_RETURN[] = $FIELD_USER;
         }
         if ($FIELD_TITLE && $FIELD_TITLE != -1) {
             $FIELDS_RETURN[] = $FIELD_TITLE;
         }
         if ($FIELD_TEXT && $FIELD_TEXT != -1) {
             $FIELDS_RETURN[] = $FIELD_TEXT;
         }
         if ($FIELD_ADD_1 && $FIELD_ADD_1 != -1) {
             $FIELDS_RETURN[] = $FIELD_ADD_1;
         }
         if ($FIELD_ADD_2 && $FIELD_ADD_2 != -1) {
             $FIELDS_RETURN[] = $FIELD_ADD_2;
         }
         $FIELDS_RETURN[] = $FIELD_SCORE;
     }
     $WHERE_COND = $params['where'] ? $params['where'] : '';
     // Not checked. Be careful with this!
     $PAST_ONLY = $params['past_only'] ? intval((bool) $params['past_only']) : $this->DEF_PARAMS['PAST_ONLY'];
     if (!$FIELD_DATE || $FIELD_DATE == -1) {
         $PAST_ONLY = false;
     }
     $RECORDS_LIMIT = $params['limit'] ? intval($params['limit']) : $this->DEF_PARAMS['RECORDS_LIMIT'];
     $ORDER_BY = $params['order_by'] ? _es($params['order_by']) : $FIELD_SCORE . ' DESC';
     $STPL_NAME = $params['stpl_name'] ? $params['stpl_name'] : $this->DEF_PARAMS['STPL_NAME'];
     $THRESHOLD = $params['thold'] ? intval($params['thold']) : $this->DEF_PARAMS['THRESHOLD'];
     $WEIGHT_TEXT = $params['weight_body'] ? intval($params['weight_body']) : $this->DEF_PARAMS['WEIGHT_TEXT'];
     $WEIGHT_TITLE = $params['weight_title'] ? intval($params['weight_title']) : $this->DEF_PARAMS['WEIGHT_TITLE'];
     // Additional fields
     $WEIGHT_ADD_1 = $params['weight_add_1'] ? intval($params['weight_add_1']) : $this->DEF_PARAMS['WEIGHT_ADD_1'];
     $WEIGHT_ADD_2 = $params['weight_add_2'] ? intval($params['weight_add_2']) : $this->DEF_PARAMS['WEIGHT_ADD_2'];
     // TODO: complete these
     $WEIGHT_TAG = $params['weight_tag'] ? intval($params['weight_tag']) : $this->DEF_PARAMS['WEIGHT_TAG'];
     $WEIGHT_CAT = $params['weight_cat'] ? intval($params['weight_cat']) : $this->DEF_PARAMS['WEIGHT_CAT'];
     // PARSE PARAMS END
     $WEIGHT_TOTAL = $WEIGHT_TEXT + $WEIGHT_TITLE + $WEIGHT_TAG + $WEIGHT_CAT;
     $WEIGHTED_THOLD = $THRESHOLD / ($WEIGHT_TOTAL + 0.1);
     $keywords_text = '';
     if ($FIELD_TEXT && $FIELD_TEXT != -1) {
         $keywords_text = $this->_get_keywords_from_text($SOURCE_ARRAY[$FIELD_TEXT]);
     }
     $keywords_title = '';
     if ($FIELD_TITLE && $FIELD_TITLE != -1) {
         $keywords_title = $this->_get_keywords_from_text($SOURCE_ARRAY[$FIELD_TITLE]);
     }
     $keywords_add_1 = '';
     if ($FIELD_ADD_1 && $FIELD_ADD_1 != -1) {
         $keywords_add_1 = $this->_get_keywords_from_text($SOURCE_ARRAY[$FIELD_ADD_1]);
     }
     $keywords_add_2 = '';
     if ($FIELD_ADD_2 && $FIELD_ADD_2 != -1) {
         $keywords_add_2 = $this->_get_keywords_from_text($SOURCE_ARRAY[$FIELD_ADD_2]);
     }
     // Keywords required
     if (!strlen($keywords_text) && !strlen($keywords_title) && !strlen($keywords_add_1) && !strlen($keywords_add_2)) {
         return false;
     }
     // Prepare fields to return as string for SQL
     $_tmp = [];
     foreach ((array) $FIELDS_RETURN as $k => $v) {
         $_tmp[$k] = db()->escape_key($v);
     }
     $fields_to_return_sql = implode(', ', $_tmp);
     unset($_tmp);
     $now = time();
     // TODO
     $cats = '';
     $tags = '';
     $sql = "SELECT *, ( \n\t\t\t\tscore_text\t* " . $WEIGHT_TEXT . " \n\t\t\t\t" . (strlen($keywords_title) ? " + score_title\t* " . $WEIGHT_TITLE : "") . "\n\t\t\t\t" . (strlen($keywords_add_1) ? " + score_add_1\t* " . $WEIGHT_ADD_1 : "") . "\n\t\t\t\t" . (strlen($keywords_add_2) ? " + score_add_2\t* " . $WEIGHT_ADD_2 : "") . "\n\t\t\t\t" . ($tags ? " + score_tag\t* " . $WEIGHT_TAG : "") . "\n\t\t\t\t" . ($cats ? " + score_cat\t* " . $WEIGHT_CAT : "") . "\n\t\t\t) AS " . $FIELD_SCORE . " \n\n\t\t\tFROM ( \n\t\t\t\tSELECT " . ($fields_to_return_sql ? $fields_to_return_sql : "1") . "\n\t\t\t\t\t, " . (strlen($keywords_text) ? "(MATCH (" . $FIELD_TEXT . ") AGAINST ('" . _es($keywords_text) . "' IN BOOLEAN MODE))" : "0") . " AS score_text \n\t\t\t\t\t" . (strlen($keywords_title) ? ", (MATCH (" . $FIELD_TITLE . ") AGAINST ('" . _es($keywords_title) . "' IN BOOLEAN MODE)) AS score_title " : "") . "\n\t\t\t\t\t" . (strlen($keywords_add_1) ? ", (MATCH (" . $FIELD_ADD_1 . ") AGAINST ('" . _es($keywords_add_1) . "' IN BOOLEAN MODE)) AS score_add_1 " : "") . "\n\t\t\t\t\t" . (strlen($keywords_add_2) ? ", (MATCH (" . $FIELD_ADD_2 . ") AGAINST ('" . _es($keywords_add_2) . "' IN BOOLEAN MODE)) AS score_add_2 " : "") . "\n\t\t\t\t\t" . ($tags ? ", IFNULL(0/*score_tag*/,0) AS score_tag " : "") . "\n\t\t\t\t\t" . ($cats ? ", IFNULL(0/*score_cat*/,0) as score_cat " : "") . "\n\t\t\t\tFROM " . $TABLE_NAME . " \n\t\t\t\tWHERE " . ($WHERE_COND ? $WHERE_COND : "1") . " \n\t\t\t\t\tAND " . $FIELD_ID . " != " . intval($SOURCE_ARRAY[$FIELD_ID]) . ($PAST_ONLY ? " AND " . $FIELD_DATE . " <= '" . $now . "' " : ' ') . ") AS rawscores \n\n\t\t\tWHERE ( \n\t\t\t\tscore_text\t* " . $WEIGHT_TEXT . "\n\t\t\t\t" . (strlen($keywords_title) ? " + score_title\t* " . $WEIGHT_TITLE : "") . "\n\t\t\t\t" . (strlen($keywords_add_1) ? " + score_add_1 * " . $WEIGHT_ADD_1 : "") . "\n\t\t\t\t" . (strlen($keywords_add_2) ? " + score_add_2 * " . $WEIGHT_ADD_2 : "") . "\n\t\t\t\t" . ($tags ? " + score_tag\t* " . $WEIGHT_TAG : "") . "\n\t\t\t\t" . ($cats ? " + score_cat\t* " . $WEIGHT_CAT : "") . "\n\t\t\t) >= " . $THRESHOLD . "\n\n\t\t\tORDER BY " . $ORDER_BY . " \n\n\t\t\tLIMIT " . $RECORDS_LIMIT;
     // Special for the db_installer (allows to easily restore if not exists FULLTEXT INDEX on used fields)
     $fulltext_needed_for = [];
     if (strlen($keywords_text)) {
         $fulltext_needed_for[] = $TABLE_NAME . "." . $FIELD_TEXT;
     }
     if (strlen($keywords_title)) {
         $fulltext_needed_for[] = $TABLE_NAME . "." . $FIELD_TITLE;
     }
     if (strlen($keywords_add_1)) {
         $fulltext_needed_for[] = $TABLE_NAME . "." . $FIELD_ADD_1;
     }
     if (strlen($keywords_add_2)) {
         $fulltext_needed_for[] = $TABLE_NAME . "." . $FIELD_ADD_2;
     }
     conf('fulltext_needed_for', $fulltext_needed_for);
     // Try to pretty format SQL with missing lines
     $sql = str_replace(["\r", "\n\t\t\t\t\t\n", "\n\t\t\t\t\n", "\n\t\t\t\n"], "\n", $sql);
     $sql = str_replace(["\n\n\n", "\n\n"], "\n", $sql);
     // RETURN RESULT HERE
     if ($WHAT_TO_RETURN == 'sql') {
         return $sql;
     }
     if ($WHAT_TO_RETURN == 'fetch') {
         return db()->query_fetch_all($sql, $FIELD_ID);
     }
     if ($WHAT_TO_RETURN == 'stpl') {
         $data = db()->query_fetch_all($sql, $FIELD_ID);
         if (!$data) {
             return '';
         }
         // Get users infos
         if ($FIELD_USER && $FIELD_USER != -1) {
             $users_ids = [];
             foreach ((array) $data as $k => $v) {
                 if ($v[$FIELD_USER]) {
                     $users_ids[$v[$FIELD_USER]] = $v[$FIELD_USER];
                 }
             }
             if (!empty($users_ids)) {
                 $users_infos = user($users_ids);
             }
         }
         foreach ((array) $data as $k => $v) {
             $data2[$k] = ['id' => intval($v[$FIELD_ID]), 'date' => _format_date($v[$FIELD_DATE]), 'title' => _prepare_html($v[$FIELD_TITLE]), 'text' => _prepare_html(_substr($v[$FIELD_TEXT], 0, 200)), 'add_1' => _prepare_html(_substr($v[$FIELD_ADD_1], 0, 200)), 'add_2' => _prepare_html(_substr($v[$FIELD_ADD_2], 0, 200)), 'user_id' => intval($v[$FIELD_USER]), 'user_name' => _prepare_html(_display_name($users_infos[$v[$FIELD_USER]])), 'profile_link' => _profile_link($v[$FIELD_USER]), 'score' => _prepare_html($v[$FIELD_SCORE]), 'href' => process_url('./?object=' . $_GET['object'] . '&action=' . $_GET['action'] . '&id=' . intval($v[$FIELD_ID]))];
         }
         $replace = ['data' => $data2, 'source' => _prepare_html($SOURCE_ARRAY)];
         return tpl()->parse($STPL_NAME, $replace);
     }
 }
Example #17
0
/**
 * Like system function, but accept arrays of strings
 *
 * @param string|string[]	$string
 * @param int				$start
 * @param int				$length
 *
 * @return string|string[]
 */
function _substr($string, $start, $length = null)
{
    if (is_array($string)) {
        foreach ($string as &$s) {
            $s = _substr($s, $start, $length);
        }
        return $string;
    }
    if ($length) {
        return substr($string, $start, $length);
    } else {
        return substr($string, $start);
    }
}
Example #18
0
 /**
  * Translation of the given string
  *
  * Some common symbol codes in HTML:
  *	_ => '&#95;'
  *	' => '&prime;' or '&#39;'
  *	' => '&quot;'
  *	/ => '&frasl;'
  *	\ => '&#92;'
  *	[ => '&#91;'
  *	] => '&#93;'
  *	( => '&#40;'
  *	) => '&#41;'
  *	{ => '&#123;'
  *	} => '&#125;'
  *	? => '&#63;'
  *	! => '&#33;'
  *	| => '&#124;'
  *
  * @code
  *	$msg = t('You must log in below or <a href="%url">create a new account</a> before viewing the next page.',
  *			array('%url' => process_url('./?object=user&action=register')));
  * @endcode
  *
  * We have ability to use custom prefix for vars with same names in different places with different translations
  * ex. for var "welcome" we can have several vars with prefixes  "::forum::welcome"
  * Prefix syntax:	 "::[a-z_-]::text to tranlate here"
  *
  * @access	public
  * @param	$string string	Text to translate
  * @param	$args	array	Optional array of items to replace after translation
  * @return string Translation result
  */
 function translate_string($input_string, $args = 0, $lang = '')
 {
     if (DEBUG_MODE) {
         $_start_time = microtime(true);
     }
     $lang = strval($lang);
     if (!$lang) {
         $lang = $this->_get_current_lang();
     }
     if (!isset($this->_loaded[$lang])) {
         $this->_load_lang($lang);
     }
     if (!$lang || !$this->_loaded[$lang]) {
         return $input_string;
     }
     if (is_array($args) && isset($args[''])) {
         unset($args['']);
     }
     if (is_array($input_string)) {
         foreach ((array) $input_string as $k => $v) {
             $input_string[$k] = $this->translate_string($v, $args, $lang);
         }
         return $input_string;
     }
     if (!$input_string) {
         return $input_string;
     }
     $input_string = trim($input_string);
     DEBUG_MODE && $this->_calls[$input_string]++;
     if ($this->USE_TRANSLATE_CACHE && empty($args)) {
         $CACHE_NAME = $lang . '#____#' . $input_string;
         if (isset($this->_LOCALE_CACHE[$CACHE_NAME])) {
             return $this->_LOCALE_CACHE[$CACHE_NAME];
         }
     }
     $is_translated = false;
     $_source = $input_string;
     $output_string = $input_string;
     // Try to find prefix (starts with '::')
     $_prefix = '';
     $_prefix_length = 0;
     if ($input_string[0] == ':' && $input_string[1] == ':') {
         $_prefix = substr($input_string, 0, strpos($input_string, '::', 2) + 2);
         $_prefix_length = strlen($_prefix);
         $input_string = substr($input_string, $_prefix_length);
     }
     if ($this->TRANSLATE_ENABLED) {
         // Prepare for case ignore
         if ($this->VARS_IGNORE_CASE) {
             $first_input_string = $input_string;
             $input_string = strtolower($input_string);
             if ($this->REPLACE_UNDERSCORE) {
                 $input_string = str_replace('&nbsp;', ' ', $input_string);
                 $input_string = str_replace(' ', '_', $input_string);
             }
         }
         // Try to find prefix (starts with '::') again
         if (!strlen($_prefix) && isset($this->TR_VARS[$lang]['::' . $_GET['object'] . '::' . $input_string])) {
             $_prefix = '::' . $_GET['object'] . '::';
         }
         // First try to translate var with prefix
         if (strlen($_prefix) && isset($this->TR_VARS[$lang][$_prefix . $input_string])) {
             $output_string = $this->TR_VARS[$lang][$_prefix . $input_string];
             $is_translated = true;
             // Then common var
         } elseif (isset($this->TR_VARS[$lang][$input_string])) {
             $output_string = $this->TR_VARS[$lang][$input_string];
             $is_translated = true;
             // Then try _un_html_entities
         } elseif (($var_un_html = $this->_un_html_entities($input_string)) && isset($this->TR_VARS[$lang][$var_un_html])) {
             $output_string = $this->TR_VARS[$lang][$var_un_html];
             $is_translated = true;
             // Last - is untranslated
         } else {
             $output_string = $input_string;
             if (DEBUG_MODE) {
                 if (!isset($this->_NOT_TRANSLATED)) {
                     $this->_NOT_TRANSLATED = [];
                 }
                 if (!isset($this->_NOT_TRANSLATED[$lang])) {
                     $this->_NOT_TRANSLATED[$lang] = [];
                 }
                 if (!isset($this->_NOT_TRANSLATED[$lang][$input_string])) {
                     $this->_NOT_TRANSLATED[$lang][$input_string] = 0;
                 }
                 $this->_NOT_TRANSLATED[$lang][$input_string]++;
                 // Check if such variable exists
                 if ($this->AUTO_FIND_VARS && !isset($this->TR_ALL_VARS[$input_string])) {
                     $this->insert_var($input_string);
                 }
             }
         }
     }
     if ($this->REPLACE_UNDERSCORE && !$is_translated) {
         $output_string = str_replace('_', ' ', $_source);
         if ($_prefix_length) {
             $output_string = substr($output_string, $_prefix_length);
         }
     }
     if (!empty($args) && is_array($args)) {
         $output_string = $this->_process_sub_patterns($output_string, $args);
         $output_string = strtr($output_string, $args);
     }
     if ($this->TRACK_FIRST_LETTER_CASE && $is_translated) {
         $input = $this->VARS_IGNORE_CASE ? $first_input_string : $input_string;
         $first_s = substr($input, 0, 1);
         $first_t = _substr($output_string, 0, 1);
         $first_s_lower = strtolower($first_s) == $first_s;
         $first_t_lower = _strtolower($first_t) == $first_t;
         if (!$first_s_lower && $first_t_lower) {
             $output_string = _strtoupper($first_t) . _substr($output_string, 1);
         }
     }
     if (DEBUG_MODE) {
         if ($this->WRAP_VARS_FOR_INLINE_EDIT && false === strpos($output_string, 'class=localetr')) {
             $r = [' ' => '%20', '=' => '&equals;', '<' => '&lt;', '>' => '&gt;'];
             $svar = _prepare_html(str_replace(array_keys($r), array_values($r), $_source));
             $output_string = '<span class=localetr svar=' . $svar . '>' . $output_string . '</span>';
         }
         debug('i18n[]', ['name_orig' => $_source, 'name' => $input_string, 'out' => $output_string, 'lang' => $lang, 'args' => $args ?: '', 'translated' => (int) $is_translated, 'time' => round(microtime(true) - $_start_time, 5), 'trace' => main()->trace_string()]);
     }
     // Put to cache
     if ($this->USE_TRANSLATE_CACHE && empty($args)) {
         $this->_LOCALE_CACHE[$CACHE_NAME] = $output_string;
     }
     return $output_string;
 }
Example #19
0
 private function setShortBody($body)
 {
     $this->data['short'] = close_dangling_tags(trim(_substr($body, 900)));
 }
Example #20
0
 public static function parse(&$str, $context)
 {
     $exp = FuzzyLink::getinstance()->getexpression();
     if ($exp != '' && mb_ereg("^{$exp}", $str, $m)) {
         $str = _substr($str, strlen($m[0]));
         return new T_FuzzyLink($m[0], $context);
     }
     return null;
 }
Example #21
0
 /**
  * Get information about the password hash. Returns an array of the information
  * that was used to generate the password hash.
  *
  * array(
  *    'algo' => 1,
  *    'algoName' => 'bcrypt',
  *    'options' => array(
  *        'cost' => PASSWORD_BCRYPT_DEFAULT_COST,
  *    ),
  * )
  *
  * @param string $hash The password hash to extract info from
  *
  * @return array The array of information about the hash.
  */
 function password_get_info($hash)
 {
     $return = array('algo' => 0, 'algoName' => 'unknown', 'options' => array());
     if (_substr($hash, 0, 4) == '$2y$' && _strlen($hash) == 60) {
         $return['algo'] = 1;
         $return['algoName'] = 'bcrypt';
         list($cost) = sscanf($hash, "\$2y\$%d\$");
         $return['options']['cost'] = $cost;
     }
     return $return;
 }
Example #22
0
File: utf8.php Project: ukd1/kohana
 /**
  * Returns part of a UTF-8 string.
  *
  * @see     http://php.net/substr
  * @author  Chris Smith <*****@*****.**>
  *
  * @param   string   input string
  * @param   integer  offset
  * @param   integer  length limit
  * @return  string
  */
 public static function substr($str, $offset, $length = NULL)
 {
     if (utf8::$server_utf8) {
         return $length === NULL ? mb_substr($str, $offset) : mb_substr($str, $offset, $length);
     }
     if (!isset(self::$called[__FUNCTION__])) {
         require SYSPATH . 'utf8/' . __FUNCTION__ . EXT;
         // Function has been called
         self::$called[__FUNCTION__] = TRUE;
     }
     return _substr($str, $offset, $length);
 }
Example #23
0
 /**
  * Returns part of a UTF-8 string.
  * @see http://php.net/substr
  *
  * @author  Chris Smith <*****@*****.**>
  *
  * @param   string   input string
  * @param   integer  offset
  * @param   integer  length limit
  * @return  string
  */
 public static function substr($str, $offset, $length = NULL)
 {
     require_once dirname(__FILE__) . '/' . __FUNCTION__ . '.php';
     return _substr($str, $offset, $length);
 }
Example #24
0
function get_the_content_with_formatting($more_link_text = '(more...)', $stripteaser = 0, $more_file = '')
{
    $pp_blog_read_more_title = get_option('pp_blog_read_more_title');
    if (empty($pp_blog_read_more_title)) {
        $pp_blog_read_more_title = 'Read More';
    }
    $content = get_the_content('', $stripteaser, $more_file);
    $content = strip_shortcodes($content);
    $content = str_replace(']]>', ']]&gt;', $content);
    $content = _substr(strip_tags(strip_shortcodes($content)), 600);
    $content .= '<br/><br/><br/><a class="button" href="' . get_permalink() . '">' . $pp_blog_read_more_title . '</a>';
    return $content;
}
Example #25
0
 /**
  * Returns part of a UTF-8 string. This is a UTF8-aware version
  * of [substr](http://php.net/substr).
  *
  *     $sub = UTF8::substr($str, $offset);
  *
  * @author  Chris Smith <*****@*****.**>
  * @param   string   input string
  * @param   integer  offset
  * @param   integer  length limit
  * @return  string
  * @uses    UTF8::$server_utf8
  * @uses    Kohana::$charset
  */
 public static function substr($str, $offset, $length = NULL)
 {
     if (UTF8::$server_utf8) {
         return $length === NULL ? mb_substr($str, $offset, mb_strlen($str), Kohana::$charset) : mb_substr($str, $offset, $length, Kohana::$charset);
     }
     if (!isset(self::$called[__FUNCTION__])) {
         require SYSPATH . 'utf8' . DIRECTORY_SEPARATOR . __FUNCTION__ . EXT;
         // Function has been called
         self::$called[__FUNCTION__] = TRUE;
     }
     return _substr($str, $offset, $length);
 }
Example #26
0
 /**
  * Returns part of a UTF-8 string. This is a UTF8-aware version
  * of [substr](http://php.net/substr).
  *
  *     $sub = UTF8::substr($str, $offset);
  *
  * @author  Chris Smith <*****@*****.**>
  * @param   string  $str    input string
  * @param   integer $offset offset
  * @param   integer $length length limit
  * @return  string
  * @uses    UTF8::$server_utf8
  * @uses    Phalcana\Phalcana::$charset
  */
 public static function substr($str, $offset, $length = null)
 {
     if (UTF8::$server_utf8) {
         return $length === null ? mb_substr($str, $offset, mb_strlen($str), Phalcana::$charset) : mb_substr($str, $offset, $length, Phalcana::$charset);
     }
     if (!isset(UTF8::$called[__FUNCTION__])) {
         require Phalcana::$di->get('fs')->findFile('utf8', __FUNCTION__);
         // Function has been called
         UTF8::$called[__FUNCTION__] = true;
     }
     return _substr($str, $offset, $length);
 }
function get_the_content_with_formatting($more_link_text = '(more...)', $stripteaser = 0, $more_file = '')
{
    $pp_blog_read_more_title = get_option('pp_blog_read_more_title');
    if (empty($pp_blog_read_more_title)) {
        $pp_blog_read_more_title = 'Read More';
    }
    $content = get_the_content('', $stripteaser, $more_file);
    $content = strip_shortcodes($content);
    $content = str_replace(']]>', ']]&gt;', $content);
    $content = '<div class="post_excerpt">' . _substr(strip_tags(strip_shortcodes($content)), 320) . '</div>';
    return $content;
}
Example #28
0
                        } else {
                            // not our post
                            continue;
                        }
                    }
                }
            }
            $pubtime = $data['update_time'];
            $y = date('Y', $pubtime);
            $m = date('m', $pubtime);
            $tblname = 'posts_data__' . $y . '_' . $m;
            if ($found) {
                $fulltext = preg_replace('/\\<script(.*)\\/script\\>/isU', '', $fulltext);
                $fulltext = preg_replace('/\\<form(.*)\\/form>/isU', '', $fulltext);
                $fulltext = preg_replace('/\\<iframe(.*)\\/iframe>/isU', '', $fulltext);
                $short = close_dangling_tags(_substr(prepare_review($fulltext, ''), 211));
                $query = 'INSERT INTO `' . $tblname . '` SET
				`id`=' . $data['id'] . ',
				`id_author`=' . $data['id_author'] . ',
				`text`=' . Database::escape($fulltext) . ',
				`short`=' . Database::escape($short) . ',
				`has_content`=1
				ON DUPLICATE KEY UPDATE
				`has_content`=1,
				`short`=' . Database::escape($short) . ',
				`text`=' . Database::escape($fulltext);
                Database::query($query);
                Database::query('UPDATE `posts` SET `short`=' . Database::escape($short) . ', `has_content`=1 WHERE `id`=' . $data['id'] . ' AND `id_author`=' . $data['id_author'] . '');
            } else {
                Database::query('UPDATE `posts` SET `has_content`=2 WHERE `id`=' . $data['id'] . ' AND `id_author`=' . $data['id_author'] . '');
            }
Example #29
0
 /**
  * Returns part of a UTF-8 string.
  * @see http://php.net/substr
  *
  * @author  Chris Smith <*****@*****.**>
  *
  * @param   string   input string
  * @param   integer  offset
  * @param   integer  length limit
  * @return  string
  */
 public static function substr($str, $offset, $length = NULL)
 {
     if (!isset(self::$called[__FUNCTION__])) {
         require SYSPATH . 'core/utf8/' . __FUNCTION__ . EXT;
         // Function has been called
         self::$called[__FUNCTION__] = TRUE;
     }
     return _substr($str, $offset, $length);
 }
Example #30
0
/**
 * viewcat()
 * 
 * @param mixed $array_subcat
 * @param mixed $array_cat
 * @param mixed $items
 * @return
 */
function viewcat($array_subcat, $array_cat, $items)
{
    global $module_info, $module_file, $lang_module, $weblinks_config;
    $xtpl = new XTemplate("viewcat.tpl", NV_ROOTDIR . "/themes/" . $module_info['template'] . "/modules/" . $module_file);
    $xtpl->assign('LANG', $lang_module);
    foreach ($array_cat as $array_cat_i) {
        $xtpl->assign('CAT', $array_cat_i);
        if (!empty($array_cat_i['description'])) {
            $xtpl->parse('main.cat.showdes');
        }
        $xtpl->parse('main.cat');
    }
    if (!empty($array_subcat)) {
        $a = 1;
        foreach ($array_subcat as $array_subcat_i) {
            $xtpl->assign('SUB', $array_subcat_i);
            if ($weblinks_config['showcatimage'] == 1 and !empty($array_subcat_i['catimage'])) {
                if (file_exists(NV_UPLOADS_REAL_DIR . NV_UPLOADS_DIR . "/" . $array_subcat_i['catimage']) && $array_subcat_i['catimage'] != "") {
                    $xtpl->assign("IMG", "" . NV_BASE_SITEURL . $array_subcat_i['catimage'] . "");
                }
            } else {
                $xtpl->assign("IMG", "" . NV_BASE_SITEURL . "themes/" . $module_info['template'] . "/images/" . $module_file . "/no_image.gif");
            }
            $xtpl->parse('main.sub.loop');
            ++$a;
        }
        $xtpl->parse('main.sub');
    }
    if (!empty($items)) {
        foreach ($items as $items_i) {
            $items_i['add_time'] = nv_date("H:i l - d/m/Y", $items_i['add_time']);
            $items_i['description'] = strip_tags($items_i['description']);
            $items_i['description'] = _substr($items_i['description'], 200);
            if (!empty($items_i['urlimg'])) {
                if (!nv_is_url($items_i['urlimg'])) {
                    $items_i['urlimg'] = $items_i['urlimg'];
                }
                $xtpl->assign('IMG', $items_i['urlimg']);
            } else {
                $xtpl->assign('IMG', "" . NV_BASE_SITEURL . "themes/" . $module_info['template'] . "/images/" . $module_file . "/no_image.gif");
            }
            $items_i['url'] = nv_clean60($items_i['url'], 70) . "...";
            $xtpl->assign('ITEM', $items_i);
            if (defined('NV_IS_ADMIN')) {
                $xtpl->assign('ADMIN_LINK', adminlink($items_i['id']));
            }
            if ($weblinks_config['showlinkimage'] == '1') {
                $xtpl->parse('main.items.loop.img');
            }
            $xtpl->parse('main.items.loop');
        }
        $xtpl->parse('main.items');
    }
    $xtpl->parse('main');
    return $xtpl->text('main');
}