Обработка запросов от JS API

@return void
544963
public function clientOnStart()
    {
        if (HTTP::request()->getFile() != 'cart.php')
        {
            return;
        }

        switch (arg('method'))
        {
            case 'addItem':
                $this->addItem(arg('class', 'word'), arg('id', 'word'), arg('count', 'int'),
                    arg('cost', '[^0-9\.]'));
                break;
            case 'changeAmount':
                $this->changeAmount(arg('class', 'word'), arg('id', 'word'), arg('amount', 'int'));
                break;
            case 'clearAll':
                $this->clearAll();
                break;
            case 'removeItem':
                $this->removeItem(arg('class', 'word'), arg('id', 'word'));
                break;
        }

        $html = $this->clientRenderBlock();
        die($html);
    }
259100
public function run()
    {
        if (!isset($this->content)) {
            $this->content = ob_get_clean();
        }
        echo TbHtml::modalBody($this->content);
        echo TbHtml::modalFooter($this->footer);
        echo '</div>' . PHP_EOL;
        echo '</div>' . PHP_EOL;
        echo '</div>' . PHP_EOL;
        $this->renderButton();
        $this->registerClientScript();
    }
292335
public function run()
	{
		$id = $this->id;
		$content = array();
		$items = $this->normalizeTabs($this->tabs, $content);

		ob_start();
		if ($this->addTabsNavBar) {
			echo '<div class="navbar"><div class="navbar-inner">';
		}
		$this->controller->widget(
			'booster.widgets.TbMenu',
			array(
				'stacked' => $this->stacked,
				'type' => $this->type,
				'encodeLabel' => $this->encodeLabel,
				'items' => $items,
			)
		);
		if ($this->addTabsNavBar) {
			echo '</div></div>';
		}
		$tabs = ob_get_clean();

		ob_start();
		echo '<div class="tab-content">';
		echo implode('', $content);
		echo $this->pagerContent;
		echo '</div>';
		$content = ob_get_clean();

		echo CHtml::openTag('div', $this->htmlOptions);
		echo $this->placement === self::PLACEMENT_BELOW ? $content . $tabs : $tabs . $content;
		echo '</div>';

		/** @var CClientScript $cs */
		$cs = Yii::app()->getClientScript();

		$cs->registerPackage('bootstrap.wizard');

		// Override options
		if ($this->type && !isset($this->options['class'])) {
			$this->options['class'] = $this->type;
		}

		$options = CJavaScript::encode($this->options);

		$cs->registerScript(__CLASS__ . '#' . $id, "jQuery('#{$id}').bootstrapWizard({$options});");

		foreach ($this->events as $name => $handler) {
			$handler = CJavaScript::encode($handler);
			$cs->registerScript(__CLASS__ . '#' . $id . '_' . $name, "jQuery('#{$id}').on('{$name}', {$handler});");
		}
	}
