1: <?php
2:
3: function reference_reverter(){
4: $all_nodes = $this->db->from('xenon_data')->where('data_id in (select distinct data_id from xenon_reference_data)')->get();
5: foreach($all_nodes->result() as $article){
6: $dom = new DOMDocument();
7: $dom->loadHTML(html_entity_decode(mb_convert_encoding($article->data_body,"HTML-ENTITIES","UTF-8")));
8: $a_tags = $dom->getElementsByTagName('a');
9: foreach ($a_tags as $a_tag) {
10: $txt = iconv("UTF-8", "ISO-8859-1",str_replace('&','&',str_replace('’', "'", $a_tag->nodeValue)));
11: if($a_tag->getAttribute('class') == 'reference'){
12: $refe_id = $this->db->select('refe_id')->from('xenon_reference_data')->where('data_id',$article->data_id)->where('row_num',substr($txt, 1))->get()->row()->refe_id;
13: $refe_hr = $this->db->select('refe_link')->from('xenon_reference')->where('refe_id',$refe_id)->get()->row()->refe_link;
14: $link = $dom->createElement('a',"references");
15: $link->setAttribute('href', $refe_hr);
16: $link->setAttribute('class','blueref');
17: $a_tag->parentNode->replaceChild($link, $a_tag);
18: }
19: }
20: $data_final['data_body'] = substr($dom->saveHTML(),119,-15);
21: $this->db->where('data_id',$article->data_id);
22: $this->db->update('xenon_data',$data_final);
23: }
24: }
25:
26: function link_extractor(){
27: $all_nodes = $this->db->from('xenon_data')->limit(1500)->get();
28:
29: foreach($all_nodes->result() as $article){
30: echo $article->data_id.'::<a target="_blank" href="http://admin.greenmedicineworks.com/article/edit/'.urlencode(base64_encode($article->data_id)).'">'.urlencode(base64_encode($article->data_id)).'</a><br />';
31:
32: $dom = new DOMDocument();
33: $dom->loadHTML(html_entity_decode(mb_convert_encoding($article->data_body,"HTML-ENTITIES","UTF-8")));
34: $a_tags = $dom->getElementsByTagName('a');
35: foreach ($a_tags as $a_tag) {
36: $txt = str_replace('&','&',str_replace('’', "'", $a_tag->nodeValue));
37: $txt = htmlentities($txt);
38: echo $txt.'<br />';
39: $data['link_text'] = $txt;
40: $data['link_class'] = $a_tag->getAttribute('class');
41: $data['link_href'] = $a_tag->getAttribute('href');
42: $data_get = $this->db->from('xenon_link')->where('link_text',$txt)->where('link_href',$a_tag->getAttribute('href'))->get();
43: if($data_get->num_rows() == 0){
44: $this->db->insert('xenon_link',$data);
45: $id_main = $this->db->insert_id();
46: $id_enc = urlencode(base64_encode($id_main));
47: if($this->db->from('xenon_data_links')->where('link_id',$id_main)->where('data_id',$article->data_id)->get()->num_rows() == 0){
48: $data_link['link_id'] = $id_main;
49: $data_link['data_id'] = $article->data_id;
50: $this->db->insert('xenon_data_links',$data_link);
51: }
52: $link = $dom->createElement('a',$txt);
53: $link->setAttribute('href', $id_enc);
54: $a_tag->parentNode->replaceChild($link, $a_tag);
55:
56: }else{
57: $id_main = $data_get->row()->link_id;
58: $id_enc = urlencode(base64_encode($id_main));
59: if($this->db->from('xenon_data_links')->where('link_id',$id_main)->where('data_id',$article->data_id)->get()->num_rows() == 0){
60: $data_link['link_id'] = $id_main;
61: $data_link['data_id'] = $article->data_id;
62: $this->db->insert('xenon_data_links',$data_link);
63: }
64: $link = $dom->createElement('a',$txt);
65: $link->setAttribute('href', $id_enc);
66: $a_tag->parentNode->replaceChild($link, $a_tag);
67: }
68: }
69: $data_final['data_body_temp'] = substr($dom->saveHTML(),119,-15);
70: $this->db->where('data_id',$article->data_id);
71: $this->db->update('xenon_data',$data_final);
72: }
73: }
74:
75:
76: 77: 78: 79:
80:
81:
82:
83:
84:
85: function file_get_html($url, $use_include_path = false, $context=null, $offset = -1, $maxLen=-1, $lowercase = true, $forceTagsClosed=true, $target_charset = DEFAULT_TARGET_CHARSET, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT)
86: {
87:
88: $dom = new simple_html_dom(null, $lowercase, $forceTagsClosed, $target_charset, $stripRN, $defaultBRText, $defaultSpanText);
89:
90: $contents = file_get_contents($url, $use_include_path, $context, $offset);
91:
92:
93: if (empty($contents) || strlen($contents) > MAX_FILE_SIZE)
94: {
95: return false;
96: }
97:
98: $dom->load($contents, $lowercase, $stripRN);
99: return $dom;
100: }
101:
102:
103: function str_get_html($str, $lowercase=true, $forceTagsClosed=true, $target_charset = DEFAULT_TARGET_CHARSET, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT)
104: {
105: $dom = new simple_html_dom(null, $lowercase, $forceTagsClosed, $target_charset, $stripRN, $defaultBRText, $defaultSpanText);
106: if (empty($str) || strlen($str) > MAX_FILE_SIZE)
107: {
108: $dom->clear();
109: return false;
110: }
111: $dom->load($str, $lowercase, $stripRN);
112: return $dom;
113: }
114:
115:
116: function dump_html_tree($node, $show_attr=true, $deep=0)
117: {
118: $node->dump($node);
119: }
120:
121:
122: