/** * @ignore */ public static function javascriptTranslations() { $tLanguage = Request::cookie('lang', 'en'); I18n::setLanguage($tLanguage); $tTranslations = array('sunday' => I18n::_('Sunday'), 'monday' => I18n::_('Monday'), 'tuesday' => I18n::_('Tuesday'), 'wednesday' => I18n::_('Wednesday'), 'thursday' => I18n::_('Thursday'), 'friday' => I18n::_('Friday'), 'saturday' => I18n::_('Saturday'), 'change' => I18n::_('Change'), 'remove' => I18n::_('Remove')); LarouxJs::addToDictionary($tTranslations); }
/** * @ignore */ public static function getFromRequest($uChangeField, array $uFields) { $tNewInstance = new static(); $tChangedRecords = Request::post($uChangeField, array()); $tFieldValues = array(); foreach ($uFields as $tField) { $tFieldValues[$tField] = Request::post($tField); } foreach ($tChangedRecords as $tIndex => $tChangedRecord) { $tRecord = array('index' => $tIndex, 'changed' => $tChangedRecord); foreach ($uFields as $tField) { $tRecord[$tField] = isset($tFieldValues[$tField][$tIndex]) ? $tFieldValues[$tField][$tIndex] : null; } $tNewInstance->records[] = $tRecord; } return $tNewInstance; }
/** * Invokes the startup methods just for framework extensions so other parties can take over execution. */ public static function run() { Request::init(); // determine active application $tSelectedApplication = null; foreach (self::$applications as $tApplication) { if (count($tApplication['endpoints']) > 0) { foreach ($tApplication['endpoints'] as $tEndpoint) { foreach ((array) $tEndpoint['address'] as $tEndpointAddress) { if (Request::matchesHostname($tEndpointAddress)) { $tSelectedApplication = $tApplication; break 3; } } } } else { $tSelectedApplication = $tApplication; break; } } // construct application object if ($tSelectedApplication !== null) { self::$application = new Application($tSelectedApplication['namespace'], $tSelectedApplication['directory']); } // load configuration w/ extensions Config::$default = Config::load(); // include files foreach (Config::get('includeList', array()) as $tInclude) { $tIncludePath = pathinfo(Io::translatePath($tInclude)); $tFiles = Io::glob($tIncludePath['dirname'] . '/', $tIncludePath['basename'], Io::GLOB_FILES); if ($tFiles !== false) { foreach ($tFiles as $tFilename) { //! todo require_once? include $tFilename; } } } // loadClass classes foreach (Config::get('loadClassList', array()) as $tClass) { class_exists($tClass, true); } // events foreach (Config::get('eventList', array()) as $tLoad) { if ($tLoad['name'] === 'load') { Events::invokeSingle(array($tLoad['type'], $tLoad['value'])); continue; } Events::register($tLoad['name'], $tLoad['type'], $tLoad['value']); } Request::setRoutes(); // output handling ob_start('Scabbia\\Framework::output'); ob_implicit_flush(false); try { // run extensions $tParms = array(); Events::invoke('pre-run', $tParms); // ignite application if ($tSelectedApplication !== null) { self::$application->before->invoke(); $tReturn = self::$application->callbacks->invoke(); self::$application->after->invoke(); if (self::$application->otherwise !== null && $tReturn !== false) { call_user_func(self::$application->otherwise); return false; } } } catch (CustomException $ex) { if ($tSelectedApplication !== null) { call_user_func(self::$application->onError, $ex->type, $ex->title, $ex->getMessage()); } return false; } return true; }
/** * @ignore */ public static function edit($uAction, $uSlug) { Auth::checkRedirect('editor'); $tModule = AutoModels::get(Panel::$module); $tViewbag = array('module' => $tModule, 'fields' => array()); if (Request::$method === 'post') { //! todo: validations Validation::addRule('name')->isRequired()->errorMessage('Name shouldn\'t be blank.'); // Validation::addRule('slug')->isRequired()->errorMessage('Slug shouldn\'t be blank.'); if (Validation::validate($_POST)) { $tSlug = Request::post('slug', ""); if (strlen(rtrim($tSlug)) === 0) { $tSlug = Request::post('name', ""); } $tInput = array('type' => Request::post('type'), 'name' => Request::post('name'), 'slug' => String::slug(String::removeAccent($tSlug))); $tAutoModel = new AutoModel('categories'); $tAutoModel->update($uSlug, $tInput); Session::set('notification', array('info', 'ok-sign', 'Record modified.')); Http::redirect('panel/categories'); return; } Session::set('notification', array('error', 'remove-sign', Validation::getErrorMessages(true))); foreach ($tModule['fieldList'] as $tField) { $tIsView = array_key_exists('view', $tField['methods']); $tIsEdit = array_key_exists('edit', $tField['methods']); if ($tIsView || $tIsEdit) { if ($tField['type'] === 'enum') { $tTypes = array(); foreach ($tField['valueList'] as $tValue) { $tTypes[$tValue['name']] = $tValue['title']; } $tAttributes = array('name' => $tField['name'], 'class' => 'input-block-level input_' . $tField['type']); if (!$tIsEdit) { $tAttributes['readonly'] = 'readonly'; } $tTag = '<p>' . I18n::_($tField['title']) . ': ' . Html::tag('select', $tAttributes, Html::selectOptions($tTypes, Request::post($tField['name'], null))) . '</p>'; } else { $tAttributes = array('type' => 'text', 'name' => $tField['name'], 'value' => Request::post($tField['name'], ""), 'class' => 'input-block-level input_' . $tField['type']); if (!$tIsEdit) { $tAttributes['readonly'] = 'readonly'; } $tTag = '<p>' . I18n::_($tField['title']) . ': ' . Html::tag('input', $tAttributes) . '</p>'; } } $tViewbag['fields'][] = array('data' => $tField, 'html' => $tTag); } Views::viewFile('{core}views/panel/models/form.php', $tViewbag); return; } $tAutoModel = new AutoModel('categories'); $tCategory = $tAutoModel->getBySlug($tModule['name'], $uSlug); foreach ($tModule['fieldList'] as $tField) { $tIsView = array_key_exists('view', $tField['methods']); $tIsEdit = array_key_exists('edit', $tField['methods']); if ($tIsView || $tIsEdit) { if ($tField['type'] === 'enum') { $tTypes = array(); foreach ($tField['valueList'] as $tValue) { $tTypes[$tValue['name']] = $tValue['title']; } $tAttributes = array('name' => $tField['name'], 'class' => 'input-block-level input_' . $tField['type']); if (!$tIsEdit) { $tAttributes['readonly'] = 'readonly'; } $tTag = '<p>' . I18n::_($tField['title']) . ': ' . Html::tag('select', $tAttributes, Html::selectOptions($tTypes, $tCategory[$tField['name']])) . '</p>'; } else { $tAttributes = array('type' => 'text', 'name' => $tField['name'], 'value' => $tCategory[$tField['name']], 'class' => 'input-block-level input_' . $tField['type']); if (!$tIsEdit) { $tAttributes['readonly'] = 'readonly'; } $tTag = '<p>' . I18n::_($tField['title']) . ': ' . Html::tag('input', $tAttributes) . '</p>'; } } $tViewbag['fields'][] = array('data' => $tField, 'html' => $tTag); } Views::viewFile('{core}views/panel/models/form.php', $tViewbag); }
/** * @ignore */ public function login() { if (Request::$method !== 'post') { Auth::clear(); $this->viewFile('{core}views/panel/login.php'); return; } // validations Validation::addRule('username')->isRequired()->errorMessage('Username shouldn\'t be blank.'); // Validation::addRule('username')->isEmail()->errorMessage('Please consider your e-mail address once again.'); Validation::addRule('password')->isRequired()->errorMessage('Password shouldn\'t be blank.'); Validation::addRule('password')->lengthMinimum(4)->errorMessage('Password should be longer than 4 characters at least.'); if (!Validation::validate($_POST)) { Session::set('notification', array('error', 'remove-sign', Validation::getErrorMessages(true))); $this->viewFile('{core}views/panel/login.php'); return; } $username = Request::post('username'); $password = Request::post('password'); // user not found if (!Auth::login($username, $password)) { Session::set('notification', array('error', 'remove-sign', 'User not found')); $this->viewFile('{core}views/panel/login.php'); return; } Http::redirect('panel'); }
/** * @ignore */ public static function loginUrl($uForcePermissions = false, $uRedirectUrl = null) { if (self::$userId !== self::NO_USER_ID) { if (!$uForcePermissions || self::checkUserPermission(self::$appPermissions)) { return array(true); } } $tError = Request::get('error_code', null); if ($tError !== null) { return array(false, null); } $tCode = Request::get('code', null); if ($tCode === null) { Session::set('facebookData', self::$facebookData); $tLoginUrl = self::$api->getLoginUrl(array('scope' => self::$appPermissions, 'redirect_uri' => $uRedirectUrl !== null ? $uRedirectUrl : self::$appRedirectUri)); return array(false, $tLoginUrl); } return array(true); }