Changeset 497 for trunk/lib


Ignore:
Timestamp:
Sep 15, 2014 9:44:27 PM (10 years ago)
Author:
anonymous
Message:

Beginning the process of adapting codebase to foundation styles.

Location:
trunk/lib
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/App.inc.php

    r492 r497  
    537537                switch ($m['type']) {
    538538                case MSG_ERR:
    539                     echo '<div class="sc-msg-error">' . $m['message'] . '</div>';
     539                    echo '<div data-alert class="sc-msg-error alert-box alert">' . $m['message'] . '<a href="#" class="close">&times;</a></div>';
    540540                    break;
    541541
    542542                case MSG_WARNING:
    543                     echo '<div class="sc-msg-warning">' . $m['message'] . '</div>';
     543                    echo '<div data-alert class="sc-msg-warning alert-box warning">' . $m['message'] . '<a href="#" class="close">&times;</a></div>';
    544544                    break;
    545545
    546546                case MSG_SUCCESS:
    547                     echo '<div class="sc-msg-success">' . $m['message'] . '</div>';
     547                    echo '<div data-alert class="sc-msg-success alert-box success">' . $m['message'] . '<a href="#" class="close">&times;</a></div>';
    548548                    break;
    549549
    550550                case MSG_NOTICE:
    551551                default:
    552                     echo '<div class="sc-msg-notice">' . $m['message'] . '</div>';
     552                    echo '<div data-alert class="sc-msg-notice alert-box info">' . $m['message'] . '<a href="#" class="close">&times;</a></div>';
    553553                    break;
    554 
    555554                }
    556555            }
  • trunk/lib/Auth_SQL.inc.php

    r484 r497  
    471471         * (2) If this number exceeds the login_abuse_max_ips, assume multiple people are logging in under the same account.
    472472        **/
     473        // TODO: make this ipv6 compatible. At the moment, ipv6 addresses are converted into zero for remote_ip_binary.
     474        // http://www.highonphp.com/5-tips-for-working-with-ipv6-in-php
     475        // https://stackoverflow.com/questions/444966/working-with-ipv6-addresses-in-php
    473476        if ($this->getParam('abuse_detection') && !$this->get('login_abuse_exempt')) {
    474477            $qid = $db->query("
  • trunk/lib/DB.inc.php

    r484 r497  
    441441    }
    442442
     443    /**
     444     * Returns the values of an ENUM or SET column, returning them as an array.
     445     *
     446     * @param  string $db_table   database table to lookup
     447     * @param  string $db_col     database column to lookup
     448     * @param  bool   $sort          Sort the output.
     449     * @return array    Array of the set/enum values on success, false on failure.
     450     */
     451    public function getEnumValues($db_table, $db_col, $sort=false)
     452    {
     453        $app =& App::getInstance();
     454
     455        $qid = $this->query("SHOW COLUMNS FROM " . $this->escapeString($db_table) . " LIKE '" . $this->escapeString($db_col) . "'", false);
     456
     457        $row = mysql_fetch_row($qid);
     458        if (preg_match('/^enum|^set/i', $row[1]) && preg_match_all("/'([^']*)'/", $row[1], $matches)) {
     459            if ($sort) {
     460                natsort($matches[1]);
     461            }
     462            return $matches[1];
     463        } else {
     464            $app->logMsg(sprintf('No set or enum fields found in %s.%s', $db_table, $db_col), LOG_ERR, __FILE__, __LINE__);
     465            return false;
     466        }
     467    }
     468
     469
    443470} // End.
    444471
  • trunk/lib/FormValidator.inc.php

    r494 r497  
    209209                    switch ($e['type']) {
    210210                    case MSG_ERR:
    211                         echo '<div class="sc-msg-error">' . $e['message'] . '</div>';
     211                        echo '<div data-alert class="sc-msg-error alert-box alert">' . $e['message'] . '<a href="#" class="close">&times;</a></div>';
    212212                        break;
    213213
    214214                    case MSG_WARNING:
    215                         echo '<div class="sc-msg-warning">' . $e['message'] . '</div>';
     215                        echo '<div data-alert class="sc-msg-warning alert-box warning">' . $e['message'] . '<a href="#" class="close">&times;</a></div>';
    216216                        break;
    217217
    218218                    case MSG_SUCCESS:
    219                         echo '<div class="sc-msg-success">' . $e['message'] . '</div>';
     219                        echo '<div data-alert class="sc-msg-success alert-box alert">' . $e['message'] . '<a href="#" class="close">&times;</a></div>';
    220220                        break;
    221221
    222222                    case MSG_NOTICE:
    223223                    default:
    224                         echo '<div class="sc-msg-notice">' . $e['message'] . '</div>';
     224                        echo '<div data-alert class="sc-msg-notice alert-box info">' . $e['message'] . '<a href="#" class="close">&times;</a></div>';
    225225                        break;
    226226                    }
     
    304304    public function isEmpty($form_name, $msg='')
    305305    {
    306         $this->notEmpty($form_name, $msg);
     306        return $this->notEmpty($form_name, $msg);
    307307    }
    308308
  • trunk/lib/Lock.inc.php

    r484 r497  
    384384    {
    385385        $app =& App::getInstance();
    386 
    387386        ?>
    388387        <form method="post" action="<?php echo oTxt($_SERVER['PHP_SELF']); ?>">
  • trunk/lib/Navigation.inc.php

    r485 r497  
    254254                        // A crumb with no link.
    255255                        $breadcrumbs[] = array(
    256                             'url' => false,
    257                             'title' => sprintf($this->getParam('last_crumb_format'), $page['title'])
     256                            'url' => $_SERVER['REQUEST_URI'],
     257                            'title' => sprintf($this->getParam('last_crumb_format'), $page['title']),
     258                            'class' => 'current'
    258259                        );
    259260                    } else if ($crumb_count > $this->getParam('chop_breadcrumb_links')) {
     
    261262                        $breadcrumbs[] = array(
    262263                            'url' => $page['url'],
    263                             'title' => sprintf($this->getParam('last_crumb_format'), $page['title'])
     264                            'title' => sprintf($this->getParam('last_crumb_format'), $page['title']),
     265                            'class' => '',
    264266                        );
    265267                    }
     
    269271                        $breadcrumbs[] = array(
    270272                            'url' => false,
    271                             'title' => $page['title']
     273                            'title' => $page['title'],
     274                            'class' => 'unavailable',
    272275                        );
    273276                    } else {
     
    275278                        $breadcrumbs[] = array(
    276279                            'url' => $page['url'],
    277                             'title' => $page['title']
     280                            'title' => $page['title'],
     281                            'class' => '',
    278282                        );
    279283                    }
     
    334338    }
    335339
     340    /*
     341    *
     342    *
     343    * @access   public
     344    * @param
     345    * @return
     346    * @author   Quinn Comendant <quinn@strangecode.com>
     347    * @version  1.0
     348    * @since    07 Sep 2014 12:22:19
     349    */
     350    public function getBreadcrumbsUL()
     351    {
     352        $breadcrumbs = $this->getBreadcrumbsArray();
     353        if (!empty($breadcrumbs)) {
     354            ?><ul class="breadcrumbs"><?php
     355            foreach ($breadcrumbs as $b) {
     356                $printclass = '' != $b['class'] ? sprintf(' class="%s"', $b['class']) : '';
     357                printf('<li%s><a href="%s">%s</a></li>', $printclass, $b['url'], $b['title']);
     358            }
     359            ?></ul><?php
     360        }
     361        unset($key, $value);
     362    }
     363
    336364    /**
    337365     * Test if the given URI matches the URL of the current page. By default the URI is tested
  • trunk/lib/SortOrder.inc.php

    r484 r497  
    212212            if ($this->sort_by == $col) {
    213213                if (mb_strtolower($this->order) == 'desc') {
    214                     ?><a href="<?php echo $app->oHREF($_SERVER['PHP_SELF'] . '?sort=' . $col . '&order=ASC'); ?>" title="<?php echo _("Change to ascending sort order"); ?>"><?php echo $this->desc_widget; ?></a><?php echo $col_name; ?><?php
     214                    ?><a href="<?php echo $app->oHREF($_SERVER['PHP_SELF'] . '?sort=' . $col . '&order=ASC'); ?>" title="<?php echo _("Change to ascending sort order"); ?>" class="sc-sort sc-desc"><?php echo $this->desc_widget; ?></a><?php echo $col_name; ?><?php
    215215                } else {
    216                     ?><a href="<?php echo $app->oHREF($_SERVER['PHP_SELF'] . '?sort=' . $col . '&order=DESC'); ?>" title="<?php echo _("Change to descending sort order"); ?>"><?php echo $this->asc_widget; ?></a><?php echo $col_name; ?><?php
     216                    ?><a href="<?php echo $app->oHREF($_SERVER['PHP_SELF'] . '?sort=' . $col . '&order=DESC'); ?>" title="<?php echo _("Change to descending sort order"); ?>" class="sc-sort sc-asc"><?php echo $this->asc_widget; ?></a><?php echo $col_name; ?><?php
    217217                }
    218218            } else {
    219                 ?><a href="<?php echo $app->oHREF($_SERVER['PHP_SELF'] . '?sort=' . $col . '&order=' . $default_order); ?>" title="<?php echo sprintf(_("Sort by %s"), $col_name); ?>"><?php echo $col_name; ?></a><?php
     219                ?><a href="<?php echo $app->oHREF($_SERVER['PHP_SELF'] . '?sort=' . $col . '&order=' . $default_order); ?>" title="<?php echo sprintf(_("Sort by %s"), $col_name); ?>" class="sc-sort"><?php echo $col_name; ?></a><?php
    220220            }
    221221        } else {
  • trunk/lib/Utilities.inc.php

    r487 r497  
    10821082}
    10831083
    1084 /**
    1085  * Returns the remote IP address, taking into consideration proxy servers.
    1086  *
    1087  * @param  bool $dolookup   If true we resolve to IP to a host name,
    1088  *                          if false we don't.
    1089  * @return string    IP address if $dolookup is false or no arg
    1090  *                   Hostname if $dolookup is true
    1091  */
    1092 function getRemoteAddr($dolookup=false)
    1093 {
    1094     $ip = getenv('HTTP_CLIENT_IP');
    1095     if (in_array($ip, array('', 'unknown', 'localhost', '127.0.0.1'))) {
    1096         $ip = getenv('HTTP_X_FORWARDED_FOR');
    1097         if (mb_strpos($ip, ',') !== false) {
    1098             // If HTTP_X_FORWARDED_FOR returns a comma-delimited list of IPs then return the first one (assuming the first is the original).
    1099             $ips = explode(',', $ip, 2);
    1100             $ip = $ips[0];
    1101         }
    1102         if (in_array($ip, array('', 'unknown', 'localhost', '127.0.0.1'))) {
    1103             $ip = getenv('REMOTE_ADDR');
    1104         }
    1105     }
    1106     return $dolookup && '' != $ip ? gethostbyaddr($ip) : $ip;
     1084/*
     1085* Returns the remote IP address, taking into consideration proxy servers.
     1086*
     1087* If strict checking is enabled, we will only trust REMOTE_ADDR or an HTTP header
     1088* value if REMOTE_ADDR is a trusted proxy (configured as an array in $cfg['trusted_proxies']).
     1089*
     1090* @access   public
     1091* @param    bool $dolookup            Resolve to IP to a hostname?
     1092* @param    bool $trust_all_proxies   Should we trust any IP address set in HTTP_* variables? Set to FALSE for secure usage.
     1093* @return   mixed Canonicalized IP address (or a corresponding hostname if $dolookup is true), or false if no IP was found.
     1094* @author   Alix Axel <http://stackoverflow.com/a/2031935/277303>
     1095* @author   Corey Ballou <http://blackbe.lt/advanced-method-to-obtain-the-client-ip-in-php/>
     1096* @author   Quinn Comendant <quinn@strangecode.com>
     1097* @version  1.0
     1098* @since    12 Sep 2014 19:07:46
     1099*/
     1100function getRemoteAddr($dolookup=false, $trust_all_proxies=true)
     1101{
     1102    global $cfg;
     1103
     1104    if (!isset($_SERVER['REMOTE_ADDR'])) {
     1105        // Must be a CLI.
     1106        return false;
     1107    }
     1108
     1109    // Use an HTTP header value only if $trust_all_proxies is true or when REMOTE_ADDR is in our $cfg['trusted_proxies'] array.
     1110    // $cfg['trusted_proxies'] is an array of proxy server addresses we expect to see in REMOTE_ADDR.
     1111    if ($trust_all_proxies || isset($cfg['trusted_proxies']) && is_array($cfg['trusted_proxies']) && in_array($_SERVER['REMOTE_ADDR'], $cfg['trusted_proxies'], true)) {
     1112        // Then it's probably safe to use an IP address value set in an HTTP header.
     1113        // Loop through possible IP address headers.
     1114        foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED') as $key) {
     1115            // Loop through and if
     1116            if (array_key_exists($key, $_SERVER)) {
     1117                foreach (explode(',', $_SERVER[$key]) as $addr) {
     1118                    $addr = canonicalIPAddr(trim($addr));
     1119                    if (false !== filter_var($addr, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
     1120                        return $dolookup && '' != $addr ? gethostbyaddr($addr) : $addr;
     1121                    }
     1122                }
     1123            }
     1124        }
     1125    }
     1126
     1127    $addr = canonicalIPAddr(trim($_SERVER['REMOTE_ADDR']));
     1128    return $dolookup && $addr ? gethostbyaddr($addr) : $addr;
     1129}
     1130
     1131/*
     1132* Converts an ipv4 IP address in hexadecimal form into canonical form (i.e., it removes the prefix).
     1133*
     1134* @access   public
     1135* @param    string  $addr   IP address.
     1136* @return   string          Canonical IP address.
     1137* @author   Sander Steffann <http://stackoverflow.com/a/12436099/277303>
     1138* @author   Quinn Comendant <quinn@strangecode.com>
     1139* @version  1.0
     1140* @since    15 Sep 2012
     1141*/
     1142function canonicalIPAddr($addr)
     1143{
     1144    // Known prefix
     1145    $v4mapped_prefix_bin = pack('H*', '00000000000000000000ffff');
     1146
     1147    // Parse
     1148    $addr_bin = inet_pton($addr);
     1149
     1150    // Check prefix
     1151    if (substr($addr_bin, 0, strlen($v4mapped_prefix_bin)) == $v4mapped_prefix_bin) {
     1152        // Strip prefix
     1153        echo 'prefix matches';
     1154        $addr_bin = substr($addr_bin, strlen($v4mapped_prefix_bin));
     1155    }
     1156
     1157    // Convert back to printable address in canonical form
     1158    return inet_ntop($addr_bin);
    11071159}
    11081160
     
    11171169 * @return  mixed   Returns the network that matched on success, false on failure.
    11181170 */
    1119 function ipInRange($ip, $networks)
     1171function ipInRange($addr, $networks)
    11201172{
    11211173    if (!is_array($networks)) {
     
    11231175    }
    11241176
    1125     $ip_binary = sprintf('%032b', ip2long($ip));
     1177    $addr_binary = sprintf('%032b', ip2long($addr));
    11261178    foreach ($networks as $network) {
    11271179        if (preg_match('![\d\.]{7,15}/\d{1,2}!', $network)) {
     
    11291181            list($cidr_ip, $cidr_bitmask) = explode('/', $network);
    11301182            $cidr_ip_binary = sprintf('%032b', ip2long($cidr_ip));
    1131             if (mb_substr($ip_binary, 0, $cidr_bitmask) === mb_substr($cidr_ip_binary, 0, $cidr_bitmask)) {
     1183            if (mb_substr($addr_binary, 0, $cidr_bitmask) === mb_substr($cidr_ip_binary, 0, $cidr_bitmask)) {
    11321184               // IP address is within the specified IP range.
    11331185               return $network;
    11341186            }
    11351187        } else {
    1136             if ($ip === $network) {
     1188            if ($addr === $network) {
    11371189               // IP address exactly matches.
    11381190               return $network;
  • trunk/lib/Version.inc.php

    r484 r497  
    266266        ");
    267267        if (!$record = mysql_fetch_assoc($qid)) {
    268             $app->raiseMsg(sprintf(_("Version ID %s%s not found."), $version_id, (empty($record['version_title']) ? '' : ' (' . $record['version_title'] . ')')), MSG_WARNING, __FILE__, __LINE__);
    269             $app->logMsg(sprintf('Version ID %s%s not found.', $version_id, (empty($record['version_title']) ? '' : ' (' . $record['version_title'] . ')')), LOG_WARNING, __FILE__, __LINE__);
     268            $app->raiseMsg(sprintf(_("Version %s%s not found."), $version_id, (empty($record['version_title']) ? '' : ' (' . $record['version_title'] . ')')), MSG_WARNING, __FILE__, __LINE__);
     269            $app->logMsg(sprintf('Version %s%s not found.', $version_id, (empty($record['version_title']) ? '' : ' (' . $record['version_title'] . ')')), LOG_WARNING, __FILE__, __LINE__);
    270270            return false;
    271271        }
     
    274274        // Ensure saved db columns match current table schema.
    275275        if (!$db->columnExists($record['record_table'], array_keys($data), $this->getParam('db_schema_strict'))) {
    276             $app->raiseMsg(sprintf(_("Version ID %s%s is not compatible with the current database table."), $version_id, (empty($record['version_title']) ? '' : ' (' . $record['version_title'] . ')')), MSG_ERR, __FILE__, __LINE__);
    277             $app->logMsg(sprintf('Version ID %s%s restoration failed, DB schema does not match for table %s.', $version_id, (empty($record['version_title']) ? '' : ' (' . $record['version_title'] . ')'), $record['record_table']), LOG_ALERT, __FILE__, __LINE__);
     276            $app->raiseMsg(sprintf(_("Version %s%s is not compatible with the current database table."), $version_id, (empty($record['version_title']) ? '' : ' (' . $record['version_title'] . ')')), MSG_ERR, __FILE__, __LINE__);
     277            $app->logMsg(sprintf('Version %s%s restoration failed, DB schema does not match for table %s.', $version_id, (empty($record['version_title']) ? '' : ' (' . $record['version_title'] . ')'), $record['record_table']), LOG_ALERT, __FILE__, __LINE__);
    278278            return false;
    279279        }
Note: See TracChangeset for help on using the changeset viewer.