Ejemplo n.º 1
0
 public static function loadFile($file)
 {
     if (function_exists('yaml_parse_file')) {
         // returns array() if no data, NULL if error.
         $a = yaml_parse_file($file);
         if ($a === NULL || $a === false) {
             throw new WFException("Error processing YAML file: {$file}");
         }
         return $a;
     } else {
         if (function_exists('syck_load')) {
             // php-lib-c version, much faster!
             // ******* NOTE: if using libsyck with PHP, you should install from pear/pecl (http://trac.symfony-project.com/wiki/InstallingSyck)
             // ******* NOTE: as it escalates YAML syntax errors to PHP Exceptions.
             // ******* NOTE: without this, if your YAML has a syntax error, you will be really confused when trying to debug it b/c syck_load will just return NULL.
             $yaml = NULL;
             $yamlfile = file_get_contents($file);
             if (strlen($yamlfile) != 0) {
                 $yaml = syck_load($yamlfile);
             }
             if ($yaml === NULL) {
                 $yaml = array();
             }
             return $yaml;
         } else {
             // php version
             return Horde_Yaml::loadFile($file);
         }
     }
 }
Ejemplo n.º 2
0
/**
 * Load language file
 *
 * @param string $language - if left empty loads saved language selection (from cookie) or default language
 * @return bool success
 */
function i18n_load_language($language = NULL)
{
    global $i18n_lang, $i18n_current_language;
    if ($language == NULL) {
        $language = $_COOKIE["i18n_language"];
        if (!$language) {
            $language = getDefaultLanguage();
        }
    }
    $i18n_current_language = $language;
    if ($i18n_lang = Horde_Yaml::loadFile("../languages/{$language}.yaml")) {
        return true;
    } else {
        return false;
    }
}
Ejemplo n.º 3
0
 public static function processUploadFile(&$pParamHash)
 {
     $pParamHash['config_log'] = array();
     if (YamlConfig::verifyUpload($pParamHash)) {
         foreach ($pParamHash['upload_process'] as $file) {
             if ($hash = Horde_Yaml::loadFile($file['tmp_name'])) {
                 // deal with anything that might be in this hash
                 // @Todo probably want to move this out of here eventually
                 // kernel_config settings
                 if (!empty($hash['kernel_config'])) {
                     // parser is a little annoying when it comes to n and y - it reinterprets them as FALSE and TRUE
                     // we're lazy and dont want to regex the dump so lets try just flipping them back
                     foreach ($hash['kernel_config'] as $pkg => $data) {
                         foreach ($hash['kernel_config'][$pkg] as $config => $value) {
                             if ($value === TRUE || $value === FALSE) {
                                 $hash['kernel_config'][$pkg][$config] = $value ? 'y' : 'n';
                             }
                         }
                     }
                     $pParamHash['config_data']['kernel_config'] = $hash['kernel_config'];
                     // store the configurations
                     YamlConfig::setKernelConfig($pParamHash);
                 }
                 // themes_layouts settings
                 if (!empty($hash['themes_layouts'])) {
                     $pParamHash['config_data']['themes_layouts'] = $hash['themes_layouts'];
                     // store the configurations
                     YamlConfig::setThemesLayouts($pParamHash);
                 }
                 // users_permissions settings
                 if (!empty($hash['users_permissions'])) {
                     $pParamHash['config_data']['users_permissions'] = $hash['users_permissions'];
                     // store the configurations
                     YamlConfig::setUsersPermissions($pParamHash);
                 }
             }
         }
     } else {
         $pParamHash['config_log']['ERRORS'] = "Upload verification failed. " . $pParamHash['errors']['files'];
     }
     return empty($pParamHash['errors']) || count($pParamHash['errors']) == 0;
 }
