コード例 #1
0
ファイル: Perms.php プロジェクト: horde/horde
 /**
  * Returns the available permissions for a given level.
  *
  * @param string $name  The permission's name.
  *
  * @return array  An array of available permissions and their titles or
  *                false if not sub permissions exist for this level.
  * @throws Horde_Perms_Exception
  */
 public function getAvailable($name)
 {
     if ($name == Horde_Perms::ROOT) {
         $name = '';
     }
     if (empty($name)) {
         /* No name passed, so top level permissions are requested. These
          * can only be applications. */
         $apps = $this->_registry->listApps(array('notoolbar', 'active', 'hidden'), true);
         foreach (array_keys($apps) as $app) {
             $apps[$app] = $this->_registry->get('name', $app) . ' (' . $app . ')';
         }
         asort($apps);
         return $apps;
     }
     /* Name has been passed, explode the name to get all the levels in
      * permission being requisted, with the app as the first level. */
     $levels = explode(':', $name);
     /* First level is always app. */
     $app = $levels[0];
     /* Call the app's permission function to return the permissions
      * specific to this app. */
     $perms = $this->getApplicationPermissions($app);
     if (!count($perms)) {
         return false;
     }
     /* Get the part of the app's permissions based on the permission
      * name requested. */
     $children = Horde_Array::getElement($perms['tree'], $levels);
     if ($children === false || !is_array($children) || !count($children)) {
         /* No array of children available for this permission name. */
         return false;
     }
     $perms_list = array();
     foreach (array_keys($children) as $perm_key) {
         $perms_list[$perm_key] = $perms['title'][$name . ':' . $perm_key];
     }
     return $perms_list;
 }
コード例 #2
0
ファイル: Type.php プロジェクト: raz0rsdge/horde
 function getUploadedFileType($field)
 {
     /* Get any index on the field name. */
     $index = Horde_Array::getArrayParts($field, $base, $keys);
     if ($index) {
         /* Index present, fetch the mime type var to check. */
         $keys_path = array_merge(array($base, 'type'), $keys);
         $type = Horde_Array::getElement($_FILES, $keys_path);
         $keys_path = array_merge(array($base, 'tmp_name'), $keys);
         $tmp_name = Horde_Array::getElement($_FILES, $keys_path);
     } else {
         /* No index, simple set up of vars to check. */
         $type = $_FILES[$field]['type'];
         $tmp_name = $_FILES[$field]['tmp_name'];
     }
     if (empty($type) || $type == 'application/octet-stream') {
         /* Type wasn't set on upload, try analising the upload. */
         if (!($type = Horde_Mime_Magic::analyzeFile($tmp_name, isset($GLOBALS['conf']['mime']['magic_db']) ? $GLOBALS['conf']['mime']['magic_db'] : null))) {
             if ($index) {
                 /* Get the name value. */
                 $keys_path = array_merge(array($base, 'name'), $keys);
                 $name = Horde_Array::getElement($_FILES, $keys_path);
                 /* Work out the type from the file name. */
                 $type = Horde_Mime_Magic::filenameToMime($name);
                 /* Set the type. */
                 $keys_path = array_merge(array($base, 'type'), $keys);
                 Horde_Array::getElement($_FILES, $keys_path, $type);
             } else {
                 /* Work out the type from the file name. */
                 $type = Horde_Mime_Magic::filenameToMime($_FILES[$field]['name']);
                 /* Set the type. */
                 $_FILES[$field]['type'] = Horde_Mime_Magic::filenameToMime($_FILES[$field]['name']);
             }
         }
     }
     return $type;
 }
