static function info($value) { if (!tr::config()->get("app.debug")) { return; } tr_log::info($value); }
static function getAdapter($dnType = 0, $userStatic = 1) { if (isset(self::$instance[$dnType]) && self::$instance[$dnType] && $userStatic) { return self::$instance[$dnType]; } $dbh = null; $slaveDBH = null; $dbconfig = tr::config()->get("app.db"); if (isset($dbconfig['master'])) { $masterConfig = $dbconfig['master']; $dbh = new PDO('mysql:host=' . $masterConfig['host'] . ';port=' . $masterConfig['port'] . ';dbname=' . $masterConfig['db_name'] . '', $masterConfig['user'], $masterConfig['password'], array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'')); } if (isset($dbconfig['slave'])) { $masterConfig = $dbconfig['slave']; $slaveDBH = new PDO('mysql:host=' . $masterConfig['host'] . ';port=' . $masterConfig['port'] . ';dbname=' . $masterConfig['db_name'] . '', $masterConfig['user'], $masterConfig['password'], array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'')); } if ($dnType == 0) { $connection = $dbh; } else { $connection = $slaveDBH ? $slaveDBH : $dbh; } $connection->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); self::$instance[$dnType] = $connection; return $connection; }
private static function minifyCSS() { $sourcePathConfig = tr::config()->get("app.minify"); $minifier = new Minify\CSS(); if ($sourcePathConfig['css']) { foreach ($sourcePathConfig['css'] as $v) { $minifier->add($v); } } $minifier->minify(ROOT_PATH . "/public/asset/global.css"); return true; }
public static function serve($routes, $routesTmp = array()) { tr_hook::fire('before_request', compact('routes')); $request_method = strtolower($_SERVER['REQUEST_METHOD']); $path_info = '/'; if (!empty($_SERVER['PATH_INFO'])) { $path_info = $_SERVER['PATH_INFO']; } elseif (!empty($_SERVER['ORIG_PATH_INFO']) && $_SERVER['ORIG_PATH_INFO'] !== '/index.php') { $path_info = $_SERVER['ORIG_PATH_INFO']; } else { if (!empty($_SERVER['REQUEST_URI'])) { $path_info = strpos($_SERVER['REQUEST_URI'], '?') > 0 ? strstr($_SERVER['REQUEST_URI'], '?', true) : $_SERVER['REQUEST_URI']; } } $discovered_handler = null; $regex_matches = array(); list($discovered_handler, $regex_matches) = self::match($routes, $path_info); $result = null; $handler_instance = null; //如果没有匹配 if (!$discovered_handler) { list($app, $apiVersion, $from, $secondFrom) = tr::getVersion(); $path_infoNew = str_replace("/" . $app . "/" . $from . $secondFrom . $apiVersion, "", $path_info); list($discovered_handler, $regex_matches) = self::match($routesTmp, $path_infoNew); } if ($discovered_handler) { if (stristr($discovered_handler, "@")) { list($className, $method) = explode("@", $discovered_handler); $handler_instance = new $className(); $request_method = $method; } else { if (is_string($discovered_handler)) { $handler_instance = new $discovered_handler(); } elseif (is_callable($discovered_handler)) { $handler_instance = $discovered_handler(); } } } if ($handler_instance) { unset($regex_matches[0]); if (method_exists($handler_instance, $request_method)) { tr_hook::fire('before_handler', compact('routes', 'discovered_handler', 'request_method', 'regex_matches')); $result = call_user_func_array(array($handler_instance, $request_method), $regex_matches); tr_hook::fire('after_handler', compact('routes', 'discovered_handler', 'request_method', 'regex_matches', 'result')); } else { tr_hook::fire('404', compact('routes', 'discovered_handler', 'request_method', 'regex_matches')); } } else { tr_hook::fire('404', compact('routes', 'discovered_handler', 'request_method', 'regex_matches')); } tr_hook::fire('after_request', compact('routes', 'discovered_handler', 'request_method', 'regex_matches', 'result')); }
/** * @return tr_cache */ public static function cache() { $className = get_called_class(); if (!isset(self::$_instance[$className]) || !self::$_instance[$className]) { $cacheConfig = tr::config()->get("cache"); if (!is_dir(ROOT_PATH . "/" . $cacheConfig['path'])) { mkdir(ROOT_PATH . "/" . $cacheConfig['path'], 0777, true); } self::$_instance[$className] = new $className(); tr_cache::$storage = $cacheConfig['storage']; tr_cache::$securityKey = $cacheConfig['path']; tr_cache::$path = ROOT_PATH; } return self::$_instance[$className]; }
static function session() { $className = get_called_class(); if (isset(self::$_instance[$className]) && self::$_instance[$className]) { return self::$_instance[$className]; } $sessionConfig = tr::config()->get("app.session.handle"); if ($sessionConfig == 'file') { $path = ROOT_PATH . "cache/session"; if (!is_dir($path)) { mkdir($path, 0777, true); } $session = new Session(new FileStore($path)); self::$_instance[$className] = $session; return $session; } elseif ($sessionConfig == 'memcache') { $param = tr::config()->get("app.session.param"); if (class_exists("Memcached")) { $memcached = new Memcached(); if (is_array($param)) { foreach ($param as $v) { $memcached->addServer($v['hostname'], $v['port'], $v['weight']); } } else { $memcached->addServer($param['hostname'], $param['port'], $param['weight']); } } else { $memcached = new Memcache(); if (is_array($param)) { foreach ($param as $name => $cache_server) { $memcached->connect($cache_server['hostname'], $cache_server['port'], $cache_server['weight']); break; } } else { $memcached->connect($param['hostname'], $param['port'], $param['weight']); } } $session = new Session(new DoctrineCache(new MemcachedCache($memcached))); self::$_instance[$className] = $session; return $session; } }
function send($recevierArr, $subject, $body, $attachment = "") { $className = get_called_class(); $obj = self::$_instance[$className]; $sender = tr::config()->get("app.mail.sender"); $obj->setFrom($sender); if (is_array($recevierArr)) { foreach ($recevierArr as $v) { $obj->addTo($v); } } else { $obj->addTo($recevierArr); } $obj->setSubject($subject); $obj->setHTMLBody($body); if ($attachment) { $obj->addAttachment($attachment); } // dd($obj); return $obj->dosend(); }
/** * Translates string; tr::_() wrapper * @param string * @param int * @return string */ function __($msg, $count = NULL) { return tr::_($msg, $count); }
function style($url) { $url = trim($url, "/"); $dir = dirname($_SERVER['PHP_SELF']); $dirArr = explode("index.php", $dir); $dir = array_shift($dirArr); $dir = str_replace("\\", "/", $dir); $path = $dir . "/asset/" . $url; $path = str_replace("//", "/", $path); $v = tr::config()->get("app.static_version"); // return $path . "?v=" . $v. ".css" ; return "<link rel=\"stylesheet\" type='text/css' href=\"" . $path . "?v=" . $v . ".css\"/>" . PHP_EOL; }
function isdebug() { return tr::config()->get("app.debug"); }
<?php if ($form->hasErrors()) { echo debug::trace($form->getErrors()); } ?> <?php echo $form; ?><br /> <a href="<?php echo $indexPage; ?>"><?php tr::__('scaffold_back', 1) ?></a>
echo '<td class="checkCell"><input type="checkbox" name="'.$multipleIdent.'[]" value="'.$l->get($multipleIdent).'" /></td>'; foreach($headers as $h) { $val = $l->get($h['name'], 'flatReal'); switch($h['type']) { case 'date': $val = $val ? utils::formatDate($val) : $val; break; case 'datetime': case 'timestamp': $val = $val ? utils::formatDate($val, 'datetime') : $val; break; case 'image': $val = $val ? $imgHelper->view($val) : $val; break; case 'tinyint': $val = ucfirst(tr::__($val ? 'yes' : 'no')); break; case 'enum': $tmp = $l->getTable()->getField($h['name']); $val = isset($tmp['precision'][$val]) ? $tmp['precision'][$val] : $val; break; } echo '<td class="'.$h['name'].'Cell">'.(is_array($val)? implode(', ', $val) : $val).'</td>'; } if ($actions) { echo '<td class="actionsCell">'; if (array_key_exists($i, $actions)) foreach($actions[$i] as $a=>$v) { $img = $actionsImg[$a]; echo '<a href="'.$v.'" class="'.$a.'">'.($img? $img : $a).'</a> '; }
/** * Init the session configuration */ private static function initCfg() { if (!self::$cfg) self::$cfg = new config(factory::loadCfg(__CLASS__)); }
public static function serve($routes) { if (!isset($_SERVER['REQUEST_METHOD'])) { return; } tr_hook::fire('before_request', compact('routes')); $onlyReset = tr::config()->get("app.only_reset"); $request_method = strtolower($_SERVER['REQUEST_METHOD']); $path_info = '/'; if (!empty($_SERVER['PATH_INFO'])) { $path_info = $_SERVER['PATH_INFO']; } elseif (!empty($_SERVER['ORIG_PATH_INFO']) && $_SERVER['ORIG_PATH_INFO'] !== '/index.php') { $path_info = $_SERVER['ORIG_PATH_INFO']; } else { if (!empty($_SERVER['REQUEST_URI'])) { $path_info = strpos($_SERVER['REQUEST_URI'], '?') > 0 ? strstr($_SERVER['REQUEST_URI'], '?', true) : $_SERVER['REQUEST_URI']; } } $discovered_handler = null; $regex_matches = array(); if (isset($routes[$path_info])) { $discovered_handler = $routes[$path_info]; } elseif ($routes) { $tokens = array(':string' => '([a-zA-Z]+)', ':number' => '([0-9]+)', ':alpha' => '([a-zA-Z0-9-_]+)'); foreach ($routes as $pattern => $handler_name) { $pattern = strtr($pattern, $tokens); if (preg_match('#^/?' . $pattern . '/?$#', $path_info, $matches)) { $discovered_handler = $handler_name; $regex_matches = $matches; break; } } } $result = null; $handler_instance = null; if ($discovered_handler) { if (stristr($discovered_handler, "@")) { list($className, $method) = explode("@", $discovered_handler); $handler_instance = new $className(); $request_method = $method; } else { if (is_string($discovered_handler)) { $handler_instance = new $discovered_handler(); } elseif (is_callable($discovered_handler)) { $handler_instance = $discovered_handler(); } } } if ($handler_instance) { unset($regex_matches[0]); if (self::is_xhr_request() && method_exists($handler_instance, $request_method . '_xhr')) { header('Content-type: application/json'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Cache-Control: no-store, no-cache, must-revalidate'); header('Cache-Control: post-check=0, pre-check=0', false); header('Pragma: no-cache'); $request_method .= '_xhr'; } if (method_exists($handler_instance, $request_method)) { tr_hook::fire('before_handler', compact('routes', 'discovered_handler', 'request_method', 'regex_matches')); $result = call_user_func_array(array($handler_instance, $request_method), $regex_matches); tr_hook::fire('after_handler', compact('routes', 'discovered_handler', 'request_method', 'regex_matches', 'result')); } else { tr_hook::fire('404', compact('routes', 'discovered_handler', 'request_method', 'regex_matches')); } } else { tr_hook::fire('404', compact('routes', 'discovered_handler', 'request_method', 'regex_matches')); } tr_hook::fire('after_request', compact('routes', 'discovered_handler', 'request_method', 'regex_matches', 'result')); }
Environment::setVariable('tempDir', Environment::expand('%baseDir%/tmp')); Environment::setVariable('themeBaseUri', Environment::expand('%baseUri%/themes/%theme%')); Environment::setVariable('mediaDir', Environment::expand('%baseDir%/media')); Environment::setVariable('mediaBaseUri', Environment::expand('%baseUri%/media')); set_include_path(LIB_DIR . PATH_SEPARATOR . get_include_path()); Html::$xhtml = FALSE; SafeStream::register(); setlocale(LC_ALL, require Environment::expand('%localeFile%')); Zend_Search_Lucene::setDefaultSearchField('description'); // configure locale require_once LIB_DIR . '/tr.php'; $available = array(); foreach (glob(APP_DIR . '/locale/' . '*.php') as $_) { $available[substr(substr($_, strlen(APP_DIR . '/locale/')), 0, 2)] = $_; } tr::$locale = Environment::getHttpRequest()->detectLanguage(array_keys($available)); if (tr::$locale) { list(tr::$plurals[tr::$locale], tr::$table[tr::$locale]) = (require $available[tr::$locale]); } // connect to DB dibi::connect(require Environment::expand('%dbFile%')); // get app $app = Environment::getApplication(); // routing $router = $app->getRouter(); Route::setStyleProperty('action', Route::FILTER_TABLE, array(__('show-cart') => 'showCart', __('fill-data') => 'fillData', __('complete') => 'complete', __('commit') => 'commit')); $router[] = new Route(__('order') . '/<action>/', array('presenter' => 'Front:Order')); $router[] = new Route('admin/<presenter>/<action>/', array('module' => 'Back', 'presenter' => 'Dashboard', 'action' => 'default')); $router[] = new Route(__('search') . ' ? q=<q .*> & ' . __('page') . '=<page \\d+>', array('presenter' => 'Front:Search', 'action' => 'default', 'page' => 1)); Route::addStyle('path', NULL); Route::setStyleProperty('path', Route::PATTERN, '.*');
protected function addEditForm($action, $id = null) { $uAction = ucfirst($action); $this->row = $id ? $this->table->find($id) : $this->table->getRow(); if (!$this->row) response::getInstance()->redirect($this->indexPage); if ($action == 'duplic') { $tmp = $this->row; $this->row = $this->table->getRow(); $this->row->setValues($tmp->getValues()); $this->row->setValues($tmp->getValues('flat')); $action = 'add'; } $this->hook($action); $this->form = $this->row->getForm($this->getFields($action), array_merge(array('sectionName'=>tr::__('scaffold_'.$action)), $this->cfg->formOpts)); $this->hook('formInit'); $this->hook('formInit'.$uAction); if (request::isPost()) { $this->form->refill(); $this->hook('formPost'.$uAction); if ($this->form->isValid()) { $this->row->setValues($this->form->getValues()); $this->hook('before'.$uAction); if ($this->row->save()) { $this->hook('after'.$uAction); response::getInstance()->redirect($this->indexPage); } } else $this->setViewVar('errors', $this->form->getErrors()); } $this->form->setSubmitText(tr::__('scaffold_'.$action)); $this->form->setSubmitplus('<a href="'.$this->indexPage.'">'.tr::__('scaffold_back').'</a>'); $this->hook('form'.$uAction); $this->setViewVars(array( 'row'=>$this->row, 'form'=>$this->form )); }
<?php $cfg = array('table' => REQUIRED, 'all' => 'all', 'listBool' => array('1' => ucfirst(tr::__('yes')), '0' => ucfirst(tr::__('no')), KEEPUNIQUE => true), 'autoValidRule' => array('email', 'url'));
static function getParam($str = null, $default = null) { return tr::getParam($str, $default); }
function put() { print_r(tr::config()->get("app.test")); exit; echo "put"; }
<?php if ($allowAdd) echo '<a href="'.$addPage.'">'.utils::getIcon(array('name'=>'add','type'=>$iconType)).' '.tr::__('scaffold_add').'</a><br />'; echo $filterTable; echo $dataTable; ?>
print_error($tr->get_errmsg()); exit; } $tr_data = $tr->get_tr(); print_object($tr_data); break; case 'deletetr': //check office can use this function if (!require_office()) { print_error($string_arr['er003']); } //check user permission, if (!check_office_staff($_SESSION['staff_no'])) { print_error($string_arr['er004']); } $tr = new tr($tr_no); if ($tr->get_errmsg()) { print_error($tr->get_errmsg()); exit; } $tr_data = $tr->get_tr(); if ($tr_data->with_po) { //no handle po with tr print_error('[!]not-in handle case (tr with po)'); } $tr_delete_action = $tr->delete_tr(); break; case 'viewdeleedtr': $data = tr::get_trdeleted_record(5529); break; default: