Better support for mospagebreak in search and pathway.

Locked
emeyer
Joomla! Explorer
Joomla! Explorer
Posts: 352
Joined: Thu Sep 29, 2005 2:37 am

Better support for mospagebreak in search and pathway.

Post by emeyer » Sun Mar 05, 2006 6:51 pm

Pklease can we have support for mospagebreak (multipage content items) in search and pathway? Here is some code to illustrate:

----------------------------------------------------
1. Showing page titles in pathway for paginated content items:
----------------------------------------------------
Two edits:
(i). Add the following to mambots/content/mospaging.php around line 101:

Code: Select all

	if ( @$args['title'] ) {
		// new line follows:
		$mainframe->appendPathway(stripslashes( $args['title']));
		$row->page_title = ': '. stripslashes( $args['title'] );
(ii) small edit to includes/pathway.php: edit line 278 -

Code: Select all

             if ($item->id == $Itemid || empty( $mid ) || empty($item->link)) {
   

  delete empty($item->link) thus:

Code: Select all

		 if ($item->id == $Itemid || empty( $mid ) ) {

----------------------------------------------------
2. Correctly navigating to article in paginated items from search results:
----------------------------------------------------
After performing a search on paginated items, Joomla returns search results which always link to the first page of the multipage article, rather than the subpage. On navigating to the found page, the text shown in the search results then doesn't appear in the displayed item.

The following changes to search.php correct the link on the serach page so it takes you to the correct page of a paginated content item. Also, when traversing to a found link, this code scrolls down to the first anchor before the first term in the search expression.

Code: Select all


	$totalRows = count( $rows );
	for ($i=0; $i < $totalRows; $i++) {
		$row = &$rows[$i]->text;
		if ($phrase == 'exact') {
			$searchwords = array($searchword);
			$needle = $searchword;
		} else {
			$searchwords = explode(' ', $searchword);
			$needle = $searchwords[0];
		}
// MOD STARTS HERE
		// extend URL for multiple-page items
		$wordpos = strpos(strtolower($row), strtolower($needle));
		$str = substr( $row, 0, $wordpos);
		$match = preg_match_all('/mospagebreak/i', $str, $matches);
		if ($match){
			$hrefArticle[$i] = "&limit=1&limitstart=".$match;	
		} else {
			$hrefArticle[$i] = "";
		}
		//search backwards for the last anchor name and add anchor name to end of search string.
		$match = preg_match_all('/<a name="([^"]*)">/i', $str, $matches);
		// $match = preg_match_all('/<a\s+.*?name="([^"]+)"[^>]*>/i', $str, $matches);
		if ($match){
			$hrefArticle[$i] .= "#".$matches[1][$match-1];	
		} 
//END MOD
		$row = mosPrepareSearchContent( $row, 200, $needle );
	  	foreach ($searchwords as $hlword) {
			$row = preg_replace( '/' . preg_quote( $hlword, '/' ) . '/i', 
'<span  class="highlight">\0</span>', $row); 
		}
		if (!eregi( '^http', $rows[$i]->href )) {
			// determines Itemid for Content items
			if ( strstr( $rows[$i]->href, 'view' ) ) {
			// tests to see if itemid has already been included - this occurs for typed content items
				if ( !strstr( $rows[$i]->href, 'Itemid' ) ) {
					$temp = explode( 'id=', $rows[$i]->href );
//ALSO $hrefarticle gets appended her ....
					@$rows[$i]->href = $rows[$i]->href. '&Itemid='. $mainframe->getItemid($temp[1]).$hrefArticle[$i];
					}
				}
			}
		}


Note: if more than one sub-page in a paginated item contains search targets, then the above code only returns one search result, which is a link to a sub-page containing the first occurance of the sought term.

speleo
Joomla! Intern
Joomla! Intern
Posts: 80
Joined: Fri Oct 07, 2005 11:45 am

Re: Better support for mospagebreak in search and pathway.

Post by speleo » Sat Mar 11, 2006 12:40 am

Excellent! This has been a problem for a while. Hopefully one of the core developers will pick this up and implement it in the offical codebase. Thanks!

emeyer
Joomla! Explorer
Joomla! Explorer
Posts: 352
Joined: Thu Sep 29, 2005 2:37 am

Re: Better support for mospagebreak in search and pathway.

Post by emeyer » Tue Mar 14, 2006 12:00 am

The above includes/pathway.php code put a link, instead of text, for the first page of a paginated item, and did not always make the link correctly. The below version of pathwya.php appears to fix these problems.

Code: Select all

<?php
/**
* @version $Id: pathway.php 1696 2006-01-07 17:00:03Z stingrey $
* @package Joomla
* @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );

function pathwayMakeLink( $id, $name, $link, $parent ) {
	$mitem = new stdClass();
	$mitem->id 		= $id;
	$mitem->name 	= html_entity_decode( $name );
	$mitem->link 	= $link;
	$mitem->parent 	= $parent;
	$mitem->type 	= '';

	return $mitem;
}

/**
* Outputs the pathway breadcrumbs
* @param database A database connector object
* @param int The db id field value of the current menu item
*/
function showPathway( $Itemid ) {
	global $database, $option, $task, $mainframe, $mosConfig_absolute_path, $mosConfig_live_site;

	// get the home page
	$query = "SELECT id, name, link, parent, type"
	. "\n FROM #__menu"
	. "\n WHERE menutype = 'mainmenu'"
	. "\n AND published = 1"
	. "\n ORDER BY parent, ordering"
	. "\n LIMIT 1"
	;
	$database->setQuery( $query );
	$home_menu = new mosMenu( $database );
	$database->loadObject( $home_menu );

	// the the whole menu array and index the array by the id
	$query = "SELECT id, name, link, parent, type"
	. "\n FROM #__menu"
	. "\n WHERE published = 1"
	. "\n ORDER BY parent, ordering"
	;
	$database->setQuery( $query );
	$mitems = $database->loadObjectList( 'id' );

	//$isWin = (substr(PHP_OS, 0, 3) == 'WIN');
	//$optionstring = $isWin ? $_SERVER['QUERY_STRING'] : $_SERVER['REQUEST_URI'];
	$optionstring = '';
	if ( isset( $_SERVER['REQUEST_URI'] ) ) {
		$optionstring = $_SERVER['REQUEST_URI'];
	} else if ( isset( $_SERVER['QUERY_STRING'] ) ) {
		$optionstring = $_SERVER['QUERY_STRING'];
	}

	// are we at the home page or not
	$homekeys 	= array_keys( $mitems );
	$home 		= @$mitems[$home_menu->id]->name;
	$path 		= '';

	// this is a patch job for the frontpage items! aje
	if ($Itemid == $home_menu->id) {
		switch ($option) {
			case 'content':
			$id = intval( mosGetParam( $_REQUEST, 'id', 0 ) );
			if ($task=='blogsection'){

				$query = "SELECT title, id"
				. "\n FROM #__sections"
				. "\n WHERE id = $id"
				;
			} else if ( $task=='blogcategory' ) {
				$query = "SELECT title, id"
				. "\n FROM #__categories"
				. "\n WHERE id = $id"
				;
			} else {
				$query = "SELECT title, catid, id"
				. "\n FROM #__content"
				. "\n WHERE id = $id"
				;
			}
			$database->setQuery( $query );

			$row = null;
			$database->loadObject( $row );

			$id = max( array_keys( $mitems ) ) + 1;

			// add the content item
			$mitem2 = pathwayMakeLink(
				$Itemid,
				$row->title,
				'',
				1
			);
			$mitems[$id] = $mitem2;
			$Itemid = $id;

			$home = '<a href="'. sefRelToAbs( 'index.php' ) .'" class="pathway">'. $home .'</a>';
			break;

		}
	}

	switch( @$mitems[$Itemid]->type ) {
		case 'content_section':
		$id = intval( mosGetParam( $_REQUEST, 'id', 0 ) );

		switch ($task) {
			case 'category':
			if ($id) {
				$query = "SELECT title, id"
				. "\n FROM #__categories"
				. "\n WHERE id = $id"
				;
				$database->setQuery( $query );
				$title = $database->loadResult();

				$id = max( array_keys( $mitems ) ) + 1;
				$mitem = pathwayMakeLink(
					$id,
					$title,
					'index.php?option='. $option .'&task='. $task .'&id='. $id .'&Itemid='. $Itemid,
					$Itemid
				);

				$mitems[$id] = $mitem;
				$Itemid = $id;
			}
			break;

			case 'view':
			if ($id) {
				// load the content item name and category
				$query = "SELECT title, catid, id"
				. "\n FROM #__content"
				. "\n WHERE id = $id"
				;
				$database->setQuery( $query );
				$row = null;
				$database->loadObject( $row );

				// load and add the category
				$query = "SELECT c.title AS title, s.id AS sectionid, c.id AS id"
				. "\n FROM #__categories AS c"
				. "\n LEFT JOIN #__sections AS s"
				. "\n ON c.section = s.id"
				. "\n WHERE c.id = $row->catid"
				;
				$database->setQuery( $query );
				$result = $database->loadObjectList();

				$title = $result[0]->title;
				$sectionid = $result[0]->sectionid;

				$id = max( array_keys( $mitems ) )+1 ;
				$mitem1 = pathwayMakeLink(
					$Itemid,
					$title,
					'index.php?option='. $option .'&task=category&sectionid='. $sectionid .'&id='. $row->catid,
					$Itemid
				);

				$mitems[$id] = $mitem1;

				// add the final content item
				$id++;
				$mitem2 = pathwayMakeLink(
					$Itemid,
					$row->title,
					'index.php?option='. $option .'&task=view&id='. $row->id,
					$id-1
				);
				$mitems[$id] = $mitem2;
				$Itemid = $id;

			}
			break;
		}
		break;

		case 'content_category':
		$id = intval( mosGetParam( $_REQUEST, 'id', 0 ) );

		switch ($task) {

			case 'view':
			if ($id) {
				// load the content item name and category
				$query = "SELECT title, catid, id"
				. "\n FROM #__content"
				. "\n WHERE id = $id"
				;
				$database->setQuery( $query );
				$row = null;
				$database->loadObject( $row );

				$id = max( array_keys( $mitems ) ) + 1;
				// add the final content item
				$mitem2 = pathwayMakeLink(
					$Itemid,
					$row->title,
					'',
					$Itemid
				);

				$mitems[$id] = $mitem2;
				$Itemid = $id;

			}
			break;
		}
		break;

		case 'content_blog_category':
		case 'content_blog_section':
		switch ($task) {
			case 'view':
			$id = intval( mosGetParam( $_REQUEST, 'id', 0 ) );

			if ($id) {
				// load the content item name and category

				$query = "SELECT title, catid, id"
				. "\n FROM #__content"
				. "\n WHERE id = $id"
				;
				$database->setQuery( $query );
				$row = null;
				$database->loadObject( $row );

				$id = max( array_keys( $mitems ) ) + 1;
				$mitem2 = pathwayMakeLink(
					$Itemid,
					$row->title,
					'',
					$Itemid
				);
				$mitems[$id] = $mitem2;
				$Itemid = $id;

			}
			break;
		}
		break;
	}

	$i = count( $mitems );
	$mid = $Itemid;

	$imgPath =  'templates/' . $mainframe->getTemplate() . '/images/arrow.png';
	if (file_exists( "$mosConfig_absolute_path/$imgPath" )){
		$img = '<img src="' . $mosConfig_live_site . '/' . $imgPath . '" border="0" alt="arrow" />';
	} else {
		$imgPath = '/images/M_images/arrow.png';
		if (file_exists( $mosConfig_absolute_path . $imgPath )){
			$img = '<img src="' . $mosConfig_live_site . '/images/M_images/arrow.png" alt="arrow" />';
		} else {
			$img = '>';
		}
	}

	while ($i--) {
		if (!$mid || empty( $mitems[$mid] )  || $mid == 1 || !eregi("option", $optionstring)) {
			break;
		}
		$item =& $mitems[$mid];

		// converts & to & for xtml compliance
		$itemname = ampReplace( $item->name );

		// if it is the current page, then display a non hyperlink
		if ($item->id == $Itemid || empty( $mid ) ) {
			$newlink = "  $itemname";
		} else if (isset($item->type) && $item->type == 'url') {
			$correctLink = eregi( 'http://', $item->link);
			if ($correctLink==1) {
				$newlink = '<a href="'. $item->link .'" target="_window" class="pathway">'. $itemname .'</a>';
			} else {
				$newlink = $itemname;
			}
		} else {
			if ( preg_match('/limit/',  $_SERVER['QUERY_STRING']) || $i +1 != count($mitems) ){
				$newlink = '<a href="'. sefRelToAbs( $item->link .'&Itemid='. $item->id ) .'" class="pathway">'. $itemname .'</a>';
			} else {
				$newlink = $itemname;
			}
		}
		$newlink = ampReplace( $newlink );

		if (trim($newlink)!="") {
			$path = $img .' '. $newlink .' '. $path;
		} else {
			$path = '';
		}

		$mid = $item->parent;
	}

	if ( eregi( 'option', $optionstring ) && trim( $path  ) ) {
		$home = '<a href="'. sefRelToAbs( 'index.php' ) .'" class="pathway">'. $home .'</a>';
	}

	if ($mainframe->getCustomPathWay()){
		$path .= $img . ' ';
		$path .= implode ( "$img " ,$mainframe->getCustomPathWay());
	}

	echo '<span class="pathway">'. $home .' '. $path .'</span>';
}

// code placed in a function to prevent messing up global variables
showPathway( $Itemid );
?>

User avatar
kper
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 198
Joined: Fri Aug 26, 2005 11:09 am

Re: Better support for mospagebreak in search and pathway.

Post by kper » Mon May 08, 2006 7:56 am

This sounds like a great improvement. Simple but useful.

Has it been implemented yet?

jbrowdy
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 226
Joined: Mon Apr 17, 2006 9:48 pm

Re: Better support for mospagebreak in search and pathway.

Post by jbrowdy » Wed Jun 14, 2006 3:07 pm

This is an incredibly pertinant issue for my site- lots of multiple page items; and searching is very important.  I would love to see this integrated.  Has the kind poster of this topic figured out how to display all the items in an article if it shows up more than once?

jbrowdy
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 226
Joined: Mon Apr 17, 2006 9:48 pm

Re: Better support for mospagebreak in search and pathway.

Post by jbrowdy » Fri Jun 16, 2006 2:13 am

This does not seem to work in 1.09- unless I've implemented it incorrectly?  Anyone?

speleo
Joomla! Intern
Joomla! Intern
Posts: 80
Joined: Fri Oct 07, 2005 11:45 am

Re: Better support for mospagebreak in search and pathway.

Post by speleo » Sat Jun 17, 2006 4:49 pm

How do we go about getting this issue addressed by the dev team?

It should be a fundemental requirement for a search to return the correct page...

jbrowdy
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 226
Joined: Mon Apr 17, 2006 9:48 pm

Re: Better support for mospagebreak in search and pathway.

Post by jbrowdy » Wed Jun 21, 2006 3:07 pm

Sorry, but BIG BUMP.  This is such a glaring issue- can anyone shed light on this?  Any chance this can be fixed?

speleo
Joomla! Intern
Joomla! Intern
Posts: 80
Joined: Fri Oct 07, 2005 11:45 am

Re: Better support for mospagebreak in search and pathway.

Post by speleo » Tue Jul 18, 2006 9:56 pm

I've raised an artifact (artf5337) in the forge for this. I know the dev team are pusing the limits to get 1.5 out the door but hopefully it'll get into the core...
http://forge.joomla.org/sf/go/artf5337?nav=1

speleo
Joomla! Intern
Joomla! Intern
Posts: 80
Joined: Fri Oct 07, 2005 11:45 am

Re: Better support for mospagebreak in search and pathway.

Post by speleo » Thu Sep 28, 2006 1:07 pm

With Joomla 1.0.11 this is now broken again. The search.php and pathway.php files have both been re-written without the search modification being addressed.

Searching for information on a site is a basic requirement and I'm amazed that it is being ignored. Maybe it'll be in 1.5...

The code examples can no longer just be inserted into the files to correct the search issue. Any chance someone could look at this and find a solution?

jbrowdy
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 226
Joined: Mon Apr 17, 2006 9:48 pm

Re: Better support for mospagebreak in search and pathway.

Post by jbrowdy » Thu Sep 28, 2006 1:48 pm

I am totally with Speleo.  Heck, if I knew what I was doing, I'd volunteer.  Can we fix this?

speleo
Joomla! Intern
Joomla! Intern
Posts: 80
Joined: Fri Oct 07, 2005 11:45 am

Re: Better support for mospagebreak in search and pathway.

Post by speleo » Sat Sep 30, 2006 10:56 pm

I get the impression that all effort at the moment is going towards the 12 October release of 1.5. Does anyone know if it fixed in this?


Locked

Return to “Wishlist Archives - Archived”