*
 *
 * @package     GravityFlow
 * @subpackage  Classes/Gravity_Flow_Step_Feed_MailChimp
 * @copyright   Copyright (c) 2015, Steven Henty
 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
 * @since       1.0
 */
if (!class_exists('GFForms')) {
    die;
}
class Gravity_Flow_Step_Feed_MailChimp extends Gravity_Flow_Step_Feed_Add_On
{
    public $_step_type = 'mailchimp';
    protected $_class_name = 'GFMailChimp';
    public function get_label()
    {
        return esc_html__('MailChimp', 'gravityflow');
    }
    public function get_icon_url()
    {
        return $this->get_base_url() . '/images/mailchimp.svg';
    }
    function get_feed_label($feed)
    {
        $label = $feed['meta']['feedName'];
        return $label;
    }
}
Gravity_Flow_Steps::register(new Gravity_Flow_Step_Feed_MailChimp());
                }
            }
        }
        GFFormsModel::refresh_product_cache($form, $lead = RGFormsModel::get_lead($lead['id']));
        //saving total field as the last field of the form.
        if (!empty($total_fields)) {
            foreach ($total_fields as $total_field) {
                gravity_flow()->log_debug(__METHOD__ . '(): Saving total field.');
                GFFormsModel::save_input($form, $total_field, $lead, $current_fields, $total_field->id);
                GFFormsModel::refresh_lead_field_value($lead['id'], $total_field->id);
            }
        }
    }
    /**
     * Replace the workflow_note merge tag and the tags in the base step class.
     *
     * @param string $text The text with merge tags.
     * @param Gravity_Flow_Assignee $assignee
     *
     * @return mixed
     */
    public function replace_variables($text, $assignee)
    {
        $text = parent::replace_variables($text, $assignee);
        $comment = rgpost('gravityflow_note');
        $text = str_replace('{workflow_note}', $comment, $text);
        return $text;
    }
}
Gravity_Flow_Steps::register(new Gravity_Flow_Step_User_Input());
        if ($feedback) {
            return $feedback;
        }
        if (!in_array($action, array('approve', 'reject'))) {
            return false;
        }
        $entry_id = rgars($token, 'scopes/entry_id');
        if (empty($entry_id) || $entry_id != $entry['id']) {
            return new WP_Error('incorrect_entry_id', esc_html__('Error: incorrect entry.', 'gravityflow'));
        }
        $step_id = rgars($token, 'scopes/step_id');
        if (empty($step_id) || $step_id != $this->get_id()) {
            return new WP_Error('step_already_processed', esc_html__('Error: step already processed.', 'gravityflow'));
        }
        $assignee_key = sanitize_text_field($token['sub']);
        $assignee = new Gravity_Flow_Assignee($assignee_key, $this);
        $new_status = false;
        switch ($token['scopes']['action']) {
            case 'approve':
                $new_status = 'approved';
                break;
            case 'reject':
                $new_status = 'rejected';
                break;
        }
        $feedback = $this->process_assignee_status($assignee, $new_status, $form);
        return $feedback;
    }
}
Gravity_Flow_Steps::register(new Gravity_Flow_Step_Approval());
        $url = GFCommon::replace_variables($url, $this->get_form(), $entry, true, false, false, 'text');
        $this->log_debug(__METHOD__ . '() - url after replacing variables: ' . $url);
        $method = strtoupper($this->method);
        $body = null;
        $headers = array();
        if (in_array($method, array('POST', 'PUT'))) {
            if ($this->format == 'json') {
                $headers = array('Content-type' => 'application/json');
                $body = json_encode($entry);
            } else {
                $headers = array();
                $body = $entry;
            }
        }
        $args = array('method' => $method, 'timeout' => 45, 'redirection' => 3, 'blocking' => true, 'headers' => $headers, 'body' => $body, 'cookies' => array());
        $args = apply_filters('gravityflow_webhook_args', $args, $entry, $this);
        $response = wp_remote_request($url, $args);
        $this->log_debug(__METHOD__ . '() - response: ' . print_r($response, true));
        if (is_wp_error($response)) {
            $step_status = 'error';
        } else {
            $step_status = 'success';
        }
        $note = esc_html__('Webhook sent. Url: ' . $url);
        $this->add_note($note, 0, 'webhook');
        do_action('gravityflow_post_webhook', $response, $args, $entry, $this);
        return $step_status;
    }
}
Gravity_Flow_Steps::register(new Gravity_Flow_Step_Webhook());
    public function get_label()
    {
        return esc_html__('Zapier', 'gravityflow');
    }
    public function get_icon_url()
    {
        return $this->get_base_url() . '/images/zapier-icon.svg';
    }
    function get_feeds()
    {
        $form_id = $this->get_form_id();
        $feeds = GFZapierData::get_feed_by_form($form_id);
        return $feeds;
    }
    function process_feed($feed)
    {
        $form = $this->get_form();
        $entry = $this->get_entry();
        GFZapier::send_form_data_to_zapier($entry, $form);
    }
    function intercept_submission()
    {
        remove_action('gform_after_submission', array('GFZapier', 'send_form_data_to_zapier'));
    }
    function get_feed_label($feed)
    {
        return $feed['name'];
    }
}
Gravity_Flow_Steps::register(new Gravity_Flow_Step_Feed_Zapier());
 /**
  * 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;
 }
<?php

/**
 * Gravity Flow Step Feed Emma
 *
 *
 * @package     GravityFlow
 * @subpackage  Classes/Gravity_Flow_Step_Feed_Emma
 * @copyright   Copyright (c) 2015, Steven Henty
 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
 * @since       1.0
 */
if (!class_exists('GFForms')) {
    die;
}
class Gravity_Flow_Step_Feed_Emma extends Gravity_Flow_Step_Feed_Add_On
{
    public $_step_type = 'emma';
    protected $_class_name = 'GFEmma';
    public function get_label()
    {
        return esc_html__('Emma', 'gravityflow');
    }
    function get_feed_label($feed)
    {
        $label = $feed['meta']['feed_name'];
        return $label;
    }
}
Gravity_Flow_Steps::register(new Gravity_Flow_Step_Feed_Emma());
            return;
        }
        $notification['workflow_notification_type'] = 'workflow';
        $notification['fromName'] = $this->workflow_notification_from_name;
        $notification['from'] = $this->workflow_notification_from_email;
        $notification['replyTo'] = $this->workflow_notification_reply_to;
        $notification['bcc'] = $this->workflow_notification_bcc;
        $notification['subject'] = $this->workflow_notification_subject;
        $notification['message'] = $this->workflow_notification_message;
        $this->send_notifications($assignees, $notification);
        $note = esc_html__('Sent Notification: ', 'gravityflow') . $this->get_name();
        $this->add_note($note);
    }
    /**
     * Replace the workflow_note merge tag and the tags in the base step class.
     *
     * @param string $text The text with merge tags.
     * @param Gravity_Flow_Assignee $assignee
     *
     * @return mixed
     */
    public function replace_variables($text, $assignee)
    {
        $text = parent::replace_variables($text, $assignee);
        $comment = rgpost('gravityflow_note');
        $text = str_replace('{workflow_note}', $comment, $text);
        return $text;
    }
}
Gravity_Flow_Steps::register(new Gravity_Flow_Step_Notification());
<?php

/**
 * Gravity Flow Step Feed Twlio
 *
 *
 * @package     GravityFlow
 * @subpackage  Classes/Gravity_Flow_Step_Feed_Twilio
 * @copyright   Copyright (c) 2015, Steven Henty
 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
 * @since       1.0
 */
if (!class_exists('GFForms')) {
    die;
}
class Gravity_Flow_Step_Feed_Twilio extends Gravity_Flow_Step_Feed_Add_On
{
    public $_step_type = 'twilio';
    protected $_class_name = 'GFTwilio';
    public function get_label()
    {
        return esc_html__('Twilio', 'gravityflow');
    }
    public function get_icon_url()
    {
        return $this->get_base_url() . '/images/twilio-icon-red.svg';
    }
}
Gravity_Flow_Steps::register(new Gravity_Flow_Step_Feed_Twilio());
    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 
        }
    }
<?php

/**
 * Gravity Flow Step Feed Campaign Monitor
 *
 *
 * @package     GravityFlow
 * @subpackage  Classes/Gravity_Flow_Step_Feed_Campaign_Monitor
 * @copyright   Copyright (c) 2015, Steven Henty
 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
 * @since       1.0
 */
if (!class_exists('GFForms')) {
    die;
}
class Gravity_Flow_Step_Feed_Campaign_Monitor extends Gravity_Flow_Step_Feed_Add_On
{
    public $_step_type = 'campaign_monitor';
    protected $_class_name = 'GFCampaignMonitor';
    public function get_label()
    {
        return esc_html__('Campaign Monitor', 'gravityflow');
    }
}
Gravity_Flow_Steps::register(new Gravity_Flow_Step_Feed_Campaign_Monitor());
    {
        if (class_exists('GF_User_Registration')) {
            parent::process_feed($feed);
            return;
        }
        $form = $this->get_form();
        $entry = $this->get_entry();
        remove_filter('gform_disable_registration', '__return_true');
        GFUser::gf_create_user($entry, $form);
        // Make sure it's not run twice
        add_filter('gform_disable_registration', '__return_true');
    }
    function intercept_submission()
    {
        if (class_exists('GF_User_Registration')) {
            parent::intercept_submission();
            return;
        }
        add_filter('gform_disable_registration', '__return_true');
    }
    function get_feed_label($feed)
    {
        if (class_exists('GF_User_Registration')) {
            return parent::get_feed_label($feed);
        }
        $label = $feed['meta']['feed_type'] == 'create' ? __('Create', 'gravityflow') : __('Update', 'gravityflow');
        return $label;
    }
}
Gravity_Flow_Steps::register(new Gravity_Flow_Step_Feed_User_Registration());