613060
public function admin_ajax() {

		if ( false === headers_sent() ) {
			pods_session_start();

			header( 'Content-Type: text/html; charset=' . get_bloginfo( 'charset' ) );
		}

		// Sanitize input
		// @codingStandardsIgnoreLine
		$params = pods_unslash( (array) $_POST );

		foreach ( $params as $key => $value ) {
			if ( 'action' === $key ) {
				continue;
			}

			// Fixup $_POST data @codingStandardsIgnoreLine
			$_POST[ str_replace( '_podsfix_', '', $key ) ] = $_POST[ $key ];

			// Fixup $params with unslashed data
			$params[ str_replace( '_podsfix_', '', $key ) ] = $value;

			// Unset the _podsfix_* keys
			unset( $params[ $key ] );
		}

		$params = (object) $params;

		$methods = array(
			'add_pod'                 => array( 'priv' => true ),
			'save_pod'                => array( 'priv' => true ),
			'load_sister_fields'      => array( 'priv' => true ),
			'process_form'            => array( 'custom_nonce' => true ),
			// priv handled through nonce
							'upgrade' => array( 'priv' => true ),
			'migrate'                 => array( 'priv' => true ),
		);

		/**
		 * AJAX Callbacks in field editor
		 *
		 * @since unknown
		 *
		 * @param array     $methods Callback methods.
		 * @param PodsAdmin $obj     PodsAdmin object.
		 */
		$methods = apply_filters( 'pods_admin_ajax_methods', $methods, $this );

		if ( ! isset( $params->method ) || ! isset( $methods[ $params->method ] ) ) {
			pods_error( 'Invalid AJAX request', $this );
		}

		$defaults = array(
			'priv'         => null,
			'name'         => $params->method,
			'custom_nonce' => null,
		);

		$method = (object) array_merge( $defaults, (array) $methods[ $params->method ] );

		if ( true !== $method->custom_nonce && ( ! isset( $params->_wpnonce ) || false === wp_verify_nonce( $params->_wpnonce, 'pods-' . $params->method ) ) ) {
			pods_error( __( 'Unauthorized request', 'pods' ), $this );
		}

		// Cleaning up $params
		unset( $params->action );
		unset( $params->method );

		if ( true !== $method->custom_nonce ) {
			unset( $params->_wpnonce );
		}

		// Check permissions (convert to array to support multiple)
		if ( ! empty( $method->priv ) && ! pods_is_admin( array( 'pods' ) ) && true !== $method->priv && ! pods_is_admin( $method->priv ) ) {
			pods_error( __( 'Access denied', 'pods' ), $this );
		}

		$params->method = $method->name;

		$method_name = $method->name;

		$params = apply_filters( "pods_api_{$method_name}", $params, $method );

		$api = pods_api();

		$api->display_errors = false;

		if ( 'upgrade' === $method->name ) {
			$output = (string) pods_upgrade( $params->version )->ajax( $params );
		} elseif ( 'migrate' === $method->name ) {
			$output = (string) apply_filters( 'pods_api_migrate_run', $params );
		} else {
			if ( ! method_exists( $api, $method->name ) ) {
				pods_error( 'API method does not exist', $this );
			} elseif ( 'save_pod' === $method->name ) {
				if ( isset( $params->field_data_json ) && is_array( $params->field_data_json ) ) {
					$params->fields = $params->field_data_json;

					unset( $params->field_data_json );

					foreach ( $params->fields as $k => $v ) {
						if ( empty( $v ) ) {
							unset( $params->fields[ $k ] );
						} elseif ( ! is_array( $v ) ) {
							$params->fields[ $k ] = (array) @json_decode( $v, true );
						}
					}
				}
			}

			// Dynamically call the API method
			$params = (array) $params;

			$output = call_user_func( array( $api, $method->name ), $params );
		}//end if

		// Output in json format
		if ( false !== $output ) {

			/**
			 * Pods Admin AJAX request was successful
			 *
			 * @since  2.6.8
			 *
			 * @param array               $params AJAX parameters.
			 * @param array|object|string $output Output for AJAX request.
			 */
			do_action( "pods_admin_ajax_success_{$method->name}", $params, $output );

			if ( is_array( $output ) || is_object( $output ) ) {
				wp_send_json( $output );
			} else {
				// @codingStandardsIgnoreLine
				echo $output;
			}
		} else {
			pods_error( 'There was a problem with your request.' );
		}//end if

		die();
		// KBAI!
	}
705939
public function run() {
		
		list($name, $id) = $this->resolveNameID();

		if ($this->hasModel()) {
			if ($this->form) {
				echo $this->form->textField($this->model, $this->attribute, $this->htmlOptions);
			} else {
				echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
			}

		} else {
			echo CHtml::textField($name, $this->value, $this->htmlOptions);
		}

		$this->registerClientScript();
		$this->registerLanguageScript();
		$options = !empty($this->options) ? CJavaScript::encode($this->options) : '';

		ob_start();
		echo "jQuery('#{$id}').datetimepicker({$options})";
		foreach ($this->events as $event => $handler) {
			echo ".on('{$event}', " . CJavaScript::encode($handler) . ")";
		}

		Yii::app()->getClientScript()->registerScript(__CLASS__ . '#' . $this->getId(), ob_get_clean() . ';');

	}
