/** * Disable plugin * * @param \Difra\Param\AnyString $name */ public function disableAjaxAction(\Difra\Param\AnyString $name) { if (!\Difra\Plugger::turnOff($name->val())) { \Difra\Ajaxer::notify(\Difra\Locales::get('adm/plugins/failed')); } \Difra\Ajaxer::refresh(); }
/** * Delete page * @param \Difra\Param\AnyInt $id * @param \Difra\Param\AjaxCheckbox $confirm */ public function deleteAjaxAction(\Difra\Param\AnyInt $id, \Difra\Param\AjaxCheckbox $confirm = null) { if ($confirm and $confirm->val()) { \Difra\Plugins\CMS\Page::get($id->val())->delete(); Ajaxer::close(); Ajaxer::redirect('/adm/content/pages'); return; } $page = \Difra\Plugins\CMS\Page::get($id->val()); Ajaxer::display('<span>' . \Difra\Locales::get('cms/adm/delete-page-confirm-1') . $page->getTitle() . \Difra\Locales::get('cms/adm/delete-page-confirm-2') . '</span>' . '<form action="/adm/content/pages/delete/' . $id . '" method="post" class="ajaxer">' . '<input type="hidden" name="confirm" value="1"/>' . '<input type="submit" value="Да"/>' . '<a href="#" onclick="ajaxer.close(this)" class="button">Нет</a>' . '</form>'); }
/** * @param \Difra\Param\AnyInt $id * @param \Difra\Param\AjaxInt $confirm */ public function delAjaxAction(\Difra\Param\AnyInt $id, \Difra\Param\AjaxInt $confirm = null) { if (!($snippet = \Difra\Plugins\CMS\Snippet::getById($id->val()))) { \Difra\Ajaxer::redirect('/adm/cms/snippets'); } if (!$confirm) { \Difra\Ajaxer::confirm(\Difra\Locales::get('cms/adm/snippet/del-confirm1') . $snippet->getName() . \Difra\Locales::get('cms/adm/snippet/del-confirm2')); return; } $snippet->del(); \Difra\Ajaxer::close(); \Difra\Ajaxer::redirect('/adm/content/snippets'); }
/** * Edit user (submit) * @param Param\AnyInt $id * @param Param\AjaxEmail $email * @param Param\AjaxCheckbox $change_pw * @param Param\AjaxString|null $new_pw * @param Param\AjaxData|null $fieldName * @param Param\AjaxData|null $fieldValue */ public function saveAjaxAction(Param\AnyInt $id, Param\AjaxEmail $email, Param\AjaxCheckbox $change_pw, Param\AjaxString $new_pw = null, Param\AjaxData $fieldName = null, Param\AjaxData $fieldValue = null) { $user = User::getById($id->val()); $user->setEmail($email->val()); // $userData['addonFields'] = !is_null($fieldName) ? $fieldName->val() : null; // $userData['addonValues'] = !is_null($fieldValue) ? $fieldValue->val() : null; if ($change_pw->val() and $new_pw and $new_pw->val()) { $user->setPassword($new_pw->val()); Ajaxer::notify(Locales::get('auth/adm/userDataSavedPassChanged')); } else { Ajaxer::notify(Locales::get('auth/adm/userDataSaved')); } Ajaxer::refresh(); }
/** * @backupGlobals enabled */ public function test_actions() { \Difra\Debugger::disable(); \Difra\Ajaxer::clean(); $actions = []; \Difra\Ajaxer::notify('notification message'); $actions[] = ['action' => 'notify', 'message' => 'notification message', 'lang' => ['close' => \Difra\Locales::get('notifications/close')]]; \Difra\Ajaxer::display('<span>test</span>'); $actions[] = ['action' => 'display', 'html' => '<span>test</span>']; \Difra\Ajaxer::error('error message <span>test</span>'); $actions[] = ['action' => 'error', 'message' => 'error message <span>test</span>', 'lang' => ['close' => \Difra\Locales::get('notifications/close')]]; \Difra\Ajaxer::required('element'); $actions[] = ['action' => 'require', 'name' => 'element']; \Difra\Ajaxer::invalid('inv1'); $actions[] = ['action' => 'invalid', 'name' => 'inv1']; \Difra\Ajaxer::invalid('inv2'); $actions[] = ['action' => 'invalid', 'name' => 'inv2']; \Difra\Ajaxer::status('field1', 'bad value', 'problem'); $actions[] = ['action' => 'status', 'name' => 'field1', 'message' => 'bad value', 'classname' => 'problem']; \Difra\Ajaxer::redirect('/some/page'); $actions[] = ['action' => 'redirect', 'url' => '/some/page']; $_SERVER['HTTP_REFERER'] = '/current/page'; \Difra\Ajaxer::refresh(); $actions[] = ['action' => 'redirect', 'url' => '/current/page']; \Difra\Ajaxer::reload(); $actions[] = ['action' => 'reload']; \Difra\Ajaxer::load('someid', 'some <b>content</b>'); $actions[] = ['action' => 'load', 'target' => 'someid', 'html' => 'some <b>content</b>']; \Difra\Ajaxer::close(); $actions[] = ['action' => 'close']; \Difra\Ajaxer::reset(); $actions[] = ['action' => 'reset']; \Difra\Envi::setUri('/current/page'); \Difra\Ajaxer::confirm('Are you sure?'); $actions[] = ['action' => 'display', 'html' => '<form action="/current/page" class="ajaxer"><input type="hidden" name="confirm" value="1"/>' . '<div>Are you sure?</div>' . '<input type="submit" value="' . \Difra\Locales::get('ajaxer/confirm-yes') . '"/>' . '<input type="button" value="' . \Difra\Locales::get('ajaxer/confirm-no') . '" onclick="ajaxer.close(this)"/>' . '</form>']; $this->assertEquals(\Difra\Ajaxer::getResponse(), json_encode(['actions' => $actions], \Difra\Ajaxer::getJsonFlags())); \Difra\Ajaxer::clean(); $this->assertEquals(\Difra\Ajaxer::getResponse(), '[]'); $this->assertFalse(\Difra\Ajaxer::hasProblem()); \Difra\Ajaxer::reload(); \Difra\Ajaxer::clean(true); $this->assertEquals(\Difra\Ajaxer::getResponse(), '[]'); $this->assertTrue(\Difra\Ajaxer::hasProblem()); }
/** * Upload image */ public function indexAction() { \Difra\View::$rendered = true; if (!isset($_GET['CKEditorFuncNum'])) { die; } $funcnum = $_GET['CKEditorFuncNum']; if (!isset($_FILES['upload']) or $_FILES['upload']['error'] != UPLOAD_ERR_OK) { die("<script type=\"text/javascript\">window.parent.CKEDITOR.tools.callFunction({$funcnum}, '','" . \Difra\Locales::get('editor/upload-error') . "');</script>"); } $img = Images::convert(file_get_contents($_FILES['upload']['tmp_name'])); if (!$img) { die("<script type=\"text/javascript\">window.parent.CKEDITOR.tools.callFunction({$funcnum},'','" . \Difra\Locales::get('editor/upload-notimage') . "');</script>"); } try { $link = \Difra\Libs\Vault::add($img); $link = "/up/tmp/{$link}"; } catch (\Difra\Exception $ex) { die("<script type=\"text/javascript\">window.parent.CKEDITOR.tools.callFunction({$funcnum},'','" . $ex->getMessage() . "');</script>"); } die('<script type="text/javascript">window.parent.CKEDITOR.tools.callFunction(' . $funcnum . ",'" . $link . "');</script>"); }
/** * Sets cookie that makes Ajaxer show notification popup * @param string $message * @param bool|string $error */ public function notify($message, $error = false) { if ($error === false) { $error = 'ok'; } elseif ($error === true) { $error = 'error'; } $this->set('notify', ['type' => $error, 'message' => (string) $message, 'lang' => ['close' => Locales::get('notifications/close')]]); }
/** * After ajax password change stuff */ protected function afterPasswordChangeAjax() { Ajaxer::notify(Locales::get('auth/password/changed')); Ajaxer::reset(); }
/** * Change password using recovery link (already logged in stub) * @param AnyString $code */ public function submitAjaxActionAuth(AnyString $code) { Ajaxer::error(Locales::get('auth/recover/already_logged')); }
/** * Delete menu element * @param Difra\Param\AnyInt $id * @param Difra\Param\AjaxCheckbox $confirm */ public function deleteAjaxAction(\Difra\Param\AnyInt $id, \Difra\Param\AjaxCheckbox $confirm = null) { if (!$confirm or !$confirm->val()) { \Difra\Ajaxer::display('<span>' . \Difra\Locales::get('cms/adm/menuitem/delete-item-confirm') . '</span>' . '<form action="/adm/content/menu/delete/' . $id . '" method="post" class="ajaxer">' . '<input type="hidden" name="confirm" value="1"/>' . '<input type="submit" value="Да"/>' . '<a href="#" onclick="ajaxer.close(this)" class="button">Нет</a>' . '</form>'); } else { \Difra\Plugins\CMS\MenuItem::get($id->val())->delete(); \Difra\Ajaxer::refresh(); \Difra\Ajaxer::close(); } }
/** * Add ajaxer events to highlight wrong or correct fields * @return bool */ public function callAjaxerEvents() { if (!empty($this->successful)) { foreach ($this->successful as $field => $result) { Ajaxer::status($field, Locales::get('auth/register/' . $result), 'ok'); } } if (!empty($this->failures)) { foreach ($this->failures as $field => $result) { switch ($result) { case self::REGISTER_LOGIN_SHORT: $loginMinChars = Users::getLoginMinChars(); Ajaxer::status($field, Locales::get('auth/register/login_short/part1') . $loginMinChars . Wordforms::getInstance()->getQuantityForm(Locales::get('auth/register/login_long/part2'), Wordforms::GENDER_MALE | Wordforms::CASE_GENITIVE, $loginMinChars) . Locales::get('auth/register/login_short/part3'), 'error'); break; case self::REGISTER_LOGIN_LONG: $loginMaxChars = Users::getLoginMaxChars(); Ajaxer::status($field, Locales::get('auth/register/login_long/part1') . $loginMaxChars . Wordforms::getInstance()->getQuantityForm(Locales::get('auth/register/login_long/part2'), Wordforms::GENDER_MALE | Wordforms::CASE_GENITIVE, $loginMaxChars) . Locales::get('auth/register/login_long/part3'), 'error'); break; default: Ajaxer::status($field, Locales::get('auth/register/' . $result), 'error'); } } return false; } return true; }
/** * Возвращает строку с "человечной" датой события */ public function getHumanizedDate() { $title = ''; if ($this->fromEventDate != '' && $this->fromEventDate != '0000-00-00' && $this->fromEventDate != $this->eventDate) { $fromEventDate = date('d|m', strtotime($this->fromEventDate)); $exFromEventDate = explode('|', $fromEventDate); $eventDate = date('d|m', strtotime($this->eventDate)); $exEventDate = explode('|', $eventDate); $title .= $exFromEventDate[0] . ' '; $title .= Locales::get("announcements/dates/months/*[name()='month_" . $exFromEventDate[1] . "']"); $title .= Locales::get('announcements/fromTo'); $title .= $exEventDate[0] . ' '; $title .= Locales::get("announcements/dates/months/*[name()='month_" . $exEventDate[1] . "']"); } else { $eventDate = date('w|m', strtotime($this->eventDate)); $exEventDate = explode('|', $eventDate); $title .= Locales::get("announcements/dates/weekdays/*[name()='day_" . $exEventDate[0] . "']") . ', '; $title .= date('d', strtotime($this->eventDate)) . ' '; $title .= Locales::get("announcements/dates/months/*[name()='month_" . $exEventDate[1] . "']"); } if (!empty($this->additionalData)) { foreach ($this->additionalData as $k => $data) { if (isset($data['alias']) && $data['alias'] == 'eventTime') { $title .= ' ' . Locales::get('announcements/in'); $title .= ' ' . $data['value']; } } } return $title; }
/** * Redefine this method if you want custom actions after activation */ protected function afterActivate() { Cookies::getInstance()->notify(Locales::get('auth/activate/done')); \Difra\View::redirect('/'); }
public function resetAjaxAction() { \Difra\Config::getInstance()->reset(); \Difra\Ajaxer::notify(\Difra\Locales::get('adm/config/reset-done')); \Difra\Ajaxer::refresh(); }