/** * Create a new XML document. * If $url is set, the DOCTYPE definition is treated as a PUBLIC * definition; $dtd should contain the ID, and $url should contain the * URL. Otherwise, $dtd should be the DTD name. */ function &createDocument($type = null, $dtd = null, $url = null) { $version = '1.0'; if (class_exists('DOMImplementation')) { // Use the new (PHP 5.x) DOM $impl = new DOMImplementation(); // only generate a DOCTYPE if type is non-empty if ($type != '') { $domdtd = $impl->createDocumentType($type, isset($url) ? $dtd : '', isset($url) ? $url : $dtd); $doc = $impl->createDocument($version, '', $domdtd); } else { $doc = $impl->createDocument($version, ''); } // ensure we are outputting UTF-8 $doc->encoding = 'UTF-8'; } else { // Use the XMLNode class $doc = new XMLNode(); $doc->setAttribute('version', $version); if ($type !== null) { $doc->setAttribute('type', $type); } if ($dtd !== null) { $doc->setAttribute('dtd', $dtd); } if ($url !== null) { $doc->setAttribute('url', $url); } } return $doc; }
function startTagElement(&$parserHandle, $elementName, $attributes) { if (!isset($this->node)) { if (!isset($this->document)) { $this->document = new XMLDocument(); $this->node =& new XMLNode(); $this->node->node_type = XML_ELEMENT; $this->node->node_name = $elementName; $this->node->node_value = array(); $keys = array_keys($attributes); for ($i = 0; $i < count($keys); $i++) { $this->node->setAttribute(new XMLAttribute($keys[$i], $attributes[$keys[$i]])); } $this->document->setRootNode($this->node); } else { print "ERROR !"; } } else { $new_node = new XMLNode(); $new_node->node_type = XML_ELEMENT; $new_node->node_name = $elementName; $keys = array_keys($attributes); for ($i = 0; $i < count($keys); $i++) { $new_node->setAttribute(new XMLAttribute($keys[$i], $attributes[$keys[$i]])); } $this->node->node_value = array(); $this->node =& $this->node->appendChild($new_node); } }
public function getEntities() { REST::requireRequestMethod('GET'); $db = new MySQL(); $entitiesNode = new XMLNode('entities'); foreach (Model::getEntities() as $entity) { $entityNode = new XMLNode('entity'); $entityNode->setAttribute('identifier', $entity['IDENTIFIER']); $entityNode->setAttribute('friendlyname', $entity['FRIENDLYNAME']); $entityNode->setAttribute('lat', $entity['LATITUDE']); $entityNode->setAttribute('lon', $entity['LONGITUDE']); $entityNode->setAttribute('date', strtotime($entity['DATETIME'])); $entitiesNode->addNode($entityNode); } $xmlDoc = new XMLDocument(); $xmlDoc->setRootNode($entitiesNode); REST::sendResponse(200, $xmlDoc, 'application/xml'); }
public function getZones() { REST::requireRequestMethod('GET'); $zonesNode = new XMLNode('zones'); foreach (Model::getZones() as $zone) { $zoneNode = new XMLNode('zone'); $zoneNode->setAttribute('id', $zone['ID']); $zoneNode->setAttribute('type', $zone['TYPE']); $zoneNode->setAttribute('date', strtotime($zone['CREATED_ON'])); $zoneNode->setAttribute('deleted', $zone['DELETED_ON'] != '0000-00-00 00:00:00' ? 'true' : 'false'); $waypointsNode = new XMLNode('waypoints'); foreach (Model::getWaypoints($zone['ID']) as $waypoint) { $waypointNode = new XMLNode('waypoint'); $waypointNode->setAttribute('latitude', $waypoint['LATITUDE']); $waypointNode->setAttribute('longitude', $waypoint['LONGITUDE']); $waypointsNode->addNode($waypointNode); } $zoneNode->addNode($waypointsNode); $zonesNode->addNode($zoneNode); } $xmlDoc = new XMLDocument(); $xmlDoc->setRootNode($zonesNode); REST::sendResponse(200, $xmlDoc, 'application/xml'); }
public function getTileUrl() { REST::requireRequestMethod('GET'); $requiredParameters = array('lat', 'lon', 'zoom'); if (Util::isValid($requiredParameters, $values, $this->params)) { extract($values); $url = "http://tile.openstreetmap.org/" . Map::getTileNumber($lat, $lon, $zoom) . ".png"; $urlNode = new XMLNode('url'); $urlNode->setAttribute('href', $url); $mapNode = new XMLNode('map'); $mapNode->setAttributes($values); $mapNode->addNode($urlNode); $xmlDoc = new XMLDocument(); $xmlDoc->setRootNode($mapNode); REST::sendResponse(200, $xmlDoc, 'application/xml'); } else { REST::sendResponse(400); } }
/** * Get all scheduled tasks that needs to be executed. * @return array */ function _getTasksToRun() { $tasksToRun = array(); $isEnabled = $this->getSetting(0, 'enabled'); if ($isEnabled) { $taskDao =& DAORegistry::getDao('ScheduledTaskDAO'); // Grab the scheduled scheduled tree $scheduledTasks = $this->getSetting(0, 'crontab'); if (is_null($scheduledTasks)) { $this->_parseCrontab(); $scheduledTasks = $this->getSetting(0, 'crontab'); } foreach ($scheduledTasks as $task) { // We don't allow tasks without frequency, see _parseCronTab(). $frequency = new XMLNode(); $frequency->setAttribute(key($task['frequency']), current($task['frequency'])); $canExecute = ScheduledTaskHelper::checkFrequency($task['className'], $frequency); if ($canExecute) { $tasksToRun[] = $task; } } } return $tasksToRun; }
/** * @see PKPPageRouter::loadHandler() */ function callbackLoadHandler($hookName, $args) { $isEnabled = $this->getSetting(0, 'enabled'); if ($isEnabled) { $taskDao = DAORegistry::getDao('ScheduledTaskDAO'); // Grab the scheduled scheduled tree $scheduledTasks = $this->getSetting(0, 'crontab'); if (is_null($scheduledTasks)) { $this->_parseCrontab(); $scheduledTasks = $this->getSetting(0, 'crontab'); } foreach ($scheduledTasks as $task) { // We don't allow tasks without frequency, see _parseCronTab(). $frequency = new XMLNode(); $frequency->setAttribute(key($task['frequency']), current($task['frequency'])); $canExecute = ScheduledTaskHelper::checkFrequency($task['className'], $frequency); if ($canExecute) { // Strip off the package name(s) to get the base class name $className = $task['className']; $pos = strrpos($className, '.'); if ($pos === false) { $baseClassName = $className; } else { $baseClassName = substr($className, $pos + 1); } $taskArgs = array(); if (isset($task['args'])) { $taskArgs = $task['args']; } // There's a race here. Several requests may come in closely spaced. // Each may decide it's time to run scheduled tasks, and more than one // can happily go ahead and do it before the "last run" time is updated. // By updating the last run time as soon as feasible, we can minimize // the race window. TODO: there ought to be a safer way of doing this. $taskDao->updateLastRunTime($className, time()); // Load and execute the task import($className); $task = new $baseClassName($taskArgs); $task->execute(); } } } return false; }