Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#16 2022-05-11 09:26:06

etc
Developer
Registered: 2010-11-11
Posts: 5,661
Website GitHub

Re: Connecting a publishing client aka using MarsEdit?

Melonking wrote #333238:

It gets as far as the image_data function, but that returns an error saying the image is not a supported filetype even when it is. I’m not sure how image_data is checking file types exactly. But it seems to be very unhappy about importing a file that has been uploaded to the server via this function!

Hi, thanks for testing.

it looks like image_data() expects an associative array of name, error, tmp_name as its first argument. You might try to pass $file itself.

Offline

#17 2022-05-11 10:55:44

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

Re: Connecting a publishing client aka using MarsEdit?

I was going off the line “@param bool $uploaded If FALSE, $file takes a filename instead of upload vars” in the image_data definition comment, is a file name not just a string?

And the $file var in this case is a struct that contains, a filename, base64 code, an mme type and a blogid. So what I’m doing is converting it into a local file on the server and then trying to pass the name of that file to the existing image upload system so that it can do its thing..

I’m starting to think I might have to call it soon, I just wanted a blog that worked with MarsEdit!


The world will tremble

Offline

#18 2022-05-11 11:15:36

etc
Developer
Registered: 2010-11-11
Posts: 5,661
Website GitHub

Re: Connecting a publishing client aka using MarsEdit?

Melonking wrote #333241:

I was going off the line “@param bool $uploaded If FALSE, $file takes a filename instead of upload vars” in the image_data definition comment, is a file name not just a string?

That’s right, but the filename comes from $file[‘tmp_name’] in this case. I guess you need to pass something like

array(
    'name' => $file['name'],
    'error' => UPLOAD_ERR_OK,
    'tmp_name' => $tempImageFolder.$file['name']
)

as the first argument to image_data().

I’m starting to think I might have to call it soon, I just wanted a blog that worked with MarsEdit!

I’m very much willing to help, but have no MarsEdit to test, sorry.

Offline

#19 2022-05-11 11:28:29

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

Re: Connecting a publishing client aka using MarsEdit?

Aha thank you! I actually tried doing that but then thought I was doing it wrong.

Let see, here is the current code: https://pastebin.com/rY6BH8vP

  • What is happening so far; the image is being uploaded to the mt-tpm folder.
  • I can see a database entry is being made for the new images, the database entries have the correct name, and dimensions, but they are missing an author.
  • However the actual image file is not being moved from the mt-tmp folder to the images folder and is not being given its sequential name.

If you can help me figure out what steps I’m missing to correctly make image_data place the image in the images folder, and how to correct the author in the database entry that would be a huge help!

Also the return url I think is wrong because its returning the image name instead of the sequential number the image should get in the images folder?

EDIT: I can see it is actually removing the images from the mt-tmp folder, so its moving/removing them but not putting them in the images folder.. there are no errors.. is there somewhere else they could be going? YES! Its putting them in the rpc folder! And its naming them “IMPATH3.jpg”. I have no idea what to do about this, image_data has no specs listed to modify its save location?

Last edited by Melonking (2022-05-11 12:36:00)


The world will tremble

Offline

#20 2022-05-11 13:13:08

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

Re: Connecting a publishing client aka using MarsEdit?

Ladies and gents, I present to you the worlds worst implementation of MetaWeblog image upload!

You’re welcome to use/modify it. You must rename the database and table name in code. Change ‘thoughs’ to your database name. (If someone knows how to get the correct database and table prefix automaticity lemmy know!)

This is melon signing off with a minimum viable product!

Add the following to /rpc/TXP_RPCServer.php

$this->addCallback(
                'metaWeblog.newMediaObject',
                'this:mt_uploadImage',
                array('boolean', 'string', 'string', 'string', 'struct'),
                'uploads a media object'
            );
/*
     metaWeblog.newMediaObject
     Description: Uploads a file to your webserver.
     Parameters: String blogid, String username, String password, struct file
     Return value: URL to the uploaded file.
     Notes: the struct file should contain two keys: base64 bits (the base64-encoded contents of the file)
     and String name (the name of the file). The type key (media type of the file) is currently ignored.
     */
     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']
        );
        image_data($newfile, false, 0, false);
        //Crappy code to make it work
        //Get the count of images from the database
        $aiQuery = safe_query("SELECT `AUTO_INCREMENT` FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'thoughts' AND TABLE_NAME = 'txp_image';");
        $aiRow = mysqli_fetch_row($aiQuery);
        $count = $aiRow[0]-1; //Retracted by 1 because we just added a row
        $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-11 14:53:14)


The world will tremble

Offline

#21 2022-05-11 13:51:07

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

Re: Connecting a publishing client aka using MarsEdit?

Nice work, melonking!

Offline

#22 2022-05-11 14:14:04

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

Re: Connecting a publishing client aka using MarsEdit?

Thanks! Iv fixed most of the major issues (its still crappy code). It now works with multiple protocols, can handle . file name and url changes.

But if someone can find a way to easily get the correct sequence number (the auto increment number of the txp_images table) for images that would infinity improve this code! My system of guessing it based on file count is awful.

EDIT: This has been fixed, but there are still issues, see my post before this!

Last edited by Melonking (2022-05-11 14:56:09)


The world will tremble

Offline

#23 2022-05-11 19:18:02

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

Re: Connecting a publishing client aka using MarsEdit?

Melonking wrote #333244:

If someone knows how to get the correct database and table prefix automaticity lemmy know!)

I’m not sure how much access you have to the rest of the Textpattern functions in the XML RPC server, but your database name and prefix is stored in $txpcfg['db'] and $txpcfg['table_prefix'] in your config.php file (sample config.php on GitHub) and if you don’t already have access to $txpcfg there you could include that file as that’s pretty much all it contains. It’s already included in /rpc/index.php but not in /RPC/TXP_RPCServer.php as far as I can see.

There’s also the built-in safe_pfx() function for automatically adding the table prefix in database queries. There’s an example in the code documentation and you can find other instances of it in use if you search txplib_db.php.

Melonking wrote #333246:

if someone can find a way to easily get the correct sequence number (the auto increment number of the txp_images table) for images

If I’m not mistaken, the image_data() function should return the new image’s ID number which you could then use for file renaming. See how it’s used here in the image_insert() function. That may obviate the need for your auto_increment lookup code and what follows it.


TXP Builders – finely-crafted code, design and txp

Offline

#24 2022-05-11 19:59:39

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

Re: Connecting a publishing client aka using MarsEdit?

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.

Is there some event that’s not being fired correctly somewhere?


The world will tremble

Offline

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

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

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

Board footer

Powered by FluxBB