Simple class to call templates efficiently. This class aims to reduce the compilation of a template as less a possible. Also it will not load in memory the compiler, except when there is not cache (compiled template) or it is out-dated.
Esempio n. 1
0
function haanga_464bf9fc69ec3d748e58e59c7b427e138da5ab9b($vars, $return = FALSE, $blocks = array())
{
    global $test_global, $global1;
    extract($vars);
    if ($return == TRUE) {
        ob_start();
    }
    $buffer1 = '
';
    $buffer2 = '
this is inner1
';
    $blocks['inner1'] = isset($blocks['inner1']) ? strpos($blocks['inner1'], '{{block.1b3231655cebb7a1f783eddf27d254ca}}') === FALSE ? $blocks['inner1'] : str_replace('{{block.1b3231655cebb7a1f783eddf27d254ca}}', $buffer2, $blocks['inner1']) : $buffer2;
    $buffer1 .= $blocks['inner1'] . '
';
    $buffer2 = '
this is inner2
';
    $blocks['inner2'] = isset($blocks['inner2']) ? strpos($blocks['inner2'], '{{block.1b3231655cebb7a1f783eddf27d254ca}}') === FALSE ? $blocks['inner2'] : str_replace('{{block.1b3231655cebb7a1f783eddf27d254ca}}', $buffer2, $blocks['inner2']) : $buffer2;
    $buffer1 .= $blocks['inner2'] . '
';
    $blocks['outer'] = isset($blocks['outer']) ? strpos($blocks['outer'], '{{block.1b3231655cebb7a1f783eddf27d254ca}}') === FALSE ? $blocks['outer'] : str_replace('{{block.1b3231655cebb7a1f783eddf27d254ca}}', $buffer1, $blocks['outer']) : $buffer1;
    echo Haanga::Load('assert_templates/empty_block_base.tpl', $vars, TRUE, $blocks);
    if ($return == TRUE) {
        return ob_get_clean();
    }
}
function do_banner_story()
{
    global $globals, $current_user;
    if ($globals['ads']) {
        Haanga::Safe_Load('private/ad-middle.html');
    }
}
Esempio n. 3
0
function create_form($view, $title, $data = array())
{
    global $site_key, $current_user;
    $time = microtime(true) * 1000;
    $form = array('title' => $title, 'hash' => sha1($site_key . $time . $current_user->user_id), 'time' => $time);
    Haanga::Load("league/form.{$view}.tpl", compact('form', 'data'));
}
Esempio n. 4
0
function print_edit_form()
{
    global $link, $comment, $current_user, $site_key, $globals;
    if ($current_user->user_level != 'god' && time() - $comment->date > $globals['comment_edit_time']) {
        die;
    }
    // $rows = min(40, max(substr_count($comment->content, "\n") * 2, 8));
    echo '<div class="commentform">' . "\n";
    //echo '<form action="'.htmlspecialchars($_SERVER['PHP_SELF']).'" class="comment" method="post" enctype="multipart/form-data">'."\n";
    echo '<form action="' . htmlspecialchars($_SERVER['REQUEST_URI']) . '" class="comment" method="post" enctype="multipart/form-data">' . "\n";
    echo '<input type="hidden" name="process" value="editcomment" />' . "\n";
    echo '<input type="hidden" name="key" value="' . md5($comment->randkey . $site_key) . '" />' . "\n";
    echo '<input type="hidden" name="id" value="' . $comment->id . '" />' . "\n";
    echo '<fieldset><legend>' . _('editar comentario') . '</legend>' . "\n";
    print_simpleformat_buttons('edit-comment-' . $comment->id);
    echo '<div style="clear: right"><textarea name="comment_content" class="droparea" id="edit-comment-' . $comment->id . '" rows="5">' . $comment->content . '</textarea></div>' . "\n";
    echo '<input class="button" type="submit" name="submit" value="' . _('modificar comentario') . '" />' . "\n";
    // Allow gods to put "admin" comments which does not allow votes
    if ($current_user->user_level == 'god') {
        if ($comment->type == 'admin') {
            $checked = 'checked="true"';
        }
        echo '&nbsp;&nbsp;&nbsp;&nbsp;<label><strong>' . _('admin') . ' </strong><input name="type" type="checkbox" value="admin" ' . $checked . '/></label>' . "\n";
    }
    $vars = compact('link', 'comment');
    Haanga::Load('comment_edit.html', $vars);
    echo '</fieldset>' . "\n";
    echo '</form>' . "\n";
    echo "</div>\n";
}
Esempio n. 5
0
 public function display($template, $page_title = '', $meta_description = '', array $css_files = array(), array $js_files = array())
 {
     $this->vars['page_title'] = $page_title ? $page_title : DEFAULT_PAGE_TITLE;
     $this->vars['meta_description'] = $meta_description ? $meta_description : DEFAULT_META_DESCRIPTION;
     // Add CSS files from arguments
     if ($css_files) {
         foreach ($css_files as $css_file) {
             $this->css_files[] = $css_file;
         }
     }
     $this->vars['css_files'] = $this->css_files;
     // Add JS files from arguments
     if ($js_files) {
         foreach ($js_files as $js_file) {
             $this->js_files[] = $js_file;
         }
     }
     $this->vars['js_files'] = $this->js_files;
     // Add preloaded CSS files
     foreach ($this->preloaded_css_files as $css_file) {
         $this->vars['css_files'][] = $css_file;
     }
     // Add preloaded JS files
     foreach ($this->preloaded_js_files as $js_file) {
         $this->vars['js_files'][] = $js_file;
     }
     $this->vars['js_vars'] = $this->js_vars;
     $this->vars['breadcrumb'] = $this->breadcrumb;
     Haanga::Load($template, $this->vars);
 }
