Location: PHPKode > projects > ProjectPress > projectpress/pm-includes/functions-filters.php
<?php
if(!defined('access')) die ('You are not allowed to execute this file directly.');

/**
 * ProjectPress action filters
 *
 * @package ProjectPress
 * @since 2.1
 */
	
	/**
	* Redirects to another page.
	*
	* @since 2.1
	* @uses apply_filter() Calls 'pm_redirect' hook on $location and $status.
	* @param string $location The path to redirect to
	* @param int $status Status code to use
	* @return bool False if $location is not set
	*/
	function pm_redirect($location, $status = 302) {
		$location = apply_filter('redirect', $location, $status);
		if ( !$location ) // allows the pm_redirect filter to cancel a redirect
			return false;
		header("Location: $location", true, $status);
	}

	/**
	  * Retrieve javascript directory URI.
	  *
	  * @since 2.1
	  * @uses apply_filter() Calls 'javascript_directory_uri' filter on javascript directory URI path.
	  *
	  * @return string Javascript directory URI.
	  */
	 function get_javascript_directory_uri() {
	 	$directory = 'js';
		$javascript_root_uri = get_site_uri();
		$javascript_dir_uri = "$javascript_root_uri/$directory";
	      return apply_filter( 'javascript_directory_uri', $javascript_dir_uri, $directory, $javascript_root_uri );
	 }
	 
	 /**
	  * Retrieve stylesheet directory URI.
	  *
	  * @since 2.1
	  * @uses apply_filter() Calls 'stylesheet_directory_uri' filter on stylesheet directory URI path.
	  *
	  * @return string Stylesheet directory URI.
	  */
	 function get_stylesheet_directory_uri() {
		$directory = 'css';
		$stylesheet_root_uri = get_site_uri();
		$stylesheet_dir_uri = "$stylesheet_root_uri/$directory";
	      return apply_filter( 'stylesheet_directory_uri', $stylesheet_dir_uri, $directory, $stylesheet_root_uri );
	 }
	 
	 /**
	  * Retrieve the sites root url.
	  *
	  * @since 2.1
	  * @uses apply_filter() Calls 'site_uri' filter.
	  *
	  * @return string Site root url.
	  */
	 function get_site_uri() {
	      return apply_filter( 'site_uri', get_pm_option('siteurl') );
	 }
	 
	 /**
	  * Logs in user and sets the session and cookie.
	  *
	  * @since 2.1
	  * @uses apply_filter() Calls 'login' filter.
	  * @param string $username Username entered by the user
	  * @param string $password Password entered by the user
	  * @return bool True if $username and $password exist
	  * 
	  */
	 function pm_login($username, $password) {
		
		// Use to set cookie session for domain.
		$cookiedomain = $_SERVER['SERVER_NAME']; 
		$cookiedomain = str_replace('www.', '', $cookiedomain);

			if(isset($_POST['login'])) { // The form has not been submitted.
				$username = pmdb::connect()->escape($_POST['username']);
				$password = pmdb::connect()->escape(md5($_POST['password'])); // Encrypts the password.
					$q = pmdb::connect()->query("SELECT * FROM ". DB ."members WHERE username = '$username' AND password = '$password' AND active = '1'"); // mySQL query
					$r = $q->fetch_array(); // Checks to see if anything is in the db.
		
			if($r['username'] && $r['password']) { // There is something in the db. The username/password match up.
				$_SESSION['logged'] = 1; // Sets the session.
				$_SESSION['username'] = $r['username']; // Sets the username session.
				$_SESSION['level'] = $r['level']; // Sets the level session.
				$_SESSION['userID'] = $r['user_id'];
				$_SESSION['remember_me'] = $_POST['remember_me']; // Sets a remember me cookie if remember me is checked.

			if(isset($_POST['remember_me'])){
      			setcookie("pm_cookname", $_SESSION['username'], time()+60*60*24*365, "/", "." . $cookiedomain);
      			setcookie("pm_cookpass", md5($_SESSION['password']), time()+60*60*24*365, "/", "." . $cookiedomain);
   			}
				pm_redirect(PM_URI . "/index.php"); // Goes to main page.
			} else { // User did not enter the correct login credentials.
				pm_redirect(PM_URI . "/login.php");
			}
		}
	      return apply_filter( 'login', $username, $password );
	 }

	 /**
	  * Borrowed from WordPress
	  *
	  * Send mail, similar to PHP's mail
	  * A true return value does not automatically mean that the user received the
	  * email successfully. It just only means that the method used was able to
	  * process the request without any errors.
	  */
	 function pm_mail( $to, $subject, $message, $headers = '' ) {
	 	global $pmMailer;
		
		// From email and name
		// If we don't have a name from the input headers
		if ( !isset( $from_name ) )
			$from_name = 'ProjectPress';
		
		if ( !isset( $from_email ) ) {
			// Get the site domain and get rid of www.
			$sitename = strtolower( $_SERVER['SERVER_NAME'] );
			if ( substr( $sitename, 0, 4 ) == 'www.' ) {
				$sitename = substr( $sitename, 4 );
			}

			$from_email = 'projectpress@' . $sitename;
		}
		
		// Plugin authors can override the default mailer
		$pmMailer->From     = apply_filter( 'pm_mail_from'     , $from_email );
		$pmMailer->FromName = apply_filter( 'pm_mail_from_name', $from_name  );
		
		// Set destination addresses
		if ( !is_array( $to ) )
			$to = explode( ',', $to );

		foreach ( (array) $to as $recipient ) {
			try {
				// Break $recipient into name and address parts if in the format "Foo <hide@address.com>"
				$recipient_name = '';
				if( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) {
					if ( count( $matches ) == 3 ) {
						$recipient_name = $matches[1];
						$recipient = $matches[2];
					}
				}
				$pmMailer->AddAddress( $recipient, $recipient_name);
			} catch ( phpmailerException $e ) {
				continue;
			}
		}

		// Set mail's subject and body
		$pmMailer->Subject = $subject;
		$pmMailer->Body    = $message;
		
		// Set to use PHP's mail()
		$pmMailer->IsMail();

		// Set Content-Type and charset
		// If we don't have a content-type from the input headers
		if ( !isset( $content_type ) )
			$content_type = 'text/plain';

			$content_type = apply_filter( 'pm_mail_content_type', $content_type );

			$pmMailer->ContentType = $content_type;

		// Set whether it's plaintext, depending on $content_type
		if ( 'text/html' == $content_type )
			$pmMailer->IsHTML( true );

			// Set the content-type and charset
			$pmMailer->CharSet = apply_filter( 'pm_mail_charset', $charset );

		// Set custom headers
		if ( !empty( $headers ) ) {
			foreach( (array) $headers as $name => $content ) {
				$pmMailer->AddCustomHeader( sprintf( '%1$s: %2$s', $name, $content ) );
			}

			if ( false !== stripos( $content_type, 'multipart' ) && ! empty($boundary) )
				$pmMailer->AddCustomHeader( sprintf( "Content-Type: %s;\n\t boundary=\"%s\"", $content_type, $boundary ) );
		}
		
		// Send!
		try {
			$pmMailer->Send();
		} catch ( phpmailerException $e ) {
			return false;
		}

			return true;
	 }
Return current item: ProjectPress