Plugin Directory

Changeset 400869


Ignore:
Timestamp:
06/24/2011 03:11:30 PM (15 years ago)
Author:
CJ_Jackson
Message:

Updated to 0.1.12

Location:
html5avmanager
Files:
79 added
6 edited

Legend:

Unmodified
Added
Removed
  • html5avmanager/trunk/html5avmanager.php

    r399441 r400869  
    55  Plugin URI: http://cj-jackson.com/
    66  Description: A video manager with a Modal-View-Controller and video uploader.
    7   Version: 0.1.11
     7  Version: 0.1.12
    88  Author: Christopher John Jackson
    99  Author URI: http://cj-jackson.com/
  • html5avmanager/trunk/lib/dbal.php

    r398851 r400869  
    2727        $this->DB_PREFIX = $table_prefix . 'html5av_';
    2828        $tempHost = explode(':', $this->DB_HOST);
    29         if(isset($tempHost[1])) {
     29        if (isset($tempHost[1])) {
    3030            $port = $tempHost[1];
    3131        } else {
     
    3434        unset($tempHost);
    3535        if (!is_numeric($port)) {
    36             $host = "unix_socket=" . end(explode(':',$this->DB_HOST));
     36            $host = "unix_socket=" . end(explode(':', $this->DB_HOST));
    3737        } else {
    3838            $array = explode(':', $this->DB_HOST);
     
    4343            unset($array);
    4444        }
    45         parent::__construct('mysql:' . $host . ';dbname=' . $this->DB_NAME,
    46                 $this->DB_USER, $this->DB_PASSWD);
     45        parent::__construct('mysql:' . $host . ';dbname=' . $this->DB_NAME, $this->DB_USER, $this->DB_PASSWD);
    4746    }
    4847
     
    6968
    7069    public function updateTables() {
    71         $curRev = (int)get_option('html5av_manager_dbrev');
     70        $curRev = (int) get_option('html5av_manager_dbrev');
    7271        if ($curRev == self::DBRev) {
    7372            return;
    7473        }
    75        
    76         if($curRev < 2) {
     74
     75        if ($curRev < 2) {
    7776            $this->execFile('update/2.sql');
    7877        }
    79        
     78
    8079        update_option('html5av_manager_dbrev', self::DBRev);
    8180    }
     
    9089    }
    9190
     91    public function save($id, $attr, $table, $idname = 'ID') {
     92        if ($id) {
     93            $param = array();
     94            $names = array();
     95            foreach ($attr as $key => $value) {
     96                $param[] = $value;
     97                $names[] = '`' . $key . '`' . "=?";
     98            }
     99            $names = implode(', ', $names);
     100            $sql = "UPDATE `" . $this->getPrefix() . $table . "`
     101            SET $names
     102            WHERE `$idname`=?;";
     103            $prepare = $this->prepare($sql);
     104            $param[] = $id;
     105            $prepare->execute($param);
     106        } else {
     107            $param = array();
     108            $names = array();
     109            $values = array();
     110            foreach ($attr as $key => $value) {
     111                $param[':param_' . $key] = $value;
     112                $names[] = '`' . $key . '`';
     113                $values[] = ':param_' . $key;
     114            }
     115            $names = implode(', ', $names);
     116            $values = implode(', ', $values);
     117            $sql = "INSERT INTO `" . $this->getPrefix() . $table . "` ($names)
     118            VALUES ($values);";
     119            $prepare = $this->prepare($sql);
     120            $prepare->execute($param);
     121            $id = $this->lastInsertId();
     122        }
     123        if ($prepare->errorCode() != 00000) {
     124            print_r($prepare->errorInfo());
     125        }
     126        return $id;
     127    }
     128
     129    public function delete($id, $table, $idname = 'ID') {
     130        if ($id) {
     131            $sql = "DELETE FROM `" . $this->getPrefix() . $table . "` WHERE `$idname`=?;";
     132            $prepare = $this->prepare($sql);
     133            $prepare->execute(array($id));
     134            if ($prepare->errorCode() != 00000) {
     135                print_r($prepare->errorInfo());
     136            }
     137            return false;
     138        }
     139        return $id;
     140    }
     141
     142    static public function toArray($objects, $name) {
     143        $objects = (array) $objects;
     144        $startPosition = strlen($name) + 1;
     145        array_shift($objects);
     146        $array = array();
     147        foreach ($objects as $property => $value) {
     148            $array[(string) trim(substr($property, $startPosition))] = $value;
     149        }
     150        return $array;
     151    }
     152
    92153}
  • html5avmanager/trunk/lib/model/html5av_audio_video.php

    r399441 r400869  
    33class html5av_audio_video {
    44
    5     private $ID;
     5    private $ID = false;
    66    private $type;
    77    private $poster_path;
     
    1717
    1818    public function getID() {
    19         return $this->ID;
     19        return (int) $this->ID;
    2020    }
    2121
     
    139139
    140140    public function save() {
    141         $db = new html5av_dbal();
    142         $StartParam = array(
    143             'type' => $this->type,
    144             'poster_path' => $this->poster_path,
    145             'poster_filename' => $this->poster_filename,
    146             'width' => $this->width,
    147             'height' => $this->height,
    148             'view' => $this->view,
    149             'title' => $this->title,
    150             'alt' => $this->alt,
    151             'author_id' => $this->author_id,
    152             'created_on' => $this->created_on,
    153             'modified' => $this->modified,
    154         );
    155         if (isset($this->ID)) {
    156             $param = array();
    157             $names = array();
    158             foreach ($StartParam as $key => $value) {
    159                 $param[] = $value;
    160                 $names[] = $key . "=?";
    161             }
    162             $names = implode(', ', $names);
    163             $sql = "UPDATE `" . $db->getPrefix() . "audio_video`
    164             SET $names
    165             WHERE ID=?;";
    166             $prepare = $db->prepare($sql);
    167             $param[] = $this->ID;
    168             $prepare->execute($param);
    169         } else {
    170             $param = array();
    171             $names = array();
    172             $values = array();
    173             foreach ($StartParam as $key => $value) {
    174                 $param[':' . $key] = $value;
    175                 $names[] = $key;
    176                 $values[] = ':' . $key;
    177             }
    178             $names = implode(', ', $names);
    179             $values = implode(', ', $values);
    180             $sql = "INSERT INTO `" . $db->getPrefix() . "audio_video` ($names)
    181             VALUES ($values);";
    182             $prepare = $db->prepare($sql);
    183             $prepare->execute($param);
    184             $this->ID = $db->lastInsertId();
    185         }
     141        $attr = html5av_dbal::toArray($this, __CLASS__);
     142        $db = new html5av_dbal();
     143        $this->ID = $db->save($this->ID, $attr, 'audio_video');
    186144    }
    187145
    188146    public function delete() {
    189         if (isset($this->ID)) {
     147        if ($this->ID) {
    190148            $sources = $this->getSources(true);
    191149            $tracks = $this->getTracks(true);
     
    198156            unlink($this->getPoster());
    199157            $db = new html5av_dbal();
    200             $sql = "DELETE FROM `" . $db->getPrefix() . "audio_video` WHERE ID=?;";
    201             $prepare = $db->prepare($sql);
    202             $prepare->execute(array($this->ID));
    203             unset($this->ID);
     158            $this->ID = $db->delete($this->ID, 'audio_video');
    204159        }
    205160    }
  • html5avmanager/trunk/lib/model/html5av_source.php

    r399441 r400869  
    33class html5av_source {
    44
    5     private $ID;
     5    private $ID = false;
    66    private $order_no;
    77    private $type;
     
    116116
    117117    public function save() {
     118        $attr = html5av_dbal::toArray($this, __CLASS__);
    118119        $db = new html5av_dbal();
    119         $StartParam = array(
    120             'order_no' => $this->order_no,
    121             'type' => $this->type,
    122             'external_mode' => $this->external_mode,
    123             'external_url' => $this->external_url,
    124             'upload_path' => $this->upload_path,
    125             'upload_filename' => $this->upload_filename,
    126             'disabled' => $this->disabled,
    127             'audio_video_id' => $this->audio_video_id
    128         );
    129         if (isset($this->ID)) {
    130             $param = array();
    131             $names = array();
    132             foreach ($StartParam as $key => $value) {
    133                 $param[] = $value;
    134                 $names[] = $key . "=?";
    135             }
    136             $names = implode(', ', $names);
    137             $sql = "UPDATE `" . $db->getPrefix() . "source`
    138             SET $names
    139             WHERE ID=?;";
    140             $prepare = $db->prepare($sql);
    141             $param[] = $this->ID;
    142             $prepare->execute($param);
    143         } else {
    144             $param = array();
    145             $names = array();
    146             $values = array();
    147             foreach ($StartParam as $key => $value) {
    148                 $param[':' . $key] = $value;
    149                 $names[] = $key;
    150                 $values[] = ':' . $key;
    151             }
    152             $names = implode(', ', $names);
    153             $values = implode(', ', $values);
    154             $sql = "INSERT INTO `" . $db->getPrefix() . "source` ($names)
    155             VALUES ($values);";
    156             $prepare = $db->prepare($sql);
    157             $prepare->execute($param);
    158             $this->ID = $db->lastInsertId();
    159         }
     120        $this->ID = $db->save($this->ID, $attr, 'source');
    160121    }
    161122
    162123    public function delete() {
    163         if (isset($this->ID)) {
     124        if ($this->ID) {
    164125            if (!$this->getExternalMode()) {
    165126                unlink($this->getSrc());
    166127            }
    167128            $db = new html5av_dbal();
    168             $sql = "DELETE FROM `" . $db->getPrefix() . "source` WHERE ID=?;";
    169             $prepare = $db->prepare($sql);
    170             $prepare->execute(array($this->ID));
    171             unset($this->ID);
     129            $this->ID = $db->delete($this->ID, 'source');
    172130        }
    173131    }
  • html5avmanager/trunk/lib/model/html5av_track.php

    r399441 r400869  
    33class html5av_track {
    44
    5     private $ID;
     5    private $ID = false;
    66    private $order_no;
    77    private $kind;
     
    134134
    135135    public function save() {
     136        $attr = html5av_dbal::toArray($this, __CLASS__);
    136137        $db = new html5av_dbal();
    137         $StartParam = array(
    138             'order_no' => $this->order_no,
    139             'kind' => $this->kind,
    140             'external_mode' => $this->external_mode,
    141             'external_url' => $this->external_url,
    142             'upload_path' => $this->upload_path,
    143             'upload_filename' => $this->upload_filename,
    144             'srclang' => $this->srclang,
    145             'label' => $this->label,
    146             'disabled' => $this->disabled,
    147             'audio_video_id' => $this->audio_video_id
    148         );
    149         if (isset($this->ID)) {
    150             $param = array();
    151             $names = array();
    152             foreach ($StartParam as $key => $value) {
    153                 $param[] = $value;
    154                 $names[] = $key . "=?";
    155             }
    156             $names = implode(', ', $names);
    157             $sql = "UPDATE `" . $db->getPrefix() . "track`
    158             SET $names
    159             WHERE ID=?;";
    160             $prepare = $db->prepare($sql);
    161             $param[] = $this->ID;
    162             $prepare->execute($param);
    163         } else {
    164             $param = array();
    165             $names = array();
    166             $values = array();
    167             foreach ($StartParam as $key => $value) {
    168                 $param[':' . $key] = $value;
    169                 $names[] = $key;
    170                 $values[] = ':' . $key;
    171             }
    172             $names = implode(', ', $names);
    173             $values = implode(', ', $values);
    174             $sql = "INSERT INTO `" . $db->getPrefix() . "track` ($names)
    175             VALUES ($values);";
    176             $prepare = $db->prepare($sql);
    177             $prepare->execute($param);
    178             $this->ID = $db->lastInsertId();
    179         }
     138        $this->ID = $db->save($this->ID, $attr, 'track');
    180139    }
    181140
    182141    public function delete() {
    183         if (isset($this->ID)) {
     142        if ($this->ID) {
    184143            if (!$this->getExternalMode()) {
    185144                unlink($this->getSrc());
    186145            }
    187146            $db = new html5av_dbal();
    188             $sql = "DELETE FROM `" . $db->getPrefix() . "track` WHERE ID=?;";
    189             $prepare = $db->prepare($sql);
    190             $prepare->execute(array($this->ID));
    191             unset($this->ID);
     147            $this->ID = $db->delete($this->ID, 'track');
    192148        }
    193149    }
  • html5avmanager/trunk/readme.txt

    r399441 r400869  
    55Requires at least: 2.7
    66Tested up to: 3.2
    7 Stable tag: 0.1.11
     7Stable tag: 0.1.12
    88
    99A HTML5 Audio and Video manager that take full advantage of
     
    6262== Changelog ==
    6363
     64= 0.1.12 =
     65* Improved Save and Delete Method in each ORM, now reuses the same code.
     66
    6467= 0.1.11 =
    6568* Unquoted magic quotes that WordPress loves to use, Thank you WordPress!
Note: See TracChangeset for help on using the changeset viewer.