Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: Custom Title Tages for Albums/Categories?  (Read 7663 times)

0 Members and 1 Guest are viewing this topic.

Walkinman

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 380
    • Skolai Images - Nature, Travel and Adventure stock photos
Custom Title Tages for Albums/Categories?
« on: January 28, 2013, 04:47:12 am »

Hey Folks,

A couple of years ago I had some work done on my cpg code to allow me to write a custom Title tag and meta description tags for Albums and Categories. It worked fine, but during the last upgrade, that code got lost, and now my cpg pages simply write the default title tag form the album/catgeory name.

I have looked at the code from the old albmgr.php file and the newer one, but I don't know php, so I have no idea how to install it. Is this pretty straightforward? I can upload a txt file of both files if it helps.

Thanks so much.

Cheers

Carl

PS: the person who did the original work doesn't seem to be around anymore.
Logged

Walkinman

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 380
    • Skolai Images - Nature, Travel and Adventure stock photos
Re: Custom Title Tages for Albums/Categories?
« Reply #1 on: January 28, 2013, 08:40:45 am »

Update:

I edited these files thumbnails.php, edit_one_pic.php, index.php, db_input.php, modifyalb.php, catmgr.php, displayimage.php and editpics.php, as well as as added a fix.php file that seems to have worked correctly.

I'll mark it solved in a day or 2 when I make sure everything is working correctly.

Cheers

Carl
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: Custom Title Tages for Albums/Categories?
« Reply #2 on: January 29, 2013, 09:55:15 am »

I guess you will share your code for interested users?
Logged

Walkinman

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 380
    • Skolai Images - Nature, Travel and Adventure stock photos
Re: Custom Title Tages for Albums/Categories?
« Reply #3 on: January 29, 2013, 10:07:08 pm »

Hey André

I'll try ... though I'll probably mess it up. I didn't write the code myself .. someone else did, and I just tried to hack it from the old files they modified, and integrate it into the new ones. So, OK .. here goes nothing;

index.php:

   lines 1127 -> 1140
       
Code: [Select]
get_cat_list($breadcrumb, $cat_data, $statistics);

    if ($cat > 0)
    {
          $result = cpg_db_query("SELECT page_title, meta_description FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = '{$cat}'");
        if (mysql_num_rows($result) > 0)
        {
            $rowX             = cpg_db_fetch_row($result);
            $page_title       = $rowX['page_title'];
            $meta_description = $rowX['meta_description'];
            $BREADCRUMB_TEXT  = $page_title ? $page_title : $BREADCRUMB_TEXT;
            $addition_meta    = "<meta name=\"description\" content=\"".addslashes($meta_description)."\" />"."\n";
        }
    }

thumbnails.php

   lines 104
         
Code: [Select]
$result = cpg_db_query("SELECT category, title, aid, keyword, description, alb_password_hint, page_title, meta_description FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid = $album");
   line 141 - 142
      
Code: [Select]
if ($cat < 0) {
        $result = cpg_db_query("SELECT category, title, aid, keyword, description, alb_password_hint, page_title, meta_description FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid = " . (- $cat));

   line 209 - 219
      
Code: [Select]
// after that add
$meta_description = $CURRENT_ALBUM_DATA['meta_description'] ? $CURRENT_ALBUM_DATA['meta_description'] : $CURRENT_ALBUM_DATA['description'];
if ($meta_description)
{
    $meta_keywords .= '<meta name="description" content="' . htmlspecialchars($meta_description) . '" />' . $LINEBREAK;
}

$section = $CURRENT_ALBUM_DATA['page_title'] ? $CURRENT_ALBUM_DATA['page_title'] : $section;

fix.php
      
Code: [Select]
<?php
define('IN_COPPERMINE'TRUE);
include 'include/init.inc.php';
cpg_db_query("
    ALTER TABLE `
{$CONFIG['TABLE_CATEGORIES']}`
    ADD `page_title` TEXT NOT NULL ,
    ADD `meta_description` TEXT NOT NULL
    "
);

?>

editpics.php

   line 151 - 152
         
Code: [Select]
array($icon_array['title'] . 'Page Title', 'page_title', 0, 255),
    array($icon_array['description'] . $captionLabel, 'caption', 2, $CONFIG['max_img_desc_length']),

   line 224
         
Code: [Select]
$page_title       = get_post_var('page_title', $pid);
   line 27
              
Code: [Select]
$update .= ", page_title = '$page_title'";
edit_one_pic.php

   line 78

         
Code: [Select]
$page_title = cpgSanitizeUserTextInput($superCage->post->getEscaped('page_title'));   line 119
         
Code: [Select]
$update .= ", page_title = '{$page_title}'";
   line 369
         
Code: [Select]
$result = cpg_db_query("SELECT *, p.title AS title, p.page_title as page_title, p.votes AS votes FROM {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = p.aid WHERE pid = '$pid'");

   lines 510 - 517
Code: [Select]
<tr>
        <td class="tableb" style="white-space: nowrap;">
            {$icon_array['title']}Page Title
        </td>
        <td width="100%" class="tableb" valign="top">
            <input type="text" style="width: 100%" name="page_title" maxlength="255" value="{$CURRENT_PIC['page_title']}" class="textinput" />
        </td>
</tr>
displayimage.php

   lines 500 - 503
      
Code: [Select]
$rowX = cpg_db_fetch_row(cpg_db_query("SELECT page_title FROM {$CONFIG['TABLE_PICTURES']} WHERE pid = '{$CURRENT_PIC_DATA['pid']}'"));
    $page_title = $rowX['page_title'] ? $rowX['page_title'] : $picture_title;

   pageheader($page_title . ' | ' . $album_name, $meta_keywords, false);
db_input.php

   lines 377 - 378
Code: [Select]
  $page_title = $superCage->post->getEscaped('page_title');
    $meta_description = $superCage->post->getEscaped('meta_description');
   line 423
         
Code: [Select]
$query = "UPDATE {$CONFIG['TABLE_ALBUMS']} SET title = '$title', description = '$description', category = $category, thumb = $thumb, comments = '$comments', votes = '$votes', visibility = $visibility, alb_password = '$password', alb_password_hint = '$password_hint', keyword = '$keyword', page_title = '{$page_title}', meta_description = '{$meta_description}'";

catmgr.php
   
   lines 67
Code: [Select]
$sql = "SELECT rgt, cid, parent, name, pos, page_title, meta_description FROM {$CONFIG['TABLE_CATEGORIES']} ORDER BY lft ASC";
   lines 515
Code: [Select]
$result = cpg_db_query("SELECT cid, name, parent, description, thumb, page_title, meta_description FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = $cid");

   lines 544-545
 
Code: [Select]
$page_title       = $superCage->post->getEscaped('page_title');
    $meta_description = $superCage->post->getEscaped('meta_description');
   lines 553 - 557
Code: [Select]
if (!in_array($parent, $children)) {
         cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET parent = $parent, name = '$name', description = '$description', page_title = '{$page_title}', meta_description = '{$meta_description}', thumb = $thumb, lft = 0 WHERE cid = $cid");
   } else {
        cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET name = '$name', description = '$description', page_title = '{$page_title}', meta_description = '{$meta_description}', thumb = $thumb, lft = 0 WHERE cid = $cid");
    }

   lines 762 - 777
         
Code: [Select]
<tr>
            <td width="40%" class="tableb">
                Page Title
            </td>
            <td width="60%" class="tableb" valign="top">
                <input type="text" style="width: 100%" name="page_title" value="{$current_category['page_title']}" class="textinput" />
            </td>
        </tr>
        <tr>
            <td class="tableb" valign="top">
                Meta Description
            </td>
            <td class="tableb" valign="top">
                <textarea name="meta_description" rows="5" cols="40" style="width: 100%;" class="textinput">{$current_category['meta_description']}</textarea>
            </td>
        </tr>
modifyalb.php

   lines 94 - 95
      
Code: [Select]
   array('Album - Page Title', 'page_title', 0),
    array('Album - Meta Description', 'meta_description', 3),

There's probably much easier, cleaner and more efficient ways to do it .. it would seem to me it should be a pretty simple mod .. but that's what I have in my cpg gallery. It's not perfect .. I seem to get 2 meta description tags, which I don't know how to resolve. I also end up with "| Stock photos" as the end part of every title tag, which I don't know how to remove.

But this code gives me the option to write a custom Title Tag for each album and category. A custom field opens up when I edit or create a new album/category.

I hope this is of some help to anyone else. If it's apparent I've overlooked part of the code in copying it here, let me know and I'll see if I can find anything else that has been edited.

Cheers

Carl
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: Custom Title Tages for Albums/Categories?
« Reply #4 on: January 30, 2013, 09:15:27 am »

I hadn't looked at the code changes, as I always prefer "find foo and replace with bar" instead of "line foo = bar".


I also end up with "| Stock photos" as the end part of every title tag, which I don't know how to remove.

In displayimage.php, find
Code: [Select]
pageheader($page_title . ' | ' . $album_name, $meta_keywords, false);and replace with
Code: [Select]
pageheader($page_title, $meta_keywords, false);
Logged

Walkinman

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 380
    • Skolai Images - Nature, Travel and Adventure stock photos
Re: Custom Title Tages for Albums/Categories?
« Reply #5 on: January 30, 2013, 10:59:09 am »

Hey André

Thanks .. I found I also had to edit my theme.php file

lines 1724-1745 for me

Code: [Select]
/******************************************************************************
** Section <<<theme_page_title>>> - START
******************************************************************************/
// Creates the title tag for each page
// For the sake of search engine friendliness, the dynamic part $section should come first
function theme_page_title($section)
{
    global $CONFIG;
    $superCage = Inspekt::makeSuperCage();
    if (strpos($superCage->server->getRaw('PHP_SELF'), 'index.php') !== FALSE && ! $superCage->get->getInt('cat'))
    {
        $return = strip_tags(bb_decode($section)) . ' | ' . $CONFIG['gallery_name'] . ($CONFIG['gallery_description'] ? " | " . $CONFIG['gallery_description'] : '');
    }
    else
    {
        $return = strip_tags(bb_decode($section)) . ' | ' . $CONFIG['gallery_name'];
    }
    return $return;
}
/******************************************************************************
** Section <<<theme_page_title>>> - END
******************************************************************************/

but remove this " . ' | ' . $CONFIG['gallery_name']" to

Code: [Select]
else
    {
        $return = strip_tags(bb_decode($section));
    }
[code]

Now it's working well enough.

How can I make it so  [code] | stock photos
will still appear on the Image Search Results thumbnails .. but only on those meta pages, not on the regular categories/albums? I looked on the search.php file; line

Code: [Select]
pageheader($lang_search_php['title']);
rigt now, the title tag would be something like:

Quote
Image Search Results ="mount blackburn"

and I would like it to be
Quote
Image Search Results ="mount blackburn" | Stock Photos

I assume I have to put this

Code: [Select]
$page_title . ' | ' . $album_name
back in somewhere .. but I can't see where. Is that possible?

Thanks so much.

Cheers

Carl

PS I realise this is kind of a 2nd question, but I figure it's (hopefully) related enough it doesn't require its own thread.
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: Custom Title Tages for Albums/Categories?
« Reply #6 on: January 30, 2013, 11:07:19 am »

Is "Stock Photos" your gallery name or somehow related to this mod?
Logged

Walkinman

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 380
    • Skolai Images - Nature, Travel and Adventure stock photos
Re: Custom Title Tages for Albums/Categories?
« Reply #7 on: January 30, 2013, 11:15:31 am »

It's what I have filled in the config for "Gallery Name".
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: Custom Title Tages for Albums/Categories?
« Reply #8 on: January 30, 2013, 11:17:27 am »

So it's not related to this mod. Please start a new thread and describe exactly what should be displayed where (I currently understood that you want to hide the gallery name in the page title everywhere, but in the search results).
Logged

Walkinman

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 380
    • Skolai Images - Nature, Travel and Adventure stock photos
Re: Custom Title Tages for Albums/Categories?
« Reply #9 on: January 30, 2013, 11:20:23 am »

Ah, OK. Thanks. I'll mark this one closed.

Logged

Walkinman

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 380
    • Skolai Images - Nature, Travel and Adventure stock photos
Re: Custom Title Tages for Albums/Categories?
« Reply #10 on: December 29, 2013, 01:04:56 pm »

Hey Folks,

I've been trying to get rid of duplicate meta tag for description mentioned here, and I can't figure it out .. in my thumbnails.php file I have

Code: [Select]

// after that add
$meta_description = $CURRENT_ALBUM_DATA['meta_description'] ? $CURRENT_ALBUM_DATA['meta_description'] : $CURRENT_ALBUM_DATA['description'];
if ($meta_description)
{
    $meta_keywords .= '<meta name="description" content="' . htmlspecialchars($meta_description) . '" />' . $LINEBREAK;
}

$section = $CURRENT_ALBUM_DATA['page_title'] ? $CURRENT_ALBUM_DATA['page_title'] : $section;

pageheader($section, $meta_keywords);

and so I get two description tags in the html output ... see here

example.com/stock/thumbnails-2-Camping-photos.html

replace example.com with http://www.skolaiimages.com

I get

Code: [Select]
<meta name="description" content="Professional stock photos of camping, backcountry backpacking and hiking campsites, tentsites, tents, pictures from Georgia and the Appalachian Trail, Denali National Park and Wrangell St. Elias National Park in Alaska. Camping in the Arctic National Wildlife Refuge, ANWR, Alaska images." />
<meta name="description" content="Photos and images of campsites, tents, tentsites, backpackers, backpacking and camping. Backcountry campsites in Alaska, including ANWR (the Arctic National Wildlife Refuge, Denali and Wrangell - St. Elias National Parks), as well as the southern Appalachian mountains. .  Page 1 " />

The description content I actually want is the stuff in the first of these 2 tags .. it's not the description from the page, but a custom field to write a tag. however, whenever I delete one of those 2 sections in the above php code, from thumbnails.php, I always get the 2nd tag show up, the one ending in "Page 1" .. that's not what I want. I would like to be able to write a longer page description, and keep the meta tag shorter and customized to fit the page title a bit better.

I'm sorry to bring this up again. I thought I had fixed it but seemingly not .. this doesn't happen on the category pages, or image display pages, just the album display thumbnail pages.

I do get another meta tag from template.html I commented out, so I'm not worried about that. Once I resolve this I'll just delete it, rather than leave it commented.

I THINK I understand (kinda) what is going on; the code is calling the description, then saying if there is no description, it calls the 2nd one instead, is that correct? Is there somewhere else maybe, in another file, i need to modify something to fix this perhaps?

Thanks for your help.

Cheers

Carl
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: Custom Title Tages for Albums/Categories?
« Reply #11 on: December 30, 2013, 09:43:18 am »

As far as I can see stock Coppermine doesn't add
Code: [Select]
<meta name="description"to the HTML output. I assume you've installed a plugin which adds the second meta tag?
Logged

Walkinman

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 380
    • Skolai Images - Nature, Travel and Adventure stock photos
Re: Custom Title Tages for Albums/Categories?
« Reply #12 on: December 31, 2013, 12:01:21 am »

Ha ha .. nailed it . I'd forgotten all about that plugin, thanks. I uninstalled it and the problem seems resolved.

Thanks for your help, as always.

Cheers

Carl
Logged
Pages: [1]   Go Up
 

Page created in 0.024 seconds with 20 queries.