[Feed-collector-svn] SF.net SVN: feed-collector: [77] trunk/class
Status: Beta
Brought to you by:
c167
|
From: <c1...@us...> - 2006-12-20 21:45:17
|
Revision: 77
http://feed-collector.svn.sourceforge.net/feed-collector/?rev=77&view=rev
Author: c167
Date: 2006-12-20 13:45:17 -0800 (Wed, 20 Dec 2006)
Log Message:
-----------
Modified Paths:
--------------
trunk/class/Feed_manager.php
trunk/class/Tag_manager.php
trunk/class/User_manager.php
Modified: trunk/class/Feed_manager.php
===================================================================
--- trunk/class/Feed_manager.php 2006-12-20 21:44:39 UTC (rev 76)
+++ trunk/class/Feed_manager.php 2006-12-20 21:45:17 UTC (rev 77)
@@ -39,6 +39,21 @@
################
/**
+ * Return the number of pages that have to be displayed
+ * @param Int $feedname The name of the feed
+ * @param Int $perPage How many feeds we should display per page
+ * @return Int
+ * @access public
+ */
+ public function getItemsMaxPages($feedname, $perPage = 30) {
+ $number = $this->stat_countItems($feedname);
+ if ($number <= $perPage) {
+ return 1;
+ }
+ return (int) ($number / $perPage) + 1;
+ }
+
+ /**
* Get items from a feed
*
* @param String $feedname The name of the feed
@@ -74,6 +89,39 @@
}
/**
+ * Get a block of items from a feed
+ *
+ * @param String $feedname The name of the feed
+ * @param Int $page The number of the page to get
+ * @param Int $count How many Items? default 30
+ * @return mixed
+ * @since 1.1 - 09.07.2006
+ * @version 1.2
+ * @access public
+ */
+ public function getItemsPerPage($feedname, $page = 1, $count = 30) {
+ $number_in_db = $this->stat_countItems($feedname);
+ if ($count > $number_in_db) {
+ $from = 0;
+ } else {
+ $from = $number_in_db - ($count * $page);
+ }
+ $feeds = $this->mdb->query("SELECT id,title,url,summary FROM f_$feedname GROUP BY id ASC LIMIT $from ,$count;");
+ if (PEAR :: isError($feeds)) {
+ return false;
+ }
+ $i = 0;
+ while ($row = $feeds->fetchRow()) {
+ $return[$i]['id'] = $row['id'];
+ $return[$i]['title'] = $row['title'];
+ $return[$i]['url'] = $row['url'];
+ $return[$i]['summary'] = $row['summary'];
+ $i++;
+ }
+ return $return;
+ }
+
+ /**
* Get items from a feed
*
* @param String $feedname The name of the feed
@@ -143,18 +191,19 @@
* @param int $count Feeds per Page
* @return int
*/
- public function getMaxPages($count = 30) {
+ public function getFeedsMaxPages($count = 30) {
$numberOfFeeds = $this->stat_countFeeds();
echo "a";
- if (($numberOfFeeds > $count) and ($numberOfFeeds < (2*$count))) {
+ if (($numberOfFeeds > $count) and ($numberOfFeeds < (2 * $count))) {
echo "b";
return 2;
- } elseif ($count <= $numberOfFeeds) {
+ }
+ elseif ($count <= $numberOfFeeds) {
echo "c";
return 1;
}
echo "d";
- return (int)($numberOfFeeds / $count);
+ return (int) ($numberOfFeeds / $count);
}
/**
@@ -251,7 +300,11 @@
else
return $query;
}
-
+
+ #############
+ # STATISTIC #
+ #############
+
/**
* STATISTIC
* Return the Number of feeds we have in our database
@@ -324,6 +377,10 @@
break;
case "RSS 2.0" :
return $this->mdb->queryOne("SELECT COUNT(*) FROM feeds WHERE feed_type = 'RSS 2.0';");
+ break;
+ case "RSS 1.0" :
+ return $this->mdb->queryOne("SELECT COUNT(*) FROM feeds WHERE feed_type = 'RSS 1.0';");
+ break;
}
}
Modified: trunk/class/Tag_manager.php
===================================================================
--- trunk/class/Tag_manager.php 2006-12-20 21:44:39 UTC (rev 76)
+++ trunk/class/Tag_manager.php 2006-12-20 21:45:17 UTC (rev 77)
@@ -5,7 +5,7 @@
* Created on 11.12.2006
*
* This file is used to
- * @since 64 - 11.12.2006
+ * @since 74 - 11.12.2006
* @author c167 <c1...@us...>
*/
@@ -17,7 +17,7 @@
* @since 1.1 - 09.07.2006
* @access protected
*/
- protected $mdb;
+ protected $db;
/**
* The standard-constructor
@@ -29,8 +29,8 @@
* @version 1.1
* @access public
*/
- public function __construct($mdb) {
- $this->mdb = $mdb;
+ public function __construct($db) {
+ $this->db = $db;
}
/**
@@ -42,7 +42,15 @@
* @access public
*/
public function addTag($tag, $by, $feed) {
-
+ $select = $this->db->queryOne("SELECT `tag` FROM `tags` WHERE tag = '$tag' AND feed = '$feed';");
+ if($select == $tag) {
+ return false;
+ }
+ $insert = $this->db->query("INSERT INTO `tags` ( `id` , `setBy` , `tag` , `feed` ) VALUES ( NULL , '$by', '$tag', '$feed');");
+ if(PEAR :: isError($insert)) {
+ return false;
+ }
+ return true;
}
/**
@@ -63,8 +71,34 @@
* @access public
*/
public function getTags($feed) {
-
+ $query = $this->db->query("SELECT tag FROM tags WHERE feed = '$feed';");
+ if(PEAR :: isError($query)) {
+ return false;
+ }
+ while($row = $query->fetchRow()) {
+ if(!isset($row['tag'])) {
+ return false;
+ }
+ $return[] = $row['tag'];
+ }
+ return $return;
}
+
+ /**
+ * Return all feeds that have a given tag
+ * @param String $tag The tag to search for
+ * @return mixed
+ * @access public
+ */
+ public function getFeedsByTag($tag) {
+ $query = $this->db->query("SELECT feed FROM tags WHERE tag = '$tag';");
+ if(PEAR :: isError($query)) {
+ return false;
+ }
+ while($row = $query->fetchRow()) {
+
+ }
+ }
/**
* Random number generator
Modified: trunk/class/User_manager.php
===================================================================
--- trunk/class/User_manager.php 2006-12-20 21:44:39 UTC (rev 76)
+++ trunk/class/User_manager.php 2006-12-20 21:45:17 UTC (rev 77)
@@ -18,38 +18,51 @@
/**
* LOGIN_WRONG_USERNAME
*/
-define('LOGIN_WRONG_USERNAME', 1);
+define('LOGIN_WRONG_VALUES', 1);
/**
* LOGIN_WRONG_PASSWD
*/
-define('LOGIN_WRONG_PASSWD', 2);
+define('LOGIN_INACTIVE', 2);
/**
- * LOGIN_NO_VALUES
+ * REGISTER_PASSWD_TOO_SHORT
*/
-define('LOGIN_NO_VALUES', 3);
+define('REGISTER_PASSWD_TOO_SHORT', 1);
/**
- * REGISTER_PASSWD_TOO_SHORT
+ * REGISTER_USERNAME_NOT_ALLOWED
*/
-define('REGISTER_PASSWD_TOO_SHORT', 1);
+define('REGISTER_USERNAME_NOT_ALLOWED', 2);
class User_Manager {
/**
* The database-object
*
* @var Object
- * @since 1.1 - 09.07.2006
* @access protected
*/
+ protected $mdb;
+
+
/**
+ * The userid
+ * @access protected
+ */
+ protected $uid = null;
+
+ /**
+ * The username
+ * @access protected
+ */
+ protected $username = null;
+
+ /**
* The standard-constructor
*
* @param Object $db The PEAR::MDB2
*
* @return void
- * @since 1.1 - 09.07.2006
* @version 1.1
* @access public
*/
@@ -145,22 +158,78 @@
* @access public
*/
public function loginUser($username, $passwd) {
- $query = $this->mdb->query("SELECT id,name,pass FROM users WHERE username = '$username';");
+ $query = $this->mdb->query("SELECT id,name,pass,state FROM users WHERE name = '$username';");
if (PEAR :: isError($query)) {
- $return['state'] = LOGIN_WRONG_USERNAME;
- return $return;
+ return array('state' => LOGIN_WRONG_VALUES);
}
$row = $query->fetchRow();
+ if($row['state'] == "inactive") {
+ return array('state' => LOGIN_INACTIVE);
+ }
if ($passwd == $row['pass']) {
+ $this->uid = $row['id'];
$return['state'] = LOGIN_SUCCESSFULL;
$return['id'] = $row['id'];
$return['username'] = $row['name'];
return $return;
} else {
return array (
- 'state' => LOGIN_WRONG_PASSWD
+ 'state' => LOGIN_WRONG_VALUES
);
}
}
+
+ /**
+ * Logs out a user
+ * @return boolean
+ */
+ public function logOut() {
+ if(is_null($this->uid)) {
+ return false;
+ }
+ $this->uid = null;
+ return true;
+ }
+
+ /**
+ * Sets the time of the users last action
+ * @return boolean
+ */
+ public function updateUserAction() {
+ if(is_null($this->uid)) {
+ return false;
+ }
+ $query = $this->mdb->query(sprintf("UPDATE `users` SET `last_action` = '%d' WHERE `users`.`ID` = %d LIMIT 1 ;", time(), $this->uid));
+ if(PEAR :: isError($query)) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * returns the time of the users last action
+ * @return int
+ */
+ public function getUserActionTime() {
+ if(is_null($this->uid)) {
+ return false;
+ }
+ $query = $this->mdb->queryOne(sprintf("SELECT last_action FROM users WHERE id= %d LIMIT 1;", $this->uid));
+ }
+
+ /**
+ * Returns the username
+ * @return String/boolean on error
+ */
+ public function getUsername() {
+ if(is_null($this->uid)) {
+ return false;
+ }
+ if(is_null($this->username)) {
+ $this->username = $this->mdb2->queryOne("SELECT name FROM users WHERE id = $this->uid");
+ }
+ return $this->username;
+
+ }
}
?>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|