Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#31 2022-05-11 21:58:28

Melonking
Member
Registered: 2022-05-10
Posts: 24
Website

Re: Connecting a publishing client aka using MarsEdit?

Aha it works! I think I’m running out of problems!


The world will tremble

Offline

#32 2022-05-12 00:28:22

Melonking
Member
Registered: 2022-05-10
Posts: 24
Website

Re: Connecting a publishing client aka using MarsEdit?

Revised upload code with fixes based on @jakob’s suggestion. Its a bit messy and but pretty robust now.

Things that someone more knowledgeable can advise on;
  • Changing the tm-tmp folder to the standard textpattern temp folder
  • Figure out why files are placed as IMPATH[id].[filetype] in the rpc folder by image_data(), instead of the images folder like they should be?
  • Using the settings image folder path instead of a hard coded path.
function mt_uploadImage($params)
     {
        list($blogid, $username, $password, $file) = $params;
        $txp = new TXP_Wrapper($username, $password);
        if (!$txp->loggedin) {
            return new IXR_Error(100, gTxt('bad_login'));
        }
        //Temp File Upload
        $tempImageFolder = getcwd().'/../images/mt-tmp/';
        if (!file_exists($tempImageFolder)) {
            mkdir($tempImageFolder, 0777, true);
        }
        file_put_contents($tempImageFolder.$file['name'], $file['bits']);
        //Create the final file and input into database
        $newfile = array(
            'name' => $file['name'],
            'error' => false,
            'tmp_name' => $tempImageFolder.$file['name']
        );
        //Get the sequence count of the new image upload
        $id = image_data($newfile, false, 0, false);
        $count = $id[1];
        //Crappy fix for the file being in the wrong location for some reason
        $filetype = end(explode('.', $file['name'])); //Get the uploaded filetype
        rename(getcwd()."/IMPATH".$count.'.'.$filetype, getcwd()."/../images/".$count.'.'.$filetype);
        //Return
        $returnValue = array(
           'url' => '/images/'.$count.'.'.$filetype
        );
        return $returnValue;
     }

Last edited by Melonking (2022-05-12 00:29:55)


The world will tremble

Offline

#33 2022-05-12 07:15:43

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,218
Website GitHub

Re: Connecting a publishing client aka using MarsEdit?

Melonking wrote #333256:

Revised upload code with fixes based on @jakob’s suggestion. Its a bit messy and but pretty robust now.

Nice going!

  • Changing the tm-tmp folder to the standard textpattern temp folder
  • Figure out why files are placed as IMPATH[id].[filetype] in the rpc folder by image_data(), instead of the images folder like they should be?
  • Using the settings image folder path instead of a hard coded path.

I’m not knowledgeable enough about how much access you have to other Textpattern functions or variables/constants in XML-RPC but generally you can retrieve values from the prefs using

  • get_pref('prefs_value'); or global $prefs; $prefs['prefs_value']. For the temporary directory the prefs value is tempdir (see here, here or here for example) and for the image directory img_dir*. The latter only holds the folder name so you also need to construct the path with $path_to_site or txpath, but you may be able to skip that because …

… the constant IMPATH is defined here as:

define('IMPATH', $path_to_site.DS.$img_dir.DS);

where DS is the platform-independent constant for directory separator (defined here using IS_WIN defined just above it here).

If you don’t have access to these functions, constants or variables, then you can recreate them accordingly.

*You can also see the available prefs values and their formats by looking at the txp_prefs table in the database.


TXP Builders – finely-crafted code, design and txp

Offline

#34 2022-05-13 17:09:21

Melonking
Member
Registered: 2022-05-10
Posts: 24
Website

Re: Connecting a publishing client aka using MarsEdit?

@jakob This was a huge help thank you! I think it should now be stable enough to include in the main code, I submitted a pull request here! https://github.com/textpattern/textpattern/pull/1809


The world will tremble

Offline

Board footer

Powered by FluxBB