Example #1
0
function resizer_route($route)
{
    if (!isset($route['params']['wildcard'])) {
        return false;
    }
    $config = ImageResizer::getConfig();
    $parts = explode('/', $route['params']['wildcard']);
    $params = array('w' => 'width', 'h' => 'height', 'q' => 'quality', 'cw' => 'crop_width', 'ch' => 'crop_height', 's' => 'scale', 'r' => 'rotation', 'xgr' => 'IMG_FILTER_GRAYSCALE', 'xbr' => 'brightness', 'xcn' => 'IMG_FILTER_CONTRAST', 'xco' => 'IMG_FILTER_COLORIZE', 'xed' => 'IMG_FILTER_EDGEDETECT', 'xem' => 'IMG_FILTER_EMBOSS', 'xgb' => 'IMG_FILTER_GAUSSIAN_BLUR', 'xsb' => 'IMG_FILTER_SELECTIVE_BLUR', 'xmr' => 'IMG_FILTER_MEAN_REMOVAL', 'xsm' => 'IMG_FILTER_SMOOTH', 'xpx' => 'IMG_FILTER_PIXELATE', 'cx' => 'cropx', 'cy' => 'cropy');
    $file = null;
    $options = array();
    for ($i = 0; $i < sizeof($parts); $i++) {
        $part = $parts[$i];
        if (is_array($file)) {
            $file[] = $part;
        } else {
            if ($part == 'bw') {
                $options['blackwhite'] = true;
            } else {
                if ($part == 'ratio') {
                    $options['ratio'] = true;
                } else {
                    if ($part == 'crop') {
                        $options['crop'] = true;
                    } else {
                        if (preg_match('/^([a-z]+)([0-9\\.]+)$/', $part, $matches)) {
                            if (isset($params[$matches[1]])) {
                                $options[$params[$matches[1]]] = $matches[2];
                            } else {
                                $options[$matches[1]] = $matches[2];
                            }
                        } else {
                            if ($part == 'f') {
                                $file = array();
                            } else {
                                if (isset($config['size'][$part])) {
                                    $options = array_merge($options, $config['size'][$part]);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (!is_array($file)) {
        return false;
    } else {
        $file = Gregory::absolutePath(implode('/', $file), array($config['path']));
    }
    if (!$file || empty($file)) {
        return false;
    }
    ini_set("memory_limit", $config['memory_limit']);
    $Resizer = new ImageResizer($file);
    $Resizer->resize($options);
    $Resizer->render();
    return true;
}
Example #2
0
 public function logout()
 {
     Gregory::get()->doAction('auth.logout', array($this->getIdentity()));
     $this->auth->clearIdentity();
     if (isset($this->identity->sessions)) {
         $this->identity->sessions->unsetAll();
     }
     $this->identity = null;
 }
Example #3
0
 public static function template($layout, $data = array(), $clean = true)
 {
     if (strlen($layout) < 1024 && file_exists($layout)) {
         $layout = Gregory::get()->renderFile($layout, $data);
     }
     $html = $layout;
     if (isset($data) && is_array($data)) {
         foreach ($data as $key => $content) {
             if (is_array($content)) {
             } else {
                 $html = str_replace('%{' . strtoupper($key) . '}', $content, $html);
             }
         }
     }
     if ($clean) {
         $html = preg_replace('/\\%\\{[^\\}]+\\}/', '', $html);
     }
     return $html;
 }