diff --git a/source/php/Helper/Post.php b/source/php/Helper/Post.php index 30528189d..1374ab552 100644 --- a/source/php/Helper/Post.php +++ b/source/php/Helper/Post.php @@ -132,174 +132,6 @@ public static function isArchive() return false; } - /** - * Prepare post object before sending to view - * Appends useful variables for views (generic). - * - * @param object $post WP_Post object - * - * @return object $post Transformed WP_Post object - */ - public static function preparePostObject($post) { - $post = self::complementObject($post); - $post = \Modularity\Helper\FormatObject::camelCase($post); - return $post; - } - - /** - * Add post data on post object - * - * @param object $postObject The post object - * @param object $appendFields Data to append on object - * - * @return object $postObject The post object, with appended data - */ - public static function complementObject( - $postObject, - $appendFields = array( - 'excerpt', - 'post_content_filtered', - 'post_title_filtered', - 'permalink', - 'terms' - ) - ) { - - //Check that a post object is entered - if (!is_a($postObject, 'WP_Post')) { - return $postObject; - throw new WP_Error("Complement object must recive a WP_Post class"); - } - - //More? Less? - $appendFields = apply_filters('Modularity/Helper/Post/complementPostObject', $appendFields); - - //Generate excerpt - if (in_array('excerpt', $appendFields)) { - if (empty($postObject->post_excerpt)) { - - //Create excerpt if not defined by editor - $postObject->excerpt = wp_trim_words( - $postObject->post_content, - apply_filters('Modularity/Helper/Post/ExcerptLenght', 55), - apply_filters('Modularity/Helper/Post/MoreTag', "...") - ); - - //Create excerpt if not defined by editor - $postObject->excerpt_short = wp_trim_words( - $postObject->post_content, - apply_filters('Modularity/Helper/Post/ExcerptLenghtShort', 20), - apply_filters('Modularity/Helper/Post/MoreTag', "...") - ); - - //No content in post - if (empty($postObject->excerpt)) { - $postObject->excerpt = '' . __("Item is missing content", 'municipio') . ""; - } - } else { - $postObject->excerpt_short = wp_trim_words( - $postObject->content, - apply_filters('Modularity/Helper/Post/ExcerptLenghtShort', 20), - apply_filters('Modularity/Helper/Post/MoreTag', "...") - ); - } - } - - //Get permalink - if (in_array('permalink', $appendFields)) { - $postObject->permalink = get_permalink($postObject); - } - - //Get filtered content - if (in_array('post_content_filtered', $appendFields)) { - //Parse lead - $parts = explode("", $postObject->post_content); - - if(is_array($parts) && count($parts) > 1) { - - //Remove the now broken more block - foreach ($parts as &$part) { - $part = str_replace('', '', $part); - $part = str_replace('', '', $part); - } - - $excerpt = self::createLeadElement(array_shift($parts)); - $content = self::removeEmptyPTag(implode(PHP_EOL, $parts)); - - } else { - $excerpt = ""; - $content = self::removeEmptyPTag($postObject->post_content); - } - - //Replace builtin css classes to our own - $postObject->post_content_filtered = $excerpt . str_replace( - [ - 'wp-caption', - 'c-image-text', - 'wp-image-', - 'alignleft', - 'alignright', - 'alignnone', - 'aligncenter', - - //Old inline transition button - 'btn-theme-first', - 'btn-theme-second', - 'btn-theme-third', - 'btn-theme-fourth', - 'btn-theme-fifth', - - //Gutenberg columns - 'wp-block-columns', - - //Gutenberg block image - 'wp-block-image', - '
' - ], - [ - 'c-image', - 'c-image__caption', - 'c-image__image wp-image-', - 'u-float--left@sm u-float--left@md u-float--left@lg u-float--left@xl u-margin__y--2 u-margin__right--2@sm u-margin__right--2@md u-margin__right--2@lg u-margin__right--2@xl u-width--100@xs', - 'u-float--right@sm u-float--right@md u-float--right@lg u-float--right@xl u-margin__y--2 u-margin__left--2@sm u-margin__left--2@md u-margin__left--2@lg u-margin__left--2@xl u-width--100@xs', - '', - 'u-margin__x--auto', - - //Old inline transition button - 'c-button c-button__filled c-button__filled--primary c-button--md', - 'c-button c-button__filled c-button__filled--secondary c-button--md', - 'c-button c-button__filled c-button__filled--secondary c-button--md', - 'c-button c-button__filled c-button__filled--secondary c-button--md', - 'c-button c-button__filled c-button__filled--secondary c-button--md', - - //Gutenberg columns - 'o-grid o-grid--no-margin@md', - - //Gutenberg block image - 'c-image', - '
' - ], - apply_filters('the_content', $content) - ); - } - - //Get filtered post title - if (in_array('post_title_filtered', $appendFields)) { - $postObject->post_title_filtered = apply_filters('the_title', $postObject->post_title); - } - - //Get post tumbnail image - $postObject->thumbnail = self::getFeaturedImage($postObject->ID, [400, 225]); - - //Append post terms - if (in_array('terms', $appendFields)) { - $postObject->terms = self::getPostTerms($postObject->ID); - $postObject->termsUnlinked = self::getPostTerms($postObject->ID, false); - } - - return $postObject; - } - /** * Remove empty ptags from string *