WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Using cron job to run Blogger Image Import (11 posts)

  1. Huwman
    Member
    Posted 7 years ago #

    Hi there, I've tried my best to use the search function and google to answer this, but I couldn't quite find one.

    I'm *this* close to finishing my blog setup but I have one minor hurdle to go before I'm done. I've just got the Sony-Ericsson K800 phone, which has a nifty photo blogging feature. Though, as you may have heard, it's only compatible with Blogger.

    I've installed FeedWordPress and set up a cron job to import new posts from the blogger account every hour and this works perfectly. However, the pictures also need to come across as Blogger does not allow hot-linking.

    So, I have installed Blogger Image Import, which also does exactly what it said it would, but only when I log in to my account and run the script from the dashboard. What I want to do is have this script scheduled to run automatically 5 minutes after the feedwordpress script runs.

    I don't really know that much about php, but I think I can see at least two ways of doing this;

    a) stripping out the code from "blogger-image-import.php" that actually performs the import, placing it in another php file and cron jobbing that every hour.

    or

    b) stripping out the import code and inserting it into the "update-feeds.php" file (the feedwordpress script). So that it's run all as part of the same file.

    If either of these would work, my problem would be that I don't know which parts of the files I'd need to edit. So any help would be greatly appreciated.

  2. Poco
    Member
    Posted 7 years ago #

    Sorry for not replying to your comment on the blogger-image-import site, but I see you have found another forum for your question (probably better as more people can help).

    The image import script is not all that complicated and most of the code is borrowed from the core WordPress scripts, with some changes. Adding that to the feedwordpress script probably wouldn't be too hard, though I don't know anything about the feedwordpress script.

    You should find it easy to use the Blogger Image Import script somewhere else. All the code is in the function ko_blogger_image_import_process which takes only two parameters, the number of images to import and whether to apply the changes. If you included that code and called that function with a sufficiently large number it should automatically import any new images since the last time you ran it.

    If you do add this to your update-feeds.php or need help with it please reply here and leave a comment about your changes on the Blogger Image Import page.
    http://notions.okuda.ca/wordpress-plugins/blogger-image-import/

  3. Huwman
    Member
    Posted 7 years ago #

    Thanks for the reply Poco, I'll try and see if I can work it out and post the changes.

    Feel free to delete my comment from the BII page if you want, I realised that I shouldn't have asked any support questions there so I came and posted this thread here.

  4. Huwman
    Member
    Posted 7 years ago #

    I may be closing in on a solution, but now I'm getting php errors, which may as well be written in greek for all I understand.

    I have edited the tail end of the blogger-image-import.php file to look like

    http://www.tehbest.com/blog-img-import.phps
    (remove the s)

    but when the server runs it, it returns an error of

    PHP Fatal error: Call to a member function on a non-object in ../wp-content/plugins/blog-img-import.php on line 246

    line 246 is
    $words = $wpdb->get_results("SELECT ID, post_content FROM $tableposts WHERE post_status = 'publish' AND post_date < '$now'");

    which I have not altered at all.

    any thoughts?

  5. Huwman
    Member
    Posted 7 years ago #

    Right, I have no idea what I'm doing so I'm giving up, for now. If anyone can solve this, please help, it's driving me up the wall.

    thanks.

  6. Poco
    Member
    Posted 7 years ago #

    Hmmm, yes, that code uses some globals that are expected to be available when executed by a plugin. I guess the way you are using it they are not.

    I don't know much about how the feedwordpress plugin is configured or executed (I assume this is the plugin to which you refer http://projects.radgeek.com/feedwordpress/).

    It looks like you want to be careful about where insert the calls to the Blogger Image Import. Including that file inside update-feeds.php might not be enough, or you may want to insert the call to ko_blogger_image_import_process somewhere else in update-feeds.php.

    I notice on the feedwordpress site there is a feedwordpress_update_complete action that might be exploited for this purpose.

    I have not tried it, but if I did (I might try when I get more time) I would keep the blogger-image-import.php as-is with the addition of an action handler for feedwordpress_update_complete. Maybe at the bottom, after the add_action('admin_menu') you could add something like the following. I am hoping that function will be called when feedwordpress is complete. When I get a chance I may try this myself, and I will report back if you haven't already.

    function ko_blogger_import_feed_complete()
    {
    ko_blogger_image_import_process(10, true);
    }

    add_action('feedwordpress_update_complete', 'ko_blogger_import_feed_complete');

  7. Huwman
    Member
    Posted 7 years ago #

    Hi.

    Again, thanks for your time,

    I've decided not to try and combine the files to help with any upgrades in the future, so if we can forget about feedwordpress, I only have to get your script working outside of the dashboard.

    I guessed it might have been taking some variables from the dashboard. I don't suppose there'd be an easy way of including them with an
    include();

    or something similar at the top of the file?

    I guess what I'm trying to achieve now is to make a version of your plug-in that works outside of the dashboard.

  8. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    Can it send photos via email? If so, I recommend just installing Postie and setting up a blog email account at GMail or something. Then to "blog" a photo you just send the picture to the special email account.

    Works for me.

  9. Poco
    Member
    Posted 7 years ago #

    If you want to make a page that you can hit to do the image import then you should be able to do something like feedwordpress has done with update-feeds.php. You shouldn't have to change the plugin at all, you just need to create a page that hits the server in a way that emulates what happens you when you press "Start" from the admin interface.

    I haven't tried this, and I will when I get some time, but if you look in update_feeds.php you will notice that most of the "feedwordpress" specific content is after the following line...

    $feedwordpress =& new FeedWordPress;

    From what I can tell, everything before that is the setup required to make sure the user is logged in and some nice formating. There might be a simpler example of that sort of thing but that would be a good start for creating a new php file that just ran the Blogger Image Import without going through the admin interface. You should not need to change the importer script at all, just add a new script to execute it.

  10. Huwman
    Member
    Posted 7 years ago #

    Otto, thanks a lot for your suggestion, it works perfectly. Well I have to press a few more buttons on the phone when I want to post, but I don't mind as it's a more direct solution. I just didn't think about doing that instead than trying to work around blogger's madness.

    Poco, thanks for anytime you spent answering my questions, your script works great, but I think I'm going to just use Postie and bid farewell to Blogger completely, which also means I don't need to use feedwordpress for this any more, either.

    Problem resolved and no more pulling my hair out. Cheers.

  11. Poco
    Member
    Posted 7 years ago #

    Well, I'm glad you found a good solution. That Postie plugin looks rather interesting as a way to post images by email. I haven't found a good image post plugin that I am happy with (I'm using Image Manager) but being able to do a post by email would be way easier. I used to use Picasa to post to Blogger and this might allow me to do the same through Picasa email.

    I may have to give that a try.

Topic Closed

This topic has been closed to new replies.

About this Topic