Commits

ncrocfer committed 41e950c

Added the edit_project activity action

  • Participants
  • Parent commits 787555c

Comments (0)

Files changed (1)

includes/bp-portfolio-functions.php

         // 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;
-            $description = $project->query->post->post_content;
-            $url = get_post_meta($result, 'bp_portfolio_url', true);
+            $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');
             
-            $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,
+                ) );
+            }
             
+
             
-            /* Now record the new activity item */
-            $user_link = bp_core_get_userlink( $bp->loggedin_user->id );
-            $user_portfolio_link = '<a href="'. bp_core_get_user_domain($bp->loggedin_user->id) . BP_PORTFOLIO_SLUG . '">portfolio</a>';
-            $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;
         }