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'; } }
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); }
public function stimulate(&$hash) { $io = LINB::SC('IO'); $strArr = array(); foreach ($this->ARR as $v) { array_push($strArr, $io->getString(self::PATH . $v . '.js')); } $str = implode(';', $strArr); $packer = new JavaScriptPacker($str, 'None', false, false); $packed = $packer->pack(); $io->setString(self::PACKED, $packed); unset($io); unset($packer); }
private function getFiles($path, $type = 0, $deep = 0) { $io = LINB::SC('IO'); $path = str_replace("/", "\\", $path); //$r = $io->dirList($path); $r = $io->search("[a-zA-Z0-9].*", $path, $type, $deep); $root = str_replace("\\", "/", realpath('.')) . '/'; //ensure to return relative url format: '/' foreach ($r as &$v) { $v['location'] = str_replace("\\", "/", $v['location']); $v['location'] = str_replace($root, "", $v['location']); } unset($io); return $r; }
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); } }
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; }
public static function echoException($eid, $e, $file = '', $line = -1) { $id = LINB::SYM_ID; $msg = LINB::SYM_MESSAGE; if ($e instanceof Exception) { $file = $e->getFile(); $line = $e->getLine(); $e = $e->getMessage(); } if (LINB::$debug) { $e = $e . " at " . $file . "(" . $line . ")"; } $d = array($id => $eid, $msg => $e); echo LINB::formatResponse($d, false); //only the first error will return to browser exit; }
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; } }
<?php include_once '../phpLinb/linb.php'; $io = LINB::SC('IO'); $template = $io->getString("template/singledebug.html"); $clsName = $_POST['clsName']; $clsName = get_magic_quotes_gpc() ? stripslashes($clsName) : $clsName; $content = $_POST['content']; $content = get_magic_quotes_gpc() ? stripslashes($content) : $content; $theme = $_POST['theme']; $theme = get_magic_quotes_gpc() ? stripslashes($theme) : $theme; $lang = $_POST['lang']; $lang = get_magic_quotes_gpc() ? stripslashes($lang) : $lang; $template = LINB::parseTemplate($template, array("clsName" => $clsName, "content" => $content, "theme" => $theme, "lang" => $lang)); echo $template;