Hello,
Many thanks for this wonderful module. It's very usefull.
I am trying to do a custom module so that the information pages module that comes with Creload will work with SEO URLs.
Here is a copy of the code I am using. This code is based on the Usu_Article_Info.php and the template provide in the SEO URLs module package.
<?php
class Usu_Pages extends aDataMap {
const MARKER = '-page-'; // Could for example be -c- or -l- etc.
const DEPENDENCY = 'pID'; // _GET key like e.g. cPath or lPath etc.
const FILENAME = 'pages.php'; // The filename define of the file where this code will be actioned, this MUST NOT be a define
public $dependency = self::DEPENDENCY;
public $dependency_tags = array( self::MARKER => self::FILENAME ); // key value pair of tag (like e.g. -c-) => filename ( e.g. FILENAME_DEFAULT )
private $page_relations = array( self::FILENAME => 1 ); // Page relation for this module ( e.g. FILENAME_DEFAULT or FILENAME_LINKS )
private $markers = array( self::MARKER => self::DEPENDENCY ); // Markers as key value pair like -c- => cPath or perhaps -l- => lPath
private $base_query; // Template query with placeholders ( :placeholder ) waiting for real values
private $query; // The final query which will be $base_query but with the placeholders replaced with real values
private $pages_title; // property populated in the acquire() method, there may be multiples of these, rename in line with the query results
private $dependency_value; // Dependency value, so if the dependency was cPath and cPath = 27 then this value would be 27
private $installed = false; // Unless it is a core module $installed should only be true if the contribution is installed ( e.g. articles or links manager etc )
public function __construct(){
$this->base_query = "SELECT pages_title FROM pages_description WHERE pages_id=':pID' AND language_id=':languages_id' LIMIT 1";
usu::$registry->merge( 'seo_pages', $this->page_relations );
usu::$registry->merge( 'markers', $this->markers );
usu::$registry->addPageDependency( array( self::FILENAME => self::DEPENDENCY ));
$this->installed = true; // pages Hardcoded to true in this instance - see above comment.
}
protected function acquire( $base_path, $full_path ) {
$this->dependency_value = $full_path; // Full path perhaps with underscores
$placeholders = array( ':pID', ':languages_id' );
$values = array( (int)$base_path, (int)usu::$languages_id ); // pages These values will replace the placeholders above in $this->base_query
$this->query = str_replace( $placeholders, $values, $this->base_query ); // Replace the placeholders with actual values
$result = usu::query( $this->query ); // Action the query
$this->query = null; // Unset the query for future usage
$row = tep_db_fetch_array( $result ); // Return the array of data ( or false if there are no results )
tep_db_free_result( $result ); // Housekeeping
if ( false === $row ) {
return false; // No results for the query so abort
}
$this->pages_title = $this->linkText( $row['pages_title'] );
if ( false === isset( usu::$registry->{self::DEPENDENCY} ) ) {
usu::$registry->{self::DEPENDENCY} = array();
}
usu::$registry->attach( self::DEPENDENCY, $this->dependency_value, $this->getProperties() );
} // End method
protected function getProperties() {
$properties = get_object_vars( $this ); // $properties becomes an array of all properties within this class
unset( $properties['page_relations'] ); // Get rid of this key as it is not needed in the registry
return $properties;
} // End method
private function get_full_path( $path ) {
return $path;
} // End method
private function get_parents() {
} // End method
public function buildLink( $page, $valuepair, &$url, &$added_qs, $parameters ) {
if ( ( $valuepair[0] != self::DEPENDENCY ) || ( false === array_key_exists( 1, $valuepair ) )
|| ( false === $this->installed )
|| !tep_not_null( $valuepair[1] ) ) {
return false; // Either this module is not installed or the value pair does not meet our requirements so abort
}
$base_path = $valuepair[1]; // well it might be a single top level item
if ( false !== strpos( $valuepair[1], '_' ) ) { // It is a path with parents? ( has underscores )
$base_path = ltrim( strrchr( $valuepair[1], '_' ), '_' ); // Grab the base path which is the number at the end of a path with parents ( e.g. 2_23_37_52 = 52 )
}
// Sanity check - if the $base_path is not numeric then we dump it
if ( false === is_numeric( $base_path ) ) {
trigger_error( __CLASS__ . ' Incorrect ' . self::DEPENDENCY . ' presented: ' . $valuepair[1], E_USER_WARNING );
return false;
}
// Get a full path with underscores from the database
$full_path = $this->get_full_path( $base_path );
// If this item is not already in the registry we use the acquire() method to query for the data
if ( !isset( usu::$registry->vars[self::DEPENDENCY][$full_path] ) ) {
if ( false === $this->acquire( $base_path, $full_path ) ) {
return false; // Looks like an invalid request so dump it
}
} else {
usu::$performance['queries_saved']++; // Already in the registry so we saved one query
}
$reg_item = array();
$reg_item = usu::$registry->vars[$valuepair[0]][$full_path];
$link_text = $reg_item['pages_title']; // the property added in the acquire function this would have been set in the acquire method like $this->pages_name
switch( true ){
case $page == self::FILENAME:
$url = $this->linkCreate( self::FILENAME, $link_text, self::MARKER, $full_path );
break;
default:
$added_qs[filter_var( $valuepair[0], FILTER_SANITIZE_STRING )] = usu::cleanse( $valuepair[1] );
break;
} # end switch
}
}
?>
Information pages are normally accessed through these kind of URLs http://www.mysite.com/pages.php?pID=1 but whenever I access a page I get a "Page not found" message and there are no query in the debugging information. Can anyone give me a clue about what's wrong here?
Thanks
Vincent