Example #1
0
 /**
  * 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();
 }
Example #2
0
 public function savesettingsAjaxAction(\Difra\Param\AjaxString $consumerKey, \Difra\Param\AjaxString $consumerSecret, \Difra\Param\AjaxString $oauthToken, \Difra\Param\AjaxString $oauthSecret, \Difra\Param\AjaxCheckbox $postToTwitter)
 {
     $oAuthArray = ['consumerKey' => $consumerKey->val(), 'consumerSecret' => $consumerSecret->val(), 'accessToken' => $oauthToken->val(), 'accessTokenSecret' => $oauthSecret->val(), 'postToTwitter' => $postToTwitter->val()];
     \Difra\Config::getInstance()->set('oAuth', $oAuthArray);
     \Difra\Ajaxer::refresh();
     \Difra\Ajaxer::notify(\Difra\Locales::getInstance()->getXPath('twitter/adm/oAuth/settingsSaved'));
 }
Example #3
0
 /**
  * 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>');
 }
Example #4
0
 /**
  * @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');
 }
Example #5
0
 public function deleteAjaxAction(\Difra\Param\AnyInt $id)
 {
     $this->subInit();
     try {
         $class = \Difra\Unify\Storage::getClass('WidgetsDirectory');
         $object = $class::get((string) $id);
         if ($object->directory != static::directory) {
             throw new \Difra\Exception('This item does not exist in this directory.');
         }
         $object->delete();
     } catch (\Difra\Exception $ex) {
     }
     \Difra\Ajaxer::getInstance()->load('#DirectoryWindow', $this->renderWindow());
 }
Example #6
0
 /**
  * Alter table for Unify object
  *
  * @param \Difra\Param\AnyString $name
  */
 public function alterAjaxAction(\Difra\Param\AnyString $name)
 {
     try {
         /** @var \Difra\Unify\Item $class */
         $class = \Difra\Unify\Storage::getClass($name->val());
         $status = $class::getObjDbStatus();
         if ($status['status'] == 'alter') {
             \Difra\MySQL::getInstance()->query($status['sql']);
         }
     } catch (\Difra\Exception $ex) {
         \Difra\Ajaxer::notify($ex->getMessage());
     }
     \Difra\Ajaxer::refresh();
 }
Example #7
0
    public function action($value)
    {
        $escapedValue = addslashes(htmlspecialchars($value));
        \Difra\Ajaxer::getInstance()->exec(<<<SCRIPT
\t\t\tvar person = \$( '.widgets-directory.last' );
\t\t\tif( person.length ) {
\t\t\t\tvar id = person.closest( 'tr' ).find( '.portfolio-role' ).attr( 'ts' );
\t\t\t\tperson.before(
\t\t\t\t\t'<div class="portfolio-person">' +
\t\t\t\t\t  '{$escapedValue}' +
\t\t\t\t\t  '<input type="hidden" name="roles[' + id + '][]" value="{$escapedValue}">' +
\t\t\t\t\t  '<a href="#" class="action delete" onclick="\$(this).parent().remove();"></a>' +
\t        \t\t\t'</div>'
\t        \t\t);
\t        \t}
SCRIPT
);
    }
