'.__('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').'
';
_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 '
';
_e('The Cache folder ','appStoreAssistant');
echo ''.WP_CONTENT_DIR."/uploads/appstoreassistant_cache";
_e(' has been created successfully!','appStoreAssistant');
echo '';
echo '
';
}
}
}
} else {
echo '
';
_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 '
';
_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 '
';
}
} else {
echo '
';
_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 '
';
}
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." br> - - - - - ".$attachmentData->post_name." br>";
}
}
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 '
'.__('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 );
?>
'
.__( "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' ) . '