WordPress.org

Plugin Directory


Ignore:
Timestamp:
06/30/11 15:47:52 (7 years ago)
Author:
SriniG
Message:

Updating to version 1.5, tagging v1.4.4

File:
1 edited

Legend:

Unmodified
Added
Removed
  • quotes-collection/trunk/quotes-collection-ajax.php

    r253475 r402859  
    11<?php 
    2 // If you have your 'wp-content' directory in a place other than the default location, please specify your blog directory here. This is not your blog url. It is the address in your server. For example: '/public_html/myblog' 
    3 $blogdir = "";  
     2function quotescollection_scripts() 
     3{ 
     4    global $quotescollection_auto_refresh_max, $quotescollection_next_quote; 
    45 
    5 if(isset($_POST['refresh'])) { 
     6    $nextquote =  $quotescollection_next_quote?$quotescollection_next_quote:__('Next quote', 'quotes-collection')."&nbsp;&raquo;"; 
     7    $loading = __('Loading...', 'quotes-collection'); 
     8    $error = __('Error getting quote', 'quotes-collection'); 
     9    $auto_refresh_max = $quotescollection_auto_refresh_max; 
    610 
    7     if (!$blogdir) { 
    8         $blogdir = preg_replace('|/wp-content.*$|','', __FILE__); 
    9     } 
    10     if($blogdir == __FILE__) { 
    11         $blogdir = preg_replace('|\wp-content.*$|','', __FILE__); 
    12         include_once($blogdir.'\wp-config.php'); 
    13         include_once($blogdir.'\wp-includes\wp-db.php'); 
    14     } 
    15     else { 
    16         include_once($blogdir.'/wp-config.php'); 
    17         include_once($blogdir.'/wp-includes/wp-db.php'); 
    18     } 
    19     include_once(str_replace("-ajax", "", __FILE__)); 
     11    wp_enqueue_script( 'quotescollection', plugin_dir_url(__FILE__).'quotes-collection.js', array('jquery') ); 
     12    wp_localize_script( 'quotescollection', 'QCAjax', array( 
     13        // URL to wp-admin/admin-ajax.php to process the request 
     14        'ajaxurl' => admin_url( 'admin-ajax.php' ), 
     15  
     16        // generate a nonce with a unique ID "myajax-post-comment-nonce" 
     17        // so that you can check it later when an AJAX request is sent 
     18        'nonce' => wp_create_nonce( 'quotescollection' ), 
     19 
     20        'nextquote' => $nextquote, 
     21        'loading' => $loading, 
     22        'error' => $error, 
     23        'auto_refresh_max' => $quotescollection_auto_refresh_max, 
     24        'auto_refresh_count' => 0 
     25        ) 
     26    ); 
     27} 
     28add_action('init', 'quotescollection_scripts'); 
     29 
     30 
     31function quotescollection_load() 
     32{ 
     33    check_ajax_referer('quotescollection');  
     34     
     35     
    2036    $show_author = isset($_POST['show_author'])?$_POST['show_author']:1; 
    2137    $show_source = isset($_POST['show_source'])?$_POST['show_source']:1; 
     
    2440    $char_limit = (isset($_POST['char_limit']) && is_numeric($_POST['char_limit']))?$_POST['char_limit']:''; 
    2541     
    26     if($random_refresh && $_POST['current'] && is_numeric($_POST['current'])) 
     42    if($random_refresh && $_POST['current'] && is_numeric($_POST['current'])) { 
    2743        $exclude = $_POST['current']; 
     44        $current = ''; 
     45    } 
    2846    else { 
    2947        if ($_POST['current'] && is_numeric($_POST['current'])) 
     
    3856 
    3957    if($response = quotescollection_quote($args)) { 
    40         @header("Content-type: text/javascript; charset=utf-8"); 
     58        @header("Content-type: text/html; charset=utf-8"); 
    4159        die( $response );  
    4260    } 
     
    4462        die( $error ); 
    4563} 
    46  
     64add_action ("wp_ajax_quotescollection", "quotescollection_load"); 
     65add_action ("wp_ajax_nopriv_quotescollection", "quotescollection_load"); 
    4766?> 
Note: See TracChangeset for help on using the changeset viewer.