Exemplo n.º 1
0
function csv_item_edit($str) {

	$str = mb_ereg_replace('"','""', $str);

	//★★★★★★★★★★★★★★★★
	return "\"".$str."\"";
	//★★★★★★★★★★★★★★★★

	$pos = strpos($str, ",");
	if ($pos !== false) {
		return "\"".$str."\"";
	}

	$pos = strpos($str, "\r");
	if ($pos !== false) {
		return "\"".$str."\"";
	}

	$pos = strpos($str, "\n");
	if ($pos !== false) {
		return "\"".$str."\"";
	}

	$pos = strpos($str, "\"");
	if ($pos !== false) {
		return "\"".$str."\"";
	}

	return $str;

}
Exemplo n.º 2
0
function fgetcsvWrapper($fp)
{
    global $gzipEnabled;
    if ($gzipEnabled) {
        // FIXME エスケープが必要なデータが来ると壊れるよーー
        $r = gzgets($fp, 4000);
        //        $r = "";
        //        $r = "";
        //        do {
        //            $r .= gzgets($fp, 4000);
        //        } while(mb_substr_count($r,'"') % 2 == 1);
        if ($r !== FALSE) {
            // 行末の\r\nは消してから分割
            $r = mb_ereg_replace("\r?\n\$", "", $r);
            return explode("\t", $r);
        } else {
            return FALSE;
        }
    } else {
        //         return fgetcsv($fp, 4000, "\t", '"');
        $r = fgets($fp, 4000);
        if ($r !== FALSE) {
            // 行末の\r\nは消してから分割
            $r = mb_ereg_replace("\r?\n\$", "", $r);
            return explode("\t", $r);
        } else {
            return FALSE;
        }
    }
}
Exemplo n.º 3
0
 /**
  * あいまい検索用正規表現の集合体を取得する。
  *
  * @param string    もとになるキーワード
  * @return    array(string)    あいまい検索用正規表現を集めた配列
  */
 static function makefuzzyexplist($key)
 {
     //仮名は全角カタカナに、英数字・空白文字は半角に、 濁点付きの文字を一文字に、記号は全角に。
     $_key = mb_strtolower(mb_convert_kana($key, 'KVCas'));
     foreach (self::$han2zen_mark_table as $han => $zen) {
         $_key = mb_ereg_replace(mb_ereg_quote($han), $zen, $_key);
     }
     //2文字以上での表現を1文字にする
     foreach (self::$two2one as $from => $to) {
         $_key = mb_ereg_replace($from, $to, $_key);
     }
     //文字により削除(表記ゆれまたはごみ)
     $_key = mb_ereg_replace('[ッー・゛゜、。]', '', $_key);
     //異体文字に対応する。
     $char = array();
     $len = mb_strlen($_key);
     for ($i = 0; $i < $len; $i++) {
         $c = mb_substr($_key, $i, 1);
         $char[] = isset($GLOBALS['itaimojitable'][$c]) ? $GLOBALS['itaimojitable'][$c] : mb_ereg_quote($c);
     }
     //ちょっと違う単語を許すようにする
     $list = self::makeagrepexplist($char);
     //表記ゆれになる文字を挟み込む
     $ret = array();
     foreach ($list as $a) {
         $ret[] = join('[・ーー]?', $a);
     }
     return $ret;
 }
Exemplo n.º 4
0
 /**
  * Formats a string to be used as an email (specifically strips whitespace
  * from the beginning/end of the Email, as well as immediately before/after
  * the @ in the Email).
  * @deprecated StringFunctions class
  */
 public function stremail($email)
 {
     $newemail = mb_ereg_replace("^[ \t]+|[ \t]+\$", "", $email);
     $newemail = mb_ereg_replace("[ \t]+@", "@", $newemail);
     $newemail = mb_ereg_replace("@[ \t]+", "@", $newemail);
     return $newemail;
 }
Exemplo n.º 5
0
 public static function GetSpellSuggestions($strText)
 {
     $strCleanText = mb_ereg_replace('[…\\n\\.,:;\\\\!\\?0-9]+', ' ', $strText);
     $strCleanText = str_replace(array('\\n', '\\r'), array(' ', ' '), $strText);
     $strCleanText = mb_ereg_replace('http://[a-z\\-A-Z\\.]+', ' ', $strCleanText);
     $strCleanText = strip_tags($strCleanText);
     /**
      * mozilla entitites: &xxx;
      */
     $strCleanText = mb_ereg_replace('&[\\.\\-a-zA-Z\\-0-9]+\\;', ' ', $strCleanText);
     /**
      * keyboard shortcuts
      */
     $strCleanText = mb_ereg_replace('[~&]', '', $strCleanText);
     /**
      * openoffice entities: %xxx %%xxx %%%xxx #xxx and so on
      */
     $strCleanText = mb_ereg_replace('[\\$\\[\\#\\%]{1,3}[a-zA-Z\\_\\-0-9]+[\\$\\]\\#\\%]{0,3}', ' ', $strCleanText);
     /**
      * some characters that mess with the spellchecking
      */
     $strCleanText = mb_ereg_replace('[\\(\\)]+', ' ', $strCleanText);
     $strCleanText = mb_ereg_replace('[„”]', ' ', $strCleanText);
     $strCleanText = mb_ereg_replace('[…\\n\\.,:;\\\\!\\?0-9]+', ' ', $strCleanText);
     return self::GetSpellSuggestionsWithPspell($strCleanText, QApplication::$TargetLanguage->LanguageCode);
 }
