Plugin Directory

Changeset 710347


Ignore:
Timestamp:
05/09/2013 01:24:44 PM (13 years ago)
Author:
oshingler
Message:

Added new shortcodes and ability to disable hyperlink

Location:
olimometer
Files:
65 added
6 edited

Legend:

Unmodified
Added
Removed
  • olimometer/trunk/olimometer-class.php

    r698522 r710347  
    3939    public $olimometer_stayclassypid = 0;
    4040    public $olimometer_stayclassyeid = 0;
     41    public $olimometer_display_dp;
     42    public $olimometer_display_thousands;
     43    public $olimometer_display_decimal;
     44    public $olimometer_link_disable = 0;
    4145   
    4246    private $olimometer_default_link = "http://www.olivershingler.co.uk/oliblog/olimometer/";
     
    8084        $this->olimometer_stayclassypid = $query_results['olimometer_stayclassypid'];
    8185        $this->olimometer_stayclassyeid = $query_results['olimometer_stayclassyeid'];
     86        $this->olimometer_link_disable = $query_results['olimometer_link_disable'];
    8287       
    8388        if($query_results['olimometer_link'] == "" || $query_results['olimometer_link'] == null) {
     
    8691        else {
    8792            $this->olimometer_link = $query_results['olimometer_link'];
     93        }
     94
     95        if($this->olimometer_number_format == null) {
     96            $this->olimometer_number_format = 0;
    8897        }
    8998
     
    167176                                                                'olimometer_overlay_y' => $this->olimometer_overlay_y,
    168177                                                                'olimometer_stayclassypid' => $this->olimometer_stayclassypid,
    169                                                                 'olimometer_stayclassyeid' => $this->olimometer_stayclassyeid
     178                                                                'olimometer_stayclassyeid' => $this->olimometer_stayclassyeid,
     179                                                                'olimometer_link_disable' => $this->olimometer_link_disable
    170180                                                                 ) );
    171181           
     
    203213                                'olimometer_overlay_y' => $this->olimometer_overlay_y,
    204214                                'olimometer_stayclassypid' => $this->olimometer_stayclassypid,
    205                                 'olimometer_stayclassyeid' => $this->olimometer_stayclassyeid
     215                                'olimometer_stayclassyeid' => $this->olimometer_stayclassyeid,
     216                                'olimometer_link_disable' => $this->olimometer_link_disable
    206217                        ),
    207218                        array( 'olimometer_id' => $this->olimometer_id )
    208219                    );
    209 /*
    210             $wpdb->update($table_name,
    211                         array(  'olimometer_description' => $this->olimometer_description,
    212                                 'olimometer_progress_value' => $olimometer_progress_value,
    213                                 'olimometer_total_value' => $this->olimometer_total_value,
    214                                 'olimometer_currency' => $this->olimometer_currency,
    215                                 'olimometer_thermometer_bg_colour' => $this->olimometer_thermometer_bg_colour,
    216                                 'olimometer_text_colour' => $this->olimometer_text_colour,
    217                                 'olimometer_thermometer_height' => $this->olimometer_thermometer_height,
    218                                 'olimometer_transparent' => $this->olimometer_transparent,
    219                                 'olimometer_show_target' => $this->olimometer_show_target,
    220                                 'olimometer_show_progress' => $this->olimometer_show_progress,
    221                                 'olimometer_progress_label' => $this->olimometer_progress_label,
    222                                 'olimometer_font_height' => $this->olimometer_font_height,
    223                                 'olimometer_suffix' => $this->olimometer_suffix,
    224                                 'olimometer_skin_slug' => $this->olimometer_skin_slug,
    225                                 'olimometer_use_paypal' => $this->olimometer_use_paypal,
    226                                 'olimometer_paypal_username' => $this->olimometer_paypal_username, 
    227                                 'olimometer_paypal_password' => $this->olimometer_paypal_password,
    228                                 'olimometer_paypal_signature' => $this->olimometer_paypal_signature,
    229                                 'olimometer_paypal_extra_value' => $olimometer_paypal_extra_value,
    230                                 'olimometer_number_format' => $this->olimometer_number_format,
    231                                 'olimometer_link' => $this->olimometer_link,
    232                                 'olimometer_overlay' => $this->olimometer_overlay,
    233                                 'olimometer_overlay_image' => $this->olimometer_overlay_image,
    234                                 'olimometer_overlay_x' => $this->olimometer_overlay_x,
    235                                 'olimometer_overlay_y' => $this->olimometer_overlay_y
    236                         ),
    237                         array( 'olimometer_id' => $this->olimometer_id )
    238                     );
    239 */
    240220        }
    241221     
     
    245225    function show($css_class = '')
    246226    {
     227        // Make sure the progress value is updated in case it is pulled in from PayPal etc...
     228        $this->update_progress();
     229   
     230        // And format...
     231        $olimometer_font = "LiberationSans-Regular.ttf";
     232        $image_location = plugins_url('olimometer/thermometer.php', dirname(__FILE__) );   
     233        if($this->olimometer_link_disable == 0) {
     234            $the_olimometer_text = "<a href='".$this->olimometer_link."' target=_blank>";
     235        }
     236        $the_olimometer_text = $the_olimometer_text."<img src='".$image_location."?olimometer_id=".$this->olimometer_id."' border=0";
     237        if(strlen($css_class) > 0) {
     238            $the_olimometer_text = $the_olimometer_text." class='".$css_class."'";
     239        }
     240        $the_olimometer_text = $the_olimometer_text." alt='Olimometer 2.47'>";
     241        if($this->olimometer_link_disable == 0) {
     242            $the_olimometer_text = $the_olimometer_text."</a>";
     243        }
     244       
     245       
     246        return $the_olimometer_text;
     247    }
     248
     249
     250    // Makes sure that the progress value is updated in case it is frmo a dynamic source such as PayPal.
     251    // Should be called before a value is displayed
     252    function update_progress() {
    247253        // If PayPal integration is configured, get the current balance and save it
    248254        if($this->olimometer_use_paypal == 1) {
     
    301307            }
    302308        }
    303    
    304    
    305         $olimometer_font = "LiberationSans-Regular.ttf";
    306 
    307         $image_location = plugins_url('olimometer/thermometer.php', dirname(__FILE__) );
    308        
    309        
    310         $the_olimometer_text = "<a href='".$this->olimometer_link."' target=_blank><img src='".$image_location."?olimometer_id=".$this->olimometer_id."' border=0";
    311         if(strlen($css_class) > 0) {
    312             $the_olimometer_text = $the_olimometer_text." class='".$css_class."'";
    313         }
    314         $the_olimometer_text = $the_olimometer_text." alt='Olimometer 2.46'></a>";
    315        
    316         return $the_olimometer_text;
    317         //return null;
    318309    }
    319310   
     
    438429    }
    439430
     431
     432    // Returns a formatted progress value string
     433    function get_display_progress() {
     434        $this->set_display_format();
     435        $display_string = number_format($this->olimometer_progress_value,$this->olimometer_display_dp,$this->olimometer_display_decimal,$this->olimometer_display_thousands);
     436        return $this->wrap_prefix_and_suffix($display_string);
     437    }
     438
     439    // Returns a formatted total to raise string
     440    function get_display_total() {
     441        $this->set_display_format();
     442        $display_string = number_format($this->olimometer_total_value,$this->olimometer_display_dp,$this->olimometer_display_decimal,$this->olimometer_display_thousands);
     443        return $this->wrap_prefix_and_suffix($display_string);
     444    }
     445
     446    // Returns a formatted '0' value string
     447    function get_display_zero() {
     448        $this->set_display_format();
     449        $display_string = number_format(0,$this->olimometer_display_dp,$this->olimometer_display_decimal,$this->olimometer_display_thousands);
     450        return $this->wrap_prefix_and_suffix($display_string);       
     451    }
     452
     453    // How much do we need to raise to meet the target?
     454    function get_display_remaining() {
     455        $this->set_display_format();
     456        $togo = $this->olimometer_total_value - $this->olimometer_progress_value;
     457
     458        $display_string = number_format($togo,$this->olimometer_display_dp,$this->olimometer_display_decimal,$this->olimometer_display_thousands);
     459        return $this->wrap_prefix_and_suffix($display_string);       
     460    }
     461
     462    function set_display_format() {
     463        // Load display array values
     464        // No dp, no thousands
     465        $olimometer_display_array[0][0] = 0;
     466        $olimometer_display_array[0][1] = '';
     467        $olimometer_display_array[0][2] = '.';
     468        // no dp, thousands marker
     469        $olimometer_display_array[1][0] = 0;
     470        $olimometer_display_array[1][1] = ',';
     471        $olimometer_display_array[1][2] = '.';
     472        // 2dp, no thousands
     473        $olimometer_display_array[2][0] = 2;
     474        $olimometer_display_array[2][1] = '';
     475        $olimometer_display_array[2][2] = '.';
     476        // 2dp, thousands marker
     477        $olimometer_display_array[3][0] = 2;
     478        $olimometer_display_array[3][1] = ',';
     479        $olimometer_display_array[3][2] = '.';
     480        // no dp, period thousands marker
     481        $olimometer_display_array[4][0] = 0;
     482        $olimometer_display_array[4][1] = '.';
     483        $olimometer_display_array[4][2] = ',';
     484        // 2dp (comma), period thousands marker
     485        $olimometer_display_array[5][0] = 2;
     486        $olimometer_display_array[5][1] = '.';
     487        $olimometer_display_array[5][2] = ',';
     488        // no dp, space thousands marker
     489        $olimometer_display_array[6][0] = 0;
     490        $olimometer_display_array[6][1] = ' ';
     491        $olimometer_display_array[6][2] = '.';
     492        // 2dp (comma), space thousands marker
     493        $olimometer_display_array[7][0] = 2;
     494        $olimometer_display_array[7][1] = ' ';
     495        $olimometer_display_array[7][2] = ',';
     496        // 2dp (period), space thousands marker
     497        $olimometer_display_array[8][0] = 2;
     498        $olimometer_display_array[8][1] = '.';
     499        $olimometer_display_array[8][2] = ' ';
     500
     501        $this->olimometer_display_dp = $olimometer_display_array[$this->olimometer_number_format][0];
     502        $this->olimometer_display_thousands = $olimometer_display_array[$this->olimometer_number_format][1];
     503        $this->olimometer_display_decimal = $olimometer_display_array[$this->olimometer_number_format][2];
     504    }   
     505
     506
     507    // Returns a string wrapped with the required prefix and suffix
     508    function wrap_prefix_and_suffix($formatted_value) {
     509        // Figure out prefix and suffix values
     510        switch($this->olimometer_currency) {
     511            case 128:
     512                $currency_symbol = "&#8364;";
     513                //$currency_symbol = "a";
     514                break;
     515            case '':
     516                $currency_symbol = "";
     517                break;
     518            case 'x':
     519                $currency_symbol = "";
     520                break;
     521            case '10000':
     522                $currency_symbol = "kr ";
     523                break;
     524            case '10001':
     525                $currency_symbol = "CHF ";
     526                break;     
     527            default:
     528                $currency_symbol = "&#$this->olimometer_currency;";
     529        }
     530   
     531        switch($this->olimometer_suffix) {
     532            case 128:
     533                $suffix_symbol = "&#8364;";
     534                break;
     535            case '':
     536                $suffix_symbol = "";
     537                break;
     538            case 'x':
     539                $suffix_symbol = "";
     540                break;
     541            case '10000':
     542                $suffix_symbol = " kr";
     543                break;
     544            case '10001':
     545                $suffix_symbol = " CHF";
     546                break;             
     547            default:
     548                $suffix_symbol = "&#$this->olimometer_suffix;";
     549        }
     550        return $currency_symbol.$formatted_value.$suffix_symbol;
     551    }
    440552   
    441553}
  • olimometer/trunk/olimometer.php

    r698555 r710347  
    66Author: Oliver Shingler
    77Author URI: http://www.olivershingler.co.uk
    8 Version: 2.46
     8Version: 2.47
    99*/
    1010
     
    3131add_shortcode('show_olimometer','call_show_olimometer'); // Legacy
    3232add_shortcode('olimometer','call_show_olimometer');
     33add_shortcode('olimometer_progress','olimometer_progress');
     34add_shortcode('olimometer_target','olimometer_target');
     35add_shortcode('olimometer_remaining','olimometer_remaining');
    3336
    3437register_activation_hook(__FILE__,'olimometer_install');
     
    145148    $an_olimometer->olimometer_number_format = $_REQUEST['olimometer_number_format'];
    146149    $an_olimometer->olimometer_link = $_REQUEST['olimometer_link'];
     150    $an_olimometer->olimometer_link_disable = $_REQUEST['olimometer_link_disable'];
    147151    //echo "Overlay = xxx".$_REQUEST['olimometer_overlay']."xxx";
    148152    $an_olimometer->olimometer_overlay = $_REQUEST['olimometer_overlay'];
     
    152156    $an_olimometer->olimometer_stayclassypid = $_REQUEST['olimometer_stayclassypid'];
    153157    $an_olimometer->olimometer_stayclassyeid = $_REQUEST['olimometer_stayclassyeid'];
     158   
    154159   
    155160    // Save it
     
    439444        </table>
    440445       
    441         <p>
    442             You can insert this Olimometer in to your posts and pages by using the following shortcode:<br />
    443             <i><b>[olimometer id=<?php echo $current_olimometer_id; ?>]</b></i>
    444         </p>
     446            You can use the following shortcodes in your posts and pages for this Olimometer:<br />
     447            <ol>
     448                <li>Display the Olimometer: <i><b>[olimometer id=<?php echo $current_olimometer_id; ?>]</b></i></li>
     449                <li>Display the Amount Raised: <i><b>[olimometer_progress id=<?php echo $current_olimometer_id; ?>]</b></i></li>
     450                <li>Display the Target: <i><b>[olimometer_target id=<?php echo $current_olimometer_id; ?>]</b></i></li>
     451                <li>Display the amount remaining to hit Target: <i><b>[olimometer_remaining id=<?php echo $current_olimometer_id; ?>]</b></i></li>
     452
     453            </ol>
    445454       
    446455        <p class="submit"><input type="submit" class="button-primary" name="olimometer_submit" value="Save Changes" /><input type="submit" class="button-primary" name="olimometer_delete" value="Delete this Olimometer" /></p>
     
    773782        </tr>
    774783
     784        <tr class="form-required">
     785            <th scope="row" valign="top"><label for="name">Disable Olimometer Hyperlink</label></th>
     786            <td><input name="olimometer_link_disable" id="olimometer_link_disable" type="radio" value="0"<?php
     787if($current_olimometer->olimometer_link_disable == 0) {
     788    echo " checked";
     789}
     790
     791?>> No<br />
     792                <input name="olimometer_link_disable" id="olimometer_link_disable" type="radio" value="1"<?php
     793if($current_olimometer->olimometer_link_disable == 1) {
     794    echo " checked";
     795}
     796
     797?>> Yes
     798            <p><span class="description">(Optional) Would you like to disable the hyperlink?</span></p></td>
     799        </tr>
     800
    775801
    776802        <!-- Overlay Image Begin -->
     
    969995    }
    970996
     997
     998// Returns the given Olimometer's progress amount.
     999/*function olimometer_progress($olimometer_id) {
     1000    // Load the olimometer
     1001    $current_olimometer = new Olimometer();
     1002    $current_olimometer->load($olimometer_id);
     1003    //return $current_olimometer->show($css_class);
     1004}*/
    9711005
    9721006/***************
     
    12471281************************/
    12481282global $olimometer_db_version;
    1249 $olimometer_db_version = "2.46";
     1283$olimometer_db_version = "2.47";
    12501284
    12511285function olimometer_install() {
     
    12851319  olimometer_stayclassypid int,
    12861320  olimometer_stayclassyeid int,
     1321  olimometer_link_disable int,
    12871322  UNIQUE KEY olimometer_id (olimometer_id)
    12881323    );";
     
    13111346        // Yes it has!
    13121347        // If currently installed database version is less than current version required for this plugin, then we need to upgrade
    1313         $required_db_version = 2.46;
     1348        $required_db_version = 2.47;
    13141349        $installed_db_version = get_option("olimometer_db_version");
    13151350        if($installed_db_version < $required_db_version) {
     
    14651500}
    14661501
    1467 
    1468 
    1469    
     1502// Shortcode to display the current amount raised all formatted nice and that
     1503function olimometer_progress($atts) {
     1504    extract( shortcode_atts( array(
     1505        'id' => '1',
     1506    ), $atts ) );
     1507
     1508    $an_olimometer = new Olimometer();
     1509    $an_olimometer->load($id);
     1510   
     1511    return $an_olimometer->get_display_progress();
     1512}
     1513
     1514// Shortcode to display the target amount all formatted nice and that
     1515function olimometer_target($atts) {
     1516    extract( shortcode_atts( array(
     1517        'id' => '1',
     1518    ), $atts ) );
     1519
     1520    $an_olimometer = new Olimometer();
     1521    $an_olimometer->load($id);
     1522   
     1523    return $an_olimometer->get_display_total();
     1524}
     1525
     1526// Shortcode to display the amount left to raise to meet the target formatted nice and that
     1527function olimometer_remaining($atts) {
     1528    extract( shortcode_atts( array(
     1529        'id' => '1',
     1530    ), $atts ) );
     1531
     1532    $an_olimometer = new Olimometer();
     1533    $an_olimometer->load($id);
     1534   
     1535    return $an_olimometer->get_display_remaining();
     1536}   
    14701537
    14711538
  • olimometer/trunk/readme.txt

    r698522 r710347  
    3939
    4040== Frequently Asked Questions ==
     41
     42= Can I display the progress / target / remaining values in a post or page? =
     43
     44Yup. Use one of these shortcodes, replacing 1 with the actual ID of your Olimometer.
     45
     46* Display the Amount Raised: [olimometer_progress id=1]
     47* Display the Target: [olimometer_target id=1]
     48* Display the amount remaining to hit Target: [olimometer_remaining id=1]
    4149
    4250= How do I add a PayPal Donate button? =
     
    99107
    100108
     109
     110
    101111== Screenshots ==
    102112
     
    108118
    109119== Changelog ==
     120
     121= 2.47 =
     122* Added three new shortcodes to display a formatted value for progress, target and remaining values. See the Olimometer settings page for a list of shortcodes.
     123* You can now disable the Olimometer's hyperlink if required.
    110124
    111125= 2.46 =
     
    248262== Upgrade Notice ==
    249263
     264= 2.47 =
     265* Added three new shortcodes to display a formatted value for progress, target and remaining values. See the Olimometer settings page for a list of shortcodes.
     266* You can now disable the Olimometer's hyperlink if required.
     267
    250268= 2.46 =
    251269* Added support for StayClassy Events in addition to Projects
  • olimometer/trunk/skins.php

    r571083 r710347  
    11<?php
    2 
     2   
    33// Olimometer Skin Loading functions
    44
    5 
    6 
    75class Olimometer_Skins
    86
  • olimometer/trunk/skins.xml

    r571083 r710347  
    11<olimometer>
    2 
    32    <skin>
    4 
    53        <skin_name>Olimometer Default Skin</skin_name>
    6 
    74        <skin_slug>oli-default</skin_slug>
    8 
    95        <bulb_file>therm_bulb.png</bulb_file>
    10 
    116        <bar_file>therm_bar_empty.png</bar_file>
    12 
    137        <top_file>therm_top.png</top_file>
    14 
    158        <bar_colour>a23344</bar_colour>
    16 
    179        <bar_pos>26</bar_pos>
    18 
    1910        <bar_width>4</bar_width>
    20 
    2111        <bar_end>7</bar_end>
    22 
    2312        <text_pos>60</text_pos>
    24 
    2513        <orientation>vertical</orientation>
    26 
    2714    </skin>
    2815
    2916    <skin>
    30 
    3117        <skin_name>Red and Rounded</skin_name>
    32 
    3318        <skin_slug>oli-rounded</skin_slug>
    34 
    3519        <bulb_file>rounded_bottom.png</bulb_file>
    36 
    3720        <bar_file>rounded_bar.png</bar_file>
    38 
    3921        <top_file>rounded_top.png</top_file>
    40 
    4122        <bar_colour>dc3429</bar_colour>
    42 
    4323        <bar_pos>29</bar_pos>
    44 
    4524        <bar_width>18</bar_width>
    46 
    4725        <bar_end>12</bar_end>       
    48 
    4926        <text_pos>60</text_pos>
    50 
    5127        <orientation>vertical</orientation>
    52 
    5328    </skin>
    5429
    5530    <skin>
    56 
    5731        <skin_name>Bold and Chunky</skin_name>
    58 
    5932        <skin_slug>oli-bold-chunky</skin_slug>
    60 
    6133        <bulb_file>bold-chunky-bottom.png</bulb_file>
    62 
    6334        <bar_file>bold-chunky-bar.png</bar_file>
    64 
    6535        <top_file>bold-chunky-top.png</top_file>
    66 
    6736        <bar_colour>d3212f</bar_colour>
    68 
    6937        <bar_pos>15</bar_pos>
    70 
    7138        <bar_width>53</bar_width>
    72 
    7339        <bar_end>22</bar_end>       
    74 
    7540        <text_pos>100</text_pos>
    76 
    7741        <orientation>vertical</orientation>
    78 
    7942    </skin>
    8043
    8144    <skin>
    82 
    8345        <skin_name>Watermaster</skin_name>
    84 
    8546        <skin_slug>oli-watermaster</skin_slug>
    86 
    8747        <bulb_file>watermaster-bottom.png</bulb_file>
    88 
    8948        <bar_file>watermaster-bar.png</bar_file>
    90 
    9149        <top_file>watermaster-top.png</top_file>
    92 
    9350        <bar_colour>3366ff</bar_colour>
    94 
    9551        <bar_pos>84</bar_pos>
    96 
    9752        <bar_width>24</bar_width>
    98 
    9953        <bar_end>130</bar_end>
    100 
    10154        <text_pos>60</text_pos>
    102 
    10355        <orientation>vertical</orientation>
    104 
    10556    </skin>
    10657
    10758    <skin>
    108 
    10959        <skin_name>Our Progress - Blue</skin_name>
    110 
    11160        <skin_slug>oli-ourprogress-blue</skin_slug>
    112 
    11361        <bulb_file>therm_bulb.png</bulb_file>
    114 
    11562        <bar_file>therm_bar_empty.png</bar_file>
    116 
    11763        <top_file>therm_top.png</top_file>
    118 
    11964        <bar_colour>164589</bar_colour>
    120 
    12165        <bar_pos>30</bar_pos>
    122 
    12366        <bar_width>12</bar_width>
    124 
    12567        <bar_end>24</bar_end>
    126 
    12768        <text_pos>70</text_pos>
    128 
    12969        <orientation>vertical</orientation>
    130 
    13170    </skin>
    13271
    13372    <skin>
    134 
    13573        <skin_name>Our Progress - Green</skin_name>
    136 
    13774        <skin_slug>oli-ourprogress-green</skin_slug>
    138 
    13975        <bulb_file>therm_bulb.png</bulb_file>
    140 
    14176        <bar_file>therm_bar_empty.png</bar_file>
    142 
    14377        <top_file>therm_top.png</top_file>
    144 
    14578        <bar_colour>05854a</bar_colour>
    146 
    14779        <bar_pos>30</bar_pos>
    148 
    14980        <bar_width>12</bar_width>
    150 
    15181        <bar_end>24</bar_end>
    152 
    15382        <text_pos>70</text_pos>
    154 
    15583        <orientation>vertical</orientation>       
    156 
    15784    </skin> 
    15885
    15986    <skin>
    160 
    16187        <skin_name>Our Progress - Red</skin_name>
    162 
    16388        <skin_slug>oli-ourprogress-red</skin_slug>
    164 
    16589        <bulb_file>therm_bulb.png</bulb_file>
    166 
    167         <bar_file>therm_bar_empty.png</bar_file>
    168 
     90        <bar_file>therm_bar_empty.png</bar_file>
    16991        <top_file>therm_top.png</top_file>
    170 
    17192        <bar_colour>891619</bar_colour>
    172 
    17393        <bar_pos>30</bar_pos>
    174 
    17594        <bar_width>12</bar_width>
    176 
    17795        <bar_end>24</bar_end>
    178 
    17996        <text_pos>70</text_pos>
    180 
    18197        <orientation>vertical</orientation>       
    182 
    18398    </skin> 
    18499
    185100    <skin>
    186 
    187101        <skin_name>ProgPress - Black</skin_name>
    188 
    189102        <skin_slug>oli-progpress-black</skin_slug>
    190 
    191103        <bulb_file>left.png</bulb_file>
    192 
    193104        <bar_file>middle.png</bar_file>
    194 
    195105        <top_file>right.png</top_file>
    196 
    197106        <bar_colour>000000</bar_colour>
    198 
    199107        <bar_pos>7</bar_pos>
    200 
    201108        <bar_width>19</bar_width>
    202 
    203109        <bar_end>20</bar_end>
    204 
    205110        <text_pos>0</text_pos>
    206 
    207111        <orientation>horizontal</orientation>
    208 
    209112    </skin>
    210113
    211114    <skin>
    212 
    213115        <skin_name>Horizontal - Thin Red</skin_name>
    214 
    215116        <skin_slug>oli-thinredhorizontal</skin_slug>
    216 
    217117        <bulb_file>left.png</bulb_file>
    218 
    219118        <bar_file>middle.png</bar_file>
    220 
    221119        <top_file>right.png</top_file>
    222 
    223120        <bar_colour>ff0000</bar_colour>
    224 
    225121        <bar_pos>0</bar_pos>
    226 
    227122        <bar_width>19</bar_width>
    228 
    229123        <bar_end>20</bar_end>
    230 
    231124        <text_pos>0</text_pos>
    232 
    233125        <orientation>horizontal</orientation>
    234 
    235126    </skin>
    236127
    237128    <skin>
    238 
    239129        <skin_name>Horizontal - Thin Blue</skin_name>
    240 
    241130        <skin_slug>oli-thinbluehorizontal</skin_slug>
    242 
    243131        <bulb_file>left.png</bulb_file>
    244 
    245132        <bar_file>middle.png</bar_file>
    246 
    247133        <top_file>right.png</top_file>
    248 
    249134        <bar_colour>0000ff</bar_colour>
    250 
    251135        <bar_pos>0</bar_pos>
    252 
    253136        <bar_width>19</bar_width>
    254 
    255137        <bar_end>20</bar_end>
    256 
    257138        <text_pos>0</text_pos>
    258 
    259139        <orientation>horizontal</orientation>
    260 
    261140    </skin>
    262141
    263142    <skin>
    264 
    265143        <skin_name>Horizontal - Thin Black</skin_name>
    266 
    267144        <skin_slug>oli-thinblackhorizontal</skin_slug>
    268 
    269145        <bulb_file>left.png</bulb_file>
    270 
    271146        <bar_file>middle.png</bar_file>
    272 
    273147        <top_file>right.png</top_file>
    274 
    275148        <bar_colour>000000</bar_colour>
    276 
    277149        <bar_pos>0</bar_pos>
    278 
    279150        <bar_width>19</bar_width>
    280 
    281151        <bar_end>20</bar_end>
    282 
    283152        <text_pos>0</text_pos>
    284 
    285153        <orientation>horizontal</orientation>
    286 
    287154    </skin>
    288155
  • olimometer/trunk/thermometer.php

    r675314 r710347  
    5757    $total_value = $olimometer_to_display->olimometer_total_value;
    5858    $progress_value = $olimometer_to_display->olimometer_progress_value;
    59     $currency = $olimometer_to_display->olimometer_currency;
    6059    $text_colour = $olimometer_to_display->olimometer_text_colour;
    6160    $transparent = $olimometer_to_display->olimometer_transparent;
     
    6463    $progress_label = $olimometer_to_display->olimometer_progress_label;
    6564    $font_height = $olimometer_to_display->olimometer_font_height;
    66     $suffix = $olimometer_to_display->olimometer_suffix;
    6765
    6866    // Overlay Variables
     
    7270    $overlay_y = $olimometer_to_display->olimometer_overlay_y;
    7371   
    74     if($olimometer_to_display->olimometer_number_format == null) {
    75         $olimometer_number_format = 0;
    76     }
    77     else {
    78         $olimometer_number_format = $olimometer_to_display->olimometer_number_format;
    79     }
    80    
    81    
    82     // Value layout array:
    83    
    84         // No dp, no thousands
    85         $olimometer_display_array[0][0] = 0;
    86         $olimometer_display_array[0][1] = '';
    87         $olimometer_display_array[0][2] = '.';
    88         // no dp, thousands marker
    89         $olimometer_display_array[1][0] = 0;
    90         $olimometer_display_array[1][1] = ',';
    91         $olimometer_display_array[1][2] = '.';
    92         // 2dp, no thousands
    93         $olimometer_display_array[2][0] = 2;
    94         $olimometer_display_array[2][1] = '';
    95         $olimometer_display_array[2][2] = '.';
    96         // 2dp, thousands marker
    97         $olimometer_display_array[3][0] = 2;
    98         $olimometer_display_array[3][1] = ',';
    99         $olimometer_display_array[3][2] = '.';
    100         // no dp, period thousands marker
    101         $olimometer_display_array[4][0] = 0;
    102         $olimometer_display_array[4][1] = '.';
    103         $olimometer_display_array[4][2] = ',';
    104         // 2dp (comma), period thousands marker
    105         $olimometer_display_array[5][0] = 2;
    106         $olimometer_display_array[5][1] = '.';
    107         $olimometer_display_array[5][2] = ',';
    108         // no dp, space thousands marker
    109         $olimometer_display_array[6][0] = 0;
    110         $olimometer_display_array[6][1] = ' ';
    111         $olimometer_display_array[6][2] = '.';
    112         // 2dp (comma), space thousands marker
    113         $olimometer_display_array[7][0] = 2;
    114         $olimometer_display_array[7][1] = ' ';
    115         $olimometer_display_array[7][2] = ',';
    116         // 2dp (period), space thousands marker
    117         $olimometer_display_array[8][0] = 2;
    118         $olimometer_display_array[8][1] = '.';
    119         $olimometer_display_array[8][2] = ' ';
    120        
    121        
    122     // Display converted values:
    123     $olimometer_display_dp = $olimometer_display_array[$olimometer_number_format][0];
    124     $olimometer_display_thousands = $olimometer_display_array[$olimometer_number_format][1];
    125     $olimometer_display_decimal = $olimometer_display_array[$olimometer_number_format][2];
    126     //$olimometer_display_dp = 2;
    127     //$olimometer_display_thousands = ',';
    128     $display_total_value = number_format($total_value,$olimometer_display_dp,$olimometer_display_decimal,$olimometer_display_thousands);
    129     $display_progress_value = number_format($progress_value,$olimometer_display_dp,$olimometer_display_decimal,$olimometer_display_thousands);
    130     $display_zero = number_format(0,$olimometer_display_dp,$olimometer_display_decimal,$olimometer_display_thousands);
    131    
    132     // Figure out prefix and suffix values
    133     switch($currency) {
    134         case 128:
    135             $currency_symbol = "&#8364;";
    136             break;
    137         case '':
    138             $currency_symbol = "";
    139             break;
    140         case 'x':
    141             $currency_symbol = "";
    142             break;
    143         case '10000':
    144             $currency_symbol = "kr ";
    145             break;
    146         case '10001':
    147             $currency_symbol = "CHF ";
    148             break;     
    149         default:
    150             $currency_symbol = "&#$currency;";
    151     }
    152    
    153     switch($suffix) {
    154         case 128:
    155             $suffix_symbol = "&#8364;";
    156             break;
    157         case '':
    158             $suffix_symbol = "";
    159             break;
    160         case 'x':
    161             $suffix_symbol = "";
    162             break;
    163         case '10000':
    164             $suffix_symbol = " kr";
    165             break;
    166         case '10001':
    167             $suffix_symbol = " CHF";
    168             break;             
    169         default:
    170             $suffix_symbol = "&#$suffix;";
    171     }
    172 
     72
     73    $display_total_value = $olimometer_to_display->get_display_total();
     74    $display_progress_value = $olimometer_to_display->get_display_progress();
     75    $display_zero = $olimometer_to_display->get_display_zero();
     76 
    17377
    17478    // Are we making a horizontal or a vertical thermometer?
     
    18084        $therm_bulb = imagecreatefrompng($therm_bulb_file);
    18185        list($therm_bulb_width, $therm_bulb_height) = getimagesize($therm_bulb_file);
    182         //$bulb_ypos = $thermometer_height - $therm_bulb_height;
    183        
    184         //if the progress value and label are being shown, leave space at the bottom of the thermometer for the label.
    185         /*if($show_progress == 1) {
    186             $thermometer_height = $therm_bulb_height - ($font_height*2);
    187         }
    188         else {
    189             $thermometer_height = $therm_bulb_height;
    190         }*/
    191        
    19286       
    19387        //create temporary image
     
    20599        $therm_bar = imagecreatefrompng($therm_bar_file);
    206100        list($therm_bar_width, $therm_bar_height) = getimagesize($therm_bar_file);
    207        
    208        
     101
    209102        //put the top on the thermometer
    210         //$therm_top = imagecreatefromjpeg($therm_top_file);
    211103        $therm_top = imagecreatefrompng($therm_top_file);
    212104        list($therm_top_width, $therm_top_height) = getimagesize($therm_top_file);
    213         //$top_xpos = $thermometer_height-$therm_top_height;
    214        
    215105       
    216106        //work out length of mercury bar
     
    229119       
    230120        //draw mercury line
    231         //$mercury_colour_rgb = imagecolorat($therm_bulb, 27, 3); // Old method of getting colour.. use new skin specified value insead
    232121        $mercury_colour_array = rgb2array($therm_bar_merc_colour);
    233122        $mercury_colour_rgb = imagecolorallocate($temp_new_image, $mercury_colour_array[0], $mercury_colour_array[1], $mercury_colour_array[2]);
     
    244133        // Are we showing the target labels?
    245134        if($show_target == 1) {
    246             $the_box = calculateTextBox($currency_symbol.$display_total_value.$suffix_symbol, $font_name, $font_height, 0);
    247             //$the_box = imagettfbboxextended($font_height, 0, $font_name, $currency_symbol.$total_value.$suffix_symbol);
     135            $the_box = calculateTextBox($olimometer_to_display->get_display_total(), $font_name, $font_height, 0);
    248136            $top_text_width = $the_box["width"];
    249            
    250             // The width of the image file = label width + x_pos of label.
    251             //$new_image_width = $top_text_width + $therm_text_xpos + 2;
    252137        }
    253138       
     
    255140        if($show_progress == 1) {
    256141            // Calculate the width of it
    257             $the_box2 = calculateTextBox($progress_label.' '.$currency_symbol.$display_progress_value.$suffix_symbol, $font_name, $font_height, 0);
    258             //$the_box2 = imagettfbboxextended($font_height, 0, $font_name, $progress_label.' '.$currency_symbol.$progress_value.$suffix_symbol);
     142            $the_box2 = calculateTextBox($progress_label.' '.$olimometer_to_display->get_display_progress(), $font_name, $font_height, 0);
    259143            $progress_text_width = $the_box2["width"] + 2;
    260144            // Is this wider than our previously calculated value?
     
    295179        imagecopyresampled($new_image, $therm_top, $image_height-$therm_top_width, $top_of_therm, 0, 0, $therm_top_width, $therm_top_height, $therm_top_width, $therm_top_height);
    296180        // - Draw mercury line
    297         //imagefilledrectangle($new_image, $therm_bulb_width, $therm_bar_merc_xpos+$top_of_therm, $top_of_bar,$therm_bar_merc_xpos+$therm_bar_merc_width+$top_of_therm, $mercury_colour_rgb);
    298181        imagefilledrectangle($new_image, $therm_bulb_width, $therm_bar_merc_xpos+$top_of_therm, $filled_bar_length+$therm_bulb_width,$therm_bar_merc_xpos+$therm_bar_merc_width+$top_of_therm, $mercury_colour_rgb);
    299182        // - Add value labels to the right of the thermometer
    300183        if($show_target == 1) {
    301             imagettftext($new_image, $font_height, 0, 0, $font_height+2, $text_colour_rgb, $font_name, $currency_symbol.$display_zero.$suffix_symbol);
    302             imagettftext($new_image, $font_height, 0, $image_height-$top_text_width, $font_height+2, $text_colour_rgb, $font_name, $currency_symbol.$display_total_value.$suffix_symbol);
     184            imagettftext($new_image, $font_height, 0, 0, $font_height+2, $text_colour_rgb, $font_name, $olimometer_to_display->get_display_zero());
     185            imagettftext($new_image, $font_height, 0, $image_height-$top_text_width, $font_height+2, $text_colour_rgb, $font_name, $olimometer_to_display->get_display_total());
    303186        }
    304187        // - If the Progress label is needed, show it!
     
    313196                $progress_label_x = ($new_image_width-$progress_text_width)/2;
    314197            }
    315             imagettftext($new_image, $font_height, 0, $progress_label_x, $therm_bulb_height+$top_of_therm+$font_height+5, $text_colour_rgb, $font_name, $progress_label.' '.$currency_symbol.$display_progress_value.$suffix_symbol);
    316             //imagettftext($new_image, $font_height, 0, 30, $therm_bulb_height+4, $text_colour_rgb, $font_name, "Testing");
    317         }
    318         //$image_height-(ceil($font_height/2))
     198            imagettftext($new_image, $font_height, 0, $progress_label_x, $therm_bulb_height+$top_of_therm+$font_height+5, $text_colour_rgb, $font_name, $progress_label.' '.$olimometer_to_display->get_display_progress());
     199        }
    319200        // - Set transparancy if required using supplied background colour as mask
    320201        if ($transparent == 1) {
     
    326207        //if the progress value and label are being shown, leave space at the bottom of the thermometer for the label.
    327208        if($show_progress == 1) {
    328         $thermometer_height = $image_height - ($font_height*2);
     209            $thermometer_height = $image_height - ($font_height*2);
    329210        }
    330211        else {
    331         $thermometer_height = $image_height;
     212            $thermometer_height = $image_height;
    332213        }
    333214       
     
    343224       
    344225        //read bulb image file and place at the bottom of new file
    345         //$therm_bulb = imagecreatefromjpeg($therm_bulb_file);
    346226        $therm_bulb = imagecreatefrompng($therm_bulb_file);
    347227        list($therm_bulb_width, $therm_bulb_height) = getimagesize($therm_bulb_file);
     
    350230       
    351231        //read bar thermometer image
    352         //$therm_bar = imagecreatefromjpeg($therm_bar_file);
    353232        $therm_bar = imagecreatefrompng($therm_bar_file);
    354233        list($therm_bar_width, $therm_bar_height) = getimagesize($therm_bar_file);
     
    356235       
    357236        //put the top on the thermometer
    358         //$therm_top = imagecreatefromjpeg($therm_top_file);
    359237        $therm_top = imagecreatefrompng($therm_top_file);
    360238        list($therm_top_width, $therm_top_height) = getimagesize($therm_top_file);
     
    376254       
    377255        //draw mercury line
    378         //$mercury_colour_rgb = imagecolorat($therm_bulb, 27, 3); // Old method of getting colour.. use new skin specified value insead
    379256        $mercury_colour_array = rgb2array($therm_bar_merc_colour);
    380257        $mercury_colour_rgb = imagecolorallocate($temp_new_image, $mercury_colour_array[0], $mercury_colour_array[1], $mercury_colour_array[2]);
     
    391268        // Are we showing the target labels?
    392269        if($show_target == 1) {
    393             $the_box = calculateTextBox($currency_symbol.$display_total_value.$suffix_symbol, $font_name, $font_height, 0);
    394             //$the_box = imagettfbboxextended($font_height, 0, $font_name, $currency_symbol.$total_value.$suffix_symbol);
     270            $the_box = calculateTextBox($olimometer_to_display->get_display_total(), $font_name, $font_height, 0);
    395271            $top_text_width = $the_box["width"];
    396272           
     
    402278        if($show_progress == 1) {
    403279            // Calculate the width of it
    404         $the_box2 = calculateTextBox($progress_label.' '.$currency_symbol.$display_progress_value.$suffix_symbol, $font_name, $font_height, 0);
    405         //$the_box2 = imagettfbboxextended($font_height, 0, $font_name, $progress_label.' '.$currency_symbol.$progress_value.$suffix_symbol);
     280        $the_box2 = calculateTextBox($progress_label.' '.$olimometer_to_display->get_display_progress(), $font_name, $font_height, 0);
    406281        $progress_text_width = $the_box2["width"] + 2;
    407282        // Is this wider than our previously calculated value?
     
    422297        // Are we using an overlay image?
    423298        if($overlay == 1) {
    424             // Convert the image URL to a real file path
    425             //$wp_root_path = str_replace('/wp-content/themes', '', get_theme_root());
    426             //$converted_overlay_image = $wp_root_path.wp_make_link_relative( $overlay_image );
    427 
    428299            // Load the overlay PNG
    429300            $overlay_image_object = imagecreatefrompng($overlay_image);
     
    465336        // - Add value labels to the right of the thermometer
    466337        if($show_target == 1) {
    467             imagettftext($new_image, $font_height, 0, $therm_text_xpos, $font_height*1.2, $text_colour_rgb, $font_name, $currency_symbol.$display_total_value.$suffix_symbol);
    468             imagettftext($new_image, $font_height, 0, $therm_text_xpos, $bulb_ypos+10, $text_colour_rgb, $font_name, $currency_symbol.$display_zero.$suffix_symbol);
     338            imagettftext($new_image, $font_height, 0, $therm_text_xpos, $font_height*1.2, $text_colour_rgb, $font_name, $olimometer_to_display->get_display_total());
     339            imagettftext($new_image, $font_height, 0, $therm_text_xpos, $bulb_ypos+10, $text_colour_rgb, $font_name, $olimometer_to_display->get_display_zero());
    469340        }
    470341        // - If the Progress label is needed, show it!
    471342        if($show_progress == 1) {
    472         imagettftext($new_image, $font_height, 0, 0, $image_height-(ceil($font_height/2)), $text_colour_rgb, $font_name, $progress_label.' '.$currency_symbol.$display_progress_value.$suffix_symbol);
     343        imagettftext($new_image, $font_height, 0, 0, $image_height-(ceil($font_height/2)), $text_colour_rgb, $font_name, $progress_label.' '.$olimometer_to_display->get_display_progress());
    473344        }
    474345
Note: See TracChangeset for help on using the changeset viewer.