* bin/nb-stdin
*/
require_once(dirname(__FILE__).'/../lib/php/nb.php');
+
define('USAGE','nb-read.php METHOD_TO_READ_LINES FUNCTION1, FUNCTION2, ... '."\n");
+
define('NAME',$argv[0]); array_shift($argv);
if (!$argv) die(USAGE);
-define('METHOD',$argv[0]); array_shift($argv);
+$METHOD = $argv[0]; array_shift($argv);
$NB = new NB();
while($line = get_line()) {
}
function get_line() {
- global $argv;
+ global $argv, $METHOD;
static $bye;
if (!empty($bye)) return;
- if (METHOD == 'fgets') return fgets(STDIN);
- if (METHOD == 'cat') return file_get_contents(fgets(STDIN));
+ if ($METHOD == 'fgets') return fgets(STDIN);
+# NB 09.12.17 if ($METHOD == 'cat') {
+# NB 09.12.17 $bye = true;
+# NB 09.12.17 $line = fgets(STDIN);
+# NB 09.12.17 return $line ? file_get_contents($line) : $line;
+# NB 09.12.17 }
$bye = true;
- array_unshift($argv,METHOD); # that is not e method, push it back to argv
+ array_unshift($argv,$METHOD); # that is not e method, push it back to argv
+ $METHOD = '';
return stream_get_contents(STDIN);
}
?>
}
this.dump = function (arr,level) {
- var dumped_text = "";
- if(!level) level = 0;
-
- //The padding given at the beginning of the line.
- var level_padding = "";
- for(var j=0;j<level+1;j++) level_padding += " ";
-
- if(typeof(arr) == 'object') { //Array/Hashes/Objects
- for(var item in arr) {
- var value = arr[item];
-
- if(typeof(value) == 'object') { //If it is an array,
- dumped_text += level_padding + "'" + item + "' ...\n";
- dumped_text += dump(value,level+1);
- } else {
- dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
- }
- }
- } else { //Stings/Chars/Numbers etc.
- dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
- }
- return dumped_text;
+ var dumped_text = "";
+ if(!level) level = 0;
+
+ //The padding given at the beginning of the line.
+ var level_padding = "";
+ for(var j=0;j<level+1;j++) level_padding += " ";
+
+ if(typeof(arr) == 'object') { //Array/Hashes/Objects
+ for(var item in arr) {
+ var value = arr[item];
+
+ if(typeof(value) == 'object') { //If it is an array,
+ dumped_text += level_padding + "'" + item + "' ...\n";
+ dumped_text += dump(value,level+1);
+ } else {
+ dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
}
+ }
+ } else { //Stings/Chars/Numbers etc.
+ dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
+ }
+ return dumped_text;
+ }
this.msg = function(msg) {
$('<p>'+msg+'</p>').prependTo( "#nb-msg" );
}
this.reload_head_js = function() {
- $("head script").each(function(){
- var oldScript = this.getAttribute("src");
- $(this).remove();
- var newScript;
- newScript = document.createElement('script');
- newScript.type = 'text/javascript';
- newScript.src = oldScript;
- document.getElementsByTagName("head")[0].appendChild(newScript);
- });
+ $("head script").each(function(){
+ var oldScript = this.getAttribute("src");
+ $(this).remove();
+ var newScript;
+ newScript = document.createElement('script');
+ newScript.type = 'text/javascript';
+ newScript.src = oldScript;
+ document.getElementsByTagName("head")[0].appendChild(newScript);
+ });
}
// <<< FUNCTIONS
}
public static function minify_js($code) {
- if (strpos($code,'/') === 0) $code = file_get_contents($code);
+ if (strpos($code,'/') === 0 and file_exists($code)) $code = file_get_contents($code);
require_once(NB_ROOT.'/lib/php/jsmin.php');
return trim(JSMin::minify($code));
}
public static function minify_css($code) {
- if (strpos($code,'/') === 0) $code = file_get_contents($code);
-
- #$code = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $code);
+ if (strpos($code,'/') === 0 and file_exists($code)) $code = file_get_contents($code);
// comments /* */
$code = preg_replace(',/\*.*?\*/,s','',$code);
}
#debug($_SERVER);
- if ($this->http_user()) $bottom[] = '<a href="/logout">Logout: '.$this->http_user().' ('.$this->perm2h().')'.'</a>';
+ if ($this->http_user()) $bottom[] = '<a href="/logout">Logout: '.$this->http_user().' (can: '.$this->perm2h().')'.'</a>';
if ($bottom and $this->page->is('html')) echo $this->page->tag('div class="block" style="display:inline-block"',join('<br />'.NB_EOL,$bottom));
echo "Minify "$( ( realpath "$f" 2> /dev/null || echo "$f" ) | sed "s,^$NB_ROOT/,," )
- eval minify --$ext < "$f" > "$min.bak" && mv "$min.bak" "$min"
+ eval minify --$ext < "$f" > "$min.new" && mv "$min.new" "$min"
+ #nb-read.php minify_$ext < "$f" > "$min.new"
+ #[ -t "$min.new" ] && diff -q "$"$min.new"" "$min" &> /dev/null && mv "$min.new" "$min" || rm $min.new"
[ "$?" = "0" ] || ex=1
#git add "$min"
#[ "$ex" = "0" ] && echo DEBUG: Should: git add "$min"