Changeset 84


Ignore:
Timestamp:
Apr 8, 2006 3:15:27 AM (18 years ago)
Author:
scdev
Message:

minor improvements

Location:
trunk/lib
Files:
3 edited

Legend:

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

    r83 r84  
    343343
    344344    /**
    345      * Add a message to the string globalmessage, which is printed in the header.
     345     * Add a message to the session, which is printed in the header.
    346346     * Just a simple way to print messages to the user.
    347347     *
     
    856856    }
    857857
    858     /**
    859      * Redirects a user by calling the App::dieURL(). It will use:
    860      * 1. the stored boomerang URL, it it exists
    861      * 2. the referring URL, it it exists.
    862      * 3. an empty string, which will force App::dieURL to use the default URL.
    863      */
    864     function dieBoomerangURL($id=null, $carry_args=null)
     858    /*
     859    * Redirects a user by calling App::dieURL(). It will use:
     860    * 1. the stored boomerang URL, it it exists
     861    * 2. a specified $default_url, it it exists
     862    * 3. the referring URL, it it exists.
     863    * 4. redirect_home_url configuration variable.
     864    *
     865    * @access   public
     866    * @param    string  $id             Identifier for this script.
     867    * @param    mixed   $carry_args     Additional arguments to carry in the URL automatically (see App::oHREF()).
     868    * @param    string  $default_url    A default URL if there is not a valid specified boomerang URL.
     869    * @return   bool                    False if the session is not running. No return otherwise.
     870    * @author   Quinn Comendant <quinn@strangecode.com>
     871    * @since    31 Mar 2006 19:17:00
     872    */
     873    function dieBoomerangURL($id=null, $carry_args=null, $default_url=null)
    865874    {
    866875        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
     
    883892            // Delete stored boomerang.
    884893            $this->deleteBoomerangURL($id);
     894        } else if (isset($default_url)) {
     895            $url = $default_url;
     896        }
    885897        } else if (!refererIsMe()) {
    886898            // Ensure that the redirecting page is not also the referrer.
     
    893905        }
    894906
    895 
    896         // A redirection will never happen immediatly twice.
     907        // A redirection will never happen immediately twice.
    897908        // Set the time so ensure this doesn't happen.
    898909        $_SESSION[$this->app]['boomerang']['time'] = time();
     
    916927            return false;
    917928        }
    918         // A redirection will never happen immediatly after setting the boomerangURL.
     929        // A redirection will never happen immediately after setting the boomerangURL.
    919930        // Set the time so ensure this doesn't happen. See App::validBoomerangURL for more.
    920931
  • trunk/lib/NodeHeirarchy.inc.php

    r83 r84  
    342342     * @return string   The parents as an array of serialized node identifiers.
    343343     */
    344     function getParents($child_type=null, $child_id=null)
     344    function getParents($child_type=null, $child_id=null, $type_constraint=null, $order='')
    345345    {
    346346        if (!isset($child_type) || !isset($child_id)) {
     
    352352                return false;
    353353            }
     354        }
     355
     356        $in_clause = '';
     357        if (isset($type_constraint)) {
     358            if (!is_array($type_constraint)) {
     359                $type_constraint = array($type_constraint);
     360            }
     361            $in_clause = "AND parent_type IN ('" . join("','", array_map('addslashes', $type_constraint)) . "')";
    354362        }
    355363
     
    359367            WHERE child_type = '" . addslashes($child_type) . "'
    360368            AND child_id = '" . addslashes($child_id) . "'
     369            $in_clause
     370            " . addslashes($order) . "
    361371        ");
    362372
  • trunk/lib/Utilities.inc.php

    r83 r84  
    192192
    193193/**
    194  * Encodes an email into a user (at) domain (dot) com format.
     194 * Encodes an email into a "user at domain dot com" format.
    195195 *
    196196 * @access  public
     
    205205    $replace = array($at, $dot);
    206206    return preg_replace($search, $replace, $email);
     207}
     208
     209/**
     210 * Turns "a really long string" into "a rea...string"
     211 *
     212 * @access  public
     213 * @param   string  $str    Input string
     214 * @param   int     $len    Maximum string length.
     215 * @param   string  $where  Where to cut the string. One of: 'start', 'middle', or 'end'.
     216 * @return  string          Truncated output string
     217 * @author  Quinn Comendant <quinn@strangecode.com>
     218 * @since   29 Mar 2006 13:48:49
     219 */
     220function truncate($str, $len, $where='middle')
     221{
     222    $part1 = floor(($len - 3) / 2);
     223    $part2 = ceil(($len - 3) / 2);
     224    switch ($where) {
     225    case 'start' :
     226        return preg_replace(array(sprintf('/^.{4,}(.{%s})$/', $part1 + $part2), '/\s*\.{3,}\s*/'), array('...$1', '...'), $str);
     227        break;
     228    default :
     229    case 'middle' :
     230        return preg_replace(array(sprintf('/^(.{%s}).{4,}(.{%s})$/', $part1, $part2), '/\s*\.{3,}\s*/'), array('$1...$2', '...'), $str);
     231        break;   
     232    case 'end' :
     233        return preg_replace(array(sprintf('/^(.{%s}).{4,}$/', $part1 + $part2), '/\s*\.{3,}\s*/'), array('$1...', '...'), $str);
     234        break;   
     235    }
    207236}
    208237
Note: See TracChangeset for help on using the changeset viewer.