Exemplo n.º 1
0
 public function loadFeed()
 {
     if (!isset(RSSFilter::$feeds[$this->A("RSSFilterFeed")])) {
         RSSFilter::$feeds[$this->A("RSSFilterFeed")] = "<phynx></phynx>";
         $content = @file_get_contents($this->A("RSSFilterFeed"));
         if ($content === false) {
             throw new Exception($this->A("RSSFilterFeed") . " could not be loaded!");
         }
         $content = str_replace("", "", $content);
         try {
             libxml_use_internal_errors(true);
             RSSFilter::$feeds[$this->A("RSSFilterFeed")] = new SimpleXMLElement($content);
         } catch (Exception $e) {
             try {
                 $config = array('indent' => true, 'clean' => true, 'input-xml' => true, 'output-xml' => true, 'wrap' => false);
                 $tidy = new Tidy();
                 $xml = $tidy->repairString($content, $config);
                 RSSFilter::$feeds[$this->A("RSSFilterFeed")] = new SimpleXMLElement($xml);
             } catch (ClassNotFoundException $e) {
                 throw new Exception($this->A("RSSFilterFeed") . " contains errors, but Tidy not found!");
             } catch (Exception $e) {
                 #$errors = "";
                 #foreach(libxml_get_errors() as $error)
                 #	print_r($error->message);
                 throw new Exception($this->A("RSSFilterFeed") . " contained errors even Tidy could not fix!");
             }
             #$errors = "";
             #foreach(libxml_get_errors() as $error)
             #	print_r($error->message);
             #throw new Exception($this->A("RSSFilterFeed"));
         }
     }
 }
Exemplo n.º 2
0
 public static function beautifyHtml($html, $config = array("output-xhtml" => true, "char-encoding" => "utf8", "indent" => true, "indent-spaces" => 4, "wrap" => 0))
 {
     if (!Ajde_Core_Autoloader::exists('Tidy')) {
         throw new Ajde_Exception('Class Tidy not found', 90023);
     }
     $tidy = new Tidy();
     // http://bugs.php.net/bug.php?id=35647
     return $tidy->repairString($html, $config, 'utf8');
 }
Exemplo n.º 3
0
 public static function beautifyHtml($html, $config = ['output-xhtml' => true, 'char-encoding' => 'utf8', 'indent' => true, 'indent-spaces' => 4, 'wrap' => 0])
 {
     if (!class_exists('Tidy')) {
         throw new Ajde_Exception('Class Tidy not found', 90023);
     }
     $tidy = new Tidy();
     // tidy does not produce valid utf8 when the encoding is specified in the config
     // so we provide a third parameter, 'utf8' to fix this
     // @see http://bugs.php.net/bug.php?id=35647
     return $tidy->repairString($html, $config, 'utf8');
 }
Exemplo n.º 4
0
 public static function beautifyHtml($html, $config = array("output-xhtml" => true, "char-encoding" => "utf8", "indent" => true, "indent-spaces" => 4, "wrap" => 0))
 {
     if (!Ajde_Core_Autoloader::exists('Tidy')) {
         throw new Ajde_Exception('Class Tidy not found', 90023);
     }
     $tidy = new Tidy();
     // tidy does not produce valid utf8 when the encoding is specified in the config
     // so we provide a third parameter, 'utf8' to fix this
     // @see http://bugs.php.net/bug.php?id=35647
     return $tidy->repairString($html, $config, 'utf8');
 }
Exemplo n.º 5
0
 /**
  * 功能:清理未闭合的标签  商品存储的时候使用  要修改联系侯保法
  * 备注:需要php开启这个扩展php_tidy.dll
  * @param unknown_type $data    要处理的数据,可以是数据或字符串
  * @param unknown_type $encode    文字编码,默认是utf8
  * @return unknown    处理好的数据
  */
 public static function htmlFixSafe($data, $encode = 'utf8')
 {
     if (empty($data)) {
         return '';
     }
     $tidyConfig = array('indent' => false, 'output-xhtml' => true, 'show-body-only' => true, 'wrap' => 200, 'vertical-space' => 2);
     $tidyObj = new \Tidy();
     if (is_array($data)) {
         foreach ($data as $key => $value) {
             $data[$key] = self::htmlFixSafe($value);
         }
     } else {
         $data = $tidyObj->repairString($data, $tidyConfig, $encode);
     }
     return $data;
 }
Exemplo n.º 6
0
 function closetags($html)
 {
     if (class_exists('Tidy')) {
         $tidy = new Tidy();
         $clean = $tidy->repairString($html, array('output-xml' => true, 'input-xml' => true));
         return $clean;
     }
     preg_match_all('#<(?!meta|img|br|hr|input\\b)\\b([a-z]+)(?: .*)?(?<![/|/ ])>#iU', $html, $result);
     $openedtags = $result[1];
     preg_match_all('#</([a-z]+)>#iU', $html, $result);
     $closedtags = $result[1];
     $len_opened = count($openedtags);
     if (count($closedtags) == $len_opened) {
         return $html;
     }
     $openedtags = array_reverse($openedtags);
     for ($i = 0; $i < $len_opened; $i++) {
         if (!in_array($openedtags[$i], $closedtags)) {
             $html .= '</' . $openedtags[$i] . '>';
         } else {
             unset($closedtags[array_search($openedtags[$i], $closedtags)]);
         }
     }
     return $html;
 }
Exemplo n.º 7
0
 function onFunction($matches, $s)
 {
     $fns = explode('||', $matches[2]);
     for ($i = count($fns) - 1; $i >= 0; $i--) {
         $fn = explode(',', $fns[$i]);
         switch ($fn[0]) {
             case 'cleanhtml':
                 $s = strip_tags($s, '<p><a><b><br><br/><i>');
                 break;
             case 'removehtml':
                 $s = strip_tags($s);
                 break;
             case 'splitbychars':
                 $s = substr($s, $fn[1], $fn[2]);
                 break;
             case 'splitbywords':
                 $len = strlen($s);
                 $pos = $fn[2] > $len ? $len : strpos($s, ' ', $fn[2]);
                 if ($pos === false) {
                     $pos = $len;
                 }
                 $s = substr($s, 0, $pos);
                 break;
             case 'findimage':
                 $index = isset($fn[1]) ? intval($fn[1]) - 1 : 0;
                 preg_match_all('/(<img.*?src=[\'"](.*?)[\'"][^>]+>)|(background(-image)??\\s*?:.*?url\\((["|\']?)?(.+?)(["|\']?)?\\))/i', $s, $r);
                 if (isset($r[2]) && !empty($r[2][$index])) {
                     $s = $r[2][$index];
                 } else {
                     if (isset($r[6]) && !empty($r[6][$index])) {
                         $s = trim($r[6][$index], "'\" \t\n\r\v");
                     } else {
                         $s = '';
                     }
                 }
                 break;
         }
     }
     if ($i !== -1) {
         if ($this->_tidy) {
             $tidy = new Tidy();
             return $tidy->repairString($s, array('show-body-only' => true, 'input-encoding' => $this->_tidyInputEncoding, 'output-encoding' => $this->_tidyOutputEncoding));
         }
     }
     return $this->closetags($s);
 }
Exemplo n.º 8
0
 private function setupEnvironment()
 {
     global $gDatabase, $cDatabaseConnectionString, $cMyDotCnfFile, $cDatabaseModule, $cIncludePath, $cLoggerName, $gLogger;
     set_exception_handler(array("Hotel", "exceptionHandler"));
     // check all the required PHP extensions are enabled on this SAPI
     $this->checkPhpExtensions();
     // start output buffering before anything is sent to the browser.
     ob_start();
     // not caught by the autoloader :(
     require_once 'smarty/Smarty.class.php';
     // many exceptions defined in one file, let's not clutter stuff.
     // This ofc breaks the autoloading, so let's include them all now.
     // (Depends on some smarty stuff)
     require_once $cIncludePath . "/_Exceptions.php";
     spl_autoload_register("Hotel::autoLoader");
     Session::start();
     $gLogger = new $cLoggerName();
     $gLogger->log("Initialising logger!");
     if (!extension_loaded($cDatabaseModule)) {
         throw new ExtensionUnavailableException($cDatabaseModule);
     }
     $mycnf = parse_ini_file($cMyDotCnfFile);
     $gDatabase = new Database($cDatabaseConnectionString, $mycnf["user"], $mycnf["password"]);
     // tidy up sensitive data we don't want lying around.
     unset($mycnf);
     // use exceptions on failed database stuff
     $gDatabase->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     // can we tidy up the output with tidy before we send it?
     if (extension_loaded("tidy")) {
         // Yes!
         global $cUseTidy;
         if ($cUseTidy) {
             // register a new function to hook into the output bit
             Hooks::register("BeforeOutputSend", function ($params) {
                 $tidy = new Tidy();
                 global $cTidyOptions;
                 return $tidy->repairString($params[0], $cTidyOptions, "utf8");
             });
         }
     }
     global $gCookieJar;
     $gCookieJar = array();
 }
Exemplo n.º 9
0
<?php

session_start();
include "dbInfo.php";
$conn = mysqli_connect("localhost", DBUSERNAME, DBPASSWORD, DB);
$title = htmlentities($_POST['title'], ENT_QUOTES);
$tidy = new Tidy();
$html = $_POST["content"];
$content = $tidy->repairString($html, array("output-xml" => true, "input-xml" => true));
$username = $_SESSION["username"];
$date = getdate();
$datef = $date['year'] . "-" . $date['mon'] . "-" . $date['mday'];
$command = "INSERT INTO `" . DB . "`.`Posts` (`ID`, `Title`, `Content`, `Author`, `Date`) VALUES (NULL, '{$title}', '{$content}', '{$username}', '{$datef}')";
if (mysqli_query($conn, $command)) {
    header("location:../index.php");
}
Exemplo n.º 10
0
Arquivo: Xml.php Projeto: xety/marsbot
 /**
  * Repair a XML string to a valid XML.
  *
  * Input :
  * - <m   t="my message" u="123456789"i="626"   />
  *
  * Output:
  * - <m t="my message" u="123456789" i="626" />
  *
  * @param string $input The XML to repair.
  * @param array $options The options to use with the Tidy class.
  *
  * @return string
  *
  * @throws \Mars\Utility\Exception\XmlException
  */
 public static function repair($input, array $options = [])
 {
     $defaults = ['indent' => true, 'input-xml' => true, 'output-xml' => true, 'wrap' => false];
     $options += $defaults;
     if (!extension_loaded('tidy')) {
         throw new XmlException('The extension Tidy is not loaded.');
     }
     $tidy = new \Tidy();
     return $tidy->repairString($input, $options);
 }