Ejemplo n.º 1
0
 /**
  * Affix source to the content.
  *
  * @params  $content    The content.
  * @returns             The content with affixed source.
  */
 function source_affix_affix_sa_source($content)
 {
     $options = $this->options;
     if ($options) {
         extract($options);
     }
     $available_post_types_array = array_keys($sa_source_posttypes);
     $current_post_type = get_post_type(get_the_ID());
     if (!in_array($current_post_type, $available_post_types_array)) {
         return $content;
     }
     $sa_source = get_post_meta(get_the_ID(), 'sa_source', true);
     if ('' != $sa_source) {
         $links_array = source_affix_convert_meta_to_array($sa_source);
         $single_link = array();
         if (!empty($links_array) && is_array($links_array)) {
             foreach ($links_array as $key => $eachline) {
                 if (!empty($eachline['url'])) {
                     $lnk = '<a href="' . $eachline['url'] . '" ';
                     $lnk .= $sa_source_open_style == 'BLANK' ? ' target="_blank" ' : '';
                     $lnk .= ' >' . esc_attr($eachline['title']) . '</a>';
                 } else {
                     $lnk = esc_attr($eachline['title']);
                 }
                 $single_link[] = $lnk;
             }
         }
         $source_message = '<div class="sa-source-wrapper"><strong>' . $sa_source_title . '</strong>';
         switch ($sa_source_style) {
             case 'COMMA':
                 $source_message .= '<p class="news-source">' . implode(', ', $single_link) . '</p>';
                 break;
             case 'LIST':
                 if (!empty($single_link)) {
                     $source_message .= '<ul class="list-source-links">';
                     $source_message .= '<li>' . implode('</li><li>', $single_link) . '</li>';
                     $source_message .= '</ul>';
                 }
                 break;
             default:
                 break;
         }
         $source_message .= '</div>';
         if (is_singular()) {
             if ('APPEND' == $sa_source_position) {
                 $content = $content . $source_message;
             } else {
                 $content = $source_message . $content;
             }
         }
         // end if
     }
     // end if
     return $content;
 }
 /**
  * Renders the nonce and the textarea for the notice.
  */
 function source_affix_sa_source_display($post)
 {
     wp_nonce_field(plugin_basename(__FILE__), 'sa_source_nonce');
     $source_meta = get_post_meta($post->ID, 'sa_source', true);
     $links_array = source_affix_convert_meta_to_array($source_meta);
     echo '<ul id="list-source-link">';
     if (!empty($links_array) && is_array($links_array)) {
         foreach ($links_array as $key => $link) {
             echo '<li>';
             echo '<span class="btn-move-source-link"><i class="dashicons dashicons-sort"></i></span>';
             echo '<input type="text" name="link_title[]" value="' . esc_attr($link['title']) . '"  class="regular-text1 code" placeholder="' . __('Enter Title', 'source-affix') . '" />';
             echo '<input type="text" name="link_url[]" value="' . esc_url($link['url']) . '"  class="regular-text code" placeholder="' . __('Enter Full URL', 'source-affix') . '" />';
             echo '<span class="btn-remove-source-link"><i class="dashicons dashicons-no-alt"></i></span>';
             echo '</li>';
         }
     } else {
         // show empty first field
         echo '<li>';
         echo '<span class="btn-move-source-link"><i class="dashicons dashicons-sort"></i></span>';
         echo '<input type="text" name="link_title[]" value=""  class="regular-text1 code" placeholder="' . __('Enter Title', 'source-affix') . '" />';
         echo '<input type="text" name="link_url[]" value=""  class="regular-text code" placeholder="' . __('Enter Full URL', 'source-affix') . '" />';
         echo '<span class="btn-remove-source-link"><i class="dashicons dashicons-no-alt"></i></span>';
         echo '</li>';
     }
     echo '</ul>';
     echo '<a href="#" class="button button-primary" id="btn-add-source-link">' . __('Add New', 'source-affix') . '</a>';
     return;
 }