Gallery
SELECT * FROM yacs_images AS images WHERE (images.id = \'.preg_quote($origin)
1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\'.preg_quote($origin)' at line 1
SELECT * FROM yacs_images AS images WHERE (images.id = =\'.preg_quote($origin)
1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=\'.preg_quote($origin)' at line 1
After a bit of thought and looking at the code, I decided not to write an overlay as I would not be storing any additional data, but I have come up with a really simply solution !
I noticed the view_as_thread.php file in the articles folder, so I decided to make a view
My first challenge was to work out how to stop image thumbnails automatically into the article.
After looking at the code and following haow images are added (images/edit.php) I noticed that the image tag is added via the article object (which extends the anchor object), using the touch method. Which has required some modification to the article class.
First I created the is_gallery function (based on the is_interactive function).
function is_gallery() {
// section asks for galleries
if(isset($this->item['anchor']) && ($anchor = Anchors::get($this->item['anchor'])) && is_object($anchor) && $anchor->has_option('view_as_gallery'))
return TRUE;
// article has been configured to be viewed as a gallery
if(isset($this->item['options']) && preg_match('/\bview_as_gallery\b/i', $this->item['options']))
return TRUE;
// not a gallery
return FALSE;
}
Then I added a could of extra pieces of logic (highlighted):
} elseif($action == 'image:create') {
if(!$this->is_gallery() && !preg_match('/\[image=='.preg_quote($origin]/', $this->item['description'])) {
I did similar for $action == 'image:insert'. This prevents image tags been inserted automatically if we are to display as an image.
The next thing to do was to actually generate the image display code in view_as_gallery_traditional.php . I started by pulling out the chunk of code from articles/view.php from where the alternate renders as loaded (approx line 310).
The description only needs to be displayed on the first page. Paging functionality is stripped from the description (toc, toq) as the paging will be based on the number of images.
// only at the first page
if($page == 1) {
// the introduction text, if any
if(isset($item['introduction']) && trim($item['introduction']))
$text .= Skin::build_block($item['introduction'], 'introduction');
else
$text .= BR;
// get text related to the overlay, if any
if(is_object($overlay))
$text .= $overlay->get_text('view', $item);
// the beautified description
if(isset($item['description']) && trim($item['description'])) {
// remove toc and toq codes as they will conflict with gallery paging
$description = preg_replace('/\s*\(toc\s*/is', '', $item['description']);
// beautify the target page
$description = Codes::beautify($description, $item['options'])."\n";
// use adequate label
if(is_object($overlay) && ($label = $overlay->get_label('description')))
$text .= Skin::build_block($label, 'title').''.$description."
\n";
else
$text .= $description."\n";
}
}
Next thing to do is generate paging for the images, but this required getting the count of images in the article, luckily the functionality exists in the image class, so that is utilised as below.
// count images in the article
include_once '../images/images.php';
$stats = Images::stat_for_anchor('article:'.$item['id']);
if($stats['count'])
$text .= sprintf(i18n::ns('1 image', '%d images', $stats['count']), $stats['count']);
Then the actual code to generate the paging was written, modifying the paging for article/view.php with image specific parameters that I noted from images/index.php.
// the maximum number of images per page
if(!defined('IMAGES_PER_PAGE'))
define('IMAGES_PER_PAGE', 20);
// navigation commands for images, if necessary
if($stats['count'] > IMAGES_PER_PAGE) {
$page_menu = array( '_' => i18n::s('Pages') );
$home = Articles::get_url($item['id'], 'view', $item['title']);
$prefix = Articles::get_url($item['id'], 'navigate', 'pages');
$page_menu = array_merge($page_menu, Skin::navigate($home, $prefix, $stats['count'], IMAGES_PER_PAGE, $page));
$text .= Skin::build_list($page_menu, 'menu_bar')."\n";
}
The the actual code to generate the images in the article, again I used images/index.php as reference.
// the list of images
$offset = ($page - 1) * IMAGES_PER_PAGE;
if($items = Images::list_by_id_for_anchor('article:'.$item['id'], $offset, 50, NULL))
$text .= Skin::build_list($items, 'rows');
else
$text .= ''.i18n::s('No image has been uploaded yet.').'
';
I had to create a new function in the images class, list_by_id_for_anchor, as I wanted to list the images in the order they are added. This is based on an existing function list_by_date_for_anchor and changing the orderby part of the query.
So that's the major parts of functionality out of the way. I can now concentrate on layout, I will be modifying the skin class (skin_skeleton.php), then we should have a beta version ready for testing.
Cheers, Nick
Files
| Gallery Beta 56,552 bytes, 84 downloads This is YACS Image Gallery Beta. Edited by N1ckR on June 5 Zoom |
Comments
| Bernard from nearby-an-airport Associate, 6796 posts | Very good job indeed. And I'm glad to see that the rigorous structure of YACS code is proving rather helpful... Would this be fully available for release 8.3, due end of March? |
NickR![]() from West Yorkshire, UK 337 posts | Yes, the code is well structured, so it did not take long to find the pieces of code I required. I am hoping to have the basic skinning code ready early next week. Then allow a bit of time for testing and tweaking on my site and it should be ready for you mid-March. Nick My Website: NGR78 |
N1ckR![]() from West Yorkshire, UK 337 posts | Beta Code is here and ready for integrating/testing. It is based on the 8.4 beta code. Only thing missing is a section overlay, which will not need integrating, hopefully I can get that done tonight. Nick NGR78 Money Traffic Blog |
| Bernard from nearby-an-airport Associate, 6796 posts |
N1ckR: sorry but this has arrived too late for the 8.5 release. I will look at this important contribution for the 8.7 release probably. Many thanks for this! |
Rate this page
Posted by NickR on Feb. 26, commented by Bernard on June 8, (popular)