190115
public function void() {
		$json = array();

		$this->load->language('extension/payment/pp_express_order');

		if (isset($this->request->get['order_id'])) {
			$order_id = $this->request->get['order_id'];
		} else {
			$order_id = 0;
		}

		$this->load->model('extension/payment/pp_express');

		$paypal_info = $this->model_extension_payment_pp_express->getOrder($order_id);

		if ($paypal_info) {
			$request = array(
				'METHOD'          => 'DoVoid',
				'AUTHORIZATIONID' => $paypal_info['authorization_id'],
				'MSGSUBID'        => uniqid(mt_rand(), true)
			);

			$response = $this->model_extension_payment_pp_express->call($request);

			if (isset($response['ACK']) && ($response['ACK'] != 'Failure') && ($response['ACK'] != 'FailureWithWarning')) {
				$transaction = array(
					'paypal_order_id'       => $paypal_info['paypal_order_id'],
					'transaction_id'        => '',
					'parent_id'             => $paypal_info['authorization_id'],
					'note'                  => '',
					'msgsubid'              => '',
					'receipt_id'            => '',
					'payment_type'          => 'void',
					'payment_status'        => 'Void',
					'pending_reason'        => '',
					'transaction_entity'    => 'auth',
					'amount'                => '',
					'debug_data'            => json_encode($response)
				);

				$this->model_extension_payment_pp_express->addTransaction($transaction);

				$this->model_extension_payment_pp_express->editPayPalOrderStatus($order_id, 'Complete');

				$json['capture_status'] = 'Complete';

				$json['success'] = $this->language->get('text_success');
			} else {
				$json['error'] = (isset($response['L_SHORTMESSAGE0']) ? $response['L_SHORTMESSAGE0'] : $this->language->get('error_transaction'));
			}
		} else {
			$json['error'] = $this->language->get('error_not_found');
		}

		$this->response->addHeader('Content-Type: application/json');
		$this->response->setOutput(json_encode($json));
	}
392717
public function run()
	{
		list($name,$id)=$this->resolveNameID();

		if(isset($this->htmlOptions['id']))
			$id=$this->htmlOptions['id'];
		else
			$this->htmlOptions['id']=$id;
		if(isset($this->htmlOptions['name']))
			$name=$this->htmlOptions['name'];

		if($this->hasModel())
			echo CHtml::activeTextField($this->model,$this->attribute,$this->htmlOptions);
		else
			echo CHtml::textField($name,$this->value,$this->htmlOptions);

		if($this->sourceUrl!==null)
			$this->options['source']=CHtml::normalizeUrl($this->sourceUrl);
		else
			$this->options['source']=$this->source;

		$options=CJavaScript::encode($this->options);
		Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').autocomplete($options);");
	}
625073
public function indexAction()
    {
        if ($this->getRequest()->isAjax()) {
            try {
                $this->loadLayout(null, false, false);
                $this->getLayout()->getUpdate()->setCacheId(null);
                $this->getLayout()->getUpdate()->addHandle(strtolower($this->getFullActionName()) . '_AJAX');
            } catch (Exception $e) {
                Mage::logException($e);
                $this->getResponse()->setHeader('Content-Type', 'application/json');
                $this->getResponse()->setBody(Zend_Json::encode(['error' => true, 'message' => $e->getMessage()]));
            }
        }

        $this->loadLayout();
        $this->renderLayout();
    }
728734
public function jsonCommand(): void
    {
        $data = [
            [
                'id'     => 1,
                'name'   => 'john',
                'status' => 2,
                'email'  => 'john@email.com',
            ],
            [
                'id'     => 2,
                'name'   => 'tom',
                'status' => 0,
                'email'  => 'tom@email.com',
            ],
            [
                'id'     => 3,
                'name'   => 'jack',
                'status' => 1,
                'email'  => 'jack-test@email.com',
            ],
        ];

        $this->output->write('use dump:');
        $this->output->dump($data);

        $this->output->write('use print:');
        $this->output->prints($data);

        $this->output->write('use json:');
        $this->output->json($data);
    }
719418
public function run()
    {
        global $controller;
        $controller = $this;
        // TODO: Implement run() method.
        $this->getResponse()->setContentType("text/plain");
        $script = $this->params['script'];
        $filename = Bootstrap::getSingleton()->getDirectory() . "/scripts/" . $script . ".php";
        ob_start();
        include $filename;
        ob_end_flush();
        $this->getResponse()->setContent(ob_get_contents());
        $this->setTemplate(null);
    }
1230115
public function init()
    {
        try
        {
            $this->data = $this->httpClientResponse->data;
        } catch (\Exception $e)
        {
            \Yii::error($this->httpClientResponse->content, self::className());

            $this->isError       = true;
            $this->errorMessage  = 'Не удалось отформатировать ответ от сервера';
            $this->errorCode     = $this->httpClientResponse->statusCode;
            $this->errorData     = $this->data;

            return;
        }

        if (!$this->httpClientResponse->isOk)
        {
            \Yii::error($this->httpClientResponse->content, self::className());

            $this->isError       = true;
            $this->errorMessage  = $this->api->getMessageByStatusCode($this->httpClientResponse->statusCode);
            $this->errorCode     = $this->httpClientResponse->statusCode;
            $this->errorData     = $this->data;

            return;
        }
    }
