public function execute(){ // If it exists and is good, nothing else needs to be done, (other than flush the session data) // This is hit if the user has to manually copy in the configuration.xml data. if(file_exists(ROOT_PDIR . '/config/configuration.xml')){ unset($_SESSION['configs']); $this->setAsPassed(); reload(); } // Load in the configuration example, merge in the SESSION data, and apply them or display the code. $xml = new \XMLLoader(); $xml->setRootName('configuration'); $xml->loadFromFile(ROOT_PDIR . 'config/configuration.example.xml'); $elements = $xml->getElements('return|define'); foreach($elements as $el){ $name = $el->getAttribute('name'); $children = $el->childNodes; foreach($children as $c){ if($c->nodeName == 'value'){ // This one requires a random string. if($name == 'SECRET_ENCRYPTION_PASSPHRASE' && isset($_SESSION['configs'][$name]) && $_SESSION['configs'][$name] == 'RANDOM'){ $value = \Core\random_hex(96); $c->nodeValue = $value; } elseif($name == 'SERVER_ID' && isset($_SESSION['configs'][$name]) && $_SESSION['configs'][$name] == 'RANDOM'){ // The server ID is a 32-digit random string. $value = \Core\random_hex(32); $c->nodeValue = $value; } // An override is provided, use that and overwrite the xml. elseif(isset($_SESSION['configs'][$name])){ $value = $_SESSION['configs'][$name]; $c->nodeValue = $value; } } } } // Try to save this back down. $fdata = $xml->asPrettyXML(); if(is_writable(ROOT_PDIR . '/config')){ // Just automatically copy it over, (with the necessary tranformations). file_put_contents(ROOT_PDIR . 'config/configuration.xml', $fdata); unset($_SESSION['configs']); $this->setAsPassed(); reload(); // :) } else{ // Display the instructions to the user. $this->getTemplate()->assign('contents', $fdata); } }
/** * Read current configuration from disk * * @access public * @param string name of the configuration file * @return bool true on success */ function fromXML($fileName) { if (!file_exists($fileName)) { Amber::showError('Error', 'Config file not found: ' . htmlspecialchars($fileName)); return false; } $loader = new XMLLoader(false); $res = $loader->getArray($fileName); if (is_array($res) && is_array($res['config'])) { foreach ($res['config'] as $key => $value) { $this->{$key} = $value; } } return true; }
/** * Get all screenshots in this metafile * * @return array */ public function getScreenshots() { $s = $this->_xmlloader->getElements('//screenshots/screenshot'); if (!$s) { return []; } else { $f = \Core\Filestore\Factory::File($this->getBaseDir() . $s->getAttribute('file')); return ['file' => $f, 'title' => $s->getAttribute('title') ? $s->getAttribute('title') : $this->getName()]; } }
private function verifyId() { $this->feed = file_get_contents($this->xml); $xml = XMLLoader::loadString($this->feed); foreach ($xml->children() as $video) { if ($video->id == '') { throw new VideoNotExistsException(); } } }
/** * Get requested DB driver. * By default XML configured driver is return. * @param string $type * @return Driver */ public static function getDriver($type = null) { if (!self::$instance) { $config = XMLLoader::load(DB_FILE); if ($type == null) { $type = $config->driver; } $driver = $type . DRIVER; self::$instance = new $driver($config); } return self::$instance; }
/** * Helper function to see if there is a valid upgrade path from the current version installed * to the version of the code available. * * @return bool */ private function _checkUpgradePath(){ // Check that if the version installed is not what's in the component file, that there is a valid upgrade path. if($this->_versionDB && $this->_version != $this->_versionDB){ // Assemble an array of upgrade paths, with the key/pairs being from//to versions. $paths = array(); foreach ($this->_xmlloader->getRootDOM()->getElementsByTagName('upgrade') as $u) { $from = $u->getAttribute('from'); $to = $u->getAttribute('to'); if(!isset($paths[$from])) $paths[$from] = array(); $paths[$from][] = $to; } if(!sizeof($paths)){ // No upgrade paths even defined! return false; } // Sort them version descending, makes finding the highest version number easier foreach($paths as $k => $vs){ rsort($paths[$k], SORT_NATURAL); } $current = $this->_versionDB; $x = 0; // My anti-infinite-loop counter. while($current != $this->_version && $x < 20){ ++$x; if(isset($paths[$current])){ $current = $paths[$current][0]; } else{ return false; } } // Yay, if it's gotten here, that means that there was a valid upgrade path! return true; } else{ // Easy enough :) // The else is that it's installed and up to date. return true; } }
/** * Get the associated XMLLoader object for this data * * @return \XMLLoader */ public function getLoader(){ $xml = new \XMLLoader(); $xml->loadFromFile($this->_file); return $xml; }
// Skip non-xml files if(!preg_match('/\.xml$/i', $file)) continue; $bundlefiles[] = $file; } closedir($dh); } } // They should be in alphabetical order... sort($bundlefiles); // Transpose them to the keyname => human readable name. foreach($bundlefiles as $b){ // Open it up $xml = new XMLLoader(); $xml->setRootName('bundler'); $xml->loadFromFile($dir . '/' . $b); $name = $xml->getRootDOM()->getAttribute('name'); $sname = preg_replace('/[^a-z0-9-\.\+]*/i', '', str_replace(' ', '-', $name)); $bundles[] = [ 'file' => $b, 'name' => $name, 'sname' => $sname, 'xml' => $xml, ]; } if(!sizeof($bundles)){
public function execute(){ // If there's already a configuration file present... just skip to the next. if(file_exists(ROOT_PDIR . '/config/configuration.xml')){ $this->setAsPassed(); reload(); } // This will contain the temporary configuration values for the installer. if(!isset($_SESSION['configs'])) $_SESSION['configs'] = []; $xml = new \XMLLoader(); $xml->setRootName('configuration'); $xml->loadFromFile(ROOT_PDIR . 'config/configuration.example.xml'); $formelements = []; // Since we're pulling from the ant version, set some nice defaults for the user. $valuedefaults = [ '@{db.server}@' => 'localhost', '@{db.port}@' => '3306', '@{db.type}@' => 'mysqli', '@{db.name}@' => '', '@{db.user}@' => '', '@{db.pass}@' => '', '@{devmode}@' => 'false', '/tmp/coreplus-web/' => '/tmp/' . $_SERVER['HTTP_HOST'] . '-web/', '/tmp/coreplus-cli/' => '/tmp/' . $_SERVER['HTTP_HOST'] . '-cli/', 'RANDOM' => \Core\random_hex(96), ]; $elements = $xml->getElements('return|define'); foreach($elements as $el){ $node = $el->nodeName; $name = $el->getAttribute('name'); $type = $el->getAttribute('type'); $formtype = $el->getAttribute('formtype'); $advanced = $el->getAttribute('advanced'); $children = $el->childNodes; $value = null; $valuenode = null; $description = null; $options = []; // Defaults if($advanced === null || $advanced === '') $advanced = "1"; foreach($children as $c){ switch($c->nodeName){ case 'value': $value = trim($c->nodeValue); $valuenode = $c; break; case 'description': $description = trim($c->nodeValue); break; case 'option': $options[] = trim($c->nodeValue); break; case '#text': break; case '#comment': break; default: trigger_error('Unknown sub-node for ' . $node . ' ' . $name . ': ' . $c->nodeName); } } // Since we're pulling from the ant version, set some nice defaults for the user. if(isset($valuedefaults[$value])){ $value = $valuedefaults[$value]; } // Save the value? if($_SERVER['REQUEST_METHOD'] == 'POST'){ if($type == 'boolean' && $formtype == 'checkbox'){ $value = isset($_POST[$name]) ? 'true' : 'false'; } else{ $value = isset($_POST[$name]) ? $_POST[$name] : ''; } $_SESSION['configs'][$name] = $value; } elseif(isset($_SESSION['configs'][$name])){ $value = $_SESSION['configs'][$name]; } //$value = $el->getElement('value')->nodeValue; // Throw this element onto the array for the template to render out. $formelements[] = [ 'name' => $name, // Make the title more appealing than machine names... 'title' => ucwords(strtolower(str_replace('_', ' ', $name))), // Remap "formtype" to "type", since this will be used in a form afterall! 'type' => $formtype, 'value' => $value, 'description' => $description, 'options' => $options, 'advanced' => $advanced, ]; } // If it's a POST... try the settings and if valid, proceed. $message = null; $instructions = null; if($_SERVER['REQUEST_METHOD'] == 'POST'){ if($message === null){ $connectionresults = $this->testDatabaseConnection(); if($connectionresults['status'] != 'passed'){ //var_dump($connectionresults); die(); $message = $connectionresults['message']; $instructions = $connectionresults['instructions']; } } if($message === null){ // Test the assets too! $results = $this->testDirectoryWritable('assets/'); if($results['status'] != 'passed'){ //var_dump($connectionresults); die(); $message = $results['message']; $instructions = $results['instructions']; } } if($message === null){ // Test the assets too! $results = $this->testDirectoryWritable('public/'); if($results['status'] != 'passed'){ //var_dump($connectionresults); die(); $message = $results['message']; $instructions = $results['instructions']; } } if($message === null){ // Still null after all the tests have ran? // w00t! $this->setAsPassed(); reload(); } } $this->getTemplate()->assign('message', $message); $this->getTemplate()->assign('instructions', $instructions); $this->getTemplate()->assign('formelements', $formelements); //var_dump($formelements);// die(); }
protected function getVideoDetails() { $unserialized = Serializer::unserialize($this->video->getFeed()); return XMLLoader::loadString($unserialized); }
/** * Helper utility to import a given remote blog. * * @param bool $verbose Set to true to enable real-time verbose output of the operation. * @return array * * @throws Exception */ public function importFeed($verbose = false) { $blogid = $this->get('id'); if (!$this->exists()) { throw new Exception('Unable to import a blog that does not exist!'); } // Make sure this is a remote blog. if ($this->get('type') != 'remote') { throw new Exception('Cannot import a blog that is not remote!'); } $file = \Core\Filestore\Factory::File($this->get('remote_url')); if (!$file->exists()) { throw new Exception($this->get('remote_url') . ' does not appear to exist'); } $defaults = ['parenturl' => $this->get('baseurl'), 'site' => $this->get('site'), 'component' => 'blog']; $changes = ['added' => 0, 'updated' => 0, 'skipped' => 0, 'deleted' => 0]; $changelog = ''; // I need a list of current articles in this feed. This is because remote deletions won't be coming in on the feed. $map = array(); $articles = BlogArticleModel::FindRaw(['blogid = ' . $blogid]); foreach ($articles as $a) { $map[$a['guid']] = $a['id']; } // I can't trust that remote files list what they actually are because many frameworks, // (WP in specific), do not correctly use content-types :/ $contents = $file->getContents(); // Which feed type is this? $header = substr($contents, 0, 400); // All the standardized records $records = array(); if (strpos($header, '<rss ') !== false) { if ($verbose) { echo 'Found an RSS feed with the URL of ' . $file->getURL() . '!<br/>' . "\n"; ob_flush(); flush(); } $xml = new XMLLoader(); $xml->setRootName('rss'); $xml->loadFromString($contents); foreach ($xml->getElements('channel/item') as $item) { $dat = ['guid' => '', 'link' => '', 'thumbnail' => '', 'published' => '', 'updated' => '', 'description' => '']; foreach ($item->childNodes as $child) { if ($child->nodeName == '#text') { continue; } switch ($child->nodeName) { case 'media:thumbnail': $dat['thumbnail'] = $child->getAttribute('url'); break; case 'pubDate': $dat['published'] = $child->nodeValue; break; default: $dat[$child->nodeName] = $child->nodeValue; } } $records[] = $dat; } } elseif (strpos($header, 'http://www.w3.org/2005/Atom') !== false) { if ($verbose) { echo 'Found an ATOM feed with the URL of ' . $file->getURL() . '!<br/>' . "\n"; ob_flush(); flush(); } $xml = new XMLLoader(); $xml->setRootName('feed'); $xml->loadFromString($contents); foreach ($xml->getRootDOM()->childNodes as $item) { if ($item->nodeName != 'entry') { continue; } $dat = ['guid' => '', 'link' => '', 'thumbnail' => '', 'published' => '', 'updated' => '', 'description' => '']; $imgheight = 0; foreach ($item->childNodes as $child) { if ($child->nodeName == '#text') { continue; } switch ($child->nodeName) { case 'id': $dat['guid'] = $child->nodeValue; break; case 'link': if ($child->getAttribute('rel') == 'alternate' && $child->getAttribute('type') == 'text/html') { if ($child->nodeValue) { $dat['link'] = $child->nodeValue; } else { $dat['link'] = $child->getAttribute('href'); } } break; case 'im:image': if ($child->getAttribute('height') > $imgheight) { $dat['thumbnail'] = $child->nodeValue; $imgheight = $child->getAttribute('height'); } break; case 'updated': $dat['updated'] = strtotime($child->nodeValue); break; case 'summary': if ($dat['description'] != '') { $dat['description'] = $child->nodeValue; } break; case 'content': $dat['description'] = $child->nodeValue; break; default: $dat[$child->nodeName] = $child->nodeValue; } } if (!$dat['published'] && $dat['updated']) { // make sure that there's a published date. $dat['published'] = $dat['updated']; } $records[] = $dat; } } else { throw new Exception('Invalid remote file found, please ensure it is either an RSS or Atom feed!'); } // Now that they're standardized... foreach ($records as $dat) { /** @var PageModel $page */ $page = PageModel::Construct($dat['link']); $published = $dat['published'] == '' || is_numeric($dat['published']) ? $dat['published'] : strtotime($dat['published']); $updated = $dat['updated'] != '' ? is_numeric($dat['updated']) ? $dat['updated'] : strtotime($dat['updated']) : $published; $pagedat = ['published' => $published, 'title' => $dat['title'], 'body' => $dat['description'], 'updated' => $updated]; $newpagedat = array_merge($defaults, ['selectable' => '0']); $page->setFromArray($pagedat); if (!$page->exists()) { // Add the "new" dat only if the page doesn't exist before. $page->setFromArray($newpagedat); } if ($dat['thumbnail']) { $remote = \Core\Filestore\Factory::File($dat['thumbnail']); $new = $remote->copyTo('public/blog/'); $page->setMeta('image', $new->getFilename(false)); } $page->setMeta('guid', $dat['guid']); $thischange = $page->exists() ? 'updated' : 'added'; if ($page->changed()) { $page->save(); $changes[$thischange]++; $changelog .= $thischange . ' ' . $dat['title'] . "<br/>\n"; if ($verbose) { echo $thischange . ' ' . $dat['title'] . "<br/>\n"; ob_flush(); flush(); } } else { $changes['skipped']++; if ($verbose) { echo 'No changes to ' . $dat['title'] . "<br/>\n"; ob_flush(); flush(); } } } return ['status' => 1, 'message' => 'Import feed successfully!', 'added' => $changes['added'], 'updated' => $changes['updated'], 'deleted' => $changes['deleted'], 'skipped' => $changes['skipped'], 'changelog' => $changelog]; }
/** * Test that I can load the ATOM page and that it returns valid XML. * The XMLLoader will take care of the validation, since it should be a valid document anyway. */ public function testATOMPage() { // Get the RSS feed and download it to a local file. $rewriteurl = $this->blog->get('rewriteurl'); $this->assertNotEmpty($rewriteurl); // Go to the page and make sure that it loads up! $request = new PageRequest($rewriteurl . '.atom'); $request->execute(); $view = $request->getView(); $this->assertEquals(200, $view->error); $markup = $view->fetch(); $this->assertNotEmpty($markup); // DEVELOPMENT DEBUG //echo $markup; // DEBUG // $xml = new XMLLoader(); $xml->setRootName('feed'); // If it's invalid markup, this load will throw an error, causing phpunit to return an error :) // If the bug is fixed, this will not throw any errors. $xml->loadFromString($markup); $parsedmarkup = $xml->asMinifiedXML(); $this->assertNotEmpty($parsedmarkup); }
} closedir($dh); unset($file, $version, $title, $c, $dh); // Load in all themes currently on the system $dir = ROOT_PDIR . 'themes'; $dh = opendir($dir); while(($file = readdir($dh)) !== false){ if($file{0} == '.') continue; if(!is_dir($dir . '/' . $file)) continue; if(!is_readable($dir . '/' . $file . '/' . 'theme.xml')) continue; $t = ThemeHandler::GetTheme($file); // What's this file's version? $xml = new XMLLoader(); $xml->setRootName('theme'); if(!$xml->loadFromFile($dir . '/' . $file . '/theme.xml')){ CLI::PrintLine('Skipping theme ' . $file . ', unable to load XML file'); continue; } // Get the current version, this will be used to autocomplete for the next version. //$version = $xml->getRootDOM()->getAttribute("version"); $version = $t->getVersion(); // If display versions is requested, tack on the version number too! if($opts['listversions']){ $title = 'Theme/' . $t->getName() . ' ' . $version; } else{
/** * * @access public * @param string report's design as XML * */ function initialize_report($strXML) { // // Common initialization // $res =& XMLLoader::_makeXMLTree($strXML); if (count($res) == 0) { Amber::showError('Parse error', XMLLoader::getParseError()); die; } $xml = $res['report']; $this->Width = $xml['Width']; if (!$this->Name) { $this->Name = $xml['Name']; } if (isset($xml['Printer'])) { $prt =& $xml['Printer']; $this->LeftMargin = empty($prt['LeftMargin']) ? 720 : $prt['LeftMargin']; $this->RightMargin = empty($prt['RightMargin']) ? 720 : $prt['RightMargin']; $this->TopMargin = empty($prt['TopMargin']) ? 720 : $prt['TopMargin']; $this->BottomMargin = empty($prt['BottomMargin']) ? 720 : $prt['BottomMargin']; $this->Orientation = MSPageOrientation($prt['Orientation']); MSPageSize($prt['PaperSize'], $this->PaperSize, $this->PaperWidth, $this->PaperHeight); } if ($xml['RecordSource']) { $this->RecordSource = $xml['RecordSource']; } $this->hReport = objectHandler::getHandle($this); /* * Sections */ $sections = array('ReportHeader', 'PageHeader', 'Detail', 'ReportFooter', 'PageFooter'); foreach ($sections as $secName) { if (isset($xml[$secName])) { $this->{$secName} =& new Section($secName); $this->Sections[$secName] =& $this->{$secName}; $this->{$secName}->load($this, $xml[$secName]); } else { $this->{$secName} =& new SectionNull($secName); $this->Sections[$secName] =& $this->{$secName}; $this->{$secName}->load($this, array()); } } /* * Group Sections */ $groupSections = array('GroupHeaders', 'GroupFooters'); foreach ($groupSections as $groupSecName) { if (is_array($xml[$groupSecName])) { foreach ($xml[$groupSecName] as $i => $sectionXML) { $t =& $this->{$groupSecName}; // reference to array $t[$i] =& new GroupSection($groupSecName); $t[$i]->load($this, $sectionXML); $this->Sections[$t[$i]->Name] =& $t[$i]; } } } /* * in labels: change property Parent from name (string) to reference (&obj) */ //FIXME: this should be moved to Control-Class (with a few parameter-changes.....) if (is_array($this->Controls)) { foreach ($this->Controls as $i => $ctrl) { if (isset($ctrl->Parent)) { if (!isset($this->Controls[$ctrl->Parent])) { Amber::showError('Internal Error', 'Referenced parent control with name="' . $ctrl->Parent . '" does not exist.'); die; } $this->Controls[$i]->Parent =& $this->Controls[$ctrl->Parent]; $this->Controls[$i]->Properties['Parent'] =& $this->Controls[$ctrl->Parent]; } } } /* * Group Levels */ if (is_array($xml['GroupLevels'])) { foreach ($xml['GroupLevels'] as $i => $levelXML) { $this->GroupLevels[$i] =& new GroupLevel(); $this->GroupLevels[$i]->load($levelXML); } } // mirror controls and sections into user space $this->_Code->initialize($this); }
public function load() { $XMLFilename = $this->getXMLFilename(); // Can't read the file? nothing to load... if (!is_readable($XMLFilename)) { throw new Exception('Unable to open XML Metafile [' . $XMLFilename . '] for reading.'); } // Start the load procedure. $this->setFilename($XMLFilename); $this->setRootName($this->_type); if (!parent::load()) { throw new Exception('Parsing of XML Metafile [' . $XMLFilename . '] failed, not valid XML.'); } if (strtolower($this->getRootDOM()->getAttribute("name")) != strtolower($this->_name)) { throw new Exception('Name mismatch in XML Metafile [' . $XMLFilename . '], defined name does not match expected name.'); } $this->_version = $this->getRootDOM()->getAttribute("version"); }
if ($fileOne != null && $fileOne != "" && $fileTwo != null && $fileTwo != "") { if (!file_exists($fileOne)) { echo "The first specified file doesn't exist<br/>"; echo "<a href = 'home.php'>Run the Tool Again</a><br />"; return; } if (!file_exists($fileTwo)) { echo "The second specified file doesn't exist<br/>"; echo "<a href = 'home.php'>Run the Tool Again</a><br />"; return; } //echo "<style>"; //include "stylenew.css"; //echo "</style>"; include "xmlLoader.php"; $xmlLoader = new XMLLoader($fileOne); $doc = new DOMDocument(); $doc->load($fileTwo); $results; $xmlLoader->compareXML($doc, $results); $previousCategory = ""; echo "<link rel=\"stylesheet\" href=\"style.css\" media=\"screen\" type=\"text/css\" />"; foreach ($results as $result) { if (strcmp($previousCategory, $result->category) != 0) { if (strcmp($previousCategory, "") != 0) { echo "</table>"; echo "<br/>"; } echo "<table summary=\"Result Table - {$result->category}\" class=\"main\" cellspacing=\"0\">"; echo "<tr>"; echo "<td colspan=\"3\" class=\"header\">Category: {$result->category}</td>";
/** * @access private * @param string name of the report * @return Report */ function &loadReport($name) { $repPath = $this->_basePath . '/reports/'; $xmlLoader = new XMLLoader(); $res =& $xmlLoader->getArray($repPath . '/' . $name . '.xml'); $param = $res['report']; $obj = new AmberObjectRaw(); $obj->type = $this->objectTypes['report']; if (isset($param['Name'])) { $obj->name = $param['Name']; } $obj->design = file_get_contents($repPath . '/' . $param['FileNameDesign']); if (isset($param['FileNameCode']) && isset($param['ClassName'])) { $obj->class = $param['ClassName']; $obj->code = trim(file_get_contents($repPath . '/' . $param['FileNameCode'])); } return $obj; }