"400", "max_description_rss" => "400", "rss_showIcon" => "yes", "rss_showShortDescription" => "yes", "enable_lightbox" => "yes", "excerpt_max_chars" => "55", "excerpt_moreinfo_text" => "More Info", "excerpt_moreinfo_link" => "button", "use_shortDesc_on_single" => "no", "use_shortDesc_on_atomfeed" => "no", "open_links_externally" => "no", "excerpt_generator" => "wordpress", "featured_image_generator" => "wordpress", "use_shortDesc_on_multiple" => "yes", "shortDesc_fullDesc_text" => "Show Full Description & Screenshots", "shortDesc_screenshot_text" => "Show Screenshots", "shortDesc_link" => "button", "smaller_buy_button_iOS" => "yes", "qty_of_apps" => "10", "ss_size" => "120", "currency_format" => "USD", "store_language" => "en_US", "store_continent" => "North America", "store_badge_language" => "US-UK", "appStore_store_badge_type" => "download", "appStore_store_badge_size" => "1", "iTunes_store_badge_type" => "getit", "iTunes_store_badge_size" => "1", "iBooks_store_badge_type" => "getit", "iBooks_store_badge_size" => "1", "amazon_badge_type" => "getit", "amazon_badge_size" => "1", "store_country" => "US", "appSearch_default" => "iOS", "PrePositionNumber" => "# ", "PostPositionNumber" => ") ", "full_star_color" => "blue", "empty_star_color" => "clear", "color_buttonStart" => "79bbff", "color_buttonStop" => "378de5", "color_buttonText" => "fcfc00", "color_buttonTextShadow" => "39618a", "color_buttonShadow" => "7a8da1", "color_buttonBorder" => "84bbf3", "color_buttonHoverStart" => "378de5", "color_buttonHoverStop" => "79bbff", "color_buttonHoverText" => "C9C9FF", "hide_button_background" => "no", "hide_button_background_hover" => "no", "button_corner_radius" => "16", "button_border_width" => "1", "newPost_status" => "draft", "newPost_addCategories" => "yes", "newPost_createCategories" => "yes", "newPost_defaultText" => "Read More...", "newPost_defaultTextShow" => "no", "displayapptitle" => "HIDE", "displayappdescription" => "NORM_TITLE", "displayappreleasenotes" => "NORM_TITLE", "displayappdetailssection" => "NORM_TITLE", "displayscreenshots" => "NORM_TITLE", "displaysupporteddevices" => "HIDE", "displayappicon" => "NORM_NOTITLE", "displayappiconbuybutton" => "NORM_NOTITLE", "displayappbadge" => "NORM_NOTITLE", "displaygamecenterenabled" => "NORM_NOTITLE", "displayappbuybutton" => "NORM_NOTITLE", "displaystarrating" => "NORM_NOTITLE", "displayversion" => "INLINE", "displaydevelopername" => "INLINE", "displaysellername" => "INLINE", "displayreleasedate" => "HIDE", "displayfilesize" => "HIDE", "displayprice" => "HIDE", "displayminimumOsVersion" => "INLINE", "displayuniversal" => "INLINE", "displaylanguages" => "INLINE", "displayadvisoryrating" => "INLINE", "displayappinapppurwarning" => "INLINE", "displaycategories" => "INLINE", "displaysupporteddevicesType" => "Normal", "displaympapptitle" => "HIDE", "displaympappdescription" => "NORM_TITLE", "displaympappreleasenotes" => "NORM_TITLE", "displaympappdetailssection" => "NORM_TITLE", "displaympscreenshots" => "NORM_TITLE", "displaympsupporteddevices" => "HIDE", "displaympappicon" => "NORM_NOTITLE", "displaympappiconbuybutton" => "NORM_NOTITLE", "displaympappbadge" => "NORM_NOTITLE", "displaympgamecenterenabled" => "NORM_NOTITLE", "displaympappbuybutton" => "NORM_NOTITLE", "displaympstarrating" => "NORM_NOTITLE", "displaympversion" => "INLINE", "displaympdevelopername" => "INLINE", "displaympsellername" => "INLINE", "displaympreleasedate" => "HIDE", "displaympfilesize" => "HIDE", "displaympprice" => "HIDE", "displaympminimumOsVersion" => "INLINE", "displaympuniversal" => "INLINE", "displaymplanguages" => "INLINE", "displaympadvisoryrating" => "INLINE", "displaympappinapppurwarning" => "INLINE", "displaympcategories" => "INLINE", "displaympsupporteddevicesType" => "Normal", "displayATOMapptitle" => "HIDE", "displayATOMappdescription" => "NORM_TITLE", "displayATOMappreleasenotes" => "NORM_TITLE", "displayATOMappdetailssection" => "NORM_TITLE", "displayATOMscreenshots" => "NORM_TITLE", "displayATOMsupporteddevices" => "HIDE", "displayATOMappicon" => "NORM_NOTITLE", "displayATOMappiconbuybutton" => "NORM_NOTITLE", "displayATOMappbadge" => "NORM_NOTITLE", "displayATOMgamecenterenabled" => "NORM_NOTITLE", "displayATOMappbuybutton" => "NORM_NOTITLE", "displayATOMstarrating" => "NORM_NOTITLE", "displayATOMversion" => "INLINE", "displayATOMdevelopername" => "INLINE", "displayATOMsellername" => "INLINE", "displayATOMreleasedate" => "HIDE", "displayATOMfilesize" => "HIDE", "displayATOMprice" => "HIDE", "displayATOMminimumOsVersion" => "INLINE", "displayATOMuniversal" => "INLINE", "displayATOMlanguages" => "INLINE", "displayATOMadvisoryrating" => "INLINE", "displayATOMappinapppurwarning" => "INLINE", "displayATOMcategories" => "INLINE", "displayATOMsupporteddevicesType" => "Normal", "displayATOMappPositionNumber" => "no", "displayexcerptthumbnail" => "yes", "displayexcerptreadmore" => "no", "displayappdetailsaslist" => "yes", "displayappdetailsasliststyle" => "bw", "displayappdetailsaslistssort" => "releasedate", "appicon_size_featured_h" => "256", "appicon_size_featured_w" => "256", "appicon_size_featured_c" => "0", "appicon_size_ios_h" => "256", "appicon_size_ios_w" => "256", "appicon_size_ios_c" => "0", "appicon_size_lists_h" => "128", "appicon_size_lists_w" => "128", "appicon_size_lists_c" => "0", "appicon_size_widget_h" => "32", "appicon_size_widget_w" => "32", "appicon_size_widget_c" => "0", "appicon_size_posts_h" => "128", "appicon_size_posts_w" => "128", "appicon_size_posts_c" => "0", "appicon_size_element_h" => "200", "appicon_size_element_w" => "200", "appicon_size_element_c" => "0", "appicon_size_rss_h" => "128", "appicon_size_rss_w" => "128", "appicon_size_rss_c" => "0", "appicon_size_ipadss_h" => "1024", "appicon_size_ipadss_w" => "1024", "appicon_size_ipadss_c" => "0", "appicon_size_iphoness_h" => "1024", "appicon_size_iphoness_w" => "1024", "appicon_size_iphoness_c" => "0", "appicon_size_amazon_h" => "1024", "appicon_size_amazon_w" => "1024", "appicon_size_amazon_c" => "0", "appDetailsOrder" => "appStoreDetail_appName,appStoreDetail_appIcon,appStoreDetail_appDescription,appStoreDetail_appReleaseNotes,appStoreDetail_appBadge,appStoreDetail_appDetails,appStoreDetail_appScreenshots,appStoreDetail_appDeviceList,appStoreDetail_appBuyButton,appStoreDetail_appRating,appStoreDetail_appGCIcon,appStoreDetail_appIconBuyButton", "appMPDetailsOrder" => "appStoreDetail_appName,appStoreDetail_appIcon,appStoreDetail_appDescription,appStoreDetail_appReleaseNotes,appStoreDetail_appBadge,appStoreDetail_appDetails,appStoreDetail_appScreenshots,appStoreDetail_appDeviceList,appStoreDetail_appBuyButton,appStoreDetail_appRating,appStoreDetail_appGCIcon,appStoreDetail_appIconBuyButton", "appATOMDetailsOrder" => "appStoreDetail_appName,appStoreDetail_appIcon,appStoreDetail_appBadge,appStoreDetail_appDescription,appStoreDetail_appReleaseNotes,appStoreDetail_appDetails,appStoreDetail_appScreenshots,appStoreDetail_appDeviceList,appStoreDetail_appBuyButton,appStoreDetail_appRating,appStoreDetail_appGCIcon,appStoreDetail_appIconBuyButton", "displayitunestitle" => "yes", "displayitunestrackcount" => "yes", "displayitunestracklisting" => "yes", "displayitunesartistname" => "yes", "displayitunesfromalbum" => "yes", "displayitunesgenre" => "yes", "displayitunesreleasedate" => "yes", "displayitunesdescription" => "yes", "displayitunesexplicitwarning" => "yes", "displayitunesradiolink" => "yes", "displayibookstitle" => "yes", "displayibooksauthorname" => "yes", "displayibooksgenre" => "yes", "displayibooksreleasedate" => "yes", "displayibooksdescription" => "yes", "displayibooksexplicitwarning" => "yes", "AWS_PARTNER_DOMAIN" => "com", "AWS_API_KEY" => "", "AWS_API_SECRET_KEY" => "", "AWS_ASSOCIATE_TAG" => "", "amazon_textlink_default" => "View on Amazon.com", "amazon_textlink_price_default" => "Available from Amazon.com for", "cache_time_select_box" => (24*60*60), "cache_images_locally" => "1", "affiliatepartnerid" => "999", "PHGaffiliateID" => "11l3KC", "phgCampaignvalue" => $phgCampaignvalue, "tdwebsiteID" => "", "tdprogramID" => "24369", "ResetCheckOne" => "NoWay", "ResetCheckTwo" => "NoWay", "ResetCheckThree" => "NoWay", "ResetCacheOne" => "NoWay", "ResetCacheTwo" => "NoWay", "ResetFIOne" => "NoWay", "ResetFITwo" => "NoWay", "RemoveCachedItem" => "NoWay", "RemoveCachedItemID" => "", "RemoveCachedItemASIN" => "", "displayLinkToFooter" => "no", "versionInstalled" => "7.0" ); $PostedValues = $_REQUEST; $appStore_options = $appStore_savedOptions; // Changes values from form if (isset($PostedValues['action']) && isset($PostedValues['appStore_options'])) { if($PostedValues['action'] == "update" && is_array($PostedValues['appStore_options'])) { foreach ($appStore_defaults as $defaultName => $defaultValue) { if(isset($PostedValues['appStore_options'][$defaultName])) { $appStore_options[$defaultName] = $PostedValues['appStore_options'][$defaultName]; } } } else { //Check for empty settings foreach ($appStore_defaults as $defaultName => $defaultValue) { $settingsValue = $appStore_savedOptions[$defaultName]; if($settingsValue == "") { $appStore_options[$defaultName] = $defaultValue; //echo "-----UPDATE------[$defaultName] = $defaultValue -------------"; } } } } //Check for empty settings foreach ($appStore_defaults as $defaultName => $defaultValue) { $settingsValue = $appStore_savedOptions[$defaultName]; if($settingsValue == "") { $appStore_options[$defaultName] = $defaultValue; //echo "-----UPDATE------[$defaultName] = $defaultValue -------------"; } } // Fix old language code from previous versions if($appStore_options['store_language'] == 'us') $appStore_options['store_language'] = 'en_US'; //echo "-----UPDATE------[
".print_r($PostedValues,true)."
]-------------"; update_option('appStore_options', $appStore_options); $amazonCacheTable = $wpdb->prefix . 'amazoncache'; $createSQL = "CREATE TABLE IF NOT EXISTS $amazonCacheTable (`Cache_id` int(10) NOT NULL auto_increment, `URL` text NOT NULL, `updated` datetime default NULL, `body` longtext, PRIMARY KEY (`Cache_id`), UNIQUE KEY `URL` (`URL`(255)), KEY `Updated` (`updated`)) ENGINE=MyISAM;"; $wpdb->query($createSQL); } // Init plugin options to white list our options function appStore_init(){ $settings = get_option('appStore_options'); appStore_add_defaults(); // Also checks for new settings that haven't been set before register_setting( 'appStore_plugin_options', 'appStore_options', 'appStore_validate_options' ); } // Add JQuery Functionality add_action( 'wp_ajax_test', 'asa_ajax_callback' ); add_action( 'wp_ajax_no_ppriv_test', 'asa_ajax_callback' ); function asa_ajax_callback() { check_ajax_referer( "asaAJAX-nonce" ); echo 'Hello World2!'; die('More Info'); /* if ( check_ajax_referer( 'asaAJAX', 'nonce' ) ) { //wp_die( 'Hello World' ); } else{ wp_die( 'Nonce error' ); } */ } function appStore_add_admin_scripts() { wp_enqueue_script('jquery'); wp_enqueue_script('jquery-ui-core');//enables UI wp_enqueue_script('jquery-ui-tabs'); wp_enqueue_script('jquery-ui-sortable'); wp_enqueue_script('jquery-ui-tabs'); wp_enqueue_style( 'farbtastic'); wp_enqueue_script('farbtastic'); wp_enqueue_script('jquerymenusstart', plugins_url('js_functions/jquerymenusstart.js',ASA_MAIN_FILE), null, null, true); wp_enqueue_script('jquerychained', plugins_url('js_functions/jquery.chained.js',ASA_MAIN_FILE), null, null, true); wp_enqueue_script('jscolor', plugins_url('js_functions/jscolor/jscolor.js',ASA_MAIN_FILE), null, null, true); //Used for Rebuilding Featured Images Progress Bar wp_enqueue_script( 'jquery-ui-progressbar', plugins_url( 'js_functions/jquery-ui/jquery.ui.progressbar.min.1.7.2.js', ASA_MAIN_FILE ), array( 'jquery-ui-core' ), '1.7.2' ); wp_enqueue_style( 'jquery-ui-appStore', plugins_url( 'js_functions/jquery-ui/redmond/jquery-ui-1.7.2.custom.css', ASA_MAIN_FILE ), array(), '1.7.2' ); wp_enqueue_script( 'asa-ajax', plugins_url('js_functions/asa-ajax.min.js',ASA_MAIN_FILE), array ( 'jquery' ), false, true ); $asaAJAX = array( 'nextNonce' => wp_create_nonce( 'asaAJAX-nonce' ), 'ajaxURL' => admin_url( 'admin-ajax.php' ) ); wp_localize_script( 'asa-ajax', 'asaAJAX', $asaAJAX ); } function appStore_add_admin_stylesheets() { wp_register_style('appStore-admin-styles', plugins_url( 'css/appStore-admin.css', ASA_MAIN_FILE )); wp_enqueue_style( 'appStore-admin-styles'); } // Add menus function appStore_add_options_page() { //add_options_page('AppStore Assistant', 'AppStore Assistant', 'manage_options', ASA_MAIN_FILE, 'appStore_sm_general'); add_menu_page( 'AppStore Assistant', 'AppStore Asst', 'manage_options', 'appStore_sm_general', 'appStore_displayAdminOptionsPage', plugins_url( 'images/app-store-logo.png', ASA_MAIN_FILE ) ); add_submenu_page( 'appStore_sm_general', __('General Settings','appStoreAssistant'), __('General','appStoreAssistant'), 'manage_options', 'appStore_sm_general', 'appStore_displayAdminOptionsPage'); add_submenu_page( 'appStore_sm_general', __('Visual Settings','appStoreAssistant'), __('Visual','appStoreAssistant'), 'manage_options', 'appStore_sm_visual', 'appStore_displayAdminOptionsPage'); add_submenu_page( 'appStore_sm_general', __('iOS & Mac App Store Settings','appStoreAssistant'), __('App Store','appStoreAssistant'), 'manage_options', 'appStore_sm_appstore', 'appStore_displayAdminOptionsPage'); add_submenu_page( 'appStore_sm_general', __('iTunes Store Settings','appStoreAssistant'), __('iTunes Store','appStoreAssistant'), 'manage_options', 'appStore_sm_itunes', 'appStore_displayAdminOptionsPage'); add_submenu_page( 'appStore_sm_general', __('iBooks Store Settings','appStoreAssistant'), __('iBooks Store','appStoreAssistant'), 'manage_options', 'appStore_sm_ibooks', 'appStore_displayAdminOptionsPage'); add_submenu_page( 'appStore_sm_general', __('Amazon.com Settings','appStoreAssistant'), __('Amazon.com','appStoreAssistant'), 'manage_options', 'appStore_sm_amazon', 'appStore_displayAdminOptionsPage'); add_submenu_page( 'appStore_sm_general', __('Utilities','appStoreAssistant'), __('Utilities','appStoreAssistant'), 'manage_options', 'appStore_sm_utilities', 'appStore_displayAdminOptionsPage'); add_submenu_page( 'appStore_sm_general', __('Rebuild','appStoreAssistant'), __('Rebuild','appStoreAssistant'), 'manage_options', 'appStore_sm_rebuild', 'appStore_displayAdminOptionsPage'); add_submenu_page( 'appStore_sm_general', __('Affiliate Programs','appStoreAssistant'), __('Affiliate Programs','appStoreAssistant'), 'manage_options', 'appStore_sm_affiliate', 'appStore_displayAdminOptionsPage'); add_submenu_page( 'appStore_sm_general', __('Help','appStoreAssistant'), __('Help','appStoreAssistant'), 'manage_options', 'appStore_sm_help', 'appStore_displayAdminOptionsPage'); add_menu_page( 'New ASA Items', 'New ASA Post', 'edit_posts', 'appStore_IDsearch', 'appStore_search_form', plugins_url( 'images/new-app-post.png', ASA_MAIN_FILE ) ); } function appStore_displayAdminOptionsPage() { global $requestedPage; $upload_dir = wp_upload_dir(); $options = get_option('appStore_options'); $affiliatepartnerid = $options['affiliatepartnerid']; $requestedPage = $_REQUEST['page']; $settingsUpdated = ""; if(isset($_REQUEST['settings-updated'])) $settingsUpdated = $_REQUEST['settings-updated']; if ( !current_user_can( 'manage_options' ) ) { wp_die( __( 'You do not have sufficient permissions to access this page.','appStoreAssistant' ) ); } if ( isset ( $_GET['tab'] ) ) { $currentTab = $_GET['tab']; } else { $currentTab = "defaultTab"; } switch ( $requestedPage ){ case 'appStore_sm_general' : $appStoreOptionsTitle = __('General Settings','appStoreAssistant'); $appStoreOptionsPage = "options_general_$currentTab.php"; break; case 'appStore_sm_visual' : $appStoreOptionsTitle = __('Visual Settings','appStoreAssistant'); $appStoreOptionsPage = "options_visual_$currentTab.php"; break; case 'appStore_sm_appstore' : $appStoreOptionsTitle = __('iOS & Mac App Store Settings','appStoreAssistant'); $appStoreOptionsPage = "options_appstore_$currentTab.php"; break; case 'appStore_sm_itunes' : $appStoreOptionsTitle = __('iTunes Store Settings','appStoreAssistant'); $appStoreOptionsPage = "options_itunes_$currentTab.php"; break; case 'appStore_sm_ibooks' : $appStoreOptionsTitle = __('iBooks Store Settings','appStoreAssistant'); $appStoreOptionsPage = "options_ibooks_$currentTab.php"; break; case 'appStore_sm_amazon' : $appStoreOptionsTitle = __('Amazon.com Settings','appStoreAssistant'); $appStoreOptionsPage = "options_amazon_$currentTab.php"; break; case 'appStore_sm_utilities' : $appStoreOptionsTitle = __('Utilities','appStoreAssistant'); $appStoreOptionsPage = "options_utils_$currentTab.php"; break; case 'appStore_sm_rebuild' : $appStoreOptionsTitle = __('Rebuild','appStoreAssistant'); $appStoreOptionsPage = "options_rebuild_$currentTab.php"; break; case 'appStore_sm_help' : $appStoreOptionsTitle = __('Help Page','appStoreAssistant'); $appStoreOptionsPage = "options_help_$currentTab.php"; break; case 'appStore_sm_affiliate' : $appStoreOptionsTitle = __('Affiliate Programs','appStoreAssistant'); $appStoreOptionsPage = "options_affiliate_$currentTab.php"; break; } if($options['ResetCheckOne']=="DoIt" && $options['ResetCheckTwo']=="DoIt" && $options['ResetCheckThree']=="DoIt") { appStore_add_defaults(); $OptionsReset = true; $options = get_option('appStore_options'); $options["ResetCheckOne"] = "NoWay"; $options["ResetCheckTwo"] = "NoWay"; $options["ResetCheckThree"] = "NoWay"; update_option('appStore_options', $options); appStore_ShowMessage( __('All settings have been reset to their defaults!','appStoreAssistant'),false); } if($options['AddFeaturedImages']=="DoIt" ) { $options["AddFeaturedImages"] = "NoWay"; update_option('appStore_options', $options); if(appStore_setting('cache_images_locally') != '1') { $options = get_option('appStore_options'); appStore_ShowMessage(__('Cache MUST be ENABLED for this function to work!','appStoreAssistant'),true); } else { $MyResults = appStore_get_shortcode_posts(); $postCounter = 1; foreach($MyResults as $MyResult) { //echo $postCounter.') ------------------------------
'; appStore_addFeaturedImages($MyResult); $postCounter++; if($postCounter >20) break; //SEALDEBUG } $options = get_option('appStore_options'); appStore_ShowMessage(__('We did it!','appStoreAssistant'),false); } } if($options['RemoveCachedItem']=="DoIt" ) { $appIDtoRemove = $options["RemoveCachedItemID"]; $asinToRemove = $options["RemoveCachedItemASIN"]; $options["RemoveCachedItem"] = "NoWay"; $options["RemoveCachedItemID"] = "EMPTY"; $options["RemoveCachedItemASIN"] = "EMPTY"; update_option('appStore_options', $options); $returnMessage = appStore_ClearSpecificItemCache($appIDtoRemove,$asinToRemove); appStore_ShowMessage($returnMessage,true); } if($options['ResetCacheOne']=="DoIt" && $options['ResetCacheTwo']=="DoIt") { appStore_ClearAppCache(); $options = get_option('appStore_options'); $options["ResetCacheOne"] = "NoWay"; $options["ResetCacheTwo"] = "NoWay"; update_option('appStore_options', $options); appStore_ShowMessage(__('The App data cache has been cleared!','appStoreAssistant'),true); } if($options['ResetFIOne']=="DoIt" && $options['ResetFITwo']=="DoIt") { $options = get_option('appStore_options'); $options["ResetFIOne"] = "NoWay"; $options["ResetFITwo"] = "NoWay"; update_option('appStore_options', $options); appStore_ClearFeaturedImages(); } echo ''; echo '
'; echo "

