'.Text::_('COM_VISFORMS_BETA').'' : ''; $betaWarning = ($isBeta) ? '
'.Text::_('COM_VISFORMS_BETA_WARNING').'' : ''; $msg = self::backendUpdateWarning(); $html = '
'. self::backendUpdateWarning() .'Visforms ' . Text::_('COM_VISFORMS_VERSION') . ' ' . self::getVersion() . $beta . (!empty(AefHelper::getVersion()) ? ', Subscription ' . Text::_('COM_VISFORMS_VERSION') . ' ' . AefHelper::getVersion() . $beta: ' ' . Text::_('COM_VISFORMS_WITHOUT_SUBSCRIPTION')) . ', © 2012 - ' . self::getCopyRightDate() . ' vi-solutions' . Text::_('COM_VISFORMS_OPEN_SOFTWARE') . ' GNU/GPL License.'.$betaWarning.'
'; $html .= ($isBeta) ? ' ' : ''; return $html; } public static function backendUpdateWarning() { $minSubVersion = self::getParamFromXMLFile('vfsubminversion', JPATH_ADMINISTRATOR . '/manifests/packages/pkg_vfbase.xml'); $subVersion = AefHelper::getVersion(); return (!empty($subVersion) && !empty($minSubVersion) && (version_compare($subVersion, $minSubVersion, 'lt'))) ? ''. Text::sprintf('COM_VISFORMS_SUBSCRIPTION_UPDATE_REQUIRED', $minSubVersion) . '
' : ''; } public static function creditsFrontend($id) { return '
' . Text::_('COM_VISFORMS_POWERED_BY') . '
'; } public static function getVersion(): string { $installed_version = self::getParamFromXMLFile('version', JPATH_ADMINISTRATOR . '/components/com_visforms/visforms.xml'); if (empty($installed_version)) { $installed_version = '1.0.0'; } return $installed_version; } public static function getParamFromXMLFile($param, $path): string { if (empty($param) || empty($path)) { return ''; } $xml_file = Path::clean($path); if (file_exists($xml_file)) { //supress warnings libxml_use_internal_errors(true); $xml = simplexml_load_file($xml_file); return (string) $xml->$param; } return ''; } public static function checkMySubmissionsMenuItemExists() { // don't allow access to data edit view if there is not visforms data edit list menu item $app = Factory::getApplication(); $menuitems = $app->getMenu()->getItems('link', 'index.php?option=com_visforms&view=mysubmissions'); if ((!(empty($menuitems))) && (is_array($menuitems)) && (!empty($menuitems[0]->id))) { return $menuitems[0]->id; } return false; } public static function checkDataViewMenuItemExists($id) { // don't allow access to data edit view if there is not visforms data edit list menu item $app = Factory::getApplication(); $id = (int) $id; $menuitems = $app->getMenu()->getItems('link', 'index.php?option=com_visforms&view=visformsdata&layout=dataeditlist&id=' . $id); if ((!(empty($menuitems))) && (is_array($menuitems)) && (!empty($menuitems[0]->id))) { return $menuitems[0]->id; } return false; } public static function getCopyRightDate() { return HTMLHelper::_('date', 'now', 'Y'); } public static function getRestrictedId($restrict) { return preg_replace('/[^0-9]/', '', $restrict); } public static function getUploadFileFullPath($registryString) { if (empty($registryString)) { return ''; } // info about uploaded files are stored in a JSON Object. $registry = new Registry(); $registry->loadString($registryString); $fileInfo = $registry->toArray(); if (isset($fileInfo['folder'])) { return Uri::root() . $fileInfo['folder'] . '/' . $fileInfo['file']; } else { return ''; } } public static function getUploadFileLink($registryString, $linkTextType = 0, $customLinkText = ''): string { if (empty($registryString)) { return ''; } // info about uploaded files are stored in a JSON Object. $registry = new Registry(); $registry->loadString($registryString); $fileInfo = $registry->toArray(); if (isset($fileInfo['folder']) && isset($fileInfo['file'])) { // get return link text $linkText = self::getUploadFileLinkText($fileInfo, $linkTextType, $customLinkText); // return link return '' . $linkText . ''; } else { return ''; } } public static function getUploadFilePath($registryString): string { if (empty($registryString)) { return ''; } // info about uploaded files are stored in a JSON Object. $registry = new Registry(); $registry->loadString($registryString); $fileInfo = $registry->toArray(); if ((isset($fileInfo['file'])) && (isset($fileInfo['folder']))) { return $fileInfo['folder'] . '/' . $fileInfo['file']; } else { return ''; } } public static function getUploadFileName($registryString): string { if (empty($registryString)) { return ''; } // info about uploaded files are stored in a JSON Object. $registry = new Registry(); $registry->loadString($registryString); $fileInfo = $registry->toArray(); if (isset($fileInfo['file'])) { return $fileInfo['file']; } else { return ''; } } public static function getFileOrgName($registryString): string { $newName = self::getUploadFileName($registryString); // newName was created from the original file name plus _ plus microtimehash if (!empty($newName)) { // get file extesion $dotSplit = explode('.', $newName); if (!empty($dotSplit)) { $extension = array_pop($dotSplit); // remove microtime hash $newBaseName = implode('.', $dotSplit); if (!empty($extension) && !empty($newBaseName)) { $nameParts = explode('_', $newBaseName); if (!empty($nameParts)) { // remove microtime hash element from array array_pop($nameParts); // rebuild original file name $orgBaseName = implode('_', $nameParts); if (!empty($orgBaseName)) { return $orgBaseName . '.' . $extension; } } } } } return ''; } private static function getUploadFileLinkText($fileInfo, $linkTextType, $customLinkText) { switch ($linkTextType) { case 1 : return $fileInfo['file']; case 2: if (!empty($customLinkText)) { return $customLinkText; } // otherwise use default which is the link break; case 3: if (!empty($fileInfo['file'])) { $wa = Factory::getApplication()->getDocument()->getWebAssetManager(); // make sure joomla-fontawesome css is loaded $wa->registerAnduseStyle('system.joomla-fontawesome', 'system/joomla-fontawesome.css'); $imagesExtensions = array('bmp','gif','jpg','jpeg','png','webp'); $audioExtensions = array('mp3','m4a','mp4a','ogg'); $videoExtensions = array('mp4','mp4v','mpeg','mov','webm'); $wordExtensions = array('doc','docx'); $textExtensions = array('txt'); $excelExtensions = array('xls','csv'); $pdfExtensions = array('pdfs'); $zipExtensions = array('zip'); // get file extesion $dotSplit = explode('.', $fileInfo['file']); if (!empty($dotSplit)) { $extension = array_pop($dotSplit); if (in_array($extension, $imagesExtensions)) { return ''; } if (in_array($extension, $audioExtensions)) { return ''; } if (in_array($extension, $videoExtensions)) { return ''; } if (in_array($extension, $wordExtensions)) { return ''; } if (in_array($extension, $excelExtensions)) { return ''; } if (in_array($extension, $textExtensions)) { return ''; } if (in_array($extension, $pdfExtensions)) { return ''; } if (in_array($extension, $zipExtensions)) { return ''; } } return ''; } break; default : break; } return Uri::root() . $fileInfo['folder'] . '/' . $fileInfo['file'] ; } public static function replaceLinebreaks($text, $replace) { if (empty($text) || empty($replace)) { return $text; } $NEWLINE_RE = '/(\r\n)|\r|\n/'; // take care of all possible newline-encodings in input return preg_replace($NEWLINE_RE, $replace, $text); } public static function includeScriptsOnlyOnce($cssScripts = array('visforms.default.min' => true), $jsScripts = array('validation' => true)) { // Add css and js links // visforms.min is the css file with the css styles that are needed in all layouts // therefore it is always included except it is explicitly excluded in the function call $wa = Factory::getApplication()->getDocument()->getWebAssetManager(); if (!isset($cssScripts['visforms.min'])) { $cssScripts['visforms.min'] = true; } // include all css files with "custom" in filename $customCSS = self::getCustomCssFileNameList(); $cssScripts = array_merge($cssScripts, $customCSS); foreach ($cssScripts as $scriptName => $scriptValue) { $wa->registerAndUseStyle('com_visforms.' . $scriptName, 'com_visforms/' . $scriptName . '.css'); } if (!isset($jsScripts['validation'])) { $jsScripts['validation'] = true; } if ($jsScripts['validation'] === true) { // we use addCustomTag to load jQuery library and dependent scripts. If already included they are stored in this array $wa = Factory::getApplication()->getDocument()->getWebAssetManager(); $wa->useScript('com_visforms.validator.messages') ->useScript('com_visforms.validator.methods') ->useScript('com_visforms.visforms'); if (!empty($jsScripts['phpError'])) { $wa->useScript('com_visforms.form.php.error'); } Text::script('COM_VISFORMS_WARNING_SELECT_UPLOAD_FILE_AGAIN'); Text::script('COM_VISFORMS_ENTER_REQUIRED'); Text::script('COM_VISFORMS_ENTER_VALID_EMAIL'); Text::script('COM_VISFORMS_ENTER_VALID_URL'); Text::script('COM_VISFORMS_ENTER_VALID_DATE'); Text::script('COM_VISFORMS_ENTER_VALID_NUMBER'); Text::script('COM_VISFORMS_ENTER_VALID_DIGIT'); Text::script('COM_VISFORMS_ENTER_CONFIRM'); Text::script('COM_VISFORMS_ENTER_VALID_MAXLENGTH'); Text::script('COM_VISFORMS_ENTER_VALID_MINLENGTH'); Text::script('COM_VISFORMS_ENTER_VALID_LENGTH'); Text::script('COM_VISFORMS_ENTER_VALID_RANGE'); Text::script('COM_VISFORMS_ENTER_VALID_MAX_VALUE'); Text::script('COM_VISFORMS_ENTER_VALID_MIN_VALUE'); Text::script('COM_VISFORMS_INVALID_INPUT'); Text::script('COM_VISFORMS_ISPAIR_VALIDATION_FAILED_JS'); Text::script('COM_VISFORMS_CALCULATION_MIN_VALUE_INVALID'); Text::script('COM_VISFORMS_CALCULATION_MAX_VALUE_INVALID'); Text::script('COM_VISFORMS_ENTER_REQUIRED_WITH_INCLUDE'); Text::script('COM_VISFORMS_MINDATE_VALIDATION_FAILED_JS'); Text::script('COM_VISFORMS_MAXDATE_VALIDATION_FAILED_JS'); Text::script('COM_VISFORMS_VALIDATOR_ERROR_COUNT_MESSAGE1'); Text::script('COM_VISFORMS_VALIDATOR_ERROR_COUNT_MESSAGE2'); Text::script('COM_VISFORMS_STEP'); Text::script('COM_VISFORMS_INVALID_UPLOAD_FILE_NAME'); } } public static function getCustomText($field, $position, $cssClass = '') { if (self::customTextTop == $position) { if (($field->customtext != '') && (isset($field->customtextposition)) && (($field->customtextposition == 0) || ($field->customtextposition == 1))) { PluginHelper::importPlugin('content'); $customtext = HTMLHelper::_('content.prepare', $field->customtext); return '
' . $customtext. '
'; } } if (self::customTextBottom == $position) { if (($field->customtext != '') && (((isset($field->customtextposition)) && ($field->customtextposition == 2)) || !(isset($field->customtextposition)))) { PluginHelper::importPlugin('content'); $customtext = HTMLHelper::_('content.prepare', $field->customtext); return '
' . $customtext. '
'; } } } public static function fixLinksInMail($text) { $urlPattern = '/^(http|https|ftp|mailto|tel)\:.*$/i'; $aPattern = '/<[ ]*a[^>]+href=[("\')]([^("\')]*)/'; $imgPattern = '/<[ ]*img[^>]+src=[("\')]([^("\')]*)/'; if (preg_match_all($aPattern, $text, $hrefs)) { $unique_urls = array_unique($hrefs[1]); foreach ($unique_urls as $href) { if (empty($href)) { continue; } if (!(preg_match($urlPattern, $href) == 1)) { //we deal with an intern Url without Root path $link = Uri::base() . $href; $newText = preg_replace('\'' . preg_quote($href) . '\'', $link, $text); $text = $newText; } } } if (preg_match_all($imgPattern, $text, $srcs)) { $unique_image = array_unique($srcs[1]); foreach ($unique_image as $src) { if (file_exists($src)) { //we deal with a local img if (!(preg_match('\'' . preg_quote(Uri::base()) . '\'', $src) == 1)) { //we deal with an intern Url without base Uri $link = Uri::base() . $src; $newText = preg_replace('\'' . preg_quote($src) . '\'', $link, $text); $text = $newText; } } } } return $text; } // ToDo parameter $tip, jsFunction no longer needed // this is a copy of HTMLHelper::_(gird.sort... // necessary to use our own function because we cannot change the icon prefix in Joomla! grid.sort function into visicon // and to allow multiple sort forms on one page (since Visforms 3.7.1) public static function sort($title, $order, $direction = 'asc', $selected = '', $task = null, $new_direction = 'asc', $tip = '', $context = 'adminForm', $unSortable = false) { $title = Text::_($title); if (!empty($unSortable)) { return Text::_($title); } $wa = Factory::getApplication()->getDocument()->getWebAssetManager(); $wa->useScript('com_visforms.visformsdata'); $helpText = htmlspecialchars(Text::_('JGLOBAL_CLICK_TO_SORT_THIS_COLUMN') . ': ' . $title, ENT_COMPAT); HTMLHelper::_('bootstrap.tooltip'); $direction = strtolower($direction); $icon = array('arrow-up-3', 'arrow-down-3'); $index = (int) ($direction == 'desc'); if ($order != $selected) { $direction = $new_direction; } else { $direction = ($direction == 'desc') ? 'asc' : 'desc'; } $html = array(); $html[] = ''; $html[] = ''; $html[] = Text::_($title); $html[] = ''; if ($order == $selected) { $html[] = ' '; } $html[] = ''. $helpText . ''; $html[] = ''; return implode('', $html); } public static function base64_url_encode($val) { return strtr(base64_encode($val), '+/=', '-_,'); } public static function base64_url_decode($val) { return base64_decode(strtr($val, '-_,', '+/=')); } public static function createSelectFromDb($table, $params = true, $textfieldname = "a.title", $where = '', $order = '', $textprefix = '', $valueprefix = '', $requiresSub = true) { $hasSub = AefHelper::checkAEF(); if (empty($requiresSub) || (!empty($hasSub)) && !empty($table)) { $db = Factory::getContainer()->get(DatabaseInterface::class); $query = $db->createQuery(); $query->select($db->quoteName('a.id', 'value') . ', ' . $db->quoteName($textfieldname, 'text')) ->from($db->quoteName($table, 'a')); if (!empty($where)) { $query->where($where); } if (!empty($order)) { $query->order($db->quoteName($order) . ' DESC'); } // Get the options try { $db->setQuery($query); $options = $db->loadObjectList(); } catch (\RuntimeException $e) { $options = array(); } if (!empty($options)) { $count = count($options); for ($i = 0; $i < $count; $i++) { if (!empty($valueprefix)) { $options[$i]->value = Text::_($valueprefix) . $options[$i]->value; } if (!empty($textprefix)) { $options[$i]->text = Text::_($textprefix) . ': ' . $options[$i]->text; } } } } else { $options = array(); } // If params is an array, push these options to the array if (is_array($params)) { $options = array_merge($params, $options); } return $options; } public static function getCustomUserFieldValue($id, $user = null, $queryFunction = 'loadResult') { if (empty($id)) { return false; } if (empty($user)) { $user = Factory::getApplication()->getIdentity(); } $userId = $user->id; if (empty($userId)) { return false; } $db = Factory::getContainer()->get(DatabaseInterface::class); $query = $db->createQuery(); $query->select($db->qn('value')) ->from($db->qn('#__fields_values')) ->where($db->qn('field_id') . ' = ' . $id) ->where($db->qn('item_id') . ' = ' . $userId); try { $db->setQuery($query); $value = $db->$queryFunction(); } catch (\RuntimeException $e) { $value = false; } return $value; } public static function getCustomUserFieldType($id) { if (empty($id)) { return false; } $db = Factory::getContainer()->get(DatabaseInterface::class); $query = $db->createQuery(); $query->select($db->qn('type')) ->from($db->qn('#__fields')) ->where($db->qn('id') . ' = ' . $id); try { $db->setQuery($query); return $db->loadResult(); } catch (\RuntimeException $e) { return false; } } public static function getVisToolTipTemplate() { // class tooltip is used in order to get custom tooltip styling from template css // class vistt is used to attach bootstrap 5 tooltip css, which controls display and design of tooltip // css in visforms.tooltip.css return ''; } // Used in all layouts exept uikit public static function visformsTooltip() { $template = self::getVisToolTipTemplate(); $wa = Factory::getApplication()->getDocument()->getWebAssetManager(); $wa->registerAndUseStyle('visforms.tooltip', 'media/com_visforms/css/visforms.tooltip.min.css', array('version' => 'auto', 'relative' => false, 'detectBrowser' => false, 'detectDebug' => false)); HTMLHelper::_('bootstrap.tooltip', '.visToolTip', array('template' => $template)); } // Load visforms-dataview.js public static function loadDataTaskJs() { $wa = Factory::getApplication()->getDocument()->getWebAssetManager(); $wa->useScript('com_visforms.visformsdata'); } private static function getCustomCssFileNameList() { $path = Path::clean(JPATH_ROOT . '/media/com_visforms/css/'); $result = array(); $dirFiles = scandir($path); $regex = '@^(.*custom.*)(\.css)$@'; foreach ($dirFiles as $key => $value) { if (is_file(Path::clean($path . $value))) { if (preg_match($regex, $value, $match)) { if ($match) { $match = preg_replace($regex, '$1', $value); $result[$match] = true; } } } } return $result; } }