Example #1
0
 public function assets(Kwf_Assets_Package $assetsPackage, $language = null)
 {
     if (!$language) {
         $language = Kwf_Trl::getInstance()->getTargetLanguage();
     }
     $indent = str_repeat(' ', 8);
     $ret = '';
     foreach ($assetsPackage->getPackageUrls('text/css', $language) as $file) {
         $ret .= "{$indent}<link rel=\"stylesheet\" type=\"text/css\" href=\"" . htmlspecialchars($file) . "\" />\n";
     }
     foreach ($assetsPackage->getPackageUrls('text/css; media=print', $language) as $file) {
         $ret .= "{$indent}<link rel=\"stylesheet\" type=\"text/css\" href=\"" . htmlspecialchars($file) . "\" ";
         if (!Kwf_Config::getValue('debug.assets.usePrintCssForAllMedia')) {
             $ret .= "media=\"print\" ";
         }
         $ret .= "/>\n";
     }
     foreach ($assetsPackage->getPackageUrls('text/javascript', $language) as $file) {
         $ret .= "{$indent}<script type=\"text/javascript\" src=\"" . htmlspecialchars($file) . "\"></script>\n";
     }
     foreach ($assetsPackage->getPackageUrls('text/javascript; defer', $language) as $file) {
         $ret .= "<script type=\"text/javascript\">\n                var se=document.createElement('script');se.type='text/javascript';se.async=true;\n                se.src='" . $file . "';\n                var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(se,s);\n            </script>";
     }
     return $ret;
 }
 /**
  * opening of the session - mandatory arguments won't be needed
  *
  * @param string $savePath
  * @param string $sessionName
  * @return bool
  */
 public function open($savePath, $sessionName)
 {
     if (!isset($this->_lifeTime)) {
         $this->_lifeTime = intval(ini_get("session.gc_maxlifetime"));
     }
     if (!isset($this->_refreshTime)) {
         $this->_refreshTime = ceil($this->_lifeTime / 3);
     }
     $this->_initSessionData = null;
     $this->_memcache = new Memcache();
     if (Kwf_Config::getValue('aws.simpleCacheCluster')) {
         $servers = Kwf_Util_Aws_ElastiCache_CacheClusterEndpoints::getCached(Kwf_Config::getValue('aws.simpleCacheCluster'));
     } else {
         if (Kwf_Cache_Simple::$memcacheHost) {
             $servers = array(array('host' => Kwf_Cache_Simple::$memcacheHost, 'port' => Kwf_Cache_Simple::$memcachePort));
         } else {
             throw new Kwf_Exception("no memcache configured");
         }
     }
     foreach ($servers as $s) {
         if (version_compare(phpversion('memcache'), '2.1.0') == -1 || phpversion('memcache') == '2.2.4') {
             // < 2.1.0
             $this->_memcache->addServer($s['host'], $s['port'], true, 1, 1, 1);
         } else {
             if (version_compare(phpversion('memcache'), '3.0.0') == -1) {
                 // < 3.0.0
                 $this->_memcache->addServer($s['host'], $s['port'], true, 1, 1, 1, true, null, 10000);
             } else {
                 $this->_memcache->addServer($s['host'], $s['port'], true, 1, 1, 1);
             }
         }
     }
     return true;
 }
Example #3
0
 public static function getSettings()
 {
     $ret = parent::getSettings();
     $ret['generators']['child'] = array('class' => 'Kwf_Component_Generator_Static', 'component' => array('linkTag' => 'Kwc_Basic_ImageEnlarge_EnlargeTag_Component'), 'addUrlPart' => false);
     $ret['cssClass'] = 'kwcBasicImageEnlarge ' . Kwf_Config::getValue('kwc.imageEnlarge.cssClass');
     return $ret;
 }
 public function getContentsPacked()
 {
     $contents = file_get_contents($this->getAbsoluteFileName());
     $useTrl = strpos($contents, 'trl') !== false && preg_match('#trl(c|p|cp)?(Kwf)?(Static)?\\(#', $contents);
     $trlData = array();
     if ($useTrl) {
         foreach (Kwf_TrlJsParser_UnderscoreTemplateParser::parseContent($contents) as $trlElement) {
             $d = Kwf_Assets_Util_Trl::getJsReplacement($trlElement);
             $contents = str_replace($d['before'], $d['replace'], $contents);
             $trlData[] = $d['trlElement'];
         }
     }
     $contents = str_replace("\n", '\\n', $contents);
     $contents = str_replace("'", "\\'", $contents);
     $contents = "var _ = require('underscore');\n" . "module.exports = _.template('" . $contents . "');\n";
     $replacements = array();
     if (strpos($contents, 'kwfUp-') !== false) {
         if (Kwf_Config::getValue('application.uniquePrefix')) {
             $replacements['kwfUp-'] = Kwf_Config::getValue('application.uniquePrefix') . '-';
         } else {
             $replacements['kwfUp-'] = '';
         }
     }
     foreach ($replacements as $search => $replace) {
         $contents = str_replace($search, $replace, $contents);
     }
     $map = Kwf_SourceMaps_SourceMap::createEmptyMap($contents);
     $data = $map->getMapContentsData();
     $data->{'_x_org_koala-framework_masterFiles'} = array($this->getAbsoluteFileName());
     if ($trlData) {
         $data->{'_x_org_koala-framework_trlData'} = $trlData;
     }
     return $map;
 }
