public function parse($value) { $output_string = $this->getOption('output_string'); if ($output_string) { $output_string = str_replace('}', cmsFormField::FIELD_CACHE_POSTFIX . '}', $output_string); return htmlspecialchars(string_replace_keys_values($output_string, $this->item)); } return htmlspecialchars($this->item[$this->getDenormalName()]); }
public function sendEmail($to, $letter, $data = array()) { if (is_array($to)) { if (empty($to['email'])) { return false; } if (empty($to['name'])) { $to['name'] = false; } } else { if (empty($to)) { return false; } $to = array('email' => $to, 'name' => false); } if (is_array($letter)) { if (empty($letter['text'])) { $letter['text'] = cmsCore::getLanguageTextFile("letters/{$letter['name']}"); } } else { $letter = array('text' => cmsCore::getLanguageTextFile("letters/{$letter}")); } if (!$letter['text']) { return false; } $config = cmsConfig::getInstance(); $data = array_merge(array('site' => $config->sitename, 'date' => html_date(time()), 'time' => html_time(time())), $data); $letter['text'] = string_replace_keys_values($letter['text'], $data); $mailer = new cmsMailer(); $mailer->addTo($to['email'], $to['name']); $letter['text'] = $mailer->parseSubject($letter['text']); $letter['text'] = $mailer->parseAttachments($letter['text']); $mailer->setBodyHTML(nl2br($letter['text'])); $result = $mailer->send(); $mailer->clearTo()->clearAttachments(); return $result; }
public function renderGridRowsJSON($grid, $dataset, $total = 1, $pages_count = 1) { $rows = array(); $row_index = 0; // // проходим по всем строкам из набора данных // if ($total && $dataset) { foreach ($dataset as $row) { $cell_index = 0; // вычисляем содержимое для каждой колонки таблицы foreach ($grid['columns'] as $field => $column) { if (!is_array($row[$field])) { $value = htmlspecialchars($row[$field]); } else { $value = $row[$field]; } if (!$value) { $value = ''; } if (isset($column['flag']) && $column['flag']) { if (isset($column['flag_on'])) { $is_flag_on = $value == $column['flag_on']; } else { $is_flag_on = (bool) $value; } $flag_class = $column['flag'] === true ? 'flag' : $column['flag']; $flag_toggle_url = isset($column['flag_toggle']) ? $column['flag_toggle'] : false; if ($flag_toggle_url) { $flag_toggle_url = string_replace_keys_values($flag_toggle_url, $row); } $flag_content = $flag_toggle_url ? '<a href="' . $flag_toggle_url . '"></a>' : ''; $value = '<div class="flag_trigger ' . ($is_flag_on ? "{$flag_class}_on" : "{$flag_class}_off") . '" data-class="' . $flag_class . '">' . $flag_content . '</div>'; } if (isset($column['handler'])) { $value = $column['handler']($value, $row); } // если из значения нужно сделать ссылку, то парсим шаблон // адреса, заменяя значения полей if (isset($column['href'])) { $column['href'] = string_replace_keys_values($column['href'], $row); $value = '<a href="' . $column['href'] . '">' . $value . '</a>'; } $rows[$row_index][] = $value; $cell_index++; } // если есть колонка действий, то формируем набор ссылок // для текущей строки if ($grid['actions']) { $actions_html = '<div class="actions">'; foreach ($grid['actions'] as $action) { $confirm_attr = ''; if (isset($action['handler'])) { $is_active = $action['handler']($row); } else { $is_active = true; } if ($is_active) { foreach ($row as $cell_id => $cell_value) { if (is_array($cell_value) || is_object($cell_value)) { continue; } // парсим шаблон адреса, заменяя значения полей if (isset($action['href'])) { $action['href'] = str_replace('{' . $cell_id . '}', $cell_value, $action['href']); } // парсим шаблон запроса подтверждения, заменяя значения полей if (isset($action['confirm'])) { $action['confirm'] = str_replace('{' . $cell_id . '}', $cell_value, $action['confirm']); $confirm_attr = 'onclick="if(!confirm(\'' . htmlspecialchars($action['confirm']) . '\')){ return false; }"'; } } $actions_html .= '<a class="' . $action['class'] . '" href="' . $action['href'] . '" title="' . $action['title'] . '" ' . $confirm_attr . '></a>'; } } $actions_html .= '</div>'; $rows[$row_index][] = $actions_html; $cell_index++; } $row_index++; } } $columns = array(); if ($grid['options']['load_columns']) { foreach ($grid['columns'] as $name => $column) { if ($name === 'id' && !$grid['options']['show_id']) { continue; } $columns[] = array('sortable' => $grid['options']['is_sortable'], 'width' => isset($column['width']) ? $column['width'] : '', 'title' => $column['title'], 'name' => $name, 'filter' => isset($column['filter']) && $column['filter'] != 'none' && $column['filter'] != false ? html_input('text', 'filter_' . $name, isset($grid['filter'][$name]) ? $grid['filter'][$name] : '', array('id' => 'filter_' . $name, 'rel' => $name)) : ''); } if ($grid['actions']) { $columns[] = array('sortable' => false, 'width' => sizeof($grid['actions']) * 30, 'title' => LANG_CP_ACTIONS, 'name' => 'dg_actions', 'filter' => ''); } } $result = array('rows' => $rows, 'pages_count' => $pages_count, 'total' => $total, 'columns' => $columns); echo json_encode($result); }