protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!file_exists('bootstrap.php')) {
         throw new \Exception("Run this script in the application root directory");
     }
     \Kwf_Setup::setUp();
     if (file_exists('setup/initial/dump.sql')) {
         unlink('setup/initial/dump.sql');
     }
     if (file_exists('setup/initial/uploads')) {
         foreach (glob('setup/initial/uploads/*') as $f) {
             unlink($f);
         }
     }
     if ($input->getOption('include-initial-dump')) {
         $output->writeln("checking for pending updates...");
         $pendingUpdatesCount = \Kwf_Util_Update_Helper::countPendingUpdates();
         if ($pendingUpdatesCount) {
             throw new \Exception("{$pendingUpdatesCount} Updates have not been executed. Run update first.");
         }
         $output->writeln("creating database dump...");
         $dump = DbDump::dump();
         if (!file_exists('setup/initial')) {
             mkdir('setup/initial', 0777, true);
             $ignore = "";
             if (file_exists('setup/.gitignore')) {
                 $ignore = file_get_contents('setup/.gitignore');
             }
             if (!preg_match('#^initial$#m', $ignore)) {
                 $ignore = rtrim($ignore);
                 if ($ignore) {
                     $ignore .= "\n";
                 }
                 $ignore .= "initial\n";
             }
             file_put_contents('setup/.gitignore', $ignore);
         }
         file_put_contents('setup/initial/dump.sql', $dump);
         $output->writeln("copying uploads...");
         if (!file_exists('setup/initial/uploads')) {
             mkdir('setup/initial/uploads');
         }
         $model = \Kwf_Model_Abstract::getInstance('Kwf_Uploads_Model');
         $select = new \Kwf_Model_Select();
         $it = new \Kwf_Model_Iterator_Packages(new \Kwf_Model_Iterator_Rows($model, $select));
         foreach ($it as $row) {
             $fileSource = $row->getFileSource();
             copy($fileSource, 'setup/initial/uploads/' . basename($fileSource));
         }
     }
     $excludes = ExcludeFinder::findExcludes('.');
     $excludeArgs = '';
     foreach ($excludes as $i) {
         $excludeArgs .= " -x " . escapeshellarg('./' . $i . '*');
     }
     $cmd = "zip deploy.zip . --quiet -r {$excludeArgs}";
     $output->writeln("creating deploy.zip archive...");
     $this->_systemCheckRet($cmd, $input, $output);
     $output->writeln("deploy.zip successfully created.");
 }
示例#2
0
 /**
  *
  * @param string
  * @param string
  * @param string
  * @param string
  * @param int Kann gesetzt werden wenn wir in diesem web auf das bild nicht direkten zugriff haben
  *            sondern nur für ein anderes web die url generieren
  */
 public static function getUrl($class, $id, $type, $filename, $time = null)
 {
     if ($filename instanceof Kwf_Uploads_Row) {
         $filename = $filename->filename . '.' . $filename->extension;
     }
     if ($filename == '.') {
         $filename = '';
     }
     //Replace Slashes and Backslashes with an underscore
     //Otherwise we would get a wrong url
     //e.g. $filename = foo/bar.png -> /media/FooModel/1/default/ab123/1234/foo/bar.png
     $filename = str_replace('/', '_', $filename);
     $filename = str_replace('\\', '_', $filename);
     $checksumType = $type;
     if (substr($type, 0, strlen(Kwf_Media::DONT_HASH_TYPE_PREFIX)) == Kwf_Media::DONT_HASH_TYPE_PREFIX) {
         $checksumType = Kwf_Media::DONT_HASH_TYPE_PREFIX;
     }
     $class = rawurlencode($class);
     $checksum = self::getChecksum($class, $id, $checksumType, rawurlencode($filename));
     $prefix = Kwf_Setup::getBaseUrl();
     if ($r = Kwf_Component_Data_Root::getInstance()) {
         if ($r->filename) {
             $prefix .= '/' . $r->filename;
         }
     }
     if (is_null($time)) {
         $cacheId = 'mtime-' . self::createCacheId($class, $id, $type);
         $time = Kwf_Media_MemoryCache::getInstance()->load($cacheId);
         if (!$time) {
             $time = time();
             Kwf_Media_MemoryCache::getInstance()->save($time, $cacheId);
         }
     }
     return $prefix . '/media/' . $class . '/' . $id . '/' . $type . '/' . $checksum . '/' . $time . '/' . rawurlencode($filename);
 }
 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'));
 }
