Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

logo images not displayed

jackmaessenjackmaessen ✭✭✭
edited December 2014 in Vanilla 2.0 - 2.8

I have a problem with displaying the images. The logo images from all the browsers should be loaded but they don't.
I only see the [?] in the right corner.
Can someone tell me why these logos are not displayed at the right top corner?
http://forum.webprofis.nl/discussion/292/increment#latest

  /**
   * Output user agent information.
   */
  protected function AttachInfo($Sender, $Attributes) {
    $Info = null;
    # Vanilla 2.1 - comment model passes in serialized string - fixed in https://github.com/vanilla/vanilla/commit/7e86195f0c5ddaf42a5a281341176e5ab2de9de0
    if (is_string($Attributes)) {
      $Attributes = unserialize($Attributes);
    }
    $UserAgent = GetValue('UserAgent', $Attributes);
    $Browser = GetValue('Browser', $Attributes);
    if ($UserAgent) {
      if ($Browser) {
        $Logo = $this->Logos[$Browser];
        if ($Logo) {
          $Info = Img($this->GetResource('logos/'.$Logo, FALSE, FALSE), array('alt' => htmlspecialchars($Browser)));
        } else {
          $Info = htmlspecialchars($Browser);
        }
      }
      If (!$Info) {
        //$Info = '[?]'; // this is the original line, but instead of ? load default browserimage below
        $Info = Img($this->GetResource('logos/browser_default.png'));
      }

      echo Wrap($Info, 'span', array('class' => 'MItem UserAgent', 'title' => htmlspecialchars($UserAgent)));
    }
  }
}

I already tried to change the [?] for a general browser image but even that image is not loaded.
The path: http://forum.webprofis.nl/plugins/UserAgent/logos/browser_default.png

Comments

  • try

    if ($Logo) {
              $Info = Img('/plugins/UserAgent/logos/' .$Logo, array('alt' => htmlspecialchars($Browser)));
            } else {
              $Info = htmlspecialchars($Browser);
            }
    

    or

    if ($Logo) {
              $Info = Img('plugins/UserAgent/logos/' .$Logo, array('alt' => htmlspecialchars($Browser)));
            } else {
              $Info = htmlspecialchars($Browser);
            }
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • jackmaessenjackmaessen ✭✭✭
    edited December 2014

    I think he isn't catching the useragent at all; when i echo useragent
    echo $UserAgent , this is the output: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36

  • about previous post: I was testing with Chrome browser. So i am outraged that browsing with Chrome, Mozilla en Safari are also in the output

  • peregrineperegrine MVP
    edited December 2014

    So i am outraged

    Did you follow the instructions properl?

    are sure you installed browscap.ini properly?

    the plugin works perfectly fine without any changes as far as my testing, as long as you set up browsecap properly

    create a test file to see if you see an array or values. if you don't your browscap is not working.

    browsercap-test.php and run it from your browser.

    <?php
    echo $_SERVER['HTTP_USER_AGENT'] . "\n\n";
    
    $useragent = $_SERVER['HTTP_USER_AGENT'];
    
    $browser = get_browser($useragent, true);
    
    echo "do you see an array of values below?";
    
    print_r($browser);
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • @jackmaessen said:
    about previous post: I was testing with Chrome browser. So i am outraged that browsing with Chrome, Mozilla en Safari are also in the output

    Mozilla is almost always in the User Agent String for historical reasons:
    http://en.wikipedia.org/wiki/User_agent#Format_for_human-operated_web_browsers

  • peregrineperegrine MVP
    edited December 2014

    http://browscap.org/

    you can get browscap.in files from here. and then modify your php_ini or httpd.conf to make sure it is properly being used.

    that said: seems like its not worth adding the memory consumption for such a trivial info, unless there is a real need to see browser info.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • peregrineperegrine MVP
    edited December 2014

    If you don't want to mess with browscap. and use a very simplistic routine.

    here is a simple change.

    change in two places in file

    $this->AttachInfo($Sender, $Attributes);
    

    to ...

    $this->SimpleAttachInfo($Sender, $Attributes);

    then add this

        protected function SimpleAttachInfo($Sender, $Attributes) {
    
    
           if (is_string($Attributes)) {
              $Attributes = unserialize($Attributes);
            }
    
            $UserAgent = $Attributes["UserAgent"];
    
                $Browser = "";      
                if(strpos($UserAgent, 'Firefox') > 0 ) {
                 $Browser = "Firefox";
                 } 
                if(strpos($UserAgent, 'Safari') > 0 ) {
                 $Browser = "Safari";
                 }
                if (strpos($UserAgent, 'Chrome') >0 ) {
                 $Browser = "Chrome";
                 }
                if (strpos($UserAgent, 'Chromium') > 0) {
                 $Browser = "Chromium";
                 }
                if (strpos($UserAgent, 'IE') > 0 ) {
                 $Browser = "IE";
                 }
                if (strpos($UserAgent, 'Opera') > 0 ) {
                 $Browser = "Opera";
                 }
    
              if ($Browser) {
                  $Info = Img('/plugins/UserAgent/logos/' . strtolower($Browser) . ".png", array('alt' => htmlspecialchars($Browser)));
    
              echo Wrap($Info, 'span', array('class' => 'MItem UserAgent', 'title' => htmlspecialchars($UserAgent)));
            }
          }
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • @peregrine i copied code above and i put it in useragent3.php
    forum.webprofis.nl/test/useragent3.php
    I do not see any values below :(

  • oke i will try your modified code

  • peregrineperegrine MVP
    edited December 2014

    obviously it will only work with new postings and the if's may need to be reorganized and some strings may need to be changed. if you have an issue post the useragent you have trouble with.

    I just tested it on Firefox.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • I see this on your forum

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Works great! @peregrine Thanks again for support :D

  • jackmaessenjackmaessen ✭✭✭
    edited December 2014

    for IE and Opera i did not get an icon, but i already found the solution: I can catch them with Trident and OPR

     if (strpos($UserAgent, 'Trident') > 0 ) { // instaed of IE
        $Browser = "IE";
        }
        if (strpos($UserAgent, 'OPR') > 0 ) {  // instead of Opera
        $Browser = "Opera";
        }
    
  • Sorry, I didn't see this thread until now.

    But yes, you definitely need to install browsecap for this to work as intended. Or you can implement your own "what browser is this user agent?" logic per above.

Sign In or Register to comment.