Example #1
0
 /**
  * Overrides the TCPDF::Image method to decrypt encrypted $file paths from the Image widget, then pass
  * them to the normal TCPDF::Image along with all of the other (unmodified) parameters.
  *
  * @param string $file    Name of the file containing the image.
  * @param float  $x       Abscissa of the upper-left corner.
  * @param float  $y       Ordinate of the upper-left corner.
  * @param float  $w       Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
  * @param float  $h       Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
  * @param string $type    Image format. Possible values are (case insensitive): JPEG and PNG (whitout GD library) and all images supported by GD: GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM;. If not specified, the type is inferred from the file extension.
  * @param mixed  $link    URL or identifier returned by AddLink().
  * @param string $align   Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:<ul><li>T: top-right for LTR or top-left for RTL</li><li>M: middle-right for LTR or middle-left for RTL</li><li>B: bottom-right for LTR or bottom-left for RTL</li><li>N: next line</li></ul>
  * @param bool   $resize  If true resize (reduce) the image to fit $w and $h (requires GD library).
  * @param int    $dpi     dot-per-inch resolution used on resize
  * @param string $palign  Allows to center or align the image on the current line. Possible values are:<ul><li>L : left align</li><li>C : center</li><li>R : right align</li><li>'' : empty string : left for LTR or right for RTL</li></ul>
  * @param bool   $ismask  true if this image is a mask, false otherwise
  * @param mixed  $imgmask image object returned by this function or false
  * @param mixed  $border  Indicates if borders must be drawn around the image. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
  *
  * @since 1.0
  */
 public function Image($file, $x = '', $y = '', $w = 0, $h = 0, $type = '', $link = '', $align = '', $resize = false, $dpi = 300, $palign = '', $ismask = false, $imgmask = false, $border = 0)
 {
     if (self::$logger == null) {
         self::$logger = new Logger('TCPDF');
     }
     $config = ConfigProvider::getInstance();
     self::$logger->debug('Processing image file URL [' . $file . ']');
     try {
         if (mb_strpos($file, '/tk/') !== false) {
             $start = mb_strpos($file, '/tk/') + 3;
             $end = mb_strlen($file);
             $tk = mb_substr($file, $start + 1, $end - ($start + 1));
             $decoded = FrontController::getDecodeQueryParams($tk);
             parent::Image($decoded['source'], $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, $ismask, $imgmask, $border);
         } else {
             // it has no query string, so threat as a regular image URL
             if (Validator::isURL($file)) {
                 parent::Image($config->get('app.root') . '/' . Image::convertImageURLToPath($file), $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, $ismask, $imgmask, $border);
             } else {
                 parent::Image($file, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, $ismask, $imgmask, $border);
             }
         }
     } catch (\Exception $e) {
         self::$logger->error('Error processing image file URL [' . $file . '], error [' . $e->getMessage() . ']');
         throw $e;
     }
 }
Example #2
0
 /**
  * Testing that the getDecodeQueryParams method will return the known params with a known encrypted result for a test key.
  *
  * @since 1.0
  */
 public function testGetDecodeQueryParams()
 {
     $config = ConfigProvider::getInstance();
     $oldKey = $config->get('security.encryption.key');
     $config->set('security.encryption.key', 'testkey12345678901234567');
     $tk = '7eYCDOP1AFAv2Kc45D2eSgFM1dJ2mboM4fMMMjs3PP6cb8Qafsv0L06zZjWeIWRH';
     $decoded = FrontController::getDecodeQueryParams($tk);
     $this->assertEquals('ViewArticleTitle', $decoded['act'], 'testing that the getDecodeQueryParams method will return the known params with a known encrypted result for a test key');
     $this->assertEquals('Test_Title', $decoded['title'], 'testing that the getDecodeQueryParams method will return the known params with a known encrypted result for a test key');
     $config->set('security.encryption.key', $oldKey);
 }