Plugin Directory

Changeset 481551


Ignore:
Timestamp:
12/28/2011 04:53:20 PM (14 years ago)
Author:
CJ_Jackson
Message:

Updated to 2011.12.28!

Location:
mediaembedder
Files:
67 added
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • mediaembedder/trunk/mediaembedder.php

    r469902 r481551  
    55  Plugin URI: http://cj-jackson.com/
    66  Description: An efficient, flexible multimedia embedder
    7   Version: 2011.12.01
     7  Version: 2011.12.28
    88  Author: Christopher John Jackson
    99  Author URI: http://cj-jackson.com/
     
    3232 * SOFTWARE.
    3333 */
    34 
    3534include "list.php";
    3635
    3736class mediaembedder {
     37
    3838    static private $meta;
    3939    static private $url;
    4040    static private $dom;
    41    
     41    static private $param;
     42
    4243    static public function init() {
    4344        global $wpdb;
    44         wp_embed_register_handler('mediaembedder',
    45                     '#http(s?)://(.*)#i',
    46                     array(__CLASS__, 'handler'));
    47         $sql = file_get_contents(dirname(__FILE__).'/sql/main.sql');
     45        wp_embed_register_handler('mediaembedder', '#http(s?)://(.*)#i', array(__CLASS__, 'handler'));
     46        $sql = file_get_contents(dirname(__FILE__) . '/sql/main.sql');
    4847        $sql = str_replace("__prefix__", $wpdb->base_prefix, $sql);
    4948        $wpdb->query($sql);
    50     }
    51    
     49
     50        // Set up param
     51        self::$param = self::cleanParam();
     52
     53        wp_enqueue_script('jquery');
     54    }
     55
     56    static public function getParam() {
     57        return self::$param;
     58    }
     59
    5260    static public function handler($matches, $attr, $url, $rawattr) {
    5361        self::$meta = array();
     
    5664        unset($matches);
    5765        global $mediaembedderlist;
    58         foreach($mediaembedderlist as $list) {
     66        foreach ($mediaembedderlist as $list) {
    5967            $pattern = self::patternWrap($list['re']);
    60             if(preg_match($pattern, $url, $matches)) {
    61                 if(file_exists(self::module($list['module']))) {
     68            if (preg_match($pattern, $url, $matches)) {
     69                if (file_exists(self::module($list['module']))) {
    6270                    include_once self::module($list['module']);
    63                     if(class_exists('me_'.$list['module'])) {
     71                    if (class_exists('me_' . $list['module'])) {
    6472                        $method = 'execute';
    65                         if(isset($list['method'])) {
     73                        if (isset($list['method'])) {
    6674                            $method = $list['method'];
    6775                        }
    68                         if(method_exists('me_'.$list['module'], $method)) {
     76                        if (method_exists('me_' . $list['module'], $method)) {
    6977                            $code = call_user_func(
    70                                     array('me_'.$list['module'], $method),
    71                                     $matches, $url);
    72                             if(!$code) {
     78                                    array('me_' . $list['module'], $method), $matches, $url);
     79                            if (!$code) {
    7380                                return false;
    7481                            }
    75                             if(self::title() && self::title_enabled())
    76                                 return self::title()."\n".$code;
     82                            if (self::title() && self::title_enabled())
     83                                return self::title() . "\n" . $code;
    7784                            else
    7885                                return $code;
     
    8491        return false;
    8592    }
    86    
     93
    8794    static private function patternWrap($pattern, $count = false) {
    8895        return "#" . str_replace("#", "\#", $pattern) . "#i";
    8996    }
    90    
     97
    9198    static public function module($module) {
    9299        return dirname(__FILE__) . '/module/' . $module . '.php';
    93100    }
    94    
     101
    95102    static public function template($module) {
    96103        $module = substr($module, 3);
    97         $custompath = WP_CONTENT_DIR . '/mediaembedder/template/'. $module.'.php';
    98         if(file_exists($custompath)) {
     104        $custompath = WP_CONTENT_DIR . '/mediaembedder/template/' . $module . '.php';
     105        if (file_exists($custompath)) {
    99106            return $custompath;
    100107        } else {
     
    102109        }
    103110    }
    104    
     111
    105112    static public function width() {
    106         if(is_numeric(get_option('mediaembedder_width'))) {
     113        if (is_numeric(get_option('mediaembedder_width'))) {
    107114            return (int) get_option('mediaembedder_width');
    108115        } else {
     
    110117        }
    111118    }
    112    
     119
    113120    static public function height() {
    114         if(is_numeric(get_option('mediaembedder_height'))) {
     121        if (is_numeric(get_option('mediaembedder_height'))) {
    115122            return (int) get_option('mediaembedder_height');
    116123        } else {
     
    118125        }
    119126    }
    120    
     127
    121128    static public function title_enabled() {
    122         if(get_option('mediaembedder_title_enabled') == '1') {
     129        if (get_option('mediaembedder_title_enabled') == '1') {
    123130            return true;
    124131        } else {
     
    126133        }
    127134    }
    128    
     135
    129136    static public function title() {
    130         if(isset(self::$meta['og:title'])) {
     137        if (isset(self::$meta['og:title'])) {
    131138            return self::$meta['og:title'];
    132         } elseif(isset(self::$meta['title'])) {
     139        } elseif (isset(self::$meta['title'])) {
    133140            return self::$meta['title'];
    134141        } else {
     
    136143        }
    137144    }
    138    
     145
    139146    static public function hasher($data) {
    140147        return hash('ripemd160', $data);
    141148    }
    142    
     149
    143150    static public function get_or_setup_data($hash) {
    144151        global $wpdb;
    145152        $record = $wpdb->get_row(
    146153                $wpdb->prepare(
    147                         "SELECT * FROM ".$wpdb->base_prefix."mediaembedder_cache
    148                             WHERE hash=%s",
    149                         array($hash)
     154                        "SELECT * FROM " . $wpdb->base_prefix . "mediaembedder_cache
     155                            WHERE hash=%s", array($hash)
    150156                ), ARRAY_A
    151157        );
    152         if($record) {
     158        if ($record) {
    153159            $data = json_decode($record['data'], true);
    154160        } else {
     
    157163            $nodes = self::$dom->getElementsByTagName('meta');
    158164            $meta = array();
    159             foreach($nodes as $node) {
    160                 if($node->getAttribute('property') != "") {
     165            foreach ($nodes as $node) {
     166                if ($node->getAttribute('property') != "") {
    161167                    $meta[strtolower($node->getAttribute('property'))] = $node->getAttribute('content');
    162168                }
    163                 if($node->getAttribute('name') != "") {
     169                if ($node->getAttribute('name') != "") {
    164170                    $meta[strtolower($node->getAttribute('name'))] = $node->getAttribute('content');
    165171                }
     
    168174            $datajson = json_encode($data);
    169175            $wpdb->insert(
    170                     $wpdb->base_prefix.'mediaembedder_cache',
    171                     array(
    172                         'hash' => $hash,
    173                         'data' => $datajson
    174                     ),
    175                     array(
    176                         '%s',
    177                         '%s'
     176                    $wpdb->base_prefix . 'mediaembedder_cache', array(
     177                'hash' => $hash,
     178                'data' => $datajson
     179                    ), array(
     180                '%s',
     181                '%s'
    178182                    )
    179183            );
     
    182186        return $data;
    183187    }
    184    
     188
    185189    static public function setdata($hash, $data) {
    186190        global $wpdb;
    187191        $data = json_encode($data);
    188192        $wpdb->update(
    189                 $wpdb->base_prefix.'mediaembedder_cache',
    190                 array(
    191                     'data' => $data
    192                 ),
    193                 array(
    194                     'hash' => $hash
    195                 ),
    196                 array(
    197                     '%s',
    198                 ),
    199                 array(
    200                     '%s',
     193                $wpdb->base_prefix . 'mediaembedder_cache', array(
     194            'data' => $data
     195                ), array(
     196            'hash' => $hash
     197                ), array(
     198            '%s',
     199                ), array(
     200            '%s',
    201201                )
    202202        );
    203203    }
    204    
    205     static public function dom_get($url, $tag, $property_name,
    206             $property_value = false, $content_name = false) {
    207         if(self::$dom && self::$url == $url) {
     204
     205    static public function dom_get($url, $tag, $property_name, $property_value = false, $content_name = false) {
     206        if (self::$dom && self::$url == $url) {
    208207            $dom = self::$dom;
    209208        } else {
     
    212211        }
    213212        $nodes = $dom->getElementsByTagName($tag);
    214         foreach($nodes as $node) {
    215             if(!$property_value) {
     213        foreach ($nodes as $node) {
     214            if (!$property_value) {
    216215                return $node->getAttribute($property_name);
    217216            }
    218             if($node->getAttribute($property_name) == $property_value) {
     217            if ($node->getAttribute($property_name) == $property_value) {
    219218                return $node->getAttribute($content_name);
    220219            }
     
    222221        return false;
    223222    }
    224    
    225     static public function doms_get($string, $tag, $property_name,
    226             $property_value = false, $content_name = false) {
     223
     224    static public function doms_get($string, $tag, $property_name, $property_value = false, $content_name = false) {
    227225        $dom = new DOMDocument();
    228226        @$dom->loadHTML($string);
    229227        $nodes = $dom->getElementsByTagName($tag);
    230         foreach($nodes as $node) {
    231             if(!$property_value) {
     228        foreach ($nodes as $node) {
     229            if (!$property_value) {
    232230                return $node->getAttribute($property_name);
    233231            }
    234             if($node->getAttribute($property_name) == $property_value) {
     232            if ($node->getAttribute($property_name) == $property_value) {
    235233                return $node->getAttribute($content_name);
    236234            }
     
    238236        return false;
    239237    }
    240    
     238
    241239    static public function activate() {
    242240        add_option('mediaembedder_title_enabled', 0);
     
    244242        add_option('mediaembedder_height', 320);
    245243    }
    246    
     244
    247245    static public function admin_page() {
    248         add_submenu_page('options-general.php', 'MediaEmbedder',
    249                 'MediaEmbedder', 'manage_options', 'media-embedder',
    250                 array(__CLASS__, 'settings'));
    251        
     246        add_menu_page('MediaEmbedder', 'MediaEmbedder', 'manage_options', 'mediaembedder.php', array(__CLASS__, 'settings'));
     247        add_submenu_page('mediaembedder.php', 'MediaEmbedder', 'MediaEmbedder', 'manage_options', 'mediaembedder.php', array(__CLASS__, 'settings'));
     248        add_submenu_page('mediaembedder.php', 'Template Editor', 'Template Editor', 'manage_options', 'mediaembedder-template.php', array(__CLASS__, 'template_editor'));
     249
    252250        $settings = array(
    253251            'mediaembedder_title_enabled',
     
    260258        unset($settings);
    261259    }
    262    
     260
    263261    static public function settings() {
    264262        $width = self::width();
    265263        $height = self::height();
    266264        $title_enabled = '';
    267         if(self::title_enabled()) {
     265        if (self::title_enabled()) {
    268266            $title_enabled = 'checked';
    269267        }
    270         include dirname(__FILE__). '/settings.php';
    271     }
     268        include dirname(__FILE__) . '/view/settings.php';
     269    }
     270
     271    static public function template_editor() {
     272        include dirname(__FILE__) . '/view/template-editor.php';
     273    }
     274
     275    static private function cleanParam() {
     276        $param = array_merge($_POST, $_GET);
     277
     278        $param = is_array($param) ?
     279                array_map('stripslashes_deep', $param) :
     280                stripslashes($param);
     281
     282        return $param;
     283    }
     284
    272285}
    273286
     
    275288register_activation_hook(__FILE__, array('mediaembedder', 'activate'));
    276289add_action('admin_menu', array('mediaembedder', 'admin_page'));
     290
     291require_once 'api.php';
  • mediaembedder/trunk/readme.txt

    r469902 r481551  
    44Tags: media, embed, video, photo, image, audio
    55Requires at least: 3.2.0
    6 Tested up to: 3.2.1
    7 Stable tag: 2011.12.01
     6Tested up to: 3.3
     7Stable tag: 2011.12.28
    88
    99Multimedia Embedder that relies on template, unlike oEmbed, therefore allowing
     
    6363== Changelog ==
    6464
     65= 2011.12.28 =
     66* Added Template Editor into Admin-CP.
     67
    6568= 2011.12.01 =
    6669* Fixed Screenr regular expression.
Note: See TracChangeset for help on using the changeset viewer.