Exemplo n.º 6
0
function viewqueries()
{
    global $tplname, $usr;
    global $viewquery_line, $noqueries, $bgcolor1, $bgcolor2;
    $tplname = 'viewqueries';
    $dbc = new dataBase();
    $i = 0;
    $content = '';
    //$rs = sql("SELECT `id`, `name` FROM `queries` WHERE `user_id`='&1' ORDER BY `name` ASC", $usr['userid']);
    $query = "SELECT id, name FROM `queries` WHERE `user_id`=:1 ORDER BY `name` ASC";
    $dbc->multiVariableQuery($query, $usr['userid']);
    if ($dbc->rowCount() != 0) {
        //while ($r = sql_fetch_array($rs))
        while ($r = $dbc->dbResultFetch()) {
            $thisline = $viewquery_line;
            $thisline = mb_ereg_replace('{queryname}', htmlspecialchars($r['name'], ENT_COMPAT, 'UTF-8'), $thisline);
            $thisline = mb_ereg_replace('{queryid}', htmlspecialchars($r['id'], ENT_COMPAT, 'UTF-8'), $thisline);
            if ($i % 2 == 1) {
                $thisline = mb_ereg_replace('{bgcolor}', $bgcolor2, $thisline);
            } else {
                $thisline = mb_ereg_replace('{bgcolor}', $bgcolor1, $thisline);
            }
            $content .= $thisline;
            $i++;
        }
        //mysql_free_result($rs);
    } else {
        $content = $noqueries;
    }
    unset($dbc);
    tpl_set_var('queries', $content);
    tpl_BuildTemplate();
    exit;
}
Exemplo n.º 7
0
function translit($input_string)
{
    $trans = array();
    $ch1 = "/\r\n-абвгдеёзийклмнопрстуфхцыэАБВГДЕЁЗИЙКЛМНОПРСТУФХЦЫЭABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $ch2 = "    abvgdeeziyklmnoprstufhcyeabvgdeeziyklmnoprstufhcyeabcdefghijklmnopqrstuvwxyz";
    for ($i = 0; $i < mb_strlen($ch1); $i++) {
        $trans[mb_substr($ch1, $i, 1)] = mb_substr($ch2, $i, 1);
    }
    $trans["Ж"] = "zh";
    $trans["ж"] = "zh";
    $trans["Ч"] = "ch";
    $trans["ч"] = "ch";
    $trans["Ш"] = "sh";
    $trans["ш"] = "sh";
    $trans["Щ"] = "sch";
    $trans["щ"] = "sch";
    $trans["Ъ"] = "";
    $trans["ъ"] = "";
    $trans["Ь"] = "";
    $trans["ь"] = "";
    $trans["Ю"] = "yu";
    $trans["ю"] = "yu";
    $trans["Я"] = "ya";
    $trans["я"] = "ya";
    $trans["\\\\"] = " ";
    $trans["[^\\. a-z0-9]"] = " ";
    $trans["^[ ]+|[ ]+\$"] = "";
    $trans["[ ]+"] = "_";
    foreach ($trans as $from => $to) {
        $input_string = mb_ereg_replace(str_replace("\\", "\\", $from), $to, $input_string);
    }
    return $input_string;
}
Exemplo n.º 8
0
 function do_url()
 {
     if (!keys_exists(Vars::$post, 'num', 'type', 'pagename')) {
         throw new PluginException('パラメータが足りません。', $this);
     }
     if (trim(Vars::$post['text']) == '') {
         redirect(Page::getinstance(Vars::$post['pagename']));
     }
     $page = Page::getinstance(Vars::$post['pagename']);
     $source = explode("\n", Page::getinstance(Vars::$post['pagename'])->getsource());
     $count = 0;
     for ($i = 0; $i < count($source); $i++) {
         if (mb_ereg('^#comment(?:\\s|\\(|{|$)', $source[$i])) {
             if ($count == Vars::$post['num']) {
                 $name = trim(Vars::$post['name']);
                 $text = mb_ereg_replace('{', '&173;', Vars::$post['text']);
                 $text = mb_ereg_replace('}', '&175;', $text);
                 $time = date('Y-m-d H:i:s', time());
                 $str = ":[[{$name}>UserPage/{$name}]] &size(80%) {{$time}}:";
                 $str .= mb_ereg("\n", $str) ? "\n#block{{$text}}" : " {$text}";
                 $n = $i + (Vars::$post['type'] == 'below' ? 1 : 0);
                 array_splice($source, $n, 0, $str);
                 $page->write(join("\n", $source));
                 setcookie('name', $name, time() + 60 * 60 * 24 * 30);
                 redirect($page);
             }
             $count++;
         }
     }
     $ret['title'] = 'error';
     $smarty = $this->getSmarty();
     $smarty->assign('text', Vars::$post['text']);
     $ret['body'] = $smarty->fetch('error.tpl.htm');
     return $ret;
 }
Exemplo n.º 9
0
 public function setBusyHours($value)
 {
     $schedule = mb_strtolower($value);
     try {
         if (mb_strpos($schedule, '(')) {
             $schedule = trim(mb_ereg_replace('\\(.*\\)', '', $schedule));
         }
         mb_ereg_search_init($schedule);
         if (mb_ereg_search('[а-я]\\:')) {
             $schedule = mb_ereg_replace('^[\\w-]+\\:', '', $schedule);
             $schedule = mb_ereg_replace(', [\\w-]+\\:', ',', $schedule);
         }
         $schedule = trim($schedule);
         $dayIntervals = explode(',', $schedule);
         foreach ($dayIntervals as $dayInterval) {
             $dayInterval = trim($dayInterval);
             if (mb_strpos($dayInterval, 'обед') === false) {
                 $this->parseDayInterval($dayInterval);
             } else {
                 list($trash, $time) = explode(' ', $dayInterval);
                 $this->parseLunch($time);
             }
         }
         foreach ($this->schedule as $day => &$workingTime) {
             if (isset($workingTime['from'])) {
                 $workingTime = [$workingTime];
             }
         }
     } catch (\Exception $e) {
         $this->schedule = 'error parsing';
     }
 }
Exemplo n.º 10
0
 public function convInt($arg)
 {
     // 全角数字や他文字を半角数字に変換
     // mb_convert_kana($arg, 'a', 'UTF-8') 全角数字を半角数字に
     // mb_ereg_replace('[^0-9]', '', foo)  半角数字以外を削除
     return mb_ereg_replace('[^0-9]', '', mb_convert_kana($arg, 'a', 'UTF-8'));
 }
Exemplo n.º 11
0
function viewqueries()
{
    global $tplname, $usr;
    global $viewquery_line, $noqueries, $bgcolor1, $bgcolor2;
    $tplname = 'viewqueries';
    $dbc = OcDb::instance();
    $i = 0;
    $content = '';
    $query = "SELECT id, name FROM `queries` WHERE `user_id`=:1 ORDER BY `name` ASC";
    $s = $dbc->multiVariableQuery($query, $usr['userid']);
    if ($dbc->rowCount($s) != 0) {
        while ($r = $dbc->dbResultFetch($s)) {
            $thisline = $viewquery_line;
            $thisline = mb_ereg_replace('{queryname}', htmlspecialchars($r['name'], ENT_COMPAT, 'UTF-8'), $thisline);
            $thisline = mb_ereg_replace('{queryid}', htmlspecialchars($r['id'], ENT_COMPAT, 'UTF-8'), $thisline);
            if ($i % 2 == 1) {
                $thisline = mb_ereg_replace('{bgcolor}', $bgcolor2, $thisline);
            } else {
                $thisline = mb_ereg_replace('{bgcolor}', $bgcolor1, $thisline);
            }
            $content .= $thisline;
            $i++;
        }
    } else {
        $content = $noqueries;
    }
    unset($dbc);
    tpl_set_var('queries', $content);
    tpl_BuildTemplate();
    exit;
}
Exemplo n.º 12
0
 public static function strip($str, $left, $right)
 {
     $qleft = preg_quote($left);
     $qright = preg_quote($right);
     $pattern = '^\\s*' . $qleft . '\\s*(.*?)\\s*' . $qright . '\\s*$';
     return mb_ereg_replace($pattern, '\\1', $str);
 }
Exemplo n.º 13
0
 function do_url()
 {
     if (!keys_exists(Vars::$post, 'base', 'config')) {
         throw new PluginException('パラメータが足りません', $this);
     }
     $source = Page::getinstance(':config/plugin/tracker/' . Vars::$post['config'] . '/page')->getsource();
     foreach (Vars::$post as $key => $data) {
         if (mb_strpos($key, 'param_') === 0) {
             $name = '[' . mb_substr($key, 6) . ']';
             $_data = trim($data);
             $_data = mb_ereg_replace('\\[', '&#x5b;', $_data, 'm');
             $_data = mb_ereg_replace('\\]', '&#x5d;', $_data, 'm');
             $replace[$name] = $_data;
         }
     }
     $replace['[_date]'] = date('Y-m-d H:i:s');
     $replace['[_base]'] = Vars::$post['base'];
     foreach ($replace as $name => $data) {
         $source = mb_ereg_replace(mb_ereg_quote($name), $data, $source, 'm');
     }
     $db = DataBase::getinstance();
     self::$sqlite_pattern = '^' . mb_ereg_quote(Vars::$post['base']) . '/(\\d+)';
     $db->create_aggregate('plugin_tracker_maxnum', array('Plugin_tracker', 'sqlite_maxnum'), array('Plugin_tracker', 'sqlite_maxnum_finalize'), 1);
     $row = $db->fetch($db->query("SELECT plugin_tracker_maxnum(pagename) FROM page"));
     $num = $row[0] + 1;
     $title = isset(Vars::$post['param_title']) && trim(Vars::$post['param_title']) != '' ? '/' . trim(Vars::$post['param_title']) : '';
     $page = Page::getinstance(Vars::$post['base'] . '/' . $num . $title);
     $page->write($source);
     redirect($page);
 }
Exemplo n.º 14
0
 public static function canonizeString($tagTitle, $replacementStr = '-', $allowNonWordChars = '', $reallyRemoveOtherChars = false)
 {
     $char_map = array('À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A', 'Æ' => 'AE', 'Ç' => 'C', 'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I', 'Ð' => 'D', 'Ñ' => 'N', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => 'O', 'Ő' => 'O', 'Ø' => 'O', 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U', 'Ű' => 'U', 'Ý' => 'Y', 'Þ' => 'TH', 'ß' => 'ss', 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'a', 'å' => 'a', 'æ' => 'ae', 'ç' => 'c', 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'ð' => 'd', 'ñ' => 'n', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ő' => 'o', 'ø' => 'o', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'u', 'ű' => 'u', 'ý' => 'y', 'þ' => 'th', 'ÿ' => 'y', '©' => '(c)', 'Α' => 'A', 'Β' => 'B', 'Γ' => 'G', 'Δ' => 'D', 'Ε' => 'E', 'Ζ' => 'Z', 'Η' => 'H', 'Θ' => '8', 'Ι' => 'I', 'Κ' => 'K', 'Λ' => 'L', 'Μ' => 'M', 'Ν' => 'N', 'Ξ' => '3', 'Ο' => 'O', 'Π' => 'P', 'Ρ' => 'R', 'Σ' => 'S', 'Τ' => 'T', 'Υ' => 'Y', 'Φ' => 'F', 'Χ' => 'X', 'Ψ' => 'PS', 'Ω' => 'W', 'Ά' => 'A', 'Έ' => 'E', 'Ί' => 'I', 'Ό' => 'O', 'Ύ' => 'Y', 'Ή' => 'H', 'Ώ' => 'W', 'Ϊ' => 'I', 'Ϋ' => 'Y', 'α' => 'a', 'β' => 'b', 'γ' => 'g', 'δ' => 'd', 'ε' => 'e', 'ζ' => 'z', 'η' => 'h', 'θ' => '8', 'ι' => 'i', 'κ' => 'k', 'λ' => 'l', 'μ' => 'm', 'ν' => 'n', 'ξ' => '3', 'ο' => 'o', 'π' => 'p', 'ρ' => 'r', 'σ' => 's', 'τ' => 't', 'υ' => 'y', 'φ' => 'f', 'χ' => 'x', 'ψ' => 'ps', 'ω' => 'w', 'ά' => 'a', 'έ' => 'e', 'ί' => 'i', 'ό' => 'o', 'ύ' => 'y', 'ή' => 'h', 'ώ' => 'w', 'ς' => 's', 'ϊ' => 'i', 'ΰ' => 'y', 'ϋ' => 'y', 'ΐ' => 'i', 'Ş' => 'S', 'İ' => 'I', 'Ç' => 'C', 'Ü' => 'U', 'Ö' => 'O', 'Ğ' => 'G', 'ş' => 's', 'ı' => 'i', 'ç' => 'c', 'ü' => 'u', 'ö' => 'o', 'ğ' => 'g', 'А' => 'A', 'Б' => 'B', 'В' => 'V', 'Г' => 'G', 'Д' => 'D', 'Е' => 'E', 'Ё' => 'Yo', 'Ж' => 'Zh', 'З' => 'Z', 'И' => 'I', 'Й' => 'J', 'К' => 'K', 'Л' => 'L', 'М' => 'M', 'Н' => 'N', 'О' => 'O', 'П' => 'P', 'Р' => 'R', 'С' => 'S', 'Т' => 'T', 'У' => 'U', 'Ф' => 'F', 'Х' => 'H', 'Ц' => 'C', 'Ч' => 'Ch', 'Ш' => 'Sh', 'Щ' => 'Sh', 'Ъ' => '', 'Ы' => 'Y', 'Ь' => '', 'Э' => 'E', 'Ю' => 'Yu', 'Я' => 'Ya', 'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd', 'е' => 'e', 'ё' => 'yo', 'ж' => 'zh', 'з' => 'z', 'и' => 'i', 'й' => 'j', 'к' => 'k', 'л' => 'l', 'м' => 'm', 'н' => 'n', 'о' => 'o', 'п' => 'p', 'р' => 'r', 'с' => 's', 'т' => 't', 'у' => 'u', 'ф' => 'f', 'х' => 'h', 'ц' => 'c', 'ч' => 'ch', 'ш' => 'sh', 'щ' => 'sh', 'ъ' => '', 'ы' => 'y', 'ь' => '', 'э' => 'e', 'ю' => 'yu', 'я' => 'ya', 'Є' => 'Ye', 'І' => 'I', 'Ї' => 'Yi', 'Ґ' => 'G', 'є' => 'ye', 'і' => 'i', 'ї' => 'yi', 'ґ' => 'g', 'Č' => 'C', 'Ď' => 'D', 'Ě' => 'E', 'Ň' => 'N', 'Ř' => 'R', 'Š' => 'S', 'Ť' => 'T', 'Ů' => 'U', 'Ž' => 'Z', 'č' => 'c', 'ď' => 'd', 'ě' => 'e', 'ň' => 'n', 'ř' => 'r', 'š' => 's', 'ť' => 't', 'ů' => 'u', 'ž' => 'z', 'Ą' => 'A', 'Ć' => 'C', 'Ę' => 'e', 'Ł' => 'L', 'Ń' => 'N', 'Ó' => 'o', 'Ś' => 'S', 'Ź' => 'Z', 'Ż' => 'Z', 'ą' => 'a', 'ć' => 'c', 'ę' => 'e', 'ł' => 'l', 'ń' => 'n', 'ó' => 'o', 'ś' => 's', 'ź' => 'z', 'ż' => 'z', 'Ā' => 'A', 'Č' => 'C', 'Ē' => 'E', 'Ģ' => 'G', 'Ī' => 'i', 'Ķ' => 'k', 'Ļ' => 'L', 'Ņ' => 'N', 'Š' => 'S', 'Ū' => 'u', 'Ž' => 'Z', 'ā' => 'a', 'č' => 'c', 'ē' => 'e', 'ģ' => 'g', 'ī' => 'i', 'ķ' => 'k', 'ļ' => 'l', 'ņ' => 'n', 'š' => 's', 'ū' => 'u', 'ž' => 'z', 'Ą' => 'A', 'Ę' => 'E', 'Ė' => 'E', 'Į' => 'I', 'Ų' => 'U', 'ą' => 'a', 'ę' => 'e', 'ė' => 'e', 'į' => 'i', 'ų' => 'u', 'ɗ' => 'd', 'ə' => 'e', 'ʍ' => 'm', 'ş' => 's', 'ţ' => 't', 'Ɗ' => 'D', 'Ə' => 'E', 'Ş' => 'S', 'Ţ' => 'T');
     $tagTitle = str_replace(array_keys($char_map), $char_map, $tagTitle);
     // replace all other characters with the replacement string
     if ($reallyRemoveOtherChars) {
         $tagTitle = preg_replace('/([^a-zA-Z0-9' . $allowNonWordChars . '])+/', $replacementStr, $tagTitle);
     } else {
         $tagTitle = mb_ereg_replace("[^\\w{$allowNonWordChars}]", $replacementStr, $tagTitle);
     }
     //no duplicates
     $tagTitle = mb_ereg_replace("[{$replacementStr}]{2,}", $replacementStr, $tagTitle);
     // convert .- to .
     $tagTitle = str_replace('.' . $replacementStr, '.', $tagTitle);
     // remove . from the beinning and the end
     if (mb_substr($tagTitle, 0, 1) == '.') {
         $tagTitle = mb_substr($tagTitle, 1);
     }
     if (mb_substr($tagTitle, mb_strlen($tagTitle) - 1, 1) == '.') {
         $tagTitle = mb_substr($tagTitle, 0, mb_strlen($tagTitle) - 1);
     }
     // remove replacement strings from the beginning and the end
     if (mb_substr($tagTitle, 0, 1) == $replacementStr) {
         $tagTitle = mb_substr($tagTitle, 1);
     }
     if (mb_substr($tagTitle, mb_strlen($tagTitle) - 1, 1) == $replacementStr) {
         $tagTitle = mb_substr($tagTitle, 0, mb_strlen($tagTitle) - 1);
     }
     return $tagTitle;
 }
Exemplo n.º 15
0
 function mb_ucfirst($str, $encoding='UTF-8')
 {
     $str = mb_ereg_replace('^[\ ]+', '', $str);
     $str = mb_strtoupper(mb_substr($str, 0, 1, $encoding), $encoding).
            mb_substr($str, 1, mb_strlen($str), $encoding);
     return $str;
 }
 /**
  * Split string & reunite it again
  * Used to create token list
  * @return string Constructed string
  */
 public function split()
 {
     $value = $this->EE->TMPL->fetch_param('value');
     $delimiter = $this->EE->TMPL->fetch_param('delimiter');
     $join = $this->EE->TMPL->fetch_param('join');
     return implode('"' . $join . '"', explode($delimiter, mb_ereg_replace("/[^ \\w]+/", "", $value)));
 }
Exemplo n.º 17
0
Arquivo: k.php Projeto: hornos/C2
function __k_str($s = NULL, $l = C2_STR_LENGTH)
{
    if (C2_MB) {
        return mb_substr(mb_ereg_replace(C2_STR_REGEXP, '', $s), 0, $l);
    }
    return substr(ereg_replace(C2_STR_REGEXP, '', $s), 0, $l);
}
Exemplo n.º 18
0
function getWaypoints($cacheid)
{
    global $waypointline;
    global $waypointlines;
    global $nowaypoints;
    $wphandler = new HandlerChildWp();
    $waypoints = $wphandler->getChildWps($cacheid);
    $ret = '';
    if (!empty($waypoints)) {
        $formatter = new FormatterCoordinate();
        foreach ($waypoints as $waypoint) {
            $tmpline = $waypointline;
            $tmpline = mb_ereg_replace('{wp_image}', htmlspecialchars($waypoint['image'], ENT_COMPAT, 'UTF-8'), $tmpline);
            $tmpline = mb_ereg_replace('{wp_type}', htmlspecialchars($waypoint['name'], ENT_COMPAT, 'UTF-8'), $tmpline);
            $htmlcoordinate = $formatter->formatHtml($waypoint['coordinate'], '</td></tr><tr><td style="white-space:nowrap">');
            $tmpline = mb_ereg_replace('{wp_coordinate}', $htmlcoordinate, $tmpline);
            $tmpline = mb_ereg_replace('{wp_description}', htmlspecialchars(trim($waypoint['description']), ENT_COMPAT, 'UTF-8'), $tmpline);
            $tmpline = mb_ereg_replace('{wp_show_description}', mb_ereg_replace('\\r\\n', '<br />', htmlspecialchars($waypoint['description'], ENT_COMPAT, 'UTF-8')), $tmpline);
            $tmpline = mb_ereg_replace('{cacheid}', htmlspecialchars($cacheid, ENT_COMPAT, 'UTF-8'), $tmpline);
            $tmpline = mb_ereg_replace('{childid}', htmlspecialchars($waypoint['childid'], ENT_COMPAT, 'UTF-8'), $tmpline);
            $ret .= $tmpline;
        }
        $ret = mb_ereg_replace('{lines}', $ret, $waypointlines);
        return $ret;
    }
    return $nowaypoints;
}
Exemplo n.º 19
0
function html2plaintext($text, $texthtml0, $wrap)
{
    global $opt, $smiley;
    if ($texthtml0) {
        $text = str_replace(['<p>', "\n", "\r"], '', $text);
        $text = str_replace(['<br />', '</p>'], "\n", $text);
        $text = html_entity_decode($text, ENT_COMPAT, 'UTF-8');
    } else {
        // convert smilies ...
        $countSmileyImage = count($smiley['image']);
        for ($n = 0; $n < $countSmileyImage; $n++) {
            $text = mb_ereg_replace("<img [^>]*?src=[^>]+?" . str_replace('.', '\\.', $smiley['file'][$n]) . "[^>]+?>", "[s![" . $smiley['text'][$n] . "]!s]", $text);
            // the [s[ ]s] is needed to protect the spaces around the smileys
        }
        $h2t = new html2text($text);
        $h2t->set_base_url($opt['page']['default_absolute_url']);
        $h2t->width = $wrap;
        $text = $h2t->get_text();
        $text = str_replace(['[s![', ']!s]'], '', $text);
        // remove e.g. trailing \n created from </p> by html2text
        while (substr($text, -2) == "\n\n") {
            $text = substr($text, 0, strlen($text) - 1);
        }
    }
    return $text;
}
 public function beforeSave($options = array())
 {
     if (isset($this->data['Mypage']['password'])) {
         $passwordHasher = new SimplePasswordHasher();
         $this->data['Mypage']['password'] = $passwordHasher->hash($this->data['Mypage']['password']);
     }
     //nameを使わず、name_1_2に分ける場合、合体させる
     if (isset($this->data['Mypage']['name_1'])) {
         if (isset($this->data['Mypage']['name_2'])) {
             $this->data['Mypage']['name'] = $this->data['Mypage']['name_1'] . ' ' . $this->data['Mypage']['name_2'];
         } else {
             $this->data['Mypage']['name'] = $this->data['Mypage']['name_1'];
         }
     }
     //telを使わず、tel_1_2_3に分ける場合、合体させる
     if (isset($this->data['Mypage']['tel_1'])) {
         $tel = $this->data['Mypage']['tel_1'] . $this->data['Mypage']['tel_2'] . $this->data['Mypage']['tel_3'];
         $tel = mb_convert_kana($tel, "n");
         $tel = mb_ereg_replace('[^0-9]', '', $tel);
         if (!empty($tel)) {
             $this->data['Mypage']['tel'] = $tel;
         }
     }
     return true;
 }
