Created
May 24, 2016 06:47
-
-
Save anthonyeden/6bb1f2be477c0075e7873e2cdd486159 to your computer and use it in GitHub Desktop.
Tally Puller WP Plugin Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Sample Appeal Tally - Wordpress Plugin | |
// Provided by Anthony Eden | |
// Finds and returns various appeal figures for embedding on our pages | |
// This should be loaded via AJAX, as we don't want a blocking script on our page | |
//All returned data will be in JSON format | |
header('Content-type: text/json'); | |
if(isset($_GET['feed']) && $_GET['feed'] == "tally") { | |
$xml = simplexml_load_file("MyTallyData.xml"); | |
$tallyData = array( | |
'partners_count' => intval($xml->tally->partners), | |
'combined_tally' => intval($xml->tally->combined_tally), | |
'combined_goal' => intval($xml->tally->combined_goal), | |
'combined_percentage' => intval($xml->tally->combined_tally / $xml->tally->combined_goal * 100), | |
); | |
// Returns general tally data | |
echo json_encode($tallyData); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Sample Appeal Tally - Wordpress Plugin | |
// Provided by Anthony Eden | |
// QuickStart: Call 'MyAppeal_TallyTile()' in your theme and echo it. | |
// You'll need to populate MyTallyData.xml | |
function myappealcomponents_scripts() { | |
wp_register_style('myappealcomponents_style', plugins_url('/style.css', __FILE__)); | |
wp_enqueue_style('myappealcomponents_style'); | |
wp_localize_script('myappealcomponents_script', 'myappealcomponents', array( | |
'pluginsUrl' => plugins_url('', __FILE__) | |
)); | |
} | |
add_action('wp_enqueue_scripts', 'myappealcomponents_script', 50); | |
function MyAppeal_TallyTile() { | |
$html = ""; | |
$html .= "<script> | |
jQuery(document).ready(function() { | |
MyAppeal_fetchTally(function(data) { | |
jQuery('#s-myappeal-tally .tallynum').html(data['combined_percentage'] + \"%\"); | |
jQuery('#s-myappeal-tally a').fadeIn('slow'); | |
}); | |
}); | |
</script>"; | |
$html .= '<a href="/donate/" style="display: none;">'; | |
$html .= '<div class="large-6 medium-6 small-12 columns"> | |
<div class="progressfull"></div> | |
<div class="progresspartial"></div> | |
<p class="tallynum"></p> | |
<p class="tallyunit">Funded</p> | |
</div>'; | |
$html .= '<div class="large-6 medium-6 small-12 columns"> | |
<img src="'.plugins_url('donate2.png', __FILE__).'" alt=\Donate Now" /> | |
</div>'; | |
$html .= "</a>"; | |
return $html; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var MyAppeal_fetchTally = function(callback) { | |
//This functions fetches the lastest tally from the server and then executes the callback | |
jQuery.ajax({ | |
type: 'GET', | |
url: myappealcomponents.pluginsUrl + '/data.php?feed=tally', | |
dataType: 'json', | |
cache: false, | |
success: function(data) { | |
callback(data); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment