public function update(Mojo $mojo) { $query = $this->_db->prepare(' UPDATE t_mojo SET x=:x,y=:y WHERE id=:id)') or die(print_r($this->_db->errorInfo())); $query->bindValue(':id', $mojo->id()); $query->bindValue(':x', $mojo->x()); $query->bindValue(':y', $mojo->y()); $query->execute(); $query->closeCursor(); }
function promptUser($question, $default) { if (preg_match('/^win/i', PHP_OS)) { $vbscript = sys_get_temp_dir() . 'prompt_password.vbs'; file_put_contents($vbscript, 'wscript.echo(InputBox("' . addslashes($question) . '", "", "' . $default . '"))'); $command = "cscript //nologo " . escapeshellarg($vbscript); $password = rtrim(shell_exec($command)); unlink($vbscript); return $password; } else { echo "\n"; Mojo::prompt($question); return trim(fgets(STDIN)); /* $command = "/usr/bin/env bash -c 'echo OK'"; if (rtrim(shell_exec($command)) !== 'OK') { trigger_error("Can't invoke bash"); return; } $command = "/usr/bin/env bash -c 'read -s -p \"" . addslashes($prompt) . "\" mypassword && echo \$mypassword'"; $password = rtrim(shell_exec($command)); echo "\n"; */ return $password; } }
static function Docs() { Mojo::line(); Mojo::prompt("Welcome to the Mojo Task help documentation..."); Mojo::prompt("Here is the default application syntax:"); Mojo::prompt("\$./mojo [Class] [Method] --param1=(arg1) --param2=(arg2) --param3=(arg3)"); Mojo::line("\n------------------------------------------------\n\n"); Mojo::prompt("CONFIGURATION"); Mojo::line(); Mojo::prompt("\$./mojo Config Setup"); Mojo::prompt("\$./mojo Config Show"); Mojo::prompt("\$./mojo Config Clear"); Mojo::prompt("\$./mojo Config Update"); Mojo::line("\n------------------------------------------------\n\n"); Mojo::prompt("SCAFFOLDING"); Mojo::line(); Mojo::prompt("\$./mojo Controller Scaffold --name='myapp.controller.SampleController' --author='Author' --description='Description'"); Mojo::prompt("@params:"); Mojo::prompt("\tname: name of the module"); Mojo::prompt("\tauthor: author name if not in config"); Mojo::prompt("\tdescription: describe the module"); Mojo::line("\n------------------------------------------------\n\n"); Mojo::prompt("BUILDING / COMPRESSING"); Mojo::line(); Mojo::prompt("\$./mojo Build Compress --overwrite=true --debug=true"); Mojo::prompt("@params:"); Mojo::prompt("\toverwrite - will stop the out put of the build from incrementing"); Mojo::prompt("\tex: mojojsdir/dist/1/application.js will not increment to 2"); Mojo::prompt("\tdebug - will show the list of dependencies"); Mojo::line(); exit; }
static function editStream($args, $stream) { if (empty($args)) { return Mojo::prompt("Cannot edit stream, no args found"); } foreach ($args as $k => $v) { $stream = str_replace("%" . strtoupper($k) . "%", trim($v), $stream); } return (string) $stream; }
function Scaffold() { //Validation if (empty($this->args['name'])) { return Mojo::exception('Provide a full mojo path in your params string, ie: name=mojo.rules.myRules'); } if (strpos($this->args['name'], 'rules.') < 1) { return Mojo::exception('Please use correct rules path, ie: name=mojo.rules.myRules'); } $source = self::Source(); $file = self::makeNewFile($this->args['name'], 'rules'); MojoFile::write($file, MojoFile::editStream($this->args, $source)); Mojo::prompt('Generated Rules Scaffolding to ' . $file); }
function Scaffold() { //Replace this with a validation method if (empty($this->args['name'])) { return Mojo::prompt('Provide a full mojo path in your params string, ie: name=mojo.behavior.myBehavior'); } if (strpos($this->args['name'], 'behavior.') < 1) { return Mojo::prompt('The name you provided for your Behavior appears to be incorrect. ' . 'Please use full Behavior path, ie: name=mojo.behavior.myBehavior'); } $source = self::Source(); $file = self::makeNewFile($this->args['name'], 'behavior'); MojoFile::write($file, MojoFile::editStream($this->args, $source)); Mojo::prompt('Generated Behavior Scaffolding to ' . $file); }
function Scaffold() { //Replace this with a validation method if (empty($this->args['name'])) { return Mojo::prompt('Provide a full mojo path in your params string, ie: name=mojo.controller.myController'); } if (strpos($this->args['name'], 'controller.') < 1) { return Mojo::prompt('The name you provided for your Controller appears to be incorrect. ' . 'Please use full Controller path, ie: name=mojo.controller.myController'); } $source = self::editStream(array('app_name' => MojoConfig::get('mojo_app_name')), self::Source()); $file = self::makeNewFile($this->args['name'], 'controller'); self::write($file, self::editStream($this->args, $source)); Mojo::prompt('Generated Controller Scaffolding to ' . $file); }
function Compress() { global $bc; define('JS_DEBUG', false); include "phpjs/js.php"; $controllers = $rules = $dependencies = array(); $app = isset($this->args['app']) ? $this->args['app'] : ''; $js_dir = explode(DIRECTORY_SEPARATOR, MojoConfig::get('mojo_js_dir')); $js_dir = array_slice($js_dir, 0, count($js_dir) - 2); $js_dir = join(DIRECTORY_SEPARATOR, $js_dir) . DIRECTORY_SEPARATOR; $dependencies = array(); //============================================== //============================================== $base = MojoConfig::get('mojo_' . (!empty($app) ? strtolower(trim($app)) . '_' : '') . 'base_dependencies'); if (isset($base)) { $base = str_replace("/", DIRECTORY_SEPARATOR, $base); $base = explode(',', $base); foreach ($base as $dependent) { $dependencies[] = $js_dir . trim($dependent); } } //============================================== //============================================== $sitemap = MojoConfig::get('mojo_js_dir') . 'SiteMap' . $app . '.js'; $src = file_get_contents($sitemap); jsc::compile($src); //============================================== //============================================== foreach ($bc['.'] as $k => $v) { #print_r($v); if (isset($v[9])) { if (isset($v[9][2][1])) { //controllers $controller = str_replace("'", "", $v[9][2][1]); $controller = $js_dir . join(DIRECTORY_SEPARATOR, explode('.', $controller)) . '.js'; $controllers[] = $controller; if (!array_search($controller, $dependencies)) { $dependencies[] = $controller; } } } if (isset($v[7])) { //sitemap entries if (isset($v[7][2][1])) { //controllers $controller = str_replace("'", "", $v[7][2][1]); $controller = $js_dir . join(DIRECTORY_SEPARATOR, explode('.', $controller)) . '.js'; $controllers[] = $controller; if (!array_search($controller, $dependencies)) { $dependencies[] = $controller; } } if (isset($v[7][6][0][1]) && isset($v[7][6][2][1])) { //rules if ($v[7][6][0][1] == 'formrules') { $rule = str_replace("'", "", $v[7][6][2][1]); $rule = $js_dir . join(DIRECTORY_SEPARATOR, explode('.', $rule)) . '.js'; $rules[] = $rule; } if ($v[7][6][0][1] == 'metricsmap') { $controller = str_replace("'", "", $v[7][6][2][1]); $controller = $js_dir . join(DIRECTORY_SEPARATOR, explode('.', $controller)) . '.js'; $controllers[] = $controller; if (!array_search($controller, $dependencies)) { $dependencies[] = $controller; } } } } } //============================================== //============================================== $locale = !empty($this->args['locale']) ? $this->args['locale'] : 'en_US'; $i18n = MojoFile::getAll(MojoConfig::get('mojo_js_dir') . '_i18n' . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR); foreach ($rules as $rule) { $c = file_get_contents($rule); preg_match_all("/\\.locale[^\"]*\"\\.([^\"]*)\"/", $c, $matches); foreach ($i18n as $files => $file) { $f = $js_dir . MojoConfig::get('mojo_app_name') . DIRECTORY_SEPARATOR . '_i18n' . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . $file; if (strpos($file, $matches[1][0]) > -1 && !array_search($f, $dependencies)) { $dependencies[] = $f; } } if (!array_search($rule, $dependencies)) { $dependencies[] = $rule; } } //============================================== //============================================== foreach ($controllers as $controller) { //commands $c = file_get_contents($controller); preg_match_all("/addCommand[^,]*[^\"']*('|\")([^'\"]*)('|\")/", $c, $matches); foreach ($matches[2] as $commands => $command) { $command = $js_dir . join(DIRECTORY_SEPARATOR, explode('.', $command)) . '.js'; if (!empty($command) && !array_search($command, $dependencies)) { $dependencies[] = $command; } } } //============================================== //=============================================== $js = ""; foreach ($dependencies as $dependency) { $js .= file_get_contents($dependency); } $js = preg_replace('/dojo\\.require\\("[^\\)]+"\\);/i', '', $js); $js = preg_replace("/dojo\\.require\\('[^\\)]+'\\);/i", '', $js); $config = !empty($app) ? $js_dir . MojoConfig::get('mojo_app_name') . '.' . strtolower($app) . '.config.js' : $js_dir . MojoConfig::get('mojo_app_name') . '.config.js'; $js .= file_get_contents($sitemap); $js .= file_get_contents($config); $dependencies[] = $sitemap; $dependencies[] = $config; if (isset($this->args['debug'])) { print_r($dependencies); } //=============================================== //=============================================== $app = !empty($app) ? $app . '.' : 'main.'; $locale = strtolower($locale) . '.'; $build = MojoConfig::get('mojo_build_number'); $build = !empty($build) ? $build : '0'; if (!isset($this->args['overwrite'])) { $build++; } if (!is_dir($js_dir . 'dist' . DIRECTORY_SEPARATOR)) { mkdir($js_dir . 'dist' . DIRECTORY_SEPARATOR); } if (!is_dir($js_dir . 'dist' . DIRECTORY_SEPARATOR . $build . DIRECTORY_SEPARATOR)) { mkdir($js_dir . 'dist' . DIRECTORY_SEPARATOR . $build . DIRECTORY_SEPARATOR); } MojoConfig::set('mojo_build_number', $build); if (MojoFile::write($js_dir . 'dist' . DIRECTORY_SEPARATOR . $build . DIRECTORY_SEPARATOR . 'application.' . $app . $locale . 'uncompressed.js', $js)) { Mojo::prompt('application.' . $app . $locale . 'uncompressed.js written to ' . $js_dir . 'dist' . DIRECTORY_SEPARATOR . $build . DIRECTORY_SEPARATOR . 'application.' . $app . $locale . 'uncompressed.js'); } Mojo::prompt('YUI Compressing application.' . $app . $locale . 'uncompressed.js to ' . $js_dir . 'dist' . DIRECTORY_SEPARATOR . $build . DIRECTORY_SEPARATOR . 'application.' . $app . $locale . 'js'); passthru('java -jar ' . MojoConfig::get('mojo_bin_dir') . 'yui.jar ' . $js_dir . 'dist' . DIRECTORY_SEPARATOR . $build . DIRECTORY_SEPARATOR . 'application.' . $app . $locale . 'uncompressed.js -o ' . $js_dir . 'dist' . DIRECTORY_SEPARATOR . $build . DIRECTORY_SEPARATOR . 'application.' . $app . $locale . 'js --charset UTF-8') . "\n"; if ($this->args['deploy']) { Mojo::prompt('Copying to deploy directory: ' . $js_dir . DIRECTORY_SEPARATOR . $this->args['deploy']); passthru('cp ' . $js_dir . 'dist' . DIRECTORY_SEPARATOR . $build . DIRECTORY_SEPARATOR . 'application.' . $app . $locale . 'js ' . $js_dir . DIRECTORY_SEPARATOR . $this->args['deploy']); } //=============================================== }
public function Show($value = false) { Mojo::line(); Mojo::prompt("Here is your current working configuration: \n"); print_r($_SESSION); echo "\n"; Mojo::prompt("To update a value use \$ mojo Config Update --key=value\n"); }