示例#4
0
 public static function afterStart()
 {
     static $validatorsRegistered = false;
     if (!$validatorsRegistered) {
         if (isset($_SESSION['__KWF']['VALID'])) {
             self::_processValidators();
         }
         //sessions timeout after 15-20 minutes of inactivity
         //this is in addition to gc_maxlifetime (which isn't reliable enough)
         $sessionTimeout = 20 * 60;
         if (!isset($_SESSION['kwfTimeout'])) {
             $_SESSION['kwfTimeout'] = time() + $sessionTimeout;
         } else {
             if ($_SESSION['kwfTimeout'] - time() < 0) {
                 $_SESSION = array();
                 $_SESSION['kwfTimeout'] = time() + $sessionTimeout;
                 Zend_Session::regenerateId();
             } else {
                 if ($_SESSION['kwfTimeout'] - time() < $sessionTimeout - 5 * 60) {
                     //extend timeout every 5 minutes (not in every request for better performance)
                     $_SESSION['kwfTimeout'] = time() + $sessionTimeout;
                 }
             }
         }
         if (!isset($_SESSION['__KWF']['VALID'])) {
             Zend_Session::registerValidator(new Kwf_Session_Validator_HttpHost());
             if (Kwf_Setup::getBaseUrl()) {
                 Zend_Session::registerValidator(new Kwf_Session_Validator_BasePath());
             }
             Zend_Session::registerValidator(new Kwf_Session_Validator_RemoteAddr());
         }
         $validatorsRegistered = true;
     }
 }
 public function processInput($postData)
 {
     if (isset($postData['redirectAuth'])) {
         $authMethods = Kwf_Registry::get('userModel')->getAuthMethods();
         if (!isset($authMethods[$postData['redirectAuth']])) {
             throw new Kwf_Exception_NotFound();
         }
         $auth = $authMethods[$postData['redirectAuth']];
         if (!$auth instanceof Kwf_User_Auth_Interface_Redirect) {
             throw new Kwf_Exception_NotFound();
         }
         $formValues = array();
         foreach ($auth->getLoginRedirectFormOptions() as $option) {
             if ($option['type'] == 'select') {
                 $formValues[$option['name']] = $postData[$option['name']];
             }
         }
         $redirectBackUrl = Kwf_Setup::getBaseUrl() . '/';
         $f = new Kwf_Filter_StrongRandom();
         $state = 'activate-' . $postData['redirectAuth'] . '-' . $f->filter(null) . '-' . $postData['code'] . '-' . $redirectBackUrl;
         //save state in namespace to validate it later
         $ns = new Kwf_Session_Namespace('kwf-login-redirect');
         $ns->state = $state;
         $url = $auth->getLoginRedirectUrl($this->_getRedirectBackUrl(), $state, $formValues);
         header("Location: " . $url);
         exit;
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     \Kwf_Setup::setUp();
     $dbConfig = \Kwf_Registry::get('dao')->getDbConfig();
     $cacheTables = \Kwf_Util_ClearCache::getInstance()->getDbCacheTables();
     $dumpCmd = "mysqldump";
     $dumpCmd .= " --host=" . escapeshellarg($dbConfig['host']);
     $dumpCmd .= " --user="******" --password="******" --ignore-table=" . escapeshellarg($dbConfig['dbname'] . '.' . $t);
     }
     $cmd .= " {$dbConfig['dbname']}";
     passthru($cmd, $ret);
     if ($ret) {
         return $ret;
     }
     foreach ($cacheTables as $t) {
         $cmd = $dumpCmd;
         $cmd .= " --no-data " . escapeshellarg($dbConfig['dbname']) . " " . escapeshellarg($t);
         passthru($cmd, $ret);
         if ($ret) {
             return $ret;
         }
     }
     return 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'));
 }
 protected function _clearCache($options)
 {
     if (!Kwf_Setup::hasDb()) {
         $this->_output("skipped: (no db configured)\n");
         return;
     }
     Kwf_Component_Cache_Url_Abstract::getInstance()->clear();
 }
 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 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;
 }
