[ ]   [ ]   [ ]   [ ]



: 0
25-02-12 07:01


igor64
: 0
16-01-12 20:13


Lil`Ga.k.a43
: 1
09-01-12 11:23



   Web -
PHP


ASP






XML



CSS

SSI





   











   Web -








   









   










Web - / PHP /

PHP

(c) 2004 Mikewww.codenet.ru

PHP . rss091 ultramode.txt.

, , :

MySql .

, .

www.codenet.ru.

, , : http://codenet.ru/webmast/php/mcaching.php

, .

(~5Kb)

(. ). :

ultramode:

  • %URL% -
  • %TITLE% -
  • %PUBDATE% -
  • %AUTHOR% -
  • %TOPIC% -
  • %COMMENTS% -
  • %IMAGE% -

rss091:

  • %URL% -
  • %TITLE% -
  • %DESCRIPTION% -
  • %PUBDATE% -

<?
/* ࠠ */
/* */
/* rss091 */
/* */
/* : */
/* */
/* $parser=new RSS091Parser(dateformat); */
/* $result=$parser->Parse(data,template,newscount); */
/* */
/* , : */
/* */
/* - dateformat - ( date()) */
/* - data - 蠠 */
/* - */
/* - 頠 */

class RSS091Parser {

var
$DATA;
var
$template;
var
$xml_parser;
var
$newscount;
var
$dateformat;

function
RSS091Parser($idateformat) {
$this->dateformat=$idateformat;
$this->DATA=Array();
$this->DATA["count"]=0;
}

/* RSS 0.91 XML Handlers */
function startElement($parser, $name, $attrs) {
$this->DATA["curtag"]=$name;
$this->DATA[$name]="";
}

function
endElement($parser, $name) {
if (
$name=="ITEM" && $this->DATA["count"]<$this->newscount) {
$t=$this->template;
if (!empty(
$this->dateformat)) {
$ttime=strtotime($this->DATA["PUBDATE"]);
$this->DATA["PUBDATE"]=date($this->dateformat,$ttime);
}

$t=str_replace("%URL%",$this->DATA["LINK"],$t);
$t=str_replace("%TITLE%",$this->DATA["TITLE"],$t);
$t=str_replace("%DESCRIPTION%",$this->DATA["DESCRIPTION"],$t);
$t=str_replace("%PUBDATE%",$this->DATA["PUBDATE"],$t);
$this->DATA["data"].=$t;
$this->DATA["count"]++;
}
$this->DATA["curtag"]="";
}

function
characterData($parser, $data) {
$this->DATA[$this->DATA["curtag"]].=$data;
}

function
Parse($data,$itemplate,$newscount) {
$this->template=$itemplate;
$this->newscount=$newscount;

$this->xml_parser=xml_parser_create();
xml_set_object($this->xml_parser, &$this);
xml_set_element_handler($this->xml_parser, "startElement", "endElement");
xml_set_character_data_handler($this->xml_parser, "characterData");
xml_parse($this->xml_parser, $data) or die("Error parsing XML");
xml_parser_free($this->xml_parser);

return(
$this->DATA["data"]);
}
};

/* ࠠ */
/* */
/* ULTRAMODE */
/* */
/* : */
/* */
/* $parser=new ULTRAMODEParser(dateformat); */
/* $result=$parser->Parse(data,template,newscount); */
/* */
/* , : */
/* */
/* - dateformat - ( date()) */
/* - data - 蠠 */
/* - */
/* - 頠 */

class ULTRAMODEParser {
var
$dateformat;

function
ULTRAMODEParser($idateformat="") {
$this->dateformat=$idateformat;
}

function
Parse($data,$itemplate,$newscount) {
if (
strpos($data,"\n ")) $data=explode("\n ",$data);
elseif (
strpos($data," \n")) $data=explode(" \n",$data);
elseif (
strpos($data,"\n")) $data=explode("\n",$data);
elseif (
strpos($data," ")) $data=explode(" ",$data);
$c=count($data);
$s=0;while (substr($data[$s],0,2)!="%%" && $s<$c) $s++;
$s++;$news=0;$result="";
for (
$i=$s;$i<$c;$i+=8) {
if (
$news>=$newscount) break;
$t=$itemplate;

$pubdate=trim($data[$i+2]);
if (!empty(
$this->dateformat)) {
$ttime=strtotime($pubdate);
$pubdate=date($this->dateformat,$ttime);
}

$t=str_replace("%URL%",trim($data[$i+1]),$t);
$t=str_replace("%TITLE%",trim($data[$i+0]),$t);
$t=str_replace("%PUBDATE%",$pubdate,$t);
$t=str_replace("%AUTHOR%",trim($data[$i+3]),$t);
$t=str_replace("%TOPIC%",trim($data[$i+4]),$t);
$t=str_replace("%COMMENTS%",trim($data[$i+5]),$t);
$t=str_replace("%IMAGE%",trim($data[$i+6]),$t);
$news++;
$result.=$t;
}
return(
$result);
}
};


/* */

class News {

var
$type; // T (rss091, ultramode)
var $updatetime; //
var $template; //
var $save; // (mysql,file)
var $newscount; //
var $MYCONN; // MySql connection
var $dateformat; // L v. + , .

// save==mysql
var $mysql_server; // MySql
var $mysql_login; // MySql
var $mysql_password; // MySql
var $mysql_database; // MySql v v

// save==file
var $file_path; //
var $file_prefix; //

/* 𠠠 */
/* */
/* iupdatetime - , ( 1 ) */
/* itype - (rss091 ultramode) */
/* inewscount - ( 10) */
/* */
/* : */
/* */
/* $news=new News(28800,"ultramode",5); */
/* */

function News($iupdatetime=3600,$itype="rss091",$inewscount=10) {
$this->MYCONN=FALSE;
$this->save="file";
$this->mysql_server="locahost";
$this->mysql_login="root";
$this->mysql_password="";
$this->mysql_database="news";
$this->file_prefix="news_";
$this->file_path="/tmp/";
$this->type=$itype;
$this->newscount=$inewscount;
$this->updatetime=$iupdatetime;
$this->template="<a href="%URL">%TITLE%</a>\n<br>%DESCRIPTION%\n<br>\n";
}

/* MySql. ,  */
/* , MySql : */
/* */
/* CREATE TABLE `newsimport` ( */
/* `id` int(11) NOT NULL default '0', */
/* `d_update` int(11) NOT NULL default '0', */
/* `data` text NOT NULL */
/* ) TYPE=MyISAM; */
/* */
/* server - (), localhost */
/* login - MySql */
/* password - MySql */
/* database - */
/* */
/* : */
/* */
/* $news->setmysql("localhost","root","","mydatabase"); */
/* */

function setmysql($server,$login,$password,$database) {
$this->save="mysql";
$this->mysql_server=$server;
$this->mysql_login=$login;
$this->mysql_password=$password;
$this->mysql_database=$database;
}

/* . ,  */
/* . */
/* */
/* /usr/home/andrey/tmp/codenet_* */
/* */
/* $news->setfile("/usr/home/andrey/tmp/","codenet_"); */
/* */
/* */

function setfile($path,$prefix) {
$this->save="file";
$this->file_prefix=$prefix;
$this->file_path=$path;
}

/* */
/* ࠠ */
/* */
/* filename - 젠 */
/* idateformat - ( date()) */
/* */

function readtemplate($filename,$idateformat="") {
if (!
is_file($filename)) die("File '".$filename."' not found\n");
$this->dateformat=$idateformat;
$this->template=implode("",file($filename));
}

/* */
/* 頠 */
/* */
/* template - 젠 */
/* idateformat - ( date()) */
/* */

function settemplate($template,$idateformat="") {
$this->dateformat=$idateformat;
$this->template=$template;
}

/* */
/* , - 䠠 */
/* */
/* url - , 蠠 */
/* */

function read($url) {
/* crc32 , */
/* */
$id=crc32($url);

/* 0 */
$lastupdatetime=0;

switch (
$this->save) {
/* MySql */
case "mysql":
/* */
if (!$this->MYCONN) {
$this->MYCONN=mysql_connect($this->mysql_server,
$this->mysql_login,
$this->mysql_password)
or die(
mysql_error());
mysql_select_db($this->mysql_database,$this->MYCONN)
or die(
mysql_error());
}

/* */
$r=mysql_query("SELECT d_update
FROM newsimport
WHERE id='"
.$id."';",$this->MYCONN)
or die(
mysql_error());

if (
mysql_num_rows($r)==1) {
$lastupdatetime=mysql_result($r,0,0);
}
/* ID , */
/* , */
/* , $lastupdatetime */
elseif (mysql_num_rows($r)==0) {
mysql_query("INSERT INTO newsimport
SET id='"
.$id."', d_update=UNIX_TIMESTAMP();");
}
mysql_free_result($r);
break;

/* */
case "file":
default:
/* */
$fname=$this->file_path.$this->file_prefix.$id;
/* */
$d=@file($fname.".time");
if (
is_array($d)) $lastupdatetime=intval($d[0]);
/* , */
/* , */
/* , $lastupdatetime */
else {
$fw=fopen($fname.".time","wt");
if (!
$fw) die("
- ""
.$fname.".time"");
fputs($fw,time());
fclose($fw);
}
}

$fromcache=0;
/* ... */
if (time()-$this->updatetime>$lastupdatetime) {
/* */
$d=@file($url);
if (
is_array($d)) {
$d=implode("",$d);
/* , , */
/* (. ) */
switch ($this->type) {
case
"ultramode":
$parser=new ULTRAMODEParser($this->dateformat);
$result=$parser->Parse($d,
$this->template,
$this->newscount);
break;
case
"rss091":
default:
$parser=new RSS091Parser($this->dateformat);
$result=$parser->Parse($d,
$this->template,
$this->newscount);
}
/* MySql */
/* */
switch ($this->save) {
case
"mysql":
mysql_query("UPDATE newsimport
SET d_update=UNIX_TIMESTAMP(),
data='"
.$result."'
WHERE id='"
.$id."';")
or die(
mysql_error());
break;
case
"file":
default:
$fname=$this->file_path.$this->file_prefix.$id;

$fw=@fopen($fname.".time","wt");
if (!
$fw) die("
- ""
.$fname.".time"");
fputs($fw,time());
fclose($fw);

$fw=@fopen($fname.".text","wt");
if (!
$fw) die("
- ""
.$fname.".text"");
fputs($fw,$result);
fclose($fw);
}
}
else
$fromcache=1;
}
else
$fromcache=1;

/* , */
/* , */
if ($fromcache==1) {
switch (
$this->save) {
/* MySql */
case "mysql":
$r=mysql_query("SELECT data
FROM newsimport
WHERE id='"
.$id."';")
or die(
mysql_error());
$result=mysql_result($r,0,0);
mysql_free_result($r);
break;
/* */
case "file":
default:
$result=implode("",file($this->file_path.
$this->file_prefix.
$id.
".text"));
}
}
return(
$result);
}
};
?>

<?
include "newsimport.php";

/* http://www.codenet.ru/export/read.xml */
/* : ࠠ */
/* : 4 */
/* : /tmp/news_* */
/* : rss091 */
/* : codenet.htm */
/* : /񠠠 */

$news=new News(7200,"rss091",5);
$news->readtemplate("codenet.htm","d/m");
print
$news->read("http://www.codenet.ru/export/read.xml");
?>
<hr>
<?
/* http://news.yandex.ru/index.rss */
/* : 10 򠠠 */
/* : 10 */
/* : mysql */
/* : rss091 */
/* : 頠 */
/* : : /񠠠 */

$news=new News(600,"rss091",10);
$news->setmysql("localhost","login","password","tablename");
$news->settemplate("<B>%PUBDATE%</B>: <a href="%URL">%TITLE%:</a>
%DESCRIPTION%"
,"H:m d/m");
print
$news->read("http://news.yandex.ru/index.rss");
?>
<hr>
<?
/* http://forum.novgorod.ru/ultramode.txt */
/* : 󠠠 */
/* : 10 */
/* : mysql */
/* : ultramode */
/* : 頠 */
/* : : */

$news=new News(60,"ultramode",10);
$news->settemplate("<B>%PUBDATE%</B>:
<a href="%URL">%TITLE%:</a>(%AUTHOR%)<br>"
,"H:m");
print
$news->read("http://forum.novgorod.ru/ultramode.txt");
?>


[ ]



  !



: Web - / PHP /

GTK+:
02-03-2010   

GTK+ . GNOME, , GTK+ , GIMP GTK+, , Abobe, NVidia VMware, ...

: 1
. : - 4302 - 0

13-11-2009   

Slashdot.org 50 . . , IT...

: 0
. : - 4148 - 1

13-11-2009   

, , ( , , ) , .. . ...

: 0
. : - 3998 - 2

No spam.php
10-11-2009   

... . , , --. , . --. ...

: 0
. : - 4038 - 2

php Windows
10-11-2009   

, , PHP4 Windows...

: 0
. : - 4022 - 1



e-mail:
:

| ?







IT -




-




  WWW.COMPROG.RU - 2009-2012 | Designed and Powered by Zaipov Renat | Projects