From af035cb860b2b936a71b1109c6e01250373b250d Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Thu, 23 Apr 2015 17:10:27 -0500 Subject: [PATCH] oops: Fix crash rendering attachments for FAQ articles Also, show sidebar on "Other Resources" pages, and fix a problem displaying the correct Other Resource page. --- assets/default/css/theme.css | 4 +-- include/class.faq.php | 4 +-- include/client/templates/sidebar.tmpl.php | 43 +++++++++++++++++++++++ index.php | 40 ++------------------- pages/index.php | 30 ++++++++++------ 5 files changed, 68 insertions(+), 53 deletions(-) create mode 100644 include/client/templates/sidebar.tmpl.php diff --git a/assets/default/css/theme.css b/assets/default/css/theme.css index 24a57c7d6..e1cf19907 100644 --- a/assets/default/css/theme.css +++ b/assets/default/css/theme.css @@ -413,7 +413,7 @@ body { } .front-page-button { } -#landing_page .welcome { +.main-content { width: 560px; } #landing_page #new_ticket { @@ -984,7 +984,7 @@ img.sign-in-image { margin-bottom: 20px; margin-left: 20px; } -#landing_page .sidebar { +.sidebar { width: 220px; } .rtl .sidebar { diff --git a/include/class.faq.php b/include/class.faq.php index 20474c733..f2d42355b 100644 --- a/include/class.faq.php +++ b/include/class.faq.php @@ -316,8 +316,8 @@ class FAQ extends VerySimpleModel { function getVisibleAttachments() { return array_merge( - $this->attachments->getSeparates() ?: array(), - $this->getLocalAttachments()); + $this->attachments->getSeparates()->all() ?: array(), + $this->getLocalAttachments()->all()); } function getAttachmentsLinks($separator=' ',$target='') { diff --git a/include/client/templates/sidebar.tmpl.php b/include/client/templates/sidebar.tmpl.php new file mode 100644 index 000000000..e3f15419e --- /dev/null +++ b/include/client/templates/sidebar.tmpl.php @@ -0,0 +1,43 @@ +<?php +$BUTTONS = isset($BUTTONS) ? $BUTTONS : true; +?> + <div class="sidebar pull-right"> +<?php if ($BUTTONS) { ?> + <div class="front-page-button flush-right"> +<p> + <a href="open.php" style="display:block" class="blue button"><?php + echo __('Open a New Ticket');?></a> +</p> +<?php if ($cfg && !$cfg->isKnowledgebaseEnabled()) { ?> +<p> + <a href="view.php" style="display:block" class="green button"><?php + echo __('Check Ticket Status');?></a> +</p> +<?php } ?> + </div> +<?php } ?> + <div class="content"><?php + $faqs = FAQ::getFeatured()->select_related('category')->limit(5); + if ($faqs->all()) { ?> + <section><div class="header"><?php echo __('Featured Questions'); ?></div> +<?php foreach ($faqs as $F) { ?> + <div><a href="<?php echo ROOT_PATH; ?>/kb/faq.php?id=<?php + echo urlencode($F->getId()); + ?>"><?php echo $F->getLocalQuestion(); ?></a></div> +<?php } ?> + </section> +<?php + } + $resources = Page::getActivePages()->filter(array('type'=>'other')); + if ($resources->all()) { ?> + <section><div class="header"><?php echo __('Other Resources'); ?></div> +<?php foreach ($resources as $page) { ?> + <div><a href="<?php echo ROOT_PATH; ?>pages/<?php echo $page->getNameAsSlug(); + ?>"><?php echo $page->getLocalName(); ?></a></div> +<?php } ?> + </section> +<?php + } + ?></div> + </div> + diff --git a/index.php b/index.php index 1c314eb23..7f341f6e4 100644 --- a/index.php +++ b/index.php @@ -21,44 +21,8 @@ $section = 'home'; require(CLIENTINC_DIR.'header.inc.php'); ?> <div id="landing_page"> - <div class="sidebar pull-right"> - <div class="front-page-button flush-right"> -<p> - <a href="open.php" style="display:block" class="blue button"><?php - echo __('Open a New Ticket');?></a> -</p> -<?php if ($cfg && !$cfg->isKnowledgebaseEnabled()) { ?> -<p> - <a href="view.php" style="display:block" class="green button"><?php - echo __('Check Ticket Status');?></a> -</p> -<?php } ?> - </div> - <div class="content"><?php - $faqs = FAQ::getFeatured()->select_related('category')->limit(5); - if ($faqs->all()) { ?> - <section><div class="header"><?php echo __('Featured Questions'); ?></div> -<?php foreach ($faqs as $F) { ?> - <div><a href="<?php echo ROOT_PATH; ?>/kb/faq.php?id=<?php - echo urlencode($F->getId()); - ?>"><?php echo $F->getLocalQuestion(); ?></a></div> -<?php } ?> - </section> -<?php - } - $resources = Page::getActivePages()->filter(array('type'=>'other')); - if ($resources->all()) { ?> - <section><div class="header"><?php echo __('Other Resources'); ?></div> -<?php foreach ($resources as $page) { ?> - <a href="<?php echo ROOT_PATH; ?>pages/<?php echo $page->getNameAsSlug(); - ?>"><?php echo $page->getLocalName(); ?></a> -<?php } ?> - </section> -<?php - } - ?></div> - </div> -<div class="welcome"> +<?php include CLIENTINC_DIR.'templates/sidebar.tmpl.php'; ?> +<div class="main-content"> <?php if ($cfg && $cfg->isKnowledgebaseEnabled()) { ?> <div class="search-form"> diff --git a/pages/index.php b/pages/index.php index ab50a1c58..e9de48734 100644 --- a/pages/index.php +++ b/pages/index.php @@ -28,27 +28,35 @@ $slug = Format::slugify($ost->get_path_info()); $first_word = explode('-', $slug); $first_word = $first_word[0]; -$sql = 'SELECT id, name FROM '.PAGE_TABLE - .' WHERE name LIKE '.db_input("$first_word%"); -$page_id = null; - -$res = db_query($sql); -while (list($id, $name) = db_fetch_row($res)) { - if (Format::slugify($name) == $slug) { - $page_id = $id; +$pages = Page::objects()->filter(array( + 'name__like' => "$first_word%" +)); + +$selected_page = null; +foreach ($pages as $P) { + if (Format::slugify($P->name) == $slug) { + $selected_page = $P; break; } } -if (!$page_id || !($page = Page::lookup($page_id))) +if (!$selected_page) Http::response(404, __('Page Not Found')); -if (!$page->isActive() || $page->getType() != 'other') +if (!$selected_page->isActive() || $selected_page->getType() != 'other') Http::response(404, __('Page Not Found')); require(CLIENTINC_DIR.'header.inc.php'); -print $page->getBodyWithImages(); +$BUTTONS = false; +include CLIENTINC_DIR.'templates/sidebar.tmpl.php'; +?> +<div class="main-content"> +<?php +print $selected_page->getBodyWithImages(); +?> +</div> +<?php require(CLIENTINC_DIR.'footer.inc.php'); ?> -- GitLab