includes/comment.php
changeset 541 acb7e23b6ffa
parent 536 218a627eb53e
child 621 68f8a9cc0a18
equal deleted inserted replaced
540:1e4b759da336 541:acb7e23b6ffa
    69    */
    69    */
    70    
    70    
    71   function process_json($json)
    71   function process_json($json)
    72   {
    72   {
    73     global $db, $session, $paths, $template, $plugins; // Common objects
    73     global $db, $session, $paths, $template, $plugins; // Common objects
       
    74     global $lang;
       
    75     
    74     $data = enano_json_decode($json);
    76     $data = enano_json_decode($json);
    75     $data = decode_unicode_array($data);
    77     $data = decode_unicode_array($data);
    76     if ( !isset($data['mode']) )
    78     if ( !isset($data['mode']) )
    77     {
    79     {
    78       $ret = Array('mode'=>'error','error'=>'No mode defined!');
    80       $ret = Array('mode'=>'error','error'=>'No mode defined!');
    85       echo enano_json_encode($ret);
    87       echo enano_json_encode($ret);
    86       return $ret;
    88       return $ret;
    87     }
    89     }
    88     $ret = Array();
    90     $ret = Array();
    89     $ret['mode'] = $data['mode'];
    91     $ret['mode'] = $data['mode'];
    90     $ret['avatar_directory'] = getConfig('avatar_directory');
       
    91     switch ( $data['mode'] )
    92     switch ( $data['mode'] )
    92     {
    93     {
    93       case 'fetch':
    94       case 'fetch':
    94         if ( !$template->theme_loaded )
    95         if ( !$template->theme_loaded )
    95           $template->load_theme();
    96           $template->load_theme();
   100         $q = $db->sql_query('SELECT c.comment_id,c.name,c.subject,c.comment_data,c.time,c.approved,( c.ip_address IS NOT NULL ) AS have_ip,u.user_level,u.user_id,u.signature,u.user_has_avatar,u.avatar_type, b.buddy_id IS NOT NULL AS is_buddy, ( b.is_friend IS NOT NULL AND b.is_friend=1 ) AS is_friend FROM '.table_prefix.'comments AS c
   101         $q = $db->sql_query('SELECT c.comment_id,c.name,c.subject,c.comment_data,c.time,c.approved,( c.ip_address IS NOT NULL ) AS have_ip,u.user_level,u.user_id,u.signature,u.user_has_avatar,u.avatar_type, b.buddy_id IS NOT NULL AS is_buddy, ( b.is_friend IS NOT NULL AND b.is_friend=1 ) AS is_friend FROM '.table_prefix.'comments AS c
   101                                LEFT JOIN '.table_prefix.'users AS u
   102                                LEFT JOIN '.table_prefix.'users AS u
   102                                  ON (u.user_id=c.user_id)
   103                                  ON (u.user_id=c.user_id)
   103                                LEFT JOIN '.table_prefix.'buddies AS b
   104                                LEFT JOIN '.table_prefix.'buddies AS b
   104                                  ON ( ( b.user_id=' . $session->user_id.' AND b.buddy_user_id=c.user_id ) OR b.user_id IS NULL)
   105                                  ON ( ( b.user_id=' . $session->user_id.' AND b.buddy_user_id=c.user_id ) OR b.user_id IS NULL)
       
   106                                LEFT JOIN '.table_prefix.'ranks AS r
       
   107                                  ON ( ( u.user_rank = r.rank_id ) )
   105                                WHERE page_id=\'' . $this->page_id . '\'
   108                                WHERE page_id=\'' . $this->page_id . '\'
   106                                  AND namespace=\'' . $this->namespace . '\'
   109                                  AND namespace=\'' . $this->namespace . '\'
   107                                GROUP BY c.comment_id,c.name,c.subject,c.comment_data,c.time,c.approved,c.ip_address,u.user_level,u.user_id,u.signature,u.user_has_avatar,u.avatar_type,b.buddy_id,b.is_friend
   110                                GROUP BY c.comment_id,c.name,c.subject,c.comment_data,c.time,c.approved,c.ip_address,u.user_level,u.user_id,u.signature,u.user_has_avatar,u.avatar_type,b.buddy_id,b.is_friend
   108                                ORDER BY c.time ASC;');
   111                                ORDER BY c.time ASC;');
   109         $count_appr = 0;
   112         $count_appr = 0;
   120             $count_total++;
   123             $count_total++;
   121             ( $row['approved'] == 1 ) ? $count_appr++ : $count_unappr++;
   124             ( $row['approved'] == 1 ) ? $count_appr++ : $count_unappr++;
   122             
   125             
   123             if ( !$this->perms->get_permissions('mod_comments') && $row['approved'] == 0 )
   126             if ( !$this->perms->get_permissions('mod_comments') && $row['approved'] == 0 )
   124               continue;
   127               continue;
       
   128             
       
   129             // Localize the rank
       
   130             $row = array_merge($row, $session->get_user_rank(intval($row['user_id'])));
   125             
   131             
   126             // Send the source
   132             // Send the source
   127             $row['comment_source'] = $row['comment_data'];
   133             $row['comment_source'] = $row['comment_data'];
   128             
   134             
   129             // Format text
   135             // Format text
   147             // Format signature
   153             // Format signature
   148             $row['signature'] = ( !empty($row['signature']) ) ? RenderMan::render($row['signature']) : '';
   154             $row['signature'] = ( !empty($row['signature']) ) ? RenderMan::render($row['signature']) : '';
   149             
   155             
   150             // Do we have the IP?
   156             // Do we have the IP?
   151             $row['have_ip'] = ( $row['have_ip'] == 1 );
   157             $row['have_ip'] = ( $row['have_ip'] == 1 );
       
   158             
       
   159             // Avatar URL
       
   160             $row['avatar_path'] = make_avatar_url($row['user_id'], $row['avatar_type']);
   152             
   161             
   153             // Add the comment to the list
   162             // Add the comment to the list
   154             $ret['comments'][] = $row;
   163             $ret['comments'][] = $row;
   155             
   164             
   156           } while ( $row = $db->fetchrow() );
   165           } while ( $row = $db->fetchrow() );
   320           
   329           
   321           $ret['auth_mod_comments'] = $this->perms->get_permissions('mod_comments');
   330           $ret['auth_mod_comments'] = $this->perms->get_permissions('mod_comments');
   322           $ret['auth_post_comments'] = $this->perms->get_permissions('post_comments');
   331           $ret['auth_post_comments'] = $this->perms->get_permissions('post_comments');
   323           $ret['auth_edit_comments'] = $this->perms->get_permissions('edit_comments');
   332           $ret['auth_edit_comments'] = $this->perms->get_permissions('edit_comments');
   324           $ret['user_id'] = $session->user_id;
   333           $ret['user_id'] = $session->user_id;
       
   334           $ret['rank_data'] = $session->get_user_rank($session->user_id);
   325           $ret['username'] = $session->username;
   335           $ret['username'] = $session->username;
   326           $ret['logged_in'] = $session->user_logged_in;
   336           $ret['logged_in'] = $session->user_logged_in;
   327           $ret['signature'] = RenderMan::render($row['signature']);
   337           $ret['signature'] = RenderMan::render($row['signature']);
   328           
   338           
   329           $ret['user_level_list'] = Array();
   339           $ret['user_level_list'] = Array();
   330           $ret['user_level_list']['guest'] = USER_LEVEL_GUEST;
   340           $ret['user_level_list']['guest'] = USER_LEVEL_GUEST;
   331           $ret['user_level_list']['member'] = USER_LEVEL_MEMBER;
   341           $ret['user_level_list']['member'] = USER_LEVEL_MEMBER;
   332           $ret['user_level_list']['mod'] = USER_LEVEL_MOD;
   342           $ret['user_level_list']['mod'] = USER_LEVEL_MOD;
   333           $ret['user_level_list']['admin'] = USER_LEVEL_ADMIN;
   343           $ret['user_level_list']['admin'] = USER_LEVEL_ADMIN;
   334           $ret['avatar_directory'] = getConfig('avatar_directory');
   344           $ret['avatar_path'] = make_avatar_url($row['user_id'], $row['avatar_type']);
   335         }
   345         }
   336         
   346         
   337         break;
   347         break;
   338       case 'approve':
   348       case 'approve':
   339         if ( !$this->perms->get_permissions('mod_comments') )
   349         if ( !$this->perms->get_permissions('mod_comments') )