Changeset 1604073
- Timestamp:
- 02/26/2017 11:11:01 PM (9 years ago)
- Location:
- real-time-crowd/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (2 diffs)
-
real-time-crowd.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
real-time-crowd/trunk/readme.txt
r1292667 r1604073 3 3 Tags: realtime, real time, real-time, realtime crowd, real time crowd, real-time crowd, woocommerce 4 4 Requires at least: 3.6 5 Tested up to: 4. 3.16 Stable tag: 1. 55 Tested up to: 4.7.2 6 Stable tag: 1.6 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 30 30 31 31 == Changelog == 32 33 = 1.6 = 34 * Set default homepage title and image. 35 * Get picture of the first product in category if category image is not available, otherwise fallback to default image if exists on filesystem. 36 * set Display=none for iframe when the widget "Display" checkbox is not checked. 32 37 33 38 = 1.5 = -
real-time-crowd/trunk/real-time-crowd.php
r1292668 r1604073 4 4 Plugin URI: http://www.realtimecrowd.net/ 5 5 Description: Enables Real-Time Crowd tracking and generation on your WordPress site. 6 Version: 1. 56 Version: 1.6 7 7 Author: RealTimeCrowd.net 8 8 Author URI: http://www.realtimecrowd.net/ … … 88 88 <td> 89 89 <input name="rtc_display_widget" type="checkbox" value="1" <?php checked( '1', get_option( 'rtc_display_widget' ) ); ?> /> 90 <span class="description">Checking this will display the widget on every post and page of the site. (The widget also contains a small icon linking to RealTimeCrowd.net)</span>90 <span class="description">Checking this will display the widget on every post and page of the site.</span> 91 91 </td> 92 92 </tr> … … 162 162 { 163 163 $pageTitle = $cat->name; 164 $thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true ); 165 $pageImageUrl = wp_get_attachment_url( $thumbnail_id ); 166 167 $icon = plugin_dir_path(__FILE__)."category-icon.png"; 168 $icon = str_replace("/","\\",$icon); 169 if (empty($pageImageUrl) && file_exists($icon)) 170 { 171 $pageImageUrl = plugin_dir_url( __FILE__ ) . "category-icon.png"; 172 } 173 } 164 } 165 $pageImageUrl = getCategoryImageUrl($postId, $cat); 174 166 } 175 167 else if (is_product()) … … 179 171 { 180 172 $pageTitle = html_entity_decode(get_the_title($postId),ENT_QUOTES,'UTF-8'); 181 if (has_post_thumbnail($postId)) 182 { 183 $images = wp_get_attachment_image_src(get_post_thumbnail_id($postId), array(100, 100)); 184 if (count($images)>0) 185 { 186 $pageImageUrl = $images[0]; 187 } 188 } 189 else 190 { 191 $attachment_ids = $product->get_gallery_attachment_ids(); 192 if (count($attachment_ids)>0) 193 { 194 $pageImageUrl = wp_get_attachment_url($attachment_ids[0]); 195 } 196 } 197 198 $icon = plugin_dir_path(__FILE__)."product-icon.png"; 199 $icon = str_replace("/","\\",$icon); 200 if (empty($pageImageUrl) && file_exists($icon)) 201 { 202 $pageImageUrl = plugin_dir_url( __FILE__ ) . "product-icon.png"; 203 } 204 } 173 } 174 $pageImageUrl = getProductImageUrl($postId, $product); 205 175 } 206 176 } … … 224 194 else if (is_front_page() || is_home()) 225 195 { 226 $pageTitle = get_bloginfo('name'); 196 //$pageTitle = get_bloginfo('name'); 197 $pageTitle = "Homepage"; 227 198 $icon = plugin_dir_path(__FILE__)."home-icon.png"; 228 $icon = str_replace("/","\\",$icon);229 199 if (empty($pageImageUrl) && file_exists($icon)) 230 200 { … … 234 204 } 235 205 236 if (!empty($pageTitle) && ! empty($accountAlias) && !is_admin())206 if (!empty($pageTitle) && !is_admin()) 237 207 { 238 208 echo "<!--rtc code--> … … 263 233 } 264 234 } 235 function getProductImageUrl($postId, $product) 236 { 237 $pageImageUrl = ""; 238 if ($product) 239 { 240 if (has_post_thumbnail($postId)) 241 { 242 $images = wp_get_attachment_image_src(get_post_thumbnail_id($postId), array(100, 100)); 243 if (count($images)>0) 244 { 245 $pageImageUrl = $images[0]; 246 } 247 } 248 else 249 { 250 $attachment_ids = $product->get_gallery_attachment_ids(); 251 if (count($attachment_ids)>0) 252 { 253 $pageImageUrl = wp_get_attachment_url($attachment_ids[0]); 254 } 255 } 256 } 257 258 //if product didnt have image, try to set default image 259 $icon = plugin_dir_path(__FILE__)."product-icon.png"; 260 if (empty($pageImageUrl) && file_exists($icon)) 261 { 262 $pageImageUrl = plugin_dir_url( __FILE__ ) . "product-icon.png"; 263 } 264 return $pageImageUrl; 265 } 266 function getCategoryImageUrl($postId, $category) 267 { 268 $pageImageUrl = ""; 269 if ($category) 270 { 271 //try to get image of the category 272 $thumbnail_id = get_woocommerce_term_meta( $category->term_id, 'thumbnail_id', true ); 273 if ($thumbnail_id) 274 { 275 $pageImageUrl = wp_get_attachment_url( $thumbnail_id ); 276 } 277 278 //if category didnt have image try to get thumbnail of first product in this category 279 if (empty($pageImageUrl)) 280 { 281 //build our query 282 $query_args = array( 283 'meta_query' => array( 284 array( 285 'key' => '_visibility', 286 'value' => array( 'catalog', 'visible' ), 287 'compare' => 'IN' 288 ) 289 ), 290 'post_status' => 'publish', 291 'post_type' => 'product', 292 'posts_per_page' => 1, 293 'tax_query' => array( 294 array( 295 'field' => 'id', 296 'taxonomy' => 'product_cat', 297 'terms' => $category->term_id 298 ) 299 ), 300 'orderby' => 'date', 301 'sort_order' => 'desc' 302 ); 303 //Query DB 304 $products = get_posts( $query_args ); 305 //If matching products found 306 if($products && count($products)>0) 307 { 308 if (has_post_thumbnail($products[0]->ID)) 309 { 310 // check for a thumbnail 311 $images = wp_get_attachment_image_src(get_post_thumbnail_id($products[0]->ID), array(100, 100)); 312 if (count($images)>0) 313 { 314 $pageImageUrl = $images[0]; 315 } 316 } 317 else 318 { 319 //check for image of product 320 $attachment_ids = $products[0]->get_gallery_attachment_ids(); 321 if (count($attachment_ids)>0) 322 { 323 $pageImageUrl = wp_get_attachment_url($attachment_ids[0]); 324 } 325 } 326 } 327 } 328 } 329 330 //if category still doesnt have image, try to set default image 331 $icon = plugin_dir_path(__FILE__)."category-icon.png"; 332 if (empty($pageImageUrl) && file_exists($icon)) 333 { 334 $pageImageUrl = plugin_dir_url( __FILE__ ) . "category-icon.png"; 335 } 336 return $pageImageUrl; 337 } 265 338 /* Puts code on Wordpress pages */ 266 339 add_action('wp_footer', 'rtc_tracking_code');
Note: See TracChangeset
for help on using the changeset viewer.