示例#11
0
 public static function dispatch($logModel = 'Kwf_Util_PayPal_Ipn_LogModel')
 {
     $url = Kwf_Setup::getRequestPath();
     if ($url != '/wirecard_confirm') {
         return;
     }
     self::process($logModel);
     echo 'OK';
     exit;
 }
 protected function _clearCache($options)
 {
     $url = Kwf_Config::getValue('assetsCacheUrl') . '?web=' . Kwf_Config::getValue('application.id') . '&section=' . Kwf_Setup::getConfigSection() . '&clear';
     try {
         $out = file_get_contents($url);
         $this->_output("cleared:     assetsServer [" . $out . "]\n");
     } catch (Exception $e) {
         $this->_output("cleared:     assetsServer [ERROR] " . $e->getMessage() . "\n");
     }
 }
 public static function getSessionToken()
 {
     if (!Kwf_Setup::hasAuthedUser()) {
         return null;
     }
     $ns = new Kwf_Session_Namespace('sessionToken');
     if (!$ns->token) {
         $ns->token = md5(microtime() . mt_rand());
     }
     return $ns->token;
 }
示例#14
0
 public function __construct($config = array())
 {
     if (isset($config['prefix'])) {
         $this->_prefix = $config['prefix'];
     } else {
         $this->_prefix = Zend_Registry::get('config')->application->id . '-' . Kwf_Setup::getConfigSection() . '-bench-';
     }
     if (isset($config['memcache'])) {
         $this->_memcache = $config['memcache'];
     }
 }
 /**
  * Proxy, der zB für cross-domain ajax requests verwendet werden kann
  *
  * @param string|array $hosts Erlaubte Hostnamen (RegExp erlaubt, ^ vorne und $ hinten werden autom. angefügt)
  */
 public static function dispatch($hostnames)
 {
     if (Kwf_Setup::getRequestPath() === false) {
         return;
     }
     if (!preg_match('#^/kwf/proxy/?$#i', Kwf_Setup::getRequestPath())) {
         return;
     }
     if (is_string($hostnames)) {
         $hostnames = array($hostnames);
     }
     $proxyUrl = $_REQUEST['proxyUrl'];
     $proxyPostVars = $_POST;
     $proxyGetVars = $_GET;
     if (array_key_exists('proxyUrl', $proxyPostVars)) {
         unset($proxyPostVars['proxyUrl']);
     }
     if (array_key_exists('proxyUrl', $proxyGetVars)) {
         unset($proxyGetVars['proxyUrl']);
     }
     // host checking
     $proxyHost = parse_url($proxyUrl, PHP_URL_HOST);
     $matched = false;
     foreach ($hostnames as $hostname) {
         if (preg_match('/^' . $hostname . '$/i', $proxyHost)) {
             $matched = true;
             break;
         }
     }
     if (!$matched) {
         return;
     }
     // proxying
     $http = new Zend_Http_Client($proxyUrl);
     if (count($_POST)) {
         $http->setMethod(Zend_Http_Client::POST);
     } else {
         $http->setMethod(Zend_Http_Client::GET);
     }
     if (count($_GET)) {
         $http->setParameterGet($proxyGetVars);
     }
     if (count($_POST)) {
         $http->setParameterPost($proxyPostVars);
     }
     $response = $http->request();
     $headers = $response->getHeaders();
     if ($headers && !empty($headers['Content-type'])) {
         header("Content-Type: " . $headers['Content-type']);
     }
     echo $response->getBody();
     exit;
 }
 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;
     }
     if (!Kwf_Setup::hasDb()) {
         $this->_output("skipped: (no db configured)\n");
         return;
     }
     Kwf_Component_Cache::getInstance()->deleteViewCache(array());
 }
示例#17
0
 public static function redirect($url)
 {
     $url = (string) $url;
     if (!$url) {
         $url = '/';
     }
     if (substr($url, 0, strlen(Kwf_Setup::getBaseUrl()) + 1) !== Kwf_Setup::getBaseUrl() . '/') {
         throw new Kwf_Exception('Invalid Url');
     }
     header('Location: ' . $url);
     exit;
 }
 public function indexAction()
 {
     $this->view->config = array('responsive' => Kwf_Config::getValue('kwc.responsive'));
     $this->view->xtype = 'kwf.component.preview';
     $this->view->initialUrl = null;
     if (preg_match('#^https?://#', $this->_getParam('url'))) {
         $this->view->initialUrl = $this->_getParam('url');
     }
     if (!$this->view->initialUrl) {
         $this->view->initialUrl = 'http://' . $_SERVER['HTTP_HOST'] . Kwf_Setup::getBaseUrl() . '/';
     }
 }
