示例#1
0
 /**
  * Generate local actions View.
  *
  * @static
  * @access   public
  * @return   View
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 public static function generateActions()
 {
     $aActions = [];
     $sForRoute = Router::getCurrentRouteName();
     $aLocalActions = static::getLocalActions($sForRoute);
     // create local actions
     foreach ($aLocalActions as $oAction) {
         /* @var $oAction LocalActions\Action */
         // check conditions
         $aConditions = $oAction->getConditions();
         $oBuilder = $oAction->getBuilder();
         $aParams = $oAction->getParameters();
         if (!empty($aConditions)) {
             foreach ($oAction->getConditions() as $sParam => $sParamValue) {
                 if (Router::getParam($sParam) != $sParamValue) {
                     continue 2;
                 }
             }
         }
         // get route and check access to it
         $oRoute = Route::factory($oAction->getRoute());
         if ($oRoute->hasAccess($aParams) === FALSE) {
             continue 1;
         }
         // use builder, if set
         if ($oBuilder !== NULL) {
             $oBuilder($oAction);
         }
         // create new local action
         $sURL = $oRoute->url($oAction->getParameters());
         $aActions[] = ['url' => $sURL, 'title' => $oAction->getTitle(), 'icon' => $oAction->getIcon()];
     }
     return View::factory('base/local_actions')->bind('aActions', $aActions);
 }
示例#2
0
文件: User.php 项目: ktrzos/plethora
 /**
  * ACTION - User login.
  *
  * @access   public
  * @return   View
  * @since    1.0.2, 2013-12-07
  * @version  1.0.7-dev, 2015-05-04
  */
 public function actionLogin()
 {
     $this->setTitle(Core::getAppName() . ' - ' . __('Login form'));
     $this->addBreadCrumb(__('Login form'));
     $oLoggedUser = Model\User::getLoggedUser();
     if ($oLoggedUser instanceof Model\User) {
         Route::factory('user_profile')->redirectTo(['id' => $oLoggedUser->getId()]);
     }
     $failedLogins = \User\LoginFail::getCachedData();
     if ($failedLogins > 4) {
         return View::factory('base/alert')->set('sType', 'danger')->set('sMsg', __('to.many.incorrect.logins'));
     }
     $oLoginForm = Form::factory('login');
     $oLoginForm->addField(Form\Field\Text::factory('login', $oLoginForm));
     $oLoginForm->addField(Form\Field\Password::factory('password', $oLoginForm));
     if ($oLoginForm->isSubmittedAndValid()) {
         $sUsername = $oLoginForm->get('login');
         $sPassword = $oLoginForm->get('password');
         $sEncryptedPassword = Helper\Encrypter::factory()->encrypt($sUsername, $sPassword);
         $oUser = DB::query("SELECT u FROM \\Model\\User u WHERE u.login = :login AND u.password = :pass")->param('login', $sUsername)->param('pass', $sEncryptedPassword)->single();
         if ($oUser instanceof Model\User) {
             Session::set('username', $sUsername);
             Session::set('uid', (int) $oUser->getId());
             $oUser->setLoginDateNOW();
             DB::flush();
             # Get role permissions for particular user and set them in session
             \UserPermissions::reset();
             Route::factory(Router::getCurrentRouteName())->redirectTo();
         } else {
             $currentUrl = Router::currentUrl();
             $alert = __('You have entered wrong username or password. Try again.');
             \User\LoginFail::addLoginFail();
             Session::flash($currentUrl, $alert, 'danger');
         }
     }
     $oLoginForm->addToSuffix(View::factory('user/frontend/login_links')->render());
     return View::factory('base/form')->bind('oForm', $oLoginForm);
 }
