コード例 #1
0
	/**
	 * Renders the URL shortening method list option
	 * 
	 * @since 2.8.6
	 */
	public static function render_url_shortening_method( $args ) {
		$metaKey = self::META_KEY_URL_SHORTENING_METHOD;
		$shortening_method = WPRSS_FTP_Settings::get_instance()->get( $metaKey );
		$field = WPRSS_FTP_Meta::get_instance()->get_meta_fields('url_shortening');
		$field = $field[$metaKey];
		$options = $field['options'];
		echo WPRSS_FTP_Utils::array_to_select( $options,
			array(
				'id'		=> str_replace('_', '-', $metaKey),
				'name'		=> WPRSS_FTP_Settings::OPTIONS_NAME . sprintf('[%1$s]', $metaKey),
				'selected'	=> $shortening_method,
			)
		);
		echo WPRSS_Help::get_instance()->do_tooltip( WPRSS_FTP_HELP_PREFIX.'url_shortening_method' );
	}
コード例 #2
0
 /**
  * Get the HTML output of a <select> element.
  *
  * @since 4.8.1
  * @param array $values The select element's options.
  * @param array $args Data for the select element.
  * @return string The select element HTML.
  */
 public static function getSelectHtml($values, $args = array())
 {
     return \WPRSS_FTP_Utils::array_to_select($values, $args);
 }
コード例 #3
0
	/**
	 * Renders the post site dropdown.
	 *
	 * @since 1.7
	 */
	public function render_post_site_dropdown( $post, $field_id, $field, $meta ) {
		$id = self::META_PREFIX . $field_id;
		$desc = isset( $field['desc'] )? $field['desc'] : '';
		$multisite_and_main_site = WPRSS_FTP_Utils::is_multisite_and_main_site();
		$input = '';
		// If the return value of WPRSS_FTP_Utils::is_multisite_and_main_site()
		// is a string, then it is an error message. Set the description to it.
		if ( is_string( $multisite_and_main_site ) ) {
			$desc = $multisite_and_main_site;
		}
		// Otherwise, if it is boolean TRUE
		elseif ( $multisite_and_main_site === TRUE) {
			// Get the sites and generate a dropdown
			$sites = WPRSS_FTP_Utils::get_sites();
			$input = WPRSS_FTP_Utils::array_to_select(
				$sites,
				array(
					'id'		=> $id,
					'name'		=> $id,
					'selected'	=> $meta,
				)
			);
		}
		// If using multisite but not the main site, simply show the site name.
		elseif ( $multisite_and_main_site === FALSE && is_multisite() ) {
			$current_site = get_bloginfo('name');
			$meta = get_current_blog_id();
			$input = "<input type='hidden' name='$id' id='$id' value='$meta' /><b>{$current_site}</b>";
			$desc = '';
		}
		// If neither multisite nor main site, do not show the row
		else return '';

		// Show the field row
		ob_start(); ?>
			<tr>
				<th><label for="<?php echo $id; ?>"><?php echo $field['label']; ?></label></th>
				<td>
					<?php echo $input; ?>
					<?php
						if ( class_exists( 'WPRSS_Help' ) ) {
							echo WPRSS_Help::get_instance()->do_tooltip( WPRSS_FTP_HELP_PREFIX.$field_id );
						}
					?>
					<br/><label class="description" for="<?php echo $id; ?>"><?php echo $desc; ?></label>
				</td>
			</tr>
		<?php
		return ob_get_clean();
	}
コード例 #4
0
/**
 * Generates a single taxonomy section for a given post type at the given entry index,
 * and uses the given and optional $meta options to set the values as selected in the fields.
 * 
 * @since 3.1
 * @param int $id The entry ID - the index/position of the section
 * @param string $post_type The post type used to determine the taxonomies
 * @param array $meta The array of meta options used to prepare the selected values
 * @return string The HTML output of the taxonomy sections
 */
function wprss_ftp_taxonomy_section( $id, $post_type, $meta = NULL ) {
	if ( $post_type == '' ) {
		$post_type = 'post';
	}
	if ( $meta === NULL ) {
		$meta = array(
			'taxonomy'	=>	'',
			'terms'		=>	'',
			'auto'		=>	'false'
		);
	}
	ob_start(); ?>

	<tr data-id="<?php echo $id; ?>" class="wprss-tr-hr ftp-taxonomy-section">
		<th>
			<?php
				$post_type_taxonomies = WPRSS_FTP_Utils::get_post_type_taxonomies( $post_type );
				if ( count($post_type_taxonomies) > 0 ) {
					echo WPRSS_FTP_Utils::array_to_select(
						$post_type_taxonomies,
						array(
							'id'		=>	'ftp-taxonomy-'.$id,
							'class'		=>	'ftp-taxonomy',
							'name'		=>	WPRSS_FTP_Meta::META_PREFIX . "post_taxonomy[$id]",
							'selected'	=>	$meta['taxonomy']
						)
					);
					/* The taxonomy 'selected' above might be saved in meta, but not in the list.
					 * Therefore, we need to check the REAL selected taxonomy, which could be either
					 * the taxonomy saved in meta also the one selected in the dropdown, or the first
					 * taxonomy in the dropdown if the saved taxonomy is not the dropdown.
					 */
					$selected_tax = $meta['taxonomy'];
					// If the saved taxonomy (also the one to be 'selected') is not present
					if ( !array_key_exists( $meta['taxonomy'], $post_type_taxonomies ) ) {
						// Use the first taxonomy in the list
						reset( $post_type_taxonomies );
						$selected_tax = key( $post_type_taxonomies );
					}

					// The edit taxonomy link - the 'href' attribute and the <span> child element will be populated via JS ?> 
					<a class="ftp-edit-tax" href="#" target="_blank" data-base-url="<?php echo admin_url('edit-tags.php?taxonomy='); ?>">
						<i class="fa fa-pencil"></i> Edit <span></span>
					</a>
					<?php
				}
			?>
		</th>

		<td>
			<?php
				if ( count($post_type_taxonomies) === 0 ) :
					$all_post_types = WPRSS_FTP_Meta::get_post_types();
					printf(
						__("<p id='ftp-no-taxonomies'>The Post Type <strong>%s</strong>  has no taxonomies available!</p>", WPRSS_TEXT_DOMAIN),
						$all_post_types[$post_type]
					);
				else :
					$tax_terms = WPRSS_FTP_Utils::get_taxonomy_terms( $selected_tax );
					if ( count($tax_terms) == 0 ) {
						echo wprss_ftp_no_terms_msg( $post_type_taxonomies[$selected_tax] );
					} else {
						echo WPRSS_FTP_Utils::array_to_select(
							$tax_terms,
							array(
								'id'			=>	'ftp-terms-'.$id,
								'class'			=>	'ftp-terms',
								'name'			=>	WPRSS_FTP_Meta::META_PREFIX . "post_terms[$id]",
								'selected'		=>	$meta['terms'],
								'multiple'		=>	TRUE
							)
						);
					}
					?>
			
					<p>
						<?php
							echo WPRSS_FTP_Utils::boolean_to_checkbox(
								$meta['auto'],
								array(
									'id'		=>	'ftp-auto-terms-'.$id,
									'class'		=>	'ftp-auto-terms',
									'name'		=>	WPRSS_FTP_Meta::META_PREFIX . "auto_terms[$id]",
									'value'		=>	'true',
								)
							);
						?>
						<label for="ftp-auto-terms-<?php echo $id; ?>"><?php _e('Auto create terms from the feed items for this taxonomy', WPRSS_TEXT_DOMAIN); ?></label>

						<span class="ftp-tax-row-buttons">
							<button title="<?php esc_attr_e("Refresh the terms, if they've changed", WPRSS_TEXT_DOMAIN); ?>" type="button" class="ftp-tax-section-refresh button-secondary" data-id="<?php echo $id; ?>">
								<fa class="fa fa-fw fa-refresh"></fa>
								<span><?php _e('Refresh terms', WPRSS_TEXT_DOMAIN); ?></span>
							</button>
					
							<button title="<?php esc_attr_e("Remove this entry", WPRSS_TEXT_DOMAIN); ?>" type="button" class="ftp-tax-section-remove button-secondary" data-id="<?php echo $id; ?>">
								<fa class="fa fa-fw fa-times"></fa>
								<span><?php _e('Remove row', WPRSS_TEXT_DOMAIN); ?></span>
							</button>
						</span>
					</p>
					<p>
						<?php
							$select = WPRSS_FTP_Utils::array_to_select(
								array(
									'title'		=> __('Feed Title', WPRSS_TEXT_DOMAIN),
									'content'	=> __('Feed Content', WPRSS_TEXT_DOMAIN)
								),
								array(
									'id'		=> 'ftp-tax-filter-subject-'.$id,
									'class'		=> 'ftp-tax-filter-subject',
									'name'		=> WPRSS_FTP_Meta::META_PREFIX . "filter_subject[$id]",
									'selected'	=> isset( $meta['filter_subject'] ) ? $meta['filter_subject'] : null,
									'multiple'	=> TRUE
								)
							);
							_e(
								sprintf(
									'Only apply the preceding terms if the %s contains all of the following keywords: ', 
									$select
								),
								WPRSS_TEXT_DOMAIN
							);
						?>
							<input
								type="text"
								id="ftp-tax-filter-keywords-<?php echo $id ?>"
								name="<?php echo WPRSS_FTP_Meta::META_PREFIX . "filter_keywords[$id]" ?>"
								value="<?php echo isset( $meta['filter_keywords'] ) ? $meta['filter_keywords'] : '' ?>"
								placeholder="<?php _e('Enter comma separated words or phrases', WPRSS_TEXT_DOMAIN) ?>"
								style="width:100%"
							/>
			<?php endif; ?>
		</td>
	</tr>

	<?php return ob_get_clean();
}
コード例 #5
0
	/**
	 * Renders the author settings
	 * 
	 * @since 1.9.3
	 */
	public function render_author_options( $post_id = NULL, $meta_row_title = '', $meta_label_for = '' ) {
		// Get the options
		$options = WPRSS_FTP_Settings::get_instance()->get_computed_options( $post_id );
		$def_author = ( $post_id !== NULL ) ? $options['def_author'] : $this->get( 'def_author' );
		$author_fallback_method = ( $post_id !== NULL ) ? $options['author_fallback_method'] : $this->get( 'author_fallback_method' );
		$author_fallback_method = ( strtolower( $author_fallback_method ) === 'use_existing' )? 'existing' : $author_fallback_method;
		$fallback_author = ( $post_id !== NULL ) ? $options['fallback_author'] : $this->get( 'fallback_author' );
		$no_author_found = ( $post_id !== NULL ) ? $options['no_author_found'] : $this->get( 'no_author_found' );
		
		// Set the HTML tag ids
		$ids = array(
			'def_author'				=>	'ftp-def-author',
			'author_fallback_method'	=>	'ftp-author-fallback-method',
			'fallback_author'			=>	'ftp-fallback-author',
			'no_author_found'			=>	'ftp-no-author-skip'
		);
		// If in meta, copy the keys into the values
		if ( $post_id !== NULL ) {
			foreach ( $ids as $field => $id ) {
				$ids[$field] = $field;
			}
		}
		// Set the HTML tag names
		$names = array(
			'def_author'				=>	'def_author',
			'author_fallback_method'	=>	'author_fallback_method',
			'fallback_author'			=>	'fallback_author',
			'no_author_found'			=>	'no_author_found',
		);
		// Set the names appropriately according to the page, meta or settings
		foreach( $names as $field => $name) {
			$names[$field] = ( $post_id !== NULL )? WPRSS_FTP_Meta::META_PREFIX . $name : self::OPTIONS_NAME . "[$name]";
		}

		// If in meta, print the table row
		if ( $post_id !== NULL ) : ?>
			<tr>
				<th>
					<label for="<?php echo $meta_label_for; ?>">
						<?php echo $meta_row_title; ?>
					</label>
				</th>
				<td>
		<?php endif; ?>

		<!-- Author to use -->
		<span id="wprss-ftp-authors-options">
			<label for="<?php echo $ids['def_author']; ?>">Use </label>
			<?php $users = WPRSS_FTP_Meta::get_users_array( WPRSS_FTP_Admin_User_Ajax::get_instance()->is_over_threshold() ? (array)$def_author : false ) ?>
			<?php echo WPRSS_FTP_Utils::array_to_select( $users, array(
					'id'		=>	$ids['def_author'],
					'name'		=>	$names['def_author'],
					'selected'	=>	$def_author,
			));
			?>
			<script type="text/javascript">
				top.wprss.f2p.userAjax.addElement('#<?php echo $ids['def_author'] ?>');
			</script>
			<?php
			echo WPRSS_Help::get_instance()->do_tooltip( WPRSS_FTP_HELP_PREFIX.'post_author' ); ?>
		</span>
		
		<!-- Separator -->
		<?php if ( $post_id !== NULL ) : ?>
			</td></tr>
			<tr class="wprss-tr-hr wprss-ftp-authors-hide-if-using-existing">
				<th>
				</th>
				<td>
		<?php endif; ?>
		
		<!-- Section that hides when using an existing user -->
		<span class="wprss-ftp-authors-hide-if-using-existing">
			
			<!-- Radio group if author has no user -->
			<span class="ftp-author-using-in-feed">
				<label for="<?php echo $ids['author_fallback_method']; ?>">
					<?php _e( 'If the author in the feed is not an existing user', WPRSS_TEXT_DOMAIN ); ?>:
				</label>
				<br/>
				<?php
					echo implode( '', WPRSS_FTP_Utils::array_to_radio_buttons(
						array(
							'existing'	=> __( 'Use the fallback user', WPRSS_TEXT_DOMAIN ),
							'create'	=> __( 'Create a user for the author', WPRSS_TEXT_DOMAIN )
						),
						array(
							'id'		=>	$ids['author_fallback_method'],
							'name'		=>	$names['author_fallback_method'],
							'checked'	=>	$author_fallback_method,
						)
					));
				?>
			</span>
			
			<!-- Radio group if author not found in feed -->
			<span class="ftp-author-using-in-feed">
				<label for="<?php echo $ids['no_author_found']; ?>">
					<?php _e( 'If the author is missing from the feed', WPRSS_TEXT_DOMAIN ); ?>
				</label>
				<br/>
				<?php
					echo implode( WPRSS_FTP_Utils::array_to_radio_buttons(
						array(
							'fallback'	=>	__( 'Use the fallback user', WPRSS_TEXT_DOMAIN ),
							'skip'		=>	__( 'Do not import the post', WPRSS_TEXT_DOMAIN )
						),
						array(
							'id'		=>	$ids['no_author_found'],
							'name'		=>	$names['no_author_found'],
							'checked'	=>	$no_author_found,
						)
					));
				?>
			</span>
		</span>
		
		
		<?php if ( $post_id !== NULL ) : ?>
			</td></tr>
			<tr class="wprss-tr-hr wprss-ftp-authors-hide-if-using-existing">
				<th>
					<label for="<?php echo $ids['fallback_author']; ?>">
						<?php _e( 'Fallback User', WPRSS_TEXT_DOMAIN ); ?>
					</label>
				</th>
				<td>
		<?php endif; ?>
		
		<!-- Section that hides when using an existing user -->
		<span class="wprss-ftp-authors-hide-if-using-existing">
			<?php if ( $post_id === NULL ) : ?>
			<label for="<?php echo $ids['fallback_author']; ?>">
				<?php _e( 'Fallback user:'******'id'		=>	$ids['fallback_author'],
					'name'		=>	$names['fallback_author'],
					'selected'	=>	$fallback_author,
				));
			?>
			<script type="text/javascript">
				top.wprss.f2p.userAjax.addElement('#<?php echo $ids['fallback_author'] ?>', {<?php echo WPRSS_FTP_Admin_User_Ajax::REQUEST_VAR_EXISTING_USERS_ONLY ?>: true, <?php echo WPRSS_FTP_Admin_User_Ajax::REQUEST_VAR_LOGIN_NAMES ?>: true});
			</script>
			<?php echo WPRSS_Help::get_instance()->do_tooltip( WPRSS_FTP_HELP_PREFIX.'fallback_author' ); ?>
		</span>
					
		<?php // Add scripts ?>

		<script type="text/javascript">
			(function($){
				$(document).ready( function(){

					// Set a pointer to the dropdowns
					var dropdown1 = $('#<?php echo $ids['def_author']; ?>');

					// Create the function that shows/hides the second section
					var authorsSection2UI = function(){
						// Show second section only if the option to use the author in the feed is chosen
						$('.wprss-ftp-authors-hide-if-using-existing').toggle( dropdown1.val() === '.' );
					}

					// Set the on change handlers
					dropdown1.change( authorsSection2UI );

					// Run the function at least once
					authorsSection2UI();

				});
			})(jQuery);
		</script>
		<?php // End of scripts

		// If in meta, close the table row
		if ( $post_id !== NULL ) {
			?></td></tr><?php
		}
	}