Location: PHPKode > projects > Zzap > zzap/app/plugins/blog/blogModel.php
<?php 
/**
 * zzap group messaging / microblogging
 * 
 * Copyright (C) 2008 Dirk Ollmetzer
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * @package Zzap
 * @subpackage plugins
 * @author Dirk Ollmetzer <hide@address.com>
 * @copyright 2008 Dirk Ollmetzer
 * @version $Id: blogModel.php 148 2008-10-27 20:37:34Z dollmetzer $
 * @license GPLv3 http://www.gnu.org/copyleft/gpl.html
 */

/**
 * blog model
 * 
 * This model provides access to the data in the DB table 'pi_blog' und 'pi_blog_entry'.
 * 
 * @package Zzap
 * @subpackage plugins
 * @author Dirk Ollmetzer <hide@address.com>
 * @copyright 2008 Dirk Ollmetzer
 * @version $Id: blogModel.php 148 2008-10-27 20:37:34Z dollmetzer $
 * @license GPLv3 http://www.gnu.org/copyleft/gpl.html
 */
class blogModel
{

	/**
	 * Get a record from pi_blog for a defined user
	 *
	 * @param integer $userid ID of the user
	 *
	 * @return array Array with informations about the blog.
	 */
	public function getBlogByUser($userid) {
		
		$sql = "SELECT * FROM pi_blog WHERE userid=$userid";
		$query = mysql_query($sql) or die ("blogModel::getBlogByUser()\n$sql\n".mysql_error());
		$row = mysql_fetch_assoc($query);
		return $row;
		
	} /* getBlogByUser($userid) */
	
	
	
	/**
	 * Get a record from pi_blog for a defined URL
	 *
	 * @param string $url URL of the blog
	 *
	 * @return array Array with informations about the blog.
	 */
	public function getBlogByURL($url) {
		
		$sql = "SELECT * FROM pi_blog WHERE blogurl like '$url'";
		$query = mysql_query($sql) or die ("blogModel::getBlogByURL()\n$sql\n".mysql_error());
		$row = mysql_fetch_assoc($query);
		return $row;
		
	} /* getBlogByURL($url) */
	
	
	
	/**
	 * Save (insert or update) an entry into pi_blog table.
	 *
	 * @param integer $userid       ID of the user
	 * @param string  $blogtype     Abbreviation for the users blogsystem (e.g. 'wp' for wordpress, 's9y' for serendipity)
	 * @param string  $blogurl      URL of the Blog (without http:// or trailing slash)
	 * @param integer $announce     1 = receive article announcements from the Blog and process them as zzap message
	 * @param integer $replycomment 1 = send replies back to the blog as a comment
	 * @param integer $sendarticle  1 = publish a zzap message as a blog article via API
	 * @param integer $sendontag    1 = use the first found hashtag as categoryname
	 * @param string  $blogcategory Category for publishing to the Blog via API
	 * @param string  $bloguser     Username for publishing to the Blog via API
	 * @param string  $blogpassword Password for publishing to the Blog via API
	 */
	public function saveBlog($userid, $blogtype, $blogurl, $announce, $replycomment, $sendarticle, $sendontag, $blogcategory, $bloguser, $blogpassword) {
		
		$set = "blogtype='$blogtype', ";
		$set .= "blogurl='$blogurl', ";
		$set .= "announce=$announce, ";
		$set .= "replycomment=$replycomment, ";
		$set .= "sendarticle=$sendarticle, ";
		$set .= "sendontag=$sendontag, ";
		$set .= "blogcategory='$blogcategory', ";
		$set .= "bloguser='$bloguser', ";
		$set .= "blogpassword='$blogpassword'";
		
		// Insert or update?
		$sql = "SELECT * FROM pi_blog WHERE userid=$userid";
		$query = mysql_query($sql) or die ("blogModel::saveBlog()\n$sql\n".mysql_error());
		if(mysql_num_rows($query) > 0) {
			$sql = "UPDATE pi_blog SET $set WHERE userid=$userid";
		} else {
			$sql = "INSERT INTO pi_blog SET userid=$userid, $set";
		}
		$query = mysql_query($sql) or die ("blogModel::saveBlog()\n$sql\n".mysql_error());
		
	} /* saveBlog($userid, $blogtype, $blogurl, $announce, $replycomment, $sendarticle, $sendtotag, $blogcategory, $bloguser, $blogpassword) */
	
	
	
	/**
	 * Gets informations for a blog entry for a specified message
	 * 
	 * @param integer $messageid ID of the zzap message
	 *
	 * @return array Blog entry data
	 */
	public function getBlogEntry($messageid) {
		
		$result = array();
		$sql = "SELECT * FROM pi_blog_entry WHERE messageid=$messageid";
		$GLOBALS['application']->writeLog($sql, 'messageProcess');
		$query = mysql_query($sql) or die ("blogModel::saveBlogEntry()\n$sql\n".mysql_error());
		if(mysql_num_rows($query) > 0) {
			$result = mysql_fetch_assoc($query);
		}
		return $result;
		
	} /* getBlogEntry($messageid) */
	
	
	
	/**
	 * Saves the id of a blog entry, belonging to a zzap message
	 * 
	 * @param integer $messageid id of the zzap message
	 * @param integer $entryid   id of the blogentry
	 */
	public function saveBlogEntry($messageid, $entryid) {
		
		$sql = "INSERT INTO pi_blog_entry SET messageid=$messageid, entryid=$entryid";
		$GLOBALS['application']->writeLog($sql, 'messageProcess');
		$query = mysql_query($sql) or die ("blogModel::saveBlogEntry()\n$sql\n".mysql_error());
		
	} /* saveBlogEntry($messageid, $entryid)  */
	
	
}
?>
Return current item: Zzap