Example #1
0
 public static function generateTempFilename(&$tab_arqs, $path)
 {
     $list = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
     $N = $list[rand(0, count($list) - 1)] . date('U') . $list[rand(0, count($list) - 1)] . RAND(12345, 9999999999.0) . $list[rand(0, count($list) - 1)] . $list[rand(0, count($list) - 1)] . RAND(12345, 9999999999.0) . '.tmp';
     $aux = $path . '/' . $N;
     array_push($tab_arqs, $aux);
     return $aux;
 }
Example #2
0
 public function addUser($firstName, $lastName, $email, $password)
 {
     $apikey = SHA1($email . $password . RAND() . time());
     $stmt = $this->pdo->prepare("INSERT INTO `users` (`firstName`, `lastName`, `email`,`password`, `apikey`) VALUES (?, ?, ?, SHA1(?), ?)");
     if ($stmt->execute(array($firstName, $lastName, $email, $password, $apikey))) {
         return $this->pdo->lastInsertId();
     } else {
         return 0;
     }
 }
Example #3
0
function token()
{
    $str = "";
    for ($i = 0; $i <= 10; $i++) {
        //$str.=chr(RAND(1,100));
    }
    $str .= RAND(0, 9999999999999.0);
    $_SESSION["x"] = $str;
    return "üretilen değer:<br/>" . $str;
}
Example #4
0
 function ImageSVG($data)
 {
     $this->svg_info = array();
     // mPDF 4.4.006
     if (preg_match('/<!ENTITY/si', $data)) {
         // Get User-defined entities
         preg_match_all('/<!ENTITY\\s+([a-z]+)\\s+\\"(.*?)\\">/si', $data, $ent);
         // Replace entities
         for ($i = 0; $i < count($ent[0]); $i++) {
             $data = preg_replace('/&' . preg_quote($ent[1][$i], '/') . ';/is', $ent[2][$i], $data);
         }
     }
     // mPDF 4.4.003
     if (preg_match('/xlink:href=/si', $data)) {
         // Get links
         preg_match_all('/(<(linearGradient|radialgradient)[^>]*)xlink:href=["\']#(.*?)["\'](.*?)\\/>/si', $data, $links);
         if (count($links[0])) {
             $links[5] = array();
         }
         // mPDF 4.5.010
         // Delete links from data - keeping in $links
         for ($i = 0; $i < count($links[0]); $i++) {
             $links[5][$i] = 'tmpLink' . RAND(100000, 9999999);
             // mPDF 4.5.010
             $data = preg_replace('/' . preg_quote($links[0][$i], '/') . '/is', '<MYLINKS' . $links[5][$i] . '>', $data);
             // mPDF 4.5.010
         }
         // Get targets
         preg_match_all('/<(linearGradient|radialgradient)([^>]*)id=["\'](.*?)["\'](.*?)>(.*?)<\\/(linearGradient|radialgradient)>/si', $data, $m);
         $targets = array();
         $stops = array();
         // keeping in $targets
         for ($i = 0; $i < count($m[0]); $i++) {
             $stops[$m[3][$i]] = $m[5][$i];
         }
         // Add back links this time as targets (gradients)
         for ($i = 0; $i < count($links[0]); $i++) {
             $def = $links[1][$i] . ' ' . $links[4][$i] . '>' . $stops[$links[3][$i]] . '</' . $links[2][$i] . '>';
             // mPDF 4.5.010
             $data = preg_replace('/<MYLINKS' . $links[5][$i] . '>/is', $def, $data);
             // mPDF 4.5.010
         }
     }
     // mPDF 4.4.003	- Removes <pattern>
     $data = preg_replace('/<pattern.*?<\\/pattern>/is', '', $data);
     // mPDF 4.4.003	- Removes <marker>
     $data = preg_replace('/<marker.*?<\\/marker>/is', '', $data);
     $this->svg_info['data'] = $data;
     $this->svg_string = '';
     //
     //	chargement unique des fonctions
     if (!function_exists("xml_svg2pdf_start")) {
         // mPDF 5.3.76
         function xml_svg2pdf_start($parser, $name, $attribs)
         {
             //
             //	definition
             global $svg_class, $last_gradid;
             // mPDF 4.4.003
             $svg_class->xbase = 0;
             $svg_class->ybase = 0;
             switch (strtolower($name)) {
                 // mPDF 5.0.039	- Don't output stuff inside <defs>
                 case 'defs':
                     $svg_class->inDefs = true;
                     return;
                 case 'svg':
                     $svg_class->svgOffset($attribs);
                     break;
                 case 'path':
                     $path = $attribs['d'];
                     // mPDF 4.4.003
                     preg_match_all('/([MZLHVCSQTAmzlhvcsqta])([e ,\\-.\\d]+)*/', $path, $commands, PREG_SET_ORDER);
                     $path_cmd = '';
                     $svg_class->subPathInit = true;
                     // mPDF 4.4.003
                     // mPDF 5.0.039
                     $svg_class->pathBBox = array(999999, 999999, -999999, -999999);
                     foreach ($commands as $c) {
                         if (count($c) == 3 || $c[2] == '') {
                             list($tmp, $command, $arguments) = $c;
                         } else {
                             list($tmp, $command) = $c;
                             $arguments = '';
                         }
                         $path_cmd .= $svg_class->svgPath($command, $arguments);
                     }
                     // mPDF 5.0.039
                     if ($svg_class->pathBBox[2] == -1999998) {
                         $svg_class->pathBBox[2] = 100;
                     }
                     if ($svg_class->pathBBox[3] == -1999998) {
                         $svg_class->pathBBox[3] = 100;
                     }
                     if ($svg_class->pathBBox[0] == 999999) {
                         $svg_class->pathBBox[0] = 0;
                     }
                     if ($svg_class->pathBBox[1] == 999999) {
                         $svg_class->pathBBox[1] = 0;
                     }
                     $critere_style = $attribs;
                     unset($critere_style['d']);
                     $path_style = $svg_class->svgDefineStyle($critere_style);
                     break;
                 case 'rect':
                     if (!isset($attribs['x'])) {
                         $attribs['x'] = 0;
                     }
                     if (!isset($attribs['y'])) {
                         $attribs['y'] = 0;
                     }
                     if (!isset($attribs['rx'])) {
                         $attribs['rx'] = 0;
                     }
                     if (!isset($attribs['ry'])) {
                         $attribs['ry'] = 0;
                     }
                     $arguments = array('x' => $attribs['x'], 'y' => $attribs['y'], 'w' => $attribs['width'], 'h' => $attribs['height'], 'rx' => $attribs['rx'], 'ry' => $attribs['ry']);
                     $path_cmd = $svg_class->svgRect($arguments);
                     $critere_style = $attribs;
                     unset($critere_style['x'], $critere_style['y'], $critere_style['rx'], $critere_style['ry'], $critere_style['height'], $critere_style['width']);
                     $path_style = $svg_class->svgDefineStyle($critere_style);
                     break;
                 case 'circle':
                     if (!isset($attribs['cx'])) {
                         $attribs['cx'] = 0;
                     }
                     if (!isset($attribs['cy'])) {
                         $attribs['cy'] = 0;
                     }
                     $arguments = array('cx' => $attribs['cx'], 'cy' => $attribs['cy'], 'rx' => $attribs['r'], 'ry' => $attribs['r']);
                     $path_cmd = $svg_class->svgEllipse($arguments);
                     $critere_style = $attribs;
                     unset($critere_style['cx'], $critere_style['cy'], $critere_style['r']);
                     $path_style = $svg_class->svgDefineStyle($critere_style);
                     break;
                 case 'ellipse':
                     if (!isset($attribs['cx'])) {
                         $attribs['cx'] = 0;
                     }
                     if (!isset($attribs['cy'])) {
                         $attribs['cy'] = 0;
                     }
                     $arguments = array('cx' => $attribs['cx'], 'cy' => $attribs['cy'], 'rx' => $attribs['rx'], 'ry' => $attribs['ry']);
                     $path_cmd = $svg_class->svgEllipse($arguments);
                     $critere_style = $attribs;
                     unset($critere_style['cx'], $critere_style['cy'], $critere_style['rx'], $critere_style['ry']);
                     $path_style = $svg_class->svgDefineStyle($critere_style);
                     break;
                 case 'line':
                     $arguments = array($attribs['x1'], $attribs['y1'], $attribs['x2'], $attribs['y2']);
                     $path_cmd = $svg_class->svgPolyline($arguments, false);
                     //  mPDF 4.4.003
                     $critere_style = $attribs;
                     unset($critere_style['x1'], $critere_style['y1'], $critere_style['x2'], $critere_style['y2']);
                     $path_style = $svg_class->svgDefineStyle($critere_style);
                     break;
                 case 'polyline':
                     $path = $attribs['points'];
                     preg_match_all('/[0-9\\-\\.]*/', $path, $tmp, PREG_SET_ORDER);
                     $arguments = array();
                     for ($i = 0; $i < count($tmp); $i++) {
                         if ($tmp[$i][0] != '') {
                             array_push($arguments, $tmp[$i][0]);
                         }
                     }
                     $path_cmd = $svg_class->svgPolyline($arguments);
                     $critere_style = $attribs;
                     unset($critere_style['points']);
                     $path_style = $svg_class->svgDefineStyle($critere_style);
                     break;
                 case 'polygon':
                     $path = $attribs['points'];
                     preg_match_all('/([\\-]*[0-9\\.]+)/', $path, $tmp);
                     $arguments = array();
                     for ($i = 0; $i < count($tmp[0]); $i++) {
                         if ($tmp[0][$i] != '') {
                             array_push($arguments, $tmp[0][$i]);
                         }
                     }
                     $path_cmd = $svg_class->svgPolygon($arguments);
                     //	definition du style de la forme:
                     $critere_style = $attribs;
                     unset($critere_style['points']);
                     $path_style = $svg_class->svgDefineStyle($critere_style);
                     break;
                 case 'lineargradient':
                     $tmp_gradient = array('type' => 'linear', 'info' => array('x1' => $attribs['x1'], 'y1' => $attribs['y1'], 'x2' => $attribs['x2'], 'y2' => $attribs['y2']), 'transform' => $attribs['gradientTransform'], 'units' => $attribs['gradientUnits'], 'spread' => $attribs['spreadMethod'], 'color' => array());
                     $last_gradid = $attribs['id'];
                     $svg_class->svgAddGradient($attribs['id'], $tmp_gradient);
                     break;
                 case 'radialgradient':
                     $tmp_gradient = array('type' => 'radial', 'info' => array('x0' => $attribs['cx'], 'y0' => $attribs['cy'], 'x1' => $attribs['fx'], 'y1' => $attribs['fy'], 'r' => $attribs['r']), 'transform' => $attribs['gradientTransform'], 'units' => $attribs['gradientUnits'], 'spread' => $attribs['spreadMethod'], 'color' => array());
                     $last_gradid = $attribs['id'];
                     $svg_class->svgAddGradient($attribs['id'], $tmp_gradient);
                     break;
                 case 'stop':
                     if (!$last_gradid) {
                         break;
                     }
                     // mPDF 4.4.003  // mPDF 5.0.040
                     if (isset($attribs['style']) and preg_match('/stop-color:\\s*([^;]*)/i', $attribs['style'], $m)) {
                         $color = trim($m[1]);
                     } else {
                         if (isset($attribs['stop-color'])) {
                             $color = $attribs['stop-color'];
                         }
                     }
                     $col = $svg_class->mpdf_ref->ConvertColor($color);
                     // mPDF 5.0.051
                     // mPDF 5.3.74
                     if ($col[0] == 3 || $col[0] == 5) {
                         // RGB
                         $color_final = sprintf('%.3F %.3F %.3F', ord($col[1]) / 255, ord($col[2]) / 255, ord($col[3]) / 255);
                         $svg_class->svg_gradient[$last_gradid]['colorspace'] = 'RGB';
                     } else {
                         if ($col[0] == 4 || $col[0] == 6) {
                             // CMYK
                             $color_final = sprintf('%.3F %.3F %.3F %.3F', ord($col[1]) / 100, ord($col[2]) / 100, ord($col[3]) / 100, ord($col[4]) / 100);
                             $svg_class->svg_gradient[$last_gradid]['colorspace'] = 'CMYK';
                         } else {
                             if ($col[0] == 1) {
                                 // Grayscale
                                 $color_final = sprintf('%.3F', ord($col[1]) / 255);
                                 $svg_class->svg_gradient[$last_gradid]['colorspace'] = 'Gray';
                             }
                         }
                     }
                     // mPDF 5.0.020
                     $stop_opacity = 1;
                     // mPDF 4.4.003
                     if (isset($attribs['style']) and preg_match('/stop-opacity:\\s*([0-9.]*)/i', $attribs['style'], $m)) {
                         $stop_opacity = $m[1];
                     } else {
                         if (isset($attribs['stop-opacity'])) {
                             $stop_opacity = $attribs['stop-opacity'];
                         } else {
                             if ($col[0] == 5) {
                                 // RGBa
                                 $stop_opacity = ord($col[4] / 100);
                             } else {
                                 if ($col[0] == 6) {
                                     // CMYKa
                                     $stop_opacity = ord($col[5] / 100);
                                 }
                             }
                         }
                     }
                     $tmp_color = array('color' => $color_final, 'offset' => $attribs['offset'], 'opacity' => $stop_opacity);
                     array_push($svg_class->svg_gradient[$last_gradid]['color'], $tmp_color);
                     break;
                 case 'a':
                     if (isset($attribs['xlink:href'])) {
                         unset($attribs['xlink:href']);
                         // this should be a hyperlink
                         // not handled like a xlink:href in other elements
                     }
                     // then continue like a <g>
                 // then continue like a <g>
                 case 'g':
                     $array_style = $svg_class->svgDefineStyle($attribs);
                     if ($array_style['transformations']) {
                         $svg_class->svgWriteString(' q ' . $array_style['transformations']);
                     }
                     array_push($svg_class->svg_style, $array_style);
                     $svg_class->svgDefineTxtStyle($attribs);
                     // mPDF 4.4.003
                     break;
                 case 'text':
                     // mPDF 4.4.003
                     $array_style = $svg_class->svgDefineStyle($attribs);
                     if ($array_style['transformations']) {
                         $svg_class->svgWriteString(' q ' . $array_style['transformations']);
                     }
                     array_push($svg_class->svg_style, $array_style);
                     $svg_class->txt_data = array();
                     $svg_class->txt_data[0] = $attribs['x'];
                     $svg_class->txt_data[1] = $attribs['y'];
                     $critere_style = $attribs;
                     unset($critere_style['x'], $critere_style['y']);
                     $svg_class->svgDefineTxtStyle($critere_style);
                     break;
             }
             //
             //insertion des path et du style dans le flux de donné general.
             if (isset($path_cmd) && $path_cmd) {
                 // mPDF 4.4.003
                 // mPDF 5.0
                 list($prestyle, $poststyle) = $svg_class->svgStyle($path_style, $attribs, strtolower($name));
                 if ($path_style['transformations']) {
                     // transformation on an element
                     $svg_class->svgWriteString(" q " . $path_style['transformations'] . " {$prestyle} {$path_cmd} {$poststyle}" . " Q\n");
                 } else {
                     $svg_class->svgWriteString("{$prestyle} {$path_cmd} {$poststyle}\n");
                 }
             }
         }
         function characterData($parser, $data)
         {
             global $svg_class;
             if (isset($svg_class->txt_data[2])) {
                 $svg_class->txt_data[2] .= $data;
             } else {
                 $svg_class->txt_data[2] = $data;
             }
         }
         function xml_svg2pdf_end($parser, $name)
         {
             global $svg_class;
             switch ($name) {
                 case "g":
                 case "a":
                     $tmp = count($svg_class->svg_style) - 1;
                     $current_style = $svg_class->svg_style[$tmp];
                     if ($current_style['transformations']) {
                         $svg_class->svgWriteString(" Q\n");
                     }
                     array_pop($svg_class->svg_style);
                     array_pop($svg_class->txt_style);
                     // mPDF 4.4.003
                     break;
                 case 'radialgradient':
                 case 'lineargradient':
                     $last_gradid = '';
                     break;
                 case "text":
                     $path_cmd = $svg_class->svgText();
                     // echo 'path >> '.$path_cmd."<br><br>";
                     // echo "style >> ".$get_style[1]."<br><br>";
                     $svg_class->svgWriteString($path_cmd);
                     // mPDF 4.4.003
                     $tmp = count($svg_class->svg_style) - 1;
                     $current_style = $svg_class->svg_style[$tmp];
                     if ($current_style['transformations']) {
                         $svg_class->svgWriteString(" Q\n");
                     }
                     array_pop($svg_class->svg_style);
                     break;
             }
             // mPDF 5.0.039	- Don't output stuff inside <defs>
             if ($name == 'defs') {
                 $svg_class->inDefs = false;
             }
         }
     }
     $svg2pdf_xml = '';
     global $svg_class;
     $svg_class = $this;
     // mPDF 5.0.039	- Don't output stuff inside <defs>
     $svg_class->inDefs = false;
     $svg2pdf_xml_parser = xml_parser_create("utf-8");
     xml_parser_set_option($svg2pdf_xml_parser, XML_OPTION_CASE_FOLDING, false);
     xml_set_element_handler($svg2pdf_xml_parser, "xml_svg2pdf_start", "xml_svg2pdf_end");
     xml_set_character_data_handler($svg2pdf_xml_parser, "characterData");
     xml_parse($svg2pdf_xml_parser, $data);
     // mPDF 4.4.003
     if ($this->svg_error) {
         return false;
     } else {
         return array('x' => $this->svg_info['x'] * $this->kp, 'y' => -$this->svg_info['y'] * $this->kp, 'w' => $this->svg_info['w'] * $this->kp, 'h' => -$this->svg_info['h'] * $this->kp, 'data' => $svg_class->svg_string);
     }
 }
