function __construct($source, $target, $data) { require_once 'pclzip.lib.php'; include_once '/agata/include/util.inc'; $this->buffer = array(); $this->break_style = '<style:style style:name="AgataPageBreak" style:family="paragraph" style:parent-style-name="Standard">' . '<style:properties fo:break-before="page"/>' . '</style:style>'; $this->page_break = '<text:p text:style-name="AgataPageBreak"/>'; define(temp, '/tmp'); define("bar", '/'); $prefix = temp . bar . RemoveExtension($source); $zip = new PclZip($source); if (($list = $zip->listContent()) == 0) { adie("Error : " . $zip->errorInfo(true)); } recursive_remove_directory($prefix); if ($zip->extract(PCLZIP_OPT_PATH, $prefix) == 0) { adie("Error : " . $zip->errorInfo(true)); } $content = file_get_contents($prefix . '/content.xml'); # break xml tags $array_content = preg_split('/(<(?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+>)/', trim($content), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); //print_r($array_content); $section = 'start'; echo "antes for\n"; foreach ($array_content as $line) { // <text:section text:style-name="Sect1" text:name="header"> if (substr(trim($line), 0, 13) == '<text:section') { $pieces = explode('text:name="', $line); $section = substr($pieces[1], 0, -2); } else { if (substr(trim($line), 0, 14) == '</office:body>') { $section = 'end'; } } if ($line == '</office:automatic-styles>') { $line = $this->break_style . $line; } $this->buffer[$section][] = $line; //echo $section . "\n"; } echo "depois for\n"; print_r($this->buffer); $output = implode('', $this->buffer['start']); $break = false; foreach ($data as $line) { $sub = array(); $sub[] = array('01/01/2005', 'abertura'); $sub[] = array('02/01/2005', 'Software Livre'); $sub[] = array('03/01/2005', 'PHP-GTK'); $sub[] = array('04/01/2005', 'Agata Report'); $sub[] = array('05/01/2005', 'encerramento'); $sub[] = array('06/01/2005', 'encerramento2'); $sub[] = array('07/01/2005', 'encerramento3'); $sub[] = array('08/01/2005', 'encerramento4'); $sub[] = array('09/01/2005', 'encerramento5'); $sub[] = array('10/01/2005', 'encerramento6'); $sub[] = array('11/01/2005', 'encerramento7'); $sub[] = array('12/01/2005', 'encerramento8'); $output .= $this->printSection('header', $line, $break); $output .= $this->printSection('details', $line, $sub); $output .= $this->printSection('footer', $line); //$output .= $page_break; $break = true; while ($this->rest) { if ($this->repeat_header) { $output .= $this->printSection('header', $line, $break); } else { $output .= $this->page_break; } $output .= $this->printSection('details', $line, $this->rest); if ($this->repeat_footer) { $output .= $this->printSection('footer', $line); } } } $output .= implode('', $this->buffer['end']); echo strlen($output); echo "\n"; file_put_contents($prefix . '/content.xml', $output); $zip2 = new PclZip($target); foreach ($list as $file) { $zip2->add($prefix . '/' . $file['filename'], PCLZIP_OPT_REMOVE_PATH, $prefix); echo "Adding " . $file['filename'] . "\n"; } }
function MakeFont($fontfile, $afmfile, $enc = 'cp1252', $patch = array(), $type = 'TrueType') { //Generate a font definition file set_magic_quotes_runtime(0); if ($enc) { $map = ReadMap($enc); foreach ($patch as $cc => $gn) { $map[$cc] = $gn; } } else { $map = array(); } if (!file_exists($afmfile)) { adie('<B>Error:</B> AFM file not found: ' . $afmfile); } $fm = ReadAFM($afmfile, $map); if ($enc) { $diff = MakeFontEncoding($map); } else { $diff = ''; } $fd = MakeFontDescriptor($fm, empty($map)); //Find font type if ($fontfile) { $ext = strtolower(substr($fontfile, -3)); if ($ext == 'ttf') { $type = 'TrueType'; } elseif ($ext == 'pfb') { $type = 'Type1'; } else { adie('<B>Error:</B> unrecognized font file extension: ' . $ext); } } else { if ($type != 'TrueType' and $type != 'Type1') { adie('<B>Error:</B> incorrect font type: ' . $type); } } //Start generation $s = '<?php' . "\n"; $s .= '$type=\'' . $type . "';\n"; $s .= '$name=\'' . $fm['FontName'] . "';\n"; $s .= '$desc=' . $fd . ";\n"; if (!isset($fm['UnderlinePosition'])) { $fm['UnderlinePosition'] = -100; } if (!isset($fm['UnderlineThickness'])) { $fm['UnderlineThickness'] = 50; } $s .= '$up=' . $fm['UnderlinePosition'] . ";\n"; $s .= '$ut=' . $fm['UnderlineThickness'] . ";\n"; $w = MakeWidthArray($fm); $s .= '$cw=' . $w . ";\n"; $s .= '$enc=\'' . $enc . "';\n"; $s .= '$diff=\'' . $diff . "';\n"; $basename = substr(basename($afmfile), 0, -4); if ($fontfile) { //Embedded font if (!file_exists($fontfile)) { adie('<B>Error:</B> font file not found: ' . $fontfile); } if ($type == 'TrueType') { CheckTTF($fontfile); } $f = fopen($fontfile, 'rb'); if (!$f) { adie('<B>Error:</B> Can\'t open ' . $fontfile); } $file = fread($f, filesize($fontfile)); fclose($f); if ($type == 'Type1') { //Find first two sections and discard third one $pos = strpos($file, 'eexec'); if (!$pos) { adie('<B>Error:</B> font file does not seem to be valid Type1'); } $size1 = $pos + 6; $pos = strpos($file, '00000000'); if (!$pos) { adie('<B>Error:</B> font file does not seem to be valid Type1'); } $size2 = $pos - $size1; $file = substr($file, 0, $size1 + $size2); } if (function_exists('gzcompress')) { $cmp = $basename . '.z'; SaveToFile($cmp, gzcompress($file), 'b'); $s .= '$file=\'' . $cmp . "';\n"; echo 'Font file compressed (' . $cmp . ')<BR>'; } else { $s .= '$file=\'' . basename($fontfile) . "';\n"; echo '<B>Notice:</B> font file could not be compressed (gzcompress not available)<BR>'; } if ($type == 'Type1') { $s .= '$size1=' . $size1 . ";\n"; $s .= '$size2=' . $size2 . ";\n"; } else { $s .= '$originalsize=' . filesize($fontfile) . ";\n"; } } else { //Not embedded font $s .= '$file=' . "'';\n"; } $s .= "?>\n"; SaveToFile($basename . '.php', $s); echo 'Font definition file generated (' . $basename . '.php' . ')<BR>'; }
function Error($msg) { //Fatal error adie('<B>FPDF error: </B>' . $msg); }
function Stroke(&$img, &$xscale, &$yscale) { $numpoints = count($this->coords[0]); if (isset($this->coords[1])) { if (count($this->coords[1]) != $numpoints) { adie("JpGraph Error: Number of X and Y points are not equal.<br>\n\t\t\t\t\tNumber of X-points:" . count($this->coords[1]) . "<br>\n\t\t\t\t\tNumber of Y-points:{$numpoints}"); } else { $exist_x = true; } } else { $exist_x = false; } $numbars = count($this->coords[0]); if ($yscale->scale[0] >= 0) { $zp = $yscale->scale_abs[0]; } else { $zp = $yscale->Translate(0.0); } if ($this->abswidth > -1) { $abswidth = $this->abswidth; } else { $abswidth = round($this->width * $xscale->scale_factor, 0); } for ($i = 0; $i < $numbars; $i++) { if ($exist_x) { $x = $this->coords[1][$i]; } else { $x = $i; } $x = $xscale->Translate($x); if ($this->align == "center") { $x -= $abswidth / 2; } elseif ($this->align == "right") { $x -= $abswidth; } $pts = array($x, $zp, $x, $yscale->Translate($this->coords[0][$i]), $x + $abswidth, $yscale->Translate($this->coords[0][$i]), $x + $abswidth, $zp); if ($this->grad) { $grad = new Gradient($img); $grad->FilledRectangle($pts[2], $pts[3], $pts[6], $pts[7], $this->grad_fromcolor, $this->grad_tocolor, $this->grad_style); } elseif (!empty($this->fill_color)) { if (is_array($this->fill_color)) { $img->PushColor($this->fill_color[$i % count($this->fill_color)]); } else { $img->PushColor($this->fill_color); } $img->FilledPolygon($pts); $img->PopColor(); } // Remember value of this bar $val = $this->coords[0][$i]; if ($this->bar_shadow && $val != 0) { $ssh = $this->bar_shadow_hsize; $ssv = $this->bar_shadow_vsize; // Create points to create a "upper-right" shadow if ($val > 0) { $sp[0] = $pts[6]; $sp[1] = $pts[7]; $sp[2] = $pts[4]; $sp[3] = $pts[5]; $sp[4] = $pts[2]; $sp[5] = $pts[3]; $sp[6] = $pts[2] + $ssh; $sp[7] = $pts[3] - $ssv; $sp[8] = $pts[4] + $ssh; $sp[9] = $pts[5] - $ssv; $sp[10] = $pts[6] + $ssh; $sp[11] = $pts[7] - $ssv; } elseif ($val < 0) { $sp[0] = $pts[4]; $sp[1] = $pts[5]; $sp[2] = $pts[6]; $sp[3] = $pts[7]; $sp[4] = $pts[0]; $sp[5] = $pts[1]; $sp[6] = $pts[0] + $ssh; $sp[7] = $pts[1] - $ssv; $sp[8] = $pts[6] + $ssh; $sp[9] = $pts[7] - $ssv; $sp[10] = $pts[4] + $ssh; $sp[11] = $pts[5] - $ssv; } $img->PushColor($this->bar_shadow_color); $img->FilledPolygon($sp); $img->PopColor(); } // Stroke the outline of the bar if (is_array($this->color)) { $img->SetColor($this->color[$i % count($this->color)]); } else { $img->SetColor($this->color); } $img->SetLineWeight($this->weight); $img->Polygon($pts); $x = $pts[2] + ($pts[4] - $pts[2]) / 2; $y = $pts[3]; $this->value->Stroke($img, $val, $x, $y); // Create the client side image map $this->csimareas .= "<area shape=\"rect\" coords=\""; // Hmmm, this is fishy. Fixes a bug in Opera whereby if Y2<Y1 or X2<X1 the csim doesn't work if ($pts[3] < $pts[7]) { if ($pts[2] < $pts[6]) { $this->csimareas .= "{$pts['2']}, {$pts['3']}, {$pts['6']}, {$pts['7']}\""; } else { $this->csimareas .= "{$pts['6']}, {$pts['3']}, {$pts['2']}, {$pts['7']}\""; } } else { if ($pts[2] < $pts[6]) { $this->csimareas .= "{$pts['2']}, {$pts['7']}, {$pts['6']}, {$pts['3']}\""; } else { $this->csimareas .= "{$pts['6']}, {$pts['7']}, {$pts['2']}, {$pts['3']}\""; } } if (!empty($this->csimtargets[$i])) { $this->csimareas .= " href=\"" . $this->csimtargets[$i] . "\""; } if (!empty($this->csimalts[$i])) { $sval = sprintf($this->csimalts[$i], $this->coords[0][$i]); $this->csimareas .= " alt=\"{$sval}\" title=\"{$sval}\" "; } $this->csimareas .= ">\r\n"; } return true; }
function _error($msg) { adie('<b>PHP DocWriter error:</b> ' . $msg); }
function PclZip($p_zipname) { //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::PclZip', "zipname=$p_zipname"); // ----- Tests the zlib if (!function_exists('gzopen')) { //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 1, "zlib extension seems to be missing"); adie('Abort ' . basename(__FILE__) . ' : Missing zlib extensions'); } // ----- Set the attributes $this->zipname = $p_zipname; $this->zip_fd = 0; // ----- Return //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 1); return; }
/** * Change the RGB components of the elements in the colour palette. * * @access public * @param integer $index colour index * @param integer $red red RGB value [0-255] * @param integer $green green RGB value [0-255] * @param integer $blue blue RGB value [0-255] * @return integer The palette index for the custom color */ function set_custom_color($index, $red, $green, $blue) { // Match a HTML #xxyyzz style parameter /*if (defined $_[1] and $_[1] =~ /^#(\w\w)(\w\w)(\w\w)/ ) { @_ = ($_[0], hex $1, hex $2, hex $3); }*/ // Check that the colour index is the right range if ($index < 8 or $index > 64) { adie("Color index {$index} outside range: 8 <= index <= 64"); } // Check that the colour components are in the right range if (($red < 0 or $red > 255) || ($green < 0 or $green > 255) || ($blue < 0 or $blue > 255)) { adie("Color component outside range: 0 <= color <= 255"); } $index -= 8; // Adjust colour index (wingless dragonfly) // Set the RGB value $this->palette[$index] = array($red, $green, $blue, 0); return $index + 8; }
/** * Write root entry, big block list and close the filehandle. * This routine is used to explicitly close the open filehandle without * having to wait for DESTROY. * * @access public * @see Workbook::store_OLE_file() */ function close() { //return if not $this->{_size_allowed}; $this->_write_padding(); $this->_write_property_storage(); $this->_write_big_block_depot(); // Close the filehandle fclose($this->_filehandle); if ($this->_OLEfilename == '-' or $this->_OLEfilename == '') { $fh = fopen($this->_tmp_filename, "rb"); if ($fh == false) { adie("Can't read temporary file."); } fpassthru($fh); // Delete the temporary file. @unlink($this->_tmp_filename); } $this->_fileclosed = 1; }
/** * It parses a function call. It assumes the following rule: * Func -> ( Expr [,Expr]* ) * */ function _func() { $num_args = 0; // number of arguments received $function = $this->_current_token; $this->_advance(); $this->_advance(); // eat the "(" while ($this->_current_token != ')') { if ($num_args > 0) { if ($this->_current_token == COMA) { $this->_advance(); // eat the "," } else { adie("Sintactic error: coma expected {$num_args}"); } $result = $this->_create_tree('arg', $result, $this->_expression()); } else { $result = $this->_create_tree('arg', '', $this->_expression()); } $num_args++; } $args = $this->_functions[$function][1]; // If fixed number of args eg. TIME($i,$j,$k). Check that the number of args is valid. if ($args >= 0 and $args != $num_args) { adie("Incorrect number of arguments in function {$function}() "); } $result = $this->_create_tree($function, $result, ''); $this->_advance(); // eat the ")" return $result; }
/** * Convert a 24 bit bitmap into the modified internal format used by Windows. * This is described in BITMAPCOREHEADER and BITMAPCOREINFO structures in the * MSDN library. * * @param string $bitmap The bitmap to process * @return array Array with data and properties of the bitmap */ function _process_bitmap($bitmap) { // Open file. $bmp_fd = fopen($bitmap, "rb"); if (!$bmp_fd) { adie("Couldn't import {$bitmap}"); } // Slurp the file into a string. $data = fread($bmp_fd, filesize($bitmap)); // Check that the file is big enough to be a bitmap. if (strlen($data) <= 0x36) { adie("{$bitmap} doesn't contain enough data.\n"); } // The first 2 bytes are used to identify the bitmap. $identity = unpack("A2", $data); if ($identity[''] != "BM") { adie("{$bitmap} doesn't appear to be a valid bitmap image.\n"); } // Remove bitmap data: ID. $data = substr($data, 2); // Read and remove the bitmap size. This is more reliable than reading // the data size at offset 0x22. // $size_array = unpack("V", substr($data, 0, 4)); $size = $size_array['']; $data = substr($data, 4); $size -= 0x36; // Subtract size of bitmap header. $size += 0xc; // Add size of BIFF header. // Remove bitmap data: reserved, offset, header length. $data = substr($data, 12); // Read and remove the bitmap width and height. Verify the sizes. $width_and_height = unpack("V2", substr($data, 0, 8)); $width = $width_and_height[1]; $height = $width_and_height[2]; $data = substr($data, 8); if ($width > 0xffff) { adie("{$bitmap}: largest image width supported is 65k.\n"); } if ($height > 0xffff) { adie("{$bitmap}: largest image height supported is 65k.\n"); } // Read and remove the bitmap planes and bpp data. Verify them. $planes_and_bitcount = unpack("v2", substr($data, 0, 4)); $data = substr($data, 4); if ($planes_and_bitcount[2] != 24) { // Bitcount adie("{$bitmap} isn't a 24bit true color bitmap.\n"); } if ($planes_and_bitcount[1] != 1) { adie("{$bitmap}: only 1 plane supported in bitmap image.\n"); } // Read and remove the bitmap compression. Verify compression. $compression = unpack("V", substr($data, 0, 4)); $data = substr($data, 4); //$compression = 0; if ($compression[""] != 0) { adie("{$bitmap}: compression not supported in bitmap image.\n"); } // Remove bitmap data: data size, hres, vres, colours, imp. colours. $data = substr($data, 20); // Add the BITMAPCOREHEADER data $header = pack("Vvvvv", 0xc, $width, $height, 0x1, 0x18); $data = $header . $data; return array($width, $height, $size, $data); }
/** * Determine the byte order and store it as class data to avoid * recalculating it for each call to new(). * * @access private */ function _set_byte_order() { if ($this->_byte_order == '') { // Check if "pack" gives the required IEEE 64bit float $teststr = pack("d", 1.2345); $number = pack("C8", 0x8d, 0x97, 0x6e, 0x12, 0x83, 0xc0, 0xf3, 0x3f); if ($number == $teststr) { $byte_order = 0; // Little Endian } elseif ($number == strrev($teststr)) { $byte_order = 1; // Big Endian } else { // Give up. I'll fix this in a later version. adie("Required floating point format not supported " . "on this platform. See the portability section " . "of the documentation."); } } $this->_byte_order = $byte_order; }