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

Link to country flags does not work correctly when embedding Piwik in PHP site #5674

Closed
anonymous-matomo-user opened this issue Jun 13, 2008 · 13 comments
Labels
Bug For errors / faults / flaws / inconsistencies etc. Major Indicates the severity or impact or benefit of an issue is much higher than normal but not critical.
Milestone

Comments

@anonymous-matomo-user
Copy link

I have embedded Piwik to my PHP site and I’m calling Piwik from PHP code directly.

In the code Piwik checks whether file exists:

```
function Piwik_getFlagFromCode($code)
{
$path = ‘plugins/UserCountry/flags/%s.png’;
$normalPath = sprintf($path,$code);
// flags not in the package !
if(!file_exists($normalPath))
{
return sprintf($path, ‘xx’);
}
return $normalPath;
}
```

The PHP file where I’m calling Piwik locates in different folder. Really flag file exists but this function can’t locate it and returns ‘xx’ value.

I have solved this problem just by commenting IF section. But you have to invent something to make it more intelligent.

Thanks,
Anton Andriyevskyy
Keywords: flag flags country countries

@robocoder
Copy link
Contributor

Is it as simple as changing it to use an absolute path? e.g.,

```
$path = dirname($SERVER[’SCRIPTFILENAME’]) . “/flags/%s.png”;
```

@robocoder
Copy link
Contributor

Attachment: updated patch
[254.patch](http://issues.piwik.org/attachments/5674/254.patch)

@mattab
Copy link
Member

mattab commented Jan 14, 2009

vipsoft, can you please confirm that you have tested the patch with the use case meglio mentionned? thanks

@robocoder
Copy link
Contributor

Yes, tested before (i.e., got “xx.png”) and after (e.g., getting “us.png”).

@robocoder
Copy link
Contributor

Attachment: test file
[testing.php](http://issues.piwik.org/attachments/5674/testing.php)

@mattab
Copy link
Member

mattab commented Jan 14, 2009

vipsoft, instead of dirname(FILE) we could use PIWIK_INCLUDE_PATH right?

@robocoder
Copy link
Contributor

I was thinking there might be a corner case that failed where PIWIK_INCLUDE_PATH was a relative path, but I just tested that scenario manually and it worked correctly.

So yeah, use PIWIK_INCLUDE_PATH instead, e.g.,

```
$path = PIWIK_INCLUDE_PATH . “/plugins/UserCountry/flags/%s.png”;
```

I’ll see if I can add a test case.

@robocoder
Copy link
Contributor

Attachment:
[UserCountry.test.php](http://issues.piwik.org/attachments/5674/UserCountry.test.php)

@mattab
Copy link
Member

mattab commented Jan 14, 2009

Perfect vipsoft: it’s a very good reflex to add test cases, or update existing test files. Fixed in 881

@robocoder
Copy link
Contributor

matt: please revert this patch; I broke the flag icons on the UI where it expects Piwik_getFlagFromCode() to return a relative path to the image file

@robocoder
Copy link
Contributor

Attachment: Patch against svn
[functions.diff](http://issues.piwik.org/attachments/5674/functions.diff)

@robocoder
Copy link
Contributor

Matt: this patch can be committed too

@robocoder
Copy link
Contributor

committed in 885

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc. Major Indicates the severity or impact or benefit of an issue is much higher than normal but not critical.
Projects
None yet
Development

No branches or pull requests

3 participants