Example #5
0
 protected function _processContents($ret)
 {
     $pathType = $this->getType();
     if ($pathType == 'ext2') {
         //hack um bei ext-css-dateien korrekte pfade für die bilder zu haben
         $ret = str_replace('../images/', '/assets/ext2/resources/images/', $ret);
     }
     //convert relative paths (as in bower dependencies; example: jquery.socialshareprivacy, mediaelement
     $fn = $this->getFileNameWithType();
     $fnDir = substr($fn, 0, strrpos($fn, '/'));
     $ret = preg_replace('#url\\(\\s*([^)]+?)\\s*\\)#', 'url(\\1)', $ret);
     //remove spaces inside url()
     $ret = preg_replace('#url\\((\'|")(?![a-z]+:)([^/\'"])#', 'url(\\1/assets/' . $fnDir . '/\\2', $ret);
     $ret = preg_replace('#url\\((?![a-z]+:)([^/\'"])#', 'url(/assets/' . $fnDir . '/\\1', $ret);
     $ret = self::expandAssetVariables($ret);
     if (strpos($ret, 'cssClass') !== false && (strpos($ret, '$cssClass') !== false || strpos($ret, '.cssClass') !== false)) {
         $cssClass = $this->_getComponentCssClass();
         if ($cssClass) {
             $ret = str_replace('$cssClass', $cssClass, $ret);
             $ret = str_replace('.cssClass', '.' . $cssClass, $ret);
         }
     }
     if (strpos($ret, 'kwfup-') !== false) {
         if (Kwf_Config::getValue('application.uniquePrefix')) {
             $ret = str_replace('kwfup-', Kwf_Config::getValue('application.uniquePrefix') . '-', $ret);
         } else {
             $ret = str_replace('kwfup-', '', $ret);
         }
     }
     return $ret;
 }
 public static function money($context, $amount)
 {
     $data = null;
     if (isset($context['data']) && $context['data'] instanceof Kwf_Component_Data) {
         $data = $context['data'];
     } else {
         if (isset($context['item']) && $context['item'] instanceof Kwf_Component_Data) {
             $data = $context['item'];
         }
     }
     if ($data) {
         $format = $data->getBaseProperty('money.format');
         $decimals = $data->getBaseProperty('money.decimals');
         $decimalSeparator = $data->getBaseProperty('money.decimalSeparator');
         $thousandSeparator = $data->getBaseProperty('money.thousandSeparator');
         if (is_null($decimalSeparator)) {
             $decimalSeparator = $data->trlcKwf('decimal separator', ".");
         }
         if (is_null($thousandSeparator)) {
             $thousandSeparator = $data->trlcKwf('thousands separator', ",");
         }
     } else {
         $format = Kwf_Config::getValue('money.format');
         $decimals = Kwf_Config::getValue('money.decimals');
         $decimalSeparator = trlcKwf('decimal separator', ".");
         $thousandSeparator = trlcKwf('thousands separator', ",");
     }
     $number = number_format($amount, $decimals, $decimalSeparator, $thousandSeparator);
     return str_replace('{0}', $number, $format);
 }
 public function getContent($includeMaster)
 {
     if ($this->_data->getBaseProperty('preLogin')) {
         $ignore = false;
         foreach (Kwf_Config::getValueArray('preLoginIgnoreIp') as $i) {
             $ip = $_SERVER['REMOTE_ADDR'];
             if ($ip == $i) {
                 $ignore = true;
             }
             if (!$ignore && substr($i, -1) == '*') {
                 $i = substr($i, 0, -1);
                 if (substr($ip, 0, strlen($i)) == $i) {
                     $ignore = true;
                 }
             }
             if (!$ignore && substr($i, 0, 1) == '*') {
                 $i = substr($i, 1);
                 if (substr($ip, -strlen($i)) == $i) {
                     $ignore = true;
                 }
             }
         }
         Kwf_Setup::checkPreLogin($this->_data->getBaseProperty('preLoginUser'), $this->_data->getBaseProperty('preLoginPassword'));
     }
     $benchmarkEnabled = Kwf_Benchmark::isEnabled();
     if ($benchmarkEnabled) {
         $startTime = microtime(true);
     }
     $process = $this->_getProcessInputComponents($includeMaster);
     if ($benchmarkEnabled) {
         Kwf_Benchmark::subCheckpoint('getProcessInputComponents', microtime(true) - $startTime);
     }
     self::_callProcessInput($process);
     if ($benchmarkEnabled) {
         Kwf_Benchmark::checkpoint('processInput');
     }
     $ret = array();
     $hasDynamicParts = false;
     $ret['content'] = $this->_render($includeMaster, $hasDynamicParts);
     if ($benchmarkEnabled) {
         Kwf_Benchmark::checkpoint('render');
     }
     $ret['mimeType'] = 'text/html; charset=utf-8';
     if (!$includeMaster) {
         $assetsBox = $this->_data->getChildComponent('-assets');
         if ($assetsBox) {
             $ret['assets'] = $assetsBox->render(null, false, $hasDynamicParts);
         } else {
             $ret['assets'] = '';
         }
     }
     if (!$hasDynamicParts) {
         $ret['lifetime'] = 60 * 60;
     }
     self::_callPostProcessInput($process);
     if ($benchmarkEnabled) {
         Kwf_Benchmark::checkpoint('postProcessInput');
     }
     return $ret;
 }
 public static function getInstance()
 {
     static $i;
     if (!isset($i)) {
         if (Kwf_Config::getValue('server.aws')) {
             throw new Kwf_Exception_NotYetImplemented("using counter on multiple servers is not yet implemented");
         }
         if (extension_loaded('apc')) {
             if (function_exists('apc_inc')) {
                 //apc >= 3.1.1
                 $i = new Kwf_Benchmark_Counter_Apc();
             } else {
                 //kein memcache-fallback, da der dann *nur* für den counter verwendet werden würde
                 $i = new Kwf_Benchmark_Counter_File();
             }
         } else {
             if (class_exists('Memcache')) {
                 $i = new Kwf_Benchmark_Counter_Memcache();
             } else {
                 $i = new Kwf_Benchmark_Counter_File();
             }
         }
     }
     return $i;
 }
 public function indexAction()
 {
     $ok = false;
     foreach (Kwf_Config::getValueArray('debug.benchmarkCounterAccessIp') as $i) {
         if (substr($i, -1) == '*') {
             $i = substr($i, 0, -1);
             if (substr($_SERVER['REMOTE_ADDR'], 0, strlen($i)) == $i) {
                 $ok = true;
             }
         } else {
             if ($_SERVER['REMOTE_ADDR'] == $i) {
                 $ok = true;
             }
         }
     }
     if (!$ok) {
         throw new Kwf_Exception_AccessDenied();
     }
     $names = array('content-requests', 'asset-requests', 'media-requests', 'admin-requests', 'fullpage-hit', 'fullpage-miss', 'dbqueries', 'render-hit', 'render-miss', 'render-noviewcache', 'viewcache-mem', 'viewcache-db', 'viewcache-miss', 'viewcache-delete-page', 'viewcache-delete-component', 'viewcache-delete-master', 'viewcache-delete-partial', 'viewcache-delete-componentLink', 'viewcache-delete-fullPage');
     $out = array();
     $load = @file_get_contents('/proc/loadavg');
     $load = explode(' ', $load);
     $out['load'] = (double) $load[0];
     foreach ($names as $name) {
         $out[$name] = Kwf_Benchmark_Counter::getInstance()->getValue($name);
     }
     echo json_encode($out);
     exit;
 }
 protected function _getRedirectPage()
 {
     if (!Kwf_Config::getValue('fbAppData.pageTabUrl')) {
         throw new Kwf_Exception('kwc.fbApp.Data.pageTabUrl has to be set in config');
     }
     return Kwf_Config::getValue('fbAppData.pageTabUrl');
 }
Example #11
0
 public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
 {
     switch ($mode) {
         case Zend_Cache::CLEANING_MODE_ALL:
             $ret = true;
             if (PHP_SAPI == 'cli') {
                 if (Kwf_Config::getValue('externalClearCacheScript')) {
                     throw new Kwf_Exception("Dont't delete complete apc-user cache via cli.");
                 }
                 $ret = Kwf_Util_Apc::callClearCacheByCli(array('type' => 'user'));
             }
             if (extension_loaded('apcu')) {
                 return $ret && apc_clear_cache('user');
             } else {
                 return $ret && apc_clear_cache();
             }
             break;
         case Zend_Cache::CLEANING_MODE_OLD:
             $this->_log("Zend_Cache_Backend_Apc::clean() : CLEANING_MODE_OLD is unsupported by the Apc backend");
             break;
         case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
         case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
         case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
             $this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_APC_BACKEND);
             break;
         default:
             Zend_Cache::throwException('Invalid mode for clean() method');
             break;
     }
 }
 public function getTemplateVars(Kwf_Component_Renderer_Abstract $renderer)
 {
     $ret = parent::getTemplateVars($renderer);
     $ret['settingsRow'] = $this->_getRow();
     $ret['tableStyle'] = $this->_getRow()->table_style;
     $ret['columnCount'] = $this->getColumnCount();
     if (Kwf_Config::getValue('kwc.responsive')) {
         $ret['rootElementClass'] .= ' responsive' . ucfirst($this->_getRow()->responsive_style);
     }
     $dataSelect = new Kwf_Model_Select();
     $dataSelect->whereEquals('visible', 1);
     $dataSelect->order('pos', 'ASC');
     $ret['dataRows'] = array();
     $rows = $this->_getRow()->getChildRows('tableData', $dataSelect);
     foreach ($rows as $row) {
         $rowData = array();
         $rowData['cssStyle'] = $row->css_style;
         $rowData['data'] = array();
         for ($i = 1; $i <= $ret['columnCount']; $i++) {
             $rowData['data']['column' . $i] = array('value' => $row->{'column' . $i}, 'cssClass' => '');
         }
         $ret['dataRows'][] = $rowData;
     }
     $ret['dataRows'] = Kwc_Basic_Table_Component::addDefaultCssClasses($ret['dataRows'], $this->_getSetting('rowStyles'));
     $ret['headerRows'] = array();
     if (isset($ret['dataRows'][0]['htmlTag']) && $ret['dataRows'][0]['htmlTag'] == 'th') {
         $ret['headerRows'] = array(array_shift($ret['dataRows']));
     }
     return $ret;
 }
 public function getTemplateVars($values, $fieldNamePostfix = '', $idPrefix = '')
 {
     $ret = parent::getTemplateVars($values, $fieldNamePostfix, $idPrefix);
     require_once 'vendor/koala-framework/recaptcha-php/recaptchalib.php';
     $ret['html'] = "<div data-fieldname=\"" . $this->getFieldName() . $fieldNamePostfix . "\">" . recaptcha_get_html(Kwf_Config::getValue('recaptcha.publicKey')) . "</div>";
     return $ret;
 }
 protected function _render($includeMaster, &$hasDynamicParts)
 {
     $lightboxContent = $this->_data->render(null, false, $hasDynamicParts);
     $kwfUniquePrefix = Kwf_Config::getValue('application.uniquePrefix');
     if ($kwfUniquePrefix) {
         $kwfUniquePrefix = $kwfUniquePrefix . '-';
     }
     if ($includeMaster) {
         $parent = $this->_getParent();
         $parentContentSender = Kwc_Abstract::getSetting($parent->componentClass, 'contentSender');
         $parentContentSender = new $parentContentSender($parent);
         $parentContent = $parentContentSender->_render($includeMaster, $hasDynamicParts);
         //remove main content to avoid duplicate content for search engines
         //content will be loaded using ajax
         $startPos = strpos($parentContent, '<main class="' . $kwfUniquePrefix . 'kwfMainContent">');
         $endPos = strpos($parentContent, '</main><!--/' . $kwfUniquePrefix . 'kwfMainContent-->');
         $parentContent = substr($parentContent, 0, $startPos) . '<main class="' . $kwfUniquePrefix . 'kwfMainContent" data-kwc-component-id="' . $parent->componentId . '">' . substr($parentContent, $endPos);
         foreach ($this->_data->getRecursiveChildComponents(array('flag' => 'hasInjectIntoRenderedHtml')) as $component) {
             $box = $component;
             $isInBox = false;
             while (!$isInBox && $box) {
                 if (isset($box->box)) {
                     $isInBox = true;
                 }
                 $box = $box->parent;
             }
             if ($isInBox) {
                 $parentContent = $component->getComponent()->injectIntoRenderedHtml($parentContent);
             }
         }
         //append lightbox after <body> in parent
         $options = $this->_getOptions();
         $style = '';
         if (isset($options['width'])) {
             $style .= "width: {$options['width']}px;";
         }
         if (isset($options['height'])) {
             $style .= "height: {$options['height']}px";
         }
         $class = $kwfUniquePrefix . 'kwfLightbox';
         $class .= " " . $kwfUniquePrefix . "kwfLightbox{$options['style']}";
         if (isset($options['cssClass'])) {
             $class .= " {$options['cssClass']}";
         }
         if (isset($options['adaptHeight']) && $options['adaptHeight']) {
             $class .= " adaptHeight";
         }
         $options = htmlspecialchars(json_encode($options));
         $lightboxContent = "<div class=\"{$class} " . $kwfUniquePrefix . "kwfLightboxOpen\">\n" . "    <div class=\"" . $kwfUniquePrefix . "kwfLightboxScrollOuter\">\n" . "        <div class=\"" . $kwfUniquePrefix . "kwfLightboxScroll\">\n" . "            <div class=\"" . $kwfUniquePrefix . "kwfLightboxBetween\">\n" . "               <div class=\"" . $kwfUniquePrefix . "kwfLightboxBetweenInner\">\n" . "                   <div class=\"" . $kwfUniquePrefix . "kwfLightboxInner\" style=\"{$style}\">\n" . "                       <input type=\"hidden\" class=\"options\" value=\"{$options}\" />\n" . "                       <div class=\"" . $kwfUniquePrefix . "kwfLightboxContent\">\n" . "                           {$lightboxContent}\n" . "                       </div>\n" . "                       <a class=\"" . $kwfUniquePrefix . "closeButton\" href=\"{$parent->url}\"><span class=\"" . $kwfUniquePrefix . "innerCloseButton\">" . $this->_data->trlKwf('Close') . "</span></a>\n" . "                   </div>\n" . "               </div>\n" . "            </div>\n" . "        </div>\n" . "        <div class=\"" . $kwfUniquePrefix . "kwfLightboxMask " . $kwfUniquePrefix . "kwfLightboxMaskOpen\"></div>\n" . "    </div>\n" . "</div>\n";
         $ret = preg_replace('#(<body[^>]*>)#', "\\1\n" . $lightboxContent, $parentContent);
         if (preg_match('#<html[^>]* class#', $ret)) {
             $ret = preg_replace('#(<html[^>]*?)( class="([^"]*)")#', "\\1 class=\"\\3 " . $kwfUniquePrefix . "kwfLightboxActive\"", $ret);
         } else {
             $ret = preg_replace('#(<html[^>]*)#', "\\1 class=\"\\3" . $kwfUniquePrefix . "kwfLightboxActive\"", $ret);
         }
         return $ret;
     } else {
         return $lightboxContent;
     }
 }
