From b3a0f96229fb739a2040c29a464967a7a3c4775f Mon Sep 17 00:00:00 2001 From: "Duck (Jakob Munih)" Date: Sat, 7 Feb 2009 18:41:54 +0100 Subject: [PATCH] Assign copyright to horde. Use autoloader. Split News class into driver based class --- news/add.php | 14 +- news/browse.php | 7 +- news/cloud.php | 6 +- news/content.php | 8 +- news/content_edit.php | 6 +- news/delete.php | 15 +- news/delete_file.php | 6 +- news/diff.php | 6 +- news/edit.php | 7 +- news/feed.php | 6 +- news/files.php | 6 +- news/index.php | 6 +- news/lib/Categories.php | 2 +- news/lib/News.php | 711 ++---------------------------------- news/lib/TagCloud.php | 7 +- news/lib/View.php | 2 +- news/lib/api.php | 0 news/lib/base.php | 11 +- news/mail.php | 6 +- news/news.php | 8 +- news/note.php | 8 +- news/pdf.php | 8 +- news/print.php | 6 +- news/reads.php | 6 +- news/search.php | 13 +- news/templates/common-header.inc | 0 news/templates/edit/row.php | 2 +- news/templates/menu.inc | 0 news/templates/news/attachments.php | 2 +- news/templates/news/info.php | 4 +- news/templates/news/parents.php | 2 +- news/trackback.php | 5 +- 32 files changed, 161 insertions(+), 735 deletions(-) mode change 100755 => 100644 news/lib/Categories.php mode change 100755 => 100644 news/lib/News.php mode change 100755 => 100644 news/lib/View.php mode change 100755 => 100644 news/lib/api.php mode change 100755 => 100644 news/lib/base.php mode change 100755 => 100644 news/templates/common-header.inc mode change 100755 => 100644 news/templates/menu.inc diff --git a/news/add.php b/news/add.php index 161eb7e3c..7cd11b14c 100644 --- a/news/add.php +++ b/news/add.php @@ -4,7 +4,10 @@ * * $Id: add.php 1186 2009-01-21 10:24:00Z duck $ * - * Copyright Obala d.o.o. (www.obala.si) + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * * @author Duck * @package News @@ -124,7 +127,7 @@ if ($id) { $form->setSection('content', _("Content"), '', false); $form->addVariable(_("News content"), 'content', 'header', false); -$v = &$form->addVariable(_("Publish"), 'publish', 'datetime', true, false, false, $news->datetimeParams()); +$v = &$form->addVariable(_("Publish"), 'publish', 'datetime', true, false, false, News::datetimeParams()); $v->setDefault(date('Y-m-d H:i:s')); $form->addVariable(_("Primary category"), 'category1', 'enum', true, false, false, array($news_cat->getEnum(), _("-- select --"))); @@ -489,9 +492,12 @@ if ($form->validate()) { } } if ($uploaded) { - $news->write_db->query('UPDATE ' . $news->prefix . ' SET attachments = ? WHERE id = ?', array(1, $id)); + $result = $news->write_db->query('UPDATE ' . $news->prefix . ' SET attachments = ? WHERE id = ?', array(1, $id)); + if ($result instanceof PEAR_Error) { + $notification->push($result->getMessage(), 'horde.warning'); + } } - } + } // Comments if (isset($info['disable_comments']) && $info['disable_comments']) { diff --git a/news/browse.php b/news/browse.php index 7171c1372..4f8fd5fac 100644 --- a/news/browse.php +++ b/news/browse.php @@ -4,13 +4,16 @@ * * $Id: browse.php 1179 2009-01-20 13:19:34Z duck $ * - * Copyright Obala d.o.o. (www.obala.si) + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * * @author Duck * @package News */ + require_once dirname(__FILE__) . '/lib/base.php'; -require_once NEWS_BASE . '/lib/Forms/Search.php'; // Default vars $title = _("Browse"); diff --git a/news/cloud.php b/news/cloud.php index db35a8000..28c071f23 100644 --- a/news/cloud.php +++ b/news/cloud.php @@ -2,11 +2,15 @@ /** * $Id: index.php 31 2007-12-13 14:33:33Z duck $ * - * Copyright Obala d.o.o. (www.obala.si) + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * * @author Duck * @package News */ + require_once dirname(__FILE__) . '/lib/base.php'; $cloud = $news->getCloud(); diff --git a/news/content.php b/news/content.php index 8bcc84785..96f0ddae1 100644 --- a/news/content.php +++ b/news/content.php @@ -2,13 +2,15 @@ /** * $Id: content.php 1162 2009-01-14 11:00:29Z duck $ * - * Copyright 2007 The Horde Project(http://www.horde.org/) + * Copyright 2009 The Horde Project (http://www.horde.org/) * - * See the enclosed file COPYING for license information(GPL). If you + * See the enclosed file COPYING for license information (GPL). If you * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * - * @author Duck + * @author Duck + * @package News */ + require_once dirname(__FILE__) . '/lib/base.php'; // Default layout. diff --git a/news/content_edit.php b/news/content_edit.php index 75895a106..75255f46b 100644 --- a/news/content_edit.php +++ b/news/content_edit.php @@ -2,13 +2,15 @@ /** * $Id: content_edit.php 803 2008-08-27 08:29:20Z duck $ * - * $Id: content_edit.php 803 2008-08-27 08:29:20Z duck $ + * Copyright 2009 The Horde Project (http://www.horde.org/) * - * Copyright Obala d.o.o. (www.obala.si) + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * * @author Duck * @package News */ + require_once dirname(__FILE__) . '/lib/base.php'; // Instantiate the blocks objects. diff --git a/news/delete.php b/news/delete.php index bc17cdfa5..2694d308d 100644 --- a/news/delete.php +++ b/news/delete.php @@ -4,11 +4,15 @@ * * $Id: delete.php 1184 2009-01-21 09:12:20Z duck $ * - * Copyright Obala d.o.o. (www.obala.si) + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * * @author Duck * @package News */ + require_once dirname(__FILE__) . '/lib/base.php'; require_once 'Horde/Variables.php'; @@ -34,10 +38,13 @@ if ($form->validate()) { if (Util::getFormData('submitbutton') == _("Remove")) { // Delete attachment - $sql = 'SELECT filename FROM ' . $news->prefix . '_attachment WHERE id = ?'; + $sql = 'SELECT file_id FROM ' . $news->prefix . '_files WHERE news_id = ?'; $files = $news->db->getCol($sql, 0, array($id)); foreach ($files as $file) { - unlink($conf['attributes']['attachments'] . $file); + $result = News::deleteFile($file_id); + if ($result instanceof PEAR_Error) { + $notification->push($result); + } } // Delete image and gallery @@ -61,7 +68,7 @@ if ($form->validate()) { $news->write_db->query('DELETE FROM ' . $news->prefix . '_version WHERE id = ?', array($id)); $news->write_db->query('DELETE FROM ' . $news->prefix . '_body WHERE id = ?', array($id)); $news->write_db->query('DELETE FROM ' . $news->prefix . '_user_reads WHERE id = ?', array($id)); - $news->write_db->query('DELETE FROM ' . $news->prefix . '_attachment WHERE id=?', array($id)); + $news->write_db->query('DELETE FROM ' . $news->prefix . '_files WHERE id = ?', array($id)); // Delete forum if ($registry->hasMethod('forums/deleteForum')) { diff --git a/news/delete_file.php b/news/delete_file.php index 93e8d0497..8c5bbf530 100644 --- a/news/delete_file.php +++ b/news/delete_file.php @@ -4,11 +4,15 @@ * * $Id: delete_file.php 1186 2009-01-21 10:24:00Z duck $ * - * Copyright Obala d.o.o. (www.obala.si) + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * * @author Duck * @package News */ + require_once dirname(__FILE__) . '/lib/base.php'; require_once 'Horde/Variables.php'; diff --git a/news/diff.php b/news/diff.php index 9ae454b40..86eac00c1 100644 --- a/news/diff.php +++ b/news/diff.php @@ -4,11 +4,15 @@ * * $Id: diff.php 803 2008-08-27 08:29:20Z duck $ * - * Copyright Obala d.o.o. (www.obala.si) + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * * @author Duck * @package News */ + require_once dirname(__FILE__) . '/lib/base.php'; $title = _("Diff"); diff --git a/news/edit.php b/news/edit.php index 980eb9c50..c558738cc 100644 --- a/news/edit.php +++ b/news/edit.php @@ -4,13 +4,16 @@ * * $Id: edit.php 1188 2009-01-21 10:33:56Z duck $ * - * Copyright Obala d.o.o. (www.obala.si) + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * * @author Duck * @package News */ + require_once dirname(__FILE__) . '/lib/base.php'; -require_once NEWS_BASE . '/lib/Forms/Search.php'; // redirect if not an admin $allowed_cats = $news_cat->getAllowed(PERMS_DELETE); diff --git a/news/feed.php b/news/feed.php index 0922e330a..b88e55ecd 100644 --- a/news/feed.php +++ b/news/feed.php @@ -4,11 +4,15 @@ * * $Id: feed.php 1179 2009-01-20 13:19:34Z duck $ * - * Copyright Obala d.o.o. (www.obala.si) + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * * @author Duck * @package News */ + require_once dirname(__FILE__) . '/lib/base.php'; function _getStories($feed_id) diff --git a/news/files.php b/news/files.php index b54fa0a2e..58a135c2e 100644 --- a/news/files.php +++ b/news/files.php @@ -4,11 +4,15 @@ * * $Id: files.php 1241 2009-01-29 23:27:58Z duck $ * - * Copyright Obala d.o.o. (www.obala.si) + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * * @author Duck * @package News */ + $no_compress = true; require_once dirname(__FILE__) . '/lib/base.php'; diff --git a/news/index.php b/news/index.php index 9cc3b6569..7b34d04d5 100644 --- a/news/index.php +++ b/news/index.php @@ -1,9 +1,11 @@ * @package News diff --git a/news/lib/Categories.php b/news/lib/Categories.php old mode 100755 new mode 100644 index 015f57f35..07baa8e4a --- a/news/lib/Categories.php +++ b/news/lib/Categories.php @@ -1,6 +1,6 @@ * @package News @@ -18,44 +21,6 @@ class News { const VFS_PATH = '.horde/news'; /** - * Hash containing connection parameters. - * - * @var array - */ - private $_params = array(); - - /** - * Handle for the current database connection. - * - * @var DB - */ - public $db; - - /** - * Handle for the current database connection, used for writing. Defaults - * to the same handle as $db if a separate write database is not required. - * - * @var DB - */ - public $write_db; - - /** - * Handle for the tables prefix. - * - * @var prefix - */ - public $prefix = 'news'; - - /** - * Constructor - */ - public function __construct() - { - $this->_params = Horde::getDriverConfig('storage', 'sql'); - $this->_connect(); - } - - /** * Returns the current language * * @return string The current language. @@ -123,7 +88,7 @@ class News { * * @param string The generated URL */ - function getUrlFor($controller, $data, $full = false, $append_session = 0) + static public function getUrlFor($controller, $data, $full = false, $append_session = 0) { switch ($controller) { @@ -188,6 +153,31 @@ class News { } /** + * Formats time according to user preferences. + * + * @param int $timestamp Message timestamp. + * + * @return string Formatted date. + */ + static public function dateFormat($timestamp) + { + static $df, $tf; + + if ($df === null) { + $df = $GLOBALS['prefs']->getValue('date_format'); + $tf = $GLOBALS['prefs']->getValue('twentyFour'); + } + + if (is_string($timestamp)) { + $timestamp = strtotime($timestamp); + } + + return strftime($df, $timestamp) + . ' ' + . (date($tf ? 'G:i' : 'g:ia', $timestamp)); + } + + /** * Format file size * * @param int $id News ID @@ -196,7 +186,7 @@ class News { */ public function format_attached($id) { - $files = $this->getFiles($id); + $files = $GLOBALS['news']->getFiles($id); if (empty($files)) { return ''; } @@ -423,30 +413,7 @@ class News { return $images; } - /** - * Formats time according to user preferences. - * - * @param int $timestamp Message timestamp. - * - * @return string Formatted date. - */ - static public function dateFormat($timestamp) - { - static $df, $tf; - if ($df === null) { - $df = $GLOBALS['prefs']->getValue('date_format'); - $tf = $GLOBALS['prefs']->getValue('twentyFour'); - } - - if (is_string($timestamp)) { - $timestamp = strtotime($timestamp); - } - - return strftime($df, $timestamp) - . ' ' - . (date($tf ? 'G:i' : 'g:ia', $timestamp)); - } /** * Fomates time accoring to user prefs @@ -460,7 +427,7 @@ class News { static $params; if (!is_array($params)) { - $sql = 'SELECT MIN(YEAR(publish)) FROM ' . $this->prefix; + $sql = 'SELECT MIN(YEAR(publish)) FROM ' . $GLOBALS['news']->prefix; $params = array('start_year' => $GLOBALS['news']->db->getOne($sql), 'end_year' => date('Y') + 1, 'picker' => true, @@ -512,618 +479,6 @@ class News { } /** - * Updates schedul comments counter - * - * @param int $id schedul id - * - * @return true on succes PEAR_Error on failure - */ - public function updateComments($id, $count) - { - return $this->write_db->query('UPDATE ' . $this->prefix . ' SET comments = ? WHERE id = ?', array($count, $id)); - } - - /** - * Get news - * - * @param int $news news id - * - * @return true on succes PEAR_Error on failure - */ - public function get($id) - { - // Admins bypass the cache (can read nonpublished and locked news) - if (!Auth::isAdmin('news:admin')) { - $key = 'news_' . self::getLang() . '_' . $id; - $data = $GLOBALS['cache']->get($key, $GLOBALS['conf']['cache']['default_lifetime']); - if ($data) { - return unserialize($data); - } - } - - $query = 'SELECT n.publish, n.user, n.source, n.sourcelink, n.category1, n.parents, ' . - ' n.category2, n.attachments, n.picture, n.comments, n.gallery, n.sponsored, ' . - ' l.title, l.content, l.picture_comment, l.tags, n.selling, n.trackbacks, n.threads, ' . - ' n.form_id, n.form_ttl FROM ' . $this->prefix . ' AS n, ' . $this->prefix . '_body AS l ' . - ' WHERE n.id = ? AND n.id=l.id AND l.lang = ?'; - - /** TODO Allow for now to allow static linked news, but not shown in list - if (!Auth::isAdmin('news:admin')) { - $query .= ' AND n.status = ' . self::CONFIRMED; - } - */ - - $data = $this->db->getRow($query, array($id, self::getLang()), DB_FETCHMODE_ASSOC); - if ($data instanceof PEAR_Error) { - return $data; - } - - if (empty($data)) { - return PEAR::raiseError(sprintf(_("There requested news %s don't exist."), $id)); - } - - /* Get talks backs */ - if ($data['trackbacks']) { - $sql = 'SELECT excerpt, created, title, url, blog_name FROM ' . $this->prefix . '_trackback WHERE id = ?'; - $data['trackback'] = $this->db->getAll($sql, array($id), DB_FETCHMODE_ASSOC); - if ($data['trackback'] instanceof PEAR_Error) { - return $data['trackback']; - } - } - - /* Get parents */ - if ($data['parents']) { - $sql = 'SELECT n.id, n.publish, n.comments, l.title ' . - ' FROM ' . $this->prefix . ' AS n, ' . $this->prefix . '_body AS l ' . - ' WHERE n.id IN (' . $data['parents'] . ') AND n.id = l.id AND l.lang = ?'; - $data['parents'] = $this->db->getAssoc($sql, false, array(self::getLang()), DB_FETCHMODE_ASSOC); - if ($data['parents'] instanceof PEAR_Error) { - return $data['parents']; - } - } - - /* Get threads */ - if ($data['threads']) { - $sql = 'SELECT message_id, forum_id, message_subject, message_seq ' . - ' FROM agora_messages WHERE message_id IN (' . $data['threads'] . ')'; - $data['threads'] = $this->db->getAssoc($sql, false, null, DB_FETCHMODE_ASSOC); - if ($data['threads'] instanceof PEAR_Error) { - return $data['threads']; - } - } - - if (!Auth::isAdmin('news:admin')) { - $GLOBALS['cache']->set($key, serialize($data)); - } - - return $data; - } - - /** - * Get news attached files - * - * @param int $news_id news id - * @param string $news_lang news language - * - * @return true on succes PEAR_Error on failure - */ - public function getFiles($news_id, $news_lang = null) - { - if (is_null($news_lang)) { - $news_lang = self::getLang(); - } - - $sql = 'SELECT file_id, news_id, news_lang, file_name, file_size, file_type FROM ' . $this->prefix . '_files' - . ' WHERE news_id = ? AND news_lang = ?'; - - return $this->db->getAll($sql, array($news_id, $news_lang), DB_FETCHMODE_ASSOC); - } - - /** - * Get version - * - * @param intiger $id news id - * @param array $info array with all news info - * - * @return result of the insert - */ - public function getVerison($id, $version) - { - $sql = 'SELECT id, created, user_uid, content FROM ' . $this->prefix . '_versions WHERE id = ? AND version = ?'; - $result = $this->db->getRow($sql, array($id, $version), DB_FETCHMODE_ASSOC); - $result['content'] = unserialize($result['content']); - return $result; - } - - /** - * Get versions - * - * @param intiger $id news id - * @param array $info array with all news info - * - * @return result of the insert - */ - public function getVerisons($id) - { - $sql = 'SELECT version, created, user_uid, content, action FROM ' . $this->prefix . '_versions WHERE id = ? ORDER BY version DESC'; - return $this->db->getAll($sql, array($id), DB_FETCHMODE_ASSOC); - } - - /** - * Logs a news view. - * - * @return boolean True, if the view was logged, false if the message was aleredy seen - */ - function logView($id) - { - if ($GLOBALS['browser']->isRobot()) { - exit; - } - - /* We already read this story? */ - if (isset($_COOKIE['news_viewed_news']) && - strpos($_COOKIE['news_viewed_news'], ':' . $id . '|') !== false) { - return false; - } - - /* Rembember when we see a story */ - if (!isset($_COOKIE['news_viewed_news'])) { - $_COOKIE['news_viewed_news'] = ':'; - } - $_COOKIE['news_viewed_news'] .= $id . '|' . $_SERVER['REQUEST_TIME'] . ':'; - - setcookie('news_viewed_news', $_COOKIE['news_viewed_news'], $_SERVER['REQUEST_TIME'] + 22896000, $GLOBALS['conf']['cookie']['path'], - $GLOBALS['conf']['cookie']['domain'], $GLOBALS['conf']['use_ssl'] == 1 ? 1 : 0); - - /* Update the count */ - $sql = 'UPDATE ' . $this->prefix . ' SET view_count = view_count + 1 WHERE id = ?'; - $result = $this->write_db->query($sql, array($id)); - if ($result instanceof PEAR_Error) { - return $result; - } - - /* Log it */ - $sql = 'INSERT INTO ' . $this->prefix . '_user_reads (id,user,ip,useragent,readdate) VALUES (?,?,?,?,NOW())'; - $result = $this->write_db->query($sql, array($id,Auth::getAuth(),$_SERVER['REMOTE_ADDR'],$_SERVER["HTTP_USER_AGENT"])); - if ($result instanceof PEAR_Error) { - return $result; - } - - return true; - } - - /** - * Remove from shop recursively by category ID: categories, articles, stocks and images - * - * @param mixed int Category ID - * - * @return mixed TRUE or PEAR error - */ - public function removeByCategory($cid) - { - /*vse v kategoriji in pol delete povsot */ - } - - /** - * Attach a trackback - */ - public function saveTrackback($id, $title, $url, $excerpt, $blog_name, $trackback_url) - { - $sql = 'SELECT COUNT(*) FROM ' . $this->prefix . '_trackback WHERE id = ? AND url = ?'; - $result = $this->db->getOne($sql, array($id, $url)); - if ($result > 0) { - return PEAR::raiseError(sprintf(_("URL already trackbacked: %s"), $url)); - } - - $params = array('id' => $id, - 'title' => $title, - 'url' => $url, - 'excerpt' => $excerpt, - 'blog_name' => $blog_name, - 'created' => date('Y-m-d H:i:s')); - - $sql = 'INSERT INTO ' . $this->prefix . '_trackback (' . implode(',', array_keys($params)) . ') VALUES (?, ?, ?, ?, ?, ?)'; - $result = $this->write_db->query($sql, $params); - if ($result instanceof PEAR_Error) { - return $result; - } - - /* Update trackback count */ - $GLOBALS['cache']->expire('news_' . self::getLang() . '_' . $id); - return $this->write_db->query('UPDATE ' . $this->prefix . ' SET trackbacks = trackbacks + 1 WHERE id = ?', array($id)); - } - - /** - * Delete a source - * - * @param integer $id The source id to delete. - * - * @return boolean - */ - public function deleteSource($id) - { - $GLOBALS['cache']->expire('newsSources'); - $this->deleteImage($id, 'sources'); - $sql = 'DELETE FROM ' . $this->prefix . '_sources WHERE sources_id = ?'; - return $this->write_db->query($sql, array($id)); - } - - /** - * Fetches sources list - * - * @return array An array containing all sources names - */ - public function getSources($flat = false) - { - $sources = $GLOBALS['cache']->get('newsSources'); - if (empty($sources)) { - $sql = 'SELECT source_id, source_name, source_url FROM ' . $this->prefix . '_sources ORDER BY source_name ASC'; - $sources = $this->db->getAssoc($sql, true, array(), DB_FETCHMODE_ASSOC); - $GLOBALS['cache']->set('newsSources', serialize($sources)); - } else { - $sources = unserialize($sources); - } - - if (!$flat) { - foreach ($sources as $source_id => $source) { - $sources[$source_id] = $source['source_name']; - } - } - - return $sources; - } - - /** - * Save a source data into the backend from edit form. - * - * @param array $info The source data to save. - * - * @return mixed PEAR error. - */ - public function saveSource($info) - { - /* Update/Insert source. */ - if (!empty($info['source_id'])) { - $result = $this->_updateSource($info['source_id'], $info); - if ($result instanceof PEAR_Error) { - return $result; - } - } else { - $info['source_id'] = $this->_insertSource($info); - if ($info['source_id'] instanceof PEAR_Error) { - return $info['source_id']; - } - } - - /* If image uploaded save to backend. */ - if (!empty($info['source_image']['name'])) { - $image = $this->_saveImage($info['source_id'], $info['source_image']['file'], 'sources', $info['source_image_resize']); - if ($image instanceof PEAR_Error) { - return $image; - } - - $sql = 'UPDATE ' . $this->prefix . '_sources SET source_image = ? WHERE source_id = ?'; - $this->write_db->query($sql, array(1, $info['source_id'])); - } - - $GLOBALS['cache']->expire('newsSources'); - return $info['source_id']; - } - - /** - * Insert source data. - * - * @param mixed $data The source data to insert. - * - * @return array Inserted ID or PEAR error. - */ - private function _insertSource($data) - { - $new_id = $this->write_db->nextId('news_sources'); - - $sql = 'INSERT INTO ' . $this->prefix . '_sources' . - ' (source_id, source_name, source_url)' . - ' VALUES (?, ?, ?)'; - $values = array($new_id, - $data['source_name'], - $data['source_url']); - - $source = $this->write_db->query($sql, $values); - if ($source instanceof PEAR_Error) { - Horde::logMessage($source, __FILE__, __LINE__, PEAR_LOG_ERR); - return $source; - } - - return $new_id; - } - - /** - * Update source data. - * - * @param integer $source_id The source id to update. - * @param array $data The source data to update. - * - * @return array NULL or PEAR error. - */ - private function _updateSource($source_id, $data) - { - $sql = 'UPDATE ' . $this->prefix . '_sources' . - ' SET source_name = ?, source_url = ?' . - ' WHERE source_id = ?'; - $values = array($data['source_name'], - $data['source_url'], - $source_id); - - $source = $this->write_db->query($sql, $values); - if ($source instanceof PEAR_Error) { - Horde::logMessage($source, __FILE__, __LINE__, PEAR_LOG_ERR); - return $source; - } - } - - /** - * Attempts to open a persistent connection to the SQL server. - * - * @return boolean True on success; exits (Horde::fatal()) on error. - */ - private function _connect() - { - Horde::assertDriverConfig($this->_params, 'storage', - array('phptype', 'charset')); - - if (!isset($this->_params['database'])) { - $this->_params['database'] = ''; - } - if (!isset($this->_params['username'])) { - $this->_params['username'] = ''; - } - if (!isset($this->_params['hostspec'])) { - $this->_params['hostspec'] = ''; - } - if (isset($this->_params['prefix'])) { - $this->prefix = $this->_params['prefix']; - } - - /* Connect to the SQL server using the supplied parameters. */ - require_once 'DB.php'; - $this->write_db = &DB::connect($this->_params, - array('persistent' => !empty($this->_params['persistent']))); - if ($this->write_db instanceof PEAR_Error) { - Horde::fatal($this->write_db, __FILE__, __LINE__); - } - - // Set DB portability options. - switch ($this->write_db->phptype) { - case 'mssql': - $this->write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $this->write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } - - /* Check if we need to set up the read DB connection seperately. */ - if (!empty($this->_params['splitread'])) { - $params = array_merge($this->_params, $this->_params['read']); - $this->db = &DB::connect($params, - array('persistent' => !empty($params['persistent']))); - if ($this->db instanceof PEAR_Error) { - Horde::fatal($this->db, __FILE__, __LINE__); - } - - // Set DB portability options. - switch ($this->db->phptype) { - case 'mssql': - $this->db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM); - break; - default: - $this->db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS); - } - - } else { - /* Default to the same DB handle for the writer too. */ - $this->db =& $this->write_db; - } - - return true; - } - - /** - * Build whare search - */ - public function buildQuery($perms = PERMS_READ, $criteria = array()) - { - static $parts; - - $id = serialize($criteria); - if (isset($parts[$id])) { - return $parts[$id]; - } - - $sql = 'FROM ' . $GLOBALS['news']->prefix . ' AS n, ' . $GLOBALS['news']->prefix . '_body AS l ' - . ' WHERE n.id = l.id AND l.lang = ?'; - $params = array('_lang' => NLS::select()); - - if ($perms == PERMS_READ) { - $sql .= ' AND n.publish <= ? '; - $params['_perms'] = date('Y-m-d H:i:s'); - $sql .= ' AND n.status = ? '; - $params['_status'] = self::CONFIRMED; - } - - if (empty($criteria)) { - $parts[$id] = array($sql, $params); - return $parts[$id]; - } - - /* check status */ - if (isset($criteria['status'])) { - $sql .= ' AND n.status = ?'; - $params['status'] = $criteria['status']; - } - - /* check status */ - if (isset($criteria['source'])) { - $sql .= ' AND n.source = ?'; - $params['source'] = $criteria['source']; - } - - /* get category */ - if (isset($criteria['category'])) { - $sql .= ' AND (n.category1 = ? OR n.category2 = ?)'; - $params['category'] = $criteria['category']; - $params['_category'] = $criteria['category']; - } - - /* seaching for a pericolar word */ - if (isset($criteria['word'])) { - $sql .= ' AND (l.title LIKE ? OR l.content LIKE ? OR l.tags LIKE ?)'; - $params['word'] = '%' . $criteria['word'] . '%'; - $params['_word'] = '%' . $criteria['word'] . '%'; - $params['tags'] = '%' . $criteria['word'] . '%'; - } - - /* submitter */ - if (isset($criteria['user'])) { - $sql .= ' AND n.user = ? '; - $params['user'] = $criteria['user']; - } - - /* editor */ - if (isset($criteria['editor'])) { - $sql .= ' AND n.editor = ? '; - $params['editor'] = $criteria['editor']; - } - - /* publish time */ - if (isset($criteria['published_to'])) { - $sql .= ' AND n.publish <= ? '; - $params['published_to'] = $criteria['published_to']; - } - - if (isset($criteria['published_from'])) { - $sql .= ' AND n.publish >= ? '; - $params['published_from'] = $criteria['published_from']; - } - - $parts[$id] = array($sql, $params); - - return $parts[$id]; - } - - /** - * Count news - * - * @param array $criteria Filter parameter - - * @param int $perms Permissions filter - * - * @return Nimber of news - */ - public function countNews($criteria = array(), $perms = PERMS_READ) - { - $binds = $this->buildQuery($perms, $criteria); - $binds[0] = 'SELECT COUNT(*) ' . $binds[0]; - - return $this->db->getOne($binds[0], $binds[1]); - } - - /** - * List news - * - * @param array $criteria Filter parameter - * @param int $from Offset - * @param int $count Limit rows - * @param int $perms Permissions filter - * - * @return array of news data - */ - public function listNews($criteria = array(), $from = 0, $count = 0, $perms = PERMS_READ) - { - $binds = $this->buildQuery($perms, $criteria); - - if (!isset($criteria['sort_by'])) { - $criteria['sort_by'] = 'n.publish'; - } - if (!isset($criteria['sort_dir'])) { - $criteria['sort_dir'] = 'DESC'; - } - - $binds[0] = 'SELECT n.id, n.publish, n.user, n.category1, n.category2, n.comments, ' - . ' n.picture, n.chars, l.title, l.abbreviation ' . $binds[0] - . ' ORDER BY ' . $criteria['sort_by'] - . ' ' . $criteria['sort_dir']; - - if ($count) { - $binds[0] = $this->db->modifyLimitQuery($binds[0], $from, $count); - } - - return $this->db->getAll($binds[0], $binds[1], DB_FETCHMODE_ASSOC); - } - - /** - * Construct tag cloud - * - * @param boolean $minimize Minimize tag cloud - * (remove 1 length strings, and single occurrence) - * - * @return mixed The HTML for the tag cloud | PEAR_Error - */ - public function getCloud($minimize = false) - { - $cache_key = 'news_cloud_' . $minimize; - $cloud = $GLOBALS['cache']->get($cache_key, $GLOBALS['conf']['cache']['default_lifetime']); - if ($cloud) { - // return $cloud; - } - - $sql = 'SELECT l.tags, n.publish FROM ' . $this->prefix . '_body AS l, ' - . $this->prefix . ' AS n WHERE l.lang = ? AND n.id = l.id AND n.status = ? ORDER BY n.publish DESC LIMIT 0, ' - . ($minimize ? '100' : '500'); - - $result = $this->db->query($sql, array(NLS::select(), self::CONFIRMED)); - if ($result instanceof PEAR_Error) { - return $result; - } - - $tags_elemets = array(); - while ($news = $result->fetchRow(DB_FETCHMODE_ASSOC)) { - foreach (explode(' ', $news['tags']) as $tag) { - if ($minimize && strlen($tag) < 2) { - continue; - } - $tags_elemets[$tag][] = strtotime($news['publish']); - } - } - - if ($minimize) { - foreach ($tags_elemets as $tag => $content) { - if (count($content) == 1) { - unset($tags_elemets[$tag]); - } - } - } - - if (empty($tags_elemets)) { - return ''; - } - - $i = 0; - require_once dirname(__FILE__) . '/TagCloud.php'; - $tags = new Oscar_TagCloud(); - $tag_link = Horde::applicationUrl('search.php'); - foreach ($tags_elemets as $tag => $time) { - sort($time); - $tags->addElement($tag, Util::addParameter($tag_link, array('word' => $tag)), - count($tags_elemets[$tag]), $time[0]); - } - - $cloud = $tags->buildHTML(); - $GLOBALS['cache']->set($cache_key, $cloud); - - return $cloud; - } - - /** * Build News's list of menu articles */ static public function getMenu($returnType = 'object') diff --git a/news/lib/TagCloud.php b/news/lib/TagCloud.php index afb1c1ad3..1d1e86806 100644 --- a/news/lib/TagCloud.php +++ b/news/lib/TagCloud.php @@ -2,7 +2,12 @@ /** * Extend Horde TagCloud to allow complete css font sizes * - * Copyright Obala d.o.o. (www.obala.si) + * $Id: News.php 1263 2009-02-01 23:25:56Z duck $ + * + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license inion (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * * @author Duck * @package News diff --git a/news/lib/View.php b/news/lib/View.php old mode 100755 new mode 100644 index 137cab3ba..193e9db3f --- a/news/lib/View.php +++ b/news/lib/View.php @@ -55,7 +55,7 @@ class News_View extends Horde_View { * * @param string $tags Video's tags */ - function getTagsLinks($tags) + public function getTagsLinks($tags) { if (empty($tags)) { return ''; diff --git a/news/lib/api.php b/news/lib/api.php old mode 100755 new mode 100644 diff --git a/news/lib/base.php b/news/lib/base.php old mode 100755 new mode 100644 index 38c87e00a..c595d2239 --- a/news/lib/base.php +++ b/news/lib/base.php @@ -22,6 +22,10 @@ if (!defined('HORDE_BASE')) { // Load the Horde Framework core, and set up inclusion paths. require_once HORDE_BASE . '/lib/core.php'; +$news_dir = dirname(__FILE__); +Horde_Autoloader::addClassPath($news_dir); +Horde_Autoloader::addClassPattern('/^News/', $news_dir); + // Registry. $registry = &Registry::singleton(); if (($pushed = $registry->pushApp('news', !defined('AUTH_HANDLER'))) instanceof PEAR_Error) { @@ -46,13 +50,8 @@ if (!defined('NEWS_BASE')) { $GLOBALS['cache'] = &Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver'])); -// News base library -require_once NEWS_BASE . '/lib/News.php'; -require_once NEWS_BASE . '/lib/Categories.php'; -require_once NEWS_BASE . '/lib/View.php'; - // Set up News drivers. -$GLOBALS['news'] = new News(); +$GLOBALS['news'] = News_Driver::factory(); $GLOBALS['news_cat'] = new News_Categories(); // Start compression. diff --git a/news/mail.php b/news/mail.php index d82d806ac..2ae563cf7 100644 --- a/news/mail.php +++ b/news/mail.php @@ -4,11 +4,15 @@ * * $Id: mail.php 1174 2009-01-19 15:11:03Z duck $ * - * Copyright Obala d.o.o. (www.obala.si) + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * * @author Duck * @package News */ + require_once dirname(__FILE__) . '/lib/base.php'; $id = Util::getFormData('id'); diff --git a/news/news.php b/news/news.php index 4c49b74e3..da83e76e1 100644 --- a/news/news.php +++ b/news/news.php @@ -4,11 +4,15 @@ * * $Id: news.php 1190 2009-01-21 16:10:50Z duck $ * - * Copyright Obala d.o.o. (www.obala.si) + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * * @author Duck * @package News */ + require_once dirname(__FILE__) . '/lib/base.php'; $id = Util::getFormData('id'); @@ -33,7 +37,7 @@ if (($version = Util::getFormData('version')) !== null) { $row['content'] = $version_data['content'][NLS::select()]['content']; $row['title'] = $version_data['content'][NLS::select()]['title'] . ' (v.' . $version . _(" by ") . $version_data['user_uid'] . - ' @ ' . $news->dateFormat($version_data['created']) . ')'; + ' @ ' . News::dateFormat($version_data['created']) . ')'; } } else { $news->logView($id); diff --git a/news/note.php b/news/note.php index d5fe2f07f..2383d62b0 100644 --- a/news/note.php +++ b/news/note.php @@ -4,11 +4,15 @@ * * $Id: note.php 1241 2009-01-29 23:27:58Z duck $ * - * Copyright Obala d.o.o. (www.obala.si) + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * * @author Duck * @package News */ + require_once dirname(__FILE__) . '/lib/base.php'; $id = Util::getFormData('id'); @@ -20,7 +24,7 @@ if ($row instanceof PEAR_Error) { } $body = $row['title'] . "\n\n" - . _("On") . ': ' . $news->dateFormat($row['publish']) . "\n" + . _("On") . ': ' . News::dateFormat($row['publish']) . "\n" . _("Link") . ': ' . News::getUrlFor('news', $id) . "\n\n" . strip_tags($row['content']); diff --git a/news/pdf.php b/news/pdf.php index b60928dd8..fda14f6a8 100644 --- a/news/pdf.php +++ b/news/pdf.php @@ -4,11 +4,15 @@ * * $Id: pdf.php 1191 2009-01-21 16:45:21Z duck $ * - * Copyright Obala d.o.o. (www.obala.si) + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * * @author Duck * @package News */ + $no_compress = true; require_once dirname(__FILE__) . '/lib/base.php'; @@ -47,7 +51,7 @@ $pdf->setFillColor('rgb', 200/255, 220/255, 255/255); $pdf->cell(0, 6, $row['title'], 0, 1, 'L', 1); $pdf->newLine(4); -$pdf->write(12, _("On") . ': ' . $news->dateFormat($row['publish']) . "\n"); +$pdf->write(12, _("On") . ': ' . News::dateFormat($row['publish']) . "\n"); $pdf->write(12, _("Link") . ': ' . News::getUrlFor('news', $id, true) . "\n\n", News::getUrlFor('news', $id, true)); $pdf->multiCell(0, 12, String::convertCharset(strip_tags($row['content']), NLS::getCharset(), 'UTF-8')); diff --git a/news/print.php b/news/print.php index efde21cf3..fca0961b4 100644 --- a/news/print.php +++ b/news/print.php @@ -4,11 +4,15 @@ * * $Id: print.php 803 2008-08-27 08:29:20Z duck $ * - * Copyright Obala d.o.o. (www.obala.si) + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * * @author Duck * @package News */ + require_once dirname(__FILE__) . '/lib/base.php'; $id = Util::getFormData('id'); diff --git a/news/reads.php b/news/reads.php index 6425f4f0e..11dc61aac 100644 --- a/news/reads.php +++ b/news/reads.php @@ -2,13 +2,15 @@ /** * News reads * - * $Id: reads.php 803 2008-08-27 08:29:20Z duck $ + * Copyright 2009 The Horde Project (http://www.horde.org/) * - * Copyright Obala d.o.o. (www.obala.si) + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * * @author Duck * @package News */ + require_once dirname(__FILE__) . '/lib/base.php'; if (!Auth::isAuthenticated()) { diff --git a/news/search.php b/news/search.php index fafa49be0..dfca090e0 100644 --- a/news/search.php +++ b/news/search.php @@ -2,15 +2,16 @@ /** * Search * - * $Id: search.php 889 2008-09-23 09:52:06Z duck $ + * Copyright 2009 The Horde Project (http://www.horde.org/) * - * Copyright Obala d.o.o. (www.obala.si) + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * * @author Duck * @package News */ + require_once dirname(__FILE__) . '/lib/base.php'; -require_once NEWS_BASE . '/lib/Forms/Search.php'; // Default vars $title = _("Browse"); @@ -37,11 +38,7 @@ if ($rows instanceof PEAR_Error) { exit; } -$vars = Variables::getDefaultVariables(); -$pager = new Horde_UI_Pager('news_page', - $vars, array('num' => $count, - 'url' => 'search.php', - 'perpage' => $per_page)); +$pager = News_Search::getPager($criteria, $count, 'search.php'); $pager->preserve($criteria); diff --git a/news/templates/common-header.inc b/news/templates/common-header.inc old mode 100755 new mode 100644 diff --git a/news/templates/edit/row.php b/news/templates/edit/row.php index 5cf999f76..20cf1ac9f 100644 --- a/news/templates/edit/row.php +++ b/news/templates/edit/row.php @@ -52,7 +52,7 @@ case News::LOCKED: } ?> -dateFormat($row['publish']) ?> +
' . $news->format_attached($id); + echo '

' . News::format_attached($id); } diff --git a/news/templates/news/info.php b/news/templates/news/info.php index 3bdcd13b2..2bb07a160 100644 --- a/news/templates/news/info.php +++ b/news/templates/news/info.php @@ -2,8 +2,8 @@ echo '
' . _("News data") . '
'; echo _("By") . ': ' . Horde::link(Util::addParameter($browse_url, 'user', $row['user'])) . $row['user'] . '
'; -echo _("On") . ': ' . Horde::link(Util::addParameter($browse_url, 'publish', $row['publish'])) . $news->dateFormat($row['publish']) . '
'; -echo _("Category") . ': ' . Horde::link(Util::addParameter($browse_url, 'cid', $row['category1'])) . $news_cat->getName($row['category1']) . '
'; +echo _("On") . ': ' . Horde::link(Util::addParameter($browse_url, 'publish', $row['publish'])) . News::dateFormat($row['publish']) . '
'; +echo _("Category") . ': ' . Horde::link(Util::addParameter($browse_url, 'cid', $row['category1'])) . $GLOBALS['news_cat']->getName($row['category1']) . '
'; $plain = preg_replace('/\s\s+/', ' ', trim(strip_tags($row['content']))); echo _("Chars") . ': ' . number_format(strlen($plain)) . '
'; diff --git a/news/templates/news/parents.php b/news/templates/news/parents.php index 0549cebdf..d4de7c162 100644 --- a/news/templates/news/parents.php +++ b/news/templates/news/parents.php @@ -4,7 +4,7 @@ if ($row['parents']) { echo _("Parents") . ':
    '; foreach ($row['parents'] as $parent_id => $data) { - echo '
  • ' . $news->dateFormat($data['publish']) . ' ' + echo '
  • ' . News::dateFormat($data['publish']) . ' ' . Horde::link(News::getUrlFor('news', $parent_id), _("Read")) . $data['title'] . ' (' . ($data['comments']> -1 ? $data['comments'] : 0) . ')'; } diff --git a/news/trackback.php b/news/trackback.php index 0bea179a5..0b454ce51 100644 --- a/news/trackback.php +++ b/news/trackback.php @@ -2,12 +2,15 @@ /** * $Id: trackback.php 803 2008-08-27 08:29:20Z duck $ * + * Copyright 2009 The Horde Project (http://www.horde.org/) * - * Copyright Obala d.o.o. (www.obala.si) + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * * @author Duck * @package News */ + define('AUTH_HANDLER', true); require_once dirname(__FILE__) . '/lib/base.php'; -- 2.11.0