function AdminGalleryUpload()
{
    // TODO: неправильный порядок изображений при мультизагрузке
    if (!isset($_POST['action']) || !isset($_GET['formid']) || !isset($_SESSION['uploadforms'][$_GET['formid']])) {
        AdminGalleryUploadForm();
        return;
    }
    global $GalleryDir, $ThumbsDir;
    $formid = $_GET['formid'];
    // Загрузка фотографий
    if ($_POST['action'] == 'upload') {
        // SwfUpload кодирует имена файлов в UTF-8
        $_FILES['up_image']['name'] = Utf8ToCp1251($_FILES['up_image']['name']);
        $Error = false;
        $_SESSION['uploadforms'][$formid]['photos'][] = LoadImage('up_image', $GalleryDir, $ThumbsDir, System::config('gallery/thumb_max_width'), System::config('gallery/thumb_max_height'), '', $Error, true, System::config('gallery/optimize_originals'), System::config('gallery/original_width'), System::config('gallery/original_height'));
        if ($Error) {
            exit('ERROR 2');
        }
        exit('OK');
    }
    // Предпросмотр добавляемых фотографий
    $_SESSION['uploadforms'][$formid]['category'] = $_POST['category'];
    $_SESSION['uploadforms'][$formid]['allow_comments'] = EnToInt($_POST['allow_comments']);
    $_SESSION['uploadforms'][$formid]['allow_votes'] = EnToInt($_POST['allow_votes']);
    $_SESSION['uploadforms'][$formid]['show'] = EnToInt($_POST['show']);
    $_SESSION['uploadforms'][$formid]['view'] = ViewLevelToInt($_POST['view']);
    AddCenterBox('Мультизагрузка - предпросмотр');
    $count_photos = count($_SESSION['uploadforms'][$formid]['photos']);
    $text = '<form action="' . ADMIN_FILE . '?exe=gallery&a=saveuploaded&formid=' . $formid . '" method="post">';
    $submits = System::admin()->Submit('Отмена', 'name="submit_cancel" value="cancel"') . System::admin()->Submit('Сохранить', 'name="submit_save" value="save"');
    $text .= '<div class="cfgboxsubmit"><div style="float: left;">Загружено ' . $count_photos . ' изображений.</div>' . $submits . '</div>';
    foreach ($_SESSION['uploadforms'][$formid]['photos'] as $id => $photo) {
        $func = System::admin()->SpeedAjax('Удалить', ADMIN_FILE . '?exe=gallery&a=deleteuploaded&id=' . $id . '&formid=' . $formid, 'images/admin/delete.png', '', '', "jQuery('#photo_box_{$id}').fadeOut();");
        $text .= Indent('
			<div class="cfgbox" id="photo_box_' . $id . '">
				<table cellspacing="0" cellpadding="0" border="0" style="width: 100%;">
					<tr>
						<td style="vertical-align: top; width: 160px;">
							<a href="' . $GalleryDir . $photo . '" target="_blank"><img src="' . $ThumbsDir . $photo . '" /></a>
							' . $photo . '
						</td>
						<td style="vertical-align: top;">
							<table cellspacing="2" cellpadding="4" style="width: 100%;" class="cfgtable">
								<tr>
									<td>Заголовок</td>
									<td colspan="3" style="text-align: left;">' . System::admin()->Edit('title_' . $id, '', false, 'maxlength="250" style="width:400px;"') . '</td>
								</tr>
								<tr>
									<td>Описание (HTML)</td>
									<td colspan="3" style="text-align: left;">' . System::admin()->TextArea('description_' . $id, '', 'style="width: 400px; height: 120px;"') . '</td>
								</tr>
								<tr>
									<td>Автор</td>
									<td style="text-align: left;">' . System::admin()->Edit('author_' . $id, '', false, 'maxlength="250" style="width:200px;"') . '</td>
									<td>Email автора</td>
									<td style="text-align: left;">' . System::admin()->Edit('email_' . $id, '', false, 'maxlength="250" style="width:200px;"') . '</td>
								</tr>
								<tr>
									<td>Сайт автора</td>
									<td colspan="3" style="text-align: left;">' . System::admin()->Edit('www_' . $id, '', false, 'maxlength="250" style="width:200px;"') . '</td>
								</tr>
							</table>
						</td>
						<td style="vertical-align: top; text-align: right; width: 50px;">' . $func . '</td>
					</tr>
				</table>
			</div>
		');
    }
    $text .= '<div class="cfgboxsubmit">' . $submits . '</div>';
    $text .= '</form>';
    AddText($text);
}
Example #2
0
//width
$img_path_arr = explode('/', $img_path);
$img_src = $img_path_arr[sizeof($img_path_arr) - 1];
$ext = explode('.', $img_src);
$ext = $ext[1];
if (file_exists("thumbs/{$size}/{$img_src}")) {
    // if the file is resized previously
    if ($ext == "jpeg" || $ext == "jpg") {
        header('Content-Type: image/jpeg');
        $img = LoadImage("thumbs/{$size}/{$img_src}", $ext);
        imagejpeg($img);
        imagedestroy($img);
    } else {
        if ($ext == "png") {
            header('Content-Type: image/png');
            $img = LoadImage("thumbs/{$size}/{$img_src}", $ext);
            imagejpeg($img);
            imagedestroy($img);
        }
    }
} else {
    $img = "thumbs/raw/" . $img_src;
    $dest_path = "thumbs/" . $size . "/";
    if (!file_exists($dest_path)) {
        mkdir($dest_path, 0777, true);
    }
    $dest_path = "thumbs/" . $size . "/" . $img_src;
    file_put_contents($img, file_get_contents($img_path));
    list($width, $height) = getimagesize($img);
    if ($ext == "jpeg" || $ext == "jpg") {
        $image = imagecreatefromjpeg($img);
function AdminArticlesSaveArticle($action)
{
    global $editarticles;
    if (!$editarticles) {
        System::admin()->AccessDenied();
    }
    $cat_id = SafeEnv($_POST['category'], 11, int);
    if (in_array($cat_id, AdminArticlesGetTree()->GetAllChildId(0)) === false || $cat_id == 0) {
        GO(ADMIN_FILE . '?exe=articles');
    }
    $author = SafeEnv($_POST['author'], 200, str, true);
    $email = SafeEnv($_POST['email'], 50, str, true);
    $www = SafeEnv(Url($_POST['www']), 250, str, true);
    $title = SafeEnv($_POST['title'], 255, str);
    $description = SafeEnv($_POST['description'], 0, str, false, true, false);
    $article = SafeEnv($_POST['article'], 0, str, false, true, false);
    // Загружаем изображение
    $Error = false;
    $image = LoadImage('up_image', System::config('articles/images_dir'), System::config('articles/images_dir') . 'thumbs', System::config('articles/thumb_max_width'), System::config('articles/thumb_max_height'), $_POST['image'], $Error);
    $auto_br_desc = EnToInt($_POST['auto_br_desc']);
    $auto_br_article = EnToInt($_POST['auto_br_article']);
    $allow_comments = EnToInt($_POST['allow_comments']);
    $allow_votes = EnToInt($_POST['allow_votes']);
    $view = ViewLevelToInt($_POST['view']);
    $active = EnToInt($_POST['active']);
    //Модуль SEO
    $seo_title = SafeEnv($_POST['seo_title'], 255, str);
    $seo_keywords = SafeEnv($_POST['seo_keywords'], 255, str);
    $seo_description = SafeEnv($_POST['seo_description'], 255, str);
    //
    $form = SafeEnv($_POST['form'], 11, int);
    $product_id = SafeEnv($_POST['product_id'], 255, str);
    if ('add' == $action) {
        $values = Values('', $cat_id, time(), $author, $email, $www, $title, $description, $article, $image, 0, $allow_comments, 0, $allow_votes, 0, 0, $active, $view, $auto_br_desc, $auto_br_article, $seo_title, $seo_keywords, $seo_description, $form, $product_id);
        System::database()->Insert('articles', $values);
        if ($active) {
            AdminArticlesGetTree()->CalcFileCounter($cat_id, true);
        }
        Audit('Статьи: Добавление статьи "' . $title . '"');
    } elseif ('save' == $action) {
        $set = "`cat_id`='{$cat_id}',`author`='{$author}',`email`='{$email}',`www`='{$www}',`title`='{$title}',`description`='{$description}',`article`='{$article}',`image`='{$image}',`allow_comments`='{$allow_comments}',`allow_votes`='{$allow_votes}',`view`='{$view}',`active`='{$active}',`auto_br_desc`='{$auto_br_desc}',`auto_br_article`='{$auto_br_article}',`seo_title`='{$seo_title}',`seo_keywords`='{$seo_keywords}',`seo_description`='{$seo_description}',`form`='{$form}',`product_id`='{$product_id}'";
        $id = SafeEnv($_GET['id'], 11, int);
        $r = System::database()->Select('articles', "`id`='{$id}'");
        if ($r[0]['cat_id'] != $cat_id && $r[0]['active'] == '1') {
            // Если переместили в другой раздел
            AdminArticlesGetTree()->CalcFileCounter($r[0]['cat_id'], false);
            AdminArticlesGetTree()->CalcFileCounter($cat_id, true);
        }
        if ($r[0]['active'] != $active) {
            // Выключили / Включили
            if ($active == 0) {
                AdminArticlesGetTree()->CalcFileCounter($cat_id, false);
            } else {
                AdminArticlesGetTree()->CalcFileCounter($cat_id, true);
            }
        }
        System::database()->Update('articles', $set, "`id`='{$id}'");
        Audit('Статьи: Изменение статьи "' . $title . '"');
    }
    if ($Error) {
        AddTextBox('Ошибка', '<p align="center">Неправильный формат файла. Можно загружать только изображения формата GIF, JPEG или PNG. Остальные изменения сохранены.</p><br><a href="' . GetRefererUrl($_REQUEST['back']) . '" class="button">Далее</a>');
        return;
    }
    GoRefererUrl($_REQUEST['back']);
}
        // Avoid potential rounding error
        if ($un[$i] > 255) {
            $un[$i] = 255;
        }
    }
    return $un;
}
if (empty($file)) {
    die("<b>Usage:</b><br>r.php?file=name&[b=value][&c=value][&s=scale][&sat=saturation]<p>\n\tfile= Filename, must end with the image format, i.e. .png, .jpg, .gif<br>\n\tb\t= Brightness value [-1, 1]<br>\n\tc\t= Contrast value [-1, 1]<br>\n\ts\t= Scale<br>\n\tsat= Color saturation value.<br>");
}
if (strstr($file, "png")) {
    $bkg = LoadImage($file);
} elseif (strstr($file, "jpg")) {
    $bkg = LoadImage($file, "jpeg");
} elseif (strstr($file, "gif")) {
    $bkg = LoadImage($file, "gif");
}
if (empty($b)) {
    $b = 0;
}
if (empty($c)) {
    $c = 0;
}
if (empty($s)) {
    $s = 1;
}
if (empty($sat)) {
    $sat = 0;
}
// Adjust contrast and brightness of background color
if ($b || $c) {
Example #5
0
 // Init variables
 $ImagePath = $Attachment->Path;
 $MaxWidth = $Context->Configuration['INLINEIMAGES_MAX_WIDTH'];
 // Check if image width exceeds the maximum width
 list($Width, $Height, $Type, $Attr) = @getimagesize($Attachment->Path);
 if ($Width > $MaxWidth) {
     // Our new width is the maximum width
     $NewWidth = $MaxWidth;
     $Quality = 100;
     // Change image path to show resized image
     $ImagePath = basename($Attachment->Path);
     $ImagePath = str_replace($ImagePath, '', $Attachment->Path);
     $ImagePath = $ImagePath . 'resized' . $MaxWidth . '-' . basename($Attachment->Path) . '.jpg';
     // Check if there's already a resized image, if not create one
     if (!file_exists($ImagePath)) {
         if ($OriginalImage = LoadImage($Attachment->Path)) {
             $OriginalWidth = ImageSX($OriginalImage);
             $OriginalHeight = ImageSY($OriginalImage);
             $NewHeight = Round($OriginalHeight * $NewWidth) / $OriginalWidth;
             $NewImage = imagecreatetruecolor($NewWidth, $NewHeight);
             imagecopyresampled($NewImage, $OriginalImage, 0, 0, 0, 0, $NewWidth, $NewHeight, $OriginalWidth, $OriginalHeight);
             // Create the resize image file
             touch($ImagePath);
             imagejpeg($NewImage, $ImagePath, $Quality);
             chmod($ImagePath, 0644);
             imagedestroy($NewImage);
             imagedestroy($OriginalImage);
         } else {
             die('Error processing image!');
         }
     }
function AdminDownloadsSaveFile($action)
{
    if ($_POST == array()) {
        AddTextBox('Ошибка', '<b>Внимание! Превышен максимальный размер POST данных. Изменения не сохранены.</b>');
        return;
    }
    $Error = '';
    if (!System::user()->CheckAccess2('downloads', 'edit_files')) {
        System::admin()->AccessDenied();
    }
    $category = SafeEnv($_POST['category'], 11, int);
    if (in_array($category, AdminDownloadsGetTree()->GetAllChildId(0)) === false || $category == 0) {
        GO(ADMIN_FILE . '?exe=downloads');
    }
    $title = SafeEnv($_POST['title'], 250, str);
    // Обрабатываем upload_file если загрузился файл
    $exts = explode(',', System::config('downloads/file_exts'));
    $exts2 = array();
    foreach ($exts as $ext) {
        $exts2[trim($ext)] = true;
    }
    $UploadErrors = array(0 => '', 1 => 'Размер файла превышен', 2 => 'Размер файла превышен', 3 => 'Файл загружен только частично', 4 => 'Файл не был загружен.', 6 => 'Не найдена папка для временных файлов на сервере', 7 => 'Ошибка во время записи на диск', 8 => 'Загрузка файла была прервана расширением PHP', 9 => 'Ошибка во время записи на диск');
    if ($_FILES['upload_file']['error'] == UPLOAD_ERR_OK) {
        if (isset($exts2[strtolower(GetFileExt($_FILES['upload_file']['name']))])) {
            // Загружаем файл
            $Dir = System::config('downloads/files_dir');
            $file_name = Translit($_FILES['upload_file']['name'], true);
            $ext = GetFileExt($file_name);
            $name = GetFileName($file_name, true);
            $i = 1;
            while (is_file($Dir . $file_name)) {
                $i++;
                $file_name = $name . '_' . $i . $ext;
            }
            $FileName = $Dir . $file_name;
            copy($_FILES['upload_file']['tmp_name'], $FileName);
            $url = SafeEnv($FileName, 255, str);
        } else {
            $url = SafeEnv($_POST['url'], 255, str);
        }
    } else {
        if ($_FILES['upload_file']['error'] != 4) {
            $Error = $UploadErrors[$_FILES['upload_file']['error']];
        }
        $url = SafeEnv($_POST['url'], 255, str);
    }
    if ($_POST['size'] > 0) {
        $file_size = SafeEnv($_POST['size'], 11, real);
        // Дробное число
        $size_type = SafeEnv($_POST['filesize_type'], 1, str);
    } elseif (file_exists($url)) {
        $file_size = filesize($url);
        $size_type = 'b';
    } elseif (file_exists(System::config('general/site_url') . $url)) {
        $file_size = filesize(System::config('general/site_url') . $url);
        $size_type = 'b';
    } else {
        $file_size = SafeEnv($_POST['size'], 11, int);
        $size_type = 'b';
    }
    $shortdesc = SafeEnv($_POST['shortdesc'], 0, str);
    $description = SafeEnv($_POST['description'], 0, str);
    // Загружаем изображение
    $ImageUploadError = false;
    $image = LoadImage('up_image', System::config('downloads/images_dir'), System::config('downloads/images_dir') . 'thumbs/', System::config('downloads/thumb_max_width'), System::config('downloads/thumb_max_height'), $_POST['image'], $ImageUploadError);
    $author = SafeEnv($_POST['author'], 50, str);
    $author_site = SafeEnv(Url($_POST['author_site']), 250, str);
    $author_email = SafeEnv($_POST['author_email'], 50, str);
    $file_ver = SafeEnv($_POST['version'], 250, str);
    $allow_comments = EnToInt($_POST['allow_comments']);
    $allow_votes = EnToInt($_POST['allow_votes']);
    $view = ViewLevelToInt($_POST['view']);
    $active = EnToInt($_POST['active']);
    if ('editfilesave' == $action) {
        //Здесь генерируем Set запрос
        $set = "title='{$title}',category='{$category}',size='{$file_size}',size_type='{$size_type}',url='{$url}',shortdesc='{$shortdesc}',description='{$description}',image='{$image}',author='{$author}',author_site='{$author_site}',author_email='{$author_email}',file_version='{$file_ver}',allow_comments='{$allow_comments}',allow_votes='{$allow_votes}',view='{$view}',active='{$active}'";
        $id = SafeEnv($_GET['id'], 11, int);
        $r = System::database()->Select('downloads', "`id`='{$id}'");
        if ($r[0]['category'] != $category && $r[0]['active'] == '1') {
            AdminDownloadsGetTree()->CalcFileCounter($r[0]['category'], false);
            AdminDownloadsGetTree()->CalcFileCounter($category, true);
        }
        if ($r[0]['active'] != $active) {
            // Выключили / Включили
            if ($active == 0) {
                AdminDownloadsGetTree()->CalcFileCounter($category, false);
            } else {
                AdminDownloadsGetTree()->CalcFileCounter($category, true);
            }
        }
        System::database()->Update('downloads', $set, "`id`='{$id}'");
        Audit('Архив файлов: Редактирование файла "' . $title . '"');
    } elseif ('addfilesave' == $action) {
        $values = Values('', $category, time(), $file_size, $size_type, $title, $url, $shortdesc, $description, $image, $author, $author_site, $author_email, $file_ver, $allow_comments, 0, $allow_votes, 0, 0, 0, $view, $active);
        System::database()->Insert('downloads', $values);
        Audit('Архив файлов: Добавление файла "' . $title . '"');
        if ($active) {
            AdminDownloadsGetTree()->CalcFileCounter($category, true);
        }
    }
    if ($ImageUploadError) {
        AddTextBox('Ошибка', '<p align="center">Неправильный формат файла. Можно загружать только изображения формата GIF, JPEG или PNG. Остальные изменения сохранены.</p><br><a href="' . GetRefererUrl($_REQUEST['back']) . '" class="button">Далее</a>');
        return;
    }
    if ($Error != '') {
        AddTextBox('Ошибка', '<p align="center">Не удалось загрузить файл, изменения сохранены. Ошибка: ' . $Error . '.</p><br><a href="' . GetRefererUrl($_REQUEST['back']) . '" class="button">Далее</a>');
        return;
    }
    GoRefererUrl($_REQUEST['back']);
}