Esempio n. 6
0
 /** 
  * @dataProvider tplProvider
  */
 public function testIsCached($test_file, $data, $expected)
 {
     /* same as above, but we ensure that the file wasn't compiled */
     $this->init($test_file, $expected);
     $output = Haanga::Load($test_file, $data, TRUE);
     $this->assertEquals($output, $expected);
     $this->assertFalse(Haanga::$has_compiled);
 }
Esempio n. 7
0
 function view($name, $base = null)
 {
     $this->set('controller', router::$controller);
     $this->set('route', router::$route);
     $this->set('session', $this->session);
     if ($base == null) {
         $base = router::$views_path;
     }
     Haanga::Load($base . '/' . $name, kernel::$haanga_var);
 }
Esempio n. 8
0
 /** 
  * @dataProvider tplProvider
  *  
  */
 public function testInvalidTemplates($tpl)
 {
     Haanga_Compiler::setOption('allow_exec', FALSE);
     try {
         Haanga::Load($tpl);
         $this->assertTrue(FALSE);
     } catch (Haanga_Compiler_Exception $e) {
         $i = preg_match("/in.*:[0-9]+/", $e->getMessage());
         $this->assertEquals(1, $i);
     }
 }
Esempio n. 9
0
 function print_summary($type = 'full', $karma_best_comment = 0, $show_tags = true)
 {
     global $current_user, $current_user, $globals, $db;
     if (!$this->read) {
         return;
     }
     $this->is_votable();
     switch ($this->status) {
         case 'queued':
             // another color box for not-published
             $box_class = 'mnm-queued';
             break;
         case 'abuse':
             // another color box for discarded
         // another color box for discarded
         case 'autodiscard':
             // another color box for discarded
         // another color box for discarded
         case 'discard':
             // another color box for discarded
             $box_class = 'mnm-discarded';
             break;
         case 'published':
             // default for published
         // default for published
         default:
             $box_class = 'mnm-published';
             break;
     }
     $this->has_warning = !(!$this->check_warn() || $this->is_discarded());
     $this->is_editable = $this->author == $current_user->user_id && $this->is_editable();
     $this->total_votes = $this->votes + $this->anonymous;
     $this->rpermalink = $this->get_relative_permalink();
     $this->author_html = '<a href="' . get_user_uri($this->username, 'history') . '">' . $this->username . '</a>';
     $this->normal_link = preg_replace('/\\/mobile\\//', '/', $this->get_relative_permalink());
     $this->show_shakebox = $type != 'preview' && $this->votes > 0;
     $this->thumb_url = $this->has_thumb();
     if ($this->status == 'abuse' || $this->has_warning) {
         $this->negative_text = FALSE;
         $negatives = $db->get_row("select SQL_CACHE vote_value, count(vote_value) as count from votes where vote_type='links' and vote_link_id={$this->id} and vote_value < 0 group by vote_value order by count desc limit 1");
         if ($negatives->count > 2 && $negatives->count >= $this->negatives / 2 && ($negatives->vote_value == -6 || $negatives->vote_value == -8)) {
             $this->negative_text = get_negative_vote($negatives->vote_value);
         }
     }
     $text = $this->content;
     $my_domain = get_server_name();
     $parent_domain = preg_replace('/m\\./', '', $my_domain);
     if ($parent_domain != $my_domain && preg_match('#[^\\.]' . preg_quote($parent_domain) . '/#', $text)) {
         $text = preg_replace('#([^\\.])' . preg_quote($parent_domain) . '/#', "\$1{$my_domain}/", $text);
     }
     $vars = compact('type', 'karma_best_comment', 'show_tags', 'box_class', 'nofollow', 'url', 'text');
     $vars['self'] = $this;
     return Haanga::Load('mobile/link_summary.html', $vars);
 }
