本文整理汇总了PHP中JUDownloadHelper::parseImageNameByTags方法的典型用法代码示例。如果您正苦于以下问题:PHP JUDownloadHelper::parseImageNameByTags方法的具体用法?PHP JUDownloadHelper::parseImageNameByTags怎么用?PHP JUDownloadHelper::parseImageNameByTags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JUDownloadHelper
的用法示例。
在下文中一共展示了JUDownloadHelper::parseImageNameByTags方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveCategoryImage
public function saveCategoryImage($pk, $table, &$data)
{
$app = JFactory::getApplication();
$jInput = $app->input;
if ($pk > 0) {
if ($jInput->post->getInt('remove_jform_images_intro_image', 0) == 1 || $jInput->post->getInt('remove_jform_images_detail_image', 0) == 1 && $jInput->post->getInt('use_detail_image', 0) == 1) {
$intro_image_dir = JPATH_ROOT . "/" . JUDownloadFrontHelper::getDirectory("category_intro_image_directory", "media/com_judownload/images/category/intro/") . $data['images']['intro_image'];
$ori_intro_image_dir = JPATH_ROOT . "/" . JUDownloadFrontHelper::getDirectory("category_intro_image_directory", "media/com_judownload/images/category/intro/") . 'original/' . $data['images']['intro_image'];
$data['images']['intro_image'] = '';
$data['images']['intro_image_alt'] = '';
$data['images']['intro_image_caption'] = '';
JFile::delete($ori_intro_image_dir);
JFile::delete($intro_image_dir);
}
if ($jInput->post->getInt('remove_jform_images_detail_image', 0) == 1) {
$full_image_dir = JPATH_ROOT . "/" . JUDownloadFrontHelper::getDirectory("category_detail_image_directory", "media/com_judownload/images/category/detail/") . $data['images']['detail_image'];
$ori_full_image_dir = JPATH_ROOT . "/" . JUDownloadFrontHelper::getDirectory("category_detail_image_directory", "media/com_judownload/images/category/detail/") . "original/" . $data['images']['detail_image'];
$data['images']['detail_image'] = '';
$data['images']['detail_image_alt'] = '';
$data['images']['detail_image_caption'] = '';
JFile::delete($full_image_dir);
JFile::delete($ori_full_image_dir);
}
}
$mime_types = array("image/jpeg", "image/pjpeg", "image/png", "image/gif", "image/bmp", "image/x-windows-bmp");
$num_files_failed_mime_type = 0;
$images = $app->input->files->get('images', array());
$old_ori_intro_image_path = isset($data['images']['intro_image']) && $data['images']['intro_image'] ? JUDownloadFrontHelper::getDirectory("category_intro_image_directory", "media/com_judownload/images/category/intro/") . 'original/' . $data['images']['intro_image'] : '';
$old_intro_image_path = $old_ori_intro_image_path ? JUDownloadFrontHelper::getDirectory("category_intro_image_directory", "media/com_judownload/images/category/intro/") . $data['images']['intro_image'] : '';
$old_ori_detail_image_path = isset($data['images']['detail_image']) && $data['images']['detail_image'] ? JUDownloadFrontHelper::getDirectory("category_detail_image_directory", "media/com_judownload/images/category/detail/") . 'original/' . $data['images']['detail_image'] : '';
$old_detail_image_path = $old_ori_detail_image_path ? JUDownloadFrontHelper::getDirectory("category_detail_image_directory", "media/com_judownload/images/category/detail/") . $data['images']['detail_image'] : '';
foreach ($images as $key => $image) {
if ($image['name']) {
if (!in_array($image['type'], $mime_types)) {
$num_files_failed_mime_type++;
continue;
}
$info = pathinfo($image['name']);
$replace = array('id' => $table->id, 'document' => '', 'category' => $table->title, 'image_name' => $info['filename']);
$image['name'] = JUDownloadHelper::parseImageNameByTags($replace, 'category', $table->id, null) . '.' . $info['extension'];
if ($key == 'intro' && $app->input->post->get('use_detail_image', 0) != 1) {
$new_ori_image_path = JUDownloadFrontHelper::getDirectory("category_intro_image_directory", "media/com_judownload/images/category/intro/") . 'original/' . $image['name'];
$new_image_path = JUDownloadFrontHelper::getDirectory("category_intro_image_directory", "media/com_judownload/images/category/intro/") . $image['name'];
if (!JFile::upload($image['tmp_name'], JPATH_ROOT . "/" . $new_ori_image_path) || !JUDownloadHelper::renderImages(JPATH_ROOT . "/" . $new_ori_image_path, JPATH_ROOT . "/" . $new_image_path, "category_intro", true, $table->id)) {
unset($images['intro']);
} else {
$delete_old_intro_image = $data['images']['intro_image'] && $data['images']['intro_image'] !== $image['name'] ? true : false;
$data['images']['intro_image'] = $image['name'];
}
if ($delete_old_intro_image) {
if ($old_intro_image_path && JFile::exists(JPATH_ROOT . "/" . $old_intro_image_path)) {
JFile::delete(JPATH_ROOT . "/" . $old_ori_intro_image_path);
JFile::delete(JPATH_ROOT . "/" . $old_intro_image_path);
}
}
}
if ($key == 'detail') {
$new_ori_image_path = JUDownloadFrontHelper::getDirectory("category_detail_image_directory", "media/com_judownload/images/category/detail/") . 'original/' . $image['name'];
$new_image_path = JUDownloadFrontHelper::getDirectory("category_detail_image_directory", "media/com_judownload/images/category/detail/") . $image['name'];
if (!JFile::upload($image['tmp_name'], JPATH_ROOT . "/" . $new_ori_image_path) || !JUDownloadHelper::renderImages(JPATH_ROOT . "/" . $new_ori_image_path, JPATH_ROOT . "/" . $new_image_path, "category_detail", true, $table->id)) {
unset($images['detail']);
} else {
if ($data['images']['detail_image'] && $data['images']['detail_image'] !== $image['name']) {
if ($old_detail_image_path && JFile::exists(JPATH_ROOT . "/" . $old_detail_image_path)) {
JFile::delete(JPATH_ROOT . "/" . $old_ori_detail_image_path);
JFile::delete(JPATH_ROOT . "/" . $old_detail_image_path);
}
}
$data['images']['detail_image'] = $image['name'];
}
}
}
}
if ($num_files_failed_mime_type) {
JError::raise(E_NOTICE, 500, JText::plural('COM_JUDOWNLOAD_N_IMAGES_ARE_NOT_VALID_MIMETYPE', $num_files_failed_mime_type, implode(",", $mime_types)));
}
if ($app->input->post->get('use_detail_image', 0) == 1 && $data['images']['detail_image']) {
$old_ori_detail_image_path = JUDownloadFrontHelper::getDirectory("category_detail_image_directory", "media/com_judownload/images/category/detail/") . 'original/' . $data['images']['detail_image'];
$new_ori_intro_image_path = JUDownloadFrontHelper::getDirectory("category_intro_image_directory", "media/com_judownload/images/category/intro/") . 'original/' . $data['images']['detail_image'];
$new_image_path = JUDownloadFrontHelper::getDirectory("category_intro_image_directory", "media/com_judownload/images/category/intro/") . $data['images']['detail_image'];
if (JFile::copy(JPATH_ROOT . "/" . $old_ori_detail_image_path, JPATH_ROOT . "/" . $new_ori_intro_image_path) && JUDownloadHelper::renderImages(JPATH_ROOT . "/" . $new_ori_intro_image_path, JPATH_ROOT . "/" . $new_image_path, 'category_intro', true, $table->id)) {
if ($data['images']['intro_image'] && $data['images']['intro_image'] !== $data['images']['detail_image']) {
if (JFile::exists(JPATH_ROOT . "/" . $old_ori_intro_image_path)) {
JFile::delete(JPATH_ROOT . "/" . $old_ori_intro_image_path);
}
if (JFile::exists(JPATH_ROOT . "/" . $old_intro_image_path)) {
JFile::delete(JPATH_ROOT . "/" . $old_intro_image_path);
}
}
$data['images']['intro_image'] = $data['images']['detail_image'];
}
}
if (!empty($data['images'])) {
$registry = new JRegistry();
$registry->loadArray($data['images']);
$table->images = (string) $registry;
$table->store();
}
}
示例2: generateImageNameByDocument
public static function generateImageNameByDocument($doc_id, $file_name)
{
if (!$doc_id || !$file_name) {
return "";
}
$dir_document_ori = JPATH_ROOT . "/" . JUDownloadFrontHelper::getDirectory("document_original_image_directory", "media/com_judownload/images/gallery/original/") . $doc_id . "/";
$info = pathinfo($file_name);
$document = JUDownloadHelper::getDocumentById($doc_id);
$replace = array('id' => $document->id, 'category' => '', 'document' => $document->title, 'image_name' => $info['filename']);
$base_file_name = JUDownloadHelper::parseImageNameByTags($replace, 'document', null, $document->id) . "." . $info['extension'];
$img_file_name = $base_file_name;
$img_path_ori = $dir_document_ori . $img_file_name;
while (JFile::exists($img_path_ori)) {
$img_file_name = JUDownloadHelper::generateRandomString(3) . "-" . $base_file_name;
$img_path_ori = $dir_document_ori . $img_file_name;
}
return $img_file_name;
}