Location: PHPKode > projects > ANJEL > com_anjel/classes/class.subscribers.php
<?php
/* $Id: class.subscribers.php 39 2005-11-23 19:23:47Z schmalls $ */
/**
 * class.subscribers.php
 * 
 * <p>Includes {@link subscribers} class.</p>
 * 
 * @package ANJEL
 * @subpackage classes
 * @copyright © 2004 Schmalls / Joshua Thompson / All Rights Reserved
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
 * @author Schmalls / Joshua Thompson <hide@address.com>
 * @version 0.6.1
 * @since 0.4.3
 * @link http://www.schmalls.com
 */
 
 /**
  *  Ensures this file is being included by a parent file
  */
 defined('_VALID_MOS') or die('Direct Access to this location is not allowed.');
 
 /**
  * Class with subscribers functions
  * 
  * <p>Class for both frontend and backend subscribers functions.</p>
  * 
  * @package ANJEL
  * @subpackage classes
  * @author Schmalls / Joshua Thompson <hide@address.com>
  * @version 0.6.1
  * @since 0.4.3
  */
 class subscribers {
	 
	 /**
	  * Gets the subscribers for a newsletter
	  * 
	  * <p>Gets the registeres subscribers then the unregistered subscribers 
	  * from the database as object arrays. Then it merges the two arrays 
	  * into one array and returns it.</P
	  * 
	  * @version 0.6.1
	  * @since 0.4.3
	  * @param int $listid the list to work with
	  * @param string $confirmed to be added to end of database query
	  * @global class access to the database
	  * @return boolean false on failure | array the subscriber information if successful
	  */
	 function getSubscribers($listid, $confirmed = ''){
		global $database;
		
		$listid = 'list_' . $listid;
		// get registered subscribers
		$query = "SELECT 
					N.subscriber_id AS id, 
					M.name AS name, 
					M.email AS email, 
					N.confirmed AS confirmed, 
					N.subscribe_date AS subscribe_date, 
					N.receive_html AS receive_html,
					N.blacklist AS blacklist,
					'1' as registered
					FROM `#__anjel_subscribers` AS N, 
					`#__users` AS M 
					WHERE N." . $listid . " != 0 " 
					. $confirmed . " 
					AND M.id = N.subscriber_id";
		$database->setQuery($query);
        $registered = $database->loadObjectList();
        $error = $database->getErrorMsg();
		// quit on error
		if (!empty($error)) {
			echo '<p>Error (classes/class.subscribers.php->getSubscribers() line ' . __LINE__ . '): Could not get registered subscribers from database. Database error: <br />' . $error . '</p>';
			return false;
		} else {
			// get unregistered subscribers
	        $query = "SELECT U.unregistered_id AS id,
						U.name AS name,
						U.email AS email,
						U.confirmed AS confirmed,
						U.subscribe_date AS subscribe_date,
						U.receive_html AS receive_html,
						U.blacklist as blacklist,
						'0' as registered
						FROM #__anjel_unregistered AS U
						WHERE U." . $listid . " != 0 "
						. $confirmed;
			$database->setQuery($query);
			$unregistered = $database->loadObjectList();
			$error = $database->getErrorMsg();
			// quit on error
			if (!empty($error)) {
				echo '<p>Error (classes/class.subscribers.php->getSubscribers() line ' . __LINE__ . '): Could not get unregistered subscribers from database. Database error: <br />' . $error . '</p>';
				return false;
			} else {
				// combine arrays and return
	        	$total = array_merge($registered, $unregistered);
				return $total;
			} // end if
		} // end if
	} // end function
	/**
	 * RFC822 Email Parser Revision 3
	 * 
	 * <p>Function name changed from is_valid_email_address to validEmail. Checks if an email address is valid using the RFC822 guidelines.</p>
	 * 
	 * @license http://creativecommons.org/licenses/by-sa/2.5/ Creative Commons Attribution-ShareAlike 2.5 License
	 * @author Cal Henderson <hide@address.com>
	 * @version 0.6.1
	 * @since 0.6.1
	 */
	 function validEmail($email) {
		 
		 $qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
		 $dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
		 $atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
		 $quoted_pair = '\\x5c[\\x00-\\x7f]';
		 $domain_literal = "\\x5b($dtext|$quoted_pair)*\\x5d";
		 $quoted_string = "\\x22($qtext|$quoted_pair)*\\x22";
		 $domain_ref = $atom;
		 $sub_domain = "($domain_ref|$domain_literal)";
		 $word = "($atom|$quoted_string)";
		 $domain = "$sub_domain(\\x2e$sub_domain)*";
		 $local_part = "$word(\\x2e$word)*";
		 $addr_spec = "$local_part\\x40$domain";
		 return preg_match("!^$addr_spec$!", $email) ? true : false;
	 } // end function
 } // end class
?>
Return current item: ANJEL