Plugin Directory

Changeset 1285850


Ignore:
Timestamp:
11/13/2015 08:19:18 PM (10 years ago)
Author:
Natallya
Message:

Fix curl

Location:
solidopinion-comments/trunk/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • solidopinion-comments/trunk/lib/common.php

    r1284779 r1285850  
    4949    return 2;
    5050}
    51 
    52 function so_community_widget($args) {
    53     $so_shortname = so_get_shortname();
    54     if (!$so_shortname ) {
    55         return;
    56     }
    57    
    58     extract($args);
    59     echo $before_widget;
    60     echo $before_title;
    61     echo __('Community', 'solidopinion-comments');
    62     echo $after_title;
    63     echo str_replace(array('%%SO_SITENAME%%'), array($so_shortname), get_include_contents(SO_COMMENTS_DIR . '/templates/community_template.php'));;
    64     echo $after_widget;
    65 }
    6651
    6752function register_so_community_widget() {
  • solidopinion-comments/trunk/lib/so_widget.class.php

    r1016940 r1285850  
    22class so_community_widget extends WP_Widget {
    33
    4     // constructor
    5     function __construct() {
    6         parent::WP_Widget(false, $name = __('SolidOpinion Community', 'solidopinion-comments') );
    7     }
     4    // constructor
     5    function __construct() {
     6        parent::WP_Widget(false, $name = __('SolidOpinion Community', 'solidopinion-comments') );
     7    }
    88
    9     // widget form creation
    10     function form($instance) { 
    11     // Check values
    12         echo "<p>You can manage this widget from <a href='".admin_url('options-general.php?page=so_comments')."'>SolidOpinion publisher panel</a></p>";
    13  /*     
    14     $tabs = array('1' => array('name' => 'top_by_points', 'text' => __('People', 'solidopinion-comments')),
    15                   '2' => array('name' => 'last_threads', 'text' => __('Recent', 'solidopinion-comments')),
    16                   '3' => array('name' => 'popular_thread', 'text' => __('Popular', 'solidopinion-comments')));
    17                  
    18                  
    19     if($instance) {
    20       $default_tab = esc_attr($instance['default_tab']);
    21       $items_number = esc_attr($instance['items_number']);
    22       $popular_thread = (isset($instance['popular_thread'])) ? esc_attr($instance['popular_thread']) : '';
    23       $last_threads = (isset($instance['last_threads'])) ? esc_attr($instance['last_threads']) : '';
    24       $top_by_points = (isset($instance['top_by_points'])) ? esc_attr($instance['top_by_points']) : '';
    25      
    26       $tabs_list = array($top_by_points, $last_threads, $popular_thread);
    27       if (!in_array($default_tab, $tabs_list)) {
    28         for ($i=0; $i<3; $i++){
    29           if ($tabs_list[$i]){
    30             $default_tab = $tabs_list[$i];
    31             break;
    32           }
     9    // widget form creation
     10    function form($instance) { 
     11        // Check values
     12        echo "<p>You can manage this widget from <a href='".admin_url('options-general.php?page=so_comments')."'>SolidOpinion publisher panel</a></p>";
     13    }
     14
     15    // widget display
     16    function widget($args, $instance) { 
     17        $so_shortname = so_get_shortname();
     18        if (!$so_shortname ) {
     19            return;
    3320        }
    34       }
    35     } else {
    36       $default_tab = '';
    37       $items_number = '';
    38       $popular_thread = '';
    39       $last_threads = '';
    40       $top_by_points = '';
     21        $lang_id = get_so_language_id();
     22        $url = SO_API_URL.'api/Site/getpublic/?shortname='.$so_shortname;
     23        $curl = curl_init($url);
     24        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     25        curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
     26        curl_setopt($curl, CURLOPT_USERPWD, "dev:eQ9UmN6WsuY");
     27        curl_setopt($curl, CURLOPT_HTTPHEADER, array('Connection: Close'));
     28        $exec = curl_exec($curl);
     29        $response = json_decode($exec,true);
     30        curl_close($curl);
     31
     32        if (!$exec || (!empty($response) && isset($response['total_messages']) && $response['total_messages'] > 0)) {
     33          echo $before_widget;
     34          echo $before_title;
     35          echo __('Community', 'solidopinion-comments');
     36          echo $after_title;
     37          echo str_replace(array('%%SO_SITENAME%%'), array($so_shortname), get_include_contents(SO_COMMENTS_DIR . '/templates/community_template.php'));
     38          echo $after_widget;
     39        }
    4140    }
    42    
    43 ?>
    44    
    45     <p>
    46       <label for="<?php echo $this->get_field_id('default_tab'); ?>"><?php echo __('Default tab', 'solidopinion-comments'); ?>:</label>
    47       <select class="widefat" style="width:100px;" id="<?php echo $this->get_field_id('default_tab'); ?>" name="<?php echo $this->get_field_name('default_tab'); ?>">
    48         <?php foreach ($tabs as $key=>$val) {
    49             //if (isset(${$val['name']}) && ${$val['name']}) { ?>
    50             <option value="<?php echo $val['name']; ?>" <?php if ($default_tab == $val['name']) { ?> selected<?php } ?>><?php echo $val['text']; ?></option>
    51         <?php //}
    52         } ?>
    53       </select>
    54     </p>
    55     <p>
    56       <label for="<?php echo $this->get_field_id('items_number'); ?>"><?php echo __('Number of items', 'solidopinion-comments'); ?>:</label>
    57       <input class="widefat" id="<?php echo $this->get_field_id('items_number'); ?>" name="<?php echo $this->get_field_name('items_number'); ?>" type="text" value="<?php echo $items_number; ?>" style="width:50px;" maxlength="3" />
    58     </p>
    59     <script>
    60       jQuery(document).ready(function(){
    61         jQuery(document).on('keyup', '#<?php echo $this->get_field_id('items_number'); ?>', function(){
    62           var val = jQuery(this).val();
    63           if (val<0) {
    64             jQuery(this).val(Math.abs(val));
    65           }
    66         });
    67       });
    68     </script>
    69    
    70     <p><?php echo __('Show tabs', 'solidopinion-comments'); ?>:</p>
    71     <p>
    72       <?php foreach ($tabs as $key=>$val) { ?>
    73         <input class="widefat so_tabs" style="width:auto" id="<?php echo $this->get_field_id($val['name']); ?>" name="<?php echo $this->get_field_name($val['name']); ?>" type="checkbox" value="<?php echo $val['name']; ?>"<?php if (${$val['name']}) { ?> checked="checked"<?php } ?> />
    74         <label for="<?php echo $this->get_field_id($val['name']); ?>"><?php echo $val['text']; ?></label><br>
    75       <?php } ?>
    76       <br>
    77     </p>
    78 <?php */
    79   }
    80 /*
    81     // widget update
    82     function update($new_instance, $old_instance) {
    83         $instance = $old_instance;
    84    
    85     $instance['items_number'] = strip_tags($new_instance['items_number']);
    86     $instance['popular_thread'] = strip_tags($new_instance['popular_thread']);
    87     $instance['last_threads']  = strip_tags($new_instance['last_threads']);
    88     $instance['top_by_points']  = strip_tags($new_instance['top_by_points']);
    89    
    90     $tabs_list = array($new_instance['top_by_points'], $new_instance['last_threads'], $new_instance['popular_thread']);
    91     if (!in_array($new_instance['default_tab'], $tabs_list)) {
    92       for ($i=0; $i<3; $i++){
    93         if ($tabs_list[$i]){
    94           $instance['default_tab'] = $tabs_list[$i];
    95           break;
    96         }
    97       }
    98     } else {
    99       $instance['default_tab']  = strip_tags($new_instance['default_tab']);
    100     }
    101    
    102    
    103    
    104    
    105     return $instance;
    106     }
    107 */
    108     // widget display
    109     function widget($args, $instance) {
    110     extract($args);   
    111     $so_option = get_option('so_options');
    112     if ( !($so_option && isset($so_option['so_shortname']) && ($so_option['so_shortname']!='')) ) {
    113         return;
    114     }
    115     /*$default_tab = $instance['default_tab'];
    116     $items_number = $instance['items_number'];
    117     $popular_thread = $instance['popular_thread'];
    118     $last_threads = $instance['last_threads'];
    119     $top_by_points = $instance['top_by_points'];
    120     $tabs_list = array($top_by_points, $last_threads, $popular_thread);
    121     if (!in_array($default_tab, $tabs_list)) {
    122       for ($i=0; $i<3; $i++){
    123         if ($tabs_list[$i]){
    124           $default_tab = $tabs_list[$i];
    125           break;
    126         }
    127       }
    128     }
    129     $allow_tabs = ($top_by_points ? $top_by_points : '') . (($top_by_points && $last_threads) ? (',' . $last_threads) : ((!$top_by_points && $last_threads) ? $last_threads : '')) .
    130                   ((($top_by_points || $last_threads) && $popular_thread) ? ',' . $popular_thread : ((!$top_by_points && !$last_threads && $popular_thread) ? $popular_thread : '') );
    131     */
    132         $lang_id = get_so_language_id();
    133     $so_shortname = $so_option['so_shortname'];
    134    
    135     $url = SO_API_URL.'api/Site/getpublic/?shortname='.$so_shortname;
    136     $curl = curl_init($url);
    137     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    138     curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    139     curl_setopt($curl, CURLOPT_USERPWD, "dev:eQ9UmN6WsuY");
    140     curl_setopt($curl, CURLOPT_HTTPHEADER, array('Connection: Close'));
    141     $response = json_decode(curl_exec($curl),true);
    142     curl_close($curl);
    143 
    144     if (/*$items_number && */!empty($response) && isset($response['total_messages']) && $response['total_messages'] > 0) {
    145       echo $before_widget;
    146       echo $before_title;
    147       echo __('Community', 'solidopinion-comments');
    148       echo $after_title;
    149       echo str_replace(array('%%SO_SITENAME%%', /*'%%TAB_ID%%', '%%MAX_VALUE%%', '%%TABS%%', */'%%LANG_ID%%'), array($so_shortname, /*$default_tab, ($items_number<10) ? (($items_number>0) ? $items_number : 1) : 10, $allow_tabs,*/ $lang_id), get_include_contents(SO_COMMENTS_DIR . '/templates/community_template.php'));
    150       echo $after_widget;
    151     }
    152    
    153     }
    15441}
    15542
Note: See TracChangeset for help on using the changeset viewer.