public static function &getInstance() { if (self::$m_instance == null) { self::$m_instance = new self(); } return self::$m_instance; }
public function getHotFiles($folderId = 0) { if (!empty($this->request->arg[3])) { $folderId = $this->request->arg[3]; } $res = $this->db->getRows('select * from folders where parent_id=' . $folderId); ZDebug::my_print($res, 'foldList result'); return $res; }
public function deleteFolder($id) { if (!isId($id)) { ZDebug::my_echo('Param error in deleteFolder!'); return FALSE; } $res = DB::$dbInstance->query("DELETE FROM folders WHERE fd_id = " . $id . ""); $res = DB::$dbInstance->query("DELETE FROM folders WHERE parent_id = " . $id . ""); $res = DB::$dbInstance->query("DELETE FROM files WHERE fd_id = " . $id . ""); return $res; }
/** * Execute application */ public final function execute() { $_errtype = E_ALL; // Set application plugin manager listen global event dispatcher $this->getPluginManager()->setTarget(Zoombi::getDispatcher()); $this->getDispatcher()->connect('_triggerError', array($this, '_error_trigger')); try { // Notify for start execution $this->emit(new ZEvent($this, 'preExecute')); // Attach error and exception handlers if applicatio execution mode is 'debug' if ($this->isMode(self::MODE_DEBUG)) { $old_errr = error_reporting($_errtype); set_error_handler(array($this, '_error_handler'), $_errtype); //set_exception_handler(array( $this, '_exception_handler' )); } // Notify befor route start //$this->emit(new ZEvent($this, 'preRoute')); if (!$this->getFlag(self::FLAG_NO_ROUTE)) { $request = null; $rvar = $_SERVER['REQUEST_URI']; // Attach routing rules to router $routes = new ZConfig(); $router = $this->getRouter(); $rs = $this->getConfig()->getValue('routes', null); switch (gettype($rs)) { case 'array': case 'object': $routes->setData($rs); break; case 'string': $cf = $rs; if (!file_exists($cf)) { $cf = $this->fromBaseDir($cf); } if (file_exists($cf)) { $routes->fromFile($cf); } break; } $ra = $routes->toArray(); $router->setRules($ra); unset($routes); $router->setRequest($rvar); $this->emit(new ZEvent($this, 'preRoute', $router->getRequest())); $redir = $router->rewrite($router->getRequest()); $router->setRedirect($redir)->setCurrent($redir)->setForward($redir); $this->emit(new ZEvent($this, 'postRoute', $redir)); $path = $router->getRedirect(); if ($path->getSegment(0) == $this->getName()) { $path->pop_start(); } $curr = null; $fpath = $this->routePath($path, $curr, true); $router->setCurrent($curr)->setForward($curr); if ($fpath->isInvalid()) { throw new ZException('Page not found', ZControllerException::EXC_ACTION); } if ($curr->getSegment(0) == $this->getName()) { $curr->pop_start(); } $this->route($curr); } } catch (ZException $e) { switch ($e->getCode()) { case ZControllerException::EXC_QUIT: $this->getConfig()->setValue('output', false); break; case ZControllerException::EXC_QUIT_OUTPUT: $this->getConfig()->setValue('output', true); break; case ZControllerException::EXC_LOAD: case ZControllerException::EXC_NO_FILE: case ZControllerException::EXC_ACTION: $this->emit(new ZEvent($this, 'onError', 404, $e)); $this->emit(new ZEvent($this, 'on404', $this->getRoute())); break; case ZControllerException::EXC_DENY: $this->emit(new ZEvent($this, 'onError', 403, $e)); $this->emit(new ZEvent($this, 'on403', $this->getRoute())); break; case ZControllerException::EXC_AUTH: $this->emit(new ZEvent($this, 'onError', 401, $e)); $this->emit(new ZEvent($this, 'on401', $this->getRoute())); break; default: $this->emit(new ZEvent($this, 'onError', 500, $e)); $this->emit(new ZEvent($this, 'on500', $e)); break; } } $responce = ZResponse::getInstance(); if (Zoombi::ack($this->getConfig()->getValue('output', false))) { ob_start(); $this->emit(new ZEvent($this, 'onOutput')); if ($this->outputLength() > 0) { $this->outputFlush(); } if (Zoombi::ack($this->getConfig()->get('showtrace', false))) { ZDebug::printTraces(); } if (Zoombi::ack($this->getConfig()->get('showerror', false))) { $this->showErrors(); } $cnt = ob_get_contents(); ob_end_clean(); $responce->appendContent($cnt); } $this->emit(new ZEvent($this, 'postExecute')); if ($this->isMode(self::MODE_DEBUG)) { restore_error_handler(); error_reporting($old_errr); } $responce->output(); }
public static function syncFolders($folderToSync) { $debug = self::$debug; $mode = self::$mode; import('dao.Folder'); $folder = new Folder(); import('dao.File'); $file = new File(); $folderFullName = $folderToSync['path']; $folderId = $folderToSync['fd_id']; // If folder is locked, ignore. Unless set mode greater than 0. if ($folderToSync['locked'] && $mode == 0) { if ($debug) { ZDebug::my_echo('Ignore locked folder: ' . $folderFullName . '(' . $folderId . ')'); } return TRUE; } // Step 1: If folder is not physically exist, set to deleted in DB. if (!is_dir($folderFullName)) { $folder->deleteFolder($folderId); if ($debug) { ZDebug::my_echo('Delete folder in DB: ' . $folderFullName . '(' . $folderId . ')'); } return TRUE; } // Step 2: Get the result set of files under this folder $filesInFolder = $folder->getFilesInFolder($folderId); $fileNameArr = array(); foreach ($filesInFolder as $theFile) { // Step 3: If a file is not physically exist, delete it in table files. if (!file_exists($theFile['path'])) { $file->deleteFile($theFile['fid']); if ($debug) { ZDebug::my_echo('Delete file in DB: ' . $theFile['path'] . '(' . $theFile['fid'] . ')'); } } elseif ($theFile['last_modified'] != my_filemtime($theFile['path'])) { $theFile['last_modified'] = my_filemtime($theFile['path']); $file->saveFile($theFile); if ($debug) { ZDebug::my_echo('Update file in DB: ' . $theFile['path'] . '(' . $theFile['fid'] . ')'); } } elseif ($mode > 1) { $file->saveFile($theFile); if ($debug) { ZDebug::my_echo('Update file in DB: ' . $theFile['path'] . '(' . $theFile['fid'] . ')'); } } else { } $fileNameArr[] = $theFile['name']; } // Step 5: Get result set of sub-folders under this folder $subFoldera = $folder->getSubFolder($folderId); $folderNameArr = array(); foreach ($subFoldera as $theFolder) { // Step 6: If a folder is not physically exist, set deleted flag in table folders. if (!file_exists($theFolder['path'])) { $folder->deleteFolder($theFolder['fd_id']); if ($debug) { ZDebug::my_echo('Delete folder in DB: ' . $theFolder['path'] . '(' . $theFolder['fd_id'] . ')'); } } elseif ($theFolder['last_modified'] != my_filemtime($theFolder['path'])) { $theFolder['last_modified'] = my_filemtime($theFolder['path']); $folder->saveFolder($theFolder); if ($debug) { ZDebug::my_echo('Update folder in DB: ' . $theFolder['path'] . '(' . $theFolder['fd_id'] . ')'); } self::syncFolders($theFolder); } else { self::syncFolders($theFolder); } $folderNameArr[] = $theFolder['name']; } $hdl = opendir($folderFullName); while ($item = readdir($hdl)) { $itemFullName = $folderFullName . DIRECTORY_SEPARATOR . $item; // Step 8: If physical file is not in DB file result set, then add a file if ($item != "." && $item != ".." && is_file($itemFullName) && !in_array($item, $fileNameArr)) { $file->saveFile(array('path' => $itemFullName, 'fd_id' => $folderId)); if ($debug > 1) { ZDebug::my_echo('Adding new file in DB: ' . $itemFullName); } } // Step 9: if physical folder is not in DB folder result set, then add a folder if ($item != "." && $item != ".." && is_dir($itemFullName) && !in_array($item, $folderNameArr)) { self::addFolder($itemFullName, $folderId); } } closedir($hdl); }
public function start() { ZDebug::my_echo("I'm pageNotFound controller, I'm gonna call model and view."); }
/** * Execute application */ public final function execute($a_route_url = null) { // Attach error and exception handlers $olderr = error_reporting(E_ALL); set_error_handler(array($this, '_error_handler')); set_exception_handler(array($this, '_exception_handler')); // Set application plugin manager listen global event dispatcher $this->getPluginManager()->setTarget(Zoombi::getDispatcher()); $this->getDispatcher()->connect('_triggerError', array($this, '_error_trigger')); try { // Notify for start execution $this->emit(new ZEvent($this, 'preExecute')); // Notify befor route start if (!$this->getFlag(self::FLAG_NO_ROUTE)) { // Attach routing rules to router $routes = new ZConfig(); $router = $this->getRouter(); $rs = $this->getConfig()->getValue('routes', null); switch (gettype($rs)) { case 'array': case 'object': $routes->setData($rs); break; case 'string': $cf = $rs; if (!file_exists($cf)) { $cf = $this->fromBaseDir($cf); } if (file_exists($cf)) { $routes->fromFile($cf); } break; } $ra = $routes->toArray(); $router->setRules($ra); unset($routes); $request = $a_route_url ? $a_route_url : $_SERVER['REQUEST_URI']; $url = new ZUrl($this->getConfig()->getValue('baseurl')); if (strstr($request, $url->path) == 0) { $request = substr($request, strlen($url->path)); } $router->setRequest($request); $this->emit(new ZEvent($this, 'preRoute', $router->getRequest())); $redirect = $router->rewrite((string) $router->getRequest()); $router->setRedirect($redirect); $this->emit(new ZEvent($this, 'postRoute', $router->getRedirect())); $path = clone $router->getRedirect(); $s = $path->getSegment(0); if ($s == $this->getName() or $s == ZModule::DEFAULT_MODULE_NAME) { if (!$this->getLoader()->hasController($s)) { $path->pop_start(); } } $this->exec_route = $this->_route((string) $path); if ($this->exec_route) { $this->getRouter()->setCurrent($this->exec_route); $this->route($this->exec_route); } } } catch (Exception $e) { switch ($e->getCode()) { case ZControllerException::EXC_QUIT: $this->getConfig()->setValue('output', false); $this->emit(new ZEvent($this, 'onQuit')); break; case ZControllerException::EXC_QUIT_OUTPUT: $this->getConfig()->setValue('output', true); $this->emit(new ZEvent($this, 'onQuit')); break; case ZControllerException::EXC_AUTH: $this->emit(new ZEvent($this, 'onError', 401, $e)); $this->emit(new ZEvent($this, 'on401', $this->getRoute())); break; case ZControllerException::EXC_DENY: $this->emit(new ZEvent($this, 'onError', 403, $e)); $this->emit(new ZEvent($this, 'on403', $this->getRoute())); break; case ZControllerException::EXC_LOAD: case ZControllerException::EXC_NO_FILE: case ZControllerException::EXC_ACTION: $this->emit(new ZEvent($this, 'onError', 404, $e)); $this->emit(new ZEvent($this, 'on404', $this->getRoute())); break; default: $this->emit(new ZEvent($this, 'onError', 500, $e)); $this->emit(new ZEvent($this, 'on500', $e)); break; } } restore_error_handler(); restore_exception_handler(); if (Zoombi::ack($this->getConfig()->getValue('output', false))) { ob_start(); if ($this->outputLength() > 0) { $this->outputFlush(); } if (Zoombi::ack($this->getConfig()->get('showtrace', false))) { ZDebug::printTraces(); } if (Zoombi::ack($this->getConfig()->get('showerror', false))) { $this->showErrors(); } ZResponse::getInstance()->appendContent(ob_get_contents()); ob_end_clean(); $this->emit(new ZEvent($this, 'onOutput')); ZResponse::getInstance()->output(); } $this->emit(new ZEvent($this, 'postExecute')); error_reporting($olderr); }
private function submitFileHelper() { ////// $submittedArr = array('folderFullName' => '车展美女/MM写真-100万MM美女车模', 'files' => array(array('url' => 'http://pic.baa.bitautotech.com/temp/2011531101247402.jpg', 'fields' => '{"Title":"【美女|美女图片-MM写真-100万MM美女车模图片】-易车网BitAuto.com","MetaDescription":"美女图片:易车网天猫美女图片库是国内天猫美女图片量最丰富、图片清晰度最高的专业天猫商城图片频道,我们团队的顶级摄影师为您呈现出,车展美女、日韩美女、欧美美女、美女写真,让您在选择爱车的同时并享受视觉大餐。","MetaKeywords":"美女,美女图片,美女写真,日韩美女,欧美美女,中国美女,美女车模,天猫","Text":"娇媚车模梁言可爱迷人"}'), array('url' => 'http://pic.baa.bitautotech.com/temp/201153110194299.jpg', 'fields' => '{"Title":"【美女|美女图片-MM写真-100万MM美女车模图片】-易车网BitAuto.com","MetaDescription":"美女图片:易车网天猫美女图片库是国内天猫美女图片量最丰富、图片清晰度最高的专业天猫商城图片频道,我们团队的顶级摄影师为您呈现出,车展美女、日韩美女、欧美美女、美女写真,让您在选择爱车的同时并享受视觉大餐。","MetaKeywords":"美女,美女图片,美女写真,日韩美女,欧美美女,中国美女,美女车模,天猫","Text":"车模制服私房照曝光"}'))); ZDebug::my_print($submittedArr, 'The array to submit should be like this:'); $data = json_encode($submittedArr); ZDebug::my_print($data, 'The json to submit should be like this:'); $dataArr = json_decode($data); ZDebug::my_print($dataArr, 'After the json is decoded in server side, the data object would look like this:'); exit; }
} elseif ($_SERVER['argc'] == 3) { $start_fid = trim($_SERVER['argv'][1]); $end_fid = trim($_SERVER['argv'][2]); } else { show_error(); } function show_error() { global $enclose; echo "Wrong Parameter! " . $enclose; echo "Usage via command line: " . $enclose; echo " ---- buildThumbnails.php <start_fid> <end_fid>" . $enclose; echo "Usage via browser: " . $enclose; echo " ---- http://foo.com/buildThumbnails.php?start_fid=123&end_fid=12345" . $enclose; exit; } include_once '../bootstrap.inc'; set_time_limit(0); $files = array(); $files = DB::$dbInstance->getRows('SELECT * FROM `files` where image_type>0 and fid>' . $start_fid . ' and fid<' . $end_fid); foreach ($files as $file) { $fileFullName = $file['path']; $myThumb = imageCache::cacheImage($fileFullName, 160, 120, TRUE); if (!$myThumb) { ZDebug::my_echo('error build thumbnail for ' . $fileFullName); } $myThumb = imageCache::cacheImage($fileFullName, 120, 90, TRUE); if (!$myThumb) { ZDebug::my_echo('error build thumbnail for ' . $fileFullName); } }
public static final function &trace($a_data) { $args = func_get_args(); $instance = ZDebug::getInstance(); call_user_func_array(array($instance, 'trace'), $args); return $instance; }