Thanks a lot !
I have another question concerning Cb Autoactions.
We have a joomla system plugin with ajax requesst to add autocompletion to CB Activity posting area.
However I'd like to limit this plugin to CB use only for CB Activity pages instead of having it an all pages system plugin, but we still need the ajax functionality.
How could we trigger the Ajax requests from a CB Autoaction code (or link to a file) ? Do you have the same functionality within CB as in Joomla ?
We call
Code:
index.php?option=com_ajax&plugin=Activation&format=json
and the plugin code is
Code:
<?php
/**
* @package Joomla.Plugin
* @author Robert Mittl <info@mittl-medien.de>
* @copyright Copyright © 2019 Robert Mittl. All rights reserved.
* @license GNU General Public License version 3 or later; see LICENSE.txt
* @link https://mittl-medien.de
*/
// No direct access
defined('_JEXEC') or die;
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Filesystem\File;
use Joomla\Registry\Registry;
use Joomla\CMS\Date\Date;
use Joomla\CMS\Uri\Uri as CMSUri;
class PlgSystemActivation extends CMSPlugin
{
/**
* Affects constructor behavior. If true, language files will be loaded automatically.
*
* @var boolean
* @since 1.0
*/
protected $autoloadLanguage = true;
/**
* Application object
*
* @var CMSApplication
* @since 3.2
*/
protected $app;
public function __construct($subject, $params)
{
parent::__construct($subject, $params);
//$this->loadLanguage();
}
//Frontend
public function onBeforeCompileHead()
{
$app = JFactory::getApplication();
$doc =\JFactory::getDocument();
$doc->addScript('/media/plg_system_activation/js/main_activation.js');
}
public static function onAjaxActivation()
{
$app = JFactory::getApplication();
$array = $app->input->getArray();
$contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';
if ($contentType === "application/json") {
//Receive the RAW post data.
$content = trim(file_get_contents("php://input"));
$receivedData = json_decode($content, true);
$folderPath = explode("/", JPATH_ROOT);
$removeLastElement = array_pop($folderPath);
$securePath = implode('/', $folderPath);
$api_key = 'xxxx';
if ($receivedData['task'] === 'getAutoCompleteLocationData') {
$curl = curl_init();
$query = $receivedData["query"];
curl_setopt_array($curl, array(
CURLOPT_URL => "https://societeinfo.com/app/rest/api/v2/places.json/autocomplete?query={$query}&key={$api_key}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$response_location = curl_exec($curl);
curl_close($curl);
//TODO: Split the company name if the result false
$location = $response_location;
return json_decode($response_location);
// Save the result
}
if ($receivedData['task'] === 'getAutoCompleteCompanyData') {
$curl = curl_init();
$query = $receivedData["query"];
$locationId = $receivedData["location_id"];
curl_setopt_array($curl, array(
//correcte url for free autocomplete
CURLOPT_URL => "https://societeinfo.com/app/rest/api/v2/companies.json/autocomplete?SearchMode=autocomplete&withHighlight=true&placeId=${locationId}&query={$query}&limit=10&key={$api_key}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$response_company = curl_exec($curl);
curl_close($curl);
//TODO: Split the company name if the result false
$company = $response_company;
return json_decode($response_company);
}
}
}
}
My idea would have been to move this plugin code to an autoaction but how would we call the ajax after then with CB ?
Thanks for the hint