public function createMenu() { if (empty(\Uc::app()->params['bundles'])) { return false; } $menuTypes = array('leftMenu' => 'getAdminMenu', 'topMenu' => 'getAdminTopMenu'); foreach ($menuTypes as $menuPosition => $methodName) { $bundles = \Uc::app()->params['bundles']; $menuItems = array(); foreach ($bundles as $bundleClassName) { if (is_callable($bundleClassName . '::' . $methodName)) { $menu = call_user_func($bundleClassName . '::' . $methodName); $menuItems = array_merge($menuItems, $menu); } } $route = \Uc::app()->url->getRoute(); foreach ($menuItems as $moduleName => $urls) { foreach ($urls as $k => $urlInfo) { if (!empty($urlInfo['route'])) { if ($urlInfo['route'] == $route) { $menuItems[$moduleName][$k]['current'] = true; } $menuItems[$moduleName][$k]['href'] = \Uc::app()->url->create($urlInfo['route']); } } } $this->{$menuPosition} = $menuItems; } }
/** * * @author Ivan Scherbak <*****@*****.**> * @param string $appName * @param array $config * @return \Uc\App */ public static function initApp($appName, $config = array()) { register_shutdown_function(array(__CLASS__, 'errorHandler')); set_error_handler(array(__CLASS__, 'errorHandler')); self::$app = new $appName($config); return self::$app; }
public function getViewUrl() { if (Controller::MAIN_PAGE_SEF == $this->sef) { return \Uc::app()->url->create('ub/site/pages/mainpage'); } else { return \Uc::app()->url->create('ub/site/pages/view', array('sef' => $this->sef)); } }
/** * * @param $model */ protected function setSeoMetaFromModel($model) { foreach (array('meta_title', 'meta_description', 'meta_keywords') as $property) { if (!empty($model->{$property})) { \Uc::app()->theme->setValue('seo_' . $property, $model->{$property}); } } if (empty($model->meta_title) and !empty($model->title)) { \Uc::app()->theme->setValue('seo_meta_title', $model->title); } }
public function getViewUrl() { if (!empty($this->category_id)) { $categories = \Ub\Simpleblog\Categories\Table::instance()->getAllFromCache(); if (!empty($categories)) { $category = $categories[$this->category_id]; } else { $category = $this->category(); } if (!empty($category)) { $params = array('postsef' => $this->sef, 'postpk' => $this->pk(), 'catsef' => $category->sef, 'catpk' => $category->pk()); return \Uc::app()->url->create('ub/simpleblog/posts/view', $params); } } return '#error'; }
/** * * @throws \Exception * @internal param string $sef */ public function actionView() { $params = \Uc::app()->url->getParams(); if (!empty($params['postpk'])) { $postTable = Table::instance(); $post = $postTable->fetchOne($params['postpk']); } if (empty($post)) { throw new \Exception('Post not found', 404); } if (isset($_GET['addcomment'])) { return $this->actionAddComment($post); } \Uc::app()->theme->setValue('simpleblog_post_id', $post->pk()); \Uc::app()->theme->setValue('simpleblog_category_id', $post->category->pk()); # set meta tags $this->setSeoMetaFromModel($post); # init comments $this->render('view', array('model' => $post)); }
/** * @author muhasjo <*****@*****.**> */ public function actionContact() { $message = null; if (empty($_POST['email']) or filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false) { $message = 'Поле email заповнено невірно'; } if (!$message and empty($_POST['message'])) { $message = 'Заповність поле "повідомлення"'; } if (empty($message)) { $mailFrom = $_POST['email']; $userName = !empty($_POST['name']) ? $_POST['name'] : 'noname'; $message = $_POST['message']; $subject = "[UkrCMS]::[ContactForm] user " . $userName; $mailTo = \Ub\Site\Settings\Table::get('adminEmail'); mail($mailTo, $subject, $message, "From: " . $mailFrom . "\r\n"); $message = 'Ваші дані успішно відправлені'; } \Uc::app()->theme->setValue('seo_meta_title', 'Зворотній звязок'); $this->render('message', array('message' => $message)); }
/** * @return \Uc\Core\Db */ public function getAdapter() { return \Uc::app()->db; }
/** * @param string $file * @return string string */ protected function getClassViewFilePath($file) { $object = new \ReflectionObject($this); $file = dirname($object->getFilename()) . DIRECTORY_SEPARATOR . \Uc::app()->theme->getViewsDir() . DIRECTORY_SEPARATOR . trim($file, DIRECTORY_SEPARATOR) . \Uc::app()->theme->getTemplateExtension(); return $file; }
protected function getSessionKey() { return md5('user_id' . \Uc::app()->url->getBaseUrl()); }
public function showError(\Exception $exc) { # run custom controller for show error if (!empty($this->params) and !empty($this->params['errorHandler'])) { $controllerActionName = \Uc::app()->url->getControllerActionFromRoute($this->params['errorHandler']); if (!empty($controllerActionName[0]) and !empty($controllerActionName[1])) { $controllerClass = $this->getControllerClassName($controllerActionName[0]); $actionName = $this->getActionName($controllerActionName[1]); $this->controller = new $controllerClass(); return $this->controller->{$actionName}($exc); } } return false; }
public function save() { if (!$this->beforeSave()) { return false; } # begin transaction $transactionKey = md5(microtime() . rand(0, 10)) . get_class($this); try { \Uc::app()->db->startTransaction($transactionKey); if (!empty($this->columnChanged) or $this->stored == false) { $table = $this->table; # insert or update if ($this->stored) { # do Update of entity $pk = $this->pk(); $fields = array_intersect_key($this->data, $this->columnChanged); $result = $this->table->update($fields, $pk); } else { # do Insert of entity $result = $this->table->insert($this->data); if ($result != false) { # set primary key for entity /* * @todo update full data for Entity. * For example we have fields id, name, title, date * date is set automatically with database engine * if we make insert in future we want to get date * for this entity. * So we need to set date for this model * Look up to zend db */ # Primary key can be set from modules. $pk = $table->pk(); if (empty($this->{$pk})) { $this->{$pk} = $result; # last insert id } } } if ($result) { # make entity new state $this->stored = true; $this->columnChanged = array(); } else { throw new \Exception('Can not save entity ' . get_class($this)); } } # end transaction // @todo make rollback \Uc::app()->db->endTransaction($transactionKey); } catch (\Exception $exc) { echo $exc->getMessage() . "\n"; echo $exc->getTraceAsString(); } $this->afterSave(); return true; }
public function getTableName() { return \Uc::app()->db->tablePrefix . 'pages'; }
/** * Run Application * * @throws \Exception */ public function run() { try { $controllerRoute = $this->url->getControllerRoute(); if (!$controllerRoute) { throw new \Uc\Core\Exception('Controller route is empty'); } $actionRoute = $this->url->getActionRoute(); if (!$actionRoute) { throw new \Uc\Core\Exception('Action route is empty'); } # get names of controller and action $controllerRealName = $this->getControllerClassName($controllerRoute); $actionRelName = $this->getActionName($actionRoute); if (!class_exists($controllerRealName)) { throw new \Uc\Core\Exception('Controller class #' . $controllerRealName . ' does not exist'); } $this->controller = new $controllerRealName(); # validation of action if (!is_callable(array($this->controller, $actionRelName))) { throw new \Uc\Core\Exception('Action #' . $actionRelName . ' in controller #' . $controllerRealName . ' can not be call'); } return $this->controller->{$actionRelName}(); } catch (\Exception $exception) { $errorAction = (!empty($this->config) and !empty($this->config->errorAction)) ? $this->config->errorAction : null; if (!empty($errorAction)) { $errorControllerAction = \Uc::app()->url->getControllerActionFromRoute($this->config->errorAction); } if (!empty($errorControllerAction)) { try { $controllerClass = $this->getControllerClassName($errorControllerAction[0]); $actionRoute = $this->getActionName($errorControllerAction[1]); $this->controller = new $controllerClass(); return $this->controller->{$actionRoute}($exception); } catch (\Exception $e) { throw $e; } } } return; }
echo \Uc::app()->url->create($listRoute); ?> " class="<?php echo $statusRequest === null ? 'current' : ''; ?> ">Усі</a> <?php foreach (\Ub\Simpleblog\Comments\Model::getStatusDescription() as $status => $statusName) { ?> <a href="<?php echo \Uc::app()->url->create($listRoute, array('-w-status' => $status)); ?> " class="<?php echo $statusRequest === $status ? 'current' : ''; ?> "><?php echo $statusName; ?> </a> <?php } ?> <div class="sep"></div> </div> </div> <?php $widget = new \Ub\Admin\WidgetCrudList(); $widget->setData($data); $widget->setOptions(array('hideTitle' => true, 'addRoute' => null, 'showFields' => array('name' => 'name', 'comment' => 'comment'), 'controllerRoute' => \Uc::app()->url->getControllerName())); echo $widget->show();
public function getViewUrl() { return \Uc::app()->url->create('ub/pages/view', array('sef' => $this->sef)); }
protected function validateLoginRoute() { $loginPageUrl = \Uc::app()->url->create(\Uc::app()->userIdentity->loginRoute); $currentUrl = \Uc::app()->url->getAbsoluteRequestUrl(); return strpos($currentUrl, $loginPageUrl) === 0; }
/** * Set default order * * @param string $field * @param bool|\Uc\Db\type $exp * @return $this */ public function order($field, $exp = false) { if (!empty($exp)) { $this->order['_def'] = \Uc::app()->db->quoteIdentifier($field) . " " . $exp; } else { $this->order['_def'] = $field; } return $this; }
<?php $widget = new \Ub\Admin\WidgetCrudList(); $widget->setData($data); $widget->setOptions(array('showFields' => array('Логін' => 'login', 'Ім\'я' => 'name'), 'controllerRoute' => \Uc::app()->url->getControllerName())); echo $widget->show();
public function getPageTemplates() { \Uc::app()->theme->getViewFilePath(); }
public function getViewUrl() { return \Uc::app()->url->create('ub/simpleblog/posts/category', array('catsef' => $this->sef, 'catpk' => $this->pk())); }
public function setNewPassword($password) { $this->password = \Uc::app()->userIdentity->getPasswordHash($password); }
/** * @todo #phpstorm return application from \Uc\initApp * @return \Uc\Core\App */ public function app() { return \Uc::app(); }
/** * @return bool */ public function save() { if (!$this->beforeSave()) { return false; } # begin transaction $transactionKey = md5(microtime() . rand(0, 10)) . get_class($this); \Uc::app()->db->startTransaction($transactionKey); if (!empty($this->columnChanged) or $this->stored == false) { $table = $this->table; # insert or update if ($this->stored) { # do Update of entity $fields = array_intersect_key($this->data, $this->columnChanged); $result = $this->table->update($fields, $this->pk()); } else { # do Insert of entity $result = $this->table->insert($this->data); if (!is_bool($result)) { $pk = $table->pk(); $this->{$pk} = $result; # last insert id } } if ($result) { # make entity new state $this->stored = true; $this->columnChanged = array(); } else { #in fact if model not saved we have exception from DB throw new \Uc\Core\Exception('Can not save entity ' . get_class($this)); } } # end transaction // @todo make rollback \Uc::app()->db->endTransaction($transactionKey); $this->afterSave(); return true; }
<?php $widget = new \Ub\Admin\WidgetCrudList(); $widget->setData($data); $widget->setOptions(array('showFields' => array('title' => 'title'), 'controllerRoute' => \Uc::app()->url->getControllerName())); echo $widget->show();
<?php $widget = new \Ub\Admin\WidgetCrudList(); $widget->setData($data); $widget->setOptions(array('hideTitle' => true, 'showFields' => array('name' => 'title'), 'controllerRoute' => \Uc::app()->url->getControllerName())); echo $widget->show(); ?> <div class="entry" style="text-align: center;"> <?php foreach (array(30, 50, 100, 500) as $onPage) { ?> <a href="<?php echo \Uc::app()->url->create(\Uc::app()->url->getRoute(), array('onPage' => $onPage, 'page' => 1)); ?> " class="<?php echo (!empty($_GET['onPage']) and $onPage == $_GET['onPage']) ? 'current' : ''; ?> " ><?php echo $onPage; ?> </a> <?php } ?> </div>
public function getPath() { return \Uc::app()->params['basePath'] . \Uc::app()->params['filesPath'] . $this->fileStr(); }
echo $model->published == 0 ? 'checked = "checked"' : ''; ?> /> No</label> </div> <div class="element"> <label for="published">Коментарів #<?php echo count($model->Comments); ?> </label> <?php foreach ($model->comments as $comment) { ?> <a href="<?php echo \Uc::app()->url->create('ub/simpleblog/comments/admin/edit', array('pk' => $comment->pk())); ?> " target="_blank">{<?php echo $comment->status; ?> } <?php echo $comment->name; ?> </a> <br> <?php } ?> </div> <div class="entry">
/** * @throws \Exception */ public function actionEdit() { $table = $this->getConnectedTable(); if (!empty($_GET[static::PK_VAR])) { $model = $table->fetchOne($_GET[static::PK_VAR]); } else { $model = $table->createModel(); } if (isset($_POST['save_and_list']) or isset($_POST['save_and_edit']) or isset($_POST['data'])) { $this->beforeSave($model); $this->setModelDataFromRequest($model); if ($model->save()) { # redirect user to edit page or list $this->afterSave($model); if (isset($_POST['save_and_list'])) { $url = \Uc::app()->url->create(\Uc::app()->url->getControllerName() . '/list'); } else { $url = \Uc::app()->url->create(\Uc::app()->url->getRoute(), array('pk' => $model->pk())); } \Uc::app()->url->redirect($url); } else { throw new \Exception('Can not save entity ' . get_class($this)); } } $this->renderView('edit', array('model' => $model)); }
/** * Render layout with content * Layout name located in theme configuration * * @param string $content */ public function renderLayout($content) { $layoutFile = \Uc::app()->theme->getLayoutFilePath(); echo $this->renderFile($layoutFile, array('content' => $content)); }