/**
  * Standard modular run function for symbol hooks. Searches for tasks to perform.
  *
  * @param  array		Symbol parameters
  * @return string		Result
  */
 function run($param)
 {
     $value = '';
     if (array_key_exists(1, $param)) {
         $map = NULL;
         $entry_id = intval($param[0]);
         $field_id = intval($param[1]);
         static $cache = array();
         if (isset($cache[$entry_id])) {
             $map = $cache[$entry_id];
         } else {
             require_code('catalogues');
             $entry = $GLOBALS['SITE_DB']->query_select('catalogue_entries', array('*'), array('id' => $entry_id), '', 1);
             if (array_key_exists(0, $entry)) {
                 $catalogue = $GLOBALS['SITE_DB']->query_select('catalogues', array('*'), array('c_name' => $entry[0]['c_name']), '', 1);
                 if (array_key_exists(0, $catalogue)) {
                     $map = get_catalogue_entry_map($entry[0], $catalogue[0], 'PAGE', 'DEFAULT', NULL, NULL);
                 }
             }
             $cache[$entry_id] = $map;
         }
         if (!is_null($map)) {
             if (isset($map['FIELD_' . strval($field_id)])) {
                 $value = $map['FIELD_' . strval($field_id)];
             } elseif (isset($map['_FIELD_' . strval($field_id)])) {
                 $value = $map['_FIELD_' . strval($field_id)];
             }
         }
         if (is_object($value)) {
             $value = $value->evaluate();
         }
     }
     return $value;
 }
Пример #2
0
 /**
  * Standard modular run function for award hooks. Renders a content box for an award/randomisation.
  *
  * @param  array		The database row for the content
  * @param  ID_TEXT	The zone to display in
  * @return tempcode	Results
  */
 function run($row, $zone)
 {
     unset($zone);
     require_code('catalogues');
     $catalogue_name = $row['c_name'];
     $catalogues = $GLOBALS['SITE_DB']->query_select('catalogues', array('*'), array('c_name' => $catalogue_name), '', 1);
     $tpl_set = $catalogue_name;
     $display = get_catalogue_entry_map($row, $catalogues[0], 'SEARCH', $tpl_set, -1, NULL, NULL, false, true);
     return do_template('CATALOGUE_' . $tpl_set . '_ENTRY_EMBED', $display, NULL, false, 'CATALOGUE_DEFAULT_ENTRY_EMBED');
     //put_in_standard_box(hyperlink($url,do_lang_tempcode('VIEW')),do_lang_tempcode('CATALOGUE_ENTRY').' ('.do_lang_tempcode('IN',get_translated_text($catalogue['c_title'])).')');
 }
Пример #3
0
 /**
  * Standard modular run function for CRON hooks. Searches for tasks to perform.
  */
 function run()
 {
     if (!addon_installed('catalogues')) {
         return;
     }
     $last = get_value('last_classified_refresh');
     $time = time();
     if (!is_null($last) && intval($last) > $time - 60 * 60) {
         return;
     }
     // Don't do more than once per hour
     if (function_exists('set_time_limit')) {
         @set_time_limit(0);
     }
     $start = 0;
     do {
         $entries = $GLOBALS['SITE_DB']->query_select('catalogue_entries e JOIN ' . get_table_prefix() . 'classifieds_prices p ON p.c_catalogue_name=e.c_name', array('e.*'), array('ce_validated' => 1), '', 1000, $start);
         foreach ($entries as $entry) {
             if ($entry['ce_last_moved'] == $entry['ce_add_date']) {
                 require_code('classifieds');
                 initialise_classified_listing($entry);
             }
             // Expiring
             if ($entry['ce_last_moved'] < $time) {
                 $GLOBALS['SITE_DB']->query_update('catalogue_entries', array('ce_validated' => 0), array('id' => $entry['id']), '', 1);
                 decache('main_cc_embed');
                 decache('main_recent_cc_entries');
                 require_code('catalogues2');
                 calculate_category_child_count_cache($entry['cc_id']);
             } elseif ($entry['ce_last_moved'] < $time + 60 * 60 * 24 && $entry['ce_last_moved'] > $time + 60 * 60 * 23) {
                 // Expiring in 24 hours
                 require_code('notifications');
                 require_lang('classifieds');
                 $member_id = $entry['ce_submitter'];
                 $renew_url = build_url(array('page' => 'classifieds', 'type' => 'adverts', 'id' => $member_id), get_module_zone('classifieds'));
                 require_code('catalogues');
                 $data_map = get_catalogue_entry_map($entry, NULL, 'CATEGORY', 'DEFAULT', NULL, NULL, array(0));
                 $ad_title = $data_map['FIELD_0_PLAIN'];
                 if (is_object($ad_title)) {
                     $ad_title = $ad_title->evaluate();
                 }
                 $subject_tag = do_lang('SUBJECT_CLASSIFIED_ADVERT_EXPIRING', $ad_title, get_site_name(), NULL, get_lang($member_id), false);
                 $mail = do_lang('MAIL_CLASSIFIED_ADVERT_EXPIRING', $ad_title, comcode_escape(get_site_name()), comcode_escape($renew_url->evaluate()), get_lang($member_id), false);
                 // Send actual notification
                 dispatch_notification('classifieds__' . $entry['c_name'], '', $subject_tag, $mail, array($member_id), A_FROM_SYSTEM_PRIVILEGED);
             }
         }
     } while (count($entries) == 1000);
     set_value('last_classified_refresh', strval($time));
 }
Пример #4
0
 /**
  * Function for administrators to pick an identifier (only used by admins, usually the identifier would be picked via some other means in the wider ocPortal codebase).
  *
  * @param  ID_TEXT		Product type code.
  * @return ?tempcode		Input field in standard Tempcode format for fields (NULL: no identifier).
  */
 function get_identifier_manual_field_inputter($type_code)
 {
     require_code('catalogues');
     require_lang('classifieds');
     $list = new ocp_tempcode();
     $rows = $GLOBALS['SITE_DB']->query_select('catalogue_entries e JOIN ' . get_table_prefix() . 'classifieds_prices c ON c.c_catalogue_name=e.c_name', array('e.*'), NULL, 'GROUP BY e.id ORDER BY ce_add_date DESC');
     foreach ($rows as $row) {
         $data_map = get_catalogue_entry_map($row, NULL, 'CATEGORY', 'DEFAULT', NULL, NULL, array(0));
         $ad_title = $data_map['FIELD_0'];
         $username = $GLOBALS['FORUM_DRIVER']->get_username($row['ce_submitter']);
         if (is_null($username)) {
             $username = do_lang('UNKNOWN');
         }
         $list->attach(form_input_list_entry(strval($row['id']), get_param_integer('id', NULL) === $row['id'], do_lang('CLASSIFIED_OF', strval($row['id']), $username, $ad_title)));
     }
     return form_input_list(do_lang_tempcode('ENTRY'), '', 'purchase_id', $list);
 }
 /**
  * Standard modular run function for symbol hooks. Searches for tasks to perform.
  *
  * @param  array		Symbol parameters
  * @return string		Result
  */
 function run($param)
 {
     $value = '';
     if (array_key_exists(0, $param)) {
         $rows = $GLOBALS['SITE_DB']->query_select('catalogue_entries', array('*'), array('id' => intval($param[0])), '', 1);
         if (array_key_exists(0, $rows)) {
             require_code('catalogues');
             $catalogue_name = $rows[0]['c_name'];
             $tpl_set = $catalogue_name;
             $display = get_catalogue_entry_map($rows[0], array('c_name' => $catalogue_name, 'c_display_type' => C_DT_MAPS), 'PAGE', $tpl_set, -1);
             if (array_key_exists(1, $param) && $param[1] == '1') {
                 $value = $display['FIELDS']->evaluate();
             } else {
                 $_value = do_template('CATALOGUE_' . $tpl_set . '_ENTRY', $display, NULL, false, 'CATALOGUE_DEFAULT_ENTRY');
                 $value = $_value->evaluate();
             }
         }
     }
     return $value;
 }
Пример #6
0
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     require_code('catalogues');
     require_lang('main_google_map');
     // Set up config/defaults
     if (!array_key_exists('title', $map)) {
         $map['title'] = '';
     }
     if (!array_key_exists('region', $map)) {
         $map['region'] = '';
     }
     if (!array_key_exists('latitude', $map)) {
         $map['latitude'] = '0';
     }
     if (!array_key_exists('longitude', $map)) {
         $map['longitude'] = '0';
     }
     $mapwidth = array_key_exists('width', $map) ? $map['width'] : '100%';
     $mapheight = array_key_exists('height', $map) ? $map['height'] : '300px';
     $api_key = array_key_exists('api_key', $map) ? $map['api_key'] : '';
     $set_zoom = array_key_exists('zoom', $map) ? $map['zoom'] : '3';
     $set_center = array_key_exists('center', $map) ? $map['center'] : '0';
     $set_show_links = array_key_exists('show_links', $map) ? $map['show_links'] : '1';
     $cluster = array_key_exists('cluster', $map) ? $map['cluster'] : '0';
     if (!array_key_exists('catalogue', $map)) {
         $map['catalogue'] = '';
     }
     if (!array_key_exists('longfield', $map)) {
         $map['longfield'] = 'Longitude';
     }
     if (!array_key_exists('latfield', $map)) {
         $map['latfield'] = 'Latitude';
     }
     $min_latitude = array_key_exists('min_latitude', $map) ? $map['min_latitude'] : '';
     $max_latitude = array_key_exists('max_latitude', $map) ? $map['max_latitude'] : '';
     $min_longitude = array_key_exists('min_longitude', $map) ? $map['min_longitude'] : '';
     $max_longitude = array_key_exists('max_longitude', $map) ? $map['max_longitude'] : '';
     $longitude_key = $map['longfield'];
     $latitude_key = $map['latfield'];
     $catalogue_name = $map['catalogue'];
     $star_entry = array_key_exists('star_entry', $map) ? $map['star_entry'] : '';
     $max_results = array_key_exists('max_results', $map) && $map['max_results'] != '' ? intval($map['max_results']) : 1000;
     $icon = array_key_exists('icon', $map) ? $map['icon'] : '';
     if (!array_key_exists('filter_category', $map)) {
         $map['filter_category'] = '';
     }
     if (!array_key_exists('filter_rating', $map)) {
         $map['filter_rating'] = '';
     }
     if (!array_key_exists('filter_term', $map)) {
         $map['filter_term'] = '';
     }
     if (!array_key_exists('filter_hours', $map)) {
         $map['filter_hours'] = '';
     }
     $data = array();
     if ($catalogue_name != '') {
         // Data query
         $query = 'SELECT * FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'catalogue_entries WHERE ce_validated=1 AND ' . db_string_equal_to('c_name', $catalogue_name);
         // Filtering
         if ($map['filter_category'] != '') {
             require_code('ocfiltering');
             $query .= ' AND (' . ocfilter_to_sqlfragment($map['filter_category'], 'id', 'catalogue_categories', 'cc_parent_id', 'cc_id', 'id') . ')';
         }
         if ($map['filter_hours'] != '') {
             $query .= ' AND ce_add_date>' . strval(time() - 60 * 60 * intval($map['filter_hours']));
         }
         if ($map['filter_rating'] != '') {
             $query .= ' AND (SELECT AVG(rating) FROM rating WHERE ' . db_string_equal_to('rating_for_type', 'catalogue_entry') . ' AND rating_for_id=id)>' . strval(intval($map['filter_rating']));
         }
         // Info about our catalogue
         $catalogue_rows = $GLOBALS['SITE_DB']->query_select('catalogues', array('*'), array('c_name' => $catalogue_name), '', 1);
         if (!array_key_exists(0, $catalogue_rows)) {
             return paragraph('Could not find the catalogue named "' . escape_html($catalogue_name) . '".', '', 'nothing_here');
         }
         $catalogue_row = $catalogue_rows[0];
         // Get results
         $entries_to_show = array();
         if ($star_entry != '') {
             $entries_to_show = array_merge($entries_to_show, $GLOBALS['SITE_DB']->query($query . ' AND id=' . strval(intval($star_entry))));
             $query .= ' AND id<>' . strval(intval($star_entry));
         }
         $entries_to_show = array_merge($entries_to_show, $GLOBALS['SITE_DB']->query($query . ' ORDER BY ce_add_date DESC', $max_results));
         if (count($entries_to_show) == 0 && ($min_latitude == '' || $max_latitude == '' || $min_longitude == '' || $max_longitude == '')) {
             //return paragraph(do_lang_tempcode('NO_ENTRIES'),'','nothing_here');
         }
         // Make marker data Javascript-friendly
         foreach ($entries_to_show as $i => $entry_row) {
             $entry_row['allow_rating'] = 0;
             // Performance: So rating is not loaded
             $details = get_catalogue_entry_map($entry_row, $catalogue_row, 'CATEGORY', $catalogue_name, NULL);
             $two_d_list = $details['FIELDS_2D'];
             $longitude = NULL;
             $latitude = NULL;
             $entry_title = '';
             $all_output = '';
             foreach ($two_d_list as $index => $l) {
                 if ($l['NAME'] == $longitude_key) {
                     $longitude = $l['VALUE'];
                 }
                 if ($l['NAME'] == $latitude_key) {
                     $latitude = $l['VALUE'];
                 }
                 if ($index == 0) {
                     $entry_title = $l['VALUE'];
                 }
                 $all_output .= (is_object($l['VALUE']) ? $l['VALUE']->evaluate() : $l['VALUE']) . ' ';
             }
             if (is_object($longitude)) {
                 $longitude = $longitude->evaluate();
             }
             if (is_object($latitude)) {
                 $latitude = $latitude->evaluate();
             }
             if (is_object($entry_title)) {
                 $entry_title = $entry_title->evaluate();
             }
             if (is_numeric($longitude) && is_numeric($latitude)) {
                 if ($map['filter_term'] == '' || strpos(strtolower($all_output), strtolower($map['filter_term'])) !== false) {
                     $details['LONGITUDE'] = float_to_raw_string(floatval($longitude));
                     $details['LATITUDE'] = float_to_raw_string(floatval($latitude));
                     $details['ENTRY_TITLE'] = $entry_title;
                     $entry_content = do_template('CATALOGUE_googlemap_ENTRY_EMBED', $details, NULL, false, 'CATALOGUE_DEFAULT_ENTRY_EMBED');
                     //put_in_standard_box(hyperlink($url,do_lang_tempcode('VIEW')),do_lang_tempcode('CATALOGUE_ENTRY').' ('.do_lang_tempcode('IN',get_translated_text($catalogue['c_title'])).')');
                     $details['ENTRY_CONTENT'] = $entry_content;
                     $details['STAR'] = '0';
                     if ($star_entry != '') {
                         if ($entry_row['id'] == intval($star_entry)) {
                             $details['STAR'] = '1';
                         }
                     }
                     $details['CC_ID'] = strval($entry_row['cc_id']);
                     $details['ICON'] = '';
                     $data[] = $details;
                 }
             }
         }
     }
     $hooks_to_use = explode('|', array_key_exists('extra_sources', $map) ? $map['extra_sources'] : '');
     $hooks = find_all_hooks('blocks', 'main_google_map');
     foreach (array_keys($hooks) as $hook) {
         if (in_array($hook, $hooks_to_use)) {
             require_code('hooks/blocks/main_google_map/' . $hook);
             $ob = object_factory('Hook_Map_' . $hook);
             $data = array_merge($data, $ob->get_data($map, $max_results, $min_latitude, $max_latitude, $min_longitude, $max_longitude, $latitude_key, $longitude_key, $catalogue_row, $catalogue_name));
         }
     }
     $uniqid = uniqid('', true);
     $div_id = 'div_' . $catalogue_name . '_' . $uniqid;
     return do_template('BLOCK_MAIN_GOOGLE_MAP', array('TITLE' => $map['title'], 'ICON' => $icon, 'MIN_LATITUDE' => $min_latitude, 'MAX_LATITUDE' => $max_latitude, 'MIN_LONGITUDE' => $min_longitude, 'MAX_LONGITUDE' => $max_longitude, 'DATA' => $data, 'SHOW_LINKS' => $set_show_links, 'DIV_ID' => $div_id, 'CLUSTER' => $cluster, 'REGION' => $map['region'], 'WIDTH' => $mapwidth, 'HEIGHT' => $mapheight, 'LATITUDE' => $map['latitude'], 'LONGITUDE' => $map['longitude'], 'ZOOM' => $set_zoom, 'CENTER' => $set_center));
 }
Пример #7
0
/**
 * Display a catalogue entry
 *
 * @param  AUTO_LINK		Entry ID
 * @param  boolean		Whether to skip rendering a title
 * @return tempcode		Tempcode interface to display an entry
 */
function render_catalogue_entry_screen($id, $no_title = false)
{
    require_code('feedback');
    if (addon_installed('ecommerce')) {
        require_code('ecommerce');
    }
    require_code('images');
    require_css('catalogues');
    require_lang('catalogues');
    $entries = $GLOBALS['SITE_DB']->query_select('catalogue_entries', array('*'), array('id' => $id), '', 1);
    if (!array_key_exists(0, $entries)) {
        return warn_screen(get_page_title('CATALOGUES'), do_lang_tempcode('MISSING_RESOURCE'));
    }
    $entry = $entries[0];
    $categories = $GLOBALS['SITE_DB']->query_select('catalogue_categories', array('*'), array('id' => $entry['cc_id']), '', 1);
    if (!array_key_exists(0, $categories)) {
        warn_exit(do_lang_tempcode('CAT_NOT_FOUND', strval($entry['cc_id'])));
    }
    $category = $categories[0];
    $GLOBALS['FEED_URL'] = find_script('backend') . '?mode=catalogues&filter=' . strval($entry['cc_id']);
    $catalogue_name = $category['c_name'];
    $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];
    // Permission for here?
    if (!has_category_access(get_member(), 'catalogues_catalogue', $catalogue_name)) {
        access_denied('CATALOGUE_ACCESS');
    }
    if (get_value('disable_cat_cat_perms') !== '1' && !has_category_access(get_member(), 'catalogues_category', strval($entry['cc_id']))) {
        access_denied('CATEGORY_ACCESS');
    }
    $ecommerce = is_ecommerce_catalogue($catalogue_name);
    if ($ecommerce) {
        $tpl_set = 'products';
    } else {
        $tpl_set = $catalogue_name;
    }
    $root = get_param_integer('root', NULL);
    $map = get_catalogue_entry_map($entry, $catalogue, 'PAGE', $tpl_set, $root, NULL, NULL, true, true);
    if (get_db_type() != 'xml') {
        $entry['ce_views']++;
        $GLOBALS['SITE_DB']->query_update('catalogue_entries', array('ce_views' => $entry['ce_views']), array('id' => $id), '', 1, NULL, false, true);
    }
    // Validation
    if ($entry['ce_validated'] == 0) {
        if (!has_specific_permission(get_member(), 'jump_to_unvalidated')) {
            access_denied('SPECIFIC_PERMISSION', 'jump_to_unvalidated');
        }
        $map['WARNINGS'] = do_template('WARNING_TABLE', array('_GUID' => 'bf604859a572ca53e969bec3d91f9cfb', 'WARNING' => do_lang_tempcode(get_param_integer('redirected', 0) == 1 ? 'UNVALIDATED_TEXT_NON_DIRECT' : 'UNVALIDATED_TEXT')));
    } else {
        $map['WARNINGS'] = '';
    }
    //Finding any hook exists for this product--------------------
    if (addon_installed('ecommerce')) {
        $object = find_product(strval($id));
        if (is_object($object) && method_exists($object, 'get_custom_product_map_fields')) {
            $object->get_custom_product_map_fields($id, $map);
        }
    }
    //------------------------------------------------------------
    $map['ENTRY'] = do_template('CATALOGUE_' . $tpl_set . '_ENTRY', $map, NULL, false, 'CATALOGUE_DEFAULT_ENTRY');
    $map['ADD_DATE'] = get_timezoned_date($entry['ce_add_date']);
    $map['ADD_DATE_RAW'] = strval($entry['ce_add_date']);
    $map['EDIT_DATE'] = is_null($entry['ce_edit_date']) ? '' : get_timezoned_date($entry['ce_edit_date']);
    $map['EDIT_DATE_RAW'] = is_null($entry['ce_edit_date']) ? '' : strval($entry['ce_edit_date']);
    $map['VIEWS'] = integer_format($entry['ce_views']);
    $title_to_use = do_lang_tempcode($catalogue_name . '__CATALOGUE_ENTRY', $map['FIELD_0']);
    $title_to_use_2 = do_lang($catalogue_name . '__CATALOGUE_ENTRY', $map['FIELD_0_PLAIN'], NULL, NULL, NULL, false);
    if (is_null($title_to_use_2)) {
        $title_to_use = do_lang_tempcode('DEFAULT__CATALOGUE_ENTRY', $map['FIELD_0']);
        $title_to_use_2 = do_lang('DEFAULT__CATALOGUE_ENTRY', $map['FIELD_0_PLAIN']);
    }
    if ($no_title) {
        $map['TITLE'] = new ocp_tempcode();
    } else {
        if (addon_installed('awards')) {
            require_code('awards');
            $awards = find_awards_for('catalogue_entry', strval($id));
        } else {
            $awards = array();
        }
        $map['TITLE'] = get_page_title($title_to_use, false, NULL, NULL, $awards);
    }
    $map['SUBMITTER'] = strval($entry['ce_submitter']);
    require_code('seo2');
    if (is_object($title_to_use_2)) {
        $title_to_use_2 = $title_to_use_2->evaluate();
    }
    seo_meta_load_for('catalogue_entry', strval($id), strip_tags($title_to_use_2));
    if ($map['TREE'] === '') {
        $map['TREE'] = new ocp_tempcode();
        $url = build_url(array('page' => '_SELF', 'type' => 'index', 'id' => $catalogue_name), '_SELF');
        $map['TREE']->attach(hyperlink($url, escape_html(get_translated_text($catalogue['c_title'])), false, false, do_lang('INDEX')));
        $map['TREE']->attach(do_template('BREADCRUMB_ESCAPED'));
        $url = build_url(array('page' => '_SELF', 'type' => 'category', 'id' => $category['id']), '_SELF');
        $map['TREE']->attach(hyperlink($url, escape_html(get_translated_text($category['cc_title'])), false, false, do_lang('GO_BACKWARDS_TO', get_translated_text($category['cc_title'])), NULL, NULL, 'up'));
    }
    $map['CATEGORY_TITLE'] = get_translated_text($category['cc_title']);
    $map['CAT'] = strval($entry['cc_id']);
    $map['TAGS'] = get_loaded_tags('catalogue_entries');
    breadcrumb_add_segment($map['TREE'], $title_to_use);
    if (is_null($root)) {
        breadcrumb_set_parents(array(array('_SELF:_SELF:misc' . ($ecommerce ? ':ecommerce=1' : ''), do_lang('CATALOGUES'))));
    }
    $GLOBALS['META_DATA'] += array('created' => date('Y-m-d', $entry['ce_add_date']), 'creator' => $GLOBALS['FORUM_DRIVER']->get_username($entry['ce_submitter']), 'publisher' => '', 'modified' => is_null($entry['ce_edit_date']) ? '' : date('Y-m-d', $entry['ce_edit_date']), 'type' => get_translated_text($catalogue['c_title']) . ' entry', 'title' => comcode_escape($title_to_use_2), 'identifier' => '_SEARCH:catalogues:entry:' . strval($id), 'description' => '');
    return do_template('CATALOGUE_' . $tpl_set . '_ENTRY_SCREEN', $map, NULL, false, 'CATALOGUE_DEFAULT_ENTRY_SCREEN');
}
Пример #8
0
 /**
  * Standard modular run function for RSS hooks.
  *
  * @param  string			A list of categories we accept from
  * @param  TIME			Cutoff time, before which we do not show results from
  * @param  string			Prefix that represents the template set we use
  * @set    RSS_ ATOM_
  * @param  string			The standard format of date to use for the syndication type represented in the prefix
  * @param  integer		The maximum number of entries to return, ordering by date
  * @return ?array			A pair: The main syndication section, and a title (NULL: error)
  */
 function run($_filters, $cutoff, $prefix, $date_string, $max)
 {
     if (!addon_installed('catalogues')) {
         return NULL;
     }
     if (!has_actual_page_access(get_member(), 'catalogues')) {
         return NULL;
     }
     $filters_1 = ocfilter_to_sqlfragment($_filters, 'id', 'catalogue_categories', 'cc_parent_id', 'id', 'id');
     // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set)
     $filters = ocfilter_to_sqlfragment($_filters, 'cc_id', 'catalogue_categories', 'cc_parent_id', 'cc_id', 'id');
     // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set)
     require_code('catalogues');
     $_categories = $GLOBALS['SITE_DB']->query('SELECT id,c_name,cc_title FROM ' . get_table_prefix() . 'catalogue_categories WHERE ' . $filters_1, 300);
     foreach ($_categories as $i => $_category) {
         $_categories[$i]['text_original'] = get_translated_text($_category['cc_title']);
     }
     $rows = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'catalogue_entries WHERE ce_add_date>' . strval(time() - $cutoff) . (!has_specific_permission(get_member(), 'see_unvalidated') ? ' AND ce_validated=1 ' : '') . ' AND ' . $filters . ' ORDER BY ce_add_date DESC', $max);
     $categories = array();
     foreach ($_categories as $category) {
         $categories[$category['id']] = $category;
     }
     $query = 'SELECT c.* FROM ' . get_table_prefix() . 'catalogues c';
     if (can_arbitrary_groupby()) {
         $query .= ' JOIN ' . get_table_prefix() . 'catalogue_entries e ON e.c_name=c.c_name GROUP BY c.c_name';
     }
     $_catalogues = $GLOBALS['SITE_DB']->query($query);
     $catalogues = array();
     foreach ($_catalogues as $catalogue) {
         $catalogues[$catalogue['c_name']] = $catalogue;
     }
     $content = new ocp_tempcode();
     foreach ($rows as $row) {
         if (count($_categories) == 300 && !array_key_exists($row['cc_id'], $categories)) {
             $val = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT cc_title FROM ' . get_table_prefix() . 'catalogue_categories WHERE id=' . strval($row['cc_id']) . ' AND (' . $filters_1 . ')');
             if (!is_null($val)) {
                 $categories[$row['cc_id']] = get_translated_text($val);
             }
         }
         if (!array_key_exists($row['cc_id'], $categories)) {
             continue;
         }
         // The catalogue was filtered out, thus category not known
         $_category = $categories[$row['cc_id']];
         if (has_category_access(get_member(), 'catalogues_catalogue', $_category['c_name']) && (get_value('disable_cat_cat_perms') === '1' || has_category_access(get_member(), 'catalogues_category', strval($row['cc_id'])))) {
             if (!isset($catalogues[$_category['c_name']])) {
                 continue;
             }
             $id = strval($row['id']);
             $author = $GLOBALS['FORUM_DRIVER']->get_username($row['ce_submitter']);
             if (is_null($author)) {
                 $author = '';
             }
             $news_date = date($date_string, $row['ce_add_date']);
             $edit_date = is_null($row['ce_edit_date']) ? '' : date($date_string, $row['ce_edit_date']);
             $tpl_set = $_category['c_name'];
             $map = get_catalogue_entry_map($row, $catalogues[$_category['c_name']], 'PAGE', $tpl_set, db_get_first_id());
             $_title = $map['FIELD_0'];
             $news_title = xmlentities(is_object($_title) ? $_title->evaluate() : escape_html($_title));
             if (array_key_exists('FIELD_1', $map)) {
                 $summary = xmlentities(is_object($map['FIELD_1']) ? $map['FIELD_1']->evaluate() : escape_html($map['FIELD_1']));
             } else {
                 $summary = '';
             }
             $news = '';
             $category = $_category['text_original'];
             $category_raw = strval($row['cc_id']);
             $view_url = build_url(array('page' => 'catalogues', 'type' => 'entry', 'id' => $row['id']), get_module_zone('catalogues'), NULL, false, false, true);
             if ($prefix == 'RSS_' && get_option('is_on_comments') == '1' && $row['allow_comments'] >= 1) {
                 $if_comments = do_template('RSS_ENTRY_COMMENTS', array('_GUID' => 'ee850d0e7f50b21f2dbe17cc49494baa', 'COMMENT_URL' => $view_url, 'ID' => strval($row['id'])));
             } else {
                 $if_comments = new ocp_tempcode();
             }
             $content->attach(do_template($prefix . 'ENTRY', array('VIEW_URL' => $view_url, 'SUMMARY' => $summary, 'EDIT_DATE' => $edit_date, 'IF_COMMENTS' => $if_comments, 'TITLE' => $news_title, 'CATEGORY_RAW' => $category_raw, 'CATEGORY' => $category, 'AUTHOR' => $author, 'ID' => $id, 'NEWS' => $news, 'DATE' => $news_date)));
         }
     }
     require_lang('catalogues');
     return array($content, do_lang('CATALOGUE_ENTRIES'));
 }
Пример #9
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;
 }
Пример #10
0
 /**
  * The actualiser to download a CSV of catalogues.
  *
  * @param ID_TEXT			The name of the catalogue
  */
 function _export_catalogue($catalogue_name)
 {
     $filename = $catalogue_name . '-' . date('Y-m-d') . '.csv';
     if (function_exists('set_time_limit')) {
         @set_time_limit(0);
     }
     header('Content-type: text/csv');
     if (strstr(ocp_srv('HTTP_USER_AGENT'), 'MSIE') !== false) {
         header('Content-Disposition: filename="' . str_replace(chr(13), '', str_replace(chr(10), '', addslashes($filename))) . '"');
     } else {
         header('Content-Disposition: attachment; filename="' . str_replace(chr(13), '', str_replace(chr(10), '', addslashes($filename))) . '"');
     }
     @ini_set('ocproducts.xss_detect', '0');
     $catalogue_row = $GLOBALS['SITE_DB']->query_select('catalogues', array('*'), array('c_name' => $catalogue_name), '', NULL, NULL, true);
     if (is_null($catalogue_row)) {
         $catalogue_row = array();
     }
     if (isset($catalogue_row[0])) {
         $catalogue_row = $catalogue_row[0];
     }
     $category_names = array();
     $start = 0;
     do {
         $entry_rows = $GLOBALS['SITE_DB']->query_select('catalogue_entries', array('*'), array('c_name' => $catalogue_name), 'ORDER BY ce_add_date ASC', 4000, $start);
         foreach ($entry_rows as $k => $entry_row) {
             if (is_null($entry_row)) {
                 $entry_row = array();
             }
             if (isset($entry_row[0])) {
                 $entry_row = $entry_row[0];
             }
             $details = get_catalogue_entry_map($entry_row, $catalogue_row, 'PAGE', 'DEFAULT', NULL);
             $better_results = array();
             foreach ($details as $key => $val) {
                 if (substr($key, 0, 10) == 'FIELDNAME_') {
                     $value = $details['FIELD_' . substr($key, 10) . '_PLAIN'];
                     if (is_object($value)) {
                         $value = $value->evaluate();
                     }
                     $better_results[$val] = $value;
                 }
             }
             if ($k == 0) {
                 echo 'CATEGORY';
                 foreach (array_keys($better_results) as $k2) {
                     echo ',';
                     echo '"' . str_replace('"', '""', $k2) . '"';
                 }
                 echo chr(10);
             }
             if (!isset($category_names[$entry_row['cc_id']])) {
                 if (!array_key_exists($entry_row['cc_id'], $category_names)) {
                     $category_names[$entry_row['cc_id']] = get_translated_text($GLOBALS['SITE_DB']->query_value('catalogue_categories', 'cc_title', array('id' => $entry_row['cc_id'])));
                 }
             }
             echo '"' . str_replace('"', '""', $category_names[$entry_row['cc_id']]) . '"';
             foreach ($better_results as $v) {
                 echo ',';
                 echo '"' . str_replace('"', '""', $v) . '"';
             }
             echo chr(10);
         }
         $start += 4000;
     } while (count($entry_rows) != 0);
     $GLOBALS['SCREEN_TEMPLATE_CALLED'] = '';
     exit;
 }