AppStore Assistant $appStoreOptionsTitle

"; echo '

'.__('Below is a collection of controls you can use to customize the App Store Assistant plugin','appStoreAssistant').'.

'; //echo "
--------------------".appStore_setting('validated')."----------------------
"; appStore_checkCacheFolder(); if($settingsUpdated) appStore_ShowMessage(__("Settings Updated!",'appStoreAssistant'),false); appStore_displayAdminTabs($requestedPage,$currentTab,$affiliatepartnerid); echo '
'; settings_fields('appStore_plugin_options'); $showSaveChangesButton = true; require_once(ASA_PLUGIN_INCLUDES_PATH."options_pages/$appStoreOptionsPage"); if($showSaveChangesButton) { echo '

'; echo ''; echo '

'; } echo '
'; require_once(ASA_PLUGIN_INCLUDES_PATH."donateform.inc"); return; } function appStore_checkForSpecialTabs($page) { if ($page == "appStore_sm_rebuild" || $page == "asa-rebuild-featuredimages" || $page == "asa-add-missingcats") { return true; } else { return false; } } function appStore_displayAdminTabs( $tabSet,$currentTab = 'defaultTab',$affiliatepartnerid ) { global $requestedPage; switch ( $tabSet ){ case 'appStore_sm_general' : $tabs_array = array ( 'defaultTab' => __('Main','appStoreAssistant'), 'descriptions' => __('Descriptions','appStoreAssistant'), 'excerpts' => __('Excerpts','appStoreAssistant'), 'createpost' => __('Create Posts','appStoreAssistant'), 'miscellaneous' => __('Miscellaneous','appStoreAssistant') ); break; case 'appStore_sm_visual' : $tabs_array = array ( 'defaultTab' => __('Ratings','appStoreAssistant'), 'imagesizes' => __('Image Sizes','appStoreAssistant'), 'buybutton' => __('Buy Button','appStoreAssistant'), 'miscellaneous' => __('Miscellaneous','appStoreAssistant') ); break; case 'appStore_sm_appstore' : $tabs_array = array ( 'defaultTab' => __('Single Post','appStoreAssistant'), 'multipost' => __('Multiple Posts','appStoreAssistant'), 'atomfeed' => __('List/Atom Feed','appStoreAssistant'), 'graphics' => __('App Store Graphics','appStoreAssistant') ); break; case 'appStore_sm_itunes' : //$tabs_array = array ('defaultTab' => 'Single Post','multipost' => 'Multiple Post','graphics' => 'App Store Graphics'); $tabs_array = array ( 'defaultTab' => __('Single Post','appStoreAssistant'), 'graphics' => __('iTunes Store Graphics','appStoreAssistant') ); break; case 'appStore_sm_ibooks' : $tabs_array = array ( 'defaultTab' => __('Single Post','appStoreAssistant'), 'graphics' => __('iBooks Store Graphics','appStoreAssistant') ); break; case 'appStore_sm_amazon' : $tabs_array = array ( 'defaultTab' => __('Text Link Defaults','appStoreAssistant'), 'graphics' => __('Amazon.com Graphics','appStoreAssistant') ); break; case 'appStore_sm_utilities' : $tabs_array = array ( 'defaultTab' => __('Clear an Item','appStoreAssistant'), 'clearcache' => __('Clear Cache','appStoreAssistant'), 'remove_featured' => __('Remove Featured','appStoreAssistant'), 'reset' => __('Reset Defaults','appStoreAssistant'), 'beta' => __('Beta Utilities','appStoreAssistant') ); break; case 'appStore_sm_help' : $tabs_array = array ( 'defaultTab' => __('Getting Started','appStoreAssistant'), 'shortcodes' => __('Shortcodes','appStoreAssistant'), 'editor' => __('Post Editor','appStoreAssistant'), 'amazon' => __('Amazon.com','appStoreAssistant') ); break; case 'appStore_sm_affiliate' : $tabs_start = array ( 'defaultTab' => __('Amazon.com','appStoreAssistant') ); switch ( $affiliatepartnerid ){ case '999' : //$tabs_end = array ('affiliate' => 'LinkShare'); break; case '2003' : $tabs_end = array ('td' => 'TradeDoubler'); break; case '2013' : $tabs_end = array ('phg' => 'PHG'); break; } $tabs_array = $tabs_start; if(isset($tabs_end)){ if(is_array($tabs_end)) $tabs_array = array_merge($tabs_start, $tabs_end); } break; } if(appStore_checkForSpecialTabs($tabSet)) $tabs_array = array ( 'asa-rebuild-featuredimages' => __('Featured Images','appStoreAssistant'), 'asa-add-missingcats' => __('Categories','appStoreAssistant') ); echo ''; } function appStore_createPostFromAppID($appShortCode,$appTitle,$appCategories,$appID) { global $current_user; get_currentuserinfo(); if(appStore_setting('newPost_status')=="") { $postStatus = "draft"; } else { $postStatus = appStore_setting('newPost_status'); } $my_post = array( 'post_title' => $appTitle, 'post_content' => $appShortCode, 'post_author' => $current_user->ID, 'post_status' => $postStatus, 'post_type' => 'post', ); $newPostID = wp_insert_post( $my_post ); echo '

