activity /system/application/models/fetch_model.php

Language PHP Lines 268
MD5 Hash 886bf0c524727085cc6710fe044e93fe Estimated Cost $19,806 (why?)
Repository https://github.com/aeil/activity.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<?php  
class fetch_model extends Model {  
  
	public $pattern = array();
	public $ci ;
    function fetch_model()  
    {  
        // Call the Model constructor  
        parent::Model();  
		$this->priority= array
			(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21);
		$this->pattern = array
			("U","H","F","y","l","L","s","t","T","k","d","B","cs","ps","et","tt","lt","as","il","dl","sl","xl");
		$this->patterno = array
			("","U","H","F","y","l","L","s","t","T","k","d","B","cs","ps","et","tt","lt","as","il","dl","sl","xl");
		$this->record = array
			(
				'nextmin'=>array
				(
					'homepage'=>array
					(
						'http://www.nextmin.com.tw/ongoing/',
						"<a\s[^>]*href=(\"??)\/event\/([^\" >]*?)\\1[^>]*>(.*)<\/a>" 
					),
					'event'=>array
					(
						'http://www.nextmin.com.tw/event/',
						"<div>\s[^>]*<b>.*<\/b>(.*)<\/div>"
						. ".*(<div\s[^>]*class=\"??block_standard[^\" >]"
						. "*?\"??[^>]*>)(.*)\\2"
					)
				)
			);
		//$this->getnextmin();
		//$this->load->model('hbase_model');
		$this->ci =& get_instance();
		$this->ci->load->model('hbase_model');
		$this->ci->hbase_model->hbaseini();
		//for($i=1;$i<=10;$i++)		
		//$this->getnextmin($i);
		//$this->hbase_model->hbaseini();
    }  
	function hbaseget($coldes,$col,$num=1)
	{
		return $this->hbase_model->hbaseget($coldes,$col,$num);
	}
	function hbasegetrange($coldes,$start,$end,$num=1)
	{
		return $this->hbase_model->hbasegetrange($coldes,$start,$end,$num);
	}
	function getnextmin($page=1)
	{
		date_default_timezone_set('UTC'); 
		/*$homepage = file_get_contents
			('http://www.nextmin.com.tw/ongoing/' 
			. $page == 1 ? "" : ("page=" . $page));
		preg_match_all("/calendar_month.+>(\w+)</",$homepage,$matches);
		*/$url = "http://www.nextmin.com.tw/ongoing/" 
			. ($page == 1 ? "" : ("?page=" . $page));
		$input = @file_get_contents($url) or die("Could not access file: $url"); 
		$regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>"; 
		$regexp = "<div\s[^>]*class=\"??calendar[^\" >]*?\"??[^>]*>(.*)<\/div>";
		$regexp = "<a\s[^>]*href=(\"??)\/event\/([^\" >]*?)\\1[^>]*>(.*)<\/a>"; 
		if(preg_match_all("/$regexp/siU", $input, $matches)) 
		{
			foreach($matches[2] as $v)
			{
				$input= file_get_contents('http://www.nextmin.com.tw/event/'.$v);
				$regexp = "<div>\s[^>]*<b>.*<\/b>(.*)<\/div>"
					. ".*(<div\s[^>]*class=\"??block_standard[^\" >]*?\"??[^>]*>)(.*)\\2";
				$iteration = 0;
				if(preg_match_all("/$regexp/siU", $input, $m)) 
				{
					foreach($m as $v1)
					{
						if($iteration % 4 == 0) 
						{
							$regexp = "<div>\s[^>]*<b>.*<\/b>(.*)<\/div>";
							preg_match_all("/$regexp/siU", $v1[0], $m1);
							$date = explode("~",$m1[1][0]);
							foreach($date as $v2)
							{
								//            2011/03/25 (???? 07:30PM
								//echo preg_replace("/[\(\):]/","/",$v2);
								(int)$times = explode("/",
									preg_replace("/[\(\):]/","/",$v2));
								$date = mktime(strlen($times[4])==1?0:(int)$times[4]
									,substr(empty($times[5]) ?0:(int)$times[5],0,2)
									,0,(int)$times[1],(int)$times[2],(int)$times[0]);
								
								//echo (int)strlen($times[4]) . "|" . ((int)substr(empty($times[5])?0:$times[5],0,2)
								//	 .(int)$times[1].(int)$times[2].(int)$times[0])."<br/>";
								break;
							}
							$place = $m1[1][1];
							$regexp = "<div\s[^>]*class=\"??event_detail_description"
								. "[^\" >]*?\"??[^>]*>(.*)"
								. "<div\s[^>]*class=\"??block_standard[^\" >]*?\"??[^>]*>";
							preg_match_all("/$regexp/siU", $v1[0], $m2);
							//print_r($m2);	
							$content = $m2[1][0];
							$this->ci->hbase_model->hbaseinsert($date,'place','place',urlencode($place));
							$this->ci->hbase_model->hbaseinsert($date,'place','content',urlencode($content));

							$nextmin[] = array
								(
									'place'=>$place,
									'content'=>$content,
									'date'=>$date.= "|" . implode("",$times)
									);
						}
						if($iteration % 4 == 1)
						{
						}
						$iteration++;
					}
				}
			}
		}
		return $nextmin;
	}
	function gethtmlparam()
	{
		$data = array(
				'title' => 'Aeil\'s Search Engine',
				'heading' => 'My Heading',
				'message' => 'My Message',
				'url' => base_url()
				);
		return $data;
	}
  
	function queryoptions($content,$c,$p,$v)
	{
		//ex:(apple & pie) | banana
		$pos = FALSE;
		if( $p == 'y')
		{
			mb_internal_encoding('UTF-8');
			//if($t === $k)echo $k;
			//if(mb_ereg_match($content,$v)) 
				//echo "PPP<br/>";
			$pre = explode(" ",$v);
			if($c == 'y')
			{
			foreach($pre as $k)
				if($content === $k)$pos++;
			}
			else
			{
			foreach($pre as $k)
				if(strcasecmp($k,$content)== 0)$pos++;
			}
		}
		else
		{
			$pattern = "/".$content."/";
			$pattern .= $c == 'y' ? "" : "i";
			preg_match_all($pattern,$v,$matches);
			$pos = (count($matches[0]) == 0) ? FALSE : count($matches[0]); 
		}
		return $pos;
	}
    function getData($content,$c,$p)
	{  
		//Query the data table for every record and row  

		//if ($query->num_rows() > 0)  
		//{  
		//	//show_error('Database is empty!');  
		//}else{  
		//	return $query->result();  
		//}  
		$this->load->helper('file');
		$this->load->helper('string');
		$this->load->library('typography');
		$string = explode("@\n",read_file('./record/recode.txt'));
		unset($string[0]);
				//$content = "AEWIN";
		$r = $r1 = Array();
		foreach($string as $s)
		{
			//echo count($s,COUNT_RECURSIVE);
			//print_r($s);
			$match = FALSE;
			$score = 0;
			foreach(preg_split('/\n@/',$s) as $k=>$v)
			{
				$v = preg_replace('/^.{1,2}:/','',$v);
				//echo $v . "<br />";
				$pos = $this->queryoptions($content,$c,$p,$v);
				if ($pos === false) {}
				else
				{
					//echo $k."||".$v."||".$pos;
					$match = TRUE;
					$score += $this->priority[$k] * $pos; 
					//echo $score ."|".$pos."|".$this->priority[$k]. "<br />";
				}
				$r1[$this->pattern[$k]] = preg_replace('/^@\w+:/','',$v);
			}
			if($match)
			{
				//array_push($r,array($r1,$score));
				$r1['score'] = $score;
				$r1['encrypt'] = "";
				foreach($r1 as $e)
				{
					$r1['encrypt'].= "|".$e;
				}
				$r1['encrypt'] = addslashes(
						$this->typography->
						format_characters(str_replace("/","&sl",$r1['encrypt'])));
				//$r1['encrypt'] = $encrypt;//$this->encrypt->encode($r1['encrypt']);
				//echo $r1['encrypt'];
				array_push($r,$r1);
				//$r[] = array($r1,$score);
				//print_r($r);
			}
			
			//echo $this->pattern->cs . "EEE";
			//echo "<pre>";
			//preg_match($content, preg_split('/\n@/',$s), $matches);
//print_r($matches);
			//echo ( array_search($content,preg_split('/\n@/',$s)));
			//print_r ( preg_split('/\n@/',$s));
			//print_r( $s);
			//echo "</pre>";
			//echo  "SSSS";
		}
		if(!empty($r))$this->getsort($r);
		//preg_match_all("/hnol/","T:AEWIN Technologies Co., Ltd.AEWINAEWINAEWINAEWINAEWINAEWINAEWINAEWINAEWIN",$matches);
		//$pre = explode(" ","T:AEWIN Technologies Co., Ltd.AEWINAEWINAEW    INAEWINAEWINAEWINAEWINAEWINAEWIN");
		//$t = "t:aEWIN";
		////print_r($pre);
		//foreach($pre as $k)
		//{
		//	if(strlen($k)>=strlen($t))
		//	{
		//		//echo strcasecmp($k,$t);
		//		//echo "{".strlen($k)."|".strlen($t)."}".substr_compare($k,$t,0,strlen($t),FALSE);
		//	}
		//	//if($t === $k)echo $k;
		//}
		//echo count($matches,COUNT_RECURSIVE) . var_dump($matches) . "EE";
		return $r;
	}  
	function getsort(&$r)
	{
		foreach($r as $k=>$v)
		{
			$orgk[$k] = $k;
			$score[$k] = $v['score'];
		}
		array_multisort($score,SORT_DESC,$orgk,SORT_ASC,$r);
			//echo "<pre>";
		//print_r($r);
		//echo 
		
		//print_r($r);
		
	//echo "</pre>";
	}
  
}  
?>  
Back to Top