Changeset 3134445
- Timestamp:
- 08/12/2024 06:10:27 PM (20 months ago)
- Location:
- tg-instantview/trunk
- Files:
-
- 4 edited
-
readme.txt (modified) (2 diffs)
-
tg-admin.php (modified) (5 diffs)
-
tg-display.php (modified) (1 diff)
-
tg-instantview.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tg-instantview/trunk/readme.txt
r3069148 r3134445 3 3 Tags: telegram 4 4 Requires at least: 5.0 5 Tested up to: 6. 46 Stable tag: 1. 35 Tested up to: 6.6 6 Stable tag: 1.4 7 7 Requires PHP: 7.0 8 8 License: GPLv3 … … 56 56 == Changelog == 57 57 58 = 1.4 = 59 * Plugin now provides full set of OpenGraph meta information for post and does not require SEO plugins anymore 60 * Add option to show/hide post published date 61 * Add option to show/hide post author 62 58 63 = 1.3 = 59 64 * Fixes from Wordpress review: template html, prefixes, license -
tg-instantview/trunk/tg-admin.php
r3069148 r3134445 42 42 { 43 43 // Set class property 44 $this->options = get_option( 'tgiv_instantview_render');44 $this->options = tgiv_options(); 45 45 46 46 ?> … … 84 84 'tgiv_render_options' // Section 85 85 ); 86 add_settings_field( 87 'tgiv_display_date', // ID 88 'Display post date?', // Title 89 array( $this, 'display_date_callback' ), // Callback 90 'tgiv-instantview-setting-admin', // Page 91 'tgiv_render_options' // Section 92 ); 93 add_settings_field( 94 'tgiv_display_author', // ID 95 'Display post author?', // Title 96 array( $this, 'display_author_callback' ), // Callback 97 'tgiv-instantview-setting-admin', // Page 98 'tgiv_render_options' // Section 99 ); 86 100 } 87 101 … … 94 108 { 95 109 $new_input = array(); 96 if ( isset( $input['tgiv_channel_name'] )) {110 if (isset($input['tgiv_channel_name'])) { 97 111 $channel_name = $input['tgiv_channel_name']; 98 112 $channel_name = trim($channel_name); … … 105 119 $new_input['tgiv_channel_name'] = $channel_name; 106 120 } 121 $new_input['tgiv_display_date'] = isset($input['tgiv_display_date']); 122 $new_input['tgiv_display_author'] = isset($input['tgiv_display_author']); 107 123 return $new_input; 108 124 } … … 126 142 ); 127 143 } 144 public function display_date_callback() 145 { 146 printf( 147 '<input type="checkbox" id="tgiv_display_date" name="tgiv_instantview_render[tgiv_display_date]" value="ON" %s/>', 148 $this->options['tgiv_display_date'] ? 'checked="checked"' : '' 149 ); 150 } 151 public function display_author_callback() 152 { 153 printf( 154 '<input type="checkbox" id="tgiv_display_author" name="tgiv_instantview_render[tgiv_display_author]" value="ON" %s/>', 155 $this->options['tgiv_display_author'] ? 'checked="checked"' : '' 156 ); 157 } 128 158 } 129 159 -
tg-instantview/trunk/tg-display.php
r3069148 r3134445 8 8 exit; 9 9 } 10 $tg_options = get_option( 'tgiv_instantview_render' ); 10 // Get Plugin settings array 11 $tgiv_options = tgiv_options(); 12 // Check for default values 13 14 // Get default WP meta tags, going to be displayed for this post 15 $tgiv_wp_meta = tgiv_extract_meta(); 16 17 // Prepare list of meta tags, rendered for preview 18 $tgiv_meta = array(); 19 // Required to render: 20 $tgiv_meta['tg:site_verification'] = 'g7j8/rPFXfhyrq5q0QQV7EsYWv4='; 21 // Channel name? 22 if ($tgiv_options['tgiv_channel_name']) { 23 $tgiv_meta['telegram:channel'] = $tgiv_options['tgiv_channel_name']; 24 } 25 26 // Published date: article:published_time 27 if ($tgiv_options['tgiv_display_date']) { 28 $tgiv_meta['article:published_time'] = get_the_date('c'); 29 } else { 30 // Date disabled, display none 31 $tgiv_meta['article:published_time'] = ''; 32 } 33 // Author: article:author 34 if ($tgiv_options['tgiv_display_author']) { 35 $tgiv_meta['article:author'] = get_the_author(); 36 } else { 37 // Author disabled, display none 38 $tgiv_meta['article:author'] = ''; 39 } 40 // Image: og:image 41 if (isset($tgiv_wp_meta['og:image'])) { 42 $tgiv_meta['og:image'] = $tgiv_wp_meta['og:image']; 43 } else { 44 // If not set, get from WP 45 $tgiv_meta['og:image'] = get_the_post_thumbnail_url(); 46 } 47 // Site name: og:site_name 48 $tgiv_meta['og:site_name'] = get_bloginfo('name'); 49 // Title: og:title 50 $tgiv_meta['og:title'] = get_the_title(); 51 // Short text: og:description 52 if (isset($tgiv_wp_meta['og:description'])) { 53 $tgiv_meta['og:description'] = $tgiv_wp_meta['og:description']; 54 } else { 55 // If not set, fill with excert 56 $tgiv_meta['og:description'] = wp_strip_all_tags(get_the_excerpt()); 57 } 58 11 59 ?> 12 60 <!DOCTYPE html> 13 61 <html <?php language_attributes(); ?>> 14 62 <head> 15 <meta charset="<?php bloginfo('charset'); ?>" >16 <?php if (isset($tg_options['tgiv_channel_name']) && strlen($tg_options['tgiv_channel_name'])) { ?>17 <meta property=" telegram:channel" content="<?php echo esc_html($tg_options['tgiv_channel_name']); ?>">63 <meta charset="<?php bloginfo('charset'); ?>" /> 64 <?php foreach ($tgiv_meta as $tgiv_meta_key => $tgiv_meta_value) { ?> 65 <meta property="<?php echo esc_html($tgiv_meta_key); ?>" content="<?php echo esc_html($tgiv_meta_value); ?>" /> 18 66 <?php } ?> 19 <meta property="tg:site_verification" content="g7j8/rPFXfhyrq5q0QQV7EsYWv4=">20 <?php wp_head(); ?>21 67 </head> 22 68 -
tg-instantview/trunk/tg-instantview.php
r3069148 r3134445 4 4 Plugin URI: https://github.com/petrows/wp-tg-instantview 5 5 Description: Triggers Telegram InstantView for posts 6 Version: 1. 36 Version: 1.4 7 7 Author: Petro 8 8 Author URI: https://petro.ws/ … … 15 15 } 16 16 17 add_option('tgiv_instanview_channel_name', ''); 17 // Define options and defaults: 18 // Displayed Telegram channel name 19 add_option('tgiv_instantview_render', array()); 18 20 19 21 // Load admin settings … … 31 33 32 34 /* 35 Function to get and prepare default options for plugin 36 */ 37 function tgiv_options() { 38 $options = get_option( 'tgiv_instantview_render' ); 39 if (!isset($options['tgiv_channel_name'])) { 40 $options['tgiv_channel_name'] = ''; 41 } 42 if (!isset($options['tgiv_display_date'])) { 43 $options['tgiv_display_date'] = true; 44 } else { 45 $options['tgiv_display_date'] = boolval($options['tgiv_display_date']); 46 } 47 if (!isset($options['tgiv_display_author'])) { 48 $options['tgiv_display_author'] = true; 49 } else { 50 $options['tgiv_display_author'] = boolval($options['tgiv_display_author']); 51 } 52 return $options; 53 } 54 55 /* 56 Function to get prepared meta HTML tags from "normal" WP output. 57 We have to use ob_* functions to get HTML, as seems to be there is 58 no better way to get rendered tags from SEO plugins and etc. 59 */ 60 function tgiv_extract_meta() { 61 ob_start(); 62 wp_head(); 63 $html_output = ob_get_contents(); 64 ob_end_clean(); 65 $meta_out = array(); 66 // Find all meta tags 67 if (preg_match_all('/<meta([^>]+)\/>/Uuims', $html_output, $out)) { 68 $html = ''; 69 foreach($out[1] as $meta_contents) { 70 // Extract HTML attributes 71 $meta_name = ''; 72 $meta_value = ''; 73 if (preg_match('/property="([^"]*)"/Uuims', $meta_contents, $meta_v)) { 74 $meta_name = $meta_v[1]; 75 } else if (preg_match('/property=\'([^\']*)\'/Uuims', $meta_contents, $meta_v)) { 76 $meta_name = $meta_v[1]; 77 } 78 if (preg_match('/content="([^"]*)"/Uuims', $meta_contents, $meta_v)) { 79 $meta_value = $meta_v[1]; 80 } else if (preg_match('/content=\'([^\']*)\'/Uuims', $meta_contents, $meta_v)) { 81 $meta_value = $meta_v[1]; 82 } 83 if ($meta_name) { 84 $meta_out[$meta_name] = htmlspecialchars_decode($meta_value); 85 } 86 } 87 } 88 return $meta_out; 89 } 90 91 /* 33 92 Telegram InstantView does not expand built-in Gutenberg gallery, 34 93 with nested <figure> with other figures inside. More precise, it … … 38 97 display them as a nice built-in images gallery. 39 98 */ 40 function tgiv_extract_gallery($block_content) 41 { 99 function tgiv_extract_gallery($block_content) { 42 100 // Find all images 43 101 if (preg_match_all('/<img[^>]+\/>/', $block_content, $out)) {
Note: See TracChangeset
for help on using the changeset viewer.