Ejemplo n.º 1
0
 public static function getMediaOutput($id, $type, $className)
 {
     if ($type == 'list') {
         $component = Kwf_Component_Data_Root::getInstance()->getComponentById($id);
         if ($component) {
             $galleryComponent = $component->parent;
             $components = $galleryComponent->getChildComponents(array('generator' => 'child'));
             $paths = array();
             foreach ($components as $component) {
                 $data = $component->getComponent()->getImageData();
                 if ($data['file']) {
                     $paths[$data['file']] = $data['filename'];
                 }
             }
         }
         if (!$paths) {
             throw new Kwf_Exception_NotFound();
         }
         Kwf_Util_TempCleaner::clean();
         $tmpname = "temp/" . uniqid() . ".zip";
         $zip = new ZipArchive();
         if ($zip->open($tmpname, ZIPARCHIVE::CREATE) !== TRUE) {
             throw new Kwf_Exception('Could not open file for writing: ' . $filename);
         }
         foreach ($paths as $path => $filename) {
             $zip->addFile($path, $filename);
         }
         $zip->close();
         $file = array('file' => $tmpname, 'mimeType' => 'application/zip', 'downloadFilename' => $galleryComponent->getPage()->name . '.zip');
         Kwf_Media_Output::output($file);
         exit;
     }
 }
Ejemplo n.º 2
0
 /**
  *
  * @param string Url as generated by Kwf_Assets_Package::getPackageUrls
  * @param string Kwf_Media_Output::ENCODING_*
  */
 public static function getOutputForUrl($url, $encoding)
 {
     if (substr($url, 0, 21) != '/assets/dependencies/') {
         throw new Kwf_Exception("invalid url: '{$url}'");
     }
     $url = substr($url, 21);
     if (strpos($url, '?') !== false) {
         $url = substr($url, 0, strpos($url, '?'));
     }
     if (substr($url, -4) == '.map' && !self::allowSourceAccess()) {
         throw new Kwf_Exception_AccessDenied();
     }
     if ($encoding != 'none') {
         //own cache for encoded contents, not using Kwf_Assets_Cache as we don't need to in two-level cache
         $cacheId = 'as_' . self::_getCacheIdByUrl($url) . '_' . $encoding;
         $ret = Kwf_Cache_SimpleStatic::fetch($cacheId);
         if ($ret === false) {
             $ret = self::_getOutputForUrlNoEncoding($url);
             $ret['contents'] = Kwf_Media_Output::encode($ret['contents'], $encoding);
             $ret['encoding'] = $encoding;
             Kwf_Cache_SimpleStatic::add($cacheId, $ret);
         }
         return $ret;
     } else {
         return self::_getOutputForUrlNoEncoding($url);
     }
 }
Ejemplo n.º 3
0
 public static function output()
 {
     $baseUrl = Kwf_Setup::getBaseUrl();
     $contents = "User-agent: *\n" . "Disallow: {$baseUrl}/admin/\n";
     $contents .= "Sitemap: http" . (isset($_SERVER['HTTPS']) ? 's' : '') . "://" . $_SERVER['HTTP_HOST'] . $baseUrl . "/sitemap.xml\n";
     Kwf_Media_Output::output(array('contents' => $contents, 'mimeType' => 'text/plain'));
 }
 public function indexAction()
 {
     $pdf = new Kwf_Pdf_TcPdf();
     $pdf->addPage();
     $pdf->Ln(5);
     $pdf->SetFont('helvetica', '', 10);
     $pdf->textBox("helvetica");
     $pdf->Ln(5);
     $pdf->SetFont('comic', '', 10);
     $pdf->textBox("comic");
     $pdf->Ln(5);
     $pdf->SetFont('helvetican', '', 10);
     $pdf->textBox("helveticanb", 'B');
     $pdf->Ln(5);
     $pdf->SetFont('helvetican', '', 10);
     $pdf->textBox("helvetican");
     $pdf->Ln(5);
     $pdf->SetFont('arial', '', 10);
     $pdf->textBox("arial", '');
     $pdf->Ln(5);
     $pdf->SetFont('arial', '', 10);
     $pdf->textBox("arialb", 'B');
     $data = array();
     $data['contents'] = $pdf->Output("text.php", "S");
     $data['mimeType'] = "application/pdf";
     Kwf_Media_Output::output($data);
     exit;
 }
Ejemplo n.º 5
0
 public function jsonIndexAction()
 {
     if ($this->_getParam('subrootComponentId')) {
         $cacheId = 'kwcMenuMobile-root-' . $this->_getParam('subrootComponentId') . '-' . $this->_getParam('class');
     } else {
         if ($this->_getParam('pageId')) {
             $cacheId = 'kwcMenuMobile-' . $this->_getParam('pageId');
         }
     }
     $data = Kwf_Cache_Simple::fetch($cacheId);
     if ($data === false) {
         if ($this->_getParam('subrootComponentId')) {
             $pages = $this->_getChildPages();
         } else {
             if ($this->_getParam('pageId')) {
                 $component = Kwf_Component_Data_Root::getInstance()->getComponentById($this->_getParam('pageId'));
                 $pages = $this->_getChildPagesRecursive(array($component), 2);
                 foreach ($pages as $k => $p) {
                     unset($pages[$k]['name']);
                     unset($pages[$k]['url']);
                 }
             }
         }
         $data = array('lifetime' => 60 * 60, 'mimeType' => 'application/json', 'mtime' => time(), 'contents' => json_encode(array('pages' => $pages)));
         Kwf_Cache_Simple::add($cacheId, $data);
     }
     Kwf_Media_Output::output($data);
 }
Ejemplo n.º 6
0
 public static function output()
 {
     $baseUrl = Kwf_Setup::getBaseUrl();
     $contents = "User-agent: *\n" . "Disallow: {$baseUrl}/admin/\n" . "Disallow: {$baseUrl}/kwf/util/kwc/render\n";
     //used to load eg. lightbox content async, we don't want getting that indexed
     $contents .= "Sitemap: http" . (isset($_SERVER['HTTPS']) ? 's' : '') . "://" . $_SERVER['HTTP_HOST'] . $baseUrl . "/sitemap.xml\n";
     Kwf_Media_Output::output(array('contents' => $contents, 'mimeType' => 'text/plain'));
 }
 public function indexAction()
 {
     Zend_Registry::set('db', false);
     Kwf_Test_SeparateDb::setDbFromCookie();
     // setzt es nur wenn es das cookie wirklich gibt
     //FnF models setzen damit tests nicht in echte tabellen schreiben
     Kwf_Component_Cache::setInstance(Kwf_Component_Cache::CACHE_BACKEND_FNF);
     Kwf_Component_Cache_Memory::setInstance(new Kwf_Component_Cache_MemoryBlackHole());
     /*
     if (class_exists('APCIterator')) {
         $prefix = Kwf_Cache::getUniquePrefix();
         apc_delete_file(new APCIterator('user', '#^'.$prefix.'#'));
     } else {
         apc_clear_cache('user');
     }
     */
     Kwf_Component_Data_Root::setComponentClass($this->_getParam('root'));
     Zend_Registry::set('testRootComponentClass', $this->_getParam('root'));
     $root = Kwf_Component_Data_Root::getInstance();
     $root->setFilename('kwf/kwctest/' . $this->_getParam('root'));
     $url = $this->_getParam('url');
     $urlParts = explode('/', $url);
     if (is_array($urlParts) && $urlParts[0] == 'media') {
         if (sizeof($urlParts) != 7) {
             throw new Kwf_Exception_NotFound();
         }
         $class = $urlParts[1];
         $id = $urlParts[2];
         $type = $urlParts[3];
         $checksum = $urlParts[4];
         // time() wäre der 5er, wird aber nur wegen browsercache benötigt
         $filename = $urlParts[6];
         if ($checksum != Kwf_Media::getChecksum($class, $id, $type, $filename)) {
             throw new Kwf_Exception_AccessDenied('Access to file not allowed.');
         }
         Kwf_Media_Output::output(Kwf_Media::getOutput($class, $id, $type));
     }
     if ($url == 'kwf/util/kwc/render') {
         if (isset($_REQUEST['url'])) {
             $_REQUEST['url'] = str_replace('/' . $root->filename, '', $_REQUEST['url']);
         }
         Kwf_Util_Component::dispatchRender();
     }
     $domain = 'http://' . Zend_Registry::get('config')->server->domain;
     $data = $root->getPageByUrl($domain . Kwf_Setup::getBaseUrl() . '/' . $url, null);
     if (!$data) {
         throw new Kwf_Exception_NotFound();
     }
     $root->setCurrentPage($data);
     $contentSender = Kwc_Abstract::getSetting($data->componentClass, 'contentSender');
     $contentSender = new $contentSender($data);
     $contentSender->sendContent(true);
     Kwf_Benchmark::shutDown();
     Kwf_Benchmark::output();
     exit;
 }
Ejemplo n.º 8
0
 public static function load($url)
 {
     try {
         $l = new self();
         $out = $l->getFileContents(substr($url, 8));
         Kwf_Media_Output::output($out);
     } catch (Kwf_Assets_NotFoundException $e) {
         throw new Kwf_Exception_NotFound();
     }
 }
 public function downloadAction()
 {
     $key = $this->_getParam('key');
     if (!preg_match('#^[a-z0-9]+$#', $key)) {
         throw new Kwf_Exception_NotFound();
     }
     if (!file_exists('temp/postback-' . $key . '-meta')) {
         throw new Kwf_Exception_NotFound();
     }
     $data = unserialize(file_get_contents('temp/postback-' . $key . '-meta'));
     Kwf_Media_Output::output($data);
 }
Ejemplo n.º 10
0
 public function downloadXlsFileAction()
 {
     if (!isset($this->_permissions['xls']) || !$this->_permissions['xls']) {
         throw new Kwf_Exception("XLS is not allowed.");
     }
     if (!file_exists('temp/' . $this->_getParam('downloadkey') . '.xls')) {
         throw new Kwf_Exception('Wrong downloadkey submitted');
     }
     Kwf_Util_TempCleaner::clean();
     $file = array('contents' => file_get_contents('temp/' . $this->_getParam('downloadkey') . '.xls'), 'mimeType' => 'application/octet-stream', 'downloadFilename' => 'form_' . date('Ymd-Hi') . '.xls');
     Kwf_Media_Output::output($file);
     $this->_helper->viewRenderer->setNoRender();
 }
Ejemplo n.º 11
0
 public static function load($url)
 {
     if (strpos($url, '?') !== false) {
         $url = substr($url, 0, strpos($url, '?'));
     }
     Kwf_Assets_Dispatcher::dispatch($url);
     try {
         $l = new self();
         $out = $l->getFileContents(substr($url, 8));
         Kwf_Media_Output::output($out);
     } catch (Kwf_Assets_NotFoundException $e) {
         throw new Kwf_Exception_NotFound();
     }
 }
Ejemplo n.º 12
0
 public function jsonIndexAction()
 {
     if ($this->_getParam('subrootComponentId')) {
         $cacheId = 'kwcMenuMobile-root-' . $this->_getParam('subrootComponentId') . '-' . $this->_getParam('class');
     } else {
         if ($this->_getParam('pageId')) {
             $cacheId = 'kwcMenuMobile-' . $this->_getParam('pageId');
         }
     }
     foreach (Kwf_Component_Data_Root::getInstance()->getPlugins('Kwf_Component_PluginRoot_Interface_PreDispatch') as $plugin) {
         $plugin->preDispatch($this->_getParam('pageUrl'));
     }
     $data = Kwf_Cache_Simple::fetch($cacheId);
     if ($data === false) {
         if ($this->_getParam('subrootComponentId')) {
             $pages = $this->_getChildPages();
         } else {
             if ($this->_getParam('pageId')) {
                 $component = Kwf_Component_Data_Root::getInstance()->getComponentById($this->_getParam('pageId'));
                 $pages = $this->_getChildPagesRecursive(array($component), 2);
                 foreach ($pages as $k => $p) {
                     unset($pages[$k]['name']);
                     unset($pages[$k]['url']);
                 }
             }
         }
         $data = array('lifetime' => 60 * 60, 'mimeType' => 'application/json', 'mtime' => time(), 'contents' => json_encode(array('pages' => $pages)));
         Kwf_Cache_Simple::add($cacheId, $data);
     }
     $skipProcessPages = true;
     foreach (Kwf_Component_Data_Root::getInstance()->getPlugins('Kwf_Component_PluginRoot_Interface_MaskComponent') as $plugin) {
         if (!$plugin->canIgnoreMasks()) {
             $skipProcessPages = false;
         }
     }
     foreach (Kwf_Component_Data_Root::getInstance()->getPlugins('Kwf_Component_PluginRoot_Interface_PostRender') as $plugin) {
         if (!$plugin->canIgnoreProcessUrl()) {
             $skipProcessPages = false;
         }
     }
     if (!$skipProcessPages) {
         $contents = json_decode($data['contents'], true);
         $contents['pages'] = $this->_processPages($contents['pages']);
         $data['contents'] = json_encode($contents);
     }
     Kwf_Media_Output::output($data);
 }
Ejemplo n.º 13
0
 public function testPartialOutput()
 {
     $file = array('contents' => 'output', 'mimeType' => 'text/plain');
     $headers = array('Range' => 'bytes=0-2');
     $output = Kwf_Media_Output::getOutputData($file, $headers);
     //check the right response conde
     $this->_assertRepsonseCode($output, 206, 206);
     //contents nur 3 bytes (out)
     $this->assertEquals($output['contents'], 'out');
     //check the Accept-Ranges header
     $this->_assertHeader($output, 'Accept-Ranges', 'bytes');
     //content length (was geschickt wird)
     $this->_assertHeader($output, 'Content-Length', '3');
     //header, Content Range (0-2/6)
     $this->_assertHeader($output, 'Content-Range', 'bytes 0-2/6');
     //TODO out of range -> reponse 416
     //TODO last modified
     //file
     $filePath = tempnam('/temp', 'outputtest_');
     file_put_contents($filePath, 'output');
     $file = array('file' => $filePath, 'mimeType' => 'text/plain');
     $headers = array('Range' => 'bytes=0-2');
     $output = Kwf_Media_Output::getOutputData($file, $headers);
     //check the right response conde
     $this->_assertRepsonseCode($output, 206, 206);
     //contents nur 3 bytes (out)
     $this->assertEquals($output['contents'], 'out');
     //check the Accept-Ranges header
     $this->_assertHeader($output, 'Accept-Ranges', 'bytes');
     //content length (was geschickt wird)
     $this->_assertHeader($output, 'Content-Length', '3');
     //header, Content Range (0-2/6)
     $this->_assertHeader($output, 'Content-Range', 'bytes 0-2/6');
     //middle range
     $filePath = tempnam('/temp', 'outputtest_');
     file_put_contents($filePath, 'outputoutputoutputoutputoutputoutput');
     $file = array('file' => $filePath, 'mimeType' => 'text/plain');
     $headers = array('Range' => 'bytes=14-23');
     $output = Kwf_Media_Output::getOutputData($file, $headers);
     //check the right response conde
     $this->_assertRepsonseCode($output, 206, 206);
     //contents nur 3 bytes (out)
     $this->assertEquals($output['contents'], 'tputoutput');
     //check the Accept-Ranges header
     $this->_assertHeader($output, 'Accept-Ranges', 'bytes');
     //content length (was geschickt wird)
     $this->_assertHeader($output, 'Content-Length', '10');
     //header, Content Range (0-2/6)
     $this->_assertHeader($output, 'Content-Range', 'bytes 14-23/36');
     unlink($filePath);
     //TODO Content-Encoding
 }
Ejemplo n.º 14
0
 public static function dispatchMedia()
 {
     $requestPath = self::getRequestPath();
     if ($requestPath === false) {
         return;
     }
     $baseUrl = Kwf_Setup::getBaseUrl();
     if ($baseUrl) {
         if (substr($requestPath, 0, strlen($baseUrl)) != $baseUrl) {
             throw new Kwf_Exception_NotFound();
         }
         $requestPath = substr($requestPath, strlen($baseUrl));
     }
     $urlParts = explode('/', substr($requestPath, 1));
     if (is_array($urlParts) && $urlParts[0] == 'media') {
         if (sizeof($urlParts) != 7) {
             throw new Kwf_Exception_NotFound();
         }
         $class = $urlParts[1];
         $id = $urlParts[2];
         $type = $urlParts[3];
         $checksum = urlencode($urlParts[4]);
         // time() wäre der 5er, wird aber nur wegen browsercache benötigt
         $filename = $urlParts[6];
         if ($checksum != Kwf_Media::getChecksum($class, $id, $type, $filename)) {
             throw new Kwf_Exception_NotFound();
         }
         $class = rawurldecode($class);
         Kwf_Media_Output::output(Kwf_Media::getOutput($class, $id, $type));
     }
 }
Ejemplo n.º 15
0
 public function downloadXlsFileByKey($downloadkey)
 {
     if (!file_exists('temp/' . $downloadkey . '.xls')) {
         throw new Kwf_Exception('Wrong downloadkey submitted');
     }
     Kwf_Util_TempCleaner::clean();
     $file = array('contents' => file_get_contents('temp/' . $downloadkey . '.xls'), 'mimeType' => 'application/octet-stream', 'downloadFilename' => 'form_' . date('Ymd-Hi') . '.xls');
     Kwf_Media_Output::output($file);
     $this->_helper->viewRenderer->setNoRender();
 }
 public function downloadHandyAction()
 {
     $fileRow = Kwf_Model_Abstract::getInstance('Kwf_Uploads_Model')->getRow($this->_getParam('uploadId'));
     if (!$fileRow) {
         throw new Kwf_Exception("Can't find upload");
     }
     if ($fileRow->getHashKey() != $this->_getParam('hashKey')) {
         throw new Kwf_Exception_AccessDenied();
     }
     $scaleFactor = Kwf_Media_Image::getHandyScaleFactor($fileRow->getFileSource());
     $outputParams = array('mimeType' => $fileRow->mime_type, 'downloadFilename' => $fileRow->filename . '.' . $fileRow->extension);
     $targetSize = array(600, 600, 'cover' => false);
     $image = Kwf_Media_Image::scale($fileRow->getFileSource(), $targetSize, $fileRow->id);
     $outputParams['contents'] = $image;
     Kwf_Media_Output::output($outputParams);
 }
 public function previewWithCropAction()
 {
     $previewWidth = 390;
     $previewHeight = 184;
     $fileRow = Kwf_Model_Abstract::getInstance('Kwf_Uploads_Model')->getRow($this->_getParam('uploadId'));
     if (!$fileRow) {
         throw new Kwf_Exception("Can't find upload");
     }
     if ($fileRow->getHashKey() != $this->_getParam('hashKey')) {
         throw new Kwf_Exception_AccessDenied();
     }
     //Scale dimensions
     $dimensions = array($previewWidth, $previewHeight, 'cover' => false);
     $cache = Kwf_Assets_Cache::getInstance();
     $cacheId = 'previewLarge_' . $fileRow->id;
     if (!($output = $cache->load($cacheId))) {
         $output = array();
         $output['contents'] = Kwf_Media_Image::scale($fileRow->getFileSource(), $dimensions, $fileRow->id);
         $output['mimeType'] = $fileRow->mime_type;
         $cache->save($output, $cacheId);
     }
     $imageOriginal = new Imagick($fileRow->getFileSource());
     if ($this->_getParam('cropX') == null || $this->_getParam('cropY') == null || $this->_getParam('cropWidth') == null || $this->_getParam('cropHeight') == null) {
         //calculate default selection
         $dimension = $this->_getParam('dimension');
         if (!$dimension) {
             Kwf_Media_Output::output($output);
         }
         $dimensions = Kwc_Abstract::getSetting($this->_getParam('class'), 'dimensions');
         $dimension = $dimensions[$dimension];
         if (!isset($dimension['width'])) {
             $dimension['width'] = 0;
         }
         if (!isset($dimension['height'])) {
             $dimension['height'] = 0;
         }
         if (!isset($dimension['cover'])) {
             $dimension['cover'] = false;
         }
         if ($dimension['width'] == Kwc_Abstract_Image_Component::USER_SELECT) {
             $dimension['width'] = $this->_getParam('width');
         }
         if ($dimension['height'] == Kwc_Abstract_Image_Component::USER_SELECT) {
             $dimension['height'] = $this->_getParam('height');
         }
         if (!$dimension['cover']) {
             Kwf_Media_Output::output($output);
         }
         if ($dimension['width'] == Kwc_Abstract_Image_Component::CONTENT_WIDTH) {
             Kwf_Media_Output::output($output);
         }
         if ($dimension['height'] == 0 || $dimension['width'] == 0) {
             Kwf_Media_Output::output($output);
         }
         $cropX = 0;
         $cropY = 0;
         $cropHeight = $imageOriginal->getImageHeight();
         $cropWidth = $imageOriginal->getImageWidth();
         if ($imageOriginal->getImageHeight() / $dimension['height'] > $imageOriginal->getImageWidth() / $dimension['width']) {
             // orientate on width
             $cropHeight = $dimension['height'] * $imageOriginal->getImageWidth() / $dimension['width'];
             $cropY = ($imageOriginal->getImageHeight() - $cropHeight) / 2;
         } else {
             // orientate on height
             $cropWidth = $dimension['width'] * $imageOriginal->getImageHeight() / $dimension['height'];
             $cropX = ($imageOriginal->getImageWidth() - $cropWidth) / 2;
         }
     } else {
         //Calculate values relative to original image size
         $factor = Kwf_Media_Image::getHandyScaleFactor($fileRow->getFileSource());
         $cropX = $this->_getParam('cropX') * $factor;
         $cropY = $this->_getParam('cropY') * $factor;
         $cropWidth = $this->_getParam('cropWidth') * $factor;
         $cropHeight = $this->_getParam('cropHeight') * $factor;
     }
     // Calculate values relative to preview image
     $image = new Imagick();
     $image->readImageBlob($output['contents']);
     $previewFactor = 1;
     if ($image->getImageWidth() == $previewWidth) {
         $previewFactor = $image->getImageWidth() / $imageOriginal->getImageWidth();
     } else {
         if ($image->getImageHeight() == $previewHeight) {
             $previewFactor = $image->getImageHeight() / $imageOriginal->getImageHeight();
         }
     }
     $cropX = floor($cropX * $previewFactor);
     $cropY = floor($cropY * $previewFactor);
     $cropWidth = floor($cropWidth * $previewFactor);
     $cropHeight = floor($cropHeight * $previewFactor);
     $draw = new ImagickDraw();
     if ($this->_isLightImage($output)) {
         $draw->setFillColor('black');
     } else {
         $draw->setFillColor('white');
     }
     $draw->setFillOpacity(0.3);
     // if cropX == 0 or cropY == 0 no rectangle should be drawn, because it
     // can't be 0 wide on topmost and leftmost position so it will result in
     // a 1px line which is wrong
     //Top region
     if ($cropY > 0) {
         $draw->rectangle(0, 0, $image->getImageWidth(), $cropY);
     }
     //Left region
     if ($cropX > 0) {
         if ($cropY > 0) {
             $draw->rectangle(0, $cropY + 1, $cropX, $cropY + $cropHeight - 1);
         } else {
             $draw->rectangle(0, $cropY, $cropX, $cropY + $cropHeight - 1);
         }
     }
     //Right region
     if ($cropY > 0) {
         $draw->rectangle($cropX + $cropWidth, $cropY + 1, $image->getImageWidth(), $cropY + $cropHeight - 1);
     } else {
         $draw->rectangle($cropX + $cropWidth, $cropY, $image->getImageWidth(), $cropY + $cropHeight - 1);
     }
     //Bottom region
     $draw->rectangle(0, $cropY + $cropHeight, $image->getImageWidth(), $image->getImageHeight());
     $image->drawImage($draw);
     $output['contents'] = $image->getImageBlob();
     Kwf_Media_Output::output($output);
 }
