Trial start for anonymous users (AJAX callback).

@author Vova Feldman (@svovaf)
@since  1.2.1.5
182845
function _start_trial_ajax_action() {
            $this->_logger->entrance();

            $this->check_ajax_referer( 'start_trial' );

            if ( ! $this->is_user_admin() ) {
                // Only for admins.
                self::shoot_ajax_failure();
            }

            $trial_data = fs_request_get( 'trial' );

            $next_page = $this->opt_in(
                false,
                false,
                false,
                false,
                false,
                $trial_data['plan_id']
            );

            if ( is_object( $next_page ) && $this->is_api_error( $next_page ) ) {
                self::shoot_ajax_failure(
                    isset( $next_page->error ) ?
                        $next_page->error->message :
                        var_export( $next_page, true )
                );
            }

            $this->shoot_ajax_success( array(
                'next_page' => $next_page,
            ) );
        }
1211472
public function startAction() {
        $posts = $this->getImportBatch(-1);

        if($posts['total'] > 0) {
            try {
                $postIDs = [];
                foreach($posts['posts'] as $post) {
                    $postIDs[] = $post['id'];
                }

                BatchManager::instance()->addToBatchAndRun($this->batchIdentifier(), $postIDs);
            } catch (\Exception $ex) {
                json_response(["status"=>"error", "error" => $ex->getMessage()]);
            }
        } else {
            BatchManager::instance()->reset($this->batchIdentifier());
            json_response(['status' => 'finished']);
        }

        $data = [
            'status' => 'running',
            'total' => $posts['total'],
            'first' => $posts['posts'][0]
        ];

        json_response($data);
    }
1102983
protected function OnSuccess()
    {
        $action = Action::Update();
        $isNew = !$this->layout->Exists();
        if ($isNew)
        {
            $action = Action::Create();
            $this->layout->SetUser(self::Guard()->GetUser());
        }
        $oldFile = $isNew ? '' : PathUtil::LayoutTemplate($this->layout);
        $this->layout->SetName($this->Value('Name'));
        $this->layout->Save();
        $logger = new Logger(self::Guard()->GetUser());
        $logger->ReportLayoutAction($this->layout, $action);
        if ($this->CanAssignGroup())
        {
            $this->SaveRights();
        }
        if ($isNew)
        {
            $this->SaveAreas();
        }
        $this->UpdateFiles($oldFile);
        $args = array('layout'=>$this->layout->GetID());
        Response::Redirect(BackendRouter::ModuleUrl(new AreaList(), $args));
    }
876862
public function callback() {
		$timestamp = date('c');

		// To standardize the way of accessing data, objects are translated to arrays
		$this->auth = $this->recursiveGetObjectVars($this->auth);

		$this->auth['provider'] = $this->strategy['strategy_name'];

		$params = array(
			'auth' => $this->auth,
			'timestamp' => $timestamp,
			'signature' => $this->sign($timestamp)
		);

		$this->shipToCallback($params);
	}
153054
public function handleAjaxCall()
    {
        $environment = $this->getEnvironment();
        $input       = $environment->getInputProvider();

        if (true === ($input->hasParameter('id'))) {
            // Redefine the parameter id if this isn´t model id conform.
            if (false === \strpos($input->getParameter('id'), '::')) {
                $modelId = new ModelId($input->getParameter('table'), $input->getParameter('id'));
                $input->setParameter('id', $modelId->getSerialized());
            }
            $modelId      = ModelId::fromSerialized($input->getParameter('id'));
            $dataProvider = $environment->getDataProvider($modelId->getDataProviderName());
            $model        = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($modelId->getId()));
        }

        $this->addAjaxPropertyForEditAll();

        $handler = new Ajax3X();
        $handler->executePostActions(new DcCompat($environment, ($model ?? null)));
    }
