Example #1
0
<?php

/**
 * Tutoriel file
 * Description : Merging a Segment with some data
 * You need PHP 5.2 at least
 * You need Zip Extension or PclZip library
 *
 * @copyright  GPL License 2008 - Julien Pauli - Cyril PIERRE de GEYER - Anaska (http://www.anaska.com)
 * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
 * @version 1.3
 */
// Make sure you have Zip extension or PclZip library loaded
// First : include the librairy
require_once '../library/Odf.php';
$odf = new Odf("tutoriel3.odt");
$odf->setVars('titre', 'Quelques articles de l\'encyclopédie Wikipédia');
$message = "La force de cette encyclopédie en ligne réside dans son nombre important de \r\n contributeurs. Ce sont en effet des millions d'articles qui sont disponibles dans la langue \r\n de Shakespeare et des centaines de milliers d'autres dans de nombreuses langues dont \r\n le français, l'espagnol, l'italien, le turc ou encore l'allemand.";
$odf->setVars('message', $message);
$listeArticles = array(array('titre' => 'PHP', 'texte' => 'PHP (sigle de PHP: Hypertext Preprocessor), est un langage de scripts (...)'), array('titre' => 'MySQL', 'texte' => 'MySQL est un système de gestion de base de données (SGDB). Selon le (...)'), array('titre' => 'Apache', 'texte' => 'Apache HTTP Server, souvent appelé Apache, est un logiciel de serveur (...)'));
$article = $odf->setSegment('articles');
foreach ($listeArticles as $element) {
    $article->titreArticle($element['titre']);
    $article->texteArticle($element['texte']);
    $article->merge();
}
$odf->mergeSegment($article);
// We export the file
$odf->exportAsAttachedFile();
Example #2
0
<?php

/**
 * Tutoriel file
 * Description : Adding a single image to the document
 * You need PHP 5.2 at least
 * You need Zip Extension or PclZip library
 *
 * @copyright  GPL License 2008 - Julien Pauli - Cyril PIERRE de GEYER - Anaska (http://www.anaska.com)
 * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
 * @version 1.3
 */
// Make sure you have Zip extension or PclZip library loaded
// First : include the librairy
require_once '../library/Odf.php';
$odf = new Odf("tutoriel2.odt");
$odf->setVars('titre', 'Anaska formation');
$message = "Anaska, leader Fran�ais de la formation informatique sur les technologies \nOpen Source, propose un catalogue de plus de 50 formations dont certaines pr�parent \naux certifications Linux, MySQL, PHP et PostgreSQL.";
$odf->setVars('message', $message);
$odf->setImage('image', './images/anaska.jpg');
// We export the file
$odf->exportAsAttachedFile();
 /**
  * Generate barcode image
  * @param object $barcode Instance of wps_barcodegen
  * @param string $meta Numerical code of barcode
  * @param string $type Texte for complete message
  * @param string $price Price of product
  * @param string $title Title of product
  */
 public function generate_image(&$barcode, $meta, $type, $price, $title, $post_ID = 0)
 {
     if (!empty($meta)) {
         $barcode->setGenerateCode($meta);
         $binCode = $barcode->getBinCode();
         $px = 3.779528;
         $x = round(66 * $px);
         //249.449 px
         $y = round(50 * $px);
         //188.976 px
         $bar_size = round(63.393 / 72);
         //0.880 px
         $len = 0;
         $test = '';
         while ($len !== strlen($binCode)) {
             $test .= substr($binCode, $len, 7) . ' ';
             $len = $len + 7;
         }
         $im = imagecreate($x, $y);
         $background_color = imagecolorallocate($im, 255, 255, 255);
         $start = round(5.79 * $px);
         //21.883
         /*Write First left guard*/
         $this->imgNormalGuard($im, $start, $start + $bar_size, imagecolorallocate($im, 0, 0, 0));
         $this->imgNormalGuard($im, $start + $bar_size * 2, $start + $bar_size * 3, imagecolorallocate($im, 255, 255, 255));
         $this->imgNormalGuard($im, $start + $bar_size * 4, $start + $bar_size * 5, imagecolorallocate($im, 0, 0, 0));
         $pos = $start + $bar_size * 7;
         $newPos = $pos + $bar_size;
         /*Write left barcode*/
         for ($i = 0; $i < 42; $i++) {
             if (substr($binCode, $i, 1) === '0') {
                 $color = imagecolorallocate($im, 255, 255, 255);
             } else {
                 $color = imagecolorallocate($im, 0, 0, 0);
             }
             $this->imgSymbole($im, $pos, $newPos, $color);
             $newPos = $pos + $bar_size;
             $pos = $newPos + $bar_size;
         }
         /*Writer center guard*/
         $pos = $newPos;
         $this->imgNormalGuard($im, $pos, $newPos + $bar_size, imagecolorallocate($im, 255, 255, 255));
         $this->imgNormalGuard($im, $pos + $bar_size * 2, $newPos + $bar_size * 3, imagecolorallocate($im, 0, 0, 0));
         $this->imgNormalGuard($im, $pos + $bar_size * 4, $newPos + $bar_size * 5, imagecolorallocate($im, 255, 255, 255));
         $this->imgNormalGuard($im, $pos + $bar_size * 6, $newPos + $bar_size * 7, imagecolorallocate($im, 0, 0, 0));
         $this->imgNormalGuard($im, $pos + $bar_size * 8, $newPos + $bar_size * 9, imagecolorallocate($im, 255, 255, 255));
         $pos = $newPos + $bar_size * 10;
         /*Write right barcode*/
         for ($i = 42; $i < 84; $i++) {
             if (substr($binCode, $i, 1) === '0') {
                 $color = imagecolorallocate($im, 255, 255, 255);
             } else {
                 $color = imagecolorallocate($im, 0, 0, 0);
             }
             $newPos = $pos + $bar_size;
             $this->imgSymbole($im, $pos, $newPos, $color);
             $pos = $newPos + $bar_size;
         }
         /*Write right guard*/
         $pos = $newPos + $bar_size;
         $this->imgNormalGuard($im, $pos, $pos + $bar_size, imagecolorallocate($im, 0, 0, 0));
         $this->imgNormalGuard($im, $pos + $bar_size * 2, $pos + $bar_size * 3, imagecolorallocate($im, 255, 255, 255));
         $this->imgNormalGuard($im, $pos + $bar_size * 4, $pos + $bar_size * 5, imagecolorallocate($im, 0, 0, 0));
         $textSize = 16;
         $font = WPS_BARCODE_PATH . '/arialbd.ttf';
         imagettftext($im, $textSize, 0, 8, $y - $start - 5, imagecolorallocate($im, 0, 0, 0), $font, substr($meta, 0, 1));
         $continue = true;
         $i = 28;
         $j = 0;
         /*Write left number code*/
         while ($j < 5) {
             $j = $j + 1;
             imagettftext($im, $textSize, 0, $i, $y - $start - 5, imagecolorallocate($im, 0, 0, 0), $font, substr($meta, $j, 1));
             $i = $i + 14;
         }
         /*Write right number code*/
         while ($j < 11) {
             $j = $j + 1;
             imagettftext($im, $textSize, 0, $i + 6, $y - $start - 5, imagecolorallocate($im, 0, 0, 0), $font, substr($meta, $j, 1));
             $i = $i + 15;
         }
         imagettftext($im, $textSize, 0, $i + 4, $y - $start - 5, imagecolorallocate($im, 0, 0, 0), $font, substr($meta, $j + 1, 1));
         /*Write ref product and price*/
         $textSize = 12;
         $currency = wpshop_tools::wpshop_get_currency() === '&euro;' ? "€" : wpshop_tools::wpshop_get_currency();
         if ($type === __('coupon', 'wps_barcode')) {
             $coupon_postmeta = get_post_meta($post_ID, 'wpshop_coupon_discount_type');
             if ($coupon_postmeta[0] === 'percent') {
                 $price = $price . ' %';
             } else {
                 $price = sprintf(number_format($price, 2) . ' ' . $currency);
             }
         } else {
             $price = sprintf(number_format($price, 2) . ' ' . $currency);
         }
         imagettftext($im, $textSize, 0, 20, round(6 * $px), imagecolorallocate($im, 0, 0, 0), $font, $title);
         imagettftext($im, $textSize, 0, $x / 2 + 40, round(6 * $px), imagecolorallocate($im, 0, 0, 0), $font, $price);
         ob_start();
         imagepng($im);
         $img = ob_get_clean();
         echo '<p><img src="data:image/png;base64,' . base64_encode($img) . '" id="barcode" width="160" height="90" /></p>';
         echo '<p style="text-align: right"><button class="button ' . 'button-primary button-large" type="button"' . 'id="print_barcode">' . __('Print', 'wps_barcode') . '</button></p>';
         wp_mkdir_p(WPS_BARCODE_UPLOAD);
         file_put_contents(WPS_BARCODE_UPLOAD . $meta . '.png', $img);
         /*Generate ODT File*/
         try {
             if (!class_exists('Odf')) {
                 require_once WPS_BARCODE_PATH . '/librairies/odtphp/odf.php';
             }
             $odf = new Odf(WPS_BARCODE_PATH . 'assets/medias/avery_a4_991_677.ott');
             $odf->setImage('barcode', WPS_BARCODE_UPLOAD . $meta . '.png');
             $odf->saveToDisk(WPS_BARCODE_UPLOAD . $meta . '.odt');
         } catch (Exception $e) {
             echo __('Generation problem', 'wps_barcode');
         }
     } else {
         echo '<p>' . sprintf(__('None bardcode generated as you did create %s.', 'wps_barcode'), $type) . '</p>';
     }
 }
Example #4
0
<?php

/**
 * Tutoriel file
 * Description : Imbricating several segments
 * You need PHP 5.2 at least
 * You need Zip Extension or PclZip library
 *
 * @copyright  GPL License 2008 - Julien Pauli - Cyril PIERRE de GEYER - Anaska (http://www.anaska.com)
 * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
 * @version 1.3
 */
// Make sure you have Zip extension or PclZip library loaded
// First : include the librairy
require_once '../library/Odf.php';
$odf = new Odf("tutoriel4.odt");
$odf->setVars('titre', 'Articles disponibles :');
$categorie = $odf->setSegment('categories');
for ($j = 1; $j <= 2; $j++) {
    $categorie->setVars('TitreCategorie', 'Cat�gorie ' . $j);
    for ($i = 1; $i <= 3; $i++) {
        $categorie->articles->titreArticle('Article ' . $i);
        $categorie->articles->date(date('d/m/Y'));
        $categorie->articles->merge();
    }
    for ($i = 1; $i <= 4; $i++) {
        $categorie->commentaires->texteCommentaire('Commentaire ' . $i);
        $categorie->commentaires->merge();
    }
    $categorie->merge();
}
Example #5
0
<?php

/**
 * Tutoriel file
 * Description : Odf object with configuration array
 * You need PHP 5.2 at least
 * You need Zip Extension or PclZip library
 *
 * @copyright  GPL License 2008 - Julien Pauli - Cyril PIERRE de GEYER - Anaska (http://www.anaska.com)
 * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
 * @version 1.3
 */
// Make sure you have Zip extension or PclZip library loaded
// First : include the librairy
require_once '../library/Odf.php';
$config = array('ZIP_PROXY' => 'PhpZipProxy', 'DELIMITER_LEFT' => '#', 'DELIMITER_RIGHT' => '#');
$odf = new Odf("tutoriel7.odt", $config);
$odf->setVars('titre', 'PHP: Hypertext PreprocessorPHP: Hypertext Preprocessor');
$message = "PHP (sigle de PHP: Hypertext Preprocessor), est un langage de scripts libre \r\nprincipalement utilisé pour produire des pages Web dynamiques via un serveur HTTP, mais \r\npouvant également fonctionner comme n'importe quel langage interprété de façon locale, \r\nen exécutant les programmes en ligne de commande.";
$odf->setVars('message', $message);
// We export the file
$odf->exportAsAttachedFile();
Example #6
0
 /**
  * Merge template variables
  * Called automatically for a save
  *
  * @return void
  */
 protected function _parse()
 {
     parent::_parse();
     $this->stylesXml = str_replace(array_keys($this->styleVars), array_values($this->styleVars), $this->stylesXml);
 }
Example #7
0
 public function __construct($filename, $config = array())
 {
     $this->_filename = \GO\Base\Fs\File::utf8Basename($filename);
     return parent::__construct($filename, $config);
 }