Query(" SELECT * FROM " . PREFIX . "_module_gallery WHERE id = '" . $gallery_id . "' "); $row_gs = $sql->FetchRow(); $limit = ($row_gs->gallery_image_on_page > 0) ? $row_gs->gallery_image_on_page : $this->_default_limit_images; $limit = empty($lim) ? $limit : $lim; $limit = ($ext != 1) ? $limit : 10000; $start = get_current_page() * $limit - $limit; switch ($row_gs->gallery_orderby) { case 'position': $order_by = "image_position ASC"; break; case 'titleasc': $order_by = "image_title ASC"; break; case 'titledesc': $order_by = "image_title DESC"; break; case 'dateasc': $order_by = "image_date ASC"; break; default: $order_by = "image_date DESC"; break; } $sql = $AVE_DB->Query(" SELECT COUNT(*) FROM " . PREFIX . "_module_gallery_images WHERE gallery_id = '" . $gallery_id . "' AND image_status = '1' "); $num = $sql->GetCell(); $sql = $AVE_DB->Query(" SELECT * FROM " . PREFIX . "_module_gallery_images WHERE gallery_id = '" . $gallery_id . "' AND image_status = '1' ORDER BY " . $order_by . " LIMIT " . $start . "," . $limit . " "); $folder = trim(UPLOAD_GALLERY_DIR . '/' . $row_gs->gallery_folder, '/'); $size = sprintf($this->_size, $row_gs->gallery_thumb_method, $row_gs->gallery_thumb_width, $row_gs->gallery_thumb_height); $search = array('[tag:gal:id]', '[tag:gal:folder]', '[tag:path]','[tag:gal:title]','[tag:gal:description]'); $replace = array($row_gs->id, ABS_PATH . $folder . '/', ABS_PATH,$row_gs->gallery_title,$row_gs->gallery_description); $main_template = str_replace($search, $replace, $row_gs->gallery_script); // Постраничная навигация if ($num > $limit) { $page_nav = '{t} '; $page_nav = get_pagination(ceil($num / $limit), 'page', $page_nav, get_settings('navi_box')); $page_nav = rewrite_link($page_nav); $GLOBALS['page_id'][$_REQUEST['id']]['page']=($GLOBALS['page_id'][$_REQUEST['id']]['page']>ceil($num / $limit) ? $GLOBALS['page_id'][$_REQUEST['id']]['page'] : ceil($num / $limit)); } else { $page_nav = ''; } $rows = array(); while ($row = $sql->FetchRow()) { $row->image_filename = rawurlencode($row->image_filename); $row->image_size = round(filesize(BASE_DIR . '/' . $folder . '/' . $row->image_filename) / 1024, 0); array_push($rows, $row); } $images = ''; $i = 0; $items_count = count($rows); // foreach ($rows as $row) { $i++; $last_item = ($i==$items_count ? true : false); $item_num = $i; $search = array( '[tag:img:id]', '[tag:img:original]', '[tag:img:thumbnail]', '[tag:img:title]', '[tag:img:description]', '[tag:img:size]', '[tag:gal:id]', '[tag:gal:folder]', '[tag:path]', '[tag:link]', '[tag:gal:title]' ); $replace = array( $row->id, ABS_PATH . $folder . '/' . $row->image_filename, make_thumbnail(array('link' => ABS_PATH . $folder . '/' . $row->image_filename, 'size' => $size)), htmlspecialchars(empty($row->image_title) ? $AVE_Template->get_config_vars('NoTitle') : $row->image_title, ENT_QUOTES), htmlspecialchars(empty($row->image_description) ? $AVE_Template->get_config_vars('NoDescr') : $row->image_description, ENT_QUOTES), $row->image_size, $row_gs->id, ABS_PATH . $folder . '/', ABS_PATH, str_ireplace('"//"','"/"', str_ireplace('///', '/', rewrite_link($row->image_link))), $row_gs->gallery_title ); $image = str_replace($search, $replace, $row_gs->gallery_image_template); $image = '<'.'?php $item_num='.var_export($item_num,1).'; $last_item='.var_export($last_item,1).'?'.'>'.$image; $image = str_replace('[tag:if_first]', '<'.'?php if(isset($item_num) && ($item_num)===1) { ?'.'>', $image); $image = str_replace('[tag:if_not_first]', '<'.'?php if(isset($item_num) && $item_num!==1) { ?'.'>', $image); $image = str_replace('[tag:if_last]', '<'.'?php if(isset($last_item) && $last_item) { ?'.'>', $image); $image = str_replace('[tag:if_not_last]', '<'.'?php if(isset($item_num) && !$last_item) { ?'.'>', $image); $image = preg_replace('/\[tag:if_every:([0-9-]+)\]/u', '<'.'?php if(isset($item_num) && !('.$i.' % $1)){ '.'?'.'>', $image); $image = preg_replace('/\[tag:if_not_every:([0-9-]+)\]/u', '<'.'?php if(isset($item_num) && ('.$i.' % $1)){ '.'?'.'>', $image); $image = str_replace('[tag:/if]', '<'.'?php } ?'.'>', $image); $image = str_replace('[tag:if:else]', '<'.'?php } else { ?'.'>', $image); $images .= eval2var('?>' . $image . ''); } $main_template = str_replace('[tag:gal:pages]', $page_nav, $main_template); $return = str_replace('[tag:gal:content]', $images, $main_template); $return = str_replace('[tag:path]', ABS_PATH, $return); $return = str_replace('[tag:mediapath]', ABS_PATH . 'templates/' . ((defined('THEME_FOLDER') === false) ? DEFAULT_THEME_FOLDER : THEME_FOLDER) . '/', $return); echo $return; } /** * Вывод одиночного изображения * * @param string $tpl_dir - путь к папке с шаблонами модуля * @param int $image_id - идентификатор изображения */ function galleryImageShow($tpl_dir, $image_id) { global $AVE_DB, $AVE_Template; $sql = $AVE_DB->Query(" SELECT image_filename, image_file_ext, image_title, gallery_folder FROM " . PREFIX . "_module_gallery_images AS img LEFT JOIN " . PREFIX . "_module_gallery AS gal ON gal.id = gallery_id WHERE img.id = '" . $image_id . "' "); $row = $sql->FetchRow(); $folder = trim(UPLOAD_GALLERY_DIR . '/' . $row->gallery_folder, '/'); // $thumb_dir = trim(THUMBNAIL_DIR . '/' . sprintf($this->_size, $row->gallery_thumb_width), '/'); $source = ABS_PATH . $folder . '/' . rawurlencode($row->image_filename); switch ($this->_galleryFileTypeGet($row->image_file_ext)) { case 'gif': case 'jpg': case 'png': list($width, $height) = getimagesize(BASE_DIR . '/' . $folder . '/' . $row->image_filename); $AVE_Template->assign('w', ($width < 350 ? 350 : ($width > 950 ? 950 : $width+8))); $AVE_Template->assign('h', ($height < 350 ? 350 : ($height > 700 ? 700 : $height+85))); $AVE_Template->assign('scrollbars', ($width > 950 || $height > 700 ? 1 : '') ); $AVE_Template->assign('source', $source); $AVE_Template->assign('image_title', $row->image_title); break; case 'video': $AVE_Template->assign('w', 350); $AVE_Template->assign('notresizable', 1); $AVE_Template->assign('h', 400); $AVE_Template->assign('source', $source); $AVE_Template->assign('mediatype', $this->_galleryMediaTypeGet($row->image_file_ext)); break; } $AVE_Template->display($tpl_dir . 'image.tpl'); } /** * ФУНКЦИИ АДМИНИСТРАТИВНОЙ ЧАСТИ */ /** * Просмотр изображений галереи в админке * * @param string $tpl_dir - путь к папке с шаблонами модуля * @param int $gallery_id - идентификатор галереи */ function galleryImageListShow($tpl_dir, $gallery_id) { global $AVE_DB, $AVE_Template; $sql = $AVE_DB->Query(" SELECT gallery_thumb_width, gallery_thumb_height, gallery_thumb_method, gallery_title, gallery_folder FROM " . PREFIX . "_module_gallery WHERE id = '" . $gallery_id . "' "); $row_gs = $sql->FetchRow(); $folder = trim(UPLOAD_GALLERY_DIR . '/' . $row_gs->gallery_folder, '/'); $size = sprintf($this->_size, $row_gs->gallery_thumb_method, $row_gs->gallery_thumb_width, $row_gs->gallery_thumb_height); if (isset($_REQUEST['sub']) && $_REQUEST['sub'] == 'save') { if (isset($_POST['del']) && sizeof($_POST['del']) > 0) { while (list($image_id) = each($_POST['del'])) { $file = BASE_DIR . '/' . $folder . '/' . $_POST['datei'][$image_id]; @unlink($file); @unlink(make_thumbnail(array('link' => $file, 'size' => $size))); $AVE_DB->Query(" DELETE FROM " . PREFIX . "_module_gallery_images WHERE id = '" . (int)$image_id . "' "); } } foreach ($_POST['gimg'] as $image_id) { $AVE_DB->Query(" UPDATE " . PREFIX . "_module_gallery_images SET image_title = '" . $_POST['image_title'][$image_id] . "', image_description = '" . $_POST['image_description'][$image_id] . "', image_position = '" . intval($_POST['image_position'][$image_id]) . "', image_link = '" . $_POST['image_link'][$image_id] . "', image_status = '" . ((empty($_POST['image_status'][$image_id]) || empty($_POST['image_status'][$image_id])) ? 0 : 1) . "' WHERE id = '" . (int)$image_id . "' AND gallery_id = '" . $gallery_id . "' "); } header('Location:' . get_redirect_link('sub')); exit; } $limit = $this->_admin_limit_images; $start = get_current_page() * $limit - $limit; $sql = $AVE_DB->Query(" SELECT SQL_CALC_FOUND_ROWS * FROM " . PREFIX . "_module_gallery_images WHERE gallery_id = '" . $gallery_id . "' ORDER BY id DESC LIMIT " . $start . "," . $limit . " "); $sql_num = $AVE_DB->Query("SELECT FOUND_ROWS()"); $num = $sql_num->GetCell(); if (!$num) { header('Location:index.php?do=modules&action=modedit&mod=gallery&moduleaction=1'); exit; } $images = array(); while ($row = $sql->FetchAssocArray()) { $row['image_type'] = $this->_galleryFileTypeGet($row['image_file_ext']); $row['image_author'] = get_username_by_id($row['image_author_id']); $row['image_size'] = @filesize(BASE_DIR . '/' . $folder . '/' . $row['image_filename']); $row['image_size'] = @round($row['image_size'] / 1024, 2); $row['image_filename'] = rawurlencode($row['image_filename']); $row['original'] = ABS_PATH . $folder . '/' . $row['image_filename']; $row['thumbnail'] = make_thumbnail(array('link' => $row['original'], 'size' => $size)); array_push($images, $row); } if ($num > $limit) { $page_nav = ' {t} '; $page_nav = get_pagination(ceil($num / $limit), 'page', $page_nav); } else { $page_nav = ''; } $AVE_Template->assign('page_nav', $page_nav); $AVE_Template->assign('gallery_title', $row_gs->gallery_title); $AVE_Template->assign('gallery_thumb_width', $row_gs->gallery_thumb_width); $AVE_Template->assign('images', $images); $AVE_Template->assign('content', $AVE_Template->fetch($tpl_dir . 'admin_gallery_image.tpl')); } /** * Загрузка изображений в галерею * * @param string $tpl_dir - путь к папке с шаблонами модуля * @param int $gallery_id - идентификатор галереи */ function galleryImageUploadForm($tpl_dir, $gallery_id) { global $AVE_DB, $AVE_Template; $sql = $AVE_DB->Query(" SELECT gallery_watermark, gallery_thumb_width, gallery_title, gallery_folder FROM " . PREFIX . "_module_gallery WHERE id = '" . $gallery_id . "' "); $row = $sql->FetchRow(); $dst_dir = BASE_DIR . '/' . trim(UPLOAD_GALLERY_DIR . '/' . $row->gallery_folder, '/'); if (isset($_REQUEST['sub']) && $_REQUEST['sub'] == 'save') { $images = array(); $path = ABS_PATH . trim(UPLOAD_GALLERY_DIR . '/' . $row->gallery_folder, '/'); @$size = sprintf($this->_size, $row_gs->gallery_thumb_method, $row_gs->gallery_thumb_width, $row_gs->gallery_thumb_height); @$admin_size = sprintf($this->admin_size, $row_gs->gallery_thumb_method, $row_gs->gallery_thumb_width, $row_gs->gallery_thumb_height); if (!empty($_REQUEST['fromfolder']) && $_REQUEST['fromfolder'] == 1) { $src_dir = BASE_DIR . '/' . UPLOAD_GALLERY_DIR . '/.temp/'; if (!file_exists($src_dir . '/') && !rmkdir($src_dir . '/', 0777)) { header('Location:index.php?do=modules&action=modedit&mod=gallery&moduleaction=1'); exit; } $htaccess_file = $src_dir . '/' . '.htaccess'; if (!file_exists($htaccess_file)) { $fp = @fopen($htaccess_file, 'w+'); if ($fp) { fputs($fp, 'Deny from all'); fclose($fp); } } if ($handle = opendir($src_dir . '/')) { while (false !== ($file = readdir($handle))) { if ($file != '.' && $file != '..') { $image_title = substr($file, 0, -4); $upload_file_ext = strtolower(substr($file, -4)); $upload_filename = prepare_fname($image_title) . $upload_file_ext; while (file_exists($dst_dir . '/' . $upload_filename)) { $upload_filename = $this->_galleryImageRename($upload_filename); } if (!empty($upload_filename) && in_array($upload_file_ext, $this->_allowed_type)) { @copy($src_dir . '/' . $file, $dst_dir . '/' . $upload_filename); @unlink($src_dir . '/' . $file); $oldumask = umask(0); @chmod($dst_dir . '/' . $upload_filename, 0777); umask($oldumask); if ($upload_file_ext != 'video') { $this->_galleryImageRebuild($dst_dir, $upload_filename, $row->gallery_watermark); } $images[] = make_thumbnail(array('link' => $path . '/' . $upload_filename, 'size' => $size)); $AVE_DB->Query(" INSERT INTO " . PREFIX . "_module_gallery_images SET id = '', gallery_id = '" . $gallery_id . "', image_filename = '" . addslashes($upload_filename) . "', image_author_id = '" . (int)$_SESSION['user_id'] . "', image_title = '" . addslashes($image_title) . "', image_file_ext = '" . addslashes($upload_file_ext) . "', image_description = '', image_date = '" . time() . "' "); } } } closedir($handle); } }else if (!empty($_REQUEST['fromuploader']) && $_REQUEST['fromuploader'] == 1) { $src_dir = BASE_DIR . '/' . UPLOAD_GALLERY_DIR . '/.uploader/'.$_SESSION['user_id']; if (!file_exists($src_dir . '/') && !rmkdir($src_dir . '/', 0777)) { header('Location:index.php?do=modules&action=modedit&mod=gallery&moduleaction=1'); exit; } $htaccess_file = $src_dir . '/' . '.htaccess'; if (!file_exists($htaccess_file)) { $fp = @fopen($htaccess_file, 'w+'); if ($fp) { fputs($fp, 'Deny from all'); fclose($fp); } } if ($handle = opendir($src_dir . '/')) { while (false !== ($file = readdir($handle))) { if ($file != '.' && $file != '..') { $image_title = substr($file, 0, -4); $upload_file_ext = strtolower(substr($file, -4)); $upload_filename = prepare_fname($image_title) . $upload_file_ext; while (file_exists($dst_dir . '/' . $upload_filename)) { $upload_filename = $this->_galleryImageRename($upload_filename); } if (!empty($upload_filename) && in_array($upload_file_ext, $this->_allowed_type)) { @copy($src_dir . '/' . $file, $dst_dir . '/' . $upload_filename); @unlink($src_dir . '/' . $file); $oldumask = umask(0); @chmod($dst_dir . '/' . $upload_filename, 0777); umask($oldumask); if ($upload_file_ext != 'video') { $this->_galleryImageRebuild($dst_dir, $upload_filename, $row->gallery_watermark); } //$images[] = make_thumbnail(array('link' => $path . '/' . $upload_filename, 'size' => $_size)); $images[] = make_thumbnail(array('size' => $admin_size, 'link' => $path . '/' . $upload_filename)); $AVE_DB->Query(" INSERT INTO " . PREFIX . "_module_gallery_images SET id = '', gallery_id = '" . $gallery_id . "', image_filename = '" . addslashes($upload_filename) . "', image_author_id = '" . (int)$_SESSION['user_id'] . "', image_title = '" . addslashes($image_title) . "', image_file_ext = '" . addslashes($upload_file_ext) . "', image_description = '', image_date = '" . time() . "' "); } } } closedir($handle); } } $count_files = sizeof(@$_FILES['file']['tmp_name']); for ($i=0;$i<$count_files;$i++) { $upload_file_ext = strtolower(substr($_FILES['file']['name'][$i], -4)); $upload_filename = prepare_fname(substr($_FILES['file']['name'][$i], 0, -4)) . $upload_file_ext; if (!empty($upload_filename)) { while (file_exists($dst_dir . '/' . $upload_filename)) { $upload_filename = $this->_galleryImageRename($upload_filename); } if (in_array($upload_file_ext, $this->_allowed_type) ) { move_uploaded_file($_FILES['file']['tmp_name'][$i], $dst_dir . '/' . $upload_filename); $oldumask = umask(0); @chmod($dst_dir . '/' . $upload_filename, 0777); umask($oldumask); if ($upload_file_ext != 'video') { $this->_galleryImageRebuild($dst_dir, $upload_filename, $row->gallery_watermark); } //$images[] = make_thumbnail(array('link' => $path . '/' . $upload_filename, 'size' => $size)); $images[] = make_thumbnail(array('size' => $admin_size, 'link' => $path . '/' . $upload_filename)); $AVE_DB->Query(" INSERT INTO " . PREFIX . "_module_gallery_images SET id = '', gallery_id = '" . $gallery_id . "', image_filename = '" . addslashes($upload_filename) . "', image_author_id = '" . (int)$_SESSION['user_id'] . "', image_title = '" . (isset($_POST['image_title'][$i]) ? $_POST['image_title'][$i] : '') . "', image_file_ext = '" . addslashes($upload_file_ext) . "', image_description = '" . (isset($_POST['image_description'][$i]) ? $_POST['image_description'][$i] : '') . "', image_date = '" . time() . "' "); } } } $AVE_Template->assign('gallery_title', $row->gallery_title); $AVE_Template->assign('images', $images); $AVE_Template->assign('content', $AVE_Template->fetch($tpl_dir . 'admin_gallery_upload_form_finish.tpl')); } else { if (!is_writable($dst_dir . '/')) { $AVE_Template->assign('not_writeable', 1); $AVE_Template->assign('upload_dir', '/' . trim(UPLOAD_GALLERY_DIR . '/' . $row->gallery_folder, '/') . '/'); } $AVE_Template->assign('gallery_title', $row->gallery_title); $AVE_Template->assign('allowed', $this->_allowed_type); $AVE_Template->assign('formaction', 'index.php?do=modules&action=modedit&mod=gallery&moduleaction=add&sub=save&id=' . $gallery_id); $AVE_Template->assign('content', $AVE_Template->fetch($tpl_dir . 'admin_gallery_upload_form.tpl')); } } /** * Вывод списка галерей * * @param string $tpl_dir - путь к папке с шаблонами модуля */ function galleryListShow($tpl_dir) { global $AVE_DB, $AVE_Template; if (!empty($_POST['create'])) { foreach ($_POST['create'] as $gallery_id) { $this->_galleryImageMove((int)$gallery_id); } } $limit = $this->_limit_galleries; $start = get_current_page() * $limit - $limit; $galleries = array(); $sql = $AVE_DB->Query(" SELECT SQL_CALC_FOUND_ROWS gal.*, COUNT(img.id) AS image_count FROM " . PREFIX . "_module_gallery AS gal LEFT JOIN " . PREFIX . "_module_gallery_images AS img ON img.gallery_id = gal.id GROUP BY gal.id ORDER BY gal.gallery_created DESC LIMIT " . $start . "," . $limit . " "); $sql_num = $AVE_DB->Query("SELECT FOUND_ROWS()"); $num = $sql_num->GetCell(); while($row = $sql->FetchAssocArray()) { $row['username'] = get_username_by_id($row['gallery_author_id']); array_push($galleries, $row); } if ($num > $limit) { $page_nav = "