Plugin Directory

Changeset 2142275


Ignore:
Timestamp:
08/20/2019 03:30:52 AM (7 years ago)
Author:
smartnewsdev
Message:

expose sponsored link

Location:
smartformat/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • smartformat/trunk/admin-sponsored-links.js

    r2142274 r2142275  
    1010  }
    1111
     12  $(".add-sponsored-link").prop("disabled", container.childElementCount === 2);
     13
    1214  $(document).on("click", ".add-sponsored-link", function(e) {
    1315    var link = {
     
    1921    };
    2022    container.append(buildSponsoredLink(container.childElementCount, link));   
     23    $(".add-sponsored-link").prop("disabled", container.childElementCount === 2);
    2124  });
    2225
     
    2427    var id = e.target.id.replace("-remove", "");
    2528    document.getElementById(id).remove();
     29    $(".add-sponsored-link").prop("disabled", container.childElementCount === 2);
    2630  });
    2731});
  • smartformat/trunk/admin-sponsored-links.php

    r2142274 r2142275  
    22  $sponsoredLinks = get_option(SMARTFORMAT__SPONSORED_LINKS);
    33  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      }
    611    }
    712  }
     
    1419    'selectThumbnail' => __('Select thumbnail'),
    1520    'remove' => __('Remove'),
    16     'sponsoredLinks' => wp_json_encode($sponsoredLinks)
     21    'sponsoredLinks' => wp_json_encode($sponsored_links)
    1722  );
    1823  wp_register_script('admin-sponsored-links', plugin_dir_url(__FILE__) . 'admin-sponsored-links.js', array('jquery'));
  • smartformat/trunk/class.smartformat-admin.php

    r2142274 r2142275  
    103103
    104104  public function sanitize_logo_image($input) {
    105     return $input;
     105    return intval($input);
    106106  }
    107107
    108108  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    );
    109126    return $input;
    110127  }
    111128
    112129  public function sanitize_analytics($input) {
    113     return $input;
     130    return force_balance_tags($input);
    114131  }
    115132
    116133  public function sanitize_adcontent($input) {
    117     return $input;
     134    return force_balance_tags($input);
    118135  }
    119136
    120137  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;
    122185  }
    123186}
  • smartformat/trunk/class.smartformat-feed.php

    r2142269 r2142275  
    99    add_feed('smartformat', array($this, 'render'));
    1010    add_filter('feed_content_type', array($this, 'content_type'), 10, 2);
     11    add_filter('the_post', 'reset_sponsored_link');
    1112  }
    1213
     
    2425}
    2526
     27function 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
    2644function the_smartformat_ttl($default_ttl = 15) {
    2745  $ttl = get_option(SMARTFORMAT__TTL);
     
    3048
    3149function 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
     60function get_smartformat_sponsored_link() {
     61  global $sponsored_links;
     62  global $sponsored_links_index;
     63
     64  return $sponsored_links[$sponsored_links_index++];
    3365}
    3466
  • smartformat/trunk/feed.php

    r2142270 r2142275  
    7575            <?php
    7676            while ( have_smartformat_sponsored_links() ) :
    77                 the_smartformat_sponsored_link();
     77                $sponsored_link = get_smartformat_sponsored_link();
    7878            ?>
    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']) ?>" />
    8084            <?php endwhile; ?>
    8185            <?php if ( has_smartformat_adcontent() ) : ?>
Note: See TracChangeset for help on using the changeset viewer.