Projet

Général

Profil

Révision e9f59ce0

Ajouté par Assos Assos il y a plus de 8 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/views_pdf/views_pdf_template.php
406 406
  }
407 407

  
408 408
  protected function renderRow($x, $y, $row, $options, &$view = NULL, $key = NULL, $printLabels = TRUE) {
409
      if ($options['position']['object'] !== 'header_footer') {
410
        $pageDim = $this->getPageDimensions();
409 411

  
410
    $pageDim = $this->getPageDimensions();
411

  
412
    // Render the content if it is not already:
413
    if (is_object($view) && $key != NULL && isset($view->field[$key]) && is_object($view->field[$key]) && !is_string($row)) {
414
      $content = $view->field[$key]->theme($row);
415
    }
416
    elseif (is_string($row)) {
417
      $content = $row;
418
    }
419
    else {
420
      // We got bad data. So return.
421
      return;
422
    }
412
        // Render the content if it is not already:
413
        if (is_object($view) && $key != NULL && isset($view->field[$key]) && is_object($view->field[$key]) && !is_string($row)) {
414
          $content = $view->field[$key]->theme($row);
415
        }
416
        elseif (is_string($row)) {
417
          $content = $row;
418
        }
419
        else {
420
          // We got bad data. So return.
421
          return;
422
        }
423 423

  
424
    if (empty($key) || !empty($view->field[$key]->options['exclude']) || (empty($content) && $view->field[$key]->options['hide_empty'])) {
425
      return '';
426
    }
424
        if (empty($key) || !empty($view->field[$key]->options['exclude']) || (empty($content) && $view->field[$key]->options['hide_empty'])) {
425
          return '';
426
        }
427 427

  
428
    // Apply the hyphenation patterns to the content:
429
    if (!isset($options['text']['hyphenate']) && is_object($view) && is_object($view->display_handler)) {
430
      $options['text']['hyphenate'] = $view->display_handler->get_option('default_text_hyphenate');
431
    }
428
        // Apply the hyphenation patterns to the content:
429
        if (!isset($options['text']['hyphenate']) && is_object($view) && is_object($view->display_handler)) {
430
          $options['text']['hyphenate'] = $view->display_handler->get_option('default_text_hyphenate');
431
        }
432 432

  
433
    if (isset($options['text']['hyphenate']) && $options['text']['hyphenate'] != 'none') {
434
      $patternFile = $options['text']['hyphenate'];
435
      if ($options['text']['hyphenate'] == 'auto' && is_object($row)) {
433
        if (isset($options['text']['hyphenate']) && $options['text']['hyphenate'] != 'none') {
434
          $patternFile = $options['text']['hyphenate'];
435
          if ($options['text']['hyphenate'] == 'auto' && is_object($row)) {
436

  
437
            // Workaround:
438
            // Since "$nodeLanguage = $row->node_language;" does not work anymore,
439
            // we using this:
440
            if (isset($row->_field_data['nid']['entity']->language)) {
441
              $nodeLanguage = $row->_field_data['nid']['entity']->language;
442

  
443
              foreach (self::getAvailableHyphenatePatterns() as $file => $pattern) {
444
                if (stristr($pattern, $nodeLanguage) !== FALSE) {
445
                  $patternFile = $file;
446
                  break;
447
                }
448
              }
449
            }
450
          }
436 451

  
437
        // Workaround:
438
        // Since "$nodeLanguage = $row->node_language;" does not work anymore,
439
        // we using this:
440
        if (isset($row->_field_data['nid']['entity']->language)) {
441
          $nodeLanguage = $row->_field_data['nid']['entity']->language;
452
          $patternFile = views_pdf_get_library('tcpdf') . '/hyphenate_patterns/' . $patternFile;
442 453

  
443
          foreach (self::getAvailableHyphenatePatterns() as $file => $pattern) {
444
            if (stristr($pattern, $nodeLanguage) !== FALSE) {
445
              $patternFile = $file;
446
              break;
454
          if (file_exists($patternFile)) {
455
            if (method_exists('TCPDF_STATIC', 'getHyphenPatternsFromTEX')) {
456
              $hyphen_patterns = TCPDF_STATIC::getHyphenPatternsFromTEX($patternFile);
457
            }
458
            else {
459
              $hyphen_patterns = $this->getHyphenPatternsFromTEX($patternFile);
447 460
            }
448
          }
449
        }
450
      }
451 461

  
452
      $patternFile = views_pdf_get_library('tcpdf') . '/hyphenate_patterns/' . $patternFile;
462
            // Bugfix if you like to print some html code to the PDF, we
463
            // need to prevent the replacement of this tags.
464
            $content = str_replace('>', '>', $content);
465
            $content = str_replace('<', '<', $content);
466
            $content = $this->hyphenateText($content, $hyphen_patterns);
453 467

  
454
      if (file_exists($patternFile)) {
455
        if (method_exists('TCPDF_STATIC', 'getHyphenPatternsFromTEX')) {
456
          $hyphen_patterns = TCPDF_STATIC::getHyphenPatternsFromTEX($patternFile);
457
        }
458
        else {
459
          $hyphen_patterns = $this->getHyphenPatternsFromTEX($patternFile);
468
          }
460 469
        }
461 470

  
462
        // Bugfix if you like to print some html code to the PDF, we
463
        // need to prevent the replacement of this tags.
464
        $content = str_replace('>', '>', $content);
465
        $content = str_replace('<', '<', $content);
466
        $content = $this->hyphenateText($content, $hyphen_patterns);
467

  
468
      }
469
    }
471
        // Set css variable
472
        if (is_object($view) && is_object($view->display_handler)) {
473
          $css_file = $view->display_handler->get_option('css_file');
474
        }
470 475

  
471
    // Set css variable
472
    if (is_object($view) && is_object($view->display_handler)) {
473
      $css_file = $view->display_handler->get_option('css_file');
474
    }
476
        // Render Labels
477
        $prefix = '';
478
        if ($printLabels && !empty($view->field[$key]->options['label'])) {
479
          $prefix = $view->field[$key]->options['label'];
480
          if ($view->field[$key]->options['element_label_colon']) {
481
            $prefix .= ':';
482
          }
483
          $prefix .= ' ';
484
        }
475 485

  
476
    // Render Labels
477
    $prefix = '';
478
    if ($printLabels && !empty($view->field[$key]->options['label'])) {
479
      $prefix = $view->field[$key]->options['label'];
480
      if ($view->field[$key]->options['element_label_colon']) {
481
        $prefix .= ':';
482
      }
483
      $prefix .= ' ';
484
    }
486
        $font_size = empty($options['text']['font_size']) ? $this->defaultFontSize : $options['text']['font_size'] ;
487
        $font_family = ($options['text']['font_family'] == 'default' || empty($options['text']['font_family'])) ? $this->defaultFontFamily : $options['text']['font_family'];
488
        $font_style = is_array($options['text']['font_style']) ? $options['text']['font_style'] : $this->defaultFontStyle;
489
        $textColor = !empty($options['text']['color']) ? $this->parseColor($options['text']['color']) : $this->parseColor($this->defaultFontColor);
490

  
491

  
492
        $w = $options['position']['width'];
493
        $h = $options['position']['height'];
494
        $border = 0;
495
        $align = isset($options['text']['align']) ? $options['text']['align'] : $this->defaultTextAlign;
496
        $fill = 0;
497
        $ln = 1;
498
        $reseth = TRUE;
499
        $stretch = 0;
500
        $ishtml = isset($options['render']['is_html']) ? $options['render']['is_html'] : 1;
501
        $stripHTML = !$ishtml;
502
        $autopadding = TRUE;
503
        $maxh = 0;
504
        $valign = 'T';
505
        $fitcell = FALSE;
506

  
507
        // Run eval before.
508
        if (VIEWS_PDF_PHP) {
509
          if (!empty($options['render']['bypass_eval_before']) && !empty($options['render']['eval_before'])) {
510
            eval($options['render']['eval_before']);
511
          }
512
          elseif (!empty($options['render']['eval_before']))  {
513
            $content = php_eval($options['render']['eval_before']);
514
          }
515
        }
485 516

  
486
    $font_size = empty($options['text']['font_size']) ? $this->defaultFontSize : $options['text']['font_size'] ;
487
    $font_family = ($options['text']['font_family'] == 'default' || empty($options['text']['font_family'])) ? $this->defaultFontFamily : $options['text']['font_family'];
488
    $font_style = is_array($options['text']['font_style']) ? $options['text']['font_style'] : $this->defaultFontStyle;
489
    $textColor = !empty($options['text']['color']) ? $this->parseColor($options['text']['color']) : $this->parseColor($this->defaultFontColor);
490

  
491

  
492
    $w = $options['position']['width'];
493
    $h = $options['position']['height'];
494
    $border = 0;
495
    $align = isset($options['text']['align']) ? $options['text']['align'] : $this->defaultTextAlign;
496
    $fill = 0;
497
    $ln = 1;
498
    $reseth = TRUE;
499
    $stretch = 0;
500
    $ishtml = isset($options['render']['is_html']) ? $options['render']['is_html'] : 1;
501
    $stripHTML = !$ishtml;
502
    $autopadding = TRUE;
503
    $maxh = 0;
504
    $valign = 'T';
505
    $fitcell = FALSE;
506

  
507
    // Run eval before.
508
    if (!empty($options['render']['bypass_eval_before']) && !empty($options['render']['eval_before'])) {
509
      eval($options['render']['eval_before']);
510
    }
511
    elseif (!empty($options['render']['eval_before']))  {
512
      $content = php_eval($options['render']['eval_before']);
513
    }
517
        // Add css if there is a css file set and stripHTML is not active.
518
        if (!empty($css_file) && is_string($css_file) && !$stripHTML && $ishtml && !empty($content)) {
519
          $content = '<link type="text/css" rel="stylesheet" media="all" href="' . $css_file . '" />' . PHP_EOL . $content;
520
        }
514 521

  
515
    // Add css if there is a css file set and stripHTML is not active.
516
    if (!empty($css_file) && is_string($css_file) && !$stripHTML && $ishtml && !empty($content)) {
517
      $content = '<link type="text/css" rel="stylesheet" media="all" href="' . $css_file . '" />' . PHP_EOL . $content;
518
    }
522
        // Set Text Color.
523
        $this->SetTextColorArray($textColor);
519 524

  
520
    // Set Text Color.
521
    $this->SetTextColorArray($textColor);
525
        // Set font.
526
        $this->SetFont($font_family, implode('', $font_style), $font_size);
522 527

  
523
    // Set font.
524
    $this->SetFont($font_family, implode('', $font_style), $font_size);
528
        // Save the last page before starting writing, this
529
        // is needed to dected if we write over a page. Then we need
530
        // to reset the y coordinate for the 'last_writing' position option.
531
        $this->lastWritingPage = $this->getPage();
525 532

  
526
    // Save the last page before starting writing, this
527
    // is needed to dected if we write over a page. Then we need
528
    // to reset the y coordinate for the 'last_writing' position option.
529
    $this->lastWritingPage = $this->getPage();
533
        if ($stripHTML) {
534
          $content = strip_tags($content);
535
        }
530 536

  
531
    if ($stripHTML) {
532
      $content = strip_tags($content);
533
    }
537
        // Write the content of a field to the pdf file:
538
        if (!empty($content)) {
539
          $this->MultiCell($w, $h, $prefix . $content, $border, $align, $fill, $ln, $x, $y, $reseth, $stretch, $ishtml, $autopadding, $maxh, $valign, $fitcell);
540
        }
541
        else {
542
          $this->MultiCell($w, $h, $prefix, $border, $align, $fill, $ln, $x, $y, $reseth, $stretch, $ishtml, $autopadding, $maxh, $valign, $fitcell);
543
        }
534 544

  
535
    // Write the content of a field to the pdf file:
536
    if (!empty($content)) {
537
      $this->MultiCell($w, $h, $prefix . $content, $border, $align, $fill, $ln, $x, $y, $reseth, $stretch, $ishtml, $autopadding, $maxh, $valign, $fitcell);
538
    }
539
    else {
540
      $this->MultiCell($w, $h, $prefix, $border, $align, $fill, $ln, $x, $y, $reseth, $stretch, $ishtml, $autopadding, $maxh, $valign, $fitcell);
541
    }
545
        // Reset font to default.
546
        $this->SetFont($this->defaultFontFamily, implode('', $this->defaultFontStyle), $this->defaultFontSize);
542 547

  
543
    // Reset font to default.
544
    $this->SetFont($this->defaultFontFamily, implode('', $this->defaultFontStyle), $this->defaultFontSize);
548
        // Run eval after.
549
        if (VIEWS_PDF_PHP) {
550
          if (!empty($options['render']['bypass_eval_after']) && !empty($options['render']['eval_after'])) {
551
            eval($options['render']['eval_after']);
552
          }
553
          elseif (!empty($options['render']['eval_after'])) {
554
            $content = php_eval($options['render']['eval_after']);
555
          }
556
        }
545 557

  
546
    // Run eval after.
547
    if (!empty($options['render']['bypass_eval_after']) && !empty($options['render']['eval_after'])) {
548
      eval($options['render']['eval_after']);
549
    }
550
    elseif (!empty($options['render']['eval_after'])) {
551
      $content = php_eval($options['render']['eval_after']);
552
    }
558
        // Write Coordinates of element.
559
        $this->elements[$key] = array(
560
          'x' => $x,
561
          'y' => $y,
562
          'width' => empty($w) ? ($pageDim['wk'] - $this->rMargin-$x) : $w,
563
          'height' => $this->y - $y,
564
          'page' => $this->lastWritingPage,
565
        );
553 566

  
554
    // Write Coordinates of element.
555
    $this->elements[$key] = array(
556
      'x' => $x,
557
      'y' => $y,
558
      'width' => empty($w) ? ($pageDim['wk'] - $this->rMargin-$x) : $w,
559
      'height' => $this->y - $y,
560
      'page' => $this->lastWritingPage,
561
    );
567
        $this->lastWritingElement = $key;
568
      }
562 569

  
563
    $this->lastWritingElement = $key;
564 570
  }
565 571

  
566 572
  /**
......
773 779

  
774 780
      $rowY += $options['position']['row_height'];
775 781

  
782
      $view->row_index++;
776 783
    }
777 784

  
778 785
    $this->SetY($rowY + $options['position']['row_height']);

Formats disponibles : Unified diff