Changeset 2142275
- Timestamp:
- 08/20/2019 03:30:52 AM (7 years ago)
- Location:
- smartformat/trunk
- Files:
-
- 5 edited
-
admin-sponsored-links.js (modified) (3 diffs)
-
admin-sponsored-links.php (modified) (2 diffs)
-
class.smartformat-admin.php (modified) (1 diff)
-
class.smartformat-feed.php (modified) (3 diffs)
-
feed.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
smartformat/trunk/admin-sponsored-links.js
r2142274 r2142275 10 10 } 11 11 12 $(".add-sponsored-link").prop("disabled", container.childElementCount === 2); 13 12 14 $(document).on("click", ".add-sponsored-link", function(e) { 13 15 var link = { … … 19 21 }; 20 22 container.append(buildSponsoredLink(container.childElementCount, link)); 23 $(".add-sponsored-link").prop("disabled", container.childElementCount === 2); 21 24 }); 22 25 … … 24 27 var id = e.target.id.replace("-remove", ""); 25 28 document.getElementById(id).remove(); 29 $(".add-sponsored-link").prop("disabled", container.childElementCount === 2); 26 30 }); 27 31 }); -
smartformat/trunk/admin-sponsored-links.php
r2142274 r2142275 2 2 $sponsoredLinks = get_option(SMARTFORMAT__SPONSORED_LINKS); 3 3 if ($sponsoredLinks) { 4 foreach ($sponsoredLinks as &$sponsoredLink) { 5 $sponsoredLink['thumbnail_attachment_url'] = wp_get_attachment_url($sponsoredLink['thumbnail_attachment_id']); 4 foreach ($sponsored_links as &$sponsored_link) { 5 $thumbnail_attachment_url = wp_get_attachment_url($sponsored_link['thumbnail_attachment_id']); 6 if ($thumbnail_attachment_url !== false) { 7 $sponsored_link['thumbnail_attachment_url'] = $thumbnail_attachment_url; 8 } else { 9 $sponsored_link['thumbnail_attachment_url'] = ''; 10 } 6 11 } 7 12 } … … 14 19 'selectThumbnail' => __('Select thumbnail'), 15 20 'remove' => __('Remove'), 16 'sponsoredLinks' => wp_json_encode($sponsored Links)21 'sponsoredLinks' => wp_json_encode($sponsored_links) 17 22 ); 18 23 wp_register_script('admin-sponsored-links', plugin_dir_url(__FILE__) . 'admin-sponsored-links.js', array('jquery')); -
smartformat/trunk/class.smartformat-admin.php
r2142274 r2142275 103 103 104 104 public function sanitize_logo_image($input) { 105 return $input;105 return intval($input); 106 106 } 107 107 108 108 public function sanitize_ttl($input) { 109 $options = array( 110 'options' => array( 111 'min_range' => 1, 112 'max_range' => 1440 113 ), 114 'flags' => FILTER_FLAG_ALLOW_OCTAL 115 ); 116 117 if (filter_var($input, FILTER_VALIDATE_INT, $options) !== false) { 118 return intval($input); 119 } 120 121 add_settings_error( 122 SMARTFORMAT__ADMIN_PAGE, 123 SMARTFORMAT__TTL, 124 __('Invalid TTL (1 - 1440)') 125 ); 109 126 return $input; 110 127 } 111 128 112 129 public function sanitize_analytics($input) { 113 return $input;130 return force_balance_tags($input); 114 131 } 115 132 116 133 public function sanitize_adcontent($input) { 117 return $input;134 return force_balance_tags($input); 118 135 } 119 136 120 137 public function sanitize_sponsored_links($input) { 121 return array_values($input); 138 $sorted = array_values($input); 139 140 foreach ($sorted as &$sponsoredLink) { 141 if ($sponsoredLink['thumbnail_attachment_id'] === '') { 142 add_settings_error( 143 SMARTFORMAT__ADMIN_PAGE, 144 SMARTFORMAT__SPONSORED_LINKS, 145 __('Thumbnail is required') 146 ); 147 } else { 148 $sponsoredLink['thumbnail_attachment_id'] = intval($sponsoredLink['thumbnail_attachment_id']); 149 } 150 151 if ($sponsoredLink['title'] === '') { 152 add_settings_error( 153 SMARTFORMAT__ADMIN_PAGE, 154 SMARTFORMAT__SPONSORED_LINKS, 155 __('Title is required') 156 ); 157 } 158 159 if ($sponsoredLink['advertiser'] === '') { 160 add_settings_error( 161 SMARTFORMAT__ADMIN_PAGE, 162 SMARTFORMAT__SPONSORED_LINKS, 163 __('Advertiser is required') 164 ); 165 } 166 167 if ($sponsoredLink['link'] === '') { 168 add_settings_error( 169 SMARTFORMAT__ADMIN_PAGE, 170 SMARTFORMAT__SPONSORED_LINKS, 171 __('Link is required') 172 ); 173 } 174 175 if (filter_var($sponsoredLink['link'], FILTER_VALIDATE_URL) === false) { 176 add_settings_error( 177 SMARTFORMAT__ADMIN_PAGE, 178 SMARTFORMAT__SPONSORED_LINKS, 179 __('Link must be URL') 180 ); 181 } 182 } 183 184 return $sorted; 122 185 } 123 186 } -
smartformat/trunk/class.smartformat-feed.php
r2142269 r2142275 9 9 add_feed('smartformat', array($this, 'render')); 10 10 add_filter('feed_content_type', array($this, 'content_type'), 10, 2); 11 add_filter('the_post', 'reset_sponsored_link'); 11 12 } 12 13 … … 24 25 } 25 26 27 function reset_sponsored_link() { 28 global $sponsored_links; 29 global $sponsored_links_index; 30 31 $sponsored_links = get_option(SMARTFORMAT__SPONSORED_LINKS); 32 foreach ($sponsored_links as &$sponsored_link) { 33 $thumbnail_attachment_url = wp_get_attachment_url($sponsored_link['thumbnail_attachment_id']); 34 if ($thumbnail_attachment_url !== false) { 35 $sponsored_link['thumbnail'] = $thumbnail_attachment_url; 36 } else { 37 $sponsored_link['thumbnail'] = ''; 38 } 39 } 40 41 $sponsored_links_index = 0; 42 } 43 26 44 function the_smartformat_ttl($default_ttl = 15) { 27 45 $ttl = get_option(SMARTFORMAT__TTL); … … 30 48 31 49 function have_smartformat_sponsored_links() { 32 return false; 50 global $sponsored_links; 51 global $sponsored_links_index; 52 53 if ($sponsored_links == null) { 54 reset_sponsored_link(); 55 } 56 57 return count($sponsored_links) > $sponsored_links_index; 58 } 59 60 function get_smartformat_sponsored_link() { 61 global $sponsored_links; 62 global $sponsored_links_index; 63 64 return $sponsored_links[$sponsored_links_index++]; 33 65 } 34 66 -
smartformat/trunk/feed.php
r2142270 r2142275 75 75 <?php 76 76 while ( have_smartformat_sponsored_links() ) : 77 the_smartformat_sponsored_link();77 $sponsored_link = get_smartformat_sponsored_link(); 78 78 ?> 79 <snf:sponsoredLink></snf:sponsoredLink> 79 <snf:sponsoredLink 80 title="<?php echo esc_attr($sponsored_link['title']) ?>" 81 link="<?php echo esc_attr($sponsored_link['link']) ?>" 82 thumbnail="<?php echo esc_attr($sponsored_link['thumbnail']) ?>" 83 advertiser="<?php echo esc_attr($sponsored_link['advertiser']) ?>" /> 80 84 <?php endwhile; ?> 81 85 <?php if ( has_smartformat_adcontent() ) : ?>
Note: See TracChangeset
for help on using the changeset viewer.