/** * Save the new item and records an activity item for it */ function bp_portfolio_save_item($args = array()) { global $bp; $defaults = array('id' => null, 'author_id' => $bp->loggedin_user->id, 'title' => null, 'description' => null, 'url' => null, 'screenshot' => null); $db_args = wp_parse_args($args, $defaults); extract($db_args, EXTR_SKIP); $portfolio = new BP_Portfolio_Item($db_args); // Records an activity if ($result = $portfolio->save()) { /* Now record the activity item */ $user_link = bp_core_get_userlink($bp->loggedin_user->id); $project = new BP_Portfolio_Item(array('id' => $result)); $project->get(); $title = $project->query->post->post_title; $user_portfolio_link = '<a href="' . bp_core_get_user_domain($bp->loggedin_user->id) . BP_PORTFOLIO_SLUG . '">portfolio</a>'; if ($id) { // Edit an existing item bp_portfolio_record_activity(array('type' => 'edit_project', 'action' => apply_filters('bp_edit_portfolio_activity_action', sprintf(__('%s edited the <strong>%s</strong> project in his %s', 'bp-portfolio'), $user_link, $title, $user_portfolio_link), $user_link, $title, $user_portfolio_link), 'item_id' => $bp->loggedin_user->id)); } else { // New item, so new activity $description = $project->query->post->post_content; $url = get_post_meta($result, 'bp_portfolio_url', true); $attachment = wp_get_attachment_image_src($project->query->post->post_parent, 'portfolio-thumb'); if ($attachment != 0) { $thumbnail = apply_filters('bp_portfolio_get_item_thumbnail', $attachment[0]); } else { $thumbnail = apply_filters('bp_portfolio_get_item_thumbnail', BP_PORTFOLIO_PLUGIN_URL . '/templates/' . BP_PORTFOLIO_TEMPLATE . '/img/default.png'); } $activity_content = sprintf(__('<div class="item-project"><div class="item-project-pictures"><img width="250px" height="170px" src="%s"></div><div class="item-project-content"><div class="item-project-title">%s</div><div class="item-project-url"><a href="%s">%s</a></div><div class="item-project-desc">%s</div></div></div></div>', 'bp-portfolio'), $thumbnail, $title, $url, $url, $description); bp_portfolio_record_activity(array('type' => 'new_project', 'action' => apply_filters('bp_new_portfolio_activity_action', sprintf(__('%s created a new project in his %s', 'bp-portfolio'), $user_link, $user_portfolio_link), $user_link, $user_portfolio_link), 'content' => $activity_content, 'item_id' => $bp->loggedin_user->id)); } return true; } return false; }