1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
| <?php
require_once('db.lib.php');
function get_news_headers($num = 30, $date = NULL, $category = NULL)
{
get_db_link();
$news = array();
$wheres = '';
if ( ! is_null($date) )
{
$wheres .= ' AND `date` LIKE \'' . $date . '%\'';
}
if ( ! is_null($category) )
{
$wheres .= ' AND `category` = \'' . $category . '\'';
}
$sql = 'SELECT `id`, `title`, `bold`, `before_title`, `url`,`thumbnail`, `logo`, `date`, `description`, `category`, `author`, `produitx`, `produity`' .
' FROM `news_news`' .
' WHERE' .
' `date` <= NOW()' .
' AND `date` > 0' .
$wheres .
' ORDER BY `date` DESC' .
( $num > 0 ? ' LIMIT 0, ' . $num . ';' : '' );
$result = mysql_query($sql);
while ( $row = mysql_fetch_assoc($result) )
{
$row['url'] = news_format_url($row['url']);
$news[$row['id']] = $row;
}
return $news;
}
function get_news($news)
{
get_db_link();
$sql = 'SELECT *' .
' FROM `news_news`' .
' WHERE `' . ( is_numeric($news) ? 'id' : 'url' ) . '` = \'' . $news . '\'' .
' LIMIT 1;';
$result = mysql_query($sql);
if ( ! $row = mysql_fetch_assoc($result) )
{
return false;
}
$row['url'] = news_format_url($row['url']);
return $row;
}
function news_format_url($page)
{
return '/article/' . $page . '.html';
}
function news_get_url_page_name($url)
{
return substr($url, 9, -5);
}
function delete_news($id)
{
get_db_link();
$sql = 'DELETE FROM `news_news` WHERE `id` = \'' . $id . '\' LIMIT 1;';
$result = mysql_query($sql);
}
function quote_replace($string)
{
return str_replace(array('"', '\''), array('\"', '\\\''), $string);
}
function get_formatted_news_headers($pattern, $num = 30, $date = NULL, $category = NULL)
{
$news_formatted = '';
preg_match_all('/##([^#]+)##/', $pattern, $matches);
$news_headers = get_news_headers($num, $date, $category);
foreach ( $news_headers as $id => $news_header )
{
$tmp_pattern = $pattern;
foreach ( $matches[1] as $id => $match )
{
if ( 'date' === substr($match, 0, 4) )
{
list($match, $date_format) = explode('@', $match);
$news_header['date'] = date($date_format, strtotime($news_header['date']));
}
$tmp_pattern = str_replace($matches[0][$id], $news_header[$match], $tmp_pattern);
}
$news_formatted .= $tmp_pattern;
}
return $news_formatted;
}
?> |
Partager