/** * 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); }
/** * Activate user account. * * @access public * @return View * @since 1.0.0 * @version 1.1.0, 2015-02-12 */ public function actionActivation() { // if user is logged, redirect to main page if (UserModel::isLogged()) { Route::factory('home')->redirectTo(); } // set page title $this->setTitle(__('Activate your new account')); // get code from URL $sCode = Router::getParam('code'); $bActivated = FALSE; // get activation code from DB $oResult = DB::query("SELECT c FROM \\Model\\User\\ActivationCode c WHERE c.code = :code")->param('code', $sCode)->single(); /* @var $oResult ActivationCodeModel */ // activate user if ($oResult instanceof ActivationCodeModel) { // Set user as activated $bActivated = TRUE; $oUser = $oResult->getUser(); $oUser->setActivation(TRUE); DB::flush(); // Remove activation code from DB DB::remove($oResult); DB::flush(); } // view return View::factory("user/frontend/register/activation")->bind('bActivated', $bActivated); }
/** * ACTION - Backend delete action. * * @access public * @return View * @since 2.1.2-dev * @version 2.1.2-dev */ public function actionDelete() { // check if someone want to remove admin account if ((int) Router::getParam('id') === 1) { return View::factory('base/alert')->set('sType', 'danger')->set('sMsg', __('Admin account cannot be removed!')); } // return View return parent::actionDelete(); }
/** * Constructor. * * @access public * @param string $name * @param Form $form * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function __construct($name, Form &$form) { // add reCaptcha JavaScript API Router::getInstance()->getController()->addJs('https://www.google.com/recaptcha/api.js?hl=pl'); // get private and public keys $this->sPublickey = Config::get('recaptcha.publickey'); $this->sPrivatekey = Config::get('recaptcha.privatekey'); // parent construct parent::__construct($name, $form); }
/** * Get whole cached translations data. * * @access public * @return array * @since 1.0.0-dev * @version 1.2.0-dev */ public static function getCachedData() { if (static::$cachedData === NULL) { $cachedData = Cache::get(Router::getLang(), 'i18n'); if ($cachedData === FALSE) { $cachedData = []; } static::$cachedData = $cachedData; } return static::$cachedData; }
/** * Change main (start or parent) breadcrumbs and/or title for this backend * constructor. * * @access protected * @since 1.2.0-dev * @version 1.2.0-dev */ protected function alterBreadcrumbsTitleMain() { // parent call parent::alterBreadcrumbsTitleMain(); // remove last breadcrumb $this->removeBreadcrumb(); // add new breadcrumb $sControllerOriginal = Router::getControllerName(); $sURL = Route::backendUrl($sControllerOriginal, 'index'); $sControllerName = strtolower($sControllerOriginal); $this->addBreadCrumb(__('section.' . $sControllerName), $sURL); }
/** * Default action for TinyMCE Responsive File Manager. Config file available * via <code>\ResponsiveFileManager::$aConfig</code> variable. For * non-commercial usage only. * * @access public * @since 1.0.0-dev * @version 1.0.1 */ public function actionDefault() { $sFileManagerAction = Router::getParam('fmaction'); if (!in_array($sFileManagerAction, ['dialog', 'ajax_calls', 'execute', 'force_download', 'upload'])) { throw new Code404Exception(); } if (!\UserPermissions::hasPerm('wysiwyg_filemanager')) { throw new Code401Exception(); } $sLang = Router::getLang(); \ResponsiveFileManager::$aConfig['default_language'] = $sLang; }
/** * Default action for database updating. * * @access public * @return View * @since 2014-08-17 * @version 1.2.0-dev */ public function actionDefault() { $this->addToTitle('Database updating module'); // create update form $oForm = new Form('db_update'); $oForm->setSubmitValue(__('make update')); // check if update button has been clicked if ($oForm->isSubmittedAndValid()) { $sUpdateOutput = static::makeUpdateNoExec(); Cache::set($sUpdateOutput, 'output', 'dbupdate'); Session::flash(Router::getCurrentUrl(), __('Database updated successfully.')); } // return View return View::factory('db_update/backend/default')->bind('oForm', $oForm); }
/** * Main action to run cron jobs. * * @access public * @since 2.33.0-dev, 2015-06-07 * @version 2.39.0-dev */ public function actionDefault() { if (!class_exists('\\Cron\\CronExpression')) { throw new Exception\Fatal('Cannot run Cron jobs without proper Cron library.'); } $sTokenFromURL = Router::getParam('token'); $sTokenFromConfig = Config::get('base.cron_token'); $iCronJobsCompleted = 0; // check Cron token if ($sTokenFromURL !== $sTokenFromConfig) { throw new Exception\Code404(); } // get all Cron jobs $aAllJobs = CronJobsHelper::getCronJobs(); // count amount of all CRON jobs $iCronJobs = count($aAllJobs); // run a single CRON job foreach ($aAllJobs as $aJobData) { $sModule = $aJobData['module']; $sJobKey = base64_encode($aJobData[1] . '.' . $aJobData[2]); $aCache = Cache::get($sModule . '.' . $sJobKey, 'cron'); $iRunDate = isset($aCache['time']) ? $aCache['time'] : NULL; $oCron = CronExpression::factory($aJobData[0]); if ($iRunDate === NULL || $iRunDate < time()) { switch ($aJobData[1]) { case 'route': $sURL = Route::factory($aJobData[2])->url(); file_get_contents($sURL); break; case 'file': case 'url': file_get_contents($aJobData[2]); break; case 'function': call_user_func($aJobData[2]); break; } $iNextRun = $oCron->getNextRunDate()->format('U'); $aCacheToSave = ['time' => $iNextRun, 'last_execution_time' => time(), 'type' => $aJobData[1], 'param' => $aJobData[2]]; Cache::set($aCacheToSave, $sModule . '.' . $sJobKey, 'cron', 0); } } // log that cron jobs turning on action was completed Log::insert('Cron jobs (in amount of ' . $iCronJobs . ') were checked and ' . $iCronJobsCompleted . ' of them were turned on.'); // end of functionality exit; }
/** * ACTION - Particular page. * * @access public * @return View * @throws Exception\Code404 * @throws Exception\Fatal * @since 1.0.1-dev, 2015-04-11 * @version 1.2.0-dev */ public function actionPage() { $query = DB::query('SELECT p FROM \\Model\\Page p WHERE p.rewrite = :rewrite'); $query->param('rewrite', Router::getParam('rewrite')); $page = $query->single(); if (!$page instanceof Model\Page) { throw new Exception\Code404('Page does not exist.'); } $this->addBreadCrumb($page->getTitle()); $this->setTitle($page->getTitle()); $this->setDescription($page->getDescription()); $this->setKeywords($page->getKeywords()); $entityConfig = ViewEntity\Configurator::factory($page); $entityConfig->setFields(['content']); $viewEntity = ViewEntity::factory($entityConfig); return $viewEntity->getView(); }
/** * Format value. * * @access public * @param string $value * @return string * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function format($value) { $sOutput = ''; if ($value instanceof ModelCore\FileBroker) { $oAttributes = Helper\Attributes::factory(); $oField = $this->getField(); /* @var $oField View\ViewField */ $sFieldName = $oField->getName(); $oFile = $value->getFile(); /* @var $oFile \Model\File */ // get file path $sFilePath = $oFile->getFullPath(); // generate HTML $oAttributes->addToAttribute('href', Router::getBase() . '/' . $sFilePath); $sOutput = '<img src="/assets/system/file_icons/' . $oFile->getExt() . '.png" alt="" /> <a ' . $oAttributes->renderAttributes() . '>' . $sFilePath . '</a>'; // remove objects unset($oFileManager); } // return final output return $this->sPrefix . $sOutput . $this->sSuffix; }
<?php # particular page \Plethora\Router::addRoute('page', '/page/{rewrite}')->addParameterType('rewrite', 'string')->setController('Frontend\\Pages')->setAction('page');
* @author Krzysztof Trzos * @package base * @since 1.0.0-alpha * @version 1.0.0-alpha */ ?> <?php /* @var $oHead \Plethora\View */ /* @var $oBody \Plethora\View */ /* @var $sBodyClasses string */ ?> <!DOCTYPE html> <html lang="<?php echo \Plethora\Router::getLang(); ?> "> <head> <?php echo $oHead->render(); ?> </head> <body class="<?php echo trim($sBodyClasses); ?> "> <?php echo $oBody->render(); ?> </body>
/** * Load translations from a given path. * * @access private * @param string $path * @throws Exception\Fatal * @version 1.2.0-dev * @since 1.2.0-dev */ private function loadFiles($path) { $localePath = $path . DS . 'locale'; $langs = Router::getLangs(); if (file_exists($localePath)) { $scannedDir = \FileManager::scanDir($localePath, 0); foreach ($scannedDir as $dirId => &$file) { list($lang, $type) = explode('.', $file); // check language if (!in_array($lang, $langs)) { unset($scannedDir[$dirId]); continue; } // import data from single file switch ($type) { case 'json': $fileTranslations = static::importFileJson($localePath . DS . $file, $lang); break; default: $fileTranslations = []; } // count translations per type $appPart = NULL; if (strpos($path, PATH_FW) !== FALSE) { $appPart = 'fw'; } elseif (strpos($path, PATH_MODULES) !== FALSE) { $appPart = 'module'; } elseif (strpos($path, PATH_APP) !== FALSE) { $appPart = 'app'; } // do counting per app part $counting = 0; foreach ($fileTranslations as $context => $translation) { $counting += count($translation); } $temp =& $this->amountLoadedPerType[$appPart]; switch ($appPart) { case 'module': $module = str_replace(PATH_MODULES, '', $path); $temp[$module][$lang] = $counting; break; case 'app': case 'fw': $temp[$lang] = $counting; break; } // merge data $this->loadedContent = array_replace_recursive($this->loadedContent, $fileTranslations); } } }
<?php # particular page \Plethora\Router::addRoute('sitemap', '/sitemap')->setController('Frontend\\Sitemap')->setAction('default');
$type = __('Modules'); break; } ?> <p><b><?php echo $type; ?> </b></p> <?php if ($part === 'module') { ?> <table class="table table-bordered table-hover"> <tr> <th>name</th> <?php foreach (\Plethora\Router::getLangs() as $lang) { ?> <th><?php echo $lang; ?> </th> <?php } ?> </tr> <?php foreach ($data as $module => $dataPerModule) { ?> <tr> <td><?php echo $module;
/** * Generate query of particular entity list and search engine. * * @access public * @return SearchEngineGeneratedQueries * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function generateQuery() { $oQuery = DB::queryBuilder()->select('t')->from($this->getModel()->getClass(), 't'); $aJoined = []; $iAlias = 0; $oForm = $this->getForm(); // if search engine form is submitted if ($oForm->isSubmitted()) { $aQueryParams = []; $aIgnoredQueryParams = []; foreach (array_keys($oForm->getFields()) as $sFieldName) { /* @var $oField Form\Field */ $mValue = $oForm->get($sFieldName); if ($mValue !== '') { $aQueryParams[$sFieldName] = $mValue; } else { $aIgnoredQueryParams[] = $sFieldName; } } $sURL = Router::currentUrlWithQueryParams($aQueryParams, $aIgnoredQueryParams); Router::relocate($sURL); } // if URL has any filters $aQueryParamsForSearch = Router::getQueryStringParams(); if (count($aQueryParamsForSearch) > 0) { foreach ($aQueryParamsForSearch as $sFieldName => $mValue) { // if value is not empty if (!is_array($mValue) && $mValue !== '' && $mValue !== NULL || is_array($mValue) && $mValue !== []) { // changing models for theirs IDs if (is_array($mValue)) { foreach ($mValue as &$oValue) { /* @var $oValue \Plethora\ModelCore */ if ($oValue instanceof ModelCore) { $oValue = $oValue->getId(); } } } elseif ($mValue instanceof ModelCore) { $mValue = $mValue->getId(); } // if field is from primary table if ($this->getModel()->getMetadata()->hasField($sFieldName)) { $oQuery->andWhere("t." . $sFieldName . " LIKE '%" . trim($mValue) . "%'"); } elseif ($this->getModel()->getMetadata()->hasAssociation($sFieldName)) { $sAssocTableAlias = 'a' . $sFieldName; if (is_array($mValue)) { $aConditions = []; foreach ($mValue as $mSingleValue) { $aConditions[] = $sAssocTableAlias . ".id ='" . trim($mSingleValue) . "'"; } $sCondition = implode(' OR ', $aConditions); } else { $sCondition = $sAssocTableAlias . ".id ='" . trim($mValue) . "'"; } $oQuery->join('t.' . $sFieldName, $sAssocTableAlias, \Doctrine\ORM\Query\Expr\Join::WITH, $sCondition); } else { $aRelFieldInfo = $this->getRelFieldInfo($sFieldName); if ($aRelFieldInfo !== FALSE) { if (!in_array($aRelFieldInfo->getVar(), $aJoined)) { $iAlias++; $sAlias = 't' . $iAlias; $aJoined[$sAlias] = $aRelFieldInfo->getVar(); $oQuery->join('t.' . $aRelFieldInfo->getVar(), $sAlias); } else { $sAlias = array_search($aRelFieldInfo->getVar(), $aJoined); } $oQuery->andWhere($sAlias . "." . $aRelFieldInfo->getOriginalName() . " LIKE '%" . trim($mValue) . "%'"); } } } } } $oQuery->orderBy('t.id', 'desc'); return SearchEngineGeneratedQueries::factory($oQuery); }
<span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand navbar-brand-logo" href="<?php echo Route::factory('home')->url(); ?> " title="<?php echo __('Main page'); ?> "> <img src="<?php echo Router::getBase() . '/' . Theme::getThemePath(); ?> /images/navbar_logo.png" alt="<?php echo \Plethora\Core::getAppName(); ?> " /> </a> <a class="navbar-brand" href="<?php echo Route::factory('home')->url(); ?> " title="<?php echo __('Main page'); ?>
/** * Get user image styled by "UserLogo" style. * * @access public * @return string * @since 2.1.2-dev * @version 2.1.2-dev */ public function getImageStyled() { $imgStyles = \Plethora\ImageStyles::factory(); $styled = $imgStyles->useStyle('UserLogo', $this->getImagePath()); return \Plethora\Router::getBase() . '/' . $styled; }
/** * Format value. * * @access public * @param ModelCore\FileBroker $oImageBroker * @return string * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function format($oImageBroker) { $sOutput = ''; if ($oImageBroker instanceof ModelCore\FileBroker && $oImageBroker->getFile() instanceof \Model\File) { $oAttributes = Helper\Attributes::factory(); $oField = $this->getField(); /* @var $oField \Plethora\View\ViewField */ $oFile = $oImageBroker->getFile(); /* @var $oFile \Model\File */ // set proper ALT if (!empty($this->sImageAltPattern)) { $oModel = $oField->getEntity()->getModel(); $aFields = $oModel->getMetadata()->getFieldNames(); if ($oModel->hasLocales()) { $aFields = array_merge($aFields, $oModel->getLocalesMetadata()->getFieldNames()); } $sAlt = $this->sImageAltPattern; foreach ($aFields as $sField) { if (strpos($sAlt, ':' . $sField) !== FALSE) { $sAlt = str_replace(':' . $sField, $oModel->{$sField}, $sAlt); } if (strpos($sAlt, ':') === FALSE) { break; } } $oAttributes->addToAttribute('alt', $sAlt); } // get image path $sFieldName = $oField->getName(); $oFormField = $oField->getEntity()->getModel()->getConfig()->getField($sFieldName); /* @var $oFormField \Plethora\Form\Field\ImageModel */ $sImagePath = $oFile->getFullPath(); if (empty($sImagePath) && $oFormField->getDefaultImage() === NULL) { return NULL; } elseif (empty($sImagePath) && $oFormField->getDefaultImage() !== NULL) { $sImagePath = $oFormField->getDefaultImage(); } // stylize image if (!empty($this->sImageStyle)) { $sImagePath = ImageStyles::useStyle($this->sImageStyle, $sImagePath); } $oAttributes->addToAttribute('src', Router::getBase() . '/' . $sImagePath); $sOutput = '<img ' . $oAttributes->renderAttributes() . ' />'; // if this image should be linked to it's original-sized equivalent if ($this->bLinkToOriginalSize) { $sImagePathOriginal = '/' . $oFormField->getUploadPath(TRUE) . '/' . $oFile->getNameWithExt(); $oAttributes = Helper\Attributes::factory()->setAttributes($this->aLinkAttributes); $sOutput = Helper\Html::a($sImagePathOriginal, $sOutput, $oAttributes); } } // return final output return $this->sPrefix . $sOutput . $this->sSuffix; }
/** * 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 */ } } }
/** * Action to set new password after e-mail validation. * * @access public * @return View * @since 1.0.0, 2015-02-17 * @version 2.1.0-dev */ public function actionNewPassword() { // fill up breadcrumbs title and other $this->addBreadCrumb(__('New password')); // get code from $_GET $sCode = Router::getParam('code'); // get recovery code from DB $oRecoveryCode = DB::query("SELECT c FROM \\Model\\User\\RecoveryCode c WHERE c.code = :code")->param('code', $sCode)->single(); /* @var $oResult User\RecoveryCode */ // check if code exists if ($oRecoveryCode instanceof User\RecoveryCode) { $this->addToTitle(' - ' . __('New password')); // get user $oUser = $oRecoveryCode->getUser(); // generate form for account access recovery $oConfig = ModelCore\ModelFormConfig::factory()->noReload()->setFieldsRestriction(['password'])->setMessage(__('Your password has been successfully changed to the new one.'))->setAction(Route::factory('password_recovery')->url()); // get form $oModelForm = $oUser->form('new_password', $oConfig); $oForm = $oModelForm->generate(); // check if form is valid if ($oForm->isSubmittedAndValid()) { $oRecoveryCode->remove(); Session::flash(Route::factory('password_recovery')->url(), __('Password has been changed successfully.')); } $oForm->addToPrefix(View::factory('user/frontend/recovery/new_pass_prefix')->render()); // return view return View::factory('base/form')->bind('oForm', $oForm); } else { $this->addToTitle(' - ' . __('Error occured')); return View::factory('user/frontend/recovery/wrong_code'); } }
/** * Fields config for backend. * * @static * @access protected * @return ModelCore\MConfig * @since 1.1.0-dev * @version 1.3.0-dev */ protected static function generateConfig() { // get config from parent $config = parent::generateConfig(); // get list of all routes $routesList = array_keys(Router::getRoutes()); $routesOptions = []; foreach ($routesList as $value) { $routesOptions[$value] = ['value' => $value, 'label' => $value]; } // BACKEND $config->addField(Form\Field\Hidden::singleton('id')->setDisabled()); $config->addField(Form\Field\Select::singleton('route')->setOptions(array_combine($routesList, $routesList))->setLabel(__('Route'))->setRequired()); $config->addField(Form\Field\Text::singleton('route_parameters')->setLabel(__('Route parameters'))->setQuantity(0)); $config->addField(Form\Field\Text::singleton('url')->setLabel('URL')); $config->addField(Form\Field\Checkbox::singleton('active_routes')->setColumnsAmount(3)->setOptions($routesOptions)->setLabel(__('Active routes'))->setTip(__('List of routes for which the actual route will be active'))); $config->addField(Form\Field\Text::singleton('classes')->setLabel(__('HTML classes'))->addRulesSet(Validator\RulesSetBuilder\String::factory()->regex(':value', '[0-9a-z_-]*'))); // return config return $config; }
/** * ACTION - Backend add action. * * @access public * @return void * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function actionAdd() { $url = Route::factoryBackendURL('files', 'list'); Router::relocate($url); }
<?php /* @version 1.0.1, 2014-11-27 */ /* @var $oUser \Model\User */ ?> <?php if (\Plethora\Router::getParam('id') == \Plethora\Session::get('uid')) { ?> <p style="text-align: center;"> <a href="<?php echo \Plethora\Route::factory('user_profile_edit')->url(); ?> " title="<?php echo __('Edit profile'); ?> "> [ <?php echo __('Edit profile'); ?> ] </a> </p> <?php } ?> <div class="user_profile"> <table> <tbody> <tr>
/** * Render field and return its rendered value. * * @access public * @return string * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function render() { $content = ''; $values = $this->getValue(); $langVersions = $this->isMultilanguage() ? Router::getLangs() : ['und']; $fieldDefaultId = $this->getAttributes()->getAttribute('id'); $fieldDefaultName = $this->getAttributes()->getAttribute('name'); // create all cases of this field's value foreach ($langVersions as $sLang) { $fieldValueContent = []; $langValues = Helper\Arrays::get($values, $sLang, []); $amountOfFieldValues = count($langValues); // check quantity of this field's value for particular lang if ($this->getQuantity() !== 0 && $this->getQuantity() < $amountOfFieldValues) { $amountOfFieldValues = $this->getQuantity(); } // if current amount of fields is below minimal quantity if ($amountOfFieldValues < $this->getQuantityMin()) { $amountOfFieldValues = $this->getQuantityMin(); } // if current amount of fields is higher than maximal quantity if ($this->getQuantityMax() > 0 && $amountOfFieldValues > $this->getQuantityMax()) { $amountOfFieldValues = $this->getQuantityMax(); } // container for one lang values $fieldSingleValue = View::factory('base/form/field_single_lang')->set('sLang', $sLang)->bind('oField', $this); // for each value number for ($i = 0; $i < $amountOfFieldValues; $i++) { $this->getAttributes()->setAttribute('id', $fieldDefaultId . '_' . $sLang . '_' . $i)->setAttribute('name', $fieldDefaultName . '[' . $sLang . '][' . $i . ']'); $this->renderSingleValue($fieldValueContent, $sLang, $i); } // prepend to field whole content $content .= $fieldSingleValue->bind('aLangValues', $fieldValueContent)->render(); } // field pattern if ($this->getQuantity() !== 1) { $this->getAttributes()->setAttribute('id', $fieldDefaultId . '_LANGUAGE_NUMBER')->setAttribute('name', $fieldDefaultName . '[LANGUAGE][NUMBER]'); $sPatternContent = $this->renderSingleValuePattern(); $sPattern = View::factory('base/form/field_single_value')->set('sLang', 'LANGUAGE')->set('sOneValueNumber', 'NUMBER')->bind('sOneValueContent', $sPatternContent)->bind('oField', $this)->render(); $this->getFormObject()->addFieldPattern($this->getName(), $sPattern); } // reset ID and NAME attributes $this->resetIdAttribute(); $this->resetNameAttribute(); // rendering base of field return View::factory($this->getViewBase())->render(['sContent' => $content, 'oField' => $this]); }
/** * This method create output for response. * * @access protected * @param View $oContent * @return Response * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function createResponse(View $oContent = NULL) { if ($oContent === NULL) { $oContent = $this->{Router::getActionName()}(); /* @var $oContent View */ $this->afterAction(); } // render page View if ($oContent instanceof View) { $sContent = $oContent->render(); } else { $sContent = $oContent; } if ($this->bResponseAsJson) { $sResponse = json_encode(['status' => $this->sStatus, 'content' => $sContent]); die($sResponse); } else { // create response $oResponse = new Response(); $oResponse->setContent($sContent); return $oResponse; } }
/** * 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 */ } } }
/** * 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; }
/** * Doctrine model loader * * @static * @access private * @return array models * @since 1.0.0-alpha * @version 1.0.0-alpha */ private static function loadModels() { foreach (Router::getModules() as $aModuleData) { $sPathToModels = PATH_MODULES . $aModuleData['path'] . DS . 'classes' . DS . 'Model'; if (file_exists($sPathToModels)) { static::scanModelDir($sPathToModels, '\\Model'); } } return static::$modelsDirectories; }