-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ruxton
committed
Sep 23, 2015
0 parents
commit 4ad17b5
Showing
7 changed files
with
338 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
syntax:glob | ||
build/*/ | ||
nbproject/private |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Chuffed Widget for WordPress | ||
==================================== | ||
|
||
Overview | ||
-------- | ||
|
||
The plugin will add a widget to your WordPress install to display Chuffed campaigns. | ||
|
||
Why Would You Do This? | ||
---------------------- | ||
|
||
I like to cut code, we're using Chuffed, I wanted a widget. | ||
|
||
Using Chuffed Widget for WordPress | ||
----------- | ||
|
||
1. You can use ant to build a zip of the project `ant build` or alternatively; | ||
2. Upload the `chuffed-widget` directory to the `/wp-content/plugins/` directory on your website | ||
3. Activate the plugin through the 'Plugins' menu in WordPress | ||
|
||
|
||
Meta | ||
---- | ||
|
||
* Code: `git clone git://github.com/ruxton/chuffed-widget.git` | ||
* Home: <http://ignite.digitalignition.net/> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
build_name=chuffed-widget | ||
dir.build=build/dev/ | ||
dir.dev=${env.WPDEV_HOME}/wp-content/plugins/app-url/ | ||
dir.src=app-url/ | ||
dir.svn=/Users/ruxton/AppsByGreg/php/app-url-svn |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<project name="italm" default="init" basedir="."> | ||
<property environment="env"/> | ||
<property file="build.properties"/> | ||
|
||
|
||
<target name="init"> | ||
<echo /> | ||
</target> | ||
<target name="checkout"> | ||
<echo message="Checking out plugin from SVN to ${dir.svn}" /> | ||
<exec executable="svn" dir="${dir.svn}"> | ||
<arg line="co http://svn.wp-plugins.org/${build_name}" /> | ||
</exec> | ||
|
||
</target> | ||
<target name="devtest"> | ||
<echo message="Setting up dev environment.." /> | ||
<echo message="Copying to ${dir.dev}.." /> | ||
<copy todir="${dir.dev}"> | ||
<fileset dir="${dir.src}"> | ||
</fileset> | ||
</copy> | ||
<echo message="Setup complete, running.." /> | ||
</target> | ||
<target name="build"> | ||
<echo message="Creating a new build.." /> | ||
<copy todir="${dir.build}/${build_name}"> | ||
<fileset dir="${dir.src}" excludes="preg_match_test.php"> | ||
</fileset> | ||
</copy> | ||
<zip destfile="${dir.build}/italm.zip"> | ||
<zipfileset dir="${dir.src}" prefix="${build_name}" excludes="preg_match_test.php" /> | ||
</zip> | ||
</target> | ||
<target name="svn-update"> | ||
<echo message="Updating....." /> | ||
<echo message="Copying to ${dir.svn}.." /> | ||
<copy todir="${dir.svn}"> | ||
<fileset dir="${dir.latest}"> | ||
</fileset> | ||
</copy> | ||
</target> | ||
</project> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
<?php | ||
/* | ||
Plugin Name: Chuffed Donation Widget | ||
Plugin URI: http://ignite.digitalignition.net/articlesexamples/chuffed-donation-widget | ||
Description: Easily add a widget for your chuffed campaign | ||
Author: Greg Tangey | ||
Author URI: http://ignite.digitalignition.net/ | ||
Version: 0.1 | ||
*/ | ||
|
||
/* Copyright 2015 Greg Tangey (email : [email protected]) | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
class ChuffedWidget extends WP_Widget { | ||
|
||
/** | ||
* Register widget with WordPress. | ||
*/ | ||
function __construct() { | ||
parent::__construct( | ||
'chuffed_widget', // Base ID | ||
__( 'Chuffed Campaign', 'text_domain' ), // Name | ||
array( 'description' => __( 'A chuffed.org campaign widget', 'text_domain' ), ) // Args | ||
); | ||
} | ||
|
||
/** | ||
* Front-end display of widget. | ||
* | ||
* @see WP_Widget::widget() | ||
* | ||
* @param array $args Widget arguments. | ||
* @param array $instance Saved values from database. | ||
*/ | ||
public function widget( $args, $instance ) { | ||
$campaign_id = $instance['campaign_id']; | ||
|
||
if( ! empty($campaign_id) ) { | ||
$transName = "chuffed-widget-$campaign_id"; | ||
$cacheTime = 30; // minutes | ||
// delete_transient($transName); | ||
if(false === ($chuffedData = get_transient($transName) ) ){ | ||
$json = wp_remote_get("http://chuffed.org/api/v1/campaign/$campaign_id"); | ||
|
||
// Check the response code | ||
$response_code = wp_remote_retrieve_response_code( $json ); | ||
$response_message = wp_remote_retrieve_response_message( $json ); | ||
|
||
|
||
if ( 200 != $response_code && ! empty( $response_message ) ) { | ||
$err = $response_message; | ||
} elseif ( 200 != $response_code ) { | ||
$err = "Uknown err"; | ||
} else { | ||
$chuffedData = wp_remote_retrieve_body( $json ); | ||
} | ||
|
||
$chuffedData = json_decode($chuffedData, true); | ||
set_transient($transName, $chuffedData, 60 * $cacheTime); | ||
} | ||
$targetAmount = intval($chuffedData['data']['camp_amount']); | ||
$collectedAmount = intval($chuffedData['data']['camp_amount_collected']); | ||
$percWidth = intval(($collectedAmount/$targetAmount)*100); | ||
$slug = $chuffedData['data']['slug']; | ||
$title = $chuffedData['data']['title']; | ||
|
||
echo $args['before_widget']; | ||
if ( ! empty( $instance['title'] ) ) { | ||
echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title']; | ||
} | ||
?> | ||
<a style="text-decoration: none" href="https://chuffed.org/project/<?php echo $slug; ?>"> | ||
<div style="position:relative;"> | ||
<h1><?php echo $title; ?></h1> | ||
<div style="width: 100%;height:15px;background-color: #F9F9F9 !important;"> | ||
<div style="width: <?php echo $percWidth;?>%; height: 15px;background-color: #28ab60 !important;"></div> | ||
</div> | ||
<h2 style="font-size: 50px;margin-bottom: 0;padding-bottom: 0;line-height: 56px;"> | ||
$<span><?php echo $collectedAmount; ?></span> | ||
</h2> | ||
<p style="color:#9b9b9b;"><?php echo __("Raised of", "text_domain"); ?> | ||
$<span><?php echo $targetAmount; ?></span> | ||
</p> | ||
</div> | ||
</a> | ||
<?php | ||
|
||
echo $args['after_widget']; | ||
} | ||
else { | ||
echo __("A Campaign ID is not set in the widgets setting", "text_domain"); | ||
} | ||
} | ||
|
||
/** | ||
* Back-end widget form. | ||
* | ||
* @see WP_Widget::form() | ||
* | ||
* @param array $instance Previously saved values from database. | ||
*/ | ||
public function form( $instance ) { | ||
$title = ! empty( $instance['title'] ) ? $instance['title'] : __( 'Chuffed Campaign', 'text_domain' ); | ||
$campaign_id = ! empty( $instance['campaign_id'] ) ? $instance['campaign_id'] : ''; | ||
|
||
?> | ||
<p> | ||
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> | ||
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>"> | ||
<label for="<?php echo $this->get_field_id( 'campaign_id' ); ?>"><?php _e( 'Campaign ID:' ); ?></label> | ||
<input class="widefat" id="<?php echo $this->get_field_id( 'campaign_id' ); ?>" name="<?php echo $this->get_field_name( 'campaign_id' ); ?>" type="text" value="<?php echo esc_attr( $campaign_id ); ?>"> | ||
</p> | ||
<?php | ||
} | ||
|
||
/** | ||
* Sanitize widget form values as they are saved. | ||
* | ||
* @see WP_Widget::update() | ||
* | ||
* @param array $new_instance Values just sent to be saved. | ||
* @param array $old_instance Previously saved values from database. | ||
* | ||
* @return array Updated safe values to be saved. | ||
*/ | ||
public function update( $new_instance, $old_instance ) { | ||
$instance = array(); | ||
$instance['campaign_id'] = ( ! empty( $new_instance['campaign_id'] ) ) ? strip_tags( $new_instance['campaign_id'] ) : ''; | ||
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : ''; | ||
|
||
return $instance; | ||
} | ||
|
||
} | ||
|
||
function register_chuffed_widget() { | ||
register_widget( 'ChuffedWidget' ); | ||
} | ||
add_action( 'widgets_init', 'register_chuffed_widget' ); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
=== Chuffed.org Widget === | ||
Contributors: ruxton | ||
Donate link: http://ignite.digitalignition.net/ | ||
Tags: chuffed, donations, widget | ||
Requires at least: 4.3.0 | ||
Tested up to: 4.3.1 | ||
Stable tag: 0.1 | ||
|
||
The plugin will add a widget to your WordPress install to display Chuffed campaigns. | ||
|
||
== Description == | ||
|
||
Do you run campaigns on chuffed.org? This widget will allow you to display a bar similar | ||
to the one on chuffed.org that shows the current progress of your campaign. | ||
|
||
== Installation == | ||
|
||
This section describes how to install the plugin and get it working. | ||
|
||
1. Unzip the contents of the zip file | ||
2. Upload the `chuffed-widget` directory to the `/wp-content/plugins/` directory on your website | ||
3. Activate the plugin through the 'Plugins' menu in WordPress |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#!/bin/bash | ||
# A modification of Dean Clatworthy's deploy script as found here: https://github.com/deanc/wordpress-plugin-git-svn | ||
# The difference is that this script lives in the plugin's git repo & doesn't require an existing SVN repo. | ||
|
||
# main config | ||
PLUGINSLUG="chuffed-widget" | ||
CURRENTDIR=`pwd` | ||
MAINFILE="chuffed-widget.php" # this should be the name of your main php file in the wordpress plugin | ||
|
||
# git config | ||
GITPATH="$CURRENTDIR/$PLUGINSLUG/" # this file should be in the base of your git repository | ||
|
||
# svn config | ||
SVNPATH="/tmp/$PLUGINSLUG" # path to a temp SVN repo. No trailing slash required and don't add trunk. | ||
SVNURL="http://plugins.svn.wordpress.org/$PLUGINSLUG/" # Remote SVN repo on wordpress.org, with no trailing slash | ||
SVNUSER="Ruxton" # your svn username | ||
|
||
|
||
# Let's begin... | ||
echo ".........................................." | ||
echo | ||
echo "Preparing to deploy wordpress plugin" | ||
echo | ||
echo ".........................................." | ||
echo | ||
|
||
# Check version in readme.txt is the same as plugin file after translating both to unix line breaks to work around grep's failure to identify mac line breaks | ||
NEWVERSION1=`grep "^Stable tag:" $GITPATH/readme.txt | awk -F' ' '{print $NF}'` | ||
echo "readme.txt version: $NEWVERSION1" | ||
NEWVERSION2=`grep "^Version:" $GITPATH/$MAINFILE | awk -F' ' '{print $NF}'` | ||
echo "$MAINFILE version: $NEWVERSION2" | ||
|
||
if [ "$NEWVERSION1" != "$NEWVERSION2" ]; then echo "Version in readme.txt & $MAINFILE don't match. Exiting...."; exit 1; fi | ||
|
||
echo "Versions match in readme.txt and $MAINFILE. Let's proceed..." | ||
|
||
if git show-ref --tags --quiet --verify -- "refs/tags/$NEWVERSION1" | ||
then | ||
echo "Version $NEWVERSION1 already exists as git tag. Exiting...."; | ||
exit 1; | ||
else | ||
echo "Git version does not exist. Let's proceed..." | ||
fi | ||
|
||
cd $GITPATH | ||
echo -e "Enter a commit message for this new version: \c" | ||
read COMMITMSG | ||
git commit -am "$COMMITMSG" | ||
|
||
echo "Tagging new version in git" | ||
git tag -a "$NEWVERSION1" -m "Tagging version $NEWVERSION1" | ||
|
||
echo "Pushing latest commit to origin, with tags" | ||
git push origin master | ||
git push origin master --tags | ||
|
||
echo | ||
echo "Creating local copy of SVN repo ..." | ||
svn co $SVNURL $SVNPATH | ||
|
||
echo "Exporting the HEAD of master from git to the trunk of SVN" | ||
cp -R * $SVNPATH/trunk/ | ||
|
||
echo "Ignoring github specific files and deployment script" | ||
svn propset svn:ignore "deploy.sh | ||
README.md | ||
.git | ||
.gitignore" "$SVNPATH/trunk/" | ||
|
||
echo "Changing directory to SVN and committing to trunk" | ||
cd $SVNPATH/trunk/ | ||
# Add all new files that are not set to be ignored | ||
svn status | grep -v "^.[ \t]*\..*" | grep "^?" | awk '{print $2}' | xargs svn add | ||
svn commit --username=$SVNUSER -m "$COMMITMSG" | ||
|
||
echo "Creating new SVN tag & committing it" | ||
cd $SVNPATH | ||
svn copy trunk/ tags/$NEWVERSION1/ | ||
cd $SVNPATH/tags/$NEWVERSION1 | ||
svn commit --username=$SVNUSER -m "Tagging version $NEWVERSION1" | ||
|
||
echo "Removing temporary directory $SVNPATH" | ||
rm -fr $SVNPATH/ | ||
|
||
echo "*** FIN ***" |