Example #8
0
 /**
  * @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 &lt;span&gt;test&lt;/span&gt;', '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());
 }
Example #9
0
    public function action($value)
    {
        $escapedValue = addslashes(htmlspecialchars($value));
        $ts = microtime(true);
        \Difra\Ajaxer::getInstance()->exec(<<<SCRIPT
\t\t\tif( \$( '.widgets-directory.last' ).closest( '#add-role' ).length ) {
\t\$( '#add-role' ).before(
\t\t'<tr>' +
\t\t '<td>' +
\t\t  '<a href="#" class="action delete" onclick="\$(this).parent().parent().remove()"></a> &nbsp; ' +
\t\t  '{$escapedValue}' +
\t\t  '<input type="hidden" name="roles[{$ts}][role]" value="{$escapedValue}" class="portfolio-role" ts="{$ts}">' +
\t         '</td>' +
\t\t '<td class="add-person"><a href="/adm/content/portfolio/persons" class="action add ajaxer widgets-directory"></a></td>' +
\t\t'</tr>'
\t);
}
SCRIPT
);
    }
Example #10
0
 /**
  * Choose view depending on request type
  */
 public static final function start()
 {
     $controller = Controller::getInstance();
     if (Controller::hasUnusedParameters()) {
         $controller->putExpires(true);
         throw new HttpError(404);
     } elseif (!is_null(self::$output)) {
         $controller->putExpires();
         header('Content-Type: ' . self::$outputType . '; charset="utf-8"');
         echo self::$output;
         View::$rendered = true;
     } elseif (Debugger::isEnabled() and isset($_GET['xml']) and $_GET['xml']) {
         if ($_GET['xml'] == '2') {
             View\XML::fillXML();
         }
         header('Content-Type: text/xml; charset="utf-8"');
         $controller->xml->formatOutput = true;
         $controller->xml->encoding = 'utf-8';
         echo rawurldecode($controller->xml->saveXML());
         View::$rendered = true;
     } elseif (!View::$rendered and Request::isAjax()) {
         $controller->putExpires();
         // should be application/json, but opera doesn't understand it and offers to save file to disk
         header('Content-type: text/plain');
         echo Ajaxer::getResponse();
         View::$rendered = true;
     } elseif (!View::$rendered) {
         $controller->putExpires();
         try {
             View::render($controller->xml);
         } catch (HttpError $ex) {
             if (!Debugger::isConsoleEnabled()) {
                 throw new HttpError(500);
             } else {
                 echo Debugger::debugHTML(true);
                 die;
             }
         }
     }
 }
Example #11
0
 /**
  * Move menu element down
  * @param Difra\Param\AnyInt $id
  */
 public function downAjaxAction(\Difra\Param\AnyInt $id)
 {
     \Difra\Plugins\CMS\MenuItem::get($id->val())->moveDown();
     \Difra\Ajaxer::refresh();
 }
Example #12
0
 public function sortAjaxAction(\Difra\Param\AnyString $sort)
 {
     \Difra\Plugins\Catalog::getInstance()->setSort($sort->val());
     \Difra\Ajaxer::refresh();
 }
Example #13
0
 /**
  * After success actions
  * @param $redirect
  */
 protected function afterSuccess($redirect = false)
 {
     if ($redirect) {
         Cookies::getInstance()->notify(Locales::get('auth/register/complete-' . Users::getActivationMethod()));
         View::redirect('/');
     } else {
         Ajaxer::notify(Locales::get('auth/register/complete-' . Users::getActivationMethod()));
         Ajaxer::close();
     }
 }
Example #14
0
 /**
  * Manual user activation
  * @param Param\AnyInt $id
  */
 public function activateAjaxAction(Param\AnyInt $id)
 {
     User::getById($id->val())->activateManual();
     Ajaxer::refresh();
 }
Example #15
0
 /**
  * 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;
 }
Example #16
0
 /**
  * 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'));
 }
Example #17
0
 /**
  * After ajax password change stuff
  */
 protected function afterPasswordChangeAjax()
 {
     Ajaxer::notify(Locales::get('auth/password/changed'));
     Ajaxer::reset();
 }
Example #18
0
 /**
  * After ajax logout stuff
  */
 protected function afterLogoutAjax()
 {
     // TODO: redirect to / if page requires auth
     Ajaxer::reload();
 }
Example #19
0
 public function deleteAction(\Difra\Param\AnyInt $id)
 {
     \Difra\Plugins\Announcements\Additionals::delete($id->val());
     \Difra\Ajaxer::getInstance()->refresh();
 }
Example #20
0
 /**
  * Callback for fatal errors
  */
 public static function captureShutdown()
 {
     if (View::$rendered) {
         return;
     }
     // was there an error?
     if (!($error = error_get_last()) and !self::$handledByException) {
         return;
     }
     if ($error) {
         // add error to console log
         if (self::$handledByNormal != $error['message']) {
             $error['error'] = Libs\Debug\ErrorConstants::getInstance()->getVerbalError($error['type']);
             $error['class'] = 'errors';
             $error['traceback'] = debug_backtrace();
             array_shift($error['traceback']);
             self::addLineAsArray($error);
         }
     }
     self::$shutdown = true;
     // view was not rendered yet, render console standalone page
     if (!View::$rendered) {
         if (!Request::isAjax()) {
             echo self::debugHTML(true);
         } else {
             echo Ajaxer::getResponse();
         }
         View::$rendered = true;
     }
 }
Example #21
0
 /**
  * Process parameters and run action
  */
 private function callAction()
 {
     $method = $this->method;
     $actionMethod = Action::${$method};
     $actionReflection = new \ReflectionMethod($this, $actionMethod);
     $actionParameters = $actionReflection->getParameters();
     // action has no parameters? just call it.
     if (empty($actionParameters)) {
         call_user_func([$this, $actionMethod]);
         return;
     }
     // get named REQUEST_URI parameters list
     $namedParameters = [];
     foreach ($actionParameters as $parameter) {
         $class = $parameter->getClass() ? $parameter->getClass()->name : 'Difra\\Param\\NamedString';
         if (call_user_func(["{$class}", "getSource"]) == 'query' and call_user_func(["{$class}", "isNamed"])) {
             $namedParameters[] = $parameter->getName();
         }
     }
     // get parameter values
     $callParameters = [];
     foreach ($actionParameters as $parameter) {
         $name = $parameter->getName();
         $class = $parameter->getClass() ? $parameter->getClass()->name : 'Difra\\Param\\NamedString';
         switch (call_user_func(["{$class}", "getSource"])) {
             // query parameters
             case 'query':
                 if (call_user_func(["{$class}", "isNamed"])) {
                     // named parameter
                     if (sizeof(self::$parameters) >= 2 and self::$parameters[0] == $name) {
                         array_shift(self::$parameters);
                         if (!call_user_func(["{$class}", 'verify'], self::$parameters[0])) {
                             throw new View\HttpError(404);
                         }
                         $callParameters[$parameter->getName()] = new $class(array_shift(self::$parameters));
                     } elseif (call_user_func(["{$class}", 'isAuto'])) {
                         $callParameters[$name] = new $class();
                     } elseif (!$parameter->isOptional()) {
                         throw new View\HttpError(404);
                     } else {
                         $callParameters[$parameter->getName()] = null;
                     }
                     array_shift($namedParameters);
                 } else {
                     // unnamed parameter
                     if (!empty(self::$parameters) and (!$parameter->isOptional() or empty($namedParameters) or self::$parameters[0] != $namedParameters[0])) {
                         if (!call_user_func(["{$class}", 'verify'], self::$parameters[0])) {
                             throw new View\HttpError(404);
                         }
                         $callParameters[$name] = new $class(array_shift(self::$parameters));
                     } elseif (!$parameter->isOptional()) {
                         throw new View\HttpError(404);
                     } else {
                         $callParameters[$parameter->getName()] = null;
                     }
                 }
                 break;
                 // ajax parameters
             // ajax parameters
             case 'ajax':
                 $value = Request::getParam($name);
                 if (!is_null($value) and $value !== '') {
                     if (!call_user_func(["{$class}", "verify"], $value)) {
                         Ajaxer::invalid($name);
                         continue;
                     }
                     $callParameters[$name] = new $class($value);
                 } elseif (call_user_func(["{$class}", 'isAuto'])) {
                     $callParameters[$name] = new $class();
                 } elseif (!$parameter->isOptional()) {
                     Ajaxer::required($name);
                 } else {
                     $callParameters[$name] = null;
                 }
         }
     }
     if (!Ajaxer::hasProblem()) {
         call_user_func_array([$this, $actionMethod], $callParameters);
     }
 }
Example #22
0
 public function resetAjaxAction()
 {
     \Difra\Config::getInstance()->reset();
     \Difra\Ajaxer::notify(\Difra\Locales::get('adm/config/reset-done'));
     \Difra\Ajaxer::refresh();
 }