/** * Prints the checkbox settings for enabling the legacy feed item. * * @since 2.9.5 */ function wprss_ftp_legacy_enable_option() { $legacy_enabled = WPRSS_FTP_Settings::get_instance()->get('legacy_enabled'); echo WPRSS_FTP_Utils::boolean_to_checkbox( WPRSS_FTP_Utils::multiboolean( $legacy_enabled ), array( 'id' => 'wprss-ftp-legacy-enabled', 'name' => WPRSS_FTP_Settings::OPTIONS_NAME . '[legacy_enabled]', 'value' => 'true', ) ); echo WPRSS_Help::get_instance()->do_tooltip( WPRSS_FTP_HELP_PREFIX.'legacy_enabled' ); }
/** * Generates HTML of a checkbox based on the passed parameters. * * @since 4.8.1 * @see PRSS_FTP_Utils::boolean_to_checkbox() * @param bool|mixed $isChecked Whether or not this checkbox should be ticked. * @param array $args Additional checkbox params. * @param bool $autoEval If true, the first value will be evaluated and compared to known 'true' values. * @return string The HTML of a checkbox. */ public static function getCheckboxHtml($isChecked, $args, $autoEval = true) { if ($autoEval) { $isChecked = static::isTrue($isChecked); } return \WPRSS_FTP_Utils::boolean_to_checkbox($isChecked, $args); }
/** * 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(); }
/** * Renders the meta box specified by the parameter. * The function will use the get_meta_fields function to retrieve the fields for * that particular meta box and render them. * * @since 1.0 */ public function render_metabox( $metabox ) { global $post; $help = class_exists('WPRSS_Help') ? WPRSS_Help::get_instance() : null; # The main metabox template ob_start(); ?> <table class="form-table wprss-form-table"> <tbody> {{fields}} </tbody> </table> <?php $template = ob_get_clean(); # The field template to use for all fields ob_start(); ?> <tr {{hr}}> <th><label for="{{id}}">{{label}}</label></th> <td> {{before}} {{input}} {{after}} {{separator}}<label for="{{id}}"><span class="description">{{desc}}</span></label> </td> </tr> <?php $field_template = ob_get_clean(); # Generate the fields HTML using the template $meta_fields = $this->get_meta_fields( $metabox, $post->ID ); $fields = ''; $options = WPRSS_FTP_Settings::get_instance()->get_computed_options( $post->ID ); # Render each field foreach ( $meta_fields as $field_id => $field ) { if ( isset( $field['ignore']) && $field['ignore'] === TRUE ) { continue; } $hr = ( isset( $field['add_hr'] ) && $field['add_hr'] === TRUE )? 'class="wprss-tr-hr"': ''; $field_html = ''; $id = self::META_PREFIX . $field_id; # Get the meta value for this field, if it exists $nid = substr( $id, strlen( self::META_PREFIX ) ); $meta = $options[ $nid ]; if ( isset( $field['settings'] ) && $field['settings'] === FALSE ) { $meta = get_post_meta( $post->ID, $id, true ); } if ( isset( $field['default'] ) && $meta === '' ) { $meta = $field['default']; } if ( isset( $field['custom_render'] ) && !empty( $field['custom_render'] ) ) { $field_html = call_user_func_array( $field['custom_render'], array( $post, $field_id, $field, $meta ) ); } else { $separator = '<br/>'; $before = ''; $after = ''; # Generate the field input $field_input = ''; $field_type_templates = array( 'text' => '<input type="text" id="{{id}}" name="{{name}}" value="{{value}}" placeholder="{{placeholder}}" {{properties}}/>', 'number' => '<input class="wprss-number-roller" type="number" id="{{id}}" name={{name}} min="0" placeholder="{{placeholder}}" value="{{value}}" {{properties}}/>', 'textarea' => '<textarea id="{{id}}" name="{{name}}" cols="60" rows="4" {{properties}}>{{value}}</textarea>' ); switch( $field['type'] ) { default: case 'text': case 'number': case 'textarea': // If the field is a textarea, and the meta value saved in DB is an array if ( $field['type'] === 'textarea' && is_array( $meta ) ) { // split the array into strings $new_meta = ''; foreach ( $meta as $entry ) { $new_meta .= $entry . "\n"; } $meta = $new_meta; } $substitutions = array( 'id' => $id, 'name' => $id, 'value' => trim( esc_attr( $meta ) ), 'placeholder' => ( isset( $field['placeholder'] )? $field['placeholder'] : 'Default' ), 'properties' => ( isset( $field['properties'] )? $field['properties'] : '' ), ); $field_input = WPRSS_FTP_Utils::template( $field_type_templates[ $field['type'] ], $substitutions ); break; case 'checkbox': $field_input = WPRSS_FTP_Utils::boolean_to_checkbox( WPRSS_FTP_Utils::multiboolean( $meta ), array( 'id' => $id, 'name' => $id, 'class' => 'meta-checkbox', 'value' => 'true', 'disabled' => ( isset( $field['disabled'] )? $field['disabled'] : FALSE ), ) ); $separator = ''; break; case 'msg': $field_input = '<p id="'.$id.'">'.$field['text'].'</p>'; break; case 'dropdown': $choices = $this->resolve_data_source( $field['options'] ); $field_input = WPRSS_FTP_Utils::array_to_select( $choices, array( 'id' => $id, 'name' => $id, 'selected' => $meta, 'disabled' => ( isset( $field['disabled'] )? $field['disabled'] : FALSE ), ) ); break; } if ( $help !== null ) { $after .= $help->do_tooltip( WPRSS_FTP_HELP_PREFIX.$field_id ); } $label = isset( $field['label'] )? $field['label'] : ''; $desc = isset( $field['desc'] )? $field['desc'] : ''; # Finish the field using the template $field_html = WPRSS_FTP_Utils::template( $field_template, array( 'id' => $id, 'input' => $field_input, 'label' => $label, 'desc' => $desc, 'separator' => $separator, 'hr' => $hr, 'before' => $before, 'after' => $after ) ); } // End of if statement that checks if using a custom renderer $fields .= $field_html; } echo str_replace( '{{fields}}', $fields, $template ); echo '<span data-post-id="'.$post->ID.'" id="wprss-ftp-post-id"></span>'; }
/** * Renders the checkbox for the option to allow local requests * * @since 2.8.6 * @deprecated 3.0 */ public function render_allow_local_requests( $args ) { $name = 'allow_local_requests'; $id = 'ftp-' . str_replace('_', '-', $name); $allow_local_requests = $this->get( $name ); echo WPRSS_FTP_Utils::boolean_to_checkbox( WPRSS_FTP_Utils::multiboolean( $allow_local_requests ), array( 'id' => $id, 'name' => sprintf('%2$s[%1$s]', $name, self::OPTIONS_NAME), 'value' => 'true' ) ); echo WPRSS_Help::get_instance()->do_tooltip( WPRSS_FTP_HELP_PREFIX.'allow_local_requests' ); }