Esempio n. 1
0
 /**
  * อ่านข้อมูลการเยี่ยมชมในวันที่เลือก
  *
  * @param string $date
  * @return array
  */
 public static function get($date)
 {
     $datas = array();
     if (preg_match('/^([0-9]+)\\-([0-9]+)\\-([0-9]+)$/', $date, $match)) {
         $y = $match[1];
         $m = $match[2];
         $d = $match[3];
         $counter_dat = ROOT_PATH . DATA_FOLDER . 'counter/' . (int) $y . '/' . (int) $m . '/' . (int) $d . '.dat';
         if (is_file($counter_dat)) {
             foreach (file($counter_dat) as $a => $item) {
                 list($sid, $sip, $sref, $sagent, $time) = explode(chr(1), $item);
                 if (preg_match_all('%(?P<browser>Firefox|Safari|MSIE|AppleWebKit|bingbot|MJ12bot|Baiduspider|Googlebot|DotBot|Twitterbot|LivelapBot|facebookexternalhit|StatusNet|PaperLiBot|SurdotlyBot|Trident|archive\\.org_bot|Yahoo\\!\\sSlurp|Go[a-z\\-]+)([\\/\\s](?P<version>[^;\\s]+))?%ix', $sagent, $result, PREG_PATTERN_ORDER)) {
                     $sagent = '<span title="' . $sagent . '">' . $result['browser'][0] . (empty($result['version'][0]) ? '' : '/' . $result['version'][0]) . '</span>';
                 } elseif ($sagent != '') {
                     $sagent = '<span title="' . $sagent . '">unknown</span>';
                 }
                 $datas[$sip . $sref] = array('time' => isset($datas[$sip . $sref]) ? $datas[$sip . $sref]['time'] : $time, 'count' => isset($datas[$sip . $sref]) ? $datas[$sip . $sref]['count'] + 1 : 1, 'ip' => '<a href="http://' . $sip . '" target=_blank>' . $sip . '</a>', 'agent' => $sagent, 'referer' => '');
                 if (preg_match('/^(https?.*(www\\.)?google(usercontent)?.*)\\/.*[\\&\\?]q=(.*)($|\\&.*)/iU', $sref, $match)) {
                     // จาก google search
                     $title = rawurldecode(rawurldecode($match[4]));
                 } elseif (preg_match('/^(https?:\\/\\/(www.)?google[\\.a-z]+\\/url\\?).*&url=(.*)($|\\&.*)/iU', $sref, $match)) {
                     // จาก google cached
                     $title = rawurldecode(rawurldecode($match[3]));
                 } elseif ($sref != '') {
                     // ลิงค์ภายในไซต์
                     $title = rawurldecode(rawurldecode($sref));
                 }
                 if ($sref != '') {
                     $datas[$sip . $sref]['referer'] = '<a href="' . $sref . '" title="' . $title . '" target=_blank>' . Text::cut($title, 149) . '</a>';
                 }
             }
         }
     }
     return $datas;
 }
 /**
  * จัดรูปแบบการแสดงผลในแต่ละแถว
  *
  * @param array $item
  * @return array
  */
 public function onRow($item)
 {
     foreach ($item as $key => $value) {
         if ($key != 'id') {
             $text = \Kotchasan\Text::toEditor(is_array($value) ? implode(', ', $value) : $value);
             $item[$key] = '<span title="' . $text . '">' . \Kotchasan\Text::cut($text, 50) . '</span>';
         }
     }
     return $item;
 }
Esempio n. 3
0
 /**
  * Generated from @assert ('123456789', 8) [==] '123456..'.
  *
  * @covers Kotchasan\Text::cut
  */
 public function testCut2()
 {
     $this->assertEquals('123456..', \Kotchasan\Text::cut('123456789', 8));
 }
Esempio n. 4
0
 /**
  * ฟังก์ชั่น แปลง html เป็น text
  * สำหรับตัด tag หรือเอา BBCode ออกจากเนื้อหาที่เป็น HTML ให้เหลือแต่ข้อความล้วน
  *
  * @param string $text ข้อความ
  * @return string คืนค่าข้อความ
  */
 public static function html2txt($text, $len = 0)
 {
     $patt = array();
     $replace = array();
     // ตัด style
     $patt[] = '@<style[^>]*?>.*?</style>@siu';
     $replace[] = '';
     // ตัด comment
     $patt[] = '@<![\\s\\S]*?--[ \\t\\n\\r]*>@u';
     $replace[] = '';
     // ตัด tag
     $patt[] = '@<[\\/\\!]*?[^<>]*?>@iu';
     $replace[] = '';
     // ตัด keywords
     $patt[] = '/{(WIDGET|LNG)_[a-zA-Z0-9_]+}/su';
     $replace[] = '';
     // ลบ BBCode
     $patt[] = '/(\\[code(.+)?\\]|\\[\\/code\\]|\\[ex(.+)?\\])/ui';
     $replace[] = '';
     // ลบ BBCode ทั่วไป [b],[i]
     $patt[] = '/\\[([a-z]+)([\\s=].*)?\\](.*?)\\[\\/\\1\\]/ui';
     $replace[] = '\\3';
     $replace[] = ' ';
     // ตัดตัวอักษรที่ไม่ต้องการออก
     $patt[] = '/(&amp;|&quot;|&nbsp;|[_\\(\\)\\-\\+\\r\\n\\s\\"\'<>\\.\\/\\\\?&\\{\\}]){1,}/isu';
     $replace[] = ' ';
     $text = trim(preg_replace($patt, $replace, $text));
     if ($len > 0) {
         $text = Text::cut($text, $len);
     }
     return $text;
 }