PageRenderTime 98ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/system/application/models/fetch_model.php

https://github.com/aeil/activity
PHP | 267 lines | 265 code | 1 blank | 1 comment | 1 complexity | 886bf0c524727085cc6710fe044e93fe MD5 | raw file
  1. <?php
  2. class fetch_model extends Model {
  3. public $pattern = array();
  4. public $ci ;
  5. function fetch_model()
  6. {
  7. // Call the Model constructor
  8. parent::Model();
  9. $this->priority= array
  10. (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21);
  11. $this->pattern = array
  12. ("U","H","F","y","l","L","s","t","T","k","d","B","cs","ps","et","tt","lt","as","il","dl","sl","xl");
  13. $this->patterno = array
  14. ("","U","H","F","y","l","L","s","t","T","k","d","B","cs","ps","et","tt","lt","as","il","dl","sl","xl");
  15. $this->record = array
  16. (
  17. 'nextmin'=>array
  18. (
  19. 'homepage'=>array
  20. (
  21. 'http://www.nextmin.com.tw/ongoing/',
  22. "<a\s[^>]*href=(\"??)\/event\/([^\" >]*?)\\1[^>]*>(.*)<\/a>"
  23. ),
  24. 'event'=>array
  25. (
  26. 'http://www.nextmin.com.tw/event/',
  27. "<div>\s[^>]*<b>.*<\/b>(.*)<\/div>"
  28. . ".*(<div\s[^>]*class=\"??block_standard[^\" >]"
  29. . "*?\"??[^>]*>)(.*)\\2"
  30. )
  31. )
  32. );
  33. //$this->getnextmin();
  34. //$this->load->model('hbase_model');
  35. $this->ci =& get_instance();
  36. $this->ci->load->model('hbase_model');
  37. $this->ci->hbase_model->hbaseini();
  38. //for($i=1;$i<=10;$i++)
  39. //$this->getnextmin($i);
  40. //$this->hbase_model->hbaseini();
  41. }
  42. function hbaseget($coldes,$col,$num=1)
  43. {
  44. return $this->hbase_model->hbaseget($coldes,$col,$num);
  45. }
  46. function hbasegetrange($coldes,$start,$end,$num=1)
  47. {
  48. return $this->hbase_model->hbasegetrange($coldes,$start,$end,$num);
  49. }
  50. function getnextmin($page=1)
  51. {
  52. date_default_timezone_set('UTC');
  53. /*$homepage = file_get_contents
  54. ('http://www.nextmin.com.tw/ongoing/'
  55. . $page == 1 ? "" : ("page=" . $page));
  56. preg_match_all("/calendar_month.+>(\w+)</",$homepage,$matches);
  57. */$url = "http://www.nextmin.com.tw/ongoing/"
  58. . ($page == 1 ? "" : ("?page=" . $page));
  59. $input = @file_get_contents($url) or die("Could not access file: $url");
  60. $regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
  61. $regexp = "<div\s[^>]*class=\"??calendar[^\" >]*?\"??[^>]*>(.*)<\/div>";
  62. $regexp = "<a\s[^>]*href=(\"??)\/event\/([^\" >]*?)\\1[^>]*>(.*)<\/a>";
  63. if(preg_match_all("/$regexp/siU", $input, $matches))
  64. {
  65. foreach($matches[2] as $v)
  66. {
  67. $input= file_get_contents('http://www.nextmin.com.tw/event/'.$v);
  68. $regexp = "<div>\s[^>]*<b>.*<\/b>(.*)<\/div>"
  69. . ".*(<div\s[^>]*class=\"??block_standard[^\" >]*?\"??[^>]*>)(.*)\\2";
  70. $iteration = 0;
  71. if(preg_match_all("/$regexp/siU", $input, $m))
  72. {
  73. foreach($m as $v1)
  74. {
  75. if($iteration % 4 == 0)
  76. {
  77. $regexp = "<div>\s[^>]*<b>.*<\/b>(.*)<\/div>";
  78. preg_match_all("/$regexp/siU", $v1[0], $m1);
  79. $date = explode("~",$m1[1][0]);
  80. foreach($date as $v2)
  81. {
  82. // 2011/03/25 (???? 07:30PM
  83. //echo preg_replace("/[\(\):]/","/",$v2);
  84. (int)$times = explode("/",
  85. preg_replace("/[\(\):]/","/",$v2));
  86. $date = mktime(strlen($times[4])==1?0:(int)$times[4]
  87. ,substr(empty($times[5]) ?0:(int)$times[5],0,2)
  88. ,0,(int)$times[1],(int)$times[2],(int)$times[0]);
  89. //echo (int)strlen($times[4]) . "|" . ((int)substr(empty($times[5])?0:$times[5],0,2)
  90. // .(int)$times[1].(int)$times[2].(int)$times[0])."<br/>";
  91. break;
  92. }
  93. $place = $m1[1][1];
  94. $regexp = "<div\s[^>]*class=\"??event_detail_description"
  95. . "[^\" >]*?\"??[^>]*>(.*)"
  96. . "<div\s[^>]*class=\"??block_standard[^\" >]*?\"??[^>]*>";
  97. preg_match_all("/$regexp/siU", $v1[0], $m2);
  98. //print_r($m2);
  99. $content = $m2[1][0];
  100. $this->ci->hbase_model->hbaseinsert($date,'place','place',urlencode($place));
  101. $this->ci->hbase_model->hbaseinsert($date,'place','content',urlencode($content));
  102. $nextmin[] = array
  103. (
  104. 'place'=>$place,
  105. 'content'=>$content,
  106. 'date'=>$date.= "|" . implode("",$times)
  107. );
  108. }
  109. if($iteration % 4 == 1)
  110. {
  111. }
  112. $iteration++;
  113. }
  114. }
  115. }
  116. }
  117. return $nextmin;
  118. }
  119. function gethtmlparam()
  120. {
  121. $data = array(
  122. 'title' => 'Aeil\'s Search Engine',
  123. 'heading' => 'My Heading',
  124. 'message' => 'My Message',
  125. 'url' => base_url()
  126. );
  127. return $data;
  128. }
  129. function queryoptions($content,$c,$p,$v)
  130. {
  131. //ex:(apple & pie) | banana
  132. $pos = FALSE;
  133. if( $p == 'y')
  134. {
  135. mb_internal_encoding('UTF-8');
  136. //if($t === $k)echo $k;
  137. //if(mb_ereg_match($content,$v))
  138. //echo "PPP<br/>";
  139. $pre = explode(" ",$v);
  140. if($c == 'y')
  141. {
  142. foreach($pre as $k)
  143. if($content === $k)$pos++;
  144. }
  145. else
  146. {
  147. foreach($pre as $k)
  148. if(strcasecmp($k,$content)== 0)$pos++;
  149. }
  150. }
  151. else
  152. {
  153. $pattern = "/".$content."/";
  154. $pattern .= $c == 'y' ? "" : "i";
  155. preg_match_all($pattern,$v,$matches);
  156. $pos = (count($matches[0]) == 0) ? FALSE : count($matches[0]);
  157. }
  158. return $pos;
  159. }
  160. function getData($content,$c,$p)
  161. {
  162. //Query the data table for every record and row
  163. //if ($query->num_rows() > 0)
  164. //{
  165. // //show_error('Database is empty!');
  166. //}else{
  167. // return $query->result();
  168. //}
  169. $this->load->helper('file');
  170. $this->load->helper('string');
  171. $this->load->library('typography');
  172. $string = explode("@\n",read_file('./record/recode.txt'));
  173. unset($string[0]);
  174. //$content = "AEWIN";
  175. $r = $r1 = Array();
  176. foreach($string as $s)
  177. {
  178. //echo count($s,COUNT_RECURSIVE);
  179. //print_r($s);
  180. $match = FALSE;
  181. $score = 0;
  182. foreach(preg_split('/\n@/',$s) as $k=>$v)
  183. {
  184. $v = preg_replace('/^.{1,2}:/','',$v);
  185. //echo $v . "<br />";
  186. $pos = $this->queryoptions($content,$c,$p,$v);
  187. if ($pos === false) {}
  188. else
  189. {
  190. //echo $k."||".$v."||".$pos;
  191. $match = TRUE;
  192. $score += $this->priority[$k] * $pos;
  193. //echo $score ."|".$pos."|".$this->priority[$k]. "<br />";
  194. }
  195. $r1[$this->pattern[$k]] = preg_replace('/^@\w+:/','',$v);
  196. }
  197. if($match)
  198. {
  199. //array_push($r,array($r1,$score));
  200. $r1['score'] = $score;
  201. $r1['encrypt'] = "";
  202. foreach($r1 as $e)
  203. {
  204. $r1['encrypt'].= "|".$e;
  205. }
  206. $r1['encrypt'] = addslashes(
  207. $this->typography->
  208. format_characters(str_replace("/","&sl",$r1['encrypt'])));
  209. //$r1['encrypt'] = $encrypt;//$this->encrypt->encode($r1['encrypt']);
  210. //echo $r1['encrypt'];
  211. array_push($r,$r1);
  212. //$r[] = array($r1,$score);
  213. //print_r($r);
  214. }
  215. //echo $this->pattern->cs . "EEE";
  216. //echo "<pre>";
  217. //preg_match($content, preg_split('/\n@/',$s), $matches);
  218. //print_r($matches);
  219. //echo ( array_search($content,preg_split('/\n@/',$s)));
  220. //print_r ( preg_split('/\n@/',$s));
  221. //print_r( $s);
  222. //echo "</pre>";
  223. //echo "SSSS";
  224. }
  225. if(!empty($r))$this->getsort($r);
  226. //preg_match_all("/hnol/","T:AEWIN Technologies Co., Ltd.AEWINAEWINAEWINAEWINAEWINAEWINAEWINAEWINAEWIN",$matches);
  227. //$pre = explode(" ","T:AEWIN Technologies Co., Ltd.AEWINAEWINAEW INAEWINAEWINAEWINAEWINAEWINAEWIN");
  228. //$t = "t:aEWIN";
  229. ////print_r($pre);
  230. //foreach($pre as $k)
  231. //{
  232. // if(strlen($k)>=strlen($t))
  233. // {
  234. // //echo strcasecmp($k,$t);
  235. // //echo "{".strlen($k)."|".strlen($t)."}".substr_compare($k,$t,0,strlen($t),FALSE);
  236. // }
  237. // //if($t === $k)echo $k;
  238. //}
  239. //echo count($matches,COUNT_RECURSIVE) . var_dump($matches) . "EE";
  240. return $r;
  241. }
  242. function getsort(&$r)
  243. {
  244. foreach($r as $k=>$v)
  245. {
  246. $orgk[$k] = $k;
  247. $score[$k] = $v['score'];
  248. }
  249. array_multisort($score,SORT_DESC,$orgk,SORT_ASC,$r);
  250. //echo "<pre>";
  251. //print_r($r);
  252. //echo
  253. //print_r($r);
  254. //echo "</pre>";
  255. }
  256. }
  257. ?>