Example #5
0
 function ReadCSS($html)
 {
     preg_match_all('/<style[^>]*media=["\']([^"\'>]*)["\'].*?<\\/style>/is', $html, $m);
     for ($i = 0; $i < count($m[0]); $i++) {
         if ($this->mpdf->CSSselectMedia && !preg_match('/(' . trim($this->mpdf->CSSselectMedia) . '|all)/i', $m[1][$i])) {
             $html = preg_replace('/' . preg_quote($m[0][$i], '/') . '/', '', $html);
         }
     }
     preg_match_all('/<link[^>]*media=["\']([^"\'>]*)["\'].*?>/is', $html, $m);
     for ($i = 0; $i < count($m[0]); $i++) {
         if ($this->mpdf->CSSselectMedia && !preg_match('/(' . trim($this->mpdf->CSSselectMedia) . '|all)/i', $m[1][$i])) {
             $html = preg_replace('/' . preg_quote($m[0][$i], '/') . '/', '', $html);
         }
     }
     // mPDF 5.5.02
     // Remove Comment tags <!-- ... --> inside CSS as <style> in HTML document
     // Remove Comment tags /* ...  */ inside CSS as <style> in HTML document
     // But first, we replace upper and mixed case closing style tag with lower
     // case so we can use str_replace later.
     preg_replace('/<\\/style>/i', '</style>', $html);
     preg_match_all('/<style.*?>(.*?)<\\/style>/si', $html, $m);
     if (count($m[1])) {
         for ($i = 0; $i < count($m[1]); $i++) {
             // Remove comment tags
             $sub = preg_replace('/(<\\!\\-\\-|\\-\\->)/s', ' ', $m[1][$i]);
             $sub = '>' . preg_replace('|/\\*.*?\\*/|s', ' ', $sub) . '</style>';
             $html = str_replace('>' . $m[1][$i] . '</style>', $sub, $html);
         }
     }
     $html = preg_replace('/<!--mpdf/i', '', $html);
     $html = preg_replace('/mpdf-->/i', '', $html);
     $html = preg_replace('/<\\!\\-\\-.*?\\-\\->/s', ' ', $html);
     $match = 0;
     // no match for instance
     $regexp = '';
     // This helps debugging: showing what is the REAL string being processed
     $CSSext = array();
     //CSS inside external files
     $regexp = '/<link[^>]*rel=["\']stylesheet["\'][^>]*href=["\']([^>"\']*)["\'].*?>/si';
     $x = preg_match_all($regexp, $html, $cxt);
     if ($x) {
         $match += $x;
         $CSSext = $cxt[1];
     }
     $regexp = '/<link[^>]*href=["\']([^>"\']*)["\'][^>]*?rel=["\']stylesheet["\'].*?>/si';
     $x = preg_match_all($regexp, $html, $cxt);
     if ($x) {
         $match += $x;
         $CSSext = array_merge($CSSext, $cxt[1]);
     }
     // look for @import stylesheets
     //$regexp = '/@import url\([\'\"]{0,1}([^\)]*?\.css)[\'\"]{0,1}\)/si';
     $regexp = '/@import url\\([\'\\"]{0,1}([^\\)]*?\\.css(\\?\\S+)?)[\'\\"]{0,1}\\)/si';
     $x = preg_match_all($regexp, $html, $cxt);
     if ($x) {
         $match += $x;
         $CSSext = array_merge($CSSext, $cxt[1]);
     }
     // look for @import without the url()
     //$regexp = '/@import [\'\"]{0,1}([^;]*?\.css)[\'\"]{0,1}/si';
     $regexp = '/@import [\'\\"]{0,1}([^;]*?\\.css(\\?\\S+)?)[\'\\"]{0,1}/si';
     $x = preg_match_all($regexp, $html, $cxt);
     if ($x) {
         $match += $x;
         $CSSext = array_merge($CSSext, $cxt[1]);
     }
     $ind = 0;
     $CSSstr = '';
     if (!is_array($this->cascadeCSS)) {
         $this->cascadeCSS = array();
     }
     while ($match) {
         $path = $CSSext[$ind];
         $this->mpdf->GetFullPath($path);
         $CSSextblock = $this->mpdf->_get_file($path);
         if ($CSSextblock) {
             // look for embedded @import stylesheets in other stylesheets
             // and fix url paths (including background-images) relative to stylesheet
             //$regexpem = '/@import url\([\'\"]{0,1}(.*?\.css)[\'\"]{0,1}\)/si';
             $regexpem = '/@import url\\([\'\\"]{0,1}(.*?\\.css(\\?\\S+)?)[\'\\"]{0,1}\\)/si';
             $xem = preg_match_all($regexpem, $CSSextblock, $cxtem);
             $cssBasePath = preg_replace('/\\/[^\\/]*$/', '', $path) . '/';
             if ($xem) {
                 foreach ($cxtem[1] as $cxtembedded) {
                     // path is relative to original stlyesheet!!
                     $this->mpdf->GetFullPath($cxtembedded, $cssBasePath);
                     $match++;
                     $CSSext[] = $cxtembedded;
                 }
             }
             $regexpem = '/(background[^;]*url\\s*\\(\\s*[\'\\"]{0,1})([^\\)\'\\"]*)([\'\\"]{0,1}\\s*\\))/si';
             $xem = preg_match_all($regexpem, $CSSextblock, $cxtem);
             if ($xem) {
                 for ($i = 0; $i < count($cxtem[0]); $i++) {
                     // path is relative to original stlyesheet!!
                     $embedded = $cxtem[2][$i];
                     if (!preg_match('/^data:image/i', $embedded)) {
                         // mPDF 5.5.13
                         $this->mpdf->GetFullPath($embedded, $cssBasePath);
                         $CSSextblock = preg_replace('/' . preg_quote($cxtem[0][$i], '/') . '/', $cxtem[1][$i] . $embedded . $cxtem[3][$i], $CSSextblock);
                     }
                 }
             }
             $CSSstr .= ' ' . $CSSextblock;
         }
         $match--;
         $ind++;
     }
     //end of match
     $match = 0;
     // reset value, if needed
     // CSS as <style> in HTML document
     $regexp = '/<style.*?>(.*?)<\\/style>/si';
     $match = preg_match_all($regexp, $html, $CSSblock);
     if ($match) {
         $tmpCSSstr = implode(' ', $CSSblock[1]);
         $regexpem = '/(background[^;]*url\\s*\\(\\s*[\'\\"]{0,1})([^\\)\'\\"]*)([\'\\"]{0,1}\\s*\\))/si';
         $xem = preg_match_all($regexpem, $tmpCSSstr, $cxtem);
         if ($xem) {
             for ($i = 0; $i < count($cxtem[0]); $i++) {
                 $embedded = $cxtem[2][$i];
                 if (!preg_match('/^data:image/i', $embedded)) {
                     // mPDF 5.5.13
                     //$this->mpdf->GetFullPath($embedded); /* Blue Liquid Designs Removed to allow both URL and PATHs to images */
                     $tmpCSSstr = preg_replace('/' . preg_quote($cxtem[0][$i], '/') . '/', $cxtem[1][$i] . $embedded . $cxtem[3][$i], $tmpCSSstr);
                 }
             }
         }
         $CSSstr .= ' ' . $tmpCSSstr;
     }
     // Remove comments
     $CSSstr = preg_replace('|/\\*.*?\\*/|s', ' ', $CSSstr);
     $CSSstr = preg_replace('/[\\s\\n\\r\\t\\f]/s', ' ', $CSSstr);
     if (preg_match('/@media/', $CSSstr)) {
         preg_match_all('/@media(.*?)\\{(([^\\{\\}]*\\{[^\\{\\}]*\\})+)\\s*\\}/is', $CSSstr, $m);
         for ($i = 0; $i < count($m[0]); $i++) {
             if ($this->mpdf->CSSselectMedia && !preg_match('/(' . trim($this->mpdf->CSSselectMedia) . '|all)/i', $m[1][$i])) {
                 $CSSstr = preg_replace('/' . preg_quote($m[0][$i], '/') . '/', '', $CSSstr);
             } else {
                 $CSSstr = preg_replace('/' . preg_quote($m[0][$i], '/') . '/', ' ' . $m[2][$i] . ' ', $CSSstr);
             }
         }
     }
     // Replace any background: url(data:image... with temporary image file reference
     preg_match_all("/(url\\(data:image\\/(jpeg|gif|png);base64,(.*?)\\))/si", $CSSstr, $idata);
     // mPDF 5.7.2
     if (count($idata[0])) {
         for ($i = 0; $i < count($idata[0]); $i++) {
             $file = _MPDF_TEMP_PATH . '_tempCSSidata' . RAND(1, 10000) . '_' . $i . '.' . $idata[2][$i];
             //Save to local file
             file_put_contents($file, base64_decode($idata[3][$i]));
             // $this->mpdf->GetFullPath($file);	// ? is this needed - NO  mPDF 5.6.03
             $CSSstr = str_replace($idata[0][$i], 'url("' . $file . '")', $CSSstr);
             // mPDF 5.5.17
         }
     }
     $CSSstr = preg_replace('/(<\\!\\-\\-|\\-\\->)/s', ' ', $CSSstr);
     if ($CSSstr) {
         preg_match_all('/(.*?)\\{(.*?)\\}/', $CSSstr, $styles);
         for ($i = 0; $i < count($styles[1]); $i++) {
             // SET array e.g. $classproperties['COLOR'] = '#ffffff';
             $stylestr = trim($styles[2][$i]);
             $stylearr = explode(';', $stylestr);
             foreach ($stylearr as $sta) {
                 if (trim($sta)) {
                     // Changed to allow style="background: url('http://www.bpm1.com/bg.jpg')"
                     list($property, $value) = explode(':', $sta, 2);
                     $property = trim($property);
                     $value = preg_replace('/\\s*!important/i', '', $value);
                     $value = trim($value);
                     if ($property && ($value || $value === '0')) {
                         // Ignores -webkit-gradient so doesn't override -moz-
                         if ((strtoupper($property) == 'BACKGROUND-IMAGE' || strtoupper($property) == 'BACKGROUND') && preg_match('/-webkit-gradient/i', $value)) {
                             continue;
                         }
                         $classproperties[strtoupper($property)] = $value;
                     }
                 }
             }
             $classproperties = $this->fixCSS($classproperties);
             $tagstr = strtoupper(trim($styles[1][$i]));
             $tagarr = explode(',', $tagstr);
             $pageselectors = false;
             // used to turn on $this->mpdf->mirrorMargins
             foreach ($tagarr as $tg) {
                 // mPDF 5.7.4
                 if (preg_match('/NTH-CHILD\\((\\s*(([\\-+]?\\d*)N(\\s*[\\-+]\\s*\\d+)?|[\\-+]?\\d+|ODD|EVEN)\\s*)\\)/', $tg, $m)) {
                     $tg = preg_replace('/NTH-CHILD\\(.*\\)/', 'NTH-CHILD(' . str_replace(' ', '', $m[1]) . ')', $tg);
                 }
                 $tags = preg_split('/\\s+/', trim($tg));
                 $level = count($tags);
                 $t = '';
                 $t2 = '';
                 $t3 = '';
                 if (trim($tags[0]) == '@PAGE') {
                     if (isset($tags[0])) {
                         $t = trim($tags[0]);
                     }
                     if (isset($tags[1])) {
                         $t2 = trim($tags[1]);
                     }
                     if (isset($tags[2])) {
                         $t3 = trim($tags[2]);
                     }
                     $tag = '';
                     if ($level == 1) {
                         $tag = $t;
                     } else {
                         if ($level == 2 && preg_match('/^[:](.*)$/', $t2, $m)) {
                             $tag = $t . '>>PSEUDO>>' . $m[1];
                             if ($m[1] == 'LEFT' || $m[1] == 'RIGHT') {
                                 $pageselectors = true;
                             }
                             // used to turn on $this->mpdf->mirrorMargins
                         } else {
                             if ($level == 2) {
                                 $tag = $t . '>>NAMED>>' . $t2;
                             } else {
                                 if ($level == 3 && preg_match('/^[:](.*)$/', $t3, $m)) {
                                     $tag = $t . '>>NAMED>>' . $t2 . '>>PSEUDO>>' . $m[1];
                                     if ($m[1] == 'LEFT' || $m[1] == 'RIGHT') {
                                         $pageselectors = true;
                                     }
                                     // used to turn on $this->mpdf->mirrorMargins
                                 }
                             }
                         }
                     }
                     if (isset($this->CSS[$tag]) && $tag) {
                         $this->CSS[$tag] = $this->array_merge_recursive_unique($this->CSS[$tag], $classproperties);
                     } else {
                         if ($tag) {
                             $this->CSS[$tag] = $classproperties;
                         }
                     }
                 } else {
                     if ($level == 1) {
                         // e.g. p or .class or #id or p.class or p#id
                         if (isset($tags[0])) {
                             $t = trim($tags[0]);
                         }
                         if ($t) {
                             $tag = '';
                             if (preg_match('/^[.](.*)$/', $t, $m)) {
                                 $tag = 'CLASS>>' . $m[1];
                             } else {
                                 if (preg_match('/^[#](.*)$/', $t, $m)) {
                                     $tag = 'ID>>' . $m[1];
                                 } else {
                                     if (preg_match('/^(' . $this->mpdf->allowedCSStags . ')[.](.*)$/', $t, $m)) {
                                         $tag = $m[1] . '>>CLASS>>' . $m[2];
                                     } else {
                                         if (preg_match('/^(' . $this->mpdf->allowedCSStags . ')\\s*:NTH-CHILD\\((.*)\\)$/', $t, $m)) {
                                             $tag = $m[1] . '>>SELECTORNTHCHILD>>' . $m[2];
                                         } else {
                                             if (preg_match('/^(' . $this->mpdf->allowedCSStags . ')[#](.*)$/', $t, $m)) {
                                                 $tag = $m[1] . '>>ID>>' . $m[2];
                                             } else {
                                                 if (preg_match('/^(' . $this->mpdf->allowedCSStags . ')$/', $t)) {
                                                     $tag = $t;
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                             if (isset($this->CSS[$tag]) && $tag) {
                                 $this->CSS[$tag] = $this->array_merge_recursive_unique($this->CSS[$tag], $classproperties);
                             } else {
                                 if ($tag) {
                                     $this->CSS[$tag] = $classproperties;
                                 }
                             }
                         }
                     } else {
                         $tmp = array();
                         for ($n = 0; $n < $level; $n++) {
                             if (isset($tags[$n])) {
                                 $t = trim($tags[$n]);
                             } else {
                                 $t = '';
                             }
                             if ($t) {
                                 $tag = '';
                                 if (preg_match('/^[.](.*)$/', $t, $m)) {
                                     $tag = 'CLASS>>' . $m[1];
                                 } else {
                                     if (preg_match('/^[#](.*)$/', $t, $m)) {
                                         $tag = 'ID>>' . $m[1];
                                     } else {
                                         if (preg_match('/^(' . $this->mpdf->allowedCSStags . ')[.](.*)$/', $t, $m)) {
                                             $tag = $m[1] . '>>CLASS>>' . $m[2];
                                         } else {
                                             if (preg_match('/^(' . $this->mpdf->allowedCSStags . ')\\s*:NTH-CHILD\\((.*)\\)$/', $t, $m)) {
                                                 $tag = $m[1] . '>>SELECTORNTHCHILD>>' . $m[2];
                                             } else {
                                                 if (preg_match('/^(' . $this->mpdf->allowedCSStags . ')[#](.*)$/', $t, $m)) {
                                                     $tag = $m[1] . '>>ID>>' . $m[2];
                                                 } else {
                                                     if (preg_match('/^(' . $this->mpdf->allowedCSStags . ')$/', $t)) {
                                                         $tag = $t;
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                                 if ($tag) {
                                     $tmp[] = $tag;
                                 } else {
                                     break;
                                 }
                             }
                         }
                         if ($tag) {
                             $x =& $this->cascadeCSS;
                             foreach ($tmp as $tp) {
                                 $x =& $x[$tp];
                             }
                             $x = $this->array_merge_recursive_unique($x, $classproperties);
                             $x['depth'] = $level;
                         }
                     }
                 }
             }
             if ($pageselectors) {
                 $this->mpdf->mirrorMargins = true;
             }
             $properties = array();
             $values = array();
             $classproperties = array();
         }
     }
     // end of if
     //Remove CSS (tags and content), if any
     $regexp = '/<style.*?>(.*?)<\\/style>/si';
     // it can be <style> or <style type="txt/css">
     $html = preg_replace($regexp, '', $html);
     //print_r($this->CSS); exit;
     //print_r($this->cascadeCSS); exit;
     return $html;
 }
Example #6
0
function AdjustHTML($html, $tabSpaces=8) {
	//Try to make the html text more manageable (turning it into XHTML)
	if (PHP_VERSION_ID < 50307) {
		if (strlen($html) > 100000) {
			if (PHP_VERSION_ID < 50200) $this->Error("The HTML code is more than 100,000 characters. You should use WriteHTML() with smaller string lengths.");
			else ini_set("pcre.backtrack_limit","1000000");
		}
	}

/*-- ANNOTATIONS --*/
	preg_match_all("/(<annotation.*?>)/si", $html, $m);
	if (count($m[1])) { 
		for($i=0;$i<count($m[1]);$i++) {
			$sub = preg_replace("/\n/si", "\xbb\xa4\xac", $m[1][$i]);
			$html = preg_replace('/'.preg_quote($m[1][$i], '/').'/si', $sub, $html); 
		}
	}
/*-- END ANNOTATIONS --*/

	preg_match_all("/(<svg.*?<\/svg>)/si", $html, $svgi);
	if (count($svgi[0])) { 
		for($i=0;$i<count($svgi[0]);$i++) {
			$file = _MPDF_TEMP_PATH.'_tempSVG'.RAND(1,10000).'_'.$i.'.svg';
			//Save to local file
			file_put_contents($file, $svgi[0][$i]);
			$html = str_replace($svgi[0][$i], '<img src="'.$file.'" />', $html); 	// mPDF 5.5.18
		}
	}

	//Remove javascript code from HTML (should not appear in the PDF file)
	$html = preg_replace('/<script.*?<\/script>/is','',$html);

	//Remove special comments
	$html = preg_replace('/<!--mpdf/i','',$html);
	$html = preg_replace('/mpdf-->/i','',$html);

	//Remove comments from HTML (should not appear in the PDF file)
	$html = preg_replace('/<!--.*?-->/s','',$html);

	$html = preg_replace('/\f/','',$html); //replace formfeed by nothing
	$html = preg_replace('/\r/','',$html); //replace carriage return by nothing

	// Well formed XHTML end tags
	$html = preg_replace('/<(br|hr)\/>/i',"<\\1 />",$html);
	// Get rid of empty <thead></thead>
	$html = preg_replace('/<thead>\s*<\/thead>/i','',$html);
	$html = preg_replace('/<tfoot>\s*<\/tfoot>/i','',$html);
	$html = preg_replace('/<table[^>]*>\s*<\/table>/i','',$html);
	$html = preg_replace('/<tr>\s*<\/tr>/i','',$html);

	// Remove spaces at end of table cells
	$html = preg_replace("/[ \n\r]+<\/t(d|h)/",'</t\\1',$html);		// mPDF 5.5.09

	$html = preg_replace("/[ ]*<dottab\s*[\/]*>[ ]*/",'<dottab />',$html);

	// Concatenates any Substitute characters from symbols/dingbats
	$html = str_replace('</tts><tts>','|',$html);
	$html = str_replace('</ttz><ttz>','|',$html);
	$html = str_replace('</tta><tta>','|',$html);

	$html = preg_replace('/<br \/>\s*/is',"<br />",$html);

	$html = preg_replace('/<wbr[ \/]*>\s*/is',"&#173;",$html);	// mPDF 5.6.04

	// Preserve '\n's in content between the tags <pre> and </pre>
	if (preg_match('/<pre/',$html)) {
		$html_a = preg_split('/(\<\/?pre[^\>]*\>)/', $html, -1, 2);
		$h = array();
		$c=0;
		foreach($html_a AS $s) {
			if ($c>1 && preg_match('/^<\/pre/i',$s)) { $c--; $s=preg_replace('/<\/pre/i','</innerpre',$s); }
			else if ($c>0 && preg_match('/^<pre/i',$s)) { $c++; $s=preg_replace('/<pre/i','<innerpre',$s); }
			else if (preg_match('/^<pre/i',$s)) { $c++; }
			else if (preg_match('/^<\/pre/i',$s)) { $c--; }
			array_push($h, $s);
		}
		$html = implode("", $h);
	}
	$thereispre = preg_match_all('#<pre(.*?)>(.*?)</pre>#si',$html,$temp);
	// Preserve '\n's in content between the tags <textarea> and </textarea>
	$thereistextarea = preg_match_all('#<textarea(.*?)>(.*?)</textarea>#si',$html,$temp2);
	$html = preg_replace('/[\n]/',' ',$html); //replace linefeed by spaces
	$html = preg_replace('/[\t]/',' ',$html); //replace tabs by spaces

	// Converts < to &lt; when not a tag
	$html = preg_replace('/<([^!\/a-zA-Z])/i','&lt;\\1',$html);
	$html = preg_replace("/[ ]+/",' ',$html);

	$html = preg_replace('/\/li>\s+<\/(u|o)l/i','/li></\\1l',$html);
	$html = preg_replace('/\/(u|o)l>\s+<\/li/i','/\\1l></li',$html);
	$html = preg_replace('/\/li>\s+<\/(u|o)l/i','/li></\\1l',$html);
	$html = preg_replace('/\/li>\s+<li/i','/li><li',$html);
	$html = preg_replace('/<(u|o)l([^>]*)>[ ]+/i','<\\1l\\2>',$html);
	$html = preg_replace('/[ ]+<(u|o)l/i','<\\1l',$html);

	$iterator = 0;
	while($thereispre) //Recover <pre attributes>content</pre>
	{
		$temp[2][$iterator] = preg_replace("/^([^\n\t]*?)\t/me", "stripslashes('\\1') . str_repeat(' ',  ( $tabSpaces - (mb_strlen(stripslashes('\\1')) % $tabSpaces))  )",$temp[2][$iterator]);
		$temp[2][$iterator] = preg_replace('/\t/',str_repeat(" ",$tabSpaces),$temp[2][$iterator]);

		$temp[2][$iterator] = preg_replace('/\n/',"<br />",$temp[2][$iterator]);
		$temp[2][$iterator] = str_replace('\\',"\\\\",$temp[2][$iterator]);
		$html = preg_replace('#<pre(.*?)>(.*?)</pre>#si','<erp'.$temp[1][$iterator].'>'.$temp[2][$iterator].'</erp>',$html,1);
		$thereispre--;
		$iterator++;
	}
	$iterator = 0;
	while($thereistextarea) //Recover <textarea attributes>content</textarea>
	{
		$temp2[2][$iterator] = preg_replace('/\t/',str_repeat(" ",$tabSpaces),$temp2[2][$iterator]);
		$temp2[2][$iterator] = str_replace('\\',"\\\\",$temp2[2][$iterator]);	// mPDF 5.3.88
		$html = preg_replace('#<textarea(.*?)>(.*?)</textarea>#si','<aeratxet'.$temp2[1][$iterator].'>'.trim($temp2[2][$iterator]) .'</aeratxet>',$html,1);
		$thereistextarea--;
		$iterator++;
	}
	//Restore original tag names
	$html = str_replace("<erp","<pre",$html);
	$html = str_replace("</erp>","</pre>",$html);
	$html = str_replace("<aeratxet","<textarea",$html);
	$html = str_replace("</aeratxet>","</textarea>",$html);
	$html = str_replace("</innerpre","</pre",$html); 
	$html = str_replace("<innerpre","<pre",$html); 

	$html = preg_replace('/<textarea([^>]*)><\/textarea>/si','<textarea\\1> </textarea>',$html);
	$html = preg_replace('/(<table[^>]*>)\s*(<caption)(.*?<\/caption>)(.*?<\/table>)/si','\\2 position="top"\\3\\1\\4\\2 position="bottom"\\3',$html);	// *TABLES*
	$html = preg_replace('/<(h[1-6])([^>]*)(>(?:(?!h[1-6]).)*?<\/\\1>\s*<table)/si','<\\1\\2 keep-with-table="1"\\3',$html);	// *TABLES*
	$html = preg_replace("/\xbb\xa4\xac/", "\n", $html);

	return $html;
}
Example #7
0
File: svg.php Project: hipogea/zega
 function ImageSVG($data)
 {
     // Try to clean up the start of the file
     // removing DOCTYPE fails with this:
     /*
     <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Tiny//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-tiny.dtd"
     [
     	<!ELEMENT Paragraph (#PCDATA)>
     ]>
     */
     //$data = preg_replace('/<!DOCTYPE.*?  >/is', '', $data);
     //$data = preg_replace('/<\?xml.*?  >/is', '', $data);
     $data = preg_replace('/^.*?<svg([> ])/is', '<svg\\1', $data);
     // mPDF 5.7.4
     $data = preg_replace('/<!--.*?-->/is', '', $data);
     // mPDF 5.7.4
     // Converts < to &lt; when not a tag
     $data = preg_replace('/<([^!?\\/a-zA-Z_:])/i', '&lt;\\1', $data);
     // mPDF 5.7.4
     if (_SVG_AUTOFONT) {
         $data = $this->markScriptToLang($data);
     }
     $this->svg_info = array();
     $last_gradid = '';
     // mPDF 6
     $last_svg_fontid = '';
     // mPDF 6
     $last_svg_fontdefw = '';
     // mPDF 6
     $last_svg_fontstyle = '';
     // mPDF 6
     if (preg_match('/<!ENTITY/si', $data)) {
         // Get User-defined entities
         preg_match_all('/<!ENTITY\\s+([a-z]+)\\s+\\"(.*?)\\">/si', $data, $ent);
         // Replace entities
         for ($i = 0; $i < count($ent[0]); $i++) {
             $data = preg_replace('/&' . preg_quote($ent[1][$i], '/') . ';/is', $ent[2][$i], $data);
         }
     }
     if (preg_match('/xlink:href\\s*=/si', $data)) {
         // GRADIENTS
         // Get links
         preg_match_all('/(<(linearGradient|radialgradient)[^>]*)xlink:href\\s*=\\s*["\']#(.*?)["\'](.*?)\\/>/si', $data, $links);
         if (count($links[0])) {
             $links[5] = array();
         }
         // Delete links from data - keeping in $links
         for ($i = 0; $i < count($links[0]); $i++) {
             $links[5][$i] = 'tmpLink' . RAND(100000, 9999999);
             $data = preg_replace('/' . preg_quote($links[0][$i], '/') . '/is', '<MYLINKS' . $links[5][$i] . '>', $data);
         }
         // Get targets
         preg_match_all('/<(linearGradient|radialgradient)([^>]*)id\\s*=\\s*["\'](.*?)["\'](.*?)>(.*?)<\\/(linearGradient|radialgradient)>/si', $data, $m);
         $targets = array();
         $stops = array();
         // keeping in $targets
         for ($i = 0; $i < count($m[0]); $i++) {
             $stops[$m[3][$i]] = $m[5][$i];
         }
         // Add back links this time as targets (gradients)
         for ($i = 0; $i < count($links[0]); $i++) {
             $def = $links[1][$i] . ' ' . $links[4][$i] . '>' . $stops[$links[3][$i]] . '</' . $links[2][$i] . '>';
             $data = preg_replace('/<MYLINKS' . $links[5][$i] . '>/is', $def, $data);
         }
         // mPDF 5.7.4
         // <TREF>
         preg_match_all('/<tref ([^>]*)xlink:href\\s*=\\s*["\']#([^>]*?)["\']([^>]*)\\/>/si', $data, $links);
         for ($i = 0; $i < count($links[0]); $i++) {
             // Get the item to use from defs
             $insert = '';
             if (preg_match('/<text [^>]*id\\s*=\\s*["\']' . $links[2][$i] . '["\'][^>]*>(.*?)<\\/text>/si', $data, $m)) {
                 $insert = $m[1];
             }
             if ($insert) {
                 $data = preg_replace('/' . preg_quote($links[0][$i], '/') . '/is', $insert, $data);
             }
         }
         // mPDF 5.7.2
         // <USE>
         preg_match_all('/<use ([^>]*)xlink:href\\s*=\\s*["\']#([^>]*?)["\']([^>]*)\\/>/si', $data, $links);
         for ($i = 0; $i < count($links[0]); $i++) {
             // Get the item to use from defs
             $insert = '';
             if (preg_match('/<([a-zA-Z]*) [^>]*id\\s*=\\s*["\']' . $links[2][$i] . '["\'][^>]*\\/>/si', $data, $m)) {
                 $insert = $m[0];
             }
             if (!$insert && preg_match('/<([a-zA-Z]*) [^>]*id\\s*=\\s*["\']' . $links[2][$i] . '["\']/si', $data, $m)) {
                 if (preg_match('/<' . $m[1] . '[^>]*id\\s*=\\s*["\']' . $links[2][$i] . '["\'][^>]*>.*?<\\/' . $m[1] . '>/si', $data, $m)) {
                     $insert = $m[0];
                 }
             }
             if ($insert) {
                 $inners = $links[1][$i] . ' ' . $links[3][$i];
                 // Change x,y coords to translate()
                 if (preg_match('/y\\s*=\\s*["\']([^>]*?)["\']/', $inners, $m)) {
                     $y = $m[1];
                 } else {
                     $y = 0;
                 }
                 if (preg_match('/x\\s*=\\s*["\']([^>]*?)["\']/', $inners, $m)) {
                     $x = $m[1];
                 } else {
                     $x = 0;
                 }
                 if ($x || $y) {
                     $inners = preg_replace('/(y|x)\\s*=\\s*["\']([^>]*?)["\']/', '', $inners);
                     if (preg_match('/transform\\s*=\\s*["\']([^>]*?)["\']/', $inners, $m)) {
                         if (preg_match('/translate\\(\\s*([0-9\\.]+)\\s*,\\s*([0-9\\.]+)\\s*\\)/', $m[1], $mm)) {
                             $transform = $m[1];
                             // transform="...."
                             $x += $mm[1];
                             $y += $mm[2];
                             $transform = preg_replace('/' . preg_quote($mm[0], '/') . '/', '', $transform);
                             $transform = 'transform="' . $transform . ' translate(' . $x . ', ' . $y . ')"';
                             $inners = preg_replace('/' . preg_quote($m[0], '/') . '/is', $transform, $inners);
                         } else {
                             $inners = preg_replace('/' . preg_quote($m[0], '/') . '/is', 'transform="' . $m[1] . ' translate(' . $x . ', ' . $y . ')"', $inners);
                         }
                     } else {
                         $inners .= ' transform="translate(' . $x . ', ' . $y . ')"';
                     }
                 }
             }
             $replacement = '<g ' . $inners . '>' . $insert . '</g>';
             $data = preg_replace('/' . preg_quote($links[0][$i], '/') . '/is', $replacement, $data);
         }
         preg_match_all('/<use ([^>]*)xlink:href\\s*=\\s*["\']#([^>]*?)["\']([^>]*)>\\s*<\\/use>/si', $data, $links);
         for ($i = 0; $i < count($links[0]); $i++) {
             // Get the item to use from defs
             $insert = '';
             if (preg_match('/<([a-zA-Z]*) [^>]*id\\s*=\\s*["\']' . $links[2][$i] . '["\'][^>]*\\/>/si', $data, $m)) {
                 $insert = $m[0];
             }
             if (!$insert && preg_match('/<([a-zA-Z]*) [^>]*id\\s*=\\s*["\']' . $links[2][$i] . '["\']/si', $data, $m)) {
                 if (preg_match('/<' . $m[1] . '[^>]*id\\s*=\\s*["\']' . $links[2][$i] . '["\'][^>]*>.*?<\\/' . $m[1] . '>/si', $data, $m)) {
                     $insert = $m[0];
                 }
             }
             if ($insert) {
                 $inners = $links[1][$i] . ' ' . $links[3][$i];
                 // Change x,y coords to translate()
                 if (preg_match('/y\\s*=\\s*["\']([^>]*?)["\']/', $inners, $m)) {
                     $y = $m[1];
                 } else {
                     $y = 0;
                 }
                 if (preg_match('/x\\s*=\\s*["\']([^>]*?)["\']/', $inners, $m)) {
                     $x = $m[1];
                 } else {
                     $x = 0;
                 }
                 if ($x || $y) {
                     $inners = preg_replace('/(y|x)\\s*=\\s*["\']([^>]*?)["\']/', '', $inners);
                     if (preg_match('/transform\\s*=\\s*["\']([^>]*?)["\']/', $inners, $m)) {
                         if (preg_match('/translate\\(\\s*([0-9\\.]+)\\s*,\\s*([0-9\\.]+)\\s*\\)/', $m[1], $mm)) {
                             $transform = $m[1];
                             // transform="...."
                             $x += $mm[1];
                             $y += $mm[2];
                             $transform = preg_replace('/' . preg_quote($mm[0], '/') . '/', '', $transform);
                             $transform = 'transform="' . $transform . ' translate(' . $x . ', ' . $y . ')"';
                             $inners = preg_replace('/' . preg_quote($m[0], '/') . '/is', $transform, $inners);
                         } else {
                             $inners = preg_replace('/' . preg_quote($m[0], '/') . '/is', 'transform="' . $m[1] . ' translate(' . $x . ', ' . $y . ')"', $inners);
                         }
                     } else {
                         $inners .= ' transform="translate(' . $x . ', ' . $y . ')"';
                     }
                 }
                 $replacement = '<g ' . $inners . '>' . $insert . '</g>';
                 $data = preg_replace('/' . preg_quote($links[0][$i], '/') . '/is', $replacement, $data);
             }
         }
     }
     // Removes <pattern>
     $data = preg_replace('/<pattern.*?<\\/pattern>/is', '', $data);
     // Removes <marker>
     $data = preg_replace('/<marker.*?<\\/marker>/is', '', $data);
     $this->svg_info['data'] = $data;
     $this->svg_string = '';
     //
     //	chargement unique des fonctions
     if (!function_exists("xml_svg2pdf_start")) {
         function xml_svg2pdf_start($parser, $name, $attribs)
         {
             //
             //	definition
             global $svg_class, $last_gradid, $last_svg_fontid, $last_svg_fontdefw, $last_svg_fontstyle;
             // mPDF 6
             // mPDF 6
             if (strtolower($name) == 'font') {
                 $last_svg_fontid = '';
                 if (isset($attribs['horiz-adv-x']) && $attribs['horiz-adv-x']) {
                     $last_svg_fontdefw = $attribs['horiz-adv-x'];
                 }
                 return;
             } else {
                 if (strtolower($name) == 'font-face') {
                     $last_svg_fontstyle = 'R';
                     $last_svg_fontstyle .= isset($attribs['font-weight']) && $attribs['font-weight'] == 'bold' ? 'B' : '';
                     $last_svg_fontstyle .= isset($attribs['font-style']) && $attribs['font-style'] == 'italic' ? 'I' : '';
                     $last_svg_fontstyle .= isset($attribs['font-variant']) && $attribs['font-variant'] == 'small-caps' ? 'S' : '';
                     if (isset($attribs['font-family']) && $attribs['font-family']) {
                         $tmp_svg_font = array('units-per-em' => isset($attribs['units-per-em']) ? $attribs['units-per-em'] : '', 'd' => '', 'glyphs' => array());
                         $last_svg_fontid = strtolower($attribs['font-family']);
                         if ($last_svg_fontdefw) {
                             $tmp_svg_font['horiz-adv-x'] = $last_svg_fontdefw;
                         } else {
                             $tmp_svg_font['horiz-adv-x'] = 500;
                         }
                         $svg_class->svg_font[$last_svg_fontid][$last_svg_fontstyle] = $tmp_svg_font;
                     }
                     return;
                 } else {
                     if (strtolower($name) == 'missing-glyph') {
                         if ($last_svg_fontid && isset($attribs['horiz-adv-x'])) {
                             $svg_class->svg_font[$last_svg_fontid][$last_svg_fontstyle]['horiz-adv-x'] = isset($attribs['horiz-adv-x']) ? $attribs['horiz-adv-x'] : '';
                             $svg_class->svg_font[$last_svg_fontid][$last_svg_fontstyle]['d'] = isset($attribs['d']) ? $attribs['d'] : '';
                         }
                         return;
                     } else {
                         if (strtolower($name) == 'glyph') {
                             if ($last_svg_fontid && isset($attribs['unicode'])) {
                                 $svg_class->svg_font[$last_svg_fontid][$last_svg_fontstyle]['glyphs'][$attribs['unicode']] = array('horiz-adv-x' => isset($attribs['horiz-adv-x']) ? $attribs['horiz-adv-x'] : $last_svg_fontdefw, 'd' => isset($attribs['d']) ? $attribs['d'] : '');
                             }
                             return;
                         } else {
                             if (strtolower($name) == 'lineargradient') {
                                 $tmp_gradient = array('type' => 'linear', 'transform' => isset($attribs['gradientTransform']) ? $attribs['gradientTransform'] : '', 'units' => isset($attribs['gradientUnits']) ? $attribs['gradientUnits'] : '', 'spread' => isset($attribs['spreadMethod']) ? $attribs['spreadMethod'] : '', 'color' => array());
                                 if (isset($attribs['x1'])) {
                                     $tmp_gradient['info']['x1'] = $attribs['x1'];
                                 }
                                 if (isset($attribs['y1'])) {
                                     $tmp_gradient['info']['y1'] = $attribs['y1'];
                                 }
                                 if (isset($attribs['x2'])) {
                                     $tmp_gradient['info']['x2'] = $attribs['x2'];
                                 }
                                 if (isset($attribs['y2'])) {
                                     $tmp_gradient['info']['y2'] = $attribs['y2'];
                                 }
                                 $last_gradid = $attribs['id'];
                                 $svg_class->svgAddGradient($attribs['id'], $tmp_gradient);
                                 return;
                             } else {
                                 if (strtolower($name) == 'radialgradient') {
                                     $tmp_gradient = array('type' => 'radial', 'transform' => isset($attribs['gradientTransform']) ? $attribs['gradientTransform'] : '', 'units' => isset($attribs['gradientUnits']) ? $attribs['gradientUnits'] : '', 'spread' => isset($attribs['spreadMethod']) ? $attribs['spreadMethod'] : '', 'color' => array());
                                     if (isset($attribs['cx'])) {
                                         $tmp_gradient['info']['x0'] = $attribs['cx'];
                                     }
                                     if (isset($attribs['cy'])) {
                                         $tmp_gradient['info']['y0'] = $attribs['cy'];
                                     }
                                     if (isset($attribs['fx'])) {
                                         $tmp_gradient['info']['x1'] = $attribs['fx'];
                                     }
                                     if (isset($attribs['fy'])) {
                                         $tmp_gradient['info']['y1'] = $attribs['fy'];
                                     }
                                     if (isset($attribs['r'])) {
                                         $tmp_gradient['info']['r'] = $attribs['r'];
                                     }
                                     $last_gradid = $attribs['id'];
                                     $svg_class->svgAddGradient($attribs['id'], $tmp_gradient);
                                     return;
                                 } else {
                                     if (strtolower($name) == 'stop') {
                                         if (!$last_gradid) {
                                             break;
                                         }
                                         $color = '#000000';
                                         if (isset($attribs['style']) and preg_match('/stop-color:\\s*([^;]*)/i', $attribs['style'], $m)) {
                                             $color = trim($m[1]);
                                         } else {
                                             if (isset($attribs['stop-color']) && $attribs['stop-color']) {
                                                 $color = $attribs['stop-color'];
                                             }
                                         }
                                         $col = $svg_class->mpdf_ref->ConvertColor($color);
                                         if (!$col) {
                                             $col = $svg_class->mpdf_ref->ConvertColor('#000000');
                                         }
                                         // In case "transparent" or "inherit" returned
                                         if ($col[0] == 3 || $col[0] == 5) {
                                             // RGB
                                             $color_final = sprintf('%.3F %.3F %.3F', ord($col[1]) / 255, ord($col[2]) / 255, ord($col[3]) / 255);
                                             $svg_class->svg_gradient[$last_gradid]['colorspace'] = 'RGB';
                                         } else {
                                             if ($col[0] == 4 || $col[0] == 6) {
                                                 // CMYK
                                                 $color_final = sprintf('%.3F %.3F %.3F %.3F', ord($col[1]) / 100, ord($col[2]) / 100, ord($col[3]) / 100, ord($col[4]) / 100);
                                                 $svg_class->svg_gradient[$last_gradid]['colorspace'] = 'CMYK';
                                             } else {
                                                 if ($col[0] == 1) {
                                                     // Grayscale
                                                     $color_final = sprintf('%.3F', ord($col[1]) / 255);
                                                     $svg_class->svg_gradient[$last_gradid]['colorspace'] = 'Gray';
                                                 }
                                             }
                                         }
                                         $stop_opacity = 1;
                                         if (isset($attribs['style']) and preg_match('/stop-opacity:\\s*([0-9.]*)/i', $attribs['style'], $m)) {
                                             $stop_opacity = $m[1];
                                         } else {
                                             if (isset($attribs['stop-opacity'])) {
                                                 $stop_opacity = $attribs['stop-opacity'];
                                             } else {
                                                 if ($col[0] == 5) {
                                                     // RGBa
                                                     $stop_opacity = ord($col[4] / 100);
                                                 } else {
                                                     if ($col[0] == 6) {
                                                         // CMYKa
                                                         $stop_opacity = ord($col[5] / 100);
                                                     }
                                                 }
                                             }
                                         }
                                         $tmp_color = array('color' => $color_final, 'offset' => isset($attribs['offset']) ? $attribs['offset'] : '', 'opacity' => $stop_opacity);
                                         array_push($svg_class->svg_gradient[$last_gradid]['color'], $tmp_color);
                                         return;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if ($svg_class->inDefs) {
                 return;
             }
             $svg_class->xbase = 0;
             $svg_class->ybase = 0;
             switch (strtolower($name)) {
                 // Don't output stuff inside <defs>
                 case 'defs':
                     $svg_class->inDefs = true;
                     return;
                 case 'svg':
                     $svg_class->svgOffset($attribs);
                     break;
                 case 'path':
                     $path = $attribs['d'];
                     preg_match_all('/([MZLHVCSQTAmzlhvcsqta])([eE ,\\-.\\d]+)*/', $path, $commands, PREG_SET_ORDER);
                     $path_cmd = '';
                     $svg_class->subPathInit = true;
                     $svg_class->pathBBox = array(999999, 999999, -999999, -999999);
                     foreach ($commands as $c) {
                         if (isset($c) && count($c) == 3 || isset($c[2]) && $c[2] == '') {
                             list($tmp, $command, $arguments) = $c;
                         } else {
                             list($tmp, $command) = $c;
                             $arguments = '';
                         }
                         $path_cmd .= $svg_class->svgPath($command, $arguments);
                     }
                     if ($svg_class->pathBBox[2] == -1999998) {
                         $svg_class->pathBBox[2] = 100;
                     }
                     if ($svg_class->pathBBox[3] == -1999998) {
                         $svg_class->pathBBox[3] = 100;
                     }
                     if ($svg_class->pathBBox[0] == 999999) {
                         $svg_class->pathBBox[0] = 0;
                     }
                     if ($svg_class->pathBBox[1] == 999999) {
                         $svg_class->pathBBox[1] = 0;
                     }
                     $critere_style = $attribs;
                     unset($critere_style['d']);
                     $path_style = $svg_class->svgDefineStyle($critere_style);
                     break;
                 case 'rect':
                     if (!isset($attribs['x'])) {
                         $attribs['x'] = 0;
                     }
                     if (!isset($attribs['y'])) {
                         $attribs['y'] = 0;
                     }
                     if (!isset($attribs['rx'])) {
                         $attribs['rx'] = 0;
                     }
                     if (!isset($attribs['ry'])) {
                         $attribs['ry'] = 0;
                     }
                     $arguments = array();
                     if (isset($attribs['x'])) {
                         $arguments['x'] = $attribs['x'];
                     }
                     if (isset($attribs['y'])) {
                         $arguments['y'] = $attribs['y'];
                     }
                     if (isset($attribs['width'])) {
                         $arguments['w'] = $attribs['width'];
                     }
                     if (isset($attribs['height'])) {
                         $arguments['h'] = $attribs['height'];
                     }
                     if (isset($attribs['rx'])) {
                         $arguments['rx'] = $attribs['rx'];
                     }
                     if (isset($attribs['ry'])) {
                         $arguments['ry'] = $attribs['ry'];
                     }
                     $path_cmd = $svg_class->svgRect($arguments);
                     $critere_style = $attribs;
                     unset($critere_style['x'], $critere_style['y'], $critere_style['rx'], $critere_style['ry'], $critere_style['height'], $critere_style['width']);
                     $path_style = $svg_class->svgDefineStyle($critere_style);
                     break;
                 case 'circle':
                     if (!isset($attribs['cx'])) {
                         $attribs['cx'] = 0;
                     }
                     if (!isset($attribs['cy'])) {
                         $attribs['cy'] = 0;
                     }
                     $arguments = array();
                     if (isset($attribs['cx'])) {
                         $arguments['cx'] = $attribs['cx'];
                     }
                     if (isset($attribs['cy'])) {
                         $arguments['cy'] = $attribs['cy'];
                     }
                     if (isset($attribs['r'])) {
                         $arguments['rx'] = $attribs['r'];
                     }
                     if (isset($attribs['r'])) {
                         $arguments['ry'] = $attribs['r'];
                     }
                     $path_cmd = $svg_class->svgEllipse($arguments);
                     $critere_style = $attribs;
                     unset($critere_style['cx'], $critere_style['cy'], $critere_style['r']);
                     $path_style = $svg_class->svgDefineStyle($critere_style);
                     break;
                 case 'ellipse':
                     if (!isset($attribs['cx'])) {
                         $attribs['cx'] = 0;
                     }
                     if (!isset($attribs['cy'])) {
                         $attribs['cy'] = 0;
                     }
                     $arguments = array();
                     if (isset($attribs['cx'])) {
                         $arguments['cx'] = $attribs['cx'];
                     }
                     if (isset($attribs['cy'])) {
                         $arguments['cy'] = $attribs['cy'];
                     }
                     if (isset($attribs['rx'])) {
                         $arguments['rx'] = $attribs['rx'];
                     }
                     if (isset($attribs['ry'])) {
                         $arguments['ry'] = $attribs['ry'];
                     }
                     $path_cmd = $svg_class->svgEllipse($arguments);
                     $critere_style = $attribs;
                     unset($critere_style['cx'], $critere_style['cy'], $critere_style['rx'], $critere_style['ry']);
                     $path_style = $svg_class->svgDefineStyle($critere_style);
                     break;
                 case 'line':
                     $arguments = array();
                     $arguments[0] = isset($attribs['x1']) ? $attribs['x1'] : '';
                     $arguments[1] = isset($attribs['y1']) ? $attribs['y1'] : '';
                     $arguments[2] = isset($attribs['x2']) ? $attribs['x2'] : '';
                     $arguments[3] = isset($attribs['y2']) ? $attribs['y2'] : '';
                     $path_cmd = $svg_class->svgPolyline($arguments, false);
                     $critere_style = $attribs;
                     unset($critere_style['x1'], $critere_style['y1'], $critere_style['x2'], $critere_style['y2']);
                     $path_style = $svg_class->svgDefineStyle($critere_style);
                     break;
                 case 'polyline':
                     $path = $attribs['points'];
                     preg_match_all('/[0-9\\-\\.]*/', $path, $tmp, PREG_SET_ORDER);
                     $arguments = array();
                     for ($i = 0; $i < count($tmp); $i++) {
                         if ($tmp[$i][0] != '') {
                             array_push($arguments, $tmp[$i][0]);
                         }
                     }
                     $path_cmd = $svg_class->svgPolyline($arguments);
                     $critere_style = $attribs;
                     unset($critere_style['points']);
                     $path_style = $svg_class->svgDefineStyle($critere_style);
                     break;
                 case 'polygon':
                     $path = $attribs['points'];
                     preg_match_all('/([\\-]*[0-9\\.]+)/', $path, $tmp);
                     $arguments = array();
                     for ($i = 0; $i < count($tmp[0]); $i++) {
                         if ($tmp[0][$i] != '') {
                             array_push($arguments, $tmp[0][$i]);
                         }
                     }
                     $path_cmd = $svg_class->svgPolygon($arguments);
                     //	definition du style de la forme:
                     $critere_style = $attribs;
                     unset($critere_style['points']);
                     $path_style = $svg_class->svgDefineStyle($critere_style);
                     break;
                     // mPDF 5.7.4 Embedded image
                 // mPDF 5.7.4 Embedded image
                 case 'image':
                     if (isset($attribs['xlink:href']) && $attribs['xlink:href']) {
                         $svg_class->svgImage($attribs);
                     }
                     break;
                 case 'a':
                     if (isset($attribs['xlink:href'])) {
                         unset($attribs['xlink:href']);
                         // this should be a hyperlink
                         // not handled like a xlink:href in other elements
                     }
                     // then continue like a <g>
                 // then continue like a <g>
                 case 'g':
                     $array_style = $svg_class->svgDefineStyle($attribs);
                     if (isset($array_style['transformations']) && $array_style['transformations']) {
                         // If in the middle of <text> element, add to textoutput, else WriteString
                         if ($svg_class->intext) {
                             $svg_class->textoutput .= ' q ' . $array_style['transformations'];
                         } else {
                             $svg_class->svgWriteString(' q ' . $array_style['transformations']);
                         }
                     }
                     array_push($svg_class->svg_style, $array_style);
                     $svg_class->svgDefineTxtStyle($attribs);
                     break;
                 case 'text':
                     $svg_class->textlength = 0;
                     // mPDF 5.7.4
                     $svg_class->texttotallength = 0;
                     // mPDF 5.7.4
                     $svg_class->textoutput = '';
                     // mPDF 5.7.4
                     $svg_class->textanchor = 'start';
                     // mPDF 5.7.4
                     $svg_class->textXorigin = 0;
                     // mPDF 5.7.4
                     $svg_class->textYorigin = 0;
                     // mPDF 5.7.4
                     $svg_class->intext = true;
                     // mPDF 5.7.4
                     $styl = '';
                     if (_SVG_CLASSES && isset($attribs['class']) && $attribs['class']) {
                         $classes = preg_split('/\\s+/', trim($attribs['class']));
                         foreach ($classes as $class) {
                             if (isset($svg_class->mpdf_ref->cssmgr->CSS['CLASS>>' . strtoupper($class)])) {
                                 $c = $svg_class->mpdf_ref->cssmgr->CSS['CLASS>>' . strtoupper($class)];
                                 foreach ($c as $prop => $val) {
                                     $styl .= strtolower($prop) . ':' . $val . ';';
                                 }
                             }
                         }
                     }
                     if (_SVG_AUTOFONT && isset($attribs['lang']) && $attribs['lang']) {
                         if (!$svg_class->mpdf_ref->usingCoreFont) {
                             if ($attribs['lang'] != $svg_class->mpdf_ref->default_lang) {
                                 list($coreSuitable, $mpdf_unifont) = GetLangOpts($attribs['lang'], $svg_class->mpdf_ref->useAdobeCJK, $svg_class->mpdf_ref->fontdata);
                                 if ($mpdf_unifont) {
                                     $styl .= 'font-family:' . $mpdf_unifont . ';';
                                 }
                             }
                         }
                     }
                     if ($styl) {
                         if (isset($attribs['style'])) {
                             $attribs['style'] = $styl . $attribs['style'];
                         } else {
                             $attribs['style'] = $styl;
                         }
                     }
                     $array_style = $svg_class->svgDefineStyle($attribs);
                     if ($array_style['transformations']) {
                         $svg_class->textoutput .= ' q ' . $array_style['transformations'];
                         // mPDF 5.7.4
                     }
                     array_push($svg_class->svg_style, $array_style);
                     $svg_class->txt_data = array();
                     $x = isset($attribs['x']) ? $svg_class->ConvertSVGSizePixels($attribs['x'], 'x') : 0;
                     // mPDF 5.7.4
                     $y = isset($attribs['y']) ? $svg_class->ConvertSVGSizePixels($attribs['y'], 'y') : 0;
                     // mPDF 5.7.4
                     $x += isset($attribs['dx']) ? $svg_class->ConvertSVGSizePixels($attribs['dx'], 'x') : 0;
                     // mPDF 5.7.4
                     $y += isset($attribs['dy']) ? $svg_class->ConvertSVGSizePixels($attribs['dy'], 'y') : 0;
                     // mPDF 5.7.4
                     $svg_class->txt_data[0] = $x;
                     // mPDF 5.7.4
                     $svg_class->txt_data[1] = $y;
                     // mPDF 5.7.4
                     $critere_style = $attribs;
                     unset($critere_style['x'], $critere_style['y']);
                     $svg_class->svgDefineTxtStyle($critere_style);
                     $svg_class->textanchor = $svg_class->txt_style[count($svg_class->txt_style) - 1]['text-anchor'];
                     // mPDF 5.7.4
                     $svg_class->textXorigin = $svg_class->txt_data[0];
                     // mPDF 5.7.4
                     $svg_class->textYorigin = $svg_class->txt_data[1];
                     // mPDF 5.7.4
                     $svg_class->textjuststarted = true;
                     // mPDF 5.7.4
                     break;
                     // mPDF 5.7.4
                 // mPDF 5.7.4
                 case 'tspan':
                     // OUTPUT CHUNK(s) UP To NOW (svgText updates $svg_class->textlength)
                     $p_cmd = $svg_class->svgText();
                     $svg_class->textoutput .= $p_cmd;
                     $tmp = count($svg_class->svg_style) - 1;
                     $current_style = $svg_class->svg_style[$tmp];
                     $styl = '';
                     if (_SVG_CLASSES && isset($attribs['class']) && $attribs['class']) {
                         $classes = preg_split('/\\s+/', trim($attribs['class']));
                         foreach ($classes as $class) {
                             if (isset($svg_class->mpdf_ref->cssmgr->CSS['CLASS>>' . strtoupper($class)])) {
                                 $c = $svg_class->mpdf_ref->cssmgr->CSS['CLASS>>' . strtoupper($class)];
                                 foreach ($c as $prop => $val) {
                                     $styl .= strtolower($prop) . ':' . $val . ';';
                                 }
                             }
                         }
                     }
                     if (_SVG_AUTOFONT && isset($attribs['lang']) && $attribs['lang']) {
                         if (!$svg_class->mpdf_ref->usingCoreFont) {
                             if ($attribs['lang'] != $svg_class->mpdf_ref->default_lang) {
                                 list($coreSuitable, $mpdf_unifont) = GetLangOpts($attribs['lang'], $svg_class->mpdf_ref->useAdobeCJK, $svg_class->mpdf_ref->fontdata);
                                 if ($mpdf_unifont) {
                                     $styl .= 'font-family:' . $mpdf_unifont . ';';
                                 }
                             }
                         }
                     }
                     if ($styl) {
                         if (isset($attribs['style'])) {
                             $attribs['style'] = $styl . $attribs['style'];
                         } else {
                             $attribs['style'] = $styl;
                         }
                     }
                     $array_style = $svg_class->svgDefineStyle($attribs);
                     $svg_class->txt_data = array();
                     // If absolute position adjustment (x or y), creates new block of text for text-alignment
                     if (isset($attribs['x']) || isset($attribs['y'])) {
                         // If text-anchor middle|end, adjust
                         if ($svg_class->textanchor == 'end') {
                             $tx = -$svg_class->texttotallength;
                         } else {
                             if ($svg_class->textanchor == 'middle') {
                                 $tx = -$svg_class->texttotallength / 2;
                             } else {
                                 $tx = 0;
                             }
                         }
                         while (preg_match('/mPDF-AXS\\((.*?)\\)/', $svg_class->textoutput, $m)) {
                             if ($tx) {
                                 $txk = $m[1] + $tx * $svg_class->kp;
                                 $svg_class->textoutput = preg_replace('/mPDF-AXS\\((.*?)\\)/', sprintf('%.4F', $txk), $svg_class->textoutput, 1);
                             } else {
                                 $svg_class->textoutput = preg_replace('/mPDF-AXS\\((.*?)\\)/', '\\1', $svg_class->textoutput, 1);
                             }
                         }
                         $svg_class->svgWriteString($svg_class->textoutput);
                         $svg_class->textXorigin += $svg_class->textlength;
                         $currentX = $svg_class->textXorigin;
                         $currentY = $svg_class->textYorigin;
                         $svg_class->textlength = 0;
                         $svg_class->texttotallength = 0;
                         $svg_class->textoutput = '';
                         $x = isset($attribs['x']) ? $svg_class->ConvertSVGSizePixels($attribs['x'], 'x') : $currentX;
                         $y = isset($attribs['y']) ? $svg_class->ConvertSVGSizePixels($attribs['y'], 'y') : $currentY;
                         $svg_class->txt_data[0] = $x;
                         $svg_class->txt_data[1] = $y;
                         $critere_style = $attribs;
                         unset($critere_style['x'], $critere_style['y']);
                         $svg_class->svgDefineTxtStyle($critere_style);
                         $svg_class->textanchor = $svg_class->txt_style[count($svg_class->txt_style) - 1]['text-anchor'];
                         $svg_class->textXorigin = $x;
                         $svg_class->textYorigin = $y;
                     } else {
                         $svg_class->textXorigin += $svg_class->textlength;
                         $currentX = $svg_class->textXorigin;
                         $currentY = $svg_class->textYorigin;
                         $currentX += isset($attribs['dx']) ? $svg_class->ConvertSVGSizePixels($attribs['dx'], 'x') : 0;
                         $currentY += isset($attribs['dy']) ? $svg_class->ConvertSVGSizePixels($attribs['dy'], 'y') : 0;
                         $svg_class->txt_data[0] = $currentX;
                         $svg_class->txt_data[1] = $currentY;
                         $critere_style = $attribs;
                         unset($critere_style['x'], $critere_style['y']);
                         $svg_class->svgDefineTxtStyle($critere_style);
                         $svg_class->textXorigin = $currentX;
                         $svg_class->textYorigin = $currentY;
                     }
                     if ($array_style['transformations']) {
                         $svg_class->textoutput .= ' q ' . $array_style['transformations'];
                     }
                     array_push($svg_class->svg_style, $array_style);
                     break;
             }
             //
             //insertion des path et du style dans le flux de donné general.
             if (isset($path_cmd) && $path_cmd) {
                 // mPDF 5.0
                 list($prestyle, $poststyle) = $svg_class->svgStyle($path_style, $attribs, strtolower($name));
                 if (isset($path_style['transformations']) && $path_style['transformations']) {
                     // transformation on an element
                     $svg_class->svgWriteString(" q " . $path_style['transformations'] . $prestyle . $path_cmd . $poststyle . " Q\n");
                 } else {
                     $svg_class->svgWriteString(" q " . $prestyle . $path_cmd . $poststyle . " Q\n");
                     // mPDF 5.7.4
                 }
             }
         }
         function characterData($parser, $data)
         {
             global $svg_class;
             if ($svg_class->inDefs) {
                 return;
             }
             // mPDF 5.7.2
             if (isset($svg_class->txt_data[2])) {
                 $svg_class->txt_data[2] .= $data;
             } else {
                 $svg_class->txt_data[2] = $data;
                 $svg_class->txt_data[0] = $svg_class->textXorigin;
                 $svg_class->txt_data[1] = $svg_class->textYorigin;
             }
         }
         function xml_svg2pdf_end($parser, $name)
         {
             global $svg_class;
             // mPDF 5.7.2
             // Don't output stuff inside <defs>
             if ($name == 'defs') {
                 $svg_class->inDefs = false;
                 return;
             }
             if ($svg_class->inDefs) {
                 return;
             }
             switch ($name) {
                 case "g":
                 case "a":
                     if ($svg_class->intext) {
                         $p_cmd = $svg_class->svgText();
                         $svg_class->textoutput .= $p_cmd;
                     }
                     $tmp = count($svg_class->svg_style) - 1;
                     $current_style = $svg_class->svg_style[$tmp];
                     if ($current_style['transformations']) {
                         // If in the middle of <text> element, add to textoutput, else WriteString
                         if ($svg_class->intext) {
                             $svg_class->textoutput .= " Q\n";
                         } else {
                             $svg_class->svgWriteString(" Q\n");
                         }
                     }
                     array_pop($svg_class->svg_style);
                     array_pop($svg_class->txt_style);
                     if ($svg_class->intext) {
                         $svg_class->textXorigin += $svg_class->textlength;
                         $svg_class->textlength = 0;
                     }
                     break;
                 case 'font':
                     $last_svg_fontdefw = '';
                     break;
                 case 'font-face':
                     $last_svg_fontid = '';
                     $last_svg_fontstyle = '';
                     break;
                 case 'radialgradient':
                 case 'lineargradient':
                     $last_gradid = '';
                     break;
                 case "text":
                     $svg_class->txt_data[2] = rtrim($svg_class->txt_data[2]);
                     // mPDF 5.7.4
                     $path_cmd = $svg_class->svgText();
                     $svg_class->textoutput .= $path_cmd;
                     // mPDF 5.7.4
                     $tmp = count($svg_class->svg_style) - 1;
                     $current_style = $svg_class->svg_style[$tmp];
                     if ($current_style['transformations']) {
                         $svg_class->textoutput .= " Q\n";
                         // mPDF 5.7.4
                     }
                     array_pop($svg_class->svg_style);
                     array_pop($svg_class->txt_style);
                     // mPDF 5.7.4
                     // mPDF 5.7.4
                     // If text-anchor middle|end, adjust
                     if ($svg_class->textanchor == 'end') {
                         $tx = -$svg_class->texttotallength;
                     } else {
                         if ($svg_class->textanchor == 'middle') {
                             $tx = -$svg_class->texttotallength / 2;
                         } else {
                             $tx = 0;
                         }
                     }
                     while (preg_match('/mPDF-AXS\\((.*?)\\)/', $svg_class->textoutput, $m)) {
                         if ($tx) {
                             $txk = $m[1] + $tx * $svg_class->kp;
                             $svg_class->textoutput = preg_replace('/mPDF-AXS\\((.*?)\\)/', sprintf('%.4F', $txk), $svg_class->textoutput, 1);
                         } else {
                             $svg_class->textoutput = preg_replace('/mPDF-AXS\\((.*?)\\)/', '\\1', $svg_class->textoutput, 1);
                         }
                     }
                     $svg_class->svgWriteString($svg_class->textoutput);
                     $svg_class->textlength = 0;
                     $svg_class->texttotallength = 0;
                     $svg_class->textoutput = '';
                     $svg_class->intext = false;
                     // mPDF 5.7.4
                     break;
                     // mPDF 5.7.4
                 // mPDF 5.7.4
                 case "tspan":
                     $p_cmd = $svg_class->svgText();
                     $svg_class->textoutput .= $p_cmd;
                     $tmp = count($svg_class->svg_style) - 1;
                     $current_style = $svg_class->svg_style[$tmp];
                     if ($current_style['transformations']) {
                         $svg_class->textoutput .= " Q\n";
                     }
                     array_pop($svg_class->svg_style);
                     array_pop($svg_class->txt_style);
                     $svg_class->textXorigin += $svg_class->textlength;
                     $svg_class->textlength = 0;
                     break;
             }
         }
     }
     $svg2pdf_xml = '';
     global $svg_class;
     $svg_class = $this;
     // Don't output stuff inside <defs>
     $svg_class->inDefs = false;
     $svg2pdf_xml_parser = xml_parser_create("utf-8");
     xml_parser_set_option($svg2pdf_xml_parser, XML_OPTION_CASE_FOLDING, false);
     xml_set_element_handler($svg2pdf_xml_parser, "xml_svg2pdf_start", "xml_svg2pdf_end");
     xml_set_character_data_handler($svg2pdf_xml_parser, "characterData");
     xml_parse($svg2pdf_xml_parser, $data);
     if ($this->svg_error) {
         return false;
     } else {
         return array('x' => $this->svg_info['x'] * $this->kp, 'y' => -$this->svg_info['y'] * $this->kp, 'w' => $this->svg_info['w'] * $this->kp, 'h' => -$this->svg_info['h'] * $this->kp, 'data' => $svg_class->svg_string);
     }
 }
    $control_settings = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . contact_bank_dynamic_settings_form() . " WHERE dynamicId  = %d", $form_fields[$flag]->control_id));
    for ($flag1 = 0; $flag1 < count($control_settings); $flag1++) {
        $column_dynamicId = $form_fields[$flag]->column_dynamicId;
        $control_settings_array[$column_dynamicId][$control_settings[$flag1]->dynamic_settings_key] = $control_settings[$flag1]->dynamic_settings_value;
    }
}
$form_settings = $wpdb->get_results($wpdb->prepare("SELECT form_message_key,form_message_value FROM " . contact_bank_form_settings_Table() . " WHERE form_id = %d", $form_id));
for ($flag2 = 0; $flag2 < count($form_settings); $flag2++) {
    $form_settings_array[$form_id][$form_settings[$flag2]->form_message_key] = $form_settings[$flag2]->form_message_value;
}
$forms_layout_settings = $wpdb->get_results($wpdb->prepare("SELECT form_settings_key,form_settings_value FROM " . contact_bank_layout_settings_Table() . " WHERE form_id = %d", $form_id));
for ($flag3 = 0; $flag3 < count($forms_layout_settings); $flag3++) {
    $layout_settings_array[$form_id][$forms_layout_settings[$flag3]->form_settings_key] = $forms_layout_settings[$flag3]->form_settings_value;
}
$forms_email_settings = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . contact_bank_email_template_admin() . " WHERE form_id = %d", $form_id));
$rand_value = RAND(10, 10000);
?>

<div class="cb_form_wrapper" id="cb_form_wrapper_<?php 
echo $form_id;
?>
">
	<form id="ux_frm_front_end_form_<?php 
echo $form_id . "_" . $rand_value;
?>
" class="form-horizontal" method="post" action="#">
		<div id="form_success_message_frontend_<?php 
echo $rand_value;
?>
" class="custom-message success_message" style="display: none;margin-bottom: 10px;">
			<span class="sucess_message_text" >
include_once '../Template/Header.php';
?>
		<div id="body" class="section">
			<div class="content-box">
				<h2>
					<?php 
echo $title;
?>
				</h2>
				<h3> Description :  </h3>
				<p>
					Creating an array os months and an array of moons, using a random number generator to get a random month and its corresponding moon.
				</p>
				<p>
					<?php 
$rand_num = RAND(0, 11);
?>
					<table>
						<tr>
							<td>
								Month
							</td>
							<td>
								Moon
							</td>
						</tr>
						<tr>
							<td>
								<?php 
echo $months[$rand_num];
?>
    $morehits = 400 - $alexahitstoday;
}
if ($alexahitstoday >= 400) {
    $bonus = 30;
    $morehits = -1;
}
if (strpos($_SERVER['HTTP_USER_AGENT'], 'AlexaToolbar') !== false) {
    $iminstalled = 1;
} else {
    $iminstalled = 0;
}
$randclicker = rand(1, 4);
$siteurlll = "http://likesplanet.com/?reff" . rand(1, 1000);
$backlinksdata0 = mysql_query("SELECT * FROM `alexagoogle` WHERE (`points` > '0') ORDER BY RAND() LIMIT 0, 1 ");
$verificareNum = mysql_num_rows($backlinksdata0);
$randommmi = RAND(1, 100);
if ($verificareNum == 1 && $randommmi >= 25) {
    $backlinksdata = mysql_fetch_object($backlinksdata0);
    $siteurlll = $backlinksdata->url;
    mysql_query("UPDATE `alexagoogle` SET `traffic`=`traffic`+'1', `traffic_total`=`traffic_total`+'1', `points`=`points`-'1' WHERE (`id` = '{$backlinksdata->id}') ");
} else {
    $surff10 = mysql_query("SELECT * FROM `surf` WHERE (`active` = '0' AND `points` > '0')  ORDER BY RAND() DESC LIMIT 0, 1");
    $extb = mysql_num_rows($surff10);
    if ($extb == 1 && $randommmi >= 25) {
        $backlinksdata2 = mysql_fetch_object($surff10);
        $siteurlll = $backlinksdata2->surf;
        mysql_query("UPDATE `surf` SET `total`=`total`+'1' WHERE `id`='{$backlinksdata2->id}'");
        if ($randommmi >= 50) {
            mysql_query("UPDATE `surf` SET `likes`=`likes`+'1', `points`=`points`-'0.25' WHERE `id`='{$backlinksdata2->id}'");
        }
        unset($backlinksdata);
Example #11
0
function _convImage(&$data, $colspace, $targetcs, $w, $h, $dpi, $mask) {
	if ($this->PDFA || $this->PDFX) { $mask=false; }
	$im = @imagecreatefromstring($data);
	$info = array();
	if ($im) {
		$imgdata = '';
		$mimgdata = '';
		$minfo = array();
		//Read transparency info
		$trns=array();
		$trnsrgb = false;
		if (!$this->PDFA && !$this->PDFX) { 
		   $p = strpos($data,'tRNS');
		   if ($p) { 
			$n=$this->_fourbytes2int(substr($data,($p-4),4));
			$t = substr($data,($p+4),$n);	
			if ($colspace=='DeviceGray') { 
				$trns=array(ord(substr($t,1,1))); 
				$trnsrgb = array($trns[0],$trns[0],$trns[0]);
			}
			else if ($colspace=='DeviceRGB') { 
				$trns=array(ord(substr($t,1,1)),ord(substr($t,3,1)),ord(substr($t,5,1))); 
				$trnsrgb = $trns;
				if ($targetcs=='DeviceCMYK') {
					$col = $this->rgb2cmyk(array(3,$trns[0],$trns[1],$trns[2]));
					$c1 = intval($col[1]*2.55);
					$c2 = intval($col[2]*2.55);
					$c3 = intval($col[3]*2.55);
					$c4 = intval($col[4]*2.55);
					$trns = array($c1,$c2,$c3,$c4);
				}
				else if ($targetcs=='DeviceGray') {
					$c = intval(($trns[0] * .21) + ($trns[1] * .71) + ($trns[2] * .07));
					$trns = array($c);
				}
			}
			else {	// Indexed
				$pos = strpos($t,chr(0));
				if (is_int($pos)) {
					$pal = imagecolorsforindex($im, $pos);
					$r = $pal['red'];
					$g = $pal['green'];
					$b = $pal['blue'];
					$trns=array($r,$g,$b);	// ****
					$trnsrgb = $trns;
					if ($targetcs=='DeviceCMYK') {
						$col = $this->rgb2cmyk(array(3,$r,$g,$b));
						$c1 = intval($col[1]*2.55);
						$c2 = intval($col[2]*2.55);
						$c3 = intval($col[3]*2.55);
						$c4 = intval($col[4]*2.55);
						$trns = array($c1,$c2,$c3,$c4);
					}
					else if ($targetcs=='DeviceGray') {
						$c = intval(($r * .21) + ($g * .71) + ($b * .07));
						$trns = array($c);
					}
				}
			}
		   }
		}
		for ($i = 0; $i < $h; $i++) {
			for ($j = 0; $j < $w; $j++) {
				$rgb = imagecolorat($im, $j, $i);
				$r = ($rgb >> 16) & 0xFF;
				$g = ($rgb >> 8) & 0xFF;
				$b = $rgb & 0xFF;
				if ($colspace=='Indexed') {
					$pal = imagecolorsforindex($im, $rgb);
					$r = $pal['red'];
					$g = $pal['green'];
					$b = $pal['blue'];
				}

				if ($targetcs=='DeviceCMYK') {
					$col = $this->rgb2cmyk(array(3,$r,$g,$b));
					$c1 = intval($col[1]*2.55);
					$c2 = intval($col[2]*2.55);
					$c3 = intval($col[3]*2.55);
					$c4 = intval($col[4]*2.55);
					if ($trnsrgb) {
						// original pixel was not set as transparent but processed color does match
						if ($trnsrgb!=array($r,$g,$b) && $trns==array($c1,$c2,$c3,$c4)) {
							if ($c4==0) { $c4=1; } else { $c4--; }
						}
					}
					$imgdata .= chr($c1).chr($c2).chr($c3).chr($c4);
				}
				else if ($targetcs=='DeviceGray') {
					$c = intval(($r * .21) + ($g * .71) + ($b * .07));
					if ($trnsrgb) {
						// original pixel was not set as transparent but processed color does match
						if ($trnsrgb!=array($r,$g,$b) && $trns==array($c)) {
							if ($c==0) { $c=1; } else { $c--; }
						}
					}
					$imgdata .= chr($c);
				}
				else if ($targetcs=='DeviceRGB') {
					$imgdata .= chr($r).chr($g).chr($b);
				}
				if ($mask) {
					// mPDF 5.7.2 Gamma correction
					$alpha = ($rgb & 0x7F000000) >> 24;
					if ($alpha < 127) { $mimgdata .= chr(255-($alpha * 2)); }
					else { $mimgdata .= chr(0); }
				}
			}
		}

		if ($targetcs=='DeviceGray') { $ncols = 1; }
		else if ($targetcs=='DeviceRGB') { $ncols = 3; }
		else if ($targetcs=='DeviceCMYK') { $ncols = 4; }

		$imgdata = gzcompress($imgdata);
		$info = array('w'=>$w,'h'=>$h,'cs'=>$targetcs,'bpc'=>8,'f'=>'FlateDecode','data'=>$imgdata, 'type'=>'png',
			'parms'=>'/DecodeParms <</Colors '.$ncols.' /BitsPerComponent 8 /Columns '.$w.'>>');
		if ($dpi) { $info['set-dpi'] = $dpi; }
		if ($mask) { 
			$mimgdata = gzcompress($mimgdata); 
			$minfo = array('w'=>$w,'h'=>$h,'cs'=>'DeviceGray','bpc'=>8,'f'=>'FlateDecode','data'=>$mimgdata, 'type'=>'png',
			'parms'=>'/DecodeParms <</Colors '.$ncols.' /BitsPerComponent 8 /Columns '.$w.'>>');
			if ($dpi) { $minfo['set-dpi'] = $dpi; }
			$tempfile = '_tempImgPNG'.md5($file).RAND(1,10000).'.png';
			$imgmask = count($this->images)+1;
			$minfo['i']=$imgmask ;
			$this->images[$tempfile] = $minfo;
			$info['masked'] = $imgmask;
		}
		else if ($trns) { $info['trns'] = $trns; }
		imagedestroy($im);
	}
	return $info;
}
Example #12
0
 function sbscrbr_register_user($user_id)
 {
     global $wpdb;
     $prefix = is_multisite() ? $wpdb->base_prefix : $wpdb->prefix;
     $wpdb->update($prefix . 'sndr_mail_users_info', array('unsubscribe_code' => MD5(RAND()), 'subscribe_time' => time()), array('id_user' => $user_id));
 }
Example #13
0
 /**
  * @funcionalidad obtenemos los post relacionados a partir del título
  * @param type obtenemos el texto del post a partir del cuál comparar
  * @return type devolvemos un array con los datos obtenidos
  */
 function postRelacionados($dato)
 {
     global $psDb, $psCore, $psUser;
     $consulta = "SELECT p.post_id, p.post_title, c.c_seo FROM p_posts AS p LEFT JOIN u_miembros AS u ON u.user_id = p.post_user LEFT JOIN p_categorias AS c ON c.cid = p.post_category WHERE p.post_status = :status ";
     $valores['status'] = 0;
     if (!$psUser->admod && $psCore->settings['c_see_mod'] != 1) {
         $consulta .= 'AND u.user_activo = :activo AND u.user_baneado = :ban';
         $valores['activo'] = 1;
         $valores['ban'] = 0;
     }
     $consulta .= " AND MATCH(p.post_title) AGAINST(:dato IN BOOLEAN MODE) ORDER BY :rand DESC";
     $valores['dato'] = $dato;
     $valores['rand'] = RAND();
     $datos = $psDb->resultadoArray($psDb->db_execute($consulta, $valores));
     return $datos;
 }
header("Content-type: application/json; charset=utf-8");
$con = new mysqli("localhost", "root", "trinity1346", "kichwa2");
if ($con->connect_errno) {
    die("Connection failed:" . $con->connect_error);
    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
//DEFINING VARIABLES
$nuevo_grados = array();
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
//mayor porejemplo
$scale_name = $request->nombre;
$scale_grades = $request->grados;
//$scale_origin=$request->origin;
//$scale_id=FLOOR(RAND() * 4001);
$scale_id = FLOOR(RAND() * 4001);
//var_dump($scale_name);
//var_dump($scale_id);
//first to find the scale
$insert_scale_name_query = "INSERT INTO numeros(numero_id,numero_name) VALUES('{$scale_id}','{$scale_name}')";
if ($con->query($insert_scale_name_query) === TRUE) {
    echo "inserted id:" . $scale_id . " scale_name: " . $scale_name . "\n";
} else {
    echo "Error: " . $insert_scale_name_query . "<br>" . $con->error . "\n";
}
foreach ($scale_grades as $index => $value) {
    if ((int) $value >= (int) 10) {
        $nuevo_grados[$index] = "C0" . $value;
    } else {
        $nuevo_grados[$index] = "C00" . $value;
    }
Example #15
0
                 <!--link to Search-->
               <li><a href="Dinos_Search.php">Search</a></li>
            </ul>
          </div><!--/.nav-collapse -->
        </div>
      </div> <!-- end navigation bar-->

<!-- In order to access the information, we have the login and opening of the connection -->
<?php 
$host = "localhost";
$user = "******";
$password = "******";
$database = "dino";
$link = mysqli_connect($host, $user, $password, $database);
//Randomize the information pulled but make sure it is all associated; some is hidden for verifying the correct answer
$rand = RAND(1, 25);
//only relevant data pulled from the database; Laura determined which ones apply to this question
$input = array("1", "4", "7", "12", "9", "13", "17", "21", "25");
$rand_key = array_rand($input);
$randtax = $input[$rand_key];
//our retrieved data from our tables
//since this website will be used in the future, certain changes to what is displayed for the flashcards such as hints or dinosaur names could be included
$searchq = "SELECT dinotaxon.dinotaxon_id, dinosaur.dinosaur_id, dinosaur.dinosaur_name, dinosaur.image_url, taxon.taxon_id, taxon.taxon, dinotaxon.prime FROM dinotaxon, dinosaur, \ntaxon WHERE dinosaur.dinosaur_id=dinotaxon.dinosaur_id AND dinotaxon.taxon_id=taxon.taxon_id AND taxon.taxon_id LIKE (?) GROUP BY dinosaur.dinosaur_id ORDER BY RAND()";
$listresult = mysqli_prepare($link, $searchq);
// Below command binds variables for the parameter markers in the SQL statement that was passed to above command
//corresponding variable type string so use letter s
mysqli_stmt_bind_param($listresult, 's', $randtax);
mysqli_stmt_bind_result($listresult, $dinotaxon_id, $dinosaur_id, $dinosaur_name, $image_url, $taxon_id, $taxon, $prime);
mysqli_stmt_execute($listresult);
// Once it is prepared and determined to be correct, then it can be executed
//The above protects this page from mysqli injections
 /**
  *
  * @return DataList (Orders)
  */
 protected function pastOrdersSelection()
 {
     $memberID = intval(Member::currentUserID());
     if (!$memberID) {
         //set t
         $memberID = RAND(0, 1000000) * -1;
     }
     if ($memberID) {
         return Order::get()->where("\"Order\".\"MemberID\" = " . $memberID . "\n\t\t\t\t\tAND (\"CancelledByID\" = 0 OR \"CancelledByID\" IS NULL)")->innerJoin("OrderStep", "\"Order\".\"StatusID\" = \"OrderStep\".\"ID\"");
     }
     return 0;
 }