Exemple #1
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);
     }
 }
Exemple #2
0
 public static function getVendorProviders()
 {
     $cacheId = 'assets-vendor-providers';
     $cachedProviders = Kwf_Cache_SimpleStatic::fetch($cacheId);
     if ($cachedProviders === false) {
         $cachedProviders = array();
         foreach (glob(VENDOR_PATH . "/*/*") as $i) {
             if (is_dir($i) && file_exists($i . '/dependencies.ini')) {
                 $config = new Zend_Config_Ini($i . '/dependencies.ini', 'config');
                 if ($config->provider) {
                     $provider = $config->provider;
                     if (is_string($provider)) {
                         $provider = array($provider);
                     }
                     foreach ($provider as $p) {
                         $cachedProviders[] = array('cls' => $p, 'file' => $i . '/dependencies.ini');
                     }
                 }
             }
         }
         foreach (glob(VENDOR_PATH . '/bower_components/*') as $i) {
             $cachedProviders[] = array('cls' => 'Kwf_Assets_Provider_BowerBuiltFile', 'file' => $i);
         }
         Kwf_Cache_SimpleStatic::add($cacheId, $cachedProviders);
     }
     $providers = array();
     foreach ($cachedProviders as $p) {
         $cls = $p['cls'];
         $providers[] = new $cls($p['file']);
     }
     if (VENDOR_PATH == '../vendor') {
         $providers[] = new Kwf_Assets_Provider_Ini('../dependencies.ini');
     }
     return $providers;
 }
 public function save($cacheData, $cacheId)
 {
     if (!file_exists(self::$_buildDir)) {
         mkdir(self::$_buildDir, 0777, true);
     }
     Kwf_Cache_SimpleStatic::add('asb-' . $cacheId, $cacheData);
     $fileName = self::$_buildDir . '/' . $cacheId;
     return file_put_contents($fileName, serialize($cacheData));
 }
 public function test($cacheId)
 {
     $ret = Kwf_Cache_SimpleStatic::fetch('as-mtime-' . $cacheId);
     if ($ret === false) {
         $ret = self::_getFileCacheInstance()->test($cacheId);
         if ($ret !== false) {
             Kwf_Cache_SimpleStatic::add('as-mtime-' . $cacheId, $ret);
         }
     }
     return $ret;
 }
 public function test($cacheId)
 {
     $ret = Kwf_Cache_SimpleStatic::fetch('as-mtime-' . $cacheId);
     if ($ret === false) {
         $ret = self::_getSlowCache()->test(str_replace('-', '_', $cacheId));
         if ($ret !== false) {
             Kwf_Cache_SimpleStatic::add('as-mtime-' . $cacheId, $ret);
         }
     }
     return $ret;
 }
 protected function _getUseComponentId()
 {
     if (!isset($this->_useComponentId)) {
         $cacheId = 'useCmpId-' . $this->_class . '-' . $this->_settings['generator'];
         //cache to delay model creation
         $this->_useComponentId = Kwf_Cache_SimpleStatic::fetch($cacheId, $success);
         if (!$success) {
             $this->_useComponentId = $this->_getModel()->hasColumn('component_id');
             Kwf_Cache_SimpleStatic::add($cacheId, $this->_useComponentId);
         }
     }
     return $this->_useComponentId;
 }
 public static function getMasterStyles()
 {
     $cacheId = 'textMasterSyles';
     $ret = Kwf_Cache_SimpleStatic::fetch($cacheId);
     if ($ret !== false) {
         return $ret;
     }
     $package = Kwf_Assets_Package_Default::getInstance('Frontend');
     $ret = array();
     foreach ($package->getDependency()->getFilteredUniqueDependencies('text/css') as $dep) {
         $ret = array_merge($ret, self::parseMasterStyles($dep->getContentsSourceString()));
     }
     Kwf_Cache_SimpleStatic::add($cacheId, $ret);
     return $ret;
 }
 public static function getPrivatePart()
 {
     $salt = Kwf_Cache_SimpleStatic::fetch('hashpp-');
     if (!$salt) {
         if ($salt = Kwf_Config::getValue('hashPrivatePart')) {
             //defined in config, required if multiple webservers should share the same salt
         } else {
             $hashFile = 'cache/hashprivatepart';
             if (!file_exists($hashFile)) {
                 file_put_contents($hashFile, time() . rand(100000, 1000000));
             }
             $salt = file_get_contents($hashFile);
             Kwf_Cache_SimpleStatic::add('hashpp-', $salt);
         }
     }
     return $salt;
 }
 protected function _getConfig()
 {
     $ret = parent::_getConfig();
     $cacheId = 'extConfig_multiFileUpload_' . $this->_class;
     $multiFileUpload = Kwf_Cache_SimpleStatic::fetch($cacheId, $success);
     if (!$success) {
         $multiFileUpload = false;
         $form = Kwc_Abstract_Form::createChildComponentForm($this->_class, 'child');
         if ($form && ($field = $this->_getFileUploadField($form))) {
             $multiFileUpload = array('allowOnlyImages' => $field->getAllowOnlyImages(), 'maxResolution' => $field->getMaxResolution(), 'maxResolution' => $field->getMaxResolution(), 'fileSizeLimit' => $field->getFileSizeLimit());
         }
         Kwf_Cache_SimpleStatic::add($cacheId, $multiFileUpload);
     }
     $ret['list']['multiFileUpload'] = $multiFileUpload;
     $ret['list']['maxEntries'] = Kwc_Abstract::getSetting($this->_class, 'maxEntries');
     $ret['list']['maxEntriesErrorMessage'] = trlKwf("Can't create more than {0} entries.", $ret['list']['maxEntries']);
     return $ret;
 }
Exemple #10
0
 protected static function _getAllPaths()
 {
     static $paths;
     if (!isset($paths)) {
         $cacheId = 'assets-file-paths';
         $paths = Kwf_Cache_SimpleStatic::fetch($cacheId);
         if ($paths === false) {
             $paths = array('webComponents' => 'components', 'webThemes' => 'themes');
             $vendors[] = KWF_PATH;
             //required for kwf tests, in web kwf is twice in $vendors but that's not a problem
             $vendors[] = '.';
             $vendors = array_merge($vendors, glob(VENDOR_PATH . "/*/*"));
             foreach ($vendors as $i) {
                 if (is_dir($i) && file_exists($i . '/dependencies.ini')) {
                     $c = new Zend_Config_Ini($i . '/dependencies.ini');
                     if ($c->config) {
                         $dep = new Zend_Config_Ini($i . '/dependencies.ini', 'config');
                         $pathType = (string) $dep->pathType;
                         if ($pathType) {
                             $paths[$pathType] = $i;
                         }
                     }
                 }
             }
             foreach (glob(VENDOR_PATH . '/bower_components/*') as $i) {
                 $type = substr($i, strlen(VENDOR_PATH . '/bower_components/'));
                 if (substr($type, -3) == '.js') {
                     $type = substr($type, 0, -3);
                 }
                 if (substr($type, -2) == 'js') {
                     $paths[$type] = $i;
                     $type = substr($type, 0, -2);
                 }
                 $paths[$type] = $i;
             }
             $paths['web'] = '.';
             Kwf_Cache_SimpleStatic::add($cacheId, $paths);
         }
     }
     return $paths;
 }
 public static function getValue($var)
 {
     $cacheId = 'config-' . $var;
     $ret = Kwf_Cache_SimpleStatic::fetch($cacheId, $success);
     if ($success) {
         return $ret;
     }
     $cfg = Kwf_Config_Web::getInstance();
     foreach (explode('.', $var) as $i) {
         if (!isset($cfg->{$i})) {
             $cfg = null;
             break;
         }
         $cfg = $cfg->{$i};
     }
     $ret = $cfg;
     if (is_object($ret)) {
         $ret = $ret->toArray();
     }
     Kwf_Cache_SimpleStatic::add($cacheId, $ret);
     return $ret;
 }
 public static function getValue($var)
 {
     $cacheId = 'config-' . $var;
     $ret = Kwf_Cache_SimpleStatic::fetch($cacheId, $success);
     if ($success) {
         return $ret;
     }
     $cfg = Kwf_Config_Web::getInstance();
     foreach (explode('.', $var) as $i) {
         if (!isset($cfg->{$i})) {
             $cfg = null;
             break;
         }
         $cfg = $cfg->{$i};
     }
     $ret = $cfg;
     if (is_object($ret)) {
         throw new Kwf_Exception("this would return an object, use getValueArray instead");
     }
     Kwf_Cache_SimpleStatic::add($cacheId, $ret);
     return $ret;
 }
 public function getCartComponentClass()
 {
     if ($this->_cartComponentClass) {
         return $this->_cartComponentClass;
     }
     $cacheId = 'kwc-shop-cart-default-cc';
     if (!($ret = Kwf_Cache_SimpleStatic::fetch($cacheId))) {
         $classes = array();
         foreach (Kwc_Abstract::getComponentClasses() as $c) {
             if (is_instance_of($c, 'Kwc_Shop_Cart_Component')) {
                 $classes[] = $c;
             }
         }
         if (count($classes) != 1) {
             throw new Kwf_Exception("Not exactly one Kwc_Shop_Cart_Component found, set _cartComponentClass manually");
         }
         $ret = $classes[0];
         Kwf_Cache_SimpleStatic::add($cacheId, $ret);
         $this->_cartComponentClass = $ret;
     }
     return $ret;
 }
 private function _fireTagEvent($event, $directory, $itemId = null)
 {
     $cacheId = 'kwc-dirlistview-isdata-' . $this->_class;
     $dirIs = Kwf_Cache_SimpleStatic::fetch($cacheId);
     if ($dirIs === false) {
         $dirIs = array('data' => false, 'string' => false);
         foreach (Kwc_Abstract::getComponentClasses() as $class) {
             if (in_array('Kwc_Directories_List_Component', Kwc_Abstract::getParentClasses($class)) || in_array('Kwc_Directories_List_Trl_Component', Kwc_Abstract::getParentClasses($class))) {
                 if (Kwc_Abstract::hasChildComponentClass($class, 'child', 'view') && $this->_class == Kwc_Abstract::getChildComponentClass($class, 'child', 'view')) {
                     $isData = call_user_func(array(strpos($class, '.') ? substr($class, 0, strpos($class, '.')) : $class, 'getItemDirectoryIsData'), $class);
                     if ($isData) {
                         $dirIs['data'] = true;
                     } else {
                         $dirIs['string'] = true;
                     }
                 }
             }
         }
         Kwf_Cache_SimpleStatic::add($cacheId, $dirIs);
     }
     $event = "Kwf_Component_Event_ComponentClass_Tag_{$event}";
     if ($itemId) {
         if ($dirIs['data']) {
             $this->fireEvent(new $event($this->_class, $directory->componentId, $itemId));
         }
         if ($dirIs['string']) {
             $this->fireEvent(new $event($this->_class, $directory->componentClass, $itemId));
         }
     } else {
         if ($dirIs['data']) {
             $this->fireEvent(new $event($this->_class, $directory->componentId));
         }
         if ($dirIs['string']) {
             $this->fireEvent(new $event($this->_class, $directory->componentClass));
         }
     }
 }
 /**
  * Returns componentClasses that match a given class in their inheritance chain
  *
  * Fast, as the result is static and will be cached
  *
  * @param string
  * @return string[]
  */
 public static function getComponentClassesByParentClass($class)
 {
     if (!is_array($class)) {
         $class = array($class);
     }
     static $prefix;
     $cacheId = 'cclsbpc-' . implode('-', $class);
     $ret = Kwf_Cache_SimpleStatic::fetch($cacheId, $success);
     if ($success) {
         return $ret;
     }
     $ret = array();
     foreach (Kwc_Abstract::getComponentClasses() as $c) {
         if (in_array($c, $class) || in_array(strpos($c, '.') ? substr($c, 0, strpos($c, '.')) : $c, $class)) {
             $ret[] = $c;
             continue;
         }
         foreach (Kwc_Abstract::getParentClasses($c) as $p) {
             if (in_array($p, $class)) {
                 $ret[] = $c;
                 break;
             }
         }
     }
     Kwf_Cache_SimpleStatic::add($cacheId, $ret);
     return $ret;
 }
Exemple #16
0
 public static function fireEvent($event)
 {
     $logger = Kwf_Events_Log::getInstance();
     if ($logger && $logger->indent == 0) {
         $logger->info('----');
         $logger->resetTimer();
     }
     $class = $event->class;
     $eventClass = get_class($event);
     $cacheId = '-ev-lst-' . Kwf_Component_Data_Root::getComponentClass() . '-' . $eventClass . '-' . $class;
     $callbacks = Kwf_Cache_SimpleStatic::fetch($cacheId);
     if ($callbacks === false) {
         $listeners = self::getAllListeners();
         $callbacks = array();
         if ($class && isset($listeners[$eventClass][$class])) {
             $callbacks = $listeners[$eventClass][$class];
         }
         if (isset($listeners[$eventClass]['all'])) {
             $callbacks = array_merge($callbacks, $listeners[$eventClass]['all']);
         }
         Kwf_Cache_SimpleStatic::add($cacheId, $callbacks);
     }
     if ($logger) {
         $logger->info($event->__toString() . ':');
         $logger->indent++;
     }
     static $callbackBenchmark = array();
     foreach ($callbacks as $callback) {
         $ev = call_user_func(array($callback['class'], 'getInstance'), $callback['class'], $callback['config']);
         if ($logger) {
             $msg = '-> ' . $callback['class'] . '::' . $callback['method'] . '(' . Kwf_Debug::_btArgsString($callback['config']) . ')';
             $logger->info($msg . ':');
             $start = microtime(true);
         }
         $ev->{$callback['method']}($event);
         if ($logger) {
             if (!isset($callbackBenchmark[$callback['class'] . '::' . $callback['method']])) {
                 $callbackBenchmark[$callback['class'] . '::' . $callback['method']] = array('calls' => 0, 'time' => 0);
             }
             $callbackBenchmark[$callback['class'] . '::' . $callback['method']]['calls']++;
             $callbackBenchmark[$callback['class'] . '::' . $callback['method']]['time'] += (microtime(true) - $start) * 1000;
             //ATM includes everything which is missleading
         }
     }
     if ($logger) {
         $logger->indent--;
         if ($logger->indent == 0) {
             foreach ($callbackBenchmark as $cb => $i) {
                 $logger->info(sprintf("% 3d", $i['calls']) . "x " . sprintf("%3d", round($i['time'], 0)) . " ms: {$cb}");
             }
             $callbackBenchmark = array();
         }
     }
     self::$eventsCount++;
 }
 public static function getAllChainedByMaster($master, $chainedType, $parentDataSelect = array())
 {
     $cacheId = 'hasChainedBMCls-' . Kwf_Component_Data_Root::getComponentClass();
     $classes = Kwf_Cache_SimpleStatic::fetch($cacheId);
     if ($classes === false) {
         $classes = array();
         foreach (Kwc_Abstract::getComponentClasses() as $cls) {
             if (Kwc_Abstract::getFlag($cls, 'hasAllChainedByMaster')) {
                 $classes[] = $cls;
             }
         }
         Kwf_Cache_SimpleStatic::add($cacheId, $classes);
     }
     $ret = array();
     foreach ($classes as $cls) {
         $c = strpos($cls, '.') ? substr($cls, 0, strpos($cls, '.')) : $cls;
         $ret = array_merge($ret, call_user_func(array($c, 'getAllChainedByMasterFromChainedStart'), $cls, $master, $chainedType, $parentDataSelect));
     }
     return $ret;
 }
 public function getPathTypes()
 {
     if (isset($this->_pathTypesCache)) {
         return $this->_pathTypesCache;
     }
     if (isset($this->_pathTypesCacheId)) {
         $ret = Kwf_Cache_SimpleStatic::fetch($this->_pathTypesCacheId);
         if ($ret !== false) {
             $this->_pathTypesCache = $ret;
             return $ret;
         }
     }
     $ret = array('webComponents' => 'components', 'webThemes' => 'themes');
     $vendors[] = KWF_PATH;
     //required for kwf tests, in web kwf is twice in $vendors but that's not a problem
     $vendors[] = '.';
     $vendors = array_merge($vendors, glob(VENDOR_PATH . "/*/*"));
     foreach ($vendors as $i) {
         if (is_dir($i) && file_exists($i . '/dependencies.ini')) {
             $c = new Zend_Config_Ini($i . '/dependencies.ini');
             if ($c->config) {
                 $dep = new Zend_Config_Ini($i . '/dependencies.ini', 'config');
                 $pathType = (string) $dep->pathType;
                 if ($pathType) {
                     $ret[$pathType] = $i;
                 }
             }
         }
     }
     foreach ($this->_providers as $p) {
         $ret = array_merge($ret, $p->getPathTypes());
     }
     $ret['web'] = '.';
     Kwf_Cache_SimpleStatic::add($this->_pathTypesCacheId, $ret);
     $this->_pathTypesCache = $ret;
     return $ret;
 }
 public final function getSupportedChildContexts($generator)
 {
     $cacheId = 'layout-childctx-' . $this->_class . '-' . $generator;
     $ret = Kwf_Cache_SimpleStatic::fetch($cacheId, $success);
     if (!$success) {
         self::_loadFromBuild();
         if (!isset(self::$_supportedChildContexts[$this->_class])) {
             self::$_supportedChildContexts[$this->_class] = $this->calcSupportedChildContexts();
         }
         if (self::$_supportedChildContexts[$this->_class] && isset(self::$_supportedChildContexts[$this->_class][$generator])) {
             $ret = self::$_supportedChildContexts[$this->_class][$generator];
         } else {
             $ret = false;
         }
         Kwf_Cache_SimpleStatic::add($cacheId, $ret);
     }
     return $ret;
 }
Exemple #20
0
 public static final function getDependsOnRowInstances()
 {
     $ret = array();
     $cacheId = 'componentsWithDependsOnRow';
     if (!($componentsWithDependsOnRow = Kwf_Cache_SimpleStatic::fetch($cacheId))) {
         $componentsWithDependsOnRow = array();
         foreach (Kwc_Abstract::getComponentClasses() as $c) {
             $a = Kwc_Admin::getInstance($c);
             if ($a instanceof Kwf_Component_Abstract_Admin_Interface_DependsOnRow) {
                 $componentsWithDependsOnRow[] = $c;
             }
         }
         Kwf_Cache_SimpleStatic::add($cacheId, $componentsWithDependsOnRow);
     }
     foreach ($componentsWithDependsOnRow as $c) {
         $ret[] = Kwc_Admin::getInstance($c);
     }
     return $ret;
 }
 /**
  * Returns child components recursively
  *
  * This method usually is very efficient and tries to create as less data objects as possible.
  * It is still a complex operation thus should not get called too often.
  *
  * @param Kwf_Component_Select|array what to search for
  * @param Kwf_Component_Select|array how deep to search
  * @return array(Kwf_Component_Data)
  */
 public function getRecursiveChildComponents($select = array(), $childSelect = array('page' => false))
 {
     if (is_array($select)) {
         $select = new Kwf_Component_Select($select);
     } else {
         $select = clone $select;
     }
     Kwf_Benchmark::count('getRecursiveChildComponents');
     if (is_array($childSelect)) {
         $childSelect = new Kwf_Component_Select($childSelect);
     }
     $ret = $this->getChildComponents($select);
     if ($select->hasPart('limitCount') && $select->getPart('limitCount') <= count($ret)) {
         return $ret;
     }
     $genSelect = new Kwf_Component_Select();
     $genSelect->copyParts(array(Kwf_Component_Select::WHERE_HOME, Kwf_Component_Select::WHERE_PAGE, Kwf_Component_Select::WHERE_PSEUDO_PAGE, Kwf_Component_Select::WHERE_FLAGS, Kwf_Component_Select::WHERE_BOX, Kwf_Component_Select::WHERE_MULTI_BOX, Kwf_Component_Select::WHERE_SHOW_IN_MENU, Kwf_Component_Select::WHERE_COMPONENT_CLASSES, Kwf_Component_Select::WHERE_PAGE_GENERATOR, Kwf_Component_Select::WHERE_GENERATOR, Kwf_Component_Select::WHERE_HAS_EDIT_COMPONENTS, Kwf_Component_Select::WHERE_INHERIT, Kwf_Component_Select::WHERE_UNIQUE, Kwf_Component_Select::WHERE_GENERATOR_CLASS, Kwf_Component_Select::WHERE_COMPONENT_KEY), $select);
     $selectHash = md5($genSelect->getHash() . $childSelect->getHash());
     $cacheId = 'recCCGen-' . $selectHash . $this->componentClass . implode('__', $this->inheritClasses);
     $generators = Kwf_Cache_SimpleStatic::fetch($cacheId, $success);
     if (!$success) {
         //get (statically=fast and cached) all generators that could create the component we are looking for
         $generators = $this->_getRecursiveGenerators(Kwc_Abstract::getChildComponentClasses($this, $childSelect), $genSelect, $childSelect, $selectHash);
         Kwf_Cache_SimpleStatic::add($cacheId, $generators);
     }
     $noSubPages = $childSelect->hasPart('wherePage') && !$childSelect->getPart('wherePage') || $childSelect->hasPart('wherePseudoPage') && !$childSelect->getPart('wherePseudoPage');
     if ($noSubPages) {
         $select->whereChildOf($this);
     } else {
         $select->whereSubroot($this);
     }
     foreach ($generators as $g) {
         if ($g['type'] == 'notStatic') {
             $gen = Kwf_Component_Generator_Abstract::getInstance($g['class'], $g['key']);
             $s = clone $select;
             if (!$noSubPages) {
                 //unset limit as we may have filter away results
                 $s->unsetPart('limitCount');
             }
             foreach ($gen->getChildData(null, $s) as $d) {
                 $add = true;
                 if (!$noSubPages) {
                     // sucht über unterseiten hinweg, wird hier erst im Nachhinein gehandelt, langsam
                     $add = false;
                     $c = $d;
                     while (!$add && $c) {
                         if ($c->componentId == $this->componentId) {
                             $add = true;
                         }
                         $c = $c->parent;
                     }
                 }
                 if ($add && !in_array($d, $ret, true)) {
                     $ret[] = $d;
                     if ($select->hasPart('limitCount') && $select->getPart('limitCount') <= count($ret)) {
                         return $ret;
                     }
                 }
             }
         }
     }
     foreach ($generators as $k => $g) {
         if ($g['type'] == 'cards') {
             $lookingForDefault = true;
             if ($select->hasPart('whereComponentClasses')) {
                 $gen = Kwf_Component_Generator_Abstract::getInstance($g['class'], $g['key'], array(), $g['pluginBaseComponentClass']);
                 $classes = array_values($gen->getChildComponentClasses());
                 $defaultCardClass = $classes[0];
                 if (!in_array($defaultCardClass, $select->getPart('whereComponentClasses'))) {
                     $lookingForDefault = false;
                 }
             }
             if ($lookingForDefault) {
                 //we have to look for it like for a static component because it's the default value that might not be in the table
                 //this is not so efficient
                 $generators[$k]['type'] = 'static';
                 //(kind of hackish to change the type here but works for now)
             } else {
                 $gen = Kwf_Component_Generator_Abstract::getInstance($g['class'], $g['key'], array(), $g['pluginBaseComponentClass']);
                 foreach ($gen->getChildData(null, clone $select) as $d) {
                     $ret[] = $d;
                     if ($select->hasPart('limitCount') && $select->getPart('limitCount') <= count($ret)) {
                         return $ret;
                     }
                 }
             }
         }
     }
     $staticGeneratorComponentClasses = array();
     foreach ($generators as $k => $g) {
         if ($g['type'] == 'static') {
             if ($g['pluginBaseComponentClass']) {
                 $staticGeneratorComponentClasses[] = $g['pluginBaseComponentClass'];
             } else {
                 $staticGeneratorComponentClasses[] = $g['class'];
             }
         }
     }
     if ($staticGeneratorComponentClasses) {
         $pdSelect = clone $childSelect;
         $pdSelect->whereComponentClasses($staticGeneratorComponentClasses);
         $pdSelect->copyParts(array('ignoreVisible'), $select);
         $pd = $this->getRecursiveChildComponents($pdSelect, $childSelect);
         foreach ($generators as $k => $g) {
             if ($g['type'] == 'static') {
                 $parentDatas = array();
                 foreach ($pd as $d) {
                     if ($d->componentClass == $g['class'] || $d->componentClass == $g['pluginBaseComponentClass']) {
                         $parentDatas[] = $d;
                     }
                 }
                 if ($parentDatas) {
                     $gen = Kwf_Component_Generator_Abstract::getInstance($g['class'], $g['key'], array(), $g['pluginBaseComponentClass']);
                     foreach ($gen->getChildData($parentDatas, $select) as $d) {
                         if (!in_array($d, $ret, true)) {
                             $ret[] = $d;
                             if ($select->hasPart('limitCount') && $select->getPart('limitCount') <= count($ret)) {
                                 return $ret;
                             }
                         }
                     }
                 }
             }
         }
     }
     return $ret;
 }
 public function save($cacheData, $cacheId)
 {
     Kwf_Cache_SimpleStatic::add('asb-' . $cacheId, $cacheData);
     return self::_getFileCacheInstance()->save($cacheData, $cacheId);
 }
Exemple #23
0
 private function _getIconAndType()
 {
     $icon = $this->_icon;
     $type = $this->_type;
     if (!$type) {
         static $paths;
         if (!isset($paths)) {
             $cacheId = 'asset-paths';
             $paths = Kwf_Cache_SimpleStatic::fetch($cacheId);
             if ($paths === false) {
                 $paths = array('web' => '.');
                 $vendors = glob(VENDOR_PATH . "/*/*");
                 $vendors[] = KWF_PATH;
                 //required for kwf tests, in web kwf is twice in $vendors but that's not a problem
                 foreach ($vendors as $i) {
                     if (is_dir($i) && file_exists($i . '/dependencies.ini')) {
                         $dep = new Zend_Config_Ini($i . '/dependencies.ini', 'config');
                         $paths[$dep->pathType] = $i;
                     }
                 }
                 Kwf_Cache_SimpleStatic::add($cacheId, $paths);
             }
         }
         if (file_exists($paths['silkicons'] . '/' . $icon)) {
             $filename = $paths['silkicons'] . '/' . $icon;
             $type = 'silkicons';
         } else {
             if (file_exists($paths['silkicons'] . '/' . $icon . '.png')) {
                 $filename = $paths['silkicons'] . '/' . $icon . '.png';
                 $type = 'silkicons';
                 $icon .= '.png';
             } else {
                 if (file_exists($paths['kwf'] . '/images/' . $icon . '.png')) {
                     $filename = $paths['kwf'] . '/images/' . $icon . '.png';
                     $type = 'kwf/images';
                     $icon .= '.png';
                 } else {
                     if (file_exists($paths['kwf'] . '/images/' . $icon . '.gif')) {
                         $filename = $paths['kwf'] . '/images/' . $icon . '.gif';
                         $type = 'kwf/images';
                         $icon .= '.gif';
                     } else {
                         if (file_exists($paths['kwf'] . '/images/' . $icon . '.jpg')) {
                             $filename = $paths['kwf'] . '/images/' . $icon . '.jpg';
                             $type = 'kwf/images';
                             $icon .= '.jpg';
                         } else {
                             if (file_exists($paths['kwf'] . '/images/fileicons/' . $icon . '.png')) {
                                 $filename = $paths['kwf'] . '/images/fileicons/' . $icon . '.png';
                                 $type = 'kwf/images/fileicons';
                                 $icon .= '.png';
                             } else {
                                 if (file_exists($paths['kwf'] . '/images/fileicons/' . $icon . '.jpg')) {
                                     $filename = $paths['kwf'] . '/images/fileicons/' . $icon . '.jpg';
                                     $type = 'kwf/images/fileicons';
                                     $icon .= '.jpg';
                                 } else {
                                     if (file_exists($paths['web'] . '/images/icons/' . $icon)) {
                                         $filename = $paths['web'] . '/images/icons/' . $icon;
                                         $type = 'web/images/icons/';
                                     } else {
                                         if (file_exists($paths['web'] . '/images/icons/' . $icon . '.png')) {
                                             $filename = $paths['web'] . '/images/icons/' . $icon;
                                             $type = 'web/images/icons/';
                                             $icon .= '.png';
                                         } else {
                                             throw new Kwf_Exception("Asset '{$icon}' not found");
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return array('type' => $type, 'icon' => $icon);
 }
 protected function _findElementPlural($needle, $plural, $source, $context = '', $language = null)
 {
     if ($language) {
         $target = $language;
     } else {
         $target = $this->getTargetLanguage();
     }
     $cacheId = 'trlp-' . $source . '-' . $target . '-' . $plural . '-' . $context;
     $ret = Kwf_Cache_SimpleStatic::fetch($cacheId, $success);
     if ($success) {
         return $ret;
     }
     if (!isset($this->_trlElements[$source][$target . '_plural'])) {
         $this->_loadTrlElements($source, $target, true);
     }
     if (isset($this->_trlElements[$source][$target . '_plural'][$plural . '-' . $context])) {
         $ret = $this->_trlElements[$source][$target . '_plural'][$plural . '-' . $context];
     } else {
         $ret = $plural;
     }
     Kwf_Cache_SimpleStatic::add($cacheId, $ret);
     return $ret;
 }
 public static function getFlag($class, $flag)
 {
     $cacheId = 'flag-' . $class . '-' . $flag;
     $ret = Kwf_Cache_SimpleStatic::fetch($cacheId, $success);
     if ($success) {
         return $ret;
     }
     $flags = self::getSetting($class, 'flags');
     if (!isset($flags[$flag])) {
         $ret = false;
     } else {
         $ret = $flags[$flag];
     }
     Kwf_Cache_SimpleStatic::add($cacheId, $ret);
     return $ret;
 }
 /**
  * Initializes metadata.
  *
  * If metadata cannot be loaded from cache, adapter's describeTable() method is called to discover metadata
  * information. Returns true if and only if the metadata are loaded from cache.
  *
  * @return boolean
  * @throws Kwf_Exception
  */
 protected function _setupMetadata()
 {
     if (count($this->_metadata) > 0) {
         return true;
     }
     // Assume that metadata will be loaded from cache
     $isMetadataFromCache = true;
     // Define the cache identifier where the metadata are saved
     //get db configuration
     $dbConfig = $this->_db->getConfig();
     $port = isset($dbConfig['options']['port']) ? ':' . $dbConfig['options']['port'] : (isset($dbConfig['port']) ? ':' . $dbConfig['port'] : null);
     $host = isset($dbConfig['options']['host']) ? ':' . $dbConfig['options']['host'] : (isset($dbConfig['host']) ? ':' . $dbConfig['host'] : null);
     // Define the cache identifier where the metadata are saved
     $cacheId = 'dbtbl_' . md5($port . $host . '/' . $dbConfig['dbname'] . ':' . $this->_schema . '.' . $this->_name);
     // If $this has no metadata cache or metadata cache misses
     if (!($metadata = Kwf_Cache_SimpleStatic::fetch($cacheId))) {
         // Metadata are not loaded from cache
         $isMetadataFromCache = false;
         // Fetch metadata from the adapter's describeTable() method
         $metadata = $this->_db->describeTable($this->_name, $this->_schema);
         // If $this has a metadata cache, then cache the metadata
         Kwf_Cache_SimpleStatic::add($cacheId, $metadata);
     }
     // Assign the metadata to $this
     $this->_metadata = $metadata;
     // Return whether the metadata were loaded from cache
     return $isMetadataFromCache;
 }
Exemple #27
0
 public function getTemplateVars()
 {
     $ret = Kwc_Abstract::getTemplateVars();
     $this->_checkWasProcessed();
     $ret['isPosted'] = $this->_posted;
     $ret['showSuccess'] = false;
     $ret['errors'] = Kwf_Form::formatValidationErrors($this->getErrors());
     if ($this->isSaved()) {
         if (!$ret['errors'] && $this->getSuccessComponent()) {
             $ret['showSuccess'] = true;
         }
     }
     if ($ret['showSuccess']) {
         $ret['success'] = $this->getSuccessComponent();
     } else {
         foreach ($this->getData()->getChildComponents(array('generator' => 'child')) as $c) {
             if ($c->id != 'success') {
                 $ret[$c->id] = $c;
             }
         }
     }
     if (!$ret['showSuccess']) {
         $values = $this->getForm()->load(null, $this->_postData);
         $ret['form'] = $this->getForm()->getTemplateVars($values, '', $this->getData()->componentId . '_');
         $dec = $this->_getSetting('decorator');
         if ($dec && is_string($dec)) {
             $dec = new $dec();
             $ret['form'] = $dec->processItem($ret['form'], $this->getErrors());
         }
         $ret['formName'] = $this->getData()->componentId;
         $ret['buttonClass'] = $this->_getSetting('buttonClass');
         $ret['formId'] = $this->getForm()->getId();
         if ($ret['formId']) {
             $ret['formIdHash'] = Kwf_Util_Hash::hash($ret['formId']);
         }
         $page = $this->getData()->getPage();
         if (!$page) {
             throw new Kwf_Exception('Form must have an url so it must be on a page but is on "' . $this->getData()->componentId . '". (If component is a box it must not be unique)');
         }
         $cachedContent = Kwf_Component_Cache::getInstance()->load($page->componentId, 'componentLink');
         if ($cachedContent) {
             $targetPage = unserialize($cachedContent);
             $ret['action'] = $targetPage[0];
         } else {
             $ret['action'] = $this->getData()->url;
         }
         if (isset($_SERVER["QUERY_STRING"])) {
             $ret['action'] .= '?' . $_SERVER["QUERY_STRING"];
         }
         $ret['method'] = $this->_getSetting('method');
     }
     $ret['isUpload'] = false;
     foreach (new RecursiveIteratorIterator(new Kwf_Collection_Iterator_RecursiveFormFields($this->getForm()->fields)) as $f) {
         if ($f instanceof Kwf_Form_Field_File) {
             $ret['isUpload'] = true;
             break;
         }
     }
     $ret['message'] = null;
     $cacheId = 'kwcFormCu-' . get_class($this);
     $controllerUrl = Kwf_Cache_SimpleStatic::fetch($cacheId);
     if (!$controllerUrl) {
         $controllerUrl = Kwc_Admin::getInstance(get_class($this))->getControllerUrl('FrontendForm');
         Kwf_Cache_SimpleStatic::add($cacheId, $controllerUrl);
     }
     $hideForValue = array();
     foreach ($this->_form->getHideForValue() as $v) {
         $hideForValue[] = array('field' => $v['field']->getFieldName(), 'value' => $v['value'], 'hide' => $v['hide']->getFieldName());
     }
     $baseParams = $this->_getBaseParams();
     $baseParams['componentId'] = $this->getData()->componentId;
     $fieldConfig = array();
     $iterator = new RecursiveIteratorIterator(new Kwf_Collection_Iterator_RecursiveFormFields($this->_form->fields), RecursiveIteratorIterator::SELF_FIRST);
     foreach ($iterator as $field) {
         if ($field->getFieldName()) {
             $fieldConfig[$field->getFieldName()] = (object) $field->getFrontendMetaData();
         }
     }
     $errorStyle = $this->_getSetting('errorStyle');
     if (!$errorStyle) {
         $errorStyle = Kwf_Config::getValue('kwc.form.errorStyle');
     }
     $ret['config'] = array('controllerUrl' => $controllerUrl, 'useAjaxRequest' => $this->_getSetting('useAjaxRequest'), 'hideFormOnSuccess' => $this->_getSetting('hideFormOnSuccess'), 'componentId' => $this->getData()->componentId, 'hideForValue' => $hideForValue, 'fieldConfig' => (object) $fieldConfig, 'errorStyle' => $errorStyle, 'baseParams' => $baseParams);
     $ret['uniquePrefix'] = Kwf_Config::getValue('application.uniquePrefix');
     if ($ret['uniquePrefix']) {
         $ret['uniquePrefix'] .= '-';
     }
     return $ret;
 }
 public static function getComponentTemplate($componentClass, $type = 'Component')
 {
     $cacheId = 'twig-cmp-' . $componentClass . '-' . $type;
     $ret = Kwf_Cache_SimpleStatic::fetch($cacheId);
     if ($ret !== false) {
         return $ret;
     }
     $file = null;
     if ($type == 'Master' && Kwc_Abstract::hasSetting($componentClass, 'masterTemplate') && Kwc_Abstract::getSetting($componentClass, 'masterTemplate')) {
         $relativeToIncludePath = Kwc_Abstract::getSetting($componentClass, 'masterTemplate');
     } else {
         static $namespaces;
         if (!isset($namespaces)) {
             $namespaces = (include VENDOR_PATH . '/composer/autoload_namespaces.php');
         }
         $pos = strpos($componentClass, '_');
         $ns1 = substr($componentClass, 0, $pos + 1);
         $pos = strpos($componentClass, '_', $pos + 1);
         if ($pos !== false) {
             $ns2 = substr($componentClass, 0, $pos + 1);
         } else {
             $ns2 = $componentClass;
         }
         $relativeToIncludePath = $componentClass;
         if (substr($relativeToIncludePath, -10) == '_Component') {
             $relativeToIncludePath = substr($relativeToIncludePath, 0, -10);
         }
         $relativeToIncludePath .= '_' . $type;
         $relativeToIncludePath = str_replace('_', '/', $relativeToIncludePath) . '.twig';
         $dirs = false;
         if (isset($namespaces[$ns2])) {
             $dirs = $namespaces[$ns2];
         } else {
             if (isset($namespaces[$ns1])) {
                 $dirs = $namespaces[$ns1];
             }
         }
         if ($dirs !== false) {
             if (count($dirs) == 1) {
                 $file = $dirs[0] . '/' . $relativeToIncludePath;
             } else {
                 foreach ($dirs as $dir) {
                     if (file_exists($dir . '/' . $relativeToIncludePath)) {
                         $dir = rtrim($dir, '/');
                         if (VENDOR_PATH == '../vendor') {
                             //hack for tests. proper solution would be not to change cwd into /tests
                             if ($dir == KWF_PATH) {
                                 $dir = '..';
                             }
                         }
                         $file = $dir . '/' . $relativeToIncludePath;
                         break;
                     }
                 }
             }
         }
     }
     if ($file) {
         $ret = $file;
     } else {
         $ret = null;
         foreach (explode(PATH_SEPARATOR, get_include_path()) as $ip) {
             $file = $ip . '/' . $relativeToIncludePath;
             if (file_exists(getcwd() . '/' . $file)) {
                 $ret = getcwd() . '/' . $file;
                 break;
             }
         }
         if (!$ret) {
             throw new Kwf_Exception("Can't find {$type} template for {$componentClass} {$relativeToIncludePath}");
         }
     }
     if (VENDOR_PATH == '../vendor') {
         $cwd = getcwd();
         $cwd = substr($cwd, 0, strrpos($cwd, '/'));
         if (substr($ret, 0, strlen($cwd)) != $cwd) {
             throw new Kwf_Exception("'{$ret}' not in cwd");
         }
         $ret = '../' . substr($ret, strlen($cwd) + 1);
     } else {
         if (substr($ret, 0, strlen(getcwd())) != getcwd()) {
             throw new Kwf_Exception("'{$ret}' not in cwd");
         }
         $ret = substr($ret, strlen(getcwd()) + 1);
     }
     Kwf_Cache_SimpleStatic::add($cacheId, $ret);
     return $ret;
 }
 /**
  * Helper function that returns the dbIdShortcuts that can be used below a componentClass (only across page)
  *
  * Static, fast and cached.
  */
 protected function _getPossibleIndirectDbIdShortcuts($class)
 {
     $cacheId = '-poss-dbid-sc-' . $this->_class . '-' . $this->getGeneratorKey() . '-' . $class;
     $ret = Kwf_Cache_SimpleStatic::fetch($cacheId, $success);
     if (!$success) {
         $ret = $this->_getPossibleIndirectDbIdShortcutsImpl($class);
         $ret = array_unique($ret);
         Kwf_Cache_SimpleStatic::add($cacheId, $ret);
     }
     return $ret;
 }
 private function _getGeneratorsForClasses($lookingForClasses)
 {
     $cacheId = 'genForCls' . $this->getComponentClass() . str_replace('.', '_', implode('', $lookingForClasses));
     if (isset($this->_generatorsForClassesCache[$cacheId])) {
     } else {
         if (($generators = Kwf_Cache_SimpleStatic::fetch($cacheId)) !== false) {
             $ret = array();
             foreach ($generators as $g) {
                 $ret[] = Kwf_Component_Generator_Abstract::getInstance($g[0], $g[1]);
             }
             $this->_generatorsForClassesCache[$cacheId] = $ret;
         } else {
             $generators = array();
             foreach (Kwc_Abstract::getComponentClasses() as $c) {
                 foreach (Kwc_Abstract::getSetting($c, 'generators') as $key => $generator) {
                     foreach ($generator['component'] as $childClass) {
                         if (in_array($childClass, $lookingForClasses)) {
                             $generators[$c . $key] = array($c, $key);
                         }
                     }
                 }
             }
             $generators = array_values($generators);
             Kwf_Cache_SimpleStatic::add($cacheId, $generators);
             $ret = array();
             foreach ($generators as $g) {
                 $ret[] = Kwf_Component_Generator_Abstract::getInstance($g[0], $g[1]);
             }
             $this->_generatorsForClassesCache[$cacheId] = $ret;
         }
     }
     return $this->_generatorsForClassesCache[$cacheId];
 }