giorjoe
|
this is my hook.php for see the classification members with avatar
cp_hooks.php
PHP script text
comment_ID);
cp_points(‘comment’, $cdata->user_id, apply_filters(‘cp_comment_points’,get_option(‘cp_comment_points’)), $cdata->comment_ID);
}
/** Comment unapproved hook */
add_action(‘comment_approved_to_unapproved’, ‘cp_commentUnapprove’, 10, 1);
add_action(‘comment_approved_to_trash’, ‘cp_commentUnapprove’, 10, 1);
add_action(‘comment_approved_to_spam’, ‘cp_commentUnapprove’, 10, 1);
function cp_commentUnapprove($cdata){
do_action(‘cp_comment_remove’, $cdata->comment_ID);
cp_points(‘comment_remove’, $cdata->user_id, apply_filters(‘cp_del_comment_points’,-get_option(‘cp_del_comment_points’)), $cdata->comment_ID);
}
/** Comments logs hook */
add_action(‘cp_logs_description’,'cp_admin_logs_desc_comment’, 10, 4);
function cp_admin_logs_desc_comment($type,$uid,$points,$data){
if($type!=’comment’) { return; }
$cdata = get_comment($data);
if($cdata==null){ echo ”.__(‘Comment’, ‘cp’).”; return; }
$pid = $cdata->comment_post_ID;
$pdata = get_post($pid);
$ptitle = $pdata->post_title;
$url = get_permalink( $pid ) . ‘#comment-’ . $data;
$detail = __(‘Comment’, ‘cp’).’: ‘.cp_truncate(strip_tags($cdata->comment_content), 100, false);
echo ”.__(‘Comment on’, ‘cp’).’ "‘.$ptitle.’"’;
}
/** Comments removal logs hook */
add_action(‘cp_logs_description’,'cp_admin_logs_desc_comment_remove’, 10, 4);
function cp_admin_logs_desc_comment_remove($type,$uid,$points,$data){
if($type!=’comment_remove’) { return; }
_e(‘Comment Deletion’, ‘cp’);
}
/** Post hook */
add_action(‘publish_post’, ‘cp_newPost’);
function cp_newPost($pid) {
$post = get_post($pid);
$uid = $post->post_author;
global $wpdb;
$count = (int) $wpdb->get_var(“select count(id) from `”.CP_DB.”` where `type`=’post’ and `data`=”. $pid);
if($count==0){
cp_points(‘post’, $uid, apply_filters(‘cp_post_points’,get_option(‘cp_post_points’)), $pid);
}
}
/** Post logs hook */
add_action(‘cp_logs_description’,'cp_admin_logs_desc_post’, 10, 4);
function cp_admin_logs_desc_post($type,$uid,$points,$data){
if($type!=’post’) { return; }
$post = get_post($data);
echo __(‘Post on’, ‘cp’) . ‘ “‘ . $post->post_title . ‘“‘;
}
/** User registration hook */
add_action(‘user_register’, ‘cp_newUser’);
function cp_newUser($uid) {
cp_points(‘register’, $uid, apply_filters(‘cp_reg_points’,get_option(‘cp_reg_points’)), $uid);
}
/** User registration logs hook */
add_action(‘cp_logs_description’,'cp_admin_logs_desc_register’, 10, 4);
function cp_admin_logs_desc_register($type,$uid,$points,$data){
if($type!=’register’) { return; }
_e(‘Registration’, ‘cp’);
}
/** Admin manage logs hook */
add_action(‘cp_logs_description’,'cp_admin_logs_desc_admin’, 10, 4);
function cp_admin_logs_desc_admin($type,$uid,$points,$data){
if($type!=’admin’) { return; }
$user = get_userdata($data);
echo __(‘Points adjusted by ‘, ‘cp’) . ‘ “‘ . $user->user_login . ‘”‘;
}
/** Remote site logs hook */
add_action(‘cp_logs_description’,'cp_admin_logs_desc_remote’, 10, 4);
function cp_admin_logs_desc_remote($type,$uid,$points,$data){
if($type!=’remote’) { return; }
list($name,$url) = explode(‘^’, $data);
echo __(‘Points earned from ‘) . ‘ “‘ . $name . ‘“‘;
}
/** Custom logs hook */
add_action(‘cp_logs_description’,'cp_admin_logs_desc_custom’, 10, 4);
function cp_admin_logs_desc_custom($type,$uid,$points,$data){
if($type!=’custom’) { return; }
echo $data;
}
/** Display top users in page */
add_shortcode(‘cubepoints_top’,'cp_shortcode_top’);
function cp_shortcode_top( $atts ){
$num = (int) $atts['num'];
if($num<1){$num=1;}
$top = cp_getAllPoints($num,get_option('cp_topfilter'));
if($atts['class']!=''){$class = ' class="'.$atts['class'].'"';}
if($atts['style']!=''){$style = ' style="'.$atts['style'].'"';}
switch ($atts['display']) {
case 'custom':
if($atts['custom'] == null) {
$atts['custom'] = '%user%%avatar%%rank% (%points%)’;
}
foreach($top as $x=>$i) {
$count = “$count” + “1″;
$text = apply_filters(‘cp_displayUserInfo’,$atts['custom'],$i,$x+1);
$c .= $count;
$c .= $text;
}
break;
case ‘ol’:
$c = ”;
if($atts['custom'] == null) {
$atts['custom'] = ‘%user%%avatar%%rank% (%points%)’;
}
foreach($top as $x=>$i) {
$count = “$count” + “1″;
$text = apply_filters(‘cp_displayUserInfo’,$atts['custom'],$i,$x+1);
$before = “”;
$c .= $before;
$c .= $count;
$c .= $text;
}
$c .= ”;
break;
case ‘table’:
$c = ”;
if($atts['custom'] == null) {
$atts['custom'] = ‘%user%%avatar%rank% %points%’;
}
foreach($top as $x=>$i) {
$count = “$count” + “1″;
$text = apply_filters(‘cp_displayUserInfo’,$atts['custom'],$i,$x+1);
$c .= $count;
$c .= $text;
}
$c .= ”;
break;
default;
$c = ”;
if($atts['custom'] == null) {
$atts['custom'] = ‘%user%%avatar%%rank% (%points%)’;
}
foreach($top as $x=>$i) {
$count = “$count” + “1″;
$text = apply_filters(‘cp_displayUserInfo’,$atts['custom'],$i,$x+1);
$c .= $count;
$c .= $text;
}
$c .= ”;
break;
}
return $c;
}
/** Display points info in page */
add_shortcode(‘cubepoints’,'cp_shortcode_user’);
function cp_shortcode_user( $atts ){
if($atts['user']!=”){
$u=get_userdatabylogin($atts['user']);
$uid = $u->ID;
if($uid==”){ return ”; }
return cp_displayPoints($uid, 1, $atts['format']);
}
else{
$uid = cp_currentUser();
if($uid==”){ return $atts['not_logged_in']; }
return cp_displayPoints($uid, 1, (bool)$atts['format']);
}
return $c;
}
/** Format displays of users */
add_filter(‘cp_displayUserInfo’, ‘cp_displayUserInfo’, 10 , 3);
function cp_displayUserInfo($string,$y,$place) {
$user = get_userdata($y['id']);
$y['avatar'] = get_avatar($user->ID);
$string = str_replace(‘%avatar%’, $y['avatar'], $string);
$y['rank'] = cp_module_ranks_getRank($user->ID);
$string = str_replace(‘%rank%’, $y['rank'], $string);
$string = str_replace(‘%points%’, $y['points_formatted'], $string);
$string = str_replace(‘%npoints%’, $y['points'], $string);
$string = str_replace(‘%user%’, $y['user'], $string);
$string = str_replace(‘%username%’, $y['display_name'], $string);
$string = str_replace(‘%userid%’, $y['id'], $string);
$string = str_replace(‘%place%’, $place, $string);
$string = str_replace(‘%emailhash%’, md5(strtolower($user->user_email)), $string);
return $string;
}
/** Formatting tables */
add_filter(‘cp_displayTable’, ‘cp_displayTable’);
function cp_displayTable($string) {
$string = ”.$string;
$string = str_replace(‘%d%’, ”, $string);
$string .= ”;
return $string;
}
/** Hook to process admin manage ajax post request to update points */
add_action( ‘wp_ajax_cp_manage_form_submit’, ‘cp_manage_form_submit’ );
function cp_manage_form_submit() {
header( “Content-Type: application/json” );
if( ! current_user_can(‘manage_options’)){
$response = json_encode( array( ‘error’ => __(‘You do not have sufficient permission to manage points!’, ‘cp’) ) );
echo $response;
exit;
}
if($_POST['points']!=” && $_POST['user_id']!=”){
$points = (int) $_POST['points'];
$uid = (int) $_POST['user_id'];
$user = get_userdata($uid);
if($user->ID==NULL){
$response = json_encode( array( ‘error’ => __(‘User does not exist!’, ‘cp’) ) );
echo $response;
exit;
}
if($points __(‘Invalid request!’, ‘cp’) ) );
echo $response;
exit;
}
$response = json_encode( array( ‘error’ => ‘ok’ ,
‘points’ => cp_displayPoints($uid, 1, 0) ,
‘points_formatted’ => cp_displayPoints($uid, 1, 1) ,
‘username’ => $user->user_login ,
‘user_id’ => $user->ID
) );
echo $response;
exit;
}
/** Hook for add-points autocomplete user suggestion */
add_action( ‘wp_ajax_cp_add_points_user_suggest’, ‘cp_add_points_user_suggest’ );
function cp_add_points_user_suggest() {
header( “Content-Type: application/json” );
if( ! current_user_can(‘manage_options’) || $_REQUEST['q']==” ){
$response = json_encode( array() );
echo $response;
exit;
}
global $wpdb;
$users = $wpdb->get_results(‘SELECT * from `’ . $wpdb->prefix . ‘users` WHERE `user_login` LIKE \”.$_REQUEST['q'].’%\’ LIMIT 10′, ARRAY_A);
$response = array();
foreach($users as $user){
$response[] = implode(“|”, array($user['user_login'], $user['ID'], $user['display_name'], $user['user_email'], md5(trim(strtolower($user['user_email'])))));
}
$response = json_encode( implode(“\n”, $response) );
echo $response;
exit;
}
/** Hook for add-points user query */
add_action( ‘wp_ajax_cp_add_points_user_query’, ‘cp_add_points_user_query’ );
function cp_add_points_user_query() {
header( “Content-Type: application/json” );
if( ! current_user_can(‘manage_options’) || $_REQUEST['q']==” ){
$response = json_encode( array() );
echo $response;
exit;
}
global $wpdb;
$user = $wpdb->get_row(‘SELECT * from `’ . $wpdb->prefix . ‘users` WHERE `user_login` LIKE \”.$wpdb->prepare(trim($_REQUEST['q'])).’\’ LIMIT 1′, ARRAY_A);
if($user['ID'] == null){
$response = json_encode( array() );
echo $response;
exit;
}
$response = json_encode( array(
‘id’ => $user['ID'],
‘user_login’ => $user['user_login'],
‘display_name’ => $user['display_name'],
‘email’ => $user['user_email'],
‘points’ => cp_getPoints($user['ID']),
‘hash’ => md5(trim(strtolower($user['user_email'])))
));
echo $response;
exit;
}
/** Hook for add-points user update */
add_action( ‘wp_ajax_cp_add_points_user_update’, ‘cp_add_points_user_update’ );
function cp_add_points_user_update() {
header( “Content-Type: application/json” );
if( ! current_user_can(‘manage_options’) || $_POST['id']==” || $_POST['points']==” || $_POST['description']==” ){
$response = json_encode( array( ‘status’ => ‘failed’ ) );
echo $response;
exit;
}
cp_points(‘addpoints’, (int)$_POST['id'], (int)$_POST['points'], htmlentities($_POST['description']));
$response = json_encode( array(
‘status’ => ‘ok’,
‘newpoints’ => cp_getPoints((int)$_POST['id'])
));
echo $response;
exit;
}
?>
|