Exemplo n.º 1
0
 public function formLoginAjaxSubmitted($form)
 {
     $values = $form->getValues();
     if ($form->isValid()) {
         $login = $values['login'];
         $password = $values['password'];
         $user = Environment::getUser();
         $user->setAuthenticationHandler(new Admin_UserModel());
         try {
             $user->authenticate($login, $password);
             $session_conf = Environment::getVariable('session');
             $user->setExpiration($session_conf['expiration'], true);
             //$session = $this->getSession('backlink');
             //$session->in_application = true;
             //$this->getApplication()->restoreRequest($session['backlink']);
             //$this->redirect('Dashboard:default');
             $this->payload->cmds = array();
             $this->payload->cmds[] = 'login_ok';
             $this->flash('Login OK');
             if ($this->isAjax()) {
                 $this->sendPayload();
                 $this->terminate();
             }
         } catch (AuthenticationException $e) {
             $form->setValues($values);
             $this->invalidateControl('frmLogin');
             if ($this->isAjax()) {
                 $this->invalidateControl('formLoginAjax');
             }
             //$this->flash('Error: '. $e->getMessage());
             $this->payload->error = $e - getMessage();
         }
     }
 }
Exemplo n.º 2
0
 /**
  * @return ITemplate
  */
 protected function createTemplate()
 {
     $template = new Template();
     $presenter = $this->getPresenter(FALSE);
     // default parameters
     $template->component = $this;
     // DEPRECATED!
     $template->control = $this;
     $template->presenter = $presenter;
     $template->baseUri = Environment::getVariable('baseUri');
     // flash message
     if ($presenter !== NULL && $presenter->hasFlashSession()) {
         $id = $this->getParamId('flash');
         $template->flashes = $presenter->getFlashSession()->{$id};
     }
     if (!isset($template->flashes) || !is_array($template->flashes)) {
         $template->flashes = array();
     }
     // default helpers
     $template->registerHelper('escape', 'Nette\\Templates\\TemplateHelpers::escapeHtml');
     $template->registerHelper('cache', 'Nette\\Templates\\CachingHelper::create');
     $template->registerHelper('snippet', 'Nette\\Templates\\SnippetHelper::create');
     $template->registerHelper('stripTags', 'strip_tags');
     $template->registerHelper('nl2br', 'nl2br');
     $template->registerHelperLoader('Nette\\Templates\\TemplateHelpers::loader');
     return $template;
 }
Exemplo n.º 3
0
 public function authenticate(array $credentials)
 {
     $login = $credentials['username'];
     $password = $this->phash($credentials['password']);
     $super_admin = Environment::getVariable('admin');
     if ($login == $super_admin['login']) {
         if ($password == $super_admin['password']) {
             $super_admin['roles'] = array('super admin');
             $super_admin['id'] = 0;
             $row = new DibiRow($super_admin);
             MokujiServiceLocator::addService('UserAuthorizator', new Admin_UserModel());
         } else {
             throw new AuthenticationException("Invalid password.", self::INVALID_CREDENTIAL);
         }
     } else {
         try {
             $login_manager = Environment::getService('UserAuthenticator');
             $row = $login_manager->authenticate($credentials);
         } catch (InvalidStateException $e) {
             throw new AuthenticationException("Login and password combination failed.", self::INVALID_CREDENTIAL);
         }
     }
     $identity = new Identity($row->id, $row->roles, $row);
     $identity->id = $row->id;
     return $identity;
 }
Exemplo n.º 4
0
 /**
  * Construct
  */
 public function __construct()
 {
     parent::__construct();
     // output
     $this->setOutputMode(self::HTML4_TRANSITIONAL);
     $this->htmlOutputModule->removeOptional = false;
     self::$advertisingNotice = false;
     // headings
     $this->headingModule->balancing = TexyHeadingModule::FIXED;
     // phrases
     $this->allowed['phrase/ins'] = true;
     // ++inserted++
     $this->allowed['phrase/del'] = true;
     // --deleted--
     $this->allowed['phrase/sup'] = true;
     // ^^superscript^^
     $this->allowed['phrase/sub'] = true;
     // __subscript__
     $this->allowed['phrase/cite'] = true;
     // ~~cite~~
     $this->allowed['deprecated/codeswitch'] = true;
     // `=code
     // images
     $this->imageModule->fileRoot = WWW_DIR . "/files";
     $this->imageModule->root = Environment::getVariable("baseUri") . "files/";
     // flash, youtube.com, stream.cz handlers
     $this->addHandler('image', array($this, 'youtubeHandler'));
     $this->addHandler('image', array($this, 'streamHandler'));
     $this->addHandler('image', array($this, 'flashHandler'));
 }
