1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
function bp_classifieds_setup_nav() {
  global $bp, $classified_obj, $current_blog;

  if ( $classified_id = BP_Classifieds_Classified::classified_exists($bp->current_action) ) { //REWORK INSIDE

    /* This is a single classified page. */
    $bp->is_single_item = true;
    $classified_obj = new BP_Classifieds_Classified( $classified_id );

    /* Using "item" not "group" for generic support in other components. */

    //CHECK IF ADMIN OR MODERATOR
    if ( classifieds_is_moderator() )
      $bp->is_item_admin = 1;

    /* If the user is not an admin, check if they are the author of the classified */
    if ( !$bp->is_item_admin ) {
      $bp->is_item_mod = classifieds_is_author( $bp->loggedin_user->id);
    }

    /* Should this classified be visible to visitor? */
    if (!$bp->loggedin_user) { //visible to visitor ?
      $is_visible = $bp->classifieds->options['allow_visitors'];
    } else { //visible to member
      $is_visible = true;
    }
  }

  /* Add 'Classifieds' to member main navigation */
  bp_core_add_nav_item( 
    __( 'Classifieds', 'bp-classifieds' ), /* The display name */ 
    $bp->classifieds->slug /* The slug */
  );

  /*default MEMBER page*/
  if ( $bp->displayed_user->id )
    bp_core_add_nav_default( $bp->classifieds->slug, 'classifieds_screen_member', 'my-classifieds' );

  $classifieds_link = $bp->loggedin_user->domain . $bp->classifieds->slug . '/';

  /*MEMBER submenus*/
  //bp_core_add_subnav_item( $parent_id, $slug, $name, $link, $function [, $css_id, $user_has_access, $admin_only ]
  bp_core_add_subnav_item( $bp->classifieds->slug, 'my-classifieds', __('My Classifieds', 'classifieds'), $classifieds_link, 'classifieds_screen_member', 'my-classifieds-list' );
  bp_core_add_subnav_item( $bp->classifieds->slug, 'create', __('Create new', 'classifieds'), $classifieds_link, 'classifieds_screen_create', false, bp_is_home() );
  bp_core_add_subnav_item( 'settings', 'classifieds', __('Classifieds', 'classifieds'), $bp->loggedin_user->domain . 'settings/', 'classifieds_screen_settings', false, bp_is_home() );

  /* Only execute the following code if we are actually viewing this component (e.g. http://example.org/example) */

  if ($bp->current_component == $bp->classifieds->slug) { //we are in classifieds

    if ( bp_is_home() && !$bp->is_single_item ) { //we are in our profile

      $bp->bp_options_title = __( 'My Example', 'bp-example' );

    } else if ( !bp_is_home() && !$bp->is_single_item ) {//we are in someone else profile

      $bp->bp_options_avatar = bp_core_get_avatar( $bp->displayed_user->id, 1 );
      $bp->bp_options_title = $bp->displayed_user->fullname;

    }else if ( $bp->is_single_item ) {
      // We are viewing a single classified, so set up the
      // classified navigation menu using the $classified_obj global.

      /* When in a single classified, the first action is bumped down one because of the
         classified name, so we need to adjust this and set the classified name to current_item. */
      $bp->current_item = $bp->current_action;
      $bp->current_action = $bp->action_variables[0];
      array_shift($bp->action_variables);

      $bp->bp_options_title = $classified_obj->name;
      $bp->bp_options_avatar = '<img src="' . $classified_obj->avatar_thumb . '" alt="Group Avatar Thumbnail" />';

      $classified_link = $bp->root_domain . '/' . $bp->classifieds->slug . '/' . $classified_obj->slug . '/';

      // Check classified access
      if (( 'published' == $classified_obj->status ) || (classifieds_is_moderator())) {
        $has_access=true;
      }else {
        $has_access=false;
      }

      // Reset the existing subnav items
      bp_core_reset_subnav_items($bp->classifieds->slug);
      bp_core_add_nav_default( $bp->classifieds->slug, 'classifieds_screen_single', 'single' );
      bp_core_add_subnav_item( $bp->classifieds->slug, 'single', __('Single', 'buddypress'), $classified_link, 'classifieds_screen_single', 'single-classified' );
      // If the user is a group mod or more, then show the group admin nav item */
      if ( $bp->is_item_mod || $bp->is_item_admin ) {
        bp_core_add_subnav_item( $bp->classifieds->slug, 'admin', __('Admin', 'buddypress'), $group_link , 'groups_screen_group_admin', 'group-admin', ( $bp->is_item_admin + (int)$bp->is_item_mod ) );
      }
    }
  }
  do_action( 'bp_classifieds_setup_nav', $has_access );
}
add_action( 'wp', 'bp_classifieds_setup_nav', 2 );
add_action( 'admin_menu', 'bp_classifieds_setup_nav', 2 ); //TO FIX : what for ?

function classifieds_screen_directory() {
  global $bp;

  if ( $bp->current_component == $bp->classifieds->slug && empty( $bp->current_action ) ) {

    $bp->is_directory = true;

    /*
    $directory_nav_tree=array();
    if ($bp->current_action=='view') { //listing ads
      $directory_nav_tree[]=__( 'View Classifieds', 'classifieds' );
      bp_classifieds_explode_args_url();
    }*/
    do_action( 'classifieds_screen_directory' );  


    bp_core_load_template( apply_filters( 'classifieds_screen_directory', 'directories/groups/index' ) );

    //bp_core_load_template( apply_filters( 'classifieds_template_directory', 'classifieds2/create' ) );

  }
}
add_action( 'wp', 'classifieds_screen_directory', 2 );


function classifieds_screen_single() {
  global $bp;
  if ( $bp->is_single_item ) {
    if ( isset($_GET['new']) ) {
      // Delete classified request notifications for the user
    }
    do_action( 'classifieds_screen_single' );  
    echo "classifieds_screen_single";
    bp_core_load_template( apply_filters( 'classifieds_template_single', 'classifieds2/classified-single' ) );    
  }
}