Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#25 2022-05-11 20:05:45

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,595
Website

Re: Connecting a publishing client aka using MarsEdit?

Melonking wrote #333248:

Thanks! I’ll mess around with that a little more.

Iv also run into a new issue that does not seem to be related to image uploads. When an article is published via XMLRPC it arrives in the database correctly, however textpattern does not seem to refresh it on the site correctly. The article shows up on the site, but its blank about 80% of the time, however when you edit it on the online interface you can see all the content is there.

In order to actually get your article to display, you have to publish it, then login to the textpattern admin page, open the article, click save and close it again.

When it arrives in the database correctly, which columns are filled? If you are using textile notation, the Body field is pre-rendered to HTML in the Body_html column when you save an article (same for Excerpt and Excerpt_html). If your initial upload is only filling the Body column, then that’s probably why you’re seeing it in the admin area but not on the public-facing site.

When using textile, there’s the function textile_main_fields() (and here but slightly different). You can see it called here as part of the article_save routine.

BTW: I find GitHub’s function cross-referencing helpful for this kind of thing. You can search for a function in the repository. If you click, for example, on textile_main_fields in one of the links above, it will show you where it’s being defined and if you click on “References” in that popup, it will show you where the function is being called so you can see where it appears in a process and how it’s being used.


TXP Builders – finely-crafted code, design and txp

Offline

#26 2022-05-11 20:06:39

redsweater
Member
From: Boston, MA
Registered: 2007-05-26
Posts: 12
Website Twitter

Re: Connecting a publishing client aka using MarsEdit?

You might want to try connecting with MarsEdit via MovableType instead of MetaWeblog. Maybe TextPattern is counting on the two-step dance that MovableType required wherein after a post was published you had to call another API method to “publish” the changes. MarsEdit will do this automatically if the blog is configured to use Movable Type API.

Offline

#27 2022-05-11 20:28:17

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

Re: Connecting a publishing client aka using MarsEdit?

redsweater wrote #333250:

You might want to try connecting with MarsEdit via MovableType instead of MetaWeblog. Maybe TextPattern is counting on the two-step dance that MovableType required wherein after a post was published you had to call another API method to “publish” the changes. MarsEdit will do this automatically if the blog is configured to use Movable Type API.

You are a wizard! That seems to have fixed it, it also fixed an issue where a random <br> tag was appearing in between every <p> tag, which lead to some crazy whitespace.

Im trying to write a few big articles to test its real world usability.

One thing Iv noticed is that if you choose “Upload image with post” instead of uploading the image instantly it totally breaks when you try and publish. That could be fixed if MarsEdit did a bunch of individual uploads as it was posting instead of.. whatever its doing now? But maybe that’s also something missing from the api here?


The world will tremble

Offline

#28 2022-05-11 20:49:48

redsweater
Member
From: Boston, MA
Registered: 2007-05-26
Posts: 12
Website Twitter

Re: Connecting a publishing client aka using MarsEdit?

If you want to investigate the disparity between “Upload with Post” and immediately, open Window -> Network Log and try to upload the same image using both methods, then copy out the portion of the network log pertaining to the newMediaObject call and see if you can determine what MarsEdit is doing differently in either case.

Offline

#29 2022-05-11 21:30:38

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

Re: Connecting a publishing client aka using MarsEdit?

I did a little more digging based on your suggestion, but I’m actually unable to replicate the issue now. Its possible that using MovableType also fixed this issue but Ill keep an eye on it. So the take away here is use MovableType! Ill summarise all this in a final post when I’m done.

Its getting down to the nitty gritty now. It would be nice to be able to write Textpattern’s article excerpts from within MarsEdit, but I imagine that’s not part of the MovableType spec. Overall though I’m pretty happy with what we’ve got so far!


The world will tremble

Offline

#30 2022-05-11 21:36:15

redsweater
Member
From: Boston, MA
Registered: 2007-05-26
Posts: 12
Website Twitter

Re: Connecting a publishing client aka using MarsEdit?

Actually “mt_excerpt” is supported by the Movable Type API and it looks like TextPattern respects it. Just select View -> Excerpt from the menu bar in MarsEdit and try to add it in there and see how it goes :)

Offline

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

Melonking
Member
Registered: 2022-05-10
Posts: 21
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: 21
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: 4,595
Website

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: 21
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