Example #15
0
 public function money($amount)
 {
     $component = null;
     if (isset($this->_view) && $this->_view && $this->_view->data && $this->_view->data instanceof Kwf_Component_Data) {
         $component = $this->_view->data;
     }
     if ($component) {
         $format = $component->getBaseProperty('money.format');
         $decimals = $component->getBaseProperty('money.decimals');
         $decimalSeparator = $component->getBaseProperty('money.decimalSeparator');
         $thousandSeparator = $component->getBaseProperty('money.thousandSeparator');
         if (is_null($decimalSeparator)) {
             $decimalSeparator = $component->trlcKwf('decimal separator', ".");
         }
         if (is_null($thousandSeparator)) {
             $thousandSeparator = $component->trlcKwf('thousands separator', ",");
         }
     } else {
         $format = Kwf_Config::getValue('money.format');
         $decimals = Kwf_Config::getValue('money.decimals');
         $decimalSeparator = trlcKwf('decimal separator', ".");
         $thousandSeparator = trlcKwf('thousands separator', ",");
     }
     $number = number_format($amount, $decimals, $decimalSeparator, $thousandSeparator);
     return str_replace('{0}', $number, $format);
 }
Example #16
0
 protected function _init()
 {
     parent::_init();
     if (is_null($this->_useMobileBreakpoints)) {
         $this->_useMobileBreakpoints = Kwf_Config::getValue('kwc.mobileBreakpoints');
     }
 }
 public function testExceptions()
 {
     // Ohne Mail
     $exception = new Kwf_Exception();
     $view = $this->_processException($exception);
     $this->assertEquals($view->message, $exception->getMessage());
     $this->assertTrue($view->debug);
     $this->assertEquals($view->template, 'error.tpl');
     // Mit Mail
     Zend_Registry::get('config')->debug->error->log = true;
     Kwf_Config::deleteValueCache('debug.error.log');
     $exception = new Kwf_Exception();
     $view = $this->_processException($exception);
     $this->assertEquals($view->message, $exception->getMessage());
     $this->assertFalse($view->debug);
     $this->assertEquals($view->template, 'error.tpl');
     // Nicht-Kwf_Exception mit Mail
     Zend_Registry::get('config')->debug->error->log = true;
     Kwf_Config::deleteValueCache('debug.error.log');
     $e = new Zend_Exception();
     $exception = new Kwf_Exception_Other($e);
     $view = $this->_processException($exception);
     $this->assertEquals($view->message, $e->getMessage());
     $this->assertFalse($view->debug);
     $this->assertEquals($view->template, 'error.tpl');
     Zend_Registry::get('config')->debug->error->log = false;
     Kwf_Config::deleteValueCache('debug.error.log');
     // Kwf_Exception_NoLog mit Debug
     Zend_Registry::get('config')->debug->error->log = true;
     Kwf_Config::deleteValueCache('debug.error.log');
     $exception = new Kwf_Exception_NoLog();
     $view = $this->_processException($exception);
     $this->assertEquals($view->message, $exception->getMessage());
     $this->assertFalse($view->debug);
     Zend_Registry::get('config')->debug->error->log = false;
     Kwf_Config::deleteValueCache('debug.error.log');
     $this->assertEquals($view->template, 'error.tpl');
     // Kwf_Exception_NoLog ohne Debug
     $exception = new Kwf_Exception_NoLog();
     $view = $this->_processException($exception);
     $this->assertEquals($view->message, $exception->getMessage());
     $this->assertTrue($view->debug);
     $this->assertEquals($view->template, 'error.tpl');
     // Kwf_Exception_NotFound
     $exception = new Kwf_Exception_NotFound();
     $view = $this->_processException($exception);
     $this->assertEquals($view->message, $exception->getMessage());
     $this->assertEquals($view->template, 'error404.tpl');
     // Nicht-Kwf_Exception
     $exception = new Exception();
     $view = $this->_processException($exception);
     $this->assertEquals($view->message, $exception->getMessage());
     $this->assertEquals($view->template, 'error.tpl');
     // ClientException
     $exception = new Kwf_ClientException();
     $view = $this->_processException($exception);
     $this->assertEquals($view->message, $exception->getMessage());
     $this->assertEquals($view->template, 'error-client.tpl');
 }
 public function getContentsPacked()
 {
     if (!$this->_features) {
         return null;
     }
     $modernizrPath = getcwd() . '/node_modules/modernizr';
     $outputFile = tempnam('./temp', 'modernizr');
     $configAll = json_decode(file_get_contents($modernizrPath . '/lib/config-all.json'), true);
     $allFeatureDetects = $configAll['feature-detects'];
     $options = array();
     foreach ($configAll['options'] as $i) {
         $options[$i] = false;
     }
     $options['mq'] = true;
     $options['setClasses'] = true;
     $featureDetects = array();
     foreach ($this->_features as $f) {
         if (isset($options[strtolower($f)])) {
             //for prefixed
             $options[strtolower($f)] = true;
         } else {
             $filter = new Zend_Filter_Word_CamelCaseToSeparator('/');
             $fFiltered = strtolower($filter->filter($f));
             if (!in_array($fFiltered, $allFeatureDetects)) {
                 throw new Kwf_Exception("Invalid Modernizr Dependency, test doesn't exist: '" . $f . "'");
             }
             $featureDetects[] = $fFiltered;
         }
     }
     foreach ($options as $k => $i) {
         if (!$i) {
             unset($options[$k]);
         }
     }
     $options = array_keys($options);
     $classPrefix = '';
     if (Kwf_Config::getValue('application.uniquePrefix')) {
         $classPrefix = Kwf_Config::getValue('application.uniquePrefix') . '-';
     }
     $config = array('classPrefix' => $classPrefix, 'options' => $options, 'feature-detects' => $featureDetects);
     $configFile = tempnam('temp/', 'modernizrbuild');
     unlink($configFile);
     $configFile .= '.json';
     file_put_contents($configFile, json_encode($config, JSON_PRETTY_PRINT));
     $cmd = getcwd() . "/" . VENDOR_PATH . "/bin/node {$modernizrPath}/bin/modernizr --config {$configFile} --uglify --dest " . $outputFile;
     exec($cmd, $out, $retVar);
     if ($retVar) {
         throw new Kwf_Exception("modernizr failed: " . implode("\n", $out));
     }
     $ret = file_get_contents($outputFile);
     unlink($configFile);
     unlink($outputFile);
     //remove comments containing selected tests
     $ret = preg_replace("#\n/\\*!\n\\{.*?\\}\n!\\*/\n#s", '', $ret);
     $ret = Kwf_SourceMaps_SourceMap::createEmptyMap($ret);
     $map = $ret->getMapContentsData(false);
     $map->{'_x_org_koala-framework_masterFiles'} = array(getcwd() . '/node_modules/modernizr/package.json');
     return $ret;
 }
Example #19
0
 public function setUp()
 {
     if (!Kwf_Config::getValue('aws.key') || !Kwf_Config::getValue('aws.secret')) {
         $this->markTestSkipped();
     }
     Kwf_Registry::get('config')->aws->uploadsBucket = 'kwf-test';
     Kwf_Config::deleteValueCache('aws.uploadsBucket');
 }
Example #20
0
 public static function createPackages()
 {
     $packages = array(self::getInstance('Frontend'), self::getInstance('Admin'));
     foreach (Kwf_Config::getValueArray('assets.packages') as $i) {
         $packages[] = self::getInstance($i);
     }
     return $packages;
 }
 protected function _clearCache($options)
 {
     if (!Kwf_Config::getValue('debug.componentCache.clearOnClearCache')) {
         $this->_output("skipped: (won't delete, use clear-view-cache to clear)\n");
         return;
     }
     Kwf_Component_Cache::getInstance()->deleteViewCache(new Kwf_Model_Select());
 }
 public function getMaxTime()
 {
     $ret = parent::getMaxTime();
     if ($value = Kwf_Config::getValue('maintenanceJobs.pageMetaRebuildMaxTime')) {
         $ret = $value;
     }
     return $ret;
 }
 public function getContents($language)
 {
     if (!Kwf_Config::getValue('ravenJs.dsn')) {
         throw new Kwf_Exception('ravenJS.dsn config setting is required');
     }
     $data = array('dsn' => Kwf_Config::getValue('ravenJs.dsn'));
     return "Kwf.RavenJsConfig = " . json_encode($data) . ";";
 }
 protected function _clearCache($options)
 {
     if (Kwf_Config::getValue('cacheSimpleNamespace')) {
         $this->_output("change cacheSimpleNamespace config setting to clear");
     } else {
         Kwf_Cache_Simple::_clear();
     }
 }
 /**
  * Helper function that returns scaled and croped images for media output
  *
  * Used by image components in getMediaOutput.
  * Tries to avoid scaling if not required (to keep gif animation intact)
  */
 public static function getMediaOutputForDimension($data, $dim, $type)
 {
     if (isset($data['url'])) {
         $file = Kwf_Config::getValue('mediaCacheDir') . '/remotefile_' . md5($data['url']);
         if (!is_file($file)) {
             $httpClientConfig = array('timeout' => 20, 'persistent' => false);
             if (Kwf_Config::getValue('http.proxy.host')) {
                 $httpClientConfig['adapter'] = 'Zend_Http_Client_Adapter_Proxy';
                 $httpClientConfig['proxy_host'] = Kwf_Config::getValue('http.proxy.host');
                 $httpClientConfig['proxy_port'] = Kwf_Config::getValue('http.proxy.port');
             }
             $httpClient = new Zend_Http_Client($data['url'], $httpClientConfig);
             $request = $httpClient->request();
             if ($request->getStatus() == 200) {
                 file_put_contents($file, $request->getBody());
                 if (!getimagesize($file)) {
                     unlink($file);
                     throw new Kwf_Exception('File is no image: ' . $data['url']);
                 }
             } else {
                 throw new Kwf_Exception('Could not download file: ' . $data['url']);
             }
         }
         $data['file'] = $file;
     }
     // calculate output width/height on base of getImageDimensions and given width
     $width = substr($type, strlen(Kwf_Media::DONT_HASH_TYPE_PREFIX));
     $width = substr($width, 0, strpos($width, '-'));
     if ($width) {
         $width = Kwf_Media_Image::getResponsiveWidthStep($width, Kwf_Media_Image::getResponsiveWidthSteps($dim, isset($data['image']) ? $data['image'] : $data['file']));
         $dim['height'] = $width / $dim['width'] * $dim['height'];
         $dim['width'] = $width;
     }
     $ret = array();
     if (isset($data['image'])) {
         $output = Kwf_Media_Image::scale($data['image'], $dim);
         $ret['contents'] = $output;
     } else {
         $sourceSize = @getimagesize($data['file']);
         $scalingNeeded = true;
         $resultingSize = Kwf_Media_Image::calculateScaleDimensions($data['file'], $dim);
         if ($sourceSize && array($resultingSize['crop']['width'], $resultingSize['crop']['height']) == array($sourceSize[0], $sourceSize[1]) && array($resultingSize['width'], $resultingSize['height']) == array($sourceSize[0], $sourceSize[1])) {
             $scalingNeeded = false;
         }
         if ($scalingNeeded) {
             //NOTE: don't pass actual size of the resulting image, scale() will calculate that on it's own
             //else size is calculated twice and we get rounding errors
             $uploadId = isset($data['uploadId']) ? $data['uploadId'] : null;
             $output = Kwf_Media_Image::scale($data['file'], $dim, $uploadId);
             $ret['contents'] = $output;
         } else {
             $ret['file'] = $data['file'];
         }
     }
     $ret['mimeType'] = $data['mimeType'];
     $ret['mtime'] = filemtime($data['file']);
     return $ret;
 }
 public function getContentsPacked()
 {
     if (!Kwf_Config::getValue('ravenJs.dsn')) {
         throw new Kwf_Exception('ravenJS.dsn config setting is required');
     }
     $data = array('dsn' => Kwf_Config::getValue('ravenJs.dsn'));
     $ret = "Kwf.RavenJsConfig = " . json_encode($data) . ";";
     return Kwf_SourceMaps_SourceMap::createEmptyMap($ret);
 }
 public function __construct($config = array())
 {
     if (isset($config['pageCategories'])) {
         $this->_pageCategories = $config['pageCategories'];
     } else {
         $this->_pageCategories = Kwf_Config::getValueArray('kwc.pageCategories');
     }
     parent::__construct($config);
 }
 public function jsonRebuildAction()
 {
     if (!Kwf_Config::getValue('server.phpCli')) {
         throw new Kwf_Exception_Client("Not (yet?) supported without phpCli");
     }
     $cmd = Kwf_Config::getValue('server.phpCli') . " bootstrap.php fulltext rebuild --silent";
     $procData = Kwf_Util_BackgroundProcess::start($cmd, $this->view);
     $this->view->assign($procData);
 }
 public function render($ignoreCli = false)
 {
     if (!Kwf_Registry::get('config')->setupFinished) {
         echo "<h1>" . Kwf_Config::getValue('application.name') . "</h1>\n";
         echo "<a href=\"" . Kwf_Setup::getBaseUrl() . "/kwf/maintenance/setup\">[start setup]</a>\n";
         exit;
     }
     parent::render($ignoreCli);
 }
 public static function getInstance()
 {
     static $i;
     if (!isset($i)) {
         $be = Kwf_Config::getValue('fulltext.backend');
         $i = new $be();
     }
     return $i;
 }