コード例 #1
0
 /** 
  * I2CE_Template constructor method.
  * 
  * This constructor sets up the basic variables for all I2CE_Template objects.
  * 
  */
 public function __construct()
 {
     parent::__construct();
     $this->node_defs = array('/' => array());
 }
コード例 #2
0
 /**
  * Create an configurationGroup node by appending on to the given configurationGroup node the values
  * stored in the magic data at the specified $key.
  * @param DOMNode $configNode.  A configurationGroup node.
  * @param I2CE_MagicDataNode $config.  The data we wish to store at this node
  * @param array $pipe.  An array of path components relative to the $config. If the pipe is a non-empty array, we export only the 
  * keys specifed by the lowest member of $pipe, if it exists.  Otherwise, if the pipe is empty, we export all keys
  * @param string $key.  The key.  (Warning.  It assumes it exists in the magic data!)
  * @param string $configType.  Defaults to the empty string.  The configuration type to give the configuration node.
  * @param array $status.  An array of status options we should set for this configuration node.  Defaults to the empty array
  */
 public function createExportNodeConfigurationGroup($configNode, $config, $pipe, $key, $configType, $status)
 {
     if (array_key_exists($configType, self::$permissions)) {
         if (is_string(self::$permissions[$configType])) {
             $status['permission'] = self::$permissions[$configType];
         } else {
             if (self::$permissions[$configType] === true) {
                 $perm = '';
                 $config->setIfIsSet($perm, 'limit_access_to');
                 $perm = trim($perm);
                 if ($perm) {
                     $status['permission'] = $perm . ' or task(custom_reports_admin)';
                 }
             } else {
                 I2CE::raiseError("Bad perm for {$configType}");
             }
         }
     }
     return parent::createExportNodeConfigurationGroup($configNode, $config, $pipe, $key, $configType, $status);
 }
コード例 #3
0
 protected function loadMDTemplate($doc, $transform = false, $erase = false)
 {
     //doc is either a file name or a DOMDocument
     if ($transform) {
         //transform
         if (is_string($doc)) {
             $file = $doc;
             $doc = new DOMDocument();
             if (!($contents = file_get_contents($file))) {
                 $this->userMessage("Could not load source file");
                 return false;
             }
             if (!$doc->loadXML($contents)) {
                 $this->userMessage("Could not load file source contents");
                 return false;
             }
         }
         if (!$doc instanceof DOMDocument) {
             $this->userMessage("Could not load xml into document");
             return false;
         }
         $proc = new XSLTProcessor();
         $xslt_doc = new DOMDocument();
         if (!$xslt_doc->loadXML($transform)) {
             $this->userMessage("Could not load transform: " . $_FILES['xsl']['name']);
             return false;
         }
         if (!$proc->importStylesheet($xslt_doc)) {
             $this->userMessage("Could not import style sheet");
             return false;
         }
         $trans_doc = new DOMDocument('1.0', 'UTF-8');
         $trans_doc->appendChild($trans_doc->importNode($doc->documentElement, true));
         if (($trans_out = $proc->transformToXML($trans_doc)) === false) {
             $this->userMessage("Could not transform accoring to xsl");
             return false;
         }
     } else {
         $trans_doc = $doc;
     }
     if ($trans_doc instanceof DOMDocument) {
         $temp_file = tempnam(sys_get_temp_dir(), 'MDN_UPLOAD');
         if (!file_put_contents($temp_file, $trans_out)) {
             $this->userMessage("Could not save transformed files");
             return false;
         }
     } else {
         $temp_file = $trans_doc;
     }
     $template = new I2CE_MagicDataTemplate();
     $template->setVerboseErrors(true);
     if (!$template->loadRootFile($temp_file)) {
         I2CE::raiseError("Unable to load transformed file as Magic Data");
         $this->userMessage("Unable to load transformed file as Magic Data");
         return false;
     }
     if (!$template->validate()) {
         I2CE::raiseError("Unable to validate transformed file as Magic Data");
         $this->userMessage("Unable to validate transformed file as Magic Data");
         return false;
     }
     $store = new I2CE_MagicDataStorageMem();
     $mem_config = I2CE_MagicData::instance("mdn_load");
     $mem_config->addStorage($store);
     $nodeList = $template->query("/configurationGroup");
     if (!$nodeList instanceof DOMNodeList || $nodeList->length == 0) {
         $nodeList = $template->query("/I2CEConfiguration/configurationGroup");
         //perhaps we really need to do something more if this is a module
     }
     foreach ($nodeList as $configNode) {
         $locale = false;
         $status = $template->getDefaultStatus();
         if ($configNode->hasAttribute('locale')) {
             $locale = $configNode->getAttribute('locale');
         }
         $vers = '0';
         if ($template->setConfigValues($configNode, $mem_config, $status, $vers) === false) {
             I2CE::raiseError("Could not load configuration values");
             $this->userMessage("Could not load configuration values");
             return false;
         }
     }
     //I2CE::raiseError(print_r($mem_config->getAsArray(),true));
     if ($erase) {
         $this->config->eraseChildren();
     }
     $merges = $template->getMerges();
     foreach ($merges as $path => $merge) {
         if ($this->config->is_scalar($path)) {
             I2CE::raiseError("Trying to merge arrays into {$path} where target is scalar valued. Skipping");
             continue;
         }
         if ($mem_config->is_scalar($path)) {
             I2CE::raiseError("Trying to merge arrays into {$path} where source is scalar valued. Skipping");
             continue;
         }
         $old_arr = $this->config->getAsArray($path);
         $new_arr = $mem_config->getAsArray($path);
         $mem_config->__unset($path);
         if (!is_array($old_arr)) {
             //in case the target did not exist
             $old_arr = array();
         }
         if (!is_array($new_arr)) {
             //in case no values were set for the source
             $new_arr = array();
         }
         switch ($merge) {
             case 'uniquemerge':
                 $new_arr = I2CE_Util::array_unique(array_merge($old_arr, $new_arr));
                 break;
             case 'merge':
                 $new_arr = array_merge($old_arr, $new_arr);
                 break;
             case 'mergerecursive':
                 I2CE_Util::merge_recursive($old_arr, $new_arr);
                 $new_arr = $old_arr;
                 break;
         }
         $this->config->__unset($path);
         $this->config->{$path} = $new_arr;
     }
     //we took care of all array merges.  anything that is left is an overwrite.
     foreach ($mem_config as $k => $v) {
         if (is_scalar($v) && $mem_config->is_translatable($k) && !$this->config->is_parent($k)) {
             $this->config->setTranslatable($k);
             $translations = $mem_config->traverse($k, true, false)->getTranslations();
             foreach ($translations as $locale => $trans) {
                 if (strlen($trans) == 0) {
                     continue;
                 }
                 $this->config->setTranslation($locale, $trans, $k);
             }
         } else {
             $this->config->{$k}->setValue($v, null, false);
         }
         if ($this->config->{$k} instanceof I2CE_MagicDataNode) {
             //free up some memory.
             $this->config->{$k}->unpopulate(true);
         }
     }
     return true;
 }
コード例 #4
0
 public function updatePaths($node = NULL, &$paths = NULL)
 {
     return parent::updatePaths($node, $paths);
 }
コード例 #5
0
 /**
  * construct a swiss swiss factory and create it if it doesn't exist.
  * @param I2CE_MagicDataNode $storage.  The root of the magic data we will be operating on
  * @param string  $swissName.  The classname for the root swiss object.
  * @throws Exception
  */
 public function __construct($page, $options = array())
 {
     $this->child_node_cache = array();
     $this->child_node_cache_index = array();
     parent::__construct($page);
     if (!array_key_exists('module', $options) || !$options['module']) {
         throw new Exception("No modules specified");
     }
     $this->module = $options['module'];
     $config_file = null;
     if (!I2CE::getConfig()->setIfIsSet($config_file, "/config/data/{$options['module']}/file")) {
         throw new Exception("No magic data template found for {$options['module']}");
     }
     $this->configTemplate = new I2CE_MagicDataTemplate();
     if (!$this->configTemplate->loadRootFile($config_file)) {
         throw new Exception("Invalid magic data template found for {$options['module']}");
     }
     $this->xpath = new DOMXPath($this->configTemplate->getDoc());
     $this->configNodes = array();
     $nodes = $this->xpath->query('/I2CEConfiguration/configurationGroup');
     if ($nodes->length != 1) {
         throw new Exception("No or invalid configuration data for {$options['module']}");
     }
     $this->configNodes['/'] = $nodes->item(0);
     $this->statii['/'] = $this->configTemplate->getDefaultStatus();
     if (!array_key_exists('version', $this->statii['/'])) {
         if (array_key_exists('version', $options)) {
             $this->statii['/']['version'] = $options['version'];
         } else {
             $this->statii['/']['version'] = 0;
         }
     }
     $file_search = new I2CE_FileSearch();
     $mod_factory = I2CE_ModuleFactory::instance();
     $mod_factory->loadPaths($this->module, 'CONFIGS', true, $file_search);
     $translated = $file_search->search('CONFIGS', $config_file, true);
     $translated_locales = $file_search->getLocaleOfLastSearch();
     $preferred_locales = I2CE_Locales::getPreferredLocales();
     $this->translatedConfigs = array();
     foreach ($preferred_locales as $locale) {
         if (($index = array_search($locale, $translated_locales)) === false) {
             continue;
         }
         $trans_file = $translated[$index];
         $trans_template = new I2CE_MagicDataTemplate();
         if (!$trans_template->loadRootFile($trans_file)) {
             continue;
         }
         $this->translatedConfigs[$locale] = $trans_template;
     }
 }
コード例 #6
0
 public function importLocalizedTemplates($localized = array())
 {
     $imported = array();
     $i2ceConfigNodeList = $this->template->query('/I2CEConfiguration');
     if ($i2ceConfigNodeList->length != 1) {
         I2CE::raiseError("No configuration template loaded");
         return $imported;
     } else {
         $configNode = $i2ceConfigNodeList->item(0);
     }
     $shortname = trim($configNode->getAttribute('name'));
     if (!$shortname) {
         I2CE::raiseError("Could not find module name");
         return $imported;
     }
     $config = $this->storage->config->data->{$shortname};
     $file = false;
     $config->setIfIsSet($file, "file");
     if (!$file) {
         I2CE::raiseError("Could not source file");
         return $imported;
     }
     $dirs = array();
     $basedir = dirname($file);
     $basename = basename($file);
     $config->setIfIsSet($dirs, "paths/CONFIGS", true);
     if (!is_array($localized)) {
         $localized = array();
     }
     foreach ($dirs as $dir) {
         foreach ($this->locales as $locale) {
             if (array_key_exists($locale, $imported)) {
                 continue;
             }
             if (I2CE_FileSearch::isAbsolut($dir)) {
                 //the config path in theconfig file is absolut.
                 $localized_file = I2CE_FileSearch::realPath($dir . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . $basename);
                 $dir = I2CE_FileSearch::relativePath($dir);
             } else {
                 //the config path in theconfig file is relative to the module file
                 $localized_file = I2CE_FileSearch::realPath($basedir . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . $basename);
             }
             if (!$localized_file || !is_file($localized_file) || !is_readable($localized_file)) {
                 continue;
             }
             I2CE::raiseError("Loading {$localized_file}");
             $loc_template = new I2CE_MagicDataTemplate();
             $loc_template->loadRootFile($localized_file);
             $loc_node = $loc_template->doc->documentElement;
             if (!$loc_node instanceof DOMNODE) {
                 continue;
             }
             $results = $loc_template->query('./configurationGroup', $loc_node);
             $localenode = null;
             if ($results->length == 1) {
                 $localenode = $results->item(0);
                 if ($localenode->getAttribute('locale') !== $locale) {
                     I2CE::raiseError("Locale mismatch on {$localized_file}");
                     continue;
                 }
             }
             $results = $loc_template->query('./metadata/version', $loc_node);
             if ($results->length != 1) {
                 I2CE::raiseError("No version on {$localized_file}");
                 continue;
             }
             $new_vers = trim($results->item(0)->textContent);
             if (!array_key_exists($locale, $localized) || !is_array($localized[$locale]) || !array_key_exists('vers', $localized[$locale]) || !is_string($localized[$locale]['vers']) || strlen($localized[$locale]['vers']) == 0) {
                 $old_vers = '0';
             } else {
                 $old_vers = $localized[$locale]['vers'];
             }
             if ($localenode) {
                 $localenode_imported = $this->template->doc->importNode($localenode, true);
                 I2CE::raiseError("Adding in localizations of {$shortname} in {$locale} to process");
                 $configNode->appendChild($localenode_imported);
             }
             $data = array('file' => I2CE_FileSearch::relativePath($localized_file), 'mtime' => @filemtime($localized_file), 'hash' => md5(file_get_contents($localized_file)), 'old_vers' => $old_vers, 'vers' => $new_vers);
             $imported[$locale] = $data;
         }
     }
     if (count($imported) > 0) {
         I2CE::raiseError("Found localized config files for " . $shortname . ": " . implode(',', array_keys($imported)));
     }
     return $imported;
 }
コード例 #7
0
}
$form = trim(ask("What form are you remapping?"));
$old_head = false;
$new_head = false;
$headers = $data_file->getHeaders();
$old_head = chooseMenuIndex("Please select the column with the old values that will be remapped from:", $headers);
$new_head = chooseMenuIndex("Please select the column with the new values that will be remapped to:", $headers);
$remaps = array();
while ($data_file->hasDataRow()) {
    if (!is_array($row = $data_file->getDataRow()) || !array_key_exists($old_head, $row) || !array_key_exists($new_head, $row)) {
        continue;
    }
    $remaps[trim(strtoupper($row[$old_head]))] = trim($row[$new_head]);
}
//print_r($remaps);
$template = new I2CE_MagicDataTemplate();
if (!$template->loadRootFile($xml_file)) {
    usage("You need to specify a data .xml file");
}
if (!($versionNodes = $template->query('//I2CEConfiguration/metadata/version')) instanceof DOMNodeList || !$versionNodes->length == 1) {
    usage("Could not find current version in data .xml file");
}
$versionNode = $versionNodes->item(0);
$version_comps = explode(".", trim($versionNode->textContent));
end($version_comps);
$key = key($version_comps);
$version_comps[$key]++;
$version = implode(".", $version_comps);
while ($versionNode->hasChildNodes()) {
    $versionNode->removeChild($versionNode->firstChild);
}