PATH:
home
/
letacommog
/
laindinois
/
OLD
/
wp-content
/
plugins
/
wordpress-seo-premium
/
premium
/
classes
<?php /** * WPSEO Premium plugin file. * * @package WPSEO\Premium\Classes */ /** * Class WPSEO_Export_Keywords_Manager. * * Manages exporting keywords. */ class WPSEO_Premium_Keyword_Export_Manager implements WPSEO_WordPress_Integration { /** * A WordPress database object. * * @var wpdb instance */ protected $wpdb; /** * Registers all hooks to WordPress. */ public function register_hooks() { // Hook into the request in case of CSV download and return our generated CSV instead. add_action( 'admin_init', array( $this, 'keywords_csv_export' ) ); // Add htaccess import block. add_action( 'wpseo_import_tab_content', array( $this, 'add_keyword_export_tab_block' ) ); add_action( 'wpseo_import_tab_header', array( $this, 'keywords_export_tab_header' ) ); } /** * Outputs a tab header for the CSV export block. */ public function keywords_export_tab_header() { if ( current_user_can( 'export' ) ) { echo '<a class="nav-tab" id="keywords-export-tab" href="#top#keywords-export">' . esc_html__( 'Export keyphrases', 'wordpress-seo-premium' ) . '</a>'; } } /** * Adds the export block for CSV. Makes it able to export redirects to CSV. */ public function add_keyword_export_tab_block() { // Display the forms. if ( current_user_can( 'export' ) ) { $yform = Yoast_Form::get_instance(); require WPSEO_PREMIUM_PATH . 'classes/views/export-keywords.php'; } } /** * Hooks into the request and returns a CSV file if we're on the right page with the right method and the right capabilities. */ public function keywords_csv_export() { global $wpdb; if ( ! $this->is_valid_csv_export_request() || ! current_user_can( 'export' ) ) { return; } // Check if we have a valid nonce. check_admin_referer( 'wpseo-export' ); $this->wpdb = $wpdb; // Clean any content that has been already outputted, for example by other plugins or faulty PHP files. if ( ob_get_contents() ) { ob_clean(); } // Make sure we don't time out during the collection of items. set_time_limit( 0 ); // Set CSV headers and content. $this->set_csv_headers(); echo $this->get_csv_contents(); // And exit so we don't start appending HTML to our CSV file. // NOTE: this makes this entire class untestable as it will exit all tests but WordPress seems to have no elegant way of handling this. exit; } /** * Returns whether this is a POST request for a CSV export of posts and keywords. * * @return bool True if this is a valid CSV export request. */ protected function is_valid_csv_export_request() { return filter_input( INPUT_GET, 'page' ) === 'wpseo_tools' && filter_input( INPUT_GET, 'tool' ) === 'import-export' && filter_input( INPUT_POST, 'export-posts' ); } /** * Sets the headers to trigger a CSV download in the browser. */ protected function set_csv_headers() { header( 'Content-type: text/csv' ); header( 'Content-Disposition: attachment; filename=' . date( 'Y-m-d' ) . '-yoast-seo-keywords.csv' ); header( 'Pragma: no-cache' ); header( 'Expires: 0' ); } /** * Generates the CSV to be exported. * * @return void */ protected function get_csv_contents() { $columns = array( 'keywords' ); $post_wpseo = filter_input( INPUT_POST, 'wpseo', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); if ( is_array( $post_wpseo ) ) { $columns = array_merge( $columns, $this->get_export_columns( $post_wpseo ) ); } $builder = new WPSEO_Export_Keywords_CSV( $columns ); $builder->print_headers(); $this->prepare_export( $builder, $columns ); } /** * Returns an array of the requested columns. * * @param array $post_object An associative array with the post data. * * @return array List of export columns. */ protected function get_export_columns( array $post_object ) { $exportable_columns = array( 'export-keywords-score' => 'keywords_score', 'export-url' => 'url', 'export-title' => 'title', 'export-seo-title' => 'seo_title', 'export-meta-description' => 'meta_description', 'export-readability-score' => 'readability_score', ); // Need to call array_values to ensure that we get a numerical key back. return array_values( array_intersect_key( $exportable_columns, $post_object ) ); } /** * Feeds post and term items to the CSV builder. * * @param WPSEO_Export_Keywords_CSV $builder The builder to use. * @param array $columns The columns that need to be exported. * * @return void */ protected function prepare_export( WPSEO_Export_Keywords_CSV $builder, array $columns ) { $this->feed_to_builder( $builder, new WPSEO_Export_Keywords_Post_Query( $this->wpdb, $columns, 1000 ), new WPSEO_Export_Keywords_Post_Presenter( $columns ) ); $this->feed_to_builder( $builder, new WPSEO_Export_Keywords_Term_Query( $this->wpdb, $columns, 1000 ), new WPSEO_Export_Keywords_Term_Presenter( $columns ) ); } /** * Fetches the items and feeds them to the builder. * * @param WPSEO_Export_Keywords_CSV $builder Builder to feed the items to. * @param WPSEO_Export_Keywords_Query $export_query Query to use to get the items. * @param WPSEO_Export_Keywords_Presenter $presenter Presenter to present the items in the builder format. * * @return void */ protected function feed_to_builder( WPSEO_Export_Keywords_CSV $builder, WPSEO_Export_Keywords_Query $export_query, WPSEO_Export_Keywords_Presenter $presenter ) { $page_size = $export_query->get_page_size(); $page = 1; do { $results = $export_query->get_data( $page ); if ( ! is_array( $results ) ) { break; } $result_count = count( $results ); // Present the result. $presented = array_map( array( $presenter, 'present' ), $results ); // Feed presented item to the builder. array_walk( $presented, array( $builder, 'print_row' ) ); ++$page; // If we have the number of items per page, there will be more items ahead. } while ( $result_count === $page_size ); } }
[+]
..
[-] premium-orphaned-content-support.php
[edit]
[-] validation-error.php
[edit]
[-] term-watcher.php
[edit]
[-] premium-redirect-export-manager.php
[edit]
[-] upgrade-manager.php
[edit]
[-] premium-import-manager.php
[edit]
[+]
redirect
[-] premium-prominent-words-link-service.php
[edit]
[-] premium-post-data-endpoint.php
[edit]
[-] post-watcher.php
[edit]
[-] premium-prominent-words-service.php
[edit]
[-] premium-link-suggestions-service.php
[edit]
[-] premium-prominent-words-recalculation.php
[edit]
[-] premium-prominent-words-link-endpoint.php
[edit]
[-] premium-gsc.php
[edit]
[-] product-premium.php
[edit]
[-] facebook-profile.php
[edit]
[-] premium-orphaned-post-notifier.php
[edit]
[-] premium-link-suggestions-endpoint.php
[edit]
[-] premium-redirect-service.php
[edit]
[-] premium-prominent-words-versioning.php
[edit]
[-] premium-register-capabilities.php
[edit]
[-] premium-prominent-words-recalculation-notifier.php
[edit]
[-] premium-expose-shortlinks.php
[edit]
[-] premium-stale-cornerstone-content-filter.php
[edit]
[-] premium-asset-js-l10n.php
[edit]
[-] premium-autoloader.php
[edit]
[-] premium-keyword-export-manager.php
[edit]
[-] dublin-core.php
[edit]
[-] premium-assets.php
[edit]
[+]
views
[-] wordpress-integration-interface.php
[edit]
[-] premium-prominent-words-recalculation-service.php
[edit]
[-] premium-stale-cornerstone-content-notification.php
[edit]
[-] custom-fields-plugin.php
[edit]
[-] premium-prominent-words-registration.php
[edit]
[-] watcher.php
[edit]
[-] validation-result.php
[edit]
[-] premium-beacon-setting.php
[edit]
[-] premium-redirect-endpoint.php
[edit]
[-] premium-prominent-words-support.php
[edit]
[-] premium-free-translations.php
[edit]
[-] premium-javascript-strings.php
[edit]
[-] metabox-link-suggestions.php
[edit]
[-] premium-prominent-words-language-support.php
[edit]
[-] premium-prominent-words-recalculation-endpoint.php
[edit]
[-] multi-keyword.php
[edit]
[-] social-previews.php
[edit]
[-] premium-post-data-service.php
[edit]
[-] validation-warning.php
[edit]
[+]
export
[-] premium-orphaned-content-utils.php
[edit]
[-] premium-gsc-modal.php
[edit]
[-] premium-metabox.php
[edit]
[-] premium-orphaned-post-filter.php
[edit]
[-] premium-prominent-words-unindexed-post-query.php
[edit]
[-] premium-prominent-words-endpoint.php
[edit]
[-] premium-orphaned-post-query.php
[edit]