Функция hak_txpcountselect

04 июня 2010

Вернуться к статье.

function hak_txpcountselect() {
function count_to_width($n, $widthc){
$result = 0;
if ($n > 99999) {$n = 99999;}
$w = $n * 4;
if ($n < 10) { $result = $n * $widthc; }
elseif ($n < 100) { $result = ($n - 9) * 2 * $widthc + (9 * $widthc); }
elseif ($n < 1000) { $result = ($n - 99) * 3 * $widthc + (180 * $widthc) + (9 * $widthc); }
elseif ($n < 10000) { $result = ($n - 999) * 4 * $widthc + (2700 * $widthc) + (180 * $widthc) + (9 * $widthc); }
else { $result = ($n - 9999) * 5 * $widthc + (36000 * $widthc) + (2700 * $widthc) + (180 * $widthc) + (9 * $widthc); }
return $result + $w;
}

function width_to_count($wl, $wh, $w, $l, $n, $widthc){
$result = array($l, $l);
$check1 = 0; $check2 = 0;

while ( $w > 0 ) {

if ($result[0] < $n) {$tl = count_to_width($result[0] + 1, $widthc) - count_to_width($result[0], $widthc);}
else {$tl = count_to_width($n, $widthc) - count_to_width($n-1, $widthc);}
if (($result[0] > 1) AND ($wl > 0) AND ($w > $tl)) {
$result[0]--;
$tmpl = count_to_width($result[0] + 1, $widthc) - count_to_width($result[0], $widthc);
$w = $w - $tmpl;
$wl = $wl - $tmpl;
}
else {
if ( $check1 == 0 ){ $w = $w - $widthc - 4; }
$check1 = 1;
}

if ($result[1] > 1) {$th = count_to_width($result[1], $widthc) - count_to_width($result[1] - 1, $widthc);}
else {$th = $widthc + 4;}
if (($result[1] < $n) AND ($wh > 0) AND ($w > $th)) {
$result[1]++;
$tmph = count_to_width($result[1], $widthc) - count_to_width($result[1] - 1, $widthc);
$w = $w - $tmph;
$wh = $wh - $tmph;
}
else {
if ($check2 = 0) {
$tmph = count_to_width($result[1], $widthc) - count_to_width($result[1] - 1, $widthc);
$w = $w - $tmph;
}
$check2 = 1;
}

if (($check1 == 1) AND ($check2 == 1)) {break;}
}

return $result;
}

global $img_dir,$path_to_site,$txpcfg;
$category = gps("c");
$category = (!empty($category)) ? "AND category='".$category."'" : "" ;

$limit_image = gps("limimg");
if ((empty($limit_image)) || ($limit_image == "All") || (!intval($limit_image))){ $limit_image = 1; }

$limit_img_count = gps("limcount");
if ((empty($limit_img_count)) || (!intval($limit_img_count)) ) { $limit_img_count = 1; }

$count_width = gps("width");
if ((empty($count_width)) || (!intval($count_width)) ) { $count_width = 0; }

$last_width = gps("wl");
if ((empty($last_width)) || (!intval($last_width))) {$last_width = 12;}
$char_width = gps("wc");
if ((empty($char_width)) || (!intval($char_width))) { $char_width = 12; }

$rcount = safe_count("txp_image", "1=1 ".$category);
echo "<input type=\"hidden\" id=\"count_images\" name=\"count_images\" value=\"$rcount\">\n";

$yw = 0;
$x = ceil($rcount/$limit_image);
$yw = ($last_width * 4 + 16) + count_to_width($x, $char_width);

echo "<ul id=\"txpLimitCount\" class=\"pagination\" style=\"visibility:hidden\">";
echo "<li><a href=\"#\" onclick=\"TxpImageDialog.loadCountImage2(tinyMCEPopup.dom.get('txpCategory').value, tinyMCEPopup.dom.get('txpLimitimg').value, 1);return false;\">&laquo</a></li>";

if ( $limit_img_count == 1 ) { echo "<li>&lt</li>"; }
else {
echo "<li><a href=\"#\" onclick=\"TxpImageDialog.loadCountImage2(tinyMCEPopup.dom.get('txpCategory').value, tinyMCEPopup.dom.get('txpLimitimg').value, $limit_img_count - 1);return false;\">&lt</a></li>";
}
$clw = 0; $chw = 0;
if ( $count_width > $yw + 16) { $xw = 1; $zw = $x; }
else {
$clw = count_to_width($limit_img_count, $char_width);
$chw = count_to_width($x, $char_width) - $clw;
$a = width_to_count($clw, $chw, $count_width - ($last_width * 4 + 16) - 16, $limit_img_count, $x, $char_width);
$xw = $a[0];
$zw = $a[1];
}

for ($i = $xw; $i <= $zw; $i++ ) {
if ($i == $limit_img_count) { echo "<li>$i</li>"; }
else { echo "<li><a href=\"#\" onclick=\"TxpImageDialog.loadCountImage2(tinyMCEPopup.dom.get('txpCategory').value, tinyMCEPopup.dom.get('txpLimitimg').value, $i);return false;\">$i</a></li>";}
}

if ( $limit_img_count == $x ) { echo "<li>&gt</li>"; }
else {
echo "<li><a href=\"#\" onclick=\"TxpImageDialog.loadCountImage2(tinyMCEPopup.dom.get('txpCategory').value, tinyMCEPopup.dom.get('txpLimitimg').value, $limit_img_count + 1);return false;\">&gt</a></li>";
}
echo "<li><a href=\"#\" onclick=\"TxpImageDialog.loadCountImage2(tinyMCEPopup.dom.get('txpCategory').value, tinyMCEPopup.dom.get('txpLimitimg').value, $x);return false;\">&raquo</a></li>";

echo "</ul>";
exit(0);
}

Вернуться к статье. 

Андрей Лебедев

,

, ,

Комментарий

Нет комментарий.

Комментировать: