/**
  * Returns the current version of pLog, determined by the value of the $version
  * variable in the version.php file.
  * If the file is not available, the result is unknown.
  * @static
  * @return The version identifier.
  */
 function getVersion()
 {
     $versionFile = PLOG_CLASS_PATH . "version.php";
     if (File::isReadable($versionFile)) {
         include_once $versionFile;
     } else {
         $version = "UNKNOWN";
     }
     return $version;
 }
 function validate($data)
 {
     // check the rules created in the constructor
     if (!parent::validate($data)) {
         return false;
     }
     // and if they succeeded, check if the file exists. If not, return false
     // and go to the main page...
     $filePath = "templates/summary/{$data}.template";
     return File::isReadable($filePath);
 }
 function LoggerConfigLoader($defaultFilePath = LOGGER_DEFAULT_CONFIG_FILE_PATH)
 {
     // load the config file if it is readable
     if (File::isReadable($defaultFilePath)) {
         include_once $defaultFilePath;
         $this->_keys = $config;
     } else {
         throw new Exception("There was an error loading logger config file: {$defaultFilePath}");
         die;
     }
 }
Example #4
0
 /**
  * Construct the iterator with a file instance
  * @param File $file Instance of a file object.
  * @throws \InvalidArgumentException
  */
 public function __construct(File $file)
 {
     if (!$file->exists()) {
         throw new \InvalidArgumentException('The file "' . $file->getPath() . '" does not exist');
     }
     if (!$file->isReadable()) {
         throw new \InvalidArgumentException('The file "' . $file->getPath() . '" is not readable.');
     }
     $this->file = $file;
     $this->file->open('r');
 }
 /**
  * Reloads the contents from the configuration file.
  *
  * @return Returns true if successul or false otherwise
  */
 function reload()
 {
     if (File::isReadable($this->_configFile)) {
         include $this->_configFile;
         $this->_props = new Properties($config);
         $result = true;
     } else {
         $this->_props = new Properties();
         $result = false;
     }
     return $result;
 }
 /**
  * Loads a plugin locale file from disk
  *
  * @private
  */
 function _loadLocaleFile()
 {
     $fileName = PLOG_CLASS_PATH . "plugins/" . $this->_pluginId . "/locale/locale_" . $this->_code . ".php";
     if (File::isReadable($fileName)) {
         include $fileName;
     }
     // The following is just to handle the case where a plugin doesn't
     // have a valid local file.
     if (!isset($messages) || !is_array($messages)) {
         $messages = array();
     }
     $this->_messages = $messages;
 }
 /**
  * Returns true if the template is a valid template set
  */
 function validate()
 {
     // first of all, check that the folder exists
     if (!File::isDir($this->_fullName)) {
         return ERROR_TEMPLATE_NOT_INSIDE_FOLDER;
     }
     // now check that all the basic files are available
     foreach ($this->_basicFiles as $basicFile) {
         if (!File::isReadable($this->_fullName . $basicFile)) {
             return ERROR_MISSING_BASE_FILES;
         }
     }
     return true;
 }
 function findBinary($binary, $searchFolders)
 {
     if ($searchFolders == null) {
         $searchFolders = array($this->_folder);
     }
     $found = false;
     $i = 0;
     while (!$found && $i < count($searchFolders)) {
         // get the current folder
         $currentFolder = $searchFolders[$i];
         // see if the file's there
         $fullPath = $currentFolder . $binary;
         if (File::isReadable($fullPath)) {
             $found = true;
         } else {
             $i++;
         }
     }
     if ($found) {
         return $fullPath;
     } else {
         return "";
     }
 }
 /**
  * Sets the folder where sessions should be saved, in case we'd like to save
  * them somewhere else. This class will check the config parameter <b>session_save_path</b>: if
  * it's not empty, it will use its value as the name of the folder where sessions should be saved, and it
  * will also take care of creating the folder if it does not exist. If the folder exists but it cannot
  * be read, it will throw an exception and quit (because this is a big issue)
  * If the value of this parameter is empty, it will not do anything and use PHP's default settings for this.
  *
  * @static
  */
 function setSessionSavePath()
 {
     $config =& Config::getConfig();
     $sessionFolder = $config->getValue("session_save_path");
     // do we need to do anything if we are using the default
     // session path?  PHP defaults to /tmp/, so there isn't
     // anything to do
     if (isset($sessionFolder)) {
         if (!File::exists($sessionFolder)) {
             // create folder with only user permissions
             // since we want to protect the session data
             if (!File::createDir($sessionFolder, 0700)) {
                 throw new Exception("Sessions should be " . "saved in {$sessionFolder} but it " . "doesn't exist and I can't create it!");
                 die;
             }
         }
         // check if the folder is accessible
         if (!File::isReadable($sessionFolder) || !File::isWritable($sessionFolder)) {
             if (!File::chMod($sessionFolder, 0700)) {
                 throw new Exception("Sessions should be " . "saved in {$sessionFolder} but it is " . "not accessible!");
                 die;
             }
         }
         // if everything ok, we can continue...
         session_save_path($sessionFolder);
     }
     return true;
 }
 /**
  * Makes sure that the file is a valid template set. The file can be packed
  * in any of the formats supported by the Unpacker class (.tar.gz, .tar.bz2
  * and .zip as of the time of writing these lines)
  * Returns true if the template is valid or a negative value carrying an
  * error code.
  *
  * @param file The file that contains the template set
  * @return Returns true (positive value) if template set is ok or a negative
  * value otherwise.
  */
 function checkTemplateSet($file, $filePath)
 {
     // get the temporary folder
     $config =& Config::getConfig();
     $tmpFolder = $config->getValue('temp_folder');
     if ($tmpFolder[strlen($tmpFolder) - 1] != '/') {
         $tmpFolder .= '/';
     }
     // get the name of the file, which we will use in many places
     $fileNameParts = explode('.', $file);
     $fileNameNoExt = $fileNameParts[0];
     // create our working folder
     $workFolder = $tmpFolder . File::getTempName() . '/';
     if (!File::createDir($workFolder, 0777)) {
         return TEMPLATE_SANDBOX_ERROR_CREATING_WORKING_FOLDER;
     }
     // now we can unpack the file to the temporary folder
     $unpacker = new Unpacker();
     if (!$unpacker->unpack($filePath . $file, $workFolder)) {
         $this->cleanUp($workFolder . $fileNameNoExt);
         if (File::exists($workFolder)) {
             File::delete($workFolder);
         }
         return TEMPLATE_SANDBOX_ERROR_UNPACKING;
     }
     // if the file was correctly unpacked, now we will need the TemplateValidator
     // class to do some work for us
     $fileNameParts = explode('.', $file);
     $fileNameNoExt = $fileNameParts[0];
     // we can use the checkTenmplateFolder which will do all the rest of
     // the work for us...
     $res = $this->checkTemplateFolder($fileNameNoExt, $workFolder);
     if ($res < 0) {
         //$this->cleanUp( $workFolder.$fileNameNoExt );
         $this->cleanUp($workFolder);
         if (File::isReadable($workFolder) && File::isDir($workFolder)) {
             File::delete($workFolder);
         }
         return $res;
     }
     $this->cleanUp($workFolder . $fileNameNoExt);
     File::delete($workFolder);
     return true;
 }
 /**
  * dynamically loads a layout formatter
  *
  * @param appenderName
  * @return a qLayout class
  */
 function createAppenderInstance($appender, $layout, $properties)
 {
     $appenderClassName = $appender . "appender";
     $appenderClassFile = PLOG_CLASS_PATH . "class/logger/appender/" . $appenderClassName . ".class.php";
     // load the class but first check if it exists...
     if (!File::isReadable($appenderClassFile)) {
         throw new Exception("Cannot find an appender suitable for appender type '{$appender}'");
         die;
     }
     // if so, load the class and create an object
     include_once $appenderClassFile;
     $appender = new $appenderClassName($layout, $properties);
     return $appender;
 }
 /**
  * Loads classes from disk using the list of folders that has been provided 
  * via ResourceClassLoader::addSearchFolder() The class will go through all the folders where 
  * classes can be located and if it can be found, it will proceed to load it. 
  * If not, an exception will be thrown
  * 
  * @param actionClassName name of the class that we are going to load, <b>without the class suffix</b>
  * @return True if successful
  */
 function load($actionClassName)
 {
     //foreach( $this->_paths as $path ) {
     $i = 0;
     $loaded = false;
     while ($i < count($this->_paths) && !$loaded) {
         // get the current folder
         $path = $this->_paths[$i];
         // build up the file name
         $fileName = $path . strtolower($actionClassName) . $this->_classFileSuffix;
         // and see if it exists and can be loaded
         if (File::exists($fileName) && File::isReadable($fileName)) {
             include_once $fileName;
             $loaded = true;
         }
         // increase the counter
         $i++;
     }
     // did we load anything??
     if (!$loaded) {
         throw new Exception("Could not load {$actionClassName}!");
         die;
     }
     // otherwise return everything ok!
     return true;
 }
 /**
  * returns true if the template set has a screenshot available in disk
  *
  * @param templateName The name of the template
  * @param blogId If the template is blog specific, then the blog id and if it is global, then
  * '0' or no parameeter
  */
 function isScreenshotAvailable($templateName, $blogId = 0)
 {
     // build up the path to the screenshot file
     $templatePath = $this->getTemplateFolder($templateName, $blogId);
     // and return whether it is available or not
     $screenshotPath = $templatePath . "/screenshot.jpg";
     return File::isReadable($screenshotPath);
 }
 /**
  * returns an stream of data with the contents of the file. This method is used by 
  * getData(), getPreviewData and getMediumSizePreviewData()
  *
  * @return The contents of the given file or nothing if empty or if it can't be read
  * @private
  */
 function _getData($file)
 {
     if (File::isReadable($file)) {
         $file = new File($file);
         $file->open("rb");
         $size = $file->getSize();
         return $file->read($size);
     } else {
         return false;
     }
 }
 /**
  * adds a resource to the gallery when the resource is already stored on disk, instead of
  * it coming from an upload as it usually happens. This method is better than 
  * GalleryResources::addResource() when instead of dealing with uploaded files, the file
  * is already in disk and all that is left to do is to add it to the database.
  *
  * @param ownerId
  * @param albumId
  * @param description
  * @param fullFilePath The real path where the file is stored. This is expected to be
  * its final and permanent destination
  * @return It will return one of the following constants:
  * - GALLERY_ERROR_RESOURCE_TOO_BIG
  * - GALLERY_ERROR_RESOURCE_FORBIDDEN_EXTENSION
  * - GALLERY_ERROR_QUOTA_EXCEEDED
  * - GALLERY_ERROR_ADDING_RESOURCE
  * - GALLERY_ERROR_UPLOADS_NOT_ENABLED
  * or the identifier of the resource that was just added if the operation succeeded.
  */
 function addResourceFromDisk($ownerId, $albumId, $description, $fullFilePath)
 {
     // check if quotas are enabled, and if this file would make us go
     // over the quota
     if (GalleryResourceQuotas::isBlogOverResourceQuota($ownerId, File::getSize($fullFilePath))) {
         return GALLERY_ERROR_QUOTA_EXCEEDED;
     }
     $fileName = basename($fullFilePath);
     $filePath = dirname($fullFilePath);
     // get the metadata
     $getId3 = new GetID3();
     $metadata = $getId3->analyze($fullFilePath);
     // nifty helper method from the getid3 package
     getid3_lib::CopyTagsToComments($metadata);
     $resourceType = $this->_getResourceType($fullFilePath, $metadata);
     $info = $this->_filterMetadata($metadata, $resourceType);
     // set the flags
     $flags = 0;
     if ($resourceType == GALLERY_RESOURCE_IMAGE) {
         $flags = $flags | GALLERY_RESOURCE_PREVIEW_AVAILABLE;
     }
     // add the record to the database
     $resourceId = $this->addResourceToDatabase($ownerId, $albumId, $description, $flags, $resourceType, $filePath, $fileName, $metadata);
     if (!$resourceId) {
         return false;
     }
     // and finally move the file to the right place in disk
     // move the file to disk
     $storage = new GalleryResourceStorage();
     $resFile = $storage->storeFile($resourceId, $ownerId, $fullFilePath, RESOURCE_STORAGE_STORE_MOVE);
     // if the file cannot be read, we will also remove the record from the
     // database so that we don't screw up
     $fileReadable = File::isReadable($resFile);
     if (!$resFile || $resFile < 0 || !$fileReadable) {
         // if something went wrong, we should not keep the record in the db
         $query = "DELETE FROM " . $this->getPrefix() . "gallery_resources\n                          WHERE id = {$resourceId}";
         $this->Execute($query);
         return $resFile;
     }
     // and finally, we can generate the thumbnail only if the file is an image, of course :)
     if ($resourceType == GALLERY_RESOURCE_IMAGE) {
         $this->generateResourceThumbnail($resFile, $resourceId, $ownerId);
     }
     // return the id of the resource we just added
     return $resourceId;
 }
 /**
  * Adds a new locale to the list of available/supported locale. It checks to make
  * sure that the file exists and that has proper access permissions.
  *
  * @param localeCode the code of the locale we'd like to add.
  * @return Returns true if the file was successfully added or false otherwise.
  */
 function addLocale($localeCode)
 {
     $config =& Config::getConfig();
     // if the locale is already there, there is no need to add it,
     // since the user is *maybe* just updating the file.
     if ($this->isValidLocale($localeCode)) {
         return true;
     }
     $fileName = $this->getLocaleFilename($localeCode);
     // make sure that the file exists and can be read and
     // give up if not so
     if (!File::isReadable($fileName)) {
         return false;
     }
     // otherwise, we can happily add it to the list of supported locales
     $availableLocales = $this->getAvailableLocales();
     array_push($availableLocales, $localeCode);
     $config->saveValue("locales", $availableLocales);
     return true;
 }
