. */ /************************************/ /* Plugin Deactivation */ /************************************/ function ashop_deactivate() { // Remove Installed Options delete_option("ashop_dbhost"); delete_option("ashop_dbhost"); delete_option("ashop_dbuser"); delete_option("ashop_dbpass"); } register_deactivation_hook(__FILE__, 'ashop_deactivate'); /************************************/ /* Widgets */ /************************************/ include_once dirname( __FILE__ ) . '/widgets.php'; $ashop_db = ashop_db_connection(); // Register widgets add_action('widgets_init', create_function('', 'return register_widget("AShopCategoriesWidget");')); add_action('widgets_init', create_function('', 'return register_widget("AShopShopsWidget");')); add_action('widgets_init', create_function('', 'return register_widget("AShopTopListWidget");')); add_action('widgets_init', create_function('', 'return register_widget("AShopLatestAdditionsWidget");')); add_action('widgets_init', create_function('', 'return register_widget("AutoresponderWidget");')); /************************************/ /* Utility Functions */ /************************************/ // Get path to product images... function ashop_getproductimages($productid,$imagenumber=0) { global $ashop_db; $ashop_path = ashop_get_preference('ashoppath', $ashop_db); $imageinfo = array(); $additionalimages = 0; if ($imagenumber > 0) $imagenumberpath = "/$imagenumber"; else $imagenumberpath = ""; if (is_numeric($productid) && is_dir("$ashop_path/prodimg/$productid$imagenumberpath")) { $findfile = opendir("$ashop_path/prodimg/$productid$imagenumberpath"); if ($findfile) while (false !== ($foundfile = readdir($findfile))) { if (strtolower(substr($foundfile,-4)) == ".gif") $imageinfo["format"] = "gif"; if (strtolower(substr($foundfile,-4)) == ".jpg") $imageinfo["format"] = "jpg"; if (!is_dir("$ashop_path/prodimg/$productid$imagenumberpath/$foundfile") && substr($foundfile,0,2) != "m-" && substr($foundfile,0,2) != "p-" && substr($foundfile,0,2) != "t-" && !is_dir($foundfile) && (strtolower(substr($foundfile,-4)) == ".gif" || strtolower(substr($foundfile,-4)) == ".jpg")) $imageinfo["main"] = $foundfile; if (substr($foundfile,0,2) == "m-" && !is_dir($foundfile)) $imageinfo["mini"] = $foundfile; if (substr($foundfile,0,2) == "p-" && !is_dir($foundfile)) $imageinfo["product"] = $foundfile; if (substr($foundfile,0,2) == "t-" && !is_dir($foundfile)) $imageinfo["thumbnail"] = $foundfile; if (is_dir("$ashop_path/prodimg/$productid$imagenumberpath/$foundfile") && is_numeric($foundfile)) $imageinfo["additionalimages"]++; } } return $imageinfo; } // Backwards compatibility for MySQLi PHP extension... function ashop_mysqli_result($res,$row=0,$col=0){ $numrows = @mysqli_num_rows($res); if ($numrows && $row <= ($numrows-1) && $row >=0) { mysqli_data_seek($res,$row); $resrow = mysqli_fetch_array($res); if (isset($resrow[$col])){ return $resrow[$col]; } } return false; } // Establish a connection to an AShop database // AShop must be installed on the same server as WordPress function ashop_db_connection() { $ashopdbhost = get_option('ashop_dbhost'); $ashopdbname = get_option('ashop_dbname'); $ashopdbuser = get_option('ashop_dbuser'); $ashopdbpass = get_option('ashop_dbpass'); $ashop_db = @mysqli_connect("$ashopdbhost", "$ashopdbuser", "$ashopdbpass", "$ashopdbname"); return $ashop_db; } // Get a configuration option from AShop function ashop_get_preference($prefname, $ashop_db) { $result = @mysqli_query($ashop_db, "SELECT prefvalue FROM preferences WHERE prefname='$prefname'"); $preferencevalue = @ashop_mysqli_result($result,0,"prefvalue"); return $preferencevalue; } // Get information about a product function ashop_get_productdetails($productid, $ashop_db) { if (is_numeric($productid)) { $result = @mysqli_query($ashop_db, "SELECT * FROM product WHERE productid='$productid'"); $row = @mysqli_fetch_array($result); } return $row; } // Return an array with a list of product categories available in AShop function ashop_get_categories($ashop_db, $shop=1) { $categories = array(); $result = @mysqli_query($ashop_db, "SELECT categoryid,name FROM category WHERE parentcategoryid=categoryid AND grandparentcategoryid=categoryid AND (userid='$shop' OR memberclone='1') ORDER BY ordernumber"); while ($row = @mysqli_fetch_array($result)) { $categoryid = $row["categoryid"]; $categoryname = $row["name"]; $categories[$categoryid] = $categoryname; } return $categories; } // Return an array with a list of shops available in AShop function ashop_get_shops($ashop_db) { $shops[1] = __('Main Shop'); $result = @mysqli_query($ashop_db, "SELECT userid,shopname FROM user WHERE userid!='1'"); while ($row = @mysqli_fetch_array($result)) { $shop = $row["userid"]; $shopname = $row["shopname"]; $shops[$shop] = $shopname; } return $shops; } // Return an array with a list of autoresponders available in AShop function ashop_get_autoresponders($ashop_db) { $result = @mysqli_query($ashop_db, "SELECT responderid,name FROM autoresponders"); while ($row = @mysqli_fetch_array($result)) { $autoresponder = $row["responderid"]; $name = $row["name"]; $autoresponders[$autoresponder] = $name; } return $autoresponders; } // Get the profile ID of a specified autoresponder function ashop_get_arprofileid($ashop_db, $autoresponderid) { if (!empty($autoresponderid) && is_numeric($autoresponderid)) { $result = @mysqli_query($ashop_db, "SELECT profileid FROM autoresponders WHERE responderid='$autoresponderid'"); $arprofileid = @ashop_mysqli_result($result,0,"profileid"); return $arprofileid; } else return FALSE; } /************************************/ /* Shortcodes */ /************************************/ include_once dirname( __FILE__ ) . '/shortcodes.php'; /************************************/ /* Administration */ /************************************/ // Admin configuration options... if ( is_admin() ) add_action('admin_menu', 'ashop_menu'); if ( is_admin() ) add_action('admin_menu', 'ashop_quicklink'); add_option('ashop_dbhost'); add_option('ashop_dbname'); add_option('ashop_dbuser'); add_option('ashop_dbpass'); function ashop_menu() { if ( function_exists('add_submenu_page') ) add_submenu_page('plugins.php', __('AShop Configuration'), __('AShop Configuration'), 'manage_options', 'ashop-config', 'ashop_conf'); } function ashop_conf() { if (!current_user_can('manage_options')) { wp_die( __('You do not have sufficient permissions to access this page.') ); } if ( isset($_POST['submit']) ) { $ashop_dbhost = $_POST["ashopdbhost"]; $ashop_dbname = $_POST["ashopdbname"]; $ashop_dbuser = $_POST["ashopdbuser"]; $ashop_dbpass = $_POST["ashopdbpass"]; $ashop_db = @mysqli_connect("$ashop_dbhost", "$ashop_dbuser", "$ashop_dbpass", "$ashop_dbname"); @mysql_select_db("$ashop_dbname",$ashop_db); if (@mysqli_error()) { $ashop_message = '
'; $ashop_message .= __('Unable to connect. The login options you entered are probably incorrect.'); $ashop_message .= '
'; } else { update_option( 'ashop_dbhost', $ashop_dbhost ); update_option( 'ashop_dbname', $ashop_dbname ); update_option( 'ashop_dbuser', $ashop_dbuser ); update_option( 'ashop_dbpass', $ashop_dbpass ); $wordpresspath = ABSPATH; if (substr($wordpresspath,-1) == "/") $wordpresspath = substr($wordpresspath,0,-1); $wordpresspath = @mysqli_real_escape_string($wordpresspath,$ashop_db); $result = @mysqli_query($ashop_db, "SELECT * FROM preferences WHERE prefname='wordpresspath'"); if (!@mysqli_num_rows($result)) @mysqli_query($ashop_db, "INSERT INTO preferences (prefid, prefname, prefvalue) VALUES ('172', 'wordpresspath', '$wordpresspath')"); @mysqli_query($ashop_db, "UPDATE preferences SET prefvalue='$wordpresspath' WHERE prefname='wordpresspath'"); $ashop_message = ''; $ashop_message .= __('Options saved.'); $ashop_message .= '
'; } } echo ''; _e('Enter the connection parameters for your AShop database.'); echo '
'; echo '|
ID ) );
echo "\" class=\"regular-text\" /> ".__("Enter your AShop admin panel username.")." |
|
|
".__("Enter your AShop admin panel password.")." |