Exemplo n.º 1
0
function xml_writer($txt_filename, $xml_filename)
{
    global $elem, $prop, $nam, $val, $option, $isInline, $bodyStyles, $path_root;
    $xml_str = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n\t\t\t\t\t<Styles>";
    $nam = array();
    $elem = array();
    $dir = dirname($xml_filename);
    $perms = decoct(fileperms($path_root . 'index.php') & 0777);
    if (!stristr(PHP_OS, 'WIN') && $perms != decoct(fileperms($dir) & 0777)) {
        $oldumask = umask(0);
        if ($perms == 755) {
            @chmod($dir, 0755);
            @chmod($xml_filename, 0644);
        } else {
            @chmod($dir, 0777);
            @chmod($xml_filename, 0666);
        }
        umask($oldumask);
    }
    $reader =& JFCKeditorHelper::getOptionXMLReader();
    $isInline = intval($reader->checkOption($option));
    if ($isInline) {
        $f = file_get_contents($txt_filename);
        $val = array();
        extract_inline_css_elements($f, dirname($txt_filename));
        if (count($val)) {
            foreach ($val as $key => $value) {
                if ($elem[$key] == "body") {
                    $bodyStyles = $value . ';' . $bodyStyles;
                } elseif ($val !== "offline") {
                    $xml_str .= '<Style name="' . $nam[$key] . '" element="' . $elem[$key] . '">
										<Attribute name="style" value="' . $value . '" />
									</Style>';
                    $xml_str .= "\n";
                }
                //end if
            }
            //end for loop
        }
        //end count
    } else {
        $f = file_get_contents($txt_filename);
        $prop = array();
        extract_css_elements($f, dirname($txt_filename));
        if (count($nam)) {
            foreach ($nam as $k => $val) {
                if ($val !== "offline") {
                    $xml_str .= '<Style name="' . $val . '" element="' . $elem[$k] . '">
										<Attribute name="' . $prop[$k] . '" value="' . $val . '" />
									</Style>';
                    $xml_str .= "\n";
                }
                //end if
            }
            //end for loop
        }
        //end count
    }
    $xml_str .= "\n" . "</Styles>";
    file_put_contents($xml_filename, $xml_str);
}
Exemplo n.º 2
0
    function xml_writer($txt_filename = "", $xml_filename = "")
    {
        global $main, $elem, $prop, $nam, $val, $option;
        /* echo '<span style="color: green;">Writing: ' . $txt_filename . ' to: '. $xml_filename .'</span><br/>'; */
        /* When was the files last modified? */
        $xml_str = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n\t\t\t\t\t<Styles>";
        $elem = array();
        $nam = array();
        $dir = dirname($xml_filename);
        $perms = decoct(fileperms($this->_path_root . 'index.php') & 0777);
        switch ($perms) {
            case 666:
                $perms = 777;
                break;
            case 644:
                $perms = 755;
        }
        if (!stristr(PHP_OS, 'WIN') && $perms != decoct(fileperms($dir) & 0777)) {
            $oldumask = umask(0);
            if ($perms == 755) {
                @chmod($dir, 0755);
                @chmod($xml_filename, 0644);
            } else {
                @chmod($dir, 0777);
                @chmod($xml_filename, 0666);
            }
            umask($oldumask);
        }
        $reader =& JFCKeditorHelper::getOptionXMLReader();
        $this->_isInline = intval($reader->checkOption($option));
        if ($this->_isInline) {
            $f = file_get_contents($txt_filename);
            $val = array();
            $this->extract_inline_css_elements($f, dirname($txt_filename));
            if (count($val)) {
                foreach ($val as $key => $value) {
                    if ($elem[$key] == "body") {
                        $this->_bodyStyles = $value . ';' . $this->_bodyStyles;
                    } elseif ($val !== "offline") {
                        $xml_str .= '<Style name="' . $nam[$key] . '" element="' . $elem[$key] . '">
										<Attribute name="style" value="' . $value . '" />
									</Style>';
                        $xml_str .= "\n";
                    }
                    //end if
                }
                //end for loop
            }
            //end count
        } else {
            $f = file_get_contents($txt_filename);
            $prop = array();
            $this->extract_css_elements($f, dirname($txt_filename));
            if (count($nam)) {
                foreach ($nam as $k => $val) {
                    if ($val !== "offline") {
                        $xml_str .= '<Style name="' . $val . '" element="' . $elem[$k] . '">
										<Attribute name="' . $prop[$k] . '" value="' . $val . '" />
									</Style>';
                        $xml_str .= "\n";
                    }
                    //end if
                }
                //end for loop
            }
            //end count
        }
        $xml_str .= "\n" . "</Styles>";
        //write file
        //Translate file path as we reuire full path
        $xml_filename = JPATH_ROOT . DS . str_replace('../', '/', $xml_filename);
        JFile::write($xml_filename, $xml_str);
    }