/** * */ public function adminGenerator() { $xml = new DOMDocument('1.0', 'utf-8'); $xml->preserveWhiteSpace = false; $xml->formatOutput = true; $root = $xml->createElement('backups'); $xml->appendChild($root); $root->appendChild($xml->createElement('suggest'))->nodeValue = date('YmdHis'); $list = scandir(__DIR__ . '/data/'); $zip = new ZipArchive(); foreach ($list as $filename) { if (pathinfo($filename, PATHINFO_EXTENSION) == 'zip') { $zip->open(__DIR__ . '/data/' . $filename); $description = $zip->getArchiveComment(); $zip->close(); $desc_node = $xml->createElement('backup'); $desc_node->appendChild($xml->createElement('filename'))->nodeValue = iconv('windows-1251', 'utf-8', $filename); $desc_node->appendChild($xml->createElement('filesize'))->nodeValue = $this->fileSizeDynamic(filesize(__DIR__ . '/data/' . $filename)); $desc_node->appendChild($xml->createElement('description'))->nodeValue = $description; $root->appendChild($desc_node); } } return XSLTransform($xml->saveXML($root), __DIR__ . '/form.xsl'); }
/** * Here generated data for module configuration dialog * */ public function AJAXHandler() { if (!user_allowed_to('manage modules')) { terminate('Forbidden', '', 403); } // фильтруем вход $input_filter = array('target' => array('filter' => FILTER_VALIDATE_REGEXP, 'options' => array('regexp' => '~^[a-zA-Z0-9\\_\\-]+$~ui')), 'action' => array('filter' => FILTER_VALIDATE_REGEXP, 'options' => array('regexp' => '~^[a-zA-Z0-9\\_\\-]+$~ui')), 'value' => array('filter' => FILTER_VALIDATE_REGEXP, 'options' => array('regexp' => '~^[\\sa-zA-Zа-яА-Я0-9\\_\\-%!@$^*\\(\\)\\[\\]&=.,/\\\\]+$~ui')), 'hash' => array('filter' => FILTER_VALIDATE_REGEXP, 'options' => array('regexp' => '~^[a-zA-Z0-9]+$~ui'))); $_INPUT = get_filtered_input($input_filter); switch ($_INPUT['action']) { case 'get_settings': if (($module_name = $_INPUT['target']) == '') { terminate('Unknown module [from:admin]', '', 404); } // get config XML, mark nodes, transform and return $xml = new DOMDocument('1.0', 'utf-8'); if ($module_name == self::CMS_SETTINGS_MODULE_PHANTOM) { $xml->loadXML($this->CMSSettingsXML()); } else { $xml->load(get_module_config_filename($module_name)); } $this->iterateAndMark($xml); return XSLTransform($xml->saveXML($xml->documentElement), __DIR__ . '/settings_box.xsl'); break; case 'save_setting': if (($module_name = $_INPUT['target']) == '') { terminate('Unknown module [from:admin]', '', 404); } // first, get right XML $xml = new DOMDocument('1.0', 'utf-8'); if ($module_name == self::CMS_SETTINGS_MODULE_PHANTOM) { $xml->loadXML($this->CMSSettingsXML()); } else { $filename = get_module_config_filename($module_name); $xml->load($filename); } // traverse and find the node to change $config_xml_path = $this->config_xml_path; $found = false; // means that node found $this->iterateXMLFromNode($xml->documentElement, function ($element) use(&$found, $_INPUT, $config_xml_path) { $node_path = $element->getNodePath(); if (md5($node_path) == $_INPUT['hash'] && substr($node_path, 0, strlen($config_xml_path)) == $config_xml_path) { $found = $element->nodeName; $element->nodeValue = htmlspecialchars($_INPUT['value']); } }); // if all OK, update file and return good if ($found) { if ($module_name == self::CMS_SETTINGS_MODULE_PHANTOM) { if (!$this->updateConstInFile('./userfiles/_data_common/conf.php', $found, $_INPUT['value'])) { terminate('Error updating file', '', 500); } } else { if (!$xml->save($filename)) { terminate('Error updating file', '', 500); } } return 'OK'; } else { terminate('Config file changed', '', 403); } break; default: terminate('Unknown action [from: admin]', '', 404); break; } }
/** * Admin! * */ function adminGenerator() { if (($table = get_array_value($this->CONFIG, 'table', false, '~^[a-zA-Z_][a-zA-Z_0-9]*$~')) == false) { popup_message_add('[ NEWS ] table not defined or configuration error', JCMS_MESSAGE_ERROR); return false; } // get all news $query = CMS::$DB->query("select stamp, id, caption, link, page, streams, summary from `{$table}`"); if ($query == false) { popup_message_add('Query error: ' . get_array_value(CMS::$DB->errorInfo(), 2), JCMS_MESSAGE_ERROR); return false; } // format all items at a time into XML and then transform to HTML $xml = array_to_xml($query->fetchAll(PDO::FETCH_ASSOC), array('all-news-list', 'news')); return XSLTransform($xml->saveXML($xml->documentElement), __DIR__ . '/list.xsl'); }
break; } return $response; } /** * */ function adminGenerator() { $userfiles_dirs = $this->getDirectoriesDescription(); // default directory if not set - either "Main files" or just the first. $r = array_keys($userfiles_dirs); $category = in_array('special', $r) ? 'special' : $r[0]; if (isset($_GET['category']) && $_GET['category'] > '') { $category = $_GET['category']; } // init $xml = new DOMDocument('1.0', 'utf-8'); $xml->preserveWhiteSpace = true; $xml->formatOutput = true; $root = $xml->createElement('root'); $xml->appendChild($root); // category - single for all files $root->appendChild($xml->createElement('category'))->nodeValue = $category; $root->appendChild($xml->createElement('full-path'))->nodeValue = $userfiles_dirs[$category]['dir']; // directory list $root->appendChild($directories_node = $xml->createElement('directories')); foreach ($userfiles_dirs as $alias => $dir) { $directories_node->appendChild($dir_node = $xml->createElement('directory')); if ($alias == $category) { $dir_node->setAttribute('selected', 'selected'); } $dir_node->appendChild($xml->createElement('caption'))->nodeValue = $dir['caption']; $dir_node->appendChild($xml->createElement('alias'))->nodeValue = $alias; } // if folder selected and exists, output its files if (isset($userfiles_dirs[$category])) { $dir = $userfiles_dirs[$category]; if (file_exists($dir['dir']) && is_dir($dir['dir'])) { $root->appendChild($filelist_node = $xml->createElement('files')); $d = scandir($dir['dir']); foreach ($d as $filename) { $filename = iconv(filesystem_encoding(), 'utf-8', $filename); if (preg_match('~^' . $dir['regexp_filename'] . '$~ui', $filename) > 0) { // only matched files $filelist_node->appendChild($file_node = $xml->createElement('file')); $file_node->appendChild($xml->createElement('filename'))->nodeValue = $filename; $file_node->appendChild($xml->createElement('path'))->nodeValue = $dir['dir'] . $filename;
/** * */ public function requestParser($template) { if (!user_allowed_to('search')) { return $template; } if (!isset($_GET['module']) || $_GET['module'] != 'search' || !isset($_GET['search'])) { return $template; } // generated HTML will be here // some init $this->chars_to_include = get_array_value($this->CONFIG, 'chars_to_include', 60); $wrap_tag = get_array_value($this->CONFIG, 'wrap_tag', 'b'); $xml = new DOMDocument('1.0', 'utf-8'); $xml->preserveWhiteSpace = false; $xml->formatOutput = true; $root_node = $xml->createElement('search-results'); $xml->appendChild($root_node); // parse search string $search_pattern = preg_replace('~[.,:;\\(\\)\\-\\\\/\'\\"]+~', ' ', $_GET['search']); if (preg_match_all('~[^\\s]{2,}~smui', $search_pattern, $matches) == 0) { $template = preg_replace(macro_regexp('content'), 'Некорректный запрос', $template); return $template; } $search = $matches[0]; // enumarate all user pages if content module exists if (module_get_config('content', $content_module_config) === true) { $files = scandir('userfiles/pages/'); foreach ($files as $file) { // skip some files (".", "..", .htaccess) if (substr($file, 0, 1) == '.') { continue; } // skip generator pages if (pathinfo($file, PATHINFO_EXTENSION) == 'php') { continue; } // ok, let's test this $content = file_get_contents('userfiles/pages/' . $file); if ($highlighted = $this->highlightPatternsItTheString($search, $content, $wrap_tag)) { // get title and link, skip if filename is not in the base (possibly means corrupted database) $query = CMS::$DB->query("select alias, title from `{$content_module_config['config']['table']}` where filename = '{$file}'"); if ($row = $query->fetch(PDO::FETCH_ASSOC)) { $root_node->appendChild($more_node = $xml->createElement('result')); $more_node->appendChild($xml->createElement('alias'))->nodeValue = $row['alias']; $more_node->appendChild($xml->createElement('title'))->nodeValue = $row['title']; $more_node->appendChild($xml->createElement('highlight'))->appendChild($xml->createCDATASection($highlighted)); } } } } // also look up at news if (module_get_config('news', $news_module_config) === true) { $query = CMS::$DB->query("select * from `{$news_module_config['config']['table']}` order by stamp desc"); while ($data = $query->fetch(PDO::FETCH_ASSOC)) { // ok, let's test this $content = $data['summary']; if ($highlighted = $this->highlightPatternsItTheString($search, $content, $wrap_tag)) { // get title and link, skip if filename is not in the base (possibly means corrupted database) $root_node->appendChild($more_node = $xml->createElement('result')); $more_node->appendChild($xml->createElement('alias'))->nodeValue = $data['page']; $more_node->appendChild($xml->createElement('title'))->nodeValue = $data['caption']; $more_node->appendChild($xml->createElement('highlight'))->appendChild($xml->createCDATASection($highlighted)); } } } $root_node->appendChild($xml->createElement('pattern'))->nodeValue = implode($search, ' '); // final HTML $result = XSLTransform($xml->saveXML($root_node), __DIR__ . '/output.xsl'); // replace content with search results $template = preg_replace(macro_regexp('content'), $result, $template); // replace page title $template = preg_replace(macro_regexp('page_title'), 'Поиск: ' . implode($search, ' '), $template); return $template; }
<?php header('Content-Type: text/html; charset=utf-8'); require '_init.php'; require 'lib/xslt.cls.php'; require 'lib/errors.cls.php'; // first, get album ID to show, try firt from GET, then from session, then root if (($id = get_album_id(@$_GET['id'])) > '') { $_SESSION['gallery_' . DB_PREFIX]['folder_id'] = $id; } else { $id = isset($_SESSION['gallery_' . DB_PREFIX]['folder_id']) ? $_SESSION['gallery_' . DB_PREFIX]['folder_id'] : $root_guid; $_SESSION['gallery_' . DB_PREFIX]['folder_id'] = $id; } $_ = ''; ///// error reporting and other messaging ///////////////////////////////////////////////////////// if (isset($_SESSION['gallery_' . DB_PREFIX]['message']) && $_SESSION['gallery_' . DB_PREFIX]['message'] > '') { $_ .= '<message>' . $_SESSION['gallery_' . DB_PREFIX]['message'] . '</message>'; unset($_SESSION['gallery_' . DB_PREFIX]['message']); } ///// folder list (for moving ability) //////////////////////////////////////////////////////////// $_ .= '<folderlist>'; $query = $DB->query('select id, caption from ' . $tab_files . ' where type = 1 order by caption'); while ($data = $query->fetch(PDO::FETCH_ASSOC)) { $_ .= '<folder id="' . $data['id'] . '">' . $data['caption'] . '</folder>'; } $_ .= '</folderlist>'; ///// ok, generate //////////////////////////////////////////////////////////////////////////////// $_ .= create_list_xml(); $_ .= create_path_xml(); echo XSLTransform('<root>' . $_ . '</root>', 'main.xsl');
function adminGenerator() { if (!user_allowed_to('manage pages')) { terminate('Forbidden', '', 403); } $q = CMS::$DB->query('select * from `' . $this->CONFIG['table'] . '`'); $data = $q->fetchAll(PDO::FETCH_ASSOC); foreach ($data as $index => $row) { $data[$index]['file_status'] = file_exists(CMS::$R['USERFILES_DIRS']['pages']['dir'] . $row['filename']) ? 'OK' : 'файл отсутствует'; $data[$index]['default-page'] = $data[$index]['alias'] == DEFAULT_PAGE_ALIAS ? 'yes' : 'no'; } $xml = array_to_xml($data, array('pages-list', 'page-data')); //echo $xml->saveXML($xml->documentElement); exit; return XSLTransform($xml->saveXML($xml->documentElement), __DIR__ . '/list.xsl'); }
/** * Generates complete HTML for catalog page * * @param mixed $id node ID or alias to show catalog * @param array $params parameters to use. Usually directly from macros * @return string HTML markup */ private function generateCatalogPageHTML($alias, $params) { // create catalog XML $xml = $this->generateCatalogPageXML($alias); if (is_string($xml)) { return '[ MENU ] error creating catalog: ' . $xml; } // determine mode if ($xml->documentElement->getAttribute('catalog-mode') == 'short') { $catalog_dir = 'catalog_short'; } else { $catalog_dir = 'catalog_full'; } // check XSL. Try userland file location first, then default // just filename, without path $xsl = get_array_value($params, 'catalog-template', 'default'); // now test with path $xsl_filename = __DIR__ . '/../../userfiles/_data_modules/menu/templates/' . $catalog_dir . '/' . $xsl . '.xsl'; if (!file_exists($xsl_filename)) { $xsl_filename = __DIR__ . '/templates/' . $catalog_dir . '/' . $xsl . '.xsl'; } return XSLTransform($xml->saveXML($xml->documentElement), $xsl_filename); }
/** * * */ function adminGenerator() { // init $xml = new DOMDocument('1.0', 'utf-8'); $xml->preserveWhiteSpace = true; $xml->formatOutput = true; $root = $xml->createElement('root'); $xml->appendChild($root); $dir = __DIR__ . '/templates/'; if (file_exists($dir) && is_dir($dir)) { $root->appendChild($filelist_node = $xml->createElement('files')); $d = scandir($dir); foreach ($d as $filename) { if (substr($filename, 0, 1) == '.') { continue; } $content = file_get_contents(__DIR__ . '/templates/' . $filename); $title = preg_match('~<title>([^<]*)</title>~ui', $content, $match) ? $match[1] : '*** no title ***'; $filename = iconv(filesystem_encoding(), 'utf-8', $filename); $filelist_node->appendChild($file_node = $xml->createElement('file')); $file_node->appendChild($xml->createElement('filename'))->nodeValue = $filename; $file_node->appendChild($xml->createElement('title'))->nodeValue = $title; } } return XSLTransform($xml->saveXML($root), __DIR__ . '/list.xsl'); }
/** * Creates dialog HTML for editing (either creating or updating) the record * */ public static function recordEdit($input, &$return_metadata, $DB) { if (!isset(CMS::$R['db_api_reports'][$input['report_id']])) { $return_metadata = array('status' => 'ERROR'); return 'bad report index'; } $report_id = $input['report_id']; $report_definition = CMS::$R['db_api_reports'][$report_id]; // determine XSL filename if (!isset($report_definition['editor'])) { $xsl_filename = 'xsl/editorial.xsl'; } else { $xsl_filename = $report_definition['editor']; } // now call XML generator $params = $input; $params['method'] = 'generate_editorial_xml'; // yeah we get data XML, now transform it $xml = J_DB::callAPI($params, $return_metadata, $DB); // transform if exists, fail elsewhere $return_metadata['type'] = 'html'; if (file_exists(__DIR__ . '/' . $xsl_filename)) { $result = XSLTransform($xml, __DIR__ . '/' . $xsl_filename); } else { $return_metadata['sratus'] = 'ERROR'; $result = '<b>[JuliaCMS][db module] error</b> : XSL stylesheet "' . $xsl_filename . '" not found'; } return $result; }