Quote from: Cx2 at Mar 23, 2008, 06:59 PM
Если поставишь 0, получишь 0 изображений.
Ставь большое число, например 1000.
Ок с этим понятно.
Появились 2 задачи:
1. Чтобы созранялись превьюшки разных размеров.
2. Чтобы выводилось несколько случайных картинок из галлереи.
Поэтому сделал быстро патчик(код быстро написан, возможны ошибки), если интересно его можно включить под какими-нибудь опциями, например "Сохранять эскизы разных размеров", "Вывод случайных эскизов".
Случайные изменения вызываются так [!easy2? &orderby=`rand()` &limit=`2` &h=`150` &w=`150`!]
Кстате из-за того, что в версии 1.1 появился в снипете код mysql_close(); echo $out; этот снипет не получается вызывать несколько раз.
вот изменения:
Index: snippet.easy2gallery.php
===================================================================
--- snippet.easy2gallery.php (revision 92)
+++ snippet.easy2gallery.php (working copy)
@@ -43,7 +43,7 @@
// ORDER BY
$orderby = (empty($orderby)) ? $e2g['orderby'] : $orderby;
-$orderby = preg_replace('/[^_a-z]/i', '', $orderby);
+$orderby = preg_replace('/[^_()a-z]/i', '', $orderby);
// ORDER
$order = (empty($order)) ? $e2g['order'] : $order;
@@ -57,6 +57,7 @@
if ($glib == 'highslide') {
$modx->regClientStartupScript('assets/modules/easy2/libs/highslide/highslide-with-html.js', 0);
+ $modx->regClientStartupScript('assets/modules/easy2/libs/highslide/russian.highslide.js', 0);
$modx->regClientStartupScript('<script type="text/javascript">
hs.graphicsDir = "assets/modules/easy2/libs/highslide/graphics/";
hs.outlineType = "rounded-white";
@@ -70,8 +71,10 @@
if ($gid > 1) $path = get_path($gid, 1);
else $path = '';
+if ($orderby=='rand()'){
+ return get_rand_pics($orderby, $order, $limit, $w, $h, $thq);
+}
-
$out = '<table cellspacing="20" class="easy2">';
$i = 0;
@@ -157,15 +160,16 @@
$out .= '</div>';
}
-mysql_close();
+//mysql_close();
-echo $out;
+//echo $out;
+return $out;
function get_thumb ($gdir, $path, $w = 150, $h = 150, $thq=80, $resize_type = 'inner') {
if (empty($path)) return false;
- $thumb_path = '_thumbnails/'.substr($path, 0, strrpos($path, '.')).'.jpg';
+ $thumb_path = '_thumbnails/'.substr($path, 0, strrpos($path, '.')).'.'.$w.'x'.$h.'.jpg';
if (!file_exists($gdir.$thumb_path) && file_exists($gdir.$path)) {
@@ -265,3 +269,33 @@
return $result;
}
+
+function get_rand_pics($orderby, $order, $limit, $w, $h, $thq){
+ global $modx;
+
+ require './assets/modules/easy2/config.easy2gallery.php';
+
+ $out .= '<ul>';
+
+ // RANDOM PICS
+ $q = 'SELECT * FROM '.$modx->db->config['table_prefix'].'easy2_files '
+ . 'WHERE status = 1 '
+ . 'ORDER BY '.$orderby.' '.$order.' '
+ . 'LIMIT '.($gpn * $limit).', '.$limit;
+ $res = mysql_query($q);
+
+ while ($l = mysql_fetch_array($res, MYSQL_ASSOC)) {
+ $pos = strrpos($l['filename'], '.');
+ $ext = substr($l['filename'], $pos);
+ // '.$e2g['dir'].$path.$l['id'].$ext.'
+ $out .= '
+<li>
+<a href="[~9~]" ><img src="'.get_thumb($e2g['dir'], get_path($l['dir_id'], true).$l['id'].$ext, $w, $h, $thq).'" alt="'.$l['name'].'" title="'.$l['name'].'" /></a>
+</li>
+';
+ }
+
+ $out .= '</ul>';
+ return $out;
+
+}