1: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2: class Model_cache extends CI_Model{
3:
4: public function build_article_cache_gmreader($body,$id){
5: $ref_count = 0;
6: $refences = '';
7: preg_match_all("/<a.*?href=\"([^`]*?)\".*?>([^`]*?)<\/a>/",$body,$ar);
8: $a_tag = $ar[0];
9: $a_href = $ar[1];
10: $a_title = $ar[2];
11: $a_temp = '';
12: $count = 1;
13: for($i = 0; $i < count($a_tag);$i++){
14: $txt = str_replace('&','&',str_replace('’', "'", $a_title[$i]));
15: $txt = htmlentities($txt);
16:
17: if(strpos($a_href[$i], '#')===FALSE){
18: if(strpos($a_href[$i], '/reference/link/')===FALSE){
19: $link_text = $this->db->from('xenon_link_gmreader')->join('xenon_data','xenon_link_gmreader.data_id = xenon_data.data_id')->where('link_id',base64_decode(urldecode($a_href[$i])))->get();
20: if($link_text->num_rows() > 0){
21: $tmp_row = $link_text->row();
22: $a_temp = '<a href="'.$tmp_row->data_id.'">'.$tmp_row->data_title.'</a>';
23: }else{
24: $a_temp = '<span>'.$txt.'</span>';
25: }
26: }else{
27: $link_text = $this->db->from('xenon_link_gmreader')->join('xenon_reference','xenon_link_gmreader.data_id = xenon_reference.refe_id')->where('link_id',base64_decode(urldecode(str_replace('/reference/link/', '',$a_href[$i]))))->get();
28: if($link_text->num_rows() > 0){
29: $tmp_row = $link_text->row();
30: $a_temp = '<a href="'.$tmp_row->refe_id.'" class="reference-transfer" id="'.$count.'">'. $tmp_row->refe_title.'</a>';
31: $count = $count + 1;
32: }else{
33: $a_temp = '<span>'.$txt.'</span>';
34: }
35: }
36: $body = str_replace($a_tag[$i], $a_temp, $body);
37:
38: }
39: }
40: $dom = new DOMDocument();
41: $dom->loadHTML($body);
42:
43: $data['data_body_cache_gmreader'] = substr($dom->saveHTML(),119,-15).($refences!=''?'<div class="ref-container"><h2 class="ref-head">References</h2>'.$refences.'</div>':'');
44: $this->db->where('data_id',$id);
45: $this->db->update('xenon_data',$data);
46: }
47: }
48: ?>