Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong URL created for image in map - wrong category used #74

Closed
ThomasDaheim opened this issue Nov 9, 2015 · 9 comments
Closed

Wrong URL created for image in map - wrong category used #74

ThomasDaheim opened this issue Nov 9, 2015 · 9 comments

Comments

@ThomasDaheim
Copy link
Contributor

Hi,

when looking at an album on my site (e.g. http://www.feuster.com/piwigo/index.php?/category/651) and clicking on a marker in the map to show a thumb I can see that the link created is incorrect:

http://www.feuster.com/piwigo/picture.php?/6675/category/630

where it should be

http://www.feuster.com/piwigo/picture.php?/6675/category/651

Note, that in the map the incorrect category is used in the link! A quick scan indicates that this happens in all albums.

In idea how to fix this?

Thanks,
Thomas

@ThomasDaheim
Copy link
Contributor Author

More info:

This seems to happen because I have a category with this name twice in piwigo: one from uploading and one from converting to virtual later on.
I show use the virtual one but the link in the osm map is to the intial, uploaded one.
Seems like the SQL to look up the images/categories doesn't use the current category id correctly/not at all?

@ThomasDaheim
Copy link
Contributor Author

Getting closer... In functions_map.php the query is using "i.storage_category_id" to create the imageurl to be used as link in the popup:

    $query="SELECT i.latitude, i.longitude,
    IFNULL(i.name, '') AS `name`,
    IF(i.representative_ext IS NULL,
        CONCAT(SUBSTRING_INDEX(TRIM(LEADING '.' FROM i.path), '.', 1 ), '-sq.', SUBSTRING_INDEX(TRIM(LEADING '.' FROM i.path), '.', -1 )),
        TRIM(LEADING '.' FROM
            REPLACE(i.path, TRIM(TRAILING '.' FROM SUBSTRING_INDEX(i.path, '/', -1 )),
                CONCAT('pwg_representative/',
                    CONCAT(
                        TRIM(TRAILING '.' FROM SUBSTRING_INDEX( SUBSTRING_INDEX(i.path, '/', -1 ) , '.', 1 )),
                        CONCAT('-sq.', i.representative_ext)
                    )
                )
            )
        )
    ) AS `pathurl`,
    TRIM(TRAILING '/' FROM CONCAT( i.id, '/category/', IFNULL(i.storage_category_id, '') ) ) AS `imgurl`,
    IFNULL(i.comment, '') AS `comment`,
    IFNULL(i.author, '') AS `author`,
    i.width
        FROM ".IMAGES_TABLE." AS i
            INNER JOIN (".IMAGE_CATEGORY_TABLE." AS ic ".$INNER_JOIN.") ON i.id = ic.image_id
            WHERE ".$LIMIT_SEARCH." i.latitude IS NOT NULL AND i.longitude IS NOT NULL ".$forbidden." GROUP BY i.id;";

And that gives another result as the link that is used for the list of thumbs below the map!

@ThomasDaheim
Copy link
Contributor Author

Which lead to this quick-hack to use the category of the page if set:

    // TF, 20151111
    // use category of $page['category']['id'] if available
    $usecategory = "IFNULL(i.storage_category_id, '')";
    if (isset($page['category']) and isset($page['category']['id']) and strlen(($page['category']['id'])>0))
    {
        $usecategory = $page['category']['id'];
    }

    $query="SELECT i.latitude, i.longitude,
    IFNULL(i.name, '') AS `name`,
    IF(i.representative_ext IS NULL,
        CONCAT(SUBSTRING_INDEX(TRIM(LEADING '.' FROM i.path), '.', 1 ), '-sq.', SUBSTRING_INDEX(TRIM(LEADING '.' FROM i.path), '.', -1 )),
        TRIM(LEADING '.' FROM
            REPLACE(i.path, TRIM(TRAILING '.' FROM SUBSTRING_INDEX(i.path, '/', -1 )),
                CONCAT('pwg_representative/',
                    CONCAT(
                        TRIM(TRAILING '.' FROM SUBSTRING_INDEX( SUBSTRING_INDEX(i.path, '/', -1 ) , '.', 1 )),
                        CONCAT('-sq.', i.representative_ext)
                    )
                )
            )
        )
    ) AS `pathurl`,
    TRIM(TRAILING '/' FROM CONCAT( i.id, '/category/', ".$usecategory." ) ) AS `imgurl`,
    IFNULL(i.comment, '') AS `comment`,
    IFNULL(i.author, '') AS `author`,
    i.width
        FROM ".IMAGES_TABLE." AS i
            INNER JOIN (".IMAGE_CATEGORY_TABLE." AS ic ".$INNER_JOIN.") ON i.id = ic.image_id
            WHERE ".$LIMIT_SEARCH." i.latitude IS NOT NULL AND i.longitude IS NOT NULL ".$forbidden." GROUP BY i.id;";

@ThomasDaheim
Copy link
Contributor Author

Well above is only a quick-hack that works in some cases. Root cause of the issue is that i.storage_category_id isn't OK to use since it might be in the list of categories returned by get_sql_condition_FandF!
Better to use the result of the inner join to the category table where the $forbidden categories are filtered out...

@ThomasDaheim
Copy link
Contributor Author

And here is the solution to use the INNER JOIN result:

Use ic.category_id instead of i.storage_category_id as category for creating the imgurl

ThomasDaheim added a commit to ThomasDaheim/piwigo-openstreetmap that referenced this issue Dec 5, 2015
i.storage_category_id might be in the list of $forbidden categories, use
ic.category_id instead
@ThomasDaheim
Copy link
Contributor Author

Pull request created for fix

xbgmsharp added a commit that referenced this issue Dec 6, 2015
xbgmsharp added a commit that referenced this issue Dec 6, 2015
@xbgmsharp
Copy link
Collaborator

Thanks for all the analyze and pointing the bug.
Pull request #85 merged.
Fully merger via #86

xbgmsharp added a commit that referenced this issue Dec 6, 2015
@ThomasDaheim
Copy link
Contributor Author

Your welcome

ThomasDaheim referenced this issue in ThomasDaheim/piwigo-openstreetmap Jan 2, 2016
# Conflicts:
#	include/functions_map.php
@IT-Sumpfling
Copy link

It seems like this issue got "re-introduced" - at least I had the problem in 2.8a and was able to fix it by changing the relevant line in functions_map.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants