Welcome! Log In Create A New Profile

Advanced

mod for shorter url and title

Posted by fmpwizard 
mod for shorter url and title
October 22, 2007 08:19AM
This is a complete version of shorter url and title with options on the admin.php file and with "smart" shorter title (I hope) as it will show complete words instead of cutting them and showing only part of them.

Here we go:

file: admin/configset.php
near line 36

add these if statements
if ($_max_len_title==""winking smiley {
	$_max_len_title=40;
}

if ($_start_char_title==""winking smiley {
	$_start_char_title=18;
}

if ($_end_char_title==""winking smiley {
	$_end_char_title=7;
}

if ($_max_len_url==""winking smiley {
	$_max_len_url=35;
}

if ($_start_char_url==""winking smiley {
	$_start_char_url=18;
}

if ($_end_char_url==""winking smiley {
	$_end_char_url=10;
}

Near line 220:
/**
 * Limit number of characters to show on title and url
 */
fwrite($fhandle, "\n\n// Max length of title to show on result the page.\n"winking smiley;
fwrite($fhandle,"$"."max_len_title = ".$_max_len_title. ";"winking smiley;
fwrite($fhandle, "\n\n// Max length of url to show on result the page.\n"winking smiley;
fwrite($fhandle,"$"."max_len_url = ".$_max_len_url. ";"winking smiley;
/**
 * Show x characters at beginning and at the end
 */
fwrite($fhandle, "\n\n// Number of characters to show at beginning of title.\n"winking smiley;
fwrite($fhandle,"$"."start_char_title = ".$_start_char_title. ";"winking smiley;
fwrite($fhandle, "\n\n// Number of characters to show at end of title.\n"winking smiley;
fwrite($fhandle,"$"."end_char_title = ".$_end_char_title. ";"winking smiley;
fwrite($fhandle, "\n\n// Number of characters to show at beginning of url.\n"winking smiley;
fwrite($fhandle,"$"."start_char_url = ".$_start_char_url. ";"winking smiley;
fwrite($fhandle, "\n\n// Number of characters to show at end of url.\n"winking smiley;
fwrite($fhandle,"$"."end_char_url = ".$_end_char_url. ";"winking smiley;

Near line 591:

<!-- Max length of title on result page - added by Diego -->
<tr>
<td class="left1"><input name="_max_len_title" type="text" value=
"<?php print $max_len_title;?>" id="max_len_title" size="5" maxlength="2"> </td>
<td>Max length of title to show on result the page.</td>
</tr>

<!-- Number of characters to show at beginning of title on result page - added by Diego -->
<tr>
<td class="left1"><input name="_start_char_title" type="text" value=
"<?php print $start_char_title;?>" id="start_char_title" size="5" maxlength="2"> </td>
<td>Number of characters to show at beginning of title on result page.</td>
</tr>

<!-- Number of characters to show at end of title on result page - added by Diego -->
<tr>
<td class="left1"><input name="_end_char_title" type="text" value=
"<?php print $end_char_title;?>" id="end_char_title" size="5" maxlength="2"> </td>
<td>Number of characters to show at end of title on result page.</td>
</tr>

<!-- Max length of url on result page - added by Diego -->
<tr>
<td class="left1"><input name="_max_len_url" type="text" value=
"<?php print $max_len_url;?>" id="max_len_url" size="5" maxlength="2"> </td>
<td>Max length of url to show on result the page.</td>
</tr>

<!-- Number of characters to show at beginning of url on result page - added by Diego -->
<tr>
<td class="left1"><input name="_start_char_url" type="text" value=
"<?php print $start_char_url;?>" id="start_char_url" size="5" maxlength="2"> </td>
<td>Number of characters to show at beginning of title on result page.</td>
</tr>

<!-- Number of characters to show at end of url on result page - added by Diego -->
<tr>
<td class="left1"><input name="_end_char_url" type="text" value=
"<?php print $end_char_url;?>" id="end_char_url" size="5" maxlength="2"> </td>
<td>Number of characters to show at end of url on result page.</td>
</tr>


File include/searchfuncs.php
Near line 597
Merge your code so that it look like this:
			if ($title=='')
				$title = $sph_messages["Untitled"];
			/**
			 * Show shorter title - added by Diego
			 */
			while( substr( $title, -$end_char_title, 1) !=' '  &&  $end_char_title < strlen($title) - $start_char_title - 3 ){
				$end_char_title++;
			}
			while( substr( $title, $start_char_title, 1) !=' '  &&  $start_char_title < strlen($title) - $end_char_title - 3 ){
				$start_char_title++;
			}
            $title = strlen($title) > $max_len_title ? substr($title, 0, $start_char_title)."...".substr($title, -$end_char_title):$title;

Near line 618
Merge your code so that it looks like:
				$url2 = $url;
				/**
				 * Show shorter url - added by Diego
				 */
				if (strlen($url2) > $max_len_url) {
					$url2 = substr($url2, 0, $start_char_url)."...".substr($url2, -$end_char_url) ;
				}

and comment out lines near 629
/*
			if (strlen($title) > 80) {
				$title = substr($title, 0,75)."...";
			}
*/
That all.
Now you can go into the admin.php file, then into the "Settings" and play around with the values.

If you find any problems, let me know and I hope this helps people using sphider.

Diego Medina
Web Developer
Re: mod for shorter url and title
October 27, 2007 05:17AM
It's a good mod. however it doesn't work for me....

It works how it is by default.

When I change the values in the admin panel nothing really changes.

Can you simply provide searchfuncs.php and configset.php files for 1.3.3. ?

Thanks in advance!
Re: mod for shorter url and title
October 27, 2007 06:42AM
Hi,

There are two options as to why it is not working.

1- the permissions on the settings/conf.php file

2- Which I found on my site so it may be what you see on your site as well

My mod does not "cut" words when it makes the title shorter, for example:

if you set the title
max length as 40 characters,
number of character at the beginning as 2
number of character at the end as 2

it will show same results as if you set


max length as 40 characters,
number of character at the beginning as 4
number of character at the end as 4

as long as the title is like this (example)
Title:

Contact us on my website.

because internally, my mod would do

max length as 40 characters,
number of character at the beginning as 7
number of character at the end as 8

(It modifies your numbers until it finds a space.)


Let me know if this may be the problem.

Diego

Diego Medina
Web Developer
Sorry, only registered users may post in this forum.

Click here to login