Exemplo n.º 1
0
 /**
  * Standard modular run function for rendering a search result.
  *
  * @param  array		The data row stored when we retrieved the result
  * @return ?tempcode	The output (NULL: compound output)
  */
 function render($row)
 {
     global $SEARCH_CATALOGUE_ENTRIES_CATALOGUES;
     require_css('catalogues');
     $catalogue_name = $row['c_name'];
     if (!array_key_exists($catalogue_name, $SEARCH_CATALOGUE_ENTRIES_CATALOGUES)) {
         return new ocp_tempcode();
     }
     if ($SEARCH_CATALOGUE_ENTRIES_CATALOGUES[$catalogue_name]['c_display_type'] == 0 || get_param_integer('specific', 0) == 0) {
         $tpl_set = $catalogue_name;
         $display = get_catalogue_entry_map($row, $SEARCH_CATALOGUE_ENTRIES_CATALOGUES[$catalogue_name], 'SEARCH', $tpl_set, -1);
         $tpl = do_template('CATALOGUE_' . $tpl_set . '_ENTRY_EMBED', $display, NULL, false, 'CATALOGUE_DEFAULT_ENTRY_EMBED');
         $tree = catalogue_category_breadcrumbs($row['cc_id'], NULL, false);
         if (!$tree->is_empty()) {
             $tpl->attach(paragraph(do_lang_tempcode('LOCATED_IN', $tree)));
         }
         return put_in_standard_box($tpl, do_lang_tempcode('CATALOGUE_ENTRY'));
     } else {
         global $CATALOGUE_ENTRIES_BUILDUP;
         if (!array_key_exists($catalogue_name, $CATALOGUE_ENTRIES_BUILDUP)) {
             $CATALOGUE_ENTRIES_BUILDUP[$catalogue_name] = array();
         }
         $CATALOGUE_ENTRIES_BUILDUP[$catalogue_name][] = $row;
     }
     return NULL;
 }
Exemplo n.º 2
0
/**
 * Get a formatted XHTML string of the route back to the specified root, from the specified category.
 *
 * @param  AUTO_LINK		The category we are finding for
 * @param  ?AUTO_LINK	The root of the tree (NULL: the true root)
 * @param  boolean		Whether to include category links at this level (the recursed levels will always contain links - the top level is optional, hence this parameter)
 * @return tempcode		The tree route
 */
function catalogue_category_breadcrumbs($category_id, $root = NULL, $no_link_for_me_sir = true)
{
    $map = array('page' => 'catalogues', 'type' => 'category', 'id' => $category_id);
    if (!is_null($root)) {
        $map['root'] = $root;
    }
    $url = build_url($map, get_module_zone('catalogues'));
    if (is_null($category_id)) {
        return new ocp_tempcode();
    }
    if ($category_id != $root || !$no_link_for_me_sir) {
        global $PT_PAIR_CACHE;
        if (!array_key_exists($category_id, $PT_PAIR_CACHE)) {
            $category_rows = $GLOBALS['SITE_DB']->query_select('catalogue_categories', array('cc_parent_id', 'cc_title'), array('id' => $category_id), '', 1);
            if (!array_key_exists(0, $category_rows)) {
                fatal_exit(do_lang_tempcode('CAT_NOT_FOUND', escape_html(strval($category_id))));
            }
            $PT_PAIR_CACHE[$category_id] = $category_rows[0];
        }
        if ($PT_PAIR_CACHE[$category_id]['cc_parent_id'] == $category_id) {
            fatal_exit(do_lang_tempcode('RECURSIVE_TREE_CHAIN', escape_html(strval($category_id))));
        }
    }
    if ($category_id == $root) {
        $below = new ocp_tempcode();
    } else {
        $below = catalogue_category_breadcrumbs($PT_PAIR_CACHE[$category_id]['cc_parent_id'], $root, false);
    }
    if (!$no_link_for_me_sir) {
        $title = get_translated_text($PT_PAIR_CACHE[$category_id]['cc_title']);
        if (!$below->is_empty()) {
            $tpl_url = do_template('BREADCRUMB_ESCAPED');
        } else {
            $tpl_url = new ocp_tempcode();
        }
        $tpl_url->attach(hyperlink($url, escape_html($title), false, false, do_lang_tempcode('GO_BACKWARDS_TO', $title), NULL, NULL, 'up'));
    } else {
        $tpl_url = new ocp_tempcode();
    }
    $below->attach($tpl_url);
    return $below;
}
Exemplo n.º 3
0
 /**
  * The UI to show a catalogue category.
  *
  * @return tempcode		The UI
  */
 function view_catalogue_category()
 {
     require_code('feedback');
     require_code('images');
     $id = get_param_integer('id', -1);
     if ($id == -1) {
         $id = $GLOBALS['SITE_DB']->query_value('catalogue_categories', 'MIN(id)', array('c_name' => get_param('catalogue_name'), 'cc_parent_id' => NULL));
     }
     $GLOBALS['FEED_URL'] = find_script('backend') . '?mode=catalogues&filter=' . strval($id);
     $categories = $GLOBALS['SITE_DB']->query_select('catalogue_categories', array('*'), array('id' => $id), '', 1);
     if (!array_key_exists(0, $categories)) {
         return warn_screen(get_page_title('CATALOGUES'), do_lang_tempcode('MISSING_RESOURCE'));
     }
     $category = $categories[0];
     // Permission for here?
     if (!has_category_access(get_member(), 'catalogues_catalogue', $category['c_name'])) {
         access_denied('CATALOGUE_ACCESS');
     }
     if (get_value('disable_cat_cat_perms') !== '1' && !has_category_access(get_member(), 'catalogues_category', strval($id))) {
         access_denied('CATEGORY_ACCESS');
     }
     $catalogue_name = $category['c_name'];
     $root = get_param_integer('root', NULL);
     $_title = get_translated_text($category['cc_title']);
     $catalogues = $GLOBALS['SITE_DB']->query_select('catalogues', array('*'), array('c_name' => $catalogue_name), '', 1);
     if (!array_key_exists(0, $catalogues)) {
         warn_exit(do_lang_tempcode('CATALOGUE_NOT_FOUND', $catalogue_name));
     }
     $catalogue = $catalogues[0];
     $tpl_set = $catalogue_name;
     if (is_ecommerce_catalogue($catalogue_name)) {
         $is_ecommerce = true;
         $tpl_set = 'products';
     } else {
         $is_ecommerce = false;
     }
     $title_to_use = do_lang_tempcode($catalogue_name . '__CATALOGUE_CATEGORY', escape_html($_title));
     $title_to_use_2 = do_lang($catalogue_name . '__CATALOGUE_CATEGORY', $_title, NULL, NULL, NULL, false);
     if (is_null($title_to_use_2)) {
         $title_to_use = do_lang_tempcode('DEFAULT__CATALOGUE_CATEGORY', escape_html($_title));
         $title_to_use_2 = do_lang('DEFAULT__CATALOGUE_CATEGORY', $_title);
     }
     $awards = array();
     if (addon_installed('awards')) {
         require_code('awards');
         $awards = array_merge($awards, find_awards_for('catalogue', $catalogue_name));
         $awards = array_merge($awards, find_awards_for('catalogue_category', strval($id)));
     }
     $title = get_page_title($title_to_use, false, NULL, NULL, $awards);
     if (is_object($title_to_use_2)) {
         $title_to_use_2 = $title_to_use_2->evaluate();
     }
     seo_meta_load_for('catalogue_category', strval($id), $title_to_use_2);
     $max = get_param_integer('max', 30);
     $start = get_param_integer('start', 0);
     list($entry_buildup, $sorting, $entries, $max_rows) = get_catalogue_category_entry_buildup($id, $catalogue_name, $catalogue, 'CATEGORY', $tpl_set, $max, $start, NULL, $root);
     // Build up subcategories
     $rows_subcategories = $GLOBALS['SITE_DB']->query_select('catalogue_categories', array('*'), array('cc_parent_id' => $id), '', 600);
     if (count($rows_subcategories) == 300) {
         $rows_subcategories = array();
     }
     // Performance issue, manual browsing will be needed
     foreach ($rows_subcategories as $i => $subcategory) {
         $rows_subcategories[$i]['cc_title'] = get_translated_text($subcategory['cc_title']);
     }
     for ($i = 0; $i < count($rows_subcategories); $i++) {
         for ($j = $i + 1; $j < count($rows_subcategories); $j++) {
             if ($rows_subcategories[$i]['cc_title'] > $rows_subcategories[$j]['cc_title']) {
                 $temp = $rows_subcategories[$j];
                 $rows_subcategories[$j] = $rows_subcategories[$i];
                 $rows_subcategories[$i] = $temp;
             }
         }
     }
     $subcategories = new ocp_tempcode();
     $uses_rep_image = false;
     foreach ($rows_subcategories as $sc) {
         if ($sc['rep_image'] != '') {
             $uses_rep_image = true;
         }
     }
     foreach ($rows_subcategories as $sc) {
         if (get_value('disable_cat_cat_perms') !== '1' && !has_category_access(get_member(), 'catalogues_category', strval($sc['id']))) {
             continue;
         }
         $child_counts = count_catalogue_category_children($sc['id']);
         $num_children = $child_counts['num_children'];
         $num_entries = $child_counts['num_entries_children'];
         $map = array('page' => '_SELF', 'id' => $sc['id'], 'type' => 'category');
         if (!is_null($root)) {
             $map['root'] = $root;
         }
         $url = build_url($map, '_SELF');
         if ($uses_rep_image || $is_ecommerce) {
             $display_string = do_lang_tempcode($catalogue['c_is_tree'] == 1 ? 'CATEGORY_SUBORDINATE' : 'CATEGORY_SUBORDINATE_2', integer_format($num_entries), integer_format($num_children));
             if ($sc['rep_image']) {
                 $rep_image = do_image_thumb($sc['rep_image'], $sc['cc_title'], $sc['cc_title'], false);
             } else {
                 $rep_image = new ocp_tempcode();
             }
             $description = $sc['cc_description'];
             $description = get_translated_tempcode($description);
             $ajax_edit_url = '_SEARCH:cms_catalogues:type=__edit_category:id=' . strval($sc['id']);
             $subcategories->attach(do_template('CATEGORY_' . $tpl_set . '_ENTRY', array('_GUID' => '871f5f5195fcb426fac716e35569d6a3', 'ID' => strval($sc['id']), 'NAME_FIELD' => 'title', 'AJAX_EDIT_URL' => $ajax_edit_url, 'URL' => $url, 'REP_IMAGE' => $rep_image, 'CHILDREN' => $display_string, 'NAME' => $sc['cc_title'], 'NAME_PLAIN' => $sc['cc_title'], 'DESCRIPTION' => $description, 'NUM_CHILDREN' => integer_format($num_children), 'NUM_CHILDREN_RECURSIVE' => integer_format($child_counts['num_children_children']), 'NUM_ENTRIES' => integer_format($num_entries), 'NUM_ENTRIES_DIRECT' => integer_format($child_counts['num_entries'])), NULL, false, 'CATEGORY_ENTRY'));
         } else {
             $subcategories->attach(do_template('CATALOGUE_' . $tpl_set . '_SUBCATEGORY', array('ID' => strval($sc['id']), 'CATALOGUE' => $catalogue_name, 'URL' => $url, 'NUM_CHILDREN' => integer_format($num_children), 'NUM_CHILDREN_RECURSIVE' => integer_format($child_counts['num_children_children']), 'NUM_ENTRIES' => integer_format($num_entries), 'NUM_ENTRIES_DIRECT' => integer_format($child_counts['num_entries']), 'NAME' => $sc['cc_title']), NULL, false, 'CATALOGUE_DEFAULT_SUBCATEGORY'));
         }
     }
     if (!$subcategories->is_empty()) {
         if ($uses_rep_image) {
             $subcategories = do_template('CATEGORY_LIST', array('_GUID' => '3041620a953e52229f752b1bccfbeee3', 'CONTENT' => $subcategories));
         } else {
             $subcategories = do_template('CATALOGUE_' . $tpl_set . '_SUBCATEGORY_WRAP', array('CATALOGUE' => $catalogue_name, 'CONTENT' => $subcategories), NULL, false, 'CATALOGUE_DEFAULT_SUBCATEGORY_WRAP');
         }
     }
     // Links to add to catalogue category etc
     if (has_actual_page_access(NULL, 'cms_catalogues', NULL, get_value('disable_cat_cat_perms') === '1' ? array('catalogues_catalogue', $catalogue_name) : array('catalogues_catalogue', $catalogue_name, 'catalogues_category', strval($id)), 'submit_midrange_content')) {
         $add_link = build_url(array('page' => 'cms_catalogues', 'type' => 'add_entry', 'catalogue_name' => $catalogue_name, 'category_id' => $id), get_module_zone('cms_catalogues'));
     } else {
         $add_link = new ocp_tempcode();
     }
     if (has_actual_page_access(NULL, 'cms_catalogues', NULL, get_value('disable_cat_cat_perms') === '1' ? array('catalogues_catalogue', $catalogue_name) : array('catalogues_catalogue', $catalogue_name, 'catalogues_category', strval($id)), 'submit_cat_midrange_content')) {
         $add_cat_url = build_url(array('page' => 'cms_catalogues', 'type' => 'add_category', 'catalogue_name' => $catalogue_name, 'parent_id' => $id), get_module_zone('cms_catalogues'));
     } else {
         $add_cat_url = new ocp_tempcode();
     }
     if (has_actual_page_access(NULL, 'cms_catalogues', NULL, get_value('disable_cat_cat_perms') === '1' ? array('catalogues_catalogue', $catalogue_name) : array('catalogues_catalogue', $catalogue_name, 'catalogues_category', strval($id)), 'edit_cat_midrange_content')) {
         $edit_cat_url = build_url(array('page' => 'cms_catalogues', 'type' => '_edit_category', 'catalogue_name' => $catalogue_name, 'id' => $id), get_module_zone('cms_catalogues'));
     } else {
         $edit_cat_url = new ocp_tempcode();
     }
     if (has_actual_page_access(NULL, 'cms_catalogues', NULL, get_value('disable_cat_cat_perms') === '1' ? array('catalogues_catalogue', $catalogue_name) : array('catalogues_catalogue', $catalogue_name), 'edit_cat_highrange_content')) {
         $edit_catalogue_url = build_url(array('page' => 'cms_catalogues', 'type' => '_edit_catalogue', 'id' => $catalogue_name), get_module_zone('cms_catalogues'));
     } else {
         $edit_catalogue_url = new ocp_tempcode();
     }
     require_code('templates_results_browser');
     $browser = results_browser(do_lang_tempcode('ENTRIES'), $id, $start, 'start', $max, 'max', $max_rows, $root, 'category', true);
     if ($catalogue['c_is_tree'] == 1) {
         $tree = catalogue_category_breadcrumbs($id, $root);
         if (!$tree->is_empty()) {
             $tree->attach(do_template('BREADCRUMB_ESCAPED'));
         }
         if (has_specific_permission(get_member(), 'open_virtual_roots')) {
             $url = get_self_url(false, false, is_null(get_param('root', NULL)) ? array('root' => $id) : array('root' => $id == -1 ? NULL : $id));
             $tree->attach(hyperlink($url, escape_html($_title), false, false, do_lang_tempcode('VIRTUAL_ROOT')));
         } else {
             $tree->attach('<span>' . escape_html($_title) . '</span>');
         }
     } else {
         $tree = new ocp_tempcode();
         $url = build_url(array('page' => '_SELF', 'type' => 'index', 'id' => $catalogue_name), '_SELF');
         $catalogue_title = get_translated_text($catalogue['c_title']);
         $tree->attach(hyperlink($url, escape_html($catalogue_title), false, false, do_lang_tempcode('GO_BACKWARDS_TO', escape_html($catalogue_name))));
         $tree->attach(do_template('BREADCRUMB_ESCAPED'));
         $tree->attach(escape_html($_title));
     }
     breadcrumb_add_segment($tree);
     if (is_null($root)) {
         breadcrumb_set_parents(array(array('_SELF:_SELF:misc' . ($is_ecommerce ? ':ecommerce=1' : ''), do_lang('CATALOGUES'))));
     }
     $GLOBALS['META_DATA'] += array('created' => date('Y-m-d', $category['cc_add_date']), 'creator' => '', 'publisher' => '', 'modified' => '', 'type' => get_translated_text($catalogue['c_title']) . ' category', 'title' => $_title, 'identifier' => '_SEARCH:catalogues:category:' . strval($id), 'description' => get_translated_text($category['cc_description']));
     $rep_image_str = $category['rep_image'];
     if ($rep_image_str != '') {
         $GLOBALS['META_DATA'] += array('image' => (url_is_local($rep_image_str) ? get_custom_base_url() . '/' : '') . $rep_image_str);
     }
     $cart_link = new ocp_tempcode();
     if ($is_ecommerce) {
         if (get_forum_type() != 'ocf') {
             warn_exit(do_lang_tempcode('NO_OCF'));
         }
         require_code('shopping');
         require_lang('shopping');
         $cart_link = show_cart_image();
     }
     return do_template('CATALOGUE_' . $tpl_set . '_CATEGORY_SCREEN', array('ID' => strval($id), 'ADD_DATE_RAW' => strval($category['cc_add_date']), 'TITLE' => $title, '_TITLE' => $_title, 'TAGS' => get_loaded_tags('catalogue_categories'), 'CATALOGUE' => $catalogue_name, 'BROWSER' => $browser, 'SORTING' => $sorting, 'ADD_LINK' => $add_link, 'ADD_CAT_URL' => $add_cat_url, 'EDIT_CAT_URL' => $edit_cat_url, 'EDIT_CATALOGUE_URL' => $edit_catalogue_url, 'ENTRIES' => $entry_buildup, 'SUBCATEGORIES' => $subcategories, 'DESCRIPTION' => get_translated_tempcode($category['cc_description']), 'CART_LINK' => $cart_link, 'TREE' => $tree), NULL, false, 'CATALOGUE_DEFAULT_CATEGORY_SCREEN');
 }