WordPress.org

Plugin Directory

Changeset 751805


Ignore:
Timestamp:
08/05/13 18:22:38 (5 years ago)
Author:
Nefzaoui
Message:
  • Fixed annoying bug of media not showing up in posts when the plugin is active.
  • Refactored code, for more performance.
Location:
foxy-board/trunk
Files:
3 added
1 edited

Legend:

Unmodified
Added
Removed
  • foxy-board/trunk/foxy-board.php

    r751270 r751805  
    1     <?php   
     1<?php   
    22    /*  
    33    Plugin Name: Foxy Board 
    44    Plugin URI: http://blog.nefzaoui.com/  
    5     Version: 0.1 
     5    Version: 0.2 
    66    Author: Ahmed Nefzaoui 
    77    Description: Easily Embed and Preview (Mozilla) Firefox Marketplace Apps in a stylish and modern way. 
    88    */   
    9     wp_register_style('general_style', plugins_url('style.css',__FILE__ )); 
    10     wp_enqueue_style('general_style'); 
     9    class Foxyboard{ 
    1110     
    12     function handle_fx_app_preview($atts){   
     11    static function initialize(){ 
     12        add_action('init',array(__CLASS__,'register_all')); 
     13    } 
     14     
     15    static function handle_fx_app_preview($atts){    
    1316    if(!(isset ($atts[id])))$atts[id] = "arabic-mozilla"; 
    1417    if( (!(isset ($atts[theme]))) || ($atts[theme]!="blue") || ($atts[theme]!="green") )$atts[theme] = "blue"; 
    15     return fetch_single_app($atts); 
     18    return self::fetch_single_app($atts); 
    1619    } 
    1720     
    18     function fetch_single_app($atts){ 
     21    static function fetch_single_app($atts){ 
    1922    $blockstyle="block"; 
    2023    $nonestyle="none"; 
    21     $fx_single_app = curl("https://marketplace.firefox.com/api/v1/apps/app/$atts[id]"); 
     24    $fx_single_app = self::curl("https://marketplace.firefox.com/api/v1/apps/app/$atts[id]"); 
    2225    $single_app_url = "https://marketplace.firefox.com/app/$fx_single_app->slug"; 
    2326    $res='<div class="fx-single-app-container">' 
     
    2831    .'      <div class="fx-single-app-dev-version">Version: '.$fx_single_app->current_version.'</div>' 
    2932    .'      <div class="fx-single-app-dev-name">By: '.$fx_single_app->author.'</div>' 
    30     .'      <div class="fx-single-app-rating"><div class="stars stars-'.getnumreviews($fx_single_app->ratings).'"></div><div class="fx-single-app-review-status">'.getreviewmessage($fx_single_app->ratings).'</div></div>' 
     33    .'      <div class="fx-single-app-rating"><div class="stars stars-'.self::getnumreviews($fx_single_app->ratings).'"></div><div class="fx-single-app-review-status">'.self::getreviewmessage($fx_single_app->ratings).'</div></div>' 
    3134    .'  </div>' 
    3235    .'</div>' 
    3336    .'<div class="qr-code" onclick="this.parentNode.childNodes[3].style.display=&#39;block&#39;">QR Code</div>' 
    34     .'<a target="_blank" href="'.$single_app_url.'" class="gotoappbtn">Get it ('.app_price($fx_single_app->price).')</a>' 
     37    .'<a target="_blank" href="'.$single_app_url.'" class="gotoappbtn">Get it ('.self::app_price($fx_single_app->price).')</a>' 
    3538    .'<img id="mysingleappqr" onclick="this.style=&#39;none&#39;" class="the-qr" src="http://api.qrserver.com/v1/create-qr-code/?size=130x130&data='.$single_app_url.'"></img>' 
    3639    .'</div>'; 
     
    3942    } 
    4043    /* App related functions */ 
    41     function app_price($price){ 
     44    static function app_price($price){ 
    4245    if($price===null){ 
    4346    return "free"; 
     
    4548    return $price; 
    4649    } 
    47     function getreviewmessage($revmsg){ 
     50    static function getreviewmessage($revmsg){ 
    4851    if($revmsg->count==0){ 
    4952    return "No review yet."; 
     
    5255    } 
    5356     
    54     function getnumreviews($revmsg){ 
     57    static function getnumreviews($revmsg){ 
    5558    if($revmsg->count!=0){ 
    5659    return round($revmsg->average); 
     
    5962    } 
    6063    /* END App related functions */ 
    61     function curl($url){ 
     64    static function curl($url){ 
    6265    $f = curl_init($url); 
    6366    curl_setopt($f, CURLOPT_SSL_VERIFYPEER, FALSE); 
     
    6871    return json_decode(curl_exec($f)); 
    6972    } 
    70     function playboard_box_init() { 
     73    static function playboard_box_init() { 
    7174        add_meta_box('playboard_box_init', 'Foxy Board Widget', 'foxy_board_widget', 'post', 'side', 'high'); 
    7275    } 
    7376 
    74     function foxy_board_widget() { 
     77    static function foxy_board_widget() { 
    7578 
    7679        $example = "[firefox-app id=&quot;arabic-mozilla&quot;]"; 
     
    9295       '; 
    9396    } 
     97    static function register_all(){ 
     98                wp_register_style('general_style', plugins_url('style.css',__FILE__ )); 
     99                wp_enqueue_style('general_style');   
     100                wp_enqueue_script('the_js', plugins_url('/jslib.js',__FILE__) ); 
     101                add_action('admin_menu', array(__CLASS__,'playboard_box_init')); 
     102                add_shortcode('firefox-app',array(__CLASS__,handle_fx_app_preview)); 
    94103     
    95     wp_enqueue_script('the_js', plugins_url('/jslib.js',__FILE__) ); 
    96     add_action('admin_menu', 'playboard_box_init'); 
    97     add_shortcode('firefox-app',handle_fx_app_preview); 
    98     ?>   
     104            } 
     105             
     106    } 
     107    FoxyBoard::initialize(); 
     108    ?> 
Note: See TracChangeset for help on using the changeset viewer.