683771
public function enableCallback()
    {
        $this->cb_view = $this->add('View');
        $this->cb_view->stickyGet('__atk_m', $this->name);
        $this->cb = $this->cb_view->add('CallbackLater');

        $this->cb->set(function () {
            if ($this->cb->triggered() && $this->fx) {
                $this->fx[0]($this->cb_view);
            }
            $modalName = isset($_GET['__atk_m']) ? $_GET['__atk_m'] : null;
            if ($modalName === $this->name) {
                $this->app->terminate($this->cb_view->renderJSON());
            }
        });
    }
199931
public function start()
    {
        foreach ($this->callbacks as $event => $callback) {
            $this->client->on($event, $callback);
        }
        $this->connect();
    }
39352
public function call()
    {
        if ('application/json' !== $this->app->request()->headers('Accept')) {

            $this->next->call();

            return; //Only JSON can be turned into JSONP
        }

        $callback = $this->app->request()->get('callback');

        $this->next->call();

        if (empty($callback)) {
            return; //Not a JSONP request
        }

        $this->app->contentType('application/javascript');
        $jsonp = htmlspecialchars($callback) . "(" .$this->app->response()->body() . ")";

        $this->app->response()->body($jsonp);
    }
1263386
public function onHandshake()
    {
        if (!isset($this->route)) {
            return;
        }
        $this->route->onWakeup();
        try {
            $this->route->onHandshake();
        } catch (\Exception $e) {
            Daemon::uncaughtExceptionHandler($e);
        }
        $this->route->onSleep();
    }
849111
public function run_ajax() {
    global $wp_query;

    if ( $wp_query->get("no-admin-ajax") ) {
      // Constant for plugins to know that we are on an AJAX request
      define("DOING_AJAX", true);

      // If we don't have an action, do nothing
      if ( ! isset( $_REQUEST["action"] ) ) {
          die(0);
      }

      // Escape the parameter to prevent disastrous things
      $action = esc_attr( $_REQUEST["action"] );

      // Run customized no-admin-ajax methods with action "no-admin-ajax/before"
      do_action( "no-admin-ajax/before" );

      // Run customized no-admin-ajax methods for specific ajax actions with "no-admin-ajax/before/{action}"
      do_action( "no-admin-ajax/before/". $action );

      // Same headers as WordPress normal AJAX routine sends
      $default_headers = array(
        "Content-Type: text/html; charset=" . get_option( "blog_charset" ),
        "X-Robots-Tag: noindex"
      );

      // Filter to customize the headers sent by ajax calls
      $headers = apply_filters( "no-admin-ajax/headers", $default_headers );

      // Send the headers to the user
      if ( is_array( $headers ) && count( $headers ) > 0 ) {
        foreach ( $headers as $header ) {
          @header( $header );
        }
      }

      send_nosniff_header();
      nocache_headers();

      // Run the actions
      if(is_user_logged_in()) {
          do_action( "wp_ajax_" . $action );
      }
      else {
          do_action( "wp_ajax_nopriv_" . $action );
      }

      die(0);
    }
  }
946277
protected function OnSuccess()
    {
        $action = $this->group->Exists() ? Action::Update() : Action::Create();
        $this->group->SetName($this->Value('Name'));
        $this->group->SetCreateContainers((bool)$this->Value('CreateContainers'));
        $this->group->SetCreateLayouts((bool)$this->Value('CreateLayouts'));
        $this->group->SetCreateContainers((bool)$this->Value('CreateContainers'));
        $this->group->Save();
        $logger = new Logger(self::Guard()->GetUser());
        $logger->ReportUserGroupAction($this->group, $action);
        $target = BackendRouter::ModuleUrl(new UsergroupList());
        Response::Redirect($target);
    }
1084418
public function onReady()
    {
        if ($this->pool->identd) {
            /** @noinspection PhpParamsInspection */
            $this->getSocketName();
            $this->pool->identd->registerPair($this->locAddr, $this->locPort, ['UNIX', $this->user]);
        }
        list($this->nick, $this->realname) = explode('/', $this->path . '/John Doe');
        $this->command('USER', $this->user, 0, '*', $this->realname);
        $this->command('NICK', $this->nick);
        if (mb_orig_strlen($this->password)) {
            $this->message('NickServ', 'IDENTIFY ' . $this->password);
        }
    }
