Пример #1
0
	    </cms:if>
	</cms:form>
    </cms:capture>
	
    <cms:if form_validated >
	<cms:php> k_install("<cms:show acct_name/>", "<cms:show acct_pwd/>", "<cms:show acct_email/>"); </cms:php>
	<cms:if k_install_error >
	    <div class="error">
		<h3>Installation failed!</h3> 
		<cms:show k_install_error />
	    </div>
	<cms:else />
	    <div class="success">
		<h3>Installation successful!</h3>
		Please <a href="<cms:php> echo K_ADMIN_URL . K_ADMIN_PAGE; </cms:php>"><b>login</b></a> using the information you provided.
	    </div>
	</cms:if>	
    <cms:else />
	<cms:show my_form />
    </cms:if>
	
    <?php 
echo $FUNCS->login_footer();
?>
    <?php 
///////////////////////////
$html = ob_get_contents();
ob_end_clean();
$parser = new KParser($html);
echo $parser->get_HTML();
die;
Пример #2
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;
 }
Пример #3
0
 function embed($html = '', $is_code = 0)
 {
     global $CTX, $TAGS;
     if (!$is_code) {
         $filename = trim($html);
         if (!strlen($filename)) {
             return;
         }
     } else {
         if (!strlen(trim($html))) {
             return;
         }
         $code = $html;
     }
     // get the 'obj_sc' object placed by the calling 'do_shortcode' tag on context stack
     $node =& $CTX->get_object('obj_sc', 'do_shortcodes');
     if (is_null($node)) {
         // Not called from a shortcode handler.
         //.. handle using a new instance of parser
         if (!$is_code) {
             if (defined('K_SNIPPETS_DIR')) {
                 // always defined relative to the site
                 $base_snippets_dir = K_SITE_DIR . K_SNIPPETS_DIR . '/';
             } else {
                 $base_snippets_dir = K_COUCH_DIR . 'snippets/';
             }
             $filepath = $base_snippets_dir . ltrim(trim($filename), '/\\');
             $html = @file_get_contents($filepath);
             if ($html === FALSE) {
                 return;
             }
         }
         $parser = new KParser($html);
         return $parser->get_HTML();
     }
     // prepare parameters for the surrogate 'embed' tag
     $params = array();
     $param = array();
     if ($is_code) {
         $param['lhs'] = 'code';
     }
     $param['op'] = '=';
     $param['rhs'] = $filename ? $filename : $code;
     $params[] = $param;
     // invoke 'embed'
     $html = $TAGS->embed($params, $node);
     return $html;
 }
Пример #4
0
 function add_hidden_fields(&$attr_custom, $params, $node)
 {
     global $FUNCS, $PAGE;
     if (!strlen($this->users_tpl)) {
         return;
     }
     // take the opportunity to add the hidden fields
     if ($PAGE->tpl_name == $this->users_tpl) {
         $html = "\n                <cms:ignore>\n                <cms:editable name='extended_user_css' type='message'>\n                <style type=\"text/css\">\n                    #k_element_extended_user_id,\n                    #k_element_extended_user_email\n                    { display:none; }\n                </style>\n                </cms:editable>\n                </cms:ignore>\n                <cms:editable label='Extended-User ID' name='extended_user_id' search_type='integer' type='text'>0</cms:editable>\n                <cms:editable label='Extended-User Email' name='extended_user_email' type='text' />\n                <cms:editable label='New Password' name='extended_user_password' type='dummy_password' />\n                <cms:editable label='Repeat New Password' name='extended_user_password_repeat' type='dummy_password' />\n                ";
         $parser = new KParser($html, $node->line_num, 0, '', $node->ID);
         $dom = $parser->get_DOM();
         foreach ($dom->children as $child_node) {
             if ($child_node->type == K_NODE_TYPE_CODE) {
                 $node->children[] = $child_node;
             }
         }
     }
 }
Пример #5
0
 function process_match_route($params, $node)
 {
     global $FUNCS, $CTX, $PAGE, $TAGS;
     if (count($node->children)) {
         die("ERROR: Tag \"" . $node->name . "\" is a self closing tag");
     }
     $attr = $FUNCS->get_named_vars(array('path' => '', 'masterpage' => '', 'debug' => '0', 'is_404' => '0'), $params);
     extract($attr);
     $path = trim($path);
     $masterpage = trim($masterpage);
     $debug = $debug == 1 ? 1 : 0;
     $is_404 = $is_404 == 1 ? 1 : 0;
     if ($path == '') {
         $path = $_GET['q'];
     }
     if ($masterpage == '') {
         $masterpage = $PAGE->tpl_name;
     }
     $routes =& $this->get_routes($masterpage);
     if (!count($routes)) {
         if ($debug) {
             $html = '<pre><b><font color="red">No routes defined.</font></b></pre>';
         }
         return $html;
     }
     $html = '<pre>';
     if ($debug) {
         $html .= 'Path to match: <i>' . htmlspecialchars($path, ENT_QUOTES, K_CHARSET) . '</i><br/><br/>';
     }
     $found = null;
     foreach ($routes as $route) {
         if ($debug) {
             $html .= 'Trying route <b>' . $route->name . ':</b><br/>';
             $html .= 'Pattern: <i>' . htmlspecialchars($route->path, ENT_QUOTES, K_CHARSET) . '</i><br/>';
             $html .= 'Regex: <i>' . htmlspecialchars($route->regex, ENT_QUOTES, K_CHARSET) . '</i><br/>';
         }
         if ($route->isMatch($path, $_SERVER)) {
             $found = $route;
             if ($debug) {
                 $html .= '<b><font color="green">Matched!</font></b> <br/>Following variable(s) will be set:<br/>';
                 $html .= '   k_matched_route = ' . $route->name . '<br />';
                 foreach ($route->values as $k => $v) {
                     if ($route->wildcard && $k == $route->wildcard) {
                         $wildcard_count = count($route->values[$route->wildcard]);
                         $html .= '   rt_wildcard_count = ' . $wildcard_count . '<br/>';
                         $html .= '   rt_' . $k . ' = ' . htmlspecialchars(implode('/', $route->values[$route->wildcard]), ENT_QUOTES, K_CHARSET) . '<br/>';
                         for ($x = 0; $x < $wildcard_count; $x++) {
                             $html .= '   rt_' . $k . '_' . ($x + 1) . ' = ' . htmlspecialchars($route->values[$route->wildcard][$x], ENT_QUOTES, K_CHARSET) . '<br/>';
                         }
                     } else {
                         $html .= '   rt_' . $k . ' = ' . htmlspecialchars($v, ENT_QUOTES, K_CHARSET) . '<br/>';
                     }
                 }
                 $html .= '<br/>';
             }
             break;
         } else {
             if ($debug) {
                 $html .= '<b><font color="red">Failed!</font></b><br/>Reason: ';
                 foreach ($route->debug as $msg) {
                     $html .= $msg . '<br/>';
                 }
                 $html .= '<br/>';
             }
         }
     }
     if ($found) {
         $route = $found;
         $CTX->set('k_matched_route', $route->name, 'global');
         $vars = array();
         foreach ($route->values as $k => $v) {
             if ($route->wildcard && $k == $route->wildcard) {
                 $wildcard_count = count($route->values[$route->wildcard]);
                 $vars['rt_wildcard_count'] = $wildcard_count;
                 $vars['rt_' . $k] = implode('/', $route->values[$route->wildcard]);
                 for ($x = 0; $x < $wildcard_count; $x++) {
                     $vars['rt_' . $k . '_' . ($x + 1)] = $route->values[$route->wildcard][$x];
                 }
             } else {
                 $vars['rt_' . $k] = $v;
             }
         }
         $CTX->set_all($vars, 'global');
         // execute filters if any
         $str_filters = $route->filters;
         // e.g. 'test=1,abc,3 | test2 | test3=xyz'
         if (strlen($str_filters)) {
             if ($debug) {
                 $html .= 'Following filter(s) will be called:<br/>';
             }
             $arr_filters = array_filter(array_map("trim", preg_split("/(?<!\\\\)\\|/", $str_filters)));
             // split on unescaped '|'
             foreach ($arr_filters as $filter) {
                 $filter = str_replace('\\|', '|', $filter);
                 // filter has arguments? e.g. 'test=1,2,3'
                 $arr_args = array_filter(array_map("trim", preg_split("/(?<!\\\\)\\=/", $filter)));
                 // split on unescaped '='
                 $filter = $arr_args[0];
                 $args = '';
                 if (isset($arr_args[1])) {
                     $str_args = str_replace('\\=', '=', $arr_args[1]);
                     // multiple arguments?
                     $arr_args = array_filter(array_map("trim", preg_split("/(?<!\\\\)\\,/", $str_args)));
                     // split on unescaped ','
                     for ($x = 0; $x < count($arr_args); $x++) {
                         $args .= " arg_" . ($x + 1) . "='" . str_replace(array("\\,", "'"), array(",", "\\'"), $arr_args[$x]) . "'";
                     }
                     $args = " arg_count='" . count($arr_args) . "'" . $args;
                 } else {
                     $args = " arg_count='0'";
                 }
                 if ($filter) {
                     $filter = 'filters/' . $filter . '.html';
                     if (!$debug) {
                         $code = "\n                                    <cms:set rs= '' />\n\n                                    <cms:capture into='rs' scope='parent'>\n                                        <cms:embed '{$filter}' {$args} />\n                                    </cms:capture>\n\n                                    <cms:php>global \$CTX; \$CTX->set( 'rs', trim(\$CTX->get('rs')) ); </cms:php>\n\n                                    <cms:if rs >\n                                        <cms:abort rs is_404 />\n                                    </cms:if>\n                                ";
                         $parser = new KParser($code, $node->line_num, 0, '', $node->ID);
                         $parser->get_HTML();
                     } else {
                         $html .= '   ' . $filter . ' (' . htmlspecialchars($args, ENT_QUOTES, K_CHARSET) . ' ) <br/>';
                     }
                 }
             }
         }
     } else {
         $CTX->set('k_matched_route', '', 'global');
         if ($debug) {
             $html .= '<h3><font color="red">No matching route found.</font></h3>';
         } elseif ($is_404) {
             $params = array(array('lhs' => 'msg', 'op' => '=', 'rhs' => ''), array('lhs' => 'is_404', 'op' => '=', 'rhs' => '1'));
             $TAGS->abort($params, $node);
         }
     }
     $html .= '</pre>';
     if ($debug) {
         return $html;
     }
 }