1319946
public function run() {
		
		$id = $this->id;
		$content = array();
		$items = $this->normalizeTabs($this->tabs, $content);

		ob_start();
		$this->controller->widget(
			'booster.widgets.TbMenu',
			array(
				'stacked' => $this->stacked,
				'justified' => $this->justified,
				'type' => $this->type,
				'encodeLabel' => $this->encodeLabel,
				'htmlOptions' => $this->tabMenuHtmlOptions,
				'items' => $items,
			)
		);
		$tabs = ob_get_clean();

		ob_start();
		echo CHtml::openTag('div', $this->tabContentHtmlOptions);
		echo implode('', $content);
		echo CHtml::closeTag('div');
		$content = ob_get_clean();

		echo CHtml::openTag('div', $this->htmlOptions);
		echo $this->placement === self::PLACEMENT_BELOW ? $content . $tabs : $tabs . $content;
		echo CHtml::closeTag('div');

		/** @var CClientScript $cs */
		$cs = Yii::app()->getClientScript();
		$cs->registerScript(__CLASS__ . '#' . $id, "jQuery('#{$id}').tab('show');");

		foreach ($this->events as $name => $handler) {
			$handler = CJavaScript::encode($handler);
			$cs->registerScript(__CLASS__ . '#' . $id . '_' . $name, "jQuery('#{$id}').on('{$name}', {$handler});");
		}
	}
839926
public function process()
	{
		$view = $this->getView();
		$context = $this->_getContext();

		try
		{
			parent::process();
		}
		catch( Client_Html_Exception $e )
		{
			$error = array( $this->_getContext()->getI18n()->dt( 'client/html', $e->getMessage() ) );
			$view->standardErrorList = $view->get( 'standardErrorList', array() ) + $error;
		}
		catch( Controller_Frontend_Exception $e )
		{
			$error = array( $this->_getContext()->getI18n()->dt( 'controller/frontend', $e->getMessage() ) );
			$view->standardErrorList = $view->get( 'standardErrorList', array() ) + $error;
		}
		catch( MShop_Plugin_Provider_Exception $e )
		{
			$errors = array( $this->_getContext()->getI18n()->dt( 'mshop', $e->getMessage() ) );
			$errors = array_merge( $errors, $this->_translatePluginErrorCodes( $e->getErrorCodes() ) );

			$view->summaryErrorCodes = $e->getErrorCodes();
			$view->standardErrorList = $view->get( 'standardErrorList', array() ) + $errors;
		}
		catch( MShop_Exception $e )
		{
			$error = array( $this->_getContext()->getI18n()->dt( 'mshop', $e->getMessage() ) );
			$view->standardErrorList = $view->get( 'standardErrorList', array() ) + $error;
		}
		catch( Exception $e )
		{
			$context->getLogger()->log( $e->getMessage() . PHP_EOL . $e->getTraceAsString() );

			$error = array( $context->getI18n()->dt( 'client/html', 'A non-recoverable error occured' ) );
			$view->standardErrorList = $view->get( 'standardErrorList', array() ) + $error;
		}
	}
