Changeset 1872783
- Timestamp:
- 05/11/2018 03:33:18 PM (8 years ago)
- Location:
- vanilla-forums/trunk
- Files:
-
- 5 edited
-
embed.php (modified) (10 diffs)
-
functions.php (modified) (3 diffs)
-
plugin.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
-
widgets.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
vanilla-forums/trunk/embed.php
r1426867 r1872783 8 8 */ 9 9 function vf_embed_admin_page() { 10 // Check that the user has the required capability 10 // Check that the user has the required capability 11 11 if (!current_user_can('manage_options')) 12 wp_die(__('You do not have sufficient permissions to access this page.'));13 12 wp_die(__('You do not have sufficient permissions to access this page.')); 13 14 14 $post_id = vf_configure_embed_container(); 15 15 $options = get_option(VF_OPTIONS_NAME); … … 22 22 jQuery(document).ready(function($) { 23 23 $('.reset-embed-code').click(function() { 24 $('#EmbedCode').val('<script type="text/javascript" src="<?php echo vf_combine_paths(array($vanilla_url, 'js/embed.js'), '/'); ?>"></scrip'+'t>');25 return false;24 $('#EmbedCode').val('<script type="text/javascript" src="<?php echo vf_combine_paths(array($vanilla_url, 'js/embed.js'), '/'); ?>"></scrip'+'t>'); 25 return false; 26 26 }); 27 27 }); … … 31 31 <h2><?php _e('Forum Integration'); ?></h2> 32 32 <p>Use this page to embed your entire Vanilla Forum into a WordPress page.</p> 33 <?php vf_open_form('embed-form'); ?>34 <strong>Forum Page in WordPress</strong>35 <em>Define where to access your Vanilla Forum within WordPress.</em>36 <div id="edit-slug-box"><?php echo get_sample_permalink_html($post_id); ?></div>37 <?php wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false ); ?>38 <em>You can further customize the page that contains your forum <a href="./post.php?post=<?php echo $post_id; ?>&action=edit">here</a>.</em>39 40 <strong>Widget Integration</strong>41 <p>42 <label>43 <input type="checkbox" name="<?php echo vf_get_option_name('embed-widgets'); ?>" value="1"<?php echo $embed_widgets == '1' ? ' checked="checked"' : ''; ?> />44 Force links in your <a href="./admin.php?page=vf-widgets-handle">widgets</a> to go to your forum page in WordPress (defined above) instead of going to the actual forum url (<?php echo $vanilla_url; ?>).45 </label>46 </p>47 48 <strong>Forum <Embed> Code</strong>49 <textarea id="EmbedCode" name="<?php echo vf_get_option_name('embed-code'); ?>"><?php echo $embed_code; ?></textarea>50 <em>You can make changes to your forum embed code here (optional). <a class="reset-embed-code" href="#">Reset embed code</a>.</em>33 <?php vf_open_form('embed-form'); ?> 34 <strong>Forum Page in WordPress</strong> 35 <em>Define where to access your Vanilla Forum within WordPress.</em> 36 <div id="edit-slug-box"><?php echo get_sample_permalink_html($post_id); ?></div> 37 <?php wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false ); ?> 38 <em>You can further customize the page that contains your forum <a href="./post.php?post=<?php echo $post_id; ?>&action=edit">here</a>.</em> 39 40 <strong>Widget Integration</strong> 41 <p> 42 <label> 43 <input type="checkbox" name="<?php echo vf_get_option_name('embed-widgets'); ?>" value="1"<?php echo $embed_widgets == '1' ? ' checked="checked"' : ''; ?> /> 44 Force links in your <a href="./admin.php?page=vf-widgets-handle">widgets</a> to go to your forum page in WordPress (defined above) instead of going to the actual forum url (<?php echo $vanilla_url; ?>). 45 </label> 46 </p> 47 48 <strong>Forum <Embed> Code</strong> 49 <textarea id="EmbedCode" name="<?php echo vf_get_option_name('embed-code'); ?>"><?php echo $embed_code; ?></textarea> 50 <em>You can make changes to your forum embed code here (optional). <a class="reset-embed-code" href="#">Reset embed code</a>.</em> 51 51 <p class="submit"><input type="submit" name="save" value="<?php _e('Save Changes'); ?>" /></p> 52 </div>52 </div> 53 53 </form> 54 54 </div> … … 60 60 */ 61 61 function vf_configure_embed_container() { 62 $post_id = vf_get_option('embed-post-id');63 $post = get_post($post_id);64 // PostID not set or not related to an existing page? Generate the page now and apply template.65 if (!is_numeric($post_id) || $post_id <= 0 || !$post) {66 $post_id = wp_insert_post(array('post_name' => 'discussions', 'post_title' => 'Discussions', 'post_type' => 'page', 'post_status' => 'publish', 'comment_status' => 'closed'));67 vf_update_option('embed-post-id', $post_id);68 }69 // Copy the vanilla template to the current theme70 $template_to_use = 'embed_template.php';71 try {62 $post_id = vf_get_option('embed-post-id'); 63 $post = get_post($post_id); 64 // PostID not set or not related to an existing page? Generate the page now and apply template. 65 if (!is_numeric($post_id) || $post_id <= 0 || !$post) { 66 $post_id = wp_insert_post(array('post_name' => 'discussions', 'post_title' => 'Discussions', 'post_type' => 'page', 'post_status' => 'publish', 'comment_status' => 'closed')); 67 vf_update_option('embed-post-id', $post_id); 68 } 69 // Copy the vanilla template to the current theme 70 $template_to_use = 'embed_template.php'; 71 try { 72 72 $filepath = __DIR__.'/templates/'.$template_to_use; 73 if (file_exists($filepath)) 73 if (file_exists($filepath)) 74 74 copy($filepath, get_template_directory().'/'.$template_to_use); 75 else76 $template_to_use = false;77 } catch (Exception $e) {78 $template_to_use = false;79 }80 if ($template_to_use)81 update_post_meta($post_id, '_wp_page_template', $template_to_use);82 83 return $post_id;75 else 76 $template_to_use = false; 77 } catch (Exception $e) { 78 $template_to_use = false; 79 } 80 if ($template_to_use) 81 update_post_meta($post_id, '_wp_page_template', $template_to_use); 82 83 return $post_id; 84 84 } 85 85 … … 91 91 */ 92 92 function vf_embed_content($content) { 93 global $post;94 if ($post->ID == vf_get_option('embed-post-id')) {93 global $post; 94 if ($post->ID == vf_get_option('embed-post-id')) { 95 95 $content = ''; 96 96 97 97 if ($sso = vf_get_sso_string()) { 98 98 // Add the sso string for automatic signin. 99 99 $content = "<script type='text/javascript'>var vanilla_sso = '$sso';</script>"; 100 100 } 101 102 $content .= stripslashes(vf_get_option('embed-code'));103 101 102 $content .= stripslashes(vf_get_option('embed-code')); 103 104 104 vf_forum_embedded(true); 105 105 } 106 return $content;106 return $content; 107 107 } 108 108 … … 111 111 */ 112 112 function vf_embed_edit_slug() { 113 $post_id = vf_configure_embed_container();114 check_ajax_referer('samplepermalink', 'samplepermalinknonce');115 $slug = isset($_POST['new_slug'])? $_POST['new_slug'] : null;116 wp_update_post(array('ID' => $post_id, 'post_name' => $slug));117 die(get_sample_permalink_html($post_id, 'Discussion Forum', $slug));113 $post_id = vf_configure_embed_container(); 114 check_ajax_referer('samplepermalink', 'samplepermalinknonce'); 115 $slug = isset($_POST['new_slug'])? $_POST['new_slug'] : null; 116 wp_update_post(array('ID' => $post_id, 'post_name' => $slug)); 117 die(get_sample_permalink_html($post_id, 'Discussion Forum', $slug)); 118 118 } 119 119 … … 125 125 */ 126 126 function vf_comment_admin_page() { 127 // Check that the user has the required capability 128 if (!current_user_can('manage_options')) 129 wp_die(__('You do not have sufficient permissions to access this page.')); 130 131 $options = get_option(VF_OPTIONS_NAME); 132 $embed_comments = vf_get_value('embed-comments', $options); 133 134 $resturl = vf_get_value('url', $options, ''); 135 $resturl = vf_combine_paths(array($resturl, '/categories/all.json'), '/'); 136 $categoryid = vf_get_value('embed-categoryid', $options, '0'); 137 $matchCategories = vf_get_value('embed-matchcategories', $options, '0'); 138 $category_data = json_decode(vf_rest($resturl)); 139 $select_options = vf_get_select_option('No Category', '0', $categoryid); 140 if (is_object($category_data)) { 141 foreach ($category_data->Categories as $Category) { 142 $select_options .= vf_get_select_option($Category->Name, $Category->CategoryID, $categoryid); 143 } 144 } 145 127 // Check that the user has the required capability 128 if (!current_user_can('manage_options')) { 129 wp_die(__('You do not have sufficient permissions to access this page.')); 130 } 131 132 $options = get_option(VF_OPTIONS_NAME); 133 $embed_comments = vf_get_value('embed-comments', $options); 134 135 $resturl = vf_get_value('url', $options, ''); 136 $resturl = vf_combine_paths(array($resturl, '/categories/all.json'), '/'); 137 $categoryid = vf_get_value('embed-categoryid', $options, '0'); 138 $matchCategories = vf_get_value('embed-matchcategories', $options, '0'); 139 $category_data = json_decode(vf_rest($resturl), true); 140 $select_options = vf_get_select_option('No Category', '0', $categoryid); 141 if (is_array($category_data)) { 142 if (isset($category_data['Categories'])) { 143 $categories = $category_data['Categories']; 144 } else { 145 $categories = vf_flatten_category_tree($category_data['CategoryTree']); 146 } 147 foreach ($categories as $Category) { 148 $select_options .= vf_get_select_option($Category['Name'], $Category['CategoryID'], $categoryid); 149 } 150 } 151 146 152 ?> 147 153 <div class="wrap"> 148 154 <div id="icon-options-general" class="icon32"><br /></div> 149 155 <h2><?php _e('Vanilla Comment Integration'); ?></h2> 150 <?php vf_open_form('embed-comments-form'); ?>151 <p>152 <label>153 <input type="checkbox" name="<?php echo vf_get_option_name('embed-comments'); ?>" value="1"<?php echo $embed_comments == '1' ? ' checked="checked"' : ''; ?> />154 Replace your blog's native commenting system with Vanilla comments.155 </label>156 </p>157 <p>158 <label>159 <select name="<?php echo vf_get_option_name('embed-categoryid'); ?>"><?php echo $select_options; ?></select>160 <?php echo __('Place embedded comments into the selected category.'); ?>161 </label>162 </p>156 <?php vf_open_form('embed-comments-form'); ?> 157 <p> 158 <label> 159 <input type="checkbox" name="<?php echo vf_get_option_name('embed-comments'); ?>" value="1"<?php echo $embed_comments == '1' ? ' checked="checked"' : ''; ?> /> 160 Replace your blog's native commenting system with Vanilla comments. 161 </label> 162 </p> 163 <p> 164 <label> 165 <select name="<?php echo vf_get_option_name('embed-categoryid'); ?>"><?php echo $select_options; ?></select> 166 <?php echo __('Place embedded comments into the selected category.'); ?> 167 </label> 168 </p> 163 169 <p> 164 170 <label> … … 175 181 // Include the javascript for comment counts on the main blog index 176 182 function vf_comment_count_js() { 177 if (!is_admin()) {178 $options = get_option(VF_OPTIONS_NAME);179 $vanilla_url = vf_get_value('url', $options, '');180 ?>181 <script type="text/javascript">182 var vanilla_forum_url = '<?php echo $vanilla_url; ?>';183 (function() {184 var vanilla_count = document.createElement('script');185 vanilla_count.type = 'text/javascript';186 vanilla_count.src = vanilla_forum_url + '/js/count.js';187 (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(vanilla_count);188 })();189 </script>190 <?php191 }183 if (!is_admin()) { 184 $options = get_option(VF_OPTIONS_NAME); 185 $vanilla_url = vf_get_value('url', $options, ''); 186 ?> 187 <script type="text/javascript"> 188 var vanilla_forum_url = '<?php echo $vanilla_url; ?>'; 189 (function() { 190 var vanilla_count = document.createElement('script'); 191 vanilla_count.type = 'text/javascript'; 192 vanilla_count.src = vanilla_forum_url + '/js/count.js'; 193 (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(vanilla_count); 194 })(); 195 </script> 196 <?php 197 } 192 198 } 193 199 … … 197 203 global $EMBED; 198 204 global $post; 199 global $comments; 200 201 if (!(is_singular() && (have_comments() || $post->comment_status == 'open')))202 return;203 205 206 if (!(is_singular() && (have_comments() || $post->comment_status == 'open'))) { 207 return; 208 } 209 204 210 if (vf_forum_embedded()) { 205 $EMBED = true; 206 return dirname(__FILE__).'/empty.php'; 207 } 208 209 $options = get_option(VF_OPTIONS_NAME); 210 $embed_comments = vf_get_value('embed-comments', $options); 211 if (!$embed_comments) 212 return $value; 211 $EMBED = true; 212 return dirname(__FILE__).'/empty.php'; 213 } 214 215 $options = get_option(VF_OPTIONS_NAME); 216 $embed_comments = vf_get_value('embed-comments', $options); 217 if (!$embed_comments) { 218 return $value; 219 } 213 220 214 221 $EMBED = true; … … 222 229 function vf_comments_open($open, $post_id = null) { 223 230 global $EMBED; 224 if ($EMBED) return false; 231 if ($EMBED) { 232 return false; 233 } 225 234 return $open; 226 235 } 227 236 228 237 function vf_comments_number($text) { 229 global $post;230 return '<span vanilla-identifier="'.$post->ID.'">'.$text.'</span>';231 } 238 global $post; 239 return '<span vanilla-identifier="'.$post->ID.'">'.$text.'</span>'; 240 } -
vanilla-forums/trunk/functions.php
r1426867 r1872783 180 180 $html = vf_rest($url); 181 181 $formats = array( 182 '"WebRoot": "', // 2.2 // BUGFIX 182 '"WebRoot": "', // 2.2 // BUGFIX 183 183 '"WebRoot":"', // 2.2 184 184 '\'WebRoot\' : "', // 2.0.18.13+ and 2.1.1+ … … 352 352 $user['wp_nonce'] = wp_create_nonce('log-out'); 353 353 354 // Do some fudgery to grab the photo url. 355 try { 356 $avatar = new SimpleXMLElement(get_avatar($current_user->ID)); 357 if (isset($avatar['src'])) 358 $user['photourl'] = (string)$avatar['src']; 359 } catch (Exception $Ex) { 354 $avatarUrl = get_avatar_url($current_user->ID); 355 if ($avatarUrl) { 356 $user['photourl'] = $avatarUrl; 360 357 } 361 358 … … 469 466 return $allowed_hosts; 470 467 } 468 469 function vf_flatten_category_tree($categoryTree) { 470 $recursiveFlattenner = function(array $category, array &$result) use (&$recursiveFlattenner) { 471 $result[] = $category; 472 if (empty($category['Children'])) { 473 return; 474 } 475 foreach ($category['Children'] as $child) { 476 $recursiveFlattenner($child, $result); 477 } 478 }; 479 480 $result = []; 481 482 foreach ($categoryTree as $category) { 483 $recursiveFlattenner($category, $result); 484 } 485 return $result; 486 } -
vanilla-forums/trunk/plugin.php
r1426867 r1872783 4 4 Plugin URI: http://vanillaforums.org/addons/ 5 5 Description: Integrates Vanilla Forums with WordPress: embedded blog comments, embedded forum, single sign on, and WordPress widgets. 6 Version: 1.1.1 76 Version: 1.1.18 7 7 Author: Todd Burry 8 8 Author URI: http://www.vanillaforums.org/ … … 66 66 - Fixed webroot parsing. 67 67 - Fixed Vanilla URL endpoints to not use 'p' parameter. 68 1.1.18 69 - Update handling of /categories/all.json 68 70 69 71 Copyright 2010-2016 Vanilla Forums Inc -
vanilla-forums/trunk/readme.txt
r1426867 r1872783 4 4 Requires at least: 3 5 5 Tested up to: 4.2.2 6 Stable tag: 1.1.1 76 Stable tag: 1.1.18 7 7 8 8 == Description == … … 72 72 We don’t have all the features that stand alone commenting systems have but we are working on many that we see as important such as pre-moderation, integration into blogging software dashboards and automated imports of legacy comments. 73 73 74 = Q. Can I seeuse this with Vanilla Forums self-hosted? =74 = Q. Can I use this with Vanilla Forums self-hosted? = 75 75 Yes, you can use this with your self-hosted Vanilla Forums install. 76 76 -
vanilla-forums/trunk/widgets.php
r1426867 r1872783 5 5 */ 6 6 function vf_widgets_admin_page() { 7 ?>7 ?> 8 8 <div class="wrap"> 9 <div id="icon-options-general" class="icon32"><br /></div> 10 <h2><?php _e('Forum Widgets'); ?></h2> 11 <p>Your Vanilla Forum provides some great widgets you can use in your WordPress blog:</p> 12 <ul> 13 <li><strong>Vanilla Discussions Widget</strong> allows you to display recent discussions in your Vanilla Forum in your WordPress site. You define how many discussions to show, and you can even filter to specific discussion categories.</li> 14 <li><strong>Vanilla Activity Widget</strong> allows you to display recent activity in your forum (user registrations, status updates, etc). You define how many activities to show, and you can even filter to activities from users in specific roles (administrator activity, for example).</li> 15 <li><strong>Vanilla Recently Active Users Widget</strong> allows you to display a list of users who have been recently active on your forum. You define how many users to show.</li> 16 </ul> 17 <p>All of these widgets are available on your <a href="./widgets.php">WordPress Widget Management page</a>.</p> 9 <div id="icon-options-general" class="icon32"><br /></div> 10 <h2><?php _e('Forum Widgets'); ?></h2> 11 <p>Your Vanilla Forum provides some great widgets you can use in your WordPress blog:</p> 12 <ul> 13 <li><strong>Vanilla Discussions Widget</strong> allows you to display recent discussions in your Vanilla Forum in your WordPress site. You define how many discussions to show, and you can even filter to specific discussion categories.</li> 14 <li><strong>Vanilla Activity Widget</strong> allows you to display recent activity in your forum (user registrations, status updates, etc). You define how many activities to show, and you can even filter to activities from users in specific roles (administrator activity, for example).</li> 15 <li><strong>Vanilla Recently Active Users Widget</strong> allows you to display a list of users who have been recently active on your forum. You define how many users to show.</li> 16 </ul> 17 <p>All of these widgets are available on your <a href="./widgets.php">WordPress Widget Management page</a>.</p> 18 <p><strong>Note that the widgets will work only with a public Vanilla installation.</strong></p> 18 19 </div> 19 <?php20 <?php 20 21 } 21 22 … … 25 26 function vf_widgets_init() { 26 27 27 // Check for the required plugin functions. This will prevent fatal28 // errors occurring when you deactivate the dynamic-sidebar plugin.29 if (!function_exists('wp_register_sidebar_widget') )30 return;28 // Check for the required plugin functions. This will prevent fatal 29 // errors occurring when you deactivate the dynamic-sidebar plugin. 30 if (!function_exists('wp_register_sidebar_widget') ) 31 return; 31 32 32 33 // Recent Discussions Widget 33 function vf_widget_discussions($args) {34 35 // $args is an array of strings that help widgets to conform to36 // the active theme: before_widget, before_title, after_widget,37 // and after_title are the array keys. Default tags: li and h2.38 extract($args);39 40 // Each widget can store its own options. We keep strings here.41 $options = get_option(VF_OPTIONS_NAME);42 $title = vf_get_value('widget-discussions-title', $options, '');43 $categoryid = (int)vf_get_value('widget-discussions-categoryid', $options, '');44 $count = (int)vf_get_value('widget-discussions-count', $options, '');45 if ($count < 5)46 $count = 5;47 48 $url = vf_get_value('url', $options, '');49 $link_url = vf_get_link_url($options);50 $resturl = array($url, '/discussions.json');51 if ($categoryid > 0)52 $resturl = array($url, '/categories/'.$categoryid.'.json');53 54 // $DataName = $categoryid > 0 ? 'DiscussionData' : 'Discussions';55 56 // Retrieve the latest discussions from the Vanilla API57 $resturl = vf_combine_paths($resturl, '/');58 $data = json_decode(vf_rest($resturl));59 if (!is_object($data))60 return;61 34 function vf_widget_discussions($args) { 35 36 // $args is an array of strings that help widgets to conform to 37 // the active theme: before_widget, before_title, after_widget, 38 // and after_title are the array keys. Default tags: li and h2. 39 extract($args); 40 41 // Each widget can store its own options. We keep strings here. 42 $options = get_option(VF_OPTIONS_NAME); 43 $title = vf_get_value('widget-discussions-title', $options, ''); 44 $categoryid = (int)vf_get_value('widget-discussions-categoryid', $options, ''); 45 $count = (int)vf_get_value('widget-discussions-count', $options, ''); 46 if ($count < 5) 47 $count = 5; 48 49 $url = vf_get_value('url', $options, ''); 50 $link_url = vf_get_link_url($options); 51 $resturl = array($url, '/discussions.json'); 52 if ($categoryid > 0) 53 $resturl = array($url, '/categories/'.$categoryid.'.json'); 54 55 // $DataName = $categoryid > 0 ? 'DiscussionData' : 'Discussions'; 56 57 // Retrieve the latest discussions from the Vanilla API 58 $resturl = vf_combine_paths($resturl, '/'); 59 $data = json_decode(vf_rest($resturl)); 60 if (!is_object($data)) 61 return; 62 62 63 if (isset($data->Discussions)) 63 64 $Discussions = $data->Discussions; … … 66 67 else 67 68 $Discussions = array(); 68 69 69 70 if (empty($Discussions)) 70 71 return; 71 72 72 // These lines generate our output. Widgets can be very complex73 // but as you can see here, they can also be very, very simple.74 echo $before_widget . $before_title . $title . $after_title;75 echo '<ul>';76 $i = 0;77 foreach ($Discussions as $Discussion) {73 // These lines generate our output. Widgets can be very complex 74 // but as you can see here, they can also be very, very simple. 75 echo $before_widget . $before_title . $title . $after_title; 76 echo '<ul>'; 77 $i = 0; 78 foreach ($Discussions as $Discussion) { 78 79 // var_dump($Discussion); 79 $i++; 80 if ($i > $count) 81 break; 82 83 echo '<li><a href="'.vf_combine_paths(array($link_url, 'discussion/'.$Discussion->DiscussionID.'/'.vf_format_url($Discussion->Name)), '/').'">'.$Discussion->Name.'</a></li>'; 84 } 85 echo '</ul>'; 86 echo $after_widget; 87 } 88 89 // This is the function that outputs the form to let the users edit 90 // the widget's title. It's an optional feature that users cry for. 91 function vf_widget_discussions_control() { 92 // Get our options and see if we're handling a form submission. 93 $options = get_option(VF_OPTIONS_NAME); 94 $title = vf_get_value('widget-discussions-title', $options, 'Recent Discussions'); 95 $categoryid = (int)vf_get_value('widget-discussions-categoryid', $options); 96 $count = (int)vf_get_value('widget-discussions-count', $options, 10); 97 if ($_POST['widget-discussions-submit']) { 98 // Remember to sanitize and format use input appropriately. 99 $title = strip_tags(stripslashes($_POST['widget-discussions-title'])); 100 $categoryid = (int)vf_get_value('widget-discussions-categoryid', $_POST); 101 $count = (int)vf_get_value('widget-discussions-count', $_POST); 102 $options['widget-discussions-title'] = $title; 103 $options['widget-discussions-categoryid'] = $categoryid; 104 $options['widget-discussions-count'] = $count; 105 update_option(VF_OPTIONS_NAME, $options); 106 } 107 108 // Be sure you format your options to be valid HTML attributes. 109 $title = htmlspecialchars($title, ENT_QUOTES); 110 111 // Retrieve & build the category dropdown 112 $resturl = vf_get_value('url', $options, ''); 113 $resturl = vf_combine_paths(array($resturl, '/categories/all.json'), '/'); 114 $category_data = json_decode(vf_rest($resturl)); 115 $select_options = vf_get_select_option('All Categories', '0', $categoryid); 116 if (is_object($category_data)) { 117 foreach ($category_data->Categories as $Category) { 118 $select_options .= vf_get_select_option($Category->Name, $Category->CategoryID, $categoryid); 119 } 120 } 121 122 // Here is our little form segment. Notice that we don't need a 123 // complete form. This will be embedded into the existing form. 124 echo '<p><label for="widget-discussions-title">' . __('Title:') . ' <input style="width: 100%;" id="widget-discussions-title" name="widget-discussions-title" type="text" value="'.$title.'" /></label></p>'; 125 echo '<p><label for="widget-discussions-categoryid">' . __('Filter to Category:') . ' <select id="widget-discussions-categoryid" name="widget-discussions-categoryid">'.$select_options.'</select></label></p>'; 126 echo '<p><label for="widget-discussions-count">' . __('Number of Discussions to show:') . ' <input style="width: 40px;" id="widget-discussions-count" name="widget-discussions-count" type="text" value="'.$count.'" /></label></p>'; 127 echo '<input type="hidden" id="widget-discussions-submit" name="widget-discussions-submit" value="1" />'; 128 } 129 130 // This registers our widget so it appears with the other available 131 // widgets and can be dragged and dropped into any active sidebars. 132 wp_register_sidebar_widget('vf-widget-discussions', 'Vanilla Discussions', 'vf_widget_discussions', array('description' => 'Recent discussions in your Vanilla Forum.')); 133 134 // This registers our optional widget control form. Because of this 135 // our widget will have a button that reveals a 300x100 pixel form. 136 wp_register_widget_control('vf-widget-discussions', 'Vanilla Discussions', 'vf_widget_discussions_control'); 80 $i++; 81 if ($i > $count) 82 break; 83 84 echo '<li><a href="'.vf_combine_paths(array($link_url, 'discussion/'.$Discussion->DiscussionID.'/'.vf_format_url($Discussion->Name)), '/').'">'.$Discussion->Name.'</a></li>'; 85 } 86 echo '</ul>'; 87 echo $after_widget; 88 } 89 90 // This is the function that outputs the form to let the users edit 91 // the widget's title. It's an optional feature that users cry for. 92 function vf_widget_discussions_control() { 93 // Get our options and see if we're handling a form submission. 94 $options = get_option(VF_OPTIONS_NAME); 95 $title = vf_get_value('widget-discussions-title', $options, 'Recent Discussions'); 96 $categoryid = (int)vf_get_value('widget-discussions-categoryid', $options); 97 $count = (int)vf_get_value('widget-discussions-count', $options, 10); 98 if ($_POST['widget-discussions-submit']) { 99 // Remember to sanitize and format use input appropriately. 100 $title = strip_tags(stripslashes($_POST['widget-discussions-title'])); 101 $categoryid = (int)vf_get_value('widget-discussions-categoryid', $_POST); 102 $count = (int)vf_get_value('widget-discussions-count', $_POST); 103 $options['widget-discussions-title'] = $title; 104 $options['widget-discussions-categoryid'] = $categoryid; 105 $options['widget-discussions-count'] = $count; 106 update_option(VF_OPTIONS_NAME, $options); 107 } 108 109 // Be sure you format your options to be valid HTML attributes. 110 $title = htmlspecialchars($title, ENT_QUOTES); 111 112 // Retrieve & build the category dropdown 113 $resturl = vf_get_value('url', $options, ''); 114 $resturl = vf_combine_paths(array($resturl, '/categories/all.json'), '/'); 115 $category_data = json_decode(vf_rest($resturl), true); 116 $select_options = vf_get_select_option('All Categories', '0', $categoryid); 117 if (is_array($category_data)) { 118 if (isset($category_data['Categories'])) { 119 $categories = $category_data['Categories']; 120 } else { 121 $categories = vf_flatten_category_tree($category_data['CategoryTree']); 122 } 123 foreach ($categories as $Category) { 124 $select_options .= vf_get_select_option($Category['Name'], $Category['CategoryID'], $categoryid); 125 } 126 } 127 128 // Here is our little form segment. Notice that we don't need a 129 // complete form. This will be embedded into the existing form. 130 echo '<p><label for="widget-discussions-title">' . __('Title:') . ' <input style="width: 100%;" id="widget-discussions-title" name="widget-discussions-title" type="text" value="'.$title.'" /></label></p>'; 131 echo '<p><label for="widget-discussions-categoryid">' . __('Filter to Category:') . ' <select id="widget-discussions-categoryid" name="widget-discussions-categoryid">'.$select_options.'</select></label></p>'; 132 echo '<p><label for="widget-discussions-count">' . __('Number of Discussions to show:') . ' <input style="width: 40px;" id="widget-discussions-count" name="widget-discussions-count" type="text" value="'.$count.'" /></label></p>'; 133 echo '<input type="hidden" id="widget-discussions-submit" name="widget-discussions-submit" value="1" />'; 134 } 135 136 // This registers our widget so it appears with the other available 137 // widgets and can be dragged and dropped into any active sidebars. 138 wp_register_sidebar_widget('vf-widget-discussions', 'Vanilla Discussions', 'vf_widget_discussions', array('description' => 'Recent discussions in your Vanilla Forum.')); 139 140 // This registers our optional widget control form. Because of this 141 // our widget will have a button that reveals a 300x100 pixel form. 142 wp_register_widget_control('vf-widget-discussions', 'Vanilla Discussions', 'vf_widget_discussions_control'); 137 143 138 144 139 145 // Recent Activity Widget 140 function vf_widget_activities($args) {141 extract($args);142 143 $options = get_option(VF_OPTIONS_NAME);144 $title = vf_get_value('widget-activities-title', $options, '');145 // $roleid = (int)vf_get_value('widget-activities-roleid', $options, '');146 $count = (int)vf_get_value('widget-activities-count', $options, '');147 if ($count < 5)148 $count = 5;149 150 $url = vf_get_value('url', $options, '');151 $link_url = vf_get_link_url($options);152 $resturl = array($url, '/activity.json');153 // if ($roleid > 0)154 //$resturl = array($url, 'activities/'.$roleid.'.json');155 156 // Retrieve the latest discussions from the Vanilla API157 $resturl = vf_combine_paths($resturl, '/');158 $data = json_decode(vf_rest($resturl));159 if (!is_object($data))160 return;146 function vf_widget_activities($args) { 147 extract($args); 148 149 $options = get_option(VF_OPTIONS_NAME); 150 $title = vf_get_value('widget-activities-title', $options, ''); 151 // $roleid = (int)vf_get_value('widget-activities-roleid', $options, ''); 152 $count = (int)vf_get_value('widget-activities-count', $options, ''); 153 if ($count < 5) 154 $count = 5; 155 156 $url = vf_get_value('url', $options, ''); 157 $link_url = vf_get_link_url($options); 158 $resturl = array($url, '/activity.json'); 159 // if ($roleid > 0) 160 // $resturl = array($url, 'activities/'.$roleid.'.json'); 161 162 // Retrieve the latest discussions from the Vanilla API 163 $resturl = vf_combine_paths($resturl, '/'); 164 $data = json_decode(vf_rest($resturl)); 165 if (!is_object($data)) 166 return; 161 167 162 168 if (isset($data->Activities)) … … 166 172 else 167 173 $Activities = array(); 168 174 169 175 if (empty($Activities)) 170 176 return; 171 177 172 // These lines generate our output. Widgets can be very complex173 // but as you can see here, they can also be very, very simple.174 echo $before_widget . $before_title . $title . $after_title;175 echo '<ul>';176 $i = 0;177 foreach ($Activities as $Activity) {178 $i++;179 if ($i > $count)180 break;181 182 echo '<li>'.vf_format_activity($Activity, $link_url).'</li>';183 }184 echo '</ul>';185 echo $after_widget;186 }187 188 function vf_widget_activities_control() {189 // Get our options and see if we're handling a form submission.190 $options = get_option(VF_OPTIONS_NAME);191 $title = vf_get_value('widget-activities-title', $options, 'Recent Forum Activity');192 // $roleid = (int)vf_get_value('widget-activities-roleid', $options);193 $count = (int)vf_get_value('widget-activities-count', $options, 10);194 if ($_POST['widget-activities-submit']) {195 // Remember to sanitize and format use input appropriately.196 $title = strip_tags(stripslashes($_POST['widget-activities-title']));197 // $roleid = (int)vf_get_value('widget-activities-roleid', $_POST);198 $count = (int)vf_get_value('widget-activities-count', $_POST);199 $options['widget-activities-title'] = $title;200 // $options['widget-activities-roleid'] = $roleid;201 $options['widget-activities-count'] = $count;202 update_option(VF_OPTIONS_NAME, $options);203 }204 205 // Be sure you format your options to be valid HTML attributes.206 $title = htmlspecialchars($title, ENT_QUOTES);207 208 // TODO: Retrieve & build the role dropdown. At time of this writing, there is no way to get the roles from Vanilla.209 /*210 $resturl = vf_get_value('url', $options, '');211 $resturl = vf_combine_paths(array($resturl, 'settings/roles.json'), '/');212 $role_data = json_decode(vf_rest($resturl));213 $select_options = vf_get_select_option('All Roles', '0', $roleid);214 if (is_object($role_data)) {215 foreach ($role_data->Categories as $Role) {216 $select_options .= vf_get_select_option($Role->Name, $Role->CategoryID, $roleid);217 }218 }219 */220 221 // Here is our little form segment. Notice that we don't need a222 // complete form. This will be embedded into the existing form.223 echo '<p><label for="widget-activities-title">' . __('Title:') . ' <input style="width: 100%;" id="widget-activities-title" name="widget-activities-title" type="text" value="'.$title.'" /></label></p>';224 // echo '<p><label for="widget-activities-roleid">' . __('Filter to Role:') . ' <select id="widget-discussions-categoryid" name="widget-activities-roleid">'.$select_options.'</select></label></p>';225 echo '<p><label for="widget-activities-count">' . __('Number of activities to show:') . ' <input style="width: 40px;" id="widget-activities-count" name="widget-activities-count" type="text" value="'.$count.'" /></label></p>';226 echo '<input type="hidden" id="widget-activities-submit" name="widget-activities-submit" value="1" />';227 }228 229 // This registers our widget so it appears with the other available230 // widgets and can be dragged and dropped into any active sidebars.231 wp_register_sidebar_widget('vf-widget-activities', 'Vanilla Activity', 'vf_widget_activities', array('description' => 'Recent activity happening on your Vanilla Forum (eg. new users, status updates, etc).'));232 233 // This registers our optional widget control form. Because of this234 // our widget will have a button that reveals a 300x100 pixel form.235 wp_register_widget_control('vf-widget-activities', 'Vanilla Recent Activity', 'vf_widget_activities_control');178 // These lines generate our output. Widgets can be very complex 179 // but as you can see here, they can also be very, very simple. 180 echo $before_widget . $before_title . $title . $after_title; 181 echo '<ul>'; 182 $i = 0; 183 foreach ($Activities as $Activity) { 184 $i++; 185 if ($i > $count) 186 break; 187 188 echo '<li>'.vf_format_activity($Activity, $link_url).'</li>'; 189 } 190 echo '</ul>'; 191 echo $after_widget; 192 } 193 194 function vf_widget_activities_control() { 195 // Get our options and see if we're handling a form submission. 196 $options = get_option(VF_OPTIONS_NAME); 197 $title = vf_get_value('widget-activities-title', $options, 'Recent Forum Activity'); 198 // $roleid = (int)vf_get_value('widget-activities-roleid', $options); 199 $count = (int)vf_get_value('widget-activities-count', $options, 10); 200 if ($_POST['widget-activities-submit']) { 201 // Remember to sanitize and format use input appropriately. 202 $title = strip_tags(stripslashes($_POST['widget-activities-title'])); 203 // $roleid = (int)vf_get_value('widget-activities-roleid', $_POST); 204 $count = (int)vf_get_value('widget-activities-count', $_POST); 205 $options['widget-activities-title'] = $title; 206 // $options['widget-activities-roleid'] = $roleid; 207 $options['widget-activities-count'] = $count; 208 update_option(VF_OPTIONS_NAME, $options); 209 } 210 211 // Be sure you format your options to be valid HTML attributes. 212 $title = htmlspecialchars($title, ENT_QUOTES); 213 214 // TODO: Retrieve & build the role dropdown. At time of this writing, there is no way to get the roles from Vanilla. 215 /* 216 $resturl = vf_get_value('url', $options, ''); 217 $resturl = vf_combine_paths(array($resturl, 'settings/roles.json'), '/'); 218 $role_data = json_decode(vf_rest($resturl)); 219 $select_options = vf_get_select_option('All Roles', '0', $roleid); 220 if (is_object($role_data)) { 221 foreach ($role_data->Categories as $Role) { 222 $select_options .= vf_get_select_option($Role->Name, $Role->CategoryID, $roleid); 223 } 224 } 225 */ 226 227 // Here is our little form segment. Notice that we don't need a 228 // complete form. This will be embedded into the existing form. 229 echo '<p><label for="widget-activities-title">' . __('Title:') . ' <input style="width: 100%;" id="widget-activities-title" name="widget-activities-title" type="text" value="'.$title.'" /></label></p>'; 230 // echo '<p><label for="widget-activities-roleid">' . __('Filter to Role:') . ' <select id="widget-discussions-categoryid" name="widget-activities-roleid">'.$select_options.'</select></label></p>'; 231 echo '<p><label for="widget-activities-count">' . __('Number of activities to show:') . ' <input style="width: 40px;" id="widget-activities-count" name="widget-activities-count" type="text" value="'.$count.'" /></label></p>'; 232 echo '<input type="hidden" id="widget-activities-submit" name="widget-activities-submit" value="1" />'; 233 } 234 235 // This registers our widget so it appears with the other available 236 // widgets and can be dragged and dropped into any active sidebars. 237 wp_register_sidebar_widget('vf-widget-activities', 'Vanilla Activity', 'vf_widget_activities', array('description' => 'Recent activity happening on your Vanilla Forum (eg. new users, status updates, etc).')); 238 239 // This registers our optional widget control form. Because of this 240 // our widget will have a button that reveals a 300x100 pixel form. 241 wp_register_widget_control('vf-widget-activities', 'Vanilla Recent Activity', 'vf_widget_activities_control'); 236 242 237 243 238 244 // Recently Active Users Widget 239 function vf_widget_users($args) {240 extract($args);241 242 $options = get_option(VF_OPTIONS_NAME);243 $title = vf_get_value('widget-users-title', $options, '');244 $count = (int)vf_get_value('widget-users-count', $options, '');245 $width = (int)vf_get_value('widget-users-iconwidth', $options, 32);246 if ($count < 5)247 $count = 5;248 249 $url = vf_get_value('url', $options, '');250 $link_url = vf_get_link_url($options);251 $resturl = array($url, '/user/summary.json');252 253 // Retrieve the latest discussions from the Vanilla API254 $resturl = vf_combine_paths($resturl, '/');255 $data = json_decode(vf_rest($resturl));256 if (!is_object($data))257 return;258 259 // These lines generate our output. Widgets can be very complex260 // but as you can see here, they can also be very, very simple.261 echo $before_widget . $before_title . $title . $after_title;262 echo '<div class="ForumUsers">';263 $i = 0;264 foreach ($data->UserData as $User) {265 $i++;266 if ($i > $count)267 break;268 269 $User->IconWidth = $width;270 echo vf_user_photo($User, $link_url).' ';271 }272 echo '</div>';273 echo $after_widget;274 }275 276 function vf_widget_users_control() {277 // Get our options and see if we're handling a form submission.278 $options = get_option(VF_OPTIONS_NAME);279 $title = vf_get_value('widget-users-title', $options, 'Recently Active Users');280 $count = (int)vf_get_value('widget-users-count', $options, 10);281 $width = (int)vf_get_value('widget-users-iconwidth', $options, 32);282 if ($_POST['widget-users-submit']) {283 // Remember to sanitize and format use input appropriately.284 $title = strip_tags(stripslashes($_POST['widget-users-title']));285 $count = (int)vf_get_value('widget-users-count', $_POST);286 $width = (int)vf_get_value('widget-users-iconwidth', $_POST);287 $options['widget-users-title'] = $title;288 $options['widget-users-count'] = $count;289 $options['widget-users-iconwidth'] = $width;290 update_option(VF_OPTIONS_NAME, $options);291 }292 293 // Be sure you format your options to be valid HTML attributes.294 $title = htmlspecialchars($title, ENT_QUOTES);295 296 echo '<p><label for="widget-users-title">' . __('Title:') . ' <input style="width: 100%;" id="widget-users-title" name="widget-users-title" type="text" value="'.$title.'" /></label></p>';297 echo '<p><label for="widget-users-count">' . __('Number of users to show:') . ' <input style="width: 40px;" id="widget-users-count" name="widget-users-count" type="text" value="'.$count.'" /></label></p>';298 echo '<p><label for="widget-users-iconwidth">' . __('Icon width:') . ' <input style="width: 40px;" id="widget-users-iconwidth" name="widget-users-iconwidth" type="text" value="'.$width.'" />px</label></p>';299 echo '<input type="hidden" id="widget-users-submit" name="widget-users-submit" value="1" />';300 }301 302 // This registers our widget so it appears with the other available303 // widgets and can be dragged and dropped into any active sidebars.304 wp_register_sidebar_widget('vf-widget-users', 'Vanilla Users', 'vf_widget_users', array('description' => 'Icons of recently active users in your Vanilla Forum.'));305 306 // This registers our optional widget control form. Because of this307 // our widget will have a button that reveals a 300x100 pixel form.308 wp_register_widget_control('vf-widget-users', 'Vanilla Recently Active User', 'vf_widget_users_control');245 function vf_widget_users($args) { 246 extract($args); 247 248 $options = get_option(VF_OPTIONS_NAME); 249 $title = vf_get_value('widget-users-title', $options, ''); 250 $count = (int)vf_get_value('widget-users-count', $options, ''); 251 $width = (int)vf_get_value('widget-users-iconwidth', $options, 32); 252 if ($count < 5) 253 $count = 5; 254 255 $url = vf_get_value('url', $options, ''); 256 $link_url = vf_get_link_url($options); 257 $resturl = array($url, '/user/summary.json'); 258 259 // Retrieve the latest discussions from the Vanilla API 260 $resturl = vf_combine_paths($resturl, '/'); 261 $data = json_decode(vf_rest($resturl)); 262 if (!is_object($data)) 263 return; 264 265 // These lines generate our output. Widgets can be very complex 266 // but as you can see here, they can also be very, very simple. 267 echo $before_widget . $before_title . $title . $after_title; 268 echo '<div class="ForumUsers">'; 269 $i = 0; 270 foreach ($data->UserData as $User) { 271 $i++; 272 if ($i > $count) 273 break; 274 275 $User->IconWidth = $width; 276 echo vf_user_photo($User, $link_url).' '; 277 } 278 echo '</div>'; 279 echo $after_widget; 280 } 281 282 function vf_widget_users_control() { 283 // Get our options and see if we're handling a form submission. 284 $options = get_option(VF_OPTIONS_NAME); 285 $title = vf_get_value('widget-users-title', $options, 'Recently Active Users'); 286 $count = (int)vf_get_value('widget-users-count', $options, 10); 287 $width = (int)vf_get_value('widget-users-iconwidth', $options, 32); 288 if ($_POST['widget-users-submit']) { 289 // Remember to sanitize and format use input appropriately. 290 $title = strip_tags(stripslashes($_POST['widget-users-title'])); 291 $count = (int)vf_get_value('widget-users-count', $_POST); 292 $width = (int)vf_get_value('widget-users-iconwidth', $_POST); 293 $options['widget-users-title'] = $title; 294 $options['widget-users-count'] = $count; 295 $options['widget-users-iconwidth'] = $width; 296 update_option(VF_OPTIONS_NAME, $options); 297 } 298 299 // Be sure you format your options to be valid HTML attributes. 300 $title = htmlspecialchars($title, ENT_QUOTES); 301 302 echo '<p><label for="widget-users-title">' . __('Title:') . ' <input style="width: 100%;" id="widget-users-title" name="widget-users-title" type="text" value="'.$title.'" /></label></p>'; 303 echo '<p><label for="widget-users-count">' . __('Number of users to show:') . ' <input style="width: 40px;" id="widget-users-count" name="widget-users-count" type="text" value="'.$count.'" /></label></p>'; 304 echo '<p><label for="widget-users-iconwidth">' . __('Icon width:') . ' <input style="width: 40px;" id="widget-users-iconwidth" name="widget-users-iconwidth" type="text" value="'.$width.'" />px</label></p>'; 305 echo '<input type="hidden" id="widget-users-submit" name="widget-users-submit" value="1" />'; 306 } 307 308 // This registers our widget so it appears with the other available 309 // widgets and can be dragged and dropped into any active sidebars. 310 wp_register_sidebar_widget('vf-widget-users', 'Vanilla Users', 'vf_widget_users', array('description' => 'Icons of recently active users in your Vanilla Forum.')); 311 312 // This registers our optional widget control form. Because of this 313 // our widget will have a button that reveals a 300x100 pixel form. 314 wp_register_widget_control('vf-widget-users', 'Vanilla Recently Active User', 'vf_widget_users_control'); 309 315 } 310 316
Note: See TracChangeset
for help on using the changeset viewer.