/** * Fix posts data */ public function fixData($data) { if (!is_array($data) || empty($data)) { return; } $all_post_ids = $all_post_authors = array(); // find all post id's and authors foreach ($data as $tmp) { $all_post_ids[] = $tmp['post_id']; $all_post_authors[] = $tmp['author_id']; } // retrieve comments for these posts $Comments = new Application_Model_Comments(); $post_comments = $Comments->getCommentsForResources($all_post_ids, 'post', $this->show_hidden_comments); // retrieve attached images for these posts $Images = new Application_Model_Images(); $post_images = $Images->getPostsImages($all_post_ids); // retrieve likes for these posts $Likes = new Application_Model_Likes(); $post_likes = $Likes->getLikesForPosts($all_post_ids, 'post'); // retrieve authors meta data $ProfilesMeta = new Application_Model_ProfilesMeta(); $profiles_meta = $ProfilesMeta->getMetaForProfiles($all_post_authors); // fix posts foreach ($data as &$post) { // depreciated $post['is_reported'] = 0; // blend in comments if (!empty($post_comments[$post['post_id']])) { $comments = $post_comments[$post['post_id']]; // trigger comments hooks Zend_Registry::get('hooks')->trigger('hook_data_comments', $comments); $post['comments'] = $comments; } // blend in images if (!empty($post_images[$post['post_id']])) { $post['post_images'] = $post_images[$post['post_id']]; } // blend in likes if (!empty($post_likes[$post['post_id']])) { $post['likes_count'] = $post_likes[$post['post_id']]['likes_count']; $post['is_liked'] = $post_likes[$post['post_id']]['is_liked']; } else { $post['likes_count'] = 0; $post['is_liked'] = 0; } // blend in author meta_data if (!empty($profiles_meta[$post['author_id']])) { $post['author_meta'] = $profiles_meta[$post['author_id']]; } // shares if (isset($post['rich_content_json'])) { $rich_content = json_decode($post['rich_content_json']); if ($rich_content->type == 'share') { $original_post_id = (int) $rich_content->data->post; if ($original_post_id) { $original_post = $this->getPosts(null, $original_post_id, false, true); if ($original_post !== null) { // copy from original $copycat = $post; $post = $original_post[0]; $post['copycat'] = $copycat; } else { // original content was removed $translator = Zend_Registry::get('Zend_Translate'); $post['post_content'] = $translator->translate('Resource not available'); } } } } // trigger post hooks Zend_Registry::get('hooks')->trigger('hook_data_postcontent', $post); } return $data; }