示例#19
0
 public static function reload()
 {
     $configClass = Kwf_Setup::$configClass;
     $config = new $configClass(Kwf_Setup::getConfigSection());
     $cacheId = 'config_' . str_replace('-', '_', Kwf_Setup::getConfigSection());
     Kwf_Config_Cache::getInstance()->save($config, $cacheId);
     if (extension_loaded('apc')) {
         $apcCacheId = $cacheId . getcwd();
         apc_delete($apcCacheId);
         apc_delete($apcCacheId . 'mtime');
     }
     Kwf_Config_Web::clearInstances();
     Kwf_Registry::set('config', $config);
 }
示例#20
0
 public function image($image, $alt = '', $attributes = null)
 {
     if (!$image) {
         return '';
     }
     $url = $this->_getImageUrl($image);
     if ($url == '') {
         return '';
     }
     if (substr($url, 0, 8) == '/assets/') {
         if (Kwf_Setup::getBaseUrl()) {
             $url = Kwf_Setup::getBaseUrl() . $url;
         }
         $subroot = null;
         if ($this->_getView() && $this->_getView()->component) {
             $subroot = $this->_getView()->component->getSubroot();
         }
         $ev = new Kwf_Events_Event_CreateAssetUrl(get_class($this), $url, $subroot);
         Kwf_Events_Dispatcher::fireEvent($ev);
         $url = $ev->url;
     }
     $class = '';
     if (is_string($attributes)) {
         $class = $attributes;
     }
     if (is_string($image)) {
         if (file_exists(str_replace('/images/', '/images/dpr2/', $this->_getAssetPath($image)))) {
             $class .= ' kwfReplaceImageDpr2';
         }
     }
     $class = trim($class);
     if (!is_array($attributes)) {
         $attributes = array();
     }
     if ($class != '') {
         $attributes['class'] = $class;
     }
     $size = $this->_getImageSize($image);
     if (!isset($attributes['width'])) {
         $attributes['width'] = $size['width'];
     }
     if (!isset($attributes['height'])) {
         $attributes['height'] = $size['height'];
     }
     $attr = '';
     foreach ($attributes as $k => $i) {
         $attr .= ' ' . $k . '="' . $i . '"';
     }
     return "<img src=\"{$url}\"{$attr} alt=\"{$alt}\" />";
 }
示例#21
0
 public function __get($var)
 {
     if ($var == 'url') {
         $c = $this;
         while ($c) {
             if (Kwf_Component_Abstract::getFlag($c->componentClass, 'hasHome') && $c->isPseudoPage) {
                 return $c->_getPseudoPageUrl();
             }
             $c = $c->parent;
         }
         $baseUrl = Kwf_Setup::getBaseUrl();
         return $baseUrl . '/';
     }
     return parent::__get($var);
 }
示例#22
0
 public function load($row)
 {
     $model = Kwc_Abstract::createOwnModel($this->_class);
     $componentId = $row->component_id . '-' . $row->id;
     if ($this->_subComponent) {
         $componentId .= $this->_subComponent;
     }
     $row = $model->getRow($componentId);
     if ($row && $row->kwf_upload_id) {
         $hashKey = Kwf_Util_Hash::hash($row->kwf_upload_id);
         return Kwf_Setup::getBaseUrl() . '/kwf/media/upload/preview?uploadId=' . $row->kwf_upload_id . '&hashKey=' . $hashKey . '&size=' . $this->_size;
     } else {
         return '';
     }
 }
 public function indexAction()
 {
     $this->view->kwfVersion = Kwf_Config::getValue('application.kwf.name') . ' ' . trlKwf('Version') . ' ' . Kwf_Config::getValue('application.kwf.version');
     $this->view->appVersion = Kwf_Config::getValue('application.name');
     $this->view->baseUrl = Kwf_Setup::getBaseUrl();
     $this->view->defaultDbName = Kwf_Config::getValue('application.id');
     $this->view->possibleConfigSections = array();
     $cfg = new Kwf_Config_Ini('config.ini');
     foreach ($cfg as $k => $i) {
         $this->view->possibleConfigSections[] = array($k, $k);
     }
     $this->view->assetsPackage = Kwf_Assets_Package_Maintenance::getInstance('Maintenance');
     $this->view->viewport = 'Kwf.Maintenance.Viewport';
     $this->view->xtype = 'kwf.maintenance.setup';
 }
