Ejemplo n.º 1
0
 public function stimulate(&$hash)
 {
     $db = new MYSQL();
     $db->connect(self::DB_HOST, self::DB_USER, self::DB_PASS, self::DB_DBNAME);
     @mysql_query("SET NAMES 'UTF8'");
     //must have a string parameter 'action'
     LINB::checkArgs($hash, array('string' => array('action' => NULL)));
     //handle the process
     switch ($hash->action) {
         case 'getlist':
             return $db->query("select `key`,`value` from `tbl_test`");
         case 'update':
             //must have string parameters 'key' and 'value'
             LINB::checkArgs($hash, array('string' => array('key' => NULL, 'value' => NULL)));
             $db->update("tbl_test", array("key" => $hash->key, "value" => $hash->value), "`key`='" . $hash->key . "'");
             return 'ok';
         case 'delete':
             //must have a string parameter 'key'
             LINB::checkArgs($hash, array('string' => array('key' => NULL)));
             $db->delete("tbl_test", "`key`='" . $hash->key . "'");
             return 'ok';
         case 'create':
             //must have string parameters 'key' and 'value'
             LINB::checkArgs($hash, array('string' => array('key' => NULL, 'value' => NULL)));
             $db->insert("tbl_test", array("key" => $hash->key, "value" => $hash->value));
             return 'ok';
     }
 }
Ejemplo n.º 2
0
 public function stimulate(&$hash)
 {
     //if request obj doesnt inlucde p1, server will return  'server_set1'
     LINB::checkArgs($hash, array('string' => array('p1' => 'server_set', 'p2' => 'server_set')));
     $hash->time = date("Y-m-d H:i:s", time());
     $hash->rand = $this->randString();
     return array($hash);
 }
Ejemplo n.º 3
0
 public function stimulate(&$hash)
 {
     LINB::checkArgs($hash, array('string' => array('action' => NULL)));
     $r = NULL;
     //only input relative path, and not ./ or ../ allowed
     switch ($hash->action) {
         case 'getWizardTypeList':
             $path = self::TPL_PATH . DIRECTORY_SEPARATOR . self::PACKAGE_PATH;
             $path = str_replace("/", "\\", $path);
             $r = $this->getFiles($path);
             break;
         case 'getWizardList':
             LINB::checkArgs($hash, array('string' => array('path' => NULL)));
             $path = self::TPL_PATH . DIRECTORY_SEPARATOR . self::PACKAGE_PATH . DIRECTORY_SEPARATOR . $hash->path;
             $r = $this->getFiles($path);
             break;
         case 'buildWizard':
             LINB::checkArgs($hash, array('string' => array('path' => ''), 'object' => array('paras' => NULL)));
             $path = NULL;
             if ($hash->path) {
                 $path = self::TPL_PATH . DIRECTORY_SEPARATOR . self::PACKAGE_PATH . DIRECTORY_SEPARATOR . $hash->path . DIRECTORY_SEPARATOR . self::BUILD_FILENAME;
             } else {
                 $path = self::TPL_PATH . DIRECTORY_SEPARATOR . self::BUILD_FILENAME;
             }
             $paras = $hash->paras;
             try {
                 if (file_exists($path)) {
                     include_once $path;
                     if (class_exists('WizardBuilder')) {
                         $ins = new WizardBuilder();
                         $path = $ins->buildApp($paras);
                         $r = $this->getFiles($path, -1, 0);
                     } else {
                         throw new LINB_E("Class 'WizardBuilder' could not be found.");
                     }
                 } else {
                     throw new LINB_E("File {$path} could not be found.");
                 }
             } catch (LINB_E $e) {
                 throw new LINB_E($e->getMessage(), $e->getCode());
             }
             break;
     }
     return $r;
 }
Ejemplo n.º 4
0
 public function stimulate(&$hash)
 {
     $db = new MYSQL();
     $db->connect(self::DB_HOST, self::DB_USER, self::DB_PASS);
     @mysql_query("SET NAMES 'UTF8'");
     //must have a string parameter 'action'
     LINB::checkArgs($hash, array('string' => array('action' => NULL)));
     //handle the process
     switch ($hash->action) {
         case 'listdbs':
             return $db->listdbs();
         case 'listtables':
             LINB::checkArgs($hash, array('string' => array('dbname' => NULL)));
             return $db->listtables($hash->dbname);
         case 'list':
             LINB::checkArgs($hash, array('string' => array('dbname' => NULL, 'tablename' => NULL, 'page' => 1, 'count' => 20)));
             $db->selectdb($hash->dbname);
             $count = $db->query("select count(*) from " . $hash->tablename);
             $table = $db->query("select * from " . $hash->tablename . " where 1 limit " . ($hash->page - 1) * 20 . ", " . $hash->count, true);
             return array($count, $table);
     }
 }
Ejemplo n.º 5
0
 public function buildApp($hash)
 {
     LINB::checkArgs($hash, array('string' => array('pathName' => NULL, 'className' => NULL)));
     $io = LINB::SC('IO');
     $prjpath = self::PROJECTS_PATH . DIRECTORY_SEPARATOR . $hash->pathName;
     //replace exists project file
     $path = $prjpath;
     if ($io->exists($path)) {
         throw new LINB_E("{$path} exists already!");
     }
     //$io->delete($path);
     $io->dirMake($path, true);
     $template = $io->getString(self::TEMPLATE_HTML);
     //html page file
     file_put_contents($path . DIRECTORY_SEPARATOR . self::INDEX . self::FILE_HTML, LINB::parseTemplate($template, $hash));
     $template = $io->getString(self::TEMPLATE_DEBUG);
     //html page file
     file_put_contents($path . DIRECTORY_SEPARATOR . self::DEBUG . self::FILE_HTML, LINB::parseTemplate($template, $hash));
     //img path
     $io->dirMake($path . DIRECTORY_SEPARATOR . self::IMG_PATH, true);
     $rpath = $path;
     //base class path
     $path = $rpath . DIRECTORY_SEPARATOR . $hash->className;
     $io->dirMake($path, true);
     //js path
     $path = $path . DIRECTORY_SEPARATOR . self::JS_PATH;
     $io->dirMake($path, true);
     $template = $io->getString(self::TEMPLATE_JS);
     // js class file
     file_put_contents($path . DIRECTORY_SEPARATOR . self::INDEX . self::FILE_JS, LINB::parseTemplate($template, $hash));
     $path = $rpath . DIRECTORY_SEPARATOR . self::LOCATE_PATH;
     //lang path
     $io->dirMake($path, true);
     $io->setString($path . DIRECTORY_SEPARATOR . self::EN_PATH, '{}');
     unset($io);
     return $prjpath;
 }
