예제 #1
0
 /**
  *
  * @return Pimple
  */
 public static function instance()
 {
     if (!self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
예제 #2
0
 public static function minify($filename)
 {
     require_once Pimple::instance()->getRessource('lib/minify/min/lib/Minify/CSS.php');
     require_once Pimple::instance()->getRessource('lib/minify/min/lib/Minify/CSS/Compressor.php');
     $isPimple = String::StartsWith($filename, Pimple::instance()->getBaseDir());
     $base = dirname($isPimple ? substr($filename, strlen(Pimple::instance()->getBaseDir() . 'www/')) : substr($filename, strlen(Pimple::instance()->getSiteDir()))) . '/';
     $base = $isPimple ? Settings::get(Pimple::URL) . $base : Url::basePath() . $base;
     return Minify_CSS::minify(String::normalize(file_get_contents($filename), false), array('prependRelativePath' => $base));
 }
예제 #3
0
 protected function tagJson($attrs)
 {
     require_once Pimple::instance()->getRessource('lib/Zend/Json.php');
     $value = $attrs->value;
     if ($attrs->striptags) {
         $value = ArrayUtil::stripValues($value);
     }
     $result = Zend_Json::encode($value);
     return $result;
 }
예제 #4
0
 /**
  *
  * @return couchClient
  */
 public static function client()
 {
     if (self::$_client == null) {
         $basepath = Pimple::instance()->getRessource('lib/phponcouch/');
         require_once "{$basepath}/couch.php";
         require_once "{$basepath}/couchAdmin.php";
         require_once "{$basepath}/couchClient.php";
         require_once "{$basepath}/couchDocument.php";
         require_once "{$basepath}/couchReplicator.php";
         self::$_client = new couchClient(Settings::get(self::URL), Settings::get(self::NAME));
     }
     return self::$_client;
 }
예제 #5
0
파일: Pdf.php 프로젝트: hofmeister/Pimple
 public static function append(MPdf $pdf, $template, $data, $containerViewFile = null)
 {
     require_once Pimple::instance()->getRessource('lib/mpdf50/mpdf.php');
     if ($containerViewFile) {
         $container = new View($containerViewFile);
     }
     $view = new View($template);
     if (!is_array($data)) {
         $data = ArrayUtil::fromObject($data);
     }
     $cData = $data;
     $cData['body'] = $view->render($data);
     $css = "";
     if ($container) {
         $html = $container->render($cData);
         self::readCss($pdf, $container);
     } else {
         $html = $cData['body'];
     }
     self::readCss($pdf, $view);
     $pdf->WriteHTML($html);
 }
예제 #6
0
 /**
  * Renders a wizard section. Each wizard section must be defined in the controller and a wizard section must 
  * corrospond to a method in the controller
  * @param string id | id of the section
  * @container
  */
 protected function tagWizard($attrs)
 {
     $current = Pimple::instance()->getAction();
     $w = Wizard::get($attrs->id);
     if ($w) {
         $cs = $w->getStep($current);
     }
     if ($cs) {
         $title = '<ul class="horizontal divided">';
         $before = true;
         foreach ($w->getSteps() as $s) {
             if ($s->getId() == $current) {
                 $title .= sprintf('<li class="active">%s</li>', $s->getTitle());
                 $before = false;
             } else {
                 $add = '';
                 if ($before) {
                     $add = ' class="done"';
                 }
                 if ($cs->canJumpTo($s->getId())) {
                     $title .= sprintf('<li%s><a href="%s">%s</a></li>', $add, Url::makeLink(Pimple::instance()->getController(), $s->getId()), $s->getTitle());
                 } else {
                     $title .= sprintf('<li%s>%s</li>', $add, $s->getTitle());
                 }
             }
         }
         $title .= '</ul>';
         return sprintf('<div class="panel wizard %s"><h2>%s<strong>' . T('Step %s of %s', $cs->getStep(), $w->getNumSteps()) . '</strong></h2>%s</div>', $attrs->class, $title, $this->body());
     } else {
         return sprintf('<div class="panel">%s</div>', $this->body());
     }
 }
예제 #7
0
파일: View.php 프로젝트: hofmeister/Pimple
 public function getInternalCssFiles()
 {
     $nodes = $this->getNodeTree()->getElementsByTagNameNS('p', 'stylesheet');
     $files = array();
     foreach ($nodes as $node) {
         if ($node->getAttribute('local') == 'false') {
             $base = Pimple::instance()->getBaseDir() . 'www/';
         } else {
             $base = Pimple::instance()->getSiteDir();
         }
         $path = $node->getAttribute('path');
         if (String::StartsWith($path, "http://") || String::StartsWith($path, "https://")) {
             $base = '';
         }
         $files[] = $base . $path;
     }
     return $files;
 }
예제 #8
0
//Load pimple
if ($_SERVER['PIMPLE_PATH']) {
    require_once rtrim($_SERVER['PIMPLE_PATH'], '/') . '/bootstrap.php';
} elseif ($_ENV['PIMPLE_PATH']) {
    require_once rtrim($_ENV['PIMPLE_PATH'], '/') . '/bootstrap.php';
} else {
    die('PIMPLE_PATH NOT FOUND');
}
//Set url to pimple/www/
Settings::set(Pimple::URL, '/pimple/');
require_once 'CouchDb.php';
require_once 'model/SessionModel.php';
require_once 'model/UserModel.php';
require_once 'service/UserService.php';
require_once 'service/ProjectService.php';
//Check for local config file (db settings etc.)
if (isset($_SERVER['HOME']) && !isset($_ENV['HOME'])) {
    $_ENV['HOME'] = $_SERVER['HOME'];
}
$localconfig = $_ENV['HOME'] . '/.pimple/scrumbanana.php';
if (isset($_ENV['HOME']) && file_exists($localconfig)) {
    require_once $localconfig;
}
Pimple::instance()->setSiteName('ScrumBanana.com');
Settings::set(Mail::FROM_NAME, 'ScrumBanana.com');
//Overrule all mails to send to this address - if debug is enabled
Settings::set(Mail::TEST_MAIL, '*****@*****.**');
//Default date formats
Settings::set(Date::DATE_FORMAT, 'd.m.Y');
Settings::set(Date::DATETIME_FORMAT, 'd.m.Y H:i:s');
Settings::set(Date::TIME_FORMAT, 'H:i:s');
예제 #9
0
 protected function asCSV($array, $firstRowHeader = true, $seperator = ';')
 {
     $this->setSkipView(true);
     header('Content-type: text/csv');
     if ($firstRowHeader) {
         $cols = array();
         foreach ($array[0] as $colName => $val) {
             $cols[] = $colName;
         }
         echo implode($seperator, $cols) . chr(10);
     }
     for ($i = 0; $i < count($array); $i++) {
         $vals = array();
         foreach ($array[$i] as $val) {
             $vals[] = $val;
         }
         echo implode($seperator, $vals) . chr(10);
     }
     echo $value;
     Pimple::instance()->end();
 }
예제 #10
0
파일: Url.php 프로젝트: hofmeister/Pimple
 public static function refresh()
 {
     Pimple::instance()->save();
     header(sprintf('Location: %s', self::current()));
 }
예제 #11
0
require_once 'lib/controller/PimpleController.php';
//Handlers
require_once 'lib/handlers/MessageHandler.php';
require_once 'lib/handlers/SessionHandler.php';
require_once 'lib/handlers/AccessHandler.php';
//Main class
require_once 'lib/Pimple.php';
require_once 'lib/TagLib.php';
require_once 'lib/taglib/CoreTagLib.php';
require_once 'lib/taglib/ValueTagLib.php';
require_once 'lib/taglib/BasicTagLib.php';
require_once 'lib/taglib/FormTagLib.php';
require_once 'lib/taglib/WidgetTagLib.php';
require_once 'lib/taglib/JavascriptTagLib.php';
require_once 'lib/taglib/UserTagLib.php';
require_once 'lib/taglib/JSTemplateTagLib.php';
//Add pimple lib to include path
IncludePath::instance()->addPath(Pimple::instance()->getBaseDir() . '/lib');
//Add pimple ressources lib to include path
IncludePath::instance()->addPath(Pimple::instance()->getRessource('lib/'), 1);
define('CACHEDIR', Dir::normalize(BASEDIR) . 'cache');
Dir::ensure(CACHEDIR);
Pimple::instance()->registerTagLib('c', new CoreTagLib());
Pimple::instance()->registerTagLib('val', new ValueTagLib());
Pimple::instance()->registerTagLib('p', new BasicTagLib());
Pimple::instance()->registerTagLib('user', new UserTagLib());
Pimple::instance()->registerTagLib('f', new FormTagLib());
Pimple::instance()->registerTagLib('w', new WidgetTagLib());
Pimple::instance()->registerTagLib('js', new JavascriptTagLib());
Pimple::instance()->registerTagLib('jst', new JSTemplateTagLib());
예제 #12
0
<?php

define('BASEURL', dirname($_SERVER['SCRIPT_NAME']) . '/');
require_once 'settings.php';
//Init session
SessionHandler::instance()->setSessionKey('SCRUMSID');
SessionHandler::instance()->setSession(new SessionModel());
SessionHandler::instance()->setExpires(3600 * 24 * 7);
SessionHandler::instance()->init();
//Init pimple
Pimple::instance()->run();
예제 #13
0
파일: Zend.php 프로젝트: hofmeister/Pimple
 public static function _use($zendClass)
 {
     require_once Pimple::instance()->getRessource('lib/' . str_replace('_', '/', $zendClass) . '.php');
 }
예제 #14
0
 /**
  * Render form element container
  *
  * @param string id | Id of input element
  * @param string label | the label of the field
  * @param string help  | help text for this field
  * @param string instructions | intructions on how to fill out field
  * @param string description | Description of the field / value
  * @param string name | name of the input element
  * @param string cClass | CSS class to apply to form element container
  * @param string cStyle | CSS styles to apply to form element container
  * @param string eClass | CSS class to apply to div element
  * @param string eStyle | CSS styles to apply to div element
  * @param boolean readonly | make field readonly (defaults to false)
  * @param boolean disabled | make field disabled (defaults to false)
  * @param boolean simple | Makes the field behave more as a std html input field (defaults to false)
  * @param boolean composit | Render the field with label, input and instructions (defaults to true)
  * @param boolean small | render field without label and instructions (defaults to false)
  * @param boolean nolabel | render field without label (defaults to false)
  * @param boolean noinstructions | render field without instructions (defaults to false)
  */
 private function formElementContainer($formElement, $attrs)
 {
     $classes = array();
     $elmClasses = explode(' ', $attrs->eClass);
     $errorMessages = array();
     $errors = array();
     $classes[] = 'line';
     if ($attrs->simple) {
         $attrs->composit = 'false';
         $classes[] = 'simple';
     }
     if ($attrs->small || $attrs->composit == 'false') {
         //Remove small attr...
         $attrs->nolabel = true;
         $attrs->noinstructions = true;
     } else {
         $classes[] = 'composit';
     }
     $label = $attrs->label;
     $help = $attrs->help;
     $validators = Pimple::instance()->getControllerInstance()->getFieldValidation($attrs->name);
     $hasValidators = $attrs->readonly != 'true' && !$attrs->disabled && count($validators) > 0;
     if ($hasValidators) {
         if (String::EndsWith($attrs->name, '[]')) {
             $i = Util::count($attrs->name);
             $fieldName = str_replace('[]', "[{$i}]", $attrs->name);
         } else {
             $fieldName = $attrs->name;
         }
         $errors = Validate::getFieldErrors($fieldName);
         if (!$errors) {
             $errors = array();
         }
         $classes[] = 'v-enabled';
         foreach ($validators as $validator) {
             $errorMessages[] = sprintf('<div style="display:none;" class="error-%s">%s</div>', current(explode('[', $validator)), Validate::getValidator($validator)->getError());
             $classes[] = "v-{$validator}";
         }
         if (in_array('required', $validators)) {
             $info = T('This field is required');
             if (!$attrs->help) {
                 $attrs->help = $info;
             }
             if ($label) {
                 $label .= sprintf('<span class="required" title="%s">*</span>', $info);
             }
         }
     }
     if ($attrs->cClass) {
         $classes[] = $attrs->cClass;
     }
     unset($attrs->cClass);
     $hasInstructions = ($attrs->help || $hasValidators || count($errors) > 0) && !$attrs->noinstructions;
     unset($attrs->noinstructions);
     if (!$hasInstructions && !$attrs->instructions) {
         $classes[] = 'no-instructions';
     }
     if ($attrs->nolabel) {
         $classes[] = 'no-label';
     }
     if (count($errors) > 0) {
         $classes[] = 'error';
     } else {
         if ($attrs->name && Validate::isFieldValid($attrs->name)) {
             $classes[] = 'valid';
         }
     }
     $output = '<div class="form-item ' . implode(' ', $classes) . '"';
     if ($attrs->cStyle) {
         $output .= sprintf(' style="%s" ', $attrs->cStyle);
     }
     $output .= '>';
     $label = trim($label);
     if (!$label && (!$attrs->simple && $attrs->composit != 'false')) {
         $label = '&nbsp;';
     }
     if ($label) {
         if (!$attrs->nolabel || $attrs->small || $attrs->composit == 'false') {
             if ($attrs->id) {
                 $output .= sprintf('<label for="%s">%s</label>', $attrs->id, $label);
             } else {
                 $output .= sprintf('<label>%s</label>', $label);
             }
         }
     }
     unset($attrs->nolabel);
     unset($attrs->simple);
     unset($attrs->composit);
     unset($attrs->small);
     unset($attrs->currentValue);
     $output .= '<div class="element ' . implode(' ', $elmClasses) . '" style="' . $attrs->eStyle . '">' . $formElement . '</div>';
     $renderedInstructions = false;
     if ($hasInstructions) {
         $output .= sprintf('<div class="instructions">
                                 <div class="help">%s</div>
                                 <div class="valid">%s</div>
                                 <div class="error">%s</div>
                                 %s
                             </div>', $attrs->help, T('Field is valid'), current($errors), implode(chr(10), $errorMessages));
         $renderedInstructions = true;
     } else {
         if ($attrs->instructions) {
             $output .= sprintf('<div class="instructions">
                                 %s
                             </div>', $attrs->instructions);
             $renderedInstructions = true;
         }
     }
     if (!$renderedInstructions && count($errors) > 0) {
         $output .= '<div class="description error">' . current($errors) . '</div>';
     } else {
         if ($attrs->description) {
             $output .= '<div class="description">' . $attrs->description . '</div>';
         }
     }
     $output .= '</div>';
     return $output;
 }
예제 #15
0
파일: Phtml.php 프로젝트: hofmeister/Pimple
    public function toPHP($filename = null) {
        
        if ($this->getTag() == 'phtml') {
            $result =  $this->getInnerPHP();
            if ($filename)
                file_put_contents($filename,$result);
            return $result;
        }
            

        $str = "<";
        $method = false;
        
        $tagName = '';


        if ($this->getNs()) {
            $method = true;
            $str = '<?=$'.$this->getNs().'->callTag("'.$this->getTag().'",';
        } else {
            $str .= $this->getTag();
        }

        
        if (count($this->getAttrs()) > 0) {
            if ($method)
                $str .= 'array(';
            else
                $str .= ' ';
            foreach($this->getAttrs() as $name=>$val) {
                if ($method)
                    $str .= sprintf('"%s"=>%s,',$name,$this->processAttrValue($val));
                else
                    $str .= sprintf('%s="%s" ',$name,$val);
            }
            if ($method)
                $str = trim($str,',').'),';
            else
                $str = trim($str);
        } else if ($method) {
            $str .= 'array(),';
        }
        if ($this->isContainer()) {

            if (!$method)
                $str .= '>';
            else
                $body = '';
            
            if ($method)
                $body .= $this->getInnerPHP();
            else
                $str .= $this->getInnerPHP();
            
            if ($method) {
                $taglibs = Pimple::instance()->getTagLibs();
                if ($taglibs[$this->getNs()] && $taglibs[$this->getNs()]->isPreprocess()) {
                    $tag = $this->getTag();
                    $str = $taglibs[$this->getNs()]->callTag($tag,$this->getAttrs(),$body);
                } else {
                    if (preg_match('/\%\{/',$body) || (preg_match('/<\?/',$body) && preg_match('/\$[A-Z]+\-\>[A-Z]+\(/is',$body))) {
                        //Body contains tags...
                        if (false && version_compare(PHP_VERSION, '5.3.0', '>=')) {
                            //If in PHP 5.3 or higher - use closures
                            $closure = sprintf('function() use (&$view,&$data) {extract($view->taglibs);ob_start();?>%s<? return ob_get_clean();}',$body);;
                            $str .= sprintf('%s,$view);?>',$closure);
                        } else {
                            $closureName = self::getNextClosure();
                            $str .= sprintf('new %s($view),$view);?>',$closureName);
                            self::$prepend .= chr(10).sprintf('<?
                                            //%1$s closure start
                                            if (!class_exists("%2$s")) {
                                                class %2$s extends PhtmlClosure {
                                                public function closure() {
                                                $view = $this->view;
                                                $data = $this->view->data;
                                                if (is_array($this->view->data)) {
                                                    extract($this->view->data);
                                                }
                                                $libs = $this->view->taglibs;
                                                extract($libs);
                                                ?>%3$s<?
                                                }}
                                            }
                                            //%1$s closure end
                                            ?>'.chr(10),$this->getTag(),$closureName,$body);
                        }
                        
                    } else {
                        $str .= sprintf('ob_get_clean(),$view);?>',$closureName);
                        $str = '<? ob_start();?>'."\n$body\n".$str;
                        
                    }
                }
                
            } else
                $str .= sprintf("</%s>",$this->getTag());
        } else {
            if ($method) {
                if ($taglibs[$this->getNs()] && $taglibs[$this->getNs()]->isPreprocess()) {
                    $tag = $this->getTag();
                    $str = $taglibs[$this->getNs()]->$tag($this->getAttrs(),null,null);
                } else {
                    $str .= 'null,$view);?>';
                }
            } else {
                $str .= '/>';
            }
        }
        if ($this->getParent() == null || $this->getParent()->getTag() == 'phtml') {
            $str = self::$prepend.$str.self::$append;
            self::$prepend = '';
            self::$append = '';
        }

        $str = $this->processEvals($str);

        if ($filename) {
            file_put_contents($filename,$str);
        }
        return $str;
    }
예제 #16
0
 /**
  * Outputs concatenated CSS for the specified view
  * @param string view | the view - optional
  */
 public function css()
 {
     $this->setContentType('text/css; charset=utf-8;');
     $this->setCache(Date::SPAN_MONTH);
     require_once Pimple::instance()->getBaseDir() . 'lib/Stylesheet.php';
     $cacheDir = Pimple::instance()->getSiteDir() . 'cache/css/';
     Dir::ensure($cacheDir);
     $templates = array();
     if (!Request::get('skipLayout', false)) {
         $templates[] = 'application';
     }
     $view = Request::get('view', false);
     if ($view) {
         $templates[] = $view;
     }
     $used = array();
     $isDebug = Settings::get(Settings::DEBUG, false);
     foreach ($templates as $template) {
         $cacheFile = $cacheDir . $template . '.css';
         echo "/* {$template} */\n";
         if ($isDebug) {
             $view = new View($template);
             $files = $view->getInternalCssFiles();
             echo "/*FILES:\n\t" . implode("\n\t", $files) . '*/' . chr(10);
             foreach ($files as $file) {
                 if (in_array($file, $used) || String::StartsWith($file, "http://") || String::StartsWith($file, "https://")) {
                     continue;
                 }
                 $used[] = $file;
                 echo "/*FILE:" . basename($file) . '*/' . chr(10) . Stylesheet::minify($file) . chr(10);
             }
         } else {
             Dir::ensure(dirname($cacheFile));
             if (!is_file($cacheFile)) {
                 File::truncate($cacheFile);
                 $view = new View($template);
                 $files = $view->getInternalCssFiles();
                 File::append($cacheFile, "/*FILES:\n\t" . implode("\n\t", $files) . '*/' . chr(10));
                 foreach ($files as $file) {
                     if (in_array($file, $used) || String::StartsWith($file, "http://") || String::StartsWith($file, "https://")) {
                         continue;
                     }
                     $used[] = $file;
                     File::append($cacheFile, "/*FILE:" . basename($file) . '*/' . chr(10) . Stylesheet::minify($file) . chr(10));
                 }
             }
             echo file_get_contents($cacheFile);
         }
     }
     Pimple::end();
 }
예제 #17
0
<?php

/**
 * User tags
 * @namespace u
 */
class UserTagLib extends TagLib
{
    /**
     * Outputs the current users full name (if any)
     */
    protected function tagFullname()
    {
        $user = SessionHandler::user();
        if ($user) {
            return $user->getFullName();
        }
    }
}
Pimple::instance()->registerTagLib('u', new UserTagLib());
예제 #18
0
 public static function compileAll()
 {
     $jsDir = Dir::concat(Pimple::instance()->getSiteDir(), 'www/js/');
 }
예제 #19
0
 /**
  * Outputs site name
  */
 protected function tagSitename($attrs)
 {
     return Pimple::instance()->getSiteName();
 }