示例#24
0
 public function render($ignoreCli = false)
 {
     try {
         if (isset($_SERVER['REQUEST_URI']) && Kwf_Setup::hasDb() && Kwf_Registry::get('dao')->getDbConfig()) {
             $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null;
             $target = Kwf_Model_Abstract::getInstance('Kwf_Util_Model_Redirects')->findRedirectUrl('path', $_SERVER['REQUEST_URI'], $host);
             if ($target) {
                 header('Location: ' . $target, true, 301);
                 exit;
             }
         }
     } catch (Exception $e) {
         Kwf_Debug::handleException($e);
     }
     parent::render($ignoreCli);
 }
示例#25
0
 public function isLoggedIn()
 {
     if (Kwf_Setup::hasAuthedUser()) {
         $user = Zend_Registry::get('userModel')->getAuthedUser();
         if (!$user) {
             return false;
         }
         if (!$this->_getSetting('validUserRoles')) {
             return true;
         }
         if (in_array($user->role, $this->_getSetting('validUserRoles'))) {
             return true;
         }
     }
     return false;
 }
示例#26
0
 public function jsonDataAction()
 {
     $showLogout = true;
     $acl = $this->_getAcl();
     $menus = $acl->getMenuConfig($this->_getAuthData());
     if (empty($menus) && $this->_getUserRole() == 'guest') {
         $menu = array();
         $menu['type'] = 'commandDialog';
         $menu['menuConfig']['text'] = trlKwf('Login');
         $menu['commandClass'] = 'Kwf.User.Login.Dialog';
         $menus[] = $menu;
         $showLogout = false;
     }
     $model = Kwf_Registry::get('userModel')->getEditModel();
     if ($this->_getAuthData() && $model->getRowByKwfUser($this->_getAuthData())) {
         foreach ($acl->getAllResources() as $resource) {
             if ($resource instanceof Kwf_Acl_Resource_UserSelf && $acl->isAllowedUser($this->_getAuthData(), $resource, 'view')) {
                 $this->view->userSelfControllerUrl = $resource->getControllerUrl();
                 break;
             }
         }
     }
     $authData = $this->_getAuthData();
     $this->view->menus = $menus;
     $this->view->showLogout = $showLogout;
     $this->view->userId = $authData ? $authData->id : null;
     $this->view->fullname = $authData ? $authData->__toString() : '';
     $role = Zend_Registry::get('userModel')->getAuthedChangedUserRole();
     $this->view->changeUser = $acl->isAllowed($role, 'kwf_user_changeuser', 'view');
     $this->view->frontendUrls = array();
     if (Kwf_Registry::get('acl')->has('kwf_component_pages')) {
         foreach (Kwc_Abstract::getComponentClasses() as $c) {
             if (Kwc_Abstract::hasSetting($c, 'baseProperties') && in_array('domain', Kwc_Abstract::getSetting($c, 'baseProperties'))) {
                 $domains = Kwf_Component_Data_Root::getInstance()->getComponentsBySameClass($c, array('ignoreVisible' => true));
                 foreach ($domains as $domain) {
                     if ($acl->getComponentAcl()->isAllowed($authData, $domain)) {
                         $this->view->frontendUrls[] = array('href' => Kwf_Setup::getBaseUrl() . '/admin/component/preview?url=' . urlencode($domain->getAbsoluteUrl(true)), 'text' => $domain->name);
                     }
                 }
             }
         }
         if (!$this->view->frontendUrls) {
             $this->view->frontendUrls[] = array('href' => Kwf_Setup::getBaseUrl() . '/admin/component/preview', 'text' => trlKwf('Frontend'));
         }
     }
 }
示例#27
0
 public function image($image, $alt = '', $attributes = null)
 {
     if (!$image) {
         return '';
     }
     $url = $this->_getImageUrl($image);
     if ($url == '') {
         return '';
     }
     if (Kwf_Config::getValue('assetsCacheUrl') && substr($url, 0, 8) == '/assets/') {
         $url = Kwf_Config::getValue('assetsCacheUrl') . '?web=' . Kwf_Config::getValue('application.id') . '&section=' . Kwf_Setup::getConfigSection() . '&url=' . substr($url, 1);
     } else {
         if (Kwf_Setup::getBaseUrl() && substr($url, 0, 8) == '/assets/') {
             $url = Kwf_Setup::getBaseUrl() . $url;
         }
     }
     $class = '';
     if (is_string($attributes)) {
         $class = $attributes;
     }
     if (is_string($image)) {
         if (file_exists(str_replace('/images/', '/images/dpr2/', $this->_getAssetPath($image)))) {
             $class .= ' kwfReplaceImageDpr2';
         }
     }
     $class = trim($class);
     if (!is_array($attributes)) {
         $attributes = array();
     }
     if ($class != '') {
         $attributes['class'] = $class;
     }
     $size = $this->_getImageSize($image);
     if (!isset($attributes['width'])) {
         $attributes['width'] = $size['width'];
     }
     if (!isset($attributes['height'])) {
         $attributes['height'] = $size['height'];
     }
     $attr = '';
     foreach ($attributes as $k => $i) {
         $attr .= ' ' . $k . '="' . $i . '"';
     }
     return "<img src=\"{$url}\"{$attr} alt=\"{$alt}\" />";
 }
