function getOrCreateThumbnail($orig_path, $file_no, $refresh_url, $small = 0, $medium = 0, $large = 0, $frontUpload = 0) { if ($frontUpload) { $returnFrontMessage = ''; } $onlyThumbnailInfo = 0; if ($small == 0 && $medium == 0 && $large == 0) { $onlyThumbnailInfo = 1; } $path = PhocaGalleryHelper::getPathSet(); $orig_path_server = str_replace(DS, '/', $path['orig_abs'] . '/'); $file['name'] = PhocaGalleryHelper::getTitleFromFilenameWithExt($file_no); $file['path_with_name'] = str_replace(DS, '/', JPath::clean($orig_path . DS . $file_no)); $file['path_with_name_relative'] = $path['orig_rel_ds'] . str_replace($orig_path_server, '', $file['path_with_name']); $file['path_with_name_relative_no'] = str_replace($orig_path_server, '', $file['path_with_name']); $file['path_without_name'] = str_replace(DS, '/', JPath::clean($orig_path . DS)); $file['path_without_name_relative'] = $path['orig_rel_ds'] . str_replace($orig_path_server, '', $file['path_without_name']); $file['path_without_name_relative_no'] = str_replace($orig_path_server, '', $file['path_without_name']); $file['path_without_name_thumbs'] = $file['path_without_name'] . 'thumbs'; $file['path_without_name_no'] = str_replace($file['name'], '', $file['path_with_name']); $file['path_without_name_thumbs_no'] = str_replace($file['name'], '', $file['path_with_name'] . 'thumbs'); $ext = strtolower(JFile::getExt($file['name'])); switch ($ext) { case 'jpg': case 'png': case 'gif': case 'jpeg': //Get File thumbnails name $thumbnail_file_s = PhocaGalleryHelper::getThumbnailName($file_no, 'small'); $file['thumb_name_s_no_abs'] = $thumbnail_file_s['abs']; $file['thumb_name_s_no_rel'] = $thumbnail_file_s['rel']; //$file['thumb_name_s_no']= str_replace($file['name'], 'thumbs/' . $file['thumb_name_s'], $file_no); $thumbnail_file_m = PhocaGalleryHelper::getThumbnailName($file_no, 'medium'); $file['thumb_name_m_no_abs'] = $thumbnail_file_m['abs']; $file['thumb_name_m_no_rel'] = $thumbnail_file_m['rel']; //$file['thumb_name_m_no']= str_replace($file['name'], 'thumbs/' . $file['thumb_name_m'], $file_no); $thumbnail_file_l = PhocaGalleryHelper::getThumbnailName($file_no, 'large'); $file['thumb_name_l_no_abs'] = $thumbnail_file_l['abs']; $file['thumb_name_l_no_rel'] = $thumbnail_file_l['rel']; //$file['thumb_name_l_no']= str_replace($file['name'], 'thumbs/' . $file['thumb_name_l'], $file_no); // Don't create thumbnails from watermarks... $dontCreateThumb = PhocaGalleryHelper::dontCreateThumb($file['name']); if ($dontCreateThumb == 1) { $onlyThumbnailInfo = 1; // WE USE $onlyThumbnailInfo FOR NOT CREATE A THUMBNAIL CLAUSE } // We want only information from the pictures OR if ($onlyThumbnailInfo == 0) { //Create thumbnail folder if not exists $creatingFolder = "ErrorCreatingFolder"; $creatingFolder = PhocaGalleryHelper::createFolderThumbnail($file['path_without_name_no'], $file['path_without_name_thumbs_no'] . '/'); $thumbInfo = $file_no; switch ($creatingFolder) { case 'Success': //case 'ThumbnailExists': //case 'ThumbnailExists': case 'DisabledThumbCreation': //case 'OnlyInformation': break; default: // BACKEND OR FRONTEND if ($frontUpload != 1) { PhocaGalleryHelper::getProcessPage($file['name'], $thumbInfo, $refresh_url, $creatingFolder, $frontUpload); exit; } else { $returnFrontMessage = $creatingFolder; } break; } // Folder must exist if (JFolder::exists($file['path_without_name_thumbs_no'])) { //There are a lot of photos, please create thumbnails //Small thumbnail if ($small == 1) { $creatingS = PhocaGalleryHelper::createFileThumbnail($file['path_with_name'], $file['thumb_name_s_no_abs'], 'small', $frontUpload); } else { $creatingS = 'ThumbnailExists'; // in case we only need medium or large, because of if clause bellow } //Medium thumbnail if ($medium == 1) { $creatingM = PhocaGalleryHelper::createFileThumbnail($file['path_with_name'], $file['thumb_name_m_no_abs'], 'medium', $frontUpload); } else { $creatingM = 'ThumbnailExists'; // in case we only need small or large, because of if clause bellow } //Large thumbnail if ($large == 1) { $creatingL = PhocaGalleryHelper::createFileThumbnail($file['path_with_name'], $file['thumb_name_l_no_abs'], 'large', $frontUpload); } else { $creatingL = 'ThumbnailExists'; // in case we only need small or medium, because of if clause bellow } // Error messages for all 3 thumbnails (if the message contains error string, we got error // Other strings can be: // - ThumbnailExists - do not display error message nor success page // - OnlyInformation - do not display error message nor success page // - DisabledThumbCreation - do not display error message nor success page $creatingSError = false; $creatingMError = false; $creatingLError = false; $creatingSError = preg_match("/Error/i", $creatingS); $creatingMError = preg_match("/Error/i", $creatingM); $creatingLError = preg_match("/Error/i", $creatingL); // BACKEND OR FRONTEND if ($frontUpload != 1) { // There is an error while creating thumbnail in m or in s or in l if ($creatingSError || $creatingMError || $creatingLError) { if ($creatingSError) { $creatingError = $creatingS; } if ($creatingMError) { $creatingError = $creatingM; } if ($creatingLError) { $creatingError = $creatingL; // if all or two errors appear, we only display the last error message } // because the errors in this case is the same PhocaGalleryHelper::getProcessPage($file['name'], $thumbInfo, $refresh_url, $creatingError); exit; } else { if ($creatingS == 'Success' && $creatingM == 'Success' && $creatingL == 'Success') { PhocaGalleryHelper::getProcessPage($file['name'], $thumbInfo, $refresh_url); exit; } else { if ($creatingS == 'Success' && $creatingM == 'Success' && $creatingL == 'ThumbnailExists') { PhocaGalleryHelper::getProcessPage($file['name'], $thumbInfo, $refresh_url); exit; } else { if ($creatingS == 'Success' && $creatingM == 'ThumbnailExists' && $creatingL == 'ThumbnailExists') { PhocaGalleryHelper::getProcessPage($file['name'], $thumbInfo, $refresh_url); exit; } else { if ($creatingS == 'Success' && $creatingM == 'ThumbnailExists' && $creatingL == 'Success') { PhocaGalleryHelper::getProcessPage($file['name'], $thumbInfo, $refresh_url); exit; } else { if ($creatingS == 'ThumbnailExists' && $creatingM == 'ThumbnailExists' && $creatingL == 'Success') { PhocaGalleryHelper::getProcessPage($file['name'], $thumbInfo, $refresh_url); exit; } else { if ($creatingS == 'ThumbnailExists' && $creatingM == 'Success' && $creatingL == 'Success') { PhocaGalleryHelper::getProcessPage($file['name'], $thumbInfo, $refresh_url); exit; } else { if ($creatingS == 'ThumbnailExists' && $creatingM == 'Success' && $creatingL == 'ThumbnailExists') { PhocaGalleryHelper::getProcessPage($file['name'], $thumbInfo, $refresh_url); exit; } } } } } } } } } else { // There is an error while creating thumbnail in m or in s or in l if ($creatingSError || $creatingMError || $creatingLError) { if ($creatingSError) { $creatingError = $creatingS; } if ($creatingMError) { $creatingError = $creatingM; } if ($creatingLError) { $creatingError = $creatingL; // if all or two errors appear, we only display the last error message } // because the errors in this case is the same $returnFrontMessage = $creatingError; } else { if ($creatingS == 'Success' && $creatingM == 'Success' && $creatingL == 'Success') { $returnFrontMessage = 'Success'; } else { if ($creatingS == 'Success' && $creatingM == 'Success' && $creatingL == 'ThumbnailExists') { $returnFrontMessage = 'Success'; } else { if ($creatingS == 'Success' && $creatingM == 'ThumbnailExists' && $creatingL == 'ThumbnailExists') { $returnFrontMessage = 'Success'; } else { if ($creatingS == 'Success' && $creatingM == 'ThumbnailExists' && $creatingL == 'Success') { $returnFrontMessage = 'Success'; } else { if ($creatingS == 'ThumbnailExists' && $creatingM == 'ThumbnailExists' && $creatingL == 'Success') { $returnFrontMessage = 'Success'; } else { if ($creatingS == 'ThumbnailExists' && $creatingM == 'Success' && $creatingL == 'Success') { $returnFrontMessage = 'Success'; } else { if ($creatingS == 'ThumbnailExists' && $creatingM == 'Success' && $creatingL == 'ThumbnailExists') { $returnFrontMessage = 'Success'; } } } } } } } } } if ($frontUpload == 1) { return $returnFrontMessage; } // Old Error handling (not for all thumbs) //Refresh the site after creating thumbnails - we can do e.g. 100 thumbanails /* switch ($creating) { case 'Success': PhocaGalleryHelper::getProcessPage( $file['name'], $refresh_url); break; case 'ThumbnailExists': case 'DisabledThumbCreation': case 'OnlyInformation': break; default: PhocaGalleryHelper::getProcessPage( $file['name'], $refresh_url, $creating); break; }*/ } } break; } return $file; }