Esempio n. 1
0
/**
 * wp-admin / Classifieds / Options panel logic.
 * 
 * This functions is being executed when wp-admin / Classifieds / Options panel 
 * is being loaded. It either generates list of available modules or loads module,
 * depending on $_REQUEST 'disabled', 'enabled' and 'module' params.
 * 
 * @global $_REQUEST
 * 
 * @uses adverts_config()
 * @uses adverts_config_set()
 * @uses adverts_config_save()
 * @uses adverts_request()
 * 
 * @since 0.1
 * @return void
 */
function adverts_admin_page_extensions()
{
    // We are on one of Adverts admin pages, load default Adverts admin styles.
    wp_enqueue_style('adverts-admin');
    // Load modules config
    $module = adverts_config('module');
    $module_groups = array(array("title" => __("Modules", "adverts"), "modules" => array("core" => array("title" => __("Core", "adverts"), "text" => __("Here you can configure most basic Adverts options, applicable on any site.", "adverts"), "type" => "static", "plugin" => null), "payments" => array("title" => __("Payments", "adverts"), "text" => __("Charge users for posting classified ads on your site.", "adverts"), "type" => "", "plugin" => null), "wc-payments" => array("title" => __("WooCommerce Payments", "adverts"), "text" => __("Use WooCommerce to charge users for posting classifieds.", "adverts"), "type" => "", "plugin" => "wpadverts-wc/wpadverts-wc.php", "purchase_url" => "http://wpadverts.com/extensions/woocommerce-integration/"))), array("title" => __("Features", "adverts"), "modules" => array("featured" => array("title" => __("Featured Ads", "adverts"), "text" => __("Allow users to post Ads displayed always at the top of the list.", "adverts"), "type" => "", "plugin" => null), "wpadverts-mal" => array("title" => __("Maps And Locations", "adverts"), "text" => __("Locations Taxonomy, Google Maps integration and more.", "adverts"), "type" => "", "plugin" => "wpadverts-mal/wpadverts-mal.php", "purchase_url" => "http://wpadverts.com/extensions/maps-and-locations/"))), array("title" => __("Payment Gateways", "adverts"), "modules" => array("bank-transfer" => array("title" => __("Bank Transfer", "adverts"), "text" => __("Allow users to pay for ad posting using direct bank transfer or cash payments.", "adverts"), "type" => "", "plugin" => null), "paypal-standard" => array("title" => __("PayPal Standard", "adverts"), "text" => __("PayPal Payments Standard, allow users to pay for ads via PayPal.", "adverts"), "type" => "", "plugin" => "wpadverts-paypal-standard/wpadverts-paypal-standard.php", "purchase_url" => "http://wpadverts.com/extensions/paypal-payments-standard/"))));
    if (adverts_request('enable')) {
        // User is trying to enable module
        $enable = adverts_request('enable');
        $module[$enable] = 0.5;
        // Save config
        adverts_config_set('config.module', $module);
        adverts_config_save('config');
        wp_redirect(add_query_arg(array('enable' => false, 'noheader' => false, 'module' => $enable)));
        exit;
    }
    if (adverts_request('disable')) {
        // User is trying to disable module
        $disable = adverts_request('disable');
        if (isset($module[$disable])) {
            unset($module[$disable]);
        }
        // Save config
        adverts_config_set('config.module', $module);
        adverts_config_save('config');
        wp_redirect(remove_query_arg(array('disable', 'noheader')));
        exit;
    }
    if (adverts_request('module')) {
        // Load module (based on $_GET[module]) panel
        $name = adverts_request('module');
        $module_current = null;
        $module_key = null;
        foreach ($module_groups as $group) {
            foreach ($group["modules"] as $key => $tmp) {
                if ($key == $name) {
                    $module_current = $tmp;
                    $module_key = $key;
                    break 2;
                }
            }
        }
        if ($module_current === null) {
            esc_html_e(sprintf(__("Module [%s] does not exist.", "adverts"), $name));
            return;
        }
        if ($module_current["plugin"]) {
            include_once dirname(ADVERTS_PATH) . '/' . dirname($module_current["plugin"]) . '/includes/admin-module-options.php';
        } else {
            include_once ADVERTS_PATH . 'addons/' . $module_key . '/includes/admin-module-options.php';
        }
    } else {
        // Display modules list template
        include ADVERTS_PATH . 'admin/options.php';
    }
}
Esempio n. 2
0
/**
 * Install Modules 
 * 
 * Run module installation functions (if any) on modules that were "just" activated. 
 * This function is executed in "init" filter with low priority so all the modules 
 * are initiated before it is run.
 * 
 * @since 0.2
 * @return void
 */
function adverts_install_modules()
{
    $module = adverts_config('config.module');
    $install = array();
    foreach ((array) $module as $mod => $status) {
        if (!is_file(ADVERTS_PATH . "addons/{$mod}/{$mod}.php")) {
            continue;
        }
        if ($status > 0) {
            include_once ADVERTS_PATH . "addons/{$mod}/{$mod}.php";
        }
        if ($status == 0.5) {
            add_action("init", "adverts_install_modules");
            Adverts_Flash::instance()->add_info(__("Module activated successfully.", "adverts"));
            $module[$mod] = 1;
            adverts_config_set('config.module', $module);
            adverts_config_save('config');
            do_action("adverts_install_module_{$mod}");
        }
    }
}
Esempio n. 3
0
 /**
  * AJAX License validation
  * 
  * This function is executed from /wp-admin/admin-ajax.php it handles
  * license key validation.
  * 
  * @see wp_ajax_adverts_license_validate_$slug action
  * @see self::connect()
  * 
  * @access public
  * @since 1.0
  * @return void
  */
 public function validate_license()
 {
     $license = trim(adverts_request("license"));
     $update = false;
     $response = new stdClass();
     $response->status = 200;
     $response->error = "";
     $response->message = "";
     if (!empty($license)) {
         $request = $this->remote("license", array("license" => $license));
         if ($request === false) {
             $response->status = 400;
             $response->message = __("Cannot connect to remote server. Please try again later.", "adverts");
         } elseif ($request->result == 1) {
             $update = true;
         } else {
             $response->status = $request->result;
             $response->message = $request->message;
         }
     } else {
         $license = null;
         $update = true;
     }
     if ($update) {
         $config = adverts_config('config.license');
         $config[$this->slug] = $license;
         adverts_config_set('config.license', $config);
         adverts_config_save('config');
     }
     $transient = get_site_transient("update_plugins");
     if ($update && $license === null && isset($transient->response[$this->plugin])) {
         unset($transient->checked[$this->plugin]);
         unset($transient->response[$this->plugin]);
         set_site_transient("update_plugins", $transient);
     }
     echo json_encode($response);
     exit;
 }