/** * Sets new encryption options * * @param string|array $options (Optional) Encryption options * @return Zend_Filter_Encrypt */ public function setAdapter($options = null) { if (is_string($options)) { $adapter = $options; } else { if (isset($options['adapter'])) { $adapter = $options['adapter']; unset($options['adapter']); } else { $adapter = 'Mcrypt'; } } if (!is_array($options)) { $options = array(); } if (Zend_Loader::isReadable('Zend/Filter/Encrypt/' . ucfirst($adapter) . '.php')) { $adapter = 'Zend_Filter_Encrypt_' . ucfirst($adapter); } if (!class_exists($adapter)) { Zend_Loader::loadClass($adapter); } $this->_adapter = new $adapter($options); if (!$this->_adapter instanceof Zend_Filter_Encrypt_Interface) { require_once 'Zend/Filter/Exception.php'; throw new Zend_Filter_Exception("Encoding adapter '" . $adapter . "' does not implement Zend_Filter_Encrypt_Interface"); } return $this; }
/** * Load a controller class * * Attempts to load the controller class file from * {@link getControllerDirectory()}. If the controller belongs to a * module, looks for the module prefix to the controller class. * * @param string $className * @return string Class name loaded * @throws Zend_Controller_Dispatcher_Exception if class not loaded */ public function loadClass($className) { $finalClass = $className; if ($this->_defaultModule != $this->_curModule || $this->getParam('prefixDefaultModule')) { $finalClass = $this->formatClassName($this->_curModule, $className); } if (class_exists($finalClass, false)) { return $finalClass; } $fileName = $this->classToFilename($className); $loadFile = APPLICATION_PATH . '/../customization/modules/' . $this->_curModule . '/controllers/' . $fileName; if (Zend_Loader::isReadable($loadFile)) { include_once $loadFile; } else { $dispatchDir = $this->getDispatchDirectory(); $loadFile = $dispatchDir . DIRECTORY_SEPARATOR . $fileName; if (Zend_Loader::isReadable($loadFile)) { include_once $loadFile; } else { require_once 'Zend/Controller/Dispatcher/Exception.php'; throw new Zend_Controller_Dispatcher_Exception('Cannot load controller class "' . $className . '" from file "' . $loadFile . "'"); } } if (!class_exists($finalClass, false)) { require_once 'Zend/Controller/Dispatcher/Exception.php'; throw new Zend_Controller_Dispatcher_Exception('Invalid controller class ("' . $finalClass . '")'); } return $finalClass; }
/** * Defined by Zend_Validate_Interface * * Returns true if the mimetype of the file does not matche the given ones. Also parts * of mimetypes can be checked. If you give for example "image" all image * mime types will not be accepted like "image/gif", "image/jpeg" and so on. * * @param string $value Real file to check for mimetype * @param array $file File data from Zend_File_Transfer * @return boolean */ public function isValid($value, $file = null) { if ($file === null) { $file = array('type' => null, 'name' => $value); } // Is file readable ? //require_once 'Zend/Loader.php'; if (!Zend_Loader::isReadable($value)) { return $this->_throw($file, self::NOT_READABLE); } $this->_type = $this->_detectMimeType($value); if (empty($this->_type) && $this->_headerCheck) { $this->_type = $file['type']; } if (empty($this->_type)) { return $this->_throw($file, self::NOT_DETECTED); } $mimetype = $this->getMimeType(true); if (in_array($this->_type, $mimetype)) { return $this->_throw($file, self::FALSE_TYPE); } $types = explode('/', $this->_type); $types = array_merge($types, explode('-', $this->_type)); foreach ($mimetype as $mime) { if (in_array($mime, $types)) { return $this->_throw($file, self::FALSE_TYPE); } } return true; }
/** * Defined by Zend_Validate_Interface * * Returns true if the mimetype of the file does not matche the given ones. Also parts * of mimetypes can be checked. If you give for example "image" all image * mime types will not be accepted like "image/gif", "image/jpeg" and so on. * * @param string $value Real file to check for mimetype * @param array $file File data from Zend_File_Transfer * @return boolean */ public function isValid($value, $file = null) { // Is file readable ? require_once 'Zend/Loader.php'; if (!Zend_Loader::isReadable($value)) { return $this->_throw($file, self::NOT_READABLE); } if ($file !== null) { if (class_exists('finfo', false) && defined('MAGIC')) { $mime = new finfo(FILEINFO_MIME); $this->_type = $mime->file($value); unset($mime); } elseif (function_exists('mime_content_type') && ini_get('mime_magic.magicfile')) { $this->_type = mime_content_type($value); } else { $this->_type = $file['type']; } } if (empty($this->_type)) { return $this->_throw($file, self::NOT_DETECTED); } $mimetype = $this->getMimeType(true); if (in_array($this->_type, $mimetype)) { return $this->_throw($file, self::FALSE_TYPE); } $types = explode('/', $this->_type); $types = array_merge($types, explode('-', $this->_type)); foreach ($mimetype as $mime) { if (in_array($mime, $types)) { return $this->_throw($file, self::FALSE_TYPE); } } return true; }
/** * Defined by Zend_Validate_Interface * * Returns true if and only if the fileextension of $value is not included in the * set extension list * * @param string $value Real file to check for extension * @param array $file File data from Zend_File_Transfer * @return boolean */ public function isValid($value, $file = null) { // Is file readable ? // require_once 'Zend/Loader.php'; if (!Zend_Loader::isReadable($value)) { return $this->_throw($file, self::NOT_FOUND); } if ($file !== null) { $info['extension'] = substr($file['name'], strrpos($file['name'], '.') + 1); } else { $info = pathinfo($value); } $extensions = $this->getExtension(); if ($this->_case and !in_array($info['extension'], $extensions)) { return true; } else { if (!$this->_case) { $found = false; foreach ($extensions as $extension) { if (strtolower($extension) == strtolower($info['extension'])) { $found = true; } } if (!$found) { return true; } } } return $this->_throw($file, self::FALSE_EXTENSION); }
public function autoload($class) { if (substr($class, 0, 10) === 'ViewHelper') { $class = substr($class, 11); $path = APPLICATION_PATH . '/modules/' . MODULE_NAME . '/views/helpers/' . $class . '.php'; if (Zend_Loader::isReadable($path)) { @(include $path); return true; } } if (substr($class, -10) === 'Controller') { $path = APPLICATION_PATH . '/modules/' . MODULE_NAME . '/controllers/' . $class . '.php'; if (Zend_Loader::isReadable($path)) { @(include $path); return true; } } if (substr($class, -4) === 'Form') { $path = APPLICATION_PATH . '/modules/' . MODULE_NAME . '/forms/' . $class . '.php'; if (Zend_Loader::isReadable($path)) { @(include $path); return true; } } $paths = array(APPLICATION_PATH . '/modules/' . MODULE_NAME . '/models', APPLICATION_PATH . '/../library/Bbx/Vendor'); foreach ($paths as $p) { $classPath = $p . '/' . $class . '.php'; if (Zend_Loader::isReadable($classPath)) { @(include $classPath); return true; } } return false; }
/** * Pre-dispatch routine * * This will replace the default pre-dispatch routine and call * the action-level pre-dispatch function, if it exists. This * gives us more flexibility in controlling the process flow. * * @return void */ public function preDispatch() { // Get controller and action names $controller = $this->getRequest()->getControllerName(); $action = $this->getRequest()->getActionName(); // Automatically add CSS and JS $cssFiles = array('default.css', $controller . '.css', $controller . '/' . $action . '.css'); $cssPrintFiles = array('default.print.css', $controller . '.print.css', $controller . '/' . $action . '.print.css'); $headLink = $this->view->headLink(); foreach ($cssFiles as $file) { if (!Zend_Loader::isReadable(ZFE_Environment::getFilePath('/css/' . $file))) { continue; } $headLink->appendStylesheet('/css/' . $file, 'screen, print'); } foreach ($cssPrintFiles as $file) { if (!Zend_Loader::isReadable(ZFE_Environment::getFilePath('/css/' . $file))) { continue; } $headLink->appendStylesheet('/css/' . $file, 'print'); } $jsFiles = array('default.js', $controller . '.js', $controller . '/' . $action . '.js'); $headScript = $this->view->headScript(); foreach ($jsFiles as $file) { if (!Zend_Loader::isReadable(ZFE_Environment::getFilePath('/js/' . $file))) { continue; } $headScript->appendFile('/js/' . $file); } // Call the action's pre-function $func = 'pre' . ucfirst(strtolower($action)) . 'Action'; if (method_exists($this, $func)) { $this->{$func}(); } }
public function registerTranslation($langCode) { // we are certainly in LogStats mode, Zend is not loaded if (!class_exists('Zend_Loader')) { return; } $infos = $this->getInformation(); if (!isset($infos['translationAvailable'])) { $infos['translationAvailable'] = false; } $translationAvailable = $infos['translationAvailable']; if (!$translationAvailable) { return; } $name = $infos['name']; $path = "plugins/" . $name . "/lang/%s.php"; $defaultLangPath = sprintf($path, $langCode); $defaultEnglishLangPath = sprintf($path, 'en'); $translations = array(); if (Zend_Loader::isReadable($defaultLangPath)) { require $defaultLangPath; } elseif (Zend_Loader::isReadable($defaultEnglishLangPath)) { require $defaultEnglishLangPath; } else { throw new Exception("Language file not found for the plugin '{$name}'."); } Piwik_Translate::getInstance()->addTranslationArray($translations); }
public static function getActions($filter = false, $module, $controller) { $controller = ucfirst($controller) . 'Controller.php'; $loadFile = _BASE_PATH . 'application/modules/' . $module . '/controllers/' . $controller; if (Zend_Loader::isReadable($loadFile)) { /** @noinspection PhpIncludeInspection */ include_once $loadFile; } if ($module == 'default') { $controller = substr($controller, 0, -4); } else { $controller = ucfirst($module) . '_' . substr($controller, 0, -4); } $res = array(); try { $reflection = new ReflectionClass($controller); $methods = $reflection->getMethods(ReflectionMethod::IS_PUBLIC); foreach ($methods as $method) { $method = $method->name; if (false !== strpos($method, 'Action')) { $name = str_replace('Action', '', $method); $res[$name] = $name; } } } catch (ReflectionException $e) { //TODO $x = 1; } return $res; }
public function direct($options = array()) { // Set default options as to where the CSS and JS directories are if (is_null($this->_options)) { $this->_options = $this->_defaultOptions; } // Merge passed options with default options $this->_options = array_merge($this->_defaultOptions, $options); // Store basename here $basename = 'bootstrap'; $css = $basename . '.css'; $js = $basename . '.js'; // Check if minified versions exist for production environment if ($this->_options['minified']) { $cssPath = $_SERVER['DOCUMENT_ROOT'] . $this->_options['css']; if (Zend_Loader::isReadable($cssPath . '/' . $basename . '.min.css')) { $css = $basename . '.min.css'; } $jsPath = $_SERVER['DOCUMENT_ROOT'] . $this->_options['js']; if (Zend_Loader::isReadable($jsPath . '/' . $basename . '.min.js')) { $js = $basename . '.min.js'; } } // Add files to view $controller = $this->getActionController(); $controller->view->headLink()->appendStylesheet($this->_options['css'] . '/' . $css); $controller->view->headScript()->appendFile($this->_options['js'] . '/' . $js); }
/** * Returns TRUE if module and controller pair can be dispatched to * * @param Zend_Controller_Request_Abstract $action * @return boolean */ public function isControllerDispatchable($moduleName, $controllerName) { $dirs = $this->getFrontController()->getControllerDirectory(); if (!$this->isValidModule($moduleName)) { return false; } $path = $dirs[$moduleName] . DIRECTORY_SEPARATOR . $this->classToFilename($this->formatControllerName($controllerName)); return Zend_Loader::isReadable($path); }
public function getPhpImageSize() { if (is_null($this->_phpImageSize)) { if (!Zend_Loader::isReadable($this->getFileName())) { throw new Exception("Cannot read image information from {$this->getFileName()}"); } $this->_phpImageSize = getimagesize($this->getFileName()); } return $this->_phpImageSize; }
protected function _initAutoLoader() { set_include_path(implode(PATH_SEPARATOR, array(APPLICATION_PATH . "/models", get_include_path()))); spl_autoload_register(function ($className) { //Write a very simple custom autoloader for models... if (Zend_Loader::isReadable("{$className}.php")) { require_once "{$className}.php"; } }); }
public static function autoload($className) { if (Zend_Loader::isReadable("{$className}.php")) { require_once "{$className}.php"; } else { if (Zend_Loader::isReadable("tables/{$className}.php")) { require_once "tables/{$className}.php"; } } }
/** * Расширяем диспетчер для функционала описанного в методе loadClass * * @param Zend_Controller_Request_Abstract $action * @return boolean */ public function isDispatchable(Zend_Controller_Request_Abstract $request) { $isDispatchable = parent::isDispatchable($request); if (!$isDispatchable) { $className = $this->getControllerClass($request); $systemControllerDir = $this->_modulesControllerDirectory(); $isDispatchable = Zend_Loader::isReadable($systemControllerDir . DS . $this->classToFilename($className)); } return $isDispatchable; }
public function __construct($application) { parent::__construct($application); if (isset($this->_file)) { // load config file $configFile = dirname($this->_file) . '/configs/config.php'; if (Zend_Loader::isReadable($configFile)) { // Set this bootstrap options $this->setOptions(include $configFile); } } }
/** * Returns the DataTable associated to the output format $name * * @throws exception If the renderer is unknown * @return Piwik_DataTable_Renderer */ public static function factory($name) { $name = ucfirst(strtolower($name)); $path = "DataTable/Renderer/" . $name . ".php"; $className = 'Piwik_DataTable_Renderer_' . $name; if (Piwik_Common::isValidFilename($name) && Zend_Loader::isReadable($path)) { require_once $path; return new $className(); } else { throw new Exception("Renderer format '{$name}' not valid. Try 'xml' or 'json' or 'csv' or 'html' or 'php' or 'original' instead."); } }
/** * Registers the API information of a given module. * * The module to be registered must be * - extending the Piwik_Apiable class * - a singleton (providing a getInstance() method) * - the API file must be located in plugins/ModuleName/API.php * for example plugins/Referers/API.php * * The method will introspect the methods, their parameters, etc. * * @param string ModuleName eg. "UserSettings" */ public function registerClass($fileName) { if (isset($this->alreadyRegistered[$fileName])) { return; } $potentialPaths = array("plugins/" . $fileName . "/API.php"); $found = false; foreach ($potentialPaths as $path) { if (Zend_Loader::isReadable($path)) { require_once $path; $found = true; break; } } if (!$found) { throw new Exception("API module {$fileName} not found."); } $class = $this->getClassNameFromModule($fileName); $rClass = new ReflectionClass($class); // check that it is a subclass of Piwik_APIable if (!$rClass->isSubclassOf(new ReflectionClass("Piwik_Apiable"))) { throw new Exception("To publish its public methods in the API, the class '{$class}' must be a subclass of 'Piwik_Apiable'."); } // check that is is singleton $this->checkClassIsSingleton($class); $rMethods = $rClass->getMethods(); foreach ($rMethods as $method) { // use this trick to read the static attribute of the class // $class::$methodsNotToPublish doesn't work $variablesClass = get_class_vars($class); $variablesClass['methodsNotToPublish'][] = 'getInstance'; if ($method->isPublic() && !$method->isConstructor() && !in_array($method->getName(), $variablesClass['methodsNotToPublish'])) { $name = $method->getName(); $parameters = $method->getParameters(); $aParameters = array(); foreach ($parameters as $parameter) { $nameVariable = $parameter->getName(); $defaultValue = Piwik_API_Proxy::NO_DEFAULT_VALUE; if ($parameter->isDefaultValueAvailable()) { $defaultValue = $parameter->getDefaultValue(); } $aParameters[$nameVariable] = $defaultValue; } $this->api[$class][$name]['parameters'] = $aParameters; $this->api[$class][$name]['numberOfRequiredParameters'] = $method->getNumberOfRequiredParameters(); } } $this->alreadyRegistered[$fileName] = true; }
public function isValid($value, $file = null) { require_once 'Zend/Loader.php'; if (is_string($value)) { $value = array($value); } $min = $this->getMin(true); $max = $this->getMax(true); $size = $this->_getSize(); foreach ($value as $files) { // Is file readable ? if (!Zend_Loader::isReadable($files)) { $this->_throw($file, self::NOT_READABLE); continue; } if (!isset($this->_files[$files])) { $this->_files[$files] = $files; } else { // file already counted... do not count twice continue; } // limited to 2GB files $size += @filesize($files); $this->_setSize($size); if ($max !== null && $max < $size) { if ($this->useByteString()) { $this->setMax($this->_toByteString($max)); $this->_throw($file, self::TOO_BIG); $this->setMax($max); } else { $this->_throw($file, self::TOO_BIG); } } } // Check that aggregate files are >= minimum size if ($min !== null && $size < $min) { if ($this->useByteString()) { $this->setMin($this->_toByteString($min)); $this->_throw($file, self::TOO_SMALL); $this->setMin($min); } else { $this->_throw($file, self::TOO_SMALL); } } if (count($this->_messages) > 0) { return false; } return true; }
/** * Sets a new adapter * * @param string $adapter Adapter to use * @param boolean $direction OPTIONAL False means Download, true means upload * @param array $options OPTIONAL Options to set for this adapter * @throws Zend_File_Transfer_Exception */ public function setAdapter($adapter, $direction = false, $options = array()) { if (Zend_Loader::isReadable('Zend/File/Transfer/Adapter/' . ucfirst($adapter) . '.php')) { $adapter = 'Zend_File_Transfer_Adapter_' . ucfirst($adapter); } if (!class_exists($adapter)) { Zend_Loader::loadClass($adapter); } $direction = (int) $direction; $this->_adapter[$direction] = new $adapter($options); if (!$this->_adapter[$direction] instanceof Zend_File_Transfer_Adapter_Abstract) { throw new Zend_File_Transfer_Exception("Adapter " . $adapter . " does not extend Zend_File_Transfer_Adapter_Abstract"); } return $this; }
/** * Добавляем путь к view с учётом проверки есть ли уже путь * * @param string $path */ public static function addBasePath($path) { $_view = Zend_Layout::startMvc()->getView(); $inView = $_view->getScriptPaths(); // не добавляем шаблоны если они уже были ранее добавлены $add = true; foreach ($inView as $in_view_dir) { if (stristr($in_view_dir, $path)) { $add = false; } } if ($add && Zend_Loader::isReadable($path)) { $_view->addBasePath($path . '/App/views/'); } }
/** * Sets a new adapter * * @param string $adapter Adapter to use * @param string|array $data Translation data * @param string|Zend_Locale $locale OPTIONAL locale to use * @param array $options OPTIONAL Options to use * @throws Zend_Translate_Exception */ public function setAdapter($adapter, $data, $locale = null, array $options = array()) { if (Zend_Loader::isReadable('Zend/Translate/Adapter/' . ucfirst($adapter) . '.php')) { $adapter = 'Zend_Translate_Adapter_' . ucfirst($adapter); } Zend_Loader::loadClass($adapter); if (self::$_cache !== null) { call_user_func(array($adapter, 'setCache'), self::$_cache); } $this->_adapter = new $adapter($data, $locale, $options); if (!$this->_adapter instanceof Zend_Translate_Adapter) { require_once 'Zend/Translate/Exception.php'; throw new Zend_Translate_Exception("Adapter " . $adapter . " does not extend Zend_Translate_Adapter"); } }
/** * Returns true if and only if the fileextension of $value is included in * the set extension list. * * @param string $value Real file to check for extension. * @param array $file File data from Zend_File_Transfer. * @return boolean */ public function isValid($value, $file = null) { // Is file readable ? require_once 'Zend/Loader.php'; if (!Zend_Loader::isReadable($value)) { return $this->_throw($file, self::NOT_FOUND); } if ($file !== null) { $info['extension'] = substr($file['name'], strrpos($file['name'], '.') + 1); } else { $info = pathinfo($value); } //set the target extension $this->_targetExtension = $info['extension']; return parent::isValid($value, $file); }
/** * Defined by Zend_Validate_Interface * * Returns true if and only if the counted words are at least min and * not bigger than max (when max is not null). * * @param string $value Filename to check for word count * @param array $file File data from Zend_File_Transfer * @return boolean */ public function isValid($value, $file = null) { // Is file readable ? if (!Zend_Loader::isReadable($value)) { return $this->_throw($file, self::NOT_FOUND); } $content = file_get_contents($value); $this->_count = str_word_count($content); if ($this->_max !== null && $this->_count > $this->_max) { return $this->_throw($file, self::TOO_MUCH); } if ($this->_min !== null && $this->_count < $this->_min) { return $this->_throw($file, self::TOO_LESS); } return true; }
public function isValid($value, $file = null) { if ($file === null) { $file = array('type' => null, 'name' => $value); } // Is file readable ? require_once 'Zend/Loader.php'; if (!Zend_Loader::isReadable($value)) { return $this->_throw($file, self::NOT_READABLE); } $mimefile = $this->_magicfile; if (class_exists('finfo', false)) { $const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME; if (!empty($mimefile) && empty($this->_finfo)) { $this->_finfo = @finfo_open($const, $mimefile); } if (empty($this->_finfo)) { $this->_finfo = @finfo_open($const); } $this->_type = null; if (!empty($this->_finfo)) { $this->_type = finfo_file($this->_finfo, $value); } } if (empty($this->_type) && (function_exists('mime_content_type') && ini_get('mime_magic.magicfile'))) { $this->_type = mime_content_type($value); } if (empty($this->_type) && $this->_headerCheck) { $this->_type = $file['type']; } if (empty($this->_type)) { return $this->_throw($file, self::NOT_DETECTED); } $mimetype = $this->getMimeType(true); if (in_array($this->_type, $mimetype)) { return true; } $types = explode('/', $this->_type); $types = array_merge($types, explode('-', $this->_type)); $types = array_merge($types, explode(';', $this->_type)); foreach ($mimetype as $mime) { if (in_array($mime, $types)) { return true; } } return $this->_throw($file, self::FALSE_TYPE); }
/** * Builds the Config object, given the optional path for the user INI file * If not specified, it will use the default path * * @param string $pathIniFileUserConfig */ function __construct($pathIniFileUserConfig = null) { Zend_Registry::set('config', $this); $this->pathIniFileDefaultConfig = 'config/global.ini.php'; if (is_null($pathIniFileUserConfig)) { $this->pathIniFileUserConfig = self::getDefaultUserConfigPath(); } else { $this->pathIniFileUserConfig = $pathIniFileUserConfig; } $this->defaultConfig = new Zend_Config_Ini($this->pathIniFileDefaultConfig, null, true); if (!Zend_Loader::isReadable($this->pathIniFileUserConfig)) { throw new Exception("The configuration file {$this->pathIniFileUserConfig} has not been found."); } $this->userConfig = new Zend_Config_Ini($this->pathIniFileUserConfig, null, true); // see http://bugs.php.net/bug.php?id=34206 $this->correctCwd = getcwd(); }
/** * Dispatches the request to the right plugin and executes the requested action on the plugin controller. * * @throws Exception in case the plugin doesn't exist, the action doesn't exist, there is not enough permission, etc. * * @param string $module * @param string $action * @param array $parameters * @return mixed The returned value of the calls, often nothing as the module print but don't return data * @see fetchDispatch() */ function dispatch($module = null, $action = null, $parameters = null) { if (self::$enableDispatch === false) { return; } if (is_null($module)) { $defaultModule = 'CoreHome'; $module = Piwik_Common::getRequestVar('module', $defaultModule, 'string'); } if (is_null($action)) { $action = Piwik_Common::getRequestVar('action', false); } if (is_null($parameters)) { $parameters = array(); } if (!ctype_alnum($module)) { throw new Exception("Invalid module name '{$module}'"); } if (!Piwik_PluginsManager::getInstance()->isPluginActivated($module)) { throw new Piwik_FrontController_PluginDeactivatedException($module); } $controllerClassName = 'Piwik_' . $module . '_Controller'; // FrontController's autoloader if (!class_exists($controllerClassName, false)) { $moduleController = PIWIK_INCLUDE_PATH . '/plugins/' . $module . '/Controller.php'; if (!Zend_Loader::isReadable($moduleController)) { throw new Exception("Module controller {$moduleController} not found!"); } require_once $moduleController; // prefixed by PIWIK_INCLUDE_PATH } $controller = new $controllerClassName(); if ($action === false) { $action = $controller->getDefaultAction(); } if (!is_callable(array($controller, $action))) { throw new Exception("Action {$action} not found in the controller {$controllerClassName}."); } try { return call_user_func_array(array($controller, $action), $parameters); } catch (Piwik_Access_NoAccessException $e) { Piwik_PostEvent('FrontController.NoAccessException', $e); } }
public function isValid($value, $file = null) { // Is file readable ? require_once 'Zend/Loader.php'; if (!Zend_Loader::isReadable($value)) { return $this->_throw($file, self::NOT_FOUND); } $hashes = array_unique(array_keys($this->_hash)); $filehash = hash_file('md5', $value); if ($filehash === false) { return $this->_throw($file, self::NOT_DETECTED); } foreach ($hashes as $hash) { if ($filehash === $hash) { return true; } } return $this->_throw($file, self::DOES_NOT_MATCH); }
public function __construct() { $this->lockFile = BASE_DIR . '/data/cache/__run_lock'; $this->jobData = array(); try { if (!Zend_Loader::isReadable(self::$DATA_FILE, BASE_DIR . '/data/cache')) { throw new Zend_Exception("Scheduled task cache not found"); } Zend_Loader::loadFile(self::$DATA_FILE, BASE_DIR . '/data/cache', null, true); global $__SCHEDULE_CACHE; if (isset($__SCHEDULE_CACHE)) { $this->jobData = $__SCHEDULE_CACHE; } else { $this->jobData = array(); } } catch (Zend_Exception $e) { // So create the cache dammit! } $this->lastRun = ifset($this->jobData, 'last_run', 0); }
/** * Load a model class and return an object instance * * @param string $model * @param string $module Use explicitly named module * @return object */ public function getModel($model, $module = null) { $model = preg_replace_callback('/(\\b|_)([a-z])/i', create_function('$m', 'return $m[1].strtoupper($m[2]);'), $model); $module = $module === null ? $this->_getModuleName() : $module; $className = 'Model_' . $model; if ('default' != $module) { $className = ucfirst($module) . '_' . $className; } if (class_exists($className, false)) { return new $className(); } $modulePath = $this->_getModulePath($module); $modelFileName = str_replace('_', '/', $model); $modelFileName = $modulePath . '/models/' . $modelFileName . '.php'; if (!Zend_Loader::isReadable($modelFileName)) { throw new Exception(sprintf('Invalid model (%s) specified; model class file (%s) not found', $model, $modelFileName)); } Zend_Loader::loadFile($modelFileName); return new $className(); }