CMS MADE SIMPLE FORGE

Gallery

 

[#5656] automatically generate "new directory name"

avatar
Created By: nic mare (nicmare)
Date Submitted: 2010-11-11 04:17

Assigned To: Jos (josvd)
Resolution: None
State: Open
Summary:
automatically generate "new directory name"
Detailed Description:
The Problem:
the client type in "my Gallery of my House" in this field and in the title the
same. Because they dont know the difference and dont understand the relation.
and those values may cause troubles on some server.

the solution:
therefore it would be nice to move the dirctory name field to bottom or hide it
by default (expand it with toggle) and they have just to fill the title and the
directory name would be generated automatically or when they want, they can type
in a own directory name.

History

Comments
avatar
Date: 2013-10-08 23:58
Posted By: Grant O'Neill (gocreative)

I overcame this issue by editing action.do_editgallery.php and then using the
gallerytitle parameter as the directoryname parameter, then converting it to
lowercase and stripping out all punctuation and spaces. Here's the code I used
(which certainly isn't perfect, but it works):

// existing code
elseif( isset($params['directoryname']) )
{

// my additions
	// cleanup the directoryname, see reference-arrays in lib/replacement.php
	$params['directoryname'] = $params['gallerytitle'];
	$params['directoryname'] = munge_string_to_url($params['directoryname']);
	
	// convert directoryname to friendly format
	function strip_punctuation( $text )
{
		$urlbrackets    = '\[\]\(\)';
		$urlspacebefore = ':;\'_\*%@&?!' . $urlbrackets;
		$urlspaceafter  = '\.,:;\'\-_\*@&\/\\\\\?!#' . $urlbrackets;
		$urlall         = '\.,:;\'\-_\*%@&\/\\\\\?!#' . $urlbrackets;
	 
		$specialquotes  = '\'"\*<>';
	 
		$fullstop       = '\x{002E}\x{FE52}\x{FF0E}';
		$comma          = '\x{002C}\x{FE50}\x{FF0C}';
		$arabsep        = '\x{066B}\x{066C}';
		$numseparators  = $fullstop . $comma . $arabsep;
	 
		$numbersign     = '\x{0023}\x{FE5F}\x{FF03}';
		$percent        = '\x{066A}\x{0025}\x{066A}\x{FE6A}\x{FF05}\x{2030}\x{2031}';
		$prime          = '\x{2032}\x{2033}\x{2034}\x{2057}';
		$nummodifiers   = $numbersign . $percent . $prime;
	 
		return preg_replace(
			array(
			// Remove separator, control, formatting, surrogate,
			// open/close quotes.
				'/[\p{Z}\p{Cc}\p{Cf}\p{Cs}\p{Pi}\p{Pf}]/u',
			// Remove other punctuation except special cases
				'/\p{Po}(?<![' . $specialquotes .
					$numseparators . $urlall . $nummodifiers . '])/u',
			// Remove non-URL open/close brackets, except URL brackets.
				'/[\p{Ps}\p{Pe}](?<![' . $urlbrackets . '])/u',
			// Remove special quotes, dashes, connectors, number
			// separators, and URL characters followed by a space
				'/[' . $specialquotes . $numseparators . $urlspaceafter .
					'\p{Pd}\p{Pc}]+((?= )|$)/u',
			// Remove special quotes, connectors, and URL characters
			// preceded by a space
				'/((?<= )|^)[' . $specialquotes . $urlspacebefore . '\p{Pc}]+/u',
			// Remove dashes preceded by a space, but not followed by a number
				'/((?<= )|^)\p{Pd}+(?![\p{N}\p{Sc}])/u',
			// Remove consecutive spaces
				'/ +/',
			),
			' ',
			$text );
	}
	
	strip_punctuation($params['directoryname']);
	
	// convert to lowercase
	$params['directoryname'] = strtolower($params['directoryname']);
	
	// replace spaces with hyphens
	$find = ' ';
	$replace = '-';
	echo str_replace($find,$replace,$params['directoryname']);

// end additions

// existing code continues...
// add subgallery
	if ( empty($params['directoryname']) )
	{
		$params['module_error'] = $this->Lang('error_directorynameinvalid');
		$this->Redirect($id, 'editgallery', '', $params);
		exit();
	}