Esempio n. 10
0
 public function render()
 {
     $config = array('template_dir' => $this->getTemplateDir(), 'cache_dir' => $this->getCacheDir(), 'debug' => $this->debug, 'compiler' => array('allow_exec' => true));
     if ($this->cache && is_callable('xcache_isset')) {
         /* don't check for changes in the template for the next 5 min */
         $config['check_ttl'] = 300;
         $config['check_get'] = 'xcache_get';
         $config['check_set'] = 'xcache_set';
     }
     \Haanga::configure($config);
     \Haanga::Load($this->getTpl(), $this->data);
 }
Esempio n. 11
0
function haanga_2918f6e9aedbd5d32e8a5d091ed1985fcf7008e3($vars, $return = FALSE, $blocks = array())
{
    global $test_global, $global1;
    extract($vars);
    if ($return == TRUE) {
        ob_start();
    }
    echo Haanga::Safe_Load('foobar-tpl.tpl', $vars, TRUE, array()) . '
' . Haanga::Safe_Load('assert_templates/partial.tpl', $vars, TRUE, array()) . '
';
    if ($return == TRUE) {
        return ob_get_clean();
    }
}
function haanga_d905488f199a96b638d52d62c0fc424fd291ed39($vars, $return = FALSE, $blocks = array())
{
    global $test_global, $global1;
    extract($vars);
    if ($return == TRUE) {
        ob_start();
    }
    $buffer1 = '
    2.1-overrided
';
    $blocks['inner2_1'] = isset($blocks['inner2_1']) ? strpos($blocks['inner2_1'], '{{block.1b3231655cebb7a1f783eddf27d254ca}}') === FALSE ? $blocks['inner2_1'] : str_replace('{{block.1b3231655cebb7a1f783eddf27d254ca}}', $buffer1, $blocks['inner2_1']) : $buffer1;
    echo Haanga::Load('assert_templates/nested_block_second_parent.tpl', $vars, TRUE, $blocks);
    if ($return == TRUE) {
        return ob_get_clean();
    }
}
function haanga_a2c536c1d9b6f09d66feff81ca9b1e993d15d32e($vars, $return = FALSE, $blocks = array())
{
    global $test_global, $global1;
    extract($vars);
    if ($return == TRUE) {
        ob_start();
    }
    $buffer1 = '
{{block.1b3231655cebb7a1f783eddf27d254ca}}
new stuff
';
    $blocks['outer'] = isset($blocks['outer']) ? strpos($blocks['outer'], '{{block.1b3231655cebb7a1f783eddf27d254ca}}') === FALSE ? $blocks['outer'] : str_replace('{{block.1b3231655cebb7a1f783eddf27d254ca}}', $buffer1, $blocks['outer']) : $buffer1;
    echo Haanga::Load('assert_templates/nested_block.tpl', $vars, TRUE, $blocks);
    if ($return == TRUE) {
        return ob_get_clean();
    }
}
Esempio n. 14
0
 public function match($uri)
 {
     global $conf;
     global $localUri;
     global $uri;
     global $acceptContentType;
     global $endpoints;
     global $lodspk;
     global $results;
     global $firstResults;
     require_once $conf['home'] . 'classes/MetaDb.php';
     $metaDb = new MetaDb($conf['metadata']['db']['location']);
     $pair = Queries::getMetadata($localUri, $acceptContentType, $metaDb);
     if ($pair == NULL) {
         // Original URI is not in metadata
         if (Queries::uriExist($uri, $endpoints['local'])) {
             $page = Queries::createPage($uri, $localUri, $acceptContentType, $metaDb);
             if ($page == NULL) {
                 HTTPStatus::send500("Can't write sqlite database.");
             }
             HTTPStatus::send303($page, $acceptContentType);
             exit(0);
         } else {
             return false;
         }
     }
     list($res, $page, $format) = $pair;
     $uri = $res;
     $queries = $this->getQueries();
     $e = $endpoints['local'];
     require_once $conf['home'] . 'lib/Haanga/lib/Haanga.php';
     Haanga::configure(array('cache_dir' => $conf['home'] . 'cache/', 'autoescape' => FALSE));
     $vars = compact('uri', 'lodspk', 'models', 'first');
     foreach ($queries as $l => $v) {
         $q = Utils::addPrefixes(file_get_contents($v));
         $fnc = Haanga::compile($q);
         $query = $fnc($vars, TRUE);
         $aux = $e->query($query, Utils::getResultsType($query));
         if ($aux["boolean"] === true) {
             $pair[] = $l;
             return $pair;
         }
     }
     return false;
 }
