Recent Topics

[Hack] [1.8] Allow for ?blog=urlname, and ?blog=shortname

Started by on Jun 07, 2006 – Contents updated: Jun 07, 2006

Jun 07, 2006 00:12    

Hey, this hack will allow for ?blog=urlname as well as ?blog=shortname instead of just ?blog=id

Heres the hack for the v1.8.x releases of b2evo.

Add [ File - /blogs/inc/MODEL/collections/_blogcache.class.php ; Line - 183 ]

// ==========================================================================================================
// START OF BALUPTON's URLNAME AND SHORTNAME HACK

	/**
	 * Get an object from cache by its URL name.
	 *
	 * Load the object into cache, if necessary.
	 *
	 * @param string SHORT name of object to load
	 * @param boolean false if you want to return false on error
	 * @return Blog|false A Blog object on success, false on failure (may also halt!)
	 */
	function & get_by_shortname( $req_shortname, $halt_on_error = true )
	{
		global $DB, $Debuglog;

		// Load just the requested object:
		$Debuglog->add( "Loading <strong>$this->objtype($req_shortname)</strong> into cache", 'dataobjects' );
		$sql = "
				SELECT *
				  FROM $this->dbtablename
				 WHERE blog_shortname = ".$DB->quote($req_shortname);
		$row = $DB->get_row( $sql );

		if( empty( $row ) )
		{ // Requested object does not exist
			if( $halt_on_error ) debug_die( "Requested $this->objtype does not exist!" );
			$r = false;
			return $r;
		}

		$Blog = new Blog( $row );
		$this->add( $Blog );

		return $Blog;
	}

// END OF BALUPTON's URLNAME AND SHORTNAME HACK
// ==========================================================================================================

Change [ File - /blogs/index.php ; Line - 24/25 ]

// Check if a specific blog has been requested in the URL:
param( 'blog', 'integer', '', true );


To

// ==========================================================================================================
// START OF BALUPTON's URLNAME AND SHORTNAME HACK

// Check if a specific blog has been requested in the URL:
param( 'blog', 'string', '', true );

// If $blog is a number
if( is_numeric($blog) ) {
	// Make $blog's type a number
	settype($blog,'integer');
} else {
	// Check for urlname, if not check for shortname, if not use the default value
	$blog =	($temp = $BlogCache->get_by_urlname($blog, false)) ? $temp->ID :
			(($temp = $BlogCache->get_by_shortname($blog, false)) ? $temp->ID : '');
	unset($temp);
}

// END OF BALUPTON's URLNAME AND SHORTNAME HACK
// ==========================================================================================================


Form is loading...

Open Source CMS – This forum is powered by b2evolution CMS, a complete engine for your website.