Exemplo n.º 1
0
function nel_parse_template($template, $subdirectory, $render, $regen)
{
    if (!empty($subdirectory)) {
        $subdirectory .= '/';
    }
    $template_short = utf8_str_replace('.tpl', '', $template);
    $info = nel_template_info($template, NULL, NULL, TRUE);
    if (is_null($info) || $info['loaded'] === FALSE || $info['loaded'] === NULL) {
        clearstatcache();
        $modify_time = filemtime(TEMPLATE_PATH . $subdirectory . $template);
        if (!isset($info['modify_time']) || $modify_time !== $info['modify_time'] || !file_exists(CACHE_PATH . $template_short . '.nelcache')) {
            $info['modify-time'] = $modify_time;
            $lol = file_get_contents(TEMPLATE_PATH . $subdirectory . $template);
            $lol = trim($lol);
            $begin = '<?php function nel_template_render_' . $template_short . '($render) { $temp = \'';
            // Start of the cached template
            $lol = preg_replace_callback('#({{.*?}})|({(.*?)})|(\')#', 'nel_escape_single_quotes', $lol);
            // Do escaping and variable parse
            $lol = preg_replace('#(})\\s*?({)#', '$1$2', $lol);
            // Clear white space between control statements
            $lol = preg_replace('#{{\\s*?(if|elseif|foreach|for|while)\\s*?(.*?)}}#', '\'; $1($2): $temp .= \'', $lol);
            // Parse opening control statements
            $lol = preg_replace('#{{\\s*?else\\s*?}}#', '\'; else: $temp .= \'', $lol);
            // Parse else statements
            $lol = preg_replace('#{{\\s*?(endif|endforeach|endfor|endwhile|endswitch)\\s*?}}#', '\'; $1; $temp .= \'', $lol);
            // Parse closing control statements
            $lol = preg_replace('#{{{\\s*?(.*?)\\s*?}}}#', '\'; $1; $temp .= \'', $lol);
            // Parse other PHP code
            $end = '\'; return $temp; } ?>';
            // End of the caches template
            $lol_out = $begin . $lol . $end;
            nel_write_file(CACHE_PATH . $template_short . '.nelcache', $lol_out, 0644);
        }
        include CACHE_PATH . $template_short . '.nelcache';
        $info['loaded'] = TRUE;
        nel_template_info($template, NULL, $info, FALSE);
    }
    if (!$regen) {
        $dat_temp = call_user_func('nel_template_render_' . $template_short, $render);
        return $dat_temp;
    }
}
Exemplo n.º 2
0
function nel_main_nel_thread_generator($dataforce, $dbh)
{
    $gen_data = array();
    $gen_data['insert_hr'] = FALSE;
    $dataforce['dotdot'] = '';
    $result = $dbh->query('SELECT post_number FROM ' . POSTTABLE . ' WHERE response_to=0 AND archive_status=0 ORDER BY sticky desc,last_update desc');
    $front_page_list = $result->fetchALL(PDO::FETCH_COLUMN);
    unset($result);
    $treeline = array(0);
    // Finding the last entry number
    $result = $dbh->query('SELECT COUNT(post_number) FROM ' . POSTTABLE . ' WHERE response_to=0');
    $row = $result->fetch();
    unset($result);
    $counttree = count($front_page_list);
    // Special handling when there's no content
    if ($counttree === 0) {
        $render = new nel_render();
        $render->add_data('header_type', 'NORMAL');
        nel_render_header($dataforce, $render, $treeline);
        nel_render_posting_form($dataforce, $render);
        $render->add_data('prev_nav', '');
        $render->add_data('next_nav', '');
        $render->add_data('page_nav', '');
        nel_render_footer($render, FALSE, TRUE, TRUE, FALSE, TRUE);
        if (empty($_SESSION) || $_SESSION['ignore_login']) {
            nel_write_file(PHP_SELF2 . PHP_EXT, $render->output(FALSE), 0644);
        } else {
            $render->output(TRUE);
        }
        return;
    }
    $thread_counter = 0;
    $page = 1;
    $gen_data['post_counter'] = -1;
    while ($thread_counter < $counttree) {
        $render = new nel_render();
        $dataforce['omitted_done'] = TRUE;
        $render->add_data('header_type', 'NORMAL');
        nel_render_header($dataforce, $render, $treeline);
        nel_render_posting_form($dataforce, $render);
        $end_of_thread = FALSE;
        $sub_page_thread_counter = 0;
        $gen_data['first100'] = FALSE;
        while ($sub_page_thread_counter < BS_THREADS_PER_PAGE) {
            if ($gen_data['post_counter'] === -1) {
                $result = $dbh->query('SELECT * FROM ' . POSTTABLE . ' WHERE post_number=' . $front_page_list[$thread_counter] . '');
                $tree_op = $result->fetchALL(PDO::FETCH_ASSOC);
                unset($result);
                $result = $dbh->query('SELECT * FROM ' . POSTTABLE . ' WHERE response_to=' . $front_page_list[$thread_counter] . ' ORDER BY post_number desc LIMIT ' . (BS_ABBREVIATE_THREAD - 1) . '');
                $tree_replies = $result->fetchALL(PDO::FETCH_ASSOC);
                unset($result);
                $treeline = array_merge($tree_op, array_reverse($tree_replies));
                $gen_data['post_count'] = $treeline[0]['post_count'];
                $gen_data['expand_post'] = $gen_data['post_count'] > BS_ABBREVIATE_THREAD ? TRUE : FALSE;
                $gen_data['first100'] = $gen_data['post_count'] > 100 ? TRUE : FALSE;
            }
            if (!empty($treeline[$gen_data['post_counter']]) && !empty($treeline[$gen_data['post_counter'] + 1])) {
                ++$gen_data['post_counter'];
            } else {
                if ($gen_data['post_counter'] === -1) {
                    $gen_data['post_counter'] = 0;
                } else {
                    $end_of_thread = TRUE;
                    $sub_page_thread_counter = $thread_counter == $counttree - 1 ? BS_THREADS_PER_PAGE : ++$sub_page_thread_counter;
                    ++$thread_counter;
                    $gen_data['insert_hr'] = TRUE;
                    nel_render_post($dataforce, $render, FALSE, FALSE, $gen_data, $treeline, $dbh);
                    $gen_data['insert_hr'] = FALSE;
                }
            }
            if (!$end_of_thread) {
                $gen_data['has_file'] = FALSE;
                if ($treeline[$gen_data['post_counter']]['has_file'] == 1) {
                    $gen_data['has_file'] = TRUE;
                    $result = $dbh->query('SELECT * FROM ' . FILETABLE . ' WHERE post_ref=' . $treeline[$gen_data['post_counter']]['post_number'] . ' ORDER BY file_order asc');
                    $gen_data['files'] = $result->fetchALL(PDO::FETCH_ASSOC);
                    unset($result);
                }
                if ($treeline[$gen_data['post_counter']]['response_to'] > 0) {
                    if (!$treeline[$gen_data['post_counter']]['post_number']) {
                        break;
                    }
                    if ($gen_data['post_count'] > BS_ABBREVIATE_THREAD && $gen_data['post_counter'] === 1) {
                        $dataforce['omitted_done'] = FALSE;
                        nel_render_post($dataforce, $render, TRUE, TRUE, $gen_data, $treeline, $dbh);
                        $dataforce['omitted_done'] = TRUE;
                    } else {
                        nel_render_post($dataforce, $render, TRUE, TRUE, $gen_data, $treeline, $dbh);
                    }
                } else {
                    nel_render_post($dataforce, $render, FALSE, FALSE, $gen_data, $treeline, $dbh);
                }
            } else {
                $end_of_thread = FALSE;
                $gen_data['post_counter'] = -1;
            }
        }
        // if not in res display mode
        $prev = $page - 1;
        $next = $page + 1;
        $render->add_data('page_nav', ' ');
        $page_count = (int) ceil($counttree / BS_THREADS_PER_PAGE);
        $render->add_data('main_page', TRUE);
        if ($page === 1) {
            $render->add_data('prev_nav', 'Previous');
        } else {
            if ($page === 2) {
                $render->add_data('prev_nav', '<a href="' . PHP_SELF2 . PHP_EXT . '">Previous</a> ');
            } else {
                $render->add_data('prev_nav', '<a href="' . PHP_SELF2 . ($page - 2) . PHP_EXT . '">Previous</a>');
            }
        }
        $render->add_data('next_nav', $page === $page_count || $dataforce['max_pages'] === 1 ? 'Next' : '<a href="' . PHP_SELF2 . $page . PHP_EXT . '">Next</a>');
        $i = 0;
        while ($i < $page_count) {
            if ($i === 0) {
                $render->add_data('page_nav', $render->retrieve_data('page_nav') . ($page > 1 ? '[<a href="' . PHP_SELF2 . PHP_EXT . '">0</a>] ' : '[0] '));
            } else {
                if ($i === $page - 1 || $dataforce['max_pages'] === 1) {
                    $render->add_data('page_nav', $render->retrieve_data('page_nav') . '[' . $i . '] ');
                } else {
                    $render->add_data('page_nav', $render->retrieve_data('page_nav') . '[<a href="' . PHP_SELF2 . $i . PHP_EXT . '">' . $i . '</a>] ');
                }
            }
            ++$i;
        }
        nel_render_footer($render, FALSE, TRUE, TRUE, FALSE, TRUE);
        if (!empty($_SESSION) && !$_SESSION['ignore_login']) {
            if ($page >= $dataforce['current_page']) {
                $page = $counttree;
            }
            $render->output(TRUE);
            die;
        } else {
            $logfilename = $page === 1 ? PHP_SELF2 . PHP_EXT : PHP_SELF2 . ($page - 1) . PHP_EXT;
            nel_write_file($logfilename, $render->output(FALSE), 0644);
        }
        ++$page;
        unset($render);
    }
}
Exemplo n.º 3
0
function nel_thread_generator($dataforce, $dbh)
{
    $render = new nel_render();
    $render_expand = new nel_render();
    $render_collapse = new nel_render();
    $gen_data['insert_hr'] = FALSE;
    $dataforce['dotdot'] = '';
    $write_id = $dataforce['response_to'] === 0 || is_null($dataforce['response_to']) ? $dataforce['response_id'] : $dataforce['response_to'];
    $result = $dbh->query('SELECT * FROM ' . POSTTABLE . ' WHERE post_number=' . $write_id . ' UNION SELECT * FROM ' . POSTTABLE . ' WHERE response_to=' . $write_id . ' ORDER BY post_number asc');
    $treeline = $result->fetchAll(PDO::FETCH_ASSOC);
    unset($result);
    if (empty($treeline)) {
        return;
    }
    if (empty($_SESSION) || $_SESSION['ignore_login']) {
        $dataforce['dotdot'] = '../../';
    }
    $gen_data['post_count'] = $treeline[0]['post_count'];
    $page = 1;
    $gen_data['post_counter'] = 0;
    $gen_data['expand_post'] = FALSE;
    $dataforce['omitted_done'] = TRUE;
    $partlimit = 1;
    $gen_data['first100'] = FALSE;
    while ($gen_data['post_counter'] < $gen_data['post_count']) {
        if ($treeline[$gen_data['post_counter']]['has_file'] == 1) {
            $gen_data['has_file'] = TRUE;
            $result = $dbh->query('SELECT * FROM ' . FILETABLE . ' WHERE post_ref=' . $treeline[$gen_data['post_counter']]['post_number'] . ' ORDER BY file_order asc');
            $gen_data['files'] = $result->fetchALL(PDO::FETCH_ASSOC);
            unset($result);
        } else {
            $gen_data['has_file'] = FALSE;
        }
        if ($gen_data['post_counter'] === 0) {
            $render->add_data('header_type', 'NORMAL');
            nel_render_header($dataforce, $render, $treeline);
            nel_render_posting_form($dataforce, $render);
        }
        if ($partlimit === 100) {
            $render_temp = clone $render;
            $gen_data['insert_hr'] = TRUE;
            nel_render_post($dataforce, $render_temp, FALSE, FALSE, $gen_data, $treeline, $dbh);
            $gen_data['insert_hr'] = FALSE;
            nel_render_footer($render_temp, FALSE, TRUE, TRUE, TRUE, FALSE);
            nel_write_file(PAGE_PATH . $write_id . '/' . $dataforce['response_id'] . '-0-100.html', $render_temp->output(), 0644);
            unset($render_temp);
        }
        if ($treeline[$gen_data['post_counter']]['response_to'] > 0) {
            if (!$treeline[$gen_data['post_counter']]['post_number']) {
                break;
            }
            $resid = $dataforce['response_id'];
            $render_temp = new nel_render();
            $render_temp2 = new nel_render();
            $render_temp3 = new nel_render();
            nel_render_post($dataforce, $render_temp, TRUE, FALSE, $gen_data, $treeline, $dbh);
            // for thread
            $dataforce['response_id'] = 0;
            nel_render_post($dataforce, $render_temp2, TRUE, TRUE, $gen_data, $treeline, $dbh);
            // for collapse
            nel_render_post($dataforce, $render_temp3, TRUE, TRUE, $gen_data, $treeline, $dbh);
            // for expand
            $dataforce['response_id'] = $resid;
            if ($gen_data['post_count'] > BS_ABBREVIATE_THREAD) {
                if ($render_collapse->output() === '') {
                    $dataforce['omitted_done'] = FALSE;
                    nel_render_post($dataforce, $render_temp2, TRUE, TRUE, $gen_data, $treeline, $dbh);
                    // for collapse
                    $dataforce['omitted_done'] = TRUE;
                }
                if ($gen_data['post_counter'] > $gen_data['post_count'] - BS_ABBREVIATE_THREAD) {
                    $render_collapse->input($render_temp2->output());
                }
            }
            $render->input($render_temp->output());
            $render_expand->input($render_temp3->output());
        } else {
            nel_render_post($dataforce, $render, FALSE, FALSE, $gen_data, $treeline, $dbh);
        }
        ++$partlimit;
        ++$gen_data['post_counter'];
        unset($render_temp);
        unset($render_temp2);
        unset($render_temp3);
    }
    nel_render_footer($render, FALSE, TRUE, TRUE, TRUE, FALSE);
    if (!empty($_SESSION) && !$_SESSION['ignore_login']) {
        if ($dataforce['expand']) {
            $render_expand->output(TRUE);
        } else {
            if ($dataforce['collapse']) {
                $render_collapse->output(TRUE);
            } else {
                $render->output(TRUE);
            }
        }
        die;
    } else {
        nel_write_file(PAGE_PATH . $write_id . '/' . $dataforce['response_id'] . '.html', $render->output(FALSE), 0644);
        nel_write_file(PAGE_PATH . $write_id . '/' . $dataforce['response_id'] . '-expand.html', $render_expand->output(FALSE), 0644);
        nel_write_file(PAGE_PATH . $write_id . '/' . $dataforce['response_id'] . '-collapse.html', $render_collapse->output(FALSE), 0644);
    }
}
Exemplo n.º 4
0
function nel_write_multi_cache($dataforce)
{
    $template_info = nel_template_info(NULL, NULL, NULL, TRUE);
    $template_info = nel_reset_template_status($template_info);
    $cache = '<?php
$dataforce[\'post_links\'] = \'' . $dataforce['post_links'] . '\';
$dataforce[\'rules_list\'] = \'' . $dataforce['rules_list'] . '\';
$template_info = ' . var_export($template_info, TRUE) . ';
nel_template_info(NULL, NULL, $template_info, FALSE);
?>';
    nel_write_file(CACHE_PATH . 'multi-cache.nelcache', $cache, 0644);
}
Exemplo n.º 5
0
 public function write_auth_file()
 {
     $new_auth = '<?php $authorized = ' . var_export($this->authorized) . '?>';
     nel_write_file(FILES_PATH . '/auth_data.nel.php', $new_auth, 0644);
 }
Exemplo n.º 6
0
function generate_auth_file($plugins)
{
    if (!file_exists(FILES_PATH . '/auth_data.nel.php')) {
        if (DEFAULTADMIN !== '' && DEFAULTADMIN_PASS !== '') {
            echo 'Creating auth file...';
            $new_auth = '<?php
$authorized = array(
	\'' . DEFAULTADMIN . '\' => array(
        \'settings\' => array(
            \'staff_password\' => \'' . nel_hash(DEFAULTADMIN_PASS, $plugins) . '\',
            \'staff_type\' => \'admin\',
            \'staff_trip\' => \'\'),
	    \'perms\' => array(
            \'perm_config\' => TRUE,
            \'perm_staff_panel\' => TRUE,
            \'perm_ban_panel\' => TRUE,
            \'perm_thread_panel\' => TRUE,
            \'perm_mod_mode\' => TRUE,
            \'perm_ban\' => TRUE,
            \'perm_delete\' => TRUE,
            \'perm_post\' => TRUE,
            \'perm_post_anon\' => TRUE,
            \'perm_sticky\' => TRUE,
            \'perm_update_pages\' => TRUE,
            \'perm_update_cache\' => TRUE
		)),
	); ?>';
            if (nel_write_file(FILES_PATH . 'auth_data.nel.php', $new_auth, 0644)) {
                $stuff_done = TRUE;
            } else {
                die('Could not create auth file. Check permissions and config.php then retry installation.');
            }
        } else {
            $stuff_done = TRUE;
            echo 'ERROR: Could not create auth file due to invalid or missing admin info. The board will probably work but you will have no administrative abilities. Check your config.php then retry installation.';
        }
    }
}