function dir_copy_wrapper($fromFile, $destFile) { // load settings $defaultNs = 'NAMESPACE'; $appNs = strtolower(__APP_NAME); // replace code if (is_file($destFile) && (preg_match('/.txt$/i', $destFile) || preg_match('/.ini$/i', $destFile) || preg_match('/.xml$/i', $destFile) || preg_match('/.java$/i', $destFile) || preg_match('/.project$/i', $destFile) || preg_match('/.properties/i', $destFile))) { echo "FILE {$destFile} ... "; $destFileContent = file_get_contents($destFile); $destFileContent = str_replace($defaultNs, $appNs, $destFileContent); file_put_contents($destFile, $destFileContent, LOCK_EX); echo "ok.\n"; return; } // change dir name if (is_dir($destFile) && preg_match("/{$defaultNs}\$/i", $destFile)) { echo "FILE1 {$destFile} ... \n"; $destDir = preg_replace("/{$defaultNs}\$/", $appNs, $destFile); echo "\nDIR1 {$destFile} > {$destDir}"; echo "\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"; Hush_Util::dir_copy($destFile, $destDir); Hush_Util::dir_remove($destFile); echo "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"; echo "ok.\n\n"; return; } }
public function server() { echo '<b>$_REQUEST >>></b>'; Hush_Util::dump($_REQUEST); echo '<b>func_get_args() >>></b>'; Hush_Util::dump(func_get_args()); }
private function pagingDemo() { $data = array(); for ($i = 0; $i < 100; $i++) { $data[$i]['id'] = $i; $data[$i]['name'] = 'Test' . $i; } /* * 分页类使用说明: * * 参数1:具体用法见本方法前面的“特别说明” * 参数2:每页包含的数据项个数 * 参数3:页码数,空则表示首页 * 参数4:分页模式,目前支持的 Mode 有三种,分别是 Google、Common、JavaEye 的分页模式 * * 更多使用方法请参考 hush-lib/Hush/Paging.php 类中的使用说明 */ $page = new Ihush_Paging($data, 5, null, array('Href' => '/test/p/{page}?debug=time', 'Mode' => 3)); /* * 打印数组形式: * * 此数组可以提供给 Smarty 等模板直接展示,非常方便! * 其中较常被展示的就是 totalPage(总页数)、prevStr(上页字串)、nextStr(下页字串)、pageStr(分页字串) */ Hush_Util::dump($page->toArray()); }
public static function autoStart() { session_start(); if (!session_id()) { Hush_Util::headerRedirect(NAMESPACE_Util_Url::format($_SERVER['REQUEST_URI'])); } }
public function mongoShardAction() { $mongo = $this->mongo->load('Foo_Foo'); // test create echo "<b>TEST CREATE :</b>"; $result = $mongo->create(array('foo' => 1, 'val' => 1, '_time' => time())); Hush_Util::dump($result); usleep(10000); $result = $mongo->read(array('foo' => 1)); Hush_Util::dump(iterator_to_array($result)); usleep(10000); // test update echo "<b>TEST UPDATE :</b>"; $result = $mongo->update(array('foo' => 1), array('foo' => 1, 'val' => 2, '_time' => time())); Hush_Util::dump($result); usleep(10000); $result = $mongo->read(array('foo' => 1)); Hush_Util::dump(iterator_to_array($result)); usleep(10000); // test delete echo "<b>TEST DELETE :</b>"; $result = $mongo->delete(array('foo' => 1)); Hush_Util::dump($result); usleep(10000); $result = $mongo->read(array('foo' => 1)); Hush_Util::dump(iterator_to_array($result)); ob_flush(); flush(); }
public function personalAction() { $aclUserDao = $this->dao->load('Core_User'); $userId = $this->admin['id'] ? $this->admin['id'] : 0; $user = $aclUserDao->read($this->admin['id']); // do post if ($_POST) { // validation if (!$userId) { $this->addError('common.notempty', 'User Id'); } if (!Zend_Validate::is($this->param('name'), 'NotEmpty')) { $this->addError('common.notempty', 'User name'); } if ($this->noError()) { $data['name'] = $this->param('name'); if ($this->param('pass')) { $data['pass'] = Hush_Util::md5($this->param('pass')); } // do update if ($userId) { $aclUserDao->update($data, 'id=' . $userId); $this->addErrorMsg('Personal Infomation updated successfully'); } } } $this->view->user = $user; }
/** * used by RequestPage::sendListAction */ public function getSendByPage($uid) { $eachPageNum = 10; $condition = $this->select()->join($this->t3, "{$this->t1}.{$this->k3} = {$this->t3}.{$this->k3}", null)->join($this->t4, "{$this->t1}.{$this->k4} = {$this->t4}.{$this->k4}", null)->where("{$this->t1}.author_id = ?", $uid)->order("{$this->t1}.{$this->k1} desc"); $condition2 = clone $condition; // used to buid $sql_list $sql_count = $condition->from($this->t1, array("count(1) as total")); $sql_list = $condition2->from($this->t1, array("{$this->t1}.*", "{$this->t3}.bpm_node_name", "{$this->t4}.bpm_flow_name"))->limitPage(Hush_Util::param('p'), $eachPageNum); $total = $this->dbr()->fetchOne($sql_count); $pager = new Ihush_Paging($total, $eachPageNum, null, array('Href' => '/request/sendList/p/{page}', 'Mode' => 2)); return array('list' => $this->dbr()->fetchAll($sql_list), 'page' => $pager->toArray()); }
/** * Paging Product List */ public function getListByPage($each = 5) { $sql_count = $this->select(); $sql_list = clone $sql_count; // used to build $sql_list $sql_count = $sql_count->from($this->t1, array("count(1) as total")); $sql_list = $sql_list->from($this->t1, array("{$this->t1}.*"))->limitPage(Hush_Util::param('p'), $each); $res_total = $this->dbr()->fetchOne($sql_count); $res_list = $this->dbr()->fetchAll($sql_list); require_once 'Hush/Paging.php'; $paging = new Hush_Paging($res_total, $each, null, array('Mode' => 2)); return array('page' => $paging->toArray(), 'list' => $res_list); }
public function __construct($name = '') { if (!extension_loaded("sysvsem") || !extension_loaded("sysvshm") || !extension_loaded("sysvmsg")) { throw new Hush_Process_Exception("You need to open sysv* extensions"); return false; } // get global queue name $this->name = get_class($this); // get queue id from name $this->name .= '_' . $name; $this->qid = Hush_Util::str_hash($this->name); // init msg queue if (!($this->queue = msg_get_queue($this->qid, 0666))) { throw new Hush_Message_Exception("Queue " . $this->name . " create failed"); return false; } }
/** * Login function * @uses Used by user login process * @param string $user * @param string $pass * @return bool or array */ public function authenticate($user, $pass) { $sql = $this->select()->from($this->t1, "*")->where("name = ?", $user); $user = $this->dbr()->fetchRow($sql); if (!$user['id'] || !$user['pass']) { return false; } if (strcmp($user['pass'], Hush_Util::md5($pass))) { return $user['id']; } $sql = $this->select()->from($this->t2, "*")->join($this->rsh, "{$this->t2}.id = {$this->rsh}.role_id", null)->where("{$this->rsh}.user_id = ?", $user['id']); $roles = $this->dbr()->fetchAll($sql); if (!sizeof($roles)) { return false; } foreach ($roles as $role) { $user['role'][] = $role['id']; $user['priv'][] = $role['alias']; } return $user; }
function dir_copy_wrapper($fromFile, $destFile) { // load settings $defaultNs = 'NAMESPACE'; if (preg_match('/.sql$/i', $destFile) || preg_match('/.project$/i', $destFile)) { $appNs = strtolower(__APP_NAME); } else { $appNs = ucfirst(strtolower(__APP_NAME)); } // replace code if (is_file($destFile) && (preg_match('/.txt$/i', $destFile) || preg_match('/.ini$/i', $destFile) || preg_match('/.php$/i', $destFile) || preg_match('/.sql$/i', $destFile) || preg_match('/.project$/i', $destFile))) { echo "FILE {$destFile} ... "; $destFileContent = file_get_contents($destFile); $destFileContent = str_replace($defaultNs, $appNs, $destFileContent); file_put_contents($destFile, $destFileContent, LOCK_EX); echo "ok.\n"; return; } // replace httpd conf if (is_file($destFile) && preg_match('/.conf$/i', $destFile)) { echo "FILE {$destFile} ... "; $destFileContent = file_get_contents($destFile); $destFileContent = str_replace(array('APPNAME', 'APPROOT'), array(__APP_NAME, __APP_ROOT), $destFileContent); file_put_contents($destFile, $destFileContent, LOCK_EX); echo "ok.\n"; return; } // change dir name if (is_dir($destFile) && preg_match("/{$defaultNs}\$/i", $destFile)) { echo "FILE {$destFile} ... \n"; $destDir = preg_replace("/{$defaultNs}\$/", $appNs, $destFile); echo "\nDIR {$destFile} > {$destDir}"; echo "\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"; Hush_Util::dir_copy($destFile, $destDir); Hush_Util::dir_remove($destFile); echo "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"; echo "ok.\n\n"; return; } }
public function cacheAction() { $args = func_get_args(); $env = isset($args[0]) ? $args[0] : null; // get template path switch ($env) { case 'fe': $cleanDir = realpath(__DAT_DIR . '/cache'); break; case 'be': $cleanDir = realpath(__DAT_DIR . '/cache'); break; default: die("Error : Invalid input"); } if (is_dir($cleanDir)) { Hush_Util::dir_clean($cleanDir); echo "clean dir '{$cleanDir}' ok.\n"; } else { echo "clean dir '{$cleanDir}' failed.\n"; } }
/** * Forward page by header redirection * J2EE like method's name :) * * @param string $url * @return void */ public function forward($url = '') { Hush_Util::headerRedirect($url); exit; }
/** * Get string or key's hash code * @param string $s * @return int */ private function __hashcode($s) { $base = ftok(__FILE__, 'r'); $code = $base + Hush_Util::str_hash($s); return $code ? $code : $base; }
/** * Check debug can be showed * Judge by url parameter named 'debug' * @param string $level * @return unknown */ public static function showDebug($str) { $debug_str = Hush_Util::param('debug'); if ($debug_str) { $debug_arr = explode(',', $debug_str); return in_array($str, $debug_arr); } return false; }
/** * Main dispatch process * @param array $app_dir * @param array $tpl_dir * @return unknown */ public function dispatch($app_dir, $tpl_dir) { // app dispatch time if (Hush_Debug::showDebug('time')) { $this->start_time = microtime(true); } $this->_formatPath(); $mapper_class = array(); $mapper = $this->getMapper(); /* MAIN PROCESS * Parse mapping file * Get mapped class */ if ($mapper) { // prepare mapping $page_map = $mapper->getPageMap(); $path_raw = $this->_request->getPathInfo(); // map with raw url path if (array_key_exists($path_raw, $page_map)) { $mapper_class = $page_map[$path_raw]; } elseif (array_key_exists($this->_path, $page_map)) { $mapper_class = $page_map[$this->_path]; } else { foreach ((array) $page_map as $pattern => $class) { // escape not REGEXP rules if (strpos($pattern, '*') === false) { continue; } // url matching $pattern = preg_quote($pattern, '/'); $pattern = str_replace('\\*', '(.*?)', $pattern); if (preg_match('/^' . $pattern . '$/i', $path_raw)) { $mapper_class = $class; break; } } } } /* MAIN PROCESS * Get class & action name */ if ($mapper_class) { // get mapped class $className = $this->getMapPageClass($mapper_class); // get action from mapping rule if (strpos($mapper_class, '*') === false) { $actionName = $this->getMapPageAction($mapper_class); // get action from url path } else { $actionName = $this->getDefaultPageAction(); } } else { // get default class & action from url $className = $this->getDefaultPageClass(); $actionName = $this->getDefaultPageAction(); } /* MAIN PROCESS * Get action args */ $actionArgs = $this->getActionArgs(); /* MAIN PROCESS * Get template name */ $tplName = $this->getTemplateName($className, $actionName); // app dispatch time if (Hush_Debug::showDebug('time')) { $this->end_time = microtime(true); $debug = Hush_Debug::getInstance(); $debug->addWriter(new Hush_Debug_Writer_Html()); $debug->debug($this->end_time - $this->start_time, '<span style="color:red">Hush App Dispatch Time >>></span>', Hush_Debug::INFO); } /* MAIN PROCESS * Enter page scope */ try { // load page class @Zend_Loader::loadClass($className, $app_dir); // debug should be closed if (!class_exists($className)) { require_once 'Hush/App/Exception.php'; throw new Hush_App_Exception('Can not find definition for class \'' . $className . '\''); } /* USE PAGE VIEW PROCESS * close auto-load for page view class */ if (self::$pageViewClass) { require_once 'Hush/Page.php'; Hush_Page::closeAutoLoad(); // close page autoload mechanism } // create page $page = new $className(); /* USE PAGE VIEW PROCESS * set template for page view class */ if (self::$pageViewClass) { if ($tpl_dir) { $page->setTemplateDir($tpl_dir); } $page->__prepare(); } // set page's debug level if ($this->_debugLevel) { $page->setDebugLevel($this->_debugLevel); } // callback method implemented in page class if (method_exists($page, '__init')) { $page->__init(); } // call page action method $page->{$actionName}($actionArgs); // callback method implemented in page class if (method_exists($page, '__done')) { $page->__done(); } /* USE PAGE VIEW PROCESS * display template for page view class */ if (self::$pageViewClass) { $page->__display($tplName); } } catch (Exception $e) { require_once 'Hush/Util.php'; if (!$this->_debug) { Hush_Util::HTTPStatus(404); if (file_exists($this->_epage)) { include_once $this->_epage; exit; } } else { echo '<b>Dispatch Debug Info >>></b>' . "<br/>\n" . "<br/>\n"; echo 'Class Name : ' . $className . "<br/>\n"; echo 'Action Name : ' . $actionName . "<br/>\n"; echo 'Action Args : ' . json_encode($actionArgs) . "<br/>\n"; echo 'Template Name : ' . $tplName . "<br/>\n" . "<br/>\n"; echo '<b>Dispatch Exception Info >>></b>' . "<br/>\n"; Hush_Util::trace($e); } } }
/** * Used by subpages for fetching all request * @access protected * @param string $key * @param mixed $value * @return mixed */ protected function param($key = '', $value = null) { return Hush_Util::param($key, $value); }
/** * Main dispatch process * @param array $app_dir * @param array $tpl_dir * @return unknown */ public function dispatch($app_dir, $tpl_dir) { // app dispatch time if (Hush_Debug::showDebug('time')) { $this->start_time = microtime(true); } $this->_formatPath(); $mapper_class = null; $mapper = $this->getMapper(); /* MAIN PROCESS * Parse mapping file * Get mapped class */ if ($mapper) { // prepare mapping $page_map = $mapper->getPageMap(); $path_raw = $this->_request->getPathInfo(); // do mapping loop foreach ((array) $page_map as $pattern => $class) { // handle REWRITE rules if (strpos($class, '/') === 0) { $pattern = preg_quote($pattern, '/'); $pattern = str_replace('\\*', '(.*?)', $pattern); $replacement = str_replace('*', '$1', $class); // not preg format $path_raw = preg_replace('/^' . $pattern . '$/i', $replacement, $path_raw); continue; } // handle NOT REGEXP rules if (strpos($pattern, '*') === false) { if (!strcasecmp($path_raw, $pattern) || !strcasecmp($this->_path, $pattern)) { $mapper_class = $class; break; } continue; } // handle REGEXP rules if (true) { $pattern = preg_quote($pattern, '/'); $pattern = str_replace('\\*', '(.*?)', $pattern); if (preg_match('/^' . $pattern . '$/i', $path_raw, $path_args)) { $mapper_class = $class; // fill params foreach ($path_args as $k => $v) { $_REQUEST['$' . $k] = $v; } break; } continue; } } } /* MAIN PROCESS * Get class & action name */ if ($mapper_class) { // get mapped class $className = $this->getMapPageClass($mapper_class); // get action from mapping rule if (strpos($mapper_class, '*') === false) { $actionName = $this->getMapPageAction($mapper_class); // get action from url path } else { $actionName = $this->getDefaultPageAction(); } } else { // get default class & action from url $className = $this->getDefaultPageClass(); $actionName = $this->getDefaultPageAction(); } /* MAIN PROCESS * Get action args */ $actionArgs = $this->getActionArgs(); /* MAIN PROCESS * Get template name */ $templateName = $this->getTemplateName($className, $actionName); // app dispatch time if (Hush_Debug::showDebug('time')) { $this->end_time = microtime(true); $debug = Hush_Debug::getInstance(); $debug->setWriter(new Hush_Debug_Writer_Html()); $debug->debug($this->end_time - $this->start_time, '<span style="color:red">Hush App Dispatch Time >>></span>', Hush_Debug::INFO); } /* MAIN PROCESS * find page by url */ try { // load page class @Zend_Loader::loadClass($className, $app_dir); // debug should be closed if (!class_exists($className)) { echo 1; require_once 'Hush/App/Exception.php'; throw new Hush_App_Exception('Can not find definition for class \'' . $className . '\''); } } catch (Exception $e) { require_once 'Hush/Util.php'; Hush_Util::HTTPStatus(404); if (!$this->_debug) { if (file_exists($this->_epage[404])) { include_once $this->_epage[404]; exit; } } else { $this->_printDebugInfo(array('className' => $className, 'actionName' => $actionName, 'actionArgs' => $actionArgs, 'templateName' => templateName), $e); } } /* MAIN PROCESS * display page by url */ try { // close auto-load for page view class if (self::$pageViewClass) { require_once 'Hush/Page.php'; Hush_Page::closeAutoLoad(); // close page autoload mechanism } // create page $page = new $className(); /* USE PAGE VIEW PROCESS * set template for page view class */ if (self::$pageViewClass) { if ($tpl_dir) { $page->setTemplateDir($tpl_dir); } $page->__prepare(); } // set page's debug level if ($this->_debugLevel) { $page->setDebugLevel($this->_debugLevel); } // callback method implemented in page class if (method_exists($page, '__init')) { $page->__init(); } // call page action method $page->{$actionName}($actionArgs); // callback method implemented in page class if (method_exists($page, '__done')) { $page->__done(); } /* USE PAGE VIEW PROCESS * display template for page view class */ if (self::$pageViewClass) { $page->__display($templateName); } } catch (Exception $e) { require_once 'Hush/Util.php'; Hush_Util::HTTPStatus(500); if (!$this->_debug) { if (file_exists($this->_epage[500])) { include_once $this->_epage[500]; exit; } } else { $this->_printDebugInfo(array('className' => $className, 'actionName' => $actionName, 'actionArgs' => $actionArgs, 'templateName' => templateName), $e); } } }
/** * Forward page by header redirection * J2EE like method's name :) * * @param string $url * @return void */ public function forward($url) { // append sid for url Hush_Util::headerRedirect($this->url->format($url)); exit; }
public function newappAction() { echo <<<NOTICE ********************************************************** * Start to create a new app copied from this app * ********************************************************** Please enter settings by following prompting !!! NAMESPACE of the new app : NOTICE; // check user input $namespace = trim(fgets(fopen("php://stdin", "r"))); if (!preg_match('/^[A-Za-z]+$/i', $namespace)) { echo "\nNAMESPACE must be a letter.\n"; exit; } echo <<<NOTICE LOCALPATH of the new app : NOTICE; // check user input $localpath = trim(fgets(fopen("php://stdin", "r"))); if (!is_dir($localpath)) { mkdir($localpath, 0777, true); } $localpath = realpath($localpath); if ($localpath) { echo "\nLOCALPATH : {$localpath}\n\n"; } echo <<<NOTICE Are you sure you want to continue [Y/N] : NOTICE; // check user input $input = fgets(fopen("php://stdin", "r")); if (strcasecmp(trim($input), 'y')) { exit; } // copy main code Hush_Util::dir_copy(__ROOT, $localpath, array('.svn'), array($this, 'copy_all_wrapper')); // used by copy_lib_wrapper callback $this->namespace = $namespace; // copy lib code $baseLibDir = realpath($localpath . '/lib/'); $oldLibDir = $baseLibDir . DIRECTORY_SEPARATOR . 'Ihush'; $newLibDir = $baseLibDir . DIRECTORY_SEPARATOR . $namespace; Hush_Util::dir_copy($oldLibDir, $newLibDir, null, array($this, 'copy_lib_wrapper')); // copy etc code $baseEtcDir = realpath($localpath . '/etc/'); $tmpEtcDir = $localpath . DIRECTORY_SEPARATOR . 'etc_tmp'; Hush_Util::dir_copy($baseEtcDir, $tmpEtcDir, null, array($this, 'copy_lib_wrapper')); Hush_Util::dir_copy($tmpEtcDir, $baseEtcDir, null, null); // copy bin code $baseBinDir = realpath($localpath . '/bin/'); $tmpBinDir = $localpath . DIRECTORY_SEPARATOR . 'bin_tmp'; Hush_Util::dir_copy($baseBinDir, $tmpBinDir, null, array($this, 'copy_lib_wrapper')); Hush_Util::dir_copy($tmpBinDir, $baseBinDir, null, null); // remove useless dir echo "Remove useless dirs ...\n"; Hush_Util::dir_remove($oldLibDir); Hush_Util::dir_remove($tmpEtcDir); Hush_Util::dir_remove($tmpBinDir); // change init configs echo "Change init configs ...\n"; $configFilePath = $baseEtcDir . DIRECTORY_SEPARATOR . 'global.config.php'; $configFileCode = file_get_contents($configFilePath); $pregArr = array('/__COMM_LIB_DIR\',.*?\\)/', '/__HUSH_LIB_DIR\',.*?\\)/'); $replaceArr = array('__COMM_LIB_DIR\', _hush_realpath(__ROOT . \'/../phplibs\')', '__HUSH_LIB_DIR\', _hush_realpath(__ROOT . \'/../phplibs\')'); $configFileCode = preg_replace($pregArr, $replaceArr, $configFileCode); file_put_contents($configFilePath, $configFileCode); // all completed echo <<<NOTICE ********************************************************** * Create successfully * ********************************************************** Please check new app in '{$localpath}' !!! NOTICE; }
/** * @pbel 跳转节点 : forward(节点ID) */ public function forward($nodeId) { $redirUrl = (string) $_SERVER['REQUEST_URI']; $redirUrl = preg_replace('/(nodeId\\/[0-9]+)/i', 'nodeId/' . $nodeId, $redirUrl); Hush_Util::headerRedirect($redirUrl); exit; }
/** * Cooperate with data class to fetch items for each page. * Use sql LIMIT to separate page items. * * @return array */ protected function __paging() { // do paging when have total count if ($this->totalNum > 0) { // for paging field $this->totalPage = $this->totalPage ? $this->totalPage : ceil($this->totalNum / $this->each); $this->page = $this->page > $this->totalPage ? $this->totalPage : $this->page; $this->frNum = $this->each * ($this->page - 1); $this->frStr = $this->frNum + 1; $this->toNum = $this->page == $this->totalPage ? $this->totalNum : $this->each * $this->page; $this->toStr = $this->toNum; for ($i = 1; $i <= $this->totalPage; $i++) { if ($this->page == $i) { if (isset($this->pattern['PageTag']) && sizeof($this->pattern['PageTag']) == 2) { $pages[$i] = $this->pattern['PageTag'][0] . $i . $this->pattern['PageTag'][1]; } else { $pages[$i] = '<b>' . $i . '</b>'; } } else { if ($this->page == $i && $this->totalPage == $i) { $pages[$i] = $this->totalPage; } else { $pages[$i] = $this->makeURL($i); } } } // provide 3 paging modes if (isset($this->pattern['Mode'])) { // init array for mode 3 $pages1 = array(); $pages2 = array(); $pages3 = array(); switch ($this->pattern['Mode']) { // Google Style Paging case '1': $start_pos = $this->page - 10 < 0 ? 0 : $this->page - 10; $end_pos = $this->page + 9 > $this->totalPage ? $this->totalPage : $this->page + 9; $pages = Hush_Util::array_chop($pages, $start_pos, $end_pos); break; // My Style Paging // My Style Paging case '2': // don't split pages array when total page < 10 $limit = isset($this->pattern['ModeArg']['LIMIT']) ? $this->pattern['ModeArg']['LIMIT'] : 10; $half_limit = ceil($limit / 2); if ($this->totalPage > $limit) { $start_pos = $this->page - $half_limit < 0 ? 0 : $this->page - $half_limit; $start_pos = $start_pos + $limit > $this->totalPage ? $this->totalPage - $limit : $start_pos; $pages = array_slice($pages, $start_pos, $limit); } break; case '3': $split1 = 5; $split2 = $this->totalPage - 4; if ($this->totalPage <= 10) { $pages1 = $pages; } else { $i = $this->page; if ($i > 1 && $i < $this->totalPage) { $pages2 = array($pages[$i - 1], $pages[$i], $pages[$i + 1]); } else { $pages2 = array($pages[$i]); } $pages1 = array_slice($pages, 0, 3); $pages3 = array_slice($pages, -3, 3); if ($this->page <= $split1) { $pages1 = array_unique(array_merge($pages1, $pages2)); $pages2 = $pages3; $pages3 = array(); } elseif ($this->page >= $split2) { if ($this->page != $this->totalPage) { $pages2 = array_unique(array_merge($pages2, $pages3)); } else { $pages2 = array_unique(array_merge($pages3, $pages2)); } $pages3 = array(); } } // Show All Paging // Show All Paging default: break; } // build paging string $spacing = array_key_exists('Spacing', $this->pattern) ? $this->pattern['Spacing'] : ' '; if ($this->pattern['Mode'] == 3) { $this->pageStr = implode($spacing, $pages1); if (sizeof($pages2)) { $this->pageStr .= ' ... ' . implode($spacing, $pages2); } if (sizeof($pages3)) { $this->pageStr .= ' ... ' . implode($spacing, $pages3); } } else { $this->pageStr = implode($spacing, $pages); } } // get page array if (is_array($this->items)) { for ($i = $this->frNum; $i < $this->toNum; $i++) { $this->pageArr[] = $this->items[$i]; } } } else { $this->frNum = $this->each * ($this->page - 1); $this->frStr = $this->frNum + 1; $this->toNum = $this->each * $this->page; $this->toStr = $this->toNum; } // for prev/next field if (1) { $prevStr = array_key_exists('Prev', $this->pattern) ? $this->pattern['Prev'] : $this->prevStr; $nextStr = array_key_exists('Next', $this->pattern) ? $this->pattern['Next'] : $this->nextStr; if ($this->page != 1) { $page = $this->page - 1; $this->prevStr = $this->makeURL($page, $prevStr); } else { if (!array_key_exists('TrimPag', $this->pattern)) { $this->prevStr = $prevStr; } else { $this->prevStr = ''; } } if ($this->page != $this->totalPage) { $page = $this->page + 1; $this->nextStr = $this->makeURL($page, $nextStr); } else { if (!array_key_exists('TrimPag', $this->pattern)) { $this->nextStr = $nextStr; } else { $this->nextStr = ''; } } } // return builded paging array return $this->toArray(); }
/** * Used by subpages for fetching all sessions * @access protected * @param string $key * @param mixed $value * @return mixed */ protected function session($key = '', $value = null) { return Hush_Util::session($key, $value); }
public function userEditAction() { $aclUserDao = $this->dao->load('Core_User'); $user = $aclUserDao->read($this->param('id')); // do post if ($_POST) { // merged roles $roles = $this->mergeRoles($this->param('roles_'), $this->param('roles')); // validation if (!Zend_Validate::is($this->param('name'), 'NotEmpty')) { $this->addError('common.notempty', 'User name'); } if (!$roles) { $this->addError('common.notempty', 'Role list'); } if ($this->noError()) { // prepare data $data['name'] = $this->param('name'); if ($this->param('pass')) { $data['pass'] = Hush_Util::md5($this->param('pass')); } // do update if ($this->param('id')) { $aclUserDao->update($data, 'id=' . $this->param('id')); $aclUserDao->updateRoles($this->param('id'), $roles); $this->forward('userList'); } } } // default data $this->view->user = $user; // fill role select box $aclRoleDao = $this->dao->load('Core_Role'); $this->view->allroles = $aclRoleDao->getAllPrivs($this->admin['role']); $this->view->selroles = $aclRoleDao->getRoleByUserId($this->param('id'), $this->getRoleIds($this->view->allroles)); $this->view->oldroles = $this->buildRoles($this->filterOldRoles($this->view->selroles)); $this->render('acl/user/edit.tpl'); }
/** * Get string or key's hash code * @param string $s * @return int */ private function __hashcode($s) { $code = $this->ftbr + Hush_Util::str_hash($s); return $code ? $code : $this->ftbr; }
<?php /** * Ihush Console * * @author James.Huang <*****@*****.**> * @license http://www.apache.org/licenses/LICENSE-2.0 * @version $Id$ */ define('__HUSH_CLI', 1); require_once '../etc/global.config.php'; require_once 'Hush/Util.php'; //////////////////////////////////////////////////////////////////////////////////////////////////// // Constants definition define('__MYSQL_IMPORT_TOOL', 'mysql'); define('__MYSQL_DUMPER_TOOL', 'mysqldump'); define('__MYSQL_IMPORT_COMMAND', __MYSQL_IMPORT_TOOL . ' {PARAMS} < {SQLFILE}'); define('__MYSQL_DUMPER_COMMAND', __MYSQL_DUMPER_TOOL . ' {PARAMS} --add-drop-database > {SQLFILE}'); //////////////////////////////////////////////////////////////////////////////////////////////////// // Main process try { require_once 'Ihush/Cli.php'; $cli = new Ihush_Cli(); $cli->run(); } catch (Exception $e) { Hush_Util::trace($e); exit; }
/** * Process main logic */ public function run() { // init first time if (!$this->port) { $ports = $this->ports; $this->port = array_pop($ports); // current process's port (no shared) $this->ports = $ports; // store children process pid // do only once !!! $this->__pid(true); } else { echo "\n"; } echo "Listening on : " . $this->port . "\n"; try { // start socket message queue server $server = Pms_Adaptor::server(array('host' => $this->host, 'port' => $this->port)); $server->daemon(); } catch (Exception $e) { Hush_Util::trace($e); $server->close(); $this->run(); } }