/** * Check if the debug file exists * * @return bool */ public function debug_file_exists() { $debug_mode = Instagrate_Pro_Helper::setting('igpsettings_support_debug-mode', 0); $debug_file = INSTAGRATEPRO_PLUGIN_DIR . 'debug.txt'; $file = file_exists($debug_file); if ($debug_mode == 1 && $file) { return true; } return false; }
/** * Get locations in Instagram * * @param $account_id * @param $location * @param $lat * @param $lng * @param bool $ajax * * @return array */ public function get_locations($account_id, $location, $lat, $lng, $ajax = false) { $account_settings = get_post_meta($account_id, '_instagrate_pro_settings', true); $access = $account_settings['token']; $options = get_post_meta($account_id, '_instagrate_pro_settings', true); $url = 'locations/search/'; $new_locations = array(); $distance = Instagrate_Pro_Helper::setting('igpsettings_general_location-distance', ''); if ($lat == '' || $lng == '') { $new_locations[0] = '— ' . __('Enter Location', 'instagrate-pro') . ' —'; return $new_locations; } $new_locations[0] = '— ' . __('No Locations Found', 'instagrate-pro') . ' —'; $params = array('lat' => $lat, 'lng' => $lng); if ($distance != '') { $params['distance'] = $distance; } $data = $this->do_http_request($access, $url, $params); if (!$data) { if ($ajax) { $options['ig_error'] = 'The Instagram API is currently throwing errors for large locations'; } else { $options['ig_error'] = '<strong>Instagram API Error</strong> For large locations try settings the distance to default or 500 metres in the <a href="' . admin_url('edit.php?post_type=instagrate_pro&page=instagrate-pro-settings&tab=general') . '">settings</a>'; } } else { if ($data->meta->code == 200) { $locations = $data->data; if ($locations && is_array($locations)) { $new_locations[0] = '— ' . __('Select', 'instagrate-pro') . ' —'; foreach ($locations as $ig_location) { $new_locations[$ig_location->id] = $ig_location->name; } $options['instagram_location'] = $location; $options['location_lat'] = $lat; $options['location_lng'] = $lng; } $options['ig_error'] = ''; } else { $options['ig_error'] = '<strong>' . $data->meta->error_type . '</strong> ' . $data->meta->error_message; } } update_post_meta($account_id, '_instagrate_pro_settings', $options); if ($ajax) { return array('locations' => $new_locations, 'error' => $options['ig_error']); } return $new_locations; }
<?php /** * 1.7.6 * * Make sure all existing accounts that use public_content are forced to be reauthed * */ $accounts = instagrate_pro()->accounts->get_accounts(); if (!isset($accounts) || !is_array($accounts)) { return; } foreach ($accounts as $key => $account) { $options = get_post_meta($key, '_instagrate_pro_settings', true); $stream = Instagrate_Pro_Helper::setting('instagram_images', 'recent', $options); if (!in_array($stream, array('recent', 'feed'))) { // Stream is using public_content $options['needs_reconnect'] = 1; update_post_meta($key, '_instagrate_pro_settings', $options); } }
/** * Helper function for building a select element * * @param $name * @param $items * @param string $default * @param $options * @param string $class */ public static function metabox_select($name, $items, $default = '', $options, $class = '') { $selected = Instagrate_Pro_Helper::setting($name, $default, $options); ?> <select name="_instagrate_pro_settings[<?php echo $name; ?> ]" <?php echo $class != '' ? 'class="' . $class . '"' : ''; ?> > <?php foreach ($items as $key => $value) { ?> <option value="<?php echo $key; ?> " <?php selected($selected, $key); ?> ><?php echo $value; ?> </option> <?php } ?> </select> <?php }
/** * Main wrapper for triggering the posting for an account * * @param $account_id * @param string $frequency * @param string $schedule * * @return mixed */ function post_account($account_id, $frequency = 'schedule', $schedule = '') { $this->account_id = $account_id; $this->account = get_post($account_id); $this->settings = (object) get_post_meta($account_id, '_instagrate_pro_settings', true); if (!$this->check_account($frequency)) { return; } if ($frequency == 'schedule') { $schedule = Instagrate_Pro_Helper::setting('posting_schedule', 'igp_daily', $this->settings); } // Lock Account instagrate_pro()->accounts->lock_account($account_id, true); instagrate_pro()->debug->make_debug('Account Now Locked'); // Set up soon defaults $this->general_defaults($frequency, $schedule); // Check the account has a token and last id if (isset($this->settings->token) && $this->settings->token == '' && isset($this->settings->last_id) && $this->settings->last_id == '') { return $this->post_exit('Account has empty token and last id'); } $this->settings->posting_frequency = Instagrate_Pro_Helper::setting('posting_frequency', 'constant', $this->settings); // Check the account has the correct frequency if ($frequency != $this->settings->posting_frequency) { return $this->post_exit('Account frequency (' . $this->settings->posting_frequency . ') is not the running frequency (' . $frequency . ')'); } // Constant specific checks if (!$this->constant_post_check()) { return; } //Account specific settings $this->account_defaults(); // Retrieve newer images from Instragam instagrate_pro()->accounts->retrieve_images($this->account_id); // Get all images pending $this->images = instagrate_pro()->images->get_images($this->account_id, 'pending', $this->image_order, !$this->dup_image, 'posting'); if (!$this->dup_image) { instagrate_pro()->images->update_duplicate_images($this->account_id); } if (!$this->images) { return $this->post_exit('0 Images to post'); } // Prepare images $this->prepare_images(); // Media Filtering $this->media_type_filtering(); // Hashtag filtering on images $this->hashtag_filtering(); // Check there are images left to post if (empty($this->images)) { return $this->post_exit('0 Images to post'); } else { $count = sizeof($this->images); instagrate_pro()->debug->make_debug('Images to post: ' . $count); $i = 0; } // Reset template tag values instagrate_pro()->tags->clear_values(); $function = $this->settings->posting_multiple; // Functions for different for posting_multiple config if (method_exists($this, $function)) { $this->{$function}($i, $count); } // Write to debug file if mode on instagrate_pro()->debug->write_debug($this->account_id); return $this->images; }
function ajax_load_images() { if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'instagrate_pro')) { return 0; } if (!isset($_POST['post_id'])) { return 0; } if (!isset($_POST['img_count'])) { return 0; } $response['error'] = false; $response['message'] = ''; $response['next_url'] = ''; $response['load'] = false; $all_count = instagrate_pro()->images->images_total($_POST['post_id']); if ($_POST['img_count'] < $all_count[0]->Total && Instagrate_Pro_Helper::setting('igpsettings_general_admin-images', '') != '') { $older_images = instagrate_pro()->images->get_images($_POST['post_id'], '', 'DESC', false, '', 20, $_POST['img_count']); $images = array(); foreach ($older_images as $image) { $images[] = array('id' => $image->image_id, 'images' => array('thumbnail' => array('url' => $image->image_thumb_url)), 'status' => $image->status, 'media_type' => $image->media_type); } $response['images'] = $images; } else { $images = instagrate_pro()->accounts->load_images($_POST['post_id']); $response['stats'] = instagrate_pro()->accounts->account_stats($_POST['post_id']); $account_settings = get_post_meta($_POST['post_id'], '_instagrate_pro_settings', true); $response['images'] = $images; $response['next_url'] = $account_settings['next_url']; $response['load'] = true; } $response['message'] = 'success'; echo json_encode($response); die; }
function custom_columns($column) { // todo default value // todo get images key // get location name global $post; $options = get_post_meta($post->ID, '_instagrate_pro_settings', true); $profile_src = INSTAGRATEPRO_PLUGIN_URL . 'assets/img/not-connected.png'; $profile_name = 'Not connected'; if (Instagrate_Pro_Helper::setting('token', '', $options) != '') { $profile_name = $options['username']; } if (Instagrate_Pro_Helper::setting('user_thumb', '', $options) != '') { $profile_src = $options['user_thumb']; } $edit_url = get_admin_url() . 'post.php?post=' . $post->ID . '&action=edit'; switch ($column) { case 'profile-img': ?> <a href="<?php echo $edit_url; ?> "> <img src="<?php echo $profile_src; ?> " width="30" height="30" alt="<?php echo $profile_name; ?> "> </a> <?php break; case 'profile': ?> <strong> <a href="<?php echo $edit_url; ?> " title="Edit Account"> <?php echo $profile_name; ?> </a> </strong> <br /> <?php echo instagrate_pro()->accounts->get_images_key($post->ID, true); break; case 'images': $posting = Instagrate_Pro_Helper::setting('instagram_images', '', $options); if ($posting == '') { $posting_text = __('Not configured', 'instagrate-pro'); } else { $posting_text = ucfirst($posting) . __(' Media', 'instagrate-pro'); if ($posting == 'users' && Instagrate_Pro_Helper::setting('instagram_user', '', $options) != '' && Instagrate_Pro_Helper::setting('instagram_users_id', '', $options) != '') { $posting_text .= '<br/>' . __('User', 'instagrate-pro') . ': <strong>' . Instagrate_Pro_Helper::setting('instagram_user', '', $options) . '</strong>'; } if ($posting == 'location' && Instagrate_Pro_Helper::setting('instagram_location', '', $options) != '' && Instagrate_Pro_Helper::setting('instagram_location_id', '', $options) != '') { $posting_text .= '<br/><strong>' . instagrate_pro()->accounts->get_location_name($post->ID, Instagrate_Pro_Helper::setting('instagram_location_id', '', $options)) . '</strong>'; } $filter = Instagrate_Pro_Helper::setting('instagram_hashtags', '', $options); if ($filter != '') { $posting_text .= '<br/>' . __('Filter', 'instagrate-pro') . ': <strong>' . $filter . '</strong>'; } } echo $posting_text; break; case 'frequency': $frequency = Instagrate_Pro_Helper::setting('posting_frequency', 'constant', $options); $frequency = ucfirst($frequency); if ($frequency == 'Schedule') { $frequency .= ' - ' . instagrate_pro()->scheduler->get_all_schedules(Instagrate_Pro_Helper::setting('posting_schedule', 'igp_daily', $options)); $frequency .= '<br/><div class="curtime"><span id="timestamp">' . __('Next', 'instagrate-pro') . ': <b>' . instagrate_pro()->scheduler->get_next_schedule($post->ID, Instagrate_Pro_Helper::setting('posting_schedule', 'igp_daily', $options)) . '</b></span></div>'; } echo $frequency; break; case 'multiple-images': $multiple = Instagrate_Pro_Helper::setting('posting_multiple', 'each', $options); switch ($multiple) { case 'each': $multiple_text = __('Post Per Media', 'instagrate-pro'); break; case 'group': $multiple_text = __('Media Grouped', 'instagrate-pro'); break; case 'single': $type = Instagrate_Pro_Helper::setting('post_type', 'post', $options); $same_post = Instagrate_Pro_Helper::setting('posting_same_post', '', $options); if ($same_post != '') { $same_post = get_post($same_post); $same_post = $same_post->post_title; $same_post = '<br/><strong>' . $same_post . '</strong>'; } $multiple_text = __('Same', 'instagrate-pro') . ' ' . ucfirst($type) . $same_post; break; } echo $multiple_text; break; case 'imagesaving': $feat = Instagrate_Pro_Helper::setting('post_featured_image', 'off', $options) == 'on' ? '<br/>Featured Image' : ''; $saving = Instagrate_Pro_Helper::setting('post_save_media', 'off', $options) == 'on' ? __('Media Library', 'instagrate-pro') . $feat : __('Instagram Media', 'instagrate-pro'); echo $saving; break; case 'classification': $tax = Instagrate_Pro_Helper::setting('post_taxonomy', '0', $options) != '0' ? ucwords(Instagrate_Pro_Helper::setting('post_taxonomy', '0', $options)) : ''; if ($tax != '') { $terms = Instagrate_Pro_Helper::setting('post_term', array(), $options); if (!is_array($terms)) { $terms = (array) $terms; } $term_text = ''; if ($terms && count($terms) > 0) { foreach ($terms as $term_selected) { $term_add = get_term($term_selected, Instagrate_Pro_Helper::setting('post_taxonomy', '0', $options)); if (!is_wp_error($term_add)) { $term_text .= $term_add->name . ', '; } } if (substr($term_text, -2) == ', ') { $term_text = substr($term_text, 0, -2); } } else { $term_text = 'Not Selected'; } echo __('Taxonomy', 'instagrate-pro') . ': <strong>' . $tax . '</strong><br/>' . __('Terms', 'instagrate-pro') . ': <strong>' . $term_text . '</strong>'; } else { _e('None', 'instagrate-pro'); } break; case 'type': $type = Instagrate_Pro_Helper::setting('post_type', 'post', $options); echo ucfirst($type); break; case 'status': $type = Instagrate_Pro_Helper::setting('post_status', 'publish', $options); echo ucfirst($type); break; case 'igp-actions': $actions = '<a class="igp-duplicate" title="Duplicate Account" rel="' . $post->ID . '" href="#">Duplicate</a>'; $actions .= '<p><strong>Sync:</strong></p>'; $actions .= '<a class="igp-sync-likes" title="Sync Likes" rel="' . $post->ID . '" href="#">Likes</a>'; if (Instagrate_Pro_Helper::setting('igpsettings_comments_enable-comments', '0') == 1) { $actions .= ' | <a class="igp-sync-comments" title="Sync Comments" rel="' . $post->ID . '" href="#">Comments</a>'; } echo $actions; break; } }
/** * Register and enqueue the scripts needed for the Google Maps */ public function add_map_scripts() { global $wp_query; $posts = $wp_query->posts; if ($this->page_has_maps($posts)) { $version = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? time() : INSTAGRATEPRO_VERSION; $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; wp_register_script('igp-google-maps', 'https://maps.googleapis.com/maps/api/js?sensor=false', array('jquery'), $version); wp_enqueue_script('igp-google-maps'); wp_register_script('igp-maps', INSTAGRATEPRO_PLUGIN_URL . "assets/js/maps{$min}.js", array('jquery', 'igp-google-maps'), $version); wp_enqueue_script('igp-maps'); $custom_rel = Instagrate_Pro_Helper::setting('igpsettings_general_lightbox-rel', 'lightbox'); wp_localize_script('igp-maps', 'igp_maps', array('lightbox_rel' => $custom_rel)); wp_register_style('igp-maps-style', INSTAGRATEPRO_PLUGIN_URL . "assets/css/maps.css", array(), $version); wp_enqueue_style('igp-maps-style'); } }
public function show_notices() { global $post; if (isset($post->post_type) && $post->post_type == INSTAGRATEPRO_POST_TYPE || isset($_GET['page']) && $_GET['page'] == 'instagrate-pro-settings') { // Duplicate Account if (isset($_GET['message']) && $_GET['message'] == '14') { echo '<div class="updated"> <p>' . __('Account duplicated') . ' </p> </div>'; } // Likes Synced Account if (isset($_GET['message']) && $_GET['message'] == '15') { echo '<div class="updated"> <p>' . __('Likes have been synced for this account successfully') . ' </p> </div>'; } // Comments Synced Account if (isset($_GET['message']) && $_GET['message'] == '16') { echo '<div class="updated"> <p>' . __('Comments have been synced for this account successfully') . ' </p> </div>'; } // Display check for user to make sure a blog page is selected if ('page' == get_option('show_on_front')) { if (0 == get_option('page_for_posts')) { $link_text = __('Settings -> Reading', 'instagrate-pro'); $link = '<a href="' . get_admin_url() . 'options-reading.php">' . $link_text . '</a>'; echo '<div class="updated"> <p>' . __('You must select a page to display your posts in ', 'instagrate-pro') . $link . ' </p> </div>'; } } // Display check to make sure there is write permissions on the debug file $debug_mode = Instagrate_Pro_Helper::setting('igpsettings_support_debug-mode', '0'); $debug_file = INSTAGRATEPRO_PLUGIN_DIR . 'debug.txt'; $file = file_exists($debug_file); if ($debug_mode == 1 && $file) { $write = instagrate_pro()->debug->can_write($debug_file); if ($write == false) { $link_text = __('file', 'instagrate-pro'); $link = ' <a href="' . plugin_dir_url(INSTAGRATEPRO_PLUGIN_FILE) . 'debug.txt">debug.txt ' . $link_text . '</a>'; echo '<div class="error"> <p>' . __('Debug mode is turned on. However, the debug file in the plugin folder is not writeable. Please contact your web hosting provider to amend the permissions on the', 'instagrate-pro') . $link . '</p> </div>'; } } // Instagram API Check $check = array(); $check = instagrate_pro()->instagram->instagram_api_check(); if ($check[0] == 0) { echo '<div class="error"><p>' . $check[1] . '</p></div>'; } // Account Error Message if (isset($_GET['post']) && isset($_GET['action']) && $_GET['action'] == 'edit') { $account_settings = get_post_meta($post->ID, '_instagrate_pro_settings', true); $settings = (object) $account_settings; if (isset($settings->ig_error) && $settings->ig_error != '') { echo '<div class="error"><p>' . $settings->ig_error . '</p></div>'; } } // Auto Draft Warning Message if (isset($_GET['post_type']) && $_GET['post_type'] == 'instagrate_pro') { if (isset($post->post_status) && $post->post_status == 'auto-draft') { echo '<div class="updated"><p>' . __('You must save the draft of this account before authorising with Instagram', 'instagrate-pro') . '</p></div>'; } } // Safe mode for execution time if (ini_get('safe_mode') && ini_get('max_execution_time') != 0) { echo '<div class="updated"> <p>' . sprintf(__("%sSafe mode%s is enabled on your server, so the PHP time and memory limits cannot be set by this plugin.\n\t\t\t\t\t\t\t\t\t\t\t\tYour time limit is %s seconds and your memory limit is %s, so if your accounts are posting lots of images at a time and saving them to the WordPress Media Library this may exceed the execution time. Each host has different methods available to increase these settings and a quick Google search should\n\t\t\t\t\t\t\t\t\t\t\t\tyield some information. If not, please contact your host for help.\n\t\t\t\t\t\t\t\t\t\t\t\tIf you cannot find an answer, please feel free to post a new topic.", 'instagrate-pro'), '<a href="http://php.net/manual/en/features.safe-mode.php"><strong>', '</a></strong>', ini_get('max_execution_time'), ini_get('memory_limit'), '</a>') . ' </p> </div>'; } } }
function meta_box_map() { global $post; $options = get_post_meta($post->ID, '_instagrate_pro_settings', true); wp_nonce_field(plugin_basename(__FILE__), 'instagrate_pro_noncename'); ?> <table class="form-table igp-admin"> <tr valign="top"> <th scope="row"><?php _e('Style', 'instagrate-pro'); ?> </th> <td> <?php $map_styles = array('ROADMAP' => __('Road', 'instagrate-pro'), 'HYBRID' => __('Hybrid', 'instagrate-pro'), 'SATELLITE' => __('Satellite', 'instagrate-pro'), 'TERRAIN' => __('Terrain', 'instagrate-pro')); Instagrate_Pro_Helper::metabox_select('map_style', $map_styles, 'ROADMAP', $options); ?> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('CSS Class', 'instagrate-pro'); ?> </th> <td> <input type="text" class="large-text" name="_instagrate_pro_settings[map_css]" value="<?php echo Instagrate_Pro_Helper::setting('map_css', '', $options); ?> " /><br /> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Width', 'instagrate-pro'); ?> </th> <td> <input type="text" class="small-text" name="_instagrate_pro_settings[map_width]" value="<?php echo Instagrate_Pro_Helper::setting('map_width', '400', $options); ?> " /> <?php $units = array('pixel' => __('px', 'instagrate-pro'), 'percent' => __('%', 'instagrate-pro')); Instagrate_Pro_Helper::metabox_select('map_width_type', $units, 'pixel', $options, 'igp-select-small'); ?> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Height', 'instagrate-pro'); ?> </th> <td> <input type="text" class="small-text" name="_instagrate_pro_settings[map_height]" value="<?php echo Instagrate_Pro_Helper::setting('map_height', '300', $options); ?> " /> <?php Instagrate_Pro_Helper::metabox_select('map_height_type', $units, 'pixel', $options, 'igp-select-small'); ?> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Zoom Level', 'instagrate-pro'); ?> </th> <td> <input type="text" class="small-text" name="_instagrate_pro_settings[map_zoom]" value="<?php echo Instagrate_Pro_Helper::setting('map_zoom', '15', $options); ?> " /> </td> </tr> </table> <?php }
/** * Reactivate all schedules for all accounts */ public function reactivate_schedules() { $accounts = instagrate_pro()->accounts->get_accounts(); if (isset($accounts) && $accounts) { foreach ($accounts as $key => $account) { $account_settings = get_post_meta($key, '_instagrate_pro_settings', true); if (Instagrate_Pro_Helper::setting('posting_frequency', 'constant', $account_settings) == 'schedule') { $schedule = Instagrate_Pro_Helper::setting('posting_schedule', 'igp_daily', $account_settings); $new_day = $this->schedule_no_day($schedule) ? '' : Instagrate_Pro_Helper::setting('posting_day', '', $account_settings); $new_time = Instagrate_Pro_Helper::setting('posting_time', date('H:00', strtotime('+1 hour')), $account_settings); $this->set_schedule($key, $new_day, $new_time, $schedule); } } } }
/** * Filter the comment text to replace usernames with links * * @param $content * @param $comment * * @return mixed */ public function comment_text($content, $comment = '') { if (Instagrate_Pro_Helper::setting('igpsettings_comments_mentions', '1') == 0) { return $content; } $igp_comment = get_comment_meta($comment->comment_ID, '_igp_comment_id', true); if ($igp_comment) { $content = preg_replace("/@(\\w+)/", "<a href=\"http://instagram.com/\\1\" target=\"_blank\">@\\1</a>", $content); } return $content; }
function deactivate_license() { if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], plugin_basename('instagrate_pro'))) { return 0; } $ajax_response['error'] = false; $ajax_response['message'] = ''; $options = get_option('igpsettings_settings'); $license = trim(Instagrate_Pro_Helper::setting('igpsettings_support_license-key', '', $options)); $api_params = array('license' => $license, 'file' => $this->sellwire_id); $url = esc_url_raw(add_query_arg($api_params, $this->sellwire_url . 'deactivate_license')); $response = wp_remote_get($url, $this->license_args()); if (is_wp_error($response)) { $ajax_response['error'] = true; $ajax_response['message'] = $response->get_error_message(); } else { $license_data = json_decode(wp_remote_retrieve_body($response)); if (isset($license_data->license) || isset($license_data->error) && $license_data->error == 'License expired') { unset($options['igpsettings_support_license-key']); unset($options['igpsettings_support_license-status']); update_option('igpsettings_settings', $options); $ajax_response['license_status'] = 'deactivated'; $ajax_response['redirect'] = admin_url('edit.php?post_type=instagrate_pro&page=instagrate-pro-settings&tab=support'); } else { if (isset($license_data->error)) { $ajax_response['error'] = true; $ajax_response['message'] = $license_data->error; } } } echo json_encode($ajax_response); die; }