Example #1
0
 public function set_default_int($name, $value)
 {
     if (is_null($this->get($name))) {
         $this->values[$name] = parse_shorthand_int($value);
     }
 }
Example #2
0
 public function onSearchTermParse($event)
 {
     $matches = array();
     if (preg_match("/^size(<|>|<=|>=|=)(\\d+)x(\\d+)\$/", $event->term, $matches)) {
         $cmp = $matches[1];
         $args = array(int_escape($matches[2]), int_escape($matches[3]));
         $event->add_querylet(new Querylet("width {$cmp} ? AND height {$cmp} ?", $args));
     } else {
         if (preg_match("/^ratio(<|>|<=|>=|=)(\\d+):(\\d+)\$/", $event->term, $matches)) {
             $cmp = $matches[1];
             $args = array(int_escape($matches[2]), int_escape($matches[3]));
             $event->add_querylet(new Querylet("width / height {$cmp} ? / ?", $args));
         } else {
             if (preg_match("/^(filesize|id)(<|>|<=|>=|=)(\\d+[kmg]?b?)\$/i", $event->term, $matches)) {
                 $col = $matches[1];
                 $cmp = $matches[2];
                 $val = parse_shorthand_int($matches[3]);
                 $event->add_querylet(new Querylet("images.{$col} {$cmp} ?", array($val)));
             } else {
                 if (preg_match("/^(hash|md5)=([0-9a-fA-F]*)\$/i", $event->term, $matches)) {
                     $hash = strtolower($matches[2]);
                     $event->add_querylet(new Querylet("images.hash = '{$hash}'"));
                 } else {
                     if (preg_match("/^(filetype|ext)=([a-zA-Z0-9]*)\$/i", $event->term, $matches)) {
                         $ext = strtolower($matches[2]);
                         $event->add_querylet(new Querylet("images.ext = '{$ext}'"));
                     } else {
                         if (preg_match("/^(filename|name)=([a-zA-Z0-9]*)\$/i", $event->term, $matches)) {
                             $filename = strtolower($matches[2]);
                             $event->add_querylet(new Querylet("images.filename LIKE '%{$filename}%'"));
                         } else {
                             if (preg_match("/^posted=(([0-9\\*]*)?(-[0-9\\*]*)?(-[0-9\\*]*)?)\$/", $event->term, $matches)) {
                                 $val = str_replace("*", "%", $matches[1]);
                                 $event->add_querylet(new Querylet("images.posted LIKE '%{$val}%'"));
                             } else {
                                 if (preg_match("/tags(<|>|<=|>=|=)(\\d+)/", $event->term, $matches)) {
                                     $cmp = $matches[1];
                                     $tags = $matches[2];
                                     $event->add_querylet(new Querylet("images.id IN (SELECT DISTINCT image_id FROM image_tags GROUP BY image_id HAVING count(image_id) {$cmp} {$tags})"));
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Example #3
0
/**
 * Figure out PHP's internal memory limit
 *
 * @return int
 */
function get_memory_limit()
{
    global $config;
    // thumbnail generation requires lots of memory
    $default_limit = 8 * 1024 * 1024;
    // 8 MB of memory is PHP's default.
    $shimmie_limit = parse_shorthand_int($config->get_int("thumb_mem_limit"));
    if ($shimmie_limit < 3 * 1024 * 1024) {
        // we aren't going to fit, override
        $shimmie_limit = $default_limit;
    }
    /*
    Get PHP's configured memory limit.
    Note that this is set to -1 for NO memory limit.
    
    http://ca2.php.net/manual/en/ini.core.php#ini.memory-limit
    */
    $memory = parse_shorthand_int(ini_get("memory_limit"));
    if ($memory == -1) {
        // No memory limit.
        // Return the larger of the set limits.
        return max($shimmie_limit, $default_limit);
    } else {
        // PHP has a memory limit set.
        if ($shimmie_limit > $memory) {
            // Shimmie wants more memory than what PHP is currently set for.
            // Attempt to set PHP's memory limit.
            if (ini_set("memory_limit", $shimmie_limit) === FALSE) {
                /*  We can't change PHP's limit, oh well, return whatever its currently set to */
                return $memory;
            }
            $memory = parse_shorthand_int(ini_get("memory_limit"));
        }
        // PHP's memory limit is more than Shimmie needs.
        return $memory;
        // return the current setting
    }
}
Example #4
0
 public function onSearchTermParse(SearchTermParseEvent $event)
 {
     $matches = array();
     // check for tags first as tag based searches are more common.
     if (preg_match("/^tags([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])(\\d+)\$/i", $event->term, $matches)) {
         $cmp = ltrim($matches[1], ":") ?: "=";
         $tags = $matches[2];
         $event->add_querylet(new Querylet('images.id IN (SELECT DISTINCT image_id FROM image_tags GROUP BY image_id HAVING count(image_id) ' . $cmp . ' ' . $tags . ')'));
     } else {
         if (preg_match("/^ratio([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])(\\d+):(\\d+)\$/i", $event->term, $matches)) {
             $cmp = preg_replace('/^:/', '=', $matches[1]);
             $args = array("width{$this->stpen}" => int_escape($matches[2]), "height{$this->stpen}" => int_escape($matches[3]));
             $event->add_querylet(new Querylet("width / height {$cmp} :width{$this->stpen} / :height{$this->stpen}", $args));
         } else {
             if (preg_match("/^(filesize|id)([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])(\\d+[kmg]?b?)\$/i", $event->term, $matches)) {
                 $col = $matches[1];
                 $cmp = ltrim($matches[2], ":") ?: "=";
                 $val = parse_shorthand_int($matches[3]);
                 $event->add_querylet(new Querylet("images.{$col} {$cmp} :val{$this->stpen}", array("val{$this->stpen}" => $val)));
             } else {
                 if (preg_match("/^(hash|md5)[=|:]([0-9a-fA-F]*)\$/i", $event->term, $matches)) {
                     $hash = strtolower($matches[2]);
                     $event->add_querylet(new Querylet('images.hash = :hash', array("hash" => $hash)));
                 } else {
                     if (preg_match("/^(filetype|ext)[=|:]([a-zA-Z0-9]*)\$/i", $event->term, $matches)) {
                         $ext = strtolower($matches[2]);
                         $event->add_querylet(new Querylet('images.ext = :ext', array("ext" => $ext)));
                     } else {
                         if (preg_match("/^(filename|name)[=|:]([a-zA-Z0-9]*)\$/i", $event->term, $matches)) {
                             $filename = strtolower($matches[2]);
                             $event->add_querylet(new Querylet("images.filename LIKE :filename{$this->stpen}", array("filename{$this->stpen}" => "%{$filename}%")));
                         } else {
                             if (preg_match("/^(source)[=|:](.*)\$/i", $event->term, $matches)) {
                                 $source = strtolower($matches[2]);
                                 if (preg_match("/^(any|none)\$/i", $source)) {
                                     $not = $source == "any" ? "NOT" : "";
                                     $event->add_querylet(new Querylet("images.source IS {$not} NULL"));
                                 } else {
                                     $event->add_querylet(new Querylet('images.source LIKE :src', array("src" => "%{$source}%")));
                                 }
                             } else {
                                 if (preg_match("/^posted([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])([0-9-]*)\$/i", $event->term, $matches)) {
                                     $cmp = ltrim($matches[1], ":") ?: "=";
                                     $val = $matches[2];
                                     $event->add_querylet(new Querylet("images.posted {$cmp} :posted{$this->stpen}", array("posted{$this->stpen}" => $val)));
                                 } else {
                                     if (preg_match("/^size([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])(\\d+)x(\\d+)\$/i", $event->term, $matches)) {
                                         $cmp = ltrim($matches[1], ":") ?: "=";
                                         $args = array("width{$this->stpen}" => int_escape($matches[2]), "height{$this->stpen}" => int_escape($matches[3]));
                                         $event->add_querylet(new Querylet("width {$cmp} :width{$this->stpen} AND height {$cmp} :height{$this->stpen}", $args));
                                     } else {
                                         if (preg_match("/^width([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])(\\d+)\$/i", $event->term, $matches)) {
                                             $cmp = ltrim($matches[1], ":") ?: "=";
                                             $event->add_querylet(new Querylet("width {$cmp} :width{$this->stpen}", array("width{$this->stpen}" => int_escape($matches[2]))));
                                         } else {
                                             if (preg_match("/^height([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])(\\d+)\$/i", $event->term, $matches)) {
                                                 $cmp = ltrim($matches[1], ":") ?: "=";
                                                 $event->add_querylet(new Querylet("height {$cmp} :height{$this->stpen}", array("height{$this->stpen}" => int_escape($matches[2]))));
                                             } else {
                                                 if (preg_match("/^order[=|:](id|width|height|filesize|filename)[_]?(desc|asc)?\$/i", $event->term, $matches)) {
                                                     global $order_sql;
                                                     $ord = strtolower($matches[1]);
                                                     $default_order_for_column = preg_match("/^(id|filename)\$/", $matches[1]) ? "ASC" : "DESC";
                                                     $sort = isset($matches[2]) ? strtoupper($matches[2]) : $default_order_for_column;
                                                     $order_sql = "images.{$ord} {$sort}";
                                                     $event->add_querylet(new Querylet("1=1"));
                                                     //small hack to avoid metatag being treated as normal tag
                                                 } else {
                                                     if (preg_match("/^order[=|:]random[_]([0-9]{1,4})\$/i", $event->term, $matches)) {
                                                         global $order_sql;
                                                         //order[=|:]random requires a seed to avoid duplicates
                                                         //since the tag can't be changed during the parseevent, we instead generate the seed during submit using js
                                                         $seed = $matches[1];
                                                         $order_sql = "RAND({$seed})";
                                                         $event->add_querylet(new Querylet("1=1"));
                                                         //small hack to avoid metatag being treated as normal tag
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->stpen++;
 }
Example #5
0
/**
 * Figure out PHP's internal memory limit
 *
 * @retval int
 */
function get_memory_limit()
{
    global $config;
    // thumbnail generation requires lots of memory
    $default_limit = 8 * 1024 * 1024;
    $shimmie_limit = parse_shorthand_int($config->get_int("thumb_mem_limit"));
    if ($shimmie_limit < 3 * 1024 * 1024) {
        // we aren't going to fit, override
        $shimmie_limit = $default_limit;
    }
    ini_set("memory_limit", $shimmie_limit);
    $memory = parse_shorthand_int(ini_get("memory_limit"));
    // changing of memory limit is disabled / failed
    if ($memory == -1) {
        $memory = $default_limit;
    }
    assert($memory > 0);
    return $memory;
}
Example #6
0
 public function onInitExt(InitExtEvent $event)
 {
     global $config;
     $config->set_default_int('thumb_width', 192);
     $config->set_default_int('thumb_height', 192);
     $config->set_default_int('thumb_quality', 75);
     $config->set_default_int('thumb_mem_limit', parse_shorthand_int('8MB'));
     $config->set_default_string('thumb_convert_path', 'convert');
     if (function_exists("exif_read_data")) {
         $config->set_default_bool('image_show_meta', false);
     }
     $config->set_default_string('image_ilink', '');
     $config->set_default_string('image_tlink', '');
     $config->set_default_string('image_tip', '$tags // $size // $filesize');
     $config->set_default_string('upload_collision_handler', 'error');
     $config->set_default_int('image_expires', 60 * 60 * 24 * 31);
     // defaults to one month
 }
Example #7
0
 public function onInitExt($event)
 {
     global $config;
     $config->set_default_int('thumb_width', 192);
     $config->set_default_int('thumb_height', 192);
     $config->set_default_int('thumb_quality', 75);
     $config->set_default_int('thumb_mem_limit', parse_shorthand_int('8MB'));
     $config->set_default_string('thumb_convert_path', 'convert.exe');
     $config->set_default_bool('image_show_meta', false);
     $config->set_default_string('image_ilink', '');
     $config->set_default_string('image_tlink', '');
     $config->set_default_string('image_tip', '$tags // $size // $filesize');
     $config->set_default_string('upload_collision_handler', 'error');
 }