Пример #1
0
/**
 * parsed module configuration file and returns result
 *
 * @param string $module_name module name to get config from
 * @param mixed &$config config array will be stored here on success, false on failure
 * @return true on success, error message on failure
 */
function module_get_config($module_name, &$config)
{
    $config_filename = get_module_config_filename($module_name);
    if (file_exists($config_filename)) {
        $config = get_array_value(StrangeXMLParser::fromFile($config_filename), 'JuliaCMS_module_definition');
        if (!$config) {
            return 'Parsing "' . $config_filename . '" failed';
        }
    } else {
        $config = false;
        return 'module definition file not found for module "' . $module_name . '"';
    }
    return true;
}
Пример #2
0
 /**
  * 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;
     }
 }