Пример #11
0
 /**
  * Get the message for use in the purchase wizard
  *
  * @param  AUTO_LINK		The product in question.
  * @return tempcode		The message.
  */
 function get_message($product)
 {
     require_code('catalogues');
     $catalogue_name = $GLOBALS['SITE_DB']->query_value('catalogue_entries', 'c_name', array('id' => $product));
     $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];
     $entries = $GLOBALS['SITE_DB']->query_select('catalogue_entries', array('*'), array('id' => $product), '', 1);
     if (!array_key_exists(0, $entries)) {
         return warn_screen(get_page_title('CATALOGUES'), do_lang_tempcode('MISSING_RESOURCE'));
     }
     $entry = $entries[0];
     $map = get_catalogue_entry_map($entry, $catalogue, 'PAGE', $catalogue_name, $product, NULL, NULL, true, true);
     return do_template('ECOMMERCE_ITEM_DETAILS', $map, NULL, false, 'ECOMMERCE_ITEM_DETAILS');
 }
Пример #12
0
 /**
  * The UI to show a catalogue A-Z screen.
  *
  * @return tempcode		The UI
  */
 function view_catalogue_category_entries()
 {
     $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');
     }
     $catalogue_name = $category['c_name'];
     $root = get_param_integer('root', NULL);
     $category = $GLOBALS['SITE_DB']->query_value('catalogue_categories', 'cc_title', array('id' => $id));
     $category_name = get_translated_text($category);
     $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('MISSING_RESOURCE'));
     }
     $catalogue = $catalogues[0];
     $tpl_set = $catalogue_name;
     $category_buildup = new ocp_tempcode();
     $max = NULL;
     $start = NULL;
     require_code('ocfiltering');
     $sql_filter = ocfilter_to_sqlfragment(strval($id) . '*', 'cc_id', 'catalogue_categories', 'cc_parent_id', 'cc_id', 'id');
     // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set)
     if ($GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . get_table_prefix() . 'catalogue_entries p WHERE ce_validated=1 AND (' . $sql_filter . ')') > 1000) {
         warn_exit(do_lang_tempcode('TOO_MANY_TO_CHOOSE_FROM'));
     }
     $cats = array();
     $rows = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'catalogue_entries p WHERE ce_validated=1 AND (' . $sql_filter . ')');
     foreach ($rows as $row) {
         $entry_map = get_catalogue_entry_map($row, $catalogue, 'CATEGORY', 'DEFAULT', $root, NULL, array(0), false, false);
         $letter = strtoupper(substr(is_object($entry_map['FIELD_0_PLAIN']) ? $entry_map['FIELD_0_PLAIN']->evaluate() : $entry_map['FIELD_0_PLAIN'], 0, 1));
         if (get_value('disable_cat_cat_perms') !== '1' && !has_category_access(get_member(), 'catalogues_category', strval($row['id']))) {
             continue;
         }
         if (!array_key_exists($letter, $cats)) {
             $cats[$letter] = array();
         }
         $cats[$letter][] = $row;
     }
     unset($rows);
     ksort($cats);
     foreach ($cats as $letter => $entries) {
         list($entry_buildup) = get_catalogue_category_entry_buildup(NULL, $catalogue_name, $catalogue, 'CATEGORY', $tpl_set, $max, $start, NULL, $root, NULL, true, $entries);
         $category_buildup->attach(do_template('CATALOGUE_CATEGORY_HEADING', array('LETTER' => is_integer($letter) ? strval($letter) : $letter, 'ENTRIES' => escape_html($entry_buildup)), NULL, false, 'CATALOGUE_CATEGORY_HEADING'));
     }
     $_title = get_translated_text($category);
     $title_to_use = do_lang_tempcode('DEFAULT__CATALOGUE_CATEGORY_ATOZ', escape_html($_title));
     $title = get_page_title($title_to_use, false);
     //Link to add to catalogue category
     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();
     }
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc' . ($catalogue['c_ecommerce'] == 1 ? ':ecommerce=1' : ''), do_lang_tempcode('CATALOGUES'))));
     return do_template('CATALOGUE_' . $tpl_set . '_CATEGORY_SCREEN', array('TITLE' => $title, 'CART_LINK' => '', '_TITLE' => $_title, 'TAGS' => get_loaded_tags('catalogue_categories'), 'CATALOGUE' => $catalogue_name, 'BROWSER' => '', 'SORTING' => '', 'ADD_LINK' => $add_link, 'ADD_CAT_URL' => $add_cat_url, 'EDIT_CAT_URL' => $edit_cat_url, 'EDIT_CATALOGUE_URL' => $edit_catalogue_url, 'ENTRIES' => $category_buildup, 'SUBCATEGORIES' => '', 'DESCRIPTION' => ''), NULL, false, 'CATALOGUE_DEFAULT_CATEGORY_SCREEN');
 }
