Ejemplo n.º 1
0
function smarty_function_link($params, &$view)
{
    if (empty($params['get'])) {
        return '';
    }
    return \Pina\App::link($params['get'], $params);
}
function smarty_function_action_attributes($params, &$view)
{
    $availableMethods = array('get', 'post', 'put', 'delete');
    $methodsParams = array_intersect($availableMethods, array_keys($params));
    $method = reset($methodsParams);
    if (empty($method)) {
        return;
    }
    $assign = '';
    if (isset($params['assign'])) {
        $assign = $params['assign'];
        unset($params['assign']);
    }
    $pattern = $params[$method];
    unset($params[$method]);
    $resource = Route::resource($pattern, $params);
    $prefix = App::getLinkPrefix($params);
    $result = ' data-method="' . $method . '"';
    $result .= ' data-resource="' . $prefix . ltrim($resource, '/') . '"';
    list($preg, $map) = Url::preg($pattern);
    $result .= ' data-params="' . http_build_query(array_diff_key($params, array_flip($map))) . '"';
    $result .= ' ';
    if ($assign) {
        $view->assign($assign, $result);
        $link = '';
    }
    return $result;
}
Ejemplo n.º 3
0
function smarty_function_form($ps, &$view)
{
    $r = '<form';
    $prefix = '';
    $app = !empty($ps['app']) ? $ps['app'] : App::get();
    $apps = App::apps();
    if (!empty($apps[$app])) {
        $prefix = $apps[$app] . "/";
    }
    $ps['action'] = $prefix . $ps['action'];
    $add = '';
    if (!empty($ps["action"]) && strpos($ps['action'], '/:') !== false) {
        foreach ($ps as $k => $p) {
            $ps["action"] = str_replace(':' . $k, $p, $ps["action"]);
        }
    }
    $resource = $ps['action'];
    if (!empty($ps['action']) && !empty($ps['method'])) {
        $ps['method'] = strtolower($ps['method']);
        $add .= '<input type="hidden" name="' . $ps['method'] . '" value="' . $ps['action'] . '" />';
        $ps['action'] = '/pina.php';
        if ($ps['method'] != 'get') {
            $ps['method'] = 'post';
        }
    }
    if (!empty($ps["action"])) {
        $r .= ' action="' . $ps["action"] . '"';
    }
    if (!empty($ps["method"])) {
        $r .= ' method="' . $ps["method"] . '"';
    }
    if (!empty($ps["id"])) {
        $r .= ' id="' . $ps["id"] . '"';
    }
    if (!empty($ps["name"])) {
        $r .= ' name="' . $ps["name"] . '"';
    }
    if (!empty($ps["class"])) {
        $r .= ' class="' . $ps["class"] . '"';
    }
    if (!empty($ps["enctype"])) {
        $r .= ' enctype="' . $ps["enctype"] . '"';
    }
    if (!empty($ps["novalidate"])) {
        $r .= ' novalidate="' . $ps["novalidate"] . '"';
    }
    if (!empty($ps["role"])) {
        $r .= ' role="' . $ps["role"] . '"';
    }
    if (!empty($ps["target"])) {
        $r .= ' target="' . $ps["target"] . '"';
    }
    $r .= '>';
    $r .= $add;
    $ps['resource'] = $resource;
    $r .= Composer::draw('templater::form', $ps, $view);
    //$r .= CSRFToken::formField($resource, $ps["method"]);
    return $r;
}
Ejemplo n.º 4
0
function smarty_modifier_htmlall($string)
{
    $charset = \Pina\App::charset();
    if (empty($charset)) {
        $charset = 'utf-8';
    }
    return htmlentities($string, ENT_QUOTES, $charset);
}
Ejemplo n.º 5
0
function smarty_block_form($ps, $content, &$view, &$repeat)
{
    if ($repeat) {
        return;
    }
    $r = '<form';
    $prefix = '';
    $app = !empty($ps['app']) ? $ps['app'] : App::get();
    $apps = App::apps();
    if (!empty($apps[$app])) {
        $prefix = $apps[$app] . "/";
    }
    $ps['action'] = $prefix . $ps['action'];
    $add = '';
    $ps['action'] = Route::resource($ps['action'], $ps);
    $resource = $ps['action'];
    if (!empty($ps['action']) && !empty($ps['method'])) {
        $ps['method'] = strtolower($ps['method']);
        $add .= '<input type="hidden" name="' . $ps['method'] . '" value="' . $ps['action'] . '" />';
        $ps['action'] = '/pina.php';
        if ($ps['method'] != 'get') {
            $ps['method'] = 'post';
        }
    }
    if (!empty($ps["action"])) {
        $r .= ' action="' . $ps["action"] . '"';
    }
    if (!empty($ps["method"])) {
        $r .= ' method="' . $ps["method"] . '"';
    }
    if (!empty($ps["id"])) {
        $r .= ' id="' . $ps["id"] . '"';
    }
    if (!empty($ps["name"])) {
        $r .= ' name="' . $ps["name"] . '"';
    }
    if (!empty($ps["class"])) {
        $r .= ' class="' . $ps["class"] . '"';
    }
    if (!empty($ps["enctype"])) {
        $r .= ' enctype="' . $ps["enctype"] . '"';
    }
    if (!empty($ps["novalidate"])) {
        $r .= ' novalidate="' . $ps["novalidate"] . '"';
    }
    if (!empty($ps["role"])) {
        $r .= ' role="' . $ps["role"] . '"';
    }
    if (!empty($ps["target"])) {
        $r .= ' target="' . $ps["target"] . '"';
    }
    $r .= '>';
    $r .= $add;
    $ps['resource'] = $resource;
    $r .= Composer::draw('templater::form', $ps, $view);
    //$r .= CSRFToken::formField($resource, $ps["method"]);
    return $r . $content . '</form>';
}
Ejemplo n.º 6
0
function smarty_modifier_cut_details($string)
{
    $charset = \Pina\App::charset();
    if (empty($charset)) {
        $charset = 'utf-8';
    }
    if (($r = mb_strstr($string, '<hr class="pinacut" />', false, $charset)) !== false) {
        return $r;
    }
    return $string;
}
Ejemplo n.º 7
0
 public function fetch($handler = '', $first = true)
 {
     $this->header('Pina-Response: Json');
     $this->contentType('text/html');
     $app = App::get();
     $this->view->assign('params', \Pina\Request::params());
     $t = $this->view->fetch('file:' . $handler . '.tpl');
     if ($first) {
         $this->view->assign("content", $t);
         ResourceManager::mode('layout');
         $t = $this->view->fetch('Layout/' . $app . '/' . $this->view->getLayout() . '.tpl');
     }
     return $t;
 }
Ejemplo n.º 8
0
function smarty_modifier_cut($string, $length = false, $etc = "...")
{
    $charset = \Pina\App::charset();
    if (empty($charset)) {
        $charset = 'utf-8';
    }
    if (($pos = mb_strpos($string, '<hr class="pinacut" />')) !== false) {
        return mb_substr($string, 0, $pos, $charset);
    }
    if ($length && mb_strlen($string, $charset) > $length) {
        $string = strip_tags($string);
        $length -= min($length, mb_strlen($etc, $charset));
        return mb_substr($string, 0, $length, $charset) . $etc;
    }
    return $string;
}
Ejemplo n.º 9
0
function smarty_function_link($params, &$view)
{
    if (empty($params['get'])) {
        return '';
    }
    $assign = '';
    if (isset($params['assign'])) {
        $assign = $params['assign'];
        unset($params['assign']);
    }
    $link = \Pina\App::link($params['get'], $params);
    if ($assign) {
        $view->assign($assign, $link);
        $link = '';
    }
    return $link;
}
Ejemplo n.º 10
0
 public function fetch($handler = '', $first = true)
 {
     $this->header('Pina-Response: Json');
     $this->contentType('text/html');
     if ($first && isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
         $first = false;
     }
     $app = App::get();
     $t = $this->view->fetch('Modules/' . $handler . '.tpl');
     if ($first) {
         $this->view->assign("content", $t);
         ResourceManager::mode('layout');
         $t = $this->view->fetch('Layout/' . $app . '/' . $this->view->getLayout() . '.tpl');
     }
     //\Pina\Modules\Core\Language::rewrite($t);
     return $t;
 }
Ejemplo n.º 11
0
 public function testPermit()
 {
     App::env('test');
     Access::permit('accounts/:account_id/items', '*', 'provider,owner;provider,manager');
     $this->assertTrue(Access::isPrivate('accounts/5/items', 'show'));
     Access::reset();
     Access::permit('accounts/:account_id/items', '*', 'provider,owner;provider,manager');
     Access::addGroup('enabled');
     Access::addGroup('provider');
     Access::addGroup('owner');
     Access::addCondition('self', array('user_id' => 2));
     $this->assertTrue(Access::isPermitted('accounts/5/items', 'show'));
     Access::reset();
     Access::permit('accounts/:account_id/items', '*', 'provider,owner;provider,manager');
     Access::addGroup('enabled');
     Access::addGroup('provider');
     $this->assertFalse(Access::isPermitted('accounts/5/items', 'show'));
     Access::reset();
     Access::permit('accounts/:account_id/items', '*', 'provider,owner;provider,manager');
     $this->assertFalse(Access::isPermitted('accounts/5/items', 'show', array()));
     Access::reset();
     Access::permit('accounts/:account_id/items', '*', 'provider,owner;self');
     Access::addCondition('self', array('account_id' => 5));
     $this->assertTrue(Access::isPermitted('accounts/5/items', 'show', array()));
     Access::reset();
     Access::permit('accounts/:account_id/items', '*', 'provider,owner;self,provider');
     Access::addGroup('provider');
     Access::addCondition('self', array('account_id' => 5));
     $this->assertTrue(Access::isPermitted('accounts/5/items', 'show', array()));
     Access::reset();
     Access::permit('accounts/:account_id/items', '*', 'provider,owner;self,provider');
     Access::addGroup('provider');
     Access::addCondition('self', array('account_id' => 4));
     $this->assertFalse(Access::isPermitted('accounts/5/items', 'show', array()));
     Access::reset();
     Access::permit('accounts/:account_id/users', '*', 'provider;buyer');
     Access::permit('accounts/:account_id/users/:user_id/lists', '*', 'buyer');
     Access::addGroup('provider');
     $this->assertTrue(Access::isPermitted('accounts/5/users', 'show', array()));
     $this->assertFalse(Access::isPermitted('accounts/5/users/5/lists', 'show', array()));
 }
Ejemplo n.º 12
0
function smarty_block_script($params, $content, &$view, &$repeat)
{
    if ($repeat) {
        return;
    }
    if (empty($content) && empty($params['src'])) {
        return '';
    }
    if (!empty($params['src']) && !empty($params['module'])) {
        $from = App::path() . "/default/Modules/" . $params['module'] . '/static/' . ltrim($params['src'], '/');
        $to = App::path() . '/public/cache/js/' . $params['module'] . '.' . str_replace("/", ".", $params['src']);
        if (!file_exists($to) && file_exists($from)) {
            copy($from, $to);
        }
        $params['src'] = "/cache/js/" . $params['module'] . "." . str_replace("/", ".", $params['src']);
    }
    if (!empty($params['src'])) {
        ResourceManager::append('js', '<script src="' . $params['src'] . '" type="text/javascript"></script>');
    } elseif (!empty($content)) {
        ResourceManager::append('js', $content);
    }
    return '';
}
Ejemplo n.º 13
0
function smarty_block_style($params, $content, &$view, &$repeat)
{
    if ($repeat) {
        return;
    }
    if (empty($content) && empty($params['src'])) {
        return '';
    }
    if (!empty($params['src']) && !empty($params['module'])) {
        $from = App::path() . "/default/Modules/" . $params['module'] . '/static/' . ltrim($params['src'], '/');
        $to = App::path() . '/public/cache/css/' . $params['module'] . '.' . str_replace("/", ".", $params['src']);
        if (!file_exists($to) && file_exists($from)) {
            copy($from, $to);
        }
        $params['src'] = "/cache/css/" . $params['module'] . "." . str_replace("/", ".", $params['src']);
    }
    if (!empty($params['src'])) {
        ResourceManager::append('css', '<link rel="stylesheet" href="' . $params['src'] . '" />');
    } elseif (!empty($content)) {
        ResourceManager::append('css', $content);
    }
    return '';
}
Ejemplo n.º 14
0
 /**
  * @dataProvider handlerProvider
  */
 public function testHandler($controller, $action, $expected)
 {
     App::set('backend');
     $route = Url::handler($controller, $action);
     $this->assertEquals($expected, $route);
 }
Ejemplo n.º 15
0
function smarty_function_meta($params, &$view)
{
    return '<meta http-equiv="Content-Type" content="text/html; charset=' . App::charset() . '" />';
}
Ejemplo n.º 16
0
 private static function mail()
 {
     if (empty(static::$config)) {
         return;
     }
     if (empty(static::$to)) {
         return;
     }
     $mail = new PHPMailer();
     if (static::$config['mode'] == 'smtp') {
         $mail->isSMTP();
         $mail->Host = static::$config['smtp']['host'];
         if (static::$config['smtp']['user']) {
             $mail->SMTPAuth = true;
             $mail->Username = static::$config['smtp']['user'];
             $mail->Password = static::$config['smtp']['pass'];
         }
         $mail->SMTPSecure = static::$config['smtp']['secure'];
         $mail->Port = static::$config['smtp']['port'];
     } else {
         $mail->isMail();
     }
     $mail->setFrom(static::$config['from']['address'], !empty(static::$config['from']['name']) ? static::$config['from']['name'] : '');
     foreach (static::$to as $u) {
         $mail->addAddress($u['address'], $u['name']);
     }
     if (!empty(static::$config['reply']['address'])) {
         $mail->addReplyTo(static::$config['reply']['address'], !empty(static::$config['reply']['name']) ? static::$config['reply']['name'] : '');
     }
     foreach (static::$cc as $u) {
         $mail->addCC($u['address'], $u['name']);
     }
     foreach (static::$bcc as $u) {
         $mail->addBCC($u['address'], $u['name']);
     }
     $mail->CharSet = App::charset();
     $mail->Subject = Place::get('mail_subject');
     $mail->Body = static::$content;
     $mail->AltBody = Place::get('mail_alternative');
     if ($mail->AltBody) {
         $mail->isHTML(true);
     }
     if (!$mail->send()) {
         Log::error("mail", "error send email to " . json_encode($mail, JSON_UNESCAPED_UNICODE));
         return false;
     }
     return true;
 }
Ejemplo n.º 17
0
 public function contentType($type, $charset = false)
 {
     if (empty($charset)) {
         $charset = App::charset();
     }
     $this->header('Content-type: ' . $type . '; charset=' . $charset);
 }