Exemplo n.º 5
0
 /**
  * @return ITemplate
  */
 protected function createTemplate()
 {
     $template = new Template();
     $presenter = $this->getPresenter(FALSE);
     $template->onPrepareFilters[] = array($this, 'templatePrepareFilters');
     // default parameters
     $template->component = $this;
     // DEPRECATED!
     $template->control = $this;
     $template->presenter = $presenter;
     $template->baseUri = Environment::getVariable('baseUri');
     $template->basePath = rtrim($template->baseUri, '/');
     // flash message
     if ($presenter !== NULL && $presenter->hasFlashSession()) {
         $id = $this->getParamId('flash');
         $template->flashes = $presenter->getFlashSession()->{$id};
     }
     if (!isset($template->flashes) || !is_array($template->flashes)) {
         $template->flashes = array();
     }
     // default helpers
     $template->registerHelper('escape', 'Nette\\Templates\\TemplateHelpers::escapeHtml');
     $template->registerHelper('escapeUrl', 'rawurlencode');
     $template->registerHelper('stripTags', 'strip_tags');
     $template->registerHelper('nl2br', 'nl2br');
     $template->registerHelper('substr', 'iconv_substr');
     $template->registerHelper('repeat', 'str_repeat');
     $template->registerHelper('implode', 'implode');
     $template->registerHelper('number', 'number_format');
     $template->registerHelperLoader('Nette\\Templates\\TemplateHelpers::loader');
     return $template;
 }
 protected function createComponentTexyla()
 {
     $texyla = new TexylaLoader();
     $texyla->filters[] = array("baseUri" => Environment::getVariable("baseUri"), "previewPath" => $this->link("Texyla:preview"), "filesPath" => $this->link("Texyla:listFiles"), "filesUploadPath" => $this->link("Texyla:upload"), "filesMkDirPath" => $this->link("Texyla:mkDir"), "filesRenamePath" => $this->link("Texyla:rename"), "filesDeletePath" => $this->link("Texyla:delete"));
     $texyla->addFile(WWW_DIR . "/js/texyla-init.js");
     return $texyla;
 }
 public function __construct($locale = NULL)
 {
     if ($locale === NULL) {
         $this->currentLocale = Environment::getVariable('lang');
     } else {
         $this->currentLocale = $locale;
     }
 }
Exemplo n.º 8
0
 public function renderManufacturer()
 {
     $this->template->paginator = new Paginator();
     $this->template->paginator->setItemCount(mapper::products()->countByManufacturer($this->template->manufacturer, $this->template->letter));
     $this->template->paginator->setItemsPerPage(Environment::getVariable('itemsPerPage', 30));
     $this->template->paginator->setPage($this->template->page_number);
     $this->template->products = mapper::products()->findByManufacturer($this->template->manufacturer, $this->template->paginator->getLength(), $this->template->paginator->getOffset(), $this->template->letter);
 }
Exemplo n.º 9
0
 public function __construct(array $items = NULL)
 {
     $this->items = array('--temp' => array('callback' => callback($this, 'clearDir'), 'name' => "Clear Temp", 'args' => array(Environment::getVariable('tempDir'))), '--log' => array('callback' => callback($this, 'clearDir'), 'name' => "Clear Logs", 'args' => array(Environment::getVariable('logDir'))), '--sessions' => array('callback' => callback($this, 'clearDir'), 'name' => "Clear Sessions", 'args' => array(Environment::getVariable('sessionDir'))));
     if (!empty($items)) {
         $this->items = array_merge($this->items, $items);
     }
     $this->processRequest();
 }
Exemplo n.º 10
0
 /**
  * Construct
  * @param IComponentContainer parent
  * @param string name
  */
 public function __construct(IComponentContainer $parent = null, $name = null)
 {
     parent::__construct($parent, $name);
     $this->tempUri = Environment::getVariable("baseUri") . "webtemp";
     $this->tempPath = WWW_DIR . "/webtemp";
     $this->sourcePath = WWW_DIR . "/texyla/";
     $this->addFiles(array("js/texyla.js", "js/selection.js", "js/texy.js", "js/buttons.js", "js/dom.js", "js/view.js", "js/ajaxupload.js", "languages/cs.js", "languages/sk.js", "languages/en.js", "plugins/keys/keys.js", "plugins/window/window.js", "plugins/resizableTextarea/resizableTextarea.js", "plugins/img/img.js", "plugins/table/table.js", "plugins/link/link.js", "plugins/emoticon/emoticon.js", "plugins/symbol/symbol.js", "plugins/files/files.js", "plugins/color/color.js", "plugins/textTransform/textTransform.js", "plugins/youtube/youtube.js"));
     $this->filters[] = "JSMin::minify";
 }
 /**
  * Startup
  */
 public function startup()
 {
     parent::startup();
     $texy = Environment::getService("Texy");
     $this->baseFolderPath = $texy->imageModule->fileRoot;
     $this->baseFolderUri = $texy->imageModule->root;
     $this->tempDir = WWW_DIR . "/webtemp";
     $this->tempUri = Environment::getVariable("baseUri") . "/webtemp";
 }
Exemplo n.º 12
0
 public function actionDefault()
 {
     $this->view = 'dashboard';
     $this->template->registerHelper('count', 'count');
     $this->template->pages = $this->model('pages')->getAll();
     $this->template->categories = $this->model('categories')->getAll();
     $this->template->menus = $this->model('menu')->getAll();
     $this->template->modules = $this->model('modules')->getAll();
     $this->template->loadedModules = Environment::getVariable('LoadedModules', array());
 }
Exemplo n.º 13
0
 /**
  * copy $path to webmodulePublicDir/$path
  */
 protected function copy($path)
 {
     $dest = Environment::getVariable('webtempDir') . '/' . static::ID . '/' . $path;
     $src = $this->buildSrcPath() . $path;
     if (!file_exists($dest)) {
         if (file_exists($src)) {
             Basic::copyr($src, $dest);
         } else {
             throw new ArgumentOutOfRangeException("Source path '{$src}' does NOT exist");
         }
     }
 }
Exemplo n.º 14
0
 public function __construct($lang)
 {
     //translator
     $this->lang = $lang;
     //suppres the query for one-language
     $langs = Environment::getVariable('langs');
     if (count($langs) <= 1) {
         return self::$cache[$lang] = array();
     }
     //fill the cache
     try {
         self::$cache[$lang] = dibi::query('SELECT * FROM translations')->fetchPairs('key', $lang);
     } catch (Exception $e) {
         self::$cache[$lang] = array();
     }
 }
Exemplo n.º 15
0
 protected function beforeRender()
 {
     parent::beforeRender();
     //copy assets to webtemp
     $relPath = "/webtemp/acl";
     $src = __DIR__ . "/../../assets";
     $dest = WWW_DIR . $relPath;
     if (!file_exists($dest)) {
         if (file_exists($src)) {
             Basic::copyr($src, $dest);
         } else {
             throw new ArgumentOutOfRangeException("Source path '{$src}' does NOT exist");
         }
     }
     $this->template->assetsBasePath = Environment::getVariable('basePath') . $relPath;
     $this->template->current = $this->getPresenter()->getName();
 }
Exemplo n.º 16
0
 private function login($username, $password)
 {
     $user = Environment::getUser();
     if (!$user->isAuthenticated()) {
         $user->setAuthenticationHandler(new Admin_UserModel());
         try {
             $user->authenticate($username, $password);
             $session_conf = Environment::getVariable('session');
             $user->setExpiration($session_conf['expiration'], true);
             return $user;
         } catch (AuthenticationException $e) {
             $this->error = new IXR_Error(403, $e->getMessage());
             return false;
         }
     }
     return $user;
 }
