sync
authorBlastytheBlue <blastofmn@gmail.com>
Wed, 17 Dec 2014 09:51:21 +0000 (17:51 +0800)
committerBlastytheBlue <blastofmn@gmail.com>
Wed, 17 Dec 2014 09:51:21 +0000 (17:51 +0800)
Pman/Reddit/DataObjects/Reddit_livefeed_embed.php
Pman/Reddit/DataObjects/reddit.sql
Reddit/ImportEmbed.php

index 85f833d..e14d6f2 100644 (file)
@@ -18,11 +18,62 @@ class Pman_Reddit_DataObjects_Reddit_livefeed_embed extends DB_DataObject
     public $frame_width;                   // int(11)
     public $frame_height;                  // int(11)
     public $frame_style;                   // TEXT
-    public $frame_body;                    // TEXT
+    public $frame_body;                    // LONGTEXT
+    public $frame_body_clean;              // LONGTEXT
     
     
     /* the code above is auto generated do not remove the tag below */
     ###END_AUTOCODE
+    function convertClean(){
+        $data = $this->frame_body;
+        libxml_use_internal_errors (true);
+        $doc = new DOMDocument();
+        $doc->loadHTML($data);
+        //$doc->loadHTML($data);
+        $xpath = new DOMXpath($doc);
+    }
+    function createAssets(){
+        $data = $this->frame_body;
+        libxml_use_internal_errors (true);
+        $doc = new DOMDocument();
+        $doc->loadHTML($data);
+        //$doc->loadHTML($data);
+        $xpath = new DOMXpath($doc);
+        
+        foreach($xpath->query('//link') as $l){
+            $url=parse_url($l->getAttribute("href"));
+            echo print_r($url);
+            $file = '/home/reddit/assets/'. $url["host"] . $url["path"];
+            if(file_exists($file)){
+                echo "file exists already.\n";
+                continue;
+            }
+            $dir = dirname($file);
+            if(!file_exists($dir)){
+                echo "Made directory: ".$dir . "\n";
+                mkdir($dir,0775,true);
+            }
+            file_put_contents($file,file_get_contents($l->getAttribute("href")));
+        }
+        
+        $x=0;
+        foreach($xpath->query('//img') as $im){
+            echo "\$x=".$x++."\n";
+            $url=parse_url($im->getAttribute("src"));
+            echo "\n\n".print_r($im->getAttribute("src"))."\n\n";
+            $file = '/home/reddit/assets/'. $url["host"] . $url["path"];
+            if(file_exists($file)){
+                echo "file exists already.";
+                continue;
+            }
+            $dir = dirname($file);
+            if(!file_exists($dir)){
+                echo "Made directory: ".$dir . "\n";
+                mkdir($dir,0775,true);
+            }
+            file_put_contents($file,file_get_contents($im->getAttribute("src")));
+        }
+    }
     function convertHTML(){
         //var_dump($url);
         
index e9958e4..7013b05 100644 (file)
@@ -25,5 +25,6 @@ alter table reddit_livefeed add column last_uid varchar(64) not null default '';
   frame_height int(11) NOT NULL DEFAULT '0',
   frame_style text,
   frame_body longtext,
+  frame_body_clean longtext,
   PRIMARY KEY (id)
 ) 
\ No newline at end of file
index f1604c0..7499ea7 100644 (file)
@@ -30,7 +30,8 @@ class Reddit_ImportEmbed extends Pman {
         $dd->find();
         while ($dd->fetch()) {
             //$dd->fetchEmbed();
-            $dd->convertHTML();
+            //$dd->convertHTML();
+            $dd->createAssets();
         }
         
         exit;