private function _getAssetPath($image)
 {
     $url = $this->_getImageUrl($image);
     if (stripos($url, "/assets/") === 0) {
         $file = new Kwf_Assets_Dependency_File(Kwf_Assets_ProviderList_Default::getInstance(), substr($url, 8));
         return $file->getAbsoluteFileName();
     } else {
         throw new Kwf_Exception("Path does not include '/assets/'. Not implemented yet.");
     }
 }
 /**
  * @internal
  */
 public static function _buildAll($componentClasses)
 {
     $masterLayouts = "\$all-master-layouts: ();\n";
     foreach (Kwc_Abstract::getComponentClasses() as $c) {
         if (Kwc_Abstract::hasSetting($c, 'masterLayout')) {
             $masterLayout = Kwc_Abstract::getSetting($c, 'masterLayout');
             $f = new Kwf_Assets_Dependency_File(Kwf_Assets_ProviderList_Default::getInstance(), $masterLayout['layoutConfig']);
             $masterLayouts .= $f->getContentsSourceString() . "\n";
             $masterLayouts .= "\$all-master-layouts: map-merge(\$all-master-layouts, \$master-layouts);\n";
         }
     }
     $masterLayouts .= "\$master-layouts: \$all-master-layouts;\n";
     $masterLayouts .= "\$all-master-layouts: null\n";
     $file = "temp/scss-generated/config/_master-layouts.scss";
     if (!is_dir(dirname($file))) {
         mkdir(dirname($file), 0777, true);
     }
     if (!file_exists($file) || file_get_contents($file) != $masterLayouts) {
         //only modify if actually changed
         file_put_contents($file, $masterLayouts);
     }
     foreach ($componentClasses as $cmp) {
         if (Kwc_Abstract::hasSetting($cmp, 'masterLayout')) {
             self::getInstance($cmp)->_build();
         }
     }
     foreach ($componentClasses as $cmp) {
         if (Kwc_Abstract::hasSetting($cmp, 'masterLayout')) {
             //fills $_supportedContexts and $_supportedBoxContexts
             self::getInstance($cmp)->getSupportedContexts();
             self::getInstance($cmp)->_getSupportedBoxesContexts();
         }
     }
     $data = array('contexts' => self::$_supportedContexts, 'boxContexts' => self::$_supportedBoxContexts);
     file_put_contents('build/component/masterlayoutcontexts', serialize($data));
 }
 public function getFilename()
 {
     $d = $this->_getIconAndType();
     $file = new Kwf_Assets_Dependency_File(Kwf_Assets_ProviderList_Default::getInstance(), $d['type'] . '/' . $d['icon']);
     return $file->getAbsoluteFileName();
 }
 public function getFileContents($file)
 {
     $ret = array();
     $checkSourceAccess = false;
     if (substr($file, -4) == '.gif') {
         $ret['mimeType'] = 'image/gif';
     } else {
         if (substr($file, -4) == '.png') {
             $ret['mimeType'] = 'image/png';
         } else {
             if (substr($file, -4) == '.jpg') {
                 $ret['mimeType'] = 'image/jpeg';
             } else {
                 if (substr($file, -4) == '.mp4') {
                     $ret['mimeType'] = 'video/mp4';
                 } else {
                     if (substr($file, -5) == '.webm') {
                         $ret['mimeType'] = 'video/webm';
                     } else {
                         if (substr($file, -4) == '.css' || substr($file, -5) == '.scss') {
                             $ret['mimeType'] = 'text/css; charset=utf-8';
                             $checkSourceAccess = true;
                         } else {
                             if (substr($file, -3) == '.js') {
                                 $ret['mimeType'] = 'text/javascript; charset=utf-8';
                                 $checkSourceAccess = true;
                             } else {
                                 if (substr($file, -4) == '.swf') {
                                     $ret['mimeType'] = 'application/flash';
                                 } else {
                                     if (substr($file, -4) == '.ico') {
                                         $ret['mimeType'] = 'image/x-icon';
                                     } else {
                                         if (substr($file, -5) == '.html') {
                                             $ret['mimeType'] = 'text/html; charset=utf-8';
                                         } else {
                                             if (substr($file, -4) == '.otf') {
                                                 // für Schriften
                                                 $ret['mimeType'] = 'application/octet-stream';
                                             } else {
                                                 if (substr($file, -4) == '.eot') {
                                                     // für Schriften
                                                     $ret['mimeType'] = 'application/vnd.ms-fontobject';
                                                 } else {
                                                     if (substr($file, -4) == '.svg') {
                                                         // für Schriften
                                                         $ret['mimeType'] = 'image/svg+xml';
                                                     } else {
                                                         if (substr($file, -4) == '.ttf') {
                                                             // für Schriften
                                                             $ret['mimeType'] = 'application/octet-stream';
                                                         } else {
                                                             if (substr($file, -5) == '.woff') {
                                                                 // für Schriften
                                                                 $ret['mimeType'] = 'application/font-woff';
                                                             } else {
                                                                 if (substr($file, -6) == '.woff2') {
                                                                     // für Schriften
                                                                     $ret['mimeType'] = 'application/font-woff2';
                                                                 } else {
                                                                     if (substr($file, -4) == '.htc') {
                                                                         // für ie css3
                                                                         $ret['mimeType'] = 'text/x-component';
                                                                     } else {
                                                                         if (substr($file, -4) == '.pdf') {
                                                                             $ret['mimeType'] = 'application/pdf';
                                                                         } else {
                                                                             if (substr($file, -4) == '.xml') {
                                                                                 $ret['mimeType'] = 'application/xml; charset=utf-8';
                                                                             } else {
                                                                                 throw new Kwf_Assets_NotFoundException("Invalid filetype ({$file})");
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($checkSourceAccess) {
         $sourceAccess = Kwf_Config::getValueArray('assets.sourceAccess');
         $access = false;
         if ($sourceAccess) {
             $access = in_array($file, $sourceAccess);
         }
         if (!$access && !Kwf_Assets_Dispatcher::getInstance()->allowSourceAccess()) {
             throw new Kwf_Exception_AccessDenied();
         }
     }
     if (substr($ret['mimeType'], 0, 5) == 'text/') {
         $ret['mtime'] = time();
         $file = new Kwf_Assets_Dependency_File(Kwf_Assets_ProviderList_Default::getInstance(), $file);
         if (!$file->getAbsoluteFileName() || !file_exists($file->getAbsoluteFileName())) {
             throw new Kwf_Exception_NotFound();
         }
         $ret['contents'] = file_get_contents($file->getAbsoluteFileName());
     } else {
         $fx = substr($file, 0, strpos($file, '/'));
         if (substr($fx, 0, 3) == 'fx_') {
             $cache = Kwf_Assets_Cache::getInstance();
             $cacheId = 'fileContents' . str_replace(array('/', '.', '-', ':'), array('_', '_', '_', '_'), $file);
             if (!($cacheData = $cache->load($cacheId))) {
                 if (substr($ret['mimeType'], 0, 6) != 'image/') {
                     throw new Kwf_Exception("Fx is only possible for images");
                 }
                 $im = new Imagick();
                 if (substr($file, -4) == '.ico') {
                     $im->setFormat('ico');
                 }
                 //required because imagick can't autodetect ico format
                 $file = new Kwf_Assets_Dependency_File(Kwf_Assets_ProviderList_Default::getInstance(), substr($file, strpos($file, '/') + 1));
                 $im->readImage($file->getAbsoluteFileName());
                 $fx = explode('_', substr($fx, 3));
                 foreach ($fx as $i) {
                     $params = array();
                     if (($pos = strpos($i, '-')) !== false) {
                         $params = explode('-', substr($i, $pos + 1));
                         $i = substr($i, 0, $pos);
                     }
                     call_user_func(array('Kwf_Assets_Effects', $i), $im, $params);
                 }
                 $cacheData['contents'] = $im->getImagesBlob();
                 $im->destroy();
                 $cache->save($cacheData, $cacheId);
             }
             $ret['contents'] = $cacheData['contents'];
             $ret['mtime'] = time();
         } else {
             $ret['mtime'] = time();
             $file = new Kwf_Assets_Dependency_File(Kwf_Assets_ProviderList_Default::getInstance(), $file);
             if (!file_exists($file->getAbsoluteFileName())) {
                 throw new Kwf_Exception_NotFound();
             }
             $ret['contents'] = file_get_contents($file->getAbsoluteFileName());
         }
     }
     return $ret;
 }