true ) ); wp_set_script_translations( 'raplace-editor', 'spotsend', RAPLACE_DIR . 'languages' ); wp_register_style( 'raplace-leaflet', RAPLACE_URL . 'vendor/leaflet/leaflet.css', array(), '1.9.4' ); wp_register_script( 'raplace-leaflet', RAPLACE_URL . 'vendor/leaflet/leaflet.js', array(), '1.9.4', array( 'in_footer' => true ) ); wp_register_script( 'raplace-map', RAPLACE_URL . 'blocks/map/view.js', array( 'raplace-leaflet' ), asset_version( 'blocks/map/view.js' ), array( 'in_footer' => true ) ); register_block_type( RAPLACE_DIR . 'blocks/form' ); register_block_type( RAPLACE_DIR . 'blocks/map' ); } ); /** * Resolved reports that have coordinates, as the map block shows them: the place as described, * its categories, the day it was resolved and, when asked for, the first photo. The description and * who sent the report are never included. * * @return array */ function resolved_reports( bool $with_photos ): array { $ids = get_posts( array( 'post_type' => POST_TYPE, 'post_status' => 'publish', 'posts_per_page' => -1, 'fields' => 'ids', 'no_found_rows' => true, 'meta_key' => 'raplace_lat', // phpcs:ignore WordPress.DB.SlowDBQuery -- reports with coordinates only. ) ); $reports = array(); foreach ( $ids as $id ) { $report = get_report( $id ); if ( '' === $report['lat'] || '' === $report['lng'] ) { continue; } $reports[] = array( 'name' => html_entity_decode( get_the_title( $id ), ENT_QUOTES ), 'lat' => (float) $report['lat'], 'lng' => (float) $report['lng'], 'categories' => array_values( $report['categories'] ), 'resolved' => '' !== $report['resolved_on'] ? (string) mysql2date( get_option( 'date_format' ), $report['resolved_on'] ) : '', 'photo' => $with_photos && $report['photo'] ? (string) wp_get_attachment_image_url( $report['photo'], 'medium' ) : '', ); } return $reports; } /** * Default text for each editable label of the form, used while the block attribute is empty. */ function default_labels(): array { return array( 'placeLabel' => __( 'Where is it?', 'spotsend' ), 'placePlaceholder' => __( 'For example, the roadside by the bridge', 'spotsend' ), 'placeHelp' => __( 'An address, a landmark or coordinates.', 'spotsend' ), 'locateLabel' => __( 'Use my location', 'spotsend' ), 'pickLabel' => __( 'Choose on map', 'spotsend' ), 'mapHelp' => __( 'Tap the map where the place is, then drag the pin to adjust it.', 'spotsend' ), 'categoriesLabel' => __( 'What is there?', 'spotsend' ), 'descriptionLabel' => __( 'Description', 'spotsend' ), 'descriptionPlaceholder' => __( 'How much, how long it has been there, how to get to it', 'spotsend' ), 'descriptionHelp' => __( 'Optional, but it helps.', 'spotsend' ), 'photoLabel' => __( 'Photos', 'spotsend' ), 'reporterLabel' => __( 'Your name', 'spotsend' ), 'reporterHelp' => __( 'Optional.', 'spotsend' ), 'emailLabel' => __( 'Your email', 'spotsend' ), 'emailHelp' => __( 'Optional. We will confirm that your report arrived, and can reply to you.', 'spotsend' ), 'submitLabel' => __( 'Send report', 'spotsend' ), 'successMessage' => __( 'Thank you! Your report has been sent.', 'spotsend' ), 'sendingMessage' => __( 'Sending…', 'spotsend' ), 'failedMessage' => __( 'The report could not be sent. Please try again in a moment.', 'spotsend' ), 'locatingMessage' => __( 'Finding your location…', 'spotsend' ), 'locatedMessage' => __( 'Coordinates added.', 'spotsend' ), 'noLocateMessage' => __( 'Your location could not be found. Please type the place instead.', 'spotsend' ), 'pickedMessage' => __( 'Point set on the map.', 'spotsend' ), ); }