Add notifications to feed publications

This commit is contained in:
Romain Neutron
2012-03-09 15:07:18 +01:00
parent b75205a807
commit 8761e04eda
8 changed files with 408 additions and 156 deletions

View File

@@ -11,18 +11,28 @@
class random
{
/**
*
*/
const NUMBERS = "0123456789";
const NUMBERS = "0123456789";
/**
*
*/
const LETTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
const LETTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
/**
*
*/
const LETTERS_AND_NUMBERS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
const TYPE_FEED_ENTRY = 'FEED_ENTRY';
const TYPE_PASSWORD = 'password';
const TYPE_DOWNLOAD = 'download';
const TYPE_MAIL_DOWNLOAD = 'mail-download';
const TYPE_EMAIL = 'email';
const TYPE_VIEW = 'view';
const TYPE_VALIDATE = 'validate';
const TYPE_RSS = 'rss';
/**
*
@@ -34,15 +44,15 @@ class random
{
$conn = connection::getPDOConnection();
$date = new DateTime();
$date = phraseadate::format_mysql($date);
$date = new DateTime();
$date = phraseadate::format_mysql($date);
$registry = registry::get_instance();
$sql = 'SELECT * FROM tokens WHERE expire_on < :date
$sql = 'SELECT * FROM tokens WHERE expire_on < :date
AND datas IS NOT NULL AND (type="download" OR type="email")';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':date' => $date));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
foreach ($rs as $row)
{
@@ -57,7 +67,7 @@ class random
}
}
$sql = 'DELETE FROM tokens WHERE expire_on < :date and (type="download" OR type="email")';
$sql = 'DELETE FROM tokens WHERE expire_on < :date and (type="download" OR type="email")';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':date' => $date));
$stmt->closeCursor();
@@ -85,8 +95,8 @@ class random
$password = "";
if (!in_array($possible, array(self::LETTERS_AND_NUMBERS, self::LETTERS, self::NUMBERS)))
$possible = self::LETTERS_AND_NUMBERS;
$i = 0;
$possible = self::LETTERS_AND_NUMBERS;
$i = 0;
$possible_length = strlen($possible);
while ($i < $length)
{
@@ -106,18 +116,32 @@ class random
* @param mixed content $datas
* @return boolean
*/
public static function getUrlToken($type, $usr, DateTime $end_date = null, $datas='')
public static function getUrlToken($type, $usr, DateTime $end_date = null, $datas = '')
{
self::cleanTokens();
$conn = connection::getPDOConnection();
$token = $test = false;
$conn = connection::getPDOConnection();
$token = $test = false;
if (!in_array($type, array('password', 'download', 'mail-download', 'email', 'view', 'validate', 'rss')))
throw new Exception_InvalidArgument();
switch ($type)
{
case self::TYPE_DOWNLOAD:
case self::TYPE_PASSWORD:
case self::TYPE_MAIL_DOWNLOAD:
case self::TYPE_EMAIL:
case self::TYPE_VALIDATE:
case self::TYPE_VIEW:
case self::TYPE_RSS:
case self::TYPE_FEED_ENTRY:
break;
default:
throw new Exception_InvalidArgument();
break;
}
$n = 1;
$sql = 'SELECT id FROM tokens WHERE value = :test ';
$sql = 'SELECT id FROM tokens WHERE value = :test ';
$stmt = $conn->prepare($sql);
while ($n < 100)
{
@@ -134,16 +158,16 @@ class random
if ($token)
{
$sql = 'INSERT INTO tokens (id, value, type, usr_id, created_on, expire_on, datas)
$sql = 'INSERT INTO tokens (id, value, type, usr_id, created_on, expire_on, datas)
VALUES (null, :token, :type, :usr, NOW(), :end_date, :datas)';
$stmt = $conn->prepare($sql);
$params = array(
':token' => $token
, ':type' => $type
, ':usr' => ($usr ? $usr : '-1')
, ':end_date' => ($end_date instanceof DateTime ? phraseadate::format_mysql($end_date) : null)
, ':datas' => ((trim($datas) != '') ? $datas : null)
':token' => $token
, ':type' => $type
, ':usr' => ($usr ? $usr : '-1')
, ':end_date' => ($end_date instanceof DateTime ? phraseadate::format_mysql($end_date) : null)
, ':datas' => ((trim($datas) != '') ? $datas : null)
);
$stmt->execute($params);
$stmt->closeCursor();
@@ -159,7 +183,7 @@ class random
try
{
$conn = connection::getPDOConnection();
$sql = 'DELETE FROM tokens WHERE value = :token';
$sql = 'DELETE FROM tokens WHERE value = :token';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':token' => $token));
$stmt->closeCursor();
@@ -202,12 +226,12 @@ class random
self::cleanTokens();
$conn = connection::getPDOConnection();
$sql = 'SELECT * FROM tokens
$sql = 'SELECT * FROM tokens
WHERE value = :token
AND (expire_on > NOW() OR expire_on IS NULL)';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':token' => $token));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if (!$row)