Changeset 724815
- Timestamp:
- 06/10/2013 08:55:29 AM (13 years ago)
- Location:
- captain-up/trunk
- Files:
-
- 4 edited
-
README.md (modified) (1 diff)
-
captainup.css (modified) (4 diffs)
-
captainup.php (modified) (8 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
captain-up/trunk/README.md
r708989 r724815 95 95 ## Changelog 96 96 97 ###### 1.3 98 99 * Beta: Added an option to add the API Secret in the Captain Up tab. This can be used by advanced users to connect user IDs between the Captain Up platform and your site for more customized user profiles. 100 101 * Fixed redirect after submitting the settings form in the admin panel. 102 103 * Added support for WordPress comments. Users can now be rewarded with points and badges for commenting with the native WordPress comments along with Disqus and Facebook comments. 104 97 105 ###### 1.2 98 106 -
captain-up/trunk/captainup.css
r708989 r724815 39 39 40 40 border: 1px solid rgba(0,0,0,.3); 41 background: rgb(235, 241, 243);41 background: #f5f5f5; 42 42 } 43 43 … … 71 71 72 72 #cpt-wrap hr { 73 height:1px; 74 background: rgba(0,0,0,.6);; 75 border:none; 76 border-bottom: 1px solid rgba(255,255,255,.8); 73 height: 1px; 74 background: rgba(207, 207, 207, 0); 75 border: none; 76 box-shadow: 0px 1px 4px #ccc; 77 margin-bottom: 20px; 77 78 } 78 79 … … 96 97 } 97 98 98 #cpt-wrap #cpt-apiinput[type="text"] {99 #cpt-wrap input[type="text"] { 99 100 font-size: 16px; 100 101 padding: 5px 10px; … … 112 113 113 114 #cpt-wrap #cpt-submit { 114 position: absolute; 115 bottom: 110px; 116 right: 50px; 115 text-align: right; 116 margin-right: 35px; 117 margin-bottom: 20px; 118 } 119 120 #captain-api-secret { 121 margin-left: 25px; 122 } 123 124 #cpt-quick-links { 125 margin-bottom: 15px; 117 126 } 118 127 -
captain-up/trunk/captainup.php
r708989 r724815 4 4 Plugin URI: http://www.captainup.com 5 5 Description: Add Game Mechanics to your site and increase your engagement and retention. 2 minutes install: Simply add your free Captain Up API Key and you are good to go. The plugin also adds widgets you can use to show leaderboards and activities within your site. 6 Version: 1. 26 Version: 1.3 7 7 Author: Captain Up Team 8 8 License: GPL2 … … 14 14 function cptup_settings() { 15 15 16 if ( isset($_POST['submit'])) {17 update_option('captain-up-enabled', $_POST['captain-up-enabled']);16 if (isset($_POST['submit'])) { 17 // Save the Captain Up options on POST 18 18 update_option('captain-api-key', $_POST['captain-api-key']); 19 update_option('captain-api-secret', $_POST['captain-api-secret']); 19 20 update_option('captain-locale', $_POST['captain-locale']); 20 21 22 // We're using JavaScript to redirect back to the page as a GET 23 // request. The reason we do that in JS instead of PHP is that 24 // the headers were already sent. This is a hack, like everything 25 // in WordPress. 26 ?> 27 <script> 28 var url = location.href; 29 url += ~url.indexOf('submitted=true') ? '' : '&submitted=true'; 30 location.replace(url); 31 </script> 32 <?php 33 } 34 35 if(isset($_GET['submitted'])) { 21 36 echo "<div id='update' class='updated'><p>Settings updated.</p></div>\n"; 22 37 } 23 38 24 // See if Captain Up is Enabled25 $captain_up = get_option('captain-up-enabled');26 27 39 // Get the Captain Up API Key 28 $captain_api = get_option('captain-api-key'); 40 $captain_api_key = get_option('captain-api-key'); 41 42 // Get the Captain Up API Secret 43 $captain_api_secret = get_option('captain-api-secret'); 29 44 30 45 // Get the Captain Up Locale … … 49 64 <h2>Configure Captain Up</h2> 50 65 51 <p>Copy your API key from the <a href='http://captainup.com/manage#settings' target='_blank'>Settings tab</a> in your Captain Up Admin Panel and paste it here. You need to <a href='http://captainup.com/users/sign_up' target='_blank'>Sign Up</a> if you don't have a Captain Up account.52 53 <div id= "cpt-api">54 <label for= "captain-api-key">Your API Key:</label>55 <input id= "captain-api-key" name="captain-api-key" type="text" size="50" value="<?php echo $captain_api; ?>"/>66 <p>Copy your API key from the <a href='http://captainup.com/manage#settings' target='_blank'>Settings tab</a> in your Captain Up admin panel and paste it here. You need to <a href='http://captainup.com/users/sign_up' target='_blank'>Sign Up</a> if you don't have a Captain Up account.</p> 67 68 <div id='cpt-api'> 69 <label for='captain-api-key'>Your API Key:</label> 70 <input id='captain-api-key' name='captain-api-key' type='text' size='50' value='<?php echo $captain_api_key; ?>' /> 56 71 </div> 57 72 … … 97 112 </div> 98 113 99 <hr/> 100 101 <h2>Quick Links and Support</h2> 102 <div id='cpt-footer'> 103 <a href='http://captainup.com/manage' target='_blank'>Dashboard</a> 104 <span class='cpt-sep'>|</span> 105 106 <a href='http://captainup.com/help' target='_blank'>Help & Support</a> 107 <span class='cpt-sep'>|</span> 108 109 <a href='http://captainup.com/manage#badges' target='_blank'>Edit Badges</a> 110 <span class='cpt-sep'>|</span> 111 112 <a href='http://captainup.com/manage#levels' target='_blank'>Edit Levels</a> 113 <span class='cpt-sep'>|</span> 114 115 <a href='http://captainup.com/blog' target='_blank'>Blog</a> 116 <span class='cpt-sep'>|</span> 117 118 <a href='http://twitter.com/cptup' target='_blank'>Twitter</a> 119 <span class='cpt-sep'>|</span> 120 121 <a href='mailto:team@captainup.com' target='_blank'>Contact Us</a> 122 114 <hr /> 115 116 <h2>Advanced Options</h2> 117 <p>You will need to add your API Secret to enable advanced options. Copy the API Secret from the <a href='http://captainup.com/manage#settings' target='_blank'>Settings tab</a> in your Captain Up admin panel and paste it here. 118 <div id='cpt-secret'> 119 <label for='captain-api-secret'>API Secret:</label> 120 <input id='captain-api-secret' name='captain-api-secret' type='text' size='50' value='<?php echo $captain_api_secret; ?>' /> 121 </div> 122 123 <div id='cpt-submit'> 124 <input type="submit" class="cpt-x-btn cpt-btn-success padded" name="submit" value="Save" /> 125 </div> 126 127 <hr /> 128 129 <div id='cpt-quick-links'> 130 <h2>Quick Links and Support</h2> 131 <div id='cpt-footer'> 132 <a href='http://captainup.com/manage' target='_blank'>Dashboard</a> 133 <span class='cpt-sep'>|</span> 134 135 <a href='http://captainup.com/help' target='_blank'>Help & Support</a> 136 <span class='cpt-sep'>|</span> 137 138 <a href='http://captainup.com/manage#badges' target='_blank'>Edit Badges</a> 139 <span class='cpt-sep'>|</span> 140 141 <a href='http://captainup.com/manage#levels' target='_blank'>Edit Levels</a> 142 <span class='cpt-sep'>|</span> 143 144 <a href='http://captainup.com/blog' target='_blank'>Blog</a> 145 <span class='cpt-sep'>|</span> 146 147 <a href='http://twitter.com/cptup' target='_blank'>Twitter</a> 148 <span class='cpt-sep'>|</span> 149 150 <a href='mailto:team@captainup.com' target='_blank'>Contact Us</a> 151 </div> 123 152 </div> 124 153 </div> … … 179 208 // set. 180 209 function cptup_start() { 181 // Grab a reference to the API Key 182 $captain_api = get_option('captain-api-key'); 210 // Grab a reference to the API Key and Secret 211 $captain_api_key = get_option('captain-api-key'); 212 $api_secret = get_option('captain-api-secret', false); 213 214 // Check if the API secret is valid - 64 hexadecimal characters 215 $valid_api_secret = preg_match("/^[0-9A-Fa-f]{64,64}$/", $api_secret) == 1; 183 216 184 217 // Add a language suffix to the Embed Script, if the 185 218 // captain-locale was not set it will return 'en'. 186 219 $lang = "." . get_option('captain-locale', 'en'); 220 221 // Grab the current user ID 222 $current_user_id = get_current_user_id(); 223 224 // Only hash the user id if the user is signed in and the api secret 225 // is valid. Otherwise we want need it and won't add it to the script 226 // configuration options below. 227 if ($current_user_id != 0 && $valid_api_secret) { 228 // Hash the WordPress User ID with with the API Secret using SHA512 229 // We need this to connect WordPress user IDs and Captain Up IDs. The 230 // $hashed_user_id makes sure the user_id is not being tampered on 231 // the client side. 232 $hashed_user_id = hash_hmac('sha512', $current_user_id, $api_secret); 233 // Encode it as Base64 234 $hashed_user_id = base64_encode($hashed_user_id); 235 // remove new lines and and the '=' part at the end. 236 $hashed_user_id = preg_replace('/(\n|=+\n?$)/', '', $hashed_user_id); 237 } 187 238 188 239 ?> … … 192 243 window.captain = {up: function(fn) { captain.topics.push(fn) }, topics: []}; 193 244 captain.up({ 194 api_key: '<?php echo $captain_api; ?>' 245 api_key: '<?php echo $captain_api_key; ?>', 246 platform: 'wordpress', 247 app: { 248 <?php if($current_user_id != 0 && $valid_api_secret) { ?> 249 user_id: '<?php echo $current_user_id; ?>', 250 hashed_user_id: '<?php echo $hashed_user_id; ?>' 251 <?php } ?> 252 } 195 253 }); 196 254 </script> … … 198 256 (function() { 199 257 var cpt = document.createElement('script'); cpt.type = 'text/javascript'; cpt.async = true; 200 cpt.src = 'http' + (location.protocol == 'https:' ? 's' : '') + ':// captainup.com/assets/embed<?php echo $lang; ?>.js';258 cpt.src = 'http' + (location.protocol == 'https:' ? 's' : '') + '://local.host/assets/embed<?php echo $lang; ?>.js'; 201 259 (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(cpt); 202 260 })(); … … 353 411 354 412 413 /* WordPress Comments Integration 414 * ----------------------------------------------------------------*/ 415 // The flow for detecting a new wordpress comment and sending 416 // to Captain Up goes like this: First, we add an action hook to 417 // `comment_post` that notifies us when comments are saved to the 418 // database. Then, if the comment was approved, we create a cookie 419 // called `wp_cpt_new_comment`. We do this since after a comment 420 // is POSTed wordpress redirects back to the post. It's like a bad 421 // man's flash messaging. We check if this cookie exists on every 422 // request. If it does, we remove it, hook to the <head> element 423 // and add a JavaScript variable there called `_cpt_wordpress_events` 424 // that stores the new comment event. The Captain Up embed code 425 // does the rest of the work. 426 // 427 // NOTE: This process -will- change and will be moved to a server-side 428 // flow. 429 430 // Setup a hook to get a notification after a new comment has been posted. 431 add_action('comment_post', 'captain_mark_new_comment', 10, 2); 432 433 // `captain_mark_new_comment` is called from the `comment_post` wordpress 434 // hook. It receives $comment_id and the $approval status of the comment, 435 // and stores a cookie telling us in the follow up request (after the 436 // redirection) that a comment was created. 437 function captain_mark_new_comment($comment_id, $approval) { 438 // $approval can either be 'spam', 0 for disapproved or 1 for approved. 439 // We give points for approved and disapproved (held for moderation) 440 // comments but not for spam. 441 if ($approval == 1 || $approval == 0) { 442 // we need to mark this in a cookie since wordpress has no built-in 443 // session or flash support and after a comment is posted wordpress 444 // redirects the user. 445 setcookie("wp_cpt_new_comment", $comment_id, time() + 3600, COOKIEPATH, COOKIE_DOMAIN); 446 } 447 } 448 449 // `captain_add_new_comment` adds a new JS snippet to the page with 450 // the `_cpt_wordpress_events` variable. The Captain Up embed picks 451 // this up later and then syncs the new comment action to our servers. 452 function captain_add_new_comment() { 453 ?> 454 <script type='text/javascript'> 455 window._cpt_wordpress_events = { 456 new_comment: true 457 }; 458 </script> 459 <?php 460 } 461 462 // On every request, check if the new comment cookie is set 463 if (isset($_COOKIE['wp_cpt_new_comment'])) { 464 // Clean the Cookie 465 setcookie("wp_cpt_new_comment", "", time() - 3600, COOKIEPATH, COOKIE_DOMAIN); 466 // hook into the <head> of the page to insert our JS snippet 467 // that tells the Captain Up embed a new comment was created. 468 add_action('wp_head', 'captain_add_new_comment'); 469 } 470 355 471 ?> -
captain-up/trunk/readme.txt
r708989 r724815 116 116 == Changelog == 117 117 118 = 1.3 = 119 120 * Beta: Added an option to add the API Secret in the Captain Up tab. This can be used by advanced users to connect user IDs between the Captain Up platform and your site for more customized user profiles. 121 122 * Fixed redirect after submitting the settings form in the admin panel. 123 124 * Added support for WordPress comments. Users can now be rewarded with points and badges for commenting with the native WordPress comments along with Disqus and Facebook comments. 125 118 126 = 1.2 = 119 127
Note: See TracChangeset
for help on using the changeset viewer.