/** * Install conference settings from an XML file. * @param $id int ID of scheduled conference/conference for settings to apply to * @param $filename string Name of XML file to parse and install * @param $paramArray array Optional parameters for variable replacement in settings */ function installSettings($id, $filename, $paramArray = array()) { $xmlParser = new XMLParser(); $tree = $xmlParser->parse($filename); if (!$tree) { $xmlParser->destroy(); return false; } foreach ($tree->getChildren() as $setting) { $nameNode =& $setting->getChildByName('name'); $valueNode =& $setting->getChildByName('value'); if (isset($nameNode) && isset($valueNode)) { $type = $setting->getAttribute('type'); $isLocaleField = $setting->getAttribute('locale'); $name =& $nameNode->getValue(); if ($type == 'date') { $value = strtotime($valueNode->getValue()); } elseif ($type == 'object') { $arrayNode =& $valueNode->getChildByName('array'); $value = $this->_buildObject($arrayNode, $paramArray); } else { $value = $this->_performReplacement($valueNode->getValue(), $paramArray); } // Replace translate calls with translated content $this->updateSetting($id, $name, $isLocaleField ? array(Locale::getLocale() => $value) : $value, $type, $isLocaleField); } } $xmlParser->destroy(); }
/** * Parse an XML file and return data in an array. * @see xml.XMLParser::parseStruct() */ function &parseStruct($file, $tagsToMatch = array()) { $parser = new XMLParser(); $data =& $parser->parseStruct($file, $tagsToMatch); $parser->destroy(); return $data; }
/** * Parse into structures the XML contents of an email data file. * @param $contents string * @return array */ function parseEmails($contents) { $parser = new XMLParser(); $result = $parser->parseTextStruct($contents, array('email_text', 'subject', 'body')); $parser->destroy(); return $result; }
/** * Parse a record's contents into an object * @param $contents string * @return object */ function &parseContents(&$contents) { $xmlParser = new XMLParser(); $result =& $xmlParser->parseText($contents); $returner = array(); $returner =& $this->handleRootNode($result); $result->destroy(); $xmlParser->destroy(); return $returner; }
/** * Parse an RT version XML file. * @param $file string path to the XML file * @return RTVersion */ function &parse($file) { $parser = new XMLParser(); $tree = $parser->parse($file); $parser->destroy(); $version = false; if ($tree !== false) { $version =& $this->parseVersion($tree); } $tree->destroy(); return $version; }
/** * Parse and execute the scheduled tasks in the specified file. * @param $file string */ function parseTasks($file) { $xmlParser = new XMLParser(); $tree = $xmlParser->parse($file); if (!$tree) { $xmlParser->destroy(); printf("Unable to parse file \"%s\"!\n", $file); exit(1); } foreach ($tree->getChildren() as $task) { $className = $task->getAttribute('class'); $frequency = $task->getChildByName('frequency'); if (isset($frequency)) { $canExecute = ScheduledTaskHelper::checkFrequency($className, $frequency); } else { // Always execute if no frequency is specified $canExecute = true; } if ($canExecute) { $this->executeTask($className, ScheduledTaskHelper::getTaskArgs($task)); } } $xmlParser->destroy(); }
/** * Parse a record's contents into an object * @param $contents string * @return object */ function &parseContents(&$contents) { $xmlParser = new XMLParser(); $result =& $xmlParser->parseText($contents); $returner = array(); $modsNode =& $result->getChildByName(array('oai_mods:mods', 'mods:mods', 'mods')); if (!isset($modsNode)) { $returner = null; return $returner; } $returner =& $this->handleRootNode($modsNode); $result->destroy(); $xmlParser->destroy(); return $returner; }
/** * Parse the installation descriptor XML file. * @return boolean */ function parseInstaller() { // Read installation descriptor file $this->log(sprintf('load: %s', $this->descriptor)); $xmlParser = new XMLParser(); $installPath = $this->isPlugin ? $this->descriptor : INSTALLER_DATA_DIR . DIRECTORY_SEPARATOR . $this->descriptor; $installTree = $xmlParser->parse($installPath); if (!$installTree) { // Error reading installation file $xmlParser->destroy(); $this->setError(INSTALLER_ERROR_GENERAL, 'installer.installFileError'); return false; } $versionString = $installTree->getAttribute('version'); if (isset($versionString)) { $this->newVersion =& Version::fromString($versionString); } else { $this->newVersion = $this->currentVersion; } // Parse descriptor $this->parseInstallNodes($installTree); $xmlParser->destroy(); $result = $this->getErrorType() == 0; HookRegistry::call('Installer::parseInstaller', array(&$this, &$result)); return $result; }
/** * Install the given filter configuration file. * @param $filterConfigFile string * @return boolean true when successful, otherwise false */ function installFilterConfig($filterConfigFile) { static $filterHelper = false; // Parse the filter configuration. $xmlParser = new XMLParser(); $tree =& $xmlParser->parse($filterConfigFile); // Validate the filter configuration. if (!$tree) { $xmlParser->destroy(); return false; } // Get the filter helper. if ($filterHelper === false) { import('lib.pkp.classes.filter.FilterHelper'); $filterHelper = new FilterHelper(); } // Are there any filter groups to be installed? $filterGroupsNode =& $tree->getChildByName('filterGroups'); if (is_a($filterGroupsNode, 'XMLNode')) { $filterHelper->installFilterGroups($filterGroupsNode); } // Are there any filters to be installed? $filtersNode =& $tree->getChildByName('filters'); if (is_a($filtersNode, 'XMLNode')) { foreach ($filtersNode->getChildren() as $filterNode) { /* @var $filterNode XMLNode */ $filterHelper->configureFilter($filterNode); } } // Get rid of the parser. $xmlParser->destroy(); unset($xmlParser); return true; }
/** * Parse all scheduled tasks files and * save the result object in database. */ function _parseCrontab() { $xmlParser = new XMLParser(); $taskFilesPath = array(); // Load all plugins so any plugin can register a crontab. PluginRegistry::loadAllPlugins(); // Let plugins register their scheduled tasks too. HookRegistry::call('AcronPlugin::parseCronTab', array(&$taskFilesPath)); // Reference needed. // Add the default tasks file. $taskFilesPath[] = 'registry/scheduledTasks.xml'; // TODO: make this a plugin setting, rather than assuming. $tasks = array(); foreach ($taskFilesPath as $filePath) { $tree = $xmlParser->parse($filePath); if (!$tree) { $xmlParser->destroy(); // TODO: graceful error handling fatalError('Error parsing scheduled tasks XML file: ' . $filePath); } foreach ($tree->getChildren() as $task) { $frequency = $task->getChildByName('frequency'); $args = ScheduledTaskHelper::getTaskArgs($task); // Tasks without a frequency defined, or defined to zero, will run on every request. // To avoid that happening (may cause performance problems) we // setup a default period of time. $setDefaultFrequency = true; $minHoursRunPeriod = 24; if ($frequency) { $frequencyAttributes = $frequency->getAttributes(); if (is_array($frequencyAttributes)) { foreach ($frequencyAttributes as $key => $value) { if ($value != 0) { $setDefaultFrequency = false; break; } } } } $tasks[] = array('className' => $task->getAttribute('class'), 'frequency' => $setDefaultFrequency ? array('hour' => $minHoursRunPeriod) : $frequencyAttributes, 'args' => $args); } $xmlParser->destroy(); } // Store the object. $this->updateSetting(0, 'crontab', $tasks, 'object'); }
/** * Install plugin settings from an XML file. * @param $conferenceId int ID of conference, if applicable * @param $schedConfId int ID of scheduled conference, if applicable * @param $pluginName name of plugin for settings to apply to * @param $filename string Name of XML file to parse and install * @param $paramArray array Optional parameters for variable replacement in settings */ function installSettings($conferenceId, $schedConfId, $pluginName, $filename, $paramArray = array()) { $xmlParser = new XMLParser(); $tree = $xmlParser->parse($filename); if (!$tree) { $xmlParser->destroy(); return false; } foreach ($tree->getChildren() as $setting) { $nameNode =& $setting->getChildByName('name'); $valueNode =& $setting->getChildByName('value'); if (isset($nameNode) && isset($valueNode)) { $type = $setting->getAttribute('type'); $name =& $nameNode->getValue(); if ($type == 'object') { $arrayNode =& $valueNode->getChildByName('array'); $value = $this->_buildObject($arrayNode, $paramArray); } else { $value = $this->_performReplacement($valueNode->getValue(), $paramArray); } // Replace translate calls with translated content $this->updateSetting($conferenceId, $schedConfId, $pluginName, $name, $value, $type); } } $xmlParser->destroy(); }
/** * Parse a record's contents into an object * @param $contents string * @return object */ function &parseContents(&$contents) { $xmlParser = new XMLParser(); $result =& $xmlParser->parseText($contents); $returner = array(); foreach ($result->getChildren() as $child) { $name = $child->getName(); $value = $child->getValue(); if (String::substr($name, 0, 6) == 'etdms:') { $name = String::substr($name, 3); } $returner[$name][] = $value; } $result->destroy(); $xmlParser->destroy(); unset($result, $xmlParser); return $returner; }
function parseCrontab() { $xmlParser = new XMLParser(); // TODO: make this a plugin setting, rather than assuming. $tree = $xmlParser->parse(Config::getVar('general', 'registry_dir') . '/scheduledTasks.xml'); if (!$tree) { $xmlParser->destroy(); // TODO: graceful error handling fatalError('Error parsing scheduled tasks XML.'); } $tasks = array(); foreach ($tree->getChildren() as $task) { $frequency = $task->getChildByName('frequency'); $args = array(); $index = 0; while (($arg = $task->getChildByName('arg', $index)) != null) { array_push($args, $arg->getValue()); $index++; } $tasks[] = array('className' => $task->getAttribute('class'), 'frequency' => $frequency ? $frequency->getAttributes() : null, 'args' => $args); } $xmlParser->destroy(); // Store the object. $this->updateSetting(0, 0, 'crontab', $tasks, 'object'); }
/** * Install plugin settings from an XML file. * @param $pluginName name of plugin for settings to apply to * @param $filename string Name of XML file to parse and install * @param $paramArray array Optional parameters for variable replacement in settings */ function installSettings($contextId, $pluginName, $filename, $paramArray = array()) { $xmlParser = new XMLParser(); $tree = $xmlParser->parse($filename); if (!$tree) { $xmlParser->destroy(); return false; } // Check for existing settings and leave them if they are already in place. $currentSettings = $this->getPluginSettings($contextId, $pluginName); foreach ($tree->getChildren() as $setting) { $nameNode = $setting->getChildByName('name'); $valueNode = $setting->getChildByName('value'); if (isset($nameNode) && isset($valueNode)) { $type = $setting->getAttribute('type'); $name = $nameNode->getValue(); // If the setting already exists, respect it. if (isset($currentSettings[$name])) { continue; } if ($type == 'object') { $arrayNode = $valueNode->getChildByName('array'); $value = $this->_buildObject($arrayNode, $paramArray); } else { $value = $this->_performReplacement($valueNode->getValue(), $paramArray); } // Replace translate calls with translated content $this->updateSetting($contextId, $pluginName, $name, $value, $type); } } $xmlParser->destroy(); }
/** * Install locale field Only journal settings from an XML file. * @param $journalId int ID of journal for settings to apply to * @param $filename string Name of XML file to parse and install * @param $paramArray array Optional parameters for variable replacement in settings * @param $locale string locale id for which settings will be loaded */ function reloadLocalizedDefaultSettings($journalId, $filename, $paramArray, $locale) { $xmlParser = new XMLParser(); $tree = $xmlParser->parse($filename); if (!$tree) { $xmlParser->destroy(); return false; } foreach ($tree->getChildren() as $setting) { $nameNode =& $setting->getChildByName('name'); $valueNode =& $setting->getChildByName('value'); if (isset($nameNode) && isset($valueNode)) { $type = $setting->getAttribute('type'); $isLocaleField = $setting->getAttribute('locale'); $name =& $nameNode->getValue(); //skip all settings that are not locale fields if (!$isLocaleField) { continue; } if ($type == 'object') { $arrayNode =& $valueNode->getChildByName('array'); $value = $this->_buildLocalizedObject($arrayNode, $paramArray, $locale); } else { $value = $this->_performLocalizedReplacement($valueNode->getValue(), $paramArray, $locale); } // Replace translate calls with translated content $this->updateSetting($journalId, $name, array($locale => $value), $type, true); } } $xmlParser->destroy(); }
/** * Update a single record by identifier. * @param $identifier string * @param $params array */ function updateRecord($identifier, $params = array()) { $verb = 'GetRecord'; $this->throttle(); $parser = new XMLParser(); $result =& $parser->parse($this->addParameters($this->oaiUrl, array('verb' => $verb, 'identifier' => $identifier, 'metadataPrefix' => $this->getMetadataFormat()))); if (!$parser->getStatus()) { foreach ($parser->getErrors() as $error) { $this->addError($error); } if (!$result) { return false; } } $parser->destroy(); unset($parser); if ($errorNode =& $result->getChildByName('error')) { $this->addError($errorNode->getValue()); } $verbNode =& $result->getChildByName($verb); $recordNode =& $result->getChildByName(array('record', 'oai:record')); if ($recordNode) { $this->handleRecordNode($recordNode); } $result->destroy(); return true; }
/** * SUSHI report * @param $useLegacyStats boolean */ function _sushiXML($useLegacyStats) { $templateManager =& TemplateManager::getManager(); $SOAPRequest = file_get_contents('php://input'); // crude handling of namespaces in the input // FIXME: only the last prefix in the input will be used for each namespace $soapEnvPrefix = ''; $sushiPrefix = ''; $counterPrefix = ''; $re = '/xmlns:([^=]+)="([^"]+)"/'; preg_match_all($re, $SOAPRequest, $mat, PREG_SET_ORDER); foreach ($mat as $xmlns) { $modURI = $xmlns[2]; if (strrpos($modURI, '/') + 1 == strlen($modURI)) { $modURI = substr($modURI, 0, -1); } switch ($modURI) { case 'http://schemas.xmlsoap.org/soap/envelope': $soapEnvPrefix = $xmlns[1]; break; case 'http://www.niso.org/schemas/sushi': $sushiPrefix = $xmlns[1]; break; case 'http://www.niso.org/schemas/sushi/counter': $counterPrefix = $xmlns[1]; break; } } if (strlen($soapEnvPrefix) > 0) { $soapEnvPrefix .= ':'; } if (strlen($sushiPrefix) > 0) { $sushiPrefix .= ':'; } if (strlen($counterPrefix) > 0) { $counterPrefix .= ':'; } $parser = new XMLParser(); $tree = $parser->parseText($SOAPRequest); $parser->destroy(); // is this necessary? if (!$tree) { $templateManager->assign('Faultcode', 'Client'); $templateManager->assign('Faultstring', 'The parser was unable to parse the input.'); header("HTTP/1.0 500 Internal Server Error"); $templateManager->display($this->getTemplatePath() . 'soaperror.tpl', 'text/xml'); } else { $reportRequestNode = $tree->getChildByName($soapEnvPrefix . 'Body')->getChildByName($counterPrefix . 'ReportRequest'); $requestorID = $reportRequestNode->getChildByName($sushiPrefix . 'Requestor')->getChildByName($sushiPrefix . 'ID')->getValue(); $requestorName = $reportRequestNode->getChildByName($sushiPrefix . 'Requestor')->getChildByName($sushiPrefix . 'Name')->getValue(); $requestorEmail = $reportRequestNode->getChildByName($sushiPrefix . 'Requestor')->getChildByName($sushiPrefix . 'Email')->getValue(); $customerReferenceID = $reportRequestNode->getChildByName($sushiPrefix . 'CustomerReference')->getChildByName($sushiPrefix . 'ID')->getValue(); $reportName = $reportRequestNode->getChildByName($sushiPrefix . 'ReportDefinition')->getAttribute('Name'); $reportRelease = $reportRequestNode->getChildByName($sushiPrefix . 'ReportDefinition')->getAttribute('Release'); $usageDateRange = $reportRequestNode->getChildByName($sushiPrefix . 'ReportDefinition')->getChildByName($sushiPrefix . 'Filters')->getChildByName($sushiPrefix . 'UsageDateRange'); $usageDateBegin = $usageDateRange->getChildByName($sushiPrefix . 'Begin')->getValue(); $usageDateEnd = $usageDateRange->getChildByName($sushiPrefix . 'End')->getValue(); $this->_assignTemplateCounterXML($templateManager, $usageDateBegin, $usageDateEnd, $useLegacyStats); $templateManager->assign('requestorID', $requestorID); $templateManager->assign('requestorName', $requestorName); $templateManager->assign('requestorEmail', $requestorEmail); $templateManager->assign('customerReferenceID', $customerReferenceID); $templateManager->assign('reportName', $reportName); $templateManager->assign('reportRelease', $reportRelease); $templateManager->assign('usageDateBegin', $usageDateBegin); $templateManager->assign('usageDateEnd', $usageDateEnd); $templateManager->assign('templatePath', $this->getTemplatePath()); $templateManager->display($this->getTemplatePath() . 'sushixml.tpl', 'text/xml'); } }
/** * Parse a record's contents into an object * @param $contents string * @return object */ function &parseContents(&$contents) { $xmlParser = new XMLParser(); $result =& $xmlParser->parseText($contents); $returner = array(); foreach ($result->getChildren() as $child) { $name = $child->getName(); switch ($child->getName()) { case 'varfield': $id = $child->getAttribute('id'); $i1 = $child->getAttribute('i1'); $i2 = $child->getAttribute('i2'); foreach ($child->getChildren() as $subfield) { if ($subfield->getName() != 'subfield') { continue; } $value = $subfield->getValue(); if (empty($value)) { continue; } $label = $subfield->getAttribute('label'); $returner[$id][$i1][$i2][$label][] = $value; } break; case 'datafield': $id = $child->getAttribute('tag'); $i1 = $child->getAttribute('ind1'); $i2 = $child->getAttribute('ind2'); foreach ($child->getChildren() as $subfield) { if ($subfield->getName() != 'subfield') { continue; } $value = $subfield->getValue(); if (empty($value)) { continue; } $label = $subfield->getAttribute('code'); $returner[$id][$i1][$i2][$label][] = $value; } break; case 'controlfield': break; } } $result->destroy(); $xmlParser->destroy(); unset($result, $xmlParser); return $returner; }
/** * Load the XML file and move the settings to the DB * @param $contextId * @param $filename * @return boolean true === success */ function installSettings($contextId, $filename) { $xmlParser = new XMLParser(); $tree = $xmlParser->parse($filename); if (!$tree) { $xmlParser->destroy(); return false; } foreach ($tree->getChildren() as $setting) { $roleId = hexdec($setting->getAttribute('roleId')); $nameKey = $setting->getAttribute('name'); $abbrevKey = $setting->getAttribute('abbrev'); $permitSelfRegistration = $setting->getAttribute('permitSelfRegistration'); $defaultStages = explode(',', $setting->getAttribute('stages')); $userGroup = $this->newDataObject(); // create a role associated with this user group $userGroup = $this->newDataObject(); $userGroup->setRoleId($roleId); $userGroup->setContextId($contextId); $userGroup->setPermitSelfRegistration($permitSelfRegistration); $userGroup->setDefault(true); // insert the group into the DB $userGroupId = $this->insertObject($userGroup); // Install default groups for each stage if (is_array($defaultStages)) { // test for groups with no stage assignments foreach ($defaultStages as $stageId) { if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { $this->assignGroupToStage($contextId, $userGroupId, $stageId); } } } // add the i18n keys to the settings table so that they // can be used when a new locale is added/reloaded $this->updateSetting($userGroup->getId(), 'nameLocaleKey', $nameKey); $this->updateSetting($userGroup->getId(), 'abbrevLocaleKey', $abbrevKey); // install the settings in the current locale for this context $this->installLocale(AppLocale::getLocale(), $contextId); } return true; }
/** * Load the XML file and move the settings to the DB * @param $pressId * @param $filename */ function installSettings($pressId, $filename) { $xmlParser = new XMLParser(); $tree = $xmlParser->parse($filename); if (!$tree) { $xmlParser->destroy(); return false; } foreach ($tree->getChildren() as $setting) { $roleId = hexdec($setting->getAttribute('roleId')); $nameKey = $setting->getAttribute('name'); $abbrevKey = $setting->getAttribute('abbrev'); $defaultStages = explode(",", $setting->getAttribute('stages')); $userGroup =& $this->newDataObject(); // create a role associated with this user group $role =& new Role($roleId); $userGroup =& $this->newDataObject(); $userGroup->setRoleId($roleId); $userGroup->setPath($role->getPath()); $userGroup->setPressId($pressId); $userGroup->setDefault(true); // insert the group into the DB $userGroupId = $this->insertUserGroup($userGroup); // Install default groups for each stage foreach ($defaultStages as $stageId) { if (!empty($stageId) && $stageId <= WORKFLOW_STAGE_ID_PRODUCTION && $stageId >= WORKFLOW_STAGE_ID_SUBMISSION) { $userGroupStageAssignmentDao =& DAORegistry::getDAO('UserGroupStageAssignmentDAO'); $userGroupStageAssignmentDao->assignGroupToStage($pressId, $userGroupId, $stageId); } } // add the i18n keys to the settings table so that they // can be used when a new locale is added/reloaded $this->updateSetting($userGroup->getId(), 'nameLocaleKey', $nameKey); $this->updateSetting($userGroup->getId(), 'abbrevLocaleKey', $abbrevKey); // install the settings in the current locale for this press $this->installLocale(Locale::getLocale(), $pressId); } }
/** * Install crosswalks from an XML file. * @param $filename string Name of XML file to parse and install * @param $paramArray array Optional parameters for variable replacement in crosswalks */ function installCrosswalks($filename, $paramArray = array()) { $xmlParser = new XMLParser(); $tree = $xmlParser->parse($filename); if (!$tree) { $xmlParser->destroy(); return false; } $schemaDao =& DAORegistry::getDAO('SchemaDAO'); $fieldDao =& DAORegistry::getDAO('FieldDAO'); foreach ($tree->getChildren() as $crosswalkNode) { $type = $crosswalkNode->getAttribute('type'); $publicId = $crosswalkNode->getAttribute('public_id'); $nameNode =& $crosswalkNode->getChildByName('name'); $descriptionNode =& $crosswalkNode->getChildByName('description'); if (isset($nameNode) && isset($descriptionNode)) { $name = $this->_performReplacement($nameNode->getValue()); $description = $this->_performReplacement($descriptionNode->getValue()); $crosswalk = new Crosswalk(); $crosswalk->setName($name); $crosswalk->setPublicCrosswalkId($publicId); $crosswalk->setDescription($description); $crosswalk->setSeq(REALLY_BIG_NUMBER); switch ($type) { case 'date': $crosswalk->setType(FIELD_TYPE_DATE); break; case 'select': $crosswalk->setType(FIELD_TYPE_SELECT); break; case 'text': case 'string': $crosswalk->setType(FIELD_TYPE_STRING); break; default: fatalError('Unknown field type "' . $type . '"!'); } $this->insertCrosswalk($crosswalk); $this->resequenceCrosswalks(); foreach ($crosswalkNode->getChildren() as $node) { if ($node->getName() == 'field') { $schemaPluginName = $node->getAttribute('schema'); $fieldName = $node->getAttribute('name'); $schema =& $schemaDao->buildSchema($schemaPluginName); $field =& $fieldDao->buildField($fieldName, $schemaPluginName); if ($field) { $this->insertCrosswalkField($crosswalk->getCrosswalkId(), $field->getFieldId()); } unset($schema); unset($field); } } unset($crosswalk); } } $xmlParser->destroy(); $tree->destroy(); }