Exemplo n.º 21
0
 public static function getCityCodeByName($cityName)
 {
     if (empty($cityName)) {
         return array();
     }
     $cityName = trim($cityName);
     $cityName = mb_ereg_replace('市*$', '', $cityName);
     $ck = Cache::CK_BAIDU_CITY_INFO . $cityName;
     $result = Cache::get($ck);
     if ($result !== false) {
         return json_decode($result, true);
     }
     $url = 'http://apistore.baidu.com/microservice/cityinfo?cityname=' . urlencode($cityName);
     $ret = HttpUtil::request($url, false, false, 2);
     if ($ret === false) {
         Log::warng('baidu ' . __METHOD__ . ' - request timeout or fail city=' . $cityName);
         return false;
     }
     $ret = json_decode($ret, true);
     if (empty($ret['retData'])) {
         Log::warng('baidu ' . __METHOD__ . ' - fail city=' . $cityName . ' ' . json_encode($ret));
         return false;
     }
     return $ret['retData']['cityCode'];
 }
Exemplo n.º 22
0
function layotter_make_search_dump($data, $raw_post)
{
    $post_id = $raw_post['ID'];
    // don't change anything if not editing a Layotter-enabled post
    if (!Layotter::is_enabled_for_post($post_id) or !isset($raw_post['layotter_json'])) {
        return $data;
    }
    // copy JSON from POST and strip slashes that were added by Wordpress
    $json = $raw_post['layotter_json'];
    $unslashed_json = stripslashes_deep($json);
    // turn JSON into post content HTML
    $layotter_post = new Layotter_Post($unslashed_json);
    $content = $layotter_post->get_frontend_view();
    // save JSON to a custom field (oddly enough, Wordpress breaks JSON if it's stripslashed)
    update_post_meta($post_id, 'layotter_json', $json);
    // insert spaces to prevent <p>foo</p><p>bar</p> becoming "foobar" instead of "foo bar"
    // then strip all tags except <img>
    // then remove excess whitespace
    $spaced_content = str_replace('<', ' <', $content);
    $clean_content = strip_tags($spaced_content, '<img>');
    $normalized_content = trim($clean_content);
    if (function_exists('mb_ereg_replace')) {
        $normalized_content = mb_ereg_replace('/\\s+/', ' ', $normalized_content);
    }
    // wrap search dump with a [layotter] shortcode and return modified post data to be saved to the database
    // add the post ID because otherwise the shortcode handler would have no reliable way to get the post ID through
    // which the JSON data will be fetched
    $shortcoded_content = '[layotter post="' . $post_id . '"]' . $normalized_content . '[/layotter]';
    $data['post_content'] = $shortcoded_content;
    return $data;
}
Exemplo n.º 23
0
/**
 * swjz.xmlを変更。処理しやすいように
 */
