class_ImageResponse.php
Go to the documentation of this file.00001 <?php
00027 class ImageResponse extends BaseResponse implements Responseable {
00031 private $imageInstance = null;
00032
00038 protected function __construct () {
00039
00040 parent::__construct(__CLASS__);
00041 }
00042
00049 public final static function createImageResponse (ManageableApplication $appInstance) {
00050
00051 $responseInstance = new ImageResponse();
00052
00053
00054 $responseInstance->setApplicationInstance($appInstance);
00055
00056
00057 $responseInstance->initTemplateEngine($appInstance);
00058
00059
00060 return $responseInstance;
00061 }
00062
00069 public final function initTemplateEngine (ManageableApplication $appInstance) {
00070
00071 $cfg = $this->getConfigInstance();
00072
00073
00074 $cfg->setConfigEntry('template_class' , $cfg->readConfig('image_template_class'));
00075 $cfg->setConfigEntry('raw_template_extension' , ".img");
00076 $cfg->setConfigEntry('code_template_extension', ".itp");
00077 $cfg->setConfigEntry('tpl_base_path' , "templates/images/");
00078 $cfg->setConfigEntry('code_template_type' , "image");
00079
00080
00081 $this->setTemplateInstance($this->prepareTemplateInstance($appInstance));
00082 }
00083
00098 public function addCookie ($cookieName, $cookieValue, $encrypted = false, $expires = null) {
00099
00100 if (headers_sent()) {
00101
00102 throw new ResponseHeadersAlreadySentException($this, self::EXCEPTION_HEADERS_ALREADY_SENT);
00103 }
00104
00105
00106 if ($encrypted === true) {
00107 }
00108
00109
00110 $_COOKIE[$cookieName] = $cookieValue;
00111
00112
00113 if (is_null($expires)) {
00114 $expires = (time() + $this->getConfigInstance()->readConfig('cookie_expire'));
00115 }
00116
00117 $path = $this->getConfigInstance()->readConfig('cookie_path');
00118 $domain = $this->getConfigInstance()->readConfig('cookie_domain');
00119
00120 setcookie($cookieName, $cookieValue, $expires);
00121
00122 return;
00123
00124
00125 $cookieString = $cookieName . "=" . $cookieValue . "; ";
00126 $cookieString .= "expires=" . date("D, d-F-Y H:i:s", $expires) . " GMT";
00127
00128
00129
00130 $this->cookies[$cookieName] = $cookieString;
00131 }
00132
00141 public function redirectToConfiguredUrl ($configEntry) {
00142
00143 if (headers_sent()) {
00144
00145 throw new ResponseHeadersAlreadySentException($this, self::EXCEPTION_HEADERS_ALREADY_SENT);
00146 }
00147
00148
00149 $this->getTemplateInstance()->assignApplicationData($this->getApplicationInstance());
00150
00151
00152 $url = $this->getConfigInstance()->readConfig($configEntry);
00153
00154
00155 $url = $this->getTemplateInstance()->compileRawCode($url);
00156
00157
00158 if (substr(strtolower($url), 0, 4) != "http") {
00159
00160 if (substr($url, 0, 1) == "/") $url = substr($url, 1);
00161
00162
00163 $url = $this->getConfigInstance()->readConfig('base_url') . "/" . $url;
00164 }
00165
00166
00167 $this->addHeader("Location", $url);
00168
00169
00170 $this->setResponseStatus("301 Moved Permanently");
00171
00172
00173 $this->setResponseBody("");
00174
00175
00176 $this->flushBuffer();
00177
00178
00179 exit();
00180 }
00181
00189 public function flushBuffer ($force = false) {
00190
00191 $this->getImageInstance()->finishImage();
00192
00193
00194 $content = $this->getImageInstance()->getContent();
00195
00196
00197 $this->setResponseBody($content);
00198
00199
00200 $this->addHeader('Content-type', "image/".$this->getImageInstance()->getImageType());
00201
00202
00203 parent::flushBuffer($force);
00204 }
00205
00212 public function expireCookie ($cookieName) {
00213
00214 if (isset($_COOKIE[$cookieName])) {
00215
00216 $this->addCookie($cookieName, "", false, (time() - 1200));
00217
00218
00219 unset($_COOKIE[$cookieName]);
00220 }
00221 }
00222
00229 public function refreshCookie ($cookieName) {
00230
00231 if (isset($_COOKIE[$cookieName])) {
00232
00233 $this->addCookie($cookieName, $_COOKIE[$cookieName], false);
00234 }
00235 }
00236
00243 public final function setImageInstance (BaseImage $imageInstance) {
00244 $this->imageInstance = $imageInstance;
00245 }
00246
00252 public final function getImageInstance () {
00253 return $this->imageInstance;
00254 }
00255
00261 public function getDefaultCommand () {
00262 $defaultCommand = $this->getConfigInstance()->readConfig('default_image_command');
00263 return $defaultCommand;
00264 }
00265 }
00266
00267
00268 ?>