Ejemplo n.º 4
0
 /**
  * Run the module.
  *
  * @param Horde_Cli $cli       The CLI handler.
  * @param mixed     $options   An array of options.
  * @param mixed     $arguments An array of arguments.
  * @param array     &$world    A list of initialized dependencies.
  *
  * @return NULL
  */
 public function run($cli, $options, $arguments, &$world)
 {
     if (!isset($arguments[1])) {
         $action = 'info';
     } else {
         $action = $arguments[1];
     }
     if (!isset($arguments[2])) {
         $folder_name = 'INBOX';
     } else {
         $folder_name = $arguments[2];
     }
     switch ($action) {
         case 'info':
             break;
         case 'synchronize':
             $world['storage']->getData($folder_name, $arguments[3])->synchronize();
             break;
         case 'stamp':
             $cli->writeln((string) $world['storage']->getData($folder_name)->getStamp());
             break;
         case 'complete':
             $data = $world['storage']->getData($folder_name);
             $complete = $data->fetchComplete($arguments[3]);
             $cli->writeln($complete[1]->toString(array('headers' => $complete[0])));
             break;
         case 'part':
             $data = $world['storage']->getData($folder_name);
             $part = $data->fetchPart($arguments[3], $arguments[4]);
             rewind($part);
             $cli->writeln(quoted_printable_decode(stream_get_contents($part)));
             break;
         case 'fetch':
             $data = $world['storage']->getData($folder_name, $arguments[3]);
             $objects = $data->fetch(explode(',', $arguments[4]));
             foreach ($objects as $uid => $message) {
                 $this->_yamlOutput($cli, $uid, $message);
             }
             break;
         case 'ids':
             $data = $world['storage']->getData($folder_name, $arguments[3]);
             foreach ($data->getObjectIds() as $id) {
                 $cli->writeln((string) $id);
             }
             break;
         case 'objects':
             $data = $world['storage']->getData($folder_name, $arguments[3]);
             foreach ($data->getObjects() as $id => $object) {
                 $this->_yamlOutput($cli, $id, $object);
             }
             break;
         case 'backendobjects':
             $data = $world['storage']->getData($folder_name, $arguments[3]);
             foreach ($data->getObjectsByBackendId() as $id => $object) {
                 $this->_yamlOutput($cli, $id, $object);
             }
             break;
         case 'object':
             $data = $world['storage']->getData($folder_name, $arguments[3]);
             $object = $data->getObject($arguments[4]);
             $this->_yamlOutput($cli, $arguments[4], $object);
             break;
         case 'backendobject':
             $data = $world['storage']->getData($folder_name, $arguments[3]);
             $object = $data->getObjectByBackendId($arguments[4]);
             $this->_yamlOutput($cli, $arguments[4], $object);
             break;
         case 'create':
             $data = $world['storage']->getData($folder_name, $arguments[3]);
             switch (Horde_String::lower($arguments[4])) {
                 case 'yaml':
                     if (class_exists('Horde_Yaml')) {
                         $object = Horde_Yaml::loadFile($arguments[5]);
                     } else {
                         throw new Horde_Kolab_Cli_Exception('The Horde_Yaml package is missing!');
                     }
             }
             $data->create($object);
             $cli->writeln($object['uid']);
             break;
         case 'move':
             $data = $world['storage']->getData($folder_name, $arguments[3]);
             $objects = $data->move($arguments[4], $arguments[5]);
             break;
         case 'delete':
             $data = $world['storage']->getData($folder_name, $arguments[3]);
             $objects = $data->delete(explode(',', $arguments[4]));
             break;
         case 'deleteall':
             $world['storage']->getData($folder_name, $arguments[3])->deleteAll();
             break;
         case 'deleteuids':
             $data = $world['storage']->getData($folder_name, $arguments[3]);
             $objects = $data->deleteBackendIds(explode(',', $arguments[4]));
             break;
         case 'backendid':
             $data = $world['storage']->getData($folder_name, $arguments[3]);
             $cli->writeln((string) $data->getBackendId($arguments[4]));
             break;
         default:
             $cli->message(sprintf(Horde_Kolab_Cli_Translation::t('Action %s not supported!'), $action), 'cli.error');
             break;
     }
 }
Ejemplo n.º 5
0
 /**
  * Establishes the connection to the database. Accepts a hash as input where
  * the :adapter key must be specified with the name of a database adapter (in lower-case)
  * 
  * Example for regular databases (MySQL, Postgresql, etc):
  * <code>
  *   Mad_Model_Base::establishConnection(array(
  *     "adapter"  => "mysql",
  *     "host"     => "localhost",
  *     "username" => "myuser",
  *     "password" => "mypass",
  *     "database" => "somedatabase"
  *   ));
  * </code>
  *
  * Example for SQLite database:
  * <code>
  *   Mad_Model_Base::establishConnection(array(
  *     "adapter"  => "sqlite",
  *     "database" => "path/to/dbfile"
  *   ));
  * </code>
  *
  * The exceptions AdapterNotSpecified, AdapterNotFound and ArgumentError
  * may be returned on an error.
  * 
  * @param   array   $spec
  * @return  Connection
  */
 public static function establishConnection($spec = null)
 {
     // $spec is empty: $spec defaults to MAD_ENV string like "development"
     // keep going to read YAML for this environment string
     if (empty($spec)) {
         if (!defined('MAD_ENV') || !MAD_ENV) {
             throw new Mad_Model_Exception('Adapter Not Specified');
         }
         $spec = MAD_ENV;
     }
     // $spec is string: read YAML config for environment named by string
     // keep going to process the resulting array
     if (is_string($spec)) {
         $config = Horde_Yaml::loadFile(MAD_ROOT . '/config/database.yml');
         $spec = $config[$spec];
     }
     // $spec is an associative array
     if (is_array($spec)) {
         // validation of array is handled by horde_db
         self::$_connectionSpec = $spec;
     } else {
         throw new Mad_Model_Exception("Invalid Connection Specification");
     }
 }
Ejemplo n.º 6
0
 /**
  * Parse the content of a YAML file into a Horde_Push element.
  *
  * @param string $argument A single command line argument (without the scheme argument).
  * @param array $conf      The configuration.
  *
  * @return Horde_Push The element to be pushed.
  */
 private function _parseYaml($argument, $conf)
 {
     if (!class_exists('Horde_Yaml')) {
         throw new Horde_Push_Exception('The Horde_Yaml package is missing!');
     }
     if (!file_exists($argument)) {
         throw new Horde_Push_Exception(sprintf('Invalid file path: "%s"!', $argument));
     }
     return $this->_createFromData(Horde_Yaml::loadFile($argument));
 }
Ejemplo n.º 7
0
<?php

require '../kernel/setup_inc.php';
$foo = Horde_Yaml::loadFile('/home/consulting/live/clients/bw/energymeasures/games.yaml');
vd($foo);
Ejemplo n.º 8
0
<?php

/**
 * @package Yaml
 */
require_once dirname(dirname(__DIR__)) . '/Yaml/__autoload.php';
$file = __DIR__ . '/example.yaml';
echo "{$file} loaded into PHP:\n";
var_dump(Horde_Yaml::loadFile($file));
Ejemplo n.º 9
0
 public function testUnliteralizing()
 {
     $parsed = Horde_Yaml::loadFile($this->fixture('basic'));
     $expected = "Line #1\nLine #2";
     $this->assertEquals($expected, $parsed['literalStringTest']);
 }
Ejemplo n.º 10
0
    /**
     * Populates the release information for the current component.
     */
    protected function _setReleaseNotes()
    {
        if (!($file = $this->_component->getReleaseNotesPath())) {
            return;
        }
        if (basename($file) == 'release.yml') {
            $version = Components_Helper_Version::parsePearVersion($this->_component->getVersion());
            $description = Horde_String::lower($version->description);
            if (strpos($description, 'release') === false) {
                $description .= ' release';
            }
            $infofile = dirname($file) . '/horde.yml';
            try {
                $info = Horde_Yaml::loadFile($infofile);
            } catch (Horde_Yaml_Exception $e) {
                throw new Components_Exception($e);
            }
            $this->_notes['name'] = $info['name'];
            if (isset($info['list'])) {
                $this->_notes['list'] = $info['list'];
            }
            try {
                $release = Horde_Yaml::loadFile($file);
            } catch (Horde_Yaml_Exception $e) {
                throw new Components_Exception($e);
            }
            if (isset($release['branch'])) {
                $this->_notes['branch'] = $release['branch'];
            }
            $this->_notes['security'] = $release['security'];
            if (is_array($release['changes'])) {
                if (!is_array(reset($release['changes']))) {
                    $release['changes'] = array($release['changes']);
                }
            } else {
                $release['changes'] = array();
            }
            $currentSection = null;
            $changes = '';
            foreach ($release['changes'] as $section => $sectionChanges) {
                if ($section != $currentSection) {
                    $changes .= "\n\n" . $section . ':';
                    $currentSection = $section;
                }
                foreach ($sectionChanges as $change) {
                    $changes .= "\n    * " . $change;
                }
            }
            switch ($version->description) {
                case 'Final':
                    $prerelease = '';
                    break;
                case 'Alpha':
                case 'Beta':
                    $prerelease = '
This is a preview version that should not be used on production systems. This version is considered feature complete but there might still be a few bugs. You should not use this preview version over existing production data.

We encourage widespread testing and feedback via the mailing lists or our bug tracking system. Updated translations are very welcome, though some strings might still change before the final release.
';
                    break;
                case 'Release Candidate':
                    $prerelease = sprintf('
Barring any problems, this code will be released as %s %s.
Testing is requested and comments are encouraged. Updated translations would also be great.
', $info['name'], $version->version);
                    break;
            }
            $this->_notes['changes'] = sprintf('The Horde Team is pleased to announce the %s%s of the %s version %s.

%s
%s
For upgrading instructions, please see
http://www.horde.org/apps/%s/docs/UPGRADING

For detailed installation and configuration instructions, please see
http://www.horde.org/apps/%s/docs/INSTALL
%s
The major changes compared to the %s version %s are:%s', $version->subversion ? NumberFormatter::create('en_US', NumberFormatter::ORDINAL)->format($version->subversion) . ' ' : '', $description, $info['full'], $version->version, $info['description'], $prerelease, $info['id'], $info['id'], !empty($release['additional']) ? "\n" . implode("\n\n", $release['additional']) . "\n" : '', $info['name'], $this->_component->getPreviousVersion(), $changes);
        } else {
            $this->_notes = (include $file);
        }
    }
Ejemplo n.º 11
0
 function parseInfoFile($pFile)
 {
     $rslt = array();
     if (file_exists($pFile)) {
         $data = Horde_Yaml::loadFile($pFile);
         if (!empty($data['games'])) {
             $rslt = $data['games'];
         }
     }
     return $rslt;
 }