Search

Over on Flickr, Bjorn wrote:

Hi Brian,

Sorry to bother you, but I would like to ask you something about how you integrated your Flickr stream into your Symphony CMS site. At the moment I’m trying to implement something similar to what you did.

I have created a dynamic xml source to grab the flickr feeds, which is working fine. But I’m interested in how you integrated the pagination. Did you use the DS pagination by Nick/Nils?

Thanks for your time, Bjorn

Hi Bjorn,

I’ll do my best to explain it. I don’t think it’s too complicated, but I’ve never tried documenting my Symphony projects. Hopefully this will make sense.

As you mentioned, I started with a Dynamic Datasource, like this:

URL

http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=[your_api_key]&user_id=[your_user_id]&page={$url-p}

Included Elements

/rsp/photos

Once it’s attached to my page, I have a template like this (HTML5, edit as needed):

<xsl:template match="photos">
    <nav>
        <xsl:call-template name="pagination">
            <xsl:with-param name="pagination" select="//photos" />
            <xsl:with-param name="pagination-url" select="concat(substring-before($current-page,'/'),'?p=$')" />
        </xsl:call-template>
    </nav>
</xsl:template>

Also attached to the page is a Flickr pagination utility. I never updated the comments, but it is a modified version of Nick’s pagination utility.

I’m using the query string for the pagination count, but now I wish I’d used a parameter. Someday I’ll get around to changing it.

Hi Brian,

Thanks for your response. In the end, while waiting for your response, I went with another solution, which doesn’t require a modified pagination utility. You have to edit your datasource file, and make your grab() function look something like this:

 <?php

// yadda

public function grab(&$param_pool=NULL){
        $result = new XMLElement($this->dsParamROOTELEMENT);

        try{
                include(TOOLKIT . '/data-sources/datasource.dynamic_xml.php');
        }
        catch(FrontendPageNotFoundException $e){
                // Work around. This ensures the 404 page is displayed and
                // is not picked up by the default catch() statement below
                FrontendPageNotFoundExceptionHandler::render($e);
        }
        catch(Exception $e){
                $result->appendChild(new XMLElement('error', $e->getMessage()));
                return $result;
        }

        // add pagination element
        preg_match('/<photos page="(?P<page>d+)" pages="(?P<pages>d+)" perpage="(?P<perpage>d+)" total="(?P<total>d+)">/', $result->getValue(), $matches);

        $result->appendChild(new XMLElement('pagination', NULL, array(
                'total-entries' => $matches['total'],
                'total-pages' => $matches['pages'],
                'entries-per-page' => $mathces['perpage'],
                'current-page' => $matches['page'],
        )));

        if($this->_force_empty_result) $result = $this->emptyXMLSet();
        return $result;
}

// yadda

?>

I don’t know if this is recommended or not, but it works fine. It adds a pagination element to the result, which can be used by the pagination utility by Nick and Nils.

Thanks for your help though,

  • Bjorn

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details