this is a bootstrap for the polyfills (iconv / intl / mbstring / normalizer / xml)
Example #1
0
File: UTF8.php Project: hhgr/hhgolf
 /**
  * Format a number with grouped thousands
  *
  * @param float  $number
  * @param int    $decimals
  * @param string $dec_point
  * @param string $thousands_sep
  *
  * @return string
  */
 public static function number_format($number, $decimals = 0, $dec_point = '.', $thousands_sep = ',')
 {
     if (Bootup::is_php('5.4') === true) {
         if (isset($thousands_sep[1]) || isset($dec_point[1])) {
             return str_replace(array('.', ','), array($dec_point, $thousands_sep), number_format($number, $decimals, '.', ','));
         }
     }
     return number_format($number, $decimals, $dec_point, $thousands_sep);
 }
Example #2
0
<?php

use voku\helper\Bootup;
if (defined('PORTABLE_UTF8__DISABLE_AUTO_FILTER') === false) {
    Bootup::initAll();
    // Enables the portability layer and configures PHP for UTF-8
    Bootup::filterRequestUri();
    // Redirects to an UTF-8 encoded URL if it's not already the case
    Bootup::filterRequestInputs();
    // Normalizes HTTP inputs to UTF-8 NFC
}
Example #3
0
 /**
  * This is a wrapper for "bind_param" what binds variables to a prepared statement as parameters. If you use this
  * wrapper, you can debug your query with e.g. "$this->get_sql_with_bound_parameters()".
  *
  * @param string $types <strong>i<strong> corresponding variable has type integer<br />
  *                      <strong>d</strong> corresponding variable has type double<br />
  *                      <strong>s</strong> corresponding variable has type string<br />
  *                      <strong>b</strong> corresponding variable is a blob and will be sent in packets
  *
  * INFO: We have to explicitly declare all parameters as references, otherwise it does not seem possible to pass them
  * on without losing the reference property.
  *
  * @param mixed  $v1
  * @param mixed  $v2
  * @param mixed  $v3
  * @param mixed  $v4
  * @param mixed  $v5
  * @param mixed  $v6
  * @param mixed  $v7
  * @param mixed  $v8
  * @param mixed  $v9
  * @param mixed  $v10
  * @param mixed  $v11
  * @param mixed  $v12
  * @param mixed  $v13
  * @param mixed  $v14
  * @param mixed  $v15
  * @param mixed  $v16
  * @param mixed  $v17
  * @param mixed  $v18
  * @param mixed  $v19
  * @param mixed  $v20
  * @param mixed  $v21
  * @param mixed  $v22
  * @param mixed  $v23
  * @param mixed  $v24
  * @param mixed  $v25
  * @param mixed  $v26
  * @param mixed  $v27
  * @param mixed  $v28
  * @param mixed  $v29
  * @param mixed  $v30
  * @param mixed  $v31
  * @param mixed  $v32
  * @param mixed  $v33
  * @param mixed  $v34
  * @param mixed  $v35
  *
  * @return mixed
  */
 public function bind_param_debug($types, &$v1 = null, &$v2 = null, &$v3 = null, &$v4 = null, &$v5 = null, &$v6 = null, &$v7 = null, &$v8 = null, &$v9 = null, &$v10 = null, &$v11 = null, &$v12 = null, &$v13 = null, &$v14 = null, &$v15 = null, &$v16 = null, &$v17 = null, &$v18 = null, &$v19 = null, &$v20 = null, &$v21 = null, &$v22 = null, &$v23 = null, &$v24 = null, &$v25 = null, &$v26 = null, &$v27 = null, &$v28 = null, &$v29 = null, &$v30 = null, &$v31 = null, &$v32 = null, &$v33 = null, &$v34 = null, &$v35 = null)
 {
     $this->_use_bound_parameters_interpolated = true;
     // debug_backtrace returns arguments by reference, see comments at http://php.net/manual/de/function.func-get-args.php
     if (Bootup::is_php('5.4')) {
         $trace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 1);
     } else {
         $trace = debug_backtrace();
     }
     $args =& $trace[0]['args'];
     $types = str_split($types);
     $args_count = count($args) - 1;
     $types_count = count($types);
     if ($args_count !== $types_count) {
         trigger_error('Number of variables doesn\'t match number of parameters in prepared statement', E_WARNING);
         return false;
     }
     $arg = 1;
     foreach ($types as $typeInner) {
         $val =& $args[$arg];
         $this->_boundParams[] = array('type' => $typeInner, 'value' => &$val);
         $arg++;
     }
     return true;
 }
Example #4
0
 /**
  * Try to get the file & line from the current sql-query.
  *
  * @return array will return array['file'] and array['line']
  */
 private function getFileAndLineFromSql()
 {
     // init
     $return = array();
     $file = '';
     $line = '';
     if (Bootup::is_php('5.4') === true) {
         $referrer = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 10);
     } else {
         $referrer = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
     }
     foreach ($referrer as $key => $ref) {
         if ($ref['function'] === 'execSQL' || $ref['function'] === 'query' || $ref['function'] === 'qry' || $ref['function'] === 'execute' || $ref['function'] === 'insert' || $ref['function'] === 'update' || $ref['function'] === 'replace' || $ref['function'] === 'delete') {
             $file = $referrer[$key]['file'];
             $line = $referrer[$key]['line'];
         }
     }
     $return['file'] = $file;
     $return['line'] = $line;
     return $return;
 }
Example #5
0
 /**
  * create DOMDocument from HTML
  *
  * @param string   $html
  * @param int|null $libXMLExtraOptions
  *
  * @return \DOMDocument
  */
 private function createDOMDocument($html, $libXMLExtraOptions = null)
 {
     if (strpos($html, '<') === false) {
         $this->isDOMDocumentCreatedWithoutHtml = true;
     }
     if (strpos($html, '<html') === false) {
         $this->isDOMDocumentCreatedWithoutHtmlWrapper = true;
     }
     // set error level
     $internalErrors = libxml_use_internal_errors(true);
     $disableEntityLoader = libxml_disable_entity_loader(true);
     libxml_clear_errors();
     $optionsSimpleXml = LIBXML_DTDLOAD | LIBXML_DTDATTR | LIBXML_NONET;
     $optionsXml = 0;
     if (defined('LIBXML_BIGLINES')) {
         $optionsSimpleXml |= LIBXML_BIGLINES;
     }
     if (defined('LIBXML_COMPACT')) {
         $optionsSimpleXml |= LIBXML_COMPACT;
     }
     if (defined('LIBXML_HTML_NOIMPLIED')) {
         $optionsSimpleXml |= LIBXML_HTML_NOIMPLIED;
     }
     if (defined('LIBXML_HTML_NODEFDTD')) {
         $optionsSimpleXml |= LIBXML_HTML_NODEFDTD;
     }
     if ($libXMLExtraOptions !== null) {
         $optionsSimpleXml |= $libXMLExtraOptions;
         $optionsXml |= $libXMLExtraOptions;
     }
     $sxe = simplexml_load_string($html, 'SimpleXMLElement', $optionsSimpleXml);
     if ($sxe !== false && count(libxml_get_errors()) === 0) {
         $this->document = dom_import_simplexml($sxe)->ownerDocument;
     } else {
         // UTF-8 hack: http://php.net/manual/en/domdocument.loadhtml.php#95251
         $html = trim($html);
         $xmlHackUsed = false;
         if (stripos('<?xml', $html) !== 0) {
             $xmlHackUsed = true;
             $html = '<?xml encoding="' . $this->getEncoding() . '" ?>' . $html;
         }
         $html = self::replaceToPreserveHtmlEntities($html);
         if ($optionsXml && Bootup::is_php('5.4')) {
             $this->document->loadHTML($html, $optionsXml);
         } else {
             $this->document->loadHTML($html);
         }
         // remove the "xml-encoding" hack
         if ($xmlHackUsed === true) {
             foreach ($this->document->childNodes as $child) {
                 if ($child->nodeType === XML_PI_NODE) {
                     $this->document->removeChild($child);
                 }
             }
         }
         libxml_clear_errors();
     }
     // set encoding
     $this->document->encoding = $this->getEncoding();
     // restore lib-xml settings
     libxml_use_internal_errors($internalErrors);
     libxml_disable_entity_loader($disableEntityLoader);
     return $this->document;
 }