Ejemplo n.º 6
0
 public function stimulate(&$hash)
 {
     LINB::checkArgs($hash, array('string' => array('action' => 'open', 'path' => 'linbApp', 'className' => 'App', 'content' => '', 'theme' => 'default', 'lang' => 'en')));
     $io = LINB::SC('IO');
     //only input relative path, and not ./ or ../ allowed
     switch ($hash->action) {
         case 'fetchwebfile':
             $content = file_get_contents($hash->path);
             if ($content !== false) {
                 return $content;
             } else {
                 throw new LINB_E("Error: Can\\'t get " . $hash->path);
             }
             break;
         case 'downloadjs':
             header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
             header("Cache-Control: private", false);
             header("Content-Description: File Transfer");
             header("Content-Type: application/force-download");
             header("Accept-Ranges: bytes");
             header("Content-Disposition: attachment; filename=\"jsLinb.Class.js\";");
             header("Content-Transfer-Encoding: binary");
             header("Content-Length: " . strlen($hash->content));
             header("Pragma: public");
             header("Expires: 0");
             echo $hash->content;
             return;
             break;
         case 'downloadhtml':
             $template = $io->getString(self::TEMPLATE_SINHTML);
             $template = LINB::parseTemplate($template, array("libpath" => "http://jslinb.appspot.com/", "clsName" => $hash->clsName, "content" => $hash->content, "theme" => $hash->theme, "lang" => $hash->lang));
             header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
             header("Cache-Control: private", false);
             header("Content-Description: File Transfer");
             header("Content-Type: application/force-download");
             header("Accept-Ranges: bytes");
             header("Content-Disposition: attachment; filename=\"linbApp.html\";");
             header("Content-Transfer-Encoding: binary");
             header("Content-Length: " . strlen($template));
             header("Pragma: public");
             header("Expires: 0");
             echo $template;
             return;
             break;
         case 'downloadzip2':
             $zip = new zip();
             $fileName = 'jsLinbApp.zip';
             $rootName = 'runtime';
             $path = self::BASE_PATH;
             $path2 = 'index.html';
             $template = $io->getString(self::TEMPLATE_SINHTML);
             $template = LINB::parseTemplate($template, array("libpath" => "", "clsName" => $hash->clsName, "content" => $hash->content, "theme" => $hash->theme, "lang" => $hash->lang));
             $zip->addFile($template, $path2);
             $path2 = $rootName . DIRECTORY_SEPARATOR . 'loading.gif';
             $f = file_get_contents($path . DIRECTORY_SEPARATOR . $path2);
             $zip->addFile($f, $path2);
             $path2 = $rootName . DIRECTORY_SEPARATOR . 'addBuilderLink.js';
             $f = file_get_contents($path . DIRECTORY_SEPARATOR . $path2);
             $zip->addFile($f, $path2);
             $io->_zip($path, $rootName . DIRECTORY_SEPARATOR . 'jsLinb' . DIRECTORY_SEPARATOR . 'Locale', $zip);
             $io->_zip($path, $rootName . DIRECTORY_SEPARATOR . 'jsLinb' . DIRECTORY_SEPARATOR . 'appearance', $zip);
             $path2 = $rootName . DIRECTORY_SEPARATOR . 'jsLinb' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'linb-all.js';
             $f = file_get_contents($path . DIRECTORY_SEPARATOR . $path2);
             $zip->addFile($f, $path2);
             $fd = fopen($fileName, "wb");
             $out = fwrite($fd, $zip->getZippedfile());
             fclose($fd);
             $zip->forceDownload($fileName);
             @unlink($fileName);
             return;
             break;
         case 'savetoserver':
             $io->setString($hash->path, $hash->content);
             return array('OK' => true);
             //throw new LINB_E("You cant save file to this server!");
             break;
         case 'del':
             foreach ($hash->path as $v) {
                 $io->delete($v);
             }
             return array('OK' => true);
             break;
         case 'add':
             $file = $hash->path;
             if ($hash->type == 'file') {
                 $file = $hash->path . '/' . $hash->filename;
             }
             if ($io->exists($io->absPath($file))) {
                 throw new LINB_E("'{$file}' exists!");
             }
             if (!$io->exists($hash->path)) {
                 $io->dirMake($hash->path, true);
             }
             if ($hash->type == 'file') {
                 $template = " ";
                 if (substr($file, -3, 3) == self::FILE_JS) {
                     $className = "==>specify_class_name_here";
                     try {
                         // Get js class name
                         $farr = explode('/js/', $file);
                         if (isset($farr[0])) {
                             $farr1 = explode('/', $farr[0]);
                             if (isset($farr[1])) {
                                 $farr2 = explode(".", $farr[1]);
                                 if (isset($farr2[0])) {
                                     $className = $farr1[sizeof($farr1) - 1] . '.' . implode('.', explode('/', $farr2[0]));
                                 }
                             }
                         }
                     } catch (Exception $e) {
                     }
                     $template = $io->getString(self::TEMPLATE_JS);
                     $template = LINB::parseTemplate($template, array("className" => $className));
                 }
                 $io->setString($io->absPath($file), $template);
             }
             return array('OK' => true);
             break;
         case 'save':
             $io->setString($hash->path, $hash->content);
             return array('OK' => true);
             break;
         case 'getfile':
             return array('file' => $io->getString($hash->path));
             break;
         case 'open':
             $prjpath = $hash->path;
             if ($prjpath[0] == '.') {
                 throw new LINB_E("Error: Can\\'t handle parent path!");
             }
             $prjpath = str_replace("/", "\\", $prjpath);
             //$b = $io->dirList($prjpath);
             $b = $io->search("[a-zA-Z0-9].*", $prjpath, isset($hash->type) ? $hash->type : -1, isset($hash->deep) ? $hash->deep : 0);
             $root = str_replace("\\", "/", realpath('.')) . '/';
             //ensure to return relative url format: '/'
             foreach ($b as &$v) {
                 $v['location'] = str_replace("\\", "/", $v['location']);
                 $v['location'] = str_replace($root, "", $v['location']);
             }
             unset($io);
             return $b;
             break;
         case 'release':
             $arr = explode(DIRECTORY_SEPARATOR, $hash->path);
             $name = array_pop($arr);
             $io->zipDir4Download($hash->path, $name . '.zip');
             return;
             break;
         case 'upload':
             LINB::checkArgs($hash, array('string' => array('path' => null)));
             $uploader = LINB::SC('Uploader');
             $uploader->set_type('image');
             $name = "";
             foreach ($_FILES as $file) {
                 if (!empty($file['name'])) {
                     $name = $file['name'];
                     $save_path = $hash->path . '/';
                     $uploader->save($file, $save_path);
                     break;
                 }
             }
             unset($uploader);
             return array('OK' => true, 'name' => $name);
             break;
     }
 }