Esempio n. 15
0
 public static function generator($cmp, $args, $redirected)
 {
     if (count($args) != 1) {
         $cmp->Error("inline needs one argument");
     }
     if ($redirected) {
         $cmp->Error("inline can't be redirected to one variable");
     }
     if (!Haanga_AST::is_str($args[0])) {
         $cmp->Error("The argument to inline must be an string");
     }
     $file = $args[0]['string'];
     if (class_exists('Haanga')) {
         $file = Haanga::getTemplatePath($file);
     }
     if (!is_file($file)) {
         $cmp->Error("{$file} is not a template");
     }
     return $cmp->getOpCodes(file_get_contents($file), $file);
 }
Esempio n. 16
0
function haanga_8012978a44e77332b744185d044350c7eb89603f($vars, $return = FALSE, $blocks = array())
{
    global $test_global, $global1;
    extract($vars);
    if ($return == TRUE) {
        ob_start();
    }
    $buffer1 = 'My Title - {{block.1b3231655cebb7a1f783eddf27d254ca}}';
    $blocks['title'] = isset($blocks['title']) ? strpos($blocks['title'], '{{block.1b3231655cebb7a1f783eddf27d254ca}}') === FALSE ? $blocks['title'] : str_replace('{{block.1b3231655cebb7a1f783eddf27d254ca}}', $buffer1, $blocks['title']) : $buffer1;
    $buffer1 = '
    {{block.1b3231655cebb7a1f783eddf27d254ca}}

    :-)