Exemplo n.º 17
0
 /**
  * Make relative url absolute
  * @param string image url
  * @param string single or double quote
  * @param string absolute css file path
  * @param string source path
  * @return string
  */
 public static function absolutizeUrl($url, $quote, $cssFile, $sourcePath)
 {
     // is already absolute
     if (preg_match("/^([a-z]+:\\/)?\\//", $url)) {
         return $url;
     }
     $docroot = realpath(WWW_DIR);
     $basePath = rtrim(Environment::getVariable("baseUri"), '/');
     // inside document root
     if (String::startsWith($cssFile, $docroot)) {
         $path = $basePath . substr(dirname($cssFile), strlen($docroot)) . DIRECTORY_SEPARATOR . $url;
         // outside document root
     } else {
         $path = $basePath . substr($sourcePath, strlen($docroot)) . DIRECTORY_SEPARATOR . $url;
     }
     $path = self::cannonicalizePath($path);
     return $quote === '"' ? addslashes($path) : $path;
 }
Exemplo n.º 18
0
 public function formatTemplateFiles($presenter, $view)
 {
     $parts = explode(':', $presenter);
     $moduleDir = $parts[0];
     $presenterDir = $parts[1];
     $parts = null;
     $appDir = Environment::getVariable('appDir');
     $path = '/' . str_replace(':', 'Modules/', $presenter);
     $path = '/Modules/' . $moduleDir;
     $pathP = $path . '/templates/' . $presenterDir;
     $themesDir = Environment::getVariable('themesDir');
     $theme = Environment::getVariable('theme');
     $this->pathToTheme = '/AdminModule/' . $themesDir . '/' . $theme;
     $list = array("{$appDir}{$pathP}/{$view}.phtml", "{$appDir}{$pathP}.{$view}.phtml", "{$appDir}{$path}/templates/@global.{$view}.phtml");
     //$list = parent::formatTemplateFiles($presenter, $view);
     //var_dump($list);exit;
     return $list;
 }
Exemplo n.º 19
0
 public function get($content_type)
 {
     $appDir = Environment::getVariable('appDir');
     $moduleDir = 'FrontModule';
     $themesDir = Environment::getVariable('themesDir');
     $data = ConfigAdapterIni::load(APP_DIR . '/config/site.ini', 'site');
     $activeTheme = $data['theme'];
     $themesPath = $appDir . '/' . $moduleDir . '/' . $themesDir;
     $folder = $themesPath . '/' . $activeTheme . '/templates/Page/';
     $templates = glob($folder . $content_type . '*');
     $new_templates = array();
     foreach ($templates as $index => $template) {
         $fn = basename($template);
         $fn = str_replace($content_type . '-', '', $fn);
         $fn = str_replace('.phtml', '', $fn);
         $new_templates[$fn] = $fn;
     }
     return $new_templates;
 }
Exemplo n.º 20
0
 public function __call($method_name, $args)
 {
     $method_name = '_' . $method_name;
     $tags = array('tags' => array('Models' . $this->getReflection()->getName()));
     if ($this->reflection->hasMethod($method_name)) {
         $method = $this->reflection->getMethod($method_name);
         if ($method->getAnnotation('cache') == 'update' || $method->getAnnotation('cache') == 'insert' || strpos(String::lower($method_name), 'update') > 0 || strpos(String::lower($method_name), 'insert') > 0 || strpos(String::lower($method_name), 'delete') > 0 || strpos(String::lower($method_name), 'edit') > 0 || strpos(String::lower($method_name), 'save') > 0 || strpos(String::lower($method_name), 'create') > 0) {
             fd('cache cleaned');
             if (!empty($args)) {
                 $method->invokeArgs($this, $args);
             } else {
                 $this->{$method_name}();
             }
             //WORKAROUND
             $cache_folder = Environment::getVariable('tempDir') . '/c-' . $this->cache->namespace;
             if (file_exists($cache_folder)) {
                 $files = glob($cache_folder . '/*');
                 if ($files != false) {
                     foreach ($files as $file) {
                         if (file_exists($file)) {
                             unlink($file);
                         }
                     }
                 }
             }
             //$this->cache->clean();
         } else {
             if (!empty($args)) {
                 $ckey = sha1($method_name . serialize($args));
                 if (!isset($this->cache[$ckey])) {
                     $this->cache->save($ckey, $method->invokeArgs($this, $args));
                 }
             } else {
                 $ckey = sha1($method_name);
                 if (!isset($this->cache[$ckey])) {
                     $this->cache->save($ckey, $this->{$method_name}());
                 }
             }
             return $this->cache[$ckey];
         }
     }
 }
