Ejemplo n.º 1
0
function cjtheme_update_bp_acmeta_thanks()
{
    global $wpdb;
    $table_bp_acmeta = $wpdb->prefix . 'cjtheme_likes_thanks';
    $check_existing = $wpdb->get_row("SELECT * FROM {$table_bp_acmeta} WHERE user_id = '{$_POST['user_id']}' AND comment_id = '{$_POST['comment_id']}'");
    if (is_null($check_existing)) {
        $acmeta_data = array('comment_id' => $_POST['comment_id'], 'user_id' => $_POST['user_id'], 'thanks' => 1);
        cjtheme_insert($table_bp_acmeta, $acmeta_data);
        $comment_thanks = cjtheme_activity_comment_thanks($_POST['comment_id']);
        $comment_thanks = !is_null($comment_thanks) ? ' ' . $comment_thanks : '';
        $comment = get_comment($_POST['comment_id']);
        if ($comment->user_id != $_POST['user_id']) {
            gamf_add_points(cjtheme_user_info($comment->user_id, 'ID'), '3', 'thank-answer', 'You received a thanks on your answer.');
        }
        echo ' ' . $comment_thanks;
    } elseif ($check_existing->thanks == 0) {
        $acmeta_data = array('comment_id' => $_POST['comment_id'], 'user_id' => $_POST['user_id'], 'thanks' => 1);
        cjtheme_update($table_bp_acmeta, $acmeta_data, 'id', $check_existing->id);
        $comment_thanks = cjtheme_activity_comment_thanks($_POST['comment_id']);
        $comment_thanks = !is_null($comment_thanks) ? ' ' . $comment_thanks : '';
        $comment = get_comment($_POST['comment_id']);
        if ($comment->user_id != $_POST['user_id']) {
            gamf_add_points(cjtheme_user_info($comment->user_id, 'ID'), '3', 'thank-answer', 'You received a thanks on your answer.');
            $nmessage = '<a href="' . site_url(cjtheme_user_info($_POST['user_id'], 'user_login')) . '">' . cjtheme_user_info($_POST['user_id'], 'display_name') . '</a> said thanks for your <a href="' . get_permalink($comment->comment_post_ID) . '#answer-' . $comment->comment_ID . '">answer</a>.';
            cjtheme_notification_add(cjtheme_user_info($comment->user_id, 'ID'), $nmessage);
        }
        echo ' ' . $comment_thanks;
    } else {
        $acmeta_data = array('comment_id' => $_POST['comment_id'], 'user_id' => $_POST['user_id'], 'thanks' => 0);
        cjtheme_update($table_bp_acmeta, $acmeta_data, 'id', $check_existing->id);
        $comment_thanks = cjtheme_activity_comment_thanks($_POST['comment_id']);
        $comment_thanks = !is_null($comment_thanks) ? ' ' . $comment_thanks : '';
        $comment = get_comment($_POST['comment_id']);
        if ($comment->user_id != $_POST['user_id']) {
            gamf_add_points(cjtheme_user_info($comment->user_id, 'ID'), '-3', 'unthank-answer', 'You received a Thanks  on your answer.');
            $nmessage = '<a href="' . site_url(cjtheme_user_info($_POST['user_id'], 'user_login')) . '">' . cjtheme_user_info($_POST['user_id'], 'display_name') . '</a> unthanked your <a href="' . get_permalink($comment->comment_post_ID) . '#answer-' . $comment->comment_ID . '">answer</a>.';
            cjtheme_notification_add(cjtheme_user_info($comment->user_id, 'ID'), $nmessage);
        }
        echo '' . $comment_thanks;
    }
    die;
}
<?php

/**
 * @package CSSJockey WordPress Framework
 * @author Mohit Aneja (cssjockey.com)
 * @version FW-20150208
*/
global $wpdb;
$options_table = cjtheme_item_info('options_table');
$settings = $wpdb->get_results("SELECT * FROM {$options_table}");
$export_settings = urlencode(serialize($settings));
$cjtheme_form_options['export_settings'] = array(array('type' => 'sub-heading', 'id' => 'export_heading', 'label' => '', 'info' => '', 'suffix' => '', 'prefix' => '', 'default' => sprintf(__('Export %s Settings', 'cjtheme'), ucwords(cjtheme_item_info('item_type'))), 'options' => ''), array('type' => 'textarea-readonly', 'id' => 'export_settings', 'label' => __('Export Settings', 'cjtheme'), 'info' => __('Copy the contents and save it in a text file.', 'cjtheme'), 'suffix' => '', 'prefix' => '', 'default' => cjtheme_post_default('export_settings', $export_settings), 'options' => '', 'params' => ' onclick="this.focus();this.select()" '));
cjtheme_admin_form_raw($cjtheme_form_options['export_settings']);
if (isset($_POST['do_import_settings'])) {
    $import_settings = unserialize(urldecode($_POST['import_settings']));
    if (is_array($import_settings)) {
        $wpdb->query("TRUNCATE TABLE {$options_table}");
        foreach ($import_settings as $key => $value) {
            $insert_data = array('option_name' => $value->option_name, 'option_value' => $value->option_value);
            cjtheme_insert($options_table, $insert_data);
        }
        $location = cjtheme_callback_url();
        wp_redirect($location, $status = 302);
        exit;
    }
}
$cjtheme_form_options['import_settings'] = array(array('type' => 'heading', 'id' => 'import_heading', 'label' => '', 'info' => '', 'suffix' => '', 'prefix' => '', 'default' => sprintf(__('Import %s Settings', 'cjtheme'), ucwords(cjtheme_item_info('item_type'))), 'options' => ''), array('type' => 'textarea', 'id' => 'import_settings', 'label' => __('Import Settings', 'cjtheme'), 'info' => __('Paste the previously copied settings and click Import Settings.', 'cjtheme'), 'suffix' => '', 'prefix' => '', 'default' => '', 'options' => ''), array('type' => 'submit', 'id' => 'do_import_settings', 'label' => __('Import Settings', 'cjtheme'), 'info' => '', 'suffix' => '', 'prefix' => '', 'default' => '', 'options' => ''));
echo '<form class="margin-30-top" action="' . admin_url('admin.php?page=' . @$_GET['page'] . '&callback=' . @$_GET['callback'] . '') . '" method="post" enctype="multipart/form-data">';
cjtheme_admin_form_raw($cjtheme_form_options['import_settings']);
echo '</form>';
function cjtheme_notification_add($user_id, $message)
{
    global $wpdb;
    $table_notifications = $wpdb->prefix . 'cjtheme_notifications';
    $notification_data = array('user_id' => $user_id, 'message' => $message, 'unread' => 1);
    return cjtheme_insert($table_notifications, $notification_data);
}