888264
function (server, callback) {
            var self = this;

            this.$server = server;
            this._start(function(err) {
                self.$started = true;
                callback(err);
            });
        }
616852
function _add_tracking_links() {
            if ( ! current_user_can( 'manage_options' ) ) {
                return;
            }

            $this->_logger->entrance();

            /**
             * If the activation has been delegated to site admins, no tracking-related actions for now.
             *
             * @author Leo Fajardo (@leorw)
             */
            if ( $this->_is_network_active && $this->is_network_delegated_connection() ) {
                return;
            }

            if ( fs_request_is_action_secure( $this->get_unique_affix() . '_reconnect' ) ) {
                if ( ! $this->is_registered() && $this->is_anonymous() ) {
                    $this->connect_again();

                    return;
                }
            }

            if ( ( $this->is_plugin() && ! self::is_plugins_page() ) ||
                 ( $this->is_theme() && ! self::is_themes_page() )
            ) {
                // Only show tracking links on the plugins and themes pages.
                return;
            }

            if ( ! $this->is_enable_anonymous() ) {
                // Don't allow to opt-out if anonymous mode is disabled.
                return;
            }

            if ( ! $this->is_free_plan() ) {
                // Don't allow to opt-out if running in paid plan.
                return;
            }

            if ( $this->add_ajax_action( 'stop_tracking', array( &$this, '_stop_tracking_callback' ) ) ) {
                return;
            }

            if ( $this->add_ajax_action( 'allow_tracking', array( &$this, '_allow_tracking_callback' ) ) ) {
                return;
            }

            $url = '#';

            if ( $this->is_registered() ) {
                if ( $this->is_tracking_allowed() ) {
                    $link_text_id = $this->get_text_inline( 'Opt Out', 'opt-out' );
                } else {
                    $link_text_id = $this->get_text_inline( 'Opt In', 'opt-in' );
                }

                add_action( 'admin_footer', array( &$this, '_add_optout_dialog' ) );
            } else {
                $link_text_id = $this->get_text_inline( 'Opt In', 'opt-in' );

                $params = ! $this->is_anonymous() ?
                    array() :
                    array(
                        'nonce'     => wp_create_nonce( $this->get_unique_affix() . '_reconnect' ),
                        'fs_action' => ( $this->get_unique_affix() . '_reconnect' ),
                    );

                $url = $this->get_activation_url( $params );
            }

            if ( $this->is_plugin() && self::is_plugins_page() ) {
                $this->add_plugin_action_link(
                    $link_text_id,
                    $url,
                    false,
                    13,
                    "opt-in-or-opt-out {$this->_slug}"
                );
            }
        }
713263
public function init()
    {
        $this->setName('users');
        $this->setLabel('Users');
        $this->setAttribute('id', 'users');
        
        
        $this->setTargetElement(
            array(
            'type' => 'hidden',
            'name' => 'user',
            )
        );
        
        $this->setCount(0)
             ->setAllowRemove(true)
             ->setAllowAdd(true)
             ->setShouldCreateTemplate(true);
    }
313534
protected function performInit()
    {
        /** @var RouteHelperInterface $routeHelper */
        $routeHelper = app(RouteHelperInterface::class);

        $this->routePrefix = $routeHelper->getRouteNameForModelClass($this->modelClass, true);

        $permissions = $this->actionData->permissions();

        if (empty($permissions)) {
            $this->isPermitted = true;
        } else {
            $this->isPermitted = cms_auth()->can($permissions);
        }
    }
1121062
private function startSession()
    {
        if ('' === session_id()) {
            // no session active
            session_set_cookie_params(
                $this->sessionOptions['lifetime'],
                $this->sessionOptions['path'],
                $this->sessionOptions['domain'],
                $this->sessionOptions['secure'],
                $this->sessionOptions['httponly']
            );
            session_start();
        }
    }