Exemple #1
0
function autoloadEvents($class)
{
    if (strToLower(right($class, 5)) !== 'event') {
        return;
    }
    require_once jailpath(DIAMONDMVC_ROOT . '/classes/events', strToLower(substr($class, 0, strlen($class) - 5)) . '.php');
}
Exemple #2
0
function autoloadFields($class)
{
    if (strToLower(left($class, 5)) !== 'field') {
        return;
    }
    require_once jailpath(DIAMONDMVC_ROOT . '/classes/fields', strToLower(substr($class, 5)) . '.php');
}
Exemple #3
0
 /**
  * Gets the generated path to this view's associated template file. If the file does not exist,
  * returns an empty string.
  * @return string
  */
 public function getPath()
 {
     $jail = realpath(DIAMONDMVC_ROOT . '/views/' . strToLower($this->controller->getName()) . '/templates');
     if ($jail === false) {
         return '';
     }
     // Add suffix unless we're viewing a simple HTML template
     $file = strToLower($this->name);
     if (strToLower($this->type) !== 'html') {
         $file .= '.' . strToLower($this->type);
     }
     $file .= '.php';
     return jailpath($jail, $file);
 }
Exemple #4
0
/**
 * Creates a temporary file in the /tmp directory, appending a random suffix for uniqueness between
 * parallel tasks of the same script.
 * @param  string $name Basic name of the temporary file. Optional
 * @return string       Path to the created temporary file. An empty string if creation failed.
 */
function create_temporary_file($name = '')
{
    $name = generateRandomName('A-Za-z0-9', 20) . '_' . $name . '.tmp';
    $path = jailpath(DIAMONDMVC_ROOT . DS . 'tmp', $name);
    if (!touch($path)) {
        return '';
    }
    return $path;
}
 /**
  * Gets the real path to the meta file. If the file does not exist, returns an empty string.
  * @param  string $__meta Path relative to the /registry directory.
  * @return string       Absolute path to the meta file or an empty string if the file does not exist.
  */
 protected static function getMetaPath($meta)
 {
     if (!endsWith($meta, '.json')) {
         $meta .= '.json';
     }
     return jailpath(DIAMONDMVC_ROOT . DS . 'registry', $meta);
 }
 /**
  * Gets the path to the given template with type
  * @param  string $template
  * @param  string $type
  * @return string The path to the template if it exists, otherwise an empty string.
  */
 public function getTemplatePath($template = '', $type = '')
 {
     $jail = realpath(DIAMONDMVC_ROOT . "/views/{$this->_controllername}/templates");
     if ($jail === false) {
         return '';
     }
     if (empty($template)) {
         $template = $this->action === 'main' ? 'default' : $this->action;
     }
     $type = strToLower($type);
     $typeSuffix = (!empty($type) and $type !== 'html') ? ".{$type}" : '';
     $path = jailpath($jail, "{$template}{$typeSuffix}.php");
     return $path;
 }
 /**
  * Loads the named library found under /classes/libs/<$libname>.php
  * The library usually simply registers a new autoloader to automatically load
  * classes with a particular prefix, but may also simply define a set of classes
  * for use.
  * @param string $libname Name of the library to load.
  */
 public function loadLibrary($libname)
 {
     require_once jailpath(DIAMONDMVC_ROOT . '/classes/libs', strToLower($libname) . '.php');
 }
Exemple #8
0
 protected function action_update()
 {
     if (!Permissions::has('access') or !Permissions::has('sys_installation_install')) {
         return $this->redirectForbidden();
     }
     $lang = i18n::load('diamondmvc-backend');
     if (!isset($_REQUEST['id']) or empty($_REQUEST['id'])) {
         $this->addMessage('Whoops!', $lang->get('ERROR_MISSING_ARGUMENTS'), 'error');
         $this->result = array('success' => false, 'msg' => $lang->get('ERROR_MISSING_ARGUMENTS'));
         return;
     }
     $path = jailpath(DIAMONDMVC_ROOT . DS . 'registry', $_REQUEST['id'] . '.json');
     if (!is_file($path)) {
         $this->addMessage('Whoops!', $lang->get('ERROR_NO_META', 'ControllerSystem.Installation', 'error'));
         $this->result = array('success' => false, 'msg' => $lang->get('ERROR_NO_META', 'ControllerSystem.Installation'));
         return;
     }
     try {
         $id = InstallationManager::update($path);
         $this->result = array('success' => true, 'id' => $id);
     } catch (Exception $ex) {
         $this->result = array('success' => false, 'msg' => $ex->getMessage());
         $this->addMessage('Whoops!', 'An exception occurred: ' . $ex->getMessage(), 'error');
         logMsg('DiamondMVC: failed to update installation ' . $_REQUEST['id'] . ' with exception (' . $ex->getCode() . '): ' . $ex->getMessage(), 9, false);
     }
 }
Exemple #9
0
 /**
  * Gets information on the files in the given directory, such as name, size, etc.
  * Sizes of directories are skipped. They can be requested via AJAX calling
  * {@link #action_size()}.
  * @param  string $dir Path to the directory whose files to get. May be either absolute or relative to the jail.
  * @return array       Array of files in the directory providing additional information.
  */
 public function getFiles($dir)
 {
     $files = array();
     // First jail the directory who's files to get. If it lies outside the jail, all its contained files will in particular.
     // This also allows us to use paths relative to the jail.
     if (!empty($this->jail)) {
         $dir = jailpath($this->jail, $dir);
     }
     // Get a list of all files in the directory
     $paths = glob("{$dir}/*");
     // Including dot files (such as .htaccess) if set
     if ($this->dotFiles) {
         $paths = array_merge(glob("{$dir}/.*"));
     }
     // Retrieve the file info
     foreach ($paths as $path) {
         if (endsWith($path, '.') or endsWith($path, '..')) {
             continue;
         }
         $path = preg_replace('/[\\\\\\/]+/', DS, $path);
         $pathparts = explode(DS, $path);
         $file = array();
         $name = $pathparts[count($pathparts) - 1];
         $file['id'] = $name;
         $file['name'] = $name;
         $file['is_dir'] = is_dir($path);
         if (is_dir($path)) {
             $file['size'] = '';
         } else {
             $file['size'] = filesize($path);
         }
         $file['perms'] = $this->getPermsString($path);
         $files[] = $file;
     }
     // Sort the files. First directories, then regular files. Both alphabetically.
     $tmp1 = $tmp2 = array();
     foreach ($files as $file) {
         if ($file['is_dir']) {
             $tmp1[] = $file;
         } else {
             $tmp2[] = $file;
         }
     }
     // The natsort works with our standardized 2-dimensional arrays as well, but converts them into strings. We'll simply repress the generated notice and it should work.
     @natsort(array_reverse($tmp1));
     @natsort(array_reverse($tmp2));
     $files = array_merge($tmp1, $tmp2);
     return $files;
 }