Ejemplo n.º 18
0
 public function downloadExportFileAction()
 {
     if (!isset($this->_permissions['xls']) || !$this->_permissions['xls']) {
         throw new Kwf_Exception("XLS is not allowed.");
     }
     if (class_exists('XMLWriter')) {
         $suffix = 'xlsx';
         $mimeType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
     } else {
         $suffix = 'xls';
         $mimeType = 'application/msexcel';
     }
     if (!file_exists('temp/' . $this->_getParam('downloadkey') . '.' . $suffix)) {
         throw new Kwf_Exception('Wrong downloadkey submitted');
     }
     Kwf_Util_TempCleaner::clean();
     $file = array('contents' => file_get_contents('temp/' . $this->_getParam('downloadkey') . '.' . $suffix), 'mimeType' => $mimeType, 'downloadFilename' => 'export_' . date('Ymd-Hi') . '.' . $suffix);
     Kwf_Media_Output::output($file);
     $this->_helper->viewRenderer->setNoRender();
 }
Ejemplo n.º 19
0
 public function output($start, $end = null)
 {
     Kwf_Media_Output::output(array('contents' => $this->getContents($start, $end), 'mimeType' => 'image/png'));
 }
Ejemplo n.º 20
0
 public function sendContent($includeMaster)
 {
     $content = $this->getContent($includeMaster);
     $content['contents'] = $content['content'];
     unset($content['content']);
     if (!isset($content['lifetime'])) {
         $content['lifetime'] = false;
     }
     if (Kwf_Benchmark::isEnabled()) {
         ob_start();
         Kwf_Benchmark::output();
         $content['contents'] .= ob_get_contents();
         ob_end_clean();
     }
     Kwf_Media_Output::outputWithoutShutdown($content);
     exit;
 }