Пример #6
0
 function resolve_dynamic_params()
 {
     if (!$this->system && $this->dynamic) {
         $arr_dynamic = array_map("trim", explode('|', $this->dynamic));
         foreach ($arr_dynamic as $dyn_param) {
             if (in_array($dyn_param, array('desc', 'type', 'order', 'group', 'separator'))) {
                 $dyn_param = 'k_' . $dyn_param;
             }
             if (array_key_exists($dyn_param, $this) && $this->{$dyn_param}) {
                 if (defined('K_SNIPPETS_DIR')) {
                     // always defined relative to the site
                     $base_snippets_dir = K_SITE_DIR . K_SNIPPETS_DIR . '/';
                 } else {
                     $base_snippets_dir = K_COUCH_DIR . 'snippets/';
                 }
                 $filepath = $base_snippets_dir . ltrim(trim($this->{$dyn_param}), '/\\');
                 if (file_exists($filepath)) {
                     $html = @file_get_contents($filepath);
                     if (strlen($html)) {
                         $parser = new KParser($html);
                         $this->{$dyn_param} = $parser->get_HTML();
                     }
                 }
             }
         }
     }
 }
Пример #7
0
 function smart_embed($params, $node)
 {
     global $CTX, $FUNCS, $PAGE;
     if (count($node->children)) {
         die("ERROR: Tag \"" . $node->name . "\" is a self closing tag");
     }
     extract($FUNCS->get_named_vars(array('folder' => '', 'debug' => '0'), $params));
     // sanitize params
     $debug = trim($debug);
     if (defined('K_SNIPPETS_DIR')) {
         // always defined relative to the site
         $base_snippets_dir = K_SITE_DIR . K_SNIPPETS_DIR;
     } else {
         $base_snippets_dir = K_COUCH_DIR . 'snippets';
     }
     $folder = trim(trim($folder), '/\\');
     $folder_name = $folder;
     if (!$folder_name) {
         $folder_name = '/';
     }
     $folder = $base_snippets_dir . ($folder ? '/' . $folder : '');
     //full path
     // What are the files available in the specified folder?
     // First check if info available from cache
     if (array_key_exists($folder_name, $FUNCS->cached_files)) {
         $available_files = $FUNCS->cached_files[$folder_name];
     } else {
         $available_files = array();
         if (is_dir($folder) && ($fp = opendir($folder))) {
             while (($file = readdir($fp)) !== false) {
                 if (is_file($folder . '/' . $file)) {
                     $pi = $FUNCS->pathinfo($file);
                     if ($pi['filename']) {
                         $available_files[$pi['filename']] = $pi['basename'];
                     }
                 }
             }
             closedir($fp);
             // cache results
             $FUNCS->cached_files[$folder_name] = $available_files;
         } else {
             if (!$debug) {
                 return;
             }
         }
     }
     // What are the candidate file names for the current view?
     // First check cache
     if (array_key_exists('cached_valid_files_for_view', $FUNCS)) {
         $valid_files = $FUNCS->cached_valid_files_for_view;
     } else {
         // What is the current view?
         if ($PAGE->tpl_is_clonable) {
             //views associated only with clonable templates
             if ($PAGE->is_master) {
                 if ($PAGE->is_folder_view) {
                     $view = 'folder';
                 } elseif ($PAGE->is_archive_view) {
                     $view = 'archive';
                 } else {
                     $view = 'home';
                 }
             } else {
                 $view = 'page';
             }
         }
         $valid_files = array();
         $tplname = $PAGE->tpl_name;
         $pos = strrpos($tplname, '.');
         if ($pos !== false) {
             $tplname = substr($tplname, 0, $pos);
             //$tplext = substr( $tplname, $pos+1 );
         }
         $tplname = str_replace('/', '-', $tplname);
         if ($view) {
             // clonable template
             switch ($view) {
                 case 'page':
                     if ($PAGE->nested_page_obj) {
                         $arr =& $PAGE->nested_page_obj->root->get_parents_by_id($PAGE->id);
                         if (is_array($arr)) {
                             for ($x = 0; $x < count($arr); $x++) {
                                 if ($x == 0) {
                                     $valid_files[] = $tplname . '-page_ex-' . $arr[$x]->name;
                                 }
                                 $valid_files[] = $tplname . '-page-' . $arr[$x]->name;
                             }
                         }
                     } else {
                         $valid_files[] = $tplname . '-page-' . $PAGE->page_name;
                     }
                     $valid_files[] = $tplname . '-page';
                     $valid_files[] = $tplname . '-default';
                     $valid_files[] = 'page';
                     $valid_files[] = 'default';
                     break;
                 case 'folder':
                     $folders =& $PAGE->folders;
                     $arr = $folders->get_parents_by_id($PAGE->folder_id);
                     if (is_array($arr)) {
                         for ($x = 0; $x < count($arr); $x++) {
                             if ($x == 0) {
                                 $valid_files[] = $tplname . '-folder_ex-' . $arr[$x]->name;
                             }
                             $valid_files[] = $tplname . '-folder-' . $arr[$x]->name;
                         }
                     }
                     $valid_files[] = $tplname . '-folder';
                     $valid_files[] = $tplname . '-list';
                     $valid_files[] = $tplname . '-default';
                     $valid_files[] = 'folder';
                     $valid_files[] = 'list';
                     $valid_files[] = 'default';
                     break;
                 case 'archive':
                     $valid_files[] = $tplname . '-archive';
                     $valid_files[] = $tplname . '-list';
                     $valid_files[] = $tplname . '-default';
                     $valid_files[] = 'archive';
                     $valid_files[] = 'list';
                     $valid_files[] = 'default';
                     break;
                 case 'home':
                     $valid_files[] = $tplname . '-home';
                     $valid_files[] = $tplname . '-list';
                     $valid_files[] = $tplname . '-default';
                     $valid_files[] = 'home';
                     $valid_files[] = 'list';
                     $valid_files[] = 'default';
             }
         } else {
             // non-clonable template
             $valid_files[] = $tplname . '-default';
             $valid_files[] = 'default';
         }
         // Cache results
         $FUNCS->cached_valid_files_for_view = $valid_files;
     }
     // Choose the first candidate file present within the available files
     foreach ($valid_files as $valid_file) {
         if (array_key_exists($valid_file, $available_files)) {
             $chosen_file = $available_files[$valid_file];
             break;
         }
     }
     // Embed chosen file
     if (!$debug) {
         if ($chosen_file) {
             $html = @file_get_contents($folder . '/' . $chosen_file);
             if ($html) {
                 $parser = new KParser($html, $node->line_num, 0, '', $node->ID);
                 return $parser->get_HTML();
             }
         }
     } else {
         // output debug info
         if ($view) {
             $html = '<h2>' . $view . '-view </h2>';
         }
         $folder = str_replace(K_SITE_DIR, '', $folder);
         $html .= 'Looking for files in folder <i>' . $folder . '</i>: ';
         $html .= '<ul>';
         foreach ($valid_files as $valid_file) {
             $html .= '<li>';
             $html .= $chosen_file && $available_files[$valid_file] == $chosen_file ? '<b>' . $valid_file . ' * </b>' : $valid_file;
             $html .= '</li>';
         }
         $html .= '</ul><b>';
         if ($chosen_file) {
             $html .= 'Chosen file: ' . $chosen_file;
         } else {
             $html .= 'No suitable file found';
         }
         $html .= '</b><br /><br />';
         return $html;
     }
 }
