Not signed in (Sign In)

Vanilla 1.1.10 is a product of Lussumo. More Information: Documentation, Community Support.

    •  
      CommentAuthormemic.a
    • CommentTimeAug 23rd 2008
     
    Hi,

    I enabled the Cruft-Free URLs in plogger and all working fine.
    When i open a picture The URLs are now like this: mysite.net/collection/album/filename

    Question:
    Is it possible to change the URL from
    "mysite.net/collection/album/filename" into
    "mysite.net/collection/album/file caption"

    Because I have a lot of files that have only numbers in the name.
    example, i would like to change
    mysite.net/collection/album/01-254_001 into mysite.net/collection/album/mountains

    Is this possible??
    Thank you
    •  
      CommentAuthormemic.a
    • CommentTimeAug 24th 2008
     
    Sidtheduck have you a quick fix for this??
    •  
      CommentAuthorkimparsell
    • CommentTimeAug 24th 2008
     
    memic.a -

    Sidtheduck should be back here tomorrow to answer your question.
    •  
      CommentAuthorsidtheduck
    • CommentTimeAug 24th 2008
     
    memic.a,

    Are you using the Beta3 version, or a newer SVN version?
    •  
      CommentAuthormemic.a
    • CommentTimeAug 25th 2008
     
    Hi, I'm using the beta 3 version.
    •  
      CommentAuthorsidtheduck
    • CommentTimeAug 25th 2008
     
    Okay memic.a, this will be a 3-step process (all within the file plog-functions.php).

    Step 1:
    Add a new function called get_caption_filename() with the following code:
    function get_caption_filename($row, $extension = true) {
    // Check for caption, use this instead of filename if it exists!
    if (!empty($row["caption"]) > 0) {
    $picture_name = $row["caption"];
    } else {
    $picture_name = basename($row["path"]);
    if ($extension === false) {
    $picture_name = substr($picture_name, 0, -4);
    }
    }

    return $picture_name;
    }


    Step 2:
    Edit the function generate_url() like so (starting around line 1067) from:
    } else if ($level == "picture") {
    $pic = get_picture_by_id($id);
    $album = $pic["parent_album"];
    $rv = $config["baseurl"].$pic["path"];
    }

    to this:
    } else if ($level == "picture") {
    $pic = get_picture_by_id($id);
    $album = get_album_by_id($pic["parent_album"]);
    $collection = get_collection_by_id($pic["parent_collection"]);
    $rv = $config['baseurl'].$collection['path'].'/'.$album['path'].'/'.sanitize_filename(get_caption_filename($pic, false))."/";
    }


    Step 3:
    Edit the function resolve_path() like so (starting around line 957) from:
    if (!empty($names["picture"])) {
    $sql = "SELECT *
    FROM `".TABLE_PREFIX."pictures`
    WHERE `caption`='".mysql_real_escape_string($names["picture"])."'
    AND `parent_album`=".intval($album["id"]);
    $result = run_query($sql);

    to this:
    if (!empty($names["picture"])) {
    $sql = "SELECT *
    FROM `".TABLE_PREFIX."pictures`
    WHERE `caption` LIKE '".mysql_real_escape_string($names["picture"])."'
    AND `parent_album`=".intval($album["id"]);
    $result = run_query($sql);


    That should do it for you! Let me know if you run into issues.
    Thankful People: memic.a
    •  
      CommentAuthormemic.a
    • CommentTimeAug 25th 2008
     
    Thank you for spending your time to help me!

    I added the function and I changed the code you tell me.
    Now when a open an album the URLs of the thumbnails are like I wanted (with the caption) but if I click on them it don't open the picture page but it return to the same album page, seems like I refresh the page.

    example:
    mysite.net/gallery/collection/album display an album with new format of links with the caption instead of file name
    when I click on a link like this
    mysite.net/gallery/collection/album/picture-caption it don't open the picture page but again the album page.

    Maybe I have to change something in the .htaccess file?
    •  
      CommentAuthorsidtheduck
    • CommentTimeAug 25th 2008
     
    2 questions:

    1. Do you have a link to this updated installation?
    2. Did you alter your sanitize_filename function previously?
    •  
      CommentAuthormemic.a
    • CommentTimeAug 25th 2008
     
    Here is my sanitize_filename function

    function sanitize_filename($str) {
    // allow only alphanumeric characters, hyphen, [, ], dot in file names
    // the rest will be replaced
    $str = preg_replace(array("/['|\"]/", "/[^\w|\.|\-|\[|\]]/"), array("", "-"), $str);
    return $str;
    }


    I think I changed something in there but don't remember what
    •  
      CommentAuthormemic.a
    • CommentTimeAug 25th 2008
     
    I forgot here is the link
    gallery
    •  
      CommentAuthorsidtheduck
    • CommentTimeAug 25th 2008
     
    Yeah, you changed your sanitize_filename function to use hyphens (-) instead of underscores (_), which is better for SEO optimization so I understand why you want that.

    To fix this, change my step3 above to this:
    Step 3:
    Edit the function resolve_path() like so (starting around line 957) from:
    if (!empty($names["picture"])) {
    $sql = "SELECT *
    FROM `".TABLE_PREFIX."pictures`
    WHERE `caption`='".mysql_real_escape_string($names["picture"])."'
    AND `parent_album`=".intval($album["id"]);
    $result = run_query($sql);

    to this:
    if (!empty($names["picture"])) {
    $sql = "SELECT *
    FROM `".TABLE_PREFIX."pictures`
    WHERE `caption` LIKE '".mysql_real_escape_string(str_replace("-", "_", $names["picture"]))."'
    AND `parent_album`=".intval($album["id"]);
    $result = run_query($sql);


    The reason it is having trouble is that MySQL uses underscores (_) as a wildcard character when using a LIKE query (which is how the old sanitize_filename worked). Change the above and it should work out for you.
    •  
      CommentAuthormemic.a
    • CommentTimeAug 25th 2008
     
    ok, thanks.
    I will try it tomorow and I'll let you know.
    •  
      CommentAuthormemic.a
    • CommentTimeAug 25th 2008 edited
     
    Thank you!

    All ok, it's working fine.