function modify(&$file, &$temp)
{
    $chap = 0;
    while ($line = fgets($file)) {
        if ($chap == 0) {
            $a = preg_match('/<chapter>/', $line, $matches);
            if ($a) {
                $chap = 1;
            }
        }
        if ($chap != 0) {
            $line = mb_ereg_replace('<!--<', '(', $line);
            //parse errorを回避
            $line = mb_ereg_replace('>-->', ')', $line);
            $line = mb_ereg_replace('<!--', '(', $line);
            //文中のコメントを得られるように。全角まるカッコ
            $line = mb_ereg_replace('-->', ')', $line);
        }
        // <wordhead> 単位で取れるように
        $line = mb_ereg_replace('<\\s*wordhead\\s+id', "</one><one><wordhead id", $line);
        $line = mb_ereg_replace('<\\s*shuowen\\s*>', "<shuowen><one>", $line);
        $line = mb_ereg_replace('</\\s*shuowen\\s*>', "</one></shuowen>", $line);
        // echo $line;
        fwrite($temp, $line);
    }
}
Exemplo n.º 24
0
 /** @inheritdoc */
 public function parse($format, $data, $charset = 'UTF-8')
 {
     if (!$this->isSupported($format)) {
         return new \RuntimeException("Format {$format} is not upported.");
     }
     // no menu on Saturdays and Sundays
     $day = date('N');
     if ($day == 6 || $day == 7) {
         return [];
     }
     $result = [];
     $key = null;
     $this->getCrawler($data, $charset)->filter('div.subBlock[value="1"] > div:nth-child(' . $day . ')')->filter('div.html > div.cont')->children()->each(function (Crawler $crawler) use(&$result, &$key) {
         try {
             if ($crawler->nodeName() == 'h4') {
                 $key = static::KEY_MAIN;
                 if (preg_match('/Polévk/', $crawler->text())) {
                     $key = static::KEY_SOUPS;
                 }
             } else {
                 if ($key == null) {
                     return;
                 }
                 $meal = $crawler->filter('td > div.nadpis.first')->first()->text();
                 foreach (static::FILTERS as $pattern) {
                     $meal = mb_ereg_replace($pattern, '', $meal);
                 }
                 $result[$key][] = [$meal, $price = 0 + $crawler->filter('td > div.prize:nth-child(2)')->first()->text()];
             }
         } catch (\Exception $e) {
         }
     });
     return $result;
 }
function xsell_db_like_input($inputText)
{
    $text = zen_db_input($inputText);
    $text = mb_ereg_replace("%", "\\%", $text);
    $text = mb_ereg_replace("_", "\\_", $text);
    return $text;
}
Exemplo n.º 26
0
/**
 *
 * @param string $string
 * @param int $word_limit
 * @param string $ending
 * @return string
 */
