AdditionalOptions.class.php
2 months ago
CampaignInfo.class.php
2 months ago
Campaigns.class.php
2 months ago
ClickTracking.class.php
2 months ago
ContactForm7.class.php
2 months ago
Debugging.class.php
4 weeks ago
EDD.class.php
4 weeks ago
General.class.php
4 weeks ago
Integrations.class.php
2 months ago
LifterLMS.class.php
2 months ago
Marketpress.class.php
4 weeks ago
MemberPress.class.php
2 months ago
Membership2.class.php
2 months ago
PMPro.class.php
2 months ago
PPBuyNowButton.class.php
2 months ago
RestrictContentPro.class.php
2 months ago
S2Member.class.php
2 months ago
Signup.class.php
2 months ago
SimplePayPro.class.php
2 months ago
StripePayments.class.php
4 weeks ago
SureCart.class.php
2 months ago
WPEasyCart.class.php
2 months ago
WPPayForms.class.php
2 months ago
WishListMember.class.php
2 months ago
WooComm.class.php
4 weeks ago
ContactForm7.class.php
224 lines
| 1 | <?php |
| 2 | if (!defined('ABSPATH')) exit; |
| 3 | |
| 4 | class postaffiliatepro_Form_Settings_ContactForm7 extends postaffiliatepro_Form_Base { |
| 5 | const CONTACT7_SIGNUP_COMMISSION_ENABLED = 'contact7-signup-commission-enabled'; |
| 6 | const CONTACT7_SIGNUP_COMMISSION_CONFIG_PAGE = 'contact7-signup-commission-config-page'; |
| 7 | const CONTACT7_CONTACT_COMMISSION_AMOUNT = 'contact7-contact-commission-amount'; |
| 8 | const CONTACT7_CONTACT_COMMISSION_CAMPAIGN = 'contact7-contact-commission-campaign'; |
| 9 | const CONTACT7_CONTACT_COMMISSION_TYPE = 'contact7-contact-commission-type'; |
| 10 | const CONTACT7_CONTACT_COMMISSION_FORM = 'contact7-contact-commission-form'; |
| 11 | const CONTACT7_CONTACT_EMAIL_AS_ORDERID = 'contact7-contact-email-as-orderid'; |
| 12 | const CONTACT7_CONTACT_COMMISSION_STORE_FORM = 'contact7-contact-commission-store-form'; |
| 13 | const CONTACT7_CONTACT_SEPARATE_ACTIONS = 'contact7-contact-separate-actions'; |
| 14 | const CONTACT7_DATA2 = 'contact7-data2'; |
| 15 | const CONTACT7_DATA3 = 'contact7-data3'; |
| 16 | const CONTACT7_DATA4 = 'contact7-data4'; |
| 17 | const CONTACT7_DATA5 = 'contact7-data5'; |
| 18 | const CONTACT7_PRODUCTID = 'contact7-prodid'; |
| 19 | |
| 20 | private $Contact7PostedData = array(); |
| 21 | |
| 22 | public function __construct() { |
| 23 | parent::__construct(self::CONTACT7_SIGNUP_COMMISSION_CONFIG_PAGE, 'options.php'); |
| 24 | } |
| 25 | |
| 26 | private function getFormData() { |
| 27 | if (count($this->Contact7PostedData) == 0) { |
| 28 | return ''; |
| 29 | } |
| 30 | $output = ''; |
| 31 | foreach ($this->Contact7PostedData as $key => $value) { |
| 32 | $output .= $key . ': ' . $value . ', '; |
| 33 | } |
| 34 | return substr($output,0,-2); |
| 35 | } |
| 36 | |
| 37 | private function getEmail() { |
| 38 | if (count($this->Contact7PostedData) == 0) { |
| 39 | return ''; |
| 40 | } |
| 41 | foreach ($this->Contact7PostedData as $key => $value) { |
| 42 | if (strpos(strtolower($key), 'email') !== false) { |
| 43 | return $value; |
| 44 | } |
| 45 | } |
| 46 | return ''; |
| 47 | } |
| 48 | |
| 49 | private function commissionEnabledForForm($form) { |
| 50 | if (get_option(self::CONTACT7_CONTACT_COMMISSION_FORM) == '0') { |
| 51 | return true; |
| 52 | } |
| 53 | return get_option(self::CONTACT7_CONTACT_COMMISSION_FORM) == $form->id; |
| 54 | } |
| 55 | |
| 56 | private function contactForm7ContactCommissionEnabled() { |
| 57 | return postaffiliatepro_Util_ContactForm7Helper::formsExists() && get_option(self::CONTACT7_SIGNUP_COMMISSION_ENABLED) === 'true'; |
| 58 | } |
| 59 | |
| 60 | private function contactForm7ContactCommissionStoreForm() { |
| 61 | return get_option(self::CONTACT7_CONTACT_COMMISSION_STORE_FORM) === 'true'; |
| 62 | } |
| 63 | |
| 64 | public function addContactForm7ContactCommission($form) { |
| 65 | if (!$this->contactForm7ContactCommissionEnabled()) { |
| 66 | postaffiliatepro_Base::_log('Contact form 7 contact commission disabled. Skipping action.'); |
| 67 | return $form; |
| 68 | } |
| 69 | if (!$this->commissionEnabledForForm($form)) { |
| 70 | postaffiliatepro_Base::_log('Contact form 7 contact commission not enabled for form ' . $form->unit_tag . '. Skipping action.'); |
| 71 | return $form; |
| 72 | } |
| 73 | $saleTracker = new Pap_Api_SaleTracker($this->getApiSessionUrl()); |
| 74 | $saleTracker->setAccountId(postaffiliatepro::getAccountName()); |
| 75 | if (get_option(self::CONTACT7_CONTACT_SEPARATE_ACTIONS) != '') { |
| 76 | $sale = $saleTracker->createAction($form->id()); |
| 77 | } elseif (get_option(self::CONTACT7_CONTACT_COMMISSION_TYPE) != '') { |
| 78 | $sale = $saleTracker->createAction(get_option(self::CONTACT7_CONTACT_COMMISSION_TYPE)); |
| 79 | } else { |
| 80 | $sale = $saleTracker->createSale(); |
| 81 | } |
| 82 | $sale->setTotalCost(get_option(self::CONTACT7_CONTACT_COMMISSION_AMOUNT)); |
| 83 | |
| 84 | $prodId = get_option(self::CONTACT7_PRODUCTID); |
| 85 | if ($prodId === '' || $prodId === ' ') { |
| 86 | $sale->setProductId($form->title()); |
| 87 | } else { |
| 88 | if (isset($this->Contact7PostedData[$prodId])) { |
| 89 | $product = $this->Contact7PostedData[$prodId]; |
| 90 | if (is_array($product)) { |
| 91 | $sale->setProductId($product[0]); |
| 92 | } else { |
| 93 | $sale->setProductId($product); |
| 94 | } |
| 95 | |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | if ($this->contactForm7ContactCommissionStoreForm()) { |
| 100 | $sale->setData1($this->getFormData()); |
| 101 | } |
| 102 | for ($i = 2; $i <= 5; $i++) { |
| 103 | if (($key = get_option(constant('self::CONTACT7_DATA' . $i))) != '' && isset($this->Contact7PostedData[$key])) { |
| 104 | $sale->setData($i, $this->Contact7PostedData[$key]); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | if (get_option(self::CONTACT7_CONTACT_EMAIL_AS_ORDERID) === 'true') { |
| 109 | $email = $this->getEmail(); |
| 110 | if ($email != '') { |
| 111 | $sale->setOrderID($email); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | if (get_option(self::CONTACT7_CONTACT_COMMISSION_CAMPAIGN) != '') { |
| 116 | $sale->setCampaignId(get_option(self::CONTACT7_CONTACT_COMMISSION_CAMPAIGN)); |
| 117 | } |
| 118 | try { |
| 119 | $saleTracker->register(); |
| 120 | } catch (Exception $e) { |
| 121 | postaffiliatepro_Base::_log('Error during registering contact commission: ' . $e->getMessage()); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | public function saveContactForm7FormData($posted_data) { |
| 126 | $this->Contact7PostedData = $posted_data; |
| 127 | return $posted_data; |
| 128 | } |
| 129 | |
| 130 | protected function getTemplateFile() { |
| 131 | return WP_PLUGIN_DIR . '/postaffiliatepro/Template/ContactForm7Config.xtpl'; |
| 132 | } |
| 133 | |
| 134 | private function getCampaignSelectData() { |
| 135 | $campaigns = $this->getCampaignHelper()->getCampaignsList(); |
| 136 | $data = array(); |
| 137 | foreach($campaigns as $rec) { |
| 138 | $data[$rec->get(postaffiliatepro_Util_CampaignHelper::CAMPAIGN_ID)] = htmlspecialchars($rec->get(postaffiliatepro_Util_CampaignHelper::CAMPAIGN_NAME)); |
| 139 | } |
| 140 | return $data; |
| 141 | } |
| 142 | |
| 143 | private function getFormsSelectData() { |
| 144 | $forms = postaffiliatepro_Util_ContactForm7Helper::getFormList(); |
| 145 | $data[0] = 'All'; |
| 146 | foreach($forms as $form) { |
| 147 | $data[$form->cf7_unit_id] = $form->title; |
| 148 | } |
| 149 | return $data; |
| 150 | } |
| 151 | |
| 152 | protected function getOption($name, $type = 'none') { |
| 153 | if ($name === self::CONTACT7_CONTACT_COMMISSION_AMOUNT && get_option($name) == '') { |
| 154 | return 0; |
| 155 | } |
| 156 | if ($name === self::CONTACT7_CONTACT_COMMISSION_FORM && get_option($name) == '') { |
| 157 | return 0; |
| 158 | } |
| 159 | return parent::getOption($name); |
| 160 | } |
| 161 | |
| 162 | protected function initForm() { |
| 163 | if (!postaffiliatepro_Util_ContactForm7Helper::formsExists()) { |
| 164 | $this->addHtml('contact7-signup-note', '<tr><td colspan="2" style="padding-top:0px;padding-bottom:15px;color:#750808;">'.__('No forms exist!', 'postaffiliatepro').'</td></tr>'); |
| 165 | } else { |
| 166 | $this->addHtml('contact7-signup-note', ''); |
| 167 | } |
| 168 | |
| 169 | $this->addTextBox(self::CONTACT7_CONTACT_COMMISSION_AMOUNT, 10); |
| 170 | $this->addSelect(self::CONTACT7_CONTACT_COMMISSION_CAMPAIGN, $this->getCampaignSelectData()); |
| 171 | $this->addTextBox(self::CONTACT7_CONTACT_COMMISSION_TYPE, 10); |
| 172 | $this->addCheckbox(self::CONTACT7_CONTACT_COMMISSION_STORE_FORM); |
| 173 | $this->addCheckbox(self::CONTACT7_CONTACT_EMAIL_AS_ORDERID); |
| 174 | $this->addCheckbox(self::CONTACT7_CONTACT_SEPARATE_ACTIONS); |
| 175 | $this->addSelect(self::CONTACT7_CONTACT_COMMISSION_FORM, $this->getFormsSelectData()); |
| 176 | $this->addTextBox(self::CONTACT7_DATA2); |
| 177 | $this->addTextBox(self::CONTACT7_DATA3); |
| 178 | $this->addTextBox(self::CONTACT7_DATA4); |
| 179 | $this->addTextBox(self::CONTACT7_DATA5); |
| 180 | $this->addTextBox(self::CONTACT7_PRODUCTID); |
| 181 | $this->addSubmit(); |
| 182 | } |
| 183 | |
| 184 | public function initSettings() { |
| 185 | register_setting(postaffiliatepro::INTEGRATIONS_SETTINGS_PAGE_NAME, self::CONTACT7_SIGNUP_COMMISSION_ENABLED); |
| 186 | register_setting(self::CONTACT7_SIGNUP_COMMISSION_CONFIG_PAGE, self::CONTACT7_CONTACT_COMMISSION_AMOUNT, ['sanitize_callback' => 'sanitize_text_field']); |
| 187 | register_setting(self::CONTACT7_SIGNUP_COMMISSION_CONFIG_PAGE, self::CONTACT7_CONTACT_COMMISSION_CAMPAIGN); |
| 188 | register_setting(self::CONTACT7_SIGNUP_COMMISSION_CONFIG_PAGE, self::CONTACT7_CONTACT_COMMISSION_TYPE, ['sanitize_callback' => 'sanitize_text_field']); |
| 189 | register_setting(self::CONTACT7_SIGNUP_COMMISSION_CONFIG_PAGE, self::CONTACT7_CONTACT_COMMISSION_FORM); |
| 190 | register_setting(self::CONTACT7_SIGNUP_COMMISSION_CONFIG_PAGE, self::CONTACT7_CONTACT_EMAIL_AS_ORDERID); |
| 191 | register_setting(self::CONTACT7_SIGNUP_COMMISSION_CONFIG_PAGE, self::CONTACT7_CONTACT_COMMISSION_STORE_FORM); |
| 192 | register_setting(self::CONTACT7_SIGNUP_COMMISSION_CONFIG_PAGE, self::CONTACT7_CONTACT_SEPARATE_ACTIONS); |
| 193 | register_setting(self::CONTACT7_SIGNUP_COMMISSION_CONFIG_PAGE, self::CONTACT7_DATA2, ['sanitize_callback' => 'sanitize_text_field']); |
| 194 | register_setting(self::CONTACT7_SIGNUP_COMMISSION_CONFIG_PAGE, self::CONTACT7_DATA3, ['sanitize_callback' => 'sanitize_text_field']); |
| 195 | register_setting(self::CONTACT7_SIGNUP_COMMISSION_CONFIG_PAGE, self::CONTACT7_DATA4, ['sanitize_callback' => 'sanitize_text_field']); |
| 196 | register_setting(self::CONTACT7_SIGNUP_COMMISSION_CONFIG_PAGE, self::CONTACT7_DATA5, ['sanitize_callback' => 'sanitize_text_field']); |
| 197 | register_setting(self::CONTACT7_SIGNUP_COMMISSION_CONFIG_PAGE, self::CONTACT7_PRODUCTID, ['sanitize_callback' => 'sanitize_text_field']); |
| 198 | } |
| 199 | |
| 200 | public function addPrimaryConfigMenu() { |
| 201 | if (postaffiliatepro_Util_ContactForm7Helper::formsExists() && get_option(self::CONTACT7_SIGNUP_COMMISSION_ENABLED) === 'true') { |
| 202 | add_submenu_page( |
| 203 | 'integrations-config-page-handle', |
| 204 | 'Contact form 7', |
| 205 | 'Contact form 7', |
| 206 | 'manage_options', |
| 207 | 'contact-form-7-settings-page', |
| 208 | array($this, 'printConfigPage') |
| 209 | ); |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | public function printConfigPage() { |
| 214 | $this->render(); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | $papSubmenuPriority = 11; |
| 219 | $papIntegrationContactForm7 = new postaffiliatepro_Form_Settings_ContactForm7(); |
| 220 | add_action('admin_init', array($papIntegrationContactForm7, 'initSettings'), 99); |
| 221 | add_action('admin_menu', array($papIntegrationContactForm7, 'addPrimaryConfigMenu'), $papSubmenuPriority); |
| 222 | |
| 223 | add_action('wpcf7_mail_sent', array($papIntegrationContactForm7, 'addContactForm7ContactCommission')); |
| 224 | add_filter('wpcf7_posted_data', array($papIntegrationContactForm7, 'saveContactForm7FormData')); |