Esempio n. 1
0
 function invoke($ignore_level = 0)
 {
     global $DB, $FUNCS, $PAGE, $AUTH, $CTX, $k_cache_file;
     if ($ignore_level > 0) {
         $ignore_canonical_url = 1;
         // if set, the url used to access page is not checked to be canonical.
         if ($ignore_level > 1) {
             $ignore_context = 1;
             // if set, all canonical GET variables are ignored. Page always remains in home-view.
         }
     }
     // $page_id, $folder_id and $archive_date are mutually exclusive.
     // If more than one are provided, $page_id will be preferred over the
     // others and $folder_id will be preferred over $archive_date.
     // All ids will be preferred over names.
     // comment_id actually resolves to becoming the page_id of
     // the associated page hence it is processed the foremost.
     $page_id = null;
     $folder_id = null;
     $archive_date = null;
     $page_name = null;
     $folder_name = null;
     $comment_id = null;
     $comment_date = '';
     if (!$ignore_context) {
         // if comment id given, find the associated page_id
         if (isset($_GET['comment']) && $FUNCS->is_non_zero_natural($_GET['comment'])) {
             $rs = $DB->select(K_TBL_COMMENTS, array('page_id', 'date', 'approved'), "id='" . $DB->sanitize(intval($_GET['comment'])) . "'");
             if (count($rs)) {
                 $comment_id = intval($_GET['comment']);
                 $comment_date = $rs[0]['date'];
                 $_GET['p'] = $rs[0]['page_id'];
             }
         }
         if (isset($_GET['p']) && $FUNCS->is_non_zero_natural($_GET['p'])) {
             $page_id = (int) $_GET['p'];
         } else {
             if (isset($_GET['f']) && $FUNCS->is_non_zero_natural($_GET['f'])) {
                 $folder_id = (int) $_GET['f'];
             } else {
                 if (isset($_GET['d']) && $FUNCS->is_non_zero_natural($_GET['d'])) {
                     $date = (int) $_GET['d'];
                     // example valid values:
                     //  ?d=20080514
                     //  ?d=200805
                     //  ?d=2008
                     $len = strlen($date);
                     if ($len >= 4) {
                         $year = substr($date, 0, 4);
                         $archive_date = $year;
                         if ($len >= 6) {
                             $month = substr($date, 4, 2);
                             $archive_date .= '-' . $month;
                             if ($len > 6) {
                                 $day = substr($date, 6, 2);
                                 $archive_date .= '-' . $day;
                             }
                         }
                         if ($day) {
                             $next_archive_date = date('Y-m-d H:i:s', mktime(0, 0, 0, $month, $day + 1, $year));
                             $is_archive_day_view = 1;
                         } elseif ($month) {
                             $next_archive_date = date('Y-m-d H:i:s', mktime(0, 0, 0, $month + 1, 1, $year));
                             $is_archive_month_view = 1;
                         } else {
                             $next_archive_date = date('Y-m-d H:i:s', mktime(0, 0, 0, 1, 1, $year + 1));
                             $is_archive_year_view = 1;
                         }
                         $archive_date = $FUNCS->make_date($archive_date);
                     }
                 } else {
                     if (isset($_GET['pname']) && $FUNCS->is_title_clean($_GET['pname'])) {
                         $page_name = $_GET['pname'];
                     } else {
                         if (isset($_GET['fname']) && $FUNCS->is_title_clean($_GET['fname'])) {
                             $folder_name = $_GET['fname'];
                         }
                     }
                 }
             }
         }
     } else {
         $CTX->ignore_context = 1;
         // necessary for nested_pages with prettyurls
     }
     if ($AUTH->user->access_level >= K_ACCESS_LEVEL_SUPER_ADMIN) {
         $DB->begin();
         // Serialize access for super-admins.. hack of a semaphore
         $DB->update(K_TBL_SETTINGS, array('k_value' => K_COUCH_VERSION), "k_key='k_couch_version'");
     }
     // Get the requested page.
     // for folder view and archive view, page_id would be null,
     // causing the default page to be loaded.
     //
     $CTX->folder_info = !is_null($folder_name) ? $folder_name : (!is_null($folder_id) ? (int) $folder_id : null);
     // added for 404 on non-existent folders
     if (!is_null($page_name)) {
         $PAGE = new KWebpage(null, null, $page_name);
     } else {
         $PAGE = new KWebpage(null, $page_id);
     }
     if ($PAGE->error) {
         ob_end_clean();
         $DB->rollback();
         if ($PAGE->err_msg == 'Page not found') {
             header('HTTP/1.1 404 Not Found');
             header('Status: 404 Not Found');
             header('Content-Type: text/html; charset=' . K_CHARSET);
             $html = '';
             if (file_exists(K_SITE_DIR . '404.php')) {
                 $html = $FUNCS->file_get_contents(K_SITE_URL . '404.php');
             }
             if (!$html) {
                 $html = 'Page not found';
             }
         } else {
             die('ERROR: ' . $PAGE->err_msg);
         }
     } else {
         $access_level = $PAGE->get_access_level($inherited);
         $AUTH->check_access($access_level);
         // set the requested view, if any
         if ($folder_id) {
             $PAGE->is_folder_view = 1;
             $PAGE->folder_id = $folder_id;
         } elseif ($archive_date) {
             $PAGE->is_archive_view = 1;
             $PAGE->archive_date = $archive_date;
             $PAGE->next_archive_date = $next_archive_date;
             if ($is_archive_day_view) {
                 $PAGE->is_archive_day_view = 1;
             } elseif ($is_archive_month_view) {
                 $PAGE->is_archive_month_view = 1;
             } else {
                 $PAGE->is_archive_year_view = 1;
             }
             $PAGE->day = $day;
             $PAGE->month = $month;
             $PAGE->year = $year;
         } elseif ($folder_name) {
             if (!$PAGE->changed_from_folder_to_page) {
                 // can happen with nested pages
                 $PAGE->is_folder_view = 1;
                 $PAGE->folder_name = $folder_name;
             }
         } elseif ($comment_id) {
             // not a view but just to remind the page that it was fetched on the basis of comment id.
             $PAGE->comment_id = $comment_id;
             $PAGE->comment_date = $comment_date;
         }
         $html = ob_get_contents();
         ob_end_clean();
         // HOOK: pre_process_page
         $FUNCS->dispatch_event('pre_process_page', array(&$html, &$PAGE, &$ignore_canonical_url));
         $parser = new KParser($html);
         $html = $parser->get_HTML();
         //echo $parser->get_info();
         $FUNCS->post_process_page();
         if ($AUTH->user->access_level >= K_ACCESS_LEVEL_SUPER_ADMIN) {
             $DB->commit(1);
         }
         // Verify that the url used to access this page is the page's canonical url
         if ($comment_id) {
             // if page accessed via comment_id, rectify the url
             $canonical_url = K_SITE_URL . $PAGE->link;
             if ($PAGE->comment_page) {
                 $sep = strpos($canonical_url, '?') === false ? '?' : '&';
                 $canonical_url .= $sep . 'comments_pg=' . $PAGE->comment_page;
             }
             $redirect_url = $canonical_url . "#comment-" . $comment_id;
         } elseif (K_PRETTY_URLS && $_SERVER['REQUEST_METHOD'] != 'POST' && !$PAGE->parent_id && $CTX->script != '404.php' && !$ignore_canonical_url) {
             $url = $FUNCS->get_url();
             if ($url) {
                 if ($_GET['_nr_']) {
                     //page link being masqueraded. Normalize before comparision.
                     $masq_tpl_name = $FUNCS->get_pretty_template_link($PAGE->tpl_name);
                     /*masquereded name*/
                     $unmasq_tpl_name = $FUNCS->get_pretty_template_link_ex($PAGE->tpl_name, $dummy, 0);
                     /*unmasquereded name*/
                     $canonical_url = K_SITE_URL . $unmasq_tpl_name . substr($PAGE->link, strlen($masq_tpl_name));
                     //replace masquered name with unmasqueraded
                 } else {
                     $canonical_url = K_SITE_URL . $PAGE->link;
                 }
                 if ($url != $canonical_url) {
                     // Redirect to canonical url
                     // append querystring params, if any
                     $sep = '';
                     foreach ($_GET as $qk => $qv) {
                         if ($qk == 'p' || $qk == 'f' || $qk == 'd' || $qk == 'fname' || $qk == 'pname' || $qk == '_nr_') {
                             continue;
                         }
                         $qs .= $sep . $qk . '=' . urlencode($qv);
                         $sep = '&';
                     }
                     if ($qs) {
                         $qs = '?' . $qs;
                     }
                     if ($_GET['_nr_']) {
                         //page link being masqueraded
                         $redirect_url = K_SITE_URL . $PAGE->link . $qs;
                     } else {
                         $redirect_url = $canonical_url . $qs;
                     }
                 }
             }
         }
     }
     $content_type = $PAGE->content_type ? $PAGE->content_type : 'text/html';
     $content_type_header = 'Content-Type: ' . $content_type . ';';
     $content_type_header .= ' charset=' . K_CHARSET;
     // Add our link to the document (if not commercial license)
     // Apply only to text/html, text/html-sandboxed, application/xhtml+xml mime-types
     // application/xml and text/xml can also be used to serve xhtml documents but we'll allow that.
     if (!(K_PAID_LICENSE || K_REMOVE_FOOTER_LINK)) {
         if (strpos($content_type, 'html') !== false) {
             $_cnt = preg_match_all("/<\\/[^\\S]*BODY[^\\S]*>/is", $html, $matches, PREG_OFFSET_CAPTURE);
             if ($_cnt) {
                 $_split_at = $matches[0][count($matches[0]) - 1][1];
             } else {
                 $_cnt = preg_match_all("/<\\/[^\\S]*HTML[^\\S]*>/is", $html, $matches, PREG_OFFSET_CAPTURE);
                 if ($_cnt) {
                     $_split_at = $matches[0][count($matches[0]) - 1][1];
                 }
             }
             $_link = "\n                    <div style=\"clear:both; text-align: center; z-index:99999 !important; display:block !important; visibility:visible !important;\">\n                        <div style=\"position:relative; top:0; margin-right:auto;margin-left:auto; z-index:99999; display:block !important; visibility:visible !important;\">\n                        <center><a href=\"http://www.couchcms.com/\" title=\"CouchCMS - Simple Open-Source Content Management\" style=\"display:block !important; visibility:visible !important;\">Powered by CouchCMS</a></center><br />\n                        </div>\n                    </div>\n                    ";
             if ($_split_at) {
                 $_pre = substr($html, 0, $_split_at);
                 $_post = substr($html, $_split_at);
                 $html = $_pre . $_link . $_post;
             } else {
                 $html .= $_link;
             }
         }
     }
     // HOOK: alter_final_page_output
     $FUNCS->dispatch_event('alter_final_page_output', array(&$html, &$PAGE, &$k_cache_file, &$redirect_url, &$content_type_header));
     // See if ouput needs to be cached
     if ($k_cache_file && strlen(trim($html)) && !$PAGE->no_cache) {
         $handle = @fopen($k_cache_file, 'w');
         if ($handle) {
             if ($redirect_url) {
                 $pg['redirect_url'] = $redirect_url;
             } else {
                 $pg['mime_type'] = $content_type_header;
                 $cached_html = $html . "\n<!-- Cached page";
                 if (!K_PAID_LICENSE) {
                     $cached_html .= " served by CouchCMS - Simple Open-Source Content Management";
                 }
                 $cached_html .= " -->\n";
                 $pg['cached_html'] = $cached_html;
                 if ($PAGE->err_msg == 'Page not found') {
                     $pg['res_404'] = 1;
                 }
             }
             @flock($handle, LOCK_EX);
             @fwrite($handle, serialize($pg));
             @flock($handle, LOCK_UN);
             @fclose($handle);
         }
     }
     if ($redirect_url) {
         header("Location: " . $redirect_url, TRUE, 301);
         die;
     }
     if (!K_PAID_LICENSE) {
         $html .= "\n<!-- Page generated by CouchCMS - Simple Open-Source Content Management";
         $html .= " -->\n";
     }
     if (defined('K_IS_MY_TEST_MACHINE')) {
         $html .= "\n<!-- in: " . k_timer_stop() . " -->\n";
         $html .= "\n<!-- Queries: " . $DB->queries . " -->\n";
     }
     header($content_type_header);
     echo $html;
 }
