ID, 'aw_affiliatewire_quick_ignition_Landing_Page_value', true)); $download_link = (aw_get_metadata('post', $post->ID, 'aw_affiliatewire_quick_ignition_Direct_Download_value', true)); $purchase_page = (aw_get_metadata('post', $post->ID, 'aw_affiliatewire_quick_ignition_Purchase_Page_value', true)); $product_box = (aw_get_metadata('post', $post->ID, 'aw_affiliatewire_quick_ignition_Product_Box_value', true)); $product_name = (aw_get_metadata('post', $post->ID, 'aw_affiliatewire_quick_ignition_Product_Name_value', true)); $product_description = (aw_get_metadata('post', $post->ID, 'aw_affiliatewire_quick_ignition_Product_Description_value', true)); $product_details = (aw_get_metadata('post', $post->ID, 'aw_affiliatewire_quick_ignition_Product_Details_value', true)); $product_price = (aw_get_metadata('post', $post->ID, 'aw_affiliatewire_quick_ignition_Product_Price_value', true)); $content = aw_affiliatewire_quick_ignition_replace_placeholder_codes_text(awItems::awDescription, '', $product_description, $content); $content = aw_affiliatewire_quick_ignition_replace_placeholder_codes_text(awItems::awProductName, '', $product_name, $content); $content = aw_affiliatewire_quick_ignition_replace_placeholder_codes_text(awItems::awProductPrice, '', $product_price, $content); $content = aw_affiliatewire_quick_ignition_replace_placeholder_codes_image(awItems::awProductBox, $product_name, $product_box, $content); $content = aw_affiliatewire_quick_ignition_replace_placeholder_codes_links(awItems::awLandingPage, 'More Information', $landing_page, $content); $content = aw_affiliatewire_quick_ignition_replace_placeholder_codes_links(awItems::awBuyNow, 'Buy Now', $purchase_page, $content); $content = aw_affiliatewire_quick_ignition_replace_placeholder_codes_links(awItems::awDownload, 'Download', $download_link, $content); $content = aw_affiliatewire_quick_ignition_add_class_to_links($content, 'post' . $post->ID, true); global $pagenow; if ($pagenow == 'index.php') { $content .= aw_affiliatewire_quick_ignition_getCSS(); } return $content; } function aw_affiliatewire_quick_ignition_replace_placeholder_codes_links($idName, $message, $link, $text) { //replace text with link with text based on text found between the tags //if no text is found use the default message $pattern = '/[[]' . $idName . '([^]]*)[]](.*)[[][\/]' . $idName . '[]]/i'; $count = preg_match_all($pattern, $text, $matches); for ($cnt = 0; $cnt < $count; $cnt++) { $matchedText = trim(str_replace(' ', ' ', htmlentities(utf8_decode(strip_tags($matches[2][$cnt]))))); $matchedText2 = $matches[2][$cnt]; if ($matchedText == '') { $matchedText = $message; $matchedText2 = $message; } $replace = '' . ($matchedText2) . ''; $replace = aw_affiliatewire_quick_ignition_add_class_to_links($replace, $idName, false); $text = str_replace($matches[0][$cnt], $replace, $text); } return $text; } function aw_affiliatewire_quick_ignition_replace_placeholder_codes_image($idName, $message, $link, $text) { //replace text with link with text based on text found between the tags //if no text is found use the default message $pattern = '/[[]' . $idName . '([^]]*)[]](.*)[[][\/]' . $idName . '[]]/i'; $count = preg_match_all($pattern, $text, $matches); for ($cnt = 0; $cnt < $count; $cnt++) { $matchedText = trim(str_replace(' ', ' ', htmlentities(utf8_decode(strip_tags($matches[2][$cnt]))))); if ($matchedText == '') { $matchedText = $message; } $replace = '' .
                ($matchedText) . ''; $replace = aw_affiliatewire_quick_ignition_add_class_to_images($replace, $idName, false); $text = str_replace($matches[0][$cnt], $replace, $text); } return $text; } function aw_affiliatewire_quick_ignition_replace_placeholder_codes_text($idName, $message, $link, $text) { //replace text with link with text based on text found between the tags //if no text is found use the default message $pattern = '/[[]' . $idName . '([^]]*)[]](.*)[[][\/]' . $idName . '[]]/i'; $count = preg_match_all($pattern, $text, $matches); for ($cnt = 0; $cnt < $count; $cnt++) { $matchedText = trim(str_replace(' ', ' ', htmlentities(utf8_decode(strip_tags($matches[2][$cnt]))))); if ($matchedText == '') { $matchedText = $message; } $replace = '' . ($link) . ''; $replace = aw_affiliatewire_quick_ignition_add_class_to_text($replace, $idName, false); $text = str_replace($matches[0][$cnt], $replace, $text); } return $text; } global $aw_affiliatewire_quick_ignition_blank_meta_boxes; $aw_affiliatewire_quick_ignition_blank_meta_boxes = aw_affiliatewire_quick_ignition_create_meta_boxes(); function aw_affiliatewire_quick_ignition_create_meta_boxes() { //define basic metaboxes for storing data used by the plugin $offerDetails = aw_affiliatewire_quick_ignition_getOptionArray($post); $affiliateAliases = get_option('aw_affiliatewire_quick_ignition_affiliateAliases'); $toReturn = array( "Affiliate_Alias" => array( "name" => "aw_affiliatewire_quick_ignition_Affiliate_Alias", "std" => "", "title" => "Affiliate Alias", "type" => 'select', "selectValues" => $affiliateAliases, "description" => "Choose an aliases.", "javascript" => aw_affiliatewire_quick_ignition_get_javascript(5), "button" => ""), "Product_Name" => array( "name" => "aw_affiliatewire_quick_ignition_Product_Name", "std" => "", "title" => "Product Name", "description" => "Select a product using the drop-down menu or enter the name manually.
", "chocies" => $offerDetails['products'], "javascript" => aw_affiliatewire_quick_ignition_get_javascript(3), "button" => ""), "Landing_Page" => array( "name" => "aw_affiliatewire_quick_ignition_Landing_Page", "std" => "", "title" => "Landing Page", "description" => "Select a pre-made landing page using the drop-down menu or enter your own landing page URL.
", "chocies" => "", "javascript" => aw_affiliatewire_quick_ignition_get_javascript(1), "button" => ''), "Purchase_Page" => array( "name" => "aw_affiliatewire_quick_ignition_Purchase_Page", "std" => "", "title" => "Purchase Page", "description" => "", "button" => ''), "Direct_Download" => array( "name" => "aw_affiliatewire_quick_ignition_Direct_Download", "std" => "", "title" => "Direct Download Link", "description" => "", "button" => ''), "Product_Price" => array( "name" => "aw_affiliatewire_quick_ignition_Product_Price", "std" => "", "title" => "Product Price", "description" => "Select the product price or enter your own text.
", "chocies" => "", "javascript" => aw_affiliatewire_quick_ignition_get_javascript(2), "button" => ""), "Product_Box" => array( "name" => "aw_affiliatewire_quick_ignition_Product_Box", "std" => "", "title" => "Product Box", "description" => "Use the default box shot shown or enter a custom image URL.", "button" => ""), "Product_Description" => array( "name" => "aw_affiliatewire_quick_ignition_Product_Description", "std" => "", "title" => "Product Description", "type" => 'textarea', "description" => "", "button" => ""), "Product_Details" => array( "name" => "aw_affiliatewire_quick_ignition_Product_Details", "std" => "", "title" => "Product Details", "type" => 'textarea', "description" => "Add a detailed description of the product here.", "button" => ""), "Product_Images" => array( "name" => "aw_affiliatewire_quick_ignition_Product_Images", "std" => "", "title" => "Product Images ", "description" => "Choose from the available images and copy the url to insert into your post.
", "chocies" => "", "javascript" => aw_affiliatewire_quick_ignition_get_javascript(4)) ); unset($toReturn['Product_Details']); return $toReturn; } function aw_affiliatewire_quick_ignition_new_meta_boxes() { //create the meta boxes when the post page is created global $post, $aw_affiliatewire_quick_ignition_blank_meta_boxes; //populate the select dropdowns with information based on //stored data with the post $offerDetails = aw_affiliatewire_quick_ignition_getOptionArray($post->ID); $aw_affiliatewire_quick_ignition_blank_meta_boxes['Landing_Page']["choices"] .= $offerDetails['landing_pages']; $aw_affiliatewire_quick_ignition_blank_meta_boxes['Landing_Page']["javascript"] = aw_affiliatewire_quick_ignition_get_javascript(1); $aw_affiliatewire_quick_ignition_blank_meta_boxes['Product_Price']["choices"] = $offerDetails['prices']; $aw_affiliatewire_quick_ignition_blank_meta_boxes['Product_Price']['javascript'] = aw_affiliatewire_quick_ignition_get_javascript(2); $aw_affiliatewire_quick_ignition_blank_meta_boxes['Product_Name']['choices'] = $offerDetails['products']; $aw_affiliatewire_quick_ignition_blank_meta_boxes['Product_Name']['javascript'] = aw_affiliatewire_quick_ignition_get_javascript(3); $aw_affiliatewire_quick_ignition_blank_meta_boxes['Product_Images']["choices"] = $offerDetails['product_images']; $aw_affiliatewire_quick_ignition_blank_meta_boxes['Product_Images']["javascript"] = aw_affiliatewire_quick_ignition_get_javascript(4); $aw_affiliatewire_quick_ignition_blank_meta_boxes['Affiliate_Alias']['defaultValue'] = aw_get_metadata('post', $post->ID, 'aw_affiliatewire_quick_ignition_Affiliate_Alias_value', true); $meta_box_value = aw_get_metadata('post', $post->ID, 'aw_affiliatewire_quick_ignition_Product_Box' . '_value', true); $aw_affiliatewire_quick_ignition_blank_meta_boxes['Product_Box']['title'] = "Product Box"; //load the data into the meta boxes from the database //and create the html to display it foreach ($aw_affiliatewire_quick_ignition_blank_meta_boxes as $meta_box_name => $meta_box) { $meta_box_value = aw_get_metadata('post', $post->ID, $meta_box['name'] . '_value', true); if ($meta_box_value == "") $meta_box_value = $meta_box['std']; echo''; echo'

' . $meta_box['title'] . '

'; echo'

' . $meta_box['choices'] . '

'; if (isset($meta_box['type']) && $meta_box['type'] == 'textarea') { echo '
' . $meta_box['button']; } elseif (isset($meta_box['type']) && $meta_box['type'] == 'select') { echo str_replace('No Items', "No Alias's Entered", aw_affiliatewire_quick_ignition_create_select($meta_box['name'] . '_value', $meta_box['selectValues'], $meta_box['defaultValue'], ' onChange="aw_change_alias();"')); } else { echo'' . $meta_box['button'] . '
'; } echo $meta_box['javascript']; } } function aw_affiliatewire_quick_ignition_create_meta_box() { //add the metaboxes to the edit post page if (function_exists('add_meta_box')) { add_meta_box('new-meta-boxes', 'AffiliateWire Quick Ignition
Product Name Product Description Product Box Image Product Price
Product Landing Page Product Buy Now Product Download Link
', 'aw_affiliatewire_quick_ignition_new_meta_boxes', 'post', 'normal', 'high'); } } function aw_affiliatewire_quick_ignition_save_postdata($post_id) { //save data stored in meta boxes on the edit page global $post, $aw_affiliatewire_quick_ignition_blank_meta_boxes; foreach ($aw_affiliatewire_quick_ignition_blank_meta_boxes as $meta_box) { // Verify if (!wp_verify_nonce($_POST[$meta_box['name'] . '_noncename'], plugin_basename(__FILE__))) { return $post_id; } if ('page' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) return $post_id; } else { if (!current_user_can('edit_post', $post_id)) return $post_id; } $data = $_POST[$meta_box['name'] . '_value']; if (aw_get_metadata('post', $post_id, $meta_box['name'] . '_value', true) == "") add_post_meta($post_id, $meta_box['name'] . '_value', $data, true); elseif ($data != aw_get_metadata('post', $post_id, $meta_box['name'] . '_value', true)) update_post_meta($post_id, $meta_box['name'] . '_value', $data); elseif ($data == "") delete_post_meta($post_id, $meta_box['name'] . '_value', aw_get_metadata('post', $post_id, $meta_box['name'] . '_value', true)); } } function aw_affiliatewire_quick_ignition_getCSS() { //create and return the CSS to make the buttons/text that is replaced in each post display //uniformly $text = ' '; return $text; } function aw_affiliatewire_quick_ignition_getOptionArray($postID) { //set defualt values for select options incase there are no products, or no product is selected $toReturn['products'] = ''; $toReturn['landing_pages'] = ''; $toReturn['prices'] = ''; $toReturn['product_images'] = ''; //take the product lists and create the drop down select menu's used //on the editor page $productsList = maybe_unserialize(get_option('aw_affiliatewire_quick_ignition_products')); foreach ($productsList as $alias => $products) { $productCount = number_format(get_option('aw_affiliatewire_quick_ignition_productsCount'), 0); if ($productCount > 0) { $affiliateAliases = get_option('aw_affiliatewire_quick_ignition_affiliateAliases'); $currentAlias = aw_get_metadata('post', $postID, 'aw_affiliatewire_quick_ignition_Affiliate_Alias_value', true); if (in_array($currentAlias, $affiliateAliases)) { $returnAlias = $currentAlias; } else { $returnAlias = array_shift($affiliateAliases); } ksort($products); if ($alias == $returnAlias) { $visable = 'inherit'; } else { $visable = 'none'; } $offers .= ''; } $toReturn['products'] = $offers; } return $toReturn; } function aw_affiliatewire_quick_ignition_create_select($selectName, $options, $selectedValue = '', $extras = '') { //create a standard select option pair based on a array using a given name $toReturn = ''; return $toReturn; } function aw_affiliatewire_quick_ignition_create_select_images($selectName, $options, $selectedValue = '', $extras = '') { //create a select option pair for images //to add a class to enable the popup to display thumbnails $toReturn = ''; return $toReturn; } function aw_getCleanString($string) { //replace double quotes with single quoutes in strings passed //to prevent errors $toReturn = str_replace('"', "'", $string); return $toReturn; } function aw_affiliatewire_quick_ignition_get_javascript($scriptID) { //function to retreive and return a javascript used to populate the textboxes for //the editor switch ($scriptID) { case 1: return ''; break; case 2: return ''; break; case 3: return ' '; break; case 4: return ' '; break; case 5: return ' '; break; } } if (!function_exists('aw_print_debug')) { function aw_print_debug($cat) { return '
' . wordwrap(print_r($cat, true), 150, "\n") . '
'; } } if (!function_exists('get_site_url')) { /** * Retrieve the site url for a given site. * * Returns the 'site_url' option with the appropriate protocol, 'https' if * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is * overridden. * * @package WordPress * @since 3.0.0 * * @param int $blog_id (optional) Blog ID. Defaults to current blog. * @param string $path Optional. Path relative to the site url. * @param string $scheme Optional. Scheme to give the site url context. Currently 'http','https', 'login', 'login_post', or 'admin'. * @return string Site url link with optional path appended. */ function get_site_url($blog_id = null, $path = '', $scheme = null) { // should the list of allowed schemes be maintained elsewhere? $orig_scheme = $scheme; if (!in_array($scheme, array('http', 'https'))) { if (( 'login_post' == $scheme || 'rpc' == $scheme ) && ( force_ssl_login() || force_ssl_admin() )) $scheme = 'https'; elseif (( 'login' == $scheme ) && force_ssl_admin()) $scheme = 'https'; elseif (( 'admin' == $scheme ) && force_ssl_admin()) $scheme = 'https'; else $scheme = ( is_ssl() ? 'https' : 'http' ); } if (empty($blog_id) || !is_multisite()) $url = get_option('siteurl'); else $url = get_blog_option($blog_id, 'siteurl'); if ('http' != $scheme) $url = str_replace('http://', "{$scheme}://", $url); if (!empty($path) && is_string($path) && strpos($path, '..') === false) $url .= '/' . ltrim($path, '/'); return apply_filters('site_url', $url, $path, $orig_scheme, $blog_id); } } function aw_affiliatewire_quick_ignition_add_class_to_links($string, $class_name = 'awpost', $alwaysAdd = true) { $toReturn = $string; $matchString = '/([<][a][^>]*[>])/i'; $matchCount = preg_match_all($matchString, $toReturn, $matches); if (is_array($matches)) { foreach ($matches[0] as $match) { if (substr_count($match, 'class')) { if ($alwaysAdd == true) { $pos = strpos($match, 'class') + 7; $replacement = substr($match, 0, $pos) . $class_name . ' ' . substr($match, $pos); $toReturn = str_replace($match, $replacement, $toReturn); } } else { $replacement = str_replace('