]> git.nbdom.net Git - nb.git/commitdiff
www/dbq/dbq.php
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Fri, 8 Jun 2018 13:13:03 +0000 (14:13 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Fri, 8 Jun 2018 13:13:03 +0000 (14:13 +0100)
lib/php/mime.php
lib/postgres/category.sql [new file with mode: 0644]
www/dbq/dbq.php

index 0633b0d7f32e29ce9fa5ff7fcf1df61b8a5bf7d4..11e0c1062ad607e59171ea4e2cd7383f76c2627a 100644 (file)
@@ -729,46 +729,107 @@ class Mime {
                return $m[1];
        }
 
-       public static function html_youtube_embed($str) {
-               static $init = '';
+       public static function html_video($str) {
+
+               $sites = [
+                       'dtube' => [
+                                       'exp'  => '(d.tube/#!/v/[^/]+/[^/\?\s]+)',
+                                       'html' => '<iframe class="video"'
+                                               .' type="text/html"'
+                                               .' src="<SRC>"'
+                                               .' frameborder="0"'
+                                               .' allowfullscreen'
+                                       .'></iframe>',
+                       ],
+                       'hooktube' => [
+                                       'exp'  => 'hooktube.com/watch\?v=([^&\s]+)',
+                                       'html' => '<iframe class="video"'
+                                               .' type="text/html"'
+                                               .' src="//hooktube.com/embed/<SRC>?enablejsapi=1"'
+                                               .' frameborder="0"'
+                                               .' allowfullscreen'
+                                       .'></iframe>',
+                       ],
+                       'youtube' => [
+                                       'exp'  => 'www.youtube.com/watch\?v=([^&\s]+)',
+                                       'html' => '<iframe class="video"'
+                                               .' type="text/html"'
+                                               .' src="//www.youtube.com/embed/<SRC>?enablejsapi=1"'
+                                               .' frameborder="0"'
+                                               .' allowfullscreen'
+                                       .'></iframe>',
+                       ],
+               ];
+
+               foreach ($sites as $k => $site) {
+                       if (!preg_match(','.$site['exp'].',',$str,$m)) continue;
+                       $id = $m[1];
+                       $idsite = $k;
+                       break;
+               }
+
+               if (empty($id)) return;
+
+               static $already_init;
+               if (empty($already_init)) {
+
+                       $init = '<script type="text/javascript"><!-- '."\n";
+                       $init .= 'var html_video = [];';
+                       $init .= 'var html_video_e = document.createElement("div");';
+
+                       foreach ($sites as $k => $site) {
+                               $init .= ''
+                                       . 'html_video_e.innerHTML = "' . htmlentities($site['html']) . '";'
+                                       . 'html_video["'.$k.'"] = html_video_e.childNodes.length === 0 ? "" : html_video_e.childNodes[0].nodeValue;'
+                               ;
+                       }
+
+      $init .= "\n".' --></script>';
+
+                       $already_init = true;
+
+               } else {
+                       $init = '';
+
+               }
+
+               return $init
+                       . '<a class="video" href="#"'
+                       .' onclick="this.outerHTML=html_video[\''.$idsite.'\'].replace(\'<SRC>\',\''.$id.'\')"'
+               .'>'.$str.'</a>';
+
                $id = '';
                if (!preg_match(',//www.youtube.com/watch\?v=([^&\s]+),',$str,$m)) return $str;
                $id = $m[1];
+
                $iframe = ''
-               #.'<details>'
                .'<iframe'
                        .' class="video"'
                        .' type="text/html"'
                        .' src="//www.youtube.com/embed/<ID>?enablejsapi=1"'
                        .' frameborder="0"'
                .'></iframe>'
-               #.'<details>'
                ;
+
+               static $init = '';
                if (empty($init)) {
                        $init = ''
         . '<script type="text/javascript"><!-- '."\n"
-        . 'var html_youtube_embed = document.createElement("div");'
-                               . 'html_youtube_embed.innerHTML = "' . htmlentities($iframe) . '";'
-        #. 'var html_youtube_embed = "' . str_replace('"','\\"',htmlentities($iframe)) . '";'
-                               . 'html_youtube_embed = html_youtube_embed.childNodes.length === 0 ? "" : html_youtube_embed.childNodes[0].nodeValue;'
+        . 'var html_video = document.createElement("div");'
+                               . 'html_video.innerHTML = "' . htmlentities($iframe) . '";'
+        #. 'var html_video = "' . str_replace('"','\\"',htmlentities($iframe)) . '";'
+                               . 'html_video = html_video.childNodes.length === 0 ? "" : html_video.childNodes[0].nodeValue;'
         . "\n".' --></script>'
                        ;
                }
+
                return $init
                        . '<a class="video" href="#"'
-                       .' onclick="this.outerHTML=html_youtube_embed.replace(\'<ID>\',\''.$id.'\')"'
+                       .' onclick="this.outerHTML=html_video.replace(\'<ID>\',\''.$id.'\')"'
                .'>'.$str.'</a>';
+
                $iframe = str_replace('<ID>',$id,$iframe);
-               return $init.$iframe;
-               return ''
-               #.'<a target="_blank" href="//www.youtube.com/v/'.$id.'?color2=FBE9EC&amp;version=3">'
-               .'<object type="application/x-shockwave-flash" class="video" data="//www.youtube.com/v/'.$id.'?color2=FBE9EC&amp;version=3">'
-                       .'<param name="movie" value="//www.youtube.com/v/'.$id.'?color2=FBE9EC&amp;version=3" />'
-                       .'<param name="allowFullScreen" value="true" />'
-                       .'<param name="allowscriptaccess" value="always" />'
-               .'</object>'
-               #.'</a>'
-               ;
+
        }
 
        public static function html_img_data($str) {
@@ -790,7 +851,7 @@ class Mime {
                if ($mime === null) $mime = self::getContent($str);
 
                if ($mime == 'text/plain') {
-                       if (preg_match(',//www.youtube.com/watch\?v=,',$str)) return self::html_youtube_embed($str);
+                       if ($v = self::html_video($str)) return $v;
 
                } elseif (preg_match('@^image/@',$mime)) {
                        return self::html_img_data($str);
diff --git a/lib/postgres/category.sql b/lib/postgres/category.sql
new file mode 100644 (file)
index 0000000..99af02d
--- /dev/null
@@ -0,0 +1,6 @@
+-- DROP TABLE IF EXISTS category;
+CREATE TABLE IF NOT EXISTS category (
+       id serial PRIMARY KEY,
+       name varchar(60),
+       description varchar(2000)
+);
index f1e69e9c0503ff07ba54c689560643f5d2f2e368..8ba5bfbee7a695bf235396b4160d04acbc8eff6e 100644 (file)
@@ -1129,6 +1129,11 @@ EOF;
                $action = $this->params['db'];
                if (!$action and self::PARAM_DB_DEFAULT) $action = self::PARAM_DB_DEFAULT;
                #$this->params = [ 'action' => $action ];
+               #bye($this->params);
+               $arg = join('/',[$this->params['table'],$this->params['action'],$this->params['args']]);
+               $arg = [];
+               foreach (['table','action','args'] as $k) { if (!empty($this->params[$k])) $arg[] = $this->params[$k]; }
+               $arg = join('/',$arg);
 
                if ($action == 'help') {
                        $this->page($this->db,[
@@ -1174,6 +1179,9 @@ EOF;
                } elseif ($action == 'cryptkey') { $this->page($this->cryptkey());
                } elseif ($action == 'status') { $this->page($this,'status');
                } elseif ($action == 'conf') { $this->page($this,'conf');
+               } elseif ($action == 'conf') { $this->page($this,'conf');
+               #} elseif ($action == 'html_video') { $this->page($arg);
+               } elseif ($action == 'html_video') { $this->page(Mime::html_video($arg));
                } elseif ($action == 'types') {
                        $types = [];
                        foreach (array_keys($this->db->out->types()) as $type) {
@@ -1402,6 +1410,9 @@ EOF;
        }
 
 } # < Class Dbq
+#die($_SERVER['REQUEST_URI']."\n");
+#die($_SERVER['QUERY_STRING']."\n");
+#phpinfo(); exit;
 $DBQ = new DbQ([
        'run' => true,
        'base' => (($base = Dbq::client_header('Dbq-Base')) ?  preg_replace(',/+$,','',$base) : ''),