Weird problem → google picasa feed & nette.ajax

Notice: This thread is very old.
Václav Novotný
Member | 13
+
0
-

Hi,
I want to load photos from google picasa albums via XML feed. I load data from all public photos from one user and then I want display only albums related with viewing content. At some pages/views, it works well, but I have problem with one case, where i get error 500 - Internal Server Error, and I cannot solve it for quite couple of hours now.

Strangely, when I write test code outside of nette, without using of ajax etc., just the pure PHP processing mechanism, it works good. Unluckily, I'm begginer, so I dont have much experience with debuging tools and now I even have no clue, where might be the problem. So any advice is welcome.

I'll put here my problematic code (only problematic part) as is, even with link to user albums. It contains pictures of some glass products etc. == no sensitive data.

PRESENTER

public function renderDefault()
    {
      //default value for language
      if ($this->lang === NULL)
        $this->lang = 'en';

      //default values for picasa image size
      if ($this->thumb_size === NULL)
          $this->thumb_size = 150;

      if ($this->full_size === NULL)
          $this->full_size = 720;

      //set tab content or dump array, if all tabs are closed (if handleTabs never triggers)
      if ($this->tab === NULL) {
        $tab = array('id' => 0, 'text' => '');
        $images = false;
      } else {
        //get content from database
        $tab = $this->database->table('tabs')->get($this->tab);
        //get album IDs to this tab content from database
        $albums = json_decode($tab['albumID']);
        //load XML from google picasa, containing album IDs, photo titles and photos src
        $userId = '102879954808276235711';
        $images = simplexml_load_file('http://picasaweb.google.com/data/feed/base/user/'
                                      .$userId
                                      .'?kind=photo&fields=entry(id,title,content/@src)');
        $images = $images->entry;
        for ($i = count($images) - 1; $i >= 0; $i--) {
          //shorten full path to album to just 19 digit album ID number
          $images[$i]->id = substr($images[$i]->id, strpos($images[$i]->id, 'albumid/') + 8, 19);
          //unset photos from albums, that we dont want to display
          if (array_search($images[$i]->id, $albums) === false)
            unset($images[$i]);
        }
        $images = (empty($images)) ? false : $images;
      }
      $this->template->tabContent = $tab;
      $this->template->images = $images;
      $this->template->tsize = $this->thumb_size;
      $this->template->fsize = $this->full_size;
    }

TEMPLATE

{block #content}
<div id="tabContainer">
    {snippet tabContent}
    <ul id="tabs">
        {foreach $tabs as $tab}
          <li class="tab{if ($tab['id'] === $tabContent['id'])} active{/if}" id="tab_{$tab['id']}">
            <a href="{link tabs!, $tab['id']}" class="ajax">
              {$tab['title']}
            </a>
          </li>
        {/foreach}
    </ul>

    <div id="tabContent">
      {!$tabContent['text']}
      <div n:if="$images" id="gallery">
        <img n:foreach="$images as $image"
          src="{$image->content->attributes()->src|crop:$tsize}" <!--custom helper sets size and crop image to square-->
          alt="{$image->title}"
        />
      </div>
  </div>
  {/snippet}
</div>
{/block}

For dynamic loading of tab content I use jQuery 1.9.1 and nette.ajax 1.2.2. When I load tab with images from other albums, than (albumID: 5927213289295143921), it works, so I have problems with this one album, but, if i rewrite processing mechanism into single PHP file, it runs without problem, you can try it with this code:

<?php
$albumID = '["5927213289295143921","5927488241704544625","5927486244080166977"]';
$albums = json_decode($albumID);
$userId = '102879954808276235711';
$images = simplexml_load_file('http://picasaweb.google.com/data/feed/base/user/'
                              .$userId
                              .'?kind=photo&fields=entry(id,title,content/@src)');
$images = $images->entry;
for ($i = count($images) - 1; $i >= 0; $i--) {
  //shorten full path to album ID/photo to just 19 digit album ID number
  $images[$i]->id = substr($images[$i]->id, strpos($images[$i]->id, 'albumid/') + 8, 19);
  //unset photos from albums, that we dont need to load
  if (array_search($images[$i]->id, $albums) === false)
    unset($images[$i]);
}
print_r($images);
echo '<br />';
foreach ($images as $image) {
  echo '<img';
  echo ' src="' . $image->content->attributes()->src . '"';
  echo ' alt="' . $image->title . '"';
  echo ' />';
}

Do you have suspicion, what could cause that error 500: internal server error? Because I'm out of bullets.

Thanks in advance

Last edited by Václav Novotný (2013-10-02 17:15)

Eda
Backer | 220
+
0
-

Show us bugreport which is generated by this error. (See log/ directory.)

Václav Novotný
Member | 13
+
0
-

Wow, so laděnka works like in production mode when ajax call is triggered. That's cool! I looked in log folder (that didn't cross my mind before) and I found that problem was in custom helper in combination with czech filename – I used preg_match and metacharacter \w for all ‘word characters’, but this metacharacter is english only, so id didn't match czech word. No it's solved. Thank YOU!