Skip to content

Commit 4ad17b5

Browse files
author
Ruxton
committed
initial commit
0 parents  commit 4ad17b5

File tree

7 files changed

+338
-0
lines changed

7 files changed

+338
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
syntax:glob
2+
build/*/
3+
nbproject/private

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Chuffed Widget for WordPress
2+
====================================
3+
4+
Overview
5+
--------
6+
7+
The plugin will add a widget to your WordPress install to display Chuffed campaigns.
8+
9+
Why Would You Do This?
10+
----------------------
11+
12+
I like to cut code, we're using Chuffed, I wanted a widget.
13+
14+
Using Chuffed Widget for WordPress
15+
-----------
16+
17+
1. You can use ant to build a zip of the project `ant build` or alternatively;
18+
2. Upload the `chuffed-widget` directory to the `/wp-content/plugins/` directory on your website
19+
3. Activate the plugin through the 'Plugins' menu in WordPress
20+
21+
22+
Meta
23+
----
24+
25+
* Code: `git clone git://github.com/ruxton/chuffed-widget.git`
26+
* Home: <http://ignite.digitalignition.net/>

build.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
build_name=chuffed-widget
2+
dir.build=build/dev/
3+
dir.dev=${env.WPDEV_HOME}/wp-content/plugins/app-url/
4+
dir.src=app-url/
5+
dir.svn=/Users/ruxton/AppsByGreg/php/app-url-svn

build.xml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<project name="italm" default="init" basedir=".">
3+
<property environment="env"/>
4+
<property file="build.properties"/>
5+
6+
7+
<target name="init">
8+
<echo />
9+
</target>
10+
<target name="checkout">
11+
<echo message="Checking out plugin from SVN to ${dir.svn}" />
12+
<exec executable="svn" dir="${dir.svn}">
13+
<arg line="co http://svn.wp-plugins.org/${build_name}" />
14+
</exec>
15+
16+
</target>
17+
<target name="devtest">
18+
<echo message="Setting up dev environment.." />
19+
<echo message="Copying to ${dir.dev}.." />
20+
<copy todir="${dir.dev}">
21+
<fileset dir="${dir.src}">
22+
</fileset>
23+
</copy>
24+
<echo message="Setup complete, running.." />
25+
</target>
26+
<target name="build">
27+
<echo message="Creating a new build.." />
28+
<copy todir="${dir.build}/${build_name}">
29+
<fileset dir="${dir.src}" excludes="preg_match_test.php">
30+
</fileset>
31+
</copy>
32+
<zip destfile="${dir.build}/italm.zip">
33+
<zipfileset dir="${dir.src}" prefix="${build_name}" excludes="preg_match_test.php" />
34+
</zip>
35+
</target>
36+
<target name="svn-update">
37+
<echo message="Updating....." />
38+
<echo message="Copying to ${dir.svn}.." />
39+
<copy todir="${dir.svn}">
40+
<fileset dir="${dir.latest}">
41+
</fileset>
42+
</copy>
43+
</target>
44+
</project>

chuffed-widget/chuffed-widget.php

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
<?php
2+
/*
3+
Plugin Name: Chuffed Donation Widget
4+
Plugin URI: http://ignite.digitalignition.net/articlesexamples/chuffed-donation-widget
5+
Description: Easily add a widget for your chuffed campaign
6+
Author: Greg Tangey
7+
Author URI: http://ignite.digitalignition.net/
8+
Version: 0.1
9+
*/
10+
11+
/* Copyright 2015 Greg Tangey (email : [email protected])
12+
13+
This program is free software; you can redistribute it and/or modify
14+
it under the terms of the GNU General Public License as published by
15+
the Free Software Foundation; either version 2 of the License, or
16+
(at your option) any later version.
17+
18+
This program is distributed in the hope that it will be useful,
19+
but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+
GNU General Public License for more details.
22+
23+
You should have received a copy of the GNU General Public License
24+
along with this program; if not, write to the Free Software
25+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26+
*/
27+
28+
class ChuffedWidget extends WP_Widget {
29+
30+
/**
31+
* Register widget with WordPress.
32+
*/
33+
function __construct() {
34+
parent::__construct(
35+
'chuffed_widget', // Base ID
36+
__( 'Chuffed Campaign', 'text_domain' ), // Name
37+
array( 'description' => __( 'A chuffed.org campaign widget', 'text_domain' ), ) // Args
38+
);
39+
}
40+
41+
/**
42+
* Front-end display of widget.
43+
*
44+
* @see WP_Widget::widget()
45+
*
46+
* @param array $args Widget arguments.
47+
* @param array $instance Saved values from database.
48+
*/
49+
public function widget( $args, $instance ) {
50+
$campaign_id = $instance['campaign_id'];
51+
52+
if( ! empty($campaign_id) ) {
53+
$transName = "chuffed-widget-$campaign_id";
54+
$cacheTime = 30; // minutes
55+
// delete_transient($transName);
56+
if(false === ($chuffedData = get_transient($transName) ) ){
57+
$json = wp_remote_get("http://chuffed.org/api/v1/campaign/$campaign_id");
58+
59+
// Check the response code
60+
$response_code = wp_remote_retrieve_response_code( $json );
61+
$response_message = wp_remote_retrieve_response_message( $json );
62+
63+
64+
if ( 200 != $response_code && ! empty( $response_message ) ) {
65+
$err = $response_message;
66+
} elseif ( 200 != $response_code ) {
67+
$err = "Uknown err";
68+
} else {
69+
$chuffedData = wp_remote_retrieve_body( $json );
70+
}
71+
72+
$chuffedData = json_decode($chuffedData, true);
73+
set_transient($transName, $chuffedData, 60 * $cacheTime);
74+
}
75+
$targetAmount = intval($chuffedData['data']['camp_amount']);
76+
$collectedAmount = intval($chuffedData['data']['camp_amount_collected']);
77+
$percWidth = intval(($collectedAmount/$targetAmount)*100);
78+
$slug = $chuffedData['data']['slug'];
79+
$title = $chuffedData['data']['title'];
80+
81+
echo $args['before_widget'];
82+
if ( ! empty( $instance['title'] ) ) {
83+
echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title'];
84+
}
85+
?>
86+
<a style="text-decoration: none" href="https://chuffed.org/project/<?php echo $slug; ?>">
87+
<div style="position:relative;">
88+
<h1><?php echo $title; ?></h1>
89+
<div style="width: 100%;height:15px;background-color: #F9F9F9 !important;">
90+
<div style="width: <?php echo $percWidth;?>%; height: 15px;background-color: #28ab60 !important;"></div>
91+
</div>
92+
<h2 style="font-size: 50px;margin-bottom: 0;padding-bottom: 0;line-height: 56px;">
93+
$<span><?php echo $collectedAmount; ?></span>
94+
</h2>
95+
<p style="color:#9b9b9b;"><?php echo __("Raised of", "text_domain"); ?>
96+
$<span><?php echo $targetAmount; ?></span>
97+
</p>
98+
</div>
99+
</a>
100+
<?php
101+
102+
echo $args['after_widget'];
103+
}
104+
else {
105+
echo __("A Campaign ID is not set in the widgets setting", "text_domain");
106+
}
107+
}
108+
109+
/**
110+
* Back-end widget form.
111+
*
112+
* @see WP_Widget::form()
113+
*
114+
* @param array $instance Previously saved values from database.
115+
*/
116+
public function form( $instance ) {
117+
$title = ! empty( $instance['title'] ) ? $instance['title'] : __( 'Chuffed Campaign', 'text_domain' );
118+
$campaign_id = ! empty( $instance['campaign_id'] ) ? $instance['campaign_id'] : '';
119+
120+
?>
121+
<p>
122+
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
123+
<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 ); ?>">
124+
<label for="<?php echo $this->get_field_id( 'campaign_id' ); ?>"><?php _e( 'Campaign ID:' ); ?></label>
125+
<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 ); ?>">
126+
</p>
127+
<?php
128+
}
129+
130+
/**
131+
* Sanitize widget form values as they are saved.
132+
*
133+
* @see WP_Widget::update()
134+
*
135+
* @param array $new_instance Values just sent to be saved.
136+
* @param array $old_instance Previously saved values from database.
137+
*
138+
* @return array Updated safe values to be saved.
139+
*/
140+
public function update( $new_instance, $old_instance ) {
141+
$instance = array();
142+
$instance['campaign_id'] = ( ! empty( $new_instance['campaign_id'] ) ) ? strip_tags( $new_instance['campaign_id'] ) : '';
143+
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
144+
145+
return $instance;
146+
}
147+
148+
}
149+
150+
function register_chuffed_widget() {
151+
register_widget( 'ChuffedWidget' );
152+
}
153+
add_action( 'widgets_init', 'register_chuffed_widget' );