Ejemplo n.º 21
0
 public static function dispatchRender()
 {
     if ((!isset($_REQUEST['url']) || !$_REQUEST["url"]) && (!isset($_REQUEST['componentId']) || !$_REQUEST['componentId']) && (!isset($_REQUEST['dbId']) || !$_REQUEST['dbId'])) {
         throw new Kwf_Exception_NotFound();
     }
     if (isset($_REQUEST['pageUrl'])) {
         foreach (Kwf_Component_Data_Root::getInstance()->getPlugins('Kwf_Component_PluginRoot_Interface_PreDispatch') as $plugin) {
             $plugin->preDispatch($_REQUEST['pageUrl']);
         }
     }
     if (isset($_REQUEST['componentId'])) {
         $data = Kwf_Component_Data_Root::getInstance()->getComponentById($_REQUEST['componentId']);
     } else {
         if (isset($_REQUEST['dbId'])) {
             $data = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($_REQUEST['dbId'], array('limit' => 1));
         } else {
             $url = $_REQUEST['url'];
             if (!is_string($url)) {
                 throw new Kwf_Exception_NotFound();
             }
             $parsedUrl = parse_url($url);
             if (isset($parsedUrl['query'])) {
                 foreach (explode('&', $parsedUrl['query']) as $get) {
                     if (!$get) {
                         continue;
                     }
                     $pos = strpos($get, '=');
                     $_GET[substr($get, 0, $pos)] = substr($get, $pos + 1);
                     //ouch
                     $_REQUEST[substr($get, 0, $pos)] = substr($get, $pos + 1);
                     //ouch
                 }
             }
             foreach (Kwf_Component_Data_Root::getInstance()->getPlugins('Kwf_Component_PluginRoot_Interface_PreDispatch') as $p) {
                 $p->preDispatch($url);
             }
             $data = Kwf_Component_Data_Root::getInstance()->getPageByUrl($url, null);
         }
     }
     if (!$data) {
         throw new Kwf_Exception_NotFound();
     }
     $contentSender = Kwc_Abstract::getSetting($data->componentClass, 'contentSender');
     $contentSender = new $contentSender($data);
     $content = $contentSender->getContent(false);
     $content['contents'] = $content['content'];
     unset($content['content']);
     if (!isset($content['lifetime'])) {
         $content['lifetime'] = false;
     }
     if (isset($_REQUEST['type']) && $_REQUEST['type'] == 'json') {
         $content['contents'] = json_encode(array('mimeType' => $content['mimeType'], 'content' => $content['contents'], 'assets' => $content['assets']));
         $content['mimeType'] = 'application/json';
     }
     Kwf_Media_Output::output($content);
     Kwf_Benchmark::shutDown();
     exit;
 }
 public function graphAction()
 {
     $frontendOptions = array('lifetime' => 60 * 5, 'automatic_serialization' => true);
     $backendOptions = array('cache_dir' => 'cache/benchmark/');
     $cache = Kwf_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
     $cacheId = md5('graph_' . $this->_getParam('rrd') . '_' . $this->_getParam('name') . '_' . $this->_getParam('start'));
     if (!($output = $cache->load($cacheId))) {
         $rrd = $this->_rrds[$this->_getParam('rrd')];
         $graphs = $rrd->getGraphs();
         $g = $graphs[$this->_getParam('name')];
         $output = array();
         $start = strtotime($this->_getParam('start'));
         if (!$start) {
             throw new Kwf_ClientException("invalid start");
         }
         $output['contents'] = $g->getContents($start);
         $output['mimeType'] = 'image/png';
         $cache->save($output, $cacheId);
     }
     Kwf_Media_Output::output($output);
 }
 public function pdfAction()
 {
     $id = $this->_getParam('id');
     if (!$id) {
         throw new Kwf_Exception("No id given");
     }
     $order = $this->_model->getRow($id);
     if (!$order->invoice_date) {
         $order->invoice_date = date('Y-m-d');
     }
     if (!$order->invoice_number) {
         $order->generateInvoiceNumber();
     }
     $order->save();
     $cls = Kwc_Admin::getComponentClass($this->_getParam('class'), 'InvoicePdf');
     $pdf = new $cls($order);
     Kwf_Media_Output::output(array('contents' => $pdf->output('', 'S'), 'mimeType' => 'application/pdf', 'downloadFilename' => $order->order_number . '.pdf'));
 }