Plugin Directory

Changeset 1606364


Ignore:
Timestamp:
03/02/2017 08:03:21 AM (9 years ago)
Author:
spindogs
Message:

release v1.6.4

Location:
wp-platform/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • wp-platform/trunk/classes/Model.php

    r1514036 r1606364  
    5555    {
    5656        global $wpdb;
     57        global $Database;
    5758
    5859        if ($this->is_loaded && !$row) {
     
    8687            $q = $this->query();
    8788            $this->query_debug = $q;
    88             $row = $wpdb->get_row($q);
     89
     90            if (isset($Database)) {
     91                $row = $Database->getRow($q);
     92                $row = (object)$row;
     93            } else {
     94                $row = $wpdb->get_row($q);
     95            }
    8996
    9097            if (!$row) {
     
    166173    {
    167174        global $wpdb;
     175        global $Database;
    168176        $static = get_called_class();
    169177
     
    179187                    WHERE id = ".intval($this->id)."";
    180188
    181             $wpdb->query($q);
     189            if (isset($Database)) {
     190                $Database->query($q);
     191            } else {
     192                $wpdb->query($q);
     193            }
    182194
    183195        }
     
    391403    {
    392404        global $wpdb;
     405        global $Database;
    393406
    394407        if (property_exists($this, 'id') && $this->id) {
     
    405418        }
    406419
    407         $rtn = $wpdb->get_results($q, $output_type);
     420        if (isset($Database)) {
     421            $rtn = $Database->getResults($q);
     422        } else {
     423            $rtn = $wpdb->get_results($q, $output_type);
     424        }
    408425
    409426        if (strpos($q, 'SQL_CALC_FOUND_ROWS') !== false) {
    410             $this->total = $wpdb->get_var("SELECT FOUND_ROWS()");
     427
     428            if (isset($Database)) {
     429                $this->total = $Database->getVal("SELECT FOUND_ROWS()");
     430            } else {
     431                $this->total = $wpdb->get_var("SELECT FOUND_ROWS()");
     432            }
     433
    411434            $this->total = intval($this->total);
    412435        }
  • wp-platform/trunk/classes/Mysql.php

    r1531633 r1606364  
    44class Mysql {
    55
    6     /**
    7      * @param array $values
    8      * @param string $table
    9      * @param string $on_duplicate IGNORE|UPDATE
    10      * @param bool $auto_condense
    11      * @return int
    12      */
    13     public static function autoCreate($values, $table, $on_duplicate='', $auto_condense=true)
    14     {
    15         global $wpdb;
    16 
    17         if ($auto_condense) {
    18             $values = self::condense($values, $table);
    19         }
    20 
    21         $q = "INSERT ".($on_duplicate == 'IGNORE' ? 'IGNORE' : '');
    22         $q .= " INTO `".$table."` (";
    23 
    24         foreach ($values as $key => $val) {
    25             $q .= "`".$key."`,";
    26         }
    27 
    28         $q = substr($q, 0, -1);
    29 
    30         $q .= ") VALUES (";
    31 
    32         foreach ($values as $key => $val) {
    33             $q .= Security::escSQL($val).",";
    34         }
    35 
    36         $q = substr($q, 0, -1);
    37 
    38         $q .= ")";
    39 
    40         if ($on_duplicate == 'UPDATE') {
    41 
    42             $q .= "ON DUPLICATE KEY UPDATE ";
    43 
    44             foreach ($values as $key => $val) {
    45                 $q .= "`".$key."` = VALUES(`".$key."`),";
    46             }
    47 
    48             $q = substr($q, 0, -1);
    49 
    50         }
    51 
    52         $wpdb->query($q);
    53 
    54         return $wpdb->insert_id;
    55 
    56     }
    57 
    58     /**
    59      * @param array $values
    60      * @param int|array $where
    61      * @param string $table
    62      * @param bool $auto_condense
    63      * @return bool
    64      */
    65     public static function autoUpdate($values, $where, $table, $auto_condense=true)
    66     {
    67         global $wpdb;
    68 
    69         if (!$where) {
    70             return false;
    71         }
    72 
    73         if ($auto_condense) {
    74             $values = self::condense($values, $table);
    75         }
    76 
    77         if (!is_array($where)) {
    78             $where = array('id' => $where); //default string to id
    79         }
    80 
    81         $q = "UPDATE `".$table."` SET ";
    82 
    83         foreach ($values as $field => $value) {
    84             $q .= "`".$field."` = ".Security::escSQL($value).",";
    85         }
    86 
    87         $q = substr($q, 0, -1);
    88         $q .= " {where}";
    89 
    90         $q = self::autoQuery($q, $where);
    91 
    92         if ($wpdb->query($q)) {
    93             return true;
    94         } else {
    95             return false;
    96         }
    97 
    98     }
    99 
    100     /**
    101      * @param string $q
    102      * @param int|array|bool $where
    103      * @param array|bool $orderby
    104      * @param string|bool $limit
    105      * @return string
    106      */
    107     public static function autoQuery($q, $where=false, $orderby=false, $limit=false)
    108     {
    109         $q_where = " WHERE 1=1";
    110 
    111         if ($where) {
    112 
    113             if (!is_array($where)) {
    114                 $where = array('id' => $where); //default string to id
    115             }
    116 
    117             foreach ($where as $field => $value) {
    118                 $q_where .= " AND `".$field."` = ".Security::escSQL($value)."";
    119             }
    120 
    121         }
    122 
    123         $q_orderby = '';
    124 
    125         if ($orderby) {
    126 
    127             $first_arg = reset($orderby);
    128             $q_orderby = " ORDER BY";
    129 
    130             if (!is_array($first_arg)) {
    131                 $orderby = array(array($orderby[0], $orderby[1])); //convert single arguments to the multi format
    132             }
    133 
    134             foreach ($orderby as $r) {
    135                 $q_orderby .= "`".$r[0]."` ".self::escASC($r[1]).",";
    136             }
    137 
    138             $q_orderby = trim($q_orderby, ','); //get rid of last comma
    139 
    140         }
    141 
    142         $q_limit = '';
    143 
    144         if ($limit) {
    145             $q_limit = " LIMIT ".$limit;
    146         }
    147 
    148         $q = str_replace('{where}', $q_where, $q);
    149         $q = str_replace('{orderby}', $q_orderby, $q);
    150         $q = str_replace('{limit}', $q_limit, $q);
    151 
    152         return $q;
    153 
    154     }
    155 
    156     /**
    157      * @param string $table
    158      * @param string $field
    159      * @param array $options
    160      * @param int|array $where
    161      * @return bool
    162      */
    163     public static function updateOptions($table, $field, $options, $where)
    164     {
    165         global $wpdb;
    166 
    167         $q = "DELETE FROM `".$table."`
    168                 {where}";
    169 
    170         $q = self::autoQuery($q, $where);
    171 
    172         $wpdb->query($q);
    173 
    174         $options = (array)$options;
    175 
    176         foreach ($options as $option) {
    177 
    178             $values = array();
    179             $values[$field] = $option;
    180             $values += $where;
    181 
    182             self::autoCreate($values, $table);
    183 
    184         }
    185 
    186         return true;
    187     }
    188 
    189     /**
    190      * @param array $values
    191      * @param string $table
    192      * @return array
    193      */
    194     public static function condense($values, $table)
    195     {
    196         $fields = self::getColumns($table);
    197         $rtn = Filter::array_condense($values, $fields);
    198 
    199         return $rtn;
    200 
    201     }
    202 
    203     /**
    204      * @param string $table
    205      * @return array
    206      */
    207     public static function getColumns($table)
    208     {
    209         global $wpdb;
    210 
    211         $schema = $wpdb->get_results("SHOW COLUMNS FROM `".$table."`");
    212         $rtn = array();
    213 
    214         foreach ($schema as $r) {
    215             $rtn[$r->Field] = $r->Field;
    216         }
    217 
    218         return $rtn;
    219 
    220     }
     6    /**
     7     * @param array $values
     8     * @param string $table
     9     * @param string $on_duplicate IGNORE|UPDATE
     10     * @param bool $auto_condense
     11     * @return int
     12     */
     13    public static function autoCreate($values, $table, $on_duplicate='', $auto_condense=true)
     14    {
     15        global $Database;
     16        global $wpdb;
     17
     18        if ($auto_condense) {
     19            $values = self::condense($values, $table);
     20        }
     21
     22         $q = "INSERT ".($on_duplicate == 'IGNORE' ? 'IGNORE' : '');
     23         $q .= " INTO `".$table."` (";
     24
     25         foreach ($values as $key => $val) {
     26             $q .= "`".$key."`,";
     27         }
     28
     29         $q = substr($q, 0, -1);
     30
     31         $q .= ") VALUES (";
     32
     33         foreach ($values as $key => $val) {
     34             $q .= Security::escSQL($val).",";
     35         }
     36
     37         $q = substr($q, 0, -1);
     38
     39         $q .= ")";
     40
     41         if ($on_duplicate == 'UPDATE') {
     42
     43             $q .= "ON DUPLICATE KEY UPDATE ";
     44
     45            foreach ($values as $key => $val) {
     46                $q .= "`".$key."` = VALUES(`".$key."`),";
     47            }
     48
     49            $q = substr($q, 0, -1);
     50
     51         }
     52
     53        if (isset($Database)) {
     54            $Database->query($q);
     55            return $Database->getInsertId();
     56        } else {
     57            $wpdb->query($q);
     58            return $wpdb->insert_id;
     59        }
     60
     61     }
     62
     63    /**
     64     * @param array $values
     65     * @param int|array $where
     66     * @param string $table
     67     * @param bool $auto_condense
     68     * @return bool
     69     */
     70    public static function autoUpdate($values, $where, $table, $auto_condense=true)
     71    {
     72        global $Database;
     73        global $wpdb;
     74
     75         if (!$where) {
     76             return false;
     77         }
     78
     79        if ($auto_condense) {
     80            $values = self::condense($values, $table);
     81        }
     82
     83         if (!is_array($where)) {
     84             $where = array('id' => $where); //default string to id
     85         }
     86
     87         $q = "UPDATE `".$table."` SET ";
     88
     89         foreach ($values as $field => $value) {
     90            $q .= "`".$field."` = ".Security::escSQL($value).",";
     91         }
     92
     93         $q = substr($q, 0, -1);
     94         $q .= " {where}";
     95
     96         $q = self::autoQuery($q, $where);
     97
     98        if (isset($Database)) {
     99            $result = $Database->query($q);
     100        } else {
     101            $result = $wpdb->query($q);
     102        }
     103
     104         if ($result) {
     105             return true;
     106         } else {
     107             return false;
     108        }
     109
     110     }
     111
     112    /**
     113     * @param string $q
     114     * @param int|array|bool $where
     115     * @param array|bool $orderby
     116     * @param string|bool $limit
     117     * @return string
     118     */
     119    public static function autoQuery($q, $where=false, $orderby=false, $limit=false)
     120    {
     121        $q_where = " WHERE 1=1";
     122
     123        if ($where) {
     124
     125            if (!is_array($where)) {
     126                $where = array('id' => $where); //default string to id
     127            }
     128
     129            foreach ($where as $field => $value) {
     130                $q_where .= " AND `".$field."` = ".Security::escSQL($value)."";
     131            }
     132
     133        }
     134
     135        $q_orderby = '';
     136
     137        if ($orderby) {
     138
     139            $first_arg = reset($orderby);
     140            $q_orderby = " ORDER BY";
     141
     142            if (!is_array($first_arg)) {
     143                $orderby = array(array($orderby[0], $orderby[1])); //convert single arguments to the multi format
     144            }
     145
     146            foreach ($orderby as $r) {
     147                $q_orderby .= "`".$r[0]."` ".self::escASC($r[1]).",";
     148            }
     149
     150            $q_orderby = trim($q_orderby, ','); //get rid of last comma
     151
     152        }
     153
     154        $q_limit = '';
     155
     156        if ($limit) {
     157            $q_limit = " LIMIT ".$limit;
     158        }
     159
     160        $q = str_replace('{where}', $q_where, $q);
     161        $q = str_replace('{orderby}', $q_orderby, $q);
     162        $q = str_replace('{limit}', $q_limit, $q);
     163
     164        return $q;
     165
     166     }
     167
     168    /**
     169     * @param string $table
     170     * @param string $field
     171     * @param array $options
     172     * @param int|array $where
     173     * @return bool
     174     */
     175    public static function updateOptions($table, $field, $options, $where)
     176    {
     177        global $Database;
     178        global $wpdb;
     179
     180         $q = "DELETE FROM `".$table."`
     181                 {where}";
     182
     183         $q = self::autoQuery($q, $where);
     184
     185        if (isset($Database)) {
     186            $Database->query($q);
     187        } else {
     188            $wpdb->query($q);
     189        }
     190
     191        $options = (array)$options;
     192
     193         foreach ($options as $option) {
     194
     195             $values = array();
     196             $values[$field] = $option;
     197             $values += $where;
     198
     199             self::autoCreate($values, $table);
     200
     201         }
     202
     203         return true;
     204     }
     205
     206    /**
     207     * @param array $values
     208     * @param string $table
     209     * @return array
     210     */
     211    public static function condense($values, $table)
     212    {
     213        $fields = self::getColumns($table);
     214        $rtn = Filter::array_condense($values, $fields);
     215
     216        return $rtn;
     217
     218    }
     219
     220    /**
     221     * @param string $table
     222     * @return array
     223     */
     224    public static function getColumns($table)
     225    {
     226        global $Database;
     227        global $wpdb;
     228
     229        if (isset($Database)) {
     230            $schema = $Database->getResults("SHOW COLUMNS FROM `".$table."`");
     231        } else {
     232            $schema = $wpdb->get_results("SHOW COLUMNS FROM `".$table."`");
     233        }
     234
     235        $rtn = array();
     236
     237        foreach ($schema as $r) {
     238            $r = (object)$r;
     239            $rtn[$r->Field] = $r->Field;
     240        }
     241
     242        return $rtn;
     243
     244    }
    221245
    222246}
  • wp-platform/trunk/classes/Setup.php

    r1605197 r1606364  
    4646        self::$platform_path = WP_PLUGIN_DIR.'/wp-platform';
    4747        self::$app_path = get_template_directory().'/app';
     48        self::$template_path = get_template_directory();
    4849
    4950        //autoloader
  • wp-platform/trunk/classes/Twitter.php

    r1605197 r1606364  
    44use \TwitterOAuth;
    55
    6 require_once('../vendor/twitteroauth/twitteroauth.php');
     6require_once(Setup::$platform_path.'/vendor/twitteroauth/twitteroauth.php');
    77
    88class Twitter {
  • wp-platform/trunk/plugin.php

    r1605197 r1606364  
    22/**
    33 * Plugin Name: WP-Platform
    4  * Version: 1.6.0
     4 * Version: 1.6.4
    55 * Description: Provides platform to allow developers to build bespoke functionality in an MVC and OOP fashion
    66 */
Note: See TracChangeset for help on using the changeset viewer.