protected function getClassName($moduleString) { $path = explode('.', $moduleString); $className = mgFileNameToClassName(array_pop($path)); array_push($path, $className); return array($className, implode('__', $path)); }
function __construct() { global $globalDbObject; parent::__construct(); if (!$globalDbObject) { $dbObjectName = mgFileNameToClassName(__DBOBJECT__); $globalDbObject = new $dbObjectName(); } $this->dbObject = $globalDbObject; $this->usedTable = array(); }
public static final function prase($from, $to, $str) { $langFile = __LIB__ . "/translate/translate.{$from}_to_{$to}.php"; if (file_exists($langFile)) { require $langFile; $className = mgFileNameToClassName("{$from}_to_{$to}"); $lang = new $className(); return $lang->prase($str); } else { return $str; } }
private function runAction() { //分析path模块传递的数据 $cacheTime = intval($this->stack['action']['cache']); $pastTime = false; if ($cacheTime) { $time = time(); $fileName = md5($_SERVER['REQUEST_URI']); $path = __HTML_CACHE__ . mgGetGuidPath($fileName); $filePath = $path . '/' . $fileName; $mimePath = $path . '/' . $fileName . '.mime'; if (!file_exists($filePath) || !file_exists($mimePath)) { $pastTime = true; } else { $pastTime = $cacheTime > $time - filemtime($filePath) ? false : true; } } else { //do nothing } if (!$cacheTime || $pastTime || __DEBUG__) { if (__DEBUG__ && !is_dir(__DIR__ . '/action/' . $this->stack['action']['action'])) { $this->throwException(E_ACTION_ACTIONNOTEXISTS, $this->stack['action']['action']); } else { $tmp = null; require_once __DIR__ . '/action/' . $this->stack['action']['action'] . '/action.' . $this->stack['action']['action'] . '.php'; eval('$tmp = new ' . mgFileNameToClassName($this->stack['action']['action']) . '("' . str_replace('{', '{$', $this->stack['action']["file"]) . '");'); $tmp->runAction(); } $contents = ob_get_contents(); if ($cacheTime) { if (!is_dir($path)) { mgMkdir($path); } file_put_contents($mimePath, $this->stack['action']['content_type']); file_put_contents($filePath, $contents); } ob_end_clean(); echo $contents; } else { header(file_get_contents($mimePath)); echo file_get_contents($filePath); } if (__DEBUG__) { global $debugData; mgPrintDebug(__DEBUG_LOG__, $debugData); } }
public function filterComment() { $filter = array(); require __CACHE__ . '/comment_filter/comment_filter.php'; $filterByType = isset($filter[$this->filterType]) ? $filter[$this->filterType] : array(); $requireDir = __MODULE__ . '/comment_filter/'; foreach ($filterByType as $key => $val) { $currentFile = $requireDir . 'comment_filter.' . $key . '.php'; if (file_exists($currentFile)) { $tmp = null; require_once $currentFile; $object = mgFileNameToClassName($key); $tmp = new $object($val); //result返回一个数组,包含两个键值publish和word $this->result = $tmp->runFilter(); if ($this->result) { break; } } } }
protected function loadModel($model, $triggerException = true) { if (isset($this->globalModel[$model])) { return $this->globalModel[$model]; } else { mgTrace(); $modelFile = __MODEL__ . '/model.' . $model . '.php'; $object = mgFileNameToClassName($model); if (!class_exists($object . 'Model')) { if (file_exists($modelFile)) { require_once $modelFile; if (isset($this->stack['action']['application_cache_path'])) { file_put_contents($this->stack['action']['application_cache_path'], __DEBUG__ ? file_get_contents($this->stack['action']['application_cache_path']) . mgGetScript(file_get_contents($modelFile)) : file_get_contents($this->stack['action']['application_cache_path']) . mgGetScript(php_strip_whitespace($modelFile))); } if (isset($this->stack['action']['application_config_path'])) { $files = array(); require $this->stack['action']['application_config_path']; $files[$modelFile] = filemtime($modelFile); mgExportArrayToFile($this->stack['action']['application_config_path'], $files, 'files'); } } else { if ($triggerException) { $this->throwException(E_MODELFILENOTEXISTS, $modelFile); } else { return NULL; } } } $object = $object . 'Model'; $tmp = new $object(); $this->globalModel[$model] = $tmp; mgTrace(false); mgDebug('Load Model', $tmp); return $tmp; } }