Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2008-09-04 22:57:16
- gfxx
- Member
- Registered: 2008-09-04
- Posts: 12
I added the possibility of spreading images over pages to upm_image
Hi,
I just would like to post my idea, just in case somebody needs it or whatever. Its not perfect, but works fine for me.
I added a config var:
$atts = lAtts(array( ‘break’ => ‘’, ‘break_class’ => ‘’, ‘class’ => ‘’, ‘form’ => ‘’, ‘id’ => ‘’, ‘limit’ => ‘’, ‘offset’ => 0, ‘show_width’ => ‘yes’, ‘show_height’ => ‘yes’, ‘show_alt’ => ‘yes’, ‘show_title’ => ‘yes’, ‘type’ => ‘image’, ‘url’ => ‘’, ‘wrapform’ => ‘’, ‘wraptag’ => ‘’, ‘xhtml’ => ‘yes’, ‘pictures_per_page’ => ‘’ ), $atts);
limit and offset are dynamically set:
function upm_article_image_list($article_image, $atts, $thing = NULL) { global $prefs;
extract($atts);
$out = array();
// This is a hack to add the possiblity to spread pictures over several pages … if ( is_numeric($atts[‘pictures_per_page’]) ) {if ( is_numeric($_GET[“upm_page_number”]) && ( $_GET[“upm_page_number”] > 0 ) ) {
$upm_page_number = $_GET[“upm_page_number”];
}
else {
$upm_page_number = 1;
}
$limit = $atts[‘pictures_per_page’];
if ($offset > 0) {
$offset = $offset + ( ($upm_page_number – 1) * $atts[‘pictures_per_page’] );
} }
// End Hack
if ($limit) { $images = array_slice(explode(‘,’, $article_image), $offset, $limit); }
And I also output backward/forward links…
// This is a hack to add the possiblity to spread pictures over several pages … function upm_image_make_forward_link($atts = array()) {
$atts = lAtts(array( ‘pictures_per_page’ => ‘’, ‘offset’ => ‘’ ), $atts);
if ( is_numeric($_GET[“upm_page_number”]) && ( $_GET[“upm_page_number”] > 0 ) ) {
$upm_page_number = $_GET[“upm_page_number”];
}
else {
$upm_page_number = 1;
}
$pictures_per_page = $atts[‘pictures_per_page’];
$article_images = $GLOBALS[‘thisarticle’][‘article_image’]; $number_of_images = count(explode(‘,’, $article_images));
$upm_limit = $upm_page_number * $pictures_per_page;
if ($atts[‘offset’] > 0) {
$upm_offset = $atts[‘offset’] + ( ($upm_page_number – 1) * $atts[‘pictures_per_page’] );
} else {
$upm_offset = ($upm_page_number – 1) * $pictures_per_page;
}
$upm_next_page = $upm_page_number + 1; $upm_previous_page = $upm_page_number – 1; $query_string = $_SERVER[‘QUERY_STRING’];
$pattern = ‘/upm\_page\_number\=\d+/’; $url = $GLOBALS[‘prefs’][‘siteurl’] . ‘/index.php?’;
if (strstr($query_string, ‘upm_page_number=’)) {
$query_string_backward = preg_replace($pattern, ‘upm_page_number=’ . $upm_previous_page, $query_string); $query_string_forward = preg_replace($pattern, ‘upm_page_number=’ . $upm_next_page, $query_string);
} else {
$query_string_backward = 0; $query_string_forward = $query_string . ‘&upm_page_number=2’; }
if ( ($upm_page_number * $pictures_per_page) < ( $number_of_images – $atts[‘offset’] ) ) {
return ‘<a href=“http://www.’ . $url . $query_string_forward . ‘”>’ . $atts[‘link_text’] . ‘</a>’;
}
}
// This is a hack to add the possiblity to spread pictures over several pages … function upm_image_make_backward_link($atts = array(), $thing = NULL) {
$atts = lAtts(array( ‘pictures_per_page’ => ‘’, ‘offset’ => ‘’ ), $atts);
if ( is_numeric($_GET[“upm_page_number”]) && ( $_GET[“upm_page_number”] > 0 ) ) {
$upm_page_number = $_GET[“upm_page_number”];
}
else {
$upm_page_number = 1;
}
$pictures_per_page = $atts[‘pictures_per_page’];
$article_images = $GLOBALS[‘thisarticle’][‘article_image’]; $number_of_images = count(explode(‘,’, $article_images));
$upm_limit = $upm_page_number * $pictures_per_page;
if ($atts[‘offset’] > 0) {
$upm_offset = $atts[‘offset’] + ( ($upm_page_number – 1) * $atts[‘pictures_per_page’] );
} else {
$upm_offset = ($upm_page_number – 1) * $pictures_per_page;
}
$upm_next_page = $upm_page_number + 1; $upm_previous_page = $upm_page_number – 1; $query_string = $_SERVER[‘QUERY_STRING’];
$pattern = ‘/upm\_page\_number\=\d+/’; $url = $GLOBALS[‘prefs’][‘siteurl’] . ‘/index.php?’;
if (strstr($query_string, ‘upm_page_number=’)) {
$query_string_backward = preg_replace($pattern, ‘upm_page_number=’ . $upm_previous_page, $query_string); $query_string_forward = preg_replace($pattern, ‘upm_page_number=’ . $upm_next_page, $query_string);
} else {
$query_string_backward = 0; $query_string_forward = $query_string . ‘&upm_page_number=2’; }
if ($upm_page_number > 1) { return ‘<a href=“http://www.’ . $url . $query_string_backward . ‘”>backward</a>s’; }
}
hm! :-)
then in templates, the following tags will work:
bq.. <div id=“picture_gallery_frame”>
<table class=“picture_gallery_table” border=“0” cellpadding=“30” cellspacing=“0”><tr>
<txp:upm_article_image offset=“1” pictures_per_page=“2”
form=“image_list” class=“gallery” />
</tr></table>
<txp:upm_image_make_backward_link pictures_per_page=“2” offset=“1” /> <txp:upm_image_make_forward_link pictures_per_page=“2” offset=“1” />
…
Last edited by gfxx (2008-09-07 14:45:44)
Offline