} elseif ($params->get('jomsocial') == 2) { if (!modPWebContactJomSocialHelper::isUserProfileView()) { if ($params->get('debug')) { $app->enqueueMessage(JText::_('MOD_PWEBCONTACT_INTEGRATION_COMPONENT_VIEW_WARNING'), 'warning'); } return; } } elseif ($params->get('sobipro') == 2) { if (!modPWebContactSobiProHelper::isEntryView()) { if ($params->get('debug')) { $app->enqueueMessage(JText::_('MOD_PWEBCONTACT_INTEGRATION_COMPONENT_VIEW_WARNING'), 'warning'); } return; } } elseif ($params->get('zoo') == 2) { if (!modPWebContactZooHelper::isItemView()) { if ($params->get('debug')) { $app->enqueueMessage(JText::_('MOD_PWEBCONTACT_INTEGRATION_COMPONENT_VIEW_WARNING'), 'warning'); } return; } } // Display error if jQuery not installed if (!class_exists('JHtmlJquery')) { $app->enqueueMessage(JText::_('MOD_PWEBCONTACT_INSTALL_PWEBLEGACY_ERR'), 'error'); return; } // Auto RTL if ($params->get('rtl', 2) == 2) { if (!JFactory::getLanguage()->isRTL()) { $params->set('rtl', 0);
protected static function parseTmplVars(&$content, $is_html = true, $lang_code = 'en-GB') { $cache_key = $lang_code . '_' . (int) $is_html . '_' . md5($content); if (!isset(self::$email_tmpls[$cache_key])) { $params = self::getParams(); $app = JFactory::getApplication(); $patterns = $replacements = $fields_replacements = array(); // text direction if ($is_html) { $patterns[] = '{dir}'; $replacements[] = $params->get('rtl', 0) ? 'rtl' : 'ltr'; } // Language variables if (preg_match_all('/{lang:([^}]+)}/i', $content, $lang_vars, PREG_SET_ORDER)) { foreach ($lang_vars as $variable) { $patterns[] = $variable[0]; $replacements[] = JText::_($variable[1]); } } // Zoo variables if ($params->get('zoo') and $item_id = $app->input->getInt('zoo', 0) and preg_match_all('/{zoo.([^}]+)}/i', $content, $zoo_vars, PREG_SET_ORDER)) { foreach ($zoo_vars as $variable) { $patterns[] = $variable[0]; $replacements[] = modPWebContactZooHelper::getFieldValue($item_id, $variable[1]); } } // Varaibles with fields $cache_fields_key = $lang_code . '_' . (int) $is_html . '_fields'; $search_fields = strpos($content, '{fields}') !== false; $fields = self::getFields(); foreach ($fields as $field) { // skip all separators which does not have any data if (strpos($field->type, 'separator') !== false) { continue; } if (isset(self::$data['fields'][$field->alias])) { $value = self::$data['fields'][$field->alias]; } else { $value = null; } switch ($field->type) { case 'textarea': if ($is_html and $value) { $value = nl2br($value); } break; case 'checkboxes': case 'multiple': if (is_array($value)) { foreach ($value as &$val) { $val = JText::_($val); } $value = implode(', ', $value); } break; case 'checkbox': case 'radio': case 'select': if ($value) { $value = JText::_($value); } break; } $patterns[] = '{' . $field->alias . '.value}'; $replacements[] = $value; $patterns[] = '{' . $field->alias . '.label}'; $replacements[] = $name = JText::_($field->name); if ($search_fields and !isset(self::$email_tmpls[$cache_fields_key])) { //TODO test RTL if need to change position of sprintf arguments $fields_replacements[] = JText::sprintf('MOD_PWEBCONTACT_EMAIL_FIELD_FORMAT_' . ($is_html ? 'HTML' : 'TEXT'), $name, $value); } } // all fields if ($search_fields) { if (!isset(self::$email_tmpls[$cache_fields_key])) { self::$email_tmpls[$cache_fields_key] = implode($is_html ? '<br>' : "\r\n", $fields_replacements); } $patterns[] = '{fields}'; $replacements[] = self::$email_tmpls[$cache_fields_key]; } // attachments if (strpos($content, '{files}') !== false) { $patterns[] = '{files}'; // attachments as links if (count(self::$data['attachments']) and $params->get('attachment_type', 1) == 2) { $cache_files_key = $lang_code . '_' . (int) $is_html . '_files'; if (!isset(self::$email_tmpls[$cache_files_key])) { $urls = array(); $url = $params->get('upload_url'); foreach (self::$data['attachments'] as $file) { $urls[] = JText::sprintf('MOD_PWEBCONTACT_EMAIL_FILE_FORMAT_' . ($is_html ? 'HTML' : 'TEXT'), $url . rawurlencode($file), $file); } self::$email_tmpls[$cache_files_key] = implode($is_html ? '<br>' : "\r\n", $urls); } $replacements[] = self::$email_tmpls[$cache_files_key]; } else { $replacements[] = ''; } } // system foreach (self::$email_vars as $variable => $value) { $patterns[] = '{' . $variable . '}'; $replacements[] = $value; } // replace email variables with values $content = str_replace($patterns, $replacements, $content); self::$email_tmpls[$cache_key] = $content; } else { $content = self::$email_tmpls[$cache_key]; } }