protected function execute(InputInterface $input, OutputInterface $output) { $fileInfo = new \SplFileInfo($this->getContainer()->getParameter('kernel.root_dir') . '/../web/sitemap.xml'); if ($fileInfo->isFile() && $fileInfo->isReadable()) { $output->write('Reading sitemap.xml...'); $file = $fileInfo->openFile(); $xml = ''; while (!$file->eof()) { $xml .= $file->fgets(); } $output->writeln(' done.'); $output->write('Updating sitemap.xml...'); $sitemap = new \SimpleXMLIterator($xml); $sitemap->rewind(); $lastmodDate = new \DateTime(); $lastmodDate->sub(new \DateInterval('P1D')); $lastmodDateFormatted = $lastmodDate->format('Y-m-d'); while ($sitemap->valid()) { $sitemap->current()->lastmod = $lastmodDateFormatted; $sitemap->next(); } $file = $file->openFile('w'); $file->fwrite($sitemap->asXML()); $output->writeln(' done.'); } else { $output->writeln('Error: Cannot open file web/sitemap.xml'); } }
public function asXML($filename = null) { if (!$this->_iso()) return $filename ? parent::asXML($filename) : parent::asXML(); $xml = @parent::asXML(); $xml = utf8_decode($xml); if ($filename) file_put_contents($filename, $xml); return $xml; }
/** * get files to be uploaded * @param object \SimpleXMLIterator $data data * @return array */ public function getFormUploadFields($data) { $data = new \SimpleXMLIterator($data->asXML()); if (isset($data->values->values->formId)) { $object = new \stdClass(); $object->id = $data->values->values->formId; $object->fields = array('xmlDefinition'); $res = $this->getOne($object); $formXml = file_get_contents('/var/www/htdocs/uploads/' . $res['fields']['xmlDefinition']); $formXml = new \SimpleXMLIterator($formXml); $uploadsFields = $formXml->xpath('//input[@type="file"]'); foreach ($uploadsFields as $field) { $controlName = (string) $field['name']; $control = $data->xpath('//' . $controlName); $fieldAnswers[] = array('fieldName' => $controlName, 'value' => (string) $control[0]); } return array('fields' => $fieldAnswers); } else { return false; } }
protected function updateAPP() { if (is_file($this->applist) && is_writable($this->applist)) { try { $doc = new SimpleXMLIterator($this->applist, null, true); } catch (Exception $e) { $this->error[] = "发生异常:" . $e->getMessage() . " 文件:" . $e->getFile() . " 行号:" . $e->getLine(); return false; } if ($doc->getName() != "apps") { $this->error[] = "applist.xml的根元素必须是apps"; return false; } $i = $doc->count(); if ($i !== 0) { $apps = $doc->app; foreach ($apps as $app) { if ($app['name'] == $this->app_name) { $this->error[] = "项目列表存在重名项目,请修改项目名称"; return false; } } } $doc->addChild("app"); $doc->app[$i]->addAttribute("name", $this->app_name); $doc->app[$i]->addAttribute("path", $this->app_path); $doc->app[$i]->addAttribute("index", $this->app_index); if ($doc->asXML($this->applist)) { return true; } else { $this->error[] = "TinkPHP助手/data/applist.xml 写入失败"; return false; } } else { $this->error[] = "TinkPHP助手/data/applist.xml不存在"; return false; } }