コード例 #3
0
ファイル: Ui.php プロジェクト: horde/horde
 /**
  * Return a Horde_Tree representation of the permissions tree.
  *
  * @return string  The html showing the permissions as a Horde_Tree.
  * @throws Horde_Perms_Exception
  */
 public function renderTree($current = Horde_Perms::ROOT)
 {
     /* Get the perms tree. */
     $nodes = $this->_perms->getTree();
     $perms_node = array('icon' => Horde_Themes::img('perms.png'));
     $add = Horde::url('admin/perms/addchild.php');
     $add_img = Horde_Themes_Image::tag('plus.png', array('alt' => Horde_Core_Translation::t("Add Permission")));
     $edit = Horde::url('admin/perms/edit.php');
     $delete = Horde::url('admin/perms/delete.php');
     $edit_img = Horde_Themes_Image::tag('edit.png', array('alt' => Horde_Core_Translation::t("Edit Permission")));
     $delete_img = Horde_Themes_Image::tag('delete.png', array('alt' => Horde_Core_Translation::t("Delete Permission")));
     $blank_img = Horde_Themes_Image::tag('blank.gif', array('attr' => array('width' => 16, 'height' => 16)));
     /* Set up the tree. */
     $tree = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Tree')->create('perms_ui', 'Javascript', array('alternate' => true, 'hideHeaders' => true));
     $tree->setHeader(array(array('class' => 'horde-tree-spacer')));
     foreach ($nodes as $perm_id => $node) {
         $node_class = $current == $perm_id ? array('class' => 'selected') : array();
         if ($perm_id == Horde_Perms::ROOT) {
             $add_link = $add->add('perm_id', $perm_id)->link(array('class' => 'permsAdd', 'title' => Horde_Core_Translation::t("Add New Permission"))) . $add_img . '</a>';
             $base_node_params = array('icon' => Horde_Themes::img('administration.png'));
             $tree->addNode(array('id' => $perm_id, 'label' => Horde_Core_Translation::t("All Permissions"), 'expanded' => true, 'params' => $base_node_params + $node_class, 'right' => array($add_link)));
         } else {
             $parent_id = $this->_perms->getParent($node);
             $perms_extra = array();
             $parents = explode(':', $node);
             if (!in_array($parents[0], $GLOBALS['registry']->listApps(array('notoolbar', 'active', 'hidden')))) {
                 // This backend has permissions for an application that is
                 // not installed.  Perhaps the application has been removed
                 // or the backend is shared with other Horde installations.
                 // Skip this app and do not include it in the tree.
                 continue;
             }
             try {
                 $app_perms = $this->_corePerms->getApplicationPermissions($parents[0]);
             } catch (Horde_Perms_Exception $e) {
                 $GLOBALS['notification']->push($e);
                 continue;
             }
             if (isset($app_perms['tree']) && is_array(Horde_Array::getElement($app_perms['tree'], $parents))) {
                 $add_link = $add->add('perm_id', $perm_id)->link(array('class' => 'permsAdd', 'title' => Horde_Core_Translation::t("Add Child Permission"))) . $add_img . '</a>';
                 $perms_extra[] = $add_link;
             } else {
                 $perms_extra[] = $blank_img;
             }
             $edit_link = $edit->add('perm_id', $perm_id)->link(array('class' => 'permsEdit', 'title' => Horde_Core_Translation::t("Edit Permission"))) . $edit_img . '</a>';
             $perms_extra[] = $edit_link;
             $delete_link = $delete->add('perm_id', $perm_id)->link(array('class' => 'permsDelete', 'title' => Horde_Core_Translation::t("Delete Permission"))) . $delete_img . '</a>';
             $perms_extra[] = $delete_link;
             $name = $this->_corePerms->getTitle($node);
             $expanded = isset($nodes[$current]) && strpos($nodes[$current], $node) === 0 && $nodes[$current] != $node;
             $tree->addNode(array('id' => $perm_id, 'parent' => $parent_id, 'label' => $name, 'expanded' => $expanded, 'params' => $perms_node + $node_class, 'right' => $perms_extra));
         }
     }
     $tree->sort('label');
     return $tree->renderTree();
 }
コード例 #4
0
ファイル: Browser.php プロジェクト: jubinpatel/horde
 /**
  * Determines if the file was uploaded or not.  If not, will return the
  * appropriate error message.
  *
  * @param string $field  The name of the field containing the uploaded
  *                       file.
  * @param string $name   The file description string to use in the error
  *                       message.  Default: 'file'.
  *
  * @throws Horde_Browser_Exception
  */
 public function wasFileUploaded($field, $name = null)
 {
     if (is_null($name)) {
         $name = 'file';
     }
     if (!($uploadSize = self::allowFileUploads())) {
         throw new Horde_Browser_Exception(Horde_Browser_Translation::t("File uploads not supported."));
     }
     /* Get any index on the field name. */
     $index = Horde_Array::getArrayParts($field, $base, $keys);
     if ($index) {
         /* Index present, fetch the error var to check. */
         $keys_path = array_merge(array($base, 'error'), $keys);
         $error = Horde_Array::getElement($_FILES, $keys_path);
         /* Index present, fetch the tmp_name var to check. */
         $keys_path = array_merge(array($base, 'tmp_name'), $keys);
         $tmp_name = Horde_Array::getElement($_FILES, $keys_path);
     } else {
         /* No index, simple set up of vars to check. */
         if (!isset($_FILES[$field])) {
             throw new Horde_Browser_Exception(Horde_Browser_Translation::t("No file uploaded"), UPLOAD_ERR_NO_FILE);
         }
         $error = $_FILES[$field]['error'];
         if (is_array($error)) {
             $error = reset($error);
         }
         $tmp_name = $_FILES[$field]['tmp_name'];
         if (is_array($tmp_name)) {
             $tmp_name = reset($tmp_name);
         }
     }
     if (empty($_FILES)) {
         $error = UPLOAD_ERR_NO_FILE;
     }
     switch ($error) {
         case UPLOAD_ERR_NO_FILE:
             throw new Horde_Browser_Exception(sprintf(Horde_Browser_Translation::t("There was a problem with the file upload: No %s was uploaded."), $name), UPLOAD_ERR_NO_FILE);
         case UPLOAD_ERR_OK:
             if (is_uploaded_file($tmp_name) && !filesize($tmp_name)) {
                 throw new Horde_Browser_Exception(Horde_Browser_Translation::t("The uploaded file appears to be empty. It may not exist on your computer."), UPLOAD_ERR_NO_FILE);
             }
             // SUCCESS
             break;
         case UPLOAD_ERR_INI_SIZE:
         case UPLOAD_ERR_FORM_SIZE:
             throw new Horde_Browser_Exception(sprintf(Horde_Browser_Translation::t("There was a problem with the file upload: The %s was larger than the maximum allowed size (%d bytes)."), $name, $uploadSize), $error);
         case UPLOAD_ERR_PARTIAL:
             throw new Horde_Browser_Exception(sprintf(Horde_Browser_Translation::t("There was a problem with the file upload: The %s was only partially uploaded."), $name), $error);
         case UPLOAD_ERR_NO_TMP_DIR:
             throw new Horde_Browser_Exception(Horde_Browser_Translation::t("There was a problem with the file upload: The temporary folder used to store the upload data is missing."), $error);
         case UPLOAD_ERR_CANT_WRITE:
             // No reason to try to explain to user what a "PHP extension" is.
         // No reason to try to explain to user what a "PHP extension" is.
         case UPLOAD_ERR_EXTENSION:
             throw new Horde_Browser_Exception(Horde_Browser_Translation::t("There was a problem with the file upload: Can't write the uploaded data to the server."), $error);
     }
 }