示例#3
0
文件: File.php 项目: ktrzos/plethora
 /**
  * Fields config for backend.
  *
  * @access   public
  * @return   ModelCore\MConfig
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 protected static function generateConfig()
 {
     $oConfig = parent::generateConfig();
     $currentRouteName = Router::getCurrentRouteName();
     $currentRouteParams = Router::getParams();
     $oConfig->addField(Form\Field\Hidden::singleton('id')->setLabel(__('ID'))->setDisabled());
     // BACKEND
     if ($currentRouteName === 'backend' && in_array($currentRouteParams['action'], ['edit', 'list'])) {
         $oConfig->addField(Form\Field\Text::singleton('name')->setLabel(__('File name'))->setDisabled());
         $oConfig->addField(Form\Field\Text::singleton('ext')->setLabel(__('File extension'))->setDisabled());
         $oConfig->addField(Form\Field\Text::singleton('file_path')->setLabel(__('File path'))->setDisabled());
         $oConfig->addField(Form\Field\Text::singleton('mime')->setLabel(__('File MIME type'))->setDisabled());
         $oConfig->addField(Form\Field\Text::singleton('size')->setLabel(__('File size'))->setTip(__('File size in KB.'))->setDisabled());
         $oConfig->addField(Form\Field\Select::singleton('status')->setOptions([0 => __('Temporary'), 1 => __('Permanent')])->setLabel(__('Status'))->setDisabled());
     }
     return $oConfig;
 }
示例#4
0
文件: Item.php 项目: ktrzos/plethora
 /**
  * Constructor
  *
  * @access     public
  * @since      1.1.2-dev
  * @version    1.1.3-dev
  */
 public function __construct()
 {
     parent::__construct();
     $this->locales = new \Doctrine\Common\Collections\ArrayCollection();
     // get menu ID
     if (Router::getCurrentRouteName() === 'backend' && in_array(Router::getParam('action'), ['add', 'edit'])) {
         $menuID = (int) Router::getParam('id');
         $this->menu = DB::find('\\Model\\Menu', $menuID);
     }
 }
示例#5
0
文件: Menu.php 项目: ktrzos/plethora
 /**
  * Find active route in particular menu.
  *
  * @access   private
  * @param    array   $routes
  * @param    integer $parentKey
  * @param    array   $parent
  * @since    1.0.0-dev
  * @version  1.3.0-dev
  */
 private function findActiveRoute(array &$routes, $parentKey = NULL, array $parent = [])
 {
     foreach ($routes as $i => &$route) {
         /* @var $route array */
         /* @var $routeName string */
         /* @var $routeParams array */
         /* @var $activeRoutes array */
         if (!isset($route['classes'])) {
             $route['classes'] = [];
         }
         $routeName = Helper\Arrays::get($route, 'route_name', NULL);
         $url = Helper\Arrays::get($route, 'url', NULL);
         $routeParams = Helper\Arrays::get($route, 'route_parameters', []);
         $activeRoutes = Helper\Arrays::get($route, 'active_routes', []);
         //            $path        = $url === NULL ? Route::factory($routeName)->path($routeParams) : $url;
         if ($routeName !== NULL) {
             $path = Route::factory($routeName)->path($routeParams);
         } else {
             $path = $url;
         }
         $path = str_replace(Router::getBase(), '', $path);
         $currentPath = Router::getCurrentUrl();
         if (in_array(Router::getCurrentRouteName(), $activeRoutes)) {
             $route['classes'][] = ['current ' . $this->activeTrailClass];
         }
         if ($parentKey !== NULL) {
             $route['parent_key'] = $parentKey;
             $route['parent'] = $parent;
         }
         if ($path === $currentPath) {
             $this->goBackAndSetActive($route);
         }
         if (isset($route['children']) && !empty($route['children'])) {
             $this->findActiveRoute($route['children'], $i, $routes);
             /* @var $oChildren View */
         }
     }
 }
示例#6
0
 /**
  * Find active route in particular menu.
  *
  * @access	private
  * @param	array    $aRoutes
  * @param	integer  $iParentKey
  * @param	array    $aParent
  * @since	1.2.0-dev
  * @version	1.2.0-dev
  */
 private function findActiveRoute(array &$aRoutes, $iParentKey = NULL, array $aParent = [])
 {
     foreach ($aRoutes as $i => &$aRoute) {
         /* @var $aRoute array */
         $oItem = $aRoute['object'];
         /* @var $oItem \Model\Menu\Item */
         $sRouteName = $oItem->getRoute();
         /* @var $sRouteName string */
         $aRouteParams = $oItem->getRouteParams() !== NULL ? $oItem->getRouteParams() : [];
         /* @var $aRouteParams array */
         $aActiveRoutes = $oItem->getActiveRoutes() !== NULL ? $oItem->getActiveRoutes() : [];
         /* @var $aRouteParams array */
         $sPath = Route::factory($sRouteName)->path($aRouteParams);
         $sCurrentPath = Router::getCurrentUrl();
         if (in_array(Router::getCurrentRouteName(), $aActiveRoutes)) {
             $aRoute['classes'] = 'current active_trail';
         } elseif (!isset($aRoute['classes'])) {
             $aRoute['classes'] = NULL;
         }
         if ($iParentKey !== NULL) {
             $aRoute['parent_key'] = $iParentKey;
             $aRoute['parent'] = $aParent;
         }
         if ($sPath === $sCurrentPath) {
             $this->goBackAndSetActive($aRoute);
         }
         if (isset($aRoute['siblings']) && !empty($aRoute['siblings'])) {
             $this->findActiveRoute($aRoute['siblings'], $i, $aRoutes);
             /* @var $oChildren View */
         }
     }
 }
示例#7
0
文件: User.php 项目: ktrzos/plethora
 /**
  * Set value for database field from form.
  *
  * @author   Krzysztof Trzos
  * @access   protected
  * @param    string     $sName
  * @param    mixed      $mValue
  * @param    Form\Field $oFormField
  * @return   boolean
  * @since    1.0.1-dev, 2015-02-20
  * @version  2.1.1-dev
  */
 protected function makeDataTransfer($sName, $mValue, Form\Field &$oFormField)
 {
     $sCurrentRoute = Router::getCurrentRouteName();
     $aCurrentRouteParams = Router::getParams();
     switch ($sName) {
         case 'password':
             switch ($sCurrentRoute) {
                 case 'backend':
                     if ($aCurrentRouteParams['controller'] === 'user' && $aCurrentRouteParams['action'] === 'edit') {
                         if (empty($mValue['und'][0])) {
                             return FALSE;
                         }
                     }
                     break;
             }
             break;
     }
     return parent::makeDataTransfer($sName, $mValue, $oFormField);
 }
示例#8
0
 /**
  * Set basic classes to "body" tag.
  *
  * @access     protected
  * @return    Controller
  * @since      1.0.0-alpha
  * @version    1.0.0-alpha
  */
 protected function setBodyBasicClasses()
 {
     // add classes whether current page is front or not
     $this->addBodyClass(Router::isFrontPage() ? 'front' : 'not_front');
     // get current route
     $this->addBodyClass('route_' . Router::getCurrentRouteName());
     return $this;
 }
示例#9
0
?>

<?php 
ksort($aRoutesList);
?>

<?php 
foreach ($aRoutesList as $sRouteName => $oRoute) {
    /* @var $oRoute \Plethora\Route */
    ?>
	<?php 
    $sClass = 'single_route';
    $sParameterTypes = implode(', ', $oRoute->getParameterTypes());
    $sDefaults = implode(', ', $oRoute->getDefaults());
    $sPermissions = implode(', ', $oRoute->getPermissions());
    if (\Plethora\Router::getCurrentRouteName() === $sRouteName) {
        $sClass .= ' current';
    }
    ?>
	<div class="<?php 
    echo $sClass;
    ?>
">
		<span class="route_name"><?php 
    echo $sRouteName;
    ?>
</span>
		<div class="additional_info">
			<div>
				<span class="name">Action: </span>
				<span class="value"><?php