How to change viewer urls

9 posts by 2 authors in: Forums > CMS Builder
Last Post: December 22, 2007   (RSS)

By Djulia - December 20, 2007 - edited: December 22, 2007

Hi Dave,

Thank you for your update. It functions perfectly. [:)]

I have another remark.

Article Manager has an important option.
It makes it possible to give a name different from the title to the file.

For example :
Menu Name?Filename

instead of :
Menu Name?Title

It will be possible to add this option ?

Thank you for your answer.

Djulia

Re: [Djulia] Add or Upload File(s)

By Dave - December 20, 2007

Absolutely, CMS Builder pages are designed to be search engine friendly so you have whatever you want in the page urls.

In your "List Viewer" page search for 'titleField', like this:

$options['titleField'] = 'title';

// (optional) MySQL fieldname used in viewer url for search engines.
// Example: 'title' would display: viewer.php/article_title_here-123


Just change "title" to whatever fieldname you want output in your urls (or even create a new "filename" field for that if you like) and it will update all your links.

Let me know if that works for you. :)
Dave Edis - Senior Developer
interactivetools.com

Re: [Djulia] Add or Upload File(s)

By Dave - December 22, 2007

I'm not sure if I understand exactly.

Typically when you add a field you can display it with some PHP code like this: <?php echo $record['fieldname'] ?>

So if you add a field called 'title' or 'urlKeywords' you could display them like this: <?php echo $record['title'] ?> or <?php echo $record['urlkeywords'] ?>

If you could explain in a little more detail what you want to do, I'll try and give you a better answer.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Add or Upload File(s)

By Djulia - December 22, 2007

Hi Dave,

Thank you for your answer.

I have Title field and Filename field.

I would like to use the function "autoFillQuickAddFieldName" to convert the characters in Filename (field).

<INPUT id=fieldTitle onkeyup=autoFillQuickAddFieldName() onchange=autoFillQuickAddFieldName() name=fieldFilename>

<INPUT id=fieldname name=fieldname>

But that seems difficult, because the fields on the page are built dynamically, not ?

Thank,

Djulia

Re: [Djulia] Add or Upload File(s)

By Dave - December 22, 2007

I understand. You want to add a 'filename' field, and have that field auto-updated when the user enters the title. Then you want to use that field in the viewer urls.

No, unfortunately there's no easy way to do that right now.

What if we updated the List Viewer so you can specify multiple fields for the 'titleField' option, and it used the first non-blank one for the url. That way you could specify:

$options['titleField'] = 'fieldname,title';

And if the filename was specified it would use that in the url, otherwise it would use the title in the url.

Would that do what you want?
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Add or Upload File(s)

By Djulia - December 22, 2007

Yes, it is exactly that.

Djulia

Re: [Djulia] Add or Upload File(s)

By Dave - December 22, 2007

I think it's a good idea. We're going to add it to the next upgrade. If you're comfortable with PHP code and you want to make the changes yourself right now here's how:

Open up /lib/viewer_functions.php and search for "$options['titleField']"

Find this block of code:

if (@$options['titleField']) {
$extraUrlDetails = "";
if (!array_key_exists($options['titleField'], $record)) {
$extraUrlDetails = "Unknown_fieldname_specified_for_titleField_option/";
}
else {
$extraUrlDetails = preg_replace('/[^a-z0-9\.\-\_]+/i', '_', @$record[$options['titleField']]);
if ($extraUrlDetails) { $extraUrlDetails .= "-"; }
}
}
$record['_link'] = $options['viewerUrl'] . $urlDelimiter . $extraUrlDetails . $record['num'];


Replace it with this block of code (note that the first and last lines don't change):

if (@$options['titleField']) {
foreach (preg_split("/\s*,\s*/", $options['titleField']) as $fieldname) {
if (!array_key_exists($fieldname, $record)) {
die("$viewerName: Unknown field '" .htmlspecialchars($fieldname). "' in titleField options!");
}
if ($extraUrlDetails == "" && $record[$fieldname] != "") {
$extraUrlDetails = preg_replace('/[^a-z0-9\.\-\_]+/i', '_', "{$record[$fieldname]}-");
}
}
}
$record['_link'] = $options['viewerUrl'] . $urlDelimiter . $extraUrlDetails . $record['num'];


Once you've done that, you can specify multiple fieldnames in the 'titleField' option and the first defined field will be used. Like this:

$options['titleField'] = 'filename,title';

Hope that helps! :)
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Add or Upload File(s)

By Djulia - December 22, 2007 - edited: December 22, 2007

Hi Dave,

Your code works correctly. [:)]

Thank you for your assistance. :)

Djulia