Author Topic: PHP Cronjob --> Automatically submit newsitem via e-mail  (Read 11317 times)

Woudloper

  • Guest
PHP Cronjob --> Automatically submit newsitem via e-mail
« on: May 12, 2006, 01:39:38 PM »
Hi,

Currently I had just some thought and was wondering if something like this is possible to combine with ‘WebsiteBaker’!?

Some while ago someone told me what cronjob are and what you might do with these. The explanation was clear and now I was thing of the following and if something like this can be made possible.

For one of the website I am using I want to give the opportunity for someone to submit weblog postings (with the news module). The person does not has internet access at work, but wants to post an weblog item from work. Would it be possible to do the following with a cronjob:
  • Import the e-mails sent to a specific mailbox;
  • Read the content of the e-mail (possible with html layout)
  • Put the information into the news table

If this is possible that would help one of my clients a lot.

Since I am not that experienced with cronjobs hints are welcome.

xillion

  • Guest
Re: PHP Cronjob --> Automatically submit newsitem via e-mail
« Reply #1 on: May 12, 2006, 02:47:08 PM »
Hi,

Currently I had just some thought and was wondering if something like this is possible to combine with ‘WebsiteBaker’!?

Some while ago someone told me what cronjob are and what you might do with these. The explanation was clear and now I was thing of the following and if something like this can be made possible.

For one of the website I am using I want to give the opportunity for someone to submit weblog postings (with the news module). The person does not has internet access at work, but wants to post an weblog item from work. Would it be possible to do the following with a cronjob:
  • Import the e-mails sent to a specific mailbox;
  • Read the content of the e-mail (possible with html layout)
  • Put the information into the news table

If this is possible that would help one of my clients a lot.

Since I am not that experienced with cronjobs hints are welcome.

I cannot give you the right hint.. but your plans is in theory right..
But you have to have a command line i think or make a batch script for it..

I think there is a better solution... get an internet connection for your client.. the internet seems to be interesting  :wink:

Offline rsmith

  • Posts: 194
  • Gender: Male
Re: PHP Cronjob --> Automatically submit newsitem via e-mail
« Reply #2 on: May 12, 2006, 02:59:05 PM »
Hi,

I've done all the peices of this before, just not as a single program, no reason it couldn't be done.

at first thought:
A few issues exist to do what you want
  • on your server you would need the ability to schedule cron jobs
  • you would need  POP3 or IMAP access to the email server to check your mail
  • you would need the IMAP functions installed as part of the php config

Cron jobs (linux) or via the Task scheduler (windows) a job can be scheduled to run,
  with windows, a simple batch file,   " php.exe filename.php?var1=xxx&var2=yyy "
  not exactly sure with linux but should be close to the same

would need to "configure" via WB the server, username, password for the email server/account, configure the WB news module to be used to store the post

using the imap php function read the mail
get the body of the message
post to the database, and check
then delete the mail from the mailbox.

The module could be built into WB
a "modify.php" to manage the settings, and even manualy call the "cronjob.php"
a "cronjob.php" to be executed by the cronjob/taskmanager

checks could also be done so a "special" account is not needed, ie test on the subject line?... or the first line of the body, looking for a key phrase (WB News Post) a check of the from address so only "allowed" email addresses can post

at first thought this seems to be a very do'able project.. the biggest and hardest to solve issue would be your mail server, if it doesnt allow pop3/imap access then your stuck..


I'll think about this more, who wants to write it? or do I get that pleasure too? :-D


Rob



pcwacht

  • Guest
Re: PHP Cronjob --> Automatically submit newsitem via e-mail
« Reply #3 on: May 12, 2006, 03:53:39 PM »
Instead of a cronjob, in case you don't have shell access, you could include a litle programm into your templates index.php page (or maybe better to inlclude it on the startpage wich does:

check time, if enough time has expired call the programm wich extract the mail etc

I believed this is called pseude cron

This way you keep the control within wb


John

Offline rsmith

  • Posts: 194
  • Gender: Male
Re: PHP Cronjob --> Automatically submit newsitem via e-mail
« Reply #4 on: May 12, 2006, 04:00:29 PM »
@ pcwacht
Good idea...

even go a step further.... have an insertable page instead of part of the template (view.php) that you can insert as a section above the news section , this could call the "cronjob.php" and update the database based on time from the last update...
it wouldn't need to display anything (but could)

Rob



pcwacht

  • Guest
Re: PHP Cronjob --> Automatically submit newsitem via e-mail
« Reply #5 on: May 12, 2006, 04:03:05 PM »
Been digging

get a copy of wordpress -> http://wordpress.org/latest.zip

read:
/include/class.pop3.php for popping, squirrelmail class
and
/wp_mail.php wich does the actual reading of the mail

to get what you need

Basicly :
include the class
create an instance with pop server,port,usernam,password
fetch the mail and import it into the database
something like :
subject = title
content = content


Have fun,

John

PS Need help?
John too :)

Woudloper

  • Guest
Re: PHP Cronjob --> Automatically submit newsitem via e-mail
« Reply #6 on: May 12, 2006, 04:14:44 PM »
interesting material. Will read some stuff this weekend. A small/fast question. Is wordpress using the pseudo cron where you are referring to!?

PS: I am hosting at pcextreme.nl and they have ssh access and there I can run bash or php...
PPS: Your idea/solution to keep it within WB also seems very nice

Offline rsmith

  • Posts: 194
  • Gender: Male
Re: PHP Cronjob --> Automatically submit newsitem via e-mail
« Reply #7 on: May 12, 2006, 04:24:06 PM »
 :-D Looks like I have another project to start for the weekend

@pcwacht
need help?.. no.....not usualy..  :-)
like help? sure... every little bit helps... i'm still learning whats in WB, and always finding new WB functions to make things easier, i'll look at the wordpress stuff tonight as well as what ive written the past... should be able to have a basic test module in a few days...

any more "features"/"wishes" to be included? can design for some in the inital rc versions

@woudloper
If i understand pcwacht correctly... "pseudo cron" would be running the "cronjob.php" when someone views the page and the time since the last update is more than xx minutes (admin sets xx, last update time is set in the database when its updated) (in his sample any page that uses the template index.php)

I would take this one step further(as i posted) and run the job when the specfic page is loaded and the time is more than xx mins...
 this way its not part of the template, all controlled by the WB admin

designed right could also be scheduled to run as a cron job, I know in the past ive had speed issues when checking mail via php, so a cron job works better for this than actively checking on page load, then again ;) my work mail has 10,000+ messages... so may not be an issue for this WB  module,




(could be a full time job programming WB modules, I have a few more in the works too  :-D but.. too much fun to be a "job" , i know, i know..strange idea of fun :-P )


Rob

« Last Edit: May 12, 2006, 04:27:16 PM by rsmith »

pcwacht

  • Guest
Re: PHP Cronjob --> Automatically submit newsitem via e-mail
« Reply #8 on: May 12, 2006, 04:33:32 PM »
ok, in that case offering some ideas....


Make db for backend popnews module settings for admin to administer through backend
in it you need:
news section -> int -> default section to insert mailed content
news categorie -> int -> default categorie to use for mailed content
popserver -> text -> obvious
popport -> int -> obvious
popaccount -> text -> obvious
poppassword -> text -> obvious
timeinterval -> int -> hours I reckon, easier then minutes ;)
lasttime -> date -> last time executed


then the code for determing the execution of the popreader woudl be executed by the view.php of this wbmodule
something like:
fetch popnews module settings from settings table
currenttime = time();
if currenttime > lasttime + interval*60*60 (making seconds of hours) {
     update db, lasttime = currenttime;
     call popreader
}

The popreader should :
include the popclass
read the pop
while there is mail {
    read the mail
    insert subject and content into database
    (maybe check if there is allready a content with same title and update the record with new submission??)
    (maybe use tags for categorie, short and long text entries in news? ifso divide content into categorie, short, long then submit to db)
    delete the mail
}


That's basicly it.

John
   

Offline frank

  • Posts: 36
  • Gender: Male
    • Clever XXL
Re: PHP Cronjob --> Automatically submit newsitem via e-mail
« Reply #9 on: May 15, 2006, 02:33:35 PM »
Hi,
I think I'm using such a script for a while.

http://www.fraikin.net/sms2email-liveticker/ in german or
http://www.fraikin.net/sms2email-liveticker/index.php?l=en in english

It is a PHP script which reads an POP3 or IMAP mailaccount.
I placed it as a wrapper modul on my page http://www.beyernetz.de

For news I only have to send a text mail to the defined mail account and one minute later it's online.

Frank

Offline YeShakka

  • Posts: 144
Re: PHP Cronjob --> Automatically submit newsitem via e-mail
« Reply #10 on: May 15, 2006, 03:43:35 PM »

It is a PHP script which reads an POP3 or IMAP mailaccount.
I placed it as a wrapper modul on my page http://www.beyernetz.de



Simsi is a 50kB Weblog Application with exactly that feature. it is currently offline:
http://www.rowlff.de/simsi/

If I remenber, I will send you a copy of the code...

Edit:
I found the simsi application. You may download the attached archive and analyze if you can take some code from ist.


[gelöscht durch Administrator]
« Last Edit: May 16, 2006, 02:07:32 PM by YeShakka »

Offline hudge

  • Posts: 174
    • http://www.hudge.com
Re: PHP Cronjob --> Automatically submit newsitem via e-mail
« Reply #11 on: May 16, 2006, 04:42:25 AM »
I use the wordpress one and this is a great feature for letting others publish articles on your site with out having them access to your admin. I would suggest an option to allow to have them inserted either active or non active. I assume this would be feature in settings.
: Member of the Baker's Dozen :
Baking at 350˚ for 2 hours now...

pcwacht

  • Guest
Re: PHP Cronjob --> Automatically submit newsitem via e-mail
« Reply #12 on: May 16, 2006, 09:27:55 AM »
Quote
have them inserted either active or non active. I assume this would be feature in settings.

If implemented, think of mail admin new submission is done.... so he can activate it.

John

Woudloper

  • Guest
Re: PHP Cronjob --> Automatically submit newsitem via e-mail
« Reply #13 on: May 16, 2006, 05:38:32 PM »
Thanks for all the great responses! This is an area of PHP (with cronjobs, etc) that I have never used and it is completely new for me.

The idea's are sounding nice, but I think I am going for an easy solution if that is not to much work. I am going to install wordpress on a subdomain weblog.domain.tld and then I am going to give that a simular design as the original website. This way I don't have to do much PHP coding and can easily do something with a template for wordpress. Another point it saves me time when I do so as I don't have much spare time lately...

huwnet

  • Guest
Re: PHP Cronjob --> Automatically submit newsitem via e-mail
« Reply #14 on: May 20, 2006, 07:12:50 PM »
Quote
you would need  POP3 or IMAP access to the email server to check your mail

If you have cpanel or direct server access then all you need to do is create a new mail account.

Pipe it to your php script. Then bin the mail so it doesn't take up to much space.

This means you won't need a cron.

The php script needs to be on the same server as the mailserver

pcwacht

  • Guest
Re: PHP Cronjob --> Automatically submit newsitem via e-mail
« Reply #15 on: May 20, 2006, 09:13:35 PM »
Quote
Pipe it to your php script. Then bin the mail


How would you do that?

If it is piped the content will be visible allmost instantly... ;)


John

huwnet

  • Guest
Re: PHP Cronjob --> Automatically submit newsitem via e-mail
« Reply #16 on: May 21, 2006, 02:33:17 PM »
Quote
How would you do that?

I'm not sure exactly how to set it up but this thread explains a demo script and forwarding through cpanel

http://www.webhostingtalk.com/showthread.php?p=3862642

Offline rsmith

  • Posts: 194
  • Gender: Male
Re: PHP Cronjob --> Automatically submit newsitem via e-mail
« Reply #17 on: May 24, 2006, 12:34:30 AM »
Per this idea, I've developed a new Module for WebsiteBaker, The "Mail2News" Module, and its ready for more testing...

More information can be found here
http://forum.WebsiteBaker.org/index.php/topic,3325.0.html


Rob

 

postern-length