Пример #8
0
function k_admin_list_pages($tpl)
{
    global $DB, $AUTH, $FUNCS, $TAGS, $CTX, $Config, $PAGE, $cid, $rid;
    // first check if any custom viewer registered for this template
    if (array_key_exists($tpl['name'], $FUNCS->admin_list_views)) {
        $snippet = $FUNCS->admin_list_views[$tpl['name']];
        if (defined('K_SNIPPETS_DIR')) {
            // always defined relative to the site
            $base_snippets_dir = K_SITE_DIR . K_SNIPPETS_DIR . '/';
        } else {
            $base_snippets_dir = K_COUCH_DIR . 'snippets/';
        }
        $filepath = $base_snippets_dir . ltrim(trim($snippet), '/\\');
        $html = @file_get_contents($filepath);
        if ($html !== FALSE) {
            $PAGE = new KWebpage($tpl['id'], null);
            if ($PAGE->error) {
                ob_end_clean();
                die('ERROR: ' . $PAGE->err_msg);
            }
            $parser = new KParser($html);
            //$html = $parser->get_HTML();
            $html = $parser->get_cached_HTML($filepath);
        } else {
            $html = 'ERROR: Unable to get contents from custom list_view <b>' . $filepath . '</b>';
        }
        return $html;
    }
    // proceed with the default logic
    $name = $tpl['title'] ? $tpl['title'] : $tpl['name'];
    $limit = 15;
    $pgn_pno = 1;
    if (isset($_GET['pg']) && $FUNCS->is_non_zero_natural($_GET['pg'])) {
        $pgn_pno = (int) $_GET['pg'];
    }
    if (isset($_GET['fid']) && $FUNCS->is_non_zero_natural($_GET['fid'])) {
        $fid = (int) $_GET['fid'];
    }
    if ($tpl['clonable']) {
        $folders =& $FUNCS->get_folders_tree($tpl['id'], $tpl['name']);
        if (count($folders->children)) {
            $has_folders = 1;
        }
        $arr_folders = array();
        if ($fid) {
            if ($has_folders) {
                $folder =& $folders->find_by_id($fid);
                if ($folder) {
                    if (!$tpl['gallery']) {
                        // get all the child folders of it. (except Gallery that shows content of only current folder)
                        $sub_folders = $folder->get_children();
                        //includes the parent folder too
                        foreach ($sub_folders as $sf) {
                            $arr_folders[$sf->name] = $sf->id;
                        }
                    }
                } else {
                    $fid = 0;
                }
            } else {
                $fid = 0;
            }
        }
        if ($tpl['gallery'] && !$fid) {
            $fid = '-1';
        }
        //root folder
        // Get pages derived from this template
        // formulate query
        $thumb_field = null;
        if ($tpl['gallery']) {
            // get id of the field that holds the thumbnail
            $rs3 = $DB->select(K_TBL_FIELDS, array('id'), "template_id='" . $DB->sanitize($tpl['id']) . "' and name='gg_thumb'");
            if (count($rs3)) {
                $thumb_field = $rs3[0]['id'];
            }
        }
        $tables = K_TBL_PAGES . ' p left outer join ' . K_TBL_FOLDERS . ' f on p.page_folder_id =  f.id';
        $tables .= ' inner join ' . K_TBL_TEMPLATES . ' t on t.id = p.template_id';
        if ($thumb_field) {
            $tables .= ' inner join ' . K_TBL_DATA_TEXT . ' d on p.id = d.page_id';
        }
        if ($cid && $rid) {
            $tables .= ' inner join ' . K_TBL_RELATIONS . ' rel on rel.pid = p.id';
        }
        $sql = "p.template_id='" . $DB->sanitize($tpl['id']) . "'";
        $sql .= " AND p.parent_id=0";
        if ($thumb_field) {
            $sql .= " AND d.field_id='" . $DB->sanitize($thumb_field) . "'";
        }
        if ($cid && $rid) {
            $sql .= " AND rel.cid='" . $DB->sanitize($cid) . "' AND rel.fid='" . $DB->sanitize($rid) . "'";
        }
        if (!$tpl['gallery']) {
            if (count($arr_folders)) {
                $sql .= " AND ";
                $sql .= "(";
                $sep = "";
                foreach ($arr_folders as $k => $v) {
                    $sql .= $sep . "p.page_folder_id='" . $DB->sanitize($v) . "'";
                    $sep = " OR ";
                }
                $sql .= ")";
            }
        } else {
            $sql .= " AND p.page_folder_id='" . $DB->sanitize($fid) . "'";
            if ($AUTH->user->access_level < K_ACCESS_LEVEL_SUPER_ADMIN) {
                $sql .= " AND p.is_master <> 1";
            }
        }
        $sql .= " ORDER BY publish_date desc";
        // first query for pagination
        $rs = $DB->select($tables, array('count(p.id) as cnt'), $sql);
        $total_rows = $rs[0]['cnt'];
        $total_pages = ceil($total_rows / $limit);
        // actual query
        if ($pgn_pno > $total_pages && $total_pages > 0) {
            $pgn_pno = $total_pages;
        }
        $limit_sql = sprintf(" LIMIT %d, %d", ($pgn_pno - 1) * $limit, $limit);
        $arr_fields = array('p.*', 'f.title', 'f.access_level as flevel', 't.access_level as tlevel');
        if ($thumb_field) {
            $arr_fields[] = 'd.value as thumb';
        }
        $rs2 = $DB->select($tables, $arr_fields, $sql . $limit_sql);
        $count = count($rs2);
        // paginator
        $adjacents = 2;
        $targetpage = K_ADMIN_URL . K_ADMIN_PAGE . '?act=list&tpl=' . $tpl['id'];
        if ($fid) {
            $targetpage .= '&fid=' . $fid;
        }
        if ($cid && $rid) {
            $targetpage .= '&cid=' . $cid . '&rid=' . $rid;
        }
        $pagestring = "&pg=";
        $prev_text = '&#171; ' . $FUNCS->t('prev');
        $next_text = $FUNCS->t('next') . ' &#187;';
        $simple = 0;
        // record counts
        $total_records_on_page = $count < $limit ? $count : $limit;
        if ($total_records_on_page > 0) {
            $first_record_on_page = $limit * ($pgn_pno - 1) + 1;
            $last_record_on_page = $first_record_on_page + $total_records_on_page - 1;
        } else {
            $first_record_on_page = $last_record_on_page = 0;
        }
        $str .= '<form name="frm_list_pages" id="frm_list_pages" action="" method="post">';
        // check for missing template
        if (!file_exists(K_SITE_DIR . $tpl['name'])) {
            $str .= '<div class="error" style="margin-bottom:10px;">';
            $str .= '<strong>' . $FUNCS->t('template_missing') . '</strong>';
            if ($AUTH->user->access_level >= K_ACCESS_LEVEL_SUPER_ADMIN) {
                $rs3 = $DB->select(K_TBL_PAGES, array('id'), "template_id='" . $DB->sanitize($tpl['id']) . "'");
                if (count($rs3)) {
                    $str .= ' <i>(' . $FUNCS->t('remove_template_completely') . ')</i>';
                }
            }
            $str .= '</div>';
        }
        if ($cid && $rid) {
            $str .= _get_rel_banner($cid, $rid);
        }
        $str .= '<div class="wrap-paginator">';
        if ($has_folders) {
            $str .= '<div class="bulk-actions">';
            $CTX->push('__ROOT__');
            $html = '';
            $param2 = $fid;
            $folders->visit(array('KFolder', '_k_visitor'), $html, $param2, 0, 0, array());
            $CTX->pop();
            $root_folder = $tpl['gallery'] ? '--- ' . $FUNCS->t('root') . ' ---' : $FUNCS->t('view_all_folders');
            $str .= '<select id="f_k_folders" name="f_k_folders"><option value="-1" >' . $root_folder . '</option>' . $html . '</select>';
            $link = K_ADMIN_URL . K_ADMIN_PAGE . '?act=list&tpl=' . $tpl['id'];
            if ($cid && $rid) {
                $link .= '&cid=' . $cid . '&rid=' . $rid;
            }
            $str .= '<a class="button" id="btn_folder_submit" href="' . $link . '" onclick="this.style.cursor=\'wait\'; return false;"><span>' . $FUNCS->t('filter') . '</span></a>';
            $str .= '</div>';
        }
        if ($total_rows > $limit) {
            $str_paginator = $FUNCS->getPaginationString($pgn_pno, $total_rows, $limit, $adjacents, $targetpage, $pagestring, $prev_text, $next_text, $simple);
            $str_paginator .= "<div class='record-count'>" . $FUNCS->t('showing') . " {$first_record_on_page}-{$last_record_on_page} / {$total_rows}</div>";
            $str .= $str_paginator;
        }
        $str .= '</div>';
        if ($tpl['gallery']) {
            $showing_related = $cid && $rid ? 1 : 0;
            $str .= '<div id="gallery" class="group-wrapper listing">';
            // Display the immediate child folders first
            $child_folder_count = 0;
            if ($pgn_pno == 1 && $has_folders && !$showing_related) {
                $root_folder = $folder ? $folder : $folders;
                $child_folder_count = count($root_folder->children);
                for ($x = 0; $x < $child_folder_count; $x++) {
                    $child_folder = $root_folder->children[$x];
                    $child_folder_name = $child_folder->title ? $child_folder->title : $child_folder->name;
                    $last_class = ($x + 1) % 5 ? '' : ' last';
                    $str .= '<div class="item' . $last_class . '">';
                    $str .= '<div class="item_inner folder">';
                    $str .= '<a style="background-image:url(\'' . K_ADMIN_URL . 'theme/images/folder.gif' . '\')" class="item_image folder" title="' . $child_folder_name . '" href="' . $link . '&fid=' . $child_folder->id . '" ></a>';
                    $str .= '</div>';
                    $str .= '<div class="name">' . $child_folder_name . '</div>';
                    $str_qty = $child_folder->consolidated_count == 1 ? $FUNCS->t('item') : $FUNCS->t('items');
                    $str .= '<div class="time">' . $child_folder->consolidated_count . ' ' . $str_qty . '</div>';
                    $str_qty = $child_folder->total_children == 1 ? $FUNCS->t('container') : $FUNCS->t('containers');
                    $str .= '<div class="size">' . $child_folder->total_children . ' ' . $str_qty . '</div>';
                    $str .= '</div>';
                }
            }
            if (!$count) {
                if (!$child_folder_count) {
                    $str .= '<div class="empty">' . $FUNCS->t('folder_empty') . '</div>';
                }
            } else {
                for ($x = 0; $x < $count; $x++) {
                    $p = $rs2[$x];
                    // Count of drafts
                    $rs3 = $DB->select(K_TBL_PAGES, array('count(id) as cnt'), "parent_id='" . $DB->sanitize($p['id']) . "'");
                    $count_drafts = $rs3[0]['cnt'];
                    // calculate effective access level
                    $access_level = $p['access_level'];
                    if ($p['flevel'] || $p['tlevel']) {
                        // access level at template or folders will override page level access
                        if (is_null($p['flevel'])) {
                            $p['flevel'] = 0;
                        }
                        $access_level = $p['flevel'] > $p['tlevel'] ? $p['flevel'] : $p['tlevel'];
                    }
                    $can_delete = $access_level <= $AUTH->user->access_level ? 1 : 0;
                    $last_class = ($x + 1 + $child_folder_count) % 5 ? '' : ' last';
                    $str .= '<div class="item' . $last_class . '">';
                    $str .= '<div class="item_inner">';
                    if ($thumb_field && $p['thumb']) {
                        $thumb_img = $p['thumb'];
                        if ($thumb_img[0] == ':') {
                            $thumb_img = substr($thumb_img, 1);
                            if (file_exists($Config['UserFilesAbsolutePath'] . 'image/' . $thumb_img)) {
                                $thumb_img = $Config['k_append_url'] . $Config['UserFilesPath'] . 'image/' . $thumb_img;
                            } else {
                                $thumb_img = K_ADMIN_URL . 'theme/images/exclaim.gif';
                            }
                        }
                    } else {
                        $thumb_img = K_ADMIN_URL . 'theme/images/exclaim.gif';
                    }
                    $abbr_title = strlen($p['page_title']) > 20 ? substr($p['page_title'], 0, 20) . '...' : $p['page_title'];
                    $update_link = K_ADMIN_URL . K_ADMIN_PAGE . '?act=edit&tpl=' . $tpl['id'] . '&p=' . $p['id'];
                    if ($showing_related) {
                        $update_link .= '&cid=' . $cid . '&rid=' . $rid;
                    }
                    $update_link .= '&nonce=' . $FUNCS->create_nonce('edit_page_' . $p['id']);
                    $str .= '<a href="' . $update_link . '" title="' . $p['page_title'] . '" class="item_image" style="background-image:url(\'' . $thumb_img . '\')">';
                    $str .= '</a>';
                    // checkbox
                    $str .= '<span class="checkbox"><input type="checkbox" value="' . $p['id'] . '" class="page-selector" name="page-id[]"';
                    if (!$can_delete || $count_drafts) {
                        $str .= ' disabled="1"';
                    }
                    $str .= '/></span>';
                    // actions
                    $str .= '<div class="actions">';
                    $str .= '<a href="' . K_SITE_URL . $tpl['name'] . '?p=' . $p['id'] . '" target="_blank" title="' . $FUNCS->t('view') . '"><img src="' . K_ADMIN_URL . 'theme/images/magnifier.gif"/></a>';
                    if ($can_delete && !$count_drafts) {
                        $nonce = $FUNCS->create_nonce('delete_page_' . $p['id']);
                        $confirm_prompt = "onclick='if( confirm(\"" . $FUNCS->t('confirm_delete_page') . ": " . $p['page_title'] . "?\") ) { return true; } return false;'";
                        $qs = '?act=delete&tpl=' . $tpl['id'] . '&p=' . $p['id'] . '&nonce=' . $nonce;
                        if (isset($_GET['fid'])) {
                            $qs .= '&fid=' . intval($_GET['fid']);
                        }
                        if (isset($_GET['pg'])) {
                            $qs .= '&pg=' . intval($_GET['pg']);
                        }
                        if ($showing_related) {
                            $qs .= '&cid=' . $cid . '&rid=' . $rid;
                        }
                        $str .= '<a href="' . K_ADMIN_URL . K_ADMIN_PAGE . $qs . '" ' . $confirm_prompt . '><img src="' . K_ADMIN_URL . 'theme/images/page_white_delete.gif" title="' . $FUNCS->t('delete') . '"/></a>';
                    }
                    if ($count_drafts) {
                        $a_title = $count_drafts > 1 ? ' ' . $FUNCS->t('drafts') : ' ' . $FUNCS->t('draft');
                        $str .= '<a title="' . $count_drafts . $a_title . '" href="' . K_ADMIN_URL . K_ADMIN_PAGE . '?o=drafts&tpl=' . $tpl['id'] . '&pid=' . $p['id'] . '"><img src="' . K_ADMIN_URL . 'theme/images/page_white_stack.gif"></a>';
                    }
                    $str .= '<a href="' . $update_link . '"><img title="' . $FUNCS->t('edit') . '" src="' . K_ADMIN_URL . 'theme/images/page_white_edit.gif" /></a>';
                    $str .= '</div>';
                    $str .= '</div>';
                    $str .= '<div class="name">' . $abbr_title . '</div>';
                    $str .= '<div class="time">';
                    if ($p['publish_date'] != '0000-00-00 00:00:00') {
                        $str .= date("M jS Y", strtotime($p['publish_date']));
                    } else {
                        $str .= $FUNCS->t('unpublished');
                    }
                    $str .= '</div>';
                    $file_size = $p['file_size'];
                    if (!$file_size) {
                        $file_size = 0;
                    }
                    if ($file_size > 0) {
                        $file_size = round($file_size / 1024);
                        if ($file_size < 1) {
                            $file_size = 1;
                        }
                    }
                    $str .= '<div class="size">' . $file_size . ' KB</div>';
                    $str .= '</div>';
                }
                // select all
                $str .= '<div style="clear:both;"></div>';
                $str .= '<div class="select_all">';
                $str .= '<label> ';
                $str .= '<input type="checkbox" name="check-all" onClick="$$(\'.page-selector\').set(\'checked\', this.checked);" />';
                $str .= '<strong>' . $FUNCS->t('select-deselect') . '</strong>';
                $str .= '</label>&nbsp;';
                $str .= '</div>';
            }
            $str .= '</div>';
        } else {
            $str .= '<div class="group-wrapper listing">';
            $str .= '<table class="listing clear" cellspacing="0" cellpadding="0">';
            $str .= '<thead>';
            $str .= '<th class="checkbox"><input type="checkbox" name="check-all" onClick="$$(\'.page-selector\').set(\'checked\', this.checked);" /></th>';
            $str .= '<th>' . $FUNCS->t('title') . '</th>';
            $str .= '<th>&nbsp;</th>';
            // count of drafts, comments
            $str .= '<th>' . $FUNCS->t('folder') . '</th>';
            $str .= '<th>' . $FUNCS->t('date') . '</th>';
            $str .= '<th>' . $FUNCS->t('actions') . '</th>';
            $str .= '</thead>';
            if (!$count) {
                $str .= '<tr><td colspan="6" class="last_row" style="text-align:center">' . $FUNCS->t('no_pages_found') . '</td></tr>';
            } else {
                for ($x = 0; $x < $count; $x++) {
                    $p = $rs2[$x];
                    // Count of drafts
                    $rs3 = $DB->select(K_TBL_PAGES, array('count(id) as cnt'), "parent_id='" . $DB->sanitize($p['id']) . "'");
                    $count_drafts = $rs3[0]['cnt'];
                    // calculate effective access level
                    $access_level = $p['access_level'];
                    if ($p['flevel'] || $p['tlevel']) {
                        // access level at template or folders will override page level access
                        if (is_null($p['flevel'])) {
                            $p['flevel'] = 0;
                        }
                        $access_level = $p['flevel'] > $p['tlevel'] ? $p['flevel'] : $p['tlevel'];
                    }
                    $can_delete = $access_level <= $AUTH->user->access_level ? 1 : 0;
                    $str .= '<tr>';
                    if ($x >= $count - 1) {
                        $last_row = " last_row";
                    }
                    // checkbox
                    $str .= '<td class="checkbox' . $last_row . '">';
                    $str .= '<input type="checkbox" value="' . $p['id'] . '" class="page-selector" name="page-id[]"';
                    if (!$can_delete || $count_drafts) {
                        $str .= ' disabled="1"';
                    }
                    $str .= '/>';
                    $str .= '</td>';
                    // page name
                    $str .= '<td class="name' . $last_row . '">';
                    if ($p['is_master'] && $AUTH->user->access_level >= K_ACCESS_LEVEL_SUPER_ADMIN) {
                        $str .= '<i>';
                    }
                    $nonce = $FUNCS->create_nonce('edit_page_' . $p['id']);
                    $edit_link = K_ADMIN_URL . K_ADMIN_PAGE . '?act=edit&tpl=' . $tpl['id'] . '&p=' . $p['id'];
                    if ($cid && $rid) {
                        $edit_link .= '&cid=' . $cid . '&rid=' . $rid;
                    }
                    $edit_link .= '&nonce=' . $nonce;
                    $abbr_title = strlen($p['page_title']) > 48 ? substr($p['page_title'], 0, 48) . '...' : $p['page_title'];
                    $str .= '<a href="' . $edit_link . '" title="' . $p['page_title'] . '">' . $abbr_title . '</a>';
                    if ($p['is_master'] && $AUTH->user->access_level >= K_ACCESS_LEVEL_SUPER_ADMIN) {
                        $str .= '</i>';
                    }
                    $str .= '</td>';
                    // drafts & comments
                    $str .= '<td class="comments-count' . $last_row . '">';
                    if ($count_drafts) {
                        $a_title = $count_drafts > 1 ? ' ' . $FUNCS->t('drafts') : ' ' . $FUNCS->t('draft');
                        $str .= '<span class="drafts-count"><a title="' . $count_drafts . $a_title . '" href="' . K_ADMIN_URL . K_ADMIN_PAGE . '?o=drafts&tpl=' . $tpl['id'] . '&pid=' . $p['id'] . '">' . $count_drafts . '<img src="' . K_ADMIN_URL . 'theme/images/page_white_stack.gif"></a></span>';
                    }
                    if ($p['comments_count']) {
                        $a_title = $p['comments_count'] > 1 ? ' ' . $FUNCS->t('comments') : ' ' . $FUNCS->t('comment');
                        $str .= '<span class="comments-count"><a title="' . $p['comments_count'] . $a_title . '" href="' . K_ADMIN_URL . K_ADMIN_PAGE . '?o=comments&page_id=' . $p['id'] . '">' . $p['comments_count'] . '<img src="' . K_ADMIN_URL . 'theme/images/comments.gif"></a></span>';
                    }
                    if (!$count_drafts && !$p['comments_count']) {
                        $str .= '&nbsp;';
                    }
                    $str .= '</td>';
                    // folder title
                    $str .= '<td class="folder' . $last_row . '">';
                    if ($p['title']) {
                        $str .= $p['title'];
                    } else {
                        $str .= '&nbsp;';
                    }
                    $str .= '</td>';
                    // date
                    $str .= '<td class="date' . $last_row . '">';
                    if ($p['publish_date'] != '0000-00-00 00:00:00') {
                        $str .= date("M jS Y", strtotime($p['publish_date']));
                    } else {
                        $str .= $FUNCS->t('unpublished');
                    }
                    $str .= '</td>';
                    // actions
                    $str .= '<td class="actions' . $last_row . '">';
                    $str .= '<a href="' . $edit_link . '"><img src="' . K_ADMIN_URL . 'theme/images/page_white_edit.gif"  title="' . $FUNCS->t('edit') . '"/></a>';
                    if ($can_delete && !$count_drafts) {
                        $nonce = $FUNCS->create_nonce('delete_page_' . $p['id']);
                        $confirm_prompt = "onclick='if( confirm(\"" . $FUNCS->t('confirm_delete_page') . ": " . $p['page_title'] . "?\") ) { return true; } return false;'";
                        $qs = '?act=delete&tpl=' . $tpl['id'] . '&p=' . $p['id'] . '&nonce=' . $nonce;
                        if (isset($_GET['fid'])) {
                            $qs .= '&fid=' . intval($_GET['fid']);
                        }
                        if (isset($_GET['pg'])) {
                            $qs .= '&pg=' . intval($_GET['pg']);
                        }
                        if ($cid && $rid) {
                            $qs .= '&cid=' . $cid . '&rid=' . $rid;
                        }
                        $str .= '<a href="' . K_ADMIN_URL . K_ADMIN_PAGE . $qs . '" ' . $confirm_prompt . '><img src="' . K_ADMIN_URL . 'theme/images/page_white_delete.gif" title="' . $FUNCS->t('delete') . '"/></a>';
                    }
                    $str .= '<a href="' . K_SITE_URL . $tpl['name'] . '?p=' . $p['id'] . '" target="_blank" title="' . $FUNCS->t('view') . '"><img src="' . K_ADMIN_URL . 'theme/images/magnifier.gif"/></a>';
                    $str .= '</td>';
                    $str .= '</tr>';
                }
            }
            $str .= '</table>';
            $str .= '</div>';
        }
        $str .= '<div class="wrap-paginator">';
        if ($count) {
            $str .= '<div class="bulk-actions">';
            $str .= '<a class="button" id="btn_bulk_submit" href="#"><span>' . $FUNCS->t('delete_selected') . '</span></a>';
            $str .= '</div>';
        } else {
            if ($AUTH->user->access_level >= K_ACCESS_LEVEL_SUPER_ADMIN) {
                if (!file_exists(K_SITE_DIR . $tpl['name'])) {
                    // make sure no drafts or pages exist before prompting for template removal
                    $rs3 = $DB->select(K_TBL_PAGES, array('id'), "template_id='" . $DB->sanitize($tpl['id']) . "'");
                    if (!count($rs3)) {
                        $str .= '<a class="button" href="javascript:k_delete_template(' . $tpl['id'] . ', \'' . $FUNCS->create_nonce('delete_tpl_' . $tpl['id']) . '\')" title="' . $FUNCS->t('remove_template') . '"><span>' . $FUNCS->t('remove_template') . '</span></a>';
                    }
                }
            }
        }
        $str .= $str_paginator;
        $str .= '</div>';
        $str .= '<input type="hidden" id="nonce" name="nonce" value="' . $FUNCS->create_nonce('bulk_action_page') . '" />';
        $str .= '<input type="hidden" id="bulk-action" name="bulk-action" value="delete" />';
        $str .= '</form>';
        // Associated JavaScript
        if (!$tpl['gallery']) {
            $str .= k_admin_js(0);
        } else {
            $str .= k_admin_js(2);
        }
    }
    return $str;
}
Пример #9
0
 function &get_DOM()
 {
     if (!$this->parsed) {
         $starts = $this->pos;
         $len = strlen($this->str);
         $tag_name = '';
         $closing_tag_name = '';
         $attributes = array();
         $attr = null;
         $quote_type = 0;
         $processing_cond = false;
         // Conditional tags requires special consideration
         $brackets_count = 0;
         while ($this->pos < $len) {
             $c = $this->str[$this->pos];
             if ($c == "\n") {
                 $this->line_num++;
             }
             switch ($this->state) {
                 case K_STATE_TEXT:
                     if ($c == '<') {
                         if (substr($this->str, $this->pos + 1, strlen(K_START_TAG_IDENT)) == K_START_TAG_IDENT) {
                             $text = substr($this->str, $starts, $this->pos - $starts);
                             if ($this->quit_at_char == '"') {
                                 $text = str_replace('\\"', '"', $text);
                             }
                             $this->add_child(K_NODE_TYPE_TEXT, '', '', $text);
                             $this->pos += strlen(K_START_TAG_IDENT);
                             $starts = $this->pos + 1;
                             $this->state = K_STATE_TAG_NAME;
                         } elseif (substr($this->str, $this->pos + 1, strlen(K_END_TAG_IDENT)) == K_END_TAG_IDENT) {
                             $text = substr($this->str, $starts, $this->pos - $starts);
                             if ($this->quit_at_char == '"') {
                                 $text = str_replace('\\"', '"', $text);
                             }
                             $this->add_child(K_NODE_TYPE_TEXT, '', '', $text);
                             $this->pos += strlen(K_END_TAG_IDENT);
                             $starts = $this->pos + 1;
                             $this->state = K_STATE_TAG_CLOSE;
                         }
                     } elseif ($this->quit_at_char && $c == $this->quit_at_char) {
                         if ($this->str[$this->pos - 1] != '\\') {
                             break 2;
                         }
                     }
                     break;
                 case K_STATE_TAG_OPEN:
                     if ($processing_cond && $brackets_count) {
                         $this->raise_error("Unclosed bracket in \"" . $tag_name . "\"", $this->line_num, $this->pos);
                     }
                     if (isset($attr)) {
                         $attributes[] = $attr;
                     }
                     for ($x = 0; $x < count($attributes); $x++) {
                         $attr =& $attributes[$x];
                         if (!isset($attr['value']) && isset($attr['name'])) {
                             $attr['value'] = $attr['name'];
                             $attr['value_type'] = K_VAL_TYPE_VARIABLE;
                             if (!$processing_cond) {
                                 $attr['op'] = '=';
                             }
                             unset($attr['name']);
                         } elseif (!$processing_cond && !isset($attr['name']) && isset($attr['value'])) {
                             $attr['op'] = '=';
                         }
                         if ($attr['value_type'] == K_VAL_TYPE_LITERAL) {
                             $quote_type = $attr['quote_type'];
                             $attr['value'] = str_replace('\\' . $quote_type, $quote_type, $attr['value']);
                         }
                     }
                     $push = $this->str[$this->pos - 1] != '/';
                     $this->add_child(K_NODE_TYPE_CODE, $tag_name, $attributes, '', $push);
                     $processing_cond = false;
                     $brackets_count = 0;
                     $starts = $this->pos + 1;
                     $this->state = K_STATE_TEXT;
                     break;
                 case K_STATE_TAG_CLOSE:
                     if ($c == '>') {
                         $closing_tag_name = trim(substr($this->str, $starts, $this->pos - $starts));
                         if ($this->curr_node->name != $closing_tag_name) {
                             $this->raise_error("Closing tag \"" . $closing_tag_name . "\" has no matching opening tag", $this->line_num, $this->pos);
                         }
                         unset($this->curr_node);
                         $this->curr_node =& $this->stack[count($this->stack) - 1];
                         unset($this->stack[count($this->stack) - 1]);
                         $starts = $this->pos + 1;
                         $this->state = K_STATE_TEXT;
                     }
                     break;
                 case K_STATE_TAG_NAME:
                     if (!($this->pos == $starts ? $this->is_valid_for_label($c, 0) : $this->is_valid_for_label($c))) {
                         if ($this->is_white_space($c) && $this->pos != $starts) {
                             $tag_name = substr($this->str, $starts, $this->pos - $starts);
                             if ($tag_name == 'if' || $tag_name == 'while' || $tag_name == 'not' || $tag_name == 'else_if') {
                                 $processing_cond = true;
                             }
                             $starts = $this->pos + 1;
                             $this->state = K_STATE_ATTR_NAME;
                         } elseif ($c == '>' || $c == '/' && $this->str[$this->pos + 1] == '>') {
                             $tag_name = substr($this->str, $starts, $this->pos - $starts);
                             if ($c == '>') {
                                 $this->pos--;
                             }
                             $this->state = K_STATE_TAG_OPEN;
                         } else {
                             $this->raise_error("TAG_NAME: Invalid char \"" . $c . "\" in tagname", $this->line_num, $this->pos);
                         }
                     } else {
                         if ($this->pos == $starts) {
                             //First valid char
                             $attributes = array();
                             unset($attr);
                         }
                     }
                     break;
                 case K_STATE_ATTR_NAME:
                     if (!($this->pos == $starts ? $this->is_valid_for_label($c, 0) : $this->is_valid_for_label($c))) {
                         if ($this->is_white_space($c)) {
                             if ($this->pos != $starts) {
                                 $attr['name'] = substr($this->str, $starts, $this->pos - $starts);
                                 $this->state = K_STATE_ATTR_OP;
                             } else {
                                 $starts++;
                             }
                         } elseif (($c == '"' || $c == "'") && $this->pos == $starts) {
                             if (isset($attr)) {
                                 $attributes[] = $attr;
                             }
                             $attr = array();
                             $this->pos--;
                             $this->state = K_STATE_ATTR_VAL;
                         } elseif ($processing_cond && $this->pos == $starts && $c == '(') {
                             if (isset($attr)) {
                                 $attributes[] = $attr;
                             }
                             $attr = array();
                             $attr['op'] = $c;
                             $brackets_count++;
                             $starts++;
                         } elseif ($processing_cond && $this->pos != $starts && ($this->is_logical_op() || $c == ')')) {
                             $attr['name'] = substr($this->str, $starts, $this->pos - $starts);
                             $starts = $this->pos;
                             $this->pos--;
                             $this->state = K_STATE_LOGIC_OP;
                         } elseif ($c == '=' || $processing_cond && $this->pos != $starts && $this->is_cond_op()) {
                             if (isset($attr['value_type'])) {
                                 // a prev standalone 'value' remains unprocessed
                                 $this->raise_error("ATTRIB_NAME: Invalid char \"" . $c . "\"", $this->line_num, $this->pos);
                             }
                             $attr['name'] = substr($this->str, $starts, $this->pos - $starts);
                             $this->pos--;
                             $this->state = K_STATE_ATTR_OP;
                         } elseif ($c == '>' || $c == '/' && $this->str[$this->pos + 1] == '>') {
                             if (isset($attr) && in_array($attr['op'], $this->logical_ops)) {
                                 $this->raise_error("ATTRIB_NAME: Orphan \"" . $attr['op'] . "\"", $this->line_num, $this->pos);
                             }
                             if ($this->pos != $starts) {
                                 $attr['name'] = substr($this->str, $starts, $this->pos - $starts);
                             }
                             if ($c == '>') {
                                 $this->pos--;
                             }
                             $this->state = K_STATE_TAG_OPEN;
                         } else {
                             $this->raise_error("ATTRIB_NAME: Invalid char \"" . $c . "\"", $this->line_num, $this->pos);
                         }
                     } else {
                         if ($this->pos == $starts) {
                             //First valid char
                             if (isset($attr)) {
                                 $attributes[] = $attr;
                             }
                             $attr = array();
                         }
                     }
                     break;
                 case K_STATE_ATTR_OP:
                     if ($this->is_white_space($c)) {
                     } elseif ($processing_cond && ($op = $this->is_logical_op() || $c == ')')) {
                         $starts = $this->pos;
                         $this->pos--;
                         $this->state = K_STATE_LOGIC_OP;
                     } elseif ($processing_cond && ($op = $this->is_cond_op())) {
                         $this->pos++;
                         $attr['op'] = $op;
                         $starts = $this->pos + 1;
                         $this->state = K_STATE_ATTR_VAL;
                     } elseif ($c == '>' || $c == '/' && $this->str[$this->pos + 1] == '>') {
                         if ($c == '>') {
                             $this->pos--;
                         }
                         $this->state = K_STATE_TAG_OPEN;
                     } elseif ($c == '=') {
                         $op = '=';
                         $attr['op'] = $op;
                         $starts = $this->pos + 1;
                         $this->state = K_STATE_ATTR_VAL;
                     } elseif ($this->is_valid_for_label($c, 0) || $c == '"' || $c == "'") {
                         $starts = $this->pos;
                         $this->pos--;
                         $this->state = K_STATE_ATTR_NAME;
                     } else {
                         $this->raise_error("OPERATOR: Invalid char \"" . $c . "\"", $this->line_num, $this->pos);
                     }
                     break;
                 case K_STATE_ATTR_VAL:
                     if ($starts == $this->pos) {
                         if ($this->is_white_space($c)) {
                             $starts++;
                         } elseif ($c == '"' || $c == "'") {
                             $quote_type = $c;
                             // A double-quoted value might contain nested code.
                             if ($quote_type == '"') {
                                 $code_starts = strpos($this->str, '<' . K_START_TAG_IDENT, $this->pos + 1);
                                 $next_quote = $this->find_next_quote($this->pos + 1);
                                 if ($code_starts !== false && $next_quote !== false && $code_starts < $next_quote) {
                                     $attr['value_type'] = K_VAL_TYPE_SPECIAL;
                                     $parser = new KParser($this->str, $this->line_num, $this->pos + 1, '"', $this->id_prefix);
                                     $attr['value'] = $parser->get_DOM();
                                     $this->line_num = $parser->line_num;
                                     $this->pos = $parser->pos;
                                     $starts = $this->pos + 1;
                                     if ($processing_cond) {
                                         $this->state = K_STATE_LOGIC_OP;
                                     } else {
                                         $this->state = K_STATE_ATTR_NAME;
                                     }
                                 }
                             }
                         } else {
                             $quote_type = 0;
                             if (!$this->is_valid_for_label($c, 0)) {
                                 $this->raise_error("ATTRIB_VALUE: Invalid first char \"" . $c . "\"", $this->line_num, $this->pos);
                             }
                         }
                     } else {
                         if (!$quote_type) {
                             if (!$this->is_valid_for_label($c)) {
                                 if ($c == '>' || $c == '/' && $this->str[$this->pos + 1] == '>') {
                                     $attr['value'] = substr($this->str, $starts, $this->pos - $starts);
                                     $attr['value_type'] = K_VAL_TYPE_VARIABLE;
                                     if ($c == '>') {
                                         $this->pos--;
                                     }
                                     $this->state = K_STATE_TAG_OPEN;
                                 } elseif ($this->is_white_space($c)) {
                                     $attr['value'] = substr($this->str, $starts, $this->pos - $starts);
                                     $attr['value_type'] = K_VAL_TYPE_VARIABLE;
                                     $starts = $this->pos + 1;
                                     if ($processing_cond) {
                                         $this->state = K_STATE_LOGIC_OP;
                                     } else {
                                         $this->state = K_STATE_ATTR_NAME;
                                     }
                                 } elseif ($processing_cond && ($this->is_logical_op() || $c == ')')) {
                                     $attr['value'] = substr($this->str, $starts, $this->pos - $starts);
                                     $attr['value_type'] = K_VAL_TYPE_VARIABLE;
                                     $starts = $this->pos;
                                     $this->pos--;
                                     $this->state = K_STATE_LOGIC_OP;
                                 } else {
                                     $this->raise_error("ATTRIB_VALUE: Invalid char \"" . $c . "\"", $this->line_num, $this->pos);
                                 }
                             }
                         } else {
                             if ($c == $quote_type) {
                                 if ($this->str[$this->pos - 1] != '\\') {
                                     $starts++;
                                     $attr['value'] = substr($this->str, $starts, $this->pos - $starts);
                                     $attr['value_type'] = K_VAL_TYPE_LITERAL;
                                     $attr['quote_type'] = $quote_type;
                                     $starts = $this->pos + 1;
                                     if ($processing_cond) {
                                         $this->state = K_STATE_LOGIC_OP;
                                     } else {
                                         $this->state = K_STATE_ATTR_NAME;
                                     }
                                 }
                             }
                         }
                     }
                     break;
                 case K_STATE_LOGIC_OP:
                     if ($this->is_white_space($c)) {
                         $starts++;
                     } elseif ($op = $this->is_logical_op()) {
                         if (isset($attr)) {
                             $attributes[] = $attr;
                         }
                         $attr = array();
                         $attr['op'] = substr($this->str, $starts, 2);
                         $this->pos++;
                         $starts = $this->pos + 1;
                         $this->state = K_STATE_ATTR_NAME;
                     } elseif ($processing_cond && $c == ')') {
                         $brackets_count--;
                         if ($brackets_count < 0) {
                             $this->raise_error("LOGIC_OP: Closing bracket has no matching open bracket", $this->line_num, $this->pos);
                         }
                         if (isset($attr)) {
                             $attributes[] = $attr;
                         }
                         $attr = array();
                         $attr['op'] = $c;
                         $starts++;
                     } elseif ($c == '>' || $c == '/' && $this->str[$this->pos + 1] == '>') {
                         if ($c == '>') {
                             $this->pos--;
                         }
                         $this->state = K_STATE_TAG_OPEN;
                     } else {
                         $this->raise_error("LOGIC_OP: Invalid char \"" . $c . "\"", $this->line_num, $this->pos);
                     }
                     break;
             }
             $this->pos++;
         }
         if ($this->state != K_STATE_TEXT) {
             $this->raise_error("Parsing ended in an invalid state", $this->line_num, $this->pos);
         }
         if (count($this->stack)) {
             if (count($this->stack) > 1) {
                 $dangling_tag =& $this->stack[count($this->stack) - 1];
             } else {
                 $dangling_tag = $this->curr_node;
             }
             $this->raise_error("Tag \"" . @$dangling_tag->name . "\" has no matching closing tag", $this->line_num, $this->pos);
         }
         $text = substr($this->str, $starts, $this->pos - $starts);
         if ($this->quit_at_char == '"') {
             $text = str_replace('\\"', '"', $text);
         }
         $this->add_child(K_NODE_TYPE_TEXT, '', '', $text);
         $this->parsed = true;
     }
     return $this->DOM;
 }