タイムスタンプからMySQL特有のdatetime表現に変換するmysqldate()関数をi18n::formatted_datetime()に移植しました。
globalfunctions.phpの当該関数は非推奨とします。
加えて、i18n::formatted_datetime()を再整備して引数の見直しをしました。これに関連して、いくつかのスクリプトのメソッドを書き換えています。
$this->updateFuturePosted($blogid);
}
- /**
- * Update a blog's future posted flag
- * @param int $blogid
- */
- function updateFuturePosted($blogid) {
- global $manager;
-
- $blog =& $manager->getBlog($blogid);
- $currenttime = $blog->getCorrectTime(time());
- $result = sql_query("SELECT * FROM ".sql_table('item').
- " WHERE iblog='".$blogid."' AND iposted=0 AND itime>".mysqldate($currenttime));
- if (sql_num_rows($result) > 0) {
- $blog->setFuturePost();
- }
- else {
- $blog->clearFuturePost();
- }
- }
+ /**
+ * ADMIN::updateFuturePosted()
+ * Update a blog's future posted flag
+ *
+ * @param integer $blogid
+ * @return void
+ *
+ */
+ function updateFuturePosted($blogid)
+ {
+ global $manager;
+
+ $blog =& $manager->getBlog($blogid);
+ $currenttime = $blog->getCorrectTime(time());
+
+ $query = "SELECT * FROM %s WHERE iblog=%d AND iposted=0 AND itime>'%s'";
+ $query = sprintf($query, sql_table('item'), (integer) $blogid, i18n::formatted_datetime('mysql', $currenttime));
+ $result = sql_query($query);
+
+ if ( sql_num_rows($result) > 0 )
+ {
+ $blog->setFuturePost();
+ }
+ else
+ {
+ $blog->clearFuturePost();
+ }
+ return;
+ }
/**
* @todo document this
}
/**
+ * BLOG::showArchive()
* Shows an archive for a given month
*
- * @param $year
- * year
- * @param $month
- * month
- * @param $template
- * String representing the template name to be used
+ * @param integer $year year
+ * @param integer $month month
+ * @param string $template String representing the template name to be used
+ * @return void
+ *
*/
- function showArchive($templatename, $year, $month=0, $day=0) {
-
+ function showArchive($templatename, $year, $month=0, $day=0)
+ {
// create extra where clause for select query
- if ($day == 0 && $month != 0) {
+ if ( $day == 0 && $month != 0 )
+ {
$timestamp_start = mktime(0,0,0,$month,1,$year);
- $timestamp_end = mktime(0,0,0,$month+1,1,$year); // also works when $month==12
- } elseif ($month == 0) {
+ // also works when $month==12
+ $timestamp_end = mktime(0,0,0,$month+1,1,$year);
+ }
+ elseif ( $month == 0 )
+ {
$timestamp_start = mktime(0,0,0,1,1,$year);
- $timestamp_end = mktime(0,0,0,12,31,$year); // also works when $month==12
- } else {
+ // also works when $month==12
+ $timestamp_end = mktime(0,0,0,12,31,$year);
+ }
+ else
+ {
$timestamp_start = mktime(0,0,0,$month,$day,$year);
$timestamp_end = mktime(0,0,0,$month,$day+1,$year);
}
- $extra_query = ' and i.itime>=' . mysqldate($timestamp_start)
- . ' and i.itime<' . mysqldate($timestamp_end);
-
-
+ $extra_query = " and i.itime>='%s' and i.itime<'%s'";
+ $extra_query = sprintf($extra_query, i18n::formatted_datetime('mysql', $timestamp_start), i18n::formatted_datetime('mysql', $timestamp_end));
+
$this->readLogAmount($templatename,0,$extra_query,'',1,1);
-
+ return;
}
/**
}
/**
+ * BLOG::showUsingQuery()
* Do the job for readLogAmmount
+ *
+ * @param string $templateName template name
+ * @param string $query string for query
+ * @param string $highlight string to be highlighted
+ * @param integer $comments the number of comments
+ * @param boolean $dateheads date header is needed or not
+ * @return integer the number of rows as a result of mysql query
+ *
*/
- function showUsingQuery($templateName, $query, $highlight = '', $comments = 0, $dateheads = 1) {
- global $CONF, $manager;
-
+ function showUsingQuery($templateName, $query, $highlight = '', $comments = 0, $dateheads = 1)
+ {
+ global $CONF, $manager, $currentTemplateName;
+
$lastVisit = cookieVar($CONF['CookiePrefix'] .'lastVisit');
- if ($lastVisit != 0)
+ if ( $lastVisit != 0 )
+ {
$lastVisit = $this->getCorrectTime($lastVisit);
-
+ }
+
// set templatename as global variable (so plugins can access it)
- global $currentTemplateName;
$currentTemplateName = $templateName;
-
$template =& $manager->getTemplate($templateName);
-
+
// create parser object & action handler
$actions = new ITEMACTIONS($this);
$parser = new PARSER($actions->getDefinedActions(),$actions);
$actions->setLastVisit($lastVisit);
$actions->setParser($parser);
$actions->setShowComments($comments);
-
+
// execute query
$items = sql_query($query);
-
+
// loop over all items
$old_date = 0;
- while ($item = sql_fetch_object($items)) {
-
+ while ( $item = sql_fetch_object($items) )
+ {
$item->timestamp = strtotime($item->itime); // string timestamp -> unix timestamp
-
+
// action handler needs to know the item we're handling
$actions->setCurrentItem($item);
-
+
// add date header if needed
- if ($dateheads) {
+ if ( $dateheads )
+ {
$new_date = date('dFY',$item->timestamp);
- if ($new_date != $old_date) {
+ if ( $new_date != $old_date )
+ {
// unless this is the first time, write date footer
$timestamp = $item->timestamp;
- if ($old_date != 0) {
+ if ( $old_date != 0 )
+ {
$oldTS = strtotime($old_date);
$manager->notify('PreDateFoot',array('blog' => &$this, 'timestamp' => $oldTS));
$tmp_footer = i18n::strftime(isset($template['DATE_FOOTER'])?$template['DATE_FOOTER']:'', $oldTS);
}
$old_date = $new_date;
}
-
+
// parse item
$parser->parse($template['ITEM_HEADER']);
$manager->notify('PreItem', array('blog' => &$this, 'item' => &$item));
$parser->parse($template['ITEM']);
$manager->notify('PostItem', array('blog' => &$this, 'item' => &$item));
$parser->parse($template['ITEM_FOOTER']);
-
}
-
+
$numrows = sql_num_rows($items);
-
+
// add another date footer if there was at least one item
- if (($numrows > 0) && $dateheads) {
+ if ( ($numrows > 0) && $dateheads )
+ {
$manager->notify('PreDateFoot',array('blog' => &$this, 'timestamp' => strtotime($old_date)));
$parser->parse($template['DATE_FOOTER']);
$manager->notify('PostDateFoot',array('blog' => &$this, 'timestamp' => strtotime($old_date)));
}
-
- sql_free_result($items); // free memory
-
+
+ sql_free_result($items);
return $numrows;
-
}
-
+
/**
* Simplified function for showing only one item
*/
}
/**
+ * BLOG::getSqlSearch()
* Returns an SQL query to use for a search query
+ * No LIMIT clause is added. (caller should add this if multiple pages are requested)
*
- * @param $query
- * search query
- * @param $amountMonths
- * amount of months to search back. Default = 0 = unlimited
- * @param $mode
- * either empty, or 'count'. In this case, the query will be a SELECT COUNT(*) query
- * @returns $highlight
- * words to highlight (out parameter)
- * @returns
- * either a full SQL query, or an empty string (if querystring empty)
- * @note
- * No LIMIT clause is added. (caller should add this if multiple pages are requested)
+ * @param string $query search query
+ * @param integer $amountMonths amount of months to search back. Default = 0 = unlimited
+ * @param string $mode either empty, or 'count'. In this case, the query will be a SELECT COUNT(*) query
+ * @return string $highlight words to highlight (out parameter)
+ * @return string either a full SQL query, or an empty string (if querystring empty)
*/
function getSqlSearch($query, $amountMonths = 0, &$highlight, $mode = '')
{
$searchclass = new SEARCH($query);
-
- $highlight = $searchclass->inclusive;
-
+
+ $highlight = $searchclass->inclusive;
+
// if querystring is empty, return empty string
- if ($searchclass->inclusive == '')
+ if ( $searchclass->inclusive == '' )
+ {
return '';
-
-
- $where = $searchclass->boolean_sql_where('ititle,ibody,imore');
- $select = $searchclass->boolean_sql_select('ititle,ibody,imore');
-
+ }
+
+ $where = $searchclass->boolean_sql_where('ititle, ibody, imore');
+ $select = $searchclass->boolean_sql_select('ititle, ibody, imore');
+
// get list of blogs to search
- $blogs = $searchclass->blogs; // array containing blogs that always need to be included
- $blogs[] = $this->getID(); // also search current blog (duh)
- $blogs = array_unique($blogs); // remove duplicates
- $selectblogs = '';
- if (count($blogs) > 0)
+ $blogs = $searchclass->blogs; // array containing blogs that always need to be included
+ $blogs[] = $this->getID(); // also search current blog (duh)
+ $blogs = array_unique($blogs); // remove duplicates
+ $selectblogs = '';
+
+ if ( count($blogs) > 0 )
+ {
$selectblogs = ' and i.iblog in (' . implode(',', $blogs) . ')';
-
- if ($mode == '')
+ }
+
+ if ( $mode == '' )
{
- $query = 'SELECT i.inumber as itemid, i.ititle as title, i.ibody as body, m.mname as author, m.mrealname as authorname, i.itime, i.imore as more, m.mnumber as authorid, m.memail as authormail, m.murl as authorurl, c.cname as category, i.icat as catid, i.iclosed as closed';
- if ($select)
+ $query = 'SELECT i.inumber as itemid, i.ititle as title, i.ibody as body, i.itime, i.imore as more, i.icat as catid, i.iclosed as closed,
+ m.mname as author, m.mrealname as authorname, m.mnumber as authorid, m.memail as authormail, m.murl as authorurl,
+ c.cname as category';
+
+ if ( $select )
+ {
$query .= ', '.$select. ' as score ';
- } else {
+ }
+ }
+ else
+ {
$query = 'SELECT COUNT(*) as result ';
}
-
+
$query .= ' FROM '.sql_table('item').' as i, '.sql_table('member').' as m, '.sql_table('category').' as c'
- . ' WHERE i.iauthor=m.mnumber'
- . ' and i.icat=c.catid'
- . ' and i.idraft=0' // exclude drafts
- . $selectblogs
- // don't show future items
- . ' and i.itime<=' . mysqldate($this->getCorrectTime())
- . ' and '.$where;
+ . ' WHERE i.iauthor=m.mnumber'
+ . ' and i.icat=c.catid'
+ // exclude drafts
+ . ' and i.idraft=0'
+ . $selectblogs
+ // don't show future items
+ . ' and i.itime<="' . i18n::formatted_datetime('mysql', $this->getCorrectTime()) . '"'
+ . ' and '.$where;
// take into account amount of months to search
- if ($amountMonths > 0)
+ if ( $amountMonths > 0 )
{
$localtime = getdate($this->getCorrectTime());
$timestamp_start = mktime(0,0,0,$localtime['mon'] - $amountMonths,1,$localtime['year']);
- $query .= ' and i.itime>' . mysqldate($timestamp_start);
+ $query .= ' and i.itime>"' . i18n::formatted_datetime('mysql', $timestamp_start) . '"';
}
-
- if ($mode == '')
+
+ if ( $mode == '' )
{
- if ($select)
+ if ( $select )
+ {
$query .= ' ORDER BY score DESC';
+ }
else
+ {
$query .= ' ORDER BY i.itime DESC ';
+ }
}
-
return $query;
}
-
+
/**
+ * BLOG::getSqlBlog()
* Returns the SQL query that's normally used to display the blog items on the index type skins
+ * No LIMIT clause is added. (caller should add this if multiple pages are requested)
*
- * @param $mode
- * either empty, or 'count'. In this case, the query will be a SELECT COUNT(*) query
- * @returns
- * either a full SQL query, or an empty string
- * @note
- * No LIMIT clause is added. (caller should add this if multiple pages are requested)
+ * @param string $extraQuery extra query string
+ * @param string $mode either empty, or 'count'. In this case, the query will be a SELECT COUNT(*) query
+ * @return string either a full SQL query, or an empty string
*/
function getSqlBlog($extraQuery, $mode = '')
{
- if ($mode == '')
- $query = 'SELECT i.inumber as itemid, i.ititle as title, i.ibody as body, m.mname as author, m.mrealname as authorname, i.itime, i.imore as more, m.mnumber as authorid, m.memail as authormail, m.murl as authorurl, c.cname as category, i.icat as catid, i.iclosed as closed';
+ if ( $mode == '' )
+ {
+ $query = 'SELECT i.inumber as itemid, i.ititle as title, i.ibody as body, m.mname as author,
+ m.mrealname as authorname, i.itime, i.imore as more, m.mnumber as authorid, m.memail as authormail,
+ m.murl as authorurl, c.cname as category, i.icat as catid, i.iclosed as closed';
+ }
else
+ {
$query = 'SELECT COUNT(*) as result ';
-
- $query .= ' FROM '.sql_table('item').' as i, '.sql_table('member').' as m, '.sql_table('category').' as c'
- . ' WHERE i.iblog='.$this->blogid
- . ' and i.iauthor=m.mnumber'
- . ' and i.icat=c.catid'
- . ' and i.idraft=0' // exclude drafts
- // don't show future items
- . ' and i.itime<=' . mysqldate($this->getCorrectTime());
-
- if ($this->getSelectedCategory())
+ }
+
+ $query .= ' FROM '.sql_table('item').' as i, '.sql_table('member').' as m, '.sql_table('category').' as c'
+ . ' WHERE i.iblog='.$this->blogid
+ . ' and i.iauthor=m.mnumber'
+ . ' and i.icat=c.catid'
+ // exclude drafts
+ . ' and i.idraft=0'
+ // don't show future items
+ . ' and i.itime<="' . i18n::formatted_datetime('mysql', $this->getCorrectTime()) . '"';
+
+ if ( $this->getSelectedCategory() )
+ {
$query .= ' and i.icat=' . $this->getSelectedCategory() . ' ';
-
-
+ }
+
$query .= $extraQuery;
-
- if ($mode == '')
+
+ if ( $mode == '' )
+ {
$query .= ' ORDER BY i.itime DESC';
-
+ }
return $query;
}
-
+
/**
* BLOG::showArchiveList()
* Shows the archivelist using the given template
$template =& $manager->getTemplate($template);
$data['blogid'] = $this->getID();
- $tplt = isset($template['ARCHIVELIST_HEADER']) ? $template['ARCHIVELIST_HEADER'] : '';
+ if ( !array_key_exists('ARCHIVELIST_HEADER', $template) || !$template['ARCHIVELIST_HEADER'] )
+ {
+ $tplt = '';
+ }
+ else
+ {
+ $tplt = $template['ARCHIVELIST_HEADER'];
+ }
+
echo TEMPLATE::fill($tplt, $data);
- $query = 'SELECT itime, SUBSTRING(itime,1,4) AS Year, SUBSTRING(itime,6,2) AS Month, SUBSTRING(itime,9,2) as Day FROM '.sql_table('item')
- . ' WHERE iblog=' . $this->getID()
- . ' and itime <=' . mysqldate($this->getCorrectTime()) // don't show future items!
- . ' and idraft=0'; // don't show draft items
+ $query = 'SELECT itime, SUBSTRING(itime,1,4) AS Year, SUBSTRING(itime,6,2) AS Month, SUBSTRING(itime,9,2) AS Day'
+ . ' FROM '.sql_table('item')
+ . ' WHERE iblog=' . $this->getID()
+ // don't show future items!
+ . ' AND itime <="' . i18n::formatted_datetime('mysql', $this->getCorrectTime()) . '"'
+ // don't show draft items
+ . ' AND idraft=0';
if ( $catid )
{
}
$res = sql_query($query);
- while ($current = sql_fetch_object($res))
+ while ( $current = sql_fetch_object($res) )
{
/* string time -> unix timestamp */
$current->itime = strtotime($current->itime);
sql_free_result($res);
- $tplt = isset($template['ARCHIVELIST_FOOTER']) ? $template['ARCHIVELIST_FOOTER'] : '';
+ if ( !array_key_exists('ARCHIVELIST_FOOTER', $template) || !$template['ARCHIVELIST_FOOTER'] )
+ {
+ $tplt = '';
+ }
+ else
+ {
+ $tplt = $template['ARCHIVELIST_FOOTER'];
+ }
+
echo TEMPLATE::fill($tplt, $data);
return;
}
}
function getID() {
- return intval($this->blogid);
+ return (integer) $this->blogid;
}
/**
}
/**
+ * BLOG::getSqlItemList()
* Returns the SQL query used to fill out templates for a list of items
+ * No LIMIT clause is added. (caller should add this if multiple pages are requested)
*
- * @param $itemarray
- * an array holding the item numbers of the items to be displayed
- * @param $showDrafts
- * 0=do not show drafts 1=show drafts
- * @param $showFuture
- * 0=do not show future posts 1=show future posts
- * @returns
- * either a full SQL query, or an empty string
- * @note
- * No LIMIT clause is added. (caller should add this if multiple pages are requested)
+ * @param array $itemarray an array holding the item numbers of the items to be displayed
+ * @param integer $showDrafts 0=do not show drafts 1=show drafts
+ * @param integer $showFuture 0=do not show future posts 1=show future posts
+ * @return string either a full SQL query, or an empty string
+ *
*/
function getSqlItemList($itemarray,$showDrafts = 0,$showFuture = 0)
{
- if (!is_array($itemarray)) return '';
+ if ( !is_array($itemarray) )
+ {
+ return '';
+ }
+
$showDrafts = intval($showDrafts);
$showFuture = intval($showFuture);
$items = array();
- foreach ($itemarray as $value) {
- if (intval($value)) $items[] = intval($value);
+
+ foreach ( $itemarray as $value )
+ {
+ if ( intval($value) )
+ {
+ $items[] = intval($value);
+ }
+ }
+ if ( !count($items) )
+ {
+ return '';
}
- if (!count($items)) return '';
- //$itemlist = implode(',',$items);
+
$i = count($items);
$query = '';
- foreach ($items as $value) {
+ foreach ( $items as $value )
+ {
$query .= '('
. 'SELECT'
. ' i.inumber as itemid,'
. ' c.cname as category,'
. ' i.icat as catid,'
. ' i.iclosed as closed';
-
+
$query .= ' FROM '
. sql_table('item') . ' as i, '
. sql_table('member') . ' as m, '
. ' i.iblog='.$this->blogid
. ' and i.iauthor=m.mnumber'
. ' and i.icat=c.catid';
- if (!$showDrafts) $query .= ' and i.idraft=0'; // exclude drafts
- if (!$showFuture) $query .= ' and i.itime<=' . mysqldate($this->getCorrectTime()); // don't show future items
-
- //$query .= ' and i.inumber IN ('.$itemlist.')';
+
+ // exclude drafts
+ if ( !$showDrafts )
+ {
+ $query .= ' and i.idraft=0';
+ }
+ if ( !$showFuture )
+ {
+ // don't show future items
+ $query .= ' and i.itime<="' . i18n::formatted_datetime('mysql', $this->getCorrectTime()) . '"';
+ }
+
$query .= ' and i.inumber='.intval($value);
$query .= ')';
$i--;
if ($i) $query .= ' UNION ';
}
-
+
return $query;
}
-
}
-
-?>
*/
function setCurrentComment(&$comment)
{
- global $manager;
+ global $currentcommentid, $currentcommentarray, $manager;
if ( $comment['memberid'] != 0 )
{
- $comment['authtext'] = $template['COMMENTS_AUTH'];
+ if ( !array_key_exists('COMMENTS_AUTH', $this->template) )
+ {
+ $comment['authtext'] = '';
+ }
+ else
+ {
+ $comment['authtext'] = $this->template['COMMENTS_AUTH'];
+ }
+
$mem =& $manager->getMember($comment['memberid']);
$comment['user'] = $mem->getDisplayName();
else
{
// create smart links
- if ( !empty($comment['userid']) )
+ if ( !array_key_exists('userid', $comment) || !empty($comment['userid']) )
{
if ( (i18n::strpos($comment['userid'], 'http://') === 0) || (i18n::strpos($comment['userid'], 'https://') === 0) )
{
}
$this->currentComment =& $comment;
- global $currentcommentid, $currentcommentarray;
$currentcommentid = $comment['commentid'];
$currentcommentarray = $comment;
return;
else
echo $this->template['COMMENTS_MANY'];
}
-
+
/**
* COMMENTACTIONS::parse_date()
* Parse templatevar date
*
* @format String $format Date format according to PHP
- * @return String formatted datetime
+ * @return void
*
*/
function parse_date($format = '')
{
+ if ( $format !== '' )
+ {
+ /* pass */
+ }
+ else if ( !array_key_exists('FORMAT_DATE', $this->template) || $this->template['FORMAT_DATE'] === '' )
+ {
+ $format = '%X';
+ }
+ else
+ {
+ $format = $this->template['FORMAT_DATE'];
+ }
+
$offset = $this->commentsObj->itemActions->blog->getTimeOffset() * 3600;
- echo i18n::formatted_datetime($format, $this->currentComment['timestamp'], $this->template['FORMAT_DATE'], $offset);
+
+ echo i18n::formatted_datetime($format, $this->currentComment['timestamp'], $offset);
+ return;
}
-
+
/**
* Parse templatevar email
*/
if ($tmp != $this->currentComment['body'])
$this->parser->parse($this->template['COMMENTS_CONTINUED']);
}
-
+
/**
+ * COMMENTACTIONS::parse_time()
* Parse templatevar time
+ *
+ * @param string $format datetime format referring to strftime() in PHP's built-in function
+ * @return void
+ *
*/
- function parse_time($format = '') {
- echo i18n::strftime(
- ($format == '') ? $this->template['FORMAT_TIME'] : $format,
- $this->currentComment['timestamp']
- );
+ function parse_time($format = '')
+ {
+ if ( $format === '' )
+ {
+ /* pass */
+ }
+ else if ( !array_key_exists('FORMAT_TIME', $this->template) || $this->template['FORMAT_TIME'] === '' )
+ {
+ $format = '%x';
+ }
+ else
+ {
+ $format = $this->template['FORMAT_TIME'];
+ }
+
+ echo i18n::strftime($format, $this->currentComment['timestamp']);
+ return;
}
-
+
/**
* Parse templatevar timestamp
*/
}
}
-?>
}
/**
+ * ITEM::getitem()
* Returns one item with the specific itemid
*
* @param int $item_id
* @param bool $allow_draft
* @param bool $allow_future
* @return mixed
+ *
*/
static public function getitem($item_id, $allow_draft, $allow_future)
{
$item_id = intval($item_id);
$query = 'SELECT ' .
- '`i`.`idraft` AS `draft`, ' .
- '`i`.`inumber` AS `itemid`, ' .
- '`i`.`iclosed` AS `closed`, ' .
- '`i`.`ititle` AS `title`, ' .
- '`i`.`ibody` AS `body`, ' .
- '`m`.`mname` AS `author`, ' .
- '`i`.`iauthor` AS `authorid`, ' .
- '`i`.`itime`, ' .
- '`i`.`imore` AS `more`, ' .
- '`i`.`ikarmapos` AS `karmapos`, ' .
- '`i`.`ikarmaneg` AS `karmaneg`, ' .
- '`i`.`icat` AS `catid`, ' .
- '`i`.`iblog` AS `blogid` ' .
- 'FROM `%s` AS `i`, `%s` AS `m`, `%s` AS `b` ' .
- 'WHERE `i`.`inumber` = %d ' .
- 'AND `i`.`iauthor` = `m`.`mnumber` ' .
- 'AND `i`.`iblog` = `b`.`bnumber`';
+ 'i.idraft AS draft, ' .
+ 'i.inumber AS itemid, ' .
+ 'i.iclosed AS closed, ' .
+ 'i.ititle AS title, ' .
+ 'i.ibody AS body, ' .
+ 'm.mname AS author, ' .
+ 'i.iauthor AS authorid, ' .
+ 'i.itime, ' .
+ 'i.imore AS more, ' .
+ 'i.ikarmapos AS karmapos, ' .
+ 'i.ikarmaneg AS karmaneg, ' .
+ 'i.icat AS catid, ' .
+ 'i.iblog AS blogid ' .
+ 'FROM %s AS i, %s AS m, %s AS b ' .
+ 'WHERE i.inumber = %d ' .
+ 'AND i.iauthor = m.mnumber ' .
+ 'AND i.iblog = b.bnumber ';
$query = sprintf($query, sql_table('item'), sql_table('member'), sql_table('blog'), $item_id);
if ( !$allow_draft )
{
- $query .= 'AND `i`.`idraft` = 0 ';
+ $query .= "AND i.idraft = 0 ";
}
if ( !$allow_future )
{
$blog =& $manager->getBlog(getBlogIDFromItemID($item_id));
- $query .= 'AND `i`.`itime` <= ' . mysqldate($blog->getCorrectTime());
+ $query .= "AND `i`.`itime` <= '" . i18n::formatted_datetime('mysql', $blog->getCorrectTime()) ."'";
}
$query .= ' LIMIT 1';
* @static
* @param void
* @return array (status = added/error/newcategory, message)
+ *
*/
static public function createFromRequest()
{
$old_blogid = getBlogIDFromItemID($itemid);
// move will be done on end of method
+ $moveNeeded = 0;
if ( $new_blogid != $old_blogid )
{
$moveNeeded = 1;
{
$query .= ', idraft = 1';
// set timestamp back to zero for a draft
- $query .= ', itime = ' . mysqldate($timestamp);
+ $query .= ", itime = '" . i18n::formatted_datetime('mysql', $timestamp) ."'";
}
// update timestamp when needed
if ( $timestamp != 0 )
{
- $query .= ', itime = ' . mysqldate($timestamp);
+ $query .= ", itime = '" . i18n::formatted_datetime('mysql', $timestamp) ."'";
}
// make sure the correct item is updated
* @param boolean $future
* @param boolean $draft
* @return boolean exists or not
+ *
*/
static public function exists($itemid, $future, $draft)
{
return 0;
}
$blog =& $manager->getBlog($blogid);
- $query .= ' and itime<=' . mysqldate($blog->getCorrectTime());
+ $query .= " and itime<='" . i18n::formatted_datetime('mysql', $blog->getCorrectTime()) ."'";
}
if ( !$draft )
{
*
* @license http://nucleuscms.org/license.txt GNU General Public License
* @copyright Copyright (C) 2002-2009 The Nucleus Group
- * @version $Id: ITEMACTIONS.php 1674 2012-02-26 05:25:02Z sakamocchi $
+ * @version $Id: ITEMACTIONS.php 1699 2012-03-10 15:46:32Z sakamocchi $
*/
class ITEMACTIONS extends BaseActions {
* ITEMACTIONS::parse_date()
* Parse templatevar date
*
- * @param String $format format optional strftime format
- * @return String formatted datetime
+ * @param string $format format optional strftime format
+ * @return void
*/
function parse_date($format = '')
{
- if ( !isset($this->template['FORMAT_DATE']) )
+ if ( $format !== '' )
{
- $this->template['FORMAT_DATE'] = '';
+ break;
+ }
+ else if ( !array_key_exists('FORMAT_DATE', $this->template) || $this->template['FORMAT_DATE'] === '' )
+ {
+ /* depends on the PHP's current locale */
+ $format = '%X';
+ }
+ else
+ {
+ $format = $this->template['FORMAT_DATE'];
}
$offset = 0;
$offset = $this->blog->getTimeOffset() * 3600;
}
- echo i18n::formatted_datetime($format, $this->currentItem->timestamp, $this->template['FORMAT_DATE'], $offset);
+ echo i18n::formatted_datetime($format, $this->currentItem->timestamp, $offset);
+ return;
}
/**
- * Parse templatevar time
- *
- * @param format optional strftime format
- */
- function parse_time($format = '') {
- if (!isset($this->template['FORMAT_TIME'])) $this->template['FORMAT_TIME'] = '';
- echo i18n::strftime($format ? $format : $this->template['FORMAT_TIME'],$this->currentItem->timestamp);
+ * ITEMACTIONS::parse_time()
+ * Parse templatevar time
+ *
+ * @param string $format format optional strftime format
+ * @return void
+ *
+ */
+ function parse_time($format = '')
+ {
+ if ( $format !== '' )
+ {
+ break;
+ }
+ else if ( !array_key_exists('FORMAT_TIME', $this->template) || $this->template['FORMAT_TIME'] === '' )
+ {
+ /* depends on the PHP's current locale */
+ $format = '%x';
+ }
+ else
+ {
+ $format = $this->template['FORMAT_TIME'];
+ }
+ echo i18n::strftime($format, $this->currentItem->timestamp);
+ return;
}
/**
/**
* @license http://nucleuscms.org/license.txt GNU General Public License
* @copyright Copyright (C) 2002-2009 The Nucleus Group
- * @version $Id: globalfunctions.php 1639 2012-01-29 08:10:11Z sakamocchi $
+ * @version $Id: globalfunctions.php 1697 2012-03-10 13:15:47Z sakamocchi $
*/
/* needed if we include globalfunctions from install.php */
/* check and die if someone is trying to override internal globals (when register_globals turn on) */
checkVars(array('nucleus', 'CONF', 'DIR_LIBS', 'MYSQL_HOST', 'MYSQL_USER', 'MYSQL_PASSWORD', 'MYSQL_DATABASE', '$DIR_LOCALES', 'DIR_PLUGINS', 'HTTP_GET_VARS', 'HTTP_POST_VARS', 'HTTP_COOKIE_VARS', 'HTTP_ENV_VARS', 'HTTP_SESSION_VARS', 'HTTP_POST_FILES', 'HTTP_SERVER_VARS', 'GLOBALS', 'argv', 'argc', '_GET', '_POST', '_COOKIE', '_ENV', '_SESSION', '_SERVER', '_FILES'));
-$CONF['debug'] = 0;
-if ( $CONF['debug'] )
+/* debug mode */
+if ( array_key_exists('debug', $CONF) && !$CONF['debug'] )
{
/* report all errors! */
error_reporting(E_ALL);
*switch URLMode back to normal when $CONF['Self'] ends in .php
* this avoids urls like index.php/item/13/index.php/item/15
*/
-if ( !array_key_exists('URLMode', $CONF) || (($CONF['URLMode'] == 'pathinfo')
+if ( !array_key_exists('URLMode', $CONF)
+ || (($CONF['URLMode'] == 'pathinfo')
&& (i18n::substr($CONF['Self'], i18n::strlen($CONF['Self']) - 4) == '.php')) )
{
$CONF['URLMode'] = 'normal';
// return isset($obj->pfile) ? $obj->pfile : false;
}
-function selector() {
+function selector()
+{
global $itemid, $blogid, $memberid, $query, $amount, $archivelist, $maxresults;
global $archive, $skinid, $blog, $memberinfo, $CONF, $member;
global $imagepopup, $catid, $special;
global $itemidprev, $itemidnext, $catid, $itemtitlenext, $itemtitleprev;
// 1. get timestamp, blogid and catid for item
- $query = 'SELECT itime, iblog, icat FROM ' . sql_table('item') . ' WHERE inumber=' . intval($itemid);
+ $query = 'SELECT itime, iblog, icat FROM %s WHERE inumber=%d';
+ $query = sprintf($query, sql_table('item'), (integer) $itemid);
$res = sql_query($query);
$obj = sql_fetch_object($res);
$b =& $manager->getBlog($blogid);
- if ( $b->isValidCategory($catid) )
+ if ( !$b->isValidCategory($catid) )
{
- $catextra = ' and icat=' . $catid;
+ $query = "SELECT inumber, ititle FROM %s WHERE itime<'%s' AND idraft=0 AND iblog=%d ORDER BY itime DESC LIMIT 1";
+ $query = sprintf($query, sql_table('item'), i18n::formatted_datetime('mysql', $timestamp), $blogid);
}
else
{
- $catextra = '';
+ $query = "SELECT inumber, ititle FROM %s WHERE itime<'%s' AND idraft=0 AND iblog=%d AND icat=%d ORDER BY itime DESC LIMIT 1";
+ $query = sprintf($query, sql_table('item'), i18n::formatted_datetime('mysql', $timestamp), $blogid, $catid);
}
- // get previous itemid and title
- $query = 'SELECT inumber, ititle FROM ' . sql_table('item') . ' WHERE itime<' . mysqldate($timestamp) . ' and idraft=0 and iblog=' . $blogid . $catextra . ' ORDER BY itime DESC LIMIT 1';
$res = sql_query($query);
-
$obj = sql_fetch_object($res);
if ( $obj )
}
// get next itemid and title
- $query = 'SELECT inumber, ititle FROM ' . sql_table('item') . ' WHERE itime>' . mysqldate($timestamp) . ' and itime <= ' . mysqldate($b->getCorrectTime()) . ' and idraft=0 and iblog=' . $blogid . $catextra . ' ORDER BY itime ASC LIMIT 1';
+ if ( !$b->isValidCategory($catid) )
+ {
+ $query = "SELECT inumber, ititle FROM %s WHERE itime>'%s' AND itime<='%s' AND idraft=0 AND iblog=%d ORDER BY itime ASC LIMIT 1";
+ $query = sprintf($query, sql_table('item'), i18n::formatted_datetime('mysql', $timestamp), i18n::formatted_datetime('mysql', $b->getCorrectTime()), $blogid);
+ }
+ else
+ {
+ $query = "SELECT inumber, ititle FROM %s WHERE itime>'%s' AND itime<='%s' AND idraft=0 AND iblog=%d AND icat=%d ORDER BY itime ASC LIMIT 1";
+ $query = sprintf($query, sql_table('item'), i18n::formatted_datetime('mysql', $timestamp), i18n::formatted_datetime('mysql', $b->getCorrectTime()), $blogid, $catid);
+
+ }
$res = sql_query($query);
$obj = sql_fetch_object($res);
$itemtitlenext = $obj->ititle;
}
}
- elseif ($archive)
+ elseif ( $archive )
{
// show archive
$type = 'archive';
}
}
}
- elseif ($archivelist)
+ elseif ( $archivelist )
{
$type = 'archivelist';
}
/**
- * Converts a unix timestamp to a mysql DATETIME format, and places
- * quotes around it.
- */
-function mysqldate($timestamp) {
- return '"' . date('Y-m-d H:i:s', $timestamp) . '"';
-}
-
-/**
* functions for use in index.php
*/
function selectBlog($shortname) {
{
$offset += $blog->getTimeOffset() * 3600;
}
- return i18n::formatted_datetime($format, $timestamp, $default_format, $offset);
+ return i18n::formatted_datetime($format, $timestamp, $offset, $default_format);
+}
+/* NOTE: use i18n::formatted_datetime() directly instead of this */
+function mysqldate($timestamp)
+{
+ return '"' . i18n::formatted_datetime('mysql', $timestamp) . '"';
}
/**
* Centralisation of the functions that generate links
*
* @license http://nucleuscms.org/license.txt GNU General Public License
* @copyright Copyright (C) 2002-2011 The Nucleus Group
- * @version $Id: i18n.php 1673 2012-02-26 04:21:21Z sakamocchi $
+ * @version $Id: i18n.php 1678 2012-02-26 07:31:36Z sakamocchi $
*/
class i18n
{
* Working with Time Zones
* @link http://www.w3.org/TR/timezone/
*
- * @param String $format timezone format
- * @param String $timestamp UNIX timestamp
- * @param String $default_format default timezone format
+ * @param String $format time expression format
+ * @param String $timestamp UNIX timestamp
* @param Integer $offset timestamp offset
- * @return String formatted datetime
+ * @return String formatted datetime
*/
- static public function formatted_datetime($format, $timestamp, $default_format, $offset)
+ static public function formatted_datetime($format, $timestamp, $offset=0)
{
$suffix = '';
$string = '';
switch ( $format )
{
+ case 'mysql':
+ /*
+ * MySQL 5.0 Reference Manual
+ * 10.3.1. The DATE, DATETIME, and TIMESTAMP Types
+ * http://dev.mysql.com/doc/refman/5.0/en/datetime.html
+ */
+ $timestamp += $offset;
+ $format = '%Y-%m-%d %H:%M:%S';
+ $suffix ='';
+ break;
case 'rfc822':
- $format = 'D, j M Y H:i:s ';
+ /*
+ * RFC 822: STANDARD FOR THE FORMAT OF ARPA INTERNET TEXT MESSAGES
+ * 5. DATE AND TIME SPECIFICATION
+ * http://www.ietf.org/rfc/rfc0822.txt
+ */
+ $format = '%a, %d %m %y %H:%M:%S ';
if ( $offset < 0 )
{
$suffix = '-';
$suffix .= sprintf("%02d%02d", floor($offset / 3600), round(($offset % 3600) / 60) );
break;
case 'rfc822GMT':
- $format = 'D, j M Y H:i:s ';
+ /*
+ * RFC 822: STANDARD FOR THE FORMAT OF ARPA INTERNET TEXT MESSAGES
+ * 5. DATE AND TIME SPECIFICATION
+ * http://www.ietf.org/rfc/rfc0822.txt
+ */
+ $format = '%a, %d %m %y %H:%M:%S ';
$timestamp -= $offset;
$suffix = 'GMT';
break;
- case 'utc':
- $timestamp -= $offset;
- $format = 'Y-m-d\TH:i:s\Z';
- $suffix = '';
- break;
case 'iso8601':
- $format = 'Y-m-d\TH:i:s';
+ case 'rfc3339':
+ /*
+ * RFC3339: Date and Time on the Internet: Timestamps
+ * 5. Date and Time format
+ * http://www.ietf.org/rfc/rfc3339.txt
+ */
+ $format = '%Y-%m-%dT%H:%M:%S';
if ( $offset < 0 )
{
$suffix = '-';
}
$suffix .= sprintf("%02d:%02d", floor($offset / 3600), round(($offset % 3600) / 60) );
break;
- case '':
- $format = $default_format;
+ case 'utc':
+ case 'iso8601UTC':
+ case 'rfc3339UTC':
+ /*
+ * RFC3339: Date and Time on the Internet: Timestamps
+ * 5. Date and Time format
+ * http://www.ietf.org/rfc/rfc3339.txt
+ */
+ $timestamp -= $offset;
+ $format = '%Y-%m-%dT%H:%M:%SZ';
$suffix = '';
break;
+ case '':
+ $format = '%X %x';
+ $offset = '';
+ break;
default:
- $suffix = 0;
+ $suffix = '';
break;
}
return i18n::strftime($format, $timestamp) . $suffix;