]> git.nbdom.net Git - nb.git/commitdiff
Bed
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 15 Jan 2017 01:02:11 +0000 (01:02 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 15 Jan 2017 01:02:11 +0000 (01:02 +0000)
bin/nb-commit
etc/profile.d/functions
etc/profile.d/php.sh
lib/php/cmd.php [new file with mode: 0644]
lib/php/jsmin.php [new file with mode: 0644]
lib/php/nb.php
lib/php/page.php
www/dbq/html/default.min.js
www/dbq/update.sh

index 82f021941a5684866b98c698595ce038d5d04752..b0f4fa2ac18755df2d570943f1462189b9f623e3 100755 (executable)
@@ -10,6 +10,8 @@ set -e
 
 cd $NB_ROOT || exit
 
+shell_replace -i $(grep -rIEl '^\s*.{1,3}SHELL_REPLACE') . /dev/null
+
 for f in www/*/update.sh; do
   [ -x "$f" ] || continue
   $f
index 589add997ba15d7f1b1e3a5e839b33fa317bb932..fe3b9ccb7b775e1b74047f6dcf48922ec0959690 100644 (file)
@@ -736,13 +736,18 @@ while (@_) {
 
 shell_replace() {
   perl -ne '
-if (/^.{1,3}>SHELL_REPLACE (.*)$/ .. /^.{1,3}<SHELL_REPLACE.*/){
+if (/^(\s*).{1,3}>SHELL_REPLACE (.*)$/ .. /^\s*.{1,3}<SHELL_REPLACE.*/){
+  $ch = 1;
+ $idt = $1;
  $i++;
- if    ($i==1 and 0) { print; system($1); }
- if    ($i==1) { print; print `$1`; }
- elsif (/^.{1,3}<SHELL_REPLACE/) { print; }
-} elsif (/^.{1,3}=SHELL_REPLACE (.*)$/) { print; system($1);
-} else {$i=0;print}
+ if    ($i==1) { print; print map{s/^/$idt/;$_} `$2`; }
+ elsif (/^\s*.{1,3}<SHELL_REPLACE/) { print; }
+} elsif (/^(\s*).{1,3}=SHELL_REPLACE (.*)$/) { $idt=$1; <>; print; print map{s/^/$idt/;$_} `$2`; $ch = 1;
+} else {$i=0;print
+}
+END {
+  warn $ARGV if 0 and $INPLACE_EDIT and $ch;
+}
 ' $@
 }
 
index 16f96910ca56a6461a3707cf0cf850a3fd721668..1ecf585c765a500e00518810e8b394914c19dd67 100644 (file)
@@ -9,10 +9,11 @@ php425() {
 
 which php > /dev/null || return 0
 php_check() {
-  php --define error_reporting=22519 --define display_errors=1 --define log_errors=1 --define html_errors=0 $@;
+  #=SHELL_REPLACE echo $(dbq t=mime id=php -cut 3) \$@
+  php --define error_reporting=22519 --define display_errors=1 --define log_errors=1 --define html_errors=0 $@
 }
 
 php_run() {
   local code="$1"; shift
-  php -f $NB_ROOT/lib/php/db.php -r "require '$NB_ROOT/lib/php/page.php';$code;" $@
+  php -r "require '$NB_ROOT/lib/php/cmd.php';$code;" $@
 }
diff --git a/lib/php/cmd.php b/lib/php/cmd.php
new file mode 100644 (file)
index 0000000..aa8926b
--- /dev/null
@@ -0,0 +1,8 @@
+<?php
+require_once(realpath(dirname(__FILE__)).'/config.php');
+require_once(NB_ROOT.'/lib/php/out.php');
+require_once(NB_ROOT.'/lib/php/mime.php');
+require_once(NB_ROOT.'/lib/php/http.php');
+require_once(NB_ROOT.'/lib/php/page.php');
+require_once(NB_ROOT.'/lib/php/db.php');
+?>
diff --git a/lib/php/jsmin.php b/lib/php/jsmin.php
new file mode 100644 (file)
index 0000000..2f3bcc7
--- /dev/null
@@ -0,0 +1,291 @@
+<?php\r
+/**\r
+ * jsmin.php - PHP implementation of Douglas Crockford's JSMin.\r
+ *\r
+ * This is pretty much a direct port of jsmin.c to PHP with just a few\r
+ * PHP-specific performance tweaks. Also, whereas jsmin.c reads from stdin and\r
+ * outputs to stdout, this library accepts a string as input and returns another\r
+ * string as output.\r
+ *\r
+ * PHP 5 or higher is required.\r
+ *\r
+ * Permission is hereby granted to use this version of the library under the\r
+ * same terms as jsmin.c, which has the following license:\r
+ *\r
+ * --\r
+ * Copyright (c) 2002 Douglas Crockford  (www.crockford.com)\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
+ * this software and associated documentation files (the "Software"), to deal in\r
+ * the Software without restriction, including without limitation the rights to\r
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\r
+ * of the Software, and to permit persons to whom the Software is furnished to do\r
+ * so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included in all\r
+ * copies or substantial portions of the Software.\r
+ *\r
+ * The Software shall be used for Good, not Evil.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ * --\r
+ *\r
+ * @package JSMin\r
+ * @author Ryan Grove <ryan@wonko.com>\r
+ * @copyright 2002 Douglas Crockford <douglas@crockford.com> (jsmin.c)\r
+ * @copyright 2008 Ryan Grove <ryan@wonko.com> (PHP port)\r
+ * @license http://opensource.org/licenses/mit-license.php MIT License\r
+ * @version 1.1.1 (2008-03-02)\r
+ * @link http://code.google.com/p/jsmin-php/\r
+ */\r
+\r
+class JSMin {\r
+  const ORD_LF    = 10;\r
+  const ORD_SPACE = 32;\r
+\r
+  protected $a           = '';\r
+  protected $b           = '';\r
+  protected $input       = '';\r
+  protected $inputIndex  = 0;\r
+  protected $inputLength = 0;\r
+  protected $lookAhead   = null;\r
+  protected $output      = '';\r
+\r
+  // -- Public Static Methods --------------------------------------------------\r
+\r
+  public static function minify($js) {\r
+    $jsmin = new JSMin($js);\r
+    return $jsmin->min();\r
+  }\r
+\r
+  // -- Public Instance Methods ------------------------------------------------\r
+\r
+  public function __construct($input) {\r
+    $this->input       = str_replace("\r\n", "\n", $input);\r
+    $this->inputLength = strlen($this->input);\r
+  }\r
+\r
+  // -- Protected Instance Methods ---------------------------------------------\r
+\r
+  protected function action($d) {\r
+    switch($d) {\r
+      case 1:\r
+        $this->output .= $this->a;\r
+\r
+      case 2:\r
+        $this->a = $this->b;\r
+\r
+        if ($this->a === "'" || $this->a === '"') {\r
+          for (;;) {\r
+            $this->output .= $this->a;\r
+            $this->a       = $this->get();\r
+\r
+            if ($this->a === $this->b) {\r
+              break;\r
+            }\r
+\r
+            if (ord($this->a) <= self::ORD_LF) {\r
+              throw new JSMinException('Unterminated string literal.');\r
+            }\r
+\r
+            if ($this->a === '\\') {\r
+              $this->output .= $this->a;\r
+              $this->a       = $this->get();\r
+            }\r
+          }\r
+        }\r
+\r
+      case 3:\r
+        $this->b = $this->next();\r
+\r
+        if ($this->b === '/' && (\r
+            $this->a === '(' || $this->a === ',' || $this->a === '=' ||\r
+            $this->a === ':' || $this->a === '[' || $this->a === '!' ||\r
+            $this->a === '&' || $this->a === '|' || $this->a === '?')) {\r
+\r
+          $this->output .= $this->a . $this->b;\r
+\r
+          for (;;) {\r
+            $this->a = $this->get();\r
+\r
+            if ($this->a === '/') {\r
+              break;\r
+            } elseif ($this->a === '\\') {\r
+              $this->output .= $this->a;\r
+              $this->a       = $this->get();\r
+            } elseif (ord($this->a) <= self::ORD_LF) {\r
+              throw new JSMinException('Unterminated regular expression '.\r
+                  'literal.');\r
+            }\r
+\r
+            $this->output .= $this->a;\r
+          }\r
+\r
+          $this->b = $this->next();\r
+        }\r
+    }\r
+  }\r
+\r
+  protected function get() {\r
+    $c = $this->lookAhead;\r
+    $this->lookAhead = null;\r
+\r
+    if ($c === null) {\r
+      if ($this->inputIndex < $this->inputLength) {\r
+        $c = $this->input[$this->inputIndex];\r
+        $this->inputIndex += 1;\r
+      } else {\r
+        $c = null;\r
+      }\r
+    }\r
+\r
+    if ($c === "\r") {\r
+      return "\n";\r
+    }\r
+\r
+    if ($c === null || $c === "\n" || ord($c) >= self::ORD_SPACE) {\r
+      return $c;\r
+    }\r
+\r
+    return ' ';\r
+  }\r
+\r
+  protected function isAlphaNum($c) {\r
+    return ord($c) > 126 || $c === '\\' || preg_match('/^[\w\$]$/', $c) === 1;\r
+  }\r
+\r
+  protected function min() {\r
+    $this->a = "\n";\r
+    $this->action(3);\r
+\r
+    while ($this->a !== null) {\r
+      switch ($this->a) {\r
+        case ' ':\r
+          if ($this->isAlphaNum($this->b)) {\r
+            $this->action(1);\r
+          } else {\r
+            $this->action(2);\r
+          }\r
+          break;\r
+\r
+        case "\n":\r
+          switch ($this->b) {\r
+            case '{':\r
+            case '[':\r
+            case '(':\r
+            case '+':\r
+            case '-':\r
+              $this->action(1);\r
+              break;\r
+\r
+            case ' ':\r
+              $this->action(3);\r
+              break;\r
+\r
+            default:\r
+              if ($this->isAlphaNum($this->b)) {\r
+                $this->action(1);\r
+              }\r
+              else {\r
+                $this->action(2);\r
+              }\r
+          }\r
+          break;\r
+\r
+        default:\r
+          switch ($this->b) {\r
+            case ' ':\r
+              if ($this->isAlphaNum($this->a)) {\r
+                $this->action(1);\r
+                break;\r
+              }\r
+\r
+              $this->action(3);\r
+              break;\r
+\r
+            case "\n":\r
+              switch ($this->a) {\r
+                case '}':\r
+                case ']':\r
+                case ')':\r
+                case '+':\r
+                case '-':\r
+                case '"':\r
+                case "'":\r
+                  $this->action(1);\r
+                  break;\r
+\r
+                default:\r
+                  if ($this->isAlphaNum($this->a)) {\r
+                    $this->action(1);\r
+                  }\r
+                  else {\r
+                    $this->action(3);\r
+                  }\r
+              }\r
+              break;\r
+\r
+            default:\r
+              $this->action(1);\r
+              break;\r
+          }\r
+      }\r
+    }\r
+\r
+    return $this->output;\r
+  }\r
+\r
+  protected function next() {\r
+    $c = $this->get();\r
+\r
+    if ($c === '/') {\r
+      switch($this->peek()) {\r
+        case '/':\r
+          for (;;) {\r
+            $c = $this->get();\r
+\r
+            if (ord($c) <= self::ORD_LF) {\r
+              return $c;\r
+            }\r
+          }\r
+\r
+        case '*':\r
+          $this->get();\r
+\r
+          for (;;) {\r
+            switch($this->get()) {\r
+              case '*':\r
+                if ($this->peek() === '/') {\r
+                  $this->get();\r
+                  return ' ';\r
+                }\r
+                break;\r
+\r
+              case null:\r
+                throw new JSMinException('Unterminated comment.');\r
+            }\r
+          }\r
+\r
+        default:\r
+          return $c;\r
+      }\r
+    }\r
+\r
+    return $c;\r
+  }\r
+\r
+  protected function peek() {\r
+    $this->lookAhead = $this->get();\r
+    return $this->lookAhead;\r
+  }\r
+}\r
+\r
+// -- Exceptions ---------------------------------------------------------------\r
+class JSMinException extends Exception {}\r
+?>
\ No newline at end of file
index 54749a0dca3c0142939f42e063177c5312df6c62..5ff972aa8589338152ef182b5fda94c649f2eb15 100644 (file)
@@ -911,8 +911,61 @@ class NB {
     return $_txt2md->text($txt);
   }
 
+  public static function minify_js($code) {
+    if (strpos($code,'/') === 0) $code = file_get_contents($code);
+         require_once(NB_ROOT.'/lib/php/jsmin.php');
+               return JSMin::minify($code);
+  }
+
+  public static function minify_css($code) {
+    if (strpos($code,'/') === 0) $code = file_get_contents($code);
+
+    #$code = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $code);
+
+    // comments /* */
+               $code = preg_replace(',/\*.*?\*/,s','',$code);
+
+    // new lines
+               $code = preg_replace('/[\r\n]+/','',$code);
+
+    // spaces
+               #$code = preg_replace('/\s*()\s*/','$1',$code);
+
+    // selectors spaces (eg: "a > p")
+    $code = preg_replace_callback('/(^|\s*\})\s*([^\}]+)\s*(\{)\s*/',function($m){
+
+      array_shift($m);
+      foreach ($m as $k=>$v) {
+        #$m[$k] = str_replace(' ','',$m[$k]);
+        #$m[$k] = trim($m[$k]);
+        $m[$k] = preg_replace('/\s*(\W)\s*/','$1',$m[$k]);
+        #$m[$k] = ':'.$m[$k].':';
+      }
+      #bye($m);
+      #debug($m);
+      return join('',$m);
+    },$code);
+
+    // Property
+    $code = preg_replace_callback('/\s*(\{|;)\s*([\w-]+)\s*(:)\s*/',function($m){
+
+      array_shift($m);
+      return join('',$m);
+      #bye($m);
+      foreach ($m as $k=>$v) {
+        $m[$k] = trim($m[$k]);
+      }
+      return join('',$m);
+    },$code);
+
+    // redudant
+    $code = str_replace(':}','}',$code);
+
+    return $code;
+  }
 } # < Class
 
+/*
 return;
 if (!count($argv) or (string)$argv[1] != 'test') return;
 $value = 'Hello World !';
@@ -926,4 +979,5 @@ echo ''
   ."enc  : $enc\n"
   ."value: ".nb::decrypt($key,$enc) ."\n"
 ;
+*/
 ?>
index 188527a9b16a214eee5bd1021a80e246f4ef258a..7f3230867b3a46518719cc8f70f9269297c29ac3 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-require_once(dirname(__FILE__).'/nb.php');
+require_once(realpath(dirname(__FILE__)).'/nb.php');
 require_once(NB_ROOT.'/lib/php/out.php');
 /*
 if (
index 233488f0db81ec1eb4702ce65405272aa2c0271a..fd7c5029ecfb278f69e62d2f575c4ccdaae8b7bc 100644 (file)
@@ -1,11 +1,3 @@
-/*
-NB 25.12.16: TODEL 
-function form_submit_clean(form) {
-  form_clean(form);
-  form.submit();
-}
-
-*/
 function form_clean(e){var t
 for(i=0;i<e.length;i++)t=e.elements[i],"none"!=t.style.display&&("text"==t.type?t.value="":!t.type.match(/^select/)||"limit"!=t.name&&"format"!=t.name||(t.selectedIndex=0))}function form_submit_clean(e){var t=0,n="",o=e.getAttribute("action"),r=e.getAttribute("method")
 if("get"!=r)return!0
index c017c2988ae1ba2d6d71387c65bfa77cc29c1ed5..894b8c6adedc2a6e77193a0113ff035c9cdc3a70 100755 (executable)
@@ -4,14 +4,14 @@ cd "$(dirname $0)"
 
 if minify -h|grep -qm1 no-comments; then
 
-  alias minify='minify --no-comments'
+  minify='minify --no-comments'
   # NB 14.01.17 # NB 27.12.16
   echo Create html/default.min.css
-  minify -o html/default.min.css html/default.css
+  $minify -o html/default.min.css html/default.css
   echo
   # NB 14.01.17 # NB 27.12.16
   echo Create html/default.min.js
-  minify -o html/default.min.js html/default.js
+  $minify -o html/default.min.js html/default.js
   echo
 
   exit