/** * Target for the gform_pre_replace_merge_tags filter. Replaces the workflow_timeline and created_by merge tags. * * * @param string $text * @param array $form * @param array $entry * @param bool $url_encode * @param bool $esc_html * @param bool $nl2br * @param string $format * * @return string */ function replace_variables($text, $form, $entry, $url_encode, $esc_html, $nl2br, $format) { preg_match_all('/{workflow_timeline(:(.*?))?}/', $text, $timeline_matches, PREG_SET_ORDER); if (is_array($timeline_matches) && isset($timeline_matches[0])) { $full_tag = $timeline_matches[0][0]; require_once gravity_flow()->get_base_path() . '/includes/pages/class-entry-detail.php'; $notes = Gravity_Flow_Entry_Detail::get_timeline_notes($entry); $html = ''; foreach ($notes as $note) { $html .= '<br />'; $html .= GFCommon::format_date($note->date_created, false, 'd M Y g:i a', false); $html .= ': '; if (empty($note->user_id)) { if ($note->user_name !== 'gravityflow') { $step = Gravity_Flow_Steps::get($note->user_name); if ($step) { $html .= $step->get_label(); } } else { $html .= esc_html(gravity_flow()->translate_navigation_label('Workflow')); } } else { $html .= esc_html($note->user_name); } $html .= '<br />'; $html .= nl2br(esc_html($note->value)); $html .= '<br />'; } $text = str_replace($full_tag, $html, $text); } preg_match_all('/{created_by(:(.*?))?}/', $text, $created_by_matches, PREG_SET_ORDER); if (is_array($created_by_matches)) { if (!empty($entry['created_by'])) { $entry_creator = new WP_User($entry['created_by']); foreach ($created_by_matches as $created_by_match) { if (!isset($created_by_match[2])) { continue; } $full_tag = $created_by_match[0]; $property = $created_by_match[2]; if ($property == 'roles') { $value = implode(', ', $entry_creator->roles); } else { $value = $entry_creator->get($property); } $value = esc_html($value); $text = str_replace($full_tag, $value, $text); } } } return $text; }
public static function notes_grid($notes, $is_editable, $emails = null, $subject = '') { if (empty($notes)) { return; } foreach ($notes as $note) { ?> <div id="gravityflow-note-<?php echo $note->id; ?> " class="gravityflow-note gravityflow-note-<?php echo $note->user_name; ?> "> <div class="gravityflow-note-avatar"> <div> <?php if (empty($note->user_id)) { $img_url = ''; if ($note->user_name !== 'gravityflow') { $step = Gravity_Flow_Steps::get($note->user_name); if ($step) { $img_url = $step->get_icon_url(); } } if (empty($img_url)) { $img_url = gravity_flow()->get_base_url() . '/images/gravityflow-icon-blue.svg'; } if (strpos($img_url, 'http') !== false) { printf('<img class="avatar avatar-65 photo" src="%s" style="width:65px;height:65px;" />', $img_url); } else { printf('<span class="avatar avatar-65 photo">%s</span>', $img_url); } } else { echo get_avatar($note->user_id, 65); } ?> </div> <div></div> </div> <div class="gravityflow-note-body-wrap"> <div class="gravityflow-note-body"> <div class="gravityflow-note-header"> <div class="gravityflow-note-title"> <?php if (empty($note->user_id)) { if ($note->user_name == 'gravityflow') { echo esc_html(gravity_flow()->translate_navigation_label('Workflow')); } else { $step = Gravity_Flow_Steps::get($note->user_name); if ($step) { echo $step->get_label(); } else { echo esc_html($note->user_name); } } } else { echo esc_html($note->user_name); } ?> </div> <div class="gravityflow-note-meta"> <?php echo esc_html(GFCommon::format_date($note->date_created, false, 'd M Y g:i a', false)); ?> </div> </div> <div class="gravityflow-note-body"> <?php echo nl2br(esc_html($note->value)); ?> </div> </div> </div> </div> <?php } }