Esempio n. 2
0
    function render_admin_page_ex($_p)
    {
        global $AUTH, $DB;
        if (!K_PAID_LICENSE) {
            $html_title = 'CouchCMS - Simple Open-Source Content Management : ';
        }
        $html_title .= $this->t('admin_panel');
        ?>
            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
            <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
            <head>
                <title><?php 
        echo $html_title;
        ?>
</title>
                <link rel="shortcut icon" href="<?php 
        echo K_ADMIN_URL . 'favicon.ico';
        ?>
" type="image/x-icon" />
                <script type="text/javascript">try { document.execCommand('BackgroundImageCache', false, true); } catch(e) {}</script>
                <script type="text/javascript" src="<?php 
        echo K_ADMIN_URL . 'includes/mootools-core-1.4.5.js';
        ?>
"></script>
                <script type="text/javascript" src="<?php 
        echo K_ADMIN_URL . 'includes/mootools-more-1.4.0.1.js';
        ?>
"></script>
                <script type="text/javascript" src="<?php 
        echo K_ADMIN_URL . 'includes/slimbox/slimbox.js';
        ?>
"></script>
                <script type="text/javascript" src="<?php 
        echo K_ADMIN_URL . 'includes/smoothbox/smoothbox.js?v=1.3.5';
        ?>
"></script>
                <?php 
        foreach ($this->scripts as $k => $v) {
            echo '<script type="text/javascript" src="' . $v . '"></script>' . "\n";
        }
        ?>

                <link rel="stylesheet" href="<?php 
        echo K_ADMIN_URL . 'includes/slimbox/slimbox.css';
        ?>
" type="text/css" media="screen" />
                <link rel="stylesheet" href="<?php 
        echo K_ADMIN_URL . 'includes/smoothbox/smoothbox.css';
        ?>
" type="text/css" media="screen" />
                <link rel="stylesheet" href="<?php 
        echo K_ADMIN_URL . 'theme/styles.css?ver=' . K_COUCH_BUILD . '';
        ?>
" type="text/css" media="screen" />
                <!--[if IE]>
                <link rel="stylesheet" href="<?php 
        echo K_ADMIN_URL . 'theme/ie.css?ver=' . K_COUCH_BUILD . '';
        ?>
" type="text/css" media="screen, projection">
                <![endif]-->
                <?php 
        foreach ($this->styles as $k => $v) {
            echo '<link rel="stylesheet" href="' . $v . '" type="text/css" media="screen" />' . "\n";
        }
        ?>
            </head>
            <body>
            <div id="container" ><div id="container2" >

            <?php 
        // header
        echo '<div id="header" >';
        if (K_PAID_LICENSE) {
            if (defined('K_LOGO_DARK')) {
                $logo_src = K_ADMIN_URL . 'theme/images/' . K_LOGO_DARK;
            } else {
                $logo_src = K_ADMIN_URL . 'theme/images/couch_dark.gif';
            }
        } else {
            $logo_src = K_ADMIN_URL . 'logo.php?d=1';
        }
        echo '<a href="' . K_ADMIN_URL . K_ADMIN_PAGE . '"><img id="couch-logo" src="' . $logo_src . '" /></a>';
        echo '<ul id="admin-subnav">';
        $nonce = $this->create_nonce('update_user_' . $AUTH->user->id);
        echo '<li>' . $this->t('greeting') . ', <a href="' . K_ADMIN_URL . K_ADMIN_PAGE . '?o=users&act=edit&id=' . $AUTH->user->id . '&nonce=' . $nonce . '"><b>' . ucwords(strtolower($AUTH->user->title)) . '</b></a></li>';
        echo '<li>|</li>';
        echo '<li><a href="' . K_SITE_URL . '" target="_blank">' . $this->t('view_site') . '</a></li>';
        echo '<li>|</li>';
        echo '<li><a href="' . $this->get_logout_link(K_ADMIN_URL . K_ADMIN_PAGE) . '">' . $this->t('logout') . '</a></li>';
        echo '</ul>';
        ?>
            <noscript>
                <div class="error">
                    <?php 
        echo $this->t('javascript_msg');
        ?>
                </div>
            </noscript>
            <?php 
        if ($_p['link']) {
            echo '<h2><a id="listing-header" href="' . $_p['link'] . '">' . $_p['title'] . '</a></h2>';
        } else {
            echo '<h2>' . $_p['title'] . '</h2>';
        }
        echo $_p['buttons'];
        echo '</div>';
        // end header
        // body
        ?>
            <div id="sidebar">
                <ul class="templates">
                    <?php 
        $show_comments_link = 0;
        $rs = $DB->select(K_TBL_TEMPLATES, array('*'), '1=1 ORDER BY k_order, id ASC');
        if (count($rs)) {
            foreach ($rs as $tpl) {
                $class = '';
                if ($tpl['hidden']) {
                    if ($AUTH->user->access_level < K_ACCESS_LEVEL_SUPER_ADMIN) {
                        continue;
                    } else {
                        $class = "hidden-template ";
                    }
                }
                $class .= $tpl['name'] == $_p['tpl_name'] ? "active-template" : "template";
                echo '<li class="' . $class . '">';
                if ($tpl['clonable']) {
                    $link = K_ADMIN_URL . K_ADMIN_PAGE . '?act=list&tpl=' . $tpl['id'];
                } else {
                    $nonce = $this->create_nonce('edit_page_' . $tpl['id']);
                    $link = K_ADMIN_URL . K_ADMIN_PAGE . '?act=edit&tpl=' . $tpl['id'] . '&nonce=' . $nonce;
                }
                if ($AUTH->user->access_level >= K_ACCESS_LEVEL_SUPER_ADMIN) {
                    echo '<a title="' . $tpl['name'] . '" href="' . $link . '">';
                } else {
                    echo '<a href="' . $link . '">';
                }
                if ($tpl['clonable']) {
                    echo '<img src="' . K_ADMIN_URL . 'theme/images/copy.gif"/> ';
                }
                echo $tpl['title'] ? $tpl['title'] : $tpl['name'];
                echo '</a>';
                echo '</li>';
                if ($tpl['commentable']) {
                    $show_comments_link = 1;
                }
            }
        }
        ?>
                    <li class="template-separator">
                        <a href="#">&nbsp;</a>
                    </li>
                    <?php 
        // Show link to comments section only if any template is commentable or if any comment exists
        if (!$show_comments_link) {
            $rs = $DB->select(K_TBL_COMMENTS, array('id'), '1=1 LIMIT 1');
            if (count($rs)) {
                $show_comments_link = 1;
            }
        }
        ?>
                    <?php 
        if ($show_comments_link) {
            $class = $_p['module'] == 'comments' ? "active-template" : "template";
            ?>
                            <li class="<?php 
            echo $class;
            ?>
">
                                <a title="<?php 
            echo $this->t('manage_comments');
            ?>
" href="<?php 
            echo K_ADMIN_URL . K_ADMIN_PAGE . '?o=comments';
            ?>
">
                                    <img src="<?php 
            echo K_ADMIN_URL . 'theme/images/comment.gif';
            ?>
">
                                    <?php 
            echo $this->t('comments');
            ?>
                                </a>
                            </li>
                    <?php 
        }
        ?>

                    <?php 
        $class = $_p['module'] == 'users' ? "active-template" : "template";
        ?>
                    <li class="<?php 
        echo $class;
        ?>
">
                        <a title="<?php 
        echo $this->t('manage_users');
        ?>
" href="<?php 
        echo K_ADMIN_URL . K_ADMIN_PAGE . '?o=users';
        ?>
">
                            <img src="<?php 
        echo K_ADMIN_URL . 'theme/images/user.gif';
        ?>
">
                            <?php 
        echo $this->t('users');
        ?>
                        </a>
                    </li>

                    <?php 
        if ($_p['module'] == 'drafts') {
            $class = 'active-template';
            $draft_img = 'drafts-open.gif';
            $show_drafts_link = 1;
        } else {
            $class = 'template';
            $draft_img = 'drafts-closed.gif';
        }
        if (!$show_drafts_link) {
            $rs = $DB->select(K_TBL_PAGES, array('id'), 'parent_id>0 LIMIT 1');
            if (count($rs)) {
                $show_drafts_link = 1;
            }
        }
        ?>
                    <?php 
        if ($show_drafts_link) {
            ?>
                    <li class="<?php 
            echo $class;
            ?>
">
                        <a title="<?php 
            echo $this->t('manage_drafts');
            ?>
" href="<?php 
            echo K_ADMIN_URL . K_ADMIN_PAGE . '?o=drafts';
            ?>
">
                            <img src="<?php 
            echo K_ADMIN_URL . 'theme/images/' . $draft_img;
            ?>
">
                            <?php 
            echo $this->t('drafts');
            ?>
                        </a>
                    </li>
                    <?php 
        }
        ?>
                </ul>
            </div>

            <div id="admin-wrapper">
                <div id="admin-wrapper-header">
                    <?php 
        if ($_p['show_advanced']) {
            ?>
                        <div id="advanced-settings">
                            <a id="toggle" class="collapsed" href="#"><?php 
            echo $this->t('advanced_settings');
            ?>
</a>
                        </div>
                    <?php 
        }
        ?>
                    <?php 
        if ($_p['subtitle']) {
            echo '<h3>' . $_p['subtitle'] . '</h3>';
        }
        ?>

                </div>
                <div id="admin-wrapper-body">
                    <?php 
        echo $_p['content'];
        ?>
                </div>
            </div>

            <div id="footer" style="z-index:99999 !important; display:block !important; visibility:visible !important;">
                <?php 
        $admin_footer = '<a href="http://www.couchcms.com/" style="display:inline !important; visibility:visible !important;">CouchCMS - Simple Open-Source Content Management ';
        $admin_footer .= 'v' . K_COUCH_VERSION . ' (build ' . K_COUCH_BUILD . ')</a>';
        if (K_PAID_LICENSE) {
            if (defined('K_ADMIN_FOOTER')) {
                $admin_footer = K_ADMIN_FOOTER;
            }
        }
        echo $admin_footer;
        if (defined('K_IS_MY_TEST_MACHINE')) {
            echo '&nbsp;[' . k_timer_stop() . ']';
        }
        ?>
            </div>
            </div></div>
            </body>
            </html>
            <?php 
        die;
    }