public static function getEmailTemplate($contentbuilder_form_id, $record_id, array $record, array $elements_allowed, $isAdmin) { static $_template; $hash = md5(($isAdmin ? 'admin' : 'user') . $contentbuilder_form_id . $record_id . implode(',', $elements_allowed)); if (is_array($_template) && isset($_template[$hash])) { return $_template[$hash]; } $db = JFactory::getDBO(); $db->setQuery("Select `name`,`type`,reference_id,email_template, email_admin_template, email_html, email_admin_html, act_as_registration, registration_name_field, registration_username_field, registration_email_field From #__contentbuilder_forms Where id = " . intval($contentbuilder_form_id)); $result = $db->loadAssoc(); if (is_array($result)) { $user = null; if ($result['act_as_registration']) { $form = contentbuilder::getForm($result['type'], $result['reference_id']); $meta = $form->getRecordMetadata($record_id); $db->setQuery("Select * From #__users Where id = " . $meta->created_id); $user = $db->loadObject(); } $_template = array(); $labels = array(); $allow_html = array(); $db->setQuery("Select `label`,`reference_id`,`options` From #__contentbuilder_elements Where form_id = " . intval($contentbuilder_form_id)); $labels_ = $db->loadAssocList(); foreach ($labels_ as $label_) { $labels[$label_['reference_id']] = $label_['label']; $opts = unserialize(base64_decode($label_['options'])); if ($opts && isset($opts->allow_html) && $opts->allow_html) { $allow_html[$label_['reference_id']] = $opts; } } $template = $isAdmin ? $result['email_admin_template'] : $result['email_template']; $html = $isAdmin ? $result['email_admin_html'] : $result['email_html']; $items = array(); $hasLabels = count($labels); foreach ($record as $item) { if (in_array($item->recElementId, $elements_allowed)) { $items[$item->recName] = array(); $items[$item->recName]['label'] = $hasLabels ? $labels[$item->recElementId] : $item->recTitle; if ($result['act_as_registration'] && $user !== null) { if ($result['registration_name_field'] == $item->recElementId) { $item->recValue = $user->name; } else { if ($result['registration_username_field'] == $item->recElementId) { $item->recValue = $user->username; } else { if ($result['registration_email_field'] == $item->recElementId) { $item->recValue = $user->email; } } } } $items[$item->recName]['value'] = $item->recValue != '' ? $item->recValue : JText::_('COM_CONTENTBUILDER_NOT_AVAILABLE'); $items[$item->recName]['id'] = $item->recElementId; $regex = "/([\\{]hide-if-empty " . $item->recName . "[\\}])(.*)([\\{][\\/]hide[\\}])/isU"; if ($item->recValue == '') { $template = preg_replace($regex, "", $template); } else { $template = preg_replace($regex, '$2', $template); } } } $item = null; $template = str_replace(array('{RECORD_ID}', '{record_id}'), $record_id, $template); $template = str_replace(array('{USER_ID}', '{user_id}'), JFactory::getUser()->get('id'), $template); $template = str_replace(array('{USERNAME}', '{username}'), JFactory::getUser()->get('username'), $template); $template = str_replace(array('{USER_FULL_NAME}', '{user_full_name}'), JFactory::getUser()->get('name'), $template); $template = str_replace(array('{VIEW_NAME}', '{view_name}'), $result['name'], $template); $template = str_replace(array('{VIEW_ID}', '{view_id}'), $contentbuilder_form_id, $template); $template = str_replace(array('{IP}', '{ip}'), $_SERVER['REMOTE_ADDR'], $template); foreach ($items as $key => $item) { $template = str_replace('{' . $key . ':label}', $html ? htmlentities($item['label'], ENT_QUOTES, 'UTF-8') : $item['label'], $template); $template = str_replace('{' . $key . ':value}', isset($allow_html[$item['id']]) && $html ? contentbuilder_is_internal_path($item['value']) ? basename($item['value']) : $item['value'] : nl2br(strip_tags(contentbuilder_is_internal_path($item['value']) ? basename($item['value']) : $item['value'])), $template); $template = str_replace('{webpath ' . $key . '}', str_replace(array('{CBSite}', '{cbsite}', JPATH_SITE), JURI::getInstance()->getScheme() . '://' . JURI::getInstance()->getHost() . (JURI::getInstance()->getPort() == 80 ? '' : ':' . JURI::getInstance()->getPort()) . JURI::root(true), $item['value']), $template); } $_template[$hash] = $template; return $template; } else { ''; } return ''; }
echo '<th>' . JText::_('COM_CONTENTBUILDER_ID') . '</th>'; } foreach ($this->data->visible_labels as $label) { echo '<th>' . $label . '</th>'; } ?> </tr> <?php foreach ($this->data->items as $item) { echo '<tr>'; if ($this->data->show_id_column) { echo '<td>' . $item->colRecord . '</td>'; } foreach ($item as $key => $value) { if ($key != 'colRecord' && in_array(str_replace('col', '', $key), $this->data->visible_cols)) { if ($value) { echo '<td class="text">' . htmlentities(contentbuilder_is_internal_path($value) ? basename($value) : $value, ENT_QUOTES, 'UTF-8') . '</td>'; } else { echo '<td> </td>'; } } } echo '</tr>'; } ?> </table> </body> </html> <?php exit;
function cbinternal($value) { $nl = ''; $out = ''; $values = explode("\n", $value); $length = count($values); $i = 0; foreach ($values as $_value) { if ($i + 1 < $length) { $nl = "\n"; } else { $nl = ''; } $out .= (contentbuilder_is_internal_path($_value) ? basename($_value) : $_value) . $nl; $i++; } return $out; }