Example #17
0
//ini_set('memory_limit', "16M");
if (!defined("PLOG_CLASS_PATH")) {
    define("PLOG_CLASS_PATH", dirname(__FILE__) . "/");
}
include_once PLOG_CLASS_PATH . "class/controller/blogcontroller.class.php";
include_once PLOG_CLASS_PATH . "class/net/http/session/sessionmanager.class.php";
include_once PLOG_CLASS_PATH . "class/dao/userinfo.class.php";
include_once PLOG_CLASS_PATH . "class/dao/bloginfo.class.php";
include_once PLOG_CLASS_PATH . "class/plugin/pluginmanager.class.php";
// just to make php use &amp; as the separator when adding the PHPSESSID
// variable to our requests
ini_set("arg_seperator.output", "&amp;");
ini_set("magic_quotes_runtime", 0);
//
// a security check, or else people might forget to remove the wizard.php script
//
if (File::isReadable("wizard.php")) {
    print "<span style=\"color:red\">The wizard.php script has to be removed after the installation process.</span><br/><br/>\n               Please remove it first to continue.";
    die;
}
// initialize the session
SessionManager::init();
$controller = new BlogController();
// load the plugins, this needs to be done *before* we call the
// Controller::process() method, as some of the plugins _might_
// add new actions to the controller
$pluginManager =& PluginManager::getPluginManager();
$pluginManager->loadPlugins();
// give control to the, ehem, controller :)
$controller->process(HttpVars::getRequest(), "op");
//xdebug_dump_function_profile(4);
 /**
  * returns true if the plugin provides the requested locale
  *
  * @param pluginId The plugin identifier that we're like to check
  * @param localeCode the locale code
  * @return True if the plugin has this locale or false otherwise
  * @static
  */
 function pluginHasLocale($pluginId, $localeCode)
 {
     return File::isReadable("plugins/{$pluginId}/locale/locale_{$localeCode}.php");
 }
 /**
  * removes a directory, optinally in a recursive fashion
  *
  * @param dirName
  * @param recursive Whether to recurse through all subdirectories that
  * are within the given one and remove them.
  * @param onlyFiles If the recursive mode is enabled, setting this to 'true' will
  * force the method to only remove files but not folders. The directory will not be
  * removed but all the files included it in (and all subdirectories) will be.
  * @return True if successful or false otherwise
  * @static
  */
 function deleteDir($dirName, $recursive = false, $onlyFiles = false)
 {
     // if the directory can't be read, then quit with an error
     if (!File::isReadable($dirName) || !File::exists($dirName)) {
         return false;
     }
     // if it's not a file, let's get out of here and transfer flow
     // to the right place...
     if (!File::isDir($dirName)) {
         return File::delete($dirName);
     }
     // Glob::myGlob is easier to use than Glob::glob, specially when
     // we're relying on the native version... This improved version
     // will automatically ignore things like "." and ".." for us,
     // making it much easier!
     $files = Glob::myGlob($dirName, "*");
     foreach ($files as $file) {
         if (File::isDir($file)) {
             // perform a recursive call if we were allowed to do so
             if ($recursive) {
                 File::deleteDir($file, $recursive, $onlyFiles);
             }
         }
         // File::delete can remove empty folders as well as files
         if (File::isReadable($file)) {
             File::delete($file);
         }
     }
     // finally, remove the top-level folder but only in case we
     // are supposed to!
     if (!$onlyFiles) {
         File::delete($dirName);
     }
     return true;
 }
 /**
  * removes a file from disk
  *
  * @param resource A GalleryResource object, representing the resource
  * we'd like to delete.
  * @return Returns ok if file was successfully deleted ok or false otherwise.
  */
 function remove($resource)
 {
     if ($resource) {
         // first of all, remove the resource file itself
         $fileParts = explode(".", $resource->getFileName());
         $fileExt = $fileParts[count($fileParts) - 1];
         $fileName = $resource->getOwnerId() . "-" . $resource->getId() . "." . $fileExt;
         $filePath = $this->getUserFolder($resource->getOwnerId());
         $fullName = $filePath . $fileName;
         if (File::isReadable($fullName)) {
             $result = File::delete($fullName);
         }
         // and now if preview images are available, remove them too!
         if ($resource->hasPreview()) {
             // delete the small thumbnail
             $previewFile = $resource->getPreviewFileName();
             if (File::isReadable($previewFile)) {
                 File::delete($previewFile);
             }
             // and the medium-sized thumbnail
             $medPreviewFile = $resource->getMediumSizePreviewFileName();
             if (File::isReadable($medPreviewFile)) {
                 File::delete($medPreviewFile);
             }
         }
     } else {
         $result = false;
     }
     return $result;
 }
 /**
  * @private
  */
 function _loadLocaleFile()
 {
     $fileName = $this->_defaultFolder . "/locale_" . $this->_code . ".php";
     if (File::isReadable($fileName)) {
         include $fileName;
     }
     // The following is just to handle the case where there isn't
     // a valid local file.
     if (!isset($messages) || !is_array($messages)) {
         $messages = array();
     }
     $this->_messages = $messages;
     unset($messages);
     /*if( function_exists('memory_get_usage'))
     		$this->log->debug('Memory used after loading locale ' . $this->_code . ': ' . memory_get_usage());*/
 }
Example #22
0
File: File.php Project: rsms/phpab
 /** @ignore */
 public static function __test()
 {
     $file = new File(__FILE__);
     assert($file->exists());
     assert($file->isFile());
     assert(!$file->isDir());
     assert($file->isReadable());
 }