Beispiel #1
0
 function vf_widget_users($args)
 {
     extract($args);
     $options = get_option(VF_OPTIONS_NAME);
     $title = vf_get_value('widget-users-title', $options, '');
     $count = (int) vf_get_value('widget-users-count', $options, '');
     $width = (int) vf_get_value('widget-users-iconwidth', $options, 32);
     if ($count < 5) {
         $count = 5;
     }
     $url = vf_get_value('url', $options, '');
     $link_url = vf_get_link_url($options);
     $resturl = array($url, '?p=user/summary.json');
     // Retrieve the latest discussions from the Vanilla API
     $resturl = vf_combine_paths($resturl, '/');
     $data = json_decode(vf_rest($resturl));
     if (!is_object($data)) {
         return;
     }
     // These lines generate our output. Widgets can be very complex
     // but as you can see here, they can also be very, very simple.
     echo $before_widget . $before_title . $title . $after_title;
     echo '<div class="ForumUsers">';
     $i = 0;
     foreach ($data->UserData as $User) {
         $i++;
         if ($i > $count) {
             break;
         }
         $User->IconWidth = $width;
         echo vf_user_photo($User, $link_url) . ' ';
     }
     echo '</div>';
     echo $after_widget;
 }
Beispiel #2
0
/**
 * Validate that the provided url is a vanilla forum root. Returns properly formatted url if it is, or FALSE.
 */
function vf_validate_url($url)
{
    $html = vf_rest($url);
    $wr_pos = strpos($html, 'WebRoot" value="');
    if ($wr_pos > 0) {
        $webroot = substr($html, $wr_pos + 16);
        $webroot = substr($webroot, 0, strpos($webroot, '"'));
        return $webroot;
    } else {
        return FALSE;
    }
}
Beispiel #3
0
/**
 * Vanilla Comments administration page.
 */
function vf_comment_admin_page()
{
    // Check that the user has the required capability
    if (!current_user_can('manage_options')) {
        wp_die(__('You do not have sufficient permissions to access this page.'));
    }
    $options = get_option(VF_OPTIONS_NAME);
    $embed_comments = vf_get_value('embed-comments', $options);
    $resturl = vf_get_value('url', $options, '');
    $resturl = vf_combine_paths(array($resturl, '?p=categories/all.json'), '/');
    $categoryid = vf_get_value('embed-categoryid', $options, '0');
    $matchCategories = vf_get_value('embed-matchcategories', $options, '0');
    $category_data = json_decode(vf_rest($resturl));
    $select_options = vf_get_select_option('No Category', '0', $categoryid);
    if (is_object($category_data)) {
        foreach ($category_data->Categories as $Category) {
            $select_options .= vf_get_select_option($Category->Name, $Category->CategoryID, $categoryid);
        }
    }
    ?>
<div class="wrap">
   <div id="icon-options-general" class="icon32"><br /></div>
   <h2><?php 
    _e('Vanilla Comment Integration');
    ?>
</h2>
	<?php 
    vf_open_form('embed-comments-form');
    ?>
	 <p>
		<label>
		  <input type="checkbox" name="<?php 
    echo vf_get_option_name('embed-comments');
    ?>
" value="1"<?php 
    echo $embed_comments == '1' ? ' checked="checked"' : '';
    ?>
 />
		  Replace your blog's native commenting system with Vanilla comments.
		</label>
	 </p>
	 <p>
		<label>
		  <select name="<?php 
    echo vf_get_option_name('embed-categoryid');
    ?>
"><?php 
    echo $select_options;
    ?>
</select>
		  <?php 
    echo __('Place embedded comments into the selected category.');
    ?>
		</label>
	 </p>
    <p>
       <label>
          <input type="checkbox" name="<?php 
    echo vf_get_option_name('embed-matchcategories');
    ?>
" value="1"<?php 
    echo $matchCategories == '1' ? ' checked="checked"' : '';
    ?>
 />
          <?php 
    echo __('Try and match your Wordpress category.');
    ?>
       </label>
    </p>
    <p class="submit"><input type="submit" name="save" value="<?php 
    _e('Save Changes');
    ?>
" /></p>
  </form>
</div>
<?php 
}
Beispiel #4
0
/**
 * Validate that the provided url is a vanilla forum root. Returns properly formatted url if it is, or FALSE.
 */
function vf_validate_url($url)
{
    $html = vf_rest($url);
    $formats = array('"WebRoot":"', '\'WebRoot\' : "', 'WebRoot" value="');
    foreach ($formats as $format) {
        if ($chars = strpos($html, $format)) {
            $offset = $chars + strlen(stripslashes($format));
            return vf_parse_webroot($html, $offset);
        }
    }
    return FALSE;
}
Beispiel #5
0
/**
 * Validates options being saved for Vanilla Forums. WordPress is a bit hinky
 * here, so we use hidden inputs to identify the forum being saved and validate
 * the inputs accordingly. This is a catch-all validation for all forms.
 */
function vf_validate_options($options)
{
    $formname = vf_get_value('form-name', $options);
    $alloptions = get_option(VF_OPTIONS_NAME);
    if (!is_array($alloptions)) {
        $alloptions = array();
    }
    switch ($formname) {
        case 'url-form':
            $url = vf_get_value('url', $options, '');
            $options = $alloptions;
            // Make a rest request to Vanilla's API to validate that the forum is at the given location.
            $resturl = vf_combine_paths(array($url, '?p=discussions.json'), '/');
            $data = json_decode(vf_rest($resturl));
            if (!is_object($data)) {
                $options['url'] = '';
                add_settings_error('url', 'url', 'Forum url could not be validated. Are you sure you entered the correct web address of your forum?');
            } else {
                $options['url'] = $url;
                if (vf_get_value('embed-code', $options, '') == '') {
                    // Set the embed_code if it is not already defined.
                    $embedurl = vf_combine_paths(array($url, 'plugins/embedvanilla/remote.js'), '/');
                    $options['embed-code'] = '<script type="text/javascript" src="' . $embedurl . '"></script>';
                }
                vf_configure_embed_container();
            }
            break;
        case 'embed-form':
            $embed_code = vf_get_value('embed-code', $options, '');
            $options = $alloptions;
            $url = vf_get_value('url', $options, '');
            if ($embed_code == '') {
                // Set the embed_code if it is not already defined.
                $embedurl = vf_combine_paths(array($url, 'plugins/embedvanilla/remote.js'), '/');
                $options['embed-code'] = '<script type="text/javascript" src="' . $embedurl . '"></script>';
            } else {
                $options['embed-code'] = $embed_code;
            }
            break;
        default:
            $options = array_merge($alloptions, $options);
            break;
    }
    return $options;
}