0

When copying a webpage to my Joomla site, there is a big hassle which is dealing with images. We can easily copy text content and its format but we will have to download the images on the webpage, upload them to my website, and modify lots of the src attributes.

Because I have a lot of articles to copy, I am thinking to make a plugin so I can just copy the webpage, paste it to the editor, and save without worrying about downloading the images and changing src manually. I've managed to write a light PHP application(it is a standalone PHP file put in Joomla site's image folder, but it has nothing to do with Joomla) that accepts a folder name and an array of images' original src as POST data, then it will create the folder and directly download images into it(using file_get_content). So after I copy/paste, the plugins needs to capture the onBeforeSave(or something like that) event, and retrieve the content's info grabbing each images' link, then send its link along with the article's id(using id as folder name) to my image downloading application.

The problem is, inside a plugin, how to send the POST data? Does joomla provide some function that can handle this? Or I have to use the vanilla PHP way?

public function onBeforeEasyBlogSave($post, $isNew)
{
    $folder = $post->id;
    $content = $post->content;
    imageLinks  = getImageLinks($content);
    // How do I post $folder and $imageLinks to getImage.php?


}
1

If you want to send requests to a remote site, use HTTP API. Basic example:

use Joomla\CMS\Http\HttpFactory;

$http     = HttpFactory::getHttp();
$response = $http->post($url, $data);

Where $url is the script's URL and $data is an associative array containing the data.

0

Not sure of the strategy, but here are the tactics:

$app = JFactory::getApplication();
$input = $app->input;
$get_or_post_var = $input->get('get_or_post_var', 'default_value');
$post_var = $input->post->get('post_var', 'default_value');
$get_var = $input->get->get('get_var', 'default_value');
// and the actual question
$image_data = $input->files->get('image_var', 'default_var');
// $image_data is an array if single upload or an array of arrays if multiple upload -- basically same data as $_FILES but pivoted into a more intuitive format

Good reference here: https://docs.joomla.org/Retrieving_request_data_using_JInput

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.