Esempio n. 1
0
 public function getData()
 {
     $app = JFactory::getApplication();
     $eventTimeZone = null;
     $error_messages = array();
     jimport('joomla.filter.output');
     // Get Params
     $params = $app->getParams();
     $submitAccess = $params->get('submitAccess', '');
     $approvalGroups = $params->get('approvalGroups', array("8"));
     // Get User
     $user = JFactory::getUser();
     // Get User Groups
     // Joomla 3.x/2.5 SWITCH
     if (version_compare(JVERSION, '3.0', 'ge')) {
         $userGroups = $user->groups;
     } else {
         $userGroups = $user->getAuthorisedGroups();
     }
     $user_id = $user->get('id');
     // logged-in Users: Name/User Name Option
     $nameJoomlaUser = $params->get('nameJoomlaUser', 1);
     $u_name = $nameJoomlaUser == 1 ? $user->get('name') : $user->get('username');
     $this->data = new stdClass();
     $this->data->id = null;
     $this->data->asset_id = JRequest::getVar('asset_id', '', 'post');
     $this->data->ordering = 0;
     $this->data->state = 1;
     // Control: if Manager
     jimport('joomla.access.access');
     $adminUsersArray = array();
     foreach ($approvalGroups as $ag) {
         $adminUsers = JAccess::getUsersByGroup($ag, False);
         $adminUsersArray = array_merge($adminUsersArray, $adminUsers);
     }
     $this->data->approval = in_array($user_id, $adminUsersArray) ? '0' : '1';
     $this->data->access = 1;
     $this->data->language = '*';
     //		$menuID 						= JRequest::getVar('menuID', '', 'post');
     // USER NAME
     $this->data->username = JRequest::getVar('username', '', 'post');
     if (!$this->data->username) {
         $error_messages[] = JText::sprintf('COM_ICAGENDA_FORM_VALIDATE_FIELD_REQUIRED_NAME', JText::_('COM_ICAGENDA_SUBMIT_FORM_USER_NAME'));
     }
     // USER EMAIL
     $this->data->created_by_email = JRequest::getVar('created_by_email', '', 'post');
     if (!$this->data->created_by_email) {
         $error_messages[] = JText::sprintf('COM_ICAGENDA_FORM_VALIDATE_FIELD_REQUIRED_NAME', JText::_('COM_ICAGENDA_SUBMIT_FORM_USER_EMAIL'));
     }
     // EVENT TITLE
     $this->data->title = JRequest::getVar('title', '', 'post');
     if (!$this->data->title) {
         $error_messages[] = JText::sprintf('COM_ICAGENDA_FORM_VALIDATE_FIELD_REQUIRED_NAME', JText::_('COM_ICAGENDA_FORM_LBL_EVENT_TITLE'));
     }
     // EVENT CATEGORY
     $this->data->catid = JRequest::getVar('catid', '', 'post');
     if (!$this->data->catid) {
         $error_messages[] = JText::sprintf('COM_ICAGENDA_FORM_VALIDATE_FIELD_REQUIRED_NAME', JText::_('COM_ICAGENDA_FORM_LBL_EVENT_CATID'));
     }
     // EVENT IMAGE - Get and Upload Image
     $image = JRequest::getVar('image', null, 'files', 'array');
     $image_session = JRequest::getVar('image_session', '', 'post');
     if ($image_session && empty($image)) {
         $this->data->image = $image_session;
     } else {
         $this->data->image = $image;
         // Process upload of files
         $this->data->image = $this->frontendImageUpload($this->data->image);
     }
     $noDateTime = '0000-00-00 00:00:00';
     $noDateTimeShort = '0000-00-00 00:00';
     // Get Single Dates
     $single_dates = JRequest::getVar('dates', '', 'post');
     $dates = iCString::isSerialized($single_dates) ? unserialize($single_dates) : $this->getDates($single_dates);
     //		$dates = !empty($dates[0]) ? $dates : array($noDateTime);
     rsort($dates);
     $datesall = iCDate::isDate($dates[0]) ? $dates[0] : $noDateTimeShort;
     if ($datesall != $noDateTimeShort) {
         $this->data->dates = serialize($dates);
     } else {
         $no_date_array = array($noDateTimeShort);
         $this->data->dates = serialize($no_date_array);
     }
     // Set Next Date from Single Dates
     $dates_array = unserialize($this->data->dates);
     $today = JHtml::date('now', 'Y-m-d H:i:s', $eventTimeZone);
     $next = JHtml::date($this->data->dates[0], 'Y-m-d H:i:s', $eventTimeZone);
     rsort($dates_array);
     $nextDate = $next;
     if ($next <= $today) {
         foreach ($dates_array as $date) {
             $single_date = JHtml::date($date, 'Y-m-d H:i:s', $eventTimeZone);
             if ($single_date >= $today) {
                 $nextDate = $single_date;
             }
         }
     }
     $single_dates_next = $nextDate;
     // PERIOD DATES
     $this->data->startdate = JRequest::getVar('startdate', '', 'post');
     $this->data->enddate = JRequest::getVar('enddate', '', 'post');
     $isDate_startdate = iCDate::isDate($this->data->startdate);
     $isDate_enddate = iCDate::isDate($this->data->enddate);
     $this->data->startdate = $isDate_startdate ? $this->data->startdate : $noDateTime;
     $this->data->enddate = $isDate_enddate ? $this->data->enddate : $noDateTime;
     // Dates from the period
     if ($isDate_startdate && $isDate_enddate) {
         $startdate = $this->data->startdate;
         $enddate = $this->data->enddate;
         if ($startdate == $noDateTime && $enddate != $noDateTime) {
             $enddate = $noDateTime;
         }
         $startcontrol = JHtml::date($startdate, 'Y-m-d H:i', $eventTimeZone);
         $endcontrol = JHtml::date($enddate, 'Y-m-d H:i', $eventTimeZone);
         $errorperiod = '';
         if ($startcontrol > $endcontrol) {
             $errorperiod = '1';
         } else {
             $period_all_dates_array = iCDatePeriod::listDates($startdate, $enddate);
         }
         // Serialize Dates of the Period
         if ($isDate_startdate && $isDate_enddate) {
             if ($errorperiod != '1') {
                 $this->data->period = serialize($period_all_dates_array);
                 $ctrl = unserialize($this->data->period);
                 if (is_array($ctrl)) {
                     $period = unserialize($this->data->period);
                 } else {
                     $period = $this->getPeriod($this->data->period);
                 }
                 rsort($period);
                 $this->data->period = serialize($period);
             } else {
                 $this->data->period = '';
             }
         }
         $period_dates_next = $this->data->startdate;
         $dates_next = JHtml::date($single_dates_next, 'Y-m-d H:i:s', $eventTimeZone);
         $period_next = JHtml::date($period_dates_next, 'Y-m-d H:i:s', $eventTimeZone);
         if ($dates_next < $period_next) {
             $this->data->next = $period_next;
         } else {
             $this->data->next = $dates_next;
         }
     } else {
         $this->data->period = '';
         $this->data->next = $single_dates_next;
     }
     // Period and Single Dates not displayed
     if ((in_array($noDateTime, $dates_array) || in_array($noDateTimeShort, $dates_array)) && (!$isDate_startdate || !$isDate_enddate)) {
         $this->data->state = '0';
         $this->data->next = $today;
         // Error message if no valid dates
         $error_messages[] = JText::sprintf('COM_ICAGENDA_FORM_WARNING', JText::_('COM_ICAGENDA_FORM_ERROR_NO_DATES'));
     }
     // WEEK DAYS
     $this->data->weekdays = JRequest::getVar('weekdays', '', 'post');
     if (!isset($this->data->weekdays) && !is_array($this->data->weekdays)) {
         $this->data->weekdays = '';
     }
     if (isset($this->data->weekdays) && is_array($this->data->weekdays)) {
         $this->data->weekdays = implode(",", $this->data->weekdays);
     }
     // Joomla 3.x/2.5 SWITCH
     if (version_compare(JVERSION, '3.0', 'ge')) {
         $this->data->desc = JFactory::getApplication()->input->get('desc', '', 'RAW');
     } else {
         $this->data->desc = JRequest::getVar('desc', '', 'post', 'string', JREQUEST_ALLOWHTML);
     }
     $this->data->shortdesc = JRequest::getVar('shortdesc', '', 'post');
     $this->data->metadesc = JRequest::getVar('metadesc', '', 'post');
     $this->data->place = JRequest::getVar('place', '', 'post');
     $this->data->email = JRequest::getVar('email', '', 'post');
     $this->data->phone = JRequest::getVar('phone', '', 'post');
     $this->data->website = JRequest::getVar('website', '', 'post');
     // ATTACHMENT FILE
     $file = JRequest::getVar('file', null, 'files', 'array');
     $file_session = JRequest::getVar('file_session', '', 'post');
     if ($file_session && empty($file)) {
         $this->data->file = $file_session;
     } else {
         $this->data->file = $file;
         // Process upload of files
         $this->data->file = $this->frontendFileUpload($this->data->file);
     }
     $this->data->address = JRequest::getVar('address', '', 'post');
     $this->data->city = JRequest::getVar('city', '', 'post');
     $this->data->country = JRequest::getVar('country', '', 'post');
     $this->data->lat = JRequest::getVar('lat', '', 'post');
     $this->data->lng = JRequest::getVar('lng', '', 'post');
     $this->data->created_by = $user_id;
     $this->data->created_by_alias = JRequest::getVar('created_by_alias', '', 'post');
     $this->data->created = JHtml::Date('now', 'Y-m-d H:i:s');
     $this->data->checked_out = JRequest::getVar('checked_out', '', 'post');
     $this->data->checked_out_time = JRequest::getVar('checked_out_time', '', 'post');
     $this->data->params = JRequest::getVar('params', '', 'post');
     $this->data->site_itemid = JRequest::getVar('site_itemid', '0', 'post');
     $site_menu_title = JRequest::getVar('site_menu_title', '', 'post');
     // Generate Alias
     $this->data->alias = JFilterOutput::stringURLSafe($this->data->title);
     // Alias is not generated if non-latin characters, so we fix it by using created date, or title if unicode is activated, as alias
     if ($this->data->alias == null) {
         if (JFactory::getConfig()->get('unicodeslugs') == 1) {
             $this->data->alias = JFilterOutput::stringURLUnicodeSlug($this->data->title);
         } else {
             $this->data->alias = JFilterOutput::stringURLSafe($this->data->created);
         }
     }
     // Convert the params field to a string.
     if (isset($this->data->params) && is_array($this->data->params)) {
         $parameter = new JRegistry();
         $parameter->loadArray($this->data->params);
         $this->data->params = (string) $parameter;
     }
     $this->data->asset_id = null;
     $custom_fields = JRequest::getVar('custom_fields', '', 'post');
     // Check if Custom Fields required not empty
     $customfields_list = icagendaCustomfields::getListCustomFields($this->data->id, 2, 1);
     if ($customfields_list) {
         foreach ($customfields_list as $cf) {
             if (isset($custom_fields[$cf->cf_slug]) && $cf->cf_required == 1 && $custom_fields[$cf->cf_slug] == '') {
                 $options_required = array('list', 'radio');
                 // If type is list or radio, should have options
                 if (in_array($cf->cf_type, $options_required) && $cf->cf_options || !in_array($cf->cf_type, $options_required)) {
                     $error_messages[] = JText::_('COM_ICAGENDA_FORM_VALIDATE_FIELD_REQUIRED') . ' ' . $cf->cf_title;
                 }
             }
         }
     }
     $address_session = JRequest::getVar('address_session', '', 'post');
     $submit_tos = JRequest::getVar('submit_tos', '', 'post');
     // Set Form Data to Session
     $session = JFactory::getSession();
     $session->set('ic_submit', $this->data);
     $session->set('custom_fields', $custom_fields);
     $session->set('ic_submit_dates', $this->data->dates);
     $session->set('ic_submit_catid', $this->data->catid);
     $session->set('ic_submit_shortdesc', $this->data->shortdesc);
     $session->set('ic_submit_metadesc', $this->data->metadesc);
     $session->set('ic_submit_city', $this->data->city);
     $session->set('ic_submit_country', $this->data->country);
     $session->set('ic_submit_lat', $this->data->lat);
     $session->set('ic_submit_lng', $this->data->lng);
     $session->set('ic_submit_address', $this->data->address);
     $session->set('ic_submit_tos', $submit_tos);
     // Captcha Control
     $captcha = JRequest::getVar('recaptcha_response_field', '', 'post');
     $captcha_plugin = $params->get('captcha') ? $params->get('captcha') : $app->getCfg('captcha');
     $submit_captcha = $params->get('submit_captcha', 1);
     if ($captcha_plugin && $submit_captcha != '0') {
         JPluginHelper::importPlugin('captcha');
         // JOOMLA 3.x/2.5 SWITCH
         if (version_compare(JVERSION, '3.0', 'ge')) {
             $dispatcher = JEventDispatcher::getInstance();
         } else {
             $dispatcher = JDispatcher::getInstance();
         }
         $res = $dispatcher->trigger('onCheckAnswer', $captcha);
         if (!$res[0]) {
             // message if captcha is invalid
             $error_messages[] = JText::sprintf('COM_ICAGENDA_FORM_ERROR', JText::_('COM_ICAGENDA_FORM_ERROR_INCORRECT_CAPTCHA_SOL'));
         }
     }
     // Get the message queue
     if (count($error_messages)) {
         $app->enqueueMessage('<strong>' . JText::_('COM_ICAGENDA_FORM_NC') . '</strong>', 'error');
         foreach ($error_messages as $msg) {
             $app->enqueueMessage($msg, 'error');
         }
         return false;
     }
     // clear the data so we don't process it again
     $session->clear('ic_submit');
     $session->clear('custom_fields');
     $session->clear('ic_submit_dates');
     $session->clear('ic_submit_catid');
     $session->clear('ic_submit_shortdesc');
     $session->clear('ic_submit_metadesc');
     $session->clear('ic_submit_city');
     $session->clear('ic_submit_country');
     $session->clear('ic_submit_lat');
     $session->clear('ic_submit_lat');
     $session->clear('ic_submit_address');
     $session->clear('ic_submit_tos');
     // insert Event in Database
     $db = JFactory::getDbo();
     if ($this->data->username != NULL && $this->data->title != NULL && $this->data->created_by_email != NULL) {
         $db->insertObject('#__icagenda_events', $this->data, id);
     } else {
         JError::raiseError(500, implode('<br />', $errors));
         return false;
     }
     // Save Custom Fields to database
     if (isset($custom_fields) && is_array($custom_fields)) {
         icagendaCustomfields::saveToData($custom_fields, $this->data->id, 2);
     }
     // Get the "event" URL
     $baseURL = JURI::base();
     $subpathURL = JURI::base(true);
     $baseURL = str_replace('/administrator', '', $baseURL);
     $subpathURL = str_replace('/administrator', '', $subpathURL);
     $urlsend = str_replace('&amp;', '&', JRoute::_('index.php?option=com_icagenda&view=submit&layout=send'));
     // Sub Path filtering
     $subpathURL = ltrim($subpathURL, '/');
     // URL List filtering
     $urlsend = ltrim($urlsend, '/');
     if (substr($urlsend, 0, strlen($subpathURL) + 1) == "{$subpathURL}/") {
         $urlsend = substr($urlsend, strlen($subpathURL) + 1);
     }
     $urlsend = rtrim($baseURL, '/') . '/' . ltrim($urlsend, '/');
     if (isset($this->data->id) and $this->data->id != '0' and $this->data->username != NULL and $this->data->title != NULL) {
         self::notificationManagerEmail($this->data, $site_menu_title, $user_id);
         if (!in_array($user_id, $adminUsersArray)) {
             self::notificationUserEmail($this->data, $urlsend);
         }
     } else {
         JError::raiseError(500, implode('<br />', $errors));
         return false;
     }
     // redirect after successful submission
     $submit_return = $params->get('submitReturn', '');
     $submit_return_article = $params->get('submitReturn_Article', $urlsend);
     $submit_return_url = $params->get('submitReturn_Url', $urlsend);
     if ($submit_return == 1 && is_numeric($submit_return_article)) {
         $url_return = JURI::root() . 'index.php?option=com_content&view=article&id=' . $submit_return_article;
     } elseif ($submit_return == 2) {
         $url_return = $submit_return_url;
     } else {
         $url_return = $urlsend;
     }
     $alert_title = $params->get('alert_title', '');
     $alert_body = $params->get('alert_body', '');
     $url_redirect = $urlsend_custom ? $urlsend_custom : $urlsend;
     $alert_title_redirect = $alert_title ? $alert_title : JText::_('COM_ICAGENDA_EVENT_SUBMISSION');
     $alert_body_redirect = $alert_body ? $alert_body : JText::_('COM_ICAGENDA_EVENT_SUBMISSION_CONFIRMATION');
     if ($submit_return != 2) {
         $app->enqueueMessage($alert_body_redirect, $alert_title_redirect);
         $app->redirect(htmlspecialchars_decode($url_return));
     } else {
         $url_return = iCUrl::urlParsed($url_return, 'scheme');
         $app->redirect($url_return);
     }
 }