';
    $blocks['main.menu'] = isset($blocks['main.menu']) ? strpos($blocks['main.menu'], '{{block.1b3231655cebb7a1f783eddf27d254ca}}') === FALSE ? $blocks['main.menu'] : str_replace('{{block.1b3231655cebb7a1f783eddf27d254ca}}', $buffer1, $blocks['main.menu']) : $buffer1;
    echo Haanga::Load('assert_templates/base.tpl', $vars, TRUE, $blocks);
    if ($return == TRUE) {
        return ob_get_clean();
    }
}
Esempio n. 17
0
function print_edit_form($comment, $link)
{
    global $current_user, $site_key, $globals, $reply_to;
    $data = array();
    $html = '';
    if ($comment->id == 0) {
        $comment->randkey = rand(1000000, 100000000);
    }
    $html .= '<div class="commentform">';
    $html .= '<form action="' . $globals['base_url'] . "comment_ajax?reply_to={$reply_to}&amp;link={$link->id}&amp;id={$comment->id}&amp;user={$current_user->user_id}" . '" class="comment" method="post" enctype="multipart/form-data" id="c_edit_form">';
    $html .= '<input type="hidden" name="randkey" value="' . $comment->randkey . '" />';
    $html .= '<input type="hidden" name="process" value="editcomment" />';
    $html .= '<input type="hidden" name="key" value="' . md5($comment->randkey . $site_key) . '" />';
    $html .= '<input type="hidden" name="id" value="' . $comment->id . '" />';
    $vars = compact('link', 'comment');
    $html .= Haanga::Load('comment_edit.html', $vars, true);
    $html .= '</form></div>';
    $data['html'] = $html;
    $data['error'] = '';
    echo json_encode($data);
}
Esempio n. 18
0
function haanga_f5ad40d56c2438ea6bb3882d3b5e5ebf18352938($vars, $return = FALSE, $blocks = array())
{
    global $test_global, $global1;
    extract($vars);
    if ($return == TRUE) {
        ob_start();
    }
    $foo = 5 + 1;
    $vars['foo'] = $foo;
    echo '
';
    $bar = 'testing';
    $vars['bar'] = $bar;
    echo '
' . htmlspecialchars($foo) . '
' . Haanga::Load('assert_templates/sub_set.tpl', $vars, TRUE, $blocks) . '
';
    if ($return == TRUE) {
        return ob_get_clean();
    }
}
function haanga_93071c9c441d1680a63883802200fe559306006e($vars, $return = FALSE, $blocks = array())
{
    global $test_global, $global1;
    extract($vars);
    if ($return == TRUE) {
        ob_start();
    }
    $buffer1 = '
    inner2\'s new value
    ';
    $buffer2 = '
        2.1
    ';
    $blocks['inner2_1'] = isset($blocks['inner2_1']) ? strpos($blocks['inner2_1'], '{{block.1b3231655cebb7a1f783eddf27d254ca}}') === FALSE ? $blocks['inner2_1'] : str_replace('{{block.1b3231655cebb7a1f783eddf27d254ca}}', $buffer2, $blocks['inner2_1']) : $buffer2;
    $buffer1 .= $blocks['inner2_1'] . '
';
    $blocks['inner2'] = isset($blocks['inner2']) ? strpos($blocks['inner2'], '{{block.1b3231655cebb7a1f783eddf27d254ca}}') === FALSE ? $blocks['inner2'] : str_replace('{{block.1b3231655cebb7a1f783eddf27d254ca}}', $buffer1, $blocks['inner2']) : $buffer1;
    echo Haanga::Load('assert_templates/nested_block.tpl', $vars, TRUE, $blocks);
    if ($return == TRUE) {
        return ob_get_clean();
    }
}
Esempio n. 20
0
function haanga_d2f931b3242b3187b9a3d407f38c7d9d691df84f($vars, $return = FALSE, $blocks = array())
{
    global $test_global, $global1;
    extract($vars);
    if ($return == TRUE) {
        ob_start();
    }
    echo '<html>
<head>
    <title>';
    $buffer1 = 'Default Title';
    echo (isset($blocks['title']) ? strpos($blocks['title'], '{{block.1b3231655cebb7a1f783eddf27d254ca}}') === FALSE ? $blocks['title'] : str_replace('{{block.1b3231655cebb7a1f783eddf27d254ca}}', $buffer1, $blocks['title']) : $buffer1) . '</title>
</head>

<body>
    <h1>Menu</h1>
    ';
    $buffer1 = '
    <ul>
        ';
    foreach ($menu as $item) {
        $buffer1 .= '
            <li><a href="' . $item['url'] . '">' . htmlspecialchars($item['name']) . '</a></li>
        ';
    }
    $buffer1 .= '
    </ul>
    ';
    echo (isset($blocks['main.menu']) ? strpos($blocks['main.menu'], '{{block.1b3231655cebb7a1f783eddf27d254ca}}') === FALSE ? $blocks['main.menu'] : str_replace('{{block.1b3231655cebb7a1f783eddf27d254ca}}', $buffer1, $blocks['main.menu']) : $buffer1) . '
    ';
    $buffer1 = '' . Haanga::Load('assert_templates/partial.tpl', $vars, TRUE, $blocks);
    echo (isset($blocks['main.include-end']) ? strpos($blocks['main.include-end'], '{{block.1b3231655cebb7a1f783eddf27d254ca}}') === FALSE ? $blocks['main.include-end'] : str_replace('{{block.1b3231655cebb7a1f783eddf27d254ca}}', $buffer1, $blocks['main.include-end']) : $buffer1) . '
</body>
</html>
';
    if ($return == TRUE) {
        return ob_get_clean();
    }
}
Esempio n. 21
0
 function print_summary($link = 0, $length = 0, $single_link = true)
 {
     global $current_user, $globals;
     if (!$this->read) {
         return;
     }
     if (!$link && $this->link > 0) {
         $link = new Link();
         $link->id = $this->link;
         $link->read();
         $this->link_object = $link;
     }
     $this->link_permalink = $link->get_relative_permalink();
     $this->check_visibility();
     if ($this->hidden) {
         $comment_meta_class = 'comment-meta-hidden';
         $comment_class = 'comment-body-hidden';
     } else {
         $comment_meta_class = 'comment-meta';
         $comment_class = 'comment-body';
         if ($this->karma > $globals['comment_highlight_karma']) {
             $comment_class .= ' high';
         }
     }
     $this->truncate($length);
     $this->txt_content = $this->to_html($this->content);
     if ($this->type == 'admin') {
         $author = '<strong>' . _('admin') . '</strong> ';
     } else {
         $author = '<a href="' . get_user_uri($this->username) . '" title="karma:&nbsp;' . $this->user_karma . '">' . $this->username . '</a> ';
     }
     if ($this->media_size > 0) {
         $this->media_thumb_dir = Upload::get_cache_relative_dir($this->id);
     }
     $vars = compact('comment_meta_class', 'comment_class', 'author');
     $vars['self'] = $this;
     return Haanga::Load('mobile/comment_summary.html', $vars);
 }
function haanga_2f06ae0d3b252465fa65c3a02cc1ebab4d90396f($vars, $return = FALSE, $blocks = array())
{
    global $test_global, $global1;
    extract($vars);
    if ($return == TRUE) {
        ob_start();
    }
    $buffer1 = '
{{block.1b3231655cebb7a1f783eddf27d254ca}}
new stuff
';
    $buffer2 = '
new inner2
';
    $blocks['inner2'] = isset($blocks['inner2']) ? strpos($blocks['inner2'], '{{block.1b3231655cebb7a1f783eddf27d254ca}}') === FALSE ? $blocks['inner2'] : str_replace('{{block.1b3231655cebb7a1f783eddf27d254ca}}', $buffer2, $blocks['inner2']) : $buffer2;
    $buffer1 .= $blocks['inner2'] . '
';
    $blocks['outer'] = isset($blocks['outer']) ? strpos($blocks['outer'], '{{block.1b3231655cebb7a1f783eddf27d254ca}}') === FALSE ? $blocks['outer'] : str_replace('{{block.1b3231655cebb7a1f783eddf27d254ca}}', $buffer1, $blocks['outer']) : $buffer1;
    echo Haanga::Load('assert_templates/nested_block.tpl', $vars, TRUE, $blocks);
    if ($return == TRUE) {
        return ob_get_clean();
    }
}
Esempio n. 23
0
            echo '</div>';
            // Print "conversation" for a given note
            $answers = $db->object_iterator("SELECT" . Post::SQL . ", conversations WHERE conversation_type='post' and conversation_to = {$post_id} and post_id = conversation_from ORDER BY conversation_from asc LIMIT 100", 'Post');
            if ($answers) {
                echo '<div style="padding-left: 40px; padding-top: 10px">';
                echo '<ol class="comments-list">';
                foreach ($answers as $answer) {
                    echo '<li>';
                    $answer->print_summary();
                    echo '</li>';
                    $ids[] = $answer->id;
                }
                echo "</ol>";
                echo '</div>' . "\n";
            }
        }
        Haanga::Load('get_total_answers_by_ids.html', array('type' => 'post', 'ids' => implode(',', $ids)));
        // Update conversation time
        if ($view == 3 && $time_read > 0 && $user->id == $current_user->user_id) {
            Post::update_read_conversation($time_read);
        }
    }
    echo '</div>';
    do_pages($rows, $page_size);
}
echo '</div>';
if ($rows > 15) {
    do_footer_menu();
}
do_footer();
exit(0);
Esempio n. 24
0
        $limit = 500;
    }
} else {
    $user = '';
}
header('Content-Type: text/html; charset=utf-8');
$media = $db->get_results("select type, id, version, unix_timestamp(date) as date, mime, user as uid, user_login as user from media, users where type in {$type_in} {$user} and version = 0 and user_id = media.user order by date desc limit {$limit}");
$images = array();
if ($media) {
    foreach ($media as $image) {
        if (!$show_all) {
            switch ($image->type) {
                case 'comment':
                    $karma = $db->get_var("select comment_karma from comments where comment_id = {$image->id}");
                    break;
                case 'post':
                    $karma = $db->get_var("select post_karma from posts where post_id = {$image->id}");
                    break;
                default:
                    $karma = 0;
            }
        }
        if ($show_all || $karma > -10) {
            $image->url = Upload::get_url($image->type, $image->id, $image->version, $image->date, $image->mime);
            $images[] = $image;
        }
    }
}
if ($images) {
    Haanga::Load("backend/gallery.html", compact('images'));
}
Esempio n. 25
0
 function output_rss()
 {
     global $session, $html;
     if (!$this->read) {
         $session->log('Eeeks! Trying to print a quote that haven\'t been read yet (id=%d)', $this->id);
         die;
     }
     $c = $this;
     $c->title = $this->text_clean($c->text, 'rss_title');
     $c->text = $this->text_clean($c->text, 'rss_body');
     $c->ts = date('r', $c->timestamp);
     $vars = compact('c');
     $html->output .= Haanga::Load('rss-quote.html', $vars, true);
     return true;
 }