chuffed-widget/readme.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
=== Chuffed.org Widget ===
2+
Contributors: ruxton
3+
Donate link: http://ignite.digitalignition.net/
4+
Tags: chuffed, donations, widget
5+
Requires at least: 4.3.0
6+
Tested up to: 4.3.1
7+
Stable tag: 0.1
8+
9+
The plugin will add a widget to your WordPress install to display Chuffed campaigns.
10+
11+
== Description ==
12+
13+
Do you run campaigns on chuffed.org? This widget will allow you to display a bar similar
14+
to the one on chuffed.org that shows the current progress of your campaign.
15+
16+
== Installation ==
17+
18+
This section describes how to install the plugin and get it working.
19+
20+
1. Unzip the contents of the zip file
21+
2. Upload the `chuffed-widget` directory to the `/wp-content/plugins/` directory on your website
22+
3. Activate the plugin through the 'Plugins' menu in WordPress

deploy.sh

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/bin/bash
2+
# A modification of Dean Clatworthy's deploy script as found here: https://github.com/deanc/wordpress-plugin-git-svn
3+
# The difference is that this script lives in the plugin's git repo & doesn't require an existing SVN repo.
4+
5+
# main config
6+
PLUGINSLUG="chuffed-widget"
7+
CURRENTDIR=`pwd`
8+
MAINFILE="chuffed-widget.php" # this should be the name of your main php file in the wordpress plugin
9+
10+
# git config
11+
GITPATH="$CURRENTDIR/$PLUGINSLUG/" # this file should be in the base of your git repository
12+
13+
# svn config
14+
SVNPATH="/tmp/$PLUGINSLUG" # path to a temp SVN repo. No trailing slash required and don't add trunk.
15+
SVNURL="http://plugins.svn.wordpress.org/$PLUGINSLUG/" # Remote SVN repo on wordpress.org, with no trailing slash
16+
SVNUSER="Ruxton" # your svn username
17+
18+
19+
# Let's begin...
20+
echo ".........................................."
21+
echo
22+
echo "Preparing to deploy wordpress plugin"
23+
echo
24+
echo ".........................................."
25+
echo
26+
27+
# 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
28+
NEWVERSION1=`grep "^Stable tag:" $GITPATH/readme.txt | awk -F' ' '{print $NF}'`
29+
echo "readme.txt version: $NEWVERSION1"
30+
NEWVERSION2=`grep "^Version:" $GITPATH/$MAINFILE | awk -F' ' '{print $NF}'`
31+
echo "$MAINFILE version: $NEWVERSION2"
32+
33+
if [ "$NEWVERSION1" != "$NEWVERSION2" ]; then echo "Version in readme.txt & $MAINFILE don't match. Exiting...."; exit 1; fi
34+
35+
echo "Versions match in readme.txt and $MAINFILE. Let's proceed..."
36+
37+
if git show-ref --tags --quiet --verify -- "refs/tags/$NEWVERSION1"
38+
then
39+
echo "Version $NEWVERSION1 already exists as git tag. Exiting....";
40+
exit 1;
41+
else
42+
echo "Git version does not exist. Let's proceed..."
43+
fi
44+
45+
cd $GITPATH
46+
echo -e "Enter a commit message for this new version: \c"
47+
read COMMITMSG
48+
git commit -am "$COMMITMSG"
49+
50+
echo "Tagging new version in git"
51+
git tag -a "$NEWVERSION1" -m "Tagging version $NEWVERSION1"
52+
53+
echo "Pushing latest commit to origin, with tags"
54+
git push origin master
55+
git push origin master --tags
56+
57+
echo
58+
echo "Creating local copy of SVN repo ..."
59+
svn co $SVNURL $SVNPATH
60+
61+
echo "Exporting the HEAD of master from git to the trunk of SVN"
62+
cp -R * $SVNPATH/trunk/
63+
64+
echo "Ignoring github specific files and deployment script"
65+
svn propset svn:ignore "deploy.sh
66+
README.md
67+
.git
68+
.gitignore" "$SVNPATH/trunk/"
69+
70+
echo "Changing directory to SVN and committing to trunk"
71+
cd $SVNPATH/trunk/
72+
# Add all new files that are not set to be ignored
73+
svn status | grep -v "^.[ \t]*\..*" | grep "^?" | awk '{print $2}' | xargs svn add
74+
svn commit --username=$SVNUSER -m "$COMMITMSG"
75+
76+
echo "Creating new SVN tag & committing it"
77+
cd $SVNPATH
78+
svn copy trunk/ tags/$NEWVERSION1/
79+
cd $SVNPATH/tags/$NEWVERSION1
80+
svn commit --username=$SVNUSER -m "Tagging version $NEWVERSION1"
81+
82+
echo "Removing temporary directory $SVNPATH"
83+
rm -fr $SVNPATH/
84+
85+
echo "*** FIN ***"

0 commit comments

Comments
 (0)