예제 #1
0
파일: table.php 프로젝트: vanie3/appland
 public static function getInstance($type, $prefix = 'MTable', $config = array())
 {
     // Sanitize and prepare the table class name.
     $type = preg_replace('/[^A-Z0-9_\\.-]/i', '', $type);
     $tableClass = $prefix . ucfirst($type);
     // Only try to load the class if it doesn't already exist.
     if (!class_exists($tableClass)) {
         // Search for the class file in the MTable include paths.
         mimport('framework.filesystem.path');
         MTable::addIncludePath(MPATH_MIWI . '/proxy/database/table');
         if ($path = MPath::find(MTable::addIncludePath(), strtolower($type) . '.php')) {
             // Import the class file.
             include_once $path;
             // If we were unable to load the proper class, raise a warning and return false.
             if (!class_exists($tableClass)) {
                 MError::raiseWarning(0, MText::sprintf('MLIB_DATABASE_ERROR_CLASS_NOT_FOUND_IN_FILE', $tableClass));
                 return false;
             }
         } else {
             // If we were unable to find the class file in the MTable include paths, raise a warning and return false.
             MError::raiseWarning(0, MText::sprintf('MLIB_DATABASE_ERROR_NOT_SUPPORTED_FILE_NOT_FOUND', $type));
             return false;
         }
     }
     // If a database object was passed in the configuration array use it, otherwise get the global one from MFactory.
     $db = isset($config['dbo']) ? $config['dbo'] : MFactory::getDbo();
     // Instantiate a new table class and return it.
     return new $tableClass($db);
 }
예제 #2
0
파일: storage.php 프로젝트: vanie3/appland
 public static function getInstance($handler = null, $options = array())
 {
     static $now = null;
     MCacheStorage::addIncludePath(MPATH_WP_CNT . '/miwi/framework/cache/storage');
     if (!isset($handler)) {
         $conf = MFactory::getConfig();
         $handler = $conf->get('cache_handler');
         if (empty($handler)) {
             return MError::raiseWarning(500, MText::_('MLIB_CACHE_ERROR_CACHE_HANDLER_NOT_SET'));
         }
     }
     if (is_null($now)) {
         $now = time();
     }
     $options['now'] = $now;
     $handler = strtolower(preg_replace('/[^A-Z0-9_\\.-]/i', '', $handler));
     $class = 'MCacheStorage' . ucfirst($handler);
     if (!class_exists($class)) {
         mimport('joomla.filesystem.path');
         if ($path = MPath::find(MCacheStorage::addIncludePath(), strtolower($handler) . '.php')) {
             include_once $path;
         } else {
             return MError::raiseWarning(500, MText::sprintf('MLIB_CACHE_ERROR_CACHE_STORAGE_LOAD', $handler));
         }
     }
     return new $class($options);
 }
예제 #3
0
 public static function getInstance($type = 'output', $options = array())
 {
     MCacheController::addIncludePath(MPATH_WP_CNT . '/miwi/framework/cache/controller');
     $type = strtolower(preg_replace('/[^A-Z0-9_\\.-]/i', '', $type));
     $class = 'MCacheController' . ucfirst($type);
     if (!class_exists($class)) {
         mimport('framework.filesystem.path');
         if ($path = MPath::find(MCacheController::addIncludePath(), strtolower($type) . '.php')) {
             include_once $path;
         } else {
             MError::raiseError(500, 'Unable to load Cache Controller: ' . $type);
         }
     }
     return new $class($options);
 }
예제 #4
0
파일: helper.php 프로젝트: vanie3/appland
 protected static function loadClass($entity, $type)
 {
     if (strpos($type, '.')) {
         list($prefix, $type) = explode('.', $type);
     } else {
         $prefix = 'M';
     }
     $class = MString::ucfirst($prefix, '_') . 'Form' . MString::ucfirst($entity, '_') . MString::ucfirst($type, '_');
     if (class_exists($class)) {
         return $class;
     }
     // Get the field search path array.
     $paths = MFormHelper::addPath($entity);
     // If the type is complex, add the base type to the paths.
     if ($pos = strpos($type, '_')) {
         // Add the complex type prefix to the paths.
         for ($i = 0, $n = count($paths); $i < $n; $i++) {
             // Derive the new path.
             $path = $paths[$i] . '/' . strtolower(substr($type, 0, $pos));
             // If the path does not exist, add it.
             if (!in_array($path, $paths)) {
                 $paths[] = $path;
             }
         }
         // Break off the end of the complex type.
         $type = substr($type, $pos + 1);
     }
     // Try to find the class file.
     $type = strtolower($type) . '.php';
     foreach ($paths as $path) {
         if ($file = MPath::find($path, $type)) {
             require_once $file;
             if (class_exists($class)) {
                 break;
             }
         }
     }
     // Check for all if the class exists.
     return class_exists($class) ? $class : false;
 }
예제 #5
0
파일: model.php 프로젝트: vanie3/appland
 public static function getInstance($type, $prefix = '', $config = array())
 {
     $type = preg_replace('/[^A-Z0-9_\\.-]/i', '', $type);
     $modelClass = $prefix . ucfirst($type);
     if (!class_exists($modelClass)) {
         mimport('framework.filesystem.path');
         $path = MPath::find(self::addIncludePath(null, $prefix), self::_createFileName('model', array('name' => $type)));
         if (!$path) {
             $path = MPath::find(self::addIncludePath(null, ''), self::_createFileName('model', array('name' => $type)));
         }
         if ($path) {
             require_once $path;
             if (!class_exists($modelClass)) {
                 MError::raiseWarning(0, MText::sprintf('MLIB_APPLICATION_ERROR_MODELCLASS_NOT_FOUND', $modelClass));
                 return false;
             }
         } else {
             return false;
         }
     }
     return new $modelClass($config);
 }
예제 #6
0
파일: html.php 프로젝트: vanie3/appland
 public static function _($key)
 {
     list($key, $prefix, $file, $func) = self::extract($key);
     if (array_key_exists($key, self::$registry)) {
         $function = self::$registry[$key];
         $args = func_get_args();
         // Remove function name from arguments
         array_shift($args);
         return MHtml::call($function, $args);
     }
     $className = $prefix . ucfirst($file);
     if (!class_exists($className)) {
         mimport('framework.filesystem.path');
         self::addIncludePath(MPATH_MIWI . '/proxy/html/html');
         if ($path = MPath::find(MHtml::$includePaths, strtolower($file) . '.php')) {
             require_once $path;
             if (!class_exists($className)) {
                 MError::raiseError(500, MText::sprintf('MLIB_HTML_ERROR_NOTFOUNDINFILE', $className, $func));
                 return false;
             }
         } else {
             MError::raiseError(500, MText::sprintf('MLIB_HTML_ERROR_NOTSUPPORTED_NOFILE', $prefix, $file));
             return false;
         }
     }
     $toCall = array($className, $func);
     if (is_callable($toCall)) {
         MHtml::register($key, $toCall);
         $args = func_get_args();
         // Remove function name from arguments
         array_shift($args);
         return MHtml::call($toCall, $args);
     } else {
         MError::raiseError(500, MText::sprintf('MLIB_HTML_ERROR_NOTSUPPORTED', $className, $func));
         return false;
     }
 }
예제 #7
0
파일: view.php 프로젝트: vanie3/appland
 public function loadHelper($hlp = null)
 {
     // Clean the file name
     $file = preg_replace('/[^A-Z0-9_\\.-]/i', '', $hlp);
     // Load the template script
     mimport('framework.filesystem.path');
     $helper = MPath::find($this->_path['helper'], $this->_createFileName('helper', array('name' => $file)));
     if ($helper != false) {
         // Include the requested template filename in the local scope
         include_once $helper;
     }
 }
예제 #8
0
파일: form.php 프로젝트: vanie3/appland
 public function loadFile($file, $reset = true, $xpath = false)
 {
     // Check to see if the path is an absolute path.
     if (!is_file($file)) {
         // Not an absolute path so let's attempt to find one using MPath.
         $file = MPath::find(self::addFormPath(), strtolower($file) . '.xml');
         // If unable to find the file return false.
         if (!$file) {
             return false;
         }
     }
     // Attempt to load the XML file.
     $xml = MFactory::getXML($file, true);
     return $this->load($xml, $reset, $xpath);
 }
예제 #9
0
파일: toolbar.php 프로젝트: vanie3/appland
 public function loadButtonType($type, $new = false)
 {
     $signature = md5($type);
     if (isset($this->_buttons[$signature]) && $new === false) {
         return $this->_buttons[$signature];
     }
     if (!class_exists('MButton')) {
         MError::raiseWarning('SOME_ERROR_CODE', MText::_('MLIB_HTML_BUTTON_BASE_CLASS'));
         return false;
     }
     $buttonClass = 'MButton' . $type;
     if (!class_exists($buttonClass)) {
         if (isset($this->_buttonPath)) {
             $dirs = $this->_buttonPath;
         } else {
             $dirs = array();
         }
         $file = MFilterInput::getInstance()->clean(str_replace('_', DIRECTORY_SEPARATOR, strtolower($type)) . '.php', 'path');
         mimport('framework.filesystem.path');
         if ($buttonFile = MPath::find($dirs, $file)) {
             include_once $buttonFile;
         } else {
             MError::raiseWarning('SOME_ERROR_CODE', MText::sprintf('MLIB_HTML_BUTTON_NO_LOAD', $buttonClass, $buttonFile));
             return false;
         }
     }
     if (!class_exists($buttonClass)) {
         //return	MError::raiseError('SOME_ERROR_CODE', "Module file $buttonFile does not contain class $buttonClass.");
         return false;
     }
     $this->_buttons[$signature] = new $buttonClass($this);
     return $this->_buttons[$signature];
 }
예제 #10
0
 protected function createView($name, $prefix = '', $type = '', $config = array())
 {
     // Clean the view name
     $viewName = preg_replace('/[^A-Z0-9_]/i', '', $name);
     $classPrefix = preg_replace('/[^A-Z0-9_]/i', '', $prefix);
     $viewType = preg_replace('/[^A-Z0-9_]/i', '', $type);
     // Build the view class name
     $viewClass = $classPrefix . $viewName;
     if (!class_exists($viewClass)) {
         mimport('framework.filesystem.path');
         $path = MPath::find($this->paths['view'], $this->createFileName('view', array('name' => $viewName, 'type' => $viewType)));
         if ($path) {
             require_once $path;
             if (!class_exists($viewClass)) {
                 MError::raiseError(500, MText::sprintf('MLIB_APPLICATION_ERROR_VIEW_CLASS_NOT_FOUND', $viewClass, $path));
                 return null;
             }
         } else {
             return null;
         }
     }
     return new $viewClass($config);
 }