Exemplo n.º 21
0
 public function renderDefault($q, $page = 1)
 {
     try {
         $ids = array();
         foreach (fulltext::index()->find($q) as $hit) {
             $ids[] = $hit->getDocument()->id;
         }
         $this->template->paginator = new Paginator();
         $this->template->paginator->setItemCount(count($ids));
         $this->template->paginator->setItemsPerPage(Environment::getVariable('itemsPerPage', 30));
         $this->template->paginator->setPage($page);
         $this->template->products = mapper::products()->findByIds(array_slice($ids, $this->template->paginator->getOffset(), $this->template->paginator->getLength()));
         $this->template->title = __('Search results for ``%s"', $q);
         $this->template->q = $q;
         Environment::getSession(SESSION_SEARCH_NS)->last = $q;
         searchlog::log($q);
     } catch (Exception $e) {
         $this->template->products = array();
     }
 }
Exemplo n.º 22
0
 protected function setWebloaderPaths()
 {
     // sets webloader source path to file calling this one ..
     $backtrace = debug_backtrace();
     self::$webloaderSrcPath = $callingFile = dirname($backtrace[0]['file']);
     // sets uri to webtemp control dir
     $webtempDir = Environment::getVariable('webtempDir');
     $baseUri = Environment::getVariable('baseUri');
     $webtempDirSlashed = str_replace('\\', '/', $webtempDir);
     //		$webtempDirname = substr($webtempDirSlashed, strpos($webtempDirSlashed, $baseUri) + strlen($baseUri));
     $webtempDirname = substr($webtempDirSlashed, strlen(WWW_DIR) + 1);
     $controlName = basename(self::$webloaderSrcPath);
     self::$webloaderDestPath = $webtempDir . '/' . $controlName;
     self::$webloaderDestUri = $baseUri . $webtempDirname . '/' . $controlName;
     // create automatically dir for scripts even if not used
     $dest = $webtempDir . '/' . $controlName;
     Basic::mkdir($dest);
     Basic::mkdir($dest . '/js');
     Basic::mkdir($dest . '/css');
 }
Exemplo n.º 23
0
 /**
  * nacita prelozene stringy do slovnika
  * 
  * @param array $supportedLangs pole podporovanych jazykov
  * @param bool $rebuild rebuild dictionary by pulling phrases out of .php and .phtml and updating database
  * @return void
  *
  */
 public function buildDictionary($supportedLangs = NULL, $rebuild = false)
 {
     if (!isset($this->langs) && !$supportedLangs) {
         throw new Exception('nastav podporovane jazyky');
     } elseif ($supportedLangs) {
         $this->langs = $supportedLangs;
     }
     if ($rebuild) {
         $this->findAllStrings();
         // calls buildDictionary() so return
         return;
     }
     $lang = Environment::getVariable('lang');
     $dictionary = Environment::getCache('dictionary');
     if ($dictionary['data'] === null) {
         $data = array();
         foreach ($this->langs as $lang) {
             $data[$lang] = dibi::select("msg_id, IF(msg_{$lang} = '', msg_id, msg_{$lang}) AS msg")->from(self::TABLE)->fetchPairs('msg_id', 'msg');
         }
         $dictionary['data'] = $data;
     }
     $this->dictionary = $dictionary['data'][$lang];
     //		dump($this->dictionary);
 }
Exemplo n.º 24
0
 /**
  * Formats presenter class file name.
  * @param  string
  * @return string
  */
 public function formatPresenterFile($presenter)
 {
     $presenter = str_replace(':', 'Module/', $presenter);
     $presenter = Environment::getVariable('presentersDir') . '/' . $presenter . 'Presenter.php';
     return $presenter;
 }