Esempio n. 26
0
function print_tabs($option)
{
    global $current_user;
    if (SitesMgr::my_id() == 1 && SitesMgr::can_edit(0)) {
        $can_edit = true;
    } else {
        $can_edit = false;
    }
    $items = array();
    if ($current_user->user_id) {
        $items[] = array('id' => 0, 'url' => 'subs', 'title' => _('suscripciones'));
    }
    $items[] = array('id' => 1, 'url' => 'subs?active', 'title' => _('más activos'));
    $items[] = array('id' => 2, 'url' => 'subs?all', 'title' => _('todos'));
    if ($can_edit) {
        $items[] = array('id' => 3, 'url' => 'subedit', 'title' => _('crear sub'));
    }
    $vars = compact('items', 'option');
    return Haanga::Load('print_tabs.html', $vars);
}
Esempio n. 27
0
function print_answers($id, $level, $visited = false)
{
    // Print answers to the comment
    global $db, $page_size;
    if (!$visited) {
        $visited = array();
        $visited[] = $id;
    }
    $printed = array();
    $sql = "SELECT conversation_from FROM conversations, comments WHERE conversation_type='comment' and conversation_to = {$id} and comment_id = conversation_from ORDER BY conversation_from asc LIMIT {$page_size}";
    $answers = $db->get_col($sql);
    if ($answers) {
        $type = 'comment';
        echo '<div style="padding-left: 6%">' . "\n";
        echo '<ol class="comments-list">';
        foreach ($answers as $dbanswer) {
            if (in_array($dbanswer, $visited)) {
                continue;
            }
            $answer = Comment::from_db($dbanswer);
            $answer->url = $answer->get_relative_individual_permalink();
            echo '<li>';
            $answer->print_summary($link);
            if ($level > 0) {
                $res = print_answers($answer->id, $level - 1, array_merge($visited, $answers));
                $visited = array_merge($visited, $res);
            }
            $printed[] = $answer->id;
            $visited[] = $answer->id;
            echo '</li>';
        }
        echo "</ol>\n";
        echo '</div>' . "\n";
        if ($level == 0) {
            $ids = implode(',', $printed);
            Haanga::Load('get_total_answers_by_ids.html', compact('type', 'ids'));
        }
    }
    return $printed;
}
Esempio n. 28
0
<?php

include '../config.php';
header('Content-Type: application/x-javascript; charset=utf-8');
header('Cache-Control: public, max-age=864000');
header("Expires: " . gmdate("r", $globals['now'] + 864000));
Haanga::Load('js/general.js');
Esempio n. 29
0
$results['tags'] = count($a);
foreach ($a as $w) {
    $w = trim($w);
    $r = array();
    $r['w'] = $w;
    $r['len'] = mb_strlen($w);
    $r['hits'] = $h = min($results['docs'], intval(sphinx_doc_hits($w)));
    $r['freq'] = round(100 * $h / $results['docs'], 1);
    if ($r['freq'] < $results['min_freq']) {
        $results['min_freq'] = $r['freq'];
    }
    if ($r['freq'] > $results['max_freq']) {
        $results['max_freq'] = $r['freq'];
    }
    if ($r['freq'] > 1) {
        $results['highs'] += 1;
    }
    if (preg_match('/ /', $w)) {
        $results['phrases'] += 1;
        $r['phrase'] = true;
    } else {
        $r['phrase'] = false;
    }
    if (preg_match('/' . preg_quote($w, '/') . '/ui', $link->title)) {
        $results['in_title'] += 1;
        $r['in_title'] = true;
    }
    $words[$w] = $r;
}
Haanga::Load('backend/tags_analysis.html', compact('results', 'words'));
Esempio n. 30
0
function do_subs()
{
    global $db, $user, $current_user;
    $sql = "select subs.* from subs, prefs where pref_user_id = {$user->id} and pref_key = 'sub_follow' and subs.id = pref_value order by name asc";
    $subs = $db->get_results($sql);
    if ($subs) {
        $title = _('suscripciones');
        Haanga::Load('subs_simple.html', compact('title', 'subs'));
    }
    if ($current_user->admin && $user->id == $current_user->user_id) {
        $sql = "select subs.* from subs where subs.sub = 1 and (subs.owner = {$user->id} or subs.owner = 0)";
    } else {
        $sql = "select subs.* from subs where subs.sub = 1 and subs.owner = {$user->id}";
    }
    $subs = $db->get_results($sql);
    if ($subs) {
        $title = _('subs de') . " {$user->username}";
        if ($current_user->user_id > 0 && $user->id == $current_user->user_id && SitesMgr::can_edit(0)) {
            $can_edit = true;
        } else {
            $can_edit = false;
        }
        Haanga::Load('subs.html', compact('title', 'subs', 'can_edit'));
    }
}