Update of /cvsroot/php-blog/serendipity
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20753
Modified Files:
Tag: branch-smarty
NEWS serendipity_config.inc.php serendipity_db_mysql.inc.php
serendipity_functions.inc.php
Log Message:
see NEWS entry - entry properties for more plugin power :)
Index: NEWS
===================================================================
RCS file: /cvsroot/php-blog/serendipity/NEWS,v
retrieving revision 1.214.2.17
retrieving revision 1.214.2.18
diff -u -d -r1.214.2.17 -r1.214.2.18
--- NEWS 21 Sep 2004 08:43:15 -0000 1.214.2.17
+++ NEWS 21 Sep 2004 20:43:14 -0000 1.214.2.18
@@ -3,6 +3,11 @@
Version 0.8 ()
------------------------------------------------------------------------
+ * New plugin serendipity_event_entryproperties: You can now define
+ any property to an entry and query it. Currently implemented
+ are "sticky posts" and "private/public/members-only" entries.
+ (garvinhicking) [DB Layout change - > 0.8-alpha2]
+
* Fixed bug #1031059 - Trackbacks to a link will not be sent more
than once (garvinhicking)
Index: serendipity_functions.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_functions.inc.php,v
retrieving revision 1.419.2.25
retrieving revision 1.419.2.26
diff -u -d -r1.419.2.25 -r1.419.2.26
--- serendipity_functions.inc.php 20 Sep 2004 14:20:21 -0000 1.419.2.25
+++ serendipity_functions.inc.php 21 Sep 2004 20:43:15 -0000 1.419.2.26
@@ -560,8 +560,8 @@
function serendipity_fetchEntries($range = null, $full = true, $limit = '', $fetchDrafts = false, $modified_since = false, $orderby = 'timestamp DESC', $filter_sql = '') {
global $serendipity;
- $and = '';
-
+ $cond = array();
+ $cond['orderby'] = $orderby;
if (isset($serendipity['short_archives']) && $serendipity['short_archives']) {
// In the short listing of all titles for a month, we don't want to have a limit applied.
$limit = '';
@@ -596,33 +596,33 @@
$endts = mktime(0, 0, 0, $month, ($day == 0 ? 1 : $day), $year);
- $and = " WHERE timestamp >= $startts AND timestamp <= $endts";
+ $cond['and'] = " WHERE timestamp >= $startts AND timestamp <= $endts";
if ($drafts) {
- $and .= " AND $drafts";
+ $cond['and'] .= " AND $drafts";
}
}
elseif (is_array($range) && count($range)==2) {
$startts = (int)$range[0];
$endts = (int)$range[1];
- $and = " WHERE timestamp >= $startts AND timestamp <= $endts";
+ $cond['and'] = " WHERE timestamp >= $startts AND timestamp <= $endts";
}
else {
if ($modified_since) {
$unix_modified = strtotime($modified_since);
if ($unix_modified != -1) {
- $and = ' WHERE last_modified >= ' . (int)$unix_modified;
+ $cond['and'] = ' WHERE last_modified >= ' . (int)$unix_modified;
if (!empty($limit)) {
$limit = ($limit > $serendipity['max_fetch_limit'] ? $limit : $serendipity['max_fetch_limit']);
}
- $orderby = 'last_modified DESC';
+ $cond['orderby'] = 'last_modified DESC';
}
}
if (!empty($drafts)) {
- if (!empty($and)) {
- $and .= " AND $drafts";
+ if (!empty($cond['and'])) {
+ $cond['and'] .= " AND $drafts";
} else {
- $and = "WHERE $drafts";
+ $cond['and'] = "WHERE $drafts";
}
}
}
@@ -632,10 +632,10 @@
$categoryid = serendipity_db_escape_string($_categoryid[0]);
if (is_numeric($categoryid)) {
- if (!empty($and)) {
- $and .= " AND c.category_left BETWEEN " . implode(' AND ', serendipity_fetchCategoryRange($categoryid));
+ if (!empty($cond['and'])) {
+ $cond['and'] .= " AND c.category_left BETWEEN " . implode(' AND ', serendipity_fetchCategoryRange($categoryid));
} else {
- $and = "WHERE c.category_left BETWEEN " . implode(' AND ', serendipity_fetchCategoryRange($categoryid));
+ $cond['and'] = "WHERE c.category_left BETWEEN " . implode(' AND ', serendipity_fetchCategoryRange($categoryid));
}
}
}
@@ -649,29 +649,31 @@
}
if (isset($serendipity['GET']['adminModule']) && $serendipity['GET']['adminModule'] == 'entries' && $serendipity['serendipityUserlevel'] < USERLEVEL_CHIEF) {
- if (!empty($and)) {
- $and .= " AND e.authorid = '" . $serendipity['authorid'] . "'";
+ if (!empty($cond['and'])) {
+ $cond['and'] .= " AND e.authorid = '" . $serendipity['authorid'] . "'";
} else {
- $and = "WHERE e.authorid = '" . $serendipity['authorid'] . "'";
+ $cond['and'] = "WHERE e.authorid = '" . $serendipity['authorid'] . "'";
}
}
if (!isset($serendipity['GET']['adminModule'])) {
- if (!empty($and)) {
- $and .= " AND e.timestamp <= '" . time() . "'";
+ if (!empty($cond['and'])) {
+ $cond['and'] .= " AND e.timestamp <= '" . time() . "'";
} else {
- $and = "WHERE e.timestamp <= '" . time() . "'";
+ $cond['and'] = "WHERE e.timestamp <= '" . time() . "'";
}
}
if (!empty($filter_sql)) {
- if (!empty($and)) {
- $and .= ' AND ' . $filter_sql;
+ if (!empty($cond['and'])) {
+ $cond['and'] .= ' AND ' . $filter_sql;
} else {
- $and = 'WHERE ' . $filter_sql;
+ $cond['and'] = 'WHERE ' . $filter_sql;
}
}
+ serendipity_plugin_api::hook_event('frontend_fetchentries', $cond);
+
if (strtolower($serendipity['dbType']) == 'postgres') {
$group = '';
$distinct = 'DISTINCT';
@@ -690,9 +692,12 @@
ON e.id = ec.entryid
LEFT JOIN {$serendipity['dbPrefix']}category c
ON ec.categoryid = c.categoryid
- $and";
+ {$cond['joins']}
+ {$cond['and']}";
$query = "SELECT $distinct
+ {$cond['orderkey']}
+
e.id,
e.title,
e.timestamp,
@@ -711,9 +716,8 @@
$body
{$serendipity['fullCountQuery']}
$group
- ORDER BY $orderby
+ ORDER BY {$cond['orderby']}
$limit";
-
$ret = serendipity_db_query($query);
if (is_string($ret)) {
@@ -737,6 +741,8 @@
$assoc_ids[$entry['id']] = $i; // store temporary reference
}
+ serendipity_plugin_api::hook_event('frontend_entryproperties', $ret, $assoc_ids);
+
$query = "SELECT
ec.entryid,
c.categoryid,
@@ -767,35 +773,56 @@
function serendipity_fetchEntry($key, $val, $full = true, $fetchDrafts = 'false') {
global $serendipity;
- $drafts = '';
+ $cond = array();
+ $cond['drafts'] = '';
if ($fetchDrafts == 'false') {
- $drafts = "AND isdraft = 'false'";
+ $cond['drafts'] = " AND isdraft = 'false'";
}
- $admin = '';
+ $cond['admin'] = '';
if (isset($serendipity['GET']['adminModule']) && $serendipity['GET']['adminModule'] == 'entries' && $serendipity['serendipityUserlevel'] < USERLEVEL_CHIEF) {
- $admin = " AND e.authorid = '" . $serendipity['authorid'] . "'";
+ $cond['admin'] = " AND e.authorid = '" . $serendipity['authorid'] . "'";
}
+ serendipity_plugin_api::hook_event('frontend_fetchentry', $cond);
+
$querystring = "SELECT
*,
a.username,
a.email
- FROM
- {$serendipity['dbPrefix']}entries e,
- {$serendipity['dbPrefix']}authors a
- WHERE
- a.authorid = e.authorid
- AND e.$key LIKE '" . serendipity_db_escape_string($val) . "'
- $admin
- $drafts
- LIMIT 1";
+ FROM
+ {$serendipity['dbPrefix']}entries e
+ LEFT JOIN {$serendipity['dbPrefix']}authors a
+ ON e.authorid = a.authorid
+ LEFT OUTER JOIN {$serendipity['dbPrefix']}entryproperties ep
+ ON e.id = ep.entryid
+
+ WHERE
+ e.$key LIKE '" . serendipity_db_escape_string($val) . "'
+ {$cond['admin']}
+ {$cond['drafts']}
+ LIMIT 1";
$ret = serendipity_db_query($querystring, true);
- $ret['categories'] = $ret[] = serendipity_fetchEntryCategories($ret['id']);
+ $ret['categories'] = serendipity_fetchEntryCategories($ret['id']);
+ $ret['properties'] = serendipity_fetchEntryProperties($ret['id']);
return $ret;
}
+function serendipity_fetchEntryProperties($id) {
+ global $serendipity;
+ $properties = serendipity_db_query("SELECT property, value FROM {$serendipity['dbPrefix']}entryproperties WHERE entryid = " . (int)$id);
+ if (!is_array($properties)) {
+ $properties = array();
+ }
+
+ $property = array();
+ foreach($properties AS $idx => $row) {
+ $property[$row['property']] = $row['value'];
+ }
+
+ return $property;
+}
/**
* Fetches a users categories
**/
@@ -885,6 +912,8 @@
$find_part = "MATCH(title,body,extended) AGAINST('$term')";
}
+ $cond = array();
+ serendipity_plugin_api::hook_event('frontend_fetchentries', $cond);
$querystring = "SELECT $distinct
e.id,
e.author,
@@ -898,19 +927,21 @@
e.extended,
e.trackbacks,
e.exflag
- FROM
- {$serendipity['dbPrefix']}entries e,
- {$serendipity['dbPrefix']}authors a,
- {$serendipity['dbPrefix']}entrycat ec
- WHERE
- a.authorid = e.authorid
- AND e.id = ec.entryid
- AND $find_part
- AND isdraft = 'false'
- AND timestamp <= " . time() . "
+ FROM
+ {$serendipity['dbPrefix']}entries e
+ LEFT JOIN {$serendipity['dbPrefix']}authors a
+ ON e.authorid = a.authorid
+ LEFT JOIN {$serendipity['dbPrefix']}entrycat ec
+ ON e.id = ec.entryid
+ LEFT OUTER JOIN {$serendipity['dbPrefix']}entryproperties ep
+ ON e.id = ep.entryid
+ WHERE
+ $find_part
+ AND isdraft = 'false'
+ AND timestamp <= " . time() . "
+ {$cond['and']}
$group
- ORDER BY
- timestamp DESC";
+ ORDER BY timestamp DESC";
$serendipity['hidefooter'] = true;
return serendipity_db_query($querystring);
@@ -1116,7 +1147,12 @@
$dateseen = array();
$datekey = -1;
for ($x = 0, $num_entries = count($entries); $x < $num_entries; $x++) {
- $ts = date('Ymd', $entries[$x]['timestamp']);
+ if (!empty($entries[$x]['properties']['ep_is_sticky']) && serendipity_db_bool($entries[$x]['properties']['ep_is_sticky'])) {
+ $timestamp = $ts = 'sticky';
+ } else {
+ $timestamp = $entries[$x]['timestamp'];
+ $ts = date('Ymd', $timestamp);
+ }
if (!isset($dateseen[$ts])) {
// No entries existing for the same timestamp. Increment to the next numerical index
@@ -1125,7 +1161,7 @@
$bydate[$datekey][] =& $entries[$x];
$dateseen[$ts] = true;
- $dateref[$datekey] = $entries[$x]['timestamp'];
+ $dateref[$datekey] = $timestamp;
}
foreach($bydate AS $date => $ents) {
@@ -2476,7 +2512,9 @@
// Send publish tags if either a new article has been inserted from scratch, or if the entry was previously
// stored as draft and is now published
if ($entry['isdraft'] == 'false' && ($newEntry || $_entry['isdraft'] == 'true')) {
- serendipity_plugin_api::hook_event('backend_publish', $entry);
+ serendipity_plugin_api::hook_event('backend_publish', $entry, $newEntry);
+ } else {
+ serendipity_plugin_api::hook_event('backend_save', $entry, $newEntry);
}
return (int)$entry['id'];
Index: serendipity_db_mysql.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_db_mysql.inc.php,v
retrieving revision 1.22
retrieving revision 1.22.2.1
diff -u -d -r1.22 -r1.22.2.1
--- serendipity_db_mysql.inc.php 26 Aug 2004 10:51:28 -0000 1.22
+++ serendipity_db_mysql.inc.php 21 Sep 2004 20:43:15 -0000 1.22.2.1
@@ -19,12 +19,12 @@
$c = mysql_query($sql);
if (mysql_error() != '') {
- return mysql_error();
+ return $sql . ' / ' . mysql_error();
}
if (!$c) {
if (!$serendipity['production']) {
- print mysql_error();
+ print $sql . ' / ' . mysql_error();
if (function_exists('debug_backtrace') && $reportErr == true) {
highlight_string(var_export(debug_backtrace(), 1));
}
Index: serendipity_config.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_config.inc.php,v
retrieving revision 1.93.2.8
retrieving revision 1.93.2.9
diff -u -d -r1.93.2.8 -r1.93.2.9
--- serendipity_config.inc.php 20 Sep 2004 10:42:36 -0000 1.93.2.8
+++ serendipity_config.inc.php 21 Sep 2004 20:43:15 -0000 1.93.2.9
@@ -15,7 +15,7 @@
include_once(S9Y_INCLUDE_PATH . 'compat.php');
-$serendipity['version'] = '0.8-alpha1';
+$serendipity['version'] = '0.8-alpha2';
$serendipity['defaultTemplate'] = 'default'; // Name of folder for the default theme
$serendipity['production'] = 1;
$serendipity['rewrite'] = 'none';
|