Exemplo n.º 25
0
 /**
  * @return Nette\Caching\ICacheStorage
  */
 public static function createCacheStorage()
 {
     return new FileStorage(Environment::getVariable('cacheBase'));
 }
Exemplo n.º 26
0
 public function renderProducts($page_number = 0)
 {
     $this->template->title = __('Products');
     $this->template->page_number = $page_number;
     $this->template->paginator = new Paginator();
     $this->template->paginator->setItemCount(mapper::products()->countAll());
     $this->template->paginator->setItemsPerPage(Environment::getVariable('itemsPerPage', 30));
     $this->template->paginator->setPage($this->template->page_number);
     $this->template->products = mapper::products()->findAll($this->template->paginator->getLength(), $this->template->paginator->getOffset());
 }
Exemplo n.º 27
0
 function constructUrl(PresenterRequest $appRequest, Url $ref)
 {
     if ($appRequest->getPresenterName() !== self::PRESENTER) {
         return NULL;
     }
     $params = $appRequest->getParameters();
     //find the friendly-url in the database
     $lang = $params['lang'];
     if ($lang == NULL) {
         $lang = $this->getDefaultLang();
     }
     //lang base url (domain or just relative prefix?)
     $langDomains = Environment::getVariable("langDomains");
     if ($langDomains) {
         $baseUrl = $ref->scheme . ':' . $langDomains[$lang];
     } else {
         $baseUrl = $ref->getBaseUrl() . ($lang == $this->getDefaultLang() ? '' : "{$lang}/");
     }
     //NULL page = /
     if (!isset($params['id_page'])) {
         return $baseUrl;
     }
     //nonexisting page - do not route
     $page = PagesModel::getPageById($params['id_page'], $lang);
     if (!$page) {
         return NULL;
     }
     unset($params['lang']);
     unset($params['id_page']);
     unset($params['action']);
     // appended parameters
     $params = http_build_query($params, '', '&');
     if ($params) {
         $params = "?{$params}";
     }
     // no pagelink -> do /p123-friendly-name
     if (!$page['seoname']) {
         return $baseUrl . "p{$page->id}" . (Strings::webalize($page->name) ? '-' : '') . Strings::webalize($page->name) . $params;
     }
     // /sth  -> normal friendly url for that page
     if ($page['seoname'][0] == '/') {
         return $baseUrl . substr($page['seoname'], 1) . $params;
     }
     return NULL;
 }
Exemplo n.º 28
0
 /**
  * @return RobotLoader
  */
 public static function createRobotLoader($options)
 {
     $loader = new RobotLoader();
     $loader->autoRebuild = !Environment::isProduction();
     //$loader->setCache(Environment::getCache('Nette.RobotLoader'));
     $dirs = isset($options['directory']) ? $options['directory'] : array(Environment::getVariable('appDir'), Environment::getVariable('libsDir'));
     $loader->addDirectory($dirs);
     $loader->register();
     return $loader;
 }
Exemplo n.º 29
0
 /**
  * Formats view template file names.
  * @param  string
  * @param  string
  * @return array
  */
 public function formatTemplateFiles($presenter, $view)
 {
     $root = Environment::getVariable('templatesDir');
     $presenter = str_replace(':', 'Module/', $presenter);
     $dir = '';
     if ($root === Environment::getVariable('presentersDir')) {
         // special supported case
         $pos = strrpos($presenter, '/');
         $presenter = $pos === FALSE ? 'templates/' . $presenter : substr_replace($presenter, '/templates', $pos, 0);
         $dir = 'templates/';
     }
     return array("{$root}/{$presenter}/{$view}.phtml", "{$root}/{$presenter}.{$view}.phtml", "{$root}/{$dir}@global.{$view}.phtml");
 }
Exemplo n.º 30
0
 /**
  * @return Nette\Caching\ICacheStorage
  */
 public static function getCacheStorage()
 {
     if (self::$cacheStorage === NULL) {
         self::$cacheStorage = new TemplateCacheStorage(Environment::getVariable('tempDir'));
     }
     return self::$cacheStorage;
 }