Update topic by latest news

Release your script here.
State:
- Author
- What it does
- Perhaps a little guide.
- Also, if the snippet is of any use to the community, it has a chance of getting posted on the main page, so don't hesitate to submit/ask!

Update topic by latest news

Postby Dandy » Fri Jun 06, 2008 12:58 pm

Code: Select all
;###########################################################
;# Author: Dandy
;# Description: Updates your topic on your channel then news are posted.
;###########################################################
alias checkupdate {
  .sockopen dandy.latest %dandy.latest.hostname %dandy.latest.port

}
on *:sockopen:dandy.latest: {
  .sockwrite -n dandy.latest HEAD / HTTP/1.1
  .sockwrite -n dandy.latest Connection: close
  .sockwrite -n dandy.latest Host: %dandy.latest.hostname
  .sockwrite -n dandy.latest $crlf
}
on *:sockread:dandy.latest: {
  sockread -f %tmp
  if ($gettok(%tmp,1,32) == Custom-Latest-Post:) {
    var %data = $decode($gettok(%tmp,2,32),m)
    var %id = $gettok(%data,1,59)
    var %headline = $gettok(%data,2,59)
    var %url = $gettok(%data,3,59)
    if (%dandy.latest.id != %id) {
      set %dandy.latest.id %id
      .msg q settopic %dandy.latest.channel %url ~ %headline
    }
    sockclose $sockname
  }
  unset %tmp
}
ON *:CONNECT: {

  .timer 0 120 .checkupdate

}


The script requires a PHP counterpart that i put into my index.php

Code: Select all
$latest = mysql_query("SELECT id,headline FROM blog ORDER BY id DESC LIMIT 1");
$lid = mysql_result($latest,0,0);
$lheadline = mysql_result($latest,0,1);
header("Custom-Latest-Post: ".base64_encode(sprintf("%d;%s;http://%s/?id=%d&headline=%s",$lid,$lheadline,$_SERVER['HTTP_HOST'],$lid,$lheadline)));


You might have to change the mysql_query according to your database structure the first field returned must be the id and the second the headline or topic.
The scripts sets a header which is ignored by browsers but the script will read it.
Also in the header you might want to change the url currently it's set to http://yourdomainname.com/?id=<id>&headline=<headline>
Dandy
 

Re: Update topic by latest news

Postby Lukemob » Sat Jun 07, 2008 7:36 pm

Usefull and interesting ;)

Keep up the good work!
Lukemob
 

Re: Update topic by latest news

Postby Lenooox » Wed Jan 06, 2010 1:09 pm

o.O
/sockopen: insufficient parameters (line 6, latestnews.mrc)
Lenooox
 

Re: Update topic by latest news

Postby PuNkTuReD » Tue Jan 26, 2010 11:41 am

thats because you have not set the vars
%dandy.latest.hostname
%dandy.latest.port
PuNkTuReD
 

Re: Update topic by latest news

Postby Lenooox » Tue Jan 26, 2010 5:49 pm

nope , i did not forget change that :) btw , Our site dont communicate for scripts :/ but u know it :/
Lenooox
 


Return to Mirc Scripting Release

Who is online

Users browsing this forum: No registered users and 2 guests

cron