function clean_text($string, $word_limit = 0, $ending = ' ...')
{
    //remove wp shortcodes
    $string = \strip_shortcodes($string);
    //adds a space before every tag open so we don't get heading/paragraphs glued together when we strip tags
    $string = str_replace('<', ' <', $string);
    //strip tags
    $string = strip_tags($string);
    //convert space entities to normal spaces to help out some users
    $string = str_replace('&nbsp;', ' ', $string);
    //convert to html entities
    $string = htmlspecialchars($string);
    //convert space entities to regular spaces so we can remove double spaces - all other hmtl entities should be fine
    $string = str_replace('&nbsp;', ' ', $string);
    //removes double spaces, tabs or line breaks, and trim the result
    $string = trim(mb_ereg_replace('\\s+', ' ', $string));
    //limit
    if ($word_limit) {
        $words = explode(' ', $string);
        if (count($words) > $word_limit) {
            array_splice($words, $word_limit);
            $string = implode(' ', $words) . $ending;
        }
    }
    return $string;
}
Exemplo n.º 27
0
/**
* Smarty truncate 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 $string input string
* @param integer $length lenght of truncated text
* @param string $etc end string
* @param boolean $break_words truncate at word boundary
* @param boolean $middle truncate in the middle of text
* @return string truncated string
*/
function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false)
{
    if ($length == 0) {
        return '';
    }
    if (is_callable('mb_strlen')) {
        if (mb_strlen($string) > $length) {
            $length -= min($length, mb_strlen($etc));
            if (!$break_words && !$middle) {
                $string = mb_ereg_replace('/\\s+?(\\S+)?$/', '', mb_substr($string, 0, $length + 1), 'p');
            }
            if (!$middle) {
                return mb_substr($string, 0, $length) . $etc;
            } else {
                return mb_substr($string, 0, $length / 2) . $etc . mb_substr($string, -$length / 2);
            }
        } else {
            return $string;
        }
    } else {
        if (strlen($string) > $length) {
            $length -= min($length, strlen($etc));
            if (!$break_words && !$middle) {
                $string = preg_replace('/\\s+?(\\S+)?$/', '', substr($string, 0, $length + 1));
            }
            if (!$middle) {
                return substr($string, 0, $length) . $etc;
            } else {
                return substr($string, 0, $length / 2) . $etc . substr($string, -$length / 2);
            }
        } else {
            return $string;
        }
    }
}
Exemplo n.º 28
0
 public function escape(array $values)
 {
     if (extension_loaded("mbstring")) {
         $toEnc = defined("SDB_MSSQL_ENCODING") ? SDB_MSSQL_ENCODING : "SJIS";
         $fromEnc = mb_internal_encoding();
         $currentRegexEnc = mb_regex_encoding();
         mb_regex_encoding($fromEnc);
         foreach ($values as $k => &$val) {
             if (is_bool($val)) {
                 $val = $val ? "1" : "0";
             } elseif (is_string($val)) {
                 $val = "'" . mb_convert_encoding(mb_ereg_replace("'", "''", $val), $toEnc, $fromEnc) . "'";
             }
         }
         mb_regex_encoding($currentRegexEnc);
     } else {
         foreach ($values as &$val) {
             if (is_bool($val)) {
                 $val = $val ? "1" : "0";
             } elseif (is_string($val)) {
                 $val = "'" . str_replace("'", "''", $val) . "'";
             }
         }
     }
     return $values;
 }
function showRelatedEntryList($text)
{
    global $pathToIndex, $app, $item;
    // SETTING BEGIN
    // Entry Count
    $entryCount = 3;
    // <h4> text </h4>
    $relatedText = '関連記事';
    //$relatedText   = 'Related Entries';
    // No related
    $noRelatedText = '&lt; No Related Entries &gt;';
    // Target string
    $tagetStr = '<!-- related -->';
    // SETTING END
    if (!preg_match('/\\/downloads\\//', $app->getRequestURI())) {
        // Get Log ID List
        $tagIdList = $app->getTagIdArray();
        foreach ($tagIdList as $row) {
            $sql = 'SELECT ' . 'log_id ' . 'FROM ' . LOG_TAG_MAP_TABLE . ' ' . 'WHERE ' . "tag_id = '" . $row . "' " . 'AND ' . "log_id != '" . $item['id'] . "'";
            if ($res = $app->db->query($sql)) {
                $list = $res->fetchAll();
                foreach ($list as $row) {
                    $logIdList[] = $row['log_id'];
                }
            }
        }
        if (count($logIdList)) {
            // Get related entry list
            $logIdList = array_count_values($logIdList);
            foreach ($logIdList as $key => $value) {
                $sql = 'SELECT ' . 'title ' . 'FROM ' . LOG_TABLE . ' ' . 'WHERE ' . "id = '" . $key . "' " . 'AND ' . "draft = '0'";
                if ($title = $app->db->query($sql)->fetchColumn()) {
                    $relatedEntryList[] = array('log_id' => $key, 'count' => $value, 'title' => $title);
                }
            }
            uasort($relatedEntryList, 'compare');
            $relatedEntryList = array_slice($relatedEntryList, 0, $entryCount);
        }
        // Markup
        if (count($relatedEntryList)) {
            $listHtml = '<ul id="related-entry-list">' . "\n";
            foreach ($relatedEntryList as $row) {
                $listHtml .= '<li><a href="' . $pathToIndex . '/index.php?id=' . $row['log_id'] . '">' . $row['title'] . '</a></li>' . "\n";
            }
            $listHtml .= '</ul>' . "\n";
        } else {
            $listHtml = '<p class="passive">' . $noRelatedText . '</p>' . "\n";
        }
        // Contents
        $content = '
<div id="related-entries">
<h4>' . $relatedText . '</h4>
' . $listHtml . '</div>
';
        // Replace
        $text = mb_ereg_replace($tagetStr, $content, $text);
    }
    return $text;
}
Exemplo n.º 30
0
 protected function includepage($pagename)
 {
     $source = mb_ereg_replace('#blognavi', '', Page::getinstance($pagename)->getsource());
     $smarty = $this->getSmarty();
     $smarty->assign('title', $pagename);
     $smarty->assign('body', convert_block($source, $pagename));
     return $smarty->fetch('include.tpl.htm');
 }