Пример #13
0
 /**
  * View an overview of the members adverts on the system.
  *
  * @return tempcode		The UI
  */
 function adverts()
 {
     require_lang('classifieds');
     require_code('catalogues');
     require_code('ecommerce');
     $member_id = get_param_integer('member_id', get_member());
     $title = get_page_title($member_id == get_member() ? 'CLASSIFIED_ADVERTS' : '_CLASSIFIED_ADVERTS', true, array($GLOBALS['FORUM_DRIVER']->get_username($member_id)));
     if (is_guest()) {
         access_denied('NOT_AS_GUEST');
     }
     enforce_personal_access($member_id);
     $start = get_param_integer('start', 0);
     $max = get_param_integer('max', 30);
     require_code('templates_results_browser');
     $max_rows = $GLOBALS['SITE_DB']->query_value('catalogue_entries e JOIN ' . get_table_prefix() . 'classifieds_prices c ON c.c_catalogue_name=e.c_name', 'COUNT(*)', array('ce_submitter' => $member_id));
     $rows = $GLOBALS['SITE_DB']->query_select('catalogue_entries e JOIN ' . get_table_prefix() . 'classifieds_prices c ON c.c_catalogue_name=e.c_name', array('e.*'), array('ce_submitter' => $member_id), 'GROUP BY e.id ORDER BY ce_add_date DESC');
     if (count($rows) == 0) {
         inform_exit(do_lang_tempcode('NO_ENTRIES'));
     }
     $ads = array();
     foreach ($rows as $row) {
         $root = get_param_integer('root', NULL);
         $data_map = get_catalogue_entry_map($row, NULL, 'CATEGORY', 'DEFAULT', $root, NULL, array(0));
         $ad_title = $data_map['FIELD_0'];
         $purchase_url = build_url(array('page' => 'purchase', 'type' => 'misc', 'filter' => 'CLASSIFIEDS_ADVERT', 'id' => $row['id']), get_module_zone('purchase'));
         // We'll show all transactions against this ad
         $transaction_details = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'transactions WHERE purchase_id=' . strval($row['id']) . ' AND item LIKE \'' . db_encode_like('CLASSIFIEDS\\_ADVERT\\_%') . '\'');
         $_transaction_details = array();
         foreach ($transaction_details as $t) {
             list($found, ) = find_product_row($t['item']);
             if (!is_null($found)) {
                 $item_title = $found[4];
             } else {
                 $item_title = $t['item'];
             }
             $_transaction_details[] = array('T_ID' => strval($t['id']), 'PURCHASE_ID' => strval($t['purchase_id']), 'STATUS' => $t['status'], 'REASON' => $t['reason'], 'AMOUNT' => float_format($t['amount']), 'T_CURRENCY' => $t['t_currency'], 'LINKED' => $t['linked'], 'T_TIME' => strval($t['t_time']), 'ITEM' => $t['item'], 'ITEM_TITLE' => $item_title, 'PENDING_REASON' => $t['pending_reason'], 'T_MEMO' => $t['t_memo'], 'T_VIA' => $t['t_via']);
         }
         $url_map = array('page' => 'catalogues', 'type' => 'entry', 'id' => $row['id'], 'root' => $root);
         $url = build_url($url_map, '_SELF');
         // No known expiry status: put on free, or let expire
         if ($row['ce_last_moved'] == $row['ce_add_date']) {
             require_code('classifieds');
             initialise_classified_listing($row);
         }
         $ads[] = array('AD_TITLE' => $ad_title, 'TRANSACTION_DETAILS' => $_transaction_details, 'DATE' => get_timezoned_date($row['ce_add_date']), 'DATE_RAW' => strval($row['ce_add_date']), 'EXPIRES_DATE' => get_timezoned_date($row['ce_last_moved']), 'EXPIRES_DATE_RAW' => strval($row['ce_last_moved']), 'ACTIVE' => $row['ce_validated'] == 1, 'PURCHASE_URL' => $purchase_url, 'ID' => strval($row['id']), 'URL' => $url, 'NUM_VIEWS' => integer_format($row['ce_views']));
     }
     $results_browser = results_browser(do_lang('_CLASSIFIED_ADVERTS'), NULL, $start, 'start', $max, 'max', $max_rows, NULL, NULL, true);
     return do_template('CLASSIFIED_ADVERTS_SCREEN', array('TITLE' => $title, 'RESULTS_BROWSER' => $results_browser, 'ADS' => $ads));
 }