Exemplo n.º 1
0
 function settings_update()
 {
     // form type
     switch ($_POST['setting_form']) {
         case 'main':
             // form main
             // set fields
             $this->setting['clientid'] = $_POST['setting']['clientid'];
             $this->setting['formid'] = $_POST['setting']['formid'];
             $this->setting['listid'] = $_POST['setting']['listid'];
             $this->setting['specialid'] = $_POST['setting']['specialid'];
             $this->setting['doubleopt'] = $_POST['setting']['doubleopt'];
             // fieldmap
             $this->setting['fieldmap'] = $this->_make_assoc($_POST['setting']['fieldmap']);
             // membershipmap
             $this->setting['membershipmap'] = $this->_make_assoc($_POST['setting']['membershipmap']);
             // update enable/disable
             $this->enabled = $_POST['enabled'];
             // enable/disable method
             $activate_method = bool_from_yn($this->enabled) ? 'activate_module' : 'deactivate_module';
             // update
             $ret = call_user_func_array(array(mgm_get_class('system'), $activate_method), array($this->code, $this->type));
             // save object options
             $this->save();
             // message
             return json_encode(array('status' => 'success', 'message' => sprintf(__('%s settings updated', 'mgm'), $this->name)));
             break;
         case 'box':
         default:
             // from box
             // set fields
             $this->setting['clientid'] = $_POST['setting']['icontact']['clientid'];
             $this->setting['formid'] = $_POST['setting']['icontact']['formid'];
             $this->setting['listid'] = $_POST['setting']['icontact']['listid'];
             $this->setting['specialid'] = $_POST['setting']['icontact']['specialid'];
             $this->setting['doubleopt'] = $_POST['setting']['icontact']['doubleopt'];
             // update object options
             $this->save();
             // message
             return json_encode(array('status' => 'success', 'message' => sprintf(__('%s settings updated', 'mgm'), $this->name)));
             break;
     }
 }
Exemplo n.º 2
0
 /**
  * API helper method auto login after subscribed
  *
  * @param int $user_id / transaction_id
  * @return bool
  */
 function _auto_login($id)
 {
     // get setting
     $setting = mgm_get_class('system')->get_setting();
     // if autologin not enabled
     if (!isset($setting['enable_autologin']) || isset($setting['enable_autologin']) && !bool_from_yn($setting['enable_autologin'])) {
         return false;
     }
     // check when enabled
     if (is_numeric($id)) {
         // user id
         $user_id = null;
         // get custom param
         $custom = $this->_get_transaction_passthrough($id);
         // verify if not subs purchase
         if ($custom['payment_type'] != 'subscription_purchase' || (!isset($custom['is_registration']) || isset($custom['is_registration']) && !bool_from_yn($custom['is_registration']))) {
             return false;
         }
         // fetch user id
         if (is_numeric($custom['user_id']) && $custom['user_id'] > 0) {
             // return id // #711, autologin is done in background
             mgm_auto_login($id);
             // redirect url for register & purchase
             if (isset($custom['post_id'])) {
                 return get_permalink($custom['post_id']);
             } elseif (isset($custom['postpack_post_id']) && isset($custom['postpack_id'])) {
                 return get_permalink($custom['postpack_post_id']);
             } else {
                 return true;
             }
         }
     }
     // return false
     return false;
 }
Exemplo n.º 3
0
function sandbox_init()
{
    load_theme_textdomain('sandbox');
    if ($GLOBALS['pagenow'] == 'themes.php' && isset($_GET['page']) && $_GET['page'] == 'skins' && isset($_GET['action']) && $_GET['action'] == 'activate' && current_user_can('switch_themes')) {
        check_admin_referer('switch-skin_' . $_GET['skin']);
        $info = sandbox_skin_info($_GET['skin']);
        sandbox_set_options(array('skin' => wp_filter_kses($_GET['skin']), 'globalnav' => bool_from_yn($info['global_navigation'])));
        wp_redirect('themes.php?page=skins&message=updated');
    }
}
 /**
  * @ticket 35972
  */
 function test_bool_from_yn()
 {
     $this->assertTrue(bool_from_yn('Y'));
     $this->assertTrue(bool_from_yn('y'));
     $this->assertFalse(bool_from_yn('n'));
 }
Exemplo n.º 5
0
function get_links_list($order = 'name', $hide_if_empty = 'obsolete')
{
    global $wpdb;
    $order = strtolower($order);
    // Handle link category sorting
    if (substr($order, 0, 1) == '_') {
        $direction = ' DESC';
        $order = substr($order, 1);
    }
    // if 'name' wasn't specified, assume 'id':
    $cat_order = 'name' == $order ? 'cat_name' : 'cat_id';
    if (!isset($direction)) {
        $direction = '';
    }
    // Fetch the link category data as an array of hashesa
    $cats = $wpdb->get_results("\n\t\tSELECT DISTINCT link_category, cat_name, show_images, \n\t\t\tshow_description, show_rating, show_updated, sort_order, \n\t\t\tsort_desc, list_limit\n\t\tFROM `{$wpdb->links}` \n\t\tLEFT JOIN `{$wpdb->linkcategories}` ON (link_category = cat_id)\n\t\tWHERE link_visible =  'Y'\n\t\t\tAND list_limit <> 0\n\t\tORDER BY {$cat_order} {$direction} ", ARRAY_A);
    // Display each category
    if ($cats) {
        foreach ($cats as $cat) {
            // Handle each category.
            // First, fix the sort_order info
            $orderby = $cat['sort_order'];
            $orderby = (bool_from_yn($cat['sort_desc']) ? '_' : '') . $orderby;
            // Display the category name
            echo '	<li id="linkcat-' . $cat['link_category'] . '"><h2>' . $cat['cat_name'] . "</h2>\n\t<ul>\n";
            // Call get_links() with all the appropriate params
            get_links($cat['link_category'], '<li>', "</li>", "\n", bool_from_yn($cat['show_images']), $orderby, bool_from_yn($cat['show_description']), bool_from_yn($cat['show_rating']), $cat['list_limit'], bool_from_yn($cat['show_updated']));
            // Close the last category
            echo "\n\t</ul>\n</li>\n";
        }
    }
}
Exemplo n.º 6
0
?>
</div>
				</div>				
			</div>
			<div class="row">
				<div class="cell width120px">
					<b><?php 
_e('Amazon S3 Settings', 'mgm');
?>
:</b> 
				</div>
			</div>
			<div class="row">		
				<div class="cell textalignleft ">
					<input type="checkbox" name="is_s3_torrent" id="is_s3_torrent" <?php 
echo bool_from_yn($data['download']->is_s3_torrent) ? "checked='checked'" : '';
?>
 /> <?php 
_e('Is Torrent', 'mgm');
?>

					<div class="tips"><?php 
printf(__('Allow Torrent for Amazon S3 larger files ( rquires public ACL ). Please read <a href="%s">here</a>.', 'mgm'), ' http://docs.amazonwebservices.com/AmazonS3/latest/dev/S3TorrentRetrieve.html');
?>
</div>
				</div>
			</div>
			<div class="row brBottom">
				<div class="cell">
					<div class="tips">
						<b><?php 
Exemplo n.º 7
0
    		<div class="cell">
				<p><input type="checkbox" name="enable_facebook" id="enable_facebook" value="Y" <?php 
if (bool_from_yn($data['system_obj']->get_setting('enable_facebook'))) {
    echo "checked='checked'";
}
?>
>&nbsp;<b><?php 
_e('Enable Facebook login/registration?', 'mgm');
?>
</b></p>				
			</div>
		</div>
  		<div class="row">
    		<div class="cell">
				<div id="enable_facebook_setting" class="<?php 
echo bool_from_yn($data['system_obj']->get_setting('enable_facebook')) ? 'displayblock' : 'displaynone';
?>
 paddingtop10px">
					<p><b><?php 
_e('Facebook API ID');
?>
:</b></p>
					<input type="text" name="facebook_id" value="<?php 
echo esc_html($data['system_obj']->get_setting('facebook_id'));
?>
" size="50" />
					<p><b><?php 
_e('Facebook API Key');
?>
:</b></p>
					<input type="text" name="facebook_key" value="<?php 
Exemplo n.º 8
0
 /**
  * Cancel Recurring Subscription
  * This is not a private function
  * @param int/string $trans_ref	
  * @param int $user_id	
  * @param int/string $subscr_id	
  * @param int $pack_id	
  * @return boolean
  */
 function cancel_recurring_subscription($trans_ref = null, $user_id = null, $subscr_id = null, $pack_id = null)
 {
     //if coming form process return after a subscription payment
     if (!empty($trans_ref)) {
         $transdata = $this->_get_transaction_passthrough($trans_ref);
         if ($transdata['payment_type'] != 'subscription_purchase') {
             return false;
         }
         $user_id = $transdata['user_id'];
         if (isset($transdata['is_another_membership_purchase']) && $transdata['is_another_membership_purchase'] == 'Y') {
             $member = mgm_get_member_another_purchase($user_id, $transdata['membership_type']);
         } else {
             $member = mgm_get_member($user_id);
         }
         if (isset($member->payment_info->module)) {
             if (isset($member->payment_info->subscr_id)) {
                 $subscr_id = $member->payment_info->subscr_id;
             } else {
                 //check pack is recurring:
                 $pid = $pack_id ? $pack_id : $member->pack_id;
                 if ($pid) {
                     $s_packs = mgm_get_class('subscription_packs');
                     $sel_pack = $s_packs->get_pack($pid);
                     if ($sel_pack['num_cycles'] != 1) {
                         $subscr_id = 0;
                     }
                 }
             }
             //check for same module: if not call the same function of the applicale module.
             if (str_replace('mgm_', '', $member->payment_info->module) != str_replace('mgm_', '', $this->code)) {
                 mgm_log('RECALLing ' . $member->payment_info->module . ': cancel_recurring_subscription FROM: ' . $this->code);
                 return mgm_get_module($member->payment_info->module, 'payment')->cancel_recurring_subscription($trans_ref, null, null, $pack_id);
             }
             //skip if same pack is updated
             if (empty($member->pack_id) || is_numeric($pack_id) && $pack_id == $member->pack_id) {
                 return false;
             }
         } else {
             return false;
         }
     }
     //send email only if setting enabled
     if (!empty($subscr_id) || $subscr_id === 0) {
         $system_obj = mgm_get_class('system');
         $dge = bool_from_yn($system_obj->get_setting('disable_gateway_emails'));
         //send email only if setting enabled
         if (!$dge) {
             // blog
             $blogname = get_option('blogname');
             // user
             $user = get_userdata($user_id);
             // notify admin
             mgm_notify_admin_membership_cancellation_manual_removal_required($blogname, $user, $member);
         }
         return true;
     }
     return false;
 }
Exemplo n.º 9
0
 function get_template($name, $data = array(), $parse = false)
 {
     // by name
     switch ($name) {
         case 'tos':
         case 'subs_intro':
         case 'text_guest_purchase_pre_button':
         case 'text_guest_purchase_pre_register':
             return mgm_get_template($name, NULL, 'messages');
             break;
         case 'private_text':
         case 'private_text_no_access':
         case 'private_text_purchasable':
         case 'private_text_purchasable_login':
         case 'private_text_purchasable_pack_login':
         case 'private_text_postdelay_no_access':
             // parse enabled
             if ($parse) {
                 // parse
                 $message_content = mgm_get_template($name, $data, 'messages');
                 // set template
                 $template = mgm_get_template('private_text_template', NULL, 'templates');
                 // return
                 return str_replace('[message]', $message_content, $template);
             } else {
                 // parse disabled
                 return mgm_get_template($name, NULL, 'messages');
             }
             break;
         case 'login_errmsg_null':
         case 'login_errmsg_expired':
         case 'login_errmsg_trial_expired':
         case 'login_errmsg_pending':
         case 'login_errmsg_cancelled':
         case 'login_errmsg_default':
         case 'login_errmsg_date_range':
         case 'login_errmsg_multiple_logins':
             // parse enabled
             if ($parse) {
                 // argas
                 $q_args = array('action' => '[[ACTION]]');
                 //
                 if (bool_from_yn($this->setting['enable_email_as_username'])) {
                     $q_args = array_merge($q_args, array('user_id' => '[[USERID]]'));
                 } else {
                     $q_args = array_merge($q_args, array('username' => '[[USERNAME]]'));
                 }
                 // set url data
                 $data['subscription_url'] = add_query_arg($q_args, mgm_get_custom_url('transactions'));
                 // return
                 return mgm_get_template($name, $data, 'messages');
             } else {
                 // parse disabled
                 return mgm_get_template($name, NULL, 'messages');
             }
             break;
         case 'pack_desc_template':
         case 'pack_desc_lifetime_template':
         case 'pack_desc_date_range_template':
         case 'ppp_pack_template':
         case 'register_form_row_template':
         case 'profile_form_row_template':
         case 'register_form_row_autoresponder_template':
             // separate
             // parse enabled
             if ($parse) {
                 // return
                 return mgm_get_template($name, $data, 'templates');
             } else {
                 // parse disabled
                 return mgm_get_template($name, NULL, 'templates');
             }
             break;
         case 'reminder_email_template_subject':
         case 'reminder_email_template_body':
         case 'registration_email_template_subject':
         case 'registration_email_template_body':
         case 'new_user_notification_email_template_subject':
         case 'new_user_notification_email_template_body':
         case 'user_upgrade_notification_email_template_subject':
         case 'user_upgrade_notification_email_template_body':
         case 'payment_success_email_template_subject':
         case 'payment_success_email_template_body':
         case 'payment_success_subscription_email_template_body':
         case 'payment_failed_email_template_subject':
         case 'payment_failed_email_template_body':
         case 'payment_active_email_template_subject':
         case 'payment_active_email_template_body':
         case 'payment_pending_email_template_subject':
         case 'payment_pending_email_template_body':
         case 'payment_error_email_template_subject':
         case 'payment_error_email_template_body':
         case 'payment_unknown_email_template_subject':
         case 'payment_unknown_email_template_body':
         case 'subscription_cancelled_email_template_subject':
         case 'subscription_cancelled_email_template_body':
         case 'retrieve_password_email_template_subject':
         case 'retrieve_password_email_template_body':
         case 'lost_password_email_template_subject':
         case 'lost_password_email_template_body':
             // parse enabled
             if ($parse) {
                 return mgm_get_template($name, $data, 'emails');
             } else {
                 // parse disabled
                 return mgm_get_template($name, NULL, 'emails');
             }
             break;
         case 'payment_success_title':
         case 'payment_success_message':
         case 'payment_failed_title':
         case 'payment_failed_message':
             // parse enabled
             if ($parse) {
                 // set urls
                 $data['home_url'] = trailingslashit(get_option('siteurl'));
                 $data['site_url'] = trailingslashit(site_url());
                 $data['register_url'] = trailingslashit(mgm_get_custom_url('register'));
                 // login or profile
                 $data['login_url'] = trailingslashit(mgm_get_custom_url(is_user_logged_in() ? 'profile' : 'login'));
                 // return
                 return mgm_get_template($name, $data, 'messages');
             } else {
                 // parse disabled
                 return mgm_get_template($name, NULL, 'messages');
             }
             break;
         default:
             return sprintf(__('%s not defined.', 'mgm'), $name);
             break;
     }
 }
 /**
  * enqueue scripts
  *
  * @since 1.1
  *
  */
 public function enqueue_scripts()
 {
     global $stt2extat_settings;
     $set = $stt2extat_settings;
     $is_single = apply_filters('stt2extat_is_single', true);
     if (!$is_single && !is_search()) {
         return false;
     }
     $post_ids = stt2extat_post_ids_query();
     if (!$post_ids) {
         return false;
     }
     $settings = array('post_ID' => $post_ids, 'showList' => isset($set['auto']) ? bool_from_yn($set['auto']) : (bool) 0, 'single' => is_single());
     $heartbeat_set = wp_heartbeat_settings($settings);
     $localize_script = wp_parse_args($heartbeat_set, $settings);
     wp_register_script('jquery-stt2extat-res', plugin_dir_url(__FILE__) . 'assets/js/jquery-stt2extat-res.js', array('jquery-core'), STT2EXTAT_VER, true);
     wp_enqueue_script('jquery-stt2extat-res');
     wp_localize_script('jquery-stt2extat-res', 'stt2extatJs', $localize_script);
 }
/**
 * override default template
 *
 * @param array $column
 * @param init $post_id
 * @return void
 */
function mgm_template_include($template)
{
    // check override
    if (bool_from_yn(mgm_get_setting('override_theme_for_custom_pages'))) {
        // name
        $name = mgm_get_query_var('name');
        // switch
        switch ($name) {
            case 'register':
            case 'profile':
            case 'lost_password':
            case 'login':
                $content = mgm_get_query_post_content();
                // @todo check #BUG_PENDING
                // check
                if (mgm_is_custom_page_published($name, $content)) {
                    // if template exists in theme only
                    if ($c_template = mgm_get_page_template($name, false, true)) {
                        $template = $c_template;
                    }
                }
                break;
        }
    }
    // return
    return $template;
}
/**
 * Send Email Notification to Admin on passthrough verification failed
 *
 * @uses mgm_notify_admin()
 * @param string $passthrough
 * @param string $module
 * @return bool @send
 */
function mgm_notify_admin_passthrough_verification_failed($passthrough, $module)
{
    // system
    $system_obj = mgm_get_class('system');
    $dge = bool_from_yn($system_obj->get_setting('disable_gateway_emails'));
    // notify admin, only if gateway emails on
    if (!$dge) {
        // subject
        $subject = sprintf('Error in %s custom passthrough verification', ucwords($module));
        // message
        $message = sprintf('Could not read custom passthrough:<br />passthrough: %s;<br>request: %s', $passthrough, print_r($_REQUEST, true));
        // mail
        return @mgm_notify_admin(null, $subject, $message);
    }
    // error
    return false;
}
Exemplo n.º 13
0
 /**
  * Cancel Recurring Subscription
  * Cancellation includes 2 webservice calls
  * 	1. delete Rebill Event on eWay
  *  2. delete Rebill Customer on eWay
  * This is not a private function
  * @param int/string $trans_ref	
  * @param int $user_id	
  * @param int/string $rebill_id	
  * @param int $pack_id	
  * @return boolean
  */
 function cancel_recurring_subscription($trans_ref = null, $user_id = null, $rebill = null, $pack_id = null)
 {
     //if coming form process return after a subscription payment
     if (!empty($trans_ref)) {
         $transdata = $this->_get_transaction_passthrough($trans_ref);
         if ($transdata['payment_type'] != 'subscription_purchase') {
             return false;
         }
         $user_id = $transdata['user_id'];
         if (isset($transdata['is_another_membership_purchase']) && $transdata['is_another_membership_purchase'] == 'Y') {
             $member = mgm_get_member_another_purchase($user_id, $transdata['membership_type']);
         } else {
             $member = mgm_get_member($user_id);
         }
         if (isset($member->payment_info->module) && !empty($member->payment_info->module)) {
             if (isset($member->payment_info->subscr_id)) {
                 $rebill['rebill_id'] = $member->payment_info->subscr_id;
                 $rebill['rebill_customer_id'] = $member->payment_info->rebill_customerid;
             } else {
                 //check pack is recurring:
                 $pid = $pack_id ? $pack_id : $member->pack_id;
                 if ($pid) {
                     $s_packs = mgm_get_class('subscription_packs');
                     $sel_pack = $s_packs->get_pack($pid);
                     if ($sel_pack['num_cycles'] != 1) {
                         $rebill['rebill_id'] = 0;
                     }
                     // 0 stands for a lost subscription id
                 }
             }
             //check for same module: if not call the same function of the applicale module.
             if (str_replace('mgm_', '', $member->payment_info->module) != str_replace('mgm_', '', $this->code)) {
                 // log
                 mgm_log('RECALLing ' . $member->payment_info->module . ': cancel_recurring_subscription FROM: ' . $this->module, $this->module . '_cancel');
                 // return
                 return mgm_get_module($member->payment_info->module, 'payment')->cancel_recurring_subscription($trans_ref, null, null, $pack_id);
             }
             //skip if same pack is updated
             if (empty($member->pack_id) || is_numeric($pack_id) && $pack_id == $member->pack_id) {
                 return false;
             }
         } else {
             return false;
         }
     }
     //if valid rebill data is found and settings are set
     if (!empty($rebill['rebill_id']) && !empty($rebill['rebill_customer_id']) && !empty($this->setting['customer_id']) && !empty($this->setting['username']) && !empty($this->setting['password'])) {
         $gateway_method = 'webservice';
         $secure = array('CustomerID' => $this->setting['customer_id'], 'Username' => $this->setting['username'], 'Password' => $this->setting['password']);
         //data to post
         //Delete Rebill Event
         $post_data = array('webservice_action' => 'DeleteRebillEvent', 'RebillCustomerID' => $rebill['rebill_customer_id'], 'RebillID' => $rebill['rebill_id']);
         $post_data = array_merge($post_data, $secure);
         // filter post data and create soap xml
         $post_string = $this->_filter_postdata($gateway_method, $post_data);
         // endpoint
         $endpoint = $this->_get_endpoint($this->status . '_' . $gateway_method);
         // test_webservice / live_webservice
         // headers
         $http_headers = $this->_get_http_headers($gateway_method, $post_data['webservice_action']);
         // log
         mgm_log('Request Headers [' . $post_data['webservice_action'] . ']' . mgm_pr($http_headers, true), __FUNCTION__);
         // log
         mgm_log('Request [' . $post_data['webservice_action'] . ']' . $post_string, __FUNCTION__);
         // create curl post
         $http_response = mgm_remote_post($endpoint, $post_string, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
         // log
         mgm_log('Response [' . $post_data['webservice_action'] . ']' . $http_response, __FUNCTION__);
         /*$http_header = array('User-Agent: NuSOAP/0.9.5 (1.123)', 'Content-Type: text/xml; charset=ISO-8859-1', 
           sprintf('SOAPAction: "http://www.eway.com.au/gateway/rebill/manageRebill/%s"', $post_data['webservice_action']));*/
         // post soap data
         // $buffer = $this->_curl_post($endpoint, $post_string, $http_header);
         // parse response
         $this->_process_response($gateway_method, $http_response, $post_data['webservice_action']);
         // log
         mgm_log('Response Parsed [' . $post_data['webservice_action'] . ']' . mgm_pr($this->response, true), __FUNCTION__);
         //if rebill event is deleted, delete rebill customer
         if (isset($this->response['response_status']) && $this->response['response_status'] == 1) {
             //delete rebill customer:
             $post_data['webservice_action'] = 'DeleteRebillCustomer';
             // filter post data and create soap xml
             $post_string = $this->_filter_postdata($gateway_method, $post_data);
             // soap_action
             $soap_action = sprintf('http://www.eway.com.au/gateway/rebill/manageRebill/%s', $post_data['webservice_action']);
             // http_headers
             $http_headers = array_merge($http_headers, array('SOAPAction' => $soap_action));
             // log
             mgm_log('Request Headers [' . $post_data['webservice_action'] . ']' . mgm_pr($http_headers, true), __FUNCTION__);
             // log
             mgm_log('Request [' . $post_data['webservice_action'] . ']' . $post_string, __FUNCTION__);
             // create curl post
             $http_response = mgm_remote_post($endpoint, $post_string, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
             // log
             mgm_log('Response [' . $post_data['webservice_action'] . ']' . $http_response, __FUNCTION__);
             /*$http_header = array('User-Agent: NuSOAP/0.9.5 (1.123)', 'Content-Type: text/xml; charset=ISO-8859-1', 
               sprintf('SOAPAction: "http://www.eway.com.au/gateway/rebill/manageRebill/%s"', $post_data['webservice_action']));*/
             // post soap data
             // $buffer = $this->_curl_post($endpoint, $post_string, $http_header);
             // parse response
             $this->_process_response($gateway_method, $http_response, $post_data['webservice_action']);
             // log
             mgm_log('Response Parsed [' . $post_data['webservice_action'] . ']' . mgm_pr($this->response, true), __FUNCTION__);
             // check
             if (isset($this->response['response_status']) && $this->response['response_status'] == 1) {
                 //done
                 return true;
             }
         }
     } elseif ($rebill['rebill_id'] === 0) {
         $system_obj = mgm_get_class('system');
         $dge = bool_from_yn($system_obj->get_setting('disable_gateway_emails'));
         //send email only if setting enabled
         if (!$dge) {
             $user = get_userdata($user_id);
             //send notification email to admin:
             $message = __('The User: '******'mgm') . $user->user_email . ' (' . $user_id . ') ' . __('has upgraded/cancelled subscription.', 'mgm');
             $message .= "<br/>" . __('Please unsubscribe the user from Gateway Merchant panel.', 'mgm');
             if (!empty($rebill['rebill_customer_id'])) {
                 $message .= "<br/><br/>" . __('Customer Rebill Id: ', 'mgm') . $rebill['rebill_customer_id'];
             }
             if (!empty($rebill['rebill_id'])) {
                 $message .= "<br/><br/>" . __('Rebill Id: ', 'mgm') . $rebill['rebill_id'];
             }
             if (isset($member->transaction_id)) {
                 $message .= "<br/>" . __('MGM Transaction Id:', 'mgm') . $member->transaction_id;
             }
             //admin email:
             if (!empty($system_obj->setting['admin_email'])) {
                 @mgm_mail($system_obj->setting['admin_email'], sprintf(__('[%s] User Subscription Cancellation', 'mgm'), get_option('blogname')), $message);
             }
         }
         //treat as done
         return true;
     }
     return false;
 }
Exemplo n.º 14
0
 /**
  * Cancel Recurring Subscription
  * This is not a private function
  * @param int/string $trans_ref	
  * @param int $user_id	
  * @param int/string $subscr_id	
  * @return boolean
  */
 function cancel_recurring_subscription($trans_ref = null, $user_id = null, $subscr_id = null, $pack_id = null)
 {
     //if coming form process return after a subscription payment
     if (!empty($trans_ref)) {
         $transdata = $this->_get_transaction_passthrough($trans_ref);
         if ($transdata['payment_type'] != 'subscription_purchase') {
             return false;
         }
         $user_id = $transdata['user_id'];
         if (isset($transdata['is_another_membership_purchase']) && $transdata['is_another_membership_purchase'] == 'Y') {
             $member = mgm_get_member_another_purchase($user_id, $transdata['membership_type']);
         } else {
             $member = mgm_get_member($user_id);
         }
         if (isset($member->payment_info->module) && !empty($member->payment_info->module)) {
             if (isset($member->payment_info->subscr_id)) {
                 $subscr_id = $member->payment_info->subscr_id;
             } else {
                 //check pack is recurring:
                 $pid = $pack_id ? $pack_id : $member->pack_id;
                 if ($pid) {
                     $s_packs = mgm_get_class('subscription_packs');
                     $sel_pack = $s_packs->get_pack($pid);
                     if ($sel_pack['num_cycles'] != 1) {
                         $subscr_id = 0;
                     }
                     // 0 stands for a lost subscription id
                 }
             }
             //check for same module: if not call the same function of the applicale module.
             if (str_replace('mgm_', '', $member->payment_info->module) != str_replace('mgm_', '', $this->code)) {
                 // mgm_log('RECALLing '. $member->payment_info->module .': cancel_recurring_subscription FROM: ' . $this->code);
                 return mgm_get_module($member->payment_info->module, 'payment')->cancel_recurring_subscription($trans_ref, null, null, $pack_id);
             }
             //skip if same pack is updated
             if (empty($member->pack_id) || is_numeric($pack_id) && $pack_id == $member->pack_id) {
                 return false;
             }
         } else {
             return false;
         }
     }
     //ony for subscription_purchase
     if ($subscr_id) {
         // end  point
         $endpoint = $this->_get_endpoint('unsubscribe');
         // base
         // add query
         $url = add_query_arg(array('SUBSCRIPTION_ID' => urlencode($subscr_id), 'MERCHANT_ID' => urlencode($this->setting['merchant_id']), 'ZombaioGWPass' => urlencode($this->setting['gw_pass']), 'ReasonCode' => urlencode(11)), $endpoint);
         // create curl post
         //$buffer = $this->_curl_post($url);
         // headers
         $http_headers = array();
         // fetch
         $http_response = mgm_remote_post($url, $post_data, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
         // verify
         if ($http_response == 1) {
             return true;
         } else {
             // message
             return $this->_get_cancel_error($http_response);
         }
     } elseif ($subscr_id === 0) {
         //send email to admin if subscription Id is absent
         $system_obj = mgm_get_class('system');
         $dge = bool_from_yn($system_obj->get_setting('disable_gateway_emails'));
         //send email only if setting enabled
         if (!$dge) {
             $user = get_userdata($user_id);
             //send notification email to admin:
             $message = __('The User: '******'mgm') . $user->user_email . ' (' . $user_id . ') ' . __('has upgraded/cancelled subscription.', 'mgm');
             $message .= "<br/>" . __('Please unsubscribe the user subscription from Gateway Merchant panel.', 'mgm');
             if (!empty($member->transaction_id)) {
                 $message .= "<br/>" . __('MGM Transaction Id:', 'mgm') . $member->transaction_id;
             }
             //admin email:
             if (!empty($system_obj->setting['admin_email'])) {
                 @mgm_mail($system_obj->setting['admin_email'], sprintf(__('[%s] User Subscription Cancellation', 'mgm'), get_option('blogname')), $message);
             }
         }
         return true;
     }
     return false;
 }
/**
 * Check secondary menu is enabled for the logged in user
 * @param string $primary_menu
 * @param string $secondary_menu
 * @return boolean
 */
function mgm_is_mgm_menu_enabled($type = 'primary', $primary_menu, $secondary_menu = null)
{
    $user_id = get_current_user_id();
    $obj_roles = new mgm_roles();
    // for the firsttime load
    if (!get_option('rolebasedmenu_init')) {
        // update administrator role with capabilities
        $custom_caps = $obj_roles->get_custom_capabilities();
        foreach ($custom_caps as $cap) {
            $obj_roles->update_capability_role('administrator', $cap, true);
        }
        // set init value
        update_option('rolebasedmenu_init', 1);
    }
    $capabilities = $obj_roles->get_loggedinuser_custom_capabilities($user_id);
    $system_obj = mgm_get_class('system');
    // common setting
    $dml = $system_obj->setting['enable_role_based_menu_loading'];
    // if dynamic menu loading is disabled/priamry and secondary menus are enabled
    return is_super_admin() && !bool_from_yn($dml) || (bool_from_yn($dml) && ($type == 'primary' && in_array($primary_menu, $capabilities)) || $type == 'secondary' && in_array($primary_menu, $capabilities) && in_array($secondary_menu, $capabilities));
    // check secondary menu capability is loaded
}
Exemplo n.º 16
0
 function get_links_list($order = 'name', $hide_if_empty = 'obsolete')
 {
     $order = strtolower($order);
     $direction = '';
     // Handle link category sorting
     if (substr($order, 0, 1) == '_') {
         $direction = ' DESC';
         $order = substr($order, 1);
     }
     // if 'name' wasn't specified, assume 'id':
     $cat_order = 'name' == $order ? 'cat_name' : 'cat_id';
     // Fetch the link category data as an array of hashes
     $cats = $GLOBALS['wpdb']->get_results("SELECT DISTINCT link_category, cat_name, show_images,\n\t\tshow_description, show_rating, show_updated, sort_order, sort_desc, list_limit\nFROM `" . wp_table('links') . "` LEFT JOIN `" . wp_table('linkcategories') . "` ON (link_category = cat_id)\nWHERE link_visible =  'Y'\n\t\tORDER BY {$cat_order} {$direction} ", ARRAY_A);
     // Display each category
     if ($cats) {
         foreach ($cats as $cat) {
             // Handle each category.
             // First, fix the sort_order info
             $orderby = $cat['sort_order'];
             $orderby = (bool_from_yn($cat['sort_desc']) ? '_' : '') . $orderby;
             // Display the category name
             $cat_id = sanitize_title($cat['cat_name']);
             if ($cat_id == "") {
                 $cat_id = "lcat-" . $cat['link_category'];
             }
             echo '	<li id="' . sanitize_title($cat['cat_name']) . '">' . stripslashes($cat['cat_name']) . "\n\t<ul>\n";
             // Call get_links() with all the appropriate params
             get_links($cat['link_category'], '<li>', "</li>", "\n", bool_from_yn($cat['show_images']), $orderby, bool_from_yn($cat['show_description']), bool_from_yn($cat['show_rating']), $cat['list_limit'], bool_from_yn($cat['show_updated']));
             // Close the last category
             echo "\n\t</ul>\n</li>\n";
         }
     }
 }
 function edit()
 {
     global $wpdb;
     // trim
     array_map('trim', $_POST);
     // extract
     extract($_POST);
     // system
     $system_obj = mgm_get_class('system');
     // save
     if (isset($submit_download)) {
         // response
         $response = array('status' => 'error', 'message' => sprintf(__('Error while updating download <b>%s</b>!', 'mgm'), $title));
         // check duplicate
         if (mgm_is_duplicate(TBL_MGM_DOWNLOAD, array('title'), "id <> '{$id}'")) {
             $response['message'] = sprintf(__('Error while updating download <b>%s</b>, title exists!', 'mgm'), $title);
         } else {
             // set vars
             $members_only = isset($members_only) ? 'Y' : 'N';
             // set vars
             $restrict_acces_ip = isset($restrict_acces_ip) ? 'Y' : 'N';
             // is_s3_torrent
             $is_s3_torrent = isset($is_s3_torrent) ? 'Y' : 'N';
             // filename
             $filename = isset($download_file_new) ? $download_file_new : $direct_url;
             // real name
             $real_filename = isset($download_file_new_realname) ? $download_file_new_realname : basename($filename);
             // filesize
             $filesize = mgm_file_get_size($filename);
             // post vars
             $post_date = date('Y-m-d H:i:s');
             // user
             $current_user = wp_get_current_user();
             // data
             $data = array('title' => $title, 'filename' => $filename, 'real_filename' => $real_filename, 'filesize' => $filesize, 'post_date' => $post_date, 'restrict_acces_ip' => $restrict_acces_ip, 'user_id' => $current_user->ID, 'members_only' => $members_only, 'is_s3_torrent' => $is_s3_torrent);
             // null
             $null_columns = array();
             // download limit
             if (isset($download_limit) && (int) $download_limit > 0) {
                 $data['download_limit'] = (int) $download_limit;
             } else {
                 $null_columns[] = "`download_limit` = NULL ";
             }
             // expire date
             if (isset($expire_dt) && !empty($expire_dt)) {
                 $data['expire_dt'] = mgm_format_inputdate_to_mysql($expire_dt);
             } else {
                 $null_columns[] = "`expire_dt` = NULL ";
             }
             // code
             if (!isset($code) || isset($code) && empty($code)) {
                 $data['code'] = uniqid();
             }
             // update
             if ($wpdb->update(TBL_MGM_DOWNLOAD, $data, array('id' => $id))) {
                 // update null
                 if (count($null_columns) > 0) {
                     // join
                     $set_string = implode(',', $null_columns);
                     // clear old
                     $wpdb->query($wpdb->prepare('UPDATE `' . TBL_MGM_DOWNLOAD . '` SET ' . $set_string . ' WHERE `id` = %d', $id));
                 }
                 // clear old
                 $wpdb->query($wpdb->prepare('DELETE FROM `' . TBL_MGM_DOWNLOAD_POST_ASSOC . '` WHERE `download_id` = %d', $id));
                 // save
                 if (bool_from_yn($members_only)) {
                     if (isset($link_to_post_id)) {
                         // loop
                         foreach ($link_to_post_id as $post_id) {
                             // insert
                             $wpdb->insert(TBL_MGM_DOWNLOAD_POST_ASSOC, array('download_id' => $id, 'post_id' => $post_id));
                         }
                     }
                 }
                 // set message
                 $response['message'] = sprintf(__('Download updated successfully <b>%s</b>', 'mgm'), $title);
                 $response['status'] = 'success';
             } else {
                 $response['message'] = sprintf(__('Error while updating download <b>%s</b> Or nothing updated!', 'mgm'), $title);
             }
         }
         // return response
         echo json_encode($response);
         exit;
     }
     // data
     $data = array();
     // download
     $data['download'] = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . TBL_MGM_DOWNLOAD . "` WHERE id = %d", $id));
     // download_posts
     $data['download_posts'] = mgm_get_download_post_ids($id);
     // get all post types
     $post_types = mgm_get_post_types();
     //get all published posts - issue #1034
     $all_posts = mgm_field_values($wpdb->posts, 'ID', 'SUBSTR(post_title,1, 100) AS post_title', "AND `post_status` ='publish' AND `post_type` IN ({$post_types})", 'post_title');
     //get all scheduled posts
     $scheduled_posts = mgm_field_values($wpdb->posts, 'ID', 'SUBSTR(post_title,1, 100) AS post_title', "AND `post_status` ='future' AND `post_type` IN ({$post_types})", 'post_title');
     foreach ($scheduled_posts as $k => $scheduled_post) {
         $all_posts[$k] = $scheduled_post . '(S)';
     }
     //get all draft posts
     $draft_posts = mgm_field_values($wpdb->posts, 'ID', 'SUBSTR(post_title,1, 100) AS post_title', "AND `post_status` ='draft' AND `post_type` IN ({$post_types})", 'post_title');
     foreach ($draft_posts as $k => $draft_post) {
         $all_posts[$k] = $draft_post . '(D)';
     }
     //sort by post name
     asort($all_posts);
     //all posts
     $data['posts'] = $all_posts;
     // hook
     $data['download_hook'] = $system_obj->get_setting('download_hook', 'download');
     // slug
     $data['download_slug'] = $system_obj->get_setting('download_slug', 'download');
     // load template view
     $this->load->template('downloads/edit', array('data' => $data));
 }
Exemplo n.º 18
0
        ?>
</a>
						</div>
						<div class="cell textalignleft width175px maxwidth175px">
							<a href="javascript:void(0);" title="<?php 
        echo $filename;
        ?>
"><?php 
        printf('%s <br>(%s)', mgm_ellipsize($filename, 20), !empty($filesize) ? $filesize : '0 bytes');
        ?>
</a>
						</div>
						<div class="cell textalignleft width50px maxwidth50px">
							<div align="center">
								<b><?php 
        echo bool_from_yn($download->members_only) ? sprintf($lbl_fmt, 'mgm_color_green', __('Yes', 'mgm')) : sprintf($lbl_fmt, 'mgm_color_red', __('No', 'mgm'));
        ?>
</b>
							</div>
						</div>
						<div class="cell textalignleft width50px maxwidth50px">					
							<div align="center">
								<b><?php 
        echo !empty($filesize) ? sprintf($lbl_fmt, 'mgm_color_green', __('Yes', 'mgm')) : sprintf($lbl_fmt, 'mgm_color_red', __('No', 'mgm'));
        ?>
</b>
							</div>
						</div>
						<div class="cell textalignleft width130px maxwidth130px">
							<?php 
        echo $expire_dt;
 function status_change()
 {
     extract($_POST);
     // get object
     $cf_obj = mgm_get_class('member_custom_fields');
     // update
     if (bool_from_yn($active)) {
         $success = $cf_obj->set_sort_order($id);
         $w = 'activated';
     } else {
         $success = $cf_obj->unset_sort_order($id);
         $w = 'deactivated';
     }
     // label
     $label = $cf_obj->get_field_attr($id, 'label');
     // send status
     if ($success) {
         // update on success
         $cf_obj->save();
         // message
         $message = sprintf(__('Successfully %s custom field: <b>%s</b>', 'mgm'), $w, mgm_stripslashes_deep($label));
         $status = 'success';
     } else {
         // message
         $message = sprintf(__('Error while %s custom field: <b>%s</b>', 'mgm'), str_replace('ed', 'ing', $w), mgm_stripslashes_deep($label));
         $status = 'error';
     }
     // return response
     echo json_encode(array('status' => $status, 'message' => $message));
     exit;
 }
 /**
  * check module enabled status
  * 
  * @param string $return_type
  * @return bool
  */
 function is_enabled($return_type = 'bool')
 {
     // return true|false on enabled
     $return = bool_from_yn($this->enabled) && mgm_get_class('system')->is_active_module($this->code, $this->type) ? true : false;
     // return
     return $return_type == 'bool' ? $return : ($return ? 'Y' : 'N');
     // needed for selection bug
 }
Exemplo n.º 21
0
_e('Shopper Response', 'mgm');
?>
:</b></p>
				</div>
			</div>
			<div class="row">
				<div class="cell">
					<input type="radio" name="setting[shopper_response]" id="setting_shopper_response_y" value="Y" <?php 
echo bool_from_yn($data['module']->setting['shopper_response']) ? 'checked="true"' : '';
?>
/> <?php 
_e('Yes', 'mgm');
?>

					<input type="radio" name="setting[shopper_response]" id="setting_shopper_response_n" value="N" <?php 
echo bool_from_yn($data['module']->setting['shopper_response']) ? 'checked="true"' : '';
?>
/> <?php 
_e('No', 'mgm');
?>
						
					<p><div class="tips"><?php 
_e('Select Yes/No depending on "Enable the Shopper Response" value on Merchant panel installation settings.', 'mgm');
?>
</div></p>
				</div>
			</div>
			<div class="row">
				<div class="cell">
					<p><b><?php 
_e('The Currency used for the payments', 'mgm');
Exemplo n.º 22
0
 /**
  * Cancel Recurring Subscription
  *
  * @param int/string $trans_ref	
  * @param int $user_id	
  * @param int/string $subscr_id	
  * @return boolean/string message
  */
 function cancel_recurring_subscription($trans_ref = null, $user_id = null, $sale_id = null, $pack_id = null)
 {
     // if coming form process return after a subscription payment
     if (!empty($trans_ref)) {
         // transaction data
         $transdata = $this->_get_transaction_passthrough($trans_ref);
         // validate
         if ($transdata['payment_type'] != 'subscription_purchase') {
             return false;
         }
         // user
         $user_id = $transdata['user_id'];
         // multiple purchase
         if (isset($transdata['is_another_membership_purchase']) && $transdata['is_another_membership_purchase'] == 'Y') {
             $member = mgm_get_member_another_purchase($user_id, $transdata['membership_type']);
         } else {
             $member = mgm_get_member($user_id);
         }
         // subscription exists
         if (isset($member->payment_info->module) && !empty($member->payment_info->module)) {
             // sale id
             if (isset($member->payment_info->txn_id)) {
                 $sale_id = $member->payment_info->txn_id;
             } else {
                 //check pack is recurring:
                 $pid = $pack_id ? $pack_id : $member->pack_id;
                 if ($pid) {
                     $s_packs = mgm_get_class('subscription_packs');
                     $sel_pack = $s_packs->get_pack($pid);
                     if ($sel_pack['num_cycles'] != 1) {
                         $sale_id = 0;
                     }
                     //not found
                 }
             }
             // module info
             // check for same module: if not call the same function of the applicale module.
             if (str_replace('mgm_', '', $member->payment_info->module) != str_replace('mgm_', '', $this->code)) {
                 // recur
                 return mgm_get_module($member->payment_info->module, 'payment')->cancel_recurring_subscription($trans_ref, null, null, $pack_id);
             }
             //skip if same pack is updated
             if (empty($member->pack_id) || is_numeric($pack_id) && $pack_id == $member->pack_id) {
                 return false;
             }
         } else {
             // error
             return false;
         }
     }
     // only for subscription_purchase
     if ($sale_id) {
         // sale id, returned order_number on approval url post back
         // saledetail_url
         $saledetail_url = add_query_arg(array('sale_id' => $sale_id), $this->_get_endpoint('saledetail'));
         // auth string
         $auth = $this->setting['apiusername'] . ':' . $this->setting['apipassword'];
         // post data
         $post_data = array();
         // headers
         $http_headers = array('Accept' => 'application/json', 'Authorization' => 'Basic ' . base64_encode($auth));
         // fetch
         $http_response = mgm_remote_post($saledetail_url, $post_data, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
         // decode
         $response = json_decode($http_response);
         // ind
         $lineitem_id = '';
         // validate
         if ((string) $response->response_code == 'OK') {
             $lineitem_id = (string) $response->sale->invoices[0]->lineitems[0]->billing->lineitem_id;
         }
         // set post
         $post_data = array('vendor_id' => $this->setting['sid'], 'lineitem_id' => $lineitem_id);
         // unsubscribe_url
         $unsubscribe_url = $this->_get_endpoint('unsubscribe');
         // fetch
         $http_response = mgm_remote_post($unsubscribe_url, $post_data, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
         // decode
         $response = json_decode($http_response);
         // return status
         if ((string) $response->response_code == 'OK') {
             return true;
         } else {
             return $response->errors[0]->message;
         }
     } elseif ($sale_id === 0) {
         //send email to admin if subscription Id is absent
         $system_obj = mgm_get_class('system');
         $dge = bool_from_yn($system_obj->get_setting('disable_gateway_emails'));
         //send email only if setting enabled
         if (!$dge) {
             // blog
             $blogname = get_option('blogname');
             // user
             $user = get_userdata($user_id);
             // notify admin
             mgm_notify_admin_membership_cancellation_manual_removal_required($blogname, $user, $member);
         }
         return true;
     }
     // default
     return false;
 }
Exemplo n.º 23
0
 /**
  * mgm subscription
  */
 private function _get_user_subscription(&$member, $user)
 {
     // init
     $subscription = array();
     // base active package
     if (isset($member->pack_id) && ($pack = mgm_get_pack($member->pack_id))) {
         // unset internal
         unset($pack['default'], $pack['move_members_pack'], $pack['active'], $pack['sort'], $pack['preference'], $pack['allow_renewal'], $pack['modules'], $pack['id'], $pack['product']);
         // update
         $pack['duration_type_expr'] = mgm_get_pack_duration_expr($pack['duration_type']);
         // sort
         ksort($pack);
         // set
         $subscription['package'] = array_merge(array('id' => $member->pack_id), $pack);
         // unset
         unset($member->pack_id);
     }
     // coupons
     $coupons = array();
     // register coupon
     if (isset($member->coupon)) {
         // set
         $coupons[] = array('register' => $member->coupon);
         // unset
         unset($member->coupon);
     }
     // upgrade coupon
     if (isset($member->upgrade)) {
         // set
         $coupons[] = array('upgrade' => $member->upgrade);
         // unset
         unset($member->upgrade);
     }
     // extend coupon
     if (isset($member->extend)) {
         // set
         $coupons[] = array('extend' => $member->extend);
         // unset
         unset($member->extend);
     }
     // set
     $subscription['coupons'] = $coupons;
     // payment
     if (isset($member->payment_info)) {
         // copy
         $payment_info = $member->payment_info;
         // module
         $payment_info->module = isset($payment_info->module) ? str_replace('mgm_', '', $payment_info->module) : '';
         // set
         $subscription['payment'] = $member->payment_info;
     }
     // other data, @ToDo add more later
     $other_fields = array('trial_on', 'trial_cost', 'trial_duration', 'trial_duration_type', 'trial_num_cycles', 'duration', 'duration_type', 'amount', 'currency', 'join_date', 'last_pay_date', 'expire_date', 'membership_type', 'status', 'status_str', 'payment_type', 'active_num_cycles', 'transaction_id');
     // loop
     foreach ($other_fields as $field) {
         switch ($field) {
             case 'join_date':
                 // join date
                 $subscription[$field] = date('Y-m-d H:i:s', isset($member->{$field}) && (int) $member->{$field} > 0 ? $member->{$field} : strtotime($user->user_registered));
                 break;
             default:
                 $subscription[$field] = isset($member->{$field}) ? $member->{$field} : '';
                 break;
         }
     }
     // newsletter
     if (isset($member->subscribed) && isset($member->autoresponder)) {
         $subscription['newsletter'] = array('module' => str_replace('mgm_', '', $member->autoresponder), 'subscribed' => bool_from_yn($member->subscribed) ? 'yes' : 'no');
     }
     // return
     return $subscription;
 }
Exemplo n.º 24
0
?>
 : <input name="direct_url" id="direct_url" type="text" value="" size="120" maxlength="255"/>				
				</div>
			</div>
			<div class="row">
				<div class="cell width120px">
					<b><?php 
_e('Restrict Access?', 'mgm');
?>
:</b> 
				</div>
			</div>
			<div class="row">		
				<div class="cell textalignleft ">
					<input type="checkbox" name="members_only" <?php 
echo bool_from_yn($download->members_only) ? "checked='checked'" : '';
?>
 /> <?php 
_e('Restrict via Post/Page Access', 'mgm');
?>
					
					<div class="tips width90">
						<?php 
_e('If checked, only users of the appropriate access level can access the file. User level is calculated by checking access to a certain post or posts.', 'mgm');
?>

					</div>						
					<p id="members_only_posts" class="displaynone">
						<select name="link_to_post_id[]" multiple size="10" class="height250px width820px">
							<?php 
echo mgm_make_combo_options($data['posts'], '', MGM_KEY_VALUE);
Exemplo n.º 25
0
 /**
  * Cancel Recurring Subscription
  * This is not a private function
  * @param int/string $trans_ref	
  * @param int $user_id	
  * @param int/string $subscr_id	
  * @param int $pack_id	
  * @return boolean
  */
 function cancel_recurring_subscription($trans_ref = null, $user_id = null, $subscr_id = null, $pack_id = null)
 {
     //if coming form process return after a subscription payment
     if (!empty($trans_ref)) {
         $transdata = $this->_get_transaction_passthrough($trans_ref);
         if ($transdata['payment_type'] != 'subscription_purchase') {
             return false;
         }
         $user_id = $transdata['user_id'];
         if (isset($transdata['is_another_membership_purchase']) && $transdata['is_another_membership_purchase'] == 'Y') {
             $member = mgm_get_member_another_purchase($user_id, $transdata['membership_type']);
         } else {
             $member = mgm_get_member($user_id);
         }
         if (isset($member->payment_info->module) && !empty($member->payment_info->module)) {
             if (isset($member->payment_info->subscr_id)) {
                 $subscr_id = $member->payment_info->subscr_id;
             } else {
                 //check pack is recurring:
                 $pid = $pack_id ? $pack_id : $member->pack_id;
                 if ($pid) {
                     $s_packs = mgm_get_class('subscription_packs');
                     $sel_pack = $s_packs->get_pack($pid);
                     if ($sel_pack['num_cycles'] != 1) {
                         $subscr_id = 0;
                     }
                 }
             }
             //check for same module: if not call the same function of the applicale module.
             if (str_replace('mgm_', '', $member->payment_info->module) != str_replace('mgm_', '', $this->code)) {
                 mgm_log('RECALLing ' . $member->payment_info->module . ': cancel_recurring_subscription FROM: ' . $this->code);
                 return mgm_get_module($member->payment_info->module, 'payment')->cancel_recurring_subscription($trans_ref, null, null, $pack_id);
             }
             //skip if same pack is updated
             if (empty($member->pack_id) || is_numeric($pack_id) && $pack_id == $member->pack_id) {
                 return false;
             }
         } else {
             return false;
         }
     } else {
         if ($this->setting['aquirer'] != 'sisow') {
             // skip sisow
             return false;
             //skip as trans reff will need to be passed always
         }
     }
     //only for subscription_purchase
     if ($this->setting['aquirer'] == 'sisow') {
         if (!isset($member)) {
             $member = mgm_get_member($user_id);
         }
         $txn_id = $member->payment_info->txn_id;
         //mgm_pr($member);
         // endpoint
         $endpoint = $this->_get_endpoint();
         // set
         $endpoint = str_replace('[action]', 'CancelReservationRequest', $endpoint);
         // keys
         $compute_keys = array($txn_id, $this->setting['merchant_id'], $this->setting['secret_key']);
         $compute_sha1 = sha1(implode('', $compute_keys));
         $post_data = array('trxid' => $txn_id, 'merchantid' => $this->setting['merchant_id'], 'sha1' => $compute_sha1);
         // headers
         $http_headers = array();
         //array('Content-Type' => 'text/xml');
         //mgm_pr($post_data); die;
         // create curl post
         $http_response = mgm_remote_post($endpoint, $post_data, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
         mgm_log($http_response, __FUNCTION__);
         // parse
         if ($xml = @simplexml_load_string($http_response)) {
             mgm_log($xml, __FUNCTION__);
             // redirect to issuer
             if (isset($xml->reservation->status)) {
                 return (string) $xml->reservation->status == 'Cancelled' ? true : false;
             } else {
                 return false;
             }
         }
     }
     //send email only if setting enabled
     if (!empty($subscr_id) || $subscr_id === 0) {
         $system_obj = mgm_get_class('system');
         $dge = bool_from_yn($system_obj->get_setting('disable_gateway_emails'));
         //send email only if setting enabled
         if (!$dge) {
             // blog
             $blogname = get_option('blogname');
             // user
             $user = get_userdata($user_id);
             // notify admin
             mgm_notify_admin_membership_cancellation_manual_removal_required($blogname, $user, $member);
         }
         return true;
     }
     return false;
 }
Exemplo n.º 26
0
 /**
  * A static method to grab the url from the packager to grab the ZIP
  * or the version of the plugin there.
  *
  * @uses bool_from_yn
  * @uses esc_url
  * @uses add_query_arg
  *
  * @param  string			$package 	Which package you want to grab
  * @param  boolean|string	$beta		Beta URL or not
  * @param  string  			$action		Which kind of URL you need? [zip|check]
  * @param  string  			$version	The version you want the URL to be related to
  * @return string|null      It will return the URL from the packager related to the asked action
  */
 public static function get_url($package = null, $beta = false, $action = 'zip', $version = null)
 {
     if (is_string($beta)) {
         if ($beta === 'beta') {
             $beta = true;
         } else {
             $beta = bool_from_yn($beta);
         }
     } else {
         $beta = (bool) $beta;
     }
     if (!in_array($action, array('zip', 'check'))) {
         return null;
     }
     $slug = self::get_slug($package);
     if (true === $beta || 'wysija-newsletters-premium' === $slug) {
         $url = self::$baseurl->packager . $action;
         $params = array('key' => self::get_slug($package));
         if ($beta === true) {
             $params['beta'] = 'true';
         }
         $url = add_query_arg($params, $url);
         return (string) $url;
     } else {
         return (string) self::$baseurl->core . $slug . '.zip';
     }
 }
Exemplo n.º 27
0
 /**
  * Cancel Recurring Subscription
  * This is not a private function
  * @param int/string $trans_ref	
  * @param int $user_id	
  * @param int/string $subscr_id	
  * @param int $pack_id	
  * @return boolean
  */
 function cancel_recurring_subscription($trans_ref = null, $user_id = null, $subscr_id = null, $pack_id = null)
 {
     //if coming form process return after a subscription payment
     if (!empty($trans_ref)) {
         $transdata = $this->_get_transaction_passthrough($trans_ref);
         if ($transdata['payment_type'] != 'subscription_purchase') {
             return false;
         }
         $user_id = $transdata['user_id'];
         if (isset($transdata['is_another_membership_purchase']) && $transdata['is_another_membership_purchase'] == 'Y') {
             $member = mgm_get_member_another_purchase($user_id, $transdata['membership_type']);
         } else {
             $member = mgm_get_member($user_id);
         }
         if (isset($member->payment_info->module) && !empty($member->payment_info->module)) {
             if (isset($member->payment_info->subscr_id)) {
                 $subscr_id = $member->payment_info->subscr_id;
             } else {
                 //check pack is recurring:
                 $pid = $pack_id ? $pack_id : $member->pack_id;
                 if ($pid) {
                     $s_packs = mgm_get_class('subscription_packs');
                     $sel_pack = $s_packs->get_pack($pid);
                     if ($sel_pack['num_cycles'] != 1) {
                         $subscr_id = 0;
                     }
                     // 0 stands for a lost subscription id
                 }
             }
             //check for same module: if not call the same function of the applicale module.
             if (str_replace('mgm_', '', $member->payment_info->module) != str_replace('mgm_', '', $this->code)) {
                 mgm_log('RECALLing ' . $member->payment_info->module . ': cancel_recurring_subscription FROM: ' . $this->code);
                 return mgm_get_module($member->payment_info->module, 'payment')->cancel_recurring_subscription($trans_ref, null, null, $pack_id);
             }
             //skip if same pack is updated
             if (empty($member->pack_id) || is_numeric($pack_id) && $pack_id == $member->pack_id) {
                 return false;
             }
         } else {
             return false;
         }
     }
     $system_obj = mgm_get_class('system');
     $dge = bool_from_yn($system_obj->get_setting('disable_gateway_emails'));
     //send email only if setting enabled
     if ((!empty($subscr_id) || $subscr_id === 0) && !$dge) {
         $user = get_userdata($user_id);
         //send notification email to admin:
         $message = __('The User: '******'mgm') . $user->user_email . ' (' . $user_id . ') ' . __('has upgraded/cancelled subscription.', 'mgm');
         $message .= "<br/>" . __('Please unsubscribe the user from Gateway Merchant panel.', 'mgm');
         if ($subscr_id) {
             $message .= "<br/><br/>" . __('Pay Id: ', 'mgm') . $subscr_id;
         }
         if (isset($member->transaction_id)) {
             $message .= "<br/>" . __('MGM Transaction Id:', 'mgm') . $member->transaction_id;
         }
         //admin email:
         if (!empty($system_obj->setting['admin_email'])) {
             @mgm_mail($system_obj->setting['admin_email'], sprintf(__('[%s] User Subscription Cancellation', 'mgm'), get_option('blogname')), $message);
         }
     }
     return true;
 }
Exemplo n.º 28
0
 /**
  * Cancel Recurring Subscription
  * This is not a private function
  * @param int/string $trans_ref	
  * @param int $user_id	
  * @param int/string $subscr_id	
  * @param int $pack_id	
  * @return boolean
  */
 function cancel_recurring_subscription($trans_ref = null, $user_id = null, $subscr_id = null, $pack_id = null)
 {
     //if coming form process return after a subscription payment
     if (!empty($trans_ref)) {
         $transdata = $this->_get_transaction_passthrough($trans_ref);
         if ($transdata['payment_type'] != 'subscription_purchase') {
             return false;
         }
         $user_id = $transdata['user_id'];
         if (isset($transdata['is_another_membership_purchase']) && $transdata['is_another_membership_purchase'] == 'Y') {
             $member = mgm_get_member_another_purchase($user_id, $transdata['membership_type']);
         } else {
             $member = mgm_get_member($user_id);
         }
         if (isset($member->payment_info->module) && !empty($member->payment_info->module)) {
             if (isset($member->payment_info->subscr_id)) {
                 $subscr_id = $member->payment_info->subscr_id;
             } else {
                 //check pack is recurring:
                 $pid = $pack_id ? $pack_id : $member->pack_id;
                 if ($pid) {
                     $s_packs = mgm_get_class('subscription_packs');
                     $sel_pack = $s_packs->get_pack($pid);
                     if ($sel_pack['num_cycles'] != 1) {
                         $subscr_id = 0;
                     }
                 }
             }
             //check for same module: if not call the same function of the applicale module.
             if (str_replace('mgm_', '', $member->payment_info->module) != str_replace('mgm_', '', $this->code)) {
                 mgm_log('RECALLing ' . $member->payment_info->module . ': cancel_recurring_subscription FROM: ' . $this->code);
                 return mgm_get_module($member->payment_info->module, 'payment')->cancel_recurring_subscription($trans_ref, null, null, $pack_id);
             }
             //skip if same pack is updated
             if (empty($member->pack_id) || is_numeric($pack_id) && $pack_id == $member->pack_id) {
                 return false;
             }
         } else {
             return false;
         }
     }
     // when a subscription found
     if ($subscr_id) {
         // @todo add api call
         // query data
         $query_data = array();
         // add internal vars
         $secure = array('clientAccnum' => $this->setting['client_acccnum'], 'clientSubacc' => $this->setting['client_subacc'], 'username' => $this->setting['datalink_username'], 'password' => $this->setting['datalink_password']);
         // merge
         $query_data = array_merge($query_data, $secure);
         // overwrite post data array with secure params
         // method
         $query_data['action'] = 'cancelSubscription';
         //check
         if (isset($member)) {
             $query_data['subscriptionId'] = $member->payment_info->subscr_id;
         } else {
             $query_data['subscriptionId'] = $subscr_id;
         }
         // xml response
         $query_data['returnXML'] = 1;
         // post string
         $query_string = _http_build_query($query_data, null, '&');
         // endpoint
         $endpoint = $this->_get_endpoint('datalink_sms');
         // url
         $url = $endpoint . '?' . $query_string;
         // log
         mgm_log($url, $this->module . '_' . __FUNCTION__);
         // remote get
         $http_response = mgm_remote_get($url, null, null, false);
         // log
         mgm_log($http_response, $this->module . '_' . __FUNCTION__);
         // xml
         if ($xml = @simplexml_load_string($http_response)) {
             // log
             mgm_log($xml, $this->module . '_' . __FUNCTION__);
             // return
             return (int) $xml == 1;
             // success
         }
         // end api call
     } elseif (is_null($subscr_id) || $subscr_id === 0) {
         $system_obj = mgm_get_class('system');
         $dge = bool_from_yn($system_obj->get_setting('disable_gateway_emails'));
         // check
         if (!$dge) {
             // blog
             $blogname = get_option('blogname');
             // user
             $user = get_userdata($user_id);
             // notify admin
             mgm_notify_admin_membership_cancellation_manual_removal_required($blogname, $user, $member);
         }
         // return
         return true;
     }
     // return
     return false;
 }
    /**
     * Cancel Recurring Subscription
     * This is not a private function
     * @param int/string $trans_ref	
     * @param int $user_id	
     * @param int/string $subscr_id	
     * @return boolean
     */
    function cancel_recurring_subscription($trans_ref = null, $user_id = null, $subscr_id = null, $pack_id = null)
    {
        //if coming form process return after a subscription payment
        if (!empty($trans_ref)) {
            $transdata = $this->_get_transaction_passthrough($trans_ref);
            if ($transdata['payment_type'] != 'subscription_purchase') {
                return false;
            }
            $user_id = $transdata['user_id'];
            if (isset($transdata['is_another_membership_purchase']) && $transdata['is_another_membership_purchase'] == 'Y') {
                $member = mgm_get_member_another_purchase($user_id, $transdata['membership_type']);
            } else {
                $member = mgm_get_member($user_id);
            }
            if (isset($member->payment_info->module) && !empty($member->payment_info->module)) {
                if (isset($member->payment_info->subscr_id)) {
                    $subscr_id = $member->payment_info->subscr_id;
                } else {
                    //check pack is recurring:
                    $pid = $pack_id ? $pack_id : $member->pack_id;
                    if ($pid) {
                        $s_packs = mgm_get_class('subscription_packs');
                        $sel_pack = $s_packs->get_pack($pid);
                        if ($sel_pack['num_cycles'] != 1) {
                            $subscr_id = 0;
                        }
                    }
                }
                //check for same module: if not call the same function of the applicale module.
                if (str_replace('mgm_', '', $member->payment_info->module) != str_replace('mgm_', '', $this->code)) {
                    // log
                    // mgm_log('RECALLing '. $member->payment_info->module .': cancel_recurring_subscription FROM: ' . $this->code);
                    // return
                    return mgm_get_module($member->payment_info->module, 'payment')->cancel_recurring_subscription($trans_ref, null, null, $pack_id);
                }
                //skip if same pack is updated
                if (empty($member->pack_id) || is_numeric($pack_id) && $pack_id == $member->pack_id) {
                    return false;
                }
            } else {
                return false;
            }
        }
        //only for subscription_purchase
        if ($subscr_id) {
            // set xml content
            $post_data = '<ARBCancelSubscriptionRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
							<merchantAuthentication>
								<name>' . $this->setting['loginid'] . '</name>
								<transactionKey>' . $this->setting['tran_key'] . '</transactionKey>
							</merchantAuthentication>
							<refId>' . $user_id . '</refId>
							<subscriptionId>' . $subscr_id . '</subscriptionId>
						</ARBCancelSubscriptionRequest>';
            // end  point
            $endpoint = $this->_get_endpoint($this->status . '_arb');
            // test_arb, live_aim etc.
            // headers
            $http_headers = array('Content-Type' => 'text/xml');
            // create curl post
            $http_response = mgm_remote_post($endpoint, $post_data, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
            // parse response and store into a different array:
            // do not use $this->response here as this will overwrite previous theprevious values in one scenario
            $arb_response = $this->_process_response('arb', $http_response, false);
            // check
            if (isset($arb_response['response_status']) && $arb_response['response_status'] == 1) {
                return true;
            }
        } elseif (is_null($subscr_id) || $subscr_id === 0) {
            //send email to admin if subscription Id is absent
            $system_obj = mgm_get_class('system');
            $dge = bool_from_yn($system_obj->get_setting('disable_gateway_emails'));
            //send email only if setting enabled
            if (!$dge) {
                // blog
                $blogname = get_option('blogname');
                // user
                $user = get_userdata($user_id);
                // notify admin
                mgm_notify_admin_membership_cancellation_manual_removal_required($blogname, $user, $member);
            }
            // return
            return true;
        }
        // return
        return false;
    }
 /**
  * Cancel Recurring Subscription
  *
  * @param int/string $trans_ref	
  * @param int $user_id	
  * @param int/string $subscr_id	
  * @return boolean
  */
 function cancel_recurring_subscription($trans_ref = null, $user_id = null, $subscr_id = null, $pack_id = null)
 {
     //if coming form process return after a subscription payment
     if (!empty($trans_ref)) {
         $transdata = $this->_get_transaction_passthrough($trans_ref);
         if ($transdata['payment_type'] != 'subscription_purchase') {
             return false;
         }
         $user_id = $transdata['user_id'];
         if (isset($transdata['is_another_membership_purchase']) && $transdata['is_another_membership_purchase'] == 'Y') {
             $member = mgm_get_member_another_purchase($user_id, $transdata['membership_type']);
         } else {
             $member = mgm_get_member($user_id);
         }
         if (isset($member->payment_info->module) && !empty($member->payment_info->module)) {
             $subscr_id = null;
             if (!empty($member->payment_info->subscr_id)) {
                 $subscr_id = $member->payment_info->subscr_id;
             } elseif (!empty($member->pack_id)) {
                 //check the pack is recurring
                 $s_packs = mgm_get_class('subscription_packs');
                 $sel_pack = $s_packs->get_pack($member->pack_id);
                 if ($sel_pack['num_cycles'] != 1) {
                     $subscr_id = 0;
                 }
                 // 0 stands for a lost subscription id
             }
             //check for same module: if not call the same function of the applicale module.
             if (str_replace('mgm_', '', $member->payment_info->module) != str_replace('mgm_', '', $this->code)) {
                 // mgm_log('RECALLing '. $member->payment_info->module .': cancel_recurring_subscription FROM: ' . $this->code);
                 return mgm_get_module($member->payment_info->module, 'payment')->cancel_recurring_subscription($trans_ref, null, null, $pack_id);
             }
             //skip if same pack is updated
             if (empty($member->pack_id) || is_numeric($pack_id) && $pack_id == $member->pack_id) {
                 return false;
             }
         } else {
             return false;
         }
     }
     //ony for subscription_purchase
     if ($subscr_id) {
         $user = get_userdata($user_id);
         $format = mgm_get_date_format('date_format');
         // compose post body
         $post_data = array('USER' => $this->setting['username'], 'PWD' => $this->setting['password'], 'SIGNATURE' => $this->setting['signature'], 'VERSION' => '64.0', 'METHOD' => 'ManageRecurringPaymentsProfileStatus', 'PROFILEID' => $subscr_id, 'ACTION' => 'Cancel', 'NOTE' => sprintf('Cancellation selected by member on UPGRADE: "%s", ID: %d on: %s', $user->user_email, $user->ID, date($format)));
         // end point url
         $end_point = $this->_get_endpoint();
         //issue #1508
         $url_parsed = parse_url($end_point);
         // domain/host
         $domain = $url_parsed['host'];
         // headers
         $http_headers = array('POST /cgi-bin/webscr HTTP/1.1\\r\\n', 'Content-Type: application/x-www-form-urlencoded\\r\\n', 'Host: ' . $domain . '\\r\\n', 'Connection: close\\r\\n\\r\\n');
         // post
         $http_response = mgm_remote_post($end_point, $post_data, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
         // log
         mgm_log($http_response, __FUNCTION__);
         // fields
         // $fields = mgm_http_build_query($post_data);
         // post
         // $response = $this->_curl_post($endpoint, $fields, '', false);
         // sleep
         sleep(1);
         // parse
         $this->response = array();
         // parse to array
         parse_str($http_response, $this->response);
         // log
         mgm_log($this->response, __FUNCTION__);
         // cancel
         return isset($this->response['ACK']) && $this->response['ACK'] == 'Success' ? true : false;
     } elseif ($subscr_id === 0) {
         //send email to admin if subscription Id is absent
         $system_obj = mgm_get_class('system');
         $dge = bool_from_yn($system_obj->get_setting('disable_gateway_emails'));
         //send email only if setting enabled
         if (!$dge) {
             // blog
             $blogname = get_option('blogname');
             // user
             $user = get_userdata($user_id);
             // notify admin
             mgm_notify_admin_membership_cancellation_manual_removal_required($blogname, $user, $member);
         }
         return true;
     }
     return false;
 }