includes/comment.php
changeset 621 68f8a9cc0a18
parent 541 acb7e23b6ffa
child 685 17ebe24cdf85
equal deleted inserted replaced
620:58852672ff12 621:68f8a9cc0a18
    96           $template->load_theme();
    96           $template->load_theme();
    97         if ( !isset($data['have_template']) )
    97         if ( !isset($data['have_template']) )
    98         {
    98         {
    99           $ret['template'] = file_get_contents(ENANO_ROOT . '/themes/' . $template->theme . '/comment.tpl');
    99           $ret['template'] = file_get_contents(ENANO_ROOT . '/themes/' . $template->theme . '/comment.tpl');
   100         }
   100         }
   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         $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.email,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
   102                                LEFT JOIN '.table_prefix.'users AS u
   102                                LEFT JOIN '.table_prefix.'users AS u
   103                                  ON (u.user_id=c.user_id)
   103                                  ON (u.user_id=c.user_id)
   104                                LEFT JOIN '.table_prefix.'buddies AS b
   104                                LEFT JOIN '.table_prefix.'buddies AS b
   105                                  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
   106                                LEFT JOIN '.table_prefix.'ranks AS r
   107                                  ON ( ( u.user_rank = r.rank_id ) )
   107                                  ON ( ( u.user_rank = r.rank_id ) )
   108                                WHERE page_id=\'' . $this->page_id . '\'
   108                                WHERE page_id=\'' . $this->page_id . '\'
   109                                  AND namespace=\'' . $this->namespace . '\'
   109                                  AND namespace=\'' . $this->namespace . '\'
   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
   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.email,u.signature,u.user_has_avatar,u.avatar_type,b.buddy_id,b.is_friend
   111                                ORDER BY c.time ASC;');
   111                                ORDER BY c.time ASC;');
   112         $count_appr = 0;
   112         $count_appr = 0;
   113         $count_total = 0;
   113         $count_total = 0;
   114         $count_unappr = 0;
   114         $count_unappr = 0;
   115         $ret['comments'] = Array();
   115         $ret['comments'] = Array();
   155             
   155             
   156             // Do we have the IP?
   156             // Do we have the IP?
   157             $row['have_ip'] = ( $row['have_ip'] == 1 );
   157             $row['have_ip'] = ( $row['have_ip'] == 1 );
   158             
   158             
   159             // Avatar URL
   159             // Avatar URL
   160             $row['avatar_path'] = make_avatar_url($row['user_id'], $row['avatar_type']);
   160             $row['avatar_path'] = make_avatar_url($row['user_id'], $row['avatar_type'], $row['email']);
   161             
   161             
   162             // Add the comment to the list
   162             // Add the comment to the list
   163             $ret['comments'][] = $row;
   163             $ret['comments'][] = $row;
   164             
   164             
   165           } while ( $row = $db->fetchrow() );
   165           } while ( $row = $db->fetchrow() );
   306                              "('$this->page_id', '$this->namespace', '$name', '$subj', '$sql_text', $appr, $time, {$session->user_id}, '$ip');");
   306                              "('$this->page_id', '$this->namespace', '$name', '$subj', '$sql_text', $appr, $time, {$session->user_id}, '$ip');");
   307           if(!$q)
   307           if(!$q)
   308             $db->die_json();
   308             $db->die_json();
   309           
   309           
   310           // Re-fetch
   310           // Re-fetch
   311           $q = $db->sql_query('SELECT c.comment_id,c.name,c.subject,c.comment_data,c.time,c.approved,u.user_level,u.user_id,u.signature,u.user_has_avatar,u.avatar_type FROM '.table_prefix.'comments AS c
   311           $q = $db->sql_query('SELECT c.comment_id,c.name,c.subject,c.comment_data,c.time,c.approved,u.user_level,u.user_id,u.email,u.signature,u.user_has_avatar,u.avatar_type FROM '.table_prefix.'comments AS c
   312                                LEFT JOIN '.table_prefix.'users AS u
   312                                LEFT JOIN '.table_prefix.'users AS u
   313                                  ON (u.user_id=c.user_id)
   313                                  ON (u.user_id=c.user_id)
   314                                WHERE page_id=\'' . $this->page_id . '\'
   314                                WHERE page_id=\'' . $this->page_id . '\'
   315                                  AND namespace=\'' . $this->namespace . '\'
   315                                  AND namespace=\'' . $this->namespace . '\'
   316                                  AND time='.$time.' ORDER BY comment_id DESC LIMIT 1;');
   316                                  AND time='.$time.' ORDER BY comment_id DESC LIMIT 1;');
   339           $ret['user_level_list'] = Array();
   339           $ret['user_level_list'] = Array();
   340           $ret['user_level_list']['guest'] = USER_LEVEL_GUEST;
   340           $ret['user_level_list']['guest'] = USER_LEVEL_GUEST;
   341           $ret['user_level_list']['member'] = USER_LEVEL_MEMBER;
   341           $ret['user_level_list']['member'] = USER_LEVEL_MEMBER;
   342           $ret['user_level_list']['mod'] = USER_LEVEL_MOD;
   342           $ret['user_level_list']['mod'] = USER_LEVEL_MOD;
   343           $ret['user_level_list']['admin'] = USER_LEVEL_ADMIN;
   343           $ret['user_level_list']['admin'] = USER_LEVEL_ADMIN;
   344           $ret['avatar_path'] = make_avatar_url($row['user_id'], $row['avatar_type']);
   344           $ret['avatar_path'] = make_avatar_url($row['user_id'], $row['avatar_type'], $row['email']);
   345         }
   345         }
   346         
   346         
   347         break;
   347         break;
   348       case 'approve':
   348       case 'approve':
   349         if ( !$this->perms->get_permissions('mod_comments') )
   349         if ( !$this->perms->get_permissions('mod_comments') )