@@ -4,26 +4,26 @@ |
||
| 4 | 4 | */ |
| 5 | 5 | class Wordlift_Sanitizer { |
| 6 | 6 | |
| 7 | - /** |
|
| 8 | - * Only accept URIs |
|
| 9 | - * |
|
| 10 | - * @param string $value |
|
| 11 | - * |
|
| 12 | - * @return null |
|
| 13 | - */ |
|
| 14 | - public static function sanitize_url( $value ) { |
|
| 7 | + /** |
|
| 8 | + * Only accept URIs |
|
| 9 | + * |
|
| 10 | + * @param string $value |
|
| 11 | + * |
|
| 12 | + * @return null |
|
| 13 | + */ |
|
| 14 | + public static function sanitize_url( $value ) { |
|
| 15 | 15 | |
| 16 | - // Initially this function used also filter_var( $value, FILTER_VALIDATE_URL ) |
|
| 17 | - // but URLs with UTF-8 characters are not valid. We store those anyway in the DB as it's up to the browser |
|
| 18 | - // to do proper url encoding when requesting the URL. |
|
| 19 | - // |
|
| 20 | - // see also http://stackoverflow.com/questions/2137080/php-filter-var-filter-validate-url |
|
| 16 | + // Initially this function used also filter_var( $value, FILTER_VALIDATE_URL ) |
|
| 17 | + // but URLs with UTF-8 characters are not valid. We store those anyway in the DB as it's up to the browser |
|
| 18 | + // to do proper url encoding when requesting the URL. |
|
| 19 | + // |
|
| 20 | + // see also http://stackoverflow.com/questions/2137080/php-filter-var-filter-validate-url |
|
| 21 | 21 | |
| 22 | - if ( ! is_null( $value ) && $value !== '' ) { |
|
| 23 | - return $value; |
|
| 24 | - } |
|
| 22 | + if ( ! is_null( $value ) && $value !== '' ) { |
|
| 23 | + return $value; |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - return null; |
|
| 27 | - } |
|
| 26 | + return null; |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | 29 | } |
| 30 | 30 | \ No newline at end of file |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | * |
| 12 | 12 | * @return null |
| 13 | 13 | */ |
| 14 | - public static function sanitize_url( $value ) { |
|
| 14 | + public static function sanitize_url($value) { |
|
| 15 | 15 | |
| 16 | 16 | // Initially this function used also filter_var( $value, FILTER_VALIDATE_URL ) |
| 17 | 17 | // but URLs with UTF-8 characters are not valid. We store those anyway in the DB as it's up to the browser |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | // |
| 20 | 20 | // see also http://stackoverflow.com/questions/2137080/php-filter-var-filter-validate-url |
| 21 | 21 | |
| 22 | - if ( ! is_null( $value ) && $value !== '' ) { |
|
| 22 | + if ( ! is_null($value) && $value !== '') { |
|
| 23 | 23 | return $value; |
| 24 | 24 | } |
| 25 | 25 | |
@@ -39,16 +39,16 @@ |
||
| 39 | 39 | |
| 40 | 40 | <!-- Show the 'JSON-LD' button only if the constant is defined and set to true. --> |
| 41 | 41 | <?php |
| 42 | - if ( |
|
| 43 | - defined( 'WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA' ) && |
|
| 44 | - WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA |
|
| 45 | - ) : |
|
| 46 | - $class_name = 'button wl-add-input wl-button'; |
|
| 47 | - |
|
| 48 | - if ( ! Wordlift_Google_Analytics_Export_Service::is_postname_permalink_structure() ) { |
|
| 49 | - $class_name .= ' wl-button-disabled'; |
|
| 50 | - } |
|
| 51 | - ?> |
|
| 42 | + if ( |
|
| 43 | + defined( 'WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA' ) && |
|
| 44 | + WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA |
|
| 45 | + ) : |
|
| 46 | + $class_name = 'button wl-add-input wl-button'; |
|
| 47 | + |
|
| 48 | + if ( ! Wordlift_Google_Analytics_Export_Service::is_postname_permalink_structure() ) { |
|
| 49 | + $class_name .= ' wl-button-disabled'; |
|
| 50 | + } |
|
| 51 | + ?> |
|
| 52 | 52 | <a href="<?php echo esc_url( admin_url( 'admin-ajax.php?action=wl_google_analytics_export' ) ); ?>" |
| 53 | 53 | class="<?php echo esc_attr( $class_name ); ?>"> |
| 54 | 54 | <?php esc_html_e( 'Google Analytics', 'wordlift' ); ?> |
@@ -14,46 +14,46 @@ |
||
| 14 | 14 | <!-- This file should primarily consist of HTML with a little bit of PHP. --> |
| 15 | 15 | |
| 16 | 16 | <div class="wrap"> |
| 17 | - <h2><?php echo esc_html_x( 'Download Your Data', 'Page title', 'wordlift' ); ?></h2> |
|
| 18 | - <p><?php esc_html_e( 'Choose the format to download your data:', 'wordlift' ); ?></p> |
|
| 17 | + <h2><?php echo esc_html_x('Download Your Data', 'Page title', 'wordlift'); ?></h2> |
|
| 18 | + <p><?php esc_html_e('Choose the format to download your data:', 'wordlift'); ?></p> |
|
| 19 | 19 | |
| 20 | - <a href="<?php echo esc_url( admin_url( 'admin-ajax.php?action=wl_download_your_data&out=json' ) ); ?>" |
|
| 20 | + <a href="<?php echo esc_url(admin_url('admin-ajax.php?action=wl_download_your_data&out=json')); ?>" |
|
| 21 | 21 | class="button wl-add-input wl-button"> |
| 22 | - <?php esc_html_e( 'JSON-LD', 'wordlift' ); ?> |
|
| 22 | + <?php esc_html_e('JSON-LD', 'wordlift'); ?> |
|
| 23 | 23 | </a> |
| 24 | 24 | |
| 25 | - <a href="<?php echo esc_url( admin_url( 'admin-ajax.php?action=wl_download_your_data&out=rdf' ) ); ?>" |
|
| 25 | + <a href="<?php echo esc_url(admin_url('admin-ajax.php?action=wl_download_your_data&out=rdf')); ?>" |
|
| 26 | 26 | class="button wl-add-input wl-button"> |
| 27 | - <?php esc_html_e( 'RDF/XML', 'wordlift' ); ?> |
|
| 27 | + <?php esc_html_e('RDF/XML', 'wordlift'); ?> |
|
| 28 | 28 | </a> |
| 29 | 29 | |
| 30 | - <a href="<?php echo esc_url( admin_url( 'admin-ajax.php?action=wl_download_your_data&out=ttl' ) ); ?>" |
|
| 30 | + <a href="<?php echo esc_url(admin_url('admin-ajax.php?action=wl_download_your_data&out=ttl')); ?>" |
|
| 31 | 31 | class="button wl-add-input wl-button"> |
| 32 | - <?php echo esc_html_x( 'Turtle', 'File format, not the animal', 'wordlift' ); ?> |
|
| 32 | + <?php echo esc_html_x('Turtle', 'File format, not the animal', 'wordlift'); ?> |
|
| 33 | 33 | </a> |
| 34 | 34 | |
| 35 | - <a href="<?php echo esc_url( admin_url( 'admin-ajax.php?action=wl_download_your_data&out=n3' ) ); ?>" |
|
| 35 | + <a href="<?php echo esc_url(admin_url('admin-ajax.php?action=wl_download_your_data&out=n3')); ?>" |
|
| 36 | 36 | class="button wl-add-input wl-button"> |
| 37 | - <?php esc_html_e( 'N3', 'wordlift' ); ?> |
|
| 37 | + <?php esc_html_e('N3', 'wordlift'); ?> |
|
| 38 | 38 | </a> |
| 39 | 39 | |
| 40 | 40 | <!-- Show the 'JSON-LD' button only if the constant is defined and set to true. --> |
| 41 | 41 | <?php |
| 42 | 42 | if ( |
| 43 | - defined( 'WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA' ) && |
|
| 43 | + defined('WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA') && |
|
| 44 | 44 | WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA |
| 45 | 45 | ) : |
| 46 | 46 | $class_name = 'button wl-add-input wl-button'; |
| 47 | 47 | |
| 48 | - if ( ! Wordlift_Google_Analytics_Export_Service::is_postname_permalink_structure() ) { |
|
| 48 | + if ( ! Wordlift_Google_Analytics_Export_Service::is_postname_permalink_structure()) { |
|
| 49 | 49 | $class_name .= ' wl-button-disabled'; |
| 50 | 50 | } |
| 51 | 51 | ?> |
| 52 | - <a href="<?php echo esc_url( admin_url( 'admin-ajax.php?action=wl_google_analytics_export' ) ); ?>" |
|
| 53 | - class="<?php echo esc_attr( $class_name ); ?>"> |
|
| 54 | - <?php esc_html_e( 'Google Analytics', 'wordlift' ); ?> |
|
| 52 | + <a href="<?php echo esc_url(admin_url('admin-ajax.php?action=wl_google_analytics_export')); ?>" |
|
| 53 | + class="<?php echo esc_attr($class_name); ?>"> |
|
| 54 | + <?php esc_html_e('Google Analytics', 'wordlift'); ?> |
|
| 55 | 55 | |
| 56 | - <?php if ( ! Wordlift_Google_Analytics_Export_Service::is_postname_permalink_structure() ) : ?> |
|
| 56 | + <?php if ( ! Wordlift_Google_Analytics_Export_Service::is_postname_permalink_structure()) : ?> |
|
| 57 | 57 | <span class="wl-tooltip">To download your data, please change <br /> the site permalink structure to "Post name"</span> |
| 58 | 58 | <?php endif ?> |
| 59 | 59 | </a> |
@@ -18,48 +18,48 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class Wordlift_Admin_Settings_Page_Action_Link { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * The {@link Wordlift_Admin_Settings_Page} instance. |
|
| 23 | - * |
|
| 24 | - * @since 3.11.0 |
|
| 25 | - * @access private |
|
| 26 | - * @var \Wordlift_Admin_Settings_Page $settings_page The {@link Wordlift_Admin_Settings_Page} instance. |
|
| 27 | - */ |
|
| 28 | - private $settings_page; |
|
| 21 | + /** |
|
| 22 | + * The {@link Wordlift_Admin_Settings_Page} instance. |
|
| 23 | + * |
|
| 24 | + * @since 3.11.0 |
|
| 25 | + * @access private |
|
| 26 | + * @var \Wordlift_Admin_Settings_Page $settings_page The {@link Wordlift_Admin_Settings_Page} instance. |
|
| 27 | + */ |
|
| 28 | + private $settings_page; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Create a {@link Wordlift_Admin_Settings_Page_Action_Link} instance. |
|
| 32 | - * |
|
| 33 | - * @since 3.11.0 |
|
| 34 | - * |
|
| 35 | - * @param \Wordlift_Admin_Settings_Page $settings_page The {@link Wordlift_Admin_Settings_Page} instance. |
|
| 36 | - */ |
|
| 37 | - function __construct( $settings_page ) { |
|
| 30 | + /** |
|
| 31 | + * Create a {@link Wordlift_Admin_Settings_Page_Action_Link} instance. |
|
| 32 | + * |
|
| 33 | + * @since 3.11.0 |
|
| 34 | + * |
|
| 35 | + * @param \Wordlift_Admin_Settings_Page $settings_page The {@link Wordlift_Admin_Settings_Page} instance. |
|
| 36 | + */ |
|
| 37 | + function __construct( $settings_page ) { |
|
| 38 | 38 | |
| 39 | - $this->settings_page = $settings_page; |
|
| 39 | + $this->settings_page = $settings_page; |
|
| 40 | 40 | |
| 41 | - } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Create a link to the WordLift settings page. |
|
| 45 | - * |
|
| 46 | - * @since 3.11.0 |
|
| 47 | - * |
|
| 48 | - * @param array $links An array of links. |
|
| 49 | - * |
|
| 50 | - * @return array An array of links including those added by the plugin. |
|
| 51 | - */ |
|
| 52 | - function action_links( $links ) { |
|
| 43 | + /** |
|
| 44 | + * Create a link to the WordLift settings page. |
|
| 45 | + * |
|
| 46 | + * @since 3.11.0 |
|
| 47 | + * |
|
| 48 | + * @param array $links An array of links. |
|
| 49 | + * |
|
| 50 | + * @return array An array of links including those added by the plugin. |
|
| 51 | + */ |
|
| 52 | + function action_links( $links ) { |
|
| 53 | 53 | |
| 54 | - // Get the menu slug from the page, then prepare the path, hence the url. |
|
| 55 | - $menu_slug = $this->settings_page->get_menu_slug(); |
|
| 56 | - $path = "admin.php?page=$menu_slug"; |
|
| 57 | - $url = get_admin_url( null, $path ); |
|
| 54 | + // Get the menu slug from the page, then prepare the path, hence the url. |
|
| 55 | + $menu_slug = $this->settings_page->get_menu_slug(); |
|
| 56 | + $path = "admin.php?page=$menu_slug"; |
|
| 57 | + $url = get_admin_url( null, $path ); |
|
| 58 | 58 | |
| 59 | - // Add our own link to the list of links. |
|
| 60 | - return array_merge( $links, array( |
|
| 61 | - sprintf( "<a href='$url'>%s</a>", __( 'Settings', 'wordlift' ) ), |
|
| 62 | - ) ); |
|
| 63 | - } |
|
| 59 | + // Add our own link to the list of links. |
|
| 60 | + return array_merge( $links, array( |
|
| 61 | + sprintf( "<a href='$url'>%s</a>", __( 'Settings', 'wordlift' ) ), |
|
| 62 | + ) ); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | 65 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * |
| 35 | 35 | * @param \Wordlift_Admin_Settings_Page $settings_page The {@link Wordlift_Admin_Settings_Page} instance. |
| 36 | 36 | */ |
| 37 | - function __construct( $settings_page ) { |
|
| 37 | + function __construct($settings_page) { |
|
| 38 | 38 | |
| 39 | 39 | $this->settings_page = $settings_page; |
| 40 | 40 | |
@@ -49,17 +49,17 @@ discard block |
||
| 49 | 49 | * |
| 50 | 50 | * @return array An array of links including those added by the plugin. |
| 51 | 51 | */ |
| 52 | - function action_links( $links ) { |
|
| 52 | + function action_links($links) { |
|
| 53 | 53 | |
| 54 | 54 | // Get the menu slug from the page, then prepare the path, hence the url. |
| 55 | 55 | $menu_slug = $this->settings_page->get_menu_slug(); |
| 56 | 56 | $path = "admin.php?page=$menu_slug"; |
| 57 | - $url = get_admin_url( null, $path ); |
|
| 57 | + $url = get_admin_url(null, $path); |
|
| 58 | 58 | |
| 59 | 59 | // Add our own link to the list of links. |
| 60 | - return array_merge( $links, array( |
|
| 61 | - sprintf( "<a href='$url'>%s</a>", __( 'Settings', 'wordlift' ) ), |
|
| 62 | - ) ); |
|
| 60 | + return array_merge($links, array( |
|
| 61 | + sprintf("<a href='$url'>%s</a>", __('Settings', 'wordlift')), |
|
| 62 | + )); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | } |
@@ -18,104 +18,104 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | class Wordlift_Google_Analytics_Export_Service { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Export the site data that could be imported in Google Analytics. |
|
| 23 | - * It will works only when permalink structure is set to "Postname". |
|
| 24 | - * |
|
| 25 | - * @since 3.16.0 |
|
| 26 | - * |
|
| 27 | - * @return void |
|
| 28 | - */ |
|
| 29 | - public function export() { |
|
| 30 | - // Bail if the permalink structure is different from "Post name". |
|
| 31 | - if ( ! $this->is_postname_permalink_structure() ) { |
|
| 32 | - wp_die( 'The current permalink structure do not allow to export your data. Please change the permalink structure to "Post name".' ); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - // Output the file data. @codingStandardsIgnoreLine |
|
| 36 | - @ob_end_clean(); |
|
| 37 | - |
|
| 38 | - // Generate unique filename using current timestamp. |
|
| 39 | - $filename = 'wl-ga-export-' . date( 'Y-m-d-H-i-s' ) . '.csv'; |
|
| 40 | - |
|
| 41 | - // Add proper file headers. |
|
| 42 | - header( "Content-Disposition: attachment; filename=$filename" ); |
|
| 43 | - header( 'Content-Type: text/csv; charset=' . get_bloginfo( 'charset' ) ); |
|
| 44 | - |
|
| 45 | - // Do not cache the file. |
|
| 46 | - header( 'Pragma: no-cache' ); |
|
| 47 | - header( 'Expires: 0' ); |
|
| 48 | - |
|
| 49 | - // Build the CSV file. |
|
| 50 | - $this->create_csv(); |
|
| 51 | - |
|
| 52 | - wp_die(); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Return site path. Some installations are in subdirectories |
|
| 57 | - * and we need add them to expported permalinks. |
|
| 58 | - * |
|
| 59 | - * @since 3.16.0 |
|
| 60 | - * |
|
| 61 | - * @return string The site path. |
|
| 62 | - */ |
|
| 63 | - public function get_site_path() { |
|
| 64 | - // Get home url from database. |
|
| 65 | - $home_url = home_url( '/' ); |
|
| 66 | - |
|
| 67 | - // Parse the url. |
|
| 68 | - $parsed = wp_parse_url( $home_url ); |
|
| 69 | - |
|
| 70 | - // Return the path. |
|
| 71 | - return $parsed['path']; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Check if the current permalink structure is set to "Post name". |
|
| 77 | - * |
|
| 78 | - * @since 3.16.0 |
|
| 79 | - * |
|
| 80 | - * @return bool whether the structure is "Post name" or not. |
|
| 81 | - */ |
|
| 82 | - public static function is_postname_permalink_structure() { |
|
| 83 | - // Get current permalink structure. |
|
| 84 | - $structure = get_option( 'permalink_structure' ); |
|
| 85 | - |
|
| 86 | - // The regular expression. It will check if the site structure contains postname. |
|
| 87 | - $regex = '~^/\%postname\%/$~'; |
|
| 88 | - |
|
| 89 | - // Check if the site structure match the rquired one. |
|
| 90 | - preg_match( $regex, $structure, $matches ); |
|
| 91 | - |
|
| 92 | - // Bail if the site have different structure. |
|
| 93 | - if ( empty( $matches ) ) { |
|
| 94 | - return false; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - return true; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Generate array data, that should be exported as csv. |
|
| 102 | - * The data contains the post/page title, entity name and type. |
|
| 103 | - * |
|
| 104 | - * @since 3.16.0 |
|
| 105 | - * |
|
| 106 | - * @return array $items Content data. |
|
| 107 | - */ |
|
| 108 | - public function get_content_data() { |
|
| 109 | - // Get the global $wpdb. |
|
| 110 | - global $wpdb; |
|
| 111 | - |
|
| 112 | - // Site path (optional). |
|
| 113 | - $path = $this->get_site_path(); |
|
| 114 | - |
|
| 115 | - // Get the data. |
|
| 116 | - $items = $wpdb->get_results( |
|
| 117 | - $wpdb->prepare( |
|
| 118 | - "SELECT |
|
| 21 | + /** |
|
| 22 | + * Export the site data that could be imported in Google Analytics. |
|
| 23 | + * It will works only when permalink structure is set to "Postname". |
|
| 24 | + * |
|
| 25 | + * @since 3.16.0 |
|
| 26 | + * |
|
| 27 | + * @return void |
|
| 28 | + */ |
|
| 29 | + public function export() { |
|
| 30 | + // Bail if the permalink structure is different from "Post name". |
|
| 31 | + if ( ! $this->is_postname_permalink_structure() ) { |
|
| 32 | + wp_die( 'The current permalink structure do not allow to export your data. Please change the permalink structure to "Post name".' ); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + // Output the file data. @codingStandardsIgnoreLine |
|
| 36 | + @ob_end_clean(); |
|
| 37 | + |
|
| 38 | + // Generate unique filename using current timestamp. |
|
| 39 | + $filename = 'wl-ga-export-' . date( 'Y-m-d-H-i-s' ) . '.csv'; |
|
| 40 | + |
|
| 41 | + // Add proper file headers. |
|
| 42 | + header( "Content-Disposition: attachment; filename=$filename" ); |
|
| 43 | + header( 'Content-Type: text/csv; charset=' . get_bloginfo( 'charset' ) ); |
|
| 44 | + |
|
| 45 | + // Do not cache the file. |
|
| 46 | + header( 'Pragma: no-cache' ); |
|
| 47 | + header( 'Expires: 0' ); |
|
| 48 | + |
|
| 49 | + // Build the CSV file. |
|
| 50 | + $this->create_csv(); |
|
| 51 | + |
|
| 52 | + wp_die(); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Return site path. Some installations are in subdirectories |
|
| 57 | + * and we need add them to expported permalinks. |
|
| 58 | + * |
|
| 59 | + * @since 3.16.0 |
|
| 60 | + * |
|
| 61 | + * @return string The site path. |
|
| 62 | + */ |
|
| 63 | + public function get_site_path() { |
|
| 64 | + // Get home url from database. |
|
| 65 | + $home_url = home_url( '/' ); |
|
| 66 | + |
|
| 67 | + // Parse the url. |
|
| 68 | + $parsed = wp_parse_url( $home_url ); |
|
| 69 | + |
|
| 70 | + // Return the path. |
|
| 71 | + return $parsed['path']; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Check if the current permalink structure is set to "Post name". |
|
| 77 | + * |
|
| 78 | + * @since 3.16.0 |
|
| 79 | + * |
|
| 80 | + * @return bool whether the structure is "Post name" or not. |
|
| 81 | + */ |
|
| 82 | + public static function is_postname_permalink_structure() { |
|
| 83 | + // Get current permalink structure. |
|
| 84 | + $structure = get_option( 'permalink_structure' ); |
|
| 85 | + |
|
| 86 | + // The regular expression. It will check if the site structure contains postname. |
|
| 87 | + $regex = '~^/\%postname\%/$~'; |
|
| 88 | + |
|
| 89 | + // Check if the site structure match the rquired one. |
|
| 90 | + preg_match( $regex, $structure, $matches ); |
|
| 91 | + |
|
| 92 | + // Bail if the site have different structure. |
|
| 93 | + if ( empty( $matches ) ) { |
|
| 94 | + return false; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + return true; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Generate array data, that should be exported as csv. |
|
| 102 | + * The data contains the post/page title, entity name and type. |
|
| 103 | + * |
|
| 104 | + * @since 3.16.0 |
|
| 105 | + * |
|
| 106 | + * @return array $items Content data. |
|
| 107 | + */ |
|
| 108 | + public function get_content_data() { |
|
| 109 | + // Get the global $wpdb. |
|
| 110 | + global $wpdb; |
|
| 111 | + |
|
| 112 | + // Site path (optional). |
|
| 113 | + $path = $this->get_site_path(); |
|
| 114 | + |
|
| 115 | + // Get the data. |
|
| 116 | + $items = $wpdb->get_results( |
|
| 117 | + $wpdb->prepare( |
|
| 118 | + "SELECT |
|
| 119 | 119 | CONCAT( '%s', p.post_name, '/' ) AS 'post_name', |
| 120 | 120 | p1.post_name AS 'entity_name', |
| 121 | 121 | t.slug AS 'entity_type' |
@@ -132,43 +132,43 @@ discard block |
||
| 132 | 132 | INNER JOIN {$wpdb->prefix}terms t |
| 133 | 133 | ON t.term_id = tt.term_id |
| 134 | 134 | WHERE p.post_type IN ( 'page', 'post' );", |
| 135 | - $path |
|
| 136 | - ) |
|
| 137 | - ); // db call ok; no-cache ok. |
|
| 138 | - |
|
| 139 | - return $items; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Create the CSV file that will be downloaded. |
|
| 144 | - * |
|
| 145 | - * @since 3.16.0 |
|
| 146 | - * |
|
| 147 | - * @return void |
|
| 148 | - */ |
|
| 149 | - public function create_csv() { |
|
| 150 | - // Create a file pointer connected to the output stream. |
|
| 151 | - // Ignoring linter notices below that complain about file output which do not actually happen. |
|
| 152 | - $file = fopen( 'php://output', 'w' ); |
|
| 153 | - |
|
| 154 | - // Add the column headers. @codingStandardsIgnoreLine |
|
| 155 | - fputcsv( |
|
| 156 | - $file, |
|
| 157 | - array( |
|
| 158 | - 'ga:pagePath', |
|
| 159 | - 'ga:dimension1', |
|
| 160 | - 'ga:dimension2', |
|
| 161 | - ) |
|
| 162 | - ); |
|
| 163 | - |
|
| 164 | - // Cycle through items and add each item data to the file. |
|
| 165 | - foreach ( $this->get_content_data() as $row ) { |
|
| 166 | - // Add new line in the file. @codingStandardsIgnoreLine |
|
| 167 | - fputcsv( |
|
| 168 | - $file, |
|
| 169 | - (array) $row // convert the object to array. |
|
| 170 | - ); |
|
| 171 | - } |
|
| 172 | - } |
|
| 135 | + $path |
|
| 136 | + ) |
|
| 137 | + ); // db call ok; no-cache ok. |
|
| 138 | + |
|
| 139 | + return $items; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Create the CSV file that will be downloaded. |
|
| 144 | + * |
|
| 145 | + * @since 3.16.0 |
|
| 146 | + * |
|
| 147 | + * @return void |
|
| 148 | + */ |
|
| 149 | + public function create_csv() { |
|
| 150 | + // Create a file pointer connected to the output stream. |
|
| 151 | + // Ignoring linter notices below that complain about file output which do not actually happen. |
|
| 152 | + $file = fopen( 'php://output', 'w' ); |
|
| 153 | + |
|
| 154 | + // Add the column headers. @codingStandardsIgnoreLine |
|
| 155 | + fputcsv( |
|
| 156 | + $file, |
|
| 157 | + array( |
|
| 158 | + 'ga:pagePath', |
|
| 159 | + 'ga:dimension1', |
|
| 160 | + 'ga:dimension2', |
|
| 161 | + ) |
|
| 162 | + ); |
|
| 163 | + |
|
| 164 | + // Cycle through items and add each item data to the file. |
|
| 165 | + foreach ( $this->get_content_data() as $row ) { |
|
| 166 | + // Add new line in the file. @codingStandardsIgnoreLine |
|
| 167 | + fputcsv( |
|
| 168 | + $file, |
|
| 169 | + (array) $row // convert the object to array. |
|
| 170 | + ); |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | 174 | } |
@@ -28,23 +28,23 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | public function export() { |
| 30 | 30 | // Bail if the permalink structure is different from "Post name". |
| 31 | - if ( ! $this->is_postname_permalink_structure() ) { |
|
| 32 | - wp_die( 'The current permalink structure do not allow to export your data. Please change the permalink structure to "Post name".' ); |
|
| 31 | + if ( ! $this->is_postname_permalink_structure()) { |
|
| 32 | + wp_die('The current permalink structure do not allow to export your data. Please change the permalink structure to "Post name".'); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | // Output the file data. @codingStandardsIgnoreLine |
| 36 | 36 | @ob_end_clean(); |
| 37 | 37 | |
| 38 | 38 | // Generate unique filename using current timestamp. |
| 39 | - $filename = 'wl-ga-export-' . date( 'Y-m-d-H-i-s' ) . '.csv'; |
|
| 39 | + $filename = 'wl-ga-export-'.date('Y-m-d-H-i-s').'.csv'; |
|
| 40 | 40 | |
| 41 | 41 | // Add proper file headers. |
| 42 | - header( "Content-Disposition: attachment; filename=$filename" ); |
|
| 43 | - header( 'Content-Type: text/csv; charset=' . get_bloginfo( 'charset' ) ); |
|
| 42 | + header("Content-Disposition: attachment; filename=$filename"); |
|
| 43 | + header('Content-Type: text/csv; charset='.get_bloginfo('charset')); |
|
| 44 | 44 | |
| 45 | 45 | // Do not cache the file. |
| 46 | - header( 'Pragma: no-cache' ); |
|
| 47 | - header( 'Expires: 0' ); |
|
| 46 | + header('Pragma: no-cache'); |
|
| 47 | + header('Expires: 0'); |
|
| 48 | 48 | |
| 49 | 49 | // Build the CSV file. |
| 50 | 50 | $this->create_csv(); |
@@ -62,10 +62,10 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | public function get_site_path() { |
| 64 | 64 | // Get home url from database. |
| 65 | - $home_url = home_url( '/' ); |
|
| 65 | + $home_url = home_url('/'); |
|
| 66 | 66 | |
| 67 | 67 | // Parse the url. |
| 68 | - $parsed = wp_parse_url( $home_url ); |
|
| 68 | + $parsed = wp_parse_url($home_url); |
|
| 69 | 69 | |
| 70 | 70 | // Return the path. |
| 71 | 71 | return $parsed['path']; |
@@ -81,16 +81,16 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | public static function is_postname_permalink_structure() { |
| 83 | 83 | // Get current permalink structure. |
| 84 | - $structure = get_option( 'permalink_structure' ); |
|
| 84 | + $structure = get_option('permalink_structure'); |
|
| 85 | 85 | |
| 86 | 86 | // The regular expression. It will check if the site structure contains postname. |
| 87 | 87 | $regex = '~^/\%postname\%/$~'; |
| 88 | 88 | |
| 89 | 89 | // Check if the site structure match the rquired one. |
| 90 | - preg_match( $regex, $structure, $matches ); |
|
| 90 | + preg_match($regex, $structure, $matches); |
|
| 91 | 91 | |
| 92 | 92 | // Bail if the site have different structure. |
| 93 | - if ( empty( $matches ) ) { |
|
| 93 | + if (empty($matches)) { |
|
| 94 | 94 | return false; |
| 95 | 95 | } |
| 96 | 96 | |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | public function create_csv() { |
| 150 | 150 | // Create a file pointer connected to the output stream. |
| 151 | 151 | // Ignoring linter notices below that complain about file output which do not actually happen. |
| 152 | - $file = fopen( 'php://output', 'w' ); |
|
| 152 | + $file = fopen('php://output', 'w'); |
|
| 153 | 153 | |
| 154 | 154 | // Add the column headers. @codingStandardsIgnoreLine |
| 155 | 155 | fputcsv( |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | ); |
| 163 | 163 | |
| 164 | 164 | // Cycle through items and add each item data to the file. |
| 165 | - foreach ( $this->get_content_data() as $row ) { |
|
| 165 | + foreach ($this->get_content_data() as $row) { |
|
| 166 | 166 | // Add new line in the file. @codingStandardsIgnoreLine |
| 167 | 167 | fputcsv( |
| 168 | 168 | $file, |
@@ -18,68 +18,68 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class Wordlift_Sparql_Query_Async_Task extends Wordlift_Async_Task { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * The protected $action property should be set to the action to which you |
|
| 23 | - * wish to attach the asynchronous task. For example, if you want to spin |
|
| 24 | - * off an asynchronous task whenever a post gets saved, you would set this |
|
| 25 | - * to save_post. |
|
| 26 | - * |
|
| 27 | - * @since 3.13.2 |
|
| 28 | - * @access protected |
|
| 29 | - * @var string $action The action to which you wish to attach the |
|
| 30 | - * asynchronous task. |
|
| 31 | - */ |
|
| 32 | - protected $action = 'wl_run_sparql_query'; |
|
| 21 | + /** |
|
| 22 | + * The protected $action property should be set to the action to which you |
|
| 23 | + * wish to attach the asynchronous task. For example, if you want to spin |
|
| 24 | + * off an asynchronous task whenever a post gets saved, you would set this |
|
| 25 | + * to save_post. |
|
| 26 | + * |
|
| 27 | + * @since 3.13.2 |
|
| 28 | + * @access protected |
|
| 29 | + * @var string $action The action to which you wish to attach the |
|
| 30 | + * asynchronous task. |
|
| 31 | + */ |
|
| 32 | + protected $action = 'wl_run_sparql_query'; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * A {@link Wordlift_Log_Service} instance. |
|
| 36 | - * |
|
| 37 | - * @since 3.13.2 |
|
| 38 | - * @access private |
|
| 39 | - * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 40 | - */ |
|
| 41 | - private $log; |
|
| 34 | + /** |
|
| 35 | + * A {@link Wordlift_Log_Service} instance. |
|
| 36 | + * |
|
| 37 | + * @since 3.13.2 |
|
| 38 | + * @access private |
|
| 39 | + * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 40 | + */ |
|
| 41 | + private $log; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Create a {@link Wordlift_Sparql_Query_Async_Task} instance. |
|
| 45 | - * |
|
| 46 | - * @since 3.13.2 |
|
| 47 | - * |
|
| 48 | - * @param int $auth_level The authentication level to use (see above) |
|
| 49 | - */ |
|
| 50 | - public function __construct( $auth_level = self::BOTH ) { |
|
| 51 | - parent::__construct( $auth_level ); |
|
| 43 | + /** |
|
| 44 | + * Create a {@link Wordlift_Sparql_Query_Async_Task} instance. |
|
| 45 | + * |
|
| 46 | + * @since 3.13.2 |
|
| 47 | + * |
|
| 48 | + * @param int $auth_level The authentication level to use (see above) |
|
| 49 | + */ |
|
| 50 | + public function __construct( $auth_level = self::BOTH ) { |
|
| 51 | + parent::__construct( $auth_level ); |
|
| 52 | 52 | |
| 53 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Sparql_Query_Async_Task' ); |
|
| 53 | + $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Sparql_Query_Async_Task' ); |
|
| 54 | 54 | |
| 55 | - } |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * @inheritdoc |
|
| 60 | - */ |
|
| 61 | - protected function prepare_data( $data ) { |
|
| 58 | + /** |
|
| 59 | + * @inheritdoc |
|
| 60 | + */ |
|
| 61 | + protected function prepare_data( $data ) { |
|
| 62 | 62 | |
| 63 | - // Return the request id, which is used to get the sparql queries stored |
|
| 64 | - // in the temporary files. |
|
| 65 | - return array( 'request_id' => $data[0] ); |
|
| 66 | - } |
|
| 63 | + // Return the request id, which is used to get the sparql queries stored |
|
| 64 | + // in the temporary files. |
|
| 65 | + return array( 'request_id' => $data[0] ); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * @inheritdoc |
|
| 70 | - */ |
|
| 71 | - protected function run_action() { |
|
| 68 | + /** |
|
| 69 | + * @inheritdoc |
|
| 70 | + */ |
|
| 71 | + protected function run_action() { |
|
| 72 | 72 | |
| 73 | - // Bail out if there's no request id. |
|
| 74 | - if ( ! isset( $_POST['request_id'] ) ) { |
|
| 75 | - $this->log->warn( 'Request Id not found.' ); |
|
| 73 | + // Bail out if there's no request id. |
|
| 74 | + if ( ! isset( $_POST['request_id'] ) ) { |
|
| 75 | + $this->log->warn( 'Request Id not found.' ); |
|
| 76 | 76 | |
| 77 | - return; |
|
| 78 | - } |
|
| 77 | + return; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - // Run the asynchronous action. |
|
| 81 | - do_action( "wl_async_$this->action", $_POST['request_id'] ); |
|
| 80 | + // Run the asynchronous action. |
|
| 81 | + do_action( "wl_async_$this->action", $_POST['request_id'] ); |
|
| 82 | 82 | |
| 83 | - } |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | 85 | } |
@@ -47,10 +47,10 @@ discard block |
||
| 47 | 47 | * |
| 48 | 48 | * @param int $auth_level The authentication level to use (see above) |
| 49 | 49 | */ |
| 50 | - public function __construct( $auth_level = self::BOTH ) { |
|
| 51 | - parent::__construct( $auth_level ); |
|
| 50 | + public function __construct($auth_level = self::BOTH) { |
|
| 51 | + parent::__construct($auth_level); |
|
| 52 | 52 | |
| 53 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Sparql_Query_Async_Task' ); |
|
| 53 | + $this->log = Wordlift_Log_Service::get_logger('Wordlift_Sparql_Query_Async_Task'); |
|
| 54 | 54 | |
| 55 | 55 | } |
| 56 | 56 | |
@@ -58,11 +58,11 @@ discard block |
||
| 58 | 58 | /** |
| 59 | 59 | * @inheritdoc |
| 60 | 60 | */ |
| 61 | - protected function prepare_data( $data ) { |
|
| 61 | + protected function prepare_data($data) { |
|
| 62 | 62 | |
| 63 | 63 | // Return the request id, which is used to get the sparql queries stored |
| 64 | 64 | // in the temporary files. |
| 65 | - return array( 'request_id' => $data[0] ); |
|
| 65 | + return array('request_id' => $data[0]); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -71,14 +71,14 @@ discard block |
||
| 71 | 71 | protected function run_action() { |
| 72 | 72 | |
| 73 | 73 | // Bail out if there's no request id. |
| 74 | - if ( ! isset( $_POST['request_id'] ) ) { |
|
| 75 | - $this->log->warn( 'Request Id not found.' ); |
|
| 74 | + if ( ! isset($_POST['request_id'])) { |
|
| 75 | + $this->log->warn('Request Id not found.'); |
|
| 76 | 76 | |
| 77 | 77 | return; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | // Run the asynchronous action. |
| 81 | - do_action( "wl_async_$this->action", $_POST['request_id'] ); |
|
| 81 | + do_action("wl_async_$this->action", $_POST['request_id']); |
|
| 82 | 82 | |
| 83 | 83 | } |
| 84 | 84 | |
@@ -19,188 +19,188 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class Wordlift_Import_Service { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * A {@link Wordlift_Log_Service} instance. |
|
| 24 | - * |
|
| 25 | - * @since 3.6.0 |
|
| 26 | - * @access private |
|
| 27 | - * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 28 | - */ |
|
| 29 | - private $log; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * A {@link Wordlift_Entity_Type_Service} instance. |
|
| 33 | - * |
|
| 34 | - * @since 3.6.0 |
|
| 35 | - * @access private |
|
| 36 | - * @var \Wordlift_Entity_Post_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance. |
|
| 37 | - */ |
|
| 38 | - private $entity_type_service; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * The entity service instance. |
|
| 42 | - * |
|
| 43 | - * @since 3.6.0 |
|
| 44 | - * @access private |
|
| 45 | - * @var \Wordlift_Entity_Service $entity_service The entity service instance. |
|
| 46 | - */ |
|
| 47 | - private $entity_service; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * The schema service instance. |
|
| 51 | - * |
|
| 52 | - * @since 3.6.0 |
|
| 53 | - * @access private |
|
| 54 | - * @var \Wordlift_Schema_Service $schema_service The schema service instance. |
|
| 55 | - */ |
|
| 56 | - private $schema_service; |
|
| 57 | - |
|
| 58 | - private $sparql_service; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * The dataset URI for this WordPress web site. |
|
| 62 | - * |
|
| 63 | - * @since 3.6.0 |
|
| 64 | - * @access private |
|
| 65 | - * @var string $dataset_uri The dataset URI for this WordPress web site. |
|
| 66 | - */ |
|
| 67 | - private $dataset_uri; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Create a Wordlift_Import_Service instance. |
|
| 71 | - * |
|
| 72 | - * @since 3.6.0 |
|
| 73 | - * |
|
| 74 | - * @param \Wordlift_Entity_Post_Type_Service $entity_type_service |
|
| 75 | - * @param \Wordlift_Entity_Service $entity_service |
|
| 76 | - * @param \Wordlift_Schema_Service $schema_service |
|
| 77 | - * @param \Wordlift_Sparql_Service $sparql_service |
|
| 78 | - * @param string $dataset_uri |
|
| 79 | - */ |
|
| 80 | - public function __construct( $entity_type_service, $entity_service, $schema_service, $sparql_service, $dataset_uri ) { |
|
| 81 | - |
|
| 82 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Import_Service' ); |
|
| 83 | - |
|
| 84 | - $this->entity_type_service = $entity_type_service; |
|
| 85 | - $this->entity_service = $entity_service; |
|
| 86 | - $this->schema_service = $schema_service; |
|
| 87 | - $this->sparql_service = $sparql_service; |
|
| 88 | - $this->dataset_uri = $dataset_uri; |
|
| 89 | - |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Handle the `wp_import_post_meta` filter by checking the `entity_url` meta. |
|
| 94 | - * If the `entity_url` meta value is not within the WP web site dataset URI, |
|
| 95 | - * it is changed into an `entity_same_as` meta key. |
|
| 96 | - * |
|
| 97 | - * @since 3.6.0 |
|
| 98 | - * |
|
| 99 | - * @param array $postmeta An array of indexed post meta. |
|
| 100 | - * @param int $post_id The post ID being imported. |
|
| 101 | - * @param array $post An array of post properties. |
|
| 102 | - * |
|
| 103 | - * @return array An array of indexed post meta. |
|
| 104 | - */ |
|
| 105 | - public function wp_import_post_meta( $postmeta, $post_id, $post ) { |
|
| 106 | - |
|
| 107 | - // If we're not dealing with entity posts, return the original post meta. |
|
| 108 | - if ( ! $this->entity_service->is_entity( $post_id ) ) { |
|
| 109 | - return $postmeta; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - // Get a reference to the entity URL meta. |
|
| 113 | - $entity_url_meta = null; |
|
| 114 | - |
|
| 115 | - foreach ( $postmeta as &$meta ) { |
|
| 116 | - if ( 'entity_url' === $meta['key'] ) { |
|
| 117 | - $entity_url_meta = &$meta; |
|
| 118 | - break; |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - // If the entity URI is within the dataset URI, we don't change anything. |
|
| 123 | - if ( null === $entity_url_meta || 0 === strpos( $entity_url_meta['value'], $this->dataset_uri ) ) { |
|
| 124 | - return $postmeta; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - // Since the entity URL doesn't belong to this WP install, as the dataset |
|
| 128 | - // URI doesn't match the start of the entity URL, we turn the entity URL |
|
| 129 | - // meta to an entity sameAs. $entity_url_meta is a reference so it should |
|
| 130 | - // update the item in the postmeta array directly. |
|
| 131 | - $entity_url_meta['key'] = 'entity_same_as'; |
|
| 132 | - |
|
| 133 | - return $postmeta; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Catch post meta updates. |
|
| 138 | - * |
|
| 139 | - * @since 3.6.0 |
|
| 140 | - * |
|
| 141 | - * @param int $mid The meta ID after successful update. |
|
| 142 | - * @param int $object_id Object ID. |
|
| 143 | - * @param string $meta_key Meta key. |
|
| 144 | - * @param mixed $meta_value Meta value. |
|
| 145 | - */ |
|
| 146 | - public function added_post_meta( $mid, $object_id, $meta_key, $meta_value ) { |
|
| 147 | - |
|
| 148 | - // Get the entity URI. |
|
| 149 | - $s = $this->entity_service->get_uri( $object_id ); |
|
| 150 | - |
|
| 151 | - // Get the field with the specified meta key. Return if the field is not defined. |
|
| 152 | - if ( null === ( $field = $this->schema_service->get_field( $meta_key ) ) ) { |
|
| 153 | - return; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - // Get the field predicate. |
|
| 157 | - $p = $field['predicate']; |
|
| 158 | - |
|
| 159 | - // Format the object value according to the field type. |
|
| 160 | - $o = Wordlift_Sparql_Service::format( $meta_value, $field['type'] ); |
|
| 161 | - |
|
| 162 | - // Create the statement. |
|
| 163 | - $stmt = sprintf( 'INSERT DATA { <%s> <%s> %s };', Wordlift_Sparql_Service::escape_uri( $s ), Wordlift_Sparql_Service::escape_uri( $p ), $o ); |
|
| 164 | - |
|
| 165 | - // Finally queue the statement. |
|
| 166 | - $this->sparql_service->execute( $stmt ); |
|
| 167 | - |
|
| 168 | - // Removed. |
|
| 169 | - // |
|
| 170 | - // See https://github.com/insideout10/wordlift-plugin/issues/686. |
|
| 171 | - // |
|
| 172 | - // Clear up the cache to avoid memory errors. |
|
| 173 | - // wp_cache_flush(); |
|
| 174 | - |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * When an import is running, hook the {@link added_post_meta} function in order |
|
| 179 | - * to insert metadata from an import in Linked Data. |
|
| 180 | - * |
|
| 181 | - * @since 3.6.0 |
|
| 182 | - */ |
|
| 183 | - public function import_start() { |
|
| 184 | - |
|
| 185 | - add_action( 'added_post_meta', array( |
|
| 186 | - $this, |
|
| 187 | - 'added_post_meta', |
|
| 188 | - ), 10, 4 ); |
|
| 189 | - |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * When an import ends, remove the hook previously added by {@link import_start}. |
|
| 194 | - * |
|
| 195 | - * @since 3.6.0 |
|
| 196 | - */ |
|
| 197 | - public function import_end() { |
|
| 198 | - |
|
| 199 | - remove_action( 'added_post_meta', array( |
|
| 200 | - $this, |
|
| 201 | - 'added_post_meta', |
|
| 202 | - ), 10 ); |
|
| 203 | - |
|
| 204 | - } |
|
| 22 | + /** |
|
| 23 | + * A {@link Wordlift_Log_Service} instance. |
|
| 24 | + * |
|
| 25 | + * @since 3.6.0 |
|
| 26 | + * @access private |
|
| 27 | + * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 28 | + */ |
|
| 29 | + private $log; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * A {@link Wordlift_Entity_Type_Service} instance. |
|
| 33 | + * |
|
| 34 | + * @since 3.6.0 |
|
| 35 | + * @access private |
|
| 36 | + * @var \Wordlift_Entity_Post_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance. |
|
| 37 | + */ |
|
| 38 | + private $entity_type_service; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * The entity service instance. |
|
| 42 | + * |
|
| 43 | + * @since 3.6.0 |
|
| 44 | + * @access private |
|
| 45 | + * @var \Wordlift_Entity_Service $entity_service The entity service instance. |
|
| 46 | + */ |
|
| 47 | + private $entity_service; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * The schema service instance. |
|
| 51 | + * |
|
| 52 | + * @since 3.6.0 |
|
| 53 | + * @access private |
|
| 54 | + * @var \Wordlift_Schema_Service $schema_service The schema service instance. |
|
| 55 | + */ |
|
| 56 | + private $schema_service; |
|
| 57 | + |
|
| 58 | + private $sparql_service; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * The dataset URI for this WordPress web site. |
|
| 62 | + * |
|
| 63 | + * @since 3.6.0 |
|
| 64 | + * @access private |
|
| 65 | + * @var string $dataset_uri The dataset URI for this WordPress web site. |
|
| 66 | + */ |
|
| 67 | + private $dataset_uri; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Create a Wordlift_Import_Service instance. |
|
| 71 | + * |
|
| 72 | + * @since 3.6.0 |
|
| 73 | + * |
|
| 74 | + * @param \Wordlift_Entity_Post_Type_Service $entity_type_service |
|
| 75 | + * @param \Wordlift_Entity_Service $entity_service |
|
| 76 | + * @param \Wordlift_Schema_Service $schema_service |
|
| 77 | + * @param \Wordlift_Sparql_Service $sparql_service |
|
| 78 | + * @param string $dataset_uri |
|
| 79 | + */ |
|
| 80 | + public function __construct( $entity_type_service, $entity_service, $schema_service, $sparql_service, $dataset_uri ) { |
|
| 81 | + |
|
| 82 | + $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Import_Service' ); |
|
| 83 | + |
|
| 84 | + $this->entity_type_service = $entity_type_service; |
|
| 85 | + $this->entity_service = $entity_service; |
|
| 86 | + $this->schema_service = $schema_service; |
|
| 87 | + $this->sparql_service = $sparql_service; |
|
| 88 | + $this->dataset_uri = $dataset_uri; |
|
| 89 | + |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Handle the `wp_import_post_meta` filter by checking the `entity_url` meta. |
|
| 94 | + * If the `entity_url` meta value is not within the WP web site dataset URI, |
|
| 95 | + * it is changed into an `entity_same_as` meta key. |
|
| 96 | + * |
|
| 97 | + * @since 3.6.0 |
|
| 98 | + * |
|
| 99 | + * @param array $postmeta An array of indexed post meta. |
|
| 100 | + * @param int $post_id The post ID being imported. |
|
| 101 | + * @param array $post An array of post properties. |
|
| 102 | + * |
|
| 103 | + * @return array An array of indexed post meta. |
|
| 104 | + */ |
|
| 105 | + public function wp_import_post_meta( $postmeta, $post_id, $post ) { |
|
| 106 | + |
|
| 107 | + // If we're not dealing with entity posts, return the original post meta. |
|
| 108 | + if ( ! $this->entity_service->is_entity( $post_id ) ) { |
|
| 109 | + return $postmeta; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + // Get a reference to the entity URL meta. |
|
| 113 | + $entity_url_meta = null; |
|
| 114 | + |
|
| 115 | + foreach ( $postmeta as &$meta ) { |
|
| 116 | + if ( 'entity_url' === $meta['key'] ) { |
|
| 117 | + $entity_url_meta = &$meta; |
|
| 118 | + break; |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + // If the entity URI is within the dataset URI, we don't change anything. |
|
| 123 | + if ( null === $entity_url_meta || 0 === strpos( $entity_url_meta['value'], $this->dataset_uri ) ) { |
|
| 124 | + return $postmeta; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + // Since the entity URL doesn't belong to this WP install, as the dataset |
|
| 128 | + // URI doesn't match the start of the entity URL, we turn the entity URL |
|
| 129 | + // meta to an entity sameAs. $entity_url_meta is a reference so it should |
|
| 130 | + // update the item in the postmeta array directly. |
|
| 131 | + $entity_url_meta['key'] = 'entity_same_as'; |
|
| 132 | + |
|
| 133 | + return $postmeta; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Catch post meta updates. |
|
| 138 | + * |
|
| 139 | + * @since 3.6.0 |
|
| 140 | + * |
|
| 141 | + * @param int $mid The meta ID after successful update. |
|
| 142 | + * @param int $object_id Object ID. |
|
| 143 | + * @param string $meta_key Meta key. |
|
| 144 | + * @param mixed $meta_value Meta value. |
|
| 145 | + */ |
|
| 146 | + public function added_post_meta( $mid, $object_id, $meta_key, $meta_value ) { |
|
| 147 | + |
|
| 148 | + // Get the entity URI. |
|
| 149 | + $s = $this->entity_service->get_uri( $object_id ); |
|
| 150 | + |
|
| 151 | + // Get the field with the specified meta key. Return if the field is not defined. |
|
| 152 | + if ( null === ( $field = $this->schema_service->get_field( $meta_key ) ) ) { |
|
| 153 | + return; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + // Get the field predicate. |
|
| 157 | + $p = $field['predicate']; |
|
| 158 | + |
|
| 159 | + // Format the object value according to the field type. |
|
| 160 | + $o = Wordlift_Sparql_Service::format( $meta_value, $field['type'] ); |
|
| 161 | + |
|
| 162 | + // Create the statement. |
|
| 163 | + $stmt = sprintf( 'INSERT DATA { <%s> <%s> %s };', Wordlift_Sparql_Service::escape_uri( $s ), Wordlift_Sparql_Service::escape_uri( $p ), $o ); |
|
| 164 | + |
|
| 165 | + // Finally queue the statement. |
|
| 166 | + $this->sparql_service->execute( $stmt ); |
|
| 167 | + |
|
| 168 | + // Removed. |
|
| 169 | + // |
|
| 170 | + // See https://github.com/insideout10/wordlift-plugin/issues/686. |
|
| 171 | + // |
|
| 172 | + // Clear up the cache to avoid memory errors. |
|
| 173 | + // wp_cache_flush(); |
|
| 174 | + |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * When an import is running, hook the {@link added_post_meta} function in order |
|
| 179 | + * to insert metadata from an import in Linked Data. |
|
| 180 | + * |
|
| 181 | + * @since 3.6.0 |
|
| 182 | + */ |
|
| 183 | + public function import_start() { |
|
| 184 | + |
|
| 185 | + add_action( 'added_post_meta', array( |
|
| 186 | + $this, |
|
| 187 | + 'added_post_meta', |
|
| 188 | + ), 10, 4 ); |
|
| 189 | + |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * When an import ends, remove the hook previously added by {@link import_start}. |
|
| 194 | + * |
|
| 195 | + * @since 3.6.0 |
|
| 196 | + */ |
|
| 197 | + public function import_end() { |
|
| 198 | + |
|
| 199 | + remove_action( 'added_post_meta', array( |
|
| 200 | + $this, |
|
| 201 | + 'added_post_meta', |
|
| 202 | + ), 10 ); |
|
| 203 | + |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | 206 | } |
@@ -77,9 +77,9 @@ discard block |
||
| 77 | 77 | * @param \Wordlift_Sparql_Service $sparql_service |
| 78 | 78 | * @param string $dataset_uri |
| 79 | 79 | */ |
| 80 | - public function __construct( $entity_type_service, $entity_service, $schema_service, $sparql_service, $dataset_uri ) { |
|
| 80 | + public function __construct($entity_type_service, $entity_service, $schema_service, $sparql_service, $dataset_uri) { |
|
| 81 | 81 | |
| 82 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Import_Service' ); |
|
| 82 | + $this->log = Wordlift_Log_Service::get_logger('Wordlift_Import_Service'); |
|
| 83 | 83 | |
| 84 | 84 | $this->entity_type_service = $entity_type_service; |
| 85 | 85 | $this->entity_service = $entity_service; |
@@ -102,25 +102,25 @@ discard block |
||
| 102 | 102 | * |
| 103 | 103 | * @return array An array of indexed post meta. |
| 104 | 104 | */ |
| 105 | - public function wp_import_post_meta( $postmeta, $post_id, $post ) { |
|
| 105 | + public function wp_import_post_meta($postmeta, $post_id, $post) { |
|
| 106 | 106 | |
| 107 | 107 | // If we're not dealing with entity posts, return the original post meta. |
| 108 | - if ( ! $this->entity_service->is_entity( $post_id ) ) { |
|
| 108 | + if ( ! $this->entity_service->is_entity($post_id)) { |
|
| 109 | 109 | return $postmeta; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | // Get a reference to the entity URL meta. |
| 113 | 113 | $entity_url_meta = null; |
| 114 | 114 | |
| 115 | - foreach ( $postmeta as &$meta ) { |
|
| 116 | - if ( 'entity_url' === $meta['key'] ) { |
|
| 115 | + foreach ($postmeta as &$meta) { |
|
| 116 | + if ('entity_url' === $meta['key']) { |
|
| 117 | 117 | $entity_url_meta = &$meta; |
| 118 | 118 | break; |
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | // If the entity URI is within the dataset URI, we don't change anything. |
| 123 | - if ( null === $entity_url_meta || 0 === strpos( $entity_url_meta['value'], $this->dataset_uri ) ) { |
|
| 123 | + if (null === $entity_url_meta || 0 === strpos($entity_url_meta['value'], $this->dataset_uri)) { |
|
| 124 | 124 | return $postmeta; |
| 125 | 125 | } |
| 126 | 126 | |
@@ -143,13 +143,13 @@ discard block |
||
| 143 | 143 | * @param string $meta_key Meta key. |
| 144 | 144 | * @param mixed $meta_value Meta value. |
| 145 | 145 | */ |
| 146 | - public function added_post_meta( $mid, $object_id, $meta_key, $meta_value ) { |
|
| 146 | + public function added_post_meta($mid, $object_id, $meta_key, $meta_value) { |
|
| 147 | 147 | |
| 148 | 148 | // Get the entity URI. |
| 149 | - $s = $this->entity_service->get_uri( $object_id ); |
|
| 149 | + $s = $this->entity_service->get_uri($object_id); |
|
| 150 | 150 | |
| 151 | 151 | // Get the field with the specified meta key. Return if the field is not defined. |
| 152 | - if ( null === ( $field = $this->schema_service->get_field( $meta_key ) ) ) { |
|
| 152 | + if (null === ($field = $this->schema_service->get_field($meta_key))) { |
|
| 153 | 153 | return; |
| 154 | 154 | } |
| 155 | 155 | |
@@ -157,13 +157,13 @@ discard block |
||
| 157 | 157 | $p = $field['predicate']; |
| 158 | 158 | |
| 159 | 159 | // Format the object value according to the field type. |
| 160 | - $o = Wordlift_Sparql_Service::format( $meta_value, $field['type'] ); |
|
| 160 | + $o = Wordlift_Sparql_Service::format($meta_value, $field['type']); |
|
| 161 | 161 | |
| 162 | 162 | // Create the statement. |
| 163 | - $stmt = sprintf( 'INSERT DATA { <%s> <%s> %s };', Wordlift_Sparql_Service::escape_uri( $s ), Wordlift_Sparql_Service::escape_uri( $p ), $o ); |
|
| 163 | + $stmt = sprintf('INSERT DATA { <%s> <%s> %s };', Wordlift_Sparql_Service::escape_uri($s), Wordlift_Sparql_Service::escape_uri($p), $o); |
|
| 164 | 164 | |
| 165 | 165 | // Finally queue the statement. |
| 166 | - $this->sparql_service->execute( $stmt ); |
|
| 166 | + $this->sparql_service->execute($stmt); |
|
| 167 | 167 | |
| 168 | 168 | // Removed. |
| 169 | 169 | // |
@@ -182,10 +182,10 @@ discard block |
||
| 182 | 182 | */ |
| 183 | 183 | public function import_start() { |
| 184 | 184 | |
| 185 | - add_action( 'added_post_meta', array( |
|
| 185 | + add_action('added_post_meta', array( |
|
| 186 | 186 | $this, |
| 187 | 187 | 'added_post_meta', |
| 188 | - ), 10, 4 ); |
|
| 188 | + ), 10, 4); |
|
| 189 | 189 | |
| 190 | 190 | } |
| 191 | 191 | |
@@ -196,10 +196,10 @@ discard block |
||
| 196 | 196 | */ |
| 197 | 197 | public function import_end() { |
| 198 | 198 | |
| 199 | - remove_action( 'added_post_meta', array( |
|
| 199 | + remove_action('added_post_meta', array( |
|
| 200 | 200 | $this, |
| 201 | 201 | 'added_post_meta', |
| 202 | - ), 10 ); |
|
| 202 | + ), 10); |
|
| 203 | 203 | |
| 204 | 204 | } |
| 205 | 205 | |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | * @param \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance. |
| 166 | 166 | * @param \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance. |
| 167 | 167 | */ |
| 168 | - function __construct( $entity_type_service, $configuration_service, $user_service ) { |
|
| 168 | + function __construct($entity_type_service, $configuration_service, $user_service) { |
|
| 169 | 169 | |
| 170 | 170 | $this->entity_type_service = $entity_type_service; |
| 171 | 171 | $this->configuration_service = $configuration_service; |
@@ -180,14 +180,14 @@ discard block |
||
| 180 | 180 | function create() { |
| 181 | 181 | |
| 182 | 182 | // Get the source image path. |
| 183 | - $source = plugin_dir_path( dirname( __FILE__ ) ) . 'images/rome.png'; |
|
| 183 | + $source = plugin_dir_path(dirname(__FILE__)).'images/rome.png'; |
|
| 184 | 184 | |
| 185 | 185 | // Create an attachment with the local file. |
| 186 | - $attachment_id = $this->create_attachment_from_local_file( $source ); |
|
| 186 | + $attachment_id = $this->create_attachment_from_local_file($source); |
|
| 187 | 187 | |
| 188 | 188 | // Add a flag to signal the attachment is sample data and allow easy delete |
| 189 | 189 | // afterwards. |
| 190 | - add_post_meta( $attachment_id, '_wl_sample_data', 1, true ); |
|
| 190 | + add_post_meta($attachment_id, '_wl_sample_data', 1, true); |
|
| 191 | 191 | |
| 192 | 192 | // Get the dataset URI, used for replacements in the `post_content`. |
| 193 | 193 | $dataset_uri = $this->configuration_service->get_dataset_uri(); |
@@ -198,29 +198,29 @@ discard block |
||
| 198 | 198 | // Create 4 entities. |
| 199 | 199 | // Create 4 posts referencing each one entity. |
| 200 | 200 | // Create 1 post referencing all the entities. |
| 201 | - foreach ( $this->samples as $sample ) { |
|
| 201 | + foreach ($this->samples as $sample) { |
|
| 202 | 202 | |
| 203 | 203 | // Get the post data. |
| 204 | - $post = array_replace_recursive( $sample['post'], array( |
|
| 205 | - 'post_content' => str_replace( '{dataset-uri}', $dataset_uri, $sample['post']['post_content'] ), |
|
| 206 | - ) ); |
|
| 204 | + $post = array_replace_recursive($sample['post'], array( |
|
| 205 | + 'post_content' => str_replace('{dataset-uri}', $dataset_uri, $sample['post']['post_content']), |
|
| 206 | + )); |
|
| 207 | 207 | |
| 208 | 208 | // Set the author. |
| 209 | 209 | $post['post_author'] = $author_id; |
| 210 | 210 | |
| 211 | 211 | // Insert the post. |
| 212 | - $post_id = wp_insert_post( $post ); |
|
| 212 | + $post_id = wp_insert_post($post); |
|
| 213 | 213 | |
| 214 | 214 | // Add a flag to signal the post is sample data and allow easy delete |
| 215 | 215 | // afterwards. |
| 216 | - add_post_meta( $post_id, '_wl_sample_data', 1, true ); |
|
| 216 | + add_post_meta($post_id, '_wl_sample_data', 1, true); |
|
| 217 | 217 | |
| 218 | 218 | // Set the post thumbnail. |
| 219 | - set_post_thumbnail( $post_id, $attachment_id ); |
|
| 219 | + set_post_thumbnail($post_id, $attachment_id); |
|
| 220 | 220 | |
| 221 | 221 | // If the `entity_type_uri` property is set, set it on the post. |
| 222 | - if ( isset( $sample['entity_type_uri'] ) ) { |
|
| 223 | - $this->entity_type_service->set( $post_id, $sample['entity_type_uri'] ); |
|
| 222 | + if (isset($sample['entity_type_uri'])) { |
|
| 223 | + $this->entity_type_service->set($post_id, $sample['entity_type_uri']); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | } |
@@ -237,17 +237,17 @@ discard block |
||
| 237 | 237 | */ |
| 238 | 238 | private function create_author() { |
| 239 | 239 | |
| 240 | - $user_id = wp_create_user( 'wl-sample-data', wp_generate_password() ); |
|
| 241 | - $author_post_id = wp_insert_post( array( |
|
| 240 | + $user_id = wp_create_user('wl-sample-data', wp_generate_password()); |
|
| 241 | + $author_post_id = wp_insert_post(array( |
|
| 242 | 242 | 'post_type' => 'entity', |
| 243 | 243 | 'post_title' => 'WordLift Sample Data Person', |
| 244 | - ) ); |
|
| 244 | + )); |
|
| 245 | 245 | // Add a flag to signal the attachment is sample data and allow easy delete |
| 246 | 246 | // afterwards. |
| 247 | - add_post_meta( $author_post_id, '_wl_sample_data', 1, true ); |
|
| 247 | + add_post_meta($author_post_id, '_wl_sample_data', 1, true); |
|
| 248 | 248 | |
| 249 | - $this->entity_type_service->set( $author_post_id, 'http://schema.org/Person' ); |
|
| 250 | - $this->user_service->set_entity( $user_id, $author_post_id ); |
|
| 249 | + $this->entity_type_service->set($author_post_id, 'http://schema.org/Person'); |
|
| 250 | + $this->user_service->set_entity($user_id, $author_post_id); |
|
| 251 | 251 | |
| 252 | 252 | return $user_id; |
| 253 | 253 | } |
@@ -259,13 +259,13 @@ discard block |
||
| 259 | 259 | */ |
| 260 | 260 | function delete() { |
| 261 | 261 | |
| 262 | - $this->delete_by_type( 'post' ); |
|
| 263 | - $this->delete_by_type( 'entity' ); |
|
| 264 | - $this->delete_by_type( 'attachment' ); |
|
| 262 | + $this->delete_by_type('post'); |
|
| 263 | + $this->delete_by_type('entity'); |
|
| 264 | + $this->delete_by_type('attachment'); |
|
| 265 | 265 | |
| 266 | 266 | // Get and delete the user. |
| 267 | - $user = get_user_by( 'login', 'wl-sample-data' ); |
|
| 268 | - wp_delete_user( $user->ID ); |
|
| 267 | + $user = get_user_by('login', 'wl-sample-data'); |
|
| 268 | + wp_delete_user($user->ID); |
|
| 269 | 269 | |
| 270 | 270 | } |
| 271 | 271 | |
@@ -277,17 +277,17 @@ discard block |
||
| 277 | 277 | * |
| 278 | 278 | * @param string $type WordPress {@link WP_Post}'s type, e.g. `post`, `entity`, `attachment`. |
| 279 | 279 | */ |
| 280 | - private function delete_by_type( $type ) { |
|
| 280 | + private function delete_by_type($type) { |
|
| 281 | 281 | |
| 282 | - $posts = get_posts( array( |
|
| 282 | + $posts = get_posts(array( |
|
| 283 | 283 | 'meta_key' => '_wl_sample_data', |
| 284 | 284 | 'meta_value' => 1, |
| 285 | 285 | 'post_status' => 'any', |
| 286 | 286 | 'post_type' => $type, |
| 287 | - ) ); |
|
| 287 | + )); |
|
| 288 | 288 | |
| 289 | - foreach ( $posts as $post ) { |
|
| 290 | - wp_delete_post( $post->ID, true ); |
|
| 289 | + foreach ($posts as $post) { |
|
| 290 | + wp_delete_post($post->ID, true); |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | } |
@@ -301,19 +301,19 @@ discard block |
||
| 301 | 301 | * |
| 302 | 302 | * @return int WordPress' attachment's id. |
| 303 | 303 | */ |
| 304 | - private function create_attachment_from_local_file( $source ) { |
|
| 304 | + private function create_attachment_from_local_file($source) { |
|
| 305 | 305 | |
| 306 | 306 | // Get the path to the upload directory. |
| 307 | 307 | $upload_dir = wp_upload_dir(); |
| 308 | 308 | $upload_path = $upload_dir['path']; |
| 309 | 309 | |
| 310 | 310 | // Get the destination image path. |
| 311 | - $destination = $upload_path . '/wl-sample-data.png'; |
|
| 311 | + $destination = $upload_path.'/wl-sample-data.png'; |
|
| 312 | 312 | |
| 313 | 313 | // Copy the source file to the destination. |
| 314 | - @copy( $source, $destination ); |
|
| 314 | + @copy($source, $destination); |
|
| 315 | 315 | |
| 316 | - return $this->create_attachment( $destination ); |
|
| 316 | + return $this->create_attachment($destination); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | /** |
@@ -327,31 +327,31 @@ discard block |
||
| 327 | 327 | * |
| 328 | 328 | * @return int The attachment id. |
| 329 | 329 | */ |
| 330 | - private function create_attachment( $filename ) { |
|
| 330 | + private function create_attachment($filename) { |
|
| 331 | 331 | |
| 332 | 332 | // Check the type of file. We'll use this as the 'post_mime_type'. |
| 333 | - $filetype = wp_check_filetype( basename( $filename ), null ); |
|
| 333 | + $filetype = wp_check_filetype(basename($filename), null); |
|
| 334 | 334 | |
| 335 | 335 | // Get the path to the upload directory. |
| 336 | 336 | $wp_upload_dir = wp_upload_dir(); |
| 337 | 337 | |
| 338 | 338 | // Prepare an array of post data for the attachment. |
| 339 | 339 | $attachment = array( |
| 340 | - 'guid' => $wp_upload_dir['url'] . '/' . basename( $filename ), |
|
| 340 | + 'guid' => $wp_upload_dir['url'].'/'.basename($filename), |
|
| 341 | 341 | 'post_mime_type' => $filetype['type'], |
| 342 | - 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ), |
|
| 342 | + 'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)), |
|
| 343 | 343 | 'post_content' => '', |
| 344 | 344 | 'post_status' => 'inherit', |
| 345 | 345 | ); |
| 346 | 346 | |
| 347 | 347 | // Insert the attachment. |
| 348 | - $attachment_id = wp_insert_attachment( $attachment, $filename ); |
|
| 348 | + $attachment_id = wp_insert_attachment($attachment, $filename); |
|
| 349 | 349 | |
| 350 | 350 | // Generate the metadata for the attachment, and update the database record. |
| 351 | - $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
| 351 | + $attachment_data = wp_generate_attachment_metadata($attachment_id, $filename); |
|
| 352 | 352 | |
| 353 | 353 | // Update the attachment metadata. |
| 354 | - wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
|
| 354 | + wp_update_attachment_metadata($attachment_id, $attachment_data); |
|
| 355 | 355 | |
| 356 | 356 | return $attachment_id; |
| 357 | 357 | } |
@@ -17,98 +17,98 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | class Wordlift_Sample_Data_Service { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * An array of sample data. |
|
| 22 | - * |
|
| 23 | - * @since 3.12.0 |
|
| 24 | - * @var array $samples An array of sample data. |
|
| 25 | - */ |
|
| 26 | - private $samples = array( |
|
| 27 | - array( |
|
| 28 | - 'post' => array( |
|
| 29 | - 'post_name' => 'praesent_imperdiet_odio_sed_lectus_vulputate_finibus', |
|
| 30 | - 'post_title' => 'Praesent imperdiet odio sed lectus vulputate finibus', |
|
| 31 | - 'post_content' => 'Praesent imperdiet odio sed lectus vulputate finibus. Donec placerat ex arcu, eget fermentum metus ullamcorper vitae. Cras interdum libero a tellus sagittis, sed ultricies sapien tincidunt. Aliquam sit amet vehicula sem. Mauris neque nisl, pellentesque ut molestie id, laoreet nec tortor. Sed tempus ornare est, nec dapibus enim ornare eu. Cras risus ligula, blandit ut faucibus ut, vulputate id ipsum. In vel purus at orci hendrerit cursus. Aliquam interdum lorem id dui maximus volutpat. Vestibulum mi velit, efficitur nec neque eu, posuere porta risus.', |
|
| 32 | - 'post_type' => 'entity', |
|
| 33 | - 'post_status' => 'publish', |
|
| 34 | - ), |
|
| 35 | - 'entity_type_uri' => 'http://schema.org/Event', |
|
| 36 | - ), |
|
| 37 | - array( |
|
| 38 | - 'post' => array( |
|
| 39 | - 'post_name' => 'nullam_tempor_lectus_sit_amet_tincidunt_euismod', |
|
| 40 | - 'post_title' => 'Nullam tempor lectus sit amet tincidunt euismod', |
|
| 41 | - 'post_content' => '<span id="urn:enhancement-da554278-9522-2d83-76ad-8129d2292cb3" class="textannotation disambiguated wl-event" itemid="{dataset-uri}/entity/praesent_imperdiet_odio_sed_lectus_vulputate_finibus">Praesent imperdiet odio sed lectus vulputate finibus</span> Nullam tempor lectus sit amet tincidunt euismod. Nunc posuere libero augue, eu pretium erat interdum id. Vivamus aliquam dui in mauris tempor, vitae vestibulum odio aliquet. Proin quis bibendum diam, nec tempus dui. Pellentesque sit amet justo vitae urna ornare volutpat quis consectetur nisl. Sed hendrerit purus et magna varius, sodales tincidunt velit finibus. Donec malesuada faucibus mattis. Morbi viverra sagittis justo nec luctus. Nullam et justo sed nisi fringilla rutrum sit amet a urna. Integer elementum, risus in condimentum rhoncus, nisi velit cursus tellus, sed sagittis ante tellus hendrerit ante. Donec et semper libero, vitae imperdiet ligula. Donec eleifend iaculis nisi sed mollis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Proin faucibus magna ac lectus tempor iaculis quis in nisi. Mauris ac nibh lacinia, ultrices erat quis, rhoncus lectus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.', |
|
| 42 | - 'post_type' => 'entity', |
|
| 43 | - 'post_status' => 'publish', |
|
| 44 | - ), |
|
| 45 | - 'entity_type_uri' => 'http://schema.org/Place', |
|
| 46 | - ), |
|
| 47 | - array( |
|
| 48 | - 'post' => array( |
|
| 49 | - 'post_name' => 'praesent_luctus_tincidunt_odio_quis_aliquam', |
|
| 50 | - 'post_title' => 'Praesent luctus tincidunt odio quis aliquam', |
|
| 51 | - 'post_content' => 'Praesent luctus tincidunt odio quis aliquam. Ut pellentesque odio nec turpis placerat, at rhoncus mauris elementum. Proin vehicula lectus a dolor bibendum, ut pretium lacus volutpat. Integer luctus enim sed odio dapibus tempus. Fusce elementum purus in diam dictum, sit amet ultricies leo molestie. Etiam id nunc tincidunt sapien tristique interdum ac at purus. Nulla eget laoreet turpis. Nullam id cursus nulla.', |
|
| 52 | - 'post_type' => 'entity', |
|
| 53 | - 'post_status' => 'publish', |
|
| 54 | - ), |
|
| 55 | - 'entity_type_uri' => 'http://schema.org/Organization', |
|
| 56 | - ), |
|
| 57 | - array( |
|
| 58 | - 'post' => array( |
|
| 59 | - 'post_name' => 'lorem_ipsum_dolor_sit_amet__consectetur_adipiscing_elit', |
|
| 60 | - 'post_title' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit', |
|
| 61 | - 'post_content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', |
|
| 62 | - 'post_type' => 'entity', |
|
| 63 | - 'post_status' => 'publish', |
|
| 64 | - ), |
|
| 65 | - 'entity_type_uri' => 'http://schema.org/CreativeWork', |
|
| 66 | - ), |
|
| 67 | - array( |
|
| 68 | - 'post' => |
|
| 69 | - array( |
|
| 70 | - 'post_name' => 'post_1', |
|
| 71 | - 'post_title' => 'Praesent imperdiet odio sed lectus vulputate finibus', |
|
| 72 | - 'post_content' => '<span><span id="urn:enhancement-da554278-9522-2d83-76ad-8129d2292cb3" class="textannotation disambiguated wl-event" itemid="{dataset-uri}/entity/praesent_imperdiet_odio_sed_lectus_vulputate_finibus">Praesent imperdiet odio sed lectus vulputate finibus</span>. Donec placerat ex arcu, eget fermentum metus ullamcorper vitae. Cras interdum libero a tellus sagittis, sed ultricies sapien tincidunt. Aliquam sit amet vehicula sem. Mauris neque nisl, pellentesque ut molestie id, laoreet nec tortor. Sed tempus ornare est, nec dapibus enim ornare eu. Cras risus ligula, blandit ut faucibus ut, vulputate id ipsum. In vel purus at orci hendrerit cursus. Aliquam interdum lorem id dui maximus volutpat. Vestibulum mi velit, efficitur nec neque eu, posuere porta risus.</span>', |
|
| 73 | - 'post_type' => 'post', |
|
| 74 | - 'post_status' => 'publish', |
|
| 75 | - ), |
|
| 76 | - ), |
|
| 77 | - array( |
|
| 78 | - 'post' => |
|
| 79 | - array( |
|
| 80 | - 'post_name' => 'post_2', |
|
| 81 | - 'post_title' => 'Nullam tempor lectus sit amet tincidunt euismod', |
|
| 82 | - 'post_content' => '<span><span id="urn:local-text-annotation-p8i5o4279ex3rsbwqkrx9z5mh1ox91ae" class="textannotation disambiguated wl-place" itemid="{dataset-uri}/entity/nullam_tempor_lectus_sit_amet_tincidunt_euismod">Nullam tempor lectus sit amet tincidunt euismod</span>. Nunc posuere libero augue, eu pretium erat interdum id. Vivamus aliquam dui in mauris tempor, vitae vestibulum odio aliquet. Proin quis bibendum diam, nec tempus dui. Pellentesque sit amet justo vitae urna ornare volutpat quis consectetur nisl. Sed hendrerit purus et magna varius, sodales tincidunt velit finibus. Donec malesuada faucibus mattis. Morbi viverra sagittis justo nec luctus. Nullam et justo sed nisi fringilla rutrum sit amet a urna. Integer elementum, risus in condimentum rhoncus, nisi velit cursus tellus, sed sagittis ante tellus hendrerit ante. Donec et semper libero, vitae imperdiet ligula. Donec eleifend iaculis nisi sed mollis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Proin faucibus magna ac lectus tempor iaculis quis in nisi. Mauris ac nibh lacinia, ultrices erat quis, rhoncus lectus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.</span>', |
|
| 83 | - 'post_type' => 'post', |
|
| 84 | - 'post_status' => 'publish', |
|
| 85 | - ), |
|
| 86 | - ), |
|
| 87 | - array( |
|
| 88 | - 'post' => |
|
| 89 | - array( |
|
| 90 | - 'post_name' => 'post_3', |
|
| 91 | - 'post_title' => 'Praesent luctus tincidunt odio quis aliquam', |
|
| 92 | - 'post_content' => '<span><span id="urn:enhancement-b3487a20-4696-b6d9-6c55-842445f5c263" class="textannotation disambiguated wl-organization" itemid="{dataset-uri}/entity/praesent_luctus_tincidunt_odio_quis_aliquam">Praesent luctus tincidunt odio quis aliquam</span>. Ut pellentesque odio nec turpis placerat, at rhoncus mauris elementum. Proin vehicula lectus a dolor bibendum, ut pretium lacus volutpat. Integer luctus enim sed odio dapibus tempus. Fusce elementum purus in diam dictum, sit amet ultricies leo molestie. Etiam id nunc tincidunt sapien tristique interdum ac at purus. Nulla eget laoreet turpis. Nullam id cursus nulla.</span>', |
|
| 93 | - 'post_type' => 'post', |
|
| 94 | - 'post_status' => 'publish', |
|
| 95 | - ), |
|
| 96 | - ), |
|
| 97 | - array( |
|
| 98 | - 'post' => |
|
| 99 | - array( |
|
| 100 | - 'post_name' => 'post_4', |
|
| 101 | - 'post_title' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit', |
|
| 102 | - 'post_content' => '<span><span id="urn:enhancement-4edc3bde-d275-22f9-8d50-0b707596b292" class="textannotation disambiguated wl-thing" itemid="{dataset-uri}/entity/lorem_ipsum_dolor_sit_amet__consectetur_adipiscing_elit">Lorem ipsum dolor sit amet, consectetur adipiscing elit</span>. Proin rutrum ultrices nulla ut elementum. Nunc nec lacus tortor. Curabitur bibendum imperdiet luctus. Vivamus a faucibus dolor. Donec blandit malesuada risus. Vestibulum volutpat ut tellus sed tincidunt. Sed id tincidunt velit. Integer sed felis id libero fringilla molestie vitae id orci. Ut vel purus ullamcorper, feugiat tortor non, iaculis neque. Vivamus vitae vehicula sem. Mauris fermentum, metus id vestibulum sodales, lorem lacus efficitur ante, non vestibulum ligula ligula a turpis. Vivamus quis scelerisque massa.</span>', |
|
| 103 | - 'post_type' => 'post', |
|
| 104 | - 'post_status' => 'publish', |
|
| 105 | - ), |
|
| 106 | - ), |
|
| 107 | - array( |
|
| 108 | - 'post' => array( |
|
| 109 | - 'post_name' => 'post_5', |
|
| 110 | - 'post_title' => 'Lorem ipsum', |
|
| 111 | - 'post_content' => " |
|
| 20 | + /** |
|
| 21 | + * An array of sample data. |
|
| 22 | + * |
|
| 23 | + * @since 3.12.0 |
|
| 24 | + * @var array $samples An array of sample data. |
|
| 25 | + */ |
|
| 26 | + private $samples = array( |
|
| 27 | + array( |
|
| 28 | + 'post' => array( |
|
| 29 | + 'post_name' => 'praesent_imperdiet_odio_sed_lectus_vulputate_finibus', |
|
| 30 | + 'post_title' => 'Praesent imperdiet odio sed lectus vulputate finibus', |
|
| 31 | + 'post_content' => 'Praesent imperdiet odio sed lectus vulputate finibus. Donec placerat ex arcu, eget fermentum metus ullamcorper vitae. Cras interdum libero a tellus sagittis, sed ultricies sapien tincidunt. Aliquam sit amet vehicula sem. Mauris neque nisl, pellentesque ut molestie id, laoreet nec tortor. Sed tempus ornare est, nec dapibus enim ornare eu. Cras risus ligula, blandit ut faucibus ut, vulputate id ipsum. In vel purus at orci hendrerit cursus. Aliquam interdum lorem id dui maximus volutpat. Vestibulum mi velit, efficitur nec neque eu, posuere porta risus.', |
|
| 32 | + 'post_type' => 'entity', |
|
| 33 | + 'post_status' => 'publish', |
|
| 34 | + ), |
|
| 35 | + 'entity_type_uri' => 'http://schema.org/Event', |
|
| 36 | + ), |
|
| 37 | + array( |
|
| 38 | + 'post' => array( |
|
| 39 | + 'post_name' => 'nullam_tempor_lectus_sit_amet_tincidunt_euismod', |
|
| 40 | + 'post_title' => 'Nullam tempor lectus sit amet tincidunt euismod', |
|
| 41 | + 'post_content' => '<span id="urn:enhancement-da554278-9522-2d83-76ad-8129d2292cb3" class="textannotation disambiguated wl-event" itemid="{dataset-uri}/entity/praesent_imperdiet_odio_sed_lectus_vulputate_finibus">Praesent imperdiet odio sed lectus vulputate finibus</span> Nullam tempor lectus sit amet tincidunt euismod. Nunc posuere libero augue, eu pretium erat interdum id. Vivamus aliquam dui in mauris tempor, vitae vestibulum odio aliquet. Proin quis bibendum diam, nec tempus dui. Pellentesque sit amet justo vitae urna ornare volutpat quis consectetur nisl. Sed hendrerit purus et magna varius, sodales tincidunt velit finibus. Donec malesuada faucibus mattis. Morbi viverra sagittis justo nec luctus. Nullam et justo sed nisi fringilla rutrum sit amet a urna. Integer elementum, risus in condimentum rhoncus, nisi velit cursus tellus, sed sagittis ante tellus hendrerit ante. Donec et semper libero, vitae imperdiet ligula. Donec eleifend iaculis nisi sed mollis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Proin faucibus magna ac lectus tempor iaculis quis in nisi. Mauris ac nibh lacinia, ultrices erat quis, rhoncus lectus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.', |
|
| 42 | + 'post_type' => 'entity', |
|
| 43 | + 'post_status' => 'publish', |
|
| 44 | + ), |
|
| 45 | + 'entity_type_uri' => 'http://schema.org/Place', |
|
| 46 | + ), |
|
| 47 | + array( |
|
| 48 | + 'post' => array( |
|
| 49 | + 'post_name' => 'praesent_luctus_tincidunt_odio_quis_aliquam', |
|
| 50 | + 'post_title' => 'Praesent luctus tincidunt odio quis aliquam', |
|
| 51 | + 'post_content' => 'Praesent luctus tincidunt odio quis aliquam. Ut pellentesque odio nec turpis placerat, at rhoncus mauris elementum. Proin vehicula lectus a dolor bibendum, ut pretium lacus volutpat. Integer luctus enim sed odio dapibus tempus. Fusce elementum purus in diam dictum, sit amet ultricies leo molestie. Etiam id nunc tincidunt sapien tristique interdum ac at purus. Nulla eget laoreet turpis. Nullam id cursus nulla.', |
|
| 52 | + 'post_type' => 'entity', |
|
| 53 | + 'post_status' => 'publish', |
|
| 54 | + ), |
|
| 55 | + 'entity_type_uri' => 'http://schema.org/Organization', |
|
| 56 | + ), |
|
| 57 | + array( |
|
| 58 | + 'post' => array( |
|
| 59 | + 'post_name' => 'lorem_ipsum_dolor_sit_amet__consectetur_adipiscing_elit', |
|
| 60 | + 'post_title' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit', |
|
| 61 | + 'post_content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', |
|
| 62 | + 'post_type' => 'entity', |
|
| 63 | + 'post_status' => 'publish', |
|
| 64 | + ), |
|
| 65 | + 'entity_type_uri' => 'http://schema.org/CreativeWork', |
|
| 66 | + ), |
|
| 67 | + array( |
|
| 68 | + 'post' => |
|
| 69 | + array( |
|
| 70 | + 'post_name' => 'post_1', |
|
| 71 | + 'post_title' => 'Praesent imperdiet odio sed lectus vulputate finibus', |
|
| 72 | + 'post_content' => '<span><span id="urn:enhancement-da554278-9522-2d83-76ad-8129d2292cb3" class="textannotation disambiguated wl-event" itemid="{dataset-uri}/entity/praesent_imperdiet_odio_sed_lectus_vulputate_finibus">Praesent imperdiet odio sed lectus vulputate finibus</span>. Donec placerat ex arcu, eget fermentum metus ullamcorper vitae. Cras interdum libero a tellus sagittis, sed ultricies sapien tincidunt. Aliquam sit amet vehicula sem. Mauris neque nisl, pellentesque ut molestie id, laoreet nec tortor. Sed tempus ornare est, nec dapibus enim ornare eu. Cras risus ligula, blandit ut faucibus ut, vulputate id ipsum. In vel purus at orci hendrerit cursus. Aliquam interdum lorem id dui maximus volutpat. Vestibulum mi velit, efficitur nec neque eu, posuere porta risus.</span>', |
|
| 73 | + 'post_type' => 'post', |
|
| 74 | + 'post_status' => 'publish', |
|
| 75 | + ), |
|
| 76 | + ), |
|
| 77 | + array( |
|
| 78 | + 'post' => |
|
| 79 | + array( |
|
| 80 | + 'post_name' => 'post_2', |
|
| 81 | + 'post_title' => 'Nullam tempor lectus sit amet tincidunt euismod', |
|
| 82 | + 'post_content' => '<span><span id="urn:local-text-annotation-p8i5o4279ex3rsbwqkrx9z5mh1ox91ae" class="textannotation disambiguated wl-place" itemid="{dataset-uri}/entity/nullam_tempor_lectus_sit_amet_tincidunt_euismod">Nullam tempor lectus sit amet tincidunt euismod</span>. Nunc posuere libero augue, eu pretium erat interdum id. Vivamus aliquam dui in mauris tempor, vitae vestibulum odio aliquet. Proin quis bibendum diam, nec tempus dui. Pellentesque sit amet justo vitae urna ornare volutpat quis consectetur nisl. Sed hendrerit purus et magna varius, sodales tincidunt velit finibus. Donec malesuada faucibus mattis. Morbi viverra sagittis justo nec luctus. Nullam et justo sed nisi fringilla rutrum sit amet a urna. Integer elementum, risus in condimentum rhoncus, nisi velit cursus tellus, sed sagittis ante tellus hendrerit ante. Donec et semper libero, vitae imperdiet ligula. Donec eleifend iaculis nisi sed mollis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Proin faucibus magna ac lectus tempor iaculis quis in nisi. Mauris ac nibh lacinia, ultrices erat quis, rhoncus lectus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.</span>', |
|
| 83 | + 'post_type' => 'post', |
|
| 84 | + 'post_status' => 'publish', |
|
| 85 | + ), |
|
| 86 | + ), |
|
| 87 | + array( |
|
| 88 | + 'post' => |
|
| 89 | + array( |
|
| 90 | + 'post_name' => 'post_3', |
|
| 91 | + 'post_title' => 'Praesent luctus tincidunt odio quis aliquam', |
|
| 92 | + 'post_content' => '<span><span id="urn:enhancement-b3487a20-4696-b6d9-6c55-842445f5c263" class="textannotation disambiguated wl-organization" itemid="{dataset-uri}/entity/praesent_luctus_tincidunt_odio_quis_aliquam">Praesent luctus tincidunt odio quis aliquam</span>. Ut pellentesque odio nec turpis placerat, at rhoncus mauris elementum. Proin vehicula lectus a dolor bibendum, ut pretium lacus volutpat. Integer luctus enim sed odio dapibus tempus. Fusce elementum purus in diam dictum, sit amet ultricies leo molestie. Etiam id nunc tincidunt sapien tristique interdum ac at purus. Nulla eget laoreet turpis. Nullam id cursus nulla.</span>', |
|
| 93 | + 'post_type' => 'post', |
|
| 94 | + 'post_status' => 'publish', |
|
| 95 | + ), |
|
| 96 | + ), |
|
| 97 | + array( |
|
| 98 | + 'post' => |
|
| 99 | + array( |
|
| 100 | + 'post_name' => 'post_4', |
|
| 101 | + 'post_title' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit', |
|
| 102 | + 'post_content' => '<span><span id="urn:enhancement-4edc3bde-d275-22f9-8d50-0b707596b292" class="textannotation disambiguated wl-thing" itemid="{dataset-uri}/entity/lorem_ipsum_dolor_sit_amet__consectetur_adipiscing_elit">Lorem ipsum dolor sit amet, consectetur adipiscing elit</span>. Proin rutrum ultrices nulla ut elementum. Nunc nec lacus tortor. Curabitur bibendum imperdiet luctus. Vivamus a faucibus dolor. Donec blandit malesuada risus. Vestibulum volutpat ut tellus sed tincidunt. Sed id tincidunt velit. Integer sed felis id libero fringilla molestie vitae id orci. Ut vel purus ullamcorper, feugiat tortor non, iaculis neque. Vivamus vitae vehicula sem. Mauris fermentum, metus id vestibulum sodales, lorem lacus efficitur ante, non vestibulum ligula ligula a turpis. Vivamus quis scelerisque massa.</span>', |
|
| 103 | + 'post_type' => 'post', |
|
| 104 | + 'post_status' => 'publish', |
|
| 105 | + ), |
|
| 106 | + ), |
|
| 107 | + array( |
|
| 108 | + 'post' => array( |
|
| 109 | + 'post_name' => 'post_5', |
|
| 110 | + 'post_title' => 'Lorem ipsum', |
|
| 111 | + 'post_content' => " |
|
| 112 | 112 | <span id=\"urn:enhancement-28cb4112-64cf-bd49-ef97-a2ee54727de7\" class=\"textannotation disambiguated wl-thing\" itemid=\"{dataset-uri}/entity/lorem_ipsum_dolor_sit_amet__consectetur_adipiscing_elit\">Lorem ipsum</span> dolor sit amet, consectetur adipiscing elit. Proin rutrum ultrices nulla ut elementum. Nunc nec lacus tortor. Curabitur bibendum imperdiet luctus. Vivamus a faucibus dolor. Donec blandit malesuada risus. Vestibulum volutpat ut tellus sed tincidunt. Sed id tincidunt velit. Integer sed felis id libero fringilla molestie vitae id orci. Ut vel purus ullamcorper, feugiat tortor non, iaculis neque. Vivamus vitae vehicula sem. Mauris fermentum, metus id vestibulum sodales, lorem lacus efficitur ante, non vestibulum ligula ligula a turpis. Vivamus quis scelerisque massa. |
| 113 | 113 | |
| 114 | 114 | [wl_navigator] |
@@ -123,237 +123,237 @@ discard block |
||
| 123 | 123 | |
| 124 | 124 | <span id=\"urn:local-text-annotation-v0kqdtx685n6cg9jrfvl67amkhm28hxh\" class=\"textannotation disambiguated wl-event\" itemid=\"{dataset-uri}/entity/praesent_imperdiet_odio_sed_lectus_vulputate_finibus\">Praesent imperdiet odio sed lectus vulputate finibus</span>. Donec placerat ex arcu, eget fermentum metus ullamcorper vitae. Cras interdum libero a tellus sagittis, sed ultricies sapien tincidunt. Aliquam sit amet vehicula sem. Mauris neque nisl, pellentesque ut molestie id, laoreet nec tortor. Sed tempus ornare est, nec dapibus enim ornare eu. Cras risus ligula, blandit ut faucibus ut, vulputate id ipsum. In vel purus at orci hendrerit cursus. Aliquam interdum lorem id dui maximus volutpat. Vestibulum mi velit, efficitur nec neque eu, posuere porta risus. |
| 125 | 125 | ", |
| 126 | - 'post_type' => 'post', |
|
| 127 | - 'post_status' => 'publish', |
|
| 128 | - ), |
|
| 129 | - ), |
|
| 130 | - ); |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * The {@link Wordlift_Entity_Type_Service} instance. |
|
| 134 | - * |
|
| 135 | - * @since 3.12.0 |
|
| 136 | - * @access private |
|
| 137 | - * @var \Wordlift_Entity_Type_Service $entity_type_service The {@link Wordlift_Entity_Type_Service} instance. |
|
| 138 | - */ |
|
| 139 | - private $entity_type_service; |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * The {@link Wordlift_Configuration_Service} instance. |
|
| 143 | - * |
|
| 144 | - * @since 3.12.0 |
|
| 145 | - * @access private |
|
| 146 | - * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance. |
|
| 147 | - */ |
|
| 148 | - private $configuration_service; |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * The {@link Wordlift_User_Service} instance. |
|
| 152 | - * |
|
| 153 | - * @since 3.16.0 |
|
| 154 | - * @access private |
|
| 155 | - * @var \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance. |
|
| 156 | - */ |
|
| 157 | - private $user_service; |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Create a {@link Wordlift_Sample_Data_Service} instance. |
|
| 161 | - * |
|
| 162 | - * @since 3.12.0 |
|
| 163 | - * |
|
| 164 | - * @param \Wordlift_Entity_Type_Service $entity_type_service The {@link Wordlift_Entity_Type_Service} instance. |
|
| 165 | - * @param \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance. |
|
| 166 | - * @param \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance. |
|
| 167 | - */ |
|
| 168 | - function __construct( $entity_type_service, $configuration_service, $user_service ) { |
|
| 169 | - |
|
| 170 | - $this->entity_type_service = $entity_type_service; |
|
| 171 | - $this->configuration_service = $configuration_service; |
|
| 172 | - $this->user_service = $user_service; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Create sample data in this WordPress instance. |
|
| 177 | - * |
|
| 178 | - * @since 3.12.0 |
|
| 179 | - */ |
|
| 180 | - function create() { |
|
| 181 | - |
|
| 182 | - // Get the source image path. |
|
| 183 | - $source = plugin_dir_path( dirname( __FILE__ ) ) . 'images/rome.png'; |
|
| 184 | - |
|
| 185 | - // Create an attachment with the local file. |
|
| 186 | - $attachment_id = $this->create_attachment_from_local_file( $source ); |
|
| 187 | - |
|
| 188 | - // Add a flag to signal the attachment is sample data and allow easy delete |
|
| 189 | - // afterwards. |
|
| 190 | - add_post_meta( $attachment_id, '_wl_sample_data', 1, true ); |
|
| 191 | - |
|
| 192 | - // Get the dataset URI, used for replacements in the `post_content`. |
|
| 193 | - $dataset_uri = $this->configuration_service->get_dataset_uri(); |
|
| 194 | - |
|
| 195 | - // Create the author and get its id. |
|
| 196 | - $author_id = $this->create_author(); |
|
| 197 | - |
|
| 198 | - // Create 4 entities. |
|
| 199 | - // Create 4 posts referencing each one entity. |
|
| 200 | - // Create 1 post referencing all the entities. |
|
| 201 | - foreach ( $this->samples as $sample ) { |
|
| 202 | - |
|
| 203 | - // Get the post data. |
|
| 204 | - $post = array_replace_recursive( $sample['post'], array( |
|
| 205 | - 'post_content' => str_replace( '{dataset-uri}', $dataset_uri, $sample['post']['post_content'] ), |
|
| 206 | - ) ); |
|
| 207 | - |
|
| 208 | - // Set the author. |
|
| 209 | - $post['post_author'] = $author_id; |
|
| 210 | - |
|
| 211 | - // Insert the post. |
|
| 212 | - $post_id = wp_insert_post( $post ); |
|
| 213 | - |
|
| 214 | - // Add a flag to signal the post is sample data and allow easy delete |
|
| 215 | - // afterwards. |
|
| 216 | - add_post_meta( $post_id, '_wl_sample_data', 1, true ); |
|
| 217 | - |
|
| 218 | - // Set the post thumbnail. |
|
| 219 | - set_post_thumbnail( $post_id, $attachment_id ); |
|
| 220 | - |
|
| 221 | - // If the `entity_type_uri` property is set, set it on the post. |
|
| 222 | - if ( isset( $sample['entity_type_uri'] ) ) { |
|
| 223 | - $this->entity_type_service->set( $post_id, $sample['entity_type_uri'] ); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Create an author to bind to posts. |
|
| 233 | - * |
|
| 234 | - * @since 3.16.0 |
|
| 235 | - * |
|
| 236 | - * @return int The {@link WP_User}'s id. |
|
| 237 | - */ |
|
| 238 | - private function create_author() { |
|
| 239 | - |
|
| 240 | - $user_id = wp_create_user( 'wl-sample-data', wp_generate_password() ); |
|
| 241 | - $author_post_id = wp_insert_post( array( |
|
| 242 | - 'post_type' => 'entity', |
|
| 243 | - 'post_title' => 'WordLift Sample Data Person', |
|
| 244 | - ) ); |
|
| 245 | - // Add a flag to signal the attachment is sample data and allow easy delete |
|
| 246 | - // afterwards. |
|
| 247 | - add_post_meta( $author_post_id, '_wl_sample_data', 1, true ); |
|
| 248 | - |
|
| 249 | - $this->entity_type_service->set( $author_post_id, 'http://schema.org/Person' ); |
|
| 250 | - $this->user_service->set_entity( $user_id, $author_post_id ); |
|
| 251 | - |
|
| 252 | - return $user_id; |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * Remove the sample data from this WordPress instance. |
|
| 257 | - * |
|
| 258 | - * @since 3.12.0 |
|
| 259 | - */ |
|
| 260 | - function delete() { |
|
| 261 | - |
|
| 262 | - $this->delete_by_type( 'post' ); |
|
| 263 | - $this->delete_by_type( 'entity' ); |
|
| 264 | - $this->delete_by_type( 'attachment' ); |
|
| 265 | - |
|
| 266 | - // Get and delete the user. |
|
| 267 | - $user = get_user_by( 'login', 'wl-sample-data' ); |
|
| 268 | - wp_delete_user( $user->ID ); |
|
| 269 | - |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * Remove the sample data of the specified type (e.g. `post`, `entity`, `attachment`) |
|
| 274 | - * from the local WordPress instance. |
|
| 275 | - * |
|
| 276 | - * @since 3.12.0 |
|
| 277 | - * |
|
| 278 | - * @param string $type WordPress {@link WP_Post}'s type, e.g. `post`, `entity`, `attachment`. |
|
| 279 | - */ |
|
| 280 | - private function delete_by_type( $type ) { |
|
| 281 | - |
|
| 282 | - $posts = get_posts( array( |
|
| 283 | - 'meta_key' => '_wl_sample_data', |
|
| 284 | - 'meta_value' => 1, |
|
| 285 | - 'post_status' => 'any', |
|
| 286 | - 'post_type' => $type, |
|
| 287 | - ) ); |
|
| 288 | - |
|
| 289 | - foreach ( $posts as $post ) { |
|
| 290 | - wp_delete_post( $post->ID, true ); |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * Create a WordPress' attachment using the specified file. |
|
| 297 | - * |
|
| 298 | - * @since 3.12.0 |
|
| 299 | - * |
|
| 300 | - * @param string $source The source file path. |
|
| 301 | - * |
|
| 302 | - * @return int WordPress' attachment's id. |
|
| 303 | - */ |
|
| 304 | - private function create_attachment_from_local_file( $source ) { |
|
| 305 | - |
|
| 306 | - // Get the path to the upload directory. |
|
| 307 | - $upload_dir = wp_upload_dir(); |
|
| 308 | - $upload_path = $upload_dir['path']; |
|
| 309 | - |
|
| 310 | - // Get the destination image path. |
|
| 311 | - $destination = $upload_path . '/wl-sample-data.png'; |
|
| 312 | - |
|
| 313 | - // Copy the source file to the destination. |
|
| 314 | - @copy( $source, $destination ); |
|
| 315 | - |
|
| 316 | - return $this->create_attachment( $destination ); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * Create a WordPress attachment using the specified file in the upload folder. |
|
| 321 | - * |
|
| 322 | - * @see https://codex.wordpress.org/Function_Reference/wp_insert_attachment |
|
| 323 | - * |
|
| 324 | - * @since 3.12.0 |
|
| 325 | - * |
|
| 326 | - * @param string $filename The image filename. |
|
| 327 | - * |
|
| 328 | - * @return int The attachment id. |
|
| 329 | - */ |
|
| 330 | - private function create_attachment( $filename ) { |
|
| 331 | - |
|
| 332 | - // Check the type of file. We'll use this as the 'post_mime_type'. |
|
| 333 | - $filetype = wp_check_filetype( basename( $filename ), null ); |
|
| 334 | - |
|
| 335 | - // Get the path to the upload directory. |
|
| 336 | - $wp_upload_dir = wp_upload_dir(); |
|
| 337 | - |
|
| 338 | - // Prepare an array of post data for the attachment. |
|
| 339 | - $attachment = array( |
|
| 340 | - 'guid' => $wp_upload_dir['url'] . '/' . basename( $filename ), |
|
| 341 | - 'post_mime_type' => $filetype['type'], |
|
| 342 | - 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ), |
|
| 343 | - 'post_content' => '', |
|
| 344 | - 'post_status' => 'inherit', |
|
| 345 | - ); |
|
| 346 | - |
|
| 347 | - // Insert the attachment. |
|
| 348 | - $attachment_id = wp_insert_attachment( $attachment, $filename ); |
|
| 349 | - |
|
| 350 | - // Generate the metadata for the attachment, and update the database record. |
|
| 351 | - $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
| 352 | - |
|
| 353 | - // Update the attachment metadata. |
|
| 354 | - wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
|
| 355 | - |
|
| 356 | - return $attachment_id; |
|
| 357 | - } |
|
| 126 | + 'post_type' => 'post', |
|
| 127 | + 'post_status' => 'publish', |
|
| 128 | + ), |
|
| 129 | + ), |
|
| 130 | + ); |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * The {@link Wordlift_Entity_Type_Service} instance. |
|
| 134 | + * |
|
| 135 | + * @since 3.12.0 |
|
| 136 | + * @access private |
|
| 137 | + * @var \Wordlift_Entity_Type_Service $entity_type_service The {@link Wordlift_Entity_Type_Service} instance. |
|
| 138 | + */ |
|
| 139 | + private $entity_type_service; |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * The {@link Wordlift_Configuration_Service} instance. |
|
| 143 | + * |
|
| 144 | + * @since 3.12.0 |
|
| 145 | + * @access private |
|
| 146 | + * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance. |
|
| 147 | + */ |
|
| 148 | + private $configuration_service; |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * The {@link Wordlift_User_Service} instance. |
|
| 152 | + * |
|
| 153 | + * @since 3.16.0 |
|
| 154 | + * @access private |
|
| 155 | + * @var \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance. |
|
| 156 | + */ |
|
| 157 | + private $user_service; |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Create a {@link Wordlift_Sample_Data_Service} instance. |
|
| 161 | + * |
|
| 162 | + * @since 3.12.0 |
|
| 163 | + * |
|
| 164 | + * @param \Wordlift_Entity_Type_Service $entity_type_service The {@link Wordlift_Entity_Type_Service} instance. |
|
| 165 | + * @param \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance. |
|
| 166 | + * @param \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance. |
|
| 167 | + */ |
|
| 168 | + function __construct( $entity_type_service, $configuration_service, $user_service ) { |
|
| 169 | + |
|
| 170 | + $this->entity_type_service = $entity_type_service; |
|
| 171 | + $this->configuration_service = $configuration_service; |
|
| 172 | + $this->user_service = $user_service; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Create sample data in this WordPress instance. |
|
| 177 | + * |
|
| 178 | + * @since 3.12.0 |
|
| 179 | + */ |
|
| 180 | + function create() { |
|
| 181 | + |
|
| 182 | + // Get the source image path. |
|
| 183 | + $source = plugin_dir_path( dirname( __FILE__ ) ) . 'images/rome.png'; |
|
| 184 | + |
|
| 185 | + // Create an attachment with the local file. |
|
| 186 | + $attachment_id = $this->create_attachment_from_local_file( $source ); |
|
| 187 | + |
|
| 188 | + // Add a flag to signal the attachment is sample data and allow easy delete |
|
| 189 | + // afterwards. |
|
| 190 | + add_post_meta( $attachment_id, '_wl_sample_data', 1, true ); |
|
| 191 | + |
|
| 192 | + // Get the dataset URI, used for replacements in the `post_content`. |
|
| 193 | + $dataset_uri = $this->configuration_service->get_dataset_uri(); |
|
| 194 | + |
|
| 195 | + // Create the author and get its id. |
|
| 196 | + $author_id = $this->create_author(); |
|
| 197 | + |
|
| 198 | + // Create 4 entities. |
|
| 199 | + // Create 4 posts referencing each one entity. |
|
| 200 | + // Create 1 post referencing all the entities. |
|
| 201 | + foreach ( $this->samples as $sample ) { |
|
| 202 | + |
|
| 203 | + // Get the post data. |
|
| 204 | + $post = array_replace_recursive( $sample['post'], array( |
|
| 205 | + 'post_content' => str_replace( '{dataset-uri}', $dataset_uri, $sample['post']['post_content'] ), |
|
| 206 | + ) ); |
|
| 207 | + |
|
| 208 | + // Set the author. |
|
| 209 | + $post['post_author'] = $author_id; |
|
| 210 | + |
|
| 211 | + // Insert the post. |
|
| 212 | + $post_id = wp_insert_post( $post ); |
|
| 213 | + |
|
| 214 | + // Add a flag to signal the post is sample data and allow easy delete |
|
| 215 | + // afterwards. |
|
| 216 | + add_post_meta( $post_id, '_wl_sample_data', 1, true ); |
|
| 217 | + |
|
| 218 | + // Set the post thumbnail. |
|
| 219 | + set_post_thumbnail( $post_id, $attachment_id ); |
|
| 220 | + |
|
| 221 | + // If the `entity_type_uri` property is set, set it on the post. |
|
| 222 | + if ( isset( $sample['entity_type_uri'] ) ) { |
|
| 223 | + $this->entity_type_service->set( $post_id, $sample['entity_type_uri'] ); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Create an author to bind to posts. |
|
| 233 | + * |
|
| 234 | + * @since 3.16.0 |
|
| 235 | + * |
|
| 236 | + * @return int The {@link WP_User}'s id. |
|
| 237 | + */ |
|
| 238 | + private function create_author() { |
|
| 239 | + |
|
| 240 | + $user_id = wp_create_user( 'wl-sample-data', wp_generate_password() ); |
|
| 241 | + $author_post_id = wp_insert_post( array( |
|
| 242 | + 'post_type' => 'entity', |
|
| 243 | + 'post_title' => 'WordLift Sample Data Person', |
|
| 244 | + ) ); |
|
| 245 | + // Add a flag to signal the attachment is sample data and allow easy delete |
|
| 246 | + // afterwards. |
|
| 247 | + add_post_meta( $author_post_id, '_wl_sample_data', 1, true ); |
|
| 248 | + |
|
| 249 | + $this->entity_type_service->set( $author_post_id, 'http://schema.org/Person' ); |
|
| 250 | + $this->user_service->set_entity( $user_id, $author_post_id ); |
|
| 251 | + |
|
| 252 | + return $user_id; |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * Remove the sample data from this WordPress instance. |
|
| 257 | + * |
|
| 258 | + * @since 3.12.0 |
|
| 259 | + */ |
|
| 260 | + function delete() { |
|
| 261 | + |
|
| 262 | + $this->delete_by_type( 'post' ); |
|
| 263 | + $this->delete_by_type( 'entity' ); |
|
| 264 | + $this->delete_by_type( 'attachment' ); |
|
| 265 | + |
|
| 266 | + // Get and delete the user. |
|
| 267 | + $user = get_user_by( 'login', 'wl-sample-data' ); |
|
| 268 | + wp_delete_user( $user->ID ); |
|
| 269 | + |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * Remove the sample data of the specified type (e.g. `post`, `entity`, `attachment`) |
|
| 274 | + * from the local WordPress instance. |
|
| 275 | + * |
|
| 276 | + * @since 3.12.0 |
|
| 277 | + * |
|
| 278 | + * @param string $type WordPress {@link WP_Post}'s type, e.g. `post`, `entity`, `attachment`. |
|
| 279 | + */ |
|
| 280 | + private function delete_by_type( $type ) { |
|
| 281 | + |
|
| 282 | + $posts = get_posts( array( |
|
| 283 | + 'meta_key' => '_wl_sample_data', |
|
| 284 | + 'meta_value' => 1, |
|
| 285 | + 'post_status' => 'any', |
|
| 286 | + 'post_type' => $type, |
|
| 287 | + ) ); |
|
| 288 | + |
|
| 289 | + foreach ( $posts as $post ) { |
|
| 290 | + wp_delete_post( $post->ID, true ); |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * Create a WordPress' attachment using the specified file. |
|
| 297 | + * |
|
| 298 | + * @since 3.12.0 |
|
| 299 | + * |
|
| 300 | + * @param string $source The source file path. |
|
| 301 | + * |
|
| 302 | + * @return int WordPress' attachment's id. |
|
| 303 | + */ |
|
| 304 | + private function create_attachment_from_local_file( $source ) { |
|
| 305 | + |
|
| 306 | + // Get the path to the upload directory. |
|
| 307 | + $upload_dir = wp_upload_dir(); |
|
| 308 | + $upload_path = $upload_dir['path']; |
|
| 309 | + |
|
| 310 | + // Get the destination image path. |
|
| 311 | + $destination = $upload_path . '/wl-sample-data.png'; |
|
| 312 | + |
|
| 313 | + // Copy the source file to the destination. |
|
| 314 | + @copy( $source, $destination ); |
|
| 315 | + |
|
| 316 | + return $this->create_attachment( $destination ); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * Create a WordPress attachment using the specified file in the upload folder. |
|
| 321 | + * |
|
| 322 | + * @see https://codex.wordpress.org/Function_Reference/wp_insert_attachment |
|
| 323 | + * |
|
| 324 | + * @since 3.12.0 |
|
| 325 | + * |
|
| 326 | + * @param string $filename The image filename. |
|
| 327 | + * |
|
| 328 | + * @return int The attachment id. |
|
| 329 | + */ |
|
| 330 | + private function create_attachment( $filename ) { |
|
| 331 | + |
|
| 332 | + // Check the type of file. We'll use this as the 'post_mime_type'. |
|
| 333 | + $filetype = wp_check_filetype( basename( $filename ), null ); |
|
| 334 | + |
|
| 335 | + // Get the path to the upload directory. |
|
| 336 | + $wp_upload_dir = wp_upload_dir(); |
|
| 337 | + |
|
| 338 | + // Prepare an array of post data for the attachment. |
|
| 339 | + $attachment = array( |
|
| 340 | + 'guid' => $wp_upload_dir['url'] . '/' . basename( $filename ), |
|
| 341 | + 'post_mime_type' => $filetype['type'], |
|
| 342 | + 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ), |
|
| 343 | + 'post_content' => '', |
|
| 344 | + 'post_status' => 'inherit', |
|
| 345 | + ); |
|
| 346 | + |
|
| 347 | + // Insert the attachment. |
|
| 348 | + $attachment_id = wp_insert_attachment( $attachment, $filename ); |
|
| 349 | + |
|
| 350 | + // Generate the metadata for the attachment, and update the database record. |
|
| 351 | + $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
| 352 | + |
|
| 353 | + // Update the attachment metadata. |
|
| 354 | + wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
|
| 355 | + |
|
| 356 | + return $attachment_id; |
|
| 357 | + } |
|
| 358 | 358 | |
| 359 | 359 | } |
@@ -31,17 +31,17 @@ discard block |
||
| 31 | 31 | public static function activate() { |
| 32 | 32 | |
| 33 | 33 | // Do not let the plugin be activate on WordPress versions before 4.4. |
| 34 | - $version = get_bloginfo( 'version' ); |
|
| 35 | - if ( version_compare( $version, '4.4', '<' ) ) { |
|
| 36 | - die( esc_html__( 'The WordLift plugin requires WordPress version 4.4 or above.', 'wordlift' ) ); |
|
| 34 | + $version = get_bloginfo('version'); |
|
| 35 | + if (version_compare($version, '4.4', '<')) { |
|
| 36 | + die(esc_html__('The WordLift plugin requires WordPress version 4.4 or above.', 'wordlift')); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | $configuration_service = Wordlift_Configuration_Service::get_instance(); |
| 40 | 40 | |
| 41 | 41 | // Create a blank application key if there is none. |
| 42 | 42 | $key = $configuration_service->get_key(); |
| 43 | - if ( empty( $key ) ) { |
|
| 44 | - $configuration_service->set_key( '' ); |
|
| 43 | + if (empty($key)) { |
|
| 44 | + $configuration_service->set_key(''); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | // Intentionally go through the whole upgrade procedure to be DRY. |
@@ -51,8 +51,8 @@ discard block |
||
| 51 | 51 | |
| 52 | 52 | // If WordLift's key is not configured, set `_wl_activation_redirect` transient. We won't redirect here, because we can't give |
| 53 | 53 | // for granted that we're in a browser admin session. |
| 54 | - if ( '' === $configuration_service->get_key() ) { |
|
| 55 | - set_transient( '_wl_activation_redirect', true, 30 ); |
|
| 54 | + if ('' === $configuration_service->get_key()) { |
|
| 55 | + set_transient('_wl_activation_redirect', true, 30); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | // Clear caches. |
@@ -21,44 +21,44 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class Wordlift_Activator { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Short Description. (use period) |
|
| 26 | - * |
|
| 27 | - * Long Description. |
|
| 28 | - * |
|
| 29 | - * @since 1.0.0 |
|
| 30 | - */ |
|
| 31 | - public static function activate() { |
|
| 24 | + /** |
|
| 25 | + * Short Description. (use period) |
|
| 26 | + * |
|
| 27 | + * Long Description. |
|
| 28 | + * |
|
| 29 | + * @since 1.0.0 |
|
| 30 | + */ |
|
| 31 | + public static function activate() { |
|
| 32 | 32 | |
| 33 | - // Do not let the plugin be activate on WordPress versions before 4.4. |
|
| 34 | - $version = get_bloginfo( 'version' ); |
|
| 35 | - if ( version_compare( $version, '4.4', '<' ) ) { |
|
| 36 | - die( esc_html__( 'The WordLift plugin requires WordPress version 4.4 or above.', 'wordlift' ) ); |
|
| 37 | - } |
|
| 33 | + // Do not let the plugin be activate on WordPress versions before 4.4. |
|
| 34 | + $version = get_bloginfo( 'version' ); |
|
| 35 | + if ( version_compare( $version, '4.4', '<' ) ) { |
|
| 36 | + die( esc_html__( 'The WordLift plugin requires WordPress version 4.4 or above.', 'wordlift' ) ); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
| 39 | + $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
| 40 | 40 | |
| 41 | - // Create a blank application key if there is none. |
|
| 42 | - $key = $configuration_service->get_key(); |
|
| 41 | + // Create a blank application key if there is none. |
|
| 42 | + $key = $configuration_service->get_key(); |
|
| 43 | 43 | |
| 44 | - if ( empty( $key ) ) { |
|
| 45 | - $configuration_service->set_key( '' ); |
|
| 46 | - } |
|
| 44 | + if ( empty( $key ) ) { |
|
| 45 | + $configuration_service->set_key( '' ); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - // Intentionally go through the whole upgrade procedure to be DRY. |
|
| 49 | - // The following function is called also from `init` so it's not necessary |
|
| 50 | - // here. |
|
| 51 | - // wl_core_update_db_check. |
|
| 48 | + // Intentionally go through the whole upgrade procedure to be DRY. |
|
| 49 | + // The following function is called also from `init` so it's not necessary |
|
| 50 | + // here. |
|
| 51 | + // wl_core_update_db_check. |
|
| 52 | 52 | |
| 53 | - // If WordLift's key is not configured, set `_wl_activation_redirect` transient. We won't redirect here, because we can't give |
|
| 54 | - // for granted that we're in a browser admin session. |
|
| 55 | - if ( '' === $configuration_service->get_key() ) { |
|
| 56 | - set_transient( '_wl_activation_redirect', true, 30 ); |
|
| 57 | - } |
|
| 53 | + // If WordLift's key is not configured, set `_wl_activation_redirect` transient. We won't redirect here, because we can't give |
|
| 54 | + // for granted that we're in a browser admin session. |
|
| 55 | + if ( '' === $configuration_service->get_key() ) { |
|
| 56 | + set_transient( '_wl_activation_redirect', true, 30 ); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - // Clear caches. |
|
| 60 | - Wordlift_File_Cache_Service::flush_all(); |
|
| 59 | + // Clear caches. |
|
| 60 | + Wordlift_File_Cache_Service::flush_all(); |
|
| 61 | 61 | |
| 62 | - } |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | 64 | } |
@@ -17,142 +17,142 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class Wordlift_Alphabet_Service { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Get the alphabet for the specified language code. |
|
| 22 | - * |
|
| 23 | - * @since 3.17.0 |
|
| 24 | - * |
|
| 25 | - * @param string $language_code A two-letter language code. |
|
| 26 | - * |
|
| 27 | - * @return array The letters array or an empty array if the language isn't supported. |
|
| 28 | - */ |
|
| 29 | - public static function get( $language_code ) { |
|
| 30 | - |
|
| 31 | - switch ( $language_code ) { |
|
| 32 | - case '': |
|
| 33 | - case 'en': |
|
| 34 | - case 'fr': |
|
| 35 | - case 'de': |
|
| 36 | - case 'ca': |
|
| 37 | - case 'nl': |
|
| 38 | - case 'id': |
|
| 39 | - case 'it': |
|
| 40 | - case 'pt': |
|
| 41 | - case 'uk': |
|
| 42 | - case 'zh-cn': |
|
| 43 | - return self::reset( range( 'A', 'Z' ) ); |
|
| 44 | - |
|
| 45 | - case 'be': |
|
| 46 | - // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/be_utf8/langconfig.php . |
|
| 47 | - return self::reset( explode( ',', 'А,Б,В,Г,Д,ДЖ,ДЗ,Е,Ё,Ж,З,І,Й,К,Л,М,Н,О,П,Р,С,Т,У,Ў,Ф,Х,Ц,Ч,Ш,Ы,Ь,Э,Ю,Я' ) ); |
|
| 48 | - |
|
| 49 | - case 'no': |
|
| 50 | - case 'da': |
|
| 51 | - // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/nn_utf8/langconfig.php . |
|
| 52 | - return self::reset( explode( ',', 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,Æ,Ø,Å' ) ); |
|
| 53 | - |
|
| 54 | - case 'bg': |
|
| 55 | - // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/bg_utf8/langconfig.php . |
|
| 56 | - return self::reset( explode( ',', 'А,Б,В,Г,Д,Е,Ж,З,И,Й,К,Л,М,Н,О,П,Р,С,Т,У,Ф,Х,Ц,Ч,Ш,Щ,Ъ,Ь,Ю,Я' ) ); |
|
| 57 | - |
|
| 58 | - case 'cs': |
|
| 59 | - // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/cs_utf8/langconfig.php . |
|
| 60 | - return self::reset( explode( ',', 'A,Á,B,C,Č,D,Ď,E,É,Ě,F,G,H,I,Í,J,K,L,M,N,Ň,O,Ó,P,Q,R,Ř,S,Š,T,Ť,U,Ú,Ů,V,W,X,Y,Ý,Z,Ž' ) ); |
|
| 61 | - |
|
| 62 | - case 'es': |
|
| 63 | - // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/es_utf8/langconfig.php . |
|
| 64 | - return self::reset( explode( ',', 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,Ñ,O,P,Q,R,S,T,U,V,W,X,Y,Z' ) ); |
|
| 65 | - |
|
| 66 | - case 'et': |
|
| 67 | - // @see https://en.wikipedia.org/wiki/Estonian_orthography#Alphabet . |
|
| 68 | - return self::reset( explode( ',', 'A,B,D,E,F,G,H,I,J,K,L,M,N,O,P,R,S,Š,Z,Ž,T,U,V,Õ,Ä,Ö,Ü' ) ); |
|
| 69 | - |
|
| 70 | - case 'fi': |
|
| 71 | - // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/fi_utf8/langconfig.php . |
|
| 72 | - return self::reset( explode( ',', 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,Å,Ä,Ö' ) ); |
|
| 73 | - |
|
| 74 | - case 'hr': |
|
| 75 | - // @see https://github.com/dismine/Valentina_sonar/blob/2930a1c51406255001331bf6013f85fc340b91f7/scripts/alphabets.py . |
|
| 76 | - return self::reset( explode( ',', 'A.B.C.Č.Ć.D.DŽ.Ð.E.F.G.H.I.J.K,L,LJ,M,N,NJ,O,P,R,S,Š,T,U,V,Z,Ž' ) ); |
|
| 77 | - |
|
| 78 | - case 'hu': |
|
| 79 | - // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/hu_utf8/langconfig.php . |
|
| 80 | - return self::reset( explode( ',', 'A,Á,B,C,CS,D,DZ,DZS,E,É,F,G,GY,H,I,Í,J,K,L,M,N,NY,O,Ó,Ö,Ő,P,Q,R,S,SZ,T,TY,U,Ú,Ü,Ű,V,W,X,Y,Z,ZS' ) ); |
|
| 81 | - |
|
| 82 | - case 'is': |
|
| 83 | - // @see https://en.wikipedia.org/wiki/Icelandic_orthography . |
|
| 84 | - return self::reset( explode( ',', 'A,Á,B,D,Ð,E,É,F,G,H,I,Í,J,K,L,M,N,O,Ó,P,R,S,T,U,Ú,V,X,Y,Ý,Þ,Æ,Ö' ) ); |
|
| 85 | - |
|
| 86 | - case 'lt': |
|
| 87 | - // @see https://en.wikipedia.org/wiki/Lithuanian_orthography#Alphabet . |
|
| 88 | - return self::reset( explode( ',', 'A,Ą,B,C,Č,D,E,Ę,Ė,F,G,H,I,Į,Y,J,K,L,M,N,O,P,R,S,Š,T,U,Ų,Ū,V,Z,Ž' ) ); |
|
| 89 | - |
|
| 90 | - case 'lv': |
|
| 91 | - // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/lv_utf8/langconfig.php . |
|
| 92 | - return self::reset( explode( ',', 'A,Ā,B,C,Č,D,E,Ē,F,G,Ģ,H,I,Ī,J,K,Ķ,L,Ļ,M,N,Ņ,O,P,Q,R,S,Š,T,U,Ū,V,W,X,Y,Z,Ž' ) ); |
|
| 93 | - |
|
| 94 | - case 'pl': |
|
| 95 | - // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/pl_utf8/langconfig.php . |
|
| 96 | - return self::reset( explode( ',', 'A,Ą,B,C,Ć,D,E,Ę,F,G,H,I,J,K,L,Ł,M,N,Ń,O,Ó,P,Q,R,S,Ś,T,U,V,W,X,Y,Z,Ź,Ż' ) ); |
|
| 97 | - |
|
| 98 | - case 'ro': |
|
| 99 | - // @see https://github.com/dismine/Valentina_sonar/blob/2930a1c51406255001331bf6013f85fc340b91f7/scripts/alphabets.py . |
|
| 100 | - return self::reset( explode( ',', 'A,Ă,Â,B,C,D,E,F,G,H,I,Î,J,K,L,M,N,O,P,Q,R,S,Ș,T,Ț,U,V,W,X,Y,Z' ) ); |
|
| 101 | - |
|
| 102 | - case 'ru': |
|
| 103 | - // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/ru_utf8/langconfig.php . |
|
| 104 | - return self::reset( explode( ',', 'А,Б,В,Г,Д,Е,Ё,Ж,З,И,К,Л,М,Н,О,П,Р,С,Т,У,Ф,Х,Ц,Ч,Ш,Щ,Э,Ю,Я' ) ); |
|
| 105 | - |
|
| 106 | - case 'sk': |
|
| 107 | - // @see https://github.com/dismine/Valentina_sonar/blob/2930a1c51406255001331bf6013f85fc340b91f7/scripts/alphabets.py . |
|
| 108 | - return self::reset( explode( ',', 'A,Á,Ä,B,C,Č,D,Ď,DZ,DŽ,E,É,F,G,H,CH,I,Í,J,K,L,Ĺ,Ľ,M,N,Ň,O,Ó,Ô,P,Q,R,Ŕ,S,Š,T,Ť,U,Ú,V,W,X,Y,Ý,Z,Ž' ) ); |
|
| 109 | - |
|
| 110 | - case 'sl': |
|
| 111 | - // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/sl_utf8/langconfig.php . |
|
| 112 | - return self::reset( explode( ',', 'A,B,C,Č,D,E,F,G,H,I,J,K,L,M,N,O,P,R,S,Š,T,U,V,Z,Ž' ) ); |
|
| 113 | - |
|
| 114 | - case 'sq': |
|
| 115 | - // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/sq_utf8/langconfig.php . |
|
| 116 | - return self::reset( explode( ',', 'A,B,C,Ç,D,E,Ë,F,G,GJ,H,I,J,K,L,LL,M,N,O,P,Q,R,RR,S,SH,T,TH,U,V,X,XH,Y,Z,ZH' ) ); |
|
| 117 | - |
|
| 118 | - case 'sr': |
|
| 119 | - // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/sr_cr_utf8/langconfig.php . |
|
| 120 | - return self::reset( explode( ',', 'А,Б,В,Г,Д,Ђ,Е,Ж,З,И,J,K,Л,Љ,М,Н,Њ,O,П,Р,С,Т,Ћ,У,Ф,Х,Ц,Ч,Џ,Ш' ) ); |
|
| 121 | - |
|
| 122 | - case 'sv': |
|
| 123 | - // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/sv_utf8/langconfig.php . |
|
| 124 | - return self::reset( explode( ',', 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,Å,Ä,Ö' ) ); |
|
| 125 | - |
|
| 126 | - case 'tr': |
|
| 127 | - // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/tr_utf8/langconfig.php . |
|
| 128 | - return self::reset( explode( ',', 'A,B,C,Ç,D,E,F,G,H,I,İ,J,K,L,M,N,O,Ö,P,R,S,Ş,T,U,Ü,V,Y,Z,Q,W,X' ) ); |
|
| 129 | - |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - // If we got here, we don't support the language, then return an empty array. |
|
| 133 | - return self::reset( array() ); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Reset the alphabet array by assigning an empty array to each key. |
|
| 138 | - * |
|
| 139 | - * @since 3.17.0 |
|
| 140 | - * |
|
| 141 | - * @param array $alphabet The alphabet array. |
|
| 142 | - * |
|
| 143 | - * @return array The alphabet array with letters as keys and empty arrays as values. |
|
| 144 | - */ |
|
| 145 | - private static function reset( $alphabet ) { |
|
| 146 | - |
|
| 147 | - $letters = array_flip( $alphabet ); |
|
| 148 | - |
|
| 149 | - foreach ( $letters as $key => $value ) { |
|
| 150 | - $letters[ $key ] = array(); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - return $letters + array( |
|
| 154 | - '#' => array(), |
|
| 155 | - ); |
|
| 156 | - } |
|
| 20 | + /** |
|
| 21 | + * Get the alphabet for the specified language code. |
|
| 22 | + * |
|
| 23 | + * @since 3.17.0 |
|
| 24 | + * |
|
| 25 | + * @param string $language_code A two-letter language code. |
|
| 26 | + * |
|
| 27 | + * @return array The letters array or an empty array if the language isn't supported. |
|
| 28 | + */ |
|
| 29 | + public static function get( $language_code ) { |
|
| 30 | + |
|
| 31 | + switch ( $language_code ) { |
|
| 32 | + case '': |
|
| 33 | + case 'en': |
|
| 34 | + case 'fr': |
|
| 35 | + case 'de': |
|
| 36 | + case 'ca': |
|
| 37 | + case 'nl': |
|
| 38 | + case 'id': |
|
| 39 | + case 'it': |
|
| 40 | + case 'pt': |
|
| 41 | + case 'uk': |
|
| 42 | + case 'zh-cn': |
|
| 43 | + return self::reset( range( 'A', 'Z' ) ); |
|
| 44 | + |
|
| 45 | + case 'be': |
|
| 46 | + // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/be_utf8/langconfig.php . |
|
| 47 | + return self::reset( explode( ',', 'А,Б,В,Г,Д,ДЖ,ДЗ,Е,Ё,Ж,З,І,Й,К,Л,М,Н,О,П,Р,С,Т,У,Ў,Ф,Х,Ц,Ч,Ш,Ы,Ь,Э,Ю,Я' ) ); |
|
| 48 | + |
|
| 49 | + case 'no': |
|
| 50 | + case 'da': |
|
| 51 | + // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/nn_utf8/langconfig.php . |
|
| 52 | + return self::reset( explode( ',', 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,Æ,Ø,Å' ) ); |
|
| 53 | + |
|
| 54 | + case 'bg': |
|
| 55 | + // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/bg_utf8/langconfig.php . |
|
| 56 | + return self::reset( explode( ',', 'А,Б,В,Г,Д,Е,Ж,З,И,Й,К,Л,М,Н,О,П,Р,С,Т,У,Ф,Х,Ц,Ч,Ш,Щ,Ъ,Ь,Ю,Я' ) ); |
|
| 57 | + |
|
| 58 | + case 'cs': |
|
| 59 | + // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/cs_utf8/langconfig.php . |
|
| 60 | + return self::reset( explode( ',', 'A,Á,B,C,Č,D,Ď,E,É,Ě,F,G,H,I,Í,J,K,L,M,N,Ň,O,Ó,P,Q,R,Ř,S,Š,T,Ť,U,Ú,Ů,V,W,X,Y,Ý,Z,Ž' ) ); |
|
| 61 | + |
|
| 62 | + case 'es': |
|
| 63 | + // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/es_utf8/langconfig.php . |
|
| 64 | + return self::reset( explode( ',', 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,Ñ,O,P,Q,R,S,T,U,V,W,X,Y,Z' ) ); |
|
| 65 | + |
|
| 66 | + case 'et': |
|
| 67 | + // @see https://en.wikipedia.org/wiki/Estonian_orthography#Alphabet . |
|
| 68 | + return self::reset( explode( ',', 'A,B,D,E,F,G,H,I,J,K,L,M,N,O,P,R,S,Š,Z,Ž,T,U,V,Õ,Ä,Ö,Ü' ) ); |
|
| 69 | + |
|
| 70 | + case 'fi': |
|
| 71 | + // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/fi_utf8/langconfig.php . |
|
| 72 | + return self::reset( explode( ',', 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,Å,Ä,Ö' ) ); |
|
| 73 | + |
|
| 74 | + case 'hr': |
|
| 75 | + // @see https://github.com/dismine/Valentina_sonar/blob/2930a1c51406255001331bf6013f85fc340b91f7/scripts/alphabets.py . |
|
| 76 | + return self::reset( explode( ',', 'A.B.C.Č.Ć.D.DŽ.Ð.E.F.G.H.I.J.K,L,LJ,M,N,NJ,O,P,R,S,Š,T,U,V,Z,Ž' ) ); |
|
| 77 | + |
|
| 78 | + case 'hu': |
|
| 79 | + // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/hu_utf8/langconfig.php . |
|
| 80 | + return self::reset( explode( ',', 'A,Á,B,C,CS,D,DZ,DZS,E,É,F,G,GY,H,I,Í,J,K,L,M,N,NY,O,Ó,Ö,Ő,P,Q,R,S,SZ,T,TY,U,Ú,Ü,Ű,V,W,X,Y,Z,ZS' ) ); |
|
| 81 | + |
|
| 82 | + case 'is': |
|
| 83 | + // @see https://en.wikipedia.org/wiki/Icelandic_orthography . |
|
| 84 | + return self::reset( explode( ',', 'A,Á,B,D,Ð,E,É,F,G,H,I,Í,J,K,L,M,N,O,Ó,P,R,S,T,U,Ú,V,X,Y,Ý,Þ,Æ,Ö' ) ); |
|
| 85 | + |
|
| 86 | + case 'lt': |
|
| 87 | + // @see https://en.wikipedia.org/wiki/Lithuanian_orthography#Alphabet . |
|
| 88 | + return self::reset( explode( ',', 'A,Ą,B,C,Č,D,E,Ę,Ė,F,G,H,I,Į,Y,J,K,L,M,N,O,P,R,S,Š,T,U,Ų,Ū,V,Z,Ž' ) ); |
|
| 89 | + |
|
| 90 | + case 'lv': |
|
| 91 | + // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/lv_utf8/langconfig.php . |
|
| 92 | + return self::reset( explode( ',', 'A,Ā,B,C,Č,D,E,Ē,F,G,Ģ,H,I,Ī,J,K,Ķ,L,Ļ,M,N,Ņ,O,P,Q,R,S,Š,T,U,Ū,V,W,X,Y,Z,Ž' ) ); |
|
| 93 | + |
|
| 94 | + case 'pl': |
|
| 95 | + // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/pl_utf8/langconfig.php . |
|
| 96 | + return self::reset( explode( ',', 'A,Ą,B,C,Ć,D,E,Ę,F,G,H,I,J,K,L,Ł,M,N,Ń,O,Ó,P,Q,R,S,Ś,T,U,V,W,X,Y,Z,Ź,Ż' ) ); |
|
| 97 | + |
|
| 98 | + case 'ro': |
|
| 99 | + // @see https://github.com/dismine/Valentina_sonar/blob/2930a1c51406255001331bf6013f85fc340b91f7/scripts/alphabets.py . |
|
| 100 | + return self::reset( explode( ',', 'A,Ă,Â,B,C,D,E,F,G,H,I,Î,J,K,L,M,N,O,P,Q,R,S,Ș,T,Ț,U,V,W,X,Y,Z' ) ); |
|
| 101 | + |
|
| 102 | + case 'ru': |
|
| 103 | + // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/ru_utf8/langconfig.php . |
|
| 104 | + return self::reset( explode( ',', 'А,Б,В,Г,Д,Е,Ё,Ж,З,И,К,Л,М,Н,О,П,Р,С,Т,У,Ф,Х,Ц,Ч,Ш,Щ,Э,Ю,Я' ) ); |
|
| 105 | + |
|
| 106 | + case 'sk': |
|
| 107 | + // @see https://github.com/dismine/Valentina_sonar/blob/2930a1c51406255001331bf6013f85fc340b91f7/scripts/alphabets.py . |
|
| 108 | + return self::reset( explode( ',', 'A,Á,Ä,B,C,Č,D,Ď,DZ,DŽ,E,É,F,G,H,CH,I,Í,J,K,L,Ĺ,Ľ,M,N,Ň,O,Ó,Ô,P,Q,R,Ŕ,S,Š,T,Ť,U,Ú,V,W,X,Y,Ý,Z,Ž' ) ); |
|
| 109 | + |
|
| 110 | + case 'sl': |
|
| 111 | + // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/sl_utf8/langconfig.php . |
|
| 112 | + return self::reset( explode( ',', 'A,B,C,Č,D,E,F,G,H,I,J,K,L,M,N,O,P,R,S,Š,T,U,V,Z,Ž' ) ); |
|
| 113 | + |
|
| 114 | + case 'sq': |
|
| 115 | + // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/sq_utf8/langconfig.php . |
|
| 116 | + return self::reset( explode( ',', 'A,B,C,Ç,D,E,Ë,F,G,GJ,H,I,J,K,L,LL,M,N,O,P,Q,R,RR,S,SH,T,TH,U,V,X,XH,Y,Z,ZH' ) ); |
|
| 117 | + |
|
| 118 | + case 'sr': |
|
| 119 | + // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/sr_cr_utf8/langconfig.php . |
|
| 120 | + return self::reset( explode( ',', 'А,Б,В,Г,Д,Ђ,Е,Ж,З,И,J,K,Л,Љ,М,Н,Њ,O,П,Р,С,Т,Ћ,У,Ф,Х,Ц,Ч,Џ,Ш' ) ); |
|
| 121 | + |
|
| 122 | + case 'sv': |
|
| 123 | + // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/sv_utf8/langconfig.php . |
|
| 124 | + return self::reset( explode( ',', 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,Å,Ä,Ö' ) ); |
|
| 125 | + |
|
| 126 | + case 'tr': |
|
| 127 | + // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/tr_utf8/langconfig.php . |
|
| 128 | + return self::reset( explode( ',', 'A,B,C,Ç,D,E,F,G,H,I,İ,J,K,L,M,N,O,Ö,P,R,S,Ş,T,U,Ü,V,Y,Z,Q,W,X' ) ); |
|
| 129 | + |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + // If we got here, we don't support the language, then return an empty array. |
|
| 133 | + return self::reset( array() ); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Reset the alphabet array by assigning an empty array to each key. |
|
| 138 | + * |
|
| 139 | + * @since 3.17.0 |
|
| 140 | + * |
|
| 141 | + * @param array $alphabet The alphabet array. |
|
| 142 | + * |
|
| 143 | + * @return array The alphabet array with letters as keys and empty arrays as values. |
|
| 144 | + */ |
|
| 145 | + private static function reset( $alphabet ) { |
|
| 146 | + |
|
| 147 | + $letters = array_flip( $alphabet ); |
|
| 148 | + |
|
| 149 | + foreach ( $letters as $key => $value ) { |
|
| 150 | + $letters[ $key ] = array(); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + return $letters + array( |
|
| 154 | + '#' => array(), |
|
| 155 | + ); |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | 158 | } |
@@ -26,9 +26,9 @@ discard block |
||
| 26 | 26 | * |
| 27 | 27 | * @return array The letters array or an empty array if the language isn't supported. |
| 28 | 28 | */ |
| 29 | - public static function get( $language_code ) { |
|
| 29 | + public static function get($language_code) { |
|
| 30 | 30 | |
| 31 | - switch ( $language_code ) { |
|
| 31 | + switch ($language_code) { |
|
| 32 | 32 | case '': |
| 33 | 33 | case 'en': |
| 34 | 34 | case 'fr': |
@@ -40,97 +40,97 @@ discard block |
||
| 40 | 40 | case 'pt': |
| 41 | 41 | case 'uk': |
| 42 | 42 | case 'zh-cn': |
| 43 | - return self::reset( range( 'A', 'Z' ) ); |
|
| 43 | + return self::reset(range('A', 'Z')); |
|
| 44 | 44 | |
| 45 | 45 | case 'be': |
| 46 | 46 | // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/be_utf8/langconfig.php . |
| 47 | - return self::reset( explode( ',', 'А,Б,В,Г,Д,ДЖ,ДЗ,Е,Ё,Ж,З,І,Й,К,Л,М,Н,О,П,Р,С,Т,У,Ў,Ф,Х,Ц,Ч,Ш,Ы,Ь,Э,Ю,Я' ) ); |
|
| 47 | + return self::reset(explode(',', 'А,Б,В,Г,Д,ДЖ,ДЗ,Е,Ё,Ж,З,І,Й,К,Л,М,Н,О,П,Р,С,Т,У,Ў,Ф,Х,Ц,Ч,Ш,Ы,Ь,Э,Ю,Я')); |
|
| 48 | 48 | |
| 49 | 49 | case 'no': |
| 50 | 50 | case 'da': |
| 51 | 51 | // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/nn_utf8/langconfig.php . |
| 52 | - return self::reset( explode( ',', 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,Æ,Ø,Å' ) ); |
|
| 52 | + return self::reset(explode(',', 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,Æ,Ø,Å')); |
|
| 53 | 53 | |
| 54 | 54 | case 'bg': |
| 55 | 55 | // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/bg_utf8/langconfig.php . |
| 56 | - return self::reset( explode( ',', 'А,Б,В,Г,Д,Е,Ж,З,И,Й,К,Л,М,Н,О,П,Р,С,Т,У,Ф,Х,Ц,Ч,Ш,Щ,Ъ,Ь,Ю,Я' ) ); |
|
| 56 | + return self::reset(explode(',', 'А,Б,В,Г,Д,Е,Ж,З,И,Й,К,Л,М,Н,О,П,Р,С,Т,У,Ф,Х,Ц,Ч,Ш,Щ,Ъ,Ь,Ю,Я')); |
|
| 57 | 57 | |
| 58 | 58 | case 'cs': |
| 59 | 59 | // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/cs_utf8/langconfig.php . |
| 60 | - return self::reset( explode( ',', 'A,Á,B,C,Č,D,Ď,E,É,Ě,F,G,H,I,Í,J,K,L,M,N,Ň,O,Ó,P,Q,R,Ř,S,Š,T,Ť,U,Ú,Ů,V,W,X,Y,Ý,Z,Ž' ) ); |
|
| 60 | + return self::reset(explode(',', 'A,Á,B,C,Č,D,Ď,E,É,Ě,F,G,H,I,Í,J,K,L,M,N,Ň,O,Ó,P,Q,R,Ř,S,Š,T,Ť,U,Ú,Ů,V,W,X,Y,Ý,Z,Ž')); |
|
| 61 | 61 | |
| 62 | 62 | case 'es': |
| 63 | 63 | // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/es_utf8/langconfig.php . |
| 64 | - return self::reset( explode( ',', 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,Ñ,O,P,Q,R,S,T,U,V,W,X,Y,Z' ) ); |
|
| 64 | + return self::reset(explode(',', 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,Ñ,O,P,Q,R,S,T,U,V,W,X,Y,Z')); |
|
| 65 | 65 | |
| 66 | 66 | case 'et': |
| 67 | 67 | // @see https://en.wikipedia.org/wiki/Estonian_orthography#Alphabet . |
| 68 | - return self::reset( explode( ',', 'A,B,D,E,F,G,H,I,J,K,L,M,N,O,P,R,S,Š,Z,Ž,T,U,V,Õ,Ä,Ö,Ü' ) ); |
|
| 68 | + return self::reset(explode(',', 'A,B,D,E,F,G,H,I,J,K,L,M,N,O,P,R,S,Š,Z,Ž,T,U,V,Õ,Ä,Ö,Ü')); |
|
| 69 | 69 | |
| 70 | 70 | case 'fi': |
| 71 | 71 | // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/fi_utf8/langconfig.php . |
| 72 | - return self::reset( explode( ',', 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,Å,Ä,Ö' ) ); |
|
| 72 | + return self::reset(explode(',', 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,Å,Ä,Ö')); |
|
| 73 | 73 | |
| 74 | 74 | case 'hr': |
| 75 | 75 | // @see https://github.com/dismine/Valentina_sonar/blob/2930a1c51406255001331bf6013f85fc340b91f7/scripts/alphabets.py . |
| 76 | - return self::reset( explode( ',', 'A.B.C.Č.Ć.D.DŽ.Ð.E.F.G.H.I.J.K,L,LJ,M,N,NJ,O,P,R,S,Š,T,U,V,Z,Ž' ) ); |
|
| 76 | + return self::reset(explode(',', 'A.B.C.Č.Ć.D.DŽ.Ð.E.F.G.H.I.J.K,L,LJ,M,N,NJ,O,P,R,S,Š,T,U,V,Z,Ž')); |
|
| 77 | 77 | |
| 78 | 78 | case 'hu': |
| 79 | 79 | // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/hu_utf8/langconfig.php . |
| 80 | - return self::reset( explode( ',', 'A,Á,B,C,CS,D,DZ,DZS,E,É,F,G,GY,H,I,Í,J,K,L,M,N,NY,O,Ó,Ö,Ő,P,Q,R,S,SZ,T,TY,U,Ú,Ü,Ű,V,W,X,Y,Z,ZS' ) ); |
|
| 80 | + return self::reset(explode(',', 'A,Á,B,C,CS,D,DZ,DZS,E,É,F,G,GY,H,I,Í,J,K,L,M,N,NY,O,Ó,Ö,Ő,P,Q,R,S,SZ,T,TY,U,Ú,Ü,Ű,V,W,X,Y,Z,ZS')); |
|
| 81 | 81 | |
| 82 | 82 | case 'is': |
| 83 | 83 | // @see https://en.wikipedia.org/wiki/Icelandic_orthography . |
| 84 | - return self::reset( explode( ',', 'A,Á,B,D,Ð,E,É,F,G,H,I,Í,J,K,L,M,N,O,Ó,P,R,S,T,U,Ú,V,X,Y,Ý,Þ,Æ,Ö' ) ); |
|
| 84 | + return self::reset(explode(',', 'A,Á,B,D,Ð,E,É,F,G,H,I,Í,J,K,L,M,N,O,Ó,P,R,S,T,U,Ú,V,X,Y,Ý,Þ,Æ,Ö')); |
|
| 85 | 85 | |
| 86 | 86 | case 'lt': |
| 87 | 87 | // @see https://en.wikipedia.org/wiki/Lithuanian_orthography#Alphabet . |
| 88 | - return self::reset( explode( ',', 'A,Ą,B,C,Č,D,E,Ę,Ė,F,G,H,I,Į,Y,J,K,L,M,N,O,P,R,S,Š,T,U,Ų,Ū,V,Z,Ž' ) ); |
|
| 88 | + return self::reset(explode(',', 'A,Ą,B,C,Č,D,E,Ę,Ė,F,G,H,I,Į,Y,J,K,L,M,N,O,P,R,S,Š,T,U,Ų,Ū,V,Z,Ž')); |
|
| 89 | 89 | |
| 90 | 90 | case 'lv': |
| 91 | 91 | // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/lv_utf8/langconfig.php . |
| 92 | - return self::reset( explode( ',', 'A,Ā,B,C,Č,D,E,Ē,F,G,Ģ,H,I,Ī,J,K,Ķ,L,Ļ,M,N,Ņ,O,P,Q,R,S,Š,T,U,Ū,V,W,X,Y,Z,Ž' ) ); |
|
| 92 | + return self::reset(explode(',', 'A,Ā,B,C,Č,D,E,Ē,F,G,Ģ,H,I,Ī,J,K,Ķ,L,Ļ,M,N,Ņ,O,P,Q,R,S,Š,T,U,Ū,V,W,X,Y,Z,Ž')); |
|
| 93 | 93 | |
| 94 | 94 | case 'pl': |
| 95 | 95 | // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/pl_utf8/langconfig.php . |
| 96 | - return self::reset( explode( ',', 'A,Ą,B,C,Ć,D,E,Ę,F,G,H,I,J,K,L,Ł,M,N,Ń,O,Ó,P,Q,R,S,Ś,T,U,V,W,X,Y,Z,Ź,Ż' ) ); |
|
| 96 | + return self::reset(explode(',', 'A,Ą,B,C,Ć,D,E,Ę,F,G,H,I,J,K,L,Ł,M,N,Ń,O,Ó,P,Q,R,S,Ś,T,U,V,W,X,Y,Z,Ź,Ż')); |
|
| 97 | 97 | |
| 98 | 98 | case 'ro': |
| 99 | 99 | // @see https://github.com/dismine/Valentina_sonar/blob/2930a1c51406255001331bf6013f85fc340b91f7/scripts/alphabets.py . |
| 100 | - return self::reset( explode( ',', 'A,Ă,Â,B,C,D,E,F,G,H,I,Î,J,K,L,M,N,O,P,Q,R,S,Ș,T,Ț,U,V,W,X,Y,Z' ) ); |
|
| 100 | + return self::reset(explode(',', 'A,Ă,Â,B,C,D,E,F,G,H,I,Î,J,K,L,M,N,O,P,Q,R,S,Ș,T,Ț,U,V,W,X,Y,Z')); |
|
| 101 | 101 | |
| 102 | 102 | case 'ru': |
| 103 | 103 | // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/ru_utf8/langconfig.php . |
| 104 | - return self::reset( explode( ',', 'А,Б,В,Г,Д,Е,Ё,Ж,З,И,К,Л,М,Н,О,П,Р,С,Т,У,Ф,Х,Ц,Ч,Ш,Щ,Э,Ю,Я' ) ); |
|
| 104 | + return self::reset(explode(',', 'А,Б,В,Г,Д,Е,Ё,Ж,З,И,К,Л,М,Н,О,П,Р,С,Т,У,Ф,Х,Ц,Ч,Ш,Щ,Э,Ю,Я')); |
|
| 105 | 105 | |
| 106 | 106 | case 'sk': |
| 107 | 107 | // @see https://github.com/dismine/Valentina_sonar/blob/2930a1c51406255001331bf6013f85fc340b91f7/scripts/alphabets.py . |
| 108 | - return self::reset( explode( ',', 'A,Á,Ä,B,C,Č,D,Ď,DZ,DŽ,E,É,F,G,H,CH,I,Í,J,K,L,Ĺ,Ľ,M,N,Ň,O,Ó,Ô,P,Q,R,Ŕ,S,Š,T,Ť,U,Ú,V,W,X,Y,Ý,Z,Ž' ) ); |
|
| 108 | + return self::reset(explode(',', 'A,Á,Ä,B,C,Č,D,Ď,DZ,DŽ,E,É,F,G,H,CH,I,Í,J,K,L,Ĺ,Ľ,M,N,Ň,O,Ó,Ô,P,Q,R,Ŕ,S,Š,T,Ť,U,Ú,V,W,X,Y,Ý,Z,Ž')); |
|
| 109 | 109 | |
| 110 | 110 | case 'sl': |
| 111 | 111 | // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/sl_utf8/langconfig.php . |
| 112 | - return self::reset( explode( ',', 'A,B,C,Č,D,E,F,G,H,I,J,K,L,M,N,O,P,R,S,Š,T,U,V,Z,Ž' ) ); |
|
| 112 | + return self::reset(explode(',', 'A,B,C,Č,D,E,F,G,H,I,J,K,L,M,N,O,P,R,S,Š,T,U,V,Z,Ž')); |
|
| 113 | 113 | |
| 114 | 114 | case 'sq': |
| 115 | 115 | // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/sq_utf8/langconfig.php . |
| 116 | - return self::reset( explode( ',', 'A,B,C,Ç,D,E,Ë,F,G,GJ,H,I,J,K,L,LL,M,N,O,P,Q,R,RR,S,SH,T,TH,U,V,X,XH,Y,Z,ZH' ) ); |
|
| 116 | + return self::reset(explode(',', 'A,B,C,Ç,D,E,Ë,F,G,GJ,H,I,J,K,L,LL,M,N,O,P,Q,R,RR,S,SH,T,TH,U,V,X,XH,Y,Z,ZH')); |
|
| 117 | 117 | |
| 118 | 118 | case 'sr': |
| 119 | 119 | // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/sr_cr_utf8/langconfig.php . |
| 120 | - return self::reset( explode( ',', 'А,Б,В,Г,Д,Ђ,Е,Ж,З,И,J,K,Л,Љ,М,Н,Њ,O,П,Р,С,Т,Ћ,У,Ф,Х,Ц,Ч,Џ,Ш' ) ); |
|
| 120 | + return self::reset(explode(',', 'А,Б,В,Г,Д,Ђ,Е,Ж,З,И,J,K,Л,Љ,М,Н,Њ,O,П,Р,С,Т,Ћ,У,Ф,Х,Ц,Ч,Џ,Ш')); |
|
| 121 | 121 | |
| 122 | 122 | case 'sv': |
| 123 | 123 | // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/sv_utf8/langconfig.php . |
| 124 | - return self::reset( explode( ',', 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,Å,Ä,Ö' ) ); |
|
| 124 | + return self::reset(explode(',', 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,Å,Ä,Ö')); |
|
| 125 | 125 | |
| 126 | 126 | case 'tr': |
| 127 | 127 | // @see https://github.com/mudrd8mz/moodle-lang/blob/9f43e2c74953545f2ff836159cbec9fb7a710fcd/tr_utf8/langconfig.php . |
| 128 | - return self::reset( explode( ',', 'A,B,C,Ç,D,E,F,G,H,I,İ,J,K,L,M,N,O,Ö,P,R,S,Ş,T,U,Ü,V,Y,Z,Q,W,X' ) ); |
|
| 128 | + return self::reset(explode(',', 'A,B,C,Ç,D,E,F,G,H,I,İ,J,K,L,M,N,O,Ö,P,R,S,Ş,T,U,Ü,V,Y,Z,Q,W,X')); |
|
| 129 | 129 | |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | // If we got here, we don't support the language, then return an empty array. |
| 133 | - return self::reset( array() ); |
|
| 133 | + return self::reset(array()); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -142,12 +142,12 @@ discard block |
||
| 142 | 142 | * |
| 143 | 143 | * @return array The alphabet array with letters as keys and empty arrays as values. |
| 144 | 144 | */ |
| 145 | - private static function reset( $alphabet ) { |
|
| 145 | + private static function reset($alphabet) { |
|
| 146 | 146 | |
| 147 | - $letters = array_flip( $alphabet ); |
|
| 147 | + $letters = array_flip($alphabet); |
|
| 148 | 148 | |
| 149 | - foreach ( $letters as $key => $value ) { |
|
| 150 | - $letters[ $key ] = array(); |
|
| 149 | + foreach ($letters as $key => $value) { |
|
| 150 | + $letters[$key] = array(); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | return $letters + array( |