/** * 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; } }
/** * Validate that the provided value is a valid URL. * * @since 1.0 */ public function testIsURL() { $this->assertTrue(Validator::isURL('http://www.alphaframework.org')); $this->assertTrue(Validator::isURL('http://www.alphaframework.org/controller/View.php?some=value')); $this->assertTrue(Validator::isURL('http://alphaframework.org/')); $this->assertTrue(Validator::isURL('https://www.alphaframework.org')); $this->assertTrue(Validator::isURL('https://www.alphaframework.org/controller/View.php?some=value')); $this->assertTrue(Validator::isURL('https://alphaframework.org/')); $this->assertFalse(Validator::isURL('http://alpha framework.org/')); $this->assertFalse(Validator::isURL('http//www.alphaframework.org')); $this->assertFalse(Validator::isURL('http:/www.alphaframework.org')); }
/** * Builds a redirect response. * * @param string $URL The URL to redirect the client to. * * @throws Alpha\Exception\IllegalArguementException * * @since 2.0 */ public function redirect($URL) { if (Validator::isURL($URL)) { $this->headers = array(); $this->setHeader('Location', $URL); } else { throw new IllegalArguementException('Unable to redirect to URL [' . $URL . '] as it is invalid'); } }
/** * Sets the name of the controller job sequence to the values in the supplied * array (and stores the array in the session). * * @param array $jobs The names of the controllers in this unit of work sequence. Will accept fully-qualified controller class name, or an absolute URL. * * @throws Alpha\Exception\IllegalArguementException * * @since 1.0 */ public function setUnitOfWork($jobs) { self::$logger->debug('>>setUnitOfWork(jobs=[' . var_export($jobs, true) . '])'); if (method_exists($this, 'before_setUnitOfWork_callback')) { $this->before_setUnitOfWork_callback(); } if (!is_array($jobs)) { throw new IllegalArguementException('Bad $jobs array [' . var_export($jobs, true) . '] passed to setUnitOfWork method!'); self::$logger->debug('<<setUnitOfWork'); return; } // validate that each controller name in the array actually exists foreach ($jobs as $job) { if (!Validator::isURL($job) && !class_exists($job)) { throw new IllegalArguementException('The controller name [' . $job . '] provided in the jobs array is not defined anywhere!'); } } // clear out any previous unit of work from the session $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); $session = SessionProviderFactory::getInstance($sessionProvider); $session->delete('unitOfWork'); $this->firstJob = null; $this->previousJob = null; $this->nextJob = null; $this->lastJob = null; $this->dirtyObjects = array(); $this->newObjects = array(); $numOfJobs = count($jobs); for ($i = 0; $i < $numOfJobs; ++$i) { // the first job in the sequence if ($i == 0) { $this->firstJob = $jobs[$i]; self::$logger->debug('First job [' . $this->firstJob . ']'); } // found the current job if ($this->name == $jobs[$i]) { if (isset($jobs[$i - 1])) { // set the previous job if it exists $this->previousJob = $jobs[$i - 1]; self::$logger->debug('Previous job [' . $this->previousJob . ']'); } if (isset($jobs[$i + 1])) { // set the next job if it exists $this->nextJob = $jobs[$i + 1]; self::$logger->debug('Next job [' . $this->nextJob . ']'); } } // the last job in the sequence if ($i == $numOfJobs - 1) { $this->lastJob = $jobs[$i]; } } if ($this->previousJob == null) { $this->previousJob = $this->firstJob; } if ($this->nextJob == null) { $this->nextJob = $this->lastJob; } $session->set('unitOfWork', $jobs); if (method_exists($this, 'after_setUnitOfWork_callback')) { $this->after_setUnitOfWork_callback(); } self::$logger->debug('<<setUnitOfWork'); }