Changeset 1861487
- Timestamp:
- 04/20/2018 12:28:04 AM (8 years ago)
- Location:
- fotki-media-bot
- Files:
-
- 17 added
- 5 edited
-
tags/0.6 (added)
-
tags/0.6/admin (added)
-
tags/0.6/admin/css (added)
-
tags/0.6/admin/css/fotki_media_bot.css (added)
-
tags/0.6/admin/js (added)
-
tags/0.6/admin/js/fotki_media_bot.js (added)
-
tags/0.6/class.incoming-data.php (added)
-
tags/0.6/class.list-table.php (added)
-
tags/0.6/class.telegram.php (added)
-
tags/0.6/fotki-media-bot.php (added)
-
tags/0.6/index.php (added)
-
tags/0.6/readme.txt (added)
-
trunk/admin (added)
-
trunk/admin/css (added)
-
trunk/admin/css/fotki_media_bot.css (added)
-
trunk/admin/js (added)
-
trunk/admin/js/fotki_media_bot.js (added)
-
trunk/class.incoming-data.php (modified) (7 diffs)
-
trunk/class.list-table.php (modified) (4 diffs)
-
trunk/class.telegram.php (modified) (3 diffs)
-
trunk/fotki-media-bot.php (modified) (12 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
fotki-media-bot/trunk/class.incoming-data.php
r1859835 r1861487 6 6 class FotkiMediaBot_IncomingData 7 7 { 8 public static function init_data() { 8 public static function init_data() 9 { 9 10 $entityBody = file_get_contents('php://input'); 10 11 … … 36 37 } 37 38 38 if (!empty($response['message']['photo'])) { 39 $is_store_photos = self::is_store_media_by_media_type('photos', $bot_token); 40 $is_store_videos = self::is_store_media_by_media_type('videos', $bot_token); 41 42 if (!empty($response['message']['photo']) && $is_store_photos) { 39 43 list($photo_string, $photo_data) = FotkiMediaBot_Telegram::get_telegram_photo($bot_token, $response); 40 self::save PhotoStringToMediaLibrary($photo_string, $photo_data);44 self::saveMediaStringToMediaLibrary($photo_string, $photo_data); 41 45 } 42 46 … … 56 60 ); 57 61 62 // if it's gif and option not store photos, then not store 63 if (!empty($response['message']['document']['file_name']) && strpos($response['message']['document']['file_name'],'.gif.') !== FALSE && !$is_store_photos) { 64 return; 65 } 66 67 // if it's photo format and option not store photos, then not store 68 if (in_array($allowed_file_types, array('jpg', 'jpeg', 'png', 'gif'),true) && !$is_store_photos) { 69 return; 70 } 71 72 // if it's video format and option not store videos, then not store 73 if (in_array($allowed_file_types, array('wmv', 'avi', 'mp4'),true) && !$is_store_videos) { 74 return; 75 } 76 58 77 if ($allowed_file_types) { 59 78 list($photo_string, $photo_data) = FotkiMediaBot_Telegram::get_telegram_document($bot_token, $response); … … 61 80 $photo_data['api_file_name'] = $response['message']['document']['file_name']; 62 81 63 self::savePhotoStringToMediaLibrary($photo_string, $photo_data); 64 } 65 } 66 } 67 68 public static function savePhotoStringToMediaLibrary($photo_string, $photo_data) { 82 self::saveMediaStringToMediaLibrary($photo_string, $photo_data); 83 } 84 } 85 } 86 87 public static function saveMediaStringToMediaLibrary($photo_string, $photo_data) 88 { 69 89 $imageurl = $photo_data['photo_path']; 70 90 $imageurl = stripslashes($imageurl); … … 124 144 } 125 145 126 if ( strpos($photo_data['api_file_name'], '.gif.') !== FALSE) {127 update_post_meta($attach_id, '_' . FotkiMediaBot::FOTKI_MEDIA_BOT_PREFIX . ' is_gif', 1);146 if (!empty($photo_data['api_file_name']) && strpos($photo_data['api_file_name'], '.gif.') !== FALSE) { 147 update_post_meta($attach_id, '_' . FotkiMediaBot::FOTKI_MEDIA_BOT_PREFIX . 'media_type', 'gif'); 128 148 } 129 149 … … 139 159 } 140 160 141 public static function write_incoming_log($message) { 161 public static function is_store_media_by_media_type($media_type, $bot_token) { 162 $bots = get_option(FotkiMediaBot::FOTKI_MEDIA_BOT_PREFIX . 'bots'); 163 164 if (!empty($bots)) { 165 166 $i = 0; 167 168 foreach ($bots as &$bot) { 169 foreach ($bot as $key => $value) { 170 if ($key === 'fmb_bot_token' && $value === $bot_token) { 171 return (empty($bot['fmb_bot_not_save_media_types'][$media_type]) ? true : false); 172 } 173 } 174 $i++; 175 } 176 } 177 178 return false; 179 } 180 181 public static function write_incoming_log($message) 182 { 142 183 $wp_date_format = get_option('date_format'); 143 144 $date = '';145 184 146 185 if ($wp_date_format) { … … 150 189 } 151 190 152 $log_file = $wp_debug_log_file_path = plugin_dir_path(__FILE__).'incoming_data_from_bots.log';191 $log_file = ABSPATH . '/wp-content/fotki-media-bot-' . get_option(FotkiMediaBot::FOTKI_MEDIA_BOT_PREFIX . 'callback_id') . '.log'; 153 192 154 193 if ($handle = fopen($log_file, 'a')) { -
fotki-media-bot/trunk/class.list-table.php
r1855604 r1861487 24 24 case 'fmb_bot_token': 25 25 return esc_attr($item[$column_name]); 26 case 'fmb_bot_not_save_media_types': 27 $not_save_photos = false; 28 $not_save_videos = false; 29 30 if (!empty($item[$column_name])) { 31 foreach ($item[$column_name] as $key => $value) { 32 if ($key === 'photos' && !empty($value) && $value === '1') { 33 $not_save_photos = true; 34 } elseif ($key === 'videos' && !empty($value) && $value === '1') { 35 $not_save_videos = true; 36 } 37 } 38 } 39 40 $html = '<div class="fmb-bot-status-group"><label for="save_photos"><input type="checkbox" class="fmb-bot-status-checkbox" id="save_photos" value="' . $item['fmb_bot_token'] . '" autocomplete="off"' . ($not_save_photos ? '' : ' checked') . '> Photos</label> <span class="fmb-bot-status-checkbox-message"></span></div>'; 41 $html .= '<div class="fmb-bot-status-group"><label for="save_videos"><input type="checkbox" class="fmb-bot-status-checkbox" id="save_videos" value="' . $item['fmb_bot_token'] . '" autocomplete="off"' . ($not_save_videos ? '' : ' checked') . '> Videos</label> <span class="fmb-bot-status-checkbox-message"></span></div>'; 42 43 return $html; 26 44 default: 27 45 return print_r($item, true); //Show the whole array for troubleshooting purposes … … 35 53 'fmb_bot_name' => __('Name', 'fotki-media-bot'), 36 54 'fmb_bot_service' => __('Service', 'fotki-media-bot'), 37 'fmb_bot_token' => __('Token', 'fotki-media-bot') 55 'fmb_bot_token' => __('Token', 'fotki-media-bot'), 56 'fmb_bot_not_save_media_types' => __('Store media type', 'fotki-media-bot'), 38 57 ]; 39 58 … … 43 62 public function column_fmb_bot_name($item) 44 63 { 45 $actions = [ 46 //'edit' => sprintf('<a href="?page=%s&action=%s&book=%s">Edit</a>',$_REQUEST['page'],'edit',$item['fmb_bot_token']), 47 'delete' => sprintf('<a href="?page=%s&action=%s&token=%s">Delete</a>', esc_attr($_REQUEST['page']), 'delete', esc_attr($item['fmb_bot_token'])), 48 'disable_webhook' => sprintf('<a href="?page=%s&action=%s&token=%s">Disable webhook</a>', esc_attr($_REQUEST['page']), 'disable_webhook', esc_attr($item['fmb_bot_token'])), 49 'enable_webhook' => sprintf('<a href="?page=%s&action=%s&token=%s">Enable webhook</a>', esc_attr($_REQUEST['page']), 'enable_webhook', esc_attr($item['fmb_bot_token'])), 50 ]; 64 $is_bot_active = FotkiMediaBot_Telegram::is_webhook_enabled($item['fmb_bot_token']); 51 65 52 return sprintf('%1$s %2$s', esc_attr($item['fmb_bot_name']), $this->row_actions($actions)); 66 $actions['delete'] = sprintf('<a href="?page=%s&action=%s&token=%s">Delete</a>', esc_attr($_REQUEST['page']), 'delete', esc_attr($item['fmb_bot_token'])); 67 68 if ($is_bot_active) { 69 $actions['disable_webhook'] = sprintf('<a href="?page=%s&action=%s&token=%s">Disable webhook</a>', esc_attr($_REQUEST['page']), 'disable_webhook', esc_attr($item['fmb_bot_token'])); 70 } else { 71 $actions['enable_webhook'] = sprintf('<a href="?page=%s&action=%s&token=%s">Enable webhook</a>', esc_attr($_REQUEST['page']), 'enable_webhook', esc_attr($item['fmb_bot_token'])); 72 } 73 74 $status_html = '<span class="fmb-bot-status ' . ($is_bot_active ? 'enabled' : 'disabled') . '" title="' . ($is_bot_active ? __('Bot enabled', 'fotki-media-bot') : __('Bot disabled', 'fotki-media-bot')) . '"> </span>'; 75 76 return sprintf('%1$s %2$s', $status_html . " " . esc_attr($item['fmb_bot_name']), $this->row_actions($actions)); 53 77 } 54 78 … … 63 87 $bots = get_option(FotkiMediaBot::FOTKI_MEDIA_BOT_PREFIX . 'bots'); 64 88 65 if (!empty($bots)) {66 foreach ($bots as &$bot) {67 foreach ($bot as $key => $value) {68 $bot[$key] = esc_attr($value);69 }70 }71 }72 73 89 $this->items = $bots; 74 90 } -
fotki-media-bot/trunk/class.telegram.php
r1859835 r1861487 38 38 } 39 39 40 public static function get_webhook_info($bot_token) 41 { 42 $url = 'https://' . self::TELEGRAM_API_URL . '/bot' . $bot_token . '/getWebhookInfo'; 43 44 $response = wp_remote_get($url); 45 $result = wp_remote_retrieve_body($response); 46 47 if ($result) { 48 return json_decode($result, true); 49 } 50 51 return false; 52 } 53 54 public static function is_webhook_enabled($bot_token) { 55 $bot_webhook_info = self::get_webhook_info($bot_token); 56 57 if ($bot_webhook_info['ok']) { 58 return $bot_webhook_info['result']['url']; 59 } 60 61 return false; 62 } 63 40 64 public static function get_telegram_photo($bot_token, $data) 41 65 { … … 47 71 48 72 $photo_data['chat_id'] = sanitize_text_field($data['message']['chat']['id']); 49 $photo_data['chat_title'] = sanitize_text_field($data['message']['chat']['title']);73 $photo_data['chat_title'] = !empty($data['message']['chat']['title']) ? sanitize_text_field($data['message']['chat']['title']) : ''; 50 74 51 75 // get last photo element (last is most bigger photo) … … 74 98 75 99 $photo_data['chat_id'] = sanitize_text_field($data['message']['chat']['id']); 76 $photo_data['chat_title'] = sanitize_text_field($data['message']['chat']['title']);100 $photo_data['chat_title'] = !empty($data['message']['chat']['title']) ? sanitize_text_field($data['message']['chat']['title']) : ''; 77 101 78 // get last photo element (last is most bigger photo)79 102 $document = $data['message']['document']; 80 103 $file_id = $document['file_id']; -
fotki-media-bot/trunk/fotki-media-bot.php
r1859835 r1861487 3 3 Plugin Name: Fotki Media Bot 4 4 Plugin URI: https://agency.fotki.com/wordpress-plugins/fotki-media-bot/ 5 Description: Fotki Media Bot allows saves your photos from your chats (currently we only support Telegram messenger) to WordPress. It also creates daily posts in your Posts and puts your photosthere. This plugin is in beta, please report to us any issues, we will try to take care of them.6 Version: 0. 55 Description: Fotki Media Bot allows saves your media from your chats (currently we only support Telegram messenger) to WordPress. It also creates daily posts in your Posts and puts your media there. This plugin is in beta, please report to us any issues, we will try to take care of them. 6 Version: 0.6 7 7 Author: FotkiAgency 8 8 Author URI: https://agency.fotki.com/ … … 16 16 17 17 if (!class_exists('FotkiMediaBot')) { 18 register_activation_hook(__FILE__, ['FotkiMediaBot', 'fmb_install']); 19 //register_deactivation_hook(__FILE__, ['FotkiMediaBot', 'on_deactivation']); 20 register_uninstall_hook(__FILE__, ['FotkiMediaBot', 'fmb_uninstall']); 21 18 22 class FotkiMediaBot 19 23 { … … 37 41 public function __construct() 38 42 { 39 if (is_admin()) {40 register_activation_hook(__FILE__, [$this, 'fmb_install']);41 register_uninstall_hook(__FILE__, 'fmb_uninstall');42 43 add_action('admin_menu', [$this, 'fmb_page_links']);44 45 add_filter('attachment_fields_to_edit', [$this, 'add_image_attachment_fields_to_edit'], 10, 2);46 }47 48 43 add_filter('query_vars', [$this, 'fmb_query_vars']); 49 44 add_action('parse_request', [$this, 'fmb_parse_request']); 50 45 51 46 add_shortcode('fotki_media_bot', [$this, 'fmb_shortcode']); 52 } 53 54 public function fmb_install() 47 48 if (is_admin()) { 49 add_action('admin_menu', [$this, 'fmb_page_links']); 50 51 add_filter('attachment_fields_to_edit', [$this, 'add_image_attachment_fields_to_edit'], 10, 2); 52 53 add_action('admin_enqueue_scripts', [$this, 'register_plugin_js_and_styles']); 54 } 55 56 add_action('wp_ajax_fmb_store_media_type_options', [$this, 'store_media_type_options_ajax']); 57 } 58 59 public static function fmb_install() 55 60 { 56 61 global $wpdb; … … 81 86 dbDelta($sql); 82 87 83 add_option( 'fotki_media_bot_db_version', self::FOTKI_MEDIA_BOT_DB_VERSION);88 add_option(self::FOTKI_MEDIA_BOT_PREFIX . 'db_version', self::FOTKI_MEDIA_BOT_DB_VERSION); 84 89 } 85 90 } … … 94 99 } 95 100 96 public function fmb_uninstall()101 public static function fmb_uninstall() 97 102 { 98 103 global $wpdb; 99 104 105 // if we have some bots then need disable this bots that they not send to site anything 106 $bots = get_option(self::FOTKI_MEDIA_BOT_PREFIX . 'bots'); 107 108 if (!empty($bots)) { 109 foreach ($bots as &$bot) { 110 foreach ($bot as $key => $value) { 111 if ($key === 'fmb_bot_token') { 112 FotkiMediaBot_Telegram::delete_webhook($value); 113 } 114 } 115 } 116 } 117 118 // drop table if exists 100 119 $sql = 'DROP TABLE IF EXISTS ' . $wpdb->prefix . self::FOTKI_MEDIA_BOT_BOTS_TABLE_NAME; 101 120 $wpdb->query($sql); 102 121 103 delete_option('fotki_media_bot_db_version'); 104 delete_option(self::FOTKI_MEDIA_BOT_PREFIX . 'callback_id'); 105 delete_option(self::FOTKI_MEDIA_BOT_PREFIX . 'bots'); 122 // find all options created by plugin and remove them all 123 $all_options = wp_load_alloptions(); 124 125 foreach ($all_options as $name => $value) { 126 if (stristr($name,self::FOTKI_MEDIA_BOT_PREFIX)) { 127 delete_option($name); 128 } 129 } 106 130 } 107 131 … … 161 185 } 162 186 187 public function register_plugin_js_and_styles() { 188 wp_register_style(self::FOTKI_MEDIA_BOT_SLUG.'-main-css',plugin_dir_url(__FILE__) . 'admin/css/fotki_media_bot.css'); 189 wp_enqueue_style(self::FOTKI_MEDIA_BOT_SLUG.'-main-css'); 190 191 wp_register_script(self::FOTKI_MEDIA_BOT_SLUG.'-main-js', plugin_dir_url(__FILE__) . 'admin/js/fotki_media_bot.js', ['jquery'], '', TRUE); 192 wp_localize_script(self::FOTKI_MEDIA_BOT_SLUG.'-main-js', 'fotki_media_bot_data', ['ajax_url' => admin_url('admin-ajax.php')]); 193 wp_enqueue_script(self::FOTKI_MEDIA_BOT_SLUG.'-main-js'); 194 } 195 196 function store_media_type_options_ajax() { 197 $debug = []; 198 $success = 0; 199 200 $bot_token = !empty($_POST['bot_token']) ? sanitize_text_field($_POST['bot_token']) : ''; 201 $media_type = !empty($_POST['media_type']) ? sanitize_text_field($_POST['media_type']) : ''; 202 $status = !empty($_POST['status']) ? sanitize_text_field($_POST['status']) : ''; 203 204 if (!empty($bot_token) && !empty($media_type)) { 205 206 if ($media_type === 'photos' || $media_type === 'videos') { 207 208 $bots = get_option(self::FOTKI_MEDIA_BOT_PREFIX . 'bots'); 209 210 if (!empty($bots)) { 211 212 $i = 0; 213 214 foreach ($bots as &$bot) { 215 foreach ($bot as $key => $value) { 216 if ($key === 'fmb_bot_token' && $value === $bot_token) { 217 $bots[$i]['fmb_bot_not_save_media_types'][$media_type] = $status; 218 } 219 } 220 $i++; 221 } 222 223 if (update_option(self::FOTKI_MEDIA_BOT_PREFIX . 'bots', $bots)) { 224 $success = 1; 225 } else { 226 $success = 0; 227 } 228 } else { 229 $success = 0; 230 } 231 } 232 } else { 233 $success = 0; 234 } 235 236 die(json_encode(['success' => $success, 'messages' => $debug])); 237 } 238 163 239 public function fmb_main_page() 164 240 { … … 170 246 global $wpdb; 171 247 172 ?> 173 <div class="wrap"> 174 <h1><?php echo get_admin_page_title(); ?></h1> 175 <?php 176 // echo '<div>Callback ID: ' . get_option(self::FOTKI_MEDIA_BOT_PREFIX . 'callback_id') . '</div>'; 177 178 if (isset($_POST['bot_submited'])) { 179 $bot_name = sanitize_text_field($_POST['bot_name']); 180 $bot_service = sanitize_text_field($_POST['bot_service']); 181 $bot_token = sanitize_text_field($_POST['bot_token']); 182 183 if ($bot_name && $bot_service && $bot_token) { 184 $bot_options = [ 185 'fmb_bot_name' => $bot_name, 186 'fmb_bot_service' => $bot_service, 187 'fmb_bot_token' => $bot_token, 188 ]; 189 } 190 191 $set_webhook = FotkiMediaBot_Telegram::set_webhook($bot_token, $this->get_callback_url()); 192 193 if ($set_webhook['ok']) { 194 if (update_option(self::FOTKI_MEDIA_BOT_PREFIX . 'bots', [$bot_options])) { 195 ?> 196 <div class="updated"><p><strong><?php _e("Bot added."); ?></strong></p> 197 </div> 198 <?php 199 } else { 200 ?> 201 <div class="error"><p><strong><?php _e("Bot not saved."); ?></strong></p></div> 202 <?php 203 } 204 } else { 205 ?> 206 <div class="error"><p> 207 <strong><?php _e("Bot not saved. Message from API: \"" . $set_webhook["description"] . "\""); ?></strong> 208 </p></div> 209 <?php 210 } 211 212 $this->show_bots(); 213 } elseif (isset($_GET['action']) && $_GET['action'] === 'delete') { 214 215 if (isset($_GET['token'])) { 216 $token = sanitize_text_field($_GET['token']); 217 } 218 219 if (!empty($token)) { 220 $bots = get_option(self::FOTKI_MEDIA_BOT_PREFIX . 'bots'); 221 222 if (!empty($bots)) { 223 224 $i = 0; 225 226 foreach ($bots as &$bot) { 227 foreach ($bot as $key => $value) { 228 if ($key === 'fmb_bot_token' && $value === $token) { 229 unset($bots[$i]); 230 } 231 } 232 $i++; 233 } 234 235 if (update_option(self::FOTKI_MEDIA_BOT_PREFIX . 'bots', $bots)) { 248 if (!empty(get_option(self::FOTKI_MEDIA_BOT_PREFIX . 'callback_id'))) { 249 ?> 250 <div class="wrap"> 251 <h1><?php echo get_admin_page_title(); ?></h1> 252 <?php 253 254 255 if (isset($_POST['bot_submited'])) { 256 $bot_name = sanitize_text_field($_POST['bot_name']); 257 $bot_service = sanitize_text_field($_POST['bot_service']); 258 $bot_token = sanitize_text_field($_POST['bot_token']); 259 260 if ($bot_name && $bot_service && $bot_token) { 261 $bot_options = [ 262 'fmb_bot_name' => $bot_name, 263 'fmb_bot_service' => $bot_service, 264 'fmb_bot_token' => $bot_token, 265 ]; 266 } 267 268 $set_webhook = FotkiMediaBot_Telegram::set_webhook($bot_token, $this->get_callback_url()); 269 270 if ($set_webhook['ok']) { 271 if (update_option(self::FOTKI_MEDIA_BOT_PREFIX . 'bots', [$bot_options])) { 236 272 ?> 237 <div class="updated"><p><strong><?php _e("Bot removed."); ?></strong></p>273 <div class="updated"><p><strong><?php _e("Bot added."); ?></strong></p> 238 274 </div> 239 275 <?php 240 276 } else { 241 277 ?> 242 <div class="error"><p><strong><?php _e("Bot not removed."); ?></strong></p></div>278 <div class="error"><p><strong><?php _e("Bot not saved."); ?></strong></p></div> 243 279 <?php 244 280 } 245 } 246 } 247 248 $this->show_default_main_page(); 249 } elseif (isset($_GET['action']) && $_GET['action'] === 'disable_webhook') { 250 251 if (isset($_GET['token'])) { 252 $token = sanitize_text_field($_GET['token']); 253 } 254 255 if (!empty($token)) { 256 $bots = get_option(self::FOTKI_MEDIA_BOT_PREFIX . 'bots'); 257 258 if (!empty($bots)) { 259 260 $i = 0; 261 $hook_disabled = false; 262 263 foreach ($bots as &$bot) { 264 foreach ($bot as $key => $value) { 265 if ($key === 'fmb_bot_token' && $value === $token) { 266 if (FotkiMediaBot_Telegram::delete_webhook($token)) { 267 $hook_disabled = true; 281 } else { 282 ?> 283 <div class="error"><p> 284 <strong><?php _e("Bot not saved. Message from API: \"" . $set_webhook["description"] . "\""); ?></strong> 285 </p></div> 286 <?php 287 } 288 289 $this->show_bots(); 290 } elseif (isset($_GET['action']) && $_GET['action'] === 'delete') { 291 292 if (isset($_GET['token'])) { 293 $token = sanitize_text_field($_GET['token']); 294 } 295 296 if (!empty($token)) { 297 $bots = get_option(self::FOTKI_MEDIA_BOT_PREFIX . 'bots'); 298 299 if (!empty($bots)) { 300 301 $i = 0; 302 303 foreach ($bots as &$bot) { 304 foreach ($bot as $key => $value) { 305 if ($key === 'fmb_bot_token' && $value === $token) { 306 unset($bots[$i]); 268 307 } 269 308 } 309 $i++; 270 310 } 271 $i++; 311 312 if (update_option(self::FOTKI_MEDIA_BOT_PREFIX . 'bots', $bots)) { 313 ?> 314 <div class="updated"><p><strong><?php _e("Bot removed."); ?></strong></p> 315 </div> 316 <?php 317 } else { 318 ?> 319 <div class="error"><p><strong><?php _e("Bot not removed."); ?></strong></p></div> 320 <?php 321 } 272 322 } 273 274 if ($hook_disabled) { 275 ?> 276 <div class="updated"><p><strong><?php _e("Weebhook disabled."); ?></strong></p> 277 </div> 278 <?php 279 } else { 280 ?> 281 <div class="error"><p><strong><?php _e("Weebhook not disabled."); ?></strong></p></div> 282 <?php 283 } 284 } 285 } 286 287 $this->show_default_main_page(); 288 } elseif (isset($_GET['action']) && $_GET['action'] === 'enable_webhook') { 289 290 if (isset($_GET['token'])) { 291 $token = sanitize_text_field($_GET['token']); 292 } 293 294 if (!empty($token)) { 295 $bots = get_option(self::FOTKI_MEDIA_BOT_PREFIX . 'bots'); 296 297 if (!empty($bots)) { 298 299 $i = 0; 300 $hook_enabled = false; 301 302 foreach ($bots as &$bot) { 303 foreach ($bot as $key => $value) { 304 if ($key === 'fmb_bot_token' && $value === $token) { 305 $set_webhook = FotkiMediaBot_Telegram::set_webhook($token, $this->get_callback_url()); 306 307 if ($set_webhook['ok']) { 308 $hook_enabled = true; 323 } 324 325 $this->show_default_main_page(); 326 } elseif (isset($_GET['action']) && $_GET['action'] === 'disable_webhook') { 327 328 if (isset($_GET['token'])) { 329 $token = sanitize_text_field($_GET['token']); 330 } 331 332 if (!empty($token)) { 333 $bots = get_option(self::FOTKI_MEDIA_BOT_PREFIX . 'bots'); 334 335 if (!empty($bots)) { 336 337 $i = 0; 338 $hook_disabled = false; 339 340 foreach ($bots as &$bot) { 341 foreach ($bot as $key => $value) { 342 if ($key === 'fmb_bot_token' && $value === $token) { 343 if (FotkiMediaBot_Telegram::delete_webhook($token)) { 344 $hook_disabled = true; 345 } 309 346 } 310 347 } 348 $i++; 311 349 } 312 $i++; 350 351 if ($hook_disabled) { 352 ?> 353 <div class="updated"><p><strong><?php _e("Weebhook disabled."); ?></strong></p> 354 </div> 355 <?php 356 } else { 357 ?> 358 <div class="error"><p><strong><?php _e("Weebhook not disabled."); ?></strong></p> 359 </div> 360 <?php 361 } 313 362 } 314 315 if ($hook_enabled) { 316 ?> 317 <div class="updated"><p><strong><?php _e("Weebhook enabled."); ?></strong></p> 318 </div> 319 <?php 320 } else { 321 ?> 322 <div class="error"><p><strong><?php _e("Weebhook not enabled."); ?></strong></p></div> 323 <?php 363 } 364 365 $this->show_default_main_page(); 366 } elseif (isset($_GET['action']) && $_GET['action'] === 'enable_webhook') { 367 368 if (isset($_GET['token'])) { 369 $token = sanitize_text_field($_GET['token']); 370 } 371 372 if (!empty($token)) { 373 $bots = get_option(self::FOTKI_MEDIA_BOT_PREFIX . 'bots'); 374 375 if (!empty($bots)) { 376 377 $i = 0; 378 $hook_enabled = false; 379 380 foreach ($bots as &$bot) { 381 foreach ($bot as $key => $value) { 382 if ($key === 'fmb_bot_token' && $value === $token) { 383 $set_webhook = FotkiMediaBot_Telegram::set_webhook($token, $this->get_callback_url()); 384 385 if ($set_webhook['ok']) { 386 $hook_enabled = true; 387 } 388 } 389 } 390 $i++; 391 } 392 393 if ($hook_enabled) { 394 ?> 395 <div class="updated"><p><strong><?php _e("Weebhook enabled."); ?></strong></p> 396 </div> 397 <?php 398 } else { 399 ?> 400 <div class="error"><p><strong><?php _e("Weebhook not enabled."); ?></strong></p> 401 </div> 402 <?php 403 } 324 404 } 325 405 } 406 407 $this->show_default_main_page(); 408 409 } else { 410 $this->show_default_main_page(); 326 411 } 327 328 $this->show_default_main_page(); 329 330 } else { 331 $this->show_default_main_page(); 332 } 333 ?> 334 335 336 </div> 337 <?php 412 ?> 413 414 415 </div> 416 <?php 417 } else { 418 echo '<div class="wrap">There is no callback ID. Please try re-activate plugin and if problem still exist please contact us.</div>'; 419 } 338 420 } 339 421 … … 351 433 echo '<h1>' . get_admin_page_title() . '</h1>'; 352 434 353 $wp_debug_log_file_path = plugin_dir_path(__FILE__).'incoming_data_from_bots.log';435 $wp_debug_log_file_path = get_home_path() . 'wp-content/fotki-media-bot-' . get_option(self::FOTKI_MEDIA_BOT_PREFIX . 'callback_id') . '.log'; 354 436 355 437 if (file_exists($wp_debug_log_file_path)) { … … 401 483 402 484 <p> 403 Now you can chat with your Bot in Telegram Messenger and send photos to it, and Bot will save these photos to your WordPress Media Library. Also, you can add your Bot to any of your group chats and Bot will save to WordPress Media Library all photosyou send to each other on Telegram.485 Now you can chat with your Bot in Telegram Messenger and send media to it, and Bot will save these media to your WordPress Media Library. Also, you can add your Bot to any of your group chats and Bot will save to WordPress Media Library all media you send to each other on Telegram. 404 486 </p> 405 487 … … 502 584 503 585 # if title eq date forma, took date from title, if not - take date from post_date 504 # if user will create post with own date and with our shortocode, then he wanna show photosfor this date505 # but post date is today and will show only photosfor post creation date586 # if user will create post with own date and with our shortocode, then he wanna show media for this date 587 # but post date is today and will show only media for post creation date 506 588 if ($post->post_title === $this->fmb_validate_date($post->post_title, $date_format)) { 507 589 $parsed_date = date_parse($post->post_title); … … 565 647 { 566 648 567 $is_ photo_by_fmb = get_post_meta($post->ID, '_' . self::FOTKI_MEDIA_BOT_PREFIX . 'uploaded_by_fmb', true);568 if (!empty($is_ photo_by_fmb)) {649 $is_media_by_fmb = get_post_meta($post->ID, '_' . self::FOTKI_MEDIA_BOT_PREFIX . 'uploaded_by_fmb', true); 650 if (!empty($is_media_by_fmb)) { 569 651 $form_fields[self::FOTKI_MEDIA_BOT_PREFIX . 'uploaded_by_fmb'] = [ 570 652 'label' => __("By"), … … 610 692 } 611 693 612 $ is_gif = get_post_meta($post->ID, '_' . self::FOTKI_MEDIA_BOT_PREFIX . 'is_gif', true);613 if (!empty($ is_gif)) {614 $form_fields[self::FOTKI_MEDIA_BOT_PREFIX . ' is_gif'] = [615 'label' => __(" Is GIF"),694 $media_type = get_post_meta($post->ID, '_' . self::FOTKI_MEDIA_BOT_PREFIX . 'media_type', true); 695 if (!empty($media_type)) { 696 $form_fields[self::FOTKI_MEDIA_BOT_PREFIX . 'media_type'] = [ 697 'label' => __("Media type"), 616 698 'input' => 'html', 617 'html' => '<input type="text" readonly="readonly" value=" yes" />'699 'html' => '<input type="text" readonly="readonly" value="' . esc_attr($media_type) . '" />' 618 700 ]; 619 701 } -
fotki-media-bot/trunk/readme.txt
r1859835 r1861487 3 3 Tags: bot, telegram, api, media, archiving, fotki, chat, messenger, gallery, backup 4 4 Requires at least: 4.0 5 Tested up to: 4.9. 46 Stable tag: 0. 55 Tested up to: 4.9.5 6 Stable tag: 0.6 7 7 License: GPLv2 or later 8 8 9 Fotki Media Bot saves your photosfrom your chats (currently we only support Telegram messenger) to WordPress.9 Fotki Media Bot saves your media from your chats (currently we only support Telegram messenger) to WordPress. 10 10 11 11 == Description == 12 Fotki Media Bot saves your photosfrom your messenger chats or chat groups to WordPress Media Library.12 Fotki Media Bot saves your media from your messenger chats or chat groups to WordPress Media Library. 13 13 Fotki Media Bot currently supports only [Telegram Messenger](https://telegram.org/). 14 Also it creates daily posts in your Posts and puts your photos there from your photoswhich you send and receive on Telegram Messenger.14 Also it creates daily posts in your Posts and puts your media there from your media which you send and receive on Telegram Messenger. 15 15 16 16 This plugin is in beta, please report to us any issues, we will try to take care of them. … … 24 24 3) Send "/setprivacy" command to BotFather using a Telegram and disable privacy (without this step, Fotki Media Bot will not be able to get media from your chats). 25 25 26 Now, you can send photos to your Telegram Bot, and all photoswill be automatically saved into your WordPress. And you can add your Bot to your group chats as well!26 Now, you can send media to your Telegram Bot, and all media will be automatically saved into your WordPress. And you can add your Bot to your group chats as well! 27 27 28 28 == Changelog == 29 30 = 0.6 = 31 * fixed minor bugs 32 * added possibility to save or not save some media types from bot, like photos or video 33 * added small features that plugin was more friendly 29 34 30 35 = 0.5 =
Note: See TracChangeset
for help on using the changeset viewer.