/** * Standard modular run function for CRON hooks. Searches for tasks to perform. */ function run() { if (!addon_installed('catalogues')) { return; } if (function_exists('set_time_limit')) { @set_time_limit(0); } $catalogue_categories = $GLOBALS['SITE_DB']->query('SELECT id,cc_move_target,cc_move_days_lower,cc_move_days_higher FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'catalogue_categories WHERE cc_move_target IS NOT NULL'); foreach ($catalogue_categories as $row) { $changed = false; $start = 0; do { $entries = $GLOBALS['SITE_DB']->query_select('catalogue_entries', array('id', 'ce_submitter', 'ce_last_moved'), array('cc_id' => $row['id']), '', 1000, $start); foreach ($entries as $entry) { $higher = has_specific_permission($entry['ce_submitter'], 'high_catalogue_entry_timeout'); $time_diff = time() - $entry['ce_last_moved']; $move_days = $higher ? $row['cc_move_days_higher'] : $row['cc_move_days_lower']; if ($time_diff / (60 * 60 * 24) > $move_days) { $GLOBALS['SITE_DB']->query_update('catalogue_entries', array('ce_last_moved' => time(), 'cc_id' => $row['cc_move_target']), array('id' => $entry['id']), '', 1); $changed = true; } } $start += 1000; } while (count($entries) == 1000); if ($changed) { require_code('catalogues2'); calculate_category_child_count_cache($row['cc_move_target']); calculate_category_child_count_cache($row['id']); } } }
/** * 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)); }
/** * Handling of a purchased classifieds advert. * * @param ID_TEXT The purchase ID. * @param array Details relating to the product. * @param ID_TEXT The product. */ function handle_classifieds_advert($purchase_id, $details, $product) { $days = $GLOBALS['SITE_DB']->query_value_null_ok('classifieds_prices', 'c_days', array('id' => intval(substr($product, 19)))); // Make validated, bump up timer $time = $GLOBALS['SITE_DB']->query_value_null_ok('catalogue_entries', 'ce_last_moved', array('id' => intval($purchase_id))); if (!is_null($time)) { $time += $days * 60 * 60 * 24; $GLOBALS['SITE_DB']->query_update('catalogue_entries', array('ce_validated' => 1, 'ce_last_moved' => $time), array('id' => intval($purchase_id)), '', 1); decache('main_cc_embed'); decache('main_recent_cc_entries'); require_code('catalogues2'); $cc_id = $GLOBALS['SITE_DB']->query_value_null_ok('catalogue_entries', 'cc_id', array('id' => intval($purchase_id))); calculate_category_child_count_cache($cc_id); } }
/** * Delete a catalogue entry. * * @param AUTO_LINK The ID of the entry to delete */ function actual_delete_catalogue_entry($id) { $old_category_id = $GLOBALS['SITE_DB']->query_value('catalogue_entries', 'cc_id', array('id' => $id)); $catalogue_name = $GLOBALS['SITE_DB']->query_value('catalogue_entries', 'c_name', array('id' => $id)); require_code('fields'); require_code('catalogues'); $fields = $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('*'), array('c_name' => $catalogue_name)); $title = NULL; foreach ($fields as $field) { $object = get_fields_hook($field['cf_type']); list(, , $storage_type) = $object->get_field_value_row_bits($field); $value = _get_catalogue_entry_field($field['id'], $id, $storage_type); if (method_exists($object, 'cleanup')) { $object->cleanup($value); } if (is_null($title)) { if ($storage_type == 'long_trans' || $storage_type == 'short_trans') { $title = get_translated_text(intval($value)); } else { $title = $value; } } } $lang1 = $GLOBALS['SITE_DB']->query_select('catalogue_efv_long_trans', array('cv_value'), array('ce_id' => $id)); $lang2 = $GLOBALS['SITE_DB']->query_select('catalogue_efv_short_trans', array('cv_value'), array('ce_id' => $id)); $lang = array_merge($lang1, $lang2); foreach ($lang as $lang_to_delete) { if (true) { require_code('attachments2'); require_code('attachments3'); delete_lang_comcode_attachments($lang_to_delete['cv_value'], 'catalogue_entry', strval($id)); } else { delete_lang($lang_to_delete['cv_value']); } } $GLOBALS['SITE_DB']->query_delete('catalogue_efv_long_trans', array('ce_id' => $id)); $GLOBALS['SITE_DB']->query_delete('catalogue_efv_short_trans', array('ce_id' => $id)); $GLOBALS['SITE_DB']->query_delete('catalogue_efv_long', array('ce_id' => $id)); $GLOBALS['SITE_DB']->query_delete('catalogue_efv_short', array('ce_id' => $id)); $GLOBALS['SITE_DB']->query_delete('catalogue_efv_float', array('ce_id' => $id)); $GLOBALS['SITE_DB']->query_delete('catalogue_efv_integer', array('ce_id' => $id)); $GLOBALS['SITE_DB']->query_delete('catalogue_entries', array('id' => $id), '', 1); $GLOBALS['SITE_DB']->query_delete('trackbacks', array('trackback_for_type' => 'catalogues', 'trackback_for_id' => $id)); $GLOBALS['SITE_DB']->query_delete('rating', array('rating_for_type' => 'catalogues', 'rating_for_id' => $id)); require_code('seo2'); seo_meta_erase_storage('catalogue_entry', strval($id)); calculate_category_child_count_cache($old_category_id); decache('main_recent_cc_entries'); decache('main_cc_embed'); if ($catalogue_name[0] != '_') { log_it('DELETE_CATALOGUE_ENTRY', strval($id), $title); } }