'.__('Creating Post...','appStoreAssistant').'

'; if(appStore_setting('newPost_addCategories')=="yes") { $appCategories = explode(",",$appCategories); foreach($appCategories as $appCategory) { $term_id = term_exists( $appCategory, 'category' ); if(is_array($term_id)) { $postCategories[] = $term_id['term_id']; $postCategoriesList[] = $appCategory; } elseif(appStore_setting('newPost_addCategories')=="yes") { $postCategoriesList[] = $appCategory.' (NEW)'; $newCategoryID = wp_create_category($appCategory); if($newCategoryID) $postCategories[] = $newCategoryID; } } wp_set_post_terms( $newPostID, $postCategories, 'category',false); } echo '

'.__('Caching App data...','appStoreAssistant').'

'; $appData = appStore_get_data( $appID ); echo '

'.__('Finding Default Featured Image...','appStoreAssistant').'

'; $filename = $appData->imageFeatured_path; if(appStore_setting('cache_images_locally')=="1") { $urlToFeaturedImage = $appData->imageFeatured_cached; } else { $urlToFeaturedImage = $appData->imageFeatured; } echo '

'.__('Saving Default Featured Image...','appStoreAssistant').'

'; $wp_filetype = wp_check_filetype(basename($filename), null ); $wp_upload_dir = wp_upload_dir(); if (!is_writable($wp_upload_dir['path'])) { echo '

' .$wp_upload_dir['path'].' '.__('must be writable!!!','appStoreAssistant').'

'; return; } if(appStore_addFeaturedImageToPost ($urlToFeaturedImage,$newPostID,$appID)){ echo '

'.__('Featured Image saved to Post','appStoreAssistant').'

'; } else { echo '

'.__('Featured Image cound not be saved to Post','appStoreAssistant').' ['.$urlToFeaturedImage.']

'; } echo '
'; if($newPostID) { echo "

"; _e('Your','appStoreAssistant'); echo ' '.$postStatus.' '; _e('POST has been created for','appStoreAssistant'); echo " $appTitle!

"; echo ''; _e('Click here to edit the new post','appStoreAssistant'); echo '.

'; if(is_array($postCategoriesList)) { if(count($postCategoriesList) > 1) { _e('In the following categories:','appStoreAssistant'); echo "
"; foreach($postCategoriesList as $category) echo "       $category
"; } else { _e('In the following category:','appStoreAssistant'); echo " "; echo "       ".$postCategoriesList[0]."
"; } } } else { _e('There was an error creating your post for','appStoreAssistant')." $appTitle!"; } echo "

"; } function appStore_addFeaturedImageToPost ($fi_url,$parent_post_id,$appID="App") { if(empty($fi_url)) return false; $desc = 'Featured Image '.$parent_post_id."-".$appID."-".date("U"); echo '

'.__('Featured Image URL','appStoreAssistant').': '.$fi_url.'

'; $tmp = download_url( $fi_url ); //preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $thumb_url, $matches); $file_array['name'] = "FI_".$appID."_".basename($fi_url); $file_array['tmp_name'] = $tmp; if ( is_wp_error( $tmp ) ) { @unlink($file_array['tmp_name']); $file_array['tmp_name'] = ''; $error_string = $tmp->get_error_message(); echo '

'.__('Featured Image File','appStoreAssistant').' ' . $error_string . '

'; return false; } // do the validation and storage stuff $thumbid = media_handle_sideload( $file_array, $parent_post_id, $desc ); // If error storing permanently, unlink if ( is_wp_error($thumbid) ) { @unlink($file_array['tmp_name']); echo ''.sprintf( __( 'Error: storing permanently, unlink %s.', 'appStoreAssistant' ),''.$wp_upload_dir['path'].'' ).''; $error_string = $thumbid->get_error_message(); echo '

' . $error_string . '

'; return false; } $setPostFI = set_post_thumbnail( $parent_post_id, $thumbid ); if ( is_wp_error($setPostFI) ) { $error_string = $setPostFI->get_error_message(); echo '

' . $error_string . '

'; return false; } echo '

'.__('Featured Image Set','appStoreAssistant').': '.$desc.'

