Changeset 452


Ignore:
Timestamp:
Dec 25, 2013 12:47:12 AM (10 years ago)
Author:
anonymous
Message:

Merged changes to lib/SortOrder.inc.php from eli_branch; other minor changes

Location:
trunk/lib
Files:
3 edited

Legend:

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

    r441 r452  
    44 * For details visit the project site: <http://trac.strangecode.com/codebase/>
    55 * Copyright 2001-2012 Strangecode, LLC
    6  * 
     6 *
    77 * This file is part of The Strangecode Codebase.
    88 *
     
    1111 * Free Software Foundation, either version 3 of the License, or (at your option)
    1212 * any later version.
    13  * 
     13 *
    1414 * The Strangecode Codebase is distributed in the hope that it will be useful, but
    1515 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1616 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    1717 * details.
    18  * 
     18 *
    1919 * You should have received a copy of the GNU General Public License along with
    2020 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
     
    8686        'session_name' => '_session',
    8787        'session_use_cookies' => true,
    88        
     88
    8989        // Pass the session-id through URLs if cookies are not enabled?
    9090        // Disable this to prevent session ID theft.
     
    190190        // Initialize default parameters.
    191191        $this->_params = array_merge($this->_params, $this->_param_defaults);
    192        
     192
    193193        // Begin timing script.
    194194        require_once dirname(__FILE__) . '/ScriptTimer.inc.php';
     
    362362            $this->setParam(array('site_url' => sprintf('%s://%s', ('on' == getenv('HTTPS') ? 'https' : 'http'), getenv('HTTP_HOST'))));
    363363        }
    364        
     364
    365365        // In case site_email isn't set, use something halfway presentable.
    366366        if (isset($_SERVER['HTTP_HOST']) && '' != $_SERVER['HTTP_HOST'] && '' == $this->getParam('site_email')) {
     
    375375        // Character set. This should also be printed in the html header template.
    376376        header('Content-type: text/html; charset=' . $this->getParam('character_set'));
    377        
     377
    378378        // Set the version of the codebase we're using.
    379379        $codebase_version_file = dirname(__FILE__) . '/../docs/version.txt';
     
    404404            $this->db->close();
    405405        }
     406        $mem_current = memory_get_usage();
     407        $mem_peak = memory_get_peak_usage();
    406408        $this->timer->stop('_app');
    407         $this->logMsg(sprintf('Script ended gracefully. Execution time: %s. Number of db queries: %s.', $this->timer->getTime('_app'), $num_queries), LOG_DEBUG, __FILE__, __LINE__);
     409        $this->logMsg(sprintf('Script ended gracefully. Execution time: %s. Number of db queries: %s. Memory usage: %s. Peak memory: %s.', $this->timer->getTime('_app'), $num_queries, $mem_current, $mem_peak), LOG_DEBUG, __FILE__, __LINE__);
    408410    }
    409411
     
    434436            return false;
    435437        }
    436        
     438
    437439        // Avoid duplicate full-stops..
    438440        $message = trim(preg_replace('/\.{2}$/', '.', $message));
     
    454456        }
    455457    }
    456    
     458
    457459    /**
    458460     * Returns an array of the raised messages.
     
    472474        return isset($_SESSION['_app'][$this->_ns]['messages']) ? $_SESSION['_app'][$this->_ns]['messages'] : array();
    473475    }
    474    
     476
    475477    /**
    476478     * Resets the message list.
     
    486488            return false;
    487489        }
    488        
     490
    489491        $_SESSION['_app'][$this->_ns]['messages'] = array();
    490492    }
     
    507509            return false;
    508510        }
    509        
     511
    510512        $messages = $this->getRaisedMessages();
    511513        if (!empty($messages)) {
     
    590592            trigger_error(sprintf('Codebase error: log directory (%s) not found or writable.', $this->getParam('log_directory')), E_USER_NOTICE);
    591593        }
    592        
     594
    593595        // Before we get any further, let's see if ANY log events are configured to be reported.
    594596        if ((false === $this->getParam('log_file_priority') || $priority > $this->getParam('log_file_priority'))
     
    626628            $site_hash = md5(empty($_SERVER['SERVER_NAME']) ? $_SERVER['SCRIPT_FILENAME'] : $_SERVER['SERVER_NAME']);
    627629            $lock_dir = $this->getParam('tmp_dir') . "/codebase_msgs_$site_hash/";
    628             // Just use the file and line for the msg_id to limit the number of possible messages 
     630            // Just use the file and line for the msg_id to limit the number of possible messages
    629631            // (the message string itself shan't be used as it may contain innumerable combinations).
    630632            $lock_file = $lock_dir . md5($file . ':' . $line);
     
    647649            }
    648650        }
    649        
     651
    650652        // Data to be stored for a log event.
    651653        $event = array(
     
    685687            mb_send_mail($this->getParam('log_to_sms_address'), $subject, $sms_msg, $headers);
    686688        }
    687    
     689
    688690        // SCREEN ACTION
    689691        if (false !== $this->getParam('log_screen_priority') && $priority <= $this->getParam('log_screen_priority')) {
     
    693695        // Restore original locale.
    694696        setlocale(LC_TIME, $locale);
    695        
     697
    696698        return true;
    697699    }
     
    771773
    772774    /**
    773      * dropQuery() is the opposite of carryQuery(). The specified value will not appear in 
     775     * dropQuery() is the opposite of carryQuery(). The specified value will not appear in
    774776     * url()/ohref()/printHiddenSession() modified URLs unless explicitly written in.
    775      * 
     777     *
    776778     * @access  public
    777779     * @param   mixed   $query_key  The key (or keys, as an array) of the query argument to remove.
  • trunk/lib/Image.inc.php

    r396 r452  
    44 * For details visit the project site: <http://trac.strangecode.com/codebase/>
    55 * Copyright 2001-2012 Strangecode, LLC
    6  * 
     6 *
    77 * This file is part of The Strangecode Codebase.
    88 *
     
    1111 * Free Software Foundation, either version 3 of the License, or (at your option)
    1212 * any later version.
    13  * 
     13 *
    1414 * The Strangecode Codebase is distributed in the hope that it will be useful, but
    1515 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1616 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    1717 * details.
    18  * 
     18 *
    1919 * You should have received a copy of the GNU General Public License along with
    2020 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
     
    4949            // Pattern passed to glob() with $id to match image filenames.
    5050            'filename_pattern' => '%s*',
    51            
     51
    5252            // The path to the image source directory. (Ex: /var/www/htdocs/images)
    5353            'base_path' => '',
    54            
     54
    5555            // The URL to the image directory. (Ex: /images)
    5656            'base_url' => '',
    57            
     57
    5858            // Image to use in the case of a missing image.
    5959            'default_image_file' => '',
     
    6161        $this->_params = array_merge($defaults, $params);
    6262    }
    63    
     63
    6464    /**
    6565     * Tests if an image with specified id exists on the file system.
     
    7777        $filepath = preg_match('!://!', $src) ? $src : getenv('DOCUMENT_ROOT') . $src;
    7878        // Use exif_imagetype to check not only file existence but that of a valid image.
     79        // The return value is the same value that getimagesize() returns in index 2 but exif_imagetype() is much faster.
    7980        return false != @exif_imagetype($filepath);
    8081    }
    81    
     82
    8283    /**
    8384     * Returns the value from getimagesize().
     
    8586     * @access  public
    8687     * @param   string  $id     Unique image identifier.
    87      * @param   int     $key    Which element from the array returned by getimagesize: 
    88      *                   - Index 0 contains the width of the image in pixels. 
    89      *                   - Index 1 contains the height. 
    90      *                   - Index 2 is the type of the image. 
     88     * @param   int     $key    Which element from the array returned by getimagesize:
     89     *                   - Index 0 contains the width of the image in pixels.
     90     *                   - Index 1 contains the height.
     91     *                   - Index 2 is the type of the image.
    9192     *                   - Index 3 is height="yyy" width="xxx" string.
    9293     * @return  mixed   return value of getimagesize.
     
    102103        return isset($img_size[$key]) ? $img_size[$key] : false;
    103104    }
    104    
     105
    105106    /**
    106107     * Returns the URL to the source of image specified by id.
     
    126127
    127128    /**
    128      * Returns an HTML <img> tag with the src set to an image specified by id. 
     129     * Returns an HTML <img> tag with the src set to an image specified by id.
    129130     * Automatically prints image width and height.
    130131     *
     
    142143        $src = $this->oSrc($id);
    143144        $filepath = preg_match('!://!', $src) ? $src : getenv('DOCUMENT_ROOT') . $src;
    144        
     145
    145146        if (false === ($gis = @getimagesize($filepath)) || preg_match('/width|height/', $extra)) {
    146147            $image_size = '';
     
    148149            $image_size = $gis[3];
    149150        }
    150        
     151
    151152        return sprintf('<img src="%s" %s alt="%s" %s />',
    152153            $src,
  • trunk/lib/SortOrder.inc.php

    r396 r452  
    44 * For details visit the project site: <http://trac.strangecode.com/codebase/>
    55 * Copyright 2001-2012 Strangecode, LLC
    6  * 
     6 *
    77 * This file is part of The Strangecode Codebase.
    88 *
     
    1111 * Free Software Foundation, either version 3 of the License, or (at your option)
    1212 * any later version.
    13  * 
     13 *
    1414 * The Strangecode Codebase is distributed in the hope that it will be useful, but
    1515 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1616 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    1717 * details.
    18  * 
     18 *
    1919 * You should have received a copy of the GNU General Public License along with
    2020 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
     
    2424 * SortOrder.inc.php
    2525 *
    26  * SortOrder can determing how to sort results of a database query for display
     26 * SortOrder can determine how to sort results of a database query for display
    2727 * on a listing. It can print column headers that will be links to
    2828 * automatically change the sort and order.
     
    5656    {
    5757        $app =& App::getInstance();
    58        
     58
    5959        // Setup the HTML for printing ASC/DESC paths.
    6060        // This should be converted to CSS someday.
     
    6262        $this->asc_widget = sprintf('<img src="%s/sort_ascending.gif" alt="%s" width="11" height="7" border="0" />', $images_path, _("Ascending"));
    6363        $this->desc_widget = sprintf('<img src="%s/sort_descending.gif" alt="%s" width="11" height="7" border="0" />', $images_path, _("Ascending"));
    64        
     64
    6565        // Setup prefs object.
    6666        $this->prefs = new Prefs($_SERVER['PHP_SELF']);
     
    154154    }
    155155
     156    /**
     157     * Get the current sort and order values.
     158     *
     159     * @return array    Array with keys: sort and order. These can be fed back into the SortOrder::set() method or defaults.
     160     */
     161    function get()
     162    {
     163        return array(
     164            'sort' => $this->prefs->get('sort_by'),
     165            'order' => $this->prefs->get('sort_order'),
     166        );
     167    }
    156168
    157169    /**
     
    202214            } else {
    203215                ?><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
    204             }           
     216            }
    205217        } else {
    206218            echo $col_name;
Note: See TracChangeset for help on using the changeset viewer.