comment + link extraction
[stapibas.git] / src / stapibas / Content / Extractor.php
index 0ede38959bc007d4c33d1f2e907d34cdc85af91e..c54344be9f7705bb79a2d020e02a39b91ed7de6d 100644 (file)
@@ -46,7 +46,19 @@ class Content_Extractor
             $doc->loadHTML($contentRow->pc_fulltext);
         }
 
-        //FIXME: delete old content
+        //delete old content
+        $this->db->exec(
+            'DELETE FROM rboomarks WHERE'
+            . ' rb_pc_id = ' . $this->db->quote($contentRow->pc_id)
+        );
+        $this->db->exec(
+            'DELETE FROM rcomments WHERE'
+            . ' rc_pc_id = ' . $this->db->quote($contentRow->pc_id)
+        );
+        $this->db->exec(
+            'DELETE FROM rlinks WHERE'
+            . ' rl_pc_id = ' . $this->db->quote($contentRow->pc_id)
+        );
 
         $ce = new Content_Extractor_Comment($this->deps->log);
         $data = $ce->extract($doc, $contentRow->p_source, $contentRow->p_target);
@@ -67,7 +79,29 @@ class Content_Extractor
             );
             return;
         }
-        //FIXME: bookmark, link
+
+        //FIXME: bookmark
+
+        $ce = new Content_Extractor_Link($this->deps->log);
+        $data = $ce->extract($doc, $contentRow->p_source, $contentRow->p_target);
+        if ($data !== null) {
+            $this->log->info('Link found');
+            var_dump($data);
+            $this->db->exec(
+                'INSERT INTO rlinks SET'
+                . '  rl_pc_id = ' . $this->db->quote($contentRow->pc_id)
+                . ', rl_source = ' . $this->db->quote($contentRow->p_source)
+                . ', rl_target = ' . $this->db->quote($contentRow->p_target)
+                . ', rl_title = ' . $this->db->quote($data['title'])
+                . ', rl_author_name = ' . $this->db->quote($data['author_name'])
+                . ', rl_author_url = ' . $this->db->quote($data['author_url'])
+                . ', rl_author_image = ' . $this->db->quote($data['author_image'])
+                . ', rc_updated = NOW()'
+            );
+            return;
+        }
+
+        $this->log->info('Nothing found');
     }