Ejemplo n.º 1
0
 public static function DOMElementToString($domelement, $contentOnly = false)
 {
     if (!is_a($domelement, "DOMElement")) {
         CMS_grandFather::raiseError('Domelement is not a DOMElement instance');
         return false;
     }
     static $autoClosedTagsList;
     if (!$autoClosedTagsList) {
         $xml2Array = new CMS_xml2Array();
         $tagsList = $xml2Array->getAutoClosedTagsList();
         $autoClosedTagsList = implode($tagsList, '|');
     }
     $output = '';
     if ($contentOnly) {
         $output = '';
         foreach ($domelement->childNodes as $node) {
             $output .= $node->ownerDocument->saveXML($node, LIBXML_NOEMPTYTAG);
         }
     } else {
         $output = $domNode->ownerDocument->saveXML($domNode, LIBXML_NOEMPTYTAG);
     }
     //convert output encoding if needed
     if (io::isUTF8($output)) {
         if (io::strtolower(APPLICATION_DEFAULT_ENCODING) != 'utf-8') {
             $output = utf8_decode($output);
         }
     } else {
         if (io::strtolower(APPLICATION_DEFAULT_ENCODING) == 'utf-8') {
             $output = utf8_encode($output);
         }
     }
     //to correct a bug in libXML < 2.6.27
     if (LIBXML_VERSION < 20627 && strpos($output, '&#x') !== false) {
         $output = preg_replace_callback('/(&#x[0-9A-Z]+;)/U', create_function('$matches', 'return io::decodeEntities($matches[0]);'), $output);
     }
     //replace tags like <br></br> by auto closed tags and strip cariage return arround entities
     $output = preg_replace(array('#\\n(&[a-z]+;)\\n#U', '#<(' . $autoClosedTagsList . ')([^>]*)></\\1>#U'), array('\\1', '<\\1\\2/>'), $output);
     return $output;
 }
Ejemplo n.º 2
0
        CMS_grandFather::raiseError('Action on this type of file is not allowed.');
        $view->show();
    }
    $fileId = md5($file);
    $file = new CMS_file($file);
    $fileDefinition = $file->readContent();
    $labelField = '';
    $anchor = '-60';
    $action = 'update';
}
if (strtolower(APPLICATION_DEFAULT_ENCODING) == 'utf-8') {
    if (!io::isUTF8($fileDefinition)) {
        $fileDefinition = utf8_encode($fileDefinition);
    }
} else {
    if (io::isUTF8($fileDefinition)) {
        $fileDefinition = utf8_decode($fileDefinition);
    }
}
//DEFINITION TAB
$content = '<textarea id="file-content-' . $fileId . '" style="display:none;">' . htmlspecialchars($fileDefinition) . '</textarea>';
$view->setContent($content);
switch ($extension) {
    case 'less':
    case 'css':
        $codemirrorConf = '
			mode: "text/css",
		';
        $title = sensitiveIO::sanitizeJSString($fileCreation ? $cms_language->getMessage(MESSAGE_PAGE_CREATE_CSS) : $cms_language->getMessage(MESSAGE_PAGE_EDIT_CSS) . ' ' . $node);
        break;
    case 'js':
Ejemplo n.º 3
0
 /**
  * Execute a SQL script
  *
  * @param $script, string : the CMS_file::FILE_SYSTEM SQL script filename
  *  This script can be SQL export provided by phpMyadmin or mysqldump, etc.
  * @param simulation : boolean, if true, only do a read of the script and if it contain sql data, return true.
  * @return boolean, true on success, false on failure
  * @access public
  */
 function executeSqlScript($script, $simulation = false)
 {
     //include PMA import functions
     require_once PATH_PACKAGES_FS . '/files/sqlDump.php';
     //read mysql version and set needed constant/vars for phpMyAdmin
     $q = new CMS_query('SELECT VERSION() AS version');
     $version = $q->getValue('version');
     $match = explode('.', $version);
     //read mysql file
     $query = PMA_readFile($script);
     //first, detect SQL file encoding
     $isUTF8 = io::isUTF8($query);
     //then, change charset declaration inside sql queries to match current Automne charset
     if (strtolower(APPLICATION_DEFAULT_ENCODING) != 'utf-8') {
         //if Automne is not in utf8, then table charset must be in latin1
         $query = str_ireplace(' CHARSET=utf8', ' CHARSET=latin1', $query);
         $query = str_ireplace('TYPE=MyISAM;', 'TYPE=MyISAM CHARSET=latin1;', $query);
     } else {
         //if Automne is in utf8, then table charset must be in utf8
         $query = str_ireplace(' CHARSET=latin1', ' CHARSET=utf8', $query);
         $query = str_ireplace('TYPE=MyISAM;', 'TYPE=MyISAM CHARSET=utf8;', $query);
     }
     //finally, clean it and split queries
     PMA_splitSqlFile($queries, $query, (int) sprintf('%d%02d%02d', $match[0], $match[1], intval($match[2])));
     if (!$simulation) {
         //set connection charset accordingly to file charset
         if ($isUTF8) {
             $q = new CMS_query("SET NAMES 'utf8'");
         } else {
             $q = new CMS_query("SET NAMES 'latin1'");
         }
         //execute all queries
         $ok = true;
         foreach ($queries as $aQuery) {
             $q = new CMS_query($aQuery);
             $ok = $q->hasError() ? false : $ok;
         }
         //set connection charset accordingly to file charset
         if ($isUTF8) {
             $q = new CMS_query("SET NAMES 'latin1'");
         } else {
             $q = new CMS_query("SET NAMES 'utf8'");
         }
     } else {
         $ok = is_array($queries) && $queries ? true : false;
     }
     //reset connection charset
     if (io::strtolower(APPLICATION_DEFAULT_ENCODING) == 'utf-8') {
         //set connection to utf-8 charset
         $q = new CMS_query("SET NAMES 'utf8'");
     } else {
         $q = new CMS_query("SET NAMES 'latin1'");
     }
     return $ok;
 }