Commit c45bfa46 authored by Francesco Iannuzzelli's avatar Francesco Iannuzzelli

Site watch

parent ec19e445
......@@ -118,6 +118,26 @@ if ($from=="scheduler")
}
}
if ($from=="watch")
{
$action = $fh->ActionGet($post);
$id_watch = $post['id_watch'];
$url = $fh->String2Url($post['url']);
$keyword = $post['keyword'];
$notify = $post['notify'];
include_once(SERVER_ROOT."/../classes/scheduler.php");
$sc = new Scheduler();
if ($action=="delete")
{
$sc->WatchDelete($id_watch);
}
if ($action=="store")
{
$id_watch = $sc->WatchStore( $id_watch, $url, $keyword, $notify );
}
header("Location: watches.php");
}
if ($from=="scheduler_params")
{
$action = $fh->ActionGet($post);
......
......@@ -69,6 +69,7 @@ if($module_admin)
<h3><?=$trm14->Translate("scheduler");?></h3>
<ul>
<li><a href="schedules.php"><?=$trm14->Translate("schedules");?></a></li>
<li><a href="watches.php">Site watches</a></li>
</ul>
<h3>Log</h3>
......
<?php
/********************************************************************
PhPeace - Portal Management System
Copyright notice
(C) 2003-2019 Francesco Iannuzzelli <francesco@phpeace.org>
All rights reserved
This script is part of PhPeace.
PhPeace is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
PhPeace is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
The GNU General Public License (GPL) is available at
http://www.gnu.org/copyleft/gpl.html.
A copy can be found in the file COPYING distributed with
these scripts.
This copyright notice MUST APPEAR in all copies of the script!
********************************************************************/
if (!defined('SERVER_ROOT'))
define('SERVER_ROOT',$_SERVER['DOCUMENT_ROOT']);
include_once(SERVER_ROOT."/include/header.php");
include_once(SERVER_ROOT."/../classes/scheduler.php");
$sc = new Scheduler();
$id = $_GET['id'];
$title[] = array('Site watches','watches.php');
if ($module_admin)
$input_right = 1;
if ($id>0)
{
$row = $sc->WatchGet($id);
$title[] = array($row['url'],'');
}
else
{
$title[] = array('add_new','');
}
echo $hh->ShowTitle($title);
echo $hh->input_form_open();
echo $hh->input_hidden("from","watch");
echo $hh->input_hidden("id_watch",$id);
echo $hh->input_table_open();
echo $hh->input_text("url","url",$row['url'],70,0,$input_right);
echo $hh->input_text("keyword","keyword",$row['keyword'],70,0,$input_right);
echo $hh->input_text("email","notify",$row['notify'],70,0,$input_right);
if($id>0) {
echo $hh->input_text("counter","counter",$row['counter'],70,0,0);
}
$actions = array();
$actions[] = array('action'=>"store",'label'=>"submit",'right'=>$input_right);
$actions[] = array('action'=>"delete",'label'=>"delete",'right'=>($input_right && $id>0));
echo $hh->input_actions($actions,$input_right);
echo $hh->input_table_close() . $hh->input_form_close();
include_once(SERVER_ROOT."/include/footer.php");
?>
<?php
/********************************************************************
PhPeace - Portal Management System
Copyright notice
(C) 2003-2019 Francesco Iannuzzelli <francesco@phpeace.org>
All rights reserved
This script is part of PhPeace.
PhPeace is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
PhPeace is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
The GNU General Public License (GPL) is available at
http://www.gnu.org/copyleft/gpl.html.
A copy can be found in the file COPYING distributed with
these scripts.
This copyright notice MUST APPEAR in all copies of the script!
********************************************************************/
if (!defined('SERVER_ROOT'))
define('SERVER_ROOT',$_SERVER['DOCUMENT_ROOT']);
include_once(SERVER_ROOT."/include/header.php");
include_once(SERVER_ROOT."/../classes/scheduler.php");
$sc = new Scheduler();
$title[] = array('Site watches','');
echo $hh->ShowTitle($title);
$watches = $sc->Watches();
if(count($watches)>0)
{
echo "<ul class=\"watches\">\n";
foreach($watches as $watch)
{
echo "<li>";
echo "<a href=\"watch.php?id={$watch['id_watch']}\">{$watch['url']}</a> ({$watch['keyword']})";
echo "</li>\n";
}
echo "</ul>\n";
}
?>
<p><a href="watch.php?id=0"><?=$hh->tr->Translate("add_new");?></a></p>
<?php
include_once(SERVER_ROOT."/include/footer.php");
?>
......@@ -59,7 +59,7 @@ define('PHPEACE_VERSION',"2.6.21");
* PhPeace Database version number (integer)
* Increased by 1 for each DB schema change
*/
define('PHPEACE_DB_VERSION',268);
define('PHPEACE_DB_VERSION',269);
/* ##################################### */
......
......@@ -126,6 +126,9 @@ class PhPeaceUpdates
{
switch($version_new)
{
case "300":
$this->UpdateDB("269");
break;
case "299":
$this->UpdateDB("268");
break;
......@@ -470,6 +473,9 @@ class PhPeaceUpdates
$dbconf = $conf->Get("dbconf");
switch($db_version)
{
case "269":
$db->TableCreate('site_watch', "`id_watch` SMALLINT(4) NOT NULL DEFAULT '0',`url` VARCHAR(250) NOT NULL DEFAULT '',`keyword` VARCHAR(50) NOT NULL DEFAULT '',`notify` VARCHAR(250) NOT NULL DEFAULT '',`counter` SMALLINT(4) NOT NULL DEFAULT '0', PRIMARY KEY (`id_watch`)");
break;
case "268":
$db->TableCreate('keywords_landing', "`id_keyword` mediumint(9) NOT NULL DEFAULT '0',`content` TEXT NOT NULL,`youtube` VARCHAR(150) NOT NULL DEFAULT ''");
break;
......
......@@ -160,7 +160,7 @@ class Scheduler
$actions[13] = "Export quotes";
$actions[14] = "Force Topic full publish";
$actions[15] = "Notify pending articles";
$actions[16] = "N/A";
$actions[16] = "Site watch";
$actions[17] = "Remove expired Rss feed items (> 30 days)";
$actions[18] = "N/A";
$actions[19] = "Resources' status changes";
......@@ -542,7 +542,34 @@ class Scheduler
$tt = new Topics();
$tt->PendingNotify();
break;
case "17":
case "16":
$watches = $this->Watches();
if(count($watches)>0) {
include_once(SERVER_ROOT."/../classes/mail.php");
$mail = new Mail();
$fm = new FileManager();
foreach($watches as $watch) {
$html = $fm->Browse($watch['url']);
if($html!='') {
$keywords = array();
if (preg_match("@{$watch['keyword']}@i", $html, $keywords)) {
$counter = count($keywords);
$prev_counter = (int)$watch['counter'];
if($counter != $prev_counter) {
$subject = "Watch notification for {$watch['keyword']}";
$message = "Keyword: {$watch['keyword']}\nURL: {$watch['url']}\nCount: $counter (was $prev_counter)\n\n";
$recipients = $mail->AddressSplitAndValidate($watch['notify']);
foreach($recipients as $recipient) {
$mail->SendMail($recipient,"",$subject,$message,array(),false,array(),false);
}
$this->WatchUpdateCounter($watch['id_watch'], $counter);
}
}
}
}
}
break;
case "17":
include_once(SERVER_ROOT."/../classes/web_feeds.php");
$wfi = new WebFeedsImporter();
$wfi->RemoveExpiredFeedItems();
......@@ -780,5 +807,68 @@ class Scheduler
{
return number_format(memory_get_usage()/1024,0,",",".") . " kB (max " . number_format(memory_get_peak_usage()/1024,0,",",".") . " kB)";
}
public function WatchDelete($id_watch)
{
$db =& Db::globaldb();
$db->begin();
$db->lock( "site_watch" );
$res[] = $db->query( "DELETE FROM site_watch WHERE id_watch=$id_watch" );
Db::finish( $res, $db);
}
public function WatchGet($id_watch)
{
$row = array();
$db =& Db::globaldb();
$sqlstr = "SELECT id_watch,url,keyword,notify,counter
FROM site_watch
WHERE id_watch=$id_watch";
$db->query_single($row,$sqlstr);
return $row;
}
public function WatchStore( $id_watch,$url,$keyword,$notify )
{
$db =& Db::globaldb();
$db->begin();
$db->lock( "site_watch" );
if ($id_watch>0)
{
$sqlstr = "UPDATE site_watch SET url='$url',keyword='$keyword',notify='$notify'
WHERE id_watch=$id_watch";
}
else
{
$id_watch = $db->nextId( "site_watch", "id_watch" );
$sqlstr = "INSERT INTO site_watch (id_watch,url,keyword,notify,counter)
VALUES ($id_watch,'$url','$keyword','$notify',0)";
}
$res[] = $db->query( $sqlstr );
Db::finish( $res, $db);
return $id_watch;
}
private function WatchUpdateCounter( $id_watch,$counter )
{
$db =& Db::globaldb();
$db->begin();
$db->lock( "site_watch" );
$sqlstr = "UPDATE site_watch SET counter='$counter' WHERE id_watch=$id_watch";
$res[] = $db->query( $sqlstr );
Db::finish( $res, $db);
}
public function Watches()
{
$rows = array();
$db =& Db::globaldb();
$sqlstr = "SELECT id_watch,url,keyword,notify,counter
FROM site_watch
ORDER BY url ";
$db->QueryExe($rows, $sqlstr);
return $rows;
}
}
?>
......@@ -2340,6 +2340,17 @@ CREATE TABLE `sessions` (
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `site_watch` (
`id_watch` smallint(4) NOT NULL DEFAULT '0',
`url` varchar(250) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`keyword` varchar(50) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`notify` varchar(250) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`counter` smallint(4) NOT NULL DEFAULT '0',
PRIMARY KEY (`id_watch`)
);
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `smart_cards` (
`id_smart_card` int(11) NOT NULL DEFAULT '0',
`smart_card_no` varchar(50) DEFAULT '',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment