Customizing single-page view

The single-page view is a bit of a neglected child. Its main purpose is to provide a static link to an image that can be easily shared on social media. But there is more!

With Backlight 2 and later, the internal classes photo and album are exposed now.

// Parses texts and replaces text links with real URLs. Used to display them in single-page view.
function to_url($text) {
   return preg_replace('@(http)?(s)?(://)?(([-\w]+\.)+([^\s]+)+[^,.\s])@', '<a href="http$2://$4">$1$2$3$4</a>', $text);
}

function single_bottom() {
   if ($this->hasPhoto()) {
      echo '<p>';
      echo '<strong>Image Infos:</strong><br/>';
      echo 'Filename: '.$this->photo->getFilename().'<br/>';
      echo 'Dimensions: '.$this->photo->getPhotoHeight().'w x '.$this->photo->getPhotoHeight().'h<br/>';
      echo 'Title: '.$this->photo->getMetadata(Photo::$PHOTO_TITLE).'<br/>';
      echo 'Caption: '.$this->to_url($this->photo->getMetadata(Photo::$PHOTO_CAPTION)).'<br/>';
      echo 'Metadata 1: '.$this->to_url($this->photo->getMetadata("metadata_one")).'<br/>';
      echo 'Metadata 2: '.$this->to_url($this->photo->getMetadata("metadata_two")).'<br/>';
      if (hasLocation()){
         echo 'Latitude: ' . $this->photo->getLatitude(() .' ';
         echo 'Longitude: ' .  $this->photo->getLongitude(() .' ';
         echo '<a href="'. $this->photo->getMapsURL() .'>Map</a>';
      } else {
         echo 'No location data';
      }
      echo '</p>';
   }

   echo '<strong>Parent album infos:</strong>';
   echo '<p>';
   echo 'Album title: '.$this->album->getTitle().'<br/>';
   echo 'Description: '.$this->album->getDescription().'<br/>';
   echo 'Slug: '.$this->album->getSlug().'<br/>';
   echo 'Number of photos : '.$this->photo->album->getNumberOfPhotos().'<br/>';
   echo '</p>';

   return true;
} 

Did you like this post? Did you use the given code? Please consider supporting me by buying me a coffee!

Buy Me A Coffee


Thanks!

2 thoughts on “Customizing single-page view”

    1. Yes, this would be part of your phplugins file. Obviously, you would need to modify it according to your preferences.

      Maybe just

      function single_bottom() {
      if ($this->hasPhoto()) {
      echo ‘<p>
      echo ‘Title: ‘.$this->photo->getMetadata(Photo::$PHOTO_TITLE).'<br/>’;
      echo ‘Caption: ‘.to_url($this->photo->getMetadata(Photo::$PHOTO_CAPTION)).'<br/>’;
      echo ‘</p>’;
      return true;
      }

Leave a Reply

Your email address will not be published. Required fields are marked *

Web Design Consulting

Do you need help designing your web site or getting Backlight working the way you want? Contact me to discuss your idea or project.


Buy me a Coffee

If you like what I share here, please consider buying me a coffee or a print. This helps keeping me motivated to continue posting. Thank you!

Buy Me A Coffee

Categories