示例#28
0
 public static function reload()
 {
     $configClass = Kwf_Setup::$configClass;
     $config = new $configClass(Kwf_Setup::getConfigSection());
     $cacheId = 'config_' . str_replace(array('-', '.'), '_', Kwf_Setup::getConfigSection());
     Kwf_Config_Cache::getInstance()->save($config, $cacheId);
     if (extension_loaded('apc')) {
         $apcCacheId = $cacheId . getcwd();
         apc_delete($apcCacheId);
         apc_delete($apcCacheId . 'mtime');
         if (PHP_SAPI == 'cli') {
             Kwf_Util_Apc::callClearCacheByCli(array(array('cacheIds' => $apcCacheId . ',' . $apcCacheId . 'mtime')));
         }
         Kwf_Cache_SimpleStatic::clear('config-');
     }
     Kwf_Config_Web::clearInstances();
     Kwf_Registry::set('config', $config);
 }
 public static function validateSettings($settings, $componentClass)
 {
     if (isset($settings['ownModel']) && $settings['ownModel']) {
         if (Kwf_Setup::hasDb()) {
             //only check if db is set up correclty (might not during installation)
             try {
                 $m = Kwf_Model_Abstract::getInstance($settings['ownModel']);
                 $pk = $m->getPrimaryKey();
             } catch (Exception $e) {
             }
             if (isset($pk) && $pk != 'component_id') {
                 throw new Kwf_Exception("ownModel for '{$componentClass}' must have 'component_id' as primary key");
             }
         }
     }
     if (isset($settings['tablename'])) {
         throw new Kwf_Exception("tablename for '{$componentClass}' is set - please convert to model");
     }
     if (isset($settings['modelname'])) {
         throw new Kwf_Exception("modelname for '{$componentClass}' is set - please rename into ownModel or childModel");
     }
     if (isset($settings['model'])) {
         throw new Kwf_Exception("model for '{$componentClass}' is set - please rename into ownModel or childModel");
     }
     if (isset($settings['formModel'])) {
         throw new Kwf_Exception("formModel is no longer supported. Set the model in the FrontendForm.php. Component: '{$componentClass}'");
     }
     if (isset($settings['assets'])) {
         $f = strpos($componentClass, '.') ? substr($componentClass, 0, strpos($componentClass, '.')) : $componentClass;
         $f = str_replace('_', '/', $f);
         foreach ($settings['assets']['files'] as $i) {
             if (substr($i, -strlen($f) - 3) == $f . '.js') {
                 throw new Kwf_Exception("Remove Component.js from assets setting, it's found automatically.");
             }
             if (substr($i, -strlen($f) - 4) == $f . '.css') {
                 throw new Kwf_Exception("Remove Component.css from assets setting, it's found automatically.");
             }
             if (substr($i, -strlen($f) - 5) == $f . '.scss') {
                 throw new Kwf_Exception("Remove Component.scss from assets setting, it's found automatically.");
             }
         }
     }
 }
 public static function getOther()
 {
     $ec2 = new Kwf_Util_Aws_Ec2();
     $r = $ec2->describe_instances(array('Filter' => array(array('Name' => 'tag:application.id', 'Value' => Kwf_Config::getValue('application.id')), array('Name' => 'tag:config_section', 'Value' => Kwf_Setup::getConfigSection()))));
     if (!$r->isOK()) {
         throw new Kwf_Exception($r->body->asXml());
     }
     $ownHostname = file_get_contents('http://169.254.169.254/latest/meta-data/public-hostname');
     $domains = array();
     foreach ($r->body->reservationSet->item as $resItem) {
         foreach ($resItem->instancesSet->item as $item) {
             $dnsName = (string) $item->dnsName;
             if ($dnsName && $dnsName != $ownHostname) {
                 $domains[] = $dnsName;
             }
         }
     }
     return array_unique($domains);
 }