Esempio n. 2
0
 protected function websiteLink($i)
 {
     $gettarget = JComponentHelper::getParams('com_icagenda')->get('targetLink', '');
     $target = !empty($gettarget) ? '_blank' : '_parent';
     $link = iCUrl::urlParsed($i->website, 'scheme');
     return '<a href="' . $link . '" target="' . $target . '">' . $i->website . '</a>';
 }
Esempio n. 3
0
 /**
  * Return the link to the thumbnail of an image
  *
  * @since   1.0.0
  */
 public static function thumbnail($image, $thumbsPath, $subFolder, $width, $height, $quality, $crop = null, $prefix = null, $type = null, $checksize = null, $name = null)
 {
     $app = JFactory::getApplication();
     $file_local = JPATH_ROOT . '/' . $image;
     $file_distant = $image;
     $linkToImage = filter_var($image, FILTER_VALIDATE_URL) ? $file_distant : $file_local;
     // Set memory_limit if possible to 512mo, and check needed memory to generate thumbnails
     ini_set('memory_limit', '512M');
     // Check if fopen is allowed
     $fopen = true;
     $result = ini_get('allow_url_fopen');
     if (empty($result)) {
         $fopen = false;
     }
     // Initialize Vars
     $Image_Link = '';
     $Thumb_Link = '';
     $Display_Thumb = false;
     $MimeTypeOK = true;
     $MimeTypeERROR = false;
     $Invalid_Link = false;
     $Invalid_Img_Format = false;
     $fopen_bmp_error_msg = false;
     $Invalid_LinkMsg = '<i class="icon-warning"></i><br /><span style="color:red;"><strong>' . JText::_('ICLIB_INVALID_PICTURE_LINK') . '</strong></span>';
     $Wrong_img_format = '<i class="icon-warning"></i><br/><span style="color:red;"><strong>' . JText::_('ICLIB_NOT_AUTHORIZED_IMAGE_TYPE') . '</strong><br/>' . JText::_('ICLIB_NOT_AUTHORIZED_IMAGE_TYPE_INFO') . '</span>';
     $fopen_bmp_error = '<i class="icon-warning"></i><br/><span style="color:red;"><strong>' . JText::_('ICLIB_PHP_ERROR_FOPEN_COPY_BMP') . '</strong><br/>' . JText::_('ICLIB_PHP_ERROR_FOPEN_COPY_BMP_INFO') . '</span>';
     $error_icthumb = '<i class="icon-warning"></i><br/><span style="color:red;"><strong>' . JText::_('ICLIB_ERROR_ICTHUMB') . '</strong><br/>' . JText::_('ICLIB_ERROR_ICTHUMB_INFO') . '</span>';
     // Mime-Type pre-settings
     $errorMimeTypeMsg = '<i class="icon-warning"></i><br /><span style="color:red;"><strong>' . JText::_('ICLIB_ERROR_MIME_TYPE') . '</strong><br/>' . JText::_('ICLIB_ERROR_MIME_TYPE_NO_THUMBNAIL');
     // Folder for copy of distant images, and jpg created from bmp
     $copyPath = $thumbsPath . '/copy';
     $cropped = $crop ? 'c' : '';
     // Thumb Destination
     if ($name) {
         $thumb_name = '';
     } elseif ($prefix) {
         $thumb_name = $prefix . '_w' . $width . 'h' . $height . 'q' . $quality . $cropped . '_';
     } else {
         $thumb_name = 'w' . $width . 'h' . $height . 'q' . $quality . $cropped . '_';
     }
     $thumb_destination = $subFolder . '/' . $thumb_name;
     // Get Image File Infos
     //		$url = $image;
     //		$decomposition = explode( '/' , $url );
     // in each parent
     //		$i = 0;
     //		while ( isset($decomposition[$i]) )
     //			$i++;
     //		$i--;
     //		$imgname = $decomposition[$i];
     //		$fichier = explode( '.', $decomposition[$i] );
     //		$imgtitle = $fichier[0];
     //		$imgextension = strtolower($fichier[1]); // fixed 3.1.10
     $image_info = pathinfo($image);
     $imgtitle = $image_info['filename'];
     $imgextension = strtolower($image_info['extension']);
     // To be checked if error with uppercase extension type
     // Clean file name
     jimport('joomla.filter.output');
     $cleanFileName = JFilterOutput::stringURLSafe($imgtitle) . '.' . $imgextension;
     $cleanTitle = JFilterOutput::stringURLSafe($imgtitle);
     // Image pre-settings
     $imageValue = $image;
     $Image_Link = $image;
     // url to thumbnails already created
     $Thumb_Link = $thumbsPath . '/' . $thumb_destination . $cleanFileName;
     $Thumb_aftercopy_Link = $thumbsPath . '/' . $thumb_destination . $cleanTitle . '.jpg';
     // url to copy original jpg created
     $MAX_aftercopy_Link = $copyPath . '/' . $cleanTitle . '.jpg';
     $file_copy = JPATH_ROOT . '/' . $MAX_aftercopy_Link;
     // Fix for previous version, if original image is too small (ic_large image only, used in event details view)
     $original_too_small = false;
     if ($prefix == 'ic_large') {
         $file_to_check = filter_var($image, FILTER_VALIDATE_URL) ? $file_copy : $file_local;
         list($w, $h) = getimagesize($file_to_check);
         if ($w < $width or $h < $height) {
             $max_image_size = filter_var($image, FILTER_VALIDATE_URL) ? $MAX_aftercopy_Link : $image;
             $original_too_small = true;
         }
     }
     // Check if thumbnails already created
     if (file_exists(JPATH_ROOT . '/' . $Thumb_Link) || $original_too_small) {
         $Thumb_Link = $original_too_small ? $max_image_size : $Thumb_Link;
         $Display_Thumb = true;
     } elseif (file_exists(JPATH_ROOT . '/' . $Thumb_aftercopy_Link) || $original_too_small) {
         $Thumb_Link = $original_too_small ? $max_image_size : $Thumb_aftercopy_Link;
         $Display_Thumb = true;
     } else {
         $memory_limit = ini_get('memory_limit');
         if (preg_match('/^(\\d+)(.)$/', $memory_limit, $matches)) {
             if ($matches[2] == 'M') {
                 $memory_limit = $matches[1] * 1024 * 1024;
                 // nnnM -> nnn MB
             } elseif ($matches[2] == 'K') {
                 $memory_limit = $matches[1] * 1024;
                 // nnnK -> nnn KB
             }
         }
         list($w, $h) = getimagesize($linkToImage);
         $rgba_factor = 4;
         $security_factor = 1.8;
         if (function_exists('memory_get_usage') && $w * $h * $rgba_factor * $security_factor + memory_get_usage() > $memory_limit) {
             if ($app->isAdmin()) {
                 $alert_message = JText::sprintf('ICLIB_ERROR_ALERT_IMAGE_TOO_LARGE', $image);
                 // Get the message queue
                 $messages = $app->getMessageQueue();
                 $display_alert_message = false;
                 // If we have messages
                 if (is_array($messages) && count($messages)) {
                     // Check each message for the one we want
                     foreach ($messages as $key => $value) {
                         if ($value['message'] == $alert_message) {
                             $display_alert_message = true;
                         }
                     }
                 }
                 if (!$display_alert_message) {
                     $app->enqueueMessage($alert_message, 'Warning');
                 }
                 return JText::_('ICLIB_ERROR_IMAGE_TOO_LARGE');
             } else {
                 return false;
             }
         }
         if (file_exists($linkToImage)) {
             // Test Mime-Type
             $fileinfos = getimagesize($linkToImage);
             $mimeType = $fileinfos['mime'];
             $extensionType = 'image/' . $imgextension;
             // SETTINGS ICTHUMB
             $errorMimeTypeInfo = '<span style="color:black;"><br/>' . JText::sprintf('ICLIB_ERROR_MIME_TYPE_INFO', $imgextension, $mimeType);
             // Error message if Mime-Type is not the same as extension
             if ($imgextension == 'jpeg' or $imgextension == 'jpg') {
                 if ($mimeType != 'image/jpeg' and $mimeType != 'image/jpg') {
                     $MimeTypeOK = false;
                     $MimeTypeERROR = true;
                 }
             } elseif ($imgextension == 'bmp') {
                 if ($mimeType != 'image/bmp' and $mimeType != 'image/x-ms-bmp') {
                     $MimeTypeOK = false;
                     $MimeTypeERROR = true;
                 }
             } elseif ($mimeType != $extensionType) {
                 $MimeTypeOK = false;
                 $MimeTypeERROR = true;
             }
         }
         // If Error mime-type, no thumbnail creation
         if ($MimeTypeOK) {
             // Call function and create image thumbnail for events list in admin
             // If Image JPG, JPEG, PNG or GIF
             if ($imgextension == "jpg" or $imgextension == "jpeg" or $imgextension == "png" or $imgextension == "gif") {
                 $Thumb_Link = $Thumb_Link;
                 if (!file_exists(JPATH_ROOT . '/' . $Thumb_Link)) {
                     if (filter_var($imageValue, FILTER_VALIDATE_URL)) {
                         if (iCUrl::url_exists($imageValue) and $fopen) {
                             $testFile = JPATH_ROOT . '/' . $copyPath . '/' . $cleanFileName;
                             if (!file_exists($testFile)) {
                                 //Get the file
                                 $content = file_get_contents($imageValue);
                                 //Store in the filesystem.
                                 $fp = fopen(JPATH_ROOT . '/' . $copyPath . '/' . $cleanFileName, "w");
                                 fwrite($fp, $content);
                                 fclose($fp);
                             }
                             $linkToImage = JPATH_ROOT . '/' . $copyPath . '/' . $cleanFileName;
                             $imageValue = $copyPath . '/' . $cleanFileName;
                         } else {
                             $linkToImage = $imageValue;
                         }
                     } else {
                         $linkToImage = JPATH_ROOT . '/' . $imageValue;
                     }
                     if (iCUrl::url_exists($linkToImage) or file_exists($linkToImage)) {
                         iCThumbCreate::createThumb($linkToImage, JPATH_ROOT . '/' . $Thumb_Link, $width, $height, $quality, $crop, $prefix, $checksize);
                     } else {
                         $Invalid_Link = true;
                     }
                 }
             } elseif ($imgextension == "bmp") {
                 $Image_Link = $copyPath . '/' . $cleanTitle . '.jpg';
                 $Thumb_Link = $Thumb_aftercopy_Link;
                 if (!file_exists(JPATH_ROOT . '/' . $Thumb_Link)) {
                     if (filter_var($imageValue, FILTER_VALIDATE_URL)) {
                         if (iCUrl::url_exists($imageValue) and $fopen) {
                             $testFile = JPATH_ROOT . '/' . $copyPath . '/' . $cleanTitle . '.jpg';
                             if (!file_exists($testFile)) {
                                 // Get the file
                                 $content = file_get_contents($imageValue);
                                 // Store in the filesystem.
                                 $fp = fopen(JPATH_ROOT . '/' . $copyPath . '/' . $cleanFileName, "w");
                                 fwrite($fp, $content);
                                 fclose($fp);
                                 $imageNewValue = JPATH_ROOT . '/' . $copyPath . '/' . $cleanFileName;
                                 imagejpeg(iCThumbImage::createFromBMP($imageNewValue), JPATH_ROOT . '/' . $copyPath . '/' . $cleanTitle . '.jpg', 100);
                                 unlink($imageNewValue);
                             }
                         } else {
                             $linkToImage = $imageValue;
                         }
                     } else {
                         imagejpeg(iCThumbImage::createFromBMP(JPATH_ROOT . '/' . $imageValue), JPATH_ROOT . '/' . $copyPath . '/' . $cleanTitle . '.jpg', 100);
                     }
                     $imageValue = $copyPath . '/' . $cleanTitle . '.jpg';
                     $linkToImage = JPATH_ROOT . '/' . $imageValue;
                     if (!$fopen) {
                         $fopen_bmp_error_msg = true;
                     } elseif (iCUrl::url_exists($linkToImage) or file_exists($linkToImage)) {
                         iCThumbCreate::createThumb($linkToImage, JPATH_ROOT . '/' . $Thumb_Link, $width, $height, $quality, $crop, $prefix, $checksize);
                     } else {
                         $Invalid_Link = true;
                     }
                 }
             } else {
                 if (iCUrl::url_exists($linkToImage) or file_exists($linkToImage)) {
                     $Invalid_Img_Format = true;
                 } else {
                     $Invalid_Link = true;
                 }
             }
             if (!$Invalid_Link) {
                 $Display_Thumb = true;
             }
         } else {
             if ($imgextension == "jpg" or $imgextension == "jpeg" or $imgextension == "png" or $imgextension == "gif" or $imgextension == "bmp") {
                 $MimeTypeERROR = true;
             } else {
                 $Invalid_Img_Format = true;
                 $MimeTypeERROR = false;
             }
         }
     }
     if ($type == 'imgTag' || $type == 'imgTagLinkModal') {
         // Display Thumbnail Image tag
         $thumbnailImgTag = '';
         if ($Invalid_Img_Format) {
             $thumbnailImgTag .= $app->isAdmin() ? $Wrong_img_format : '';
         }
         if ($Invalid_Link) {
             $thumbnailImgTag .= $app->isAdmin() ? $Invalid_LinkMsg : '';
         }
         if ($MimeTypeERROR) {
             $thumbnailImgTag .= $app->isAdmin() ? $errorMimeTypeMsg : '';
             $thumbnailImgTag .= $app->isAdmin() ? $errorMimeTypeInfo : '';
         }
         if ($fopen_bmp_error_msg) {
             $thumbnailImgTag .= $app->isAdmin() ? $fopen_bmp_error : '';
         }
         if ($Display_Thumb) {
             if ($imgextension == "bmp") {
                 if ($type == 'imgTagLinkModal') {
                     $thumbnailImgTag .= '<a href="' . JURI::root(true) . '/' . $MAX_aftercopy_Link . '" class="modal">';
                 }
                 $thumbnailImgTag .= '<img src="' . JURI::root(true) . '/' . $Thumb_aftercopy_Link . '" alt="" />';
                 if ($type == 'imgTagLinkModal') {
                     $thumbnailImgTag .= '</a>';
                 }
             } else {
                 if ($type == 'imgTagLinkModal') {
                     if (filter_var($Image_Link, FILTER_VALIDATE_URL)) {
                         $thumbnailImgTag .= '<a href="' . $Image_Link . '" class="modal">';
                     } else {
                         $thumbnailImgTag .= '<a href="' . JURI::root(true) . '/' . $Image_Link . '" class="modal">';
                     }
                 }
                 $thumbnailImgTag .= '<img src="' . JURI::root(true) . '/' . $Thumb_Link . '" alt="" />';
                 if ($type == 'imgTagLinkModal') {
                     $thumbnailImgTag .= '</a>';
                 }
             }
         }
         if (!file_exists(JPATH_ROOT . '/' . $Thumb_Link) && $image && !$fopen) {
             $thumbnailImgTag .= $app->isAdmin() ? $error_icthumb : '';
         }
         return $thumbnailImgTag;
     } else {
         // Display Thumbnail Image tag
         $thumb_img = '';
         // Set Thumbnail
         $default_thumbnail = 'media/com_icagenda/images/nophoto.jpg';
         if ($Invalid_Img_Format || $Invalid_Link || $MimeTypeERROR || $fopen_bmp_error_msg || !file_exists(JPATH_ROOT . '/' . $Thumb_Link) && $image) {
             $thumb_img = $default_thumbnail;
         } elseif ($Display_Thumb) {
             $thumb_img = $Thumb_Link;
         }
         return $thumb_img;
     }
 }