Beispiel #1
0
 /**
  * Standard modular info function for award hooks. Provides information to allow task reporting, randomisation, and add-screen linking, to function.
  *
  * @return ?array	Map of award content-type info (NULL: disabled).
  */
 function info()
 {
     $info = array();
     $info['connection'] = $GLOBALS['SITE_DB'];
     $info['table'] = 'download_downloads';
     $info['date_field'] = 'add_date';
     $info['id_field'] = 'id';
     $info['add_url'] = has_submit_permission('mid', get_member(), get_ip_address(), 'cms_downloads') ? build_url(array('page' => 'cms_downloads', 'type' => 'ad'), get_module_zone('cms_downloads')) : new ocp_tempcode();
     $info['category_field'] = 'category_id';
     $info['category_type'] = 'downloads';
     $info['parent_spec__table_name'] = 'download_categories';
     $info['parent_spec__parent_name'] = 'parent_id';
     $info['parent_spec__field_name'] = 'id';
     $info['parent_field_name'] = 'id';
     $info['submitter_field'] = 'submitter';
     $info['id_is_string'] = false;
     require_lang('downloads');
     $info['title'] = do_lang_tempcode('SECTION_DOWNLOADS');
     $info['validated_field'] = 'validated';
     $info['category_is_string'] = false;
     $info['archive_url'] = build_url(array('page' => 'downloads'), get_module_zone('downloads'));
     $info['cms_page'] = 'cms_downloads';
     $info['views_field'] = 'download_views';
     $info['supports_custom_fields'] = true;
     return $info;
 }
Beispiel #2
0
 /**
  * Standard modular info function for award hooks. Provides information to allow task reporting, randomisation, and add-screen linking, to function.
  *
  * @return ?array	Map of award content-type info (NULL: disabled).
  */
 function info()
 {
     $info = array();
     $info['connection'] = $GLOBALS['SITE_DB'];
     $info['table'] = 'videos';
     $info['date_field'] = 'add_date';
     $info['id_field'] = 'id';
     $info['add_url'] = has_submit_permission('mid', get_member(), get_ip_address(), 'cms_galleries') ? build_url(array('page' => 'cms_galleries', 'type' => 'av'), get_module_zone('cms_galleries')) : new ocp_tempcode();
     $info['category_field'] = 'cat';
     $info['category_type'] = 'galleries';
     $info['parent_spec__table_name'] = 'galleries';
     $info['parent_spec__parent_name'] = 'parent_id';
     $info['parent_spec__field_name'] = 'name';
     $info['parent_field_name'] = 'cat';
     $info['submitter_field'] = 'submitter';
     $info['id_is_string'] = false;
     require_lang('galleries');
     $info['title'] = do_lang_tempcode('VIDEOS');
     $info['validated_field'] = 'validated';
     $info['category_is_string'] = true;
     $info['archive_url'] = build_url(array('page' => 'galleries'), get_module_zone('galleries'));
     $info['cms_page'] = 'cms_galleries';
     $info['where'] = 'cat NOT LIKE \'' . db_encode_like('download\\_%') . '\'';
     $info['views_field'] = 'video_views';
     $info['supports_custom_fields'] = true;
     return $info;
 }
Beispiel #3
0
 /**
  * Standard modular info function for award hooks. Provides information to allow task reporting, randomisation, and add-screen linking, to function.
  *
  * @param  ?ID_TEXT	Catalogue we'll be using (NULL: unknown).
  * @return ?array		Map of award content-type info (NULL: disabled).
  */
 function info($catalogue_name = NULL)
 {
     $info = array();
     $info['connection'] = $GLOBALS['SITE_DB'];
     $info['table'] = 'catalogue_entries';
     $info['date_field'] = 'ce_add_date';
     $info['id_field'] = 'id';
     $info['add_url'] = has_submit_permission('mid', get_member(), get_ip_address(), 'cms_catalogues') ? build_url(array('page' => 'cms_catalogues', 'type' => 'add_entry', 'catalogue_name' => $catalogue_name), get_module_zone('cms_catalogues')) : new ocp_tempcode();
     $info['category_field'] = array('c_name', 'cc_id');
     $info['category_type'] = array('catalogues_catalogue', 'catalogues_category');
     $info['parent_spec__table_name'] = 'catalogue_categories';
     $info['parent_spec__parent_name'] = 'cc_parent_id';
     $info['parent_spec__field_name'] = 'id';
     $info['parent_field_name'] = 'cc_id';
     $info['submitter_field'] = 'ce_submitter';
     $info['id_is_string'] = false;
     require_lang('catalogues');
     $info['title'] = do_lang_tempcode('CATALOGUE_ENTRIES');
     $info['validated_field'] = 'ce_validated';
     $info['category_is_string'] = array(true, false);
     $info['archive_url'] = build_url(array('page' => 'catalogues'), get_module_zone('catalogues'));
     $info['cms_page'] = 'cms_catalogues';
     $info['views_field'] = 'ce_views';
     return $info;
 }
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     require_code('catalogues');
     require_lang('catalogues');
     require_css('catalogues');
     $number = array_key_exists('param', $map) ? intval($map['param']) : 10;
     $catalogue = array_key_exists('catalogue', $map) ? $map['catalogue'] : 'faqs';
     $zone = array_key_exists('zone', $map) ? $map['zone'] : get_module_zone('catalogues');
     $root = array_key_exists('root', $map) && $map['root'] != '' ? intval($map['root']) : NULL;
     $catalogues = $GLOBALS['SITE_DB']->query_select('catalogues', array('*'), array('c_name' => $catalogue), '', 1);
     if (!array_key_exists(0, $catalogues)) {
         return do_lang_tempcode('MISSING_RESOURCE', escape_html($catalogue));
     }
     $catalogue_row = $catalogues[0];
     $entries = $GLOBALS['SITE_DB']->query_select('catalogue_entries', array('*'), array('c_name' => $catalogue, 'ce_validated' => 1), 'ORDER BY ce_add_date DESC', $number);
     $tpl_set = $catalogue;
     $display_type = array_key_exists('display_type', $map) ? intval($map['display_type']) : NULL;
     list($content, , ) = get_catalogue_category_entry_buildup(db_get_first_id(), $catalogue, $catalogue_row, 'SEARCH', $tpl_set, $number, 0, NULL, $root, $display_type, false, $entries);
     $catalogue_title = get_translated_text($catalogue_row['c_title']);
     if ($content->is_empty()) {
         if (has_actual_page_access(NULL, 'cms_catalogues', NULL, NULL) && has_submit_permission('mid', get_member(), get_ip_address(), 'cms_catalogues')) {
             $submit_url = build_url(array('page' => 'cms_catalogues', 'type' => 'add_entry', 'catalogue_name' => $catalogue, 'redirect' => SELF_REDIRECT), get_module_zone('cms_catalogues'));
         } else {
             $submit_url = new ocp_tempcode();
         }
         return do_template('BLOCK_NO_ENTRIES', array('HIGH' => false, 'TITLE' => do_lang_tempcode('RECENT', escape_html(integer_format($number)), escape_html($catalogue_title)), 'MESSAGE' => do_lang_tempcode('NO_ENTRIES'), 'ADD_NAME' => do_lang_tempcode('CATALOGUE_GENERIC_ADD', escape_html($catalogue_title)), 'SUBMIT_URL' => $submit_url));
     }
     return do_template('BLOCK_MAIN_RECENT_CC_ENTRIES', array('_GUID' => 'a57fa1b83d1b6fe3acbceb2b618e6d7f', 'CATALOGUE_TITLE' => $catalogue_title, 'CATALOGUE' => $catalogue, 'CONTENT' => $content, 'NUMBER' => integer_format($number)));
 }
Beispiel #5
0
 /**
  * Standard modular info function for award hooks. Provides information to allow task reporting, randomisation, and add-screen linking, to function.
  *
  * @return ?array	Map of award content-type info (NULL: disabled).
  */
 function info()
 {
     $info = array();
     $info['connection'] = $GLOBALS['SITE_DB'];
     $info['table'] = 'seedy_posts';
     $info['date_field'] = 'date_and_time';
     $info['id_field'] = 'id';
     $info['add_url'] = has_submit_permission('low', get_member(), get_ip_address(), 'cedi') ? build_url(array('page' => 'cedi', 'type' => 'add_post'), get_module_zone('cedi')) : new ocp_tempcode();
     $info['category_field'] = 'page_id';
     $info['category_type'] = 'seedy_page';
     $info['parent_spec__table_name'] = 'seedy_children';
     $info['parent_spec__parent_name'] = 'parent_id';
     $info['parent_spec__field_name'] = 'child_id';
     $info['parent_field_name'] = 'page_id';
     $info['submitter_field'] = 'the_user';
     $info['id_is_string'] = false;
     require_lang('cedi');
     $info['title'] = do_lang_tempcode('CEDI_POSTS');
     $info['validated_field'] = 'validated';
     $info['category_is_string'] = false;
     $info['archive_url'] = build_url(array('page' => 'cedi'), get_module_zone('cedi'));
     $info['cms_page'] = 'cedi';
     $info['supports_custom_fields'] = true;
     return $info;
 }
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     require_code('downloads');
     require_css('downloads');
     require_lang('downloads');
     require_code('ocfiltering');
     $number = array_key_exists('param', $map) ? intval($map['param']) : 10;
     $filter = array_key_exists('filter', $map) ? $map['filter'] : '*';
     $zone = array_key_exists('zone', $map) ? $map['zone'] : get_module_zone('downloads');
     $sql_filter = ocfilter_to_sqlfragment($filter, 'p.category_id', 'download_categories', 'parent_id', 'p.category_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)
     $rows = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'download_downloads p WHERE validated=1 AND (' . $sql_filter . ') ORDER BY add_date DESC', $number);
     $title = do_lang_tempcode('RECENT', make_string_tempcode(integer_format($number)), do_lang_tempcode('SECTION_DOWNLOADS'));
     if (array_key_exists('title', $map) && $map['title'] != '') {
         $title = protect_from_escaping(escape_html($map['title']));
     }
     $out = new ocp_tempcode();
     foreach ($rows as $i => $row) {
         if ($i != 0) {
             $out->attach(do_template('BLOCK_SEPARATOR'));
         }
         $out->attach(get_download_html($row, true, true, $zone));
     }
     if ($out->is_empty()) {
         if (has_actual_page_access(NULL, 'cms_downloads', NULL, NULL) && has_submit_permission('mid', get_member(), get_ip_address(), 'cms_downloads')) {
             $submit_url = build_url(array('page' => 'cms_downloads', 'type' => 'ad', 'redirect' => SELF_REDIRECT), get_module_zone('cms_downloads'));
         } else {
             $submit_url = new ocp_tempcode();
         }
         return do_template('BLOCK_NO_ENTRIES', array('_GUID' => '74399763a51102bdd6e6d92c2c11354f', 'HIGH' => false, 'TITLE' => $title, 'MESSAGE' => do_lang_tempcode('NO_DOWNLOADS_YET'), 'ADD_NAME' => do_lang_tempcode('ADD_DOWNLOAD'), 'SUBMIT_URL' => $submit_url));
     }
     return do_template('BLOCK_MAIN_RECENT_DOWNLOADS', array('_GUID' => '257fa1b83d1b6fe3acbceb2b618e6d7f', 'TITLE' => $title, 'CONTENT' => $out, 'NUMBER' => integer_format($number)));
 }
Beispiel #7
0
 /**
  * Standard modular run function for do_next_menu hooks. They find links to put on standard navigation menus of the system.
  *
  * @param  boolean		Whether to look deep into the database (or whatever else might be time-intensive) for links
  * @return array			Array of links and where to show
  */
 function run($exhaustive = false)
 {
     if (!addon_installed('catalogues')) {
         return array();
     }
     $ret = array();
     if (has_specific_permission(get_member(), 'submit_cat_highrange_content', 'cms_catalogues')) {
         $ret[] = array('cms', 'catalogues', array('cms_catalogues', array('type' => 'misc'), get_module_zone('cms_catalogues')), do_lang_tempcode('ITEMS_HERE', do_lang_tempcode('CATALOGUES'), make_string_tempcode(escape_html(integer_format($GLOBALS['SITE_DB']->query_value_null_ok('catalogues', 'COUNT(*)', NULL, '', true))))), 'DOC_CATALOGUES');
     }
     if ($exhaustive) {
         $catalogues = $GLOBALS['SITE_DB']->query_select('catalogues', array('c_name', 'c_title', 'c_description', 'c_ecommerce'), NULL, '', 10, NULL, true);
         if (!is_null($catalogues)) {
             $ret2 = array();
             foreach ($catalogues as $row) {
                 if (substr($row['c_name'], 0, 1) == '_') {
                     continue;
                 }
                 if ($row['c_ecommerce'] == 0 || addon_installed('shopping')) {
                     if (has_submit_permission('mid', get_member(), get_ip_address(), 'cms_catalogues', array('catalogues_catalogue', $row['c_name']))) {
                         $ret2[] = array('cms', 'of_catalogues', array('cms_catalogues', array('type' => 'misc', 'catalogue_name' => $row['c_name']), get_module_zone('cms_catalogues')), do_lang_tempcode('ITEMS_HERE', escape_html(get_translated_text($row['c_title'])), escape_html(integer_format($GLOBALS['SITE_DB']->query_value_null_ok('catalogue_entries', 'COUNT(*)', array('c_name' => $row['c_name']), '', true)))), get_translated_text($row['c_description']));
                     }
                 }
             }
             if (count($ret2) < 10) {
                 $ret = array_merge($ret, $ret2);
             }
         }
     }
     return $ret;
 }
Beispiel #8
0
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     require_lang('iotds');
     require_css('iotds');
     $mode = array_key_exists('param', $map) ? $map['param'] : 'current';
     $zone = array_key_exists('zone', $map) ? $map['zone'] : get_module_zone('iotds');
     if (has_actual_page_access(NULL, 'cms_iotds', NULL, NULL) && has_submit_permission('mid', get_member(), get_ip_address(), 'cms_iotds')) {
         $submit_url = build_url(array('page' => 'cms_iotds', 'type' => 'ad', 'redirect' => SELF_REDIRECT), get_module_zone('cms_iotds'));
     } else {
         $submit_url = new ocp_tempcode();
     }
     if ($mode == 'current') {
         $iotd = $GLOBALS['SITE_DB']->query_select('iotd', array('*'), array('is_current' => 1), 'ORDER BY id DESC', 1);
     } elseif (is_numeric($mode)) {
         $iotd = $GLOBALS['SITE_DB']->query_select('iotd', array('*'), array('id' => intval($mode)), '', 1);
         if (!array_key_exists(0, $iotd)) {
             return do_template('BLOCK_NO_ENTRIES', array('HIGH' => true, 'TITLE' => do_lang_tempcode('IOTD'), 'MESSAGE' => do_lang_tempcode('NO_ENTRIES'), 'ADD_NAME' => do_lang_tempcode('ADD_IOTD'), 'SUBMIT_URL' => $submit_url));
         }
     } else {
         $cnt = $GLOBALS['SITE_DB']->query_value('iotd', 'COUNT(*)', array('used' => 1));
         if ($cnt == 0) {
             return do_template('BLOCK_NO_ENTRIES', array('HIGH' => true, 'TITLE' => do_lang_tempcode('IOTD'), 'MESSAGE' => do_lang_tempcode('NO_ENTRIES'), 'ADD_NAME' => do_lang_tempcode('ADD_IOTD'), 'SUBMIT_URL' => $submit_url));
         }
         $at = mt_rand(0, $cnt - 1);
         $iotd = $GLOBALS['SITE_DB']->query_select('iotd', array('*'), array('used' => 1), '', 1, $at);
     }
     if (!array_key_exists(0, $iotd)) {
         return do_template('BLOCK_NO_ENTRIES', array('_GUID' => '62baa388e068d4334f7a6c6093ead56a', 'HIGH' => true, 'TITLE' => do_lang_tempcode('IOTD'), 'MESSAGE' => do_lang_tempcode('NO_ENTRIES'), 'ADD_NAME' => do_lang_tempcode('ADD_IOTD'), 'SUBMIT_URL' => $submit_url));
     }
     $myrow = $iotd[0];
     $image_url = $myrow['url'];
     if (url_is_local($image_url)) {
         $image_url = get_custom_base_url() . '/' . $image_url;
     }
     $view_url = build_url(array('page' => 'iotds', 'wide' => 1, 'type' => 'view', 'id' => $myrow['id']), $zone);
     require_code('images');
     $thumb_url = ensure_thumbnail($myrow['url'], $myrow['thumb_url'], 'iotds', 'iotd', $myrow['id']);
     $caption = get_translated_tempcode($myrow['i_title']);
     $image = do_image_thumb($thumb_url, do_lang('IOTD'));
     $archive_url = build_url(array('page' => 'iotds', 'type' => 'misc'), $zone);
     $tpl = do_template('IOTD', array('_GUID' => 'ca9c4b4941c12c15f7bdfe4cb57cd266', 'ID' => strval($myrow['id']), 'IMAGE_URL' => $image_url, 'SUBMITTER' => strval($myrow['submitter']), 'VIEW_URL' => $view_url, 'CAPTION' => $caption, 'IMAGE' => $image));
     $map2 = array('_GUID' => 'd710da3675a1775867168ae37db02ad4', 'CURRENT' => $mode == 'current', 'FULL_URL' => $view_url, 'ID' => strval($myrow['id']), 'CONTENT' => $tpl, 'ARCHIVE_URL' => $archive_url, 'SUBMIT_URL' => $submit_url);
     if (get_option('is_on_comments') == '1' && get_forum_type() != 'none' && $myrow['allow_comments'] >= 1) {
         $map2['COMMENT_COUNT'] = '1';
     }
     return do_template('BLOCK_MAIN_IOTD', $map2);
 }
Beispiel #9
0
 /**
  * Standard modular info function for award hooks. Provides information to allow task reporting, randomisation, and add-screen linking, to function.
  *
  * @return ?array	Map of award content-type info (NULL: disabled).
  */
 function info()
 {
     $info = array();
     $info['connection'] = $GLOBALS['SITE_DB'];
     $info['table'] = 'catalogues';
     $info['date_field'] = 'c_add_date';
     $info['id_field'] = 'c_name';
     $info['add_url'] = has_submit_permission('mid', get_member(), get_ip_address(), 'cms_catalogues') ? build_url(array('page' => 'cms_catalogues', 'type' => 'add_entry', 'catalogue_name' => '!'), get_module_zone('cms_catalogues')) : new ocp_tempcode();
     $info['category_field'] = 'c_name';
     $info['category_type'] = 'catalogues_catalogue';
     $info['id_is_string'] = true;
     require_lang('catalogues');
     $info['title'] = do_lang_tempcode('CATALOGUES');
     $info['category_is_string'] = true;
     $info['archive_url'] = build_url(array('page' => 'catalogues'), get_module_zone('catalogues'));
     $info['cms_page'] = 'cms_catalogues';
     return $info;
 }
Beispiel #10
0
 /**
  * Standard modular info function for award hooks. Provides information to allow task reporting, randomisation, and add-screen linking, to function.
  *
  * @return ?array	Map of award content-type info (NULL: disabled).
  */
 function info()
 {
     $info = array();
     $info['connection'] = $GLOBALS['SITE_DB'];
     $info['table'] = 'authors';
     $info['date_field'] = NULL;
     $info['id_field'] = 'author';
     $info['add_url'] = has_submit_permission('mid', get_member(), get_ip_address(), 'cms_authors') ? build_url(array('page' => 'cms_authors', 'type' => '_ad'), get_module_zone('cms_authors')) : new ocp_tempcode();
     $info['category_field'] = NULL;
     $info['submitter_field'] = 'forum_handle';
     $info['id_is_string'] = true;
     require_lang('authors');
     $info['title'] = do_lang_tempcode('AUTHORS');
     $info['category_is_string'] = true;
     $info['archive_url'] = build_url(array('page' => 'authors'), get_module_zone('authors'));
     $info['cms_page'] = 'cms_authors';
     $info['supports_custom_fields'] = true;
     return $info;
 }
Beispiel #11
0
 /**
  * Standard modular info function for award hooks. Provides information to allow task reporting, randomisation, and add-screen linking, to function.
  *
  * @return ?array	Map of award content-type info (NULL: disabled).
  */
 function info()
 {
     $info = array();
     $info['connection'] = $GLOBALS['SITE_DB'];
     $info['table'] = 'comcode_pages';
     $info['date_field'] = 'p_add_date';
     $info['id_field'] = array('the_zone', 'the_page');
     $info['add_url'] = has_submit_permission('high', get_member(), get_ip_address(), 'cms_comcode_pages') ? build_url(array('page' => 'cms_comcode_pages', 'type' => 'ed'), get_module_zone('cms_comcode_pages')) : new ocp_tempcode();
     $info['category_field'] = array('the_zone', 'the_page');
     $info['category_type'] = '!';
     $info['submitter_field'] = 'p_submitter';
     $info['id_is_string'] = true;
     require_lang('zones');
     $info['title'] = do_lang_tempcode('COMCODE_PAGES');
     $info['validated_field'] = 'p_validated';
     $info['category_is_string'] = true;
     $info['archive_url'] = build_url(array('page' => 'sitemap'), get_page_zone('sitemap'));
     $info['cms_page'] = 'cms_comcode_pages';
     return $info;
 }
Beispiel #12
0
 /**
  * Standard modular render function for profile tab hooks.
  *
  * @param  MEMBER			The ID of the member who is being viewed
  * @param  MEMBER			The ID of the member who is doing the viewing
  * @param  boolean		Whether to leave the tab contents NULL, if tis hook supports it, so that AJAX can load it later
  * @return array			A triple: The tab title, the tab contents, the suggested tab order
  */
 function render_tab($member_id_of, $member_id_viewing, $leave_to_ajax_if_possible = false)
 {
     require_lang('galleries');
     $title = do_lang_tempcode('GALLERIES');
     $order = 30;
     if ($leave_to_ajax_if_possible) {
         return array($title, NULL, $order);
     }
     $galleries = new ocp_tempcode();
     require_code('galleries');
     require_css('galleries');
     $rows = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'galleries WHERE name LIKE \'' . db_encode_like('member\\_' . strval($member_id_of) . '\\_%') . '\'');
     foreach ($rows as $i => $row) {
         $galleries->attach(do_template('GALLERY_SUBGALLERY_WRAP', array('CONTENT' => show_gallery_box($row, 'root', false, get_module_zone('galleries')))));
         $this->attach_gallery_subgalleries($row['name'], $galleries);
     }
     $add_gallery_url = new ocp_tempcode();
     $add_image_url = new ocp_tempcode();
     $add_video_url = new ocp_tempcode();
     if ($member_id_of == $member_id_viewing) {
         if (count($rows) == 0) {
             $test = $GLOBALS['SITE_DB']->query_select('galleries', array('accept_images', 'accept_videos', 'name'), array('is_member_synched' => 1));
             if (array_key_exists(0, $test)) {
                 if ($test[0]['accept_images'] == 1) {
                     $add_image_url = build_url(array('page' => 'cms_galleries', 'type' => 'ad', 'cat' => 'member_' . strval($member_id_of) . '_' . $test[0]['name']), get_module_zone('cms_galleries'));
                 }
                 if ($test[0]['accept_videos'] == 1) {
                     $add_video_url = build_url(array('page' => 'cms_galleries', 'type' => 'av', 'cat' => 'member_' . strval($member_id_of) . '_' . $test[0]['name']), get_module_zone('cms_galleries'));
                 }
             }
         } else {
             if (has_actual_page_access(NULL, 'cms_galleries', NULL, NULL) && has_submit_permission('cat_mid', get_member(), get_ip_address(), 'cms_galleries')) {
                 $add_gallery_url = build_url(array('page' => 'cms_galleries', 'type' => 'ac', 'cat' => $rows[0]['name']), get_module_zone('cms_galleries'));
             }
         }
     }
     $content = do_template('OCF_MEMBER_PROFILE_GALLERIES', array('MEMBER_ID' => strval($member_id_of), 'GALLERIES' => $galleries, 'ADD_GALLERY_URL' => $add_gallery_url, 'ADD_IMAGE_URL' => $add_image_url, 'ADD_VIDEO_URL' => $add_video_url));
     return array($title, $content, $order);
 }
Beispiel #13
0
 /**
  * Standard modular info function for award hooks. Provides information to allow task reporting, randomisation, and add-screen linking, to function.
  *
  * @return ?array	Map of award content-type info (NULL: disabled).
  */
 function info()
 {
     $info = array();
     $info['connection'] = $GLOBALS['SITE_DB'];
     $info['table'] = 'quizzes';
     $info['date_field'] = 'q_add_date';
     $info['id_field'] = 'id';
     $info['add_url'] = has_submit_permission('high', get_member(), get_ip_address(), 'cms_quiz') ? build_url(array('page' => 'cms_quiz', 'type' => 'ad'), get_module_zone('cms_quiz')) : new ocp_tempcode();
     $info['category_field'] = 'q_type';
     $info['parent_spec__table_name'] = NULL;
     $info['parent_spec__parent_name'] = NULL;
     $info['parent_spec__field_name'] = NULL;
     $info['parent_field_name'] = NULL;
     $info['submitter_field'] = 'q_submitter';
     $info['id_is_string'] = false;
     require_lang('quiz');
     $info['title'] = do_lang_tempcode('QUIZZES');
     $info['validated_field'] = 'q_validated';
     $info['category_is_string'] = true;
     $info['archive_url'] = build_url(array('page' => 'quiz'), get_module_zone('quiz'));
     $info['cms_page'] = 'cms_quiz';
     $info['supports_custom_fields'] = true;
     return $info;
 }
Beispiel #14
0
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     if (!array_key_exists('param', $map)) {
         $map['param'] = '';
     }
     require_code('banners');
     require_lang('banners');
     $b_type = $map['param'];
     $myquery = 'SELECT * FROM ' . get_table_prefix() . 'banners WHERE validated=1 AND ' . db_string_equal_to('b_type', $b_type) . ' AND (expiry_date IS NULL OR expiry_date>' . strval(time()) . ') ORDER BY hits_from+hits_to DESC';
     $_banners = $GLOBALS['SITE_DB']->query($myquery, 200);
     $assemble = new ocp_tempcode();
     $banners = array();
     foreach ($_banners as $banner) {
         $description = get_translated_tempcode($banner['caption']);
         $bd = show_banner($banner['name'], $banner['b_title_text'], $description, $banner['img_url'], '', $banner['site_url'], $banner['b_type']);
         $banners[] = array('BANNER' => $bd, 'NAME' => $banner['name'], 'URL' => $banner['site_url'], 'DESCRIPTION' => $description, 'HITSFROM' => strval($banner['hits_from']), 'HITSTO' => strval($banner['hits_to']), 'VIEWSFROM' => strval($banner['views_from']), 'VIEWSTO' => strval($banner['views_to']), 'ADDDATE' => strval($banner['add_date']), 'SUBMITTER' => strval($banner['submitter']));
     }
     if (has_actual_page_access(NULL, 'cms_banners', NULL, NULL) && has_submit_permission('mid', get_member(), get_ip_address(), 'cms_banners')) {
         $submit_url = build_url(array('page' => 'cms_banners', 'type' => 'ad', 'redirect' => SELF_REDIRECT), get_module_zone('cms_banners'));
     } else {
         $submit_url = new ocp_tempcode();
     }
     return do_template('BLOCK_MAIN_TOPSITES', array('TYPE' => $map['param'], 'BANNERS' => $banners, 'SUBMIT_URL' => $submit_url));
 }
Beispiel #15
0
/**
 * Show a banner according to GET parameter specification.
 *
 * @param  boolean		Whether to return a result rather than outputting
 * @param  ?string		Whether we are displaying or click-processing (NULL: get from URL param)
 * @set    "click" ""
 * @param  ?string		Specific banner to display (NULL: get from URL param) (blank: randomise)
 * @param  ?string		Banner type to display (NULL: get from URL param)
 * @param  ?integer		Whether we are only showing our own banners, rather than allowing external rotation ones (NULL: get from URL param)
 * @param  ?string		The banner advertisor who is actively displaying the banner (calling up this function) and hence is rewarded (NULL: get from URL param) (blank: our own site)
 * @return ?tempcode		Result (NULL: we weren't asked to return the result)
 */
function banners_script($ret = false, $type = NULL, $dest = NULL, $b_type = NULL, $internal_only = NULL, $source = NULL)
{
    require_code('images');
    require_lang('banners');
    // If this is being called for a click through
    if (is_null($type)) {
        $type = get_param('type', '');
    }
    if ($type == 'click') {
        // Input parameters
        if (is_null($source)) {
            $source = get_param('source', '');
        }
        if (is_null($dest)) {
            $dest = get_param('dest', '');
        }
        // Has the banner been clicked before?
        $test = $GLOBALS['SITE_DB']->query_value('banner_clicks', 'MAX(c_date_and_time)', array('c_ip_address' => get_ip_address(), 'c_banner_id' => $dest));
        $unique = is_null($test) || $test < time() - 60 * 60 * 24;
        // Find the information about the dest
        $rows = $GLOBALS['SITE_DB']->query_select('banners', array('site_url', 'hits_to', 'campaign_remaining'), array('name' => $dest));
        if (!array_key_exists(0, $rows)) {
            fatal_exit(do_lang_tempcode('MISSING_RESOURCE'));
        }
        $myrow = $rows[0];
        $url = $myrow['site_url'];
        $page_link = url_to_pagelink($url);
        if ($page_link != '') {
            $keep = symbol_tempcode('KEEP', array(strpos($url, '?') === false ? '1' : '0'));
            $url .= $keep->evaluate();
        }
        if ($unique) {
            if (get_db_type() != 'xml') {
                $GLOBALS['SITE_DB']->query('UPDATE ' . get_table_prefix() . 'banners SET hits_to=(hits_to+1) WHERE ' . db_string_equal_to('name', $dest), 1);
            }
            $campaignremaining = $myrow['campaign_remaining'];
            if (!is_null($campaignremaining)) {
                if (get_db_type() != 'xml') {
                    $GLOBALS['SITE_DB']->query('UPDATE ' . get_table_prefix() . 'banners SET campaign_remaining=(campaign_remaining-1) WHERE ' . db_string_equal_to('name', $dest), 1);
                }
            }
        }
        // Find the information about the source
        if ($source != '' && $unique) {
            $rows = $GLOBALS['SITE_DB']->query_select('banners', array('hits_from', 'campaign_remaining'), array('name' => $source));
            if (!array_key_exists(0, $rows)) {
                fatal_exit(do_lang_tempcode('BANNER_MISSING_SOURCE'));
            }
            $myrow = $rows[0];
            if (get_db_type() != 'xml') {
                $GLOBALS['SITE_DB']->query('UPDATE ' . get_table_prefix() . 'banners SET hits_from=(hits_from+1) WHERE ' . db_string_equal_to('name', $source), 1);
            }
            $campaignremaining = $myrow['campaign_remaining'];
            if (!is_null($campaignremaining)) {
                if (get_db_type() != 'xml') {
                    $GLOBALS['SITE_DB']->query('UPDATE ' . get_table_prefix() . 'banners SET campaign_remaining=(campaign_remaining+1) WHERE ' . db_string_equal_to('name', $source), 1);
                }
            }
        }
        // Log the click
        load_user_stuff();
        $GLOBALS['SITE_DB']->query_insert('banner_clicks', array('c_date_and_time' => time(), 'c_member_id' => get_member(), 'c_ip_address' => get_ip_address(), 'c_source' => $source, 'c_banner_id' => $dest));
        if (strpos($url, chr(10)) !== false || strpos($url, chr(13)) !== false) {
            log_hack_attack_and_exit('HEADER_SPLIT_HACK');
        }
        header('Location: ' . $url);
    } else {
        if (is_null($dest)) {
            $dest = get_param('dest', '');
        }
        if (is_null($b_type)) {
            $b_type = get_param('b_type', '');
        }
        if (is_null($internal_only)) {
            $internal_only = get_param_integer('internal_only', 0);
        }
        if ($internal_only == 0 && $dest == '' && $b_type == '') {
            $adcode = get_option('money_ad_code');
            if ($adcode != '' && (0 == $GLOBALS['SITE_DB']->query_value('banners', 'COUNT(*)', array('validated' => 1)) || mt_rand(0, 100) > intval(get_option('advert_chance')))) {
                if ($ret) {
                    return make_string_tempcode($adcode);
                }
                $echo = do_template('BASIC_HTML_WRAP', array('_GUID' => 'fd6fc24384dd13e7931ceb369a500672', 'TITLE' => do_lang_tempcode('BANNER'), 'CONTENT' => $adcode));
                $echo->evaluate_echo();
                return NULL;
            }
        }
        // A community banner then...
        // ==========================
        // Input parameters (clicks-in from source site)
        if (is_null($source)) {
            $source = get_param('source', '');
        }
        // To allow overriding to specify a specific banner
        if ($dest != '') {
            $myquery = 'SELECT * FROM ' . get_table_prefix() . 'banners WHERE ' . db_string_equal_to('name', $dest);
        } else {
            $myquery = 'SELECT * FROM ' . get_table_prefix() . 'banners WHERE ((the_type<>' . strval(BANNER_CAMPAIGN) . ') OR (campaign_remaining>0)) AND ((expiry_date IS NULL) OR (expiry_date>' . strval(time()) . ')) AND ' . db_string_not_equal_to('name', $source) . ' AND validated=1 AND ' . db_string_equal_to('b_type', $b_type);
        }
        // Run Query
        $rows = $GLOBALS['SITE_DB']->query($myquery, 500, NULL, true);
        if (is_null($rows)) {
            $rows = array();
        }
        // Error, but tolerate it as it could be on each page load
        // Filter out what we don't have permission for
        if (get_option('use_banner_permissions', true) === '1') {
            load_user_stuff();
            require_code('permissions');
            $groups = _get_where_clause_groups(get_member());
            if (!is_null($groups)) {
                $perhaps = collapse_1d_complexity('category_name', $GLOBALS['SITE_DB']->query('SELECT category_name FROM ' . get_table_prefix() . 'group_category_access WHERE ' . db_string_equal_to('module_the_name', 'banners') . ' AND (' . $groups . ')'));
                $new_rows = array();
                foreach ($rows as $row) {
                    if (in_array($row['name'], $perhaps)) {
                        $new_rows[] = $row;
                    }
                }
                $rows = $new_rows;
            }
        }
        // Are we allowed to show default banners?
        $counter = 0;
        $show_defaults = true;
        while (array_key_exists($counter, $rows)) {
            $myrow = $rows[$counter];
            if ($myrow['the_type'] == BANNER_CAMPAIGN) {
                $show_defaults = false;
            }
            $counter++;
        }
        // Count the total of all importance_modulus entries
        $tally = 0;
        $counter = 0;
        $bound = array();
        while (array_key_exists($counter, $rows)) {
            $myrow = $rows[$counter];
            if ($myrow['the_type'] == 2 && !$show_defaults) {
                $myrow['importance_modulus'] = 0;
            }
            $tally += $myrow['importance_modulus'];
            $bound[$counter] = $tally;
            $counter++;
        }
        if ($tally == 0) {
            load_user_stuff();
            require_code('permissions');
            if (has_actual_page_access(NULL, 'cms_banners') && has_submit_permission('mid', get_member(), get_ip_address(), 'cms_banners')) {
                $add_banner_url = build_url(array('page' => 'cms_banners', 'type' => 'ad'), get_module_zone('cms_banners'));
            } else {
                $add_banner_url = new ocp_tempcode();
            }
            $content = do_template('BANNERS_NONE', array('_GUID' => 'b786ec327365d1ef38134ce401db9dd2', 'ADD_BANNER_URL' => $add_banner_url));
            if ($ret) {
                return $content;
            }
            $echo = do_template('BASIC_HTML_WRAP', array('_GUID' => '00c8549b88dac8a1291450eb5b681d80', 'TARGET' => '_top', 'TITLE' => do_lang_tempcode('BANNER'), 'CONTENT' => $content));
            $echo->evaluate_echo();
            return NULL;
        }
        // Choose which banner to show from the results
        $rand = mt_rand(0, $tally);
        for ($i = 0; $i < $counter; $i++) {
            if ($rand <= $bound[$i]) {
                break;
            }
        }
        $name = $rows[$i]['name'];
        // Update the counts (ones done per-view)
        if (get_db_type() != 'xml') {
            $GLOBALS['SITE_DB']->query('UPDATE ' . get_table_prefix() . 'banners SET views_to=(views_to+1) WHERE ' . db_string_equal_to('name', $name), 1, NULL, false, true);
        }
        if ($source != '') {
            if (get_db_type() != 'xml') {
                $GLOBALS['SITE_DB']->query('UPDATE ' . get_table_prefix() . 'banners SET views_from=(views_from+1) WHERE ' . db_string_equal_to('name', $name), 1, NULL, false, true);
            }
        }
        // Display!
        $img = $rows[$i]['img_url'];
        $caption = get_translated_tempcode($rows[$i]['caption']);
        $content = show_banner($name, $rows[$i]['b_title_text'], $caption, $img, $source, $rows[$i]['site_url'], $rows[$i]['b_type']);
        if ($ret) {
            return $content;
        }
        $echo = do_template('BASIC_HTML_WRAP', array('_GUID' => 'd23424ded86c850f4ae0006241407ff9', 'TITLE' => do_lang_tempcode('BANNER'), 'CONTENT' => $content));
        $echo->evaluate_echo();
    }
    return NULL;
}
Beispiel #16
0
/**
 * Get a list of maps containing all the subcategories, and path information, of the specified category - and those beneath it, recursively.
 *
 * @param  ?AUTO_LINK	The category being at the root of our recursion (NULL: true root category)
 * @param  ?string		The tree up to this point in the recursion (NULL: blank, as we are starting the recursion)
 * @param  ?ID_TEXT		The category name of the $category_id we are currently going through (NULL: look it up). This is here for efficiency reasons, as finding children IDs to recurse to also reveals the childs title
 * @param  boolean		Whether to collect download counts with our tree information
 * @param  boolean		Whether to make a compound list (a pair of a comma-separated list of children, and the child array)
 * @param  ?integer		The number of recursive levels to search (NULL: all)
 * @param  boolean		Whether to only show for what may be added to by the current member
 * @return array			A list of maps for all subcategories. Each map entry containins the fields 'id' (category ID) and 'tree' (tree path to the category, including the categories own title). There is also an additional 'downloadcount' entry if stats were requested
 */
function get_download_category_tree($category_id = NULL, $tree = NULL, $title = NULL, $do_stats = true, $use_compound_list = false, $levels = NULL, $addable_filter = false)
{
    if (!$use_compound_list) {
        if ($levels == -1) {
            return array();
        }
    }
    //	if (!has_category_access(get_member(),'downloads',strval($category_id))) return array();
    if (is_null($category_id)) {
        $category_id = db_get_first_id();
    }
    if (is_null($tree)) {
        $tree = '';
    }
    // Put our title onto our tree
    if (is_null($title)) {
        $title = get_translated_text($GLOBALS['SITE_DB']->query_value('download_categories', 'category', array('id' => $category_id)));
    }
    $tree .= $title;
    // We'll be putting all children in this entire tree into a single list
    $children = array();
    $children[0] = array();
    $children[0]['id'] = $category_id;
    $children[0]['title'] = $title;
    $children[0]['tree'] = $tree;
    $children[0]['compound_list'] = strval($category_id) . ',';
    if ($addable_filter) {
        $children[0]['addable'] = has_submit_permission('mid', get_member(), get_ip_address(), 'cms_downloads', array('downloads', $category_id));
    }
    if ($do_stats) {
        $children[0]['filecount'] = $GLOBALS['SITE_DB']->query_value('download_downloads', 'COUNT(*)', array('category_id' => $category_id));
    }
    // Children of this category
    $rows = $GLOBALS['SITE_DB']->query_select('download_categories', array('id', 'category'), array('parent_id' => $category_id), '', 300);
    if (count($rows) == 300) {
        $rows = array();
    }
    $children[0]['child_count'] = count($rows);
    $tree .= ' > ';
    if ($levels !== 0 || $use_compound_list) {
        foreach ($rows as $child) {
            $child_id = $child['id'];
            $child_title = get_translated_text($child['category']);
            $child_tree = $tree;
            $child_children = get_download_category_tree($child_id, $child_tree, $child_title, $do_stats, $use_compound_list, is_null($levels) ? NULL : max(0, $levels - 1), $addable_filter);
            if ($use_compound_list) {
                list($child_children, $_compound_list) = $child_children;
                $children[0]['compound_list'] .= $_compound_list;
            }
            if ($levels !== 0) {
                $children = array_merge($children, $child_children);
            }
        }
    }
    return $use_compound_list ? array($children, $children[0]['compound_list']) : $children;
}
Beispiel #17
0
/**
 * Get a list of maps containing all the subcategories, and path information, of the specified category - and those beneath it, recursively.
 *
 * @param  ID_TEXT		The catalogue name
 * @param  ?AUTO_LINK	The category being at the root of our recursion (NULL: true root category)
 * @param  ?tempcode		The tree up to this point in the recursion (NULL: blank, as we are starting the recursion)
 * @param  ?string		The category name of the $category_id we are currently going through (NULL: look it up). This is here for efficiency reasons, as finding children IDs to recurse to also reveals the childs title
 * @param  ?integer		The number of recursive levels to search (NULL: all)
 * @param  boolean		Whether to only show for what may be added to by the current member
 * @param  boolean		Whether to make the list elements store comma-separated child lists instead of IDs
 * @return array			A list of maps for all subcategories. Each map entry containins the fields 'id' (category ID) and 'tree' (tree path to the category, including the categories own title), and 'count' (the number of entries in the category).
 */
function get_catalogue_category_tree($catalogue_name, $category_id, $tree = NULL, $title = NULL, $levels = NULL, $addable_filter = false, $use_compound_list = false)
{
    if (!$use_compound_list) {
        if ($levels == -1) {
            return array();
        }
    }
    if (!has_category_access(get_member(), 'catalogues_catalogue', $catalogue_name)) {
        return array();
    }
    if (!is_null($category_id) && get_value('disable_cat_cat_perms') !== '1' && !has_category_access(get_member(), 'catalogues_category', strval($category_id))) {
        return array();
    }
    if (is_null($tree)) {
        $tree = new ocp_tempcode();
    }
    // Put our title onto our tree
    if (is_null($title)) {
        if (is_null($category_id)) {
            $_title = $GLOBALS['SITE_DB']->query_value_null_ok('catalogue_categories', 'cc_title', array('id' => $category_id));
        } else {
            $_title = $GLOBALS['SITE_DB']->query_value('catalogue_categories', 'cc_title', array('id' => $category_id));
        }
        $title = is_null($_title) ? do_lang('HOME') : get_translated_text($_title);
    }
    $tree->attach($title);
    // We'll be putting all children in this entire tree into a single list
    $children = array();
    $is_tree = $GLOBALS['SITE_DB']->query_value_null_ok('catalogues', 'c_is_tree', array('c_name' => $catalogue_name));
    if (is_null($is_tree)) {
        warn_exit(do_lang_tempcode('_MISSING_RESOURCE', 'catalogue:' . escape_html($catalogue_name)));
    }
    if (!is_null($category_id)) {
        $children[0]['id'] = $category_id;
        $children[0]['title'] = $title;
        $children[0]['tree'] = $tree;
        $children[0]['compound_list'] = strval($category_id) . ',';
        $children[0]['count'] = $GLOBALS['SITE_DB']->query_value('catalogue_entries', 'COUNT(*)', array('cc_id' => $category_id));
        if ($addable_filter) {
            $children[0]['addable'] = has_submit_permission('mid', get_member(), get_ip_address(), 'cms_catalogues', array('catalogues_catalogue', $catalogue_name, 'catalogues_category', $category_id));
        }
    }
    // Children of this category
    $tree2 = new ocp_tempcode();
    $tree2->attach($tree);
    $tree2->attach(do_template('BREADCRUMB'));
    $rows = $GLOBALS['SITE_DB']->query_select('catalogue_categories', array('id', 'cc_title'), array('c_name' => $catalogue_name, 'cc_parent_id' => $category_id), 'ORDER BY id DESC', 300);
    foreach ($rows as $i => $child) {
        $rows[$i]['text_original'] = get_translated_text($child['cc_title']);
    }
    if (get_page_name() == 'cms_catalogues') {
        if (count($rows) == 300) {
            attach_message(do_lang_tempcode('TOO_MUCH_CHOOSE__RECENT_ONLY', escape_html(integer_format(300))), 'warn');
        }
    }
    global $M_SORT_KEY;
    $M_SORT_KEY = 'text_original';
    usort($rows, 'multi_sort');
    $no_root = !array_key_exists(0, $children);
    if (!$no_root) {
        $children[0]['child_count'] = count($rows);
    }
    if ($levels !== 0 || $use_compound_list) {
        foreach ($rows as $child) {
            $child_id = $child['id'];
            $child_title = $child['text_original'];
            $child_tree = new ocp_tempcode();
            $child_tree->attach($tree2);
            $child_children = get_catalogue_category_tree($catalogue_name, $child_id, $child_tree, $child_title, is_null($levels) ? NULL : $levels - 1, $addable_filter, $use_compound_list);
            if ($child_children != array()) {
                if ($use_compound_list) {
                    list($child_children, $_compound_list) = $child_children;
                    if (!$no_root) {
                        $children[0]['compound_list'] .= $_compound_list;
                    }
                }
                if ($levels !== 0) {
                    $children = array_merge($children, $child_children);
                }
            }
        }
    }
    return $use_compound_list ? array($children, $no_root ? '' : $children[0]['compound_list']) : $children;
}
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     require_code('downloads');
     require_css('downloads');
     require_lang('downloads');
     $category_id = array_key_exists('param', $map) ? intval($map['param']) : db_get_first_id();
     $title = array_key_exists('title', $map) ? $map['title'] : do_lang('SECTION_DOWNLOADS');
     $order = array_key_exists('order', $map) ? $map['order'] : NULL;
     $cat_order = array_key_exists('cat_order', $map) ? $map['cat_order'] : NULL;
     if (!is_null($order) && strpos($order, ' ') === false) {
         $order .= ' ASC';
     }
     if (!is_null($cat_order) && strpos($cat_order, ' ') === false) {
         $cat_order .= ' ASC';
     }
     if (!is_null($order)) {
         if ($order != 't.text_original ASC' && $order != 't.text_original DESC' && $order != 't.text_original ASC' && $order != 't.text_original DESC' && $order != 'file_size ASC' && $order != 'file_size DESC' && $order != 'num_downloads DESC' && $order != 'add_date ASC' && $order != 'add_date DESC') {
             $order = NULL;
         }
     }
     if (!is_null($cat_order)) {
         if ($cat_order != 't.text_original ASC' && $cat_order != 't.text_original DESC' && $cat_order != 'add_date ASC' && $order != 'add_date DESC') {
             $cat_order = NULL;
         }
     }
     $subcategories = get_download_sub_categories($category_id, NULL, NULL, $cat_order);
     $downloads = get_category_downloads($category_id, $category_id, $order);
     if ($subcategories->is_empty() && $downloads->is_empty()) {
         if (has_actual_page_access(NULL, 'cms_downloads', NULL, NULL) && has_submit_permission('mid', get_member(), get_ip_address(), 'cms_downloads')) {
             $submit_url = build_url(array('page' => 'cms_downloads', 'type' => 'ad', 'cat' => $category_id, 'redirect' => SELF_REDIRECT), get_module_zone('cms_downloads'));
         } else {
             $submit_url = new ocp_tempcode();
         }
         return do_template('BLOCK_NO_ENTRIES', array('_GUID' => '1e7be43cf5074821854d64458202b09d', 'HIGH' => false, 'TITLE' => $title, 'MESSAGE' => do_lang_tempcode('NO_ENTRIES'), 'ADD_NAME' => do_lang_tempcode('ADD_DOWNLOAD'), 'SUBMIT_URL' => $submit_url));
     }
     $submit_url = new ocp_tempcode();
     if (has_actual_page_access(NULL, 'cms_downloads', NULL, NULL) && has_submit_permission('high', get_member(), get_ip_address(), 'cms_downloads')) {
         $submit_url = build_url(array('page' => 'cms_downloads', 'type' => 'ad', 'cat' => $category_id, 'redirect' => SELF_REDIRECT), get_module_zone('cms_downloads'));
     }
     return do_template('BLOCK_MAIN_DOWNLOAD_CATEGORY', array('_GUID' => '518c63ef968e3b452d3b5cfa2e9505ec', 'SUBMIT_URL' => $submit_url, 'SUBCATEGORIES' => $subcategories, 'DOWNLOADS' => $downloads, 'TITLE' => $title));
 }
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     require_css('galleries');
     require_lang('galleries');
     require_code('galleries');
     require_code('images');
     require_code('feedback');
     require_code('ocfiltering');
     $cat = array_key_exists('param', $map) ? $map['param'] : 'root';
     $cat_select = ocfilter_to_sqlfragment($cat, 'cat', 'galleries', 'parent_id', 'cat', 'name', false, false);
     $title = array_key_exists('title', $map) ? $map['title'] : '';
     /*if ((file_exists(get_custom_file_base().'/themes/default/templates_custom/JAVASCRIPT_GALLERIES.tpl')) || (file_exists(get_file_base().'/themes/default/templates/JAVASCRIPT_GALLERIES.tpl')))
     		require_javascript('javascript_galleries');*/
     $max = get_param_integer('mge_max', array_key_exists('max', $map) ? intval($map['max']) : 30);
     $start = get_param_integer('mge_start', 0);
     if (!array_key_exists('select', $map)) {
         $map['select'] = '*';
     }
     $image_select = ocfilter_to_sqlfragment($map['select'], 'id');
     if (!array_key_exists('video_select', $map)) {
         $map['video_select'] = '*';
     }
     $video_select = ocfilter_to_sqlfragment($map['video_select'], 'id');
     $zone = array_key_exists('zone', $map) ? $map['zone'] : get_module_zone('galleries');
     $_days = array_key_exists('days', $map) ? $map['days'] : '';
     $days = mixed();
     $days = $_days == '' ? NULL : intval($_days);
     $where_sup = '';
     if (!is_null($days)) {
         $where_sup .= ' AND add_date>=' . strval(time() - $days * 60 * 60 * 24);
     }
     $sort = array_key_exists('sort', $map) ? $map['sort'] : 'add_date DESC';
     if ($sort != 'random ASC' && $sort != 'fixed_random ASC' && $sort != 'compound_rating DESC' && $sort != 'compound_rating ASC' && $sort != 'add_date DESC' && $sort != 'add_date ASC' && $sort != 'url DESC' && $sort != 'url ASC') {
         $sort = 'add_date DESC';
     }
     list($_sort, $_dir) = explode(' ', $sort, 2);
     $total_images = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . get_table_prefix() . 'images WHERE ' . $cat_select . ' AND ' . $image_select . $where_sup);
     $total_videos = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . get_table_prefix() . 'videos WHERE ' . $cat_select . ' AND ' . $video_select . $where_sup);
     if ($_sort == 'random') {
         $start = 0;
         $max = min($total_images + $total_videos, $max);
         $done_images = '1=1';
         $done_videos = '1=1';
         $rows_images = array();
         $rows_videos = array();
         for ($i = 0; $i < $max; $i++) {
             if (mt_rand(0, 1) == 0 || $total_videos - count($rows_videos) == 0) {
                 $rows = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'images e WHERE ' . $cat_select . ' AND ' . $image_select . $where_sup . ' AND ' . $done_images, 1, mt_rand(0, $total_images - count($rows_images) - 1));
                 $rows_images[] = $rows[0];
                 $done_images .= ' AND ';
                 $done_images .= 'id<>' . strval($rows[0]['id']);
             } else {
                 $rows = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'videos e WHERE ' . $cat_select . ' AND ' . $video_select . $where_sup . ' AND ' . $done_videos, 1, mt_rand(0, $total_videos - count($rows_videos) - 1));
                 $rows_videos[] = $rows[0];
                 $done_videos .= ' AND ';
                 $done_videos .= 'id<>' . strval($rows[0]['id']);
             }
         }
     } else {
         if ($_sort == 'compound_rating') {
             $rating_sort = ',(SELECT AVG(rating) FROM ' . get_table_prefix() . 'rating WHERE ' . db_string_equal_to('rating_for_type', 'images') . ' AND rating_for_id=e.id) AS compound_rating';
         } elseif ($_sort == 'fixed_random') {
             $rating_sort = ',(MOD(id,3.142)) AS fixed_random';
         } else {
             $rating_sort = '';
         }
         $rows_images = $GLOBALS['SITE_DB']->query('SELECT *' . $rating_sort . ' FROM ' . get_table_prefix() . 'images e WHERE ' . $cat_select . ' AND ' . $image_select . $where_sup . ' ORDER BY ' . $sort, $max + $start);
         if ($_sort == 'compound_rating') {
             $rating_sort = ',(SELECT AVG(rating) FROM ' . get_table_prefix() . 'rating WHERE ' . db_string_equal_to('rating_for_type', 'videos') . ' AND rating_for_id=e.id) AS compound_rating';
         } elseif ($_sort == 'fixed_random') {
             $rating_sort = ',(MOD(id,3.142)) AS fixed_random';
         } else {
             $rating_sort = '';
         }
         $rows_videos = $GLOBALS['SITE_DB']->query('SELECT *' . $rating_sort . ' FROM ' . get_table_prefix() . 'videos e WHERE ' . $cat_select . ' AND ' . $video_select . $where_sup . ' ORDER BY ' . $sort, $max + $start);
     }
     // Sort
     $combined = array();
     foreach ($rows_images as $row_image) {
         $combined[] = array($row_image, 'image', $_sort == 'random' ? NULL : $row_image[$_sort]);
     }
     foreach ($rows_videos as $row_video) {
         $combined[] = array($row_video, 'video', $_sort == 'random' ? NULL : $row_video[$_sort]);
     }
     if ($_sort == 'random') {
         shuffle($combined);
     } else {
         global $M_SORT_KEY;
         $M_SORT_KEY = 2;
         usort($combined, 'multi_sort');
         if ($_dir == 'DESC') {
             $combined = array_reverse($combined);
         }
     }
     // Display
     $entries = new ocp_tempcode();
     foreach ($combined as $i => $c) {
         if ($i >= $start) {
             switch ($c[1]) {
                 case 'image':
                     // Display image
                     $row_image = $c[0];
                     $view_url = build_url(array('page' => 'galleries', 'type' => 'image', 'wide' => 1, 'id' => $row_image['id']), $zone);
                     $thumb_url = ensure_thumbnail($row_image['url'], $row_image['thumb_url'], 'galleries', 'images', $row_image['id']);
                     $thumb = do_image_thumb($thumb_url, '', true);
                     $full_url = $row_image['url'];
                     $file_size = url_is_local($full_url) ? file_exists(get_custom_file_base() . '/' . rawurldecode($full_url)) ? strval(filesize(get_custom_file_base() . '/' . rawurldecode($full_url))) : '' : '';
                     if (url_is_local($full_url)) {
                         $full_url = get_custom_base_url() . '/' . $full_url;
                     }
                     $thumb_url = $row_image['thumb_url'];
                     if (url_is_local($thumb_url)) {
                         $thumb_url = get_custom_base_url() . '/' . $thumb_url;
                     }
                     $entry_rating_details = $row_image['allow_rating'] == 1 ? display_rating($view_url, get_translated_text($row_image['title']), 'images', strval($row_image['id']), 'RATING_INLINE_STATIC', $row_image['submitter']) : NULL;
                     $entry_map = array('_GUID' => '043ac7d15ce02715ac02309f6e8340ff', 'RATING_DETAILS' => $entry_rating_details, 'TITLE' => get_translated_text($row_image['title']), 'DESCRIPTION' => get_translated_tempcode($row_image['comments']), 'ID' => strval($row_image['id']), 'FILE_SIZE' => $file_size, 'SUBMITTER' => strval($row_image['submitter']), 'FULL_URL' => $full_url, 'THUMB_URL' => $thumb_url, 'CAT' => $cat, 'THUMB' => $thumb, 'VIEW_URL' => $view_url, 'VIEWS' => strval($row_image['image_views']), 'ADD_DATE_RAW' => strval($row_image['add_date']), 'EDIT_DATE_RAW' => is_null($row_image['edit_date']) ? '' : strval($row_image['edit_date']));
                     $entry = do_template('GALLERY_IMAGE', $entry_map);
                     $entries->attach(do_template('GALLERY_ENTRY_WRAP', array('_GUID' => '13134830e1ebea158ab44885eeec0953', 'ENTRY' => $entry) + $entry_map));
                     break;
                 case 'video':
                     // Display video
                     $row_video = $c[0];
                     $view_url = build_url(array('page' => 'galleries', 'type' => 'video', 'wide' => 1, 'id' => $row_video['id']), $zone);
                     $thumb_url = $row_video['thumb_url'];
                     if ($thumb_url != '' && url_is_local($thumb_url)) {
                         $thumb_url = get_custom_base_url() . '/' . $thumb_url;
                     }
                     if ($thumb_url == '') {
                         $thumb_url = find_theme_image('na');
                     }
                     $thumb = do_image_thumb($thumb_url, '', true);
                     $full_url = $row_video['url'];
                     if (url_is_local($full_url)) {
                         $full_url = get_custom_base_url() . '/' . $full_url;
                     }
                     $thumb_url = $row_video['thumb_url'];
                     if ($thumb_url != '' && url_is_local($thumb_url)) {
                         $thumb_url = get_custom_base_url() . '/' . $thumb_url;
                     }
                     $entry_rating_details = $row_video['allow_rating'] == 1 ? display_rating($view_url, get_translated_text($row_video['title']), 'videos', strval($row_video['id']), 'RATING_INLINE_STATIC', $row_video['submitter']) : NULL;
                     $entry_map = array('_GUID' => '66b7fb4d3b61ef79d6803c170d102cbf', 'RATING_DETAILS' => $entry_rating_details, 'TITLE' => get_translated_text($row_video['title']), 'DESCRIPTION' => get_translated_tempcode($row_video['comments']), 'ID' => strval($row_video['id']), 'CAT' => $cat, 'THUMB' => $thumb, 'VIEW_URL' => $view_url, 'SUBMITTER' => strval($row_video['submitter']), 'FULL_URL' => $full_url, 'THUMB_URL' => $thumb_url, 'VIDEO_DETAILS' => show_video_details($row_video), 'VIEWS' => strval($row_video['video_views']), 'ADD_DATE_RAW' => strval($row_video['add_date']), 'EDIT_DATE_RAW' => is_null($row_video['edit_date']) ? '' : strval($row_video['edit_date']));
                     $entry = do_template('GALLERY_VIDEO', $entry_map);
                     $entries->attach(do_template('GALLERY_ENTRY_WRAP', array('_GUID' => 'a0ff010ae7fd1f7b3341993072ed23cf', 'ENTRY' => $entry) + $entry_map));
                     break;
             }
         }
         $i++;
         if ($i == $start + $max) {
             break;
         }
     }
     if (!isset($map['render_if_empty']) || $map['render_if_empty'] != '1') {
         if ($entries->is_empty()) {
             if (has_actual_page_access(NULL, 'cms_galleries', NULL, NULL) && has_submit_permission('mid', get_member(), get_ip_address(), 'cms_galleries', array('galleries', $cat))) {
                 $submit_url = build_url(array('page' => 'cms_galleries', 'type' => 'ad', 'cat' => $cat, 'redirect' => SELF_REDIRECT), get_module_zone('cms_galleries'));
             } else {
                 $submit_url = new ocp_tempcode();
             }
             return do_template('BLOCK_NO_ENTRIES', array('_GUID' => 'bf84d65b8dd134ba6cd7b1b7bde99de2', 'HIGH' => false, 'TITLE' => do_lang_tempcode('GALLERY'), 'MESSAGE' => do_lang_tempcode('NO_ENTRIES'), 'ADD_NAME' => do_lang_tempcode('ADD_IMAGE'), 'SUBMIT_URL' => $submit_url));
         }
     }
     // Results browser
     require_code('templates_results_browser');
     $_selectors = array_map('intval', explode(',', get_option('gallery_selectors')));
     $root = get_param('root', 'root');
     $results_browser = results_browser(do_lang('ENTRY'), $cat, $start, 'mge_start', $max, 'mge_max', $total_videos + $total_images, $root, 'misc', true, false, 10, $_selectors);
     $tpl = do_template('BLOCK_MAIN_GALLERY_EMBED', array('_GUID' => 'b7b969c8fe8c398dd6e3af7ee06717ea', 'IMAGE_SELECT' => $map['select'], 'VIDEO_SELECT' => $map['video_select'], 'DAYS' => $_days, 'SORT' => $sort, 'BLOCK_PARAMS' => block_params_arr_to_str($map), 'RESULTS_BROWSER' => $results_browser, 'TITLE' => $title, 'CAT' => $cat, 'IMAGES' => $entries, 'MAX' => strval($max), 'ZONE' => $zone, 'TOTAL_VIDEOS' => strval($total_videos), 'TOTAL_IMAGES' => strval($total_images), 'TOTAL' => strval($total_videos + $total_images)));
     return $tpl;
 }
Beispiel #20
0
/**
 * Check to see if a member's has permission to submit an item. If it doesn't, an error message is outputted.
 *
 * @param  string			The range of permission we are checking to see if they have; these ranges are like trust levels
 * @set	 low mid high cat_low cat_mid cat_high
 * @param  ?array			A list of cat details to require access to (c-type-1,c-id-1,c-type-2,c-d-2,...) (NULL: N/A)
 * @param  ?ID_TEXT		The ID code for the page being checked (NULL: current page)
 */
function check_submit_permission($range, $cats = NULL, $page = NULL)
{
    if (is_null($page)) {
        $page = get_page_name();
    }
    if (!has_submit_permission($range, get_member(), get_ip_address(), $page, $cats)) {
        access_denied('SPECIFIC_PERMISSION', 'submit_' . $range . 'range_content');
    }
}
Beispiel #21
0
/**
 * Get a nice formatted XHTML list of news categories.
 *
 * @param  ?mixed			The selected news category. Array or AUTO_LINK (NULL: personal)
 * @param  boolean		Whether to add all personal categories into the list (for things like the adminzone, where all categories must be shown, regardless of permissions)
 * @param  boolean		Whether to only show for what may be added to by the current member
 * @param  boolean		Whether to limit to only existing cats (otherwise we dynamically add unstarted blogs)
 * @param  ?boolean		Whether to limit to only show blog categories (NULL: don't care, true: blogs only, false: no blogs)
 * @param  boolean		Whether to prefer to choose a non-blog category as the default
 * @return tempcode		The tempcode for the news category select list
 */
function nice_get_news_categories($it = NULL, $show_all_personal_categories = false, $addable_filter = false, $only_existing = false, $only_blogs = NULL, $prefer_not_blog_selected = false)
{
    if (!is_array($it)) {
        $it = array($it);
    }
    if ($only_blogs === true) {
        $where = 'WHERE nc_owner IS NOT NULL';
    } elseif ($only_blogs === false) {
        $where = 'WHERE nc_owner IS NULL';
    } else {
        $where = 'WHERE 1=1';
    }
    $count = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . get_table_prefix() . 'news_categories ' . $where . ' ORDER BY id');
    if ($count > 500) {
        $where .= ' AND (nc_owner IS NULL OR nc_owner=' . strval(get_member()) . ')';
    }
    $_cats = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'news_categories ' . $where . ' ORDER BY id');
    foreach ($_cats as $i => $cat) {
        $_cats[$i]['nice_title'] = get_translated_text($cat['nc_title']);
    }
    global $M_SORT_KEY;
    $M_SORT_KEY = 'nice_title';
    usort($_cats, 'multi_sort');
    $categories = new ocp_tempcode();
    $add_cat = true;
    foreach ($_cats as $cat) {
        if ($cat['nc_owner'] == get_member()) {
            $add_cat = false;
        }
        if (!has_category_access(get_member(), 'news', strval($cat['id']))) {
            continue;
        }
        if ($addable_filter && !has_submit_permission('high', get_member(), get_ip_address(), 'cms_news', array('news', $cat['id']))) {
            continue;
        }
        if (is_null($cat['nc_owner'])) {
            $li = form_input_list_entry(strval($cat['id']), $it != array(NULL) && in_array($cat['id'], $it), $cat['nice_title'] . ' (#' . strval($cat['id']) . ')');
            $categories->attach($li);
        } else {
            if (!is_null($cat['nc_owner']) && has_specific_permission(get_member(), 'can_submit_to_others_categories') || $cat['nc_owner'] == get_member() && !is_guest() || $show_all_personal_categories) {
                $categories->attach(form_input_list_entry(strval($cat['id']), $cat['nc_owner'] == get_member() && (!$prefer_not_blog_selected && in_array(NULL, $it)) || in_array($cat['id'], $it), $cat['nice_title'] . ' (#' . strval($cat['id']) . ')'));
            }
        }
    }
    if (!$only_existing && has_specific_permission(get_member(), 'have_personal_category', 'cms_news') && $add_cat && !is_guest()) {
        $categories->attach(form_input_list_entry('personal', !$prefer_not_blog_selected && in_array(NULL, $it), do_lang_tempcode('MEMBER_CATEGORY', do_lang_tempcode('_NEW', escape_html($GLOBALS['FORUM_DRIVER']->get_username(get_member()))))));
    }
    return $categories;
}
Beispiel #22
0
/**
 * Show an actual poll block.
 *
 * @param  boolean			Whether to show results (if we've already voted, this'll be overrided)
 * @param  array				The poll row
 * @param  ID_TEXT			The zone our poll module is in
 * @return tempcode			The block
 */
function show_poll($results, $myrow, $zone)
{
    $ip = get_ip_address();
    if (!may_vote_in_poll($myrow)) {
        $results = true;
    }
    // Count our total votes
    $num_options = $myrow['num_options'];
    $totalvotes = 0;
    for ($i = 1; $i <= $num_options; $i++) {
        if (!array_key_exists('votes' . strval($i), $myrow)) {
            $myrow['votes' . strval($i)] = 0;
        }
        $totalvotes += $myrow['votes' . strval($i)];
    }
    // Sort by results
    $orderings = array();
    for ($i = 1; $i <= $num_options; $i++) {
        $orderings[$i] = $myrow['votes' . strval($i)];
    }
    if ($results) {
        asort($orderings);
    }
    if (running_script('poll')) {
        $keep = symbol_tempcode('KEEP');
        $vote_url = find_script('poll') . '?poll_id=' . strval($myrow['id']) . '&show_poll_results_' . strval($myrow['id']) . '=1&param=' . urlencode(strval($myrow['id'])) . '&zone=' . urlencode(get_param('zone', get_module_zone('polls'))) . $keep->evaluate();
        if (get_param_integer('in_panel', 0) == 1) {
            $vote_url .= '&in_panel=1';
        }
        if (get_param_integer('interlock', 0) == 1) {
            $vote_url .= '&interlock=1';
        }
        $result_url = $results ? '' : $vote_url;
    } else {
        $poll_results = 'show_poll_results_' . strval($myrow['id']);
        $vote_url = get_self_url(false, true, array('poll_id' => $myrow['id'], $poll_results => 1, 'utheme' => NULL));
        $result_url = $results ? '' : get_self_url(false, true, array($poll_results => 1, 'utheme' => NULL));
    }
    if (get_param('utheme', '') != '') {
        if (is_object($result_url)) {
            if (!$result_url->is_empty()) {
                $result_url->attach('&utheme=' . get_param('utheme'));
            }
        } else {
            if ($result_url != '') {
                $result_url .= '&utheme=' . get_param('utheme');
            }
        }
        if (is_object($vote_url)) {
            if (!$vote_url->is_empty()) {
                $vote_url->attach('&utheme=' . get_param('utheme'));
            }
        } else {
            if ($vote_url != '') {
                $vote_url .= '&utheme=' . get_param('utheme');
            }
        }
    }
    // Our questions templated
    $tpl = new ocp_tempcode();
    for ($i = 1; $i <= $num_options; $i++) {
        $answer = get_translated_tempcode($myrow['option' . strval($i)]);
        $answer_plain = get_translated_text($myrow['option' . strval($i)]);
        if (!$results) {
            $tpl->attach(do_template('POLL_ANSWER', array('_GUID' => 'bc9c2e818f2e7031075d8d7b01d79cd5', 'PID' => strval($myrow['id']), 'I' => strval($i), 'CAST' => strval($i), 'VOTE_URL' => $vote_url, 'ANSWER' => $answer, 'ANSWER_PLAIN' => $answer_plain)));
        } else {
            $votes = $myrow['votes' . strval($i)];
            if (!is_numeric($votes)) {
                $votes = 0;
            }
            if ($totalvotes != 0) {
                $width = intval(round(70.0 * floatval($votes) / floatval($totalvotes)));
            } else {
                $width = 0;
            }
            $tpl->attach(do_template('POLL_ANSWER_RESULT', array('_GUID' => '887ea0ed090c48305eb84500865e5178', 'PID' => strval($myrow['id']), 'I' => strval($i), 'VOTE_URL' => $vote_url, 'ANSWER' => $answer, 'ANSWER_PLAIN' => $answer_plain, 'WIDTH' => strval($width), 'VOTES' => integer_format($votes))));
        }
    }
    if (has_actual_page_access(NULL, 'cms_polls', NULL, NULL) && has_submit_permission('mid', get_member(), get_ip_address(), 'cms_polls')) {
        $submit_url = build_url(array('page' => 'cms_polls', 'type' => 'ad', 'redirect' => running_script('index') ? get_self_url(true, true, array()) : NULL), get_module_zone('cms_polls'));
    } else {
        $submit_url = new ocp_tempcode();
    }
    // Do our final template
    $question = get_translated_tempcode($myrow['question']);
    $question_plain = get_translated_text($myrow['question']);
    $archive_url = build_url(array('page' => 'polls', 'type' => 'misc'), $zone);
    $full_url = new ocp_tempcode();
    if (get_page_name() != 'polls' || get_param('type', '') != 'view') {
        $full_url = build_url(array('page' => 'polls', 'type' => 'view', 'id' => $myrow['id']), $zone);
    }
    $map2 = array('_GUID' => '4c6b026f7ed96f0b5b8408eb5e5affb5', 'VOTE_URL' => $vote_url, 'SUBMITTER' => strval($myrow['submitter']), 'PID' => strval($myrow['id']), 'FULL_URL' => $full_url, 'CONTENT' => $tpl, 'QUESTION' => $question, 'QUESTION_PLAIN' => $question_plain, 'SUBMIT_URL' => $submit_url, 'ARCHIVE_URL' => $archive_url, 'RESULT_URL' => $result_url, 'ZONE' => $zone);
    if (get_option('is_on_comments') == '1' && !has_no_forum() && $myrow['allow_comments'] >= 1) {
        $map2['COMMENT_COUNT'] = '1';
    }
    return do_template('POLL', $map2);
}
Beispiel #23
0
/**
 * Gets a gallery selection tree list, extending deeper from the given category_id, showing all sub(sub...)galleries.
 *
 * @param  ?ID_TEXT		The gallery we are getting the tree starting from (NULL: root)
 * @param  string			The parent tree at this point of the recursion
 * @param  ?array			The database row for the $category_id gallery (NULL: get it from the DB)
 * @param  boolean		Whether to include video/image statistics in the returned tree
 * @param  ?string		A function name to filter galleries with (NULL: no filter)
 * @param  boolean		Whether displayed galleries must support images
 * @param  boolean		Whether displayed galleries must support videos
 * @param  boolean		Whether to NOT show member galleries that do not exist yet
 * @param  boolean		Whether to get a list of child galleries (not just direct ones, recursively), instead of just IDs
 * @param  ?integer		The number of recursive levels to search (NULL: all)
 * @param  ?MEMBER		Member we are filtering for (NULL: not needed)
 * @param  boolean		Whether to only show for what may be added to by the current member
 * @return array			The tree structure, or if $use_compound_list, the tree structure built with pairs containing the compound list in addition to the child branches
 */
function get_gallery_tree($category_id = 'root', $tree = '', $gallery_info = NULL, $do_stats = true, $filter = NULL, $must_accept_images = false, $must_accept_videos = false, $purity = false, $use_compound_list = false, $levels = NULL, $member_id = NULL, $addable_filter = false)
{
    if ($levels == -1) {
        return $use_compound_list ? array(array(), '') : array();
    }
    if (is_null($category_id)) {
        $category_id = 'root';
    }
    if (!has_category_access(get_member(), 'galleries', $category_id)) {
        return $use_compound_list ? array(array(), '') : array();
    }
    // Put our title onto our tree
    if (is_null($gallery_info)) {
        $_gallery_info = $GLOBALS['SITE_DB']->query_select('galleries', array('fullname', 'is_member_synched', 'accept_images', 'accept_videos'), array('name' => $category_id), '', 1);
        if (!array_key_exists(0, $_gallery_info)) {
            warn_exit(do_lang_tempcode('_MISSING_RESOURCE', escape_html('gallery:' . $category_id)));
        }
        $gallery_info = $_gallery_info[0];
    }
    $title = array_key_exists('text_original', $gallery_info) ? $gallery_info['text_original'] : get_translated_text($gallery_info['fullname']);
    $is_member_synched = $gallery_info['is_member_synched'] == 1;
    $accept_images = $gallery_info['accept_images'] == 1;
    $accept_videos = $gallery_info['accept_videos'] == 1;
    $tree .= $title;
    $children = array();
    $sub = false;
    $query = 'FROM ' . get_table_prefix() . 'galleries g LEFT JOIN ' . get_table_prefix() . 'translate t ON ' . db_string_equal_to('language', user_lang()) . ' AND g.fullname=t.id WHERE ' . db_string_equal_to('parent_id', $category_id);
    if (current(current($GLOBALS['SITE_DB']->query('SELECT COUNT(*) ' . $query))) >= 300) {
        $rows = $GLOBALS['SITE_DB']->query('SELECT text_original,name,fullname,accept_images,accept_videos,is_member_synched,g.fullname ' . $query . ' ORDER BY add_date', 300);
    } else {
        $rows = $GLOBALS['SITE_DB']->query('SELECT text_original,name,fullname,accept_images,accept_videos,is_member_synched,g.fullname ' . $query . ' ORDER BY text_original ASC');
    }
    if ((is_null($filter) || call_user_func_array($filter, array($category_id, $member_id, count($rows)))) && (!$must_accept_images || $accept_images && !$is_member_synched) && (!$must_accept_videos || $accept_videos && !$is_member_synched)) {
        // We'll be putting all children in this entire tree into a single list
        $children[0]['id'] = $category_id;
        $children[0]['tree'] = $tree;
        $children[0]['title'] = $title;
        $children[0]['accept_images'] = $gallery_info['accept_images'];
        $children[0]['accept_videos'] = $gallery_info['accept_videos'];
        $children[0]['is_member_synched'] = $gallery_info['is_member_synched'];
        if ($addable_filter) {
            $children[0]['addable'] = has_submit_permission('mid', get_member(), get_ip_address(), 'cms_galleries', array('galleries', $category_id));
        }
        if ($do_stats) {
            $good_row_count = 0;
            foreach ($rows as $row) {
                if ((is_null($filter) || call_user_func_array($filter, array($row['name'], $member_id, 1))) && (!$must_accept_images || $row['accept_images'] && $row['is_member_synched'] == 0) && (!$must_accept_videos || $row['accept_videos'] && $row['is_member_synched'] == 0)) {
                    $good_row_count++;
                }
            }
            $children[0]['child_count'] = $good_row_count;
            if ($good_row_count == 0 && !$purity && $gallery_info['is_member_synched']) {
                $children[0]['child_count'] = 1;
            }
            // XHTMLXHTML
            $children[0]['video_count'] = $GLOBALS['SITE_DB']->query_value('videos', 'COUNT(*)', array('cat' => $category_id));
            $children[0]['image_count'] = $GLOBALS['SITE_DB']->query_value('images', 'COUNT(*)', array('cat' => $category_id));
        }
        $sub = true;
    }
    $can_submit = mixed();
    // Children of this category
    $tree .= ' > ';
    $found_own_gallery = false;
    $found_member_galleries = array($GLOBALS['FORUM_DRIVER']->get_guest_id() => 1);
    $compound_list = $category_id . ',';
    foreach ($rows as $child) {
        if ($child['name'] == 'root') {
            continue;
        }
        $can_submit = can_submit_to_gallery($child['name']);
        if ($can_submit === false) {
            $can_submit = !$addable_filter;
        }
        if ($can_submit !== false && $can_submit !== true) {
            $found_own_gallery = true;
            $found_member_galleries[$can_submit] = 1;
        }
        if ($can_submit !== false && ($levels !== 0 || $use_compound_list)) {
            $child_id = $child['name'];
            //			$child_title=$child['text_original'];
            $child_tree = $tree;
            $child_children = get_gallery_tree($child_id, $child_tree, $child, $do_stats, $filter, $must_accept_images, $must_accept_videos, $purity, $use_compound_list, is_null($levels) ? NULL : $levels - 1, $member_id, $addable_filter);
            if ($use_compound_list) {
                list($child_children, $_compound_list) = $child_children;
                $compound_list .= $_compound_list;
            }
            if ($levels !== 0) {
                $children = array_merge($children, $child_children);
            }
        }
    }
    if ($sub && array_key_exists(0, $children)) {
        $children[0]['compound_list'] = $compound_list;
    }
    $done_for_all = false;
    if ($is_member_synched && !$purity && $levels !== 0) {
        if (has_specific_permission(get_member(), 'can_submit_to_others_categories') && get_forum_type() == 'ocf') {
            ocf_require_all_forum_stuff();
            $members = $GLOBALS['FORUM_DB']->query_select('f_members', array('id', 'm_username', 'm_primary_group'), NULL, 'ORDER BY m_username', 100);
            if (count($members) != 100) {
                $done_for_all = true;
                $group_membership = $GLOBALS['FORUM_DB']->query_select('f_group_members', array('gm_group_id', 'gm_member_id'), array('gm_validated' => 1));
                $group_permissions = $GLOBALS['SITE_DB']->query('SELECT group_id,the_page,the_value FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'gsp WHERE ' . db_string_equal_to('specific_permission', 'have_personal_category') . ' AND (' . db_string_equal_to('the_page', '') . ' OR ' . db_string_equal_to('the_page', 'cms_galleries') . ')');
                $is_super_admin = $GLOBALS['FORUM_DRIVER']->is_super_admin(get_member());
                foreach ($members as $_member) {
                    $member = $_member['id'];
                    $username = $_member['m_username'];
                    $this_category_id = 'member_' . strval($member) . '_' . $category_id;
                    if ($member == get_member()) {
                        $has_permission = true;
                    } else {
                        $a = in_array(array('group_id' => $member['m_primary_group'], 'the_page' => '', 'the_value' => 1), $group_permissions);
                        $b = in_array(array('group_id' => $member['m_primary_group'], 'the_page' => 'cms_galleries', 'the_value' => 0), $group_permissions);
                        $c = in_array(array('group_id' => $member['m_primary_group'], 'the_page' => 'cms_galleries', 'the_value' => 1), $group_permissions);
                        $has_permission = $is_super_admin;
                        if ($a && !$b || $c) {
                            $has_permission = true;
                        }
                        if (!$has_permission) {
                            foreach ($group_membership as $_g) {
                                if ($_g['gm_member_id'] == $member) {
                                    $a = in_array(array('group_id' => $_g['gm_group_id'], 'the_page' => '', 'the_value' => 1), $group_permissions);
                                    $b = in_array(array('group_id' => $_g['gm_group_id'], 'the_page' => 'cms_galleries', 'the_value' => 0), $group_permissions);
                                    $c = in_array(array('group_id' => $_g['gm_group_id'], 'the_page' => 'cms_galleries', 'the_value' => 1), $group_permissions);
                                    if ($a && !$b || $c) {
                                        $has_permission = true;
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    if ($has_permission && !array_key_exists($member, $found_member_galleries) && (is_null($filter) || call_user_func_array($filter, array($this_category_id, $member_id, 0)))) {
                        $own_gallery = array();
                        $own_gallery['id'] = $this_category_id;
                        $this_title = do_lang('NEW_PERSONAL_GALLERY_OF', $username, $title);
                        $own_gallery['tree'] = $tree . $this_title;
                        $own_gallery['video_count'] = 0;
                        $own_gallery['image_count'] = 0;
                        $own_gallery['child_count'] = 0;
                        $own_gallery['title'] = $this_title;
                        $own_gallery['accept_images'] = $gallery_info['accept_images'];
                        $own_gallery['accept_videos'] = $gallery_info['accept_videos'];
                        $own_gallery['is_member_synched'] = 0;
                        $own_gallery['compound_list'] = $compound_list;
                        $own_gallery['addable'] = true;
                        $children[] = $own_gallery;
                        if ($member == get_member()) {
                            $found_own_gallery = true;
                        }
                    }
                }
            }
        }
        if ((!$done_for_all || !$found_own_gallery) && !array_key_exists(get_member(), $found_member_galleries) && !is_guest() && !$purity && has_specific_permission(get_member(), 'have_personal_category')) {
            $this_category_id = 'member_' . strval(get_member()) . '_' . $category_id;
            if (is_null($filter) || call_user_func_array($filter, array($this_category_id, $member_id, 0))) {
                $own_gallery = array();
                $own_gallery['id'] = $this_category_id;
                $this_title = do_lang('NEW_PERSONAL_GALLERY_OF', $GLOBALS['FORUM_DRIVER']->get_username(get_member()), $title);
                $own_gallery['tree'] = $tree . $this_title;
                $own_gallery['video_count'] = 0;
                $own_gallery['image_count'] = 0;
                $own_gallery['child_count'] = 0;
                $own_gallery['title'] = $this_title;
                $own_gallery['accept_images'] = $gallery_info['accept_images'];
                $own_gallery['accept_videos'] = $gallery_info['accept_videos'];
                $own_gallery['is_member_synched'] = 0;
                $own_gallery['addable'] = true;
                $own_gallery['compound_list'] = $compound_list;
                $children[] = $own_gallery;
            }
        }
    }
    return $use_compound_list ? array($children, $compound_list) : $children;
}
Beispiel #24
0
/**
 * Get a list of event types, taking security into account against the current member.
 *
 * @param  ?AUTO_LINK		The event type to select by default (NULL: none)
 * @return tempcode			The list
 */
function nice_get_event_types($it = NULL)
{
    $type_list = new ocp_tempcode();
    $types = $GLOBALS['SITE_DB']->query_select('calendar_types', array('id', 't_title'));
    $first_type = NULL;
    foreach ($types as $type) {
        if (!has_category_access(get_member(), 'calendar', strval($type['id']))) {
            continue;
        }
        if (!has_submit_permission('low', get_member(), get_ip_address(), 'cms_calendar', array('calendar', $type['id']))) {
            continue;
        }
        if ($type['id'] != db_get_first_id()) {
            $type_list->attach(form_input_list_entry(strval($type['id']), $type['id'] == $it, get_translated_text($type['t_title'])));
        } else {
            $first_type = $type;
        }
    }
    if (has_actual_page_access(get_member(), 'admin_occle') && !is_null($first_type) && is_null($GLOBALS['CURRENT_SHARE_USER'])) {
        $type_list->attach(form_input_list_entry(strval(db_get_first_id()), db_get_first_id() == $it, get_translated_text($first_type['t_title'])));
    }
    return $type_list;
}
Beispiel #25
0
 /**
  * Standard aed_module edit actualiser.
  *
  * @param  ID_TEXT		The entry being edited
  */
 function edit_actualisation($_id)
 {
     require_code('catalogues2');
     $category_id = intval($_id);
     $catalogue_name = $GLOBALS['SITE_DB']->query_value_null_ok('catalogue_categories', 'c_name', array('id' => $category_id));
     if (is_null($catalogue_name)) {
         warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
     }
     $title = post_param('title');
     $description = post_param('description', STRING_MAGIC_NULL);
     $notes = post_param('notes', STRING_MAGIC_NULL);
     $parent_id = post_param_integer('parent_id', INTEGER_MAGIC_NULL);
     $move_days_lower = post_param_integer('move_days_lower', INTEGER_MAGIC_NULL);
     $move_days_higher = post_param_integer('move_days_higher', INTEGER_MAGIC_NULL);
     $move_target = post_param_integer('move_target', INTEGER_MAGIC_NULL);
     if ($move_target == -1) {
         $move_target = NULL;
     }
     if (!is_null($move_target)) {
         if (!has_submit_permission('mid', get_member(), get_ip_address(), 'cms_catalogues', array('catalogues_catalogue', $catalogue_name, 'catalogues_category', $move_target))) {
             access_denied('CATEGORY_ACCESS');
         }
     }
     if (!fractional_edit()) {
         $urls = get_url('image_url', 'rep_image', 'uploads/grepimages', 0, OCP_UPLOAD_IMAGE);
         $rep_image = $urls[0];
         if ($rep_image == '' && post_param_integer('rep_image_unlink', 0) != 1) {
             $rep_image = NULL;
         }
     } else {
         $rep_image = STRING_MAGIC_NULL;
     }
     actual_edit_catalogue_category($category_id, $title, $description, $notes, $parent_id, post_param('meta_keywords', STRING_MAGIC_NULL), post_param('meta_description', STRING_MAGIC_NULL), $rep_image, $move_days_lower, $move_days_higher, $move_target);
     if (!fractional_edit()) {
         if (get_value('disable_cat_cat_perms') !== '1') {
             $this->set_permissions(strval($category_id));
         }
     }
     $this->donext_category_id = $category_id;
     $this->donext_catalogue_name = $catalogue_name;
 }
Beispiel #26
0
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     require_lang('news');
     require_lang('ocf');
     require_css('news');
     $days = array_key_exists('param', $map) ? intval($map['param']) : 14;
     $multiplier = array_key_exists('multiplier', $map) ? floatval($map['multiplier']) : 0.5;
     $fallback_full = array_key_exists('fallback_full', $map) ? intval($map['fallback_full']) : 3;
     $fallback_archive = array_key_exists('fallback_archive', $map) ? intval($map['fallback_archive']) : 6;
     $zone = array_key_exists('zone', $map) ? $map['zone'] : get_module_zone('news');
     $historic = array_key_exists('historic', $map) ? $map['historic'] : '';
     $filter_and = array_key_exists('filter_and', $map) ? $map['filter_and'] : '';
     $blogs = array_key_exists('blogs', $map) ? intval($map['blogs']) : -1;
     $member_based = array_key_exists('member_based', $map) && $map['member_based'] == '1';
     global $NEWS_CATS;
     if (!isset($NEWS_CATS)) {
         $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('nc_owner' => NULL));
         $NEWS_CATS = list_to_map('id', $NEWS_CATS);
     }
     $days_full = floatval($days) * $multiplier;
     $days_outline = floatval($days) - $days_full;
     // News Query
     require_code('ocfiltering');
     $filter = array_key_exists('filter', $map) ? $map['filter'] : get_param('news_filter', '*');
     $filters_1 = ocfilter_to_sqlfragment($filter, 'p.news_category', 'news_categories', NULL, 'p.news_category', '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_2 = ocfilter_to_sqlfragment($filter, 'd.news_entry_category', 'news_categories', NULL, 'd.news_category', '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)
     $q_filter = '(' . $filters_1 . ' OR ' . $filters_2 . ')';
     if ($blogs === 0) {
         if ($q_filter != '') {
             $q_filter .= ' AND ';
         }
         $q_filter .= 'nc_owner IS NULL';
     } elseif ($blogs === 1) {
         if ($q_filter != '') {
             $q_filter .= ' AND ';
         }
         $q_filter .= '(nc_owner IS NOT NULL)';
     }
     if ($blogs != -1) {
         $join = ' LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news_categories c ON c.id=p.news_category';
     } else {
         $join = '';
     }
     if ($filter_and != '') {
         $filters_and_1 = ocfilter_to_sqlfragment($filter_and, 'p.news_category', 'news_categories', NULL, 'p.news_category', '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_and_2 = ocfilter_to_sqlfragment($filter_and, 'd.news_entry_category', 'news_categories', NULL, 'd.news_category', '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)
         $q_filter .= ' AND (' . $filters_and_1 . ' OR ' . $filters_and_2 . ')';
     }
     if ($historic == '') {
         $rows = $days_full == 0.0 ? array() : $GLOBALS['SITE_DB']->query('SELECT *,p.id AS p_id FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news p LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news_category_entries d ON d.news_entry=p.id' . $join . ' WHERE ' . $q_filter . ' AND validated=1 AND date_and_time>=' . strval(time() - 60 * 60 * 24 * intval($days_full)) . (can_arbitrary_groupby() ? ' GROUP BY p.id' : '') . ' ORDER BY p.date_and_time DESC', 300);
         if (!array_key_exists(0, $rows)) {
             $rows = $GLOBALS['SITE_DB']->query('SELECT *,p.id AS p_id FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news p LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news_category_entries d ON p.id=d.news_entry' . $join . ' WHERE ' . $q_filter . ' AND validated=1' . (can_arbitrary_groupby() ? ' GROUP BY p.id' : '') . ' ORDER BY p.date_and_time DESC', $fallback_full);
             $rows2 = $GLOBALS['SITE_DB']->query('SELECT *,p.id AS p_id FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news p LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news_category_entries d ON p.id=d.news_entry' . $join . ' WHERE ' . $q_filter . ' AND validated=1' . (can_arbitrary_groupby() ? ' GROUP BY p.id' : '') . ' ORDER BY p.date_and_time DESC', $fallback_archive, $fallback_full);
         } else {
             $rows2 = $GLOBALS['SITE_DB']->query('SELECT *,p.id AS p_id FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news p LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news_category_entries d ON p.id=d.news_entry' . $join . ' WHERE ' . $q_filter . ' AND validated=1 AND date_and_time>=' . strval(time() - 60 * 60 * 24 * intval($days_full + $days_outline)) . ' AND date_and_time<' . strval(time() - 60 * 60 * 24 * intval($days_full)) . (can_arbitrary_groupby() ? ' GROUP BY p.id' : '') . ' ORDER BY p.date_and_time DESC', 300);
         }
     } else {
         if (function_exists('set_time_limit')) {
             @set_time_limit(0);
         }
         $start = 0;
         do {
             $_rows = $GLOBALS['SITE_DB']->query('SELECT *,p.id AS p_id FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news p LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news_category_entries d ON p.id=d.news_entry' . $join . ' WHERE ' . $q_filter . ' AND validated=1' . (can_arbitrary_groupby() ? ' GROUP BY p.id' : '') . ' ORDER BY p.date_and_time DESC', 200, $start);
             $rows = array();
             $rows2 = array();
             foreach ($_rows as $row) {
                 $ok = false;
                 switch ($historic) {
                     case 'month':
                         if (date('m', utctime_to_usertime($row['date_and_time'])) == date('m', utctime_to_usertime()) && date('Y', utctime_to_usertime($row['date_and_time'])) != date('Y', utctime_to_usertime())) {
                             $ok = true;
                         }
                         break;
                     case 'week':
                         if (date('W', utctime_to_usertime($row['date_and_time'])) == date('W', utctime_to_usertime()) && date('Y', utctime_to_usertime($row['date_and_time'])) != date('Y', utctime_to_usertime())) {
                             $ok = true;
                         }
                         break;
                     case 'day':
                         if (date('d', utctime_to_usertime($row['date_and_time'])) == date('d', utctime_to_usertime()) && date('m', utctime_to_usertime($row['date_and_time'])) == date('m', utctime_to_usertime()) && date('Y', utctime_to_usertime($row['date_and_time'])) != date('Y', utctime_to_usertime())) {
                             $ok = true;
                         }
                         break;
                 }
                 if ($ok) {
                     if (count($rows) < $fallback_full) {
                         $rows[] = $row;
                     } elseif (count($rows2) < $fallback_archive) {
                         $rows2[] = $row;
                     } else {
                         break 2;
                     }
                 }
             }
             $start += 200;
         } while (count($_rows) == 200);
         unset($_rows);
     }
     $rows = remove_duplicate_rows($rows, 'p_id');
     $i = 0;
     $news_text = new ocp_tempcode();
     while (array_key_exists($i, $rows)) {
         $myrow = $rows[$i];
         //		$categories=$GLOBALS['SITE_DB']->query_select('news_category_entries',array('news_entry_category'),array('news_entry'=>$myrow['p_id']));
         if (has_category_access(get_member(), 'news', strval($myrow['news_category']))) {
             $id = $myrow['p_id'];
             $date = get_timezoned_date($myrow['date_and_time']);
             $author_url = addon_installed('authors') && !$member_based ? build_url(array('page' => 'authors', 'type' => 'misc', 'id' => $myrow['author']), get_module_zone('authors')) : new ocp_tempcode();
             $author = $myrow['author'];
             $news_title = get_translated_tempcode($myrow['title']);
             if (array_key_exists('show_in_full', $map) && $map['show_in_full'] == '1') {
                 $news = get_translated_tempcode($myrow['news_article']);
                 $truncate = false;
                 if ($news->is_empty()) {
                     $news = get_translated_tempcode($myrow['news']);
                 }
             } else {
                 $news = get_translated_tempcode($myrow['news']);
                 if ($news->is_empty()) {
                     $news = get_translated_tempcode($myrow['news_article']);
                     $truncate = true;
                 } else {
                     $truncate = false;
                 }
             }
             $tmp = array('page' => 'news', 'type' => 'view', 'id' => $id);
             if ($filter != '*') {
                 $tmp['filter'] = $filter;
             }
             if ($filter_and != '*' && $filter_and != '') {
                 $tmp['filter_and'] = $filter_and;
             }
             if ($blogs != -1) {
                 $tmp['blog'] = $blogs;
             }
             $full_url = build_url($tmp, $zone);
             if (!array_key_exists($myrow['news_category'], $NEWS_CATS)) {
                 $_news_cats = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('id' => $myrow['news_category']), '', 1);
                 if (array_key_exists(0, $_news_cats)) {
                     $NEWS_CATS[$myrow['news_category']] = $_news_cats[0];
                 }
             }
             if (!array_key_exists($myrow['news_category'], $NEWS_CATS) || !array_key_exists('nc_title', $NEWS_CATS[$myrow['news_category']])) {
                 $myrow['news_category'] = db_get_first_id();
             }
             $img = find_theme_image($NEWS_CATS[$myrow['news_category']]['nc_img']);
             if (is_null($img)) {
                 $img = '';
             }
             if ($myrow['news_image'] != '') {
                 $img = $myrow['news_image'];
                 if (url_is_local($img)) {
                     $img = get_custom_base_url() . '/' . $img;
                 }
             }
             $category = get_translated_text($NEWS_CATS[$myrow['news_category']]['nc_title']);
             $seo_bits = seo_meta_get_for('news', strval($id));
             $map2 = array('TAGS' => get_loaded_tags('news', explode(',', $seo_bits[0])), 'ID' => strval($id), 'TRUNCATE' => $truncate, 'BLOG' => $blogs === 1, 'SUBMITTER' => strval($myrow['submitter']), 'CATEGORY' => $category, 'IMG' => $img, 'DATE' => $date, 'DATE_RAW' => strval($myrow['date_and_time']), 'NEWS_TITLE' => $news_title, 'AUTHOR' => $author, 'AUTHOR_URL' => $author_url, 'NEWS' => $news, 'FULL_URL' => $full_url);
             if (get_option('is_on_comments') == '1' && !has_no_forum() && $myrow['allow_comments'] >= 1) {
                 $map2['COMMENT_COUNT'] = '1';
             }
             $news_text->attach(do_template('NEWS_PIECE_SUMMARY', $map2));
         }
         $i++;
     }
     $j = 0;
     $news_text2 = new ocp_tempcode();
     while (array_key_exists($j, $rows2)) {
         $myrow = $rows2[$j];
         //		$categories=$GLOBALS['SITE_DB']->query_select('news_category_entries',array('news_entry_category'),array('news_entry'=>$myrow['id']));
         if (has_category_access(get_member(), 'news', strval($myrow['news_category']))) {
             $date = get_timezoned_date($myrow['date_and_time']);
             $tmp = array('page' => 'news', 'type' => 'view', 'id' => $myrow['p_id']);
             if ($filter != '*') {
                 $tmp['filter'] = $filter;
             }
             if ($filter_and != '*' && $filter_and != '') {
                 $tmp['filter_and'] = $filter_and;
             }
             if ($blogs != -1) {
                 $tmp['blog'] = $blogs;
             }
             $url = build_url($tmp, $zone);
             $title = get_translated_tempcode($myrow['title']);
             $title_plain = get_translated_text($myrow['title']);
             $seo_bits = seo_meta_get_for('news', strval($myrow['p_id']));
             $map2 = array('_GUID' => 'd81bda3a0912a1e708af6bb1f503b296', 'TAGS' => get_loaded_tags('news', explode(',', $seo_bits[0])), 'BLOG' => $blogs === 1, 'ID' => strval($myrow['p_id']), 'SUBMITTER' => strval($myrow['submitter']), 'DATE' => $date, 'DATE_RAW' => strval($myrow['date_and_time']), 'URL' => $url, 'TITLE_PLAIN' => $title_plain, 'TITLE' => $title);
             if (get_option('is_on_comments') == '1' && !has_no_forum() && $myrow['allow_comments'] >= 1) {
                 $map2['COMMENT_COUNT'] = '1';
             }
             $news_text2->attach(do_template('NEWS_BRIEF', $map2));
         }
         $j++;
     }
     $tmp = array('page' => 'news', 'type' => 'misc');
     if ($filter != '*') {
         $tmp[is_numeric($filter) ? 'id' : 'filter'] = $filter;
     }
     if ($filter_and != '*' && $filter_and != '') {
         $tmp['filter_and'] = $filter_and;
     }
     if ($blogs != -1) {
         $tmp['blog'] = $blogs;
     }
     $archive_url = build_url($tmp, $zone);
     $_is_on_rss = get_option('is_rss_advertised', true);
     $is_on_rss = is_null($_is_on_rss) ? 0 : intval($_is_on_rss);
     // Set to zero if we don't want to show RSS links
     $submit_url = new ocp_tempcode();
     if (($blogs !== 1 || has_specific_permission(get_member(), 'have_personal_category', 'cms_news')) && has_actual_page_access(NULL, $blogs === 1 ? 'cms_blogs' : 'cms_news', NULL, NULL) && has_submit_permission('high', get_member(), get_ip_address(), $blogs === 1 ? 'cms_blogs' : 'cms_news')) {
         $map2 = array('page' => $blogs === 1 ? 'cms_blogs' : 'cms_news', 'type' => 'ad', 'redirect' => SELF_REDIRECT);
         if (is_numeric($filter)) {
             $map2['cat'] = $filter;
             // select news cat by default, if we are only showing one news cat in this block
         } elseif ($filter != '*') {
             $pos_a = strpos($filter, ',');
             $pos_b = strpos($filter, '-');
             if ($pos_a !== false) {
                 $first_cat = substr($filter, 0, $pos_a);
             } elseif ($pos_b !== false) {
                 $first_cat = substr($filter, 0, $pos_b);
             } else {
                 $first_cat = '';
             }
             if (is_numeric($first_cat)) {
                 $map2['cat'] = $first_cat;
             }
         }
         $submit_url = build_url($map2, get_module_zone($blogs === 1 ? 'cms_blogs' : 'cms_news'));
     }
     $_title = do_lang_tempcode($blogs == 1 ? 'BLOGS_POSTS' : 'NEWS');
     if (array_key_exists('title', $map) && $map['title'] != '') {
         $_title = protect_from_escaping(escape_html($map['title']));
     }
     if ($i == 0 && $j == 0) {
         return do_template('BLOCK_NO_ENTRIES', array('_GUID' => '9d7065af4dd4026ffb34243fd931f99d', 'HIGH' => false, 'TITLE' => $_title, 'MESSAGE' => do_lang_tempcode($blogs == 1 ? 'BLOG_NO_NEWS' : 'NO_NEWS'), 'ADD_NAME' => do_lang_tempcode($blogs == 1 ? 'ADD_NEWS_BLOG' : 'ADD_NEWS'), 'SUBMIT_URL' => $submit_url));
     }
     $atom_url = new ocp_tempcode();
     $rss_url = new ocp_tempcode();
     if ($is_on_rss == 1) {
         $atom_url = make_string_tempcode(find_script('backend') . '?type=atom&mode=news&filter=' . $filter);
         $atom_url->attach(symbol_tempcode('KEEP'));
         $rss_url = make_string_tempcode(find_script('backend') . '?type=rss2&mode=news&filter=' . $filter);
         $rss_url->attach(symbol_tempcode('KEEP'));
     }
     return do_template('BLOCK_MAIN_NEWS', array('_GUID' => '01f5fbd2b0c7c8f249023ecb4254366e', 'BLOG' => $blogs === 1, 'TITLE' => $_title, 'CONTENT' => $news_text, 'BRIEF' => $news_text2, 'FILTER' => $filter, 'ARCHIVE_URL' => $archive_url, 'SUBMIT_URL' => $submit_url, 'RSS_URL' => $rss_url, 'ATOM_URL' => $atom_url));
 }
Beispiel #27
0
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     require_lang('news');
     require_css('news');
     require_css('side_blocks');
     $max = array_key_exists('param', $map) ? intval($map['param']) : 5;
     $zone = array_key_exists('zone', $map) ? $map['zone'] : get_module_zone('news');
     require_lang('news');
     $blogs = array_key_exists('blogs', $map) ? intval($map['blogs']) : -1;
     $historic = array_key_exists('historic', $map) ? $map['historic'] : '';
     $filter_and = array_key_exists('filter_and', $map) ? $map['filter_and'] : '';
     global $NEWS_CATS;
     if (!isset($NEWS_CATS)) {
         $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('nc_owner' => NULL));
         $NEWS_CATS = list_to_map('id', $NEWS_CATS);
     }
     $content = new ocp_tempcode();
     // News Query
     require_code('ocfiltering');
     $filter = array_key_exists('filter', $map) ? $map['filter'] : get_param('news_filter', '*');
     $filters_1 = ocfilter_to_sqlfragment($filter, 'p.news_category', 'news_categories', NULL, 'p.news_category', '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_2 = ocfilter_to_sqlfragment($filter, 'd.news_entry_category', 'news_categories', NULL, 'd.news_category', '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)
     $q_filter = '(' . $filters_1 . ' OR ' . $filters_2 . ')';
     if ($blogs === 0) {
         if ($q_filter != '') {
             $q_filter .= ' AND ';
         }
         $q_filter .= 'nc_owner IS NULL';
     } elseif ($blogs === 1) {
         if ($q_filter != '') {
             $q_filter .= ' AND ';
         }
         $q_filter .= '(nc_owner IS NOT NULL)';
     }
     if ($blogs != -1) {
         $join = ' LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news_categories c ON c.id=p.news_category';
     } else {
         $join = '';
     }
     if ($filter_and != '') {
         $filters_and_1 = ocfilter_to_sqlfragment($filter_and, 'p.news_category', 'news_categories', NULL, 'p.news_category', '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_and_2 = ocfilter_to_sqlfragment($filter_and, 'd.news_entry_category', 'news_categories', NULL, 'd.news_category', '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)
         $q_filter .= ' AND (' . $filters_and_1 . ' OR ' . $filters_and_2 . ')';
     }
     if ($historic == '') {
         $news = $GLOBALS['SITE_DB']->query('SELECT p.* FROM ' . get_table_prefix() . 'news p LEFT JOIN ' . get_table_prefix() . 'news_category_entries d ON d.news_entry=p.id' . $join . ' WHERE ' . $q_filter . ' AND validated=1' . (can_arbitrary_groupby() ? ' GROUP BY p.id' : '') . ' ORDER BY date_and_time DESC', $max);
     } else {
         if (function_exists('set_time_limit')) {
             @set_time_limit(0);
         }
         $start = 0;
         do {
             $_rows = $GLOBALS['SITE_DB']->query('SELECT p.* FROM ' . get_table_prefix() . 'news p LEFT JOIN ' . get_table_prefix() . 'news_category_entries d ON p.id=d.news_entry' . $join . ' WHERE ' . $q_filter . ' AND validated=1' . (can_arbitrary_groupby() ? ' GROUP BY p.id' : '') . ' ORDER BY p.date_and_time DESC', 200, $start);
             $news = array();
             foreach ($_rows as $row) {
                 $ok = false;
                 switch ($historic) {
                     case 'month':
                         if (date('m', utctime_to_usertime($row['date_and_time'])) == date('m', utctime_to_usertime()) && date('Y', utctime_to_usertime($row['date_and_time'])) != date('Y', utctime_to_usertime())) {
                             $ok = true;
                         }
                         break;
                     case 'week':
                         if (date('W', utctime_to_usertime($row['date_and_time'])) == date('W', utctime_to_usertime()) && date('Y', utctime_to_usertime($row['date_and_time'])) != date('Y', utctime_to_usertime())) {
                             $ok = true;
                         }
                         break;
                     case 'day':
                         if (date('d', utctime_to_usertime($row['date_and_time'])) == date('d', utctime_to_usertime()) && date('Y', utctime_to_usertime($row['date_and_time'])) != date('Y', utctime_to_usertime())) {
                             $ok = true;
                         }
                         break;
                 }
                 if ($ok) {
                     if (count($news) < $max) {
                         $news[] = $row;
                     } else {
                         break;
                     }
                 }
             }
             $start += 200;
         } while (count($_rows) == 200 && count($news) < $max);
         unset($_rows);
     }
     $news = remove_duplicate_rows($news, 'id');
     $_title = do_lang_tempcode($blogs === 1 ? 'BLOGS_POSTS' : 'NEWS');
     if (array_key_exists('title', $map) && $map['title'] != '') {
         $_title = protect_from_escaping(escape_html($map['title']));
     }
     foreach ($news as $myrow) {
         if (has_category_access(get_member(), 'news', strval($myrow['news_category']))) {
             $url_map = array('page' => 'news', 'type' => 'view', 'id' => $myrow['id']);
             if ($filter != '*') {
                 $url_map['filter'] = $filter;
             }
             if ($filter_and != '*' && $filter_and != '') {
                 $url_map['filter_and'] = $filter_and;
             }
             if ($blogs === 1) {
                 $url_map['blog'] = 1;
             }
             $full_url = build_url($url_map, $zone);
             $news_title = get_translated_tempcode($myrow['title']);
             $date = locale_filter(date('d M', utctime_to_usertime($myrow['date_and_time'])));
             $summary = get_translated_tempcode($myrow['news']);
             if ($summary->is_empty()) {
                 $summary = get_translated_tempcode($myrow['news_article']);
             }
             if (!array_key_exists($myrow['news_category'], $NEWS_CATS)) {
                 $_news_cats = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('id' => $myrow['news_category']), '', 1);
                 if (array_key_exists(0, $_news_cats)) {
                     $NEWS_CATS[$myrow['news_category']] = $_news_cats[0];
                 }
             }
             $category = get_translated_text($NEWS_CATS[$myrow['news_category']]['nc_title']);
             $content->attach(do_template('BLOCK_SIDE_NEWS_SUMMARY', array('_GUID' => 'f7bc5288680e68641ca94ca4a3111d4a', 'IMG_URL' => find_theme_image($NEWS_CATS[$myrow['news_category']]['nc_img']), 'AUTHOR' => $myrow['author'], 'ID' => strval($myrow['id']), 'SUBMITTER' => strval($myrow['submitter']), 'CATEGORY' => $category, 'BLOG' => $blogs === 1, 'FULL_URL' => $full_url, 'NEWS' => $summary, 'NEWS_TITLE' => $news_title, '_DATE' => strval($myrow['date_and_time']), 'DATE' => $date)));
         }
     }
     $tmp = array('page' => 'news', 'type' => 'misc');
     if ($filter != '*') {
         $tmp[is_numeric($filter) ? 'id' : 'filter'] = $filter;
     }
     if ($filter_and != '*' && $filter_and != '') {
         $tmp['filter_and'] = $filter_and;
     }
     if ($blogs != -1) {
         $tmp['blog'] = $blogs;
     }
     $archive_url = build_url($tmp, $zone);
     $_is_on_rss = get_option('is_rss_advertised', true);
     $is_on_rss = is_null($_is_on_rss) ? 0 : intval($_is_on_rss);
     // Set to zero if we don't want to show RSS links
     $submit_url = new ocp_tempcode();
     if (($blogs !== 1 || has_specific_permission(get_member(), 'have_personal_category', 'cms_news')) && has_actual_page_access(NULL, $blogs === 1 ? 'cms_blogs' : 'cms_news', NULL, NULL) && has_submit_permission('high', get_member(), get_ip_address(), $blogs === 1 ? 'cms_blogs' : 'cms_news')) {
         $map2 = array('page' => $blogs === 1 ? 'cms_blogs' : 'cms_news', 'type' => 'ad', 'redirect' => SELF_REDIRECT);
         if (is_numeric($filter)) {
             $map2['cat'] = $filter;
             // select news cat by default, if we are only showing one news cat in this block
         } elseif ($filter != '*') {
             $pos_a = strpos($filter, ',');
             $pos_b = strpos($filter, '-');
             if ($pos_a !== false) {
                 $first_cat = substr($filter, 0, $pos_a);
             } elseif ($pos_b !== false) {
                 $first_cat = substr($filter, 0, $pos_b);
             } else {
                 $first_cat = '';
             }
             if (is_numeric($first_cat)) {
                 $map2['cat'] = $first_cat;
             }
         }
         $submit_url = build_url($map2, get_module_zone($blogs === 1 ? 'cms_blogs' : 'cms_news'));
     }
     return do_template('BLOCK_SIDE_NEWS', array('_GUID' => '611b83965c4b6e42fb4a709d94c332f7', 'BLOG' => $blogs === 1, 'TITLE' => $_title, 'CONTENT' => $content, 'SUBMIT_URL' => $submit_url, 'ARCHIVE_URL' => $archive_url));
 }
Beispiel #28
0
/**
 * Import wordpress db
 */
function import_wordpress_db()
{
    disable_php_memory_limit();
    $data = get_wordpress_data();
    $is_validated = post_param_integer('wp_auto_validate', 0);
    $to_own_account = post_param_integer('wp_add_to_own', 0);
    // Create members
    require_code('ocf_members_action');
    require_code('ocf_groups');
    $def_grp_id = get_first_default_group();
    $cat_id = array();
    $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('nc_owner' => NULL));
    $NEWS_CATS = list_to_map('id', $NEWS_CATS);
    foreach ($data as $values) {
        if (get_forum_type() == 'ocf') {
            $member_id = $GLOBALS['FORUM_DB']->query_value_null_ok('f_members', 'id', array('m_username' => $values['user_login']));
            if (is_null($member_id)) {
                if (post_param_integer('wp_import_wordpress_users', 0) == 1) {
                    $member_id = ocf_make_member($values['user_login'], $values['user_pass'], '', NULL, NULL, NULL, NULL, array(), NULL, $def_grp_id, 1, time(), time(), '', NULL, '', 0, 0, 1, '', '', '', 1, 0, '', 1, 1, '', NULL, '', false, 'wordpress');
                } else {
                    $member_id = $GLOBALS['FORUM_DRIVER']->get_member_from_username('admin');
                    // Set admin as owner
                    if (is_null($member_id)) {
                        $member_id = $GLOBALS['FORUM_DRIVER']->get_guest_id() + 1;
                    }
                }
            }
        } else {
            $member_id = $GLOBALS['FORUM_DRIVER']->get_guest_id();
        }
        // Guest user
        // If post should go to own account
        if ($to_own_account == 1) {
            $member_id = get_member();
        }
        if (array_key_exists('POSTS', $values)) {
            // Create posts in blog
            foreach ($values['POSTS'] as $post_id => $post) {
                if (array_key_exists('category', $post)) {
                    $cat_id = array();
                    foreach ($post['category'] as $cat_code => $category) {
                        $cat_code = NULL;
                        if ($category == 'Uncategorized') {
                            continue;
                        }
                        // Skip blank category creation
                        foreach ($NEWS_CATS as $id => $existing_cat) {
                            if (get_translated_text($existing_cat['nc_title']) == $category) {
                                $cat_code = $id;
                            }
                        }
                        if (is_null($cat_code)) {
                            $cat_code = add_news_category($category, 'newscats/community', $category);
                            $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'));
                            $NEWS_CATS = list_to_map('id', $NEWS_CATS);
                        }
                        $cat_id = array_merge($cat_id, array($cat_code));
                    }
                }
                $owner_category_id = $GLOBALS['SITE_DB']->query_value_null_ok('news_categories', 'id', array('nc_owner' => $member_id));
                if ($post['post_type'] == 'post') {
                    $id = add_news($post['post_title'], html_to_comcode($post['post_content']), NULL, $is_validated, 1, $post['comment_status'] == 'closed' ? 0 : 1, 1, '', html_to_comcode($post['post_content']), $owner_category_id, $cat_id, NULL, $member_id, 0, time(), NULL, '');
                } elseif ($post['post_type'] == 'page') {
                    // If dont have permission to write comcode page, skip the post
                    if (!has_submit_permission('high', get_member(), get_ip_address(), NULL, NULL)) {
                        continue;
                    }
                    require_code('comcode');
                    // Save articles as new comcode pages
                    $zone = filter_naughty(post_param('zone', 'site'));
                    $lang = filter_naughty(post_param('lang', 'EN'));
                    $file = preg_replace('/[^A-Za-z0-9]/', '_', $post['post_title']);
                    // Filter non alphanumeric charactors
                    $parent_page = post_param('parent_page', '');
                    $fullpath = zone_black_magic_filterer(get_custom_file_base() . '/' . $zone . '/pages/comcode_custom/' . $lang . '/' . $file . '.txt');
                    // Check existancy of new page
                    $submiter = $GLOBALS['SITE_DB']->query_value_null_ok('comcode_pages', 'p_submitter', array('the_zone' => $zone, 'the_page' => $file));
                    if (!is_null($submiter)) {
                        continue;
                    }
                    // Skip existing titled articles	- may need change
                    require_code('submit');
                    give_submit_points('COMCODE_PAGE_ADD');
                    if (!addon_installed('unvalidated')) {
                        $is_validated = 1;
                    }
                    $GLOBALS['SITE_DB']->query_insert('comcode_pages', array('the_zone' => $zone, 'the_page' => $file, 'p_parent_page' => $parent_page, 'p_validated' => $is_validated, 'p_edit_date' => NULL, 'p_add_date' => strtotime($post['post_date']), 'p_submitter' => $member_id, 'p_show_as_edit' => 0));
                    if (!file_exists($fullpath)) {
                        $_content = html_to_comcode($post['post_content']);
                        $myfile = @fopen($fullpath, 'wt');
                        if ($myfile === false) {
                            intelligent_write_error($fullpath);
                        }
                        if (fwrite($myfile, $_content) < strlen($_content)) {
                            warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
                        }
                        fclose($myfile);
                        sync_file($fullpath);
                    }
                    require_code('seo2');
                    seo_meta_set_for_explicit('comcode_page', $zone . ':' . $file, post_param('meta_keywords', ''), post_param('meta_description', ''));
                    require_code('permissions2');
                    set_page_permissions_from_environment($zone, $file);
                }
                $content_url = build_url(array('page' => 'news', 'type' => 'view', 'id' => $id), get_module_zone('news'), NULL, false, false, true);
                $content_title = $post['post_title'];
                // Add comments
                if (post_param_integer('wp_import_blog_comments', 0) == 1) {
                    if (array_key_exists('COMMENTS', $post)) {
                        $submitter = NULL;
                        foreach ($post['COMMENTS'] as $comment) {
                            $submitter = $GLOBALS['FORUM_DB']->query_value_null_ok('f_members', 'id', array('m_username' => $comment['comment_author']));
                            if (is_null($submitter)) {
                                $submitter = $GLOBALS['FORUM_DRIVER']->get_guest_id();
                            }
                            // If comment is made by a non-member, assign comment to guest account
                            $forum = is_null(get_value('comment_forum__news')) ? get_option('comments_forum_name') : get_value('comment_forum__news');
                            $result = $GLOBALS['FORUM_DRIVER']->make_post_forum_topic($forum, 'news_' . strval($id), $submitter, $post['post_title'], $comment['comment_content'], $content_title, do_lang('COMMENT'), $content_url, NULL, NULL, 1, 1, false);
                        }
                    }
                }
            }
        }
    }
}
Beispiel #29
0
 /**
  * The UI to show a gallery.
  *
  * @return tempcode		The UI
  */
 function do_gallery()
 {
     require_code('images');
     $cat = get_param('id', 'root');
     $GLOBALS['FEED_URL'] = find_script('backend') . '?mode=galleries&filter=' . $cat;
     $root = get_param('root', 'root');
     if (!has_category_access(get_member(), 'galleries', $cat)) {
         access_denied('CATEGORY_ACCESS');
     }
     // Info on our gallery
     $gallery_rows = $GLOBALS['SITE_DB']->query_select('galleries', array('*'), array('name' => $cat), '', 1);
     $implied_existence = false;
     if (!array_key_exists(0, $gallery_rows)) {
         // Possibly we will 'imply' it's existence if this is a member gallery; allows normal rendering to finish, with add links
         $matches = array();
         if (preg_match('#^member\\_(\\d+)\\_(.*)$#', $cat, $matches) != 0) {
             $username = $GLOBALS['FORUM_DRIVER']->get_username(intval($matches[1]));
             if (!is_null($username)) {
                 $gallery_rows = $GLOBALS['SITE_DB']->query_select('galleries', array('*'), array('name' => $matches[2]), '', 1);
             }
         }
         if (!array_key_exists(0, $gallery_rows)) {
             return warn_screen(get_page_title('ERROR_OCCURRED'), do_lang_tempcode('MISSING_RESOURCE'));
         }
         $myrow = $gallery_rows[0];
         $myrow['is_member_synched'] = 0;
         $fullname = do_lang('PERSONAL_GALLERY_OF', $username, get_translated_text($myrow['fullname']));
         $myrow['parent_id'] = $matches[2];
         $implied_existence = true;
     } else {
         $myrow = $gallery_rows[0];
         $fullname = get_translated_text($myrow['fullname']);
     }
     if ($fullname == '') {
         $fullname = $cat;
     }
     $description = get_translated_tempcode($myrow['description']);
     if (has_actual_page_access(NULL, 'cms_galleries', NULL, NULL) && has_submit_permission('mid', get_member(), get_ip_address(), 'cms_galleries', array('galleries', $cat))) {
         $submit_cat = $myrow['is_member_synched'] == 1 ? 'member_' . strval(get_member()) . '_' . $cat : $cat;
         $submit_image_url = $myrow['accept_images'] == 0 ? new ocp_tempcode() : build_url(array('page' => 'cms_galleries', 'type' => 'ad', 'cat' => $submit_cat), get_module_zone('cms_galleries'));
         $submit_video_url = $myrow['accept_videos'] == 0 ? new ocp_tempcode() : build_url(array('page' => 'cms_galleries', 'type' => 'av', 'cat' => $submit_cat), get_module_zone('cms_galleries'));
     } else {
         $submit_image_url = new ocp_tempcode();
         $submit_video_url = new ocp_tempcode();
     }
     if (!$implied_existence && has_actual_page_access(NULL, 'cms_galleries', NULL, NULL) && has_edit_permission('cat_mid', get_member(), get_member_id_from_gallery_name($cat), 'cms_galleries', array('galleries', $cat))) {
         $edit_url = build_url(array('page' => 'cms_galleries', 'type' => '_ec', 'id' => $cat), get_module_zone('cms_galleries'));
     } else {
         $edit_url = new ocp_tempcode();
     }
     if (!$implied_existence && has_actual_page_access(NULL, 'cms_galleries', NULL, NULL) && has_submit_permission('cat_mid', get_member(), get_ip_address(), 'cms_galleries')) {
         $add_gallery_url = build_url(array('page' => 'cms_galleries', 'type' => 'ac', 'cat' => $cat), get_module_zone('cms_galleries'));
     } else {
         $add_gallery_url = new ocp_tempcode();
     }
     $may_download_gallery = has_specific_permission(get_member(), 'may_download_gallery', 'galleries', array('galleries', $cat));
     $tree = gallery_breadcrumbs($cat, $root, true, get_module_zone('galleries'));
     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, array('root' => $cat));
         $tree->attach(hyperlink($url, escape_html($fullname), false, false, do_lang_tempcode('VIRTUAL_ROOT')));
     } else {
         $tree->attach('<span>' . escape_html($fullname) . '</span>');
     }
     $myrow['flow_mode_interface'] = get_param_integer('flow_mode_interface', $myrow['flow_mode_interface']);
     // Allow override via URL
     // Flow mode puts emphasis on subgalleries, rather than entries; it is subgalleries that there are a lot of, rather than entries
     if ($myrow['flow_mode_interface'] == 1) {
         $max = get_param_integer('max', get_default_gallery_max());
         if ($max < 1) {
             $max = 1;
         }
         $start = get_param_integer('start', 0);
     } else {
         $max = NULL;
         $start = NULL;
     }
     // Subgalleries
     $order = 'add_date DESC';
     if (get_option('gallery_name_order') == '1') {
         $order = 'name ASC';
     }
     $rows_children = $GLOBALS['SITE_DB']->query_select('galleries', array('*'), array('parent_id' => $cat), 'ORDER BY ' . $order, 200);
     $children = new ocp_tempcode();
     $num_galleries = 0;
     if (count($rows_children) == 200) {
         $rows_children = array();
     }
     // Lots of personal galleries. Will need to be reached via member profiles
     foreach ($rows_children as $child) {
         if (substr($child['name'], 0, 9) == 'download_') {
             continue;
         }
         if (!has_category_access(get_member(), 'galleries', $child['name'])) {
             continue;
         }
         if (get_option('show_empty_galleries') == '1' || gallery_has_content($child['name'])) {
             if (is_null($max) || $num_galleries >= $start && $num_galleries < $start + $max) {
                 $content = show_gallery_box($child, $root, true, get_zone_name(), get_option('show_empty_galleries') != '1');
                 if (!$content->is_empty()) {
                     $children->attach(do_template('GALLERY_SUBGALLERY_WRAP', array('CONTENT' => $content)));
                 }
             }
             $num_galleries++;
         }
     }
     // Views
     if (get_db_type() != 'xml') {
         $myrow['gallery_views']++;
         $GLOBALS['SITE_DB']->query_update('galleries', array('gallery_views' => $myrow['gallery_views']), array('name' => $cat), '', 1, NULL, false, true);
     }
     // Page title
     if (addon_installed('awards')) {
         require_code('awards');
         $awards = find_awards_for('gallery', $cat);
     } else {
         $awards = array();
     }
     $title_to_use = do_lang_tempcode('_GALLERY', escape_html($fullname));
     $title_to_use_2 = do_lang('_GALLERY', $fullname);
     $title = get_page_title($title_to_use, false, NULL, NULL, $awards);
     seo_meta_load_for('gallery', $cat, $title_to_use_2);
     $rep_image = $myrow['rep_image'];
     if (post_param_integer('rating_' . $cat, -1) != -1) {
         decache('main_top_galleries');
     }
     list($rating_details, $comment_details, $trackback_details) = embed_feedback_systems(get_page_name(), $cat, $myrow['allow_rating'], $myrow['allow_comments'], 0, 1, NULL, build_url(array('page' => '_SELF'), '_SELF', NULL, true, false, true), $title_to_use_2, get_value('comment_forum__galleries'));
     breadcrumb_add_segment($tree);
     $GLOBALS['META_DATA'] += array('created' => date('Y-m-d', $myrow['add_date']), 'creator' => is_null($myrow['g_owner']) ? '' : $GLOBALS['FORUM_DRIVER']->get_username($myrow['g_owner']), 'publisher' => '', 'modified' => '', 'type' => 'Gallery', 'title' => $fullname, 'identifier' => '_SEARCH:galleries:misc:' . $cat, 'description' => get_translated_text($myrow['description']));
     if ($rep_image != '') {
         $GLOBALS['META_DATA'] += array('image' => (url_is_local($rep_image) ? get_custom_base_url() . '/' : '') . $rep_image);
     }
     // Sorting
     list($sort, $sort_backwards, $sql_suffix_images, $sql_suffix_videos) = $this->get_sort_order();
     if (get_option('is_on_rating') == '1') {
         $_selectors['compound_rating DESC'] = 'POPULARITY';
     }
     $_selectors = array_merge($_selectors, array('url ASC' => 'FILENAME', 'add_date ASC' => 'OLDEST_FIRST', 'add_date DESC' => 'NEWEST_FIRST', 'title ASC' => 'TITLE'));
     $selectors = new ocp_tempcode();
     foreach ($_selectors as $selector_value => $selector_name) {
         $selected = $sort == $selector_value;
         $selectors->attach(do_template('RESULTS_BROWSER_SORTER', array('SELECTED' => $selected, 'NAME' => do_lang_tempcode($selector_name), 'VALUE' => $selector_value)));
     }
     $sort_url = get_self_url(false, false, array('sort' => NULL), false, true);
     $sorting = do_template('RESULTS_BROWSER_SORT', array('SORT' => 'sort', 'RAND' => uniqid(''), 'URL' => $sort_url, 'SELECTORS' => $selectors));
     if ($myrow['flow_mode_interface'] == 1) {
         return $this->do_gallery_flow_mode($rating_details, $comment_details, $cat, $root, $description, $children, $may_download_gallery, $edit_url, $add_gallery_url, $submit_image_url, $submit_video_url, $title, $rep_image, $start, $max, $num_galleries, $fullname, $sorting);
     } else {
         return $this->do_gallery_regular_mode($rating_details, $comment_details, $cat, $root, $description, $children, $may_download_gallery, $edit_url, $add_gallery_url, $submit_image_url, $submit_video_url, $title, $fullname, $sorting);
     }
 }
Beispiel #30
0
 /**
  * The calendar area view for viewing a single week.
  *
  * @param  string			The week we are viewing
  * @param  string			The day (Y-m-d) we are viewing
  * @param  array			List of components of our viewed ID
  * @param  MEMBER			The member ID we are viewing as
  * @param  ?array			The type filter (NULL: none)
  * @return tempcode		The UI
  */
 function view_calendar_view_week($view_id, $day, $explode, $member_id, $filter)
 {
     $start_year = intval($explode[0]);
     $start_week = intval($explode[1]);
     list($start_month, $start_day, $start_year) = date_from_week_of_year($start_year, $start_week);
     $period_start = mktime(0, 0, 0, $start_month, $start_day, $start_year);
     $period_end = $period_start + 60 * 60 * 24 * 7;
     $happenings = calendar_matches($member_id, true, $period_start, $period_end, $filter);
     global $M_SORT_KEY;
     $M_SORT_KEY = 0;
     usort($happenings, 'multi_sort');
     if (get_option('ssw') == '0') {
         $day_remap = array('Mon' => 0, 'Tue' => 1, 'Wed' => 2, 'Thu' => 3, 'Fri' => 4, 'Sat' => 5, 'Sun' => 6);
     } else {
         $day_remap = array('Sun' => 0, 'Mon' => 1, 'Tue' => 2, 'Wed' => 3, 'Thu' => 4, 'Fri' => 5, 'Sat' => 6);
     }
     // We start with our 24x7 stream array, assuming all is free time
     $streams = array();
     // hour X day
     for ($i = 0; $i < 24; $i++) {
         $streams[$i] = array();
         for ($j = 0; $j < 7; $j++) {
             $streams[$i][$j] = array('free_time', '', $i);
         }
     }
     for ($j = 0; $j < 7; $j++) {
         for ($i = 0; $i < 24; $i++) {
             $entries = new ocp_tempcode();
             $class = '';
             $worst_priority = 6;
             $continuation = $i;
             // Happenings in a single day
             $cnt = count($happenings);
             for ($hap_i = 0; $hap_i < $cnt; $hap_i++) {
                 $happening = $happenings[$hap_i];
                 list($e_id, $event, $from, $to, $real_from, $real_to, $utc_real_from) = $happening;
                 $date = date('D:H', $from);
                 $explode2 = explode(':', $date);
                 if (intval($explode2[1]) == $i && $day_remap[$explode2[0]] == $j) {
                     $date = is_null($event['e_start_hour']) ? '' : locale_filter(my_strftime(do_lang('calendar_minute'), $real_from));
                     if (is_numeric($e_id)) {
                         $map = array_merge($filter, array('page' => '_SELF', 'type' => 'view', 'id' => $event['e_id'], 'day' => date('Y-m-d', $utc_real_from), 'date' => $view_id, 'back' => 'week'));
                         if (get_param_integer('member_id', get_member()) != get_member()) {
                             $map['member_id'] = get_param_integer('member_id');
                         }
                         $url = build_url($map, '_SELF');
                     } else {
                         $url = $e_id;
                     }
                     $icon = $event['t_logo'];
                     if (!is_null($to)) {
                         $date = date_range($real_from, $real_to, !is_null($event['e_start_hour']));
                         if (!is_null($to) && $to >= mktime(0, 0, 0, $start_month, $start_day + $j + 1, $start_year)) {
                             $continuation = 24;
                             $ntime = mktime(0, 0, 0, $start_month, $start_day + $j + 1, $start_year);
                             if ($ntime < $period_end) {
                                 $happenings[] = array($e_id, $event, $ntime, $to, $real_from, $real_to, $utc_real_from);
                             }
                         } elseif (intval(date('H', $to)) > $i + 1) {
                             $continuation = max($continuation, intval(date('H', $to)));
                         }
                     }
                     $title = is_integer($event['e_title']) ? get_translated_text($event['e_title']) : $event['e_title'];
                     $entries->attach(do_template('CALENDAR_WEEK_ENTRY', array('_GUID' => 'a5577fb634ecc5480789d1cd21f686fb', 'ID' => is_string($event['e_id']) ? $event['e_id'] : strval($event['e_id']), 'T_TITLE' => array_key_exists('t_title', $event) ? is_string($event['t_title']) ? $event['t_title'] : get_translated_text($event['t_title']) : 'RSS', 'PRIORITY' => strval($event['e_priority']), 'ICON' => $icon, 'TIME' => $date, 'TITLE' => $title, 'URL' => $url, 'RECURRING' => $event['e_recurrence'] != 'none')));
                     if ($event['e_priority'] < $worst_priority) {
                         $worst_priority = $event['e_priority'];
                         $class = 'priority_' . strval($event['e_priority']);
                     }
                 }
             }
             // Not free time anymore
             if ($class != '') {
                 $streams[$i][$j] = array($class, $entries, $continuation);
                 // Now work backwards to cut back any continuation onto this spot
                 for ($k = $i - 1; $k >= 0; $k--) {
                     if ($streams[$k][$j][2] >= $i) {
                         $streams[$k][$j][2] = $i - 1;
                     }
                 }
             }
         }
     }
     // Now mark continuations ahead
     for ($i = 0; $i < 24; $i++) {
         for ($j = 0; $j < 7; $j++) {
             if ($streams[$i][$j][0] != 'continuation') {
                 $continuation = $streams[$i][$j][2];
                 for ($k = $i + 1; $k <= $continuation; $k++) {
                     $streams[$k][$j][0] = 'continuation';
                 }
             }
         }
     }
     // Now render
     $hours = new ocp_tempcode();
     for ($i = 0; $i < 24; $i++) {
         $hour = locale_filter(date(do_lang('time_hour_and_mins'), $i * 60 * 60));
         $days = new ocp_tempcode();
         for ($j = 0; $j < 7; $j++) {
             $class = $streams[$i][$j][0];
             $entries = $streams[$i][$j][1];
             $continuation = $streams[$i][$j][2];
             if ((!is_object($entries) || $entries->is_empty()) && $class != 'continuation') {
                 $entries = do_template('CALENDAR_WEEK_ENTRY_FREE', array('_GUID' => '4a16cdd5a2a0e5a444fd61a6aafa2ffa', 'CLASS' => $class, 'TEXT' => ''));
             }
             $down = $continuation - $i;
             if ($class != 'continuation') {
                 $timestamp = $period_start + ($i + 24 * $j) * 60 * 60;
                 if (has_actual_page_access(NULL, 'cms_calendar', NULL, NULL) && has_submit_permission('low', get_member(), get_ip_address(), 'cms_calendar')) {
                     $and_filter = $this->get_and_filter();
                     $add_url = build_url(array('page' => 'cms_calendar', 'type' => 'ad', 'date' => date('Y-m-d H:i:s', $timestamp), 'e_type' => count($and_filter) == 1 ? $and_filter[0] : NULL), get_module_zone('cms_calendar'));
                 } else {
                     $add_url = new ocp_tempcode();
                 }
                 $days->attach(do_template('CALENDAR_WEEK_HOUR_DAY', array('_GUID' => 'e001b4b2ea1995760ef0d4460d93b2e1', 'CURRENT' => date('Y-m-d H', utctime_to_usertime()) == date('Y-m-d H', $timestamp), 'ADD_URL' => $add_url, 'DOWN' => strval($down + 1), 'DAY' => $day, 'HOUR' => $hour, 'CLASS' => $class, 'ENTRIES' => $entries)));
             }
         }
         $hours->attach(do_template('CALENDAR_WEEK_HOUR', array('_GUID' => 'a57d0d6a683d30fc0a48168b43299607', 'HOUR' => $hour, 'DAYS' => $days)));
     }
     $offset = 0;
     if (get_option('ssw') == '1') {
         $datex = date('Y-m-d', mktime(0, 0, 0, $start_month, $start_day + $offset, intval($explode[0])));
         $map = array_merge($filter, array('page' => '_SELF', 'type' => 'misc', 'view' => 'day', 'id' => $datex));
         if (get_param_integer('member_id', get_member()) != get_member()) {
             $map['member_id'] = get_param_integer('member_id');
         }
         $sunday_url = build_url($map, '_SELF');
         $sunday_date = locale_filter(date(do_lang('calendar_day_of_month_verbose'), $period_start + $offset * 60 * 60 * 24));
         $offset++;
     }
     $datex = date('Y-m-d', mktime(0, 0, 0, $start_month, $start_day + $offset, intval($explode[0])));
     $map = array_merge($filter, array('page' => '_SELF', 'type' => 'misc', 'view' => 'day', 'id' => $datex));
     if (get_param_integer('member_id', get_member()) != get_member()) {
         $map['member_id'] = get_param_integer('member_id');
     }
     $monday_url = build_url($map, '_SELF');
     $monday_date = locale_filter(date(do_lang('calendar_day_of_month_verbose'), $period_start + $offset * 60 * 60 * 24));
     $offset++;
     $datex = date('Y-m-d', mktime(0, 0, 0, $start_month, $start_day + $offset, intval($explode[0])));
     $map = array_merge($filter, array('page' => '_SELF', 'type' => 'misc', 'view' => 'day', 'id' => $datex));
     if (get_param_integer('member_id', get_member()) != get_member()) {
         $map['member_id'] = get_param_integer('member_id');
     }
     $tuesday_url = build_url($map, '_SELF');
     $tuesday_date = locale_filter(date(do_lang('calendar_day_of_month_verbose'), $period_start + $offset * 60 * 60 * 24));
     $offset++;
     $datex = date('Y-m-d', mktime(0, 0, 0, $start_month, $start_day + $offset, intval($explode[0])));
     $map = array_merge($filter, array('page' => '_SELF', 'type' => 'misc', 'view' => 'day', 'id' => $datex));
     if (get_param_integer('member_id', get_member()) != get_member()) {
         $map['member_id'] = get_param_integer('member_id');
     }
     $wednesday_url = build_url($map, '_SELF');
     $wednesday_date = locale_filter(date(do_lang('calendar_day_of_month_verbose'), $period_start + $offset * 60 * 60 * 24));
     $offset++;
     $datex = date('Y-m-d', mktime(0, 0, 0, $start_month, $start_day + $offset, intval($explode[0])));
     $map = array_merge($filter, array('page' => '_SELF', 'type' => 'misc', 'view' => 'day', 'id' => $datex));
     if (get_param_integer('member_id', get_member()) != get_member()) {
         $map['member_id'] = get_param_integer('member_id');
     }
     $thursday_url = build_url($map, '_SELF');
     $thursday_date = locale_filter(date(do_lang('calendar_day_of_month_verbose'), $period_start + $offset * 60 * 60 * 24));
     $offset++;
     $datex = date('Y-m-d', mktime(0, 0, 0, $start_month, $start_day + $offset, intval($explode[0])));
     $map = array_merge($filter, array('page' => '_SELF', 'type' => 'misc', 'view' => 'day', 'id' => $datex));
     if (get_param_integer('member_id', get_member()) != get_member()) {
         $map['member_id'] = get_param_integer('member_id');
     }
     $friday_url = build_url($map, '_SELF');
     $friday_date = locale_filter(date(do_lang('calendar_day_of_month_verbose'), $period_start + $offset * 60 * 60 * 24));
     $offset++;
     $datex = date('Y-m-d', mktime(0, 0, 0, $start_month, $start_day + $offset, intval($explode[0])));
     $map = array_merge($filter, array('page' => '_SELF', 'type' => 'misc', 'view' => 'day', 'id' => $datex));
     if (get_param_integer('member_id', get_member()) != get_member()) {
         $map['member_id'] = get_param_integer('member_id');
     }
     $saturday_url = build_url($map, '_SELF');
     $saturday_date = locale_filter(date(do_lang('calendar_day_of_month_verbose'), $period_start + $offset * 60 * 60 * 24));
     $offset++;
     if (get_option('ssw') == '0') {
         $datex = date('Y-m-d', mktime(0, 0, 0, $start_month, $start_day + $offset, intval($explode[0])));
         $map = array_merge($filter, array('page' => '_SELF', 'type' => 'misc', 'view' => 'day', 'id' => $datex));
         if (get_param_integer('member_id', get_member()) != get_member()) {
             $map['member_id'] = get_param_integer('member_id');
         }
         $sunday_url = build_url($map, '_SELF');
         $sunday_date = locale_filter(date(do_lang('calendar_day_of_month_verbose'), $period_start + $offset * 60 * 60 * 24));
         $offset++;
     }
     return do_template('CALENDAR_WEEK', array('_GUID' => '8dd9ad4e874d2f320a48551e0c9bde57', 'MONDAY_DATE' => $monday_date, 'TUESDAY_DATE' => $tuesday_date, 'WEDNESDAY_DATE' => $wednesday_date, 'THURSDAY_DATE' => $thursday_date, 'FRIDAY_DATE' => $friday_date, 'SATURDAY_DATE' => $saturday_date, 'SUNDAY_DATE' => $sunday_date, 'MONDAY_URL' => $monday_url, 'TUESDAY_URL' => $tuesday_url, 'WEDNESDAY_URL' => $wednesday_url, 'THURSDAY_URL' => $thursday_url, 'FRIDAY_URL' => $friday_url, 'SATURDAY_URL' => $saturday_url, 'SUNDAY_URL' => $sunday_url, 'HOURS' => $hours, 'PERIOD_START' => strval($period_start), 'PERIOD_END' => strval($period_end)));
 }