'; return true; } function appStore_CreateListOfAppsUsedInPosts() { $MyResults = appStore_get_shortcode_posts(); $postCounter = 1; $arrayOfIDs['ASA'][] = "000000000"; $arrayOfIDs['iOS'][] = "000000000"; $arrayOfIDs['iTunes'][] = "000000000"; $arrayOfIDs['Amazon'][] = "000000000"; foreach($MyResults as $MyResult) { preg_match_all('/asa_item\ id=\"([^\"]*?)\"/', $MyResult->post_content, $asa_matches); preg_match_all('/_app\ id=\"([^\"]*?)\"/', $MyResult->post_content, $app_matches); preg_match_all('/itunes_store\ id=\"([^\"]*?)\"/', $MyResult->post_content, $iTunes_matches); preg_match_all('/amazon_item\ asin=\"([^\"]*?)\"/', $MyResult->post_content, $amazon_matches); if(isset($asa_matches[1][0])) $arrayOfIDs['ASA'][] = $asa_matches[1][0]; if(isset($app_matches[1][0])) $arrayOfIDs['iOS'][] = $app_matches[1][0]; if(isset($iTunes_matches[1][0])) $arrayOfIDs['iTunes'][] = $iTunes_matches[1][0]; if(isset($amazon_matches[1][0])) $arrayOfIDs['Amazon'][] = $amazon_matches[1][0]; //appStore_addFeaturedImages($MyResult); $postCounter++; } //echo "
------RESULT-----[
".print_r($arrayOfIDs,true)."
]-------------
"; return $arrayOfIDs; } function appStore_buildListOfFoundApps($listOfApps,$startKey,$shortCodeStart,$type){ GLOBAL $masterList,$checkForDuplicates; $i = $startKey; $listOfAlreadyAddedIDs = appStore_CreateListOfAppsUsedInPosts(); $listOfAlreadyAddediOSIDs = array_merge($listOfAlreadyAddedIDs['ASA'],$listOfAlreadyAddedIDs['iOS']); foreach ($listOfApps as $appData) { $masterList[$i] = ''; $item_Price = ''; $count = count(get_object_vars($appData)); echo '";//Debug // Get Data appropriate for item type if(isset($appData->wrapperType )) { switch ( $appData->wrapperType ){ case 'collection' : $item_Name = $appData->collectionName; $item_ID = $appData->collectionId; $item_Categories = $appData->primaryGenreName; $item_By = $appData->artistName; if (isset ($appData->collectionPrice)) $item_Price = appStore_format_price($appData->collectionPrice); $item_Version = ''; $item_TypeDescription = 'Album'; break; case 'track' : $item_Name = $appData->trackName; $item_ID = $appData->trackId; $item_Categories = $appData->primaryGenreName; $item_By = $appData->artistName; if (isset ($appData->trackPrice)) $item_Price = appStore_format_price($appData->trackPrice); if (isset ($appData->trackHdPrice)) $item_Price .= '(HD: '.appStore_format_price($appData->trackHdPrice).')'; $item_Version = ''; $item_TypeDescription = 'Item'; break; case 'audiobook' : $item_Name = $appData->collectionName; $item_ID = $appData->collectionId; $item_Categories = $appData->primaryGenreName; $item_By = $appData->artistName; if (isset ($appData->collectionPrice)) $item_Price = appStore_format_price($appData->collectionPrice); $item_Version = ''; $item_TypeDescription = 'Audiobook'; break; case 'software' : $item_Name = $appData->trackName; $item_ID = $appData->trackId; $item_Categories = $appData->genres; $item_By = $appData->artistName."/".$appData->sellerName; $item_Price = appStore_format_price($appData->price); $item_Version = ' ('.$appData->version.')'; $item_TypeDescription = 'App'; break; } } switch ( $appData->kind ){ case 'ebook' : $item_Name = $appData->trackName; $item_ID = $appData->trackId; $item_Categories = $appData->genres; $item_By = $appData->artistName; if (isset ($appData->price)) $item_Price = appStore_format_price($appData->price); $item_Version = ''; $item_TypeDescription = 'eBook'; break; } if (!array_search($item_ID, $checkForDuplicates) && $count > 10) { if(is_array($item_Categories)) { $Categories = implode(", ", $item_Categories); $CategoriesNS = implode(",", $item_Categories); } else { if(isset($item_Categories)) { $Categories = $item_Categories; $CategoriesNS = $item_Categories; } else { $Categories = "Unknown"; $CategoriesNS = "Unknown"; } } $theShortCode = $shortCodeStart.' id="'.$item_ID.'"'; if(appStore_setting('newPost_defaultTextShow') == "yes") $theShortCode .= ' more_info_text="'.appStore_setting('newPost_defaultText').'"'; $theShortCode .= ']'; $masterList[$i] .= "
  • artworkUrl60."\")'>"; $masterList[$i] .= '

    '; $masterList[$i] .= ""; $masterList[$i] .= $item_Name; $masterList[$i] .= ""; $masterList[$i] .= $item_Version."
    "; $masterList[$i] .= " by ".$item_By."
    "; $masterList[$i] .= " [".$item_Price."] "; $masterList[$i] .= " [".$Categories."] "; if($startKey == "2") $masterList[$i] .= " [".__('iPad only','appStoreAssistant')."]"; $masterList[$i] .= "

    "; $masterList[$i] .= ''; //$masterList[$i] .= ''; $masterList[$i] .= ''; $masterList[$i] .= ''; $masterList[$i] .= ''; $masterList[$i] .= ''; $masterList[$i] .= ''; if (is_array($listOfAlreadyAddediOSIDs)) { if (in_array($item_ID, $listOfAlreadyAddediOSIDs)) { $masterList[$i] .= '
    '.__('You have already added this item.','appStoreAssistant').''; } else { $string = __('Create Post for this ','appStoreAssistant').$item_TypeDescription; $masterList[$i] .= '
    '; } } $masterList[$i] .= "

    "; $masterList[$i] .= '
  • '."\r\n\r\n"; } $checkForDuplicates[] = $item_ID; $i = $i + 2; } } function appStore_getSearchResultsFromApple($entity){ $url = "https://itunes.apple.com/search?term="; $url .= urlencode($_POST['appname'])."&country=us&entity=$entity"; //echo $url; //Debug $contents = file_get_contents($url); //$contents = utf8_encode($contents); $foundApps = json_decode($contents); $listOfApps = $foundApps->results; return $listOfApps; } function appStore_search_form() { GLOBAL $masterList,$checkForDuplicates; echo '

    '; echo '

    '.__('Find an item from iTunes or an App from the App Store or Mac App Store','appStoreAssistant').'

    '; echo '

    '.__('This will generate a shortcode that you can paste into your POST. You will also have the option to auto-create a post which will include a Featured Image, Item Title, Shortcode and Categories. After creation, you will be given a link to edit the post.','appStoreAssistant').'

    '; $searchType = '';$SearchTerm=''; if (!empty($_POST)) { $postType = $_POST['type']; if(isset($_POST['appname'])) if(is_numeric($_POST['appname'])) $postType = "byID"; switch ($postType) { case "iPhone": $Searchtype = __('iPhone/iPod Software','appStoreAssistant'); $shortCodeStart = "[asa_item"; $entity = "software"; $searchType = "iPhone"; break; case "iOS": $Searchtype = __('All iOS Software','appStoreAssistant'); $shortCodeStart = "[asa_item"; $entity = "software"; $searchType = "iOS"; break; case "iPad": $Searchtype = __('iPad Software','appStoreAssistant'); $shortCodeStart = "[asa_item"; $entity = "iPadSoftware"; $searchType = "iPad"; break; case "Mac": $Searchtype = __('Macintosh Software','appStoreAssistant'); $shortCodeStart = "[asa_item"; $entity = "macSoftware"; $searchType = "Mac"; break; case "iTunes-Album": $Searchtype = __('iTunes Album','appStoreAssistant'); $shortCodeStart = "[asa_item"; $entity = "album"; $searchType = "iTunes-Album"; break; case "iTunes-TV": $Searchtype = __('iTunes TV Show','appStoreAssistant'); $shortCodeStart = "[asa_item"; $entity = "tvSeason"; $searchType = "iTunes-TV"; break; case "iTunes-Movie": $Searchtype = __('iTunes Movie','appStoreAssistant'); $shortCodeStart = "[asa_item"; $entity = "movie"; $searchType = "iTunes-Movie"; break; case "iTunes-Podcast": $Searchtype = __('iTunes Podcast','appStoreAssistant'); $shortCodeStart = "[asa_item"; $entity = "podcast"; $searchType = "iTunes-Podcast"; break; case "iTunes-Audiobook": $Searchtype = __('iTunes Audiobook','appStoreAssistant'); $shortCodeStart = "[asa_item"; $entity = "audiobook"; $searchType = "iTunes-Audiobook"; break; case "iTunes-eBook": $Searchtype = __('iTunes eBook','appStoreAssistant'); $shortCodeStart = "[asa_item"; $entity = "ebook"; $searchType = "iTunes-eBook"; break; case "byID": $Searchtype = __('Item by ID','appStoreAssistant'); $shortCodeStart = "[asa_item"; $entity = "software"; break; default: $Searchtype = __('iPhone/iPod Software','appStoreAssistant'); $shortCodeStart = "[asa_item"; $entity = "software"; } if (isset($_POST['appname'])) $SearchTerm = $_POST['appname']; if(!empty($_POST['createPost'])) { appStore_createPostFromAppID($_POST['shortcode'],$_POST['postTitle'],$_POST['postCategories'],$_POST['appID']); } } else { $SearchTerm = ""; } appStore_displaySearchForm($searchType,$SearchTerm); if (!empty($_POST['asaSearch'])) { $checkForDuplicates[] = "000000000"; //Setup array for later use if($postType == "byID") { $listOfApps[0] = appStore_get_data( intval($_POST['appname'])); } else { $listOfApps = appStore_getSearchResultsFromApple($entity); } //print_r($listOfApps); //Debug appStore_buildListOfFoundApps($listOfApps,"1",$shortCodeStart,$_POST['type']); if($_POST['type'] == "iOS") { $biggerListOfApps = appStore_getSearchResultsFromApple("iPadSoftware"); appStore_buildListOfFoundApps($biggerListOfApps,"2",$shortCodeStart,$_POST['type']); } if(is_array($masterList)){ echo "

    $Searchtype

    "; echo '
    '; echo ''; echo "
    "; } else { $string = sprintf( __('No %d Results Found!', 'plugin-domain'), $Searchtype ); echo "

    $string

    "; } echo '
     
    '; } } //------------------------------TEST----------------------------------------------- function appStore_get_shortcode_posts() { add_filter( 'posts_where', 'appStore_shortcode_query_filter' ); $posts = get_posts( array( 'posts_per_page' => 1550, 'post_status' => 'any' ) ); remove_filter( 'posts_where', 'appStore_shortcode_query_filter' ); return $posts; } function appStore_addFeaturedImages ($postData) { $newPostID = $postData->ID; if(!$newPostID) { echo ''.__('Skipping','appStoreAssistant').': '.__('No Post ID Found','appStoreAssistant').'
    '; return; } else { //echo "Post ID Found
    "; } if(has_post_thumbnail( $newPostID )) { //$returnData = 'Skipping ('.$newPostID.'): Post Already has Featured Image
    '; return; } else { echo "
    ".__('No Featured Image Found','appStoreAssistant')."
    "; } $postContent = $postData->post_content; //$postContent = '[asa_item id="443987910" more_info_text="Read More..."] '; $appOldIDs = preg_match_all('/_app\ id=\"([^\"]*?)\"/', $postContent, $appOld_matches); $appIDs = preg_match_all('/asa_item\ id=\"([^\"]*?)\"/', $postContent, $app_matches); $applinks = preg_match_all('/_app\ link=\"([^\"]*?)\"/', $postContent, $applink_matches); $iTunesIDs = preg_match_all('/itunes_store\ id=\"([^\"]*?)\"/', $postContent, $iTunes_matches); $amazonIDs = preg_match_all('/amazon_item\ asin=\"([^\"]*?)\"/', $postContent, $amazon_matches); //echo $postData->post_content."
    "; if(!$appIDs && !$amazonIDs && !$iTunesIDs && !$applinks && !$appOldIDs) { echo 'Skipping: '.__('No App IDs or Amazon ASINs found for post','appStoreAssistant').' ('.$newPostID.')
    '; //print_r($app_matches); //DEBUG echo "[$appIDs][".$postContent."]"; return; } $postTitle = $postData->post_title; if(!$postTitle) { echo ''.__('Error','appStoreAssistant').': '.__('No Post Title Found for post','appStoreAssistant').' ('.$newPostID.')
    '; return; } else { echo __('Post Title Found','appStoreAssistant').' ('.$postTitle.')
    '; } $shortcodeData = ""; if($appIDs || $iTunesIDs || $applinks || $appOldIDs) { if($iTunesIDs) { $matchesToCheck = $iTunes_matches; echo __('iTunes IDs Found','appStoreAssistant')."
    "; foreach ($matchesToCheck[1] as $shortcodeID) { $shortcodeData[] = $shortcodeID; } } if($applinks) { $matchesToCheck = $applink_matches; echo __('App ID via Link Found','appStoreAssistant')."
    "; foreach ($matchesToCheck[1] as $link) { $pattern = '(id[0-9]+)'; preg_match($pattern, $link, $matches, PREG_OFFSET_CAPTURE, 3); $appIDs = substr($matches[0][0], 2); $shortcodeData[] = $appIDs; } } if($appIDs) { $matchesToCheck = $app_matches; echo __('App IDs Found','appStoreAssistant')."
    "; foreach ($matchesToCheck[1] as $shortcodeID) { $shortcodeData[] = $shortcodeID; } } if($appOldIDs) { $matchesToCheck = $appOld_matches; echo __('App IDs Found','appStoreAssistant')."
    "; foreach ($matchesToCheck[1] as $shortcodeID) { $shortcodeData[] = $shortcodeID; } } $appID = $shortcodeData[0]; echo __('First App ID Found','appStoreAssistant')." ($appID)
    "; $app_data=appStore_get_data( $appID ); if(!is_array($app_data) && !is_object($app_data)) { echo ''.__('Error','appStoreAssistant').': '.__('Could Not Cache Data for App ID','appStoreAssistant').' '.$appID.'
    '; return; } else { echo __('Caching App data for','appStoreAssistant').' ('.$newPostID.') - '.$postTitle.'...
    '; } $filename = $app_data->imageFeatured_path; //echo "[[[[".print_r($app_data,true)."]]]]]"; } elseif($amazonIDs) { echo __("Amazon ASINs Found",'appStoreAssistant')."
    "; foreach ($amazon_matches[1] as $shortcodeID) { $shortcodeData[] = $shortcodeID; } $asin = $shortcodeData[0]; echo __("First Amazon ASIN Found",'appStoreAssistant')." ($asin)
    "; $AmazonProductData = appStore_get_amazonData($asin); $filename = CACHE_DIRECTORY.$AmazonProductData['imageFeatured']; } else { echo ''.__('Error','appStoreAssistant').': '.__('Could Not Process Featured Image URL for Post','appStoreAssistant').' ('.$newPostID.')
    '; } if(!$filename) { echo ''.__('Error','appStoreAssistant').': '.__('No Featured Images found for App ID','appStoreAssistant').' '.$appID.'
    - - '.__('Images may be missing or in the wrong format.','appStoreAssistant'); return; } else { _e('Featured Image Found','appStoreAssistant'); echo "
    $filename
    "; } $wp_filetype = wp_check_filetype(basename($filename), null ); $wp_upload_dir = wp_upload_dir(); $attachment = array( 'guid' => $wp_upload_dir['url'] . '/' . basename( $filename ), 'post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)), 'post_content' => '', 'post_status' => 'inherit' ); $attachment_id = wp_insert_attachment( $attachment, $filename, $newPostID ); echo "Created Attachment ID: $attachment_id
    "; update_post_meta($newPostID, '_thumbnail_id', $attachment_id); echo "
    "; return; } function appStore_checkCacheFolder() { $upload_dir = wp_upload_dir(); $appStore_cacheFolder = $upload_dir['basedir'] . '/appstoreassistant_cache'; echo "
      "; if(@is_dir($upload_dir['basedir'])) { if(!@is_writable(stripslashes($upload_dir['basedir']))) { echo '
    1. '; _e('The Uploads folder is not WRITABLE. Please CHMOD the folder ','appStoreAssistant'); echo ''.WP_CONTENT_DIR."/uploads/".''; echo " to '777'.
      "; _e('Images will not load without this folder, if you have "Cache Images Locally" turned on.','appStoreAssistant'); echo '
      '; echo '
    2. '; } else { if(!is_dir($upload_dir['basedir'] . '/appstoreassistant_cache/')) { if(!mkdir($upload_dir['basedir'] . '/appstoreassistant_cache/', 0755, true)) { appStore_set_setting('cache_images_locally', '0'); } else { echo '
    3. '; _e('The Cache folder ','appStoreAssistant'); echo ''.WP_CONTENT_DIR."/uploads/appstoreassistant_cache"; _e(' has been created successfully!','appStoreAssistant'); echo ''; echo '
    4. '; } } } } else { echo '
    5. '; _e('The Cache folder does NOT exist. Please create ','appStoreAssistant'); echo ''.WP_CONTENT_DIR."/uploads".''; _e(' folder and CHMOD it to "777"','appStoreAssistant').".
      "; _e('Images will not load without this folder, if you have "Cache Images Locally" turned on.','appStoreAssistant'); echo '
      '; echo '
    6. '; } if(@is_dir($appStore_cacheFolder)) { if(!@is_writable(stripslashes($appStore_cacheFolder))) { echo '
    7. '; _e('The Cache folder is not WRITABLE. Please CHMOD the folder','appStoreAssistant')." "; echo ''.WP_CONTENT_DIR."/uploads/appstoreassistant_cache".''; echo " to '777'.
      "; _e('Images will not load without this folder, if you have "Cache Images Locally" turned on.','appStoreAssistant'); echo '
      '; echo '
    8. '; } } else { echo '
    9. '; _e( "The Cache folder does NOT exist. Please create ",'appStoreAssistant'); echo ''."'appstoreassistant_cache'".''; _e( " folder in ",'appStoreAssistant'); echo ''.WP_CONTENT_DIR."/uploads".''; _e(' folder and CHMOD it to "777"','appStoreAssistant').'.
      '; _e('Images will not load without this folder, if you have "Cache Images Locally" turned on.','appStoreAssistant'); echo '
      '; echo '
    10. '; } echo '
    '; } function requires_wordpress_version() { global $wp_version; $plugin = plugin_basename( ASA_MAIN_FILE ); $plugin_data = get_plugin_data( ASA_MAIN_FILE, false ); if ( version_compare($wp_version, "3.6", "<" ) ) { if( is_plugin_active($plugin) ) { deactivate_plugins( $plugin ); wp_die( "'".$plugin_data['Name']."' requires WordPress 3.6 or higher, and has been deactivated! Please upgrade WordPress and try again.

    (Older installations please use version 6.2.1)

    Back to WordPress admin." ); } } } // Display a Settings link on the main Plugins page function appStore_plugin_action_links( $links, $file ) { if ( $file == plugin_basename( ASA_MAIN_FILE ) ) { $appStore_links = ''.__('Settings','appStoreAssistant').''; // make the 'Settings' link appear first array_unshift( $links, $appStore_links ); } return $links; } // Sanitize and validate input. Accepts an array, return a sanitized array. function appStore_validate_options($input) { $options = get_option('appStore_options'); if(isset($input['checkboxedoptions'])) { $checkboxedoptions = explode(",", $input['checkboxedoptions']); foreach($checkboxedoptions as $checkboxedoption) { $options[$checkboxedoption] = "no"; } } if(isset($input['textboxoptions'])) { $textboxoptions = explode(",", $input['textboxoptions']); foreach($textboxoptions as $textboxoption) { $options[$textboxoption] = "EMP"; } } foreach( $input as $optionName => $optionValue ){ if($optionValue != "") $options[$optionName] = $optionValue; } //print_r($options); $options['validated'] = _x('You Betcha!', 'a positive acknowledgment','appStoreAssistant').' - '.date('r'); return $options; } function appStore_ClearSpecificItemCache($appIDtoRemove,$asinToRemove) { global $wpdb; $upload_dir = wp_upload_dir(); //Clear AppStore Cache $appID_option = "appStore_appData_".$appIDtoRemove; $asin_option = "appStore_amazonData_".$asinToRemove; $returnMessage = __('Processing IDs','appStoreAssistant').'
    '; if(strlen($appID_option) > 22){ if( get_option($appID_option)) { $returnMessage .= "App ID $appIDtoRemove Found.
    "; if(delete_option( $appID_option)) $returnMessage .= __('App ID Cache data cleared','appStoreAssistant').'.
    '; rrmdir(CACHE_DIRECTORY."AppStore/".$appIDtoRemove); $returnMessage .= __('App ID Cache folder deleted','appStoreAssistant').'.
    '; } else { $returnMessage .= sprintf(__('App ID %s Not Found','appStoreAssistant'), $appIDtoRemove).'.
    '; } } if(strlen($asin_option) > 26){ if(get_option($asin_option)) { $returnMessage .= sprintf(__('Amazon ASIN %s Found','appStoreAssistant'), $asinToRemove).'
    '; if(delete_option( $asin_option)) $returnMessage .= __('Amazon ASIN Cache data cleared','appStoreAssistant').'.
    '; rrmdir(CACHE_DIRECTORY."Amazon/".$asinToRemove); $returnMessage .= __('Amazon ASIN Cache folder deleted','appStoreAssistant').'.
    '; } else { $returnMessage .= sprintf(__('Amazon ASIN %s Not Found','appStoreAssistant'),$asinToRemove).'.
    '; } } return $returnMessage; } function appStore_ClearFeaturedImages() { $args = array( 'post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => 'any', 'post_parent' => null ); $attachments = (array) get_posts( $args ); foreach($attachments as $key => $attachmentData) { $postID = $attachmentData->ID; $validFI = FALSE; if(preg_match('/featured-image/i',$attachmentData->post_name,$matches)) $validFI = TRUE; if(preg_match('/appstoreassistant_cache/i',$attachmentData->guid,$matches)) $validFI = TRUE; if(preg_match('/asaArtwork_/i',$attachmentData->guid,$matches)) $validFI = TRUE; if(preg_match('/artworkUrl/i',$attachmentData->post_title,$matches)) $validFI = TRUE; if(preg_match('/artworkOriginal_/i',$attachmentData->post_title,$matches)) $validFI = TRUE; if(preg_match('/artworkUrl/i',$attachmentData->post_name,$matches)) $validFI = TRUE; if($validFI) { echo "DEBUG: [$key] VALID for Post ID:".$postID."
    "; if(wp_delete_post($postID)) { echo "[$key] Featured Imaged ID:$postID has been moved to trash.
    "; } else { echo "[$key] Error removing Featured Imaged ID:$postID!
    "; } } else { echo "DEBUG: [$key] NOT an ASA generated Featured Image (".$postID.")
    - - - - - ".$attachmentData->post_title." - - - - - ".$attachmentData->post_name.""; } } return; } function appStore_ClearAppCache() { global $wpdb; $upload_dir = wp_upload_dir(); //Clear AppStore Cache $options = $wpdb->get_results( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE 'appStore_appData_%'"); if ( is_null($options) ) return false; foreach( $options as $option ) { delete_option( $option->option_name ); } //Clear ATOM Feed Cache $options = $wpdb->get_results( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE 'appStore_rssfeed_%'"); if ( is_null($options) ) return false; foreach( $options as $option ) { delete_option( $option->option_name ); } //Clear Amazon Cache $options = $wpdb->get_results( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE 'appStore_amazonData_%'"); if ( is_null($options) ) return false; foreach( $options as $option ) { delete_option( $option->option_name ); } //Remove Cache Directory rrmdir(CACHE_DIRECTORY); } function rrmdir($dir) { if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $object) { if ($object != "." && $object != "..") { if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object); } } reset($objects); rmdir($dir); } } function appStore_ShowMessage($message, $errormsg = false) { if ($errormsg) { echo '
    '; } else { echo '
    '; } echo "

    $message

    "; } //Setting Field Functions function setting_string_fn() { $options = get_option('plugin_options'); echo ""; } function setting_dropdown_fn() { $options = get_option('plugin_options'); $items = array("Red", "Green", "Blue", "Orange", "White", "Violet", "Yellow"); echo ""; } function setting_textarea_fn() { $options = get_option('plugin_options'); echo ""; } function setting_pass_fn() { $options = get_option('plugin_options'); echo ""; } function setting_chk1_fn() { $options = get_option('plugin_options'); if($options['chkbox1']) { $checked = ' checked="checked" '; } echo ""; } function setting_radio_fn() { $options = get_option('plugin_options'); $items = array("Square", "Triangle", "Circle"); foreach($items as $item) { $checked = ($options['option_set1']==$item) ? ' checked="checked" ' : ''; echo "
    "; } } // Add Missing Categories to Posts class AddMissingCategories { var $menu_id; // Plugin initialization function AddMissingCategories() { add_action( 'admin_menu', array( &$this, 'add_admin_menu' ) ); add_action( 'wp_ajax_addmissingcategories', array( &$this, 'ajax_process_categories' ) ); } // Register the admin page function add_admin_menu() { add_submenu_page( 'appStore_sm_rebuild', __('Add ASA Missing Categories','appStoreAssistant'), __('Add Missing Cats','appStoreAssistant'), 'manage_options', 'asa-add-missingcats', array(&$this, 'addmc_interface')); } function addmc_interface() { global $wpdb,$requestedPage; echo ''; echo '
    '; echo ''; echo '
    '; echo '

    '.__('AppStore Assistant Add Missing Categories','appStoreAssistant').'

    '; echo '

    '.__('Below is a collection of controls you can use to customize the App Store Assistant plugin','appStoreAssistant').'.

    '; //$requestedPage = 'appStore_sm_utilities'; appStore_displayAdminTabs('asa-add-missingcats','defaultTab',''); // If the button was clicked if ( ! empty( $_POST['asa-add-missingcats'] ) || ! empty( $_REQUEST['ids'] ) ) { // Form nonce check check_admin_referer( 'asa-add-missingcats' ); // GET LIST OF POSTS WITH ASA SHORT CODES if ( ! empty( $_REQUEST['ids'] ) ) { $postsWithASAshortcodes = array_map( 'intval', explode( ',', trim( $_REQUEST['ids'], ',' ) ) ); $ids = implode( ',', $postsWithASAshortcodes ); } else { // Directly querying the database is normally frowned upon, but all // of the API functions will return the full post objects which will // suck up lots of memory. This is best, just not as future proof. if ( ! $postsWithASAshortcodes = $wpdb->get_results( "SELECT ID FROM $wpdb->posts WHERE post_type = 'post' ORDER BY ID DESC" ) ) { echo '

    ' . sprintf( __( 'Unable to find any posts. Are you sure some exist?', 'appStoreAssistant' ), admin_url( 'upload.php?post_mime_type=image' ) ) . "

    "; return; } // Generate the list of IDs $ids = array(); foreach ( $postsWithASAshortcodes as $postWithASAshortcode ) $ids[] = $postWithASAshortcode->ID; $ids = implode( ',', $ids ); } echo '

    ' . __('Please be patient while the Missing Categories for ASA Posts are added. This can take a while, depending on the speed of this server or if you have lots of posts. Do not navigate away from this page until the process is complete.', 'appStoreAssistant' ) . '

    '; $count = count( $postsWithASAshortcodes ); $text_goback = ( ! empty( $_GET['goback'] ) ) ? sprintf( __( 'To go back to the previous page, click here.', 'appStoreAssistant' ), 'javascript:history.go(-1)' ) : '

    '.sprintf( __( 'To Start Over and try adding categories again click here. %5$s', 'appStoreAssistant' ), "' + rt_successes + '", "' + rt_totaltime + '", "' + rt_errors + '", esc_url( wp_nonce_url( admin_url( 'admin.php?page=asa-add-missingcats' ), 'asa-add-missingcats' ) ) . "' + rt_failedlist + '", $text_goback );; $text_failures = sprintf( __( 'All done! %1$s Posts with missing categories were successfully corrected in %2$s seconds and there were %3$s posts that do not have ASA shortcodes.

    If you think some of the posts that we did not find any ASA Shortcodes for really had them, then try rebuilding again by clicking here. This probably will not do anything, but you can try just incase of a network issue. %5$s', 'appStoreAssistant' ), "' + rt_successes + '", "' + rt_totaltime + '", "' + rt_errors + '", esc_url( wp_nonce_url( admin_url( 'admin.php?page=asa-add-missingcats' ), 'asa-add-missingcats' ) . '&ids=' ) . "' + rt_failedlist + '", $text_goback ); $text_nofailures = sprintf( __( 'All done! %1$s Posts with missing categories were corrected in %2$s seconds and there were 0 failures. %3$s', 'appStoreAssistant' ), "' + rt_successes + '", "' + rt_totaltime + '", $text_goback ); ?>


    0' ); ?>
    0' ); ?>

    '; wp_nonce_field('asa-add-missingcats'); echo '

    '.__('Use this utility to add missing categories to posts that have ASA Shortcodes. This is useful if you\'ve manually added posts with ASA shortcodes.', 'appStoreAssistant' ).'

    '; echo '

    '.__('Adding Missing Categories to posts is NOT reversible.','appStoreAssistant').'

    '; echo '

    '.__('This feature will first check for any posts that use the Mac App Store, iOS App Store or Amazon.com shortcodes. It will then check for missing categories. I will then add any missing categories to the post.','appStoreAssistant').'

    '; echo '

    '.__('To begin, just press the button below.','appStoreAssistant').'

    '; echo '

    '; echo ''; echo ''; } } // Process a post ID (this is an AJAX handler) function ajax_process_categories() { @error_reporting( 0 ); // Don't break the JSON result header( 'Content-type: application/json' ); $id = (int) $_REQUEST['id']; $postData = get_post( $id ); //if ( ! current_user_can( $this->capability ) ) //$this->die_json_error_msg( $postData->ID, __( 'Your user account doesn't have permission to process Featured Images.', 'appStoreAssistant' ) ); $postContent = $postData->post_content; $thePostName = $postData->post_title; //Adding Missing Category goes here $asaIDs = array(); $amazonIDs = array(); if(preg_match('/asa_item\ id="/i', $postContent, $matches) || preg_match('/_app\ id="/i', $postContent, $matches) || preg_match('/_app_elements\ id="/i', $postContent, $matches)|| preg_match('/itunes_store\ id="/i', $postContent, $matches)) { $pattern = '/id="([0-9]+)/i'; preg_match($pattern, $postContent, $matches, PREG_OFFSET_CAPTURE, 5); $asaIDs[] = $matches[1][0]; } if(preg_match('/amazon_item\ asin="/i', $postContent, $matches) || preg_match('/amazon_item_link\ asin="/i', $postContent, $matches) ) { $pattern = '/asin="([a-zA-Z0-9]+)/i'; preg_match($pattern, $postContent, $matches, PREG_OFFSET_CAPTURE, 5); $amazonIDs[] = $matches[1][0]; } if(preg_match('/asa_item\ link="/i', $postContent, $matches) || preg_match('/_app\ link="/i', $postContent, $matches)) { $pattern = '/id([0-9]+)/i'; preg_match($pattern, $postContent, $matches, PREG_OFFSET_CAPTURE, 3); $asaIDs[] = $matches[1][0]; } $idsFound = count($asaIDs) + count($amazonIDs); if($idsFound < 1 ) die( json_encode( array( 'error' => '' .sprintf( __( 'Skipping: No App IDs or Amazon ASINs found for post %s.', 'appStoreAssistant' ), esc_html( $thePostName )) .' ('.$id.')' ) ) ); @set_time_limit( 900 ); // 5 minutes per post should be PLENTY if(!$thePostName) die( json_encode( array( 'error' => '' .__( 'Skipping: No Post Title found for post ID', 'appStoreAssistant' ) .' ('.$id.')' ) ) ); if(count($asaIDs) > 0) { // Process asaIDs $appID = $asaIDs[0]; $appData = appStore_get_data( $appID ); $categories = $appData->genres; $post_categories = wp_get_post_categories( $id ); $cats = array(); foreach($post_categories as $c){ $cat = get_category( $c ); $categories[] = $cat->name; } //$logEntry .= "----Filename:$thumb_url\r\r"; //Debug //$logEntry .= "----FileArray:".print_r($appData,true)."\r\r"; //Debug //file_put_contents($logFile, $logEntry, FILE_APPEND | LOCK_EX); //Debug $appCategories = array_unique($categories); foreach($appCategories as $appCategory) { $term_id = term_exists( $appCategory, 'category' ); if(is_array($term_id)) { $postCategories[] = $term_id['term_id']; $postCategoriesList[] = $appCategory; } elseif(appStore_setting('newPost_addCategories')=="yes") { $postCategoriesList[] = $appCategory.' (NEW)'; $newCategoryID = wp_create_category($appCategory); if($newCategoryID) $postCategories[] = $newCategoryID; } } $postCategoriesList = implode(",",$postCategoriesList); $postUpdate = wp_set_post_terms( $id, $postCategories, 'category',false); if(is_array($postUpdate)) die( json_encode( array( 'success' => '' .sprintf( __( 'Updated Apple App Store App "%s" (%s) with categories: %s', 'appStoreAssistant' ), ''.esc_html( $thePostName ).'',$id,$postCategoriesList ) .'' ) ) ); } if(count($amazonIDs) > 0) { // Process amazonIDs $amazonItem = appStore_get_amazonData($amazonIDs[0]); // New code Starts here $categories[] = $amazonItem['ProductGroup']; $post_categories = wp_get_post_categories( $id ); $cats = array(); foreach($post_categories as $c){ $cat = get_category( $c ); $categories[] = $cat->name; } //$logEntry = "----FileArray:".print_r($amazonItem,true); //Debug $appCategories = array_unique($categories); foreach($appCategories as $appCategory) { $term_id = term_exists( $appCategory, 'category' ); if(is_array($term_id)) { $postCategories[] = $term_id['term_id']; $postCategoriesList[] = $appCategory; } elseif(appStore_setting('newPost_addCategories')=="yes") { $postCategoriesList[] = $appCategory.' (NEW)'; $newCategoryID = wp_create_category($appCategory); if($newCategoryID) $postCategories[] = $newCategoryID; } } $postCategoriesList = implode(",",$postCategoriesList); $postUpdate = wp_set_post_terms( $id, $postCategories, 'category',false); die( json_encode( array( 'success' => '' .sprintf( __( 'Updated Amazon Item "%s" (%s) with categories: %s', 'appStoreAssistant' ), ''.esc_html( $amazonItem['Title'] ).'',$id,$postCategoriesList ) .'' ) ) ); } die( json_encode( array( 'success' => sprintf( __( '"%1$s" (ID %2$s) was successfully resized in %3$s seconds.', 'appStoreAssistant' ), esc_html( $thePostName ), $image->ID, timer_stop() ) ) ) ); } // Helper to make a JSON error message function die_json_error_msg( $id, $message ) { die( json_encode( array( 'error' => sprintf( __( '"%1$s" (ID %2$s) failed to resize. The error message was: %3$s', 'appStoreAssistant' ), esc_html( get_the_title( $id ) ), $id, $message ) ) ) ); } // Helper function to escape quotes in strings for use in Javascript function esc_quotes( $string ) { return str_replace( '"', '\"', $string ); } } // END AddMissingCategories // Start up this Class add_action( 'init', 'AddMissingCategories' ); function AddMissingCategories() { global $AddMissingCategories; $AddMissingCategories = new AddMissingCategories(); } // Rebuild Featured Images class RebuildFeaturedImages { var $menu_id; // Plugin initialization function RebuildFeaturedImages() { add_action( 'admin_menu', array( &$this, 'add_admin_menu' ) ); add_action( 'wp_ajax_rebuildfeatured', array( &$this, 'ajax_process_image' ) ); } // Register the admin page function add_admin_menu() { add_submenu_page( 'appStore_sm_rebuild', __('Rebuild ASA Featured Images', 'appStoreAssistant' ), __('Rebuild Featured', 'appStoreAssistant' ), 'manage_options', 'asa-rebuild-featuredimages', array(&$this, 'rebuildfi_interface')); } // The user interface plus Featured Image regenerator function rebuildfi_interface() { global $wpdb,$requestedPage; echo ''; echo '
    '; echo ''; echo '
    '; echo '

    AppStore Assistant '.__('Rebuild Featured Images', 'appStoreAssistant' ).'

    '; echo '

    '.__('Below is a collection of controls you can use to customize the App Store Assistant plugin','appStoreAssistant').'.

    '; //$requestedPage = 'appStore_sm_utilities'; appStore_displayAdminTabs('asa-rebuild-featuredimages','defaultTab',''); // If the button was clicked if ( ! empty( $_POST['asa-rebuild-featuredimages'] ) || ! empty( $_REQUEST['ids'] ) ) { // Form nonce check check_admin_referer( 'asa-rebuild-featuredimages' ); // Create the list of image IDs if ( ! empty( $_REQUEST['ids'] ) ) { $images = array_map( 'intval', explode( ',', trim( $_REQUEST['ids'], ',' ) ) ); $ids = implode( ',', $images ); } else { // Directly querying the database is normally frowned upon, but all // of the API functions will return the full post objects which will // suck up lots of memory. This is best, just not as future proof. if ( ! $images = $wpdb->get_results( "SELECT ID FROM $wpdb->posts WHERE post_type = 'post' ORDER BY ID DESC" ) ) { echo '

    ' . sprintf( __( 'Unable to find any posts. Are you sure some exist?', 'appStoreAssistant' ), admin_url( 'upload.php?post_mime_type=image' ) ) . "

    "; return; } // Generate the list of IDs $ids = array(); foreach ( $images as $image ) $ids[] = $image->ID; $ids = implode( ',', $ids ); } echo '

    ' . __('Please be patient while the Featured Images for ASA Posts are rebuilt. This can take a while, depending on the speed of this server or if you have lots of posts. Do not navigate away from this page until the process is complete.', 'appStoreAssistant' ) . '

    '; $count = count( $images ); $text_goback = ''; $text_goback = ( ! empty( $_GET['goback'] ) ) ? sprintf( __( 'To go back to the previous page, click here.', 'appStoreAssistant' ), 'javascript:history.go(-1)' ) : '

    '.sprintf( __( 'To Start Over and try rebuilding again click here. %5$s', 'appStoreAssistant' ), "' + rt_successes + '", "' + rt_totaltime + '", "' + rt_errors + '", esc_url( wp_nonce_url( admin_url( 'admin.php?page=asa-rebuild-featuredimages' ), 'asa-rebuild-featuredimages' ) ) . "' + rt_failedlist + '", $text_goback ); $text_failures = sprintf( __( 'All done! %1$s Featured Images were successfully created in %2$s seconds and there were %3$s posts that do not have ASA shortcodes.

    If you think some of the posts that we did not find any ASA Shortcodes for really had them, then try rebuilding again by clicking here. This probably will not do anything, but you can try just incase of a network issue. %5$s', 'appStoreAssistant' ), "' + rt_successes + '", "' + rt_totaltime + '", "' + rt_errors + '", esc_url( wp_nonce_url( admin_url( 'admin.php?page=asa-rebuild-featuredimages' ), 'asa-rebuild-featuredimages' ) . '&ids=' ) . "' + rt_failedlist + '", $text_goback ); $text_nofailures = sprintf( __( 'All done! %1$s Featured Images were successfully rebuild in %2$s seconds and there were 0 failures. %3$s', 'appStoreAssistant' ), "' + rt_successes + '", "' + rt_totaltime + '", $text_goback ); ?>


    0' ); ?>
    0' ); ?>

    '; wp_nonce_field('asa-rebuild-featuredimages'); echo '

    ' .__( "Use this utility to rebuild Featured Images for posts that have ASA Shortcodes. This is useful if you've changed of the Featured Image dimensions on the", 'appStoreAssistant' ) .' ' .__('settings page', 'appStoreAssistant' ) .'. ' .__('Old Featured Images will be kept to avoid any broken images due to hard-coded URLs.', 'appStoreAssistant' ) .'

    '; echo '

    '.__('Featured Image rebuilding is NOT reversible, but you can just change your Featured Image dimensions back to the old values and then re-run this utility.', 'appStoreAssistant' ).'

    '; echo '

    '.__('This feature will first check for any posts that use the ', 'appStoreAssistant' ) .''.__('Mac App Store', 'appStoreAssistant' ).'' .', '.__('iOS App Store', 'appStoreAssistant' ).'' .' or '.__('Amazon.com', 'appStoreAssistant' ).' ' .__('shortcodes', 'appStoreAssistant' ).'. ' .__('It will then check for a Featured Image. If no image is assigned to that post it will then assign a Featured Image based on the icon or product image.', 'appStoreAssistant' ).'

    '; echo '

    '.__("The size of the image can be set in the respective store's settings.", 'appStoreAssistant' ).'

    '; echo '

    ('; _e('Cache MUST be ENABLED for this function to work!.', 'appStoreAssistant' ); echo ' See General -> Miscellaneous section.)

    '; echo '

    '.__( 'To begin, just press the button below.', 'appStoreAssistant ').'

    '; echo '

    '; echo ''; echo ''; } // End if button echo '
    '; } // Process a single image ID (this is an AJAX handler) function ajax_process_image() { @error_reporting( 0 ); // Don't break the JSON result header( 'Content-type: application/json' ); $id = (int) $_REQUEST['id']; $postData = get_post( $id ); $logFile = CACHE_DIRECTORY."FI_Reset_Log.txt"; //if ( ! current_user_can( $this->capability ) ) //$this->die_json_error_msg( $postData->ID, __( "Your user account doesn't have permission to process Featured Images.", 'appStoreAssistant' ) ); $postContent = $postData->post_content; $thePostName = $postData->post_title; if(has_post_thumbnail($id)) { $featuredImageURL = wp_get_attachment_url(get_post_thumbnail_id( $id )); //$logEntry = "----Line 1989 ($id):".$featuredImageURL."\r\r"; //Debug //file_put_contents($logFile, $logEntry, FILE_APPEND | LOCK_EX); //Debug if(preg_match('/appstoreassistant_cache|artworkOriginal|artworkUrl|asaArtwork/',$featuredImageURL,$matches)) { if(delete_post_meta($id, '_thumbnail_id')) { //Featured Image Removed } else { die( json_encode( array( 'error' => '' .sprintf( __( 'Error: Cannot remove old Featured Image for "%s" (%s)', 'appStoreAssistant' ),''.$featuredImageURL.'',$id ) .'' ) ) ); } } else { //$logEntry = "----Line 2006 ($id):".$thePostName."\r\r"; //Debug //file_put_contents($logFile, $logEntry, FILE_APPEND | LOCK_EX); //Debug die( json_encode( array( 'error' => '' .sprintf( __( 'Skipping: Already has non ASA Featured Image for "%s"', 'appStoreAssistant' ),''.$thePostName.'') .' ('.$id.')' ) ) ); } } $asaIDs = array(); $amazonIDs = array(); if(preg_match('/asa_item\ id="/i', $postContent, $matches) || preg_match('/_app\ id="/i', $postContent, $matches) || preg_match('/_app_elements\ id="/i', $postContent, $matches)|| preg_match('/itunes_store\ id="/i', $postContent, $matches)) { $pattern = '/id="([0-9]+)/i'; preg_match($pattern, $postContent, $matches, PREG_OFFSET_CAPTURE, 5); $asaIDs[] = $matches[1][0]; } if(preg_match('/amazon_item\ asin="/i', $postContent, $matches) || preg_match('/amazon_item_link\ asin="/i', $postContent, $matches) ) { $pattern = '/asin="([a-zA-Z0-9]+)/i'; preg_match($pattern, $postContent, $matches, PREG_OFFSET_CAPTURE, 5); $amazonIDs[] = $matches[1][0]; } if(preg_match('/asa_item\ link="/i', $postContent, $matches) || preg_match('/_app\ link="/i', $postContent, $matches)) { $pattern = '/id([0-9]+)/i'; preg_match($pattern, $postContent, $matches, PREG_OFFSET_CAPTURE, 3); $asaIDs[] = $matches[1][0]; } $idsFound = count($asaIDs) + count($amazonIDs); if($idsFound < 1 ) die( json_encode( array( 'error' => '' .sprintf( __( 'Skipping: No ASA IDs or Amazon ASINs found for post %s.', 'appStoreAssistant' ), esc_html( $thePostName )) .' ('.$id.')' ) ) ); @set_time_limit( 900 ); // 5 minutes per image should be PLENTY //Rebuilding goes here if(!$thePostName) die( json_encode( array( 'error' => '' .sprintf( __( 'Skipping: No Post Title found for post ID', 'appStoreAssistant' )) .' ('.$id.')' ) ) ); //////DELETE OLD FEATURED IMAGES if(count($asaIDs) > 0) { // Process asaIDs $appID = $asaIDs[0]; if($appData = appStore_get_data( $appID )) { //$logEntry = "----Got ID $id:$appID\r\r"; } else { die( json_encode( array( 'error' => '' .sprintf( __( 'Skipping: The app or item is no longer available.', 'appStoreAssistant' )) .' ('.$id.')' ) ) ); } //$filename = $appData->imageFeatured_path; // New code Starts here if(appStore_setting('cache_images_locally')=="1") { $urlToFeaturedImage = $appData->imageFeatured_cached; } else { $urlToFeaturedImage = $appData->imageFeatured; } $desc = 'Featured Image '.$id."-".date("U"); //$logEntry = "----$desc:$appID\r\r"; //$logEntry = "----Filename:$thumb_url\r\r"; //$logEntry .= "----FileArray:".print_r($appData,true)."\r\r"; //$logEntry = "----Filename:$appID\r\r"; //file_put_contents($logFile, $logEntry, FILE_APPEND | LOCK_EX); //Debug if ( ! empty($urlToFeaturedImage) ) { $tmp = download_url( $urlToFeaturedImage ); preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $urlToFeaturedImage, $matches); $file_array['name'] = "FI_".$appID."_".basename($urlToFeaturedImage); $file_array['tmp_name'] = $tmp; if ( is_wp_error( $tmp ) ) { @unlink($file_array['tmp_name']); $file_array['tmp_name'] = ''; $error_string = $tmp->get_error_message(); die( json_encode( array( 'error' => '' .sprintf( __( 'Error: Featured Image File ' . $error_string . '(%s)', 'appStoreAssistant' ),$urlToFeaturedImage ) .'' ) ) ); } // do the validation and storage stuff $thumbid = media_handle_sideload( $file_array, $id, $desc ); // If error storing permanently, unlink if ( is_wp_error($thumbid) ) { @unlink($file_array['tmp_name']); die( json_encode( array( 'error' => '' .sprintf( __( 'Error: storing permanently, unlink. (%s)', 'appStoreAssistant' ),print_r($thumbid,true)) .'' ) ) ); } } set_post_thumbnail( $id, $thumbid ); die( json_encode( array( 'success' => '' .sprintf( __( 'Updated Apple Featured Image for: "%s" (%s)', 'appStoreAssistant' ), ''.esc_html( $thePostName ).'',$id ) .'' ) ) ); } if(count($amazonIDs) > 0) { // Process amazonIDs $amazonItem = appStore_get_amazonData($amazonIDs[0]); // New code Starts here $thumb_url = $amazonItem['imageFeatured_cached']; $desc = 'Featured Image '.$id."-".date("U"); //$logEntry .= "----Filename:$thumb_url\r\r"; //Debug //$logEntry .= "----FileArray:".print_r($amazonItem,true)."\r\r"; //Debug //file_put_contents($logFile, $logEntry, FILE_APPEND | LOCK_EX); //Debug if ( ! empty($thumb_url) ) { $tmp = download_url( $thumb_url ); preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $thumb_url, $matches); $file_array['name'] = "FI_".$amazonIDs[0]."_".basename($thumb_url); $file_array['tmp_name'] = $tmp; if ( is_wp_error( $tmp ) ) { @unlink($file_array['tmp_name']); $file_array['tmp_name'] = ''; } // do the validation and storage stuff $thumbid = media_handle_sideload( $file_array, $id, $desc ); // If error storing permanently, unlink if ( is_wp_error($thumbid) ) { @unlink($file_array['tmp_name']); die( json_encode( array( 'error' => '' .sprintf( __( 'Error: storing permanently, unlink.', 'appStoreAssistant' ),$wp_upload_dir['path'] ) .'' ) ) ); } } set_post_thumbnail( $id, $thumbid ); die( json_encode( array( 'success' => '' .sprintf( __( 'Updated Amazon Featured Image for: "%s" (%s)', 'appStoreAssistant' ), ''.esc_html( $amazonItem['Title'] ).'',$id ) .'' ) ) ); } die( json_encode( array( 'error' => sprintf( __( 'Test Code: %s. :%s', 'appStoreAssistant' ), esc_html( $postContent ),print_r($applinks[1],true) ) ) ) ); /* if ( ! $image || 'attachment' != $image->post_type || 'image/' != substr( $image->post_mime_type, 0, 6 ) ) die( json_encode( array( 'error' => sprintf( __( 'Failed resize: %s is an invalid image ID.', 'appStoreAssistant' ), esc_html( $_REQUEST['id'] ) ) ) ) ); */ $fullsizepath = get_attached_file( $image->ID ); if ( false === $fullsizepath || ! file_exists( $fullsizepath ) ) $this->die_json_error_msg( $image->ID, sprintf( __( 'The originally uploaded image file cannot be found at %s', 'appStoreAssistant' ), '' . esc_html( $fullsizepath ) . '' ) ); $thePostID = $image->ID; $thePostName = $image->post_content; //$metadata = wp_generate_attachment_metadata( $image->ID, $fullsizepath ); $metadata = true; if ( is_wp_error( $metadata ) ) $this->die_json_error_msg( $image->ID, $metadata->get_error_message() ); if ( empty( $metadata ) ) $this->die_json_error_msg( $image->ID, __( 'Unknown failure reason.', 'appStoreAssistant' ) ); // If this fails, then it just means that nothing was changed (old value == new value) //wp_update_attachment_metadata( $image->ID, $metadata ); die( json_encode( array( 'success' => sprintf( __( '%1$s (ID %2$s) was successfully resized in %3$s seconds.', 'appStoreAssistant' ), '"'.esc_html( $thePostName ).'"', $image->ID, timer_stop() ) ) ) ); } // Helper to make a JSON error message function die_json_error_msg( $id, $message ) { die( json_encode( array( 'error' => sprintf( __( '%1$s (ID %2$s) failed to resize. The error message was: %3$s', 'appStoreAssistant' ), '"'.esc_html( get_the_title( $id ) ).'"', $id, $message ) ) ) ); } // Helper function to escape quotes in strings for use in Javascript function esc_quotes( $string ) { return str_replace( '"', '\"', $string ); } } //END RebuildFeaturedImages // Start up this Class add_action( 'init', 'RebuildFeaturedImages' ); function RebuildFeaturedImages() { global $RebuildFeaturedImages; $RebuildFeaturedImages = new RebuildFeaturedImages(); } // Add Pointers add_action( 'admin_enqueue_scripts', 'custom_admin_pointers_header' ); function custom_admin_pointers_header() { if ( custom_admin_pointers_check() ) { add_action( 'admin_print_footer_scripts', 'custom_admin_pointers_footer' ); wp_enqueue_script( 'wp-pointer' ); wp_enqueue_style( 'wp-pointer' ); } } function custom_admin_pointers_check() { $admin_pointers = custom_admin_pointers(); foreach ( $admin_pointers as $pointer => $array ) { if ( $array['active'] ) return true; } } function custom_admin_pointers_footer() { $admin_pointers = custom_admin_pointers(); ?> ' . __( 'Important Changes!!', 'appStoreAssistant' ) . ''; $new_pointer_content .= '

    ' . __( 'The following shortcodes Removed:
    ios_app, mac_app, itunes_store, ibooks_store, ios_app_elements, ios_app_list, ios_app_link, itunes_store_link, mac_app_link

    See for help replacing shortcodes

    Please see the Change Log (readme.txt) for Important Changes to this version!', 'appStoreAssistant' ) . '

    '; return array( $prefix . 'new_items' => array( 'content' => $new_pointer_content, 'anchor_id' => '#toplevel_page_appStore_IDsearch', 'edge' => 'left', 'align' => 'right', 'active' => ( ! in_array( $prefix . 'new_items', $dismissed ) ) ), ); } function appStore_add_dashboard_widgets() { wp_add_dashboard_widget( 'appStore_dashboard_widget', // Widget slug. 'App Store Assistant: Search for App', // Title. 'appStore_displaySearchForm' // Display function. ); } add_action( 'wp_dashboard_setup', 'appStore_add_dashboard_widgets' ); /** * Create the function to output the contents of our Dashboard Widget. */ function appStore_displaySearchForm($searchType,$SearchTerm) { //echo 'Posted SearchType: ['.$searchType.']
    '; //Debug if ($searchType == '') $searchType = appStore_setting('appSearch_default'); //echo 'Adjusted SearchType: ['.$searchType.']
    '; //Debug $searchTypes = array ( "iOS" => __('All iOS Apps','appStoreAssistant'), "Mac" => __('Mac Apps','appStoreAssistant'), "iPhone" => __('Just iPhone/iPod Apps','appStoreAssistant'), "iPad" => __('Just iPad Apps','appStoreAssistant'), "iTunes-Album" => __('iTunes Albums','appStoreAssistant'), "iTunes-Audiobook" => __('iTunes Audiobook','appStoreAssistant'), "iTunes-eBook" => __('iTunes eBook','appStoreAssistant'), "iTunes-Movie" => __('iTunes Movie','appStoreAssistant'), "iTunes-Podcast" => __('iTunes Podcast','appStoreAssistant'), "iTunes-TV" => __('iTunes TV Show','appStoreAssistant') ); echo '
    '; echo '
    '; echo 'Search for '; echo '

    '; $string = __('Find Items','appStoreAssistant'); echo __('App Name, Artist, Title or ID','appStoreAssistant').":
    "; echo ''; echo ''; echo ''; echo ''; echo '
    '; echo '
    '; } ?>