コード例 #5
0
ファイル: Browser.php プロジェクト: ivan801/ampache
 /**
  * Determines if the file was uploaded or not.  If not, will return the
  * appropriate error message.
  *
  * @param string $field  The name of the field containing the uploaded
  *                       file.
  * @param string $name   The file description string to use in the error
  *                       message.  Default: 'file'.
  *
  * @throws Horde_Browser_Exception
  */
 public function wasFileUploaded($field, $name = null)
 {
     if (is_null($name)) {
         $name = 'file';
     }
     if (!($uploadSize = self::allowFileUploads())) {
         throw new Horde_Browser_Exception(Horde_Browser_Translation::t("File uploads not supported."));
     }
     /* Get any index on the field name. */
     $index = Horde_Array::getArrayParts($field, $base, $keys);
     if ($index) {
         /* Index present, fetch the error var to check. */
         $keys_path = array_merge(array($base, 'error'), $keys);
         $error = Horde_Array::getElement($_FILES, $keys_path);
         /* Index present, fetch the tmp_name var to check. */
         $keys_path = array_merge(array($base, 'tmp_name'), $keys);
         $tmp_name = Horde_Array::getElement($_FILES, $keys_path);
     } else {
         /* No index, simple set up of vars to check. */
         if (!isset($_FILES[$field])) {
             throw new Horde_Browser_Exception(Horde_Browser_Translation::t("No file uploaded"), UPLOAD_ERR_NO_FILE);
         }
         $error = $_FILES[$field]['error'];
         $tmp_name = $_FILES[$field]['tmp_name'];
     }
     if (empty($_FILES) || $error == UPLOAD_ERR_NO_FILE) {
         throw new Horde_Browser_Exception(sprintf(Horde_Browser_Translation::t("There was a problem with the file upload: No %s was uploaded."), $name), UPLOAD_ERR_NO_FILE);
     } elseif ($error == UPLOAD_ERR_OK && is_uploaded_file($tmp_name)) {
         if (!filesize($tmp_name)) {
             throw new Horde_Browser_Exception(Horde_Browser_Translation::t("The uploaded file appears to be empty. It may not exist on your computer."), UPLOAD_ERR_NO_FILE);
         }
         // SUCCESS
     } elseif ($error == UPLOAD_ERR_INI_SIZE || $error == UPLOAD_ERR_FORM_SIZE) {
         throw new Horde_Browser_Exception(sprintf(Horde_Browser_Translation::t("There was a problem with the file upload: The %s was larger than the maximum allowed size (%d bytes)."), $name, $uploadSize), $error);
     } elseif ($error == UPLOAD_ERR_PARTIAL) {
         throw new Horde_Browser_Exception(sprintf(Horde_Browser_Translation::t("There was a problem with the file upload: The %s was only partially uploaded."), $name), $error);
     }
 }
コード例 #6
0
ファイル: Horde.php プロジェクト: justinlyon/scc
 /**
  * Returns the driver parameters for the specified backend.
  *
  * @param mixed $backend  The backend system (e.g. 'prefs', 'categories',
  *                        'contacts') being used.
  *                        The used configuration array will be
  *                        $conf[$backend]. If an array gets passed, it will
  *                        be $conf[$key1][$key2].
  * @param string $type    The type of driver.
  *
  * @return array  The connection parameters.
  */
 function getDriverConfig($backend, $type = 'sql')
 {
     global $conf;
     $c = null;
     if (is_array($backend)) {
         require_once 'Horde/Array.php';
         $c = Horde_Array::getElement($conf, $backend);
     } elseif (isset($conf[$backend])) {
         $c = $conf[$backend];
     }
     if (!is_null($c) && isset($c['params'])) {
         $c['params']['umask'] = $conf['umask'];
         if (isset($conf[$type])) {
             return array_merge($conf[$type], $c['params']);
         } else {
             return $c['params'];
         }
     }
     return isset($conf[$type]) ? $conf[$type] : array();
 }
コード例 #7
0
ファイル: Horde.php プロジェクト: jubinpatel/horde
 /**
  * Returns the driver parameters for the specified backend.
  *
  * @param mixed $backend  The backend system (e.g. 'prefs', 'categories',
  *                        'contacts') being used.
  *                        The used configuration array will be
  *                        $conf[$backend]. If an array gets passed, it will
  *                        be $conf[$key1][$key2].
  * @param string $type    The type of driver. If null, will not merge with
  *                        base config.
  *
  * @return array  The connection parameters.
  */
 public static function getDriverConfig($backend, $type = 'sql')
 {
     global $conf;
     if (!is_null($type)) {
         $type = Horde_String::lower($type);
     }
     if (is_array($backend)) {
         $c = Horde_Array::getElement($conf, $backend);
     } elseif (isset($conf[$backend])) {
         $c = $conf[$backend];
     } else {
         $c = null;
     }
     if (!is_null($c) && isset($c['params'])) {
         $c['params']['umask'] = $conf['umask'];
         return !is_null($type) && isset($conf[$type]) ? array_merge($conf[$type], $c['params']) : $c['params'];
     }
     return !is_null($type) && isset($conf[$type]) ? $conf[$type] : array();
 }