578025
public function process()
        {
            if ($this->_isXhtml === null) {
                $this->_isXhtml = (false !== strpos($this->_html, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML'));
            }

            $this->_replacementHash = 'MINIFYHTML' . md5($_SERVER['REQUEST_TIME']);
            $this->_placeholders = array();

            // replace SCRIPTs (and minify) with placeholders
            $this->_html = preg_replace_callback(
                    '/(\\s*)(<script\\b[^>]*?>)([\\s\\S]*?)<\\/script>(\\s*)/i'
                    , array($this, '_removeScriptCB')
                    , $this->_html);

            // replace STYLEs (and minify) with placeholders
            $this->_html = preg_replace_callback(
                    '/\\s*(<style\\b[^>]*?>)([\\s\\S]*?)<\\/style>\\s*/i'
                    , array($this, '_removeStyleCB')
                    , $this->_html);

            // remove HTML comments (not containing IE conditional comments).
            $this->_html = preg_replace_callback(
                    '/<!--([\\s\\S]*?)-->/'
                    , array($this, '_commentCB')
                    , $this->_html);

            // replace PREs with placeholders
            $this->_html = preg_replace_callback('/\\s*(<pre\\b[^>]*?>[\\s\\S]*?<\\/pre>)\\s*/i'
                    , array($this, '_removePreCB')
                    , $this->_html);

            // replace TEXTAREAs with placeholders
            $this->_html = preg_replace_callback(
                    '/\\s*(<textarea\\b[^>]*?>[\\s\\S]*?<\\/textarea>)\\s*/i'
                    , array($this, '_removeTextareaCB')
                    , $this->_html);

            // trim each line.
            // @todo take into account attribute values that span multiple lines.
            $this->_html = preg_replace('/^\\s+|\\s+$/m', '', $this->_html);

            // remove ws around block/undisplayed elements
            $this->_html = preg_replace('/\\s+(<\\/?(?:area|base(?:font)?|blockquote|body'
                    . '|caption|center|cite|col(?:group)?|dd|dir|div|dl|dt|fieldset|form'
                    . '|frame(?:set)?|h[1-6]|head|hr|html|legend|li|link|map|menu|meta'
                    . '|ol|opt(?:group|ion)|p|param|t(?:able|body|head|d|h||r|foot|itle)'
                    . '|ul)\\b[^>]*>)/i', '$1', $this->_html);

            // remove ws outside of all elements
            $this->_html = preg_replace_callback(
                    '/>([^<]+)</'
                    , array($this, '_outsideTagCB')
                    , $this->_html);

            // use newlines before 1st attribute in open tags (to limit line lengths)
            $this->_html = preg_replace('/(<[a-z\\-]+)\\s+([^>]+>)/i', "$1\n$2", $this->_html);

            // fill placeholders
            $this->_html = str_replace(
                    array_keys($this->_placeholders)
                    , array_values($this->_placeholders)
                    , $this->_html
            );

            return $this->_html;
        }
627392
public function run()
	{
		if(isset($_GET[self::REFRESH_GET_VAR]))  // AJAX request for regenerating code
		{
			$code=$this->getVerifyCode(true);
			echo CJSON::encode(array(
				'hash1'=>$this->generateValidationHash($code),
				'hash2'=>$this->generateValidationHash(strtolower($code)),
				// we add a random 'v' parameter so that FireFox can refresh the image
				// when src attribute of image tag is changed
				'url'=>$this->getController()->createUrl($this->getId(),array('v' => uniqid())),
			));
		}
		else
			$this->renderImage($this->getVerifyCode());
		Yii::app()->end();
	}
247344
public function fire() {
        $elements = [];
        //добавим геттеры в контейнеры
        //добавим сеттеры в контейнеры
        foreach (Register::$containers as $container) {
            $this->info($container);
            foreach ($this->form_element_methods_get as $method) {
                $params = $this->getMethodParams($container, $method);
                $this->putPhpDoc($container, 'string', $method, $params);
            }
            foreach ($this->form_element_methods_set as $method) {
                $params = $this->getMethodParams($container, $method);
                $this->putPhpDoc($container, $container, $method, $params);
            }
        }
        //добавим элементы в контейнеры
        foreach (Register::$elements as $name => $data) {
            $class = Arr::get($data, 'class');
            foreach (Register::$containers as $container) {
                $params = $this->getMethodParams($class, 'laraform');
                $method = \Illuminate\Support\Str::camel('put_' . $name);
                $this->putPhpDoc($container, $class, $method, $params);
            }
            foreach ($this->form_element_methods_get as $method) {
                $params = $this->getMethodParams($class, $method);
                $this->putPhpDoc($class, 'string', $method, $params);
            }
            foreach ($this->form_element_methods_set as $method) {
                $params = $this->getMethodParams($class, $method);
                $this->putPhpDoc($class, $class, $method, $params);
            }
        }
        $data    = $this->ret;
        $content = \View::make(
            'larakit::!.quickform.ide-helper', [
                'data' => $data,
                'tab'  => "\t",
            ]
        );
        file_put_contents(base_path() . '/_ide_helper_laraform.php', $content);
        $this->info('IDE helper сгенерирован для ' . HelperText::plural_with_number(count($this->classes), 'элемента', 'элементов', 'элементов'));
    }
59750
public function webhook(): void
	{
		//$log = new Logger('botlog');
		//$log->pushHandler(new StreamHandler(__DIR__ . "/../log/botlog.log", Logger::DEBUG));

		if ($data = BotApi::jsonValidate(file_get_contents('php://input'), true)) {
			//$log->debug(file_get_contents('php://input'));
			$update = Update::fromResponse($data);
			$this->processUpdate($update);
		}
	}