コード例 #1
0
ファイル: gambling.php プロジェクト: erico-deh/ocPortal
 /**
  * Standard actualisation stage of pointstore item purchase.
  *
  * @return tempcode		The UI
  */
 function action_done()
 {
     $class = str_replace('hook_pointstore_', '', strtolower(get_class($this)));
     if (get_option('is_on_' . $class . '_buy') == '0') {
         return new ocp_tempcode();
     }
     $amount = post_param_integer('amount', -1);
     $title = get_page_title('GAMBLING');
     // Check points
     $cost = intval(get_option('minimum_gamble_amount'));
     $points_left = available_points(get_member());
     $max = min(intval(get_option('maximum_gamble_amount')), $points_left);
     if (!has_specific_permission(get_member(), 'give_points_self') || $amount < 0) {
         if ($amount < $cost || $amount > $max) {
             warn_exit(do_lang_tempcode('INVALID_GAMBLE_AMOUNT'));
         }
         if ($points_left < $amount) {
             return warn_screen($title, do_lang_tempcode('_CANT_AFFORD', integer_format($cost), integer_format($points_left)));
         }
     }
     // Calculate
     $average_gamble_multiplier = floatval(get_option('average_gamble_multiplier')) / 100.0;
     $maximum_gamble_multiplier = floatval(get_option('maximum_gamble_multiplier')) / 100.0;
     $above_average = mt_rand(0, 10) < 5;
     if ($above_average) {
         //			$winnings=round($average_gamble_multiplier*$amount+mt_rand(0,round($maximum_gamble_multiplier*$amount-$average_gamble_multiplier*$amount)));	  Even distribution is NOT wise
         $peak = $maximum_gamble_multiplier * $amount;
         $under = 0.0;
         $number = intval(round($average_gamble_multiplier * $amount + mt_rand(0, intval(round($maximum_gamble_multiplier * $amount - $average_gamble_multiplier * $amount)))));
         for ($x = 1; $x < intval($peak); $x++) {
             $p = $peak * (1.0 / pow(floatval($x) + 0.4, 2.0) - 1.0 / pow($maximum_gamble_multiplier * floatval($amount), 2.0));
             // Using a 1/x^2 curve. 0.4 is a bit of a magic number to get the averaging right
             $under += $p;
             if ($under > floatval($number)) {
                 break;
             }
         }
         $winnings = intval(round($average_gamble_multiplier * $amount + $x * 1.1));
         // 1.1 is a magic number to make it seem a bit fairer
     } else {
         $winnings = mt_rand(0, intval(round($average_gamble_multiplier * $amount)));
     }
     // Actuate
     require_code('points2');
     charge_member(get_member(), $amount - $winnings, do_lang('GAMBLING'));
     $GLOBALS['SITE_DB']->query_insert('sales', array('date_and_time' => time(), 'memberid' => get_member(), 'purchasetype' => 'GAMBLING', 'details' => strval($amount), 'details2' => ''));
     // Show message
     if ($winnings > $amount) {
         $result = do_lang_tempcode('GAMBLE_CONGRATULATIONS', integer_format($winnings - $amount), integer_format($amount));
     } else {
         $result = do_lang_tempcode('GAMBLE_COMMISERATIONS', integer_format($amount - $winnings), integer_format($amount));
     }
     $url = build_url(array('page' => '_SELF', 'type' => 'misc'), '_SELF');
     return redirect_screen($title, $url, $result);
 }
コード例 #2
0
ファイル: ocp_merge.php プロジェクト: erico-deh/ocPortal
 /**
  * Do some tests, to make sure we're happy to continue importing.
  *
  * @param  object			The DB connection to import from
  * @param  string			The table prefix the target prefix is using
  * @param  PATH			The base directory we are importing from
  * @return ?tempcode		Error/warning UI (NULL: no error/warning)
  */
 function pre_import_tests($db, $table_prefix, $file_base)
 {
     $title = get_page_title('IMPORT');
     $bad = false;
     // Check actually is ocPortal DB (ERROR)
     $test = $db->query_value('zones', 'zone_name');
     if (is_null($test)) {
         return warn_screen($title, do_lang_tempcode('ERROR_NOT_CORRECT_DATABASE'));
     }
     // Check version (WARNING)
     $test = $db->query_value_null_ok('values', 'the_value', array('the_name' => 'version'));
     if (is_null($test) || intval($test) != ocp_version()) {
         attach_message(do_lang_tempcode('ERROR_NOT_CORRECT_VERSION'), 'warn');
         $bad = true;
     }
     // Check actually is ocPortal file path (ERROR)
     if (!file_exists($file_base . '/info.php') || !file_exists($file_base . '/sources_custom')) {
         attach_message(do_lang_tempcode('ERROR_NOT_CORRECT_FILES'), 'warn');
         if (isset($GLOBALS['FORUM_DB']) && $db->connection_write != $GLOBALS['FORUM_DB']->connection_write && !file_exists($file_base . '/info.php')) {
             attach_message(do_lang_tempcode('ERROR_NOT_CORRECT_LINKING_POSSIBLY'), 'warn');
         }
         $bad = true;
     }
     // Check is on same MSN or is OCF (WARNING)
     if (file_exists($file_base . '/info.php')) {
         global $SITE_INFO;
         $backup_site_info = $SITE_INFO;
         $SITE_INFO = NULL;
         @(include $file_base . '/info.php');
         if (is_null($SITE_INFO)) {
             $SITE_INFO = $backup_site_info;
             attach_message(do_lang_tempcode('ERROR_INACESSIBLE_DIR'), 'warn');
             if (isset($GLOBALS['FORUM_DB']) && $db->connection_write != $GLOBALS['FORUM_DB']->connection_write) {
                 attach_message(do_lang_tempcode('ERROR_NOT_CORRECT_LINKING_POSSIBLY'), 'warn');
             }
             $bad = true;
         } else {
             $this_site_info = $SITE_INFO;
             $SITE_INFO = $backup_site_info;
             if (!array_key_exists('db_forums_host', $SITE_INFO)) {
                 $SITE_INFO['db_forums_host'] = 'localhost';
             }
             $same_forum = $this_site_info['db_forums'] == $SITE_INFO['db_forums'] && $this_site_info['db_forums_host'] == $SITE_INFO['db_forums_host'] && $db->table_prefix;
             if ($this_site_info['forum_type'] != 'ocf' && !$same_forum) {
                 attach_message(do_lang_tempcode('ERROR_NOT_CORRECT_LINKING'), 'warn');
                 $bad = true;
             }
         }
     }
     // Show warning
     if ($bad) {
         return do_template('CONFIRM_SCREEN', array('_GUID' => '286928b79830cdff4ac506e4f4f00f3a', 'TITLE' => $title, 'PREVIEW' => do_lang_tempcode('IMPORT_WARNINGS_GIVEN'), 'FIELDS' => build_keep_post_fields(), 'URL' => get_self_url(false, false, array('happy' => 1))));
     }
     return NULL;
 }
コード例 #3
0
 /**
  * The UI to show OCF posting rates.
  *
  * @param  object			The stats module object
  * @param  string			The screen type
  * @return tempcode		The UI
  */
 function posting_rates($ob, $type)
 {
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('SITE_STATISTICS'))));
     require_lang('ocf');
     //This will show a plain bar chart with all the downloads listed
     $title = get_page_title('POSTING_RATES');
     // Handle time range
     if (get_param_integer('dated', 0) == 0) {
         $title = get_page_title('POSTING_RATES');
         $extra_fields = new ocp_tempcode();
         require_code('form_templates');
         $extra_fields->attach(form_input_tick(do_lang_tempcode('HOURLY_BREAKDOWNS'), do_lang_tempcode('DESCRIPTION_HOURLY_BREAKDOWNS'), 'hourly', false));
         return $ob->get_between($title, false, $extra_fields);
     }
     $time_start = get_input_date('time_start', true);
     $time_end = get_input_date('time_end', true);
     if (!is_null($time_end)) {
         $time_end += 60 * 60 * 24 - 1;
     }
     // So it is end of day not start
     if (is_null($time_start)) {
         $time_start = 0;
     }
     if (is_null($time_end)) {
         $time_end = time();
     }
     $title = get_page_title('SECTION_POSTING_RATES_RANGE', true, array(escape_html(get_timezoned_date($time_start, false)), escape_html(get_timezoned_date($time_end, false))));
     $poster_exception = '';
     foreach (explode(',', get_param('poster_exception', '')) as $e) {
         if (trim($e) == '') {
             continue;
         }
         $poster_exception .= 'p_poster<>' . strval(intval($e)) . ' AND ';
     }
     $csv = get_param_integer('csv', 0) == 1;
     if ($csv) {
         $time_start = 0;
         $time_end = time();
         $hourly = false;
     }
     $rows = $GLOBALS['FORUM_DB']->query('SELECT p_time FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts WHERE ' . $poster_exception . 'p_time>' . strval($time_start) . ' AND p_time<' . strval($time_end));
     if (count($rows) < 1) {
         return warn_screen($title, do_lang_tempcode('NO_DATA'));
     }
     $hourly = get_param_integer('hourly', 0) == 1;
     //($time_end-$time_start)<=60*60*24*2;
     $iterate_months = floatval($time_end - $time_start) / (60.0 * 60.0 * 24.0) > 100.0;
     // Gather data
     $posting_rates = array();
     if ($hourly) {
         for ($i = 0; $i < 24; $i++) {
             $date = str_pad(strval($i), 2, '0', STR_PAD_LEFT) . ':00';
             $posting_rates[$date] = 0;
         }
     } else {
         if ($iterate_months) {
             $year = intval(date('Y', $time_start));
             $month = intval(date('m', $time_start));
             while (mktime(0, 0, 0, $month - 1, 0, $year) < $time_end) {
                 $date = date('Y/m', mktime(0, 0, 0, $month, 0, $year));
                 $posting_rates[$date] = 0;
                 $month++;
                 if ($month == 13) {
                     $month = 1;
                     $year++;
                 }
             }
         } else {
             for ($i = $time_start - 60 * 60 * 12; $i <= $time_end + 60 * 60 * 12; $i += 60 * 60 * 24) {
                 $date = date('Y/m/d', $i);
                 $posting_rates[$date] = 0;
             }
         }
     }
     foreach ($rows as $row) {
         if ($hourly) {
             $date = date('H', $row['p_time']) . ':00';
         } else {
             if ($iterate_months) {
                 $date = date('Y/m', $row['p_time']);
             } else {
                 $date = date('Y/m/d', $row['p_time']);
             }
         }
         $posting_rates[$date]++;
     }
     $start = 0;
     $max = 1000;
     // Little trick, as we want all to fit
     $sortables = array();
     require_code('templates_results_table');
     $fields_title = results_field_title(array(do_lang_tempcode('DATE'), do_lang_tempcode('COUNT_TOTAL')), $sortables);
     $fields = new ocp_tempcode();
     $real_data = array();
     $i = 0;
     foreach ($posting_rates as $date => $value) {
         $fields->attach(results_entry(array(escape_html($date), escape_html(integer_format($value)))));
         $real_data[] = array('Date/Time' => $date, 'Tally' => $value);
         $i++;
     }
     $list = results_table(do_lang_tempcode('POSTING_RATES'), $start, 'start', $max, 'max', count($posting_rates), $fields_title, $fields, $sortables, '', '', 'sort', new ocp_tempcode());
     if ($csv) {
         make_csv($real_data, 'posting_rates.csv');
     }
     $output = create_bar_chart($posting_rates, do_lang('DATE'), do_lang('COUNT_TOTAL'), '', '');
     $ob->save_graph('Global-Posting_rates', $output);
     $graph = do_template('STATS_GRAPH', array('GRAPH' => get_custom_base_url() . '/data_custom/modules/admin_stats/Global-Posting_rates.xml', 'TITLE' => do_lang_tempcode('POSTING_RATES'), 'TEXT' => do_lang_tempcode('DESCRIPTION_POSTING_RATES')));
     return do_template('STATS_SCREEN', array('TITLE' => $title, 'GRAPH' => $graph, 'STATS' => $list));
 }
コード例 #4
0
ファイル: iotds.php プロジェクト: erico-deh/ocPortal
 /**
  * The UI to view an IOTD.
  *
  * @return tempcode		The UI
  */
 function view()
 {
     $title = get_page_title('IOTD');
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('IOTD_ARCHIVE'))));
     $id = get_param_integer('id');
     $rows = $GLOBALS['SITE_DB']->query_select('iotd', array('*'), array('id' => $id), '', 1);
     if (!array_key_exists(0, $rows)) {
         return warn_screen($title, do_lang_tempcode('MISSING_RESOURCE'));
     }
     $myrow = $rows[0];
     list($rating_details, $comment_details, $trackback_details) = embed_feedback_systems(get_page_name(), strval($id), $myrow['allow_rating'], $myrow['allow_comments'], $myrow['allow_trackbacks'], is_null($myrow['date_and_time']) && $myrow['used'] == 0 ? 0 : 1, $myrow['submitter'], build_url(array('page' => '_SELF', 'type' => 'view', 'id' => $id), '_SELF', NULL, false, false, true), get_translated_text($myrow['i_title']), get_value('comment_forum__iotds'));
     $date_raw = strval($myrow['date_and_time']);
     $add_date_raw = strval($myrow['add_date']);
     $edit_date_raw = is_null($myrow['edit_date']) ? '' : strval($myrow['edit_date']);
     $date = get_timezoned_date($myrow['date_and_time']);
     $add_date = get_timezoned_date($myrow['add_date']);
     $edit_date = get_timezoned_date($myrow['edit_date']);
     // Views
     if (get_db_type() != 'xml') {
         $myrow['iotd_views']++;
         $GLOBALS['SITE_DB']->query_update('iotd', array('iotd_views' => $myrow['iotd_views']), array('id' => $id), '', 1, NULL, false, true);
     }
     if (has_actual_page_access(NULL, 'cms_iotds', NULL, NULL) && has_edit_permission('high', get_member(), $myrow['submitter'], 'cms_iotds')) {
         $edit_url = build_url(array('page' => 'cms_iotds', 'type' => '_ed', 'id' => $id), get_module_zone('cms_iotds'));
     } else {
         $edit_url = new ocp_tempcode();
     }
     $url = $myrow['url'];
     if (url_is_local($url)) {
         $url = get_custom_base_url() . '/' . $url;
     }
     $GLOBALS['META_DATA'] += array('created' => date('Y-m-d', $myrow['add_date']), 'creator' => $GLOBALS['FORUM_DRIVER']->get_username($myrow['submitter']), 'publisher' => '', 'modified' => is_null($myrow['edit_date']) ? '' : date('Y-m-d', $myrow['edit_date']), 'type' => 'Poll', 'title' => get_translated_text($myrow['i_title']), 'identifier' => '_SEARCH:iotds:view:' . strval($id), 'description' => '', 'image' => $url);
     return do_template('IOTD_VIEW_SCREEN', array('_GUID' => 'f508d483459b88fab44cd8b9f4db780b', 'TITLE' => $title, 'SUBMITTER' => strval($myrow['submitter']), 'I_TITLE' => get_translated_tempcode($myrow['i_title']), 'CAPTION' => get_translated_tempcode($myrow['caption']), 'DATE_RAW' => $date_raw, 'ADD_DATE_RAW' => $add_date_raw, 'EDIT_DATE_RAW' => $edit_date_raw, 'DATE' => $date, 'ADD_DATE' => $add_date, 'EDIT_DATE' => $edit_date, 'VIEWS' => integer_format($myrow['iotd_views']), 'TRACKBACK_DETAILS' => $trackback_details, 'RATING_DETAILS' => $rating_details, 'COMMENT_DETAILS' => $comment_details, 'EDIT_URL' => $edit_url, 'URL' => $url));
 }
コード例 #5
0
ファイル: galleries.php プロジェクト: erico-deh/ocPortal
 /**
  * The UI to show a video.
  *
  * @param  ?string		Alternate category name to use (NULL: use standard one). This is useful if you are overriding this code to show images in virtual galleries.
  * @param  ?tempcode		Breadcrumbs (NULL: derive in this function).
  * @return tempcode		The UI
  */
 function show_video($category_name = NULL, $tree = NULL)
 {
     $id = get_param_integer('id');
     if (get_param_integer('ajax', 0) == 1) {
         header('Content-type: text/xml');
     }
     list($sort, $sort_backwards, $sql_suffix_images, $sql_suffix_videos) = $this->get_sort_order();
     if (addon_installed('awards')) {
         require_code('awards');
         $awards = find_awards_for('video', strval($id));
     } else {
         $awards = array();
     }
     // Pic up some info
     $rows = $GLOBALS['SITE_DB']->query_select('videos', array('*'), array('id' => $id), '', 1);
     if (!array_key_exists(0, $rows)) {
         return warn_screen(get_page_title('ERROR_OCCURRED'), do_lang_tempcode('MISSING_RESOURCE'));
     }
     $myrow = $rows[0];
     $url = $myrow['url'];
     if (url_is_local($url)) {
         $url = get_custom_base_url() . '/' . $url;
     }
     $cat = $myrow['cat'];
     $GLOBALS['FEED_URL'] = find_script('backend') . '?mode=galleries&filter=' . urlencode($cat);
     if (get_value('no_individual_gallery_view') === '1' && $GLOBALS['SITE_DB']->query_value('galleries', 'flow_mode_interface', array('name' => $cat)) == '1') {
         require_code('site2');
         assign_refresh(build_url(array('page' => '_SELF', 'type' => 'misc', 'id' => $cat, 'probe_id' => $id, 'probe_type' => 'video'), '_SELF'), 0.0);
     }
     $true_category_name = get_translated_text($GLOBALS['SITE_DB']->query_value('galleries', 'fullname', array('name' => $cat)));
     if (is_null($category_name)) {
         $category_name = $true_category_name;
     }
     if (get_param_integer('slideshow', 0) == 1) {
         $title = get_page_title('VIEW_SLIDESHOW', true, array(escape_html($category_name)));
         global $EXTRA_HEAD;
         $EXTRA_HEAD->attach('<meta name="robots" content="noindex" />');
         // XHTMLXHTML
     } else {
         $title = get_page_title(get_translated_text($myrow['title']) == '' ? 'VIEW_VIDEO' : '_VIEW_VIDEO', true, array(escape_html(get_translated_text($myrow['title']))), NULL, $awards);
     }
     $root = get_param('root', 'root');
     seo_meta_load_for('video', strval($id));
     $thumb_url = $myrow['thumb_url'];
     if (url_is_local($thumb_url)) {
         $thumb_url = get_custom_base_url() . '/' . $thumb_url;
     }
     if (!has_category_access(get_member(), 'galleries', $cat)) {
         access_denied('CATEGORY_ACCESS');
     }
     // Views
     if (get_db_type() != 'xml') {
         $myrow['video_views']++;
         $GLOBALS['SITE_DB']->query_update('videos', array('video_views' => $myrow['video_views']), array('id' => $id), '', 1, NULL, false, true);
     }
     list($rating_details, $comment_details, $trackback_details) = embed_feedback_systems('videos', strval($id), $myrow['allow_rating'], $myrow['allow_comments'], $myrow['allow_trackbacks'], $myrow['validated'], $myrow['submitter'], build_url(array('page' => '_SELF', 'type' => 'video', 'id' => $id), '_SELF', NULL, false, false, true), get_translated_text($myrow['title']) == '' ? do_lang('VIEW_VIDEO_IN', $true_category_name) : get_translated_text($myrow['title']), get_value('comment_forum__videos'));
     // Validation
     if ($myrow['validated'] == 0) {
         if (!has_specific_permission(get_member(), 'jump_to_unvalidated')) {
             access_denied('SPECIFIC_PERMISSION', 'jump_to_unvalidated');
         }
         $warning_details = do_template('WARNING_TABLE', array('_GUID' => 'b32faacba974e648a67e5e91ffd3d8e5', 'WARNING' => do_lang_tempcode(get_param_integer('redirected', 0) == 1 ? 'UNVALIDATED_TEXT_NON_DIRECT' : 'UNVALIDATED_TEXT')));
     } else {
         $warning_details = new ocp_tempcode();
     }
     // Comments
     $comments = get_translated_tempcode($myrow['comments']);
     if (has_actual_page_access(NULL, 'cms_galleries', NULL, NULL) && has_edit_permission('mid', get_member(), $myrow['submitter'], 'cms_galleries', array('galleries', $cat))) {
         $edit_url = build_url(array('page' => 'cms_galleries', 'type' => '_ev', 'id' => $id), get_module_zone('cms_galleries'));
     } else {
         $edit_url = new ocp_tempcode();
     }
     $add_date = get_timezoned_date($myrow['add_date']);
     $edit_date = is_null($myrow['edit_date']) ? '' : get_timezoned_date($myrow['edit_date']);
     // Video HTML
     $video = show_gallery_media($url, $thumb_url, $myrow['video_width'], $myrow['video_height'], $myrow['video_length']);
     $extension = get_file_extension($url);
     require_code('mime_types');
     $mime_type = get_mime_type($extension);
     list($n, $x, $nav) = $this->build_set_navigation(db_string_equal_to('cat', $cat), '', $category_name, $id, $root, 'video', get_param_integer('slideshow', 0), get_param_integer('wide_high', 0), get_param_integer('start', 0), get_param_integer('max', get_default_gallery_max()), $cat, $sort, $sort_backwards, $sql_suffix_images, $sql_suffix_videos, get_param('select', '*'), get_param('video_select', '*'));
     $member_id = get_member_id_from_gallery_name($cat, NULL, true);
     if (get_forum_type() == 'ocf') {
         require_code('ocf_members');
         require_code('ocf_members2');
     }
     $member_details = is_null($member_id) || get_forum_type() != 'ocf' ? new ocp_tempcode() : ocf_show_member_box($member_id);
     $video_details = show_video_details($myrow);
     if (is_null($tree)) {
         $tree = gallery_breadcrumbs($cat, $root, false, get_module_zone('galleries'));
     }
     breadcrumb_add_segment($tree, do_lang_tempcode('VIEW_VIDEO'));
     $GLOBALS['META_DATA'] += array('created' => date('Y-m-d', $myrow['add_date']), 'creator' => $GLOBALS['FORUM_DRIVER']->get_username($myrow['submitter']), 'publisher' => '', 'modified' => is_null($myrow['edit_date']) ? '' : date('Y-m-d', $myrow['edit_date']), 'type' => 'Video', 'title' => get_translated_text($myrow['title']), 'identifier' => '_SEARCH:galleries:video:' . strval($id), 'description' => get_translated_text($myrow['comments']), 'image' => $thumb_url, 'video' => $url, 'video:height' => strval($myrow['video_height']), 'video:width' => strval($myrow['video_width']), 'video:type' => $mime_type);
     return do_template('GALLERY_ENTRY_SCREEN', array('_GUID' => '91e231906ed899513ec2db8a2974dddf', 'MEDIA_TYPE' => 'video', 'E_TITLE' => get_translated_text($myrow['title']), 'CAT' => $cat, 'SLIDESHOW' => get_param_integer('slideshow', 0) == 1, 'TRUE_GALLERY_TITLE' => $true_category_name, 'GALLERY_TITLE' => $category_name, 'MEMBER_ID' => is_null($member_id) ? '' : strval($member_id), 'ID' => strval($id), 'TAGS' => get_loaded_tags('videos'), 'TITLE' => $title, 'SUBMITTER' => strval($myrow['submitter']), 'URL' => $url, 'VIDEO_DETAILS' => $video_details, 'MEMBER_DETAILS' => $member_details, 'X' => integer_format($x), 'N' => integer_format($n), 'VIEWS' => integer_format($myrow['video_views']), 'ADD_DATE_RAW' => strval($myrow['add_date']), 'EDIT_DATE_RAW' => is_null($myrow['edit_date']) ? '' : strval($myrow['edit_date']), 'ADD_DATE' => $add_date, 'EDIT_DATE' => $edit_date, 'RATING_DETAILS' => $rating_details, 'TRACKBACK_DETAILS' => $trackback_details, 'COMMENT_DETAILS' => $comment_details, 'EDIT_URL' => $edit_url, 'NAV' => $nav, 'COMMENTS' => $comments, 'VIDEO' => $video, 'WARNING_DETAILS' => $warning_details));
 }
コード例 #6
0
ファイル: downloads.php プロジェクト: erico-deh/ocPortal
 /**
  * The UI to view a download.
  *
  * @return tempcode		The UI
  */
 function dloadinfo_screen()
 {
     $id = get_param_integer('id');
     $root = get_param_integer('root', db_get_first_id(), true);
     // Basic Init
     $rows = $GLOBALS['SITE_DB']->query_select('download_downloads', array('*'), array('id' => $id), '', 1);
     if (!array_key_exists(0, $rows)) {
         return warn_screen(get_page_title('SECTION_DOWNLOADS'), do_lang_tempcode('MISSING_RESOURCE'));
     }
     $myrow = $rows[0];
     $GLOBALS['FEED_URL'] = find_script('backend') . '?mode=downloads&filter=' . strval($myrow['category_id']);
     if (!has_category_access(get_member(), 'downloads', strval($myrow['category_id']))) {
         access_denied('CATEGORY_ACCESS');
     }
     $name = get_translated_text($myrow['name']);
     list($rating_details, $comment_details, $trackback_details) = embed_feedback_systems(get_page_name(), strval($id), $myrow['allow_rating'], $myrow['allow_comments'], $myrow['allow_trackbacks'], $myrow['validated'], $myrow['submitter'], build_url(array('page' => '_SELF', 'type' => 'entry', 'id' => $id), '_SELF', NULL, false, false, true), $name, get_value('comment_forum__downloads'));
     // Views
     if (get_db_type() != 'xml') {
         $myrow['download_views']++;
         $GLOBALS['SITE_DB']->query_update('download_downloads', array('download_views' => $myrow['download_views']), array('id' => $id), '', 1, NULL, false, true);
     }
     // Tree
     $tree = download_breadcrumbs($myrow['category_id'], $root, false, get_zone_name());
     $title_to_use = do_lang_tempcode('DOWNLOAD_TITLE', escape_html($name));
     $title_to_use_2 = do_lang('DOWNLOAD_TITLE', $name);
     if (addon_installed('awards')) {
         require_code('awards');
         $awards = find_awards_for('download', strval($id));
     } else {
         $awards = array();
     }
     $title = get_page_title($title_to_use, false, NULL, NULL, $awards);
     seo_meta_load_for('downloads_download', strval($id), $title_to_use_2);
     $warning_details = new ocp_tempcode();
     // Validation
     if ($myrow['validated'] == 0) {
         if (!has_specific_permission(get_member(), 'jump_to_unvalidated')) {
             access_denied('SPECIFIC_PERMISSION', 'jump_to_unvalidated');
         }
         $warning_details->attach(do_template('WARNING_TABLE', array('_GUID' => '5b1781b8fbb1ef9b8f47693afcff02b9', 'WARNING' => do_lang_tempcode(get_param_integer('redirected', 0) == 1 ? 'UNVALIDATED_TEXT_NON_DIRECT' : 'UNVALIDATED_TEXT'))));
     }
     // Cost warning
     if ($myrow['download_cost'] != 0 && addon_installed('points')) {
         require_lang('points');
         $warning_details->attach(do_template('WARNING_TABLE', array('_GUID' => '05fc448bf79b373385723c5af5ec93af', 'WARNING' => do_lang_tempcode('WILL_COST', integer_format($myrow['download_cost'])))));
     }
     // Admin functions
     $edit_url = new ocp_tempcode();
     $add_img_url = new ocp_tempcode();
     if (has_actual_page_access(NULL, 'cms_downloads', NULL, NULL) && has_edit_permission('mid', get_member(), $myrow['submitter'], 'cms_downloads', array('downloads', $myrow['category_id']))) {
         $edit_url = build_url(array('page' => 'cms_downloads', 'type' => '_ed', 'id' => $id), get_module_zone('cms_downloads'));
     }
     if (addon_installed('galleries')) {
         if (has_actual_page_access(NULL, 'cms_galleries', NULL, NULL) && has_edit_permission('mid', get_member(), $myrow['submitter'], 'cms_galleries', array('galleries', 'download_' . strval($id)))) {
             require_lang('galleries');
             $add_img_url = build_url(array('page' => 'cms_galleries', 'type' => 'ad', 'cat' => 'download_' . strval($id)), get_module_zone('cms_galleries'));
         }
     }
     // Outmoding
     if (!is_null($myrow['out_mode_id'])) {
         $outmode_url = build_url(array('page' => '_SELF', 'type' => 'entry', 'id' => $myrow['out_mode_id'], 'root' => $root == db_get_first_id() ? NULL : $root), '_SELF');
     } else {
         $outmode_url = new ocp_tempcode();
     }
     // Stats
     $add_date = get_timezoned_date($myrow['add_date'], false);
     // Additional information
     $additional_details = get_translated_tempcode($myrow['comments']);
     // Edit date
     if (!is_null($myrow['edit_date'])) {
         $edit_date = make_string_tempcode(get_timezoned_date($myrow['edit_date'], false));
     } else {
         $edit_date = new ocp_tempcode();
     }
     $images_details = new ocp_tempcode();
     $image_url = '';
     $counter = 0;
     if (addon_installed('galleries')) {
         // Images
         require_lang('galleries');
         $cat = 'download_' . strval($id);
         $map = array('cat' => $cat);
         if (!has_specific_permission(get_member(), 'see_unvalidated')) {
             $map['validated'] = 1;
         }
         $rows = $GLOBALS['SITE_DB']->query_select('images', array('*'), $map, 'ORDER BY id', 200);
         $div = 2;
         $_out = new ocp_tempcode();
         $_row = new ocp_tempcode();
         require_code('images');
         while (array_key_exists($counter, $rows)) {
             $row = $rows[$counter];
             //		$view_url=build_url(array('page'=>'galleries','type'=>'image','wide'=>1,'id'=>$row['id']),get_module_zone('galleries'));
             $view_url = $row['url'];
             if ($image_url == '') {
                 $image_url = $row['url'];
             }
             if (url_is_local($view_url)) {
                 $view_url = get_custom_base_url() . '/' . $view_url;
             }
             $thumb_url = ensure_thumbnail($row['url'], $row['thumb_url'], 'galleries', 'images', $row['id']);
             $comment = get_translated_tempcode($row['comments']);
             $thumb = do_image_thumb($thumb_url, '');
             if (has_actual_page_access(NULL, 'cms_galleries', NULL, NULL) && has_edit_permission('mid', get_member(), $row['submitter'], 'cms_galleries', array('galleries', 'download_' . strval($id)))) {
                 $iedit_url = build_url(array('page' => 'cms_galleries', 'type' => '_ed', 'id' => $row['id']), get_module_zone('cms_galleries'));
             } else {
                 $iedit_url = new ocp_tempcode();
             }
             $_content = do_template('DOWNLOAD_SCREEN_IMAGE', array('_GUID' => 'fba0e309aa0ae04891e32c65a625b177', 'ID' => strval($row['id']), 'VIEW_URL' => $view_url, 'EDIT_URL' => $iedit_url, 'THUMB' => $thumb, 'COMMENT' => $comment));
             $_row->attach(do_template('DOWNLOAD_GALLERY_IMAGE_CELL', array('_GUID' => '8400a832dbed64bb63f264eb3a038895', 'CONTENT' => $_content)));
             if ($counter % $div == 1 && $counter != 0) {
                 $_out->attach(do_template('DOWNLOAD_GALLERY_ROW', array('_GUID' => '205c4f5387e98c534d5be1bdfcccdd7d', 'CELLS' => $_row)));
                 $_row = new ocp_tempcode();
             }
             $counter++;
         }
         if (!$_row->is_empty()) {
             $_out->attach(do_template('DOWNLOAD_GALLERY_ROW', array('_GUID' => 'e9667ca2545ac72f85a873f236cbbd6f', 'CELLS' => $_row)));
         }
         $images_details = $_out;
     }
     // Download link
     $author = $myrow['author'];
     $author_url = addon_installed('authors') ? build_url(array('page' => 'authors', 'type' => 'misc', 'id' => $author), get_module_zone('authors')) : new ocp_tempcode();
     // Licence
     $licence_title = NULL;
     $licence_url = NULL;
     $licence_hyperlink = NULL;
     $licence = $myrow['download_licence'];
     if (!is_null($licence)) {
         $licence_title = $GLOBALS['SITE_DB']->query_value_null_ok('download_licences', 'l_title', array('id' => $licence));
         if (!is_null($licence_title)) {
             $keep = symbol_tempcode('KEEP');
             $licence_url = find_script('download_licence') . '?id=' . strval($licence) . $keep->evaluate();
             $licence_hyperlink = do_template('HYPERLINK_POPUP_WINDOW', array('_GUID' => '10582f28c37ee7e9e462fdbd6a2cb8dd', 'TITLE' => '', 'CAPTION' => $licence_title, 'URL' => $licence_url, 'WIDTH' => '600', 'HEIGHT' => '500', 'REL' => 'license'));
         } else {
             $licence = NULL;
             // Orphaned
         }
     }
     breadcrumb_add_segment($tree, $title_to_use);
     $GLOBALS['META_DATA'] += array('created' => date('Y-m-d', $myrow['add_date']), 'creator' => $myrow['author'], 'publisher' => $GLOBALS['FORUM_DRIVER']->get_username($myrow['submitter']), 'modified' => is_null($myrow['edit_date']) ? '' : date('Y-m-d', $myrow['edit_date']), 'type' => 'Download', 'title' => get_translated_text($myrow['name']), 'identifier' => '_SEARCH:downloads:view:' . strval($id), 'description' => get_translated_text($myrow['description']), 'image' => $image_url);
     return do_template('DOWNLOAD_SCREEN', array('_GUID' => 'a9af438f84783d0d38c20b5f9a62dbdb', 'ORIGINAL_FILENAME' => $myrow['original_filename'], 'URL' => $myrow['url'], 'NUM_IMAGES' => strval($counter), 'TAGS' => get_loaded_tags('downloads'), 'LICENCE' => is_null($licence) ? NULL : strval($licence), 'LICENCE_TITLE' => $licence_title, 'LICENCE_HYPERLINK' => $licence_hyperlink, 'SUBMITTER' => strval($myrow['submitter']), 'EDIT_DATE' => $edit_date, 'EDIT_DATE_RAW' => is_null($myrow['edit_date']) ? '' : strval($myrow['edit_date']), 'VIEWS' => integer_format($myrow['download_views']), 'NAME' => $name, 'DATE' => $add_date, 'DATE_RAW' => strval($myrow['add_date']), 'NUM_DOWNLOADS' => integer_format($myrow['num_downloads']), 'TITLE' => $title, 'OUTMODE_URL' => $outmode_url, 'WARNING_DETAILS' => $warning_details, 'EDIT_URL' => $edit_url, 'ADD_IMG_URL' => $add_img_url, 'DESCRIPTION' => get_translated_tempcode($myrow['description']), 'ADDITIONAL_DETAILS' => $additional_details, 'IMAGES_DETAILS' => $images_details, 'ID' => strval($id), 'FILE_SIZE' => clean_file_size($myrow['file_size']), 'AUTHOR_URL' => $author_url, 'AUTHOR' => $author, 'TRACKBACK_DETAILS' => $trackback_details, 'RATING_DETAILS' => $rating_details, 'COMMENTS_DETAILS' => $comment_details));
 }
コード例 #7
0
ファイル: mail.php プロジェクト: erico-deh/ocPortal
/**
 * Attempt to send an e-mail to the specified recipient. The mail will be forwarding to the CC address specified in the options (if there is one, and if not specified not to cc).
 * The mail will be sent in dual HTML/text format, where the text is the unconverted comcode source: if a member does not read HTML mail, they may wish to fallback to reading that.
 *
 * @param  string			The subject of the mail in plain text
 * @param  LONG_TEXT		The message, as Comcode
 * @param  ?array			The destination (recipient) e-mail addresses [array of strings] (NULL: site staff address)
 * @param  ?mixed			The recipient name. Array or string. (NULL: site name)
 * @param  EMAIL			The from address (blank: site staff address)
 * @param  string			The from name (blank: site name)
 * @param  integer		The message priority (1=urgent, 3=normal, 5=low)
 * @range  1 5
 * @param  ?array			An list of attachments (each attachment being a map, path=>filename) (NULL: none)
 * @param  boolean		Whether to NOT CC to the CC address
 * @param  ?MEMBER		Convert comcode->tempcode as this member (a privilege thing: we don't want people being able to use admin rights by default!) (NULL: guest)
 * @param  boolean		Replace above with arbitrary admin
 * @param  boolean		HTML-only
 * @param  boolean		Whether to bypass queueing, because this code is running as a part of the queue management tools
 * @param  ID_TEXT		The template used to show the email
 * @param  boolean		Whether to bypass queueing
 * @return ?tempcode		A full page (not complete XHTML) piece of tempcode to output (NULL: it worked so no tempcode message)
 */
function mail_wrap($subject_tag, $message_raw, $to_email = NULL, $to_name = NULL, $from_email = '', $from_name = '', $priority = 3, $attachments = NULL, $no_cc = false, $as = NULL, $as_admin = false, $in_html = false, $coming_out_of_queue = false, $mail_template = 'MAIL', $bypass_queue = false)
{
    if (get_option('smtp_sockets_use') == '0') {
        return non_overrided__mail_wrap($subject_tag, $message_raw, $to_email, $to_name, $from_email, $from_name, $priority, $attachments, $no_cc, $as, $as_admin, $in_html, $coming_out_of_queue);
    }
    if (running_script('stress_test_loader')) {
        return NULL;
    }
    if (is_null($bypass_queue)) {
        $bypass_queue = $priority < 3 || strpos(serialize($attachments), 'tmpfile') !== false;
    }
    global $EMAIL_ATTACHMENTS;
    $EMAIL_ATTACHMENTS = array();
    require_code('site');
    require_code('mime_types');
    if (is_null($as)) {
        $as = $GLOBALS['FORUM_DRIVER']->get_guest_id();
    }
    if (!$coming_out_of_queue) {
        $GLOBALS['SITE_DB']->query('DELETE FROM ' . get_table_prefix() . 'logged_mail_messages WHERE m_date_and_time<' . strval(time() - 60 * 60 * 24 * 14) . ' AND m_queued=0');
        // Log it all for 2 weeks, then delete
        $through_queue = !$bypass_queue && (get_option('mail_queue_debug') === '1' || get_option('mail_queue') === '1' && cron_installed());
        $GLOBALS['SITE_DB']->query_insert('logged_mail_messages', array('m_subject' => $subject_tag, 'm_message' => $message_raw, 'm_to_email' => serialize($to_email), 'm_to_name' => serialize($to_name), 'm_from_email' => $from_email, 'm_from_name' => $from_name, 'm_priority' => 3, 'm_attachments' => serialize($attachments), 'm_no_cc' => $no_cc ? 1 : 0, 'm_as' => $as, 'm_as_admin' => $as_admin ? 1 : 0, 'm_in_html' => $in_html ? 1 : 0, 'm_date_and_time' => time(), 'm_member_id' => get_member(), 'm_url' => get_self_url(true), 'm_queued' => $through_queue ? 1 : 0, 'm_template' => $mail_template));
        if ($through_queue) {
            return NULL;
        }
    }
    if (count($attachments) == 0) {
        $attachments = NULL;
    }
    global $SENDING_MAIL;
    if ($SENDING_MAIL) {
        return NULL;
    }
    $SENDING_MAIL = true;
    // To and from, and language
    $staff_address = get_option('staff_address');
    if (is_null($to_email)) {
        $to_email = array($staff_address);
    }
    $to_email_new = array();
    foreach ($to_email as $test_address) {
        if ($test_address != '') {
            $to_email_new[] = $test_address;
        }
    }
    $to_email = $to_email_new;
    if ($to_email == array()) {
        $SENDING_MAIL = false;
        return NULL;
    }
    if ($to_email[0] == $staff_address) {
        $lang = get_site_default_lang();
    } else {
        $lang = user_lang();
        if (method_exists($GLOBALS['FORUM_DRIVER'], 'get_member_from_email_address')) {
            $member_id = $GLOBALS['FORUM_DRIVER']->get_member_from_email_address($to_email[0]);
            if (!is_null($member_id)) {
                $lang = get_lang($member_id);
            }
        }
    }
    if (is_null($to_name)) {
        if ($to_email[0] == $staff_address) {
            $to_name = get_site_name();
        } else {
            $to_name = '';
        }
    }
    if ($from_email == '') {
        $from_email = get_option('staff_address');
    }
    if ($from_name == '') {
        $from_name = get_site_name();
    }
    $theme = method_exists($GLOBALS['FORUM_DRIVER'], 'get_theme') ? $GLOBALS['FORUM_DRIVER']->get_theme() : 'default';
    if ($theme == 'default') {
        $theme = $GLOBALS['FORUM_DRIVER']->get_theme('');
        // ... So get theme of welcome zone
    }
    // Our subject
    $_subject = do_template('MAIL_SUBJECT', array('_GUID' => '44a57c666bb00f96723256e26aade9e5', 'SUBJECT_TAG' => $subject_tag), $lang, false, NULL, '.tpl', 'templates', $theme);
    $subject = $_subject->evaluate($lang);
    // Note that this is slightly against spec, because characters aren't forced to be printable us-ascii. But it's better we allow this (which works in practice) than risk incompatibility via charset-base64 encoding.
    // Evaluate message. Needs doing early so we know if we have any headers
    // Misc settings
    $website_email = get_option('website_email');
    if ($website_email == '') {
        $website_email = $from_email;
    }
    $cc_address = $no_cc ? '' : get_option("cc_address");
    global $CID_IMG_ATTACHMENT;
    $CID_IMG_ATTACHMENT = array();
    // Decide message
    $GLOBALS['NO_LINK_TITLES'] = true;
    global $LAX_COMCODE;
    $temp = $LAX_COMCODE;
    $LAX_COMCODE = true;
    $html_content = comcode_to_tempcode($message_raw, $as, $as_admin);
    $LAX_COMCODE = $temp;
    $GLOBALS['NO_LINK_TITLES'] = false;
    if (!$in_html) {
        $_html_content = $html_content->evaluate($lang);
        $_html_content = preg_replace('#(keep|for)_session=[\\d\\w]*#', 'filtered=1', $_html_content);
        $message_html = strpos($_html_content, '<html') !== false ? make_string_tempcode($_html_content) : do_template($mail_template, array('_GUID' => 'b23069c20202aa59b7450ebf8d49cde1', 'CSS' => '{CSS}', 'LOGOURL' => get_logo_url(''), 'LANG' => $lang, 'TITLE' => $subject, 'CONTENT' => $_html_content), $lang, false, NULL, '.tpl', 'templates', $theme);
        $css = css_tempcode(true, true, $message_html->evaluate($lang), $theme);
        $_css = $css->evaluate($lang);
        if (get_option('allow_ext_images') != '1') {
            $_css = preg_replace_callback('#url\\(["\']?(http://[^"]*)["\']?\\)#U', '_mail_css_rep_callback', $_css);
        }
        $html_evaluated = $message_html->evaluate($lang);
        $html_evaluated = str_replace('{CSS}', $_css, $html_evaluated);
        // Cleanup the Comcode a bit
        $message_plain = comcode_to_clean_text($message_raw);
    } else {
        $html_evaluated = $message_raw;
    }
    // Character set
    $regexp = '#^[\\x' . dechex(32) . '-\\x' . dechex(126) . ']*$#';
    $charset = preg_match($regexp, $html_evaluated) == 0 ? do_lang('charset', NULL, NULL, NULL, $lang) : 'us-ascii';
    // CID attachments
    if (get_option('allow_ext_images') != '1') {
        $html_evaluated = preg_replace_callback('#<img\\s([^>]*)src="(http://[^"]*)"#U', '_mail_img_rep_callback', $html_evaluated);
        $matches = array();
        foreach (array('#<([^"<>]*\\s)style="([^"]*)"#', '#<style( [^<>]*)?' . '>(.*)</style>#Us') as $over) {
            $num_matches = preg_match_all($over, $html_evaluated, $matches);
            for ($i = 0; $i < $num_matches; $i++) {
                $altered_inner = preg_replace_callback('#url\\(["\']?(http://[^"]*)["\']?\\)#U', '_mail_css_rep_callback', $matches[2][$i]);
                if ($matches[2][$i] != $altered_inner) {
                    $altered_outer = str_replace($matches[2][$i], $altered_inner, $matches[0][$i]);
                    $html_evaluated = str_replace($matches[0][$i], $altered_outer, $html_evaluated);
                }
            }
        }
    }
    $cid_attachments = array();
    foreach ($CID_IMG_ATTACHMENT as $id => $img) {
        $file_path_stub = convert_url_to_path($img);
        $mime_type = get_mime_type(get_file_extension($img));
        $filename = basename($img);
        if (!is_null($file_path_stub)) {
            $cid_attachment = array('mime' => $mime_type, 'filename' => $filename, 'path' => $file_path_stub, 'temp' => false, 'cid' => $id);
        } else {
            $myfile = ocp_tempnam('email_attachment');
            http_download_file($img, NULL, false, false, 'ocPortal', NULL, NULL, NULL, NULL, NULL, $myfile);
            if (!is_null($GLOBALS['HTTP_DOWNLOAD_MIME_TYPE'])) {
                $mime_type = $GLOBALS['HTTP_DOWNLOAD_MIME_TYPE'];
            }
            if (!is_null($GLOBALS['HTTP_FILENAME'])) {
                $filename = $GLOBALS['HTTP_FILENAME'];
            }
            $cid_attachment = array('mime' => $mime_type, 'filename' => $filename, 'path' => $myfile, 'temp' => true, 'cid' => $id);
        }
        $cid_attachments[] = $cid_attachment;
    }
    // Attachments
    $real_attachments = array();
    $attachments = array_merge(is_null($attachments) ? array() : $attachments, $EMAIL_ATTACHMENTS);
    if (!is_null($attachments)) {
        foreach ($attachments as $path => $filename) {
            $mime_type = get_mime_type(get_file_extension($filename));
            if (strpos($path, '://') === false) {
                $real_attachment = array('mime' => $mime_type, 'filename' => $filename, 'path' => $path, 'temp' => false);
            } else {
                $myfile = ocp_tempnam('email_attachment');
                http_download_file($path, NULL, false, false, 'ocPortal', NULL, NULL, NULL, NULL, NULL, $myfile);
                if (!is_null($GLOBALS['HTTP_DOWNLOAD_MIME_TYPE'])) {
                    $mime_type = $GLOBALS['HTTP_DOWNLOAD_MIME_TYPE'];
                }
                if (!is_null($GLOBALS['HTTP_FILENAME'])) {
                    $filename = $GLOBALS['HTTP_FILENAME'];
                }
                $real_attachment = array('mime' => $mime_type, 'filename' => $filename, 'path' => $myfile, 'temp' => true);
            }
            $real_attachments[] = $real_attachment;
        }
    }
    // ==========================
    // Interface with SwiftMailer
    // ==========================
    require_code('Swift-4.1.1/lib/swift_required');
    // Read in SMTP settings
    $host = get_option('smtp_sockets_host');
    $port = intval(get_option('smtp_sockets_port'));
    $username = get_option('smtp_sockets_username');
    $password = get_option('smtp_sockets_password');
    $smtp_from_address = get_option('smtp_from_address');
    if ($smtp_from_address != '') {
        $from_email = $smtp_from_address;
    }
    // Create the Transport
    $transport = Swift_SmtpTransport::newInstance($host, $port)->setUsername($username)->setPassword($password);
    if ($port == 419 || $port == 465 || $port == 587) {
        $transport->setEncryption('tls');
    }
    // Create the Mailer using your created Transport
    $mailer = Swift_Mailer::newInstance($transport);
    // Create a message
    $to_array = array();
    if ($to_name === '') {
        foreach ($to_email as $_to_email) {
            $to_array[] = $_to_email;
        }
    } else {
        foreach ($to_email as $i => $_to_email) {
            $to_array[$_to_email] = is_array($to_name) ? $to_name[$i] : $to_name;
        }
    }
    $message = Swift_Message::newInstance($subject)->setFrom(array($website_email => $from_name))->setReplyTo(array($from_email => $from_name))->setTo($to_array)->setPriority($priority)->setCharset($charset)->setBody($html_evaluated, 'text/html', $charset)->addPart($message_plain, 'text/plain', $charset);
    if ($cc_address != '') {
        $message->setCc($cc_address);
    }
    // Attachments
    foreach ($real_attachments as $r) {
        $attachment = Swift_Attachment::fromPath($r['path'], $r['mime'])->setFilename($r['filename'])->setDisposition('attachment');
        $message->attach($attachment);
    }
    foreach ($cid_attachments as $r) {
        $attachment = Swift_Attachment::fromPath($r['path'], $r['mime'])->setFilename($r['filename'])->setDisposition('attachment')->setId($r['cid']);
        $message->attach($attachment);
    }
    // Send the message, and error collection
    $error = '';
    try {
        $result = $mailer->send($message);
    } catch (Exception $e) {
        $error = $e->getMessage();
    }
    if ($error == '' && !$result) {
        $error = 'Unknown error';
    }
    // Attachment cleanup
    foreach ($real_attachments as $r) {
        if ($r['temp']) {
            @unlink($r['path']);
        }
    }
    foreach ($cid_attachments as $r) {
        if ($r['temp']) {
            @unlink($r['path']);
        }
    }
    // Return / Error handling
    $SENDING_MAIL = false;
    if ($error != '') {
        if (get_param_integer('keep_hide_mail_failure', 0) == 0) {
            require_code('site');
            attach_message(!is_null($error) ? make_string_tempcode($error) : do_lang_tempcode('MAIL_FAIL', escape_html(get_option('staff_address'))), 'warn');
        } else {
            return warn_screen(get_page_title('ERROR_OCCURRED'), do_lang_tempcode('MAIL_FAIL', escape_html(get_option('staff_address'))));
        }
    }
    return NULL;
}
コード例 #8
0
ファイル: points.php プロジェクト: erico-deh/ocPortal
 /**
  * The actualiser for a gift point transaction.
  *
  * @return tempcode		The UI
  */
 function do_give()
 {
     $member_id_of = get_param_integer('id');
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('USER_POINT_FIND')), array('_SELF:_SELF:member:id=' . strval($member_id_of), do_lang_tempcode('_POINTS', escape_html($GLOBALS['FORUM_DRIVER']->get_username($member_id_of))))));
     $title = get_page_title('POINTS');
     $trans_type = post_param('trans_type', 'gift');
     $amount = post_param_integer('amount');
     $reason = post_param('reason');
     $worked = false;
     $member_id_viewing = get_member();
     if ($member_id_of == $member_id_viewing && !has_specific_permission($member_id_viewing, 'give_points_self')) {
         $message = do_lang_tempcode('PE_SELF');
     } elseif (is_guest($member_id_viewing)) {
         $message = do_lang_tempcode('MUST_LOGIN');
     } else {
         if ($trans_type == 'gift') {
             $anonymous = post_param_integer('anonymous', 0);
             $viewer_gift_points_available = get_gift_points_to_give($member_id_viewing);
             //$viewer_gift_points_used=get_gift_points_used($member_id_viewing);
             if ($viewer_gift_points_available < $amount && !has_specific_permission($member_id_viewing, 'have_negative_gift_points')) {
                 $message = do_lang_tempcode('PE_LACKING_GIFT_POINTS');
             } elseif ($amount < 0 && !has_specific_permission($member_id_viewing, 'give_negative_points')) {
                 $message = do_lang_tempcode('PE_NEGATIVE_GIFT');
             } elseif ($reason == '') {
                 $message = do_lang_tempcode('IMPROPERLY_FILLED_IN');
             } else {
                 // Write transfer
                 require_code('points2');
                 give_points($amount, $member_id_of, $member_id_viewing, $reason, $anonymous == 1);
                 // Randomised gifts
                 if (mt_rand(0, 4) == 1) {
                     $message = do_lang_tempcode('PR_LUCKY');
                     $_current_gift = point_info($member_id_viewing);
                     $current_gift = array_key_exists('points_gained_given', $_current_gift) ? $_current_gift['points_gained_given'] : 0;
                     $GLOBALS['FORUM_DRIVER']->set_custom_field($member_id_viewing, 'points_gained_given', $current_gift + 25);
                     // TODO: 25 should be a config option
                 } else {
                     $message = do_lang_tempcode('PR_NORMAL');
                 }
                 $worked = true;
             }
         }
         if ($trans_type == 'refund') {
             $trans_type = 'charge';
             $amount = -$amount;
         }
         if ($trans_type == 'charge') {
             if (has_actual_page_access($member_id_viewing, 'adminzone')) {
                 require_code('points2');
                 charge_member($member_id_of, $amount, $reason);
                 $left = available_points($member_id_of);
                 $username = $GLOBALS['FORUM_DRIVER']->get_username($member_id_of);
                 if (is_null($username)) {
                     $username = do_lang('UNKNOWN');
                 }
                 $message = do_lang_tempcode('USER_HAS_BEEN_CHARGED', escape_html($username), escape_html(integer_format($amount)), escape_html(integer_format($left)));
                 $worked = true;
             } else {
                 access_denied('I_ERROR');
             }
         }
     }
     if ($worked) {
         // Show it worked / Refresh
         $url = build_url(array('page' => '_SELF', 'type' => 'member', 'id' => $member_id_of), '_SELF');
         return redirect_screen($title, $url, $message);
     } else {
         return warn_screen($title, $message);
     }
 }
コード例 #9
0
ファイル: newsletter.php プロジェクト: erico-deh/ocPortal
 /**
  * The UI for having confirmed an e-mail address onto the newsletter.
  *
  * @return tempcode		The UI
  */
 function newsletter_confirm_joining()
 {
     $title = get_page_title(get_option('newsletter_title'), false);
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', get_option('newsletter_title'))));
     $code_confirm = get_param_integer('confirm');
     $email = trim(get_param('email'));
     $correct_confirm = $GLOBALS['SITE_DB']->query_value('newsletter', 'code_confirm', array('email' => $email));
     if ($correct_confirm == $code_confirm) {
         $GLOBALS['SITE_DB']->query_update('newsletter', array('code_confirm' => 0), array('email' => $email), '', 1);
         return inform_screen($title, do_lang_tempcode('NEWSLETTER_CONFIRMED'));
     }
     return warn_screen($title, do_lang_tempcode($correct_confirm == 0 ? 'ALREADY_CONFIRMED' : 'INCORRECT_CONFIRMATION'));
 }
コード例 #10
0
 /**
  * Get the message for use in the purchase wizard
  *
  * @param  AUTO_LINK		The product in question.
  * @return tempcode		The message.
  */
 function get_message($product)
 {
     require_code('catalogues');
     $catalogue_name = $GLOBALS['SITE_DB']->query_value('catalogue_entries', 'c_name', array('id' => $product));
     $catalogues = $GLOBALS['SITE_DB']->query_select('catalogues', array('*'), array('c_name' => $catalogue_name), '', 1);
     if (!array_key_exists(0, $catalogues)) {
         warn_exit(do_lang_tempcode('CATALOGUE_NOT_FOUND', $catalogue_name));
     }
     $catalogue = $catalogues[0];
     $entries = $GLOBALS['SITE_DB']->query_select('catalogue_entries', array('*'), array('id' => $product), '', 1);
     if (!array_key_exists(0, $entries)) {
         return warn_screen(get_page_title('CATALOGUES'), do_lang_tempcode('MISSING_RESOURCE'));
     }
     $entry = $entries[0];
     $map = get_catalogue_entry_map($entry, $catalogue, 'PAGE', $catalogue_name, $product, NULL, NULL, true, true);
     return do_template('ECOMMERCE_ITEM_DETAILS', $map, NULL, false, 'ECOMMERCE_ITEM_DETAILS');
 }
コード例 #11
0
ファイル: ocdeadpeople.php プロジェクト: erico-deh/ocPortal
 /**
  * Standard actualisation stage of pointstore item purchase.
  *
  * @return tempcode		The UI
  */
 function action_done()
 {
     $class = str_replace('hook_pointstore_', '', strtolower(get_class($this)));
     $disease_id = get_param('disease', 0);
     $member_id = get_member();
     //default values
     $sick = 0;
     $get_cure = get_param_integer('cure', 0);
     $get_immunization = get_param_integer('immunization', 0);
     $cure = $get_cure == 1 ? 1 : 0;
     $immunization = $get_immunization == 1 ? 1 : 0;
     $member_rows = $GLOBALS['SITE_DB']->query_select('members_diseases', array('*'), array('user_id' => $member_id, 'disease_id' => $disease_id));
     $insert = true;
     if (isset($member_rows[0]['user_id']) && $member_rows[0]['user_id'] != 0) {
         //there is already a db member disease record
         $insert = false;
         $sick = $get_cure == 1 && $member_rows[0]['sick'] == 1 ? 0 : $sick;
     } else {
         //we should insert a new db member disease record
     }
     $rows = $GLOBALS['SITE_DB']->query_select('diseases', array('*'), array('id' => $disease_id));
     $cure_price = isset($rows[0]['cure_price']) && intval($rows[0]['cure_price']) > 0 ? intval($rows[0]['cure_price']) : 0;
     $immunization_price = isset($rows[0]['immunisation_price']) && intval($rows[0]['immunisation_price']) > 0 ? intval($rows[0]['immunisation_price']) : 0;
     $amount = $get_immunization == 1 ? $immunization_price : $cure_price;
     $title = get_page_title('DISEASES_CURES_IMMUNIZATIONS_TITLE');
     // Check points
     $points_left = available_points(get_member());
     if (!has_specific_permission(get_member(), 'give_points_self')) {
         if ($points_left < $amount) {
             return warn_screen($title, do_lang_tempcode('_CANT_AFFORD_THIS'));
         }
     }
     // Actuate
     require_code('points2');
     if ($get_immunization == 1) {
         charge_member(get_member(), $amount, do_lang('IMMUNIZATION_PURCHASED'));
     } else {
         charge_member(get_member(), $amount, do_lang('CURE_PURCHASED'));
     }
     if ($insert) {
         $GLOBALS['SITE_DB']->query_insert('members_diseases', array('user_id' => $member_id, 'disease_id' => $disease_id, 'sick' => strval($sick), 'cure' => strval($cure), 'immunisation' => strval($immunization)));
     } else {
         $GLOBALS['SITE_DB']->query_update('members_diseases', array('user_id' => $member_id, 'disease_id' => $disease_id, 'sick' => strval($sick), 'cure' => strval($cure), 'immunisation' => strval($immunization)), array('user_id' => $member_id, 'disease_id' => $disease_id), '', 1);
     }
     if ($get_immunization == 1) {
         // Show message
         $result = do_lang_tempcode('IMMUNIZATION_CONGRATULATIONS');
     } else {
         // Show message
         $result = do_lang_tempcode('CURE_CONGRATULATIONS');
     }
     $url = build_url(array('page' => '_SELF', 'type' => 'misc'), '_SELF');
     return redirect_screen($title, $url, $result);
 }
コード例 #12
0
ファイル: admin_addons.php プロジェクト: erico-deh/ocPortal
 /**
  * The UI to retrieve a specified addon.
  *
  * @return tempcode		The UI
  */
 function _addon_import()
 {
     $title = get_page_title('IMPORT_ADDON');
     require_code('uploads');
     $url = post_param('url', '');
     if (is_numeric($url)) {
         $_POST['url'] = 'http://ocportal.com/site/dload.php?id=' . $url;
     } else {
         $_POST['url'] = $url;
         // In case it was submitted in array form, which is possible on some UAs (based on an automated bug report)
     }
     //		if ($url=='')
     //		{
     $urls = get_url('url', 'file', 'imports/mods', 0, 0, false, '', '', true);
     //		}
     //		else
     //		{
     //			$urls=array($url);
     //		}
     $full = get_custom_file_base() . '/' . $urls[0];
     if (strtolower(substr($full, -4)) != '.tar') {
         return warn_screen(get_page_title('ERROR_OCCURRED'), do_lang_tempcode('ADDON_NOT_TAR'));
     }
     // Show it worked / Refresh
     $_url = build_url(array('page' => '_SELF', 'type' => 'addon_install', 'file' => basename($urls[0])), '_SELF');
     return redirect_screen($title, $_url, do_lang_tempcode('ADDON_IMPORTED'));
 }
コード例 #13
0
ファイル: custom.php プロジェクト: erico-deh/ocPortal
 /**
  * Standard actualisation stage of pointstore item purchase.
  *
  * @return tempcode		The UI
  */
 function action_done()
 {
     $class = str_replace('hook_pointstore_', '', strtolower(get_class($this)));
     post_param_integer('confirm');
     // Make sure POSTed
     $id = get_param_integer('sub_id');
     $rows = $GLOBALS['SITE_DB']->query_select('pstore_customs', array('id', 'c_title', 'c_cost', 'c_one_per_member'), array('id' => $id, 'c_enabled' => 1));
     if (!array_key_exists(0, $rows)) {
         warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
     }
     $cost = $rows[0]['c_cost'];
     $c_title = get_translated_text($rows[0]['c_title']);
     $title = get_page_title('PURCHASE_SOME_PRODUCT', true, array(escape_html($c_title)));
     // Check points
     $points_left = available_points(get_member());
     if ($points_left < $cost && !has_specific_permission(get_member(), 'give_points_self')) {
         return warn_screen($title, do_lang_tempcode('_CANT_AFFORD', integer_format($cost), integer_format($points_left)));
     }
     if ($rows[0]['c_one_per_member'] == 1) {
         // Test to see if it's been bought
         $test = $GLOBALS['SITE_DB']->query_value_null_ok('sales', 'id', array('purchasetype' => 'PURCHASE_CUSTOM_PRODUCT', 'details2' => strval($rows[0]['id']), 'memberid' => get_member()));
         if (!is_null($test)) {
             warn_exit(do_lang_tempcode('ONE_PER_MEMBER_ONLY'));
         }
     }
     require_code('points2');
     charge_member(get_member(), $cost, $c_title);
     $sale_id = $GLOBALS['SITE_DB']->query_insert('sales', array('date_and_time' => time(), 'memberid' => get_member(), 'purchasetype' => 'PURCHASE_CUSTOM_PRODUCT', 'details' => $c_title, 'details2' => strval($rows[0]['id'])), true);
     require_code('notifications');
     $subject = do_lang('MAIL_REQUEST_CUSTOM', comcode_escape($c_title), NULL, NULL, get_site_default_lang());
     $username = $GLOBALS['FORUM_DRIVER']->get_username(get_member());
     $message_raw = do_lang('MAIL_REQUEST_CUSTOM_BODY', comcode_escape($c_title), $username, NULL, get_site_default_lang());
     dispatch_notification('pointstore_request_custom', 'custom' . strval($id) . '_' . strval($sale_id), $subject, $message_raw, NULL, NULL, 3, true);
     // Show message
     $url = build_url(array('page' => '_SELF', 'type' => 'misc'), '_SELF');
     return redirect_screen($title, $url, do_lang_tempcode('ORDER_GENERAL_DONE'));
 }
コード例 #14
0
ファイル: catalogues.php プロジェクト: erico-deh/ocPortal
 /**
  * The UI to show a catalogue A-Z screen.
  *
  * @return tempcode		The UI
  */
 function view_catalogue_category_entries()
 {
     $id = get_param_integer('id', -1);
     if ($id == -1) {
         $id = $GLOBALS['SITE_DB']->query_value('catalogue_categories', 'MIN(id)', array('c_name' => get_param('catalogue_name'), 'cc_parent_id' => NULL));
     }
     $GLOBALS['FEED_URL'] = find_script('backend') . '?mode=catalogues&filter=' . strval($id);
     $categories = $GLOBALS['SITE_DB']->query_select('catalogue_categories', array('*'), array('id' => $id), '', 1);
     if (!array_key_exists(0, $categories)) {
         return warn_screen(get_page_title('CATALOGUES'), do_lang_tempcode('MISSING_RESOURCE'));
     }
     $category = $categories[0];
     // Permission for here?
     if (!has_category_access(get_member(), 'catalogues_catalogue', $category['c_name'])) {
         access_denied('CATALOGUE_ACCESS');
     }
     $catalogue_name = $category['c_name'];
     $root = get_param_integer('root', NULL);
     $category = $GLOBALS['SITE_DB']->query_value('catalogue_categories', 'cc_title', array('id' => $id));
     $category_name = get_translated_text($category);
     $catalogues = $GLOBALS['SITE_DB']->query_select('catalogues', array('*'), array('c_name' => $catalogue_name), '', 1);
     if (!array_key_exists(0, $catalogues)) {
         warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
     }
     $catalogue = $catalogues[0];
     $tpl_set = $catalogue_name;
     $category_buildup = new ocp_tempcode();
     $max = NULL;
     $start = NULL;
     require_code('ocfiltering');
     $sql_filter = ocfilter_to_sqlfragment(strval($id) . '*', 'cc_id', 'catalogue_categories', 'cc_parent_id', 'cc_id', 'id');
     // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set)
     if ($GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . get_table_prefix() . 'catalogue_entries p WHERE ce_validated=1 AND (' . $sql_filter . ')') > 1000) {
         warn_exit(do_lang_tempcode('TOO_MANY_TO_CHOOSE_FROM'));
     }
     $cats = array();
     $rows = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'catalogue_entries p WHERE ce_validated=1 AND (' . $sql_filter . ')');
     foreach ($rows as $row) {
         $entry_map = get_catalogue_entry_map($row, $catalogue, 'CATEGORY', 'DEFAULT', $root, NULL, array(0), false, false);
         $letter = strtoupper(substr(is_object($entry_map['FIELD_0_PLAIN']) ? $entry_map['FIELD_0_PLAIN']->evaluate() : $entry_map['FIELD_0_PLAIN'], 0, 1));
         if (get_value('disable_cat_cat_perms') !== '1' && !has_category_access(get_member(), 'catalogues_category', strval($row['id']))) {
             continue;
         }
         if (!array_key_exists($letter, $cats)) {
             $cats[$letter] = array();
         }
         $cats[$letter][] = $row;
     }
     unset($rows);
     ksort($cats);
     foreach ($cats as $letter => $entries) {
         list($entry_buildup) = get_catalogue_category_entry_buildup(NULL, $catalogue_name, $catalogue, 'CATEGORY', $tpl_set, $max, $start, NULL, $root, NULL, true, $entries);
         $category_buildup->attach(do_template('CATALOGUE_CATEGORY_HEADING', array('LETTER' => is_integer($letter) ? strval($letter) : $letter, 'ENTRIES' => escape_html($entry_buildup)), NULL, false, 'CATALOGUE_CATEGORY_HEADING'));
     }
     $_title = get_translated_text($category);
     $title_to_use = do_lang_tempcode('DEFAULT__CATALOGUE_CATEGORY_ATOZ', escape_html($_title));
     $title = get_page_title($title_to_use, false);
     //Link to add to catalogue category
     if (has_actual_page_access(NULL, 'cms_catalogues', NULL, get_value('disable_cat_cat_perms') === '1' ? array('catalogues_catalogue', $catalogue_name) : array('catalogues_catalogue', $catalogue_name, 'catalogues_category', strval($id)), 'submit_midrange_content')) {
         $add_link = build_url(array('page' => 'cms_catalogues', 'type' => 'add_entry', 'catalogue_name' => $catalogue_name, 'category_id' => $id), get_module_zone('cms_catalogues'));
     } else {
         $add_link = new ocp_tempcode();
     }
     if (has_actual_page_access(NULL, 'cms_catalogues', NULL, get_value('disable_cat_cat_perms') === '1' ? array('catalogues_catalogue', $catalogue_name) : array('catalogues_catalogue', $catalogue_name, 'catalogues_category', strval($id)), 'submit_cat_midrange_content')) {
         $add_cat_url = build_url(array('page' => 'cms_catalogues', 'type' => 'add_category', 'catalogue_name' => $catalogue_name, 'parent_id' => $id), get_module_zone('cms_catalogues'));
     } else {
         $add_cat_url = new ocp_tempcode();
     }
     if (has_actual_page_access(NULL, 'cms_catalogues', NULL, get_value('disable_cat_cat_perms') === '1' ? array('catalogues_catalogue', $catalogue_name) : array('catalogues_catalogue', $catalogue_name, 'catalogues_category', strval($id)), 'edit_cat_midrange_content')) {
         $edit_cat_url = build_url(array('page' => 'cms_catalogues', 'type' => '_edit_category', 'catalogue_name' => $catalogue_name, 'id' => $id), get_module_zone('cms_catalogues'));
     } else {
         $edit_cat_url = new ocp_tempcode();
     }
     if (has_actual_page_access(NULL, 'cms_catalogues', NULL, get_value('disable_cat_cat_perms') === '1' ? array('catalogues_catalogue', $catalogue_name) : array('catalogues_catalogue', $catalogue_name), 'edit_cat_highrange_content')) {
         $edit_catalogue_url = build_url(array('page' => 'cms_catalogues', 'type' => '_edit_catalogue', 'id' => $catalogue_name), get_module_zone('cms_catalogues'));
     } else {
         $edit_catalogue_url = new ocp_tempcode();
     }
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc' . ($catalogue['c_ecommerce'] == 1 ? ':ecommerce=1' : ''), do_lang_tempcode('CATALOGUES'))));
     return do_template('CATALOGUE_' . $tpl_set . '_CATEGORY_SCREEN', array('TITLE' => $title, 'CART_LINK' => '', '_TITLE' => $_title, 'TAGS' => get_loaded_tags('catalogue_categories'), 'CATALOGUE' => $catalogue_name, 'BROWSER' => '', 'SORTING' => '', 'ADD_LINK' => $add_link, 'ADD_CAT_URL' => $add_cat_url, 'EDIT_CAT_URL' => $edit_cat_url, 'EDIT_CATALOGUE_URL' => $edit_catalogue_url, 'ENTRIES' => $category_buildup, 'SUBCATEGORIES' => '', 'DESCRIPTION' => ''), NULL, false, 'CATALOGUE_DEFAULT_CATEGORY_SCREEN');
 }
コード例 #15
0
ファイル: downloads.php プロジェクト: erico-deh/ocPortal
 /**
  * The UI to show download statistics.
  *
  * @param  object			The stats module object
  * @param  string			The screen type
  * @return tempcode		The UI
  */
 function downloads($ob, $type)
 {
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('SITE_STATISTICS'))));
     require_lang('downloads');
     //This will show a plain bar chart with all the downloads listed
     $title = get_page_title('SECTION_DOWNLOADS');
     // Handle time range
     if (get_param_integer('dated', 0) == 0) {
         $title = get_page_title('SECTION_DOWNLOADS');
         return $ob->get_between($title, false, NULL, do_lang_tempcode('DOWNLOAD_STATS_RANGE'));
     }
     $time_start = get_input_date('time_start', true);
     $time_end = get_input_date('time_end', true);
     if (!is_null($time_end)) {
         $time_end += 60 * 60 * 24 - 1;
     }
     // So it is end of day not start
     if (is_null($time_start) && is_null($time_end)) {
         $rows = $GLOBALS['SITE_DB']->query_select('download_downloads', array('id', 'num_downloads', 'name'));
     } else {
         if (is_null($time_start)) {
             $time_start = 0;
         }
         if (is_null($time_end)) {
             $time_end = time();
         }
         $title = get_page_title('SECTION_DOWNLOADS_RANGE', true, array(escape_html(get_timezoned_date($time_start, false)), escape_html(get_timezoned_date($time_end, false))));
         $rows = $GLOBALS['SITE_DB']->query('SELECT id,num_downloads,name FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'download_downloads WHERE add_date>' . strval($time_start) . ' AND add_date<' . strval($time_end));
     }
     //$rows=array(array('id'=>1,'num_downloads'=>10,'name'=>3),array('id'=>2,'num_downloads'=>20,'name'=>4));
     if (count($rows) < 1) {
         return warn_screen($title, do_lang_tempcode('NO_DATA'));
     }
     $downloads = array();
     foreach ($rows as $i => $row) {
         if (!array_key_exists('num_downloads', $row)) {
             $row['num_downloads'] = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'download_logging WHERE id=' . strval($row['id']));
             $rows[$i] = $row;
         }
         $downloads[get_translated_text($row['name']) . ' (#' . strval($row['id']) . ')'] = $row['num_downloads'];
     }
     $start = get_param_integer('start', 0);
     $max = get_param_integer('max', 30);
     $csv = get_param_integer('csv', 0) == 1;
     if ($csv) {
         if (function_exists('set_time_limit')) {
             @set_time_limit(0);
         }
         $start = 0;
         $max = 10000;
     }
     $sortables = array('num_downloads' => do_lang_tempcode('COUNT_DOWNLOADS'));
     $test = explode(' ', get_param('sort', 'num_downloads DESC'), 2);
     if (count($test) == 1) {
         $test[1] = 'DESC';
     }
     list($sortable, $sort_order) = $test;
     if (strtoupper($sort_order) != 'ASC' && strtoupper($sort_order) != 'DESC' || !array_key_exists($sortable, $sortables)) {
         log_hack_attack_and_exit('ORDERBY_HACK');
     }
     global $NON_CANONICAL_PARAMS;
     $NON_CANONICAL_PARAMS[] = 'sort';
     if ($sort_order == 'ASC') {
         asort($downloads);
     } else {
         arsort($downloads);
     }
     require_code('templates_results_table');
     $fields_title = results_field_title(array(do_lang_tempcode('TITLE'), do_lang_tempcode('COUNT_DOWNLOADS')), $sortables, 'sort', $sortable . ' ' . $sort_order);
     $fields = new ocp_tempcode();
     $real_data = array();
     $i = 0;
     foreach ($downloads as $download_name => $value) {
         if ($i < $start) {
             $i++;
             continue;
         } elseif ($i >= $start + $max) {
             break;
         }
         $fields->attach(results_entry(array(escape_html($download_name), escape_html(integer_format($value)))));
         $real_data[] = array('Download name' => $download_name, 'Tally' => $value);
         $i++;
     }
     $list = results_table(do_lang_tempcode('SECTION_DOWNLOADS'), $start, 'start', $max, 'max', count($downloads), $fields_title, $fields, $sortables, $sortable, $sort_order, 'sort', new ocp_tempcode());
     if ($csv) {
         make_csv($real_data, 'download_stats.csv');
     }
     $output = create_bar_chart(array_slice($downloads, $start, $max), do_lang('TITLE'), do_lang('COUNT_DOWNLOADS'), '', '');
     $ob->save_graph('Global-Downloads', $output);
     $graph = do_template('STATS_GRAPH', array('GRAPH' => get_custom_base_url() . '/data_custom/modules/admin_stats/Global-Downloads.xml', 'TITLE' => do_lang_tempcode('SECTION_DOWNLOADS'), 'TEXT' => do_lang_tempcode('DESCRIPTION_DOWNLOADS_STATISTICS')));
     return do_template('STATS_SCREEN', array('_GUID' => '4b8e0478231473d690e947ffc4580840', 'TITLE' => $title, 'GRAPH' => $graph, 'STATS' => $list));
 }
コード例 #16
0
ファイル: search.php プロジェクト: erico-deh/ocPortal
 /**
  * The UI to show top search keywords.
  *
  * @param  object			The stats module object
  * @param  string			The screen type
  * @return tempcode		The UI
  */
 function search($ob, $type)
 {
     // Handle time range
     if (get_param_integer('dated', 0) == 0) {
         $title = get_page_title('SEARCH_STATISTICS');
         return $ob->get_between($title);
     }
     $time_start = get_input_date('time_start', true);
     $time_end = get_input_date('time_end', true);
     if (!is_null($time_end)) {
         $time_end += 60 * 60 * 24 - 1;
     }
     // So it is end of day not start
     if (is_null($time_start)) {
         $time_start = 0;
     }
     if (is_null($time_end)) {
         $time_end = time();
     }
     $title = get_page_title('SEARCH_STATISTICS_RANGE', true, array(escape_html(get_timezoned_date($time_start, false)), escape_html(get_timezoned_date($time_end, false))));
     $start = get_param_integer('start', 0);
     $max = get_param_integer('max', 20);
     $sortables = array('s_primary' => do_lang_tempcode('SEARCH_STATISTICS'));
     $test = explode(' ', get_param('sort', 's_primary DESC'), 2);
     if (count($test) == 1) {
         $test[1] = 'DESC';
     }
     list($sortable, $sort_order) = $test;
     if (strtoupper($sort_order) != 'ASC' && strtoupper($sort_order) != 'DESC' || !array_key_exists($sortable, $sortables)) {
         log_hack_attack_and_exit('ORDERBY_HACK');
     }
     global $NON_CANONICAL_PARAMS;
     $NON_CANONICAL_PARAMS[] = 'sort';
     $rows = $GLOBALS['SITE_DB']->query('SELECT s_primary,COUNT(*) AS cnt FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'searches_logged WHERE s_time>' . strval((int) $time_start) . ' AND s_time<' . strval((int) $time_end) . ' GROUP BY s_primary ORDER BY ' . $sortable . ' ' . $sort_order);
     if (count($rows) < 1) {
         return warn_screen($title, do_lang_tempcode('NO_DATA'));
     }
     $keywords = array();
     $total = 0;
     foreach ($rows as $value) {
         $keywords[$value['s_primary']] = $value['cnt'];
         $total += $value['cnt'];
     }
     if ($sort_order == 'ASC') {
         asort($keywords);
     } else {
         arsort($keywords);
     }
     require_code('templates_results_table');
     $fields_title = results_field_title(array(do_lang_tempcode('KEYWORD'), do_lang_tempcode('COUNT_VIEWS')), $sortables, 'sort', $sortable . ' ' . $sort_order);
     $fields = new ocp_tempcode();
     $degrees = 360 / $total;
     $done_total = 0;
     //$done=0;
     $data = array();
     $i = 0;
     foreach ($keywords as $keyword => $views) {
         if ($i < $start) {
             $i++;
             continue;
         } elseif ($i >= $start + $max) {
             break;
         }
         if ($keyword == '') {
             $link = do_lang_tempcode('SEARCH_STATS_ADVANCED');
         } else {
             $link = protect_from_escaping(escape_html($keyword));
         }
         $fields->attach(results_entry(array($link, integer_format($views)), true));
         //if ($done<20)
         //{
         $data[$keyword] = $keywords[$keyword] * $degrees;
         //$done++;
         $done_total += $data[$keyword];
         //}
         $i++;
     }
     if (360 - $done_total > 0) {
         $data[do_lang('OTHER')] = 360 - $done_total;
         $fields->attach(results_entry(array(do_lang('OTHER'), float_format((360 - $done_total) / $degrees))));
     }
     $list = results_table(do_lang_tempcode('SEARCH_STATISTICS'), $start, 'start', $max, 'max', count($keywords), $fields_title, $fields, $sortables, $sortable, $sort_order, 'sort', new ocp_tempcode());
     $output = create_pie_chart($data);
     $ob->save_graph('Global-Search', $output);
     $graph = do_template('STATS_GRAPH', array('GRAPH' => get_custom_base_url() . '/data_custom/modules/admin_stats/Global-Search.xml', 'TITLE' => do_lang_tempcode('SEARCH_STATISTICS'), 'TEXT' => do_lang_tempcode('DESCRIPTION_SEARCH_STATISTICS')));
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('SITE_STATISTICS'))));
     return do_template('STATS_SCREEN', array('_GUID' => '727a59e061727c4a1e24345cecb769aa', 'TITLE' => $title, 'GRAPH' => $graph, 'STATS' => $list));
 }
コード例 #17
0
ファイル: highlight_name.php プロジェクト: erico-deh/ocPortal
 /**
  * Standard actualisation stage of pointstore item purchase.
  *
  * @return tempcode		The UI
  */
 function action_done()
 {
     $class = str_replace('hook_pointstore_', '', strtolower(get_class($this)));
     if (get_option('is_on_' . $class . '_buy') == '0' || get_forum_type() != 'ocf') {
         return new ocp_tempcode();
     }
     if ($GLOBALS['FORUM_DRIVER']->get_member_row_field(get_member(), 'm_highlighted_name') == 1) {
         warn_exit(do_lang_tempcode('_ALREADY_HAVE'));
     }
     $title = get_page_title('NAME_HIGHLIGHTING');
     post_param_integer('confirm');
     // To make sure we're not being passed by a GET
     // Check points
     $cost = intval(get_option($class));
     $points_left = available_points(get_member());
     if ($points_left < $cost && !has_specific_permission(get_member(), 'give_points_self')) {
         return warn_screen($title, do_lang_tempcode('_CANT_AFFORD', integer_format($cost), integer_format($points_left)));
     }
     // Actuate
     $GLOBALS['FORUM_DB']->query_update('f_members', array('m_highlighted_name' => 1), array('id' => get_member()), '', 1);
     require_code('points2');
     charge_member(get_member(), $cost, do_lang('NAME_HIGHLIGHTING'));
     $GLOBALS['SITE_DB']->query_insert('sales', array('date_and_time' => time(), 'memberid' => get_member(), 'purchasetype' => 'NAME_HIGHLIGHTING', 'details' => '', 'details2' => ''));
     // Show message
     $url = build_url(array('page' => '_SELF', 'type' => 'misc'), '_SELF');
     return redirect_screen($title, $url, do_lang_tempcode('ORDER_GENERAL_DONE'));
 }
コード例 #18
0
ファイル: admin_themes.php プロジェクト: erico-deh/ocPortal
 /**
  * The actualiser to edit a theme image.
  *
  * @return tempcode		The UI
  */
 function _edit_image()
 {
     require_code('uploads');
     $title = get_page_title('EDIT_THEME_IMAGE');
     $lang = choose_language($title, true, true);
     if (is_object($lang)) {
         return $lang;
     }
     $theme = post_param('theme');
     //if ((get_file_base()!=get_custom_file_base()) && ($theme=='default')) warn_exit(do_lang_tempcode('SHARED_INSTALL_PROHIBIT'));
     $id = post_param('id');
     $old_id = post_param('old_id');
     if (post_param_integer('delete', 0) == 1) {
         require_code('themes3');
         actual_delete_theme_image($old_id, $theme, $lang);
     } else {
         $path = get_url('path', 'file', 'themes/' . $theme . '/images_custom');
         if (url_is_local($path[0]) && !file_exists((substr($path[0], 0, 15) == 'themes/default/' ? get_file_base() : get_custom_file_base()) . '/' . rawurldecode($path[0]))) {
             warn_screen($title, do_lang_tempcode('IMPROPERLY_FILLED_IN_UPLOAD'));
         }
         if ($path[0] == '') {
             return warn_screen($title, do_lang_tempcode('IMPROPERLY_FILLED_IN_UPLOAD'));
         }
         actual_edit_theme_image($old_id, $theme, $lang, $id, $path[0]);
     }
     persistant_cache_delete('THEME_IMAGES');
     erase_cached_templates();
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('MANAGE_THEMES')), array('_SELF:_SELF:manage_images:theme=' . $theme, do_lang_tempcode('CHOOSE')), array('_SELF:_SELF:edit_theme_image:id=' . $id, do_lang_tempcode('EDIT_THEME_IMAGE'))));
     breadcrumb_set_self(do_lang_tempcode('DONE'));
     return $this->do_next_manager($title, do_lang_tempcode('SUCCESS'), $theme, $lang, 'image', $id);
 }
コード例 #19
0
 /**
  * The UI to show OCF demographics.
  *
  * @param  object			The stats module object
  * @param  string			The screen type
  * @return tempcode		The UI
  */
 function demographics($ob, $type)
 {
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('SITE_STATISTICS'))));
     require_lang('ocf');
     //This will show a plain bar chart with all the downloads listed
     $title = get_page_title('DEMOGRAPHICS');
     // Handle time range
     if (get_param_integer('dated', 0) == 0) {
         $title = get_page_title('DEMOGRAPHICS');
         return $ob->get_between($title, false, NULL, do_lang_tempcode('DEMOGRAPHICS_STATS_RANGE'));
     }
     $time_start = get_input_date('time_start', true);
     $time_end = get_input_date('time_end', true);
     if (!is_null($time_end)) {
         $time_end += 60 * 60 * 24 - 1;
     }
     // So it is end of day not start
     if (is_null($time_start) && is_null($time_end)) {
         $rows = $GLOBALS['FORUM_DB']->query_select('f_members', array('m_dob_year', 'COUNT(*) AS cnt', NULL, 'GROUP BY m_dob_year'));
     } else {
         if (is_null($time_start)) {
             $time_start = 0;
         }
         if (is_null($time_end)) {
             $time_end = time();
         }
         $title = get_page_title('SECTION_DEMOGRAPHICS_RANGE', true, array(escape_html(get_timezoned_date($time_start, false)), escape_html(get_timezoned_date($time_end, false))));
         $rows = $GLOBALS['FORUM_DB']->query('SELECT m_dob_year,COUNT(*) AS cnt FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_members WHERE m_join_time>' . strval($time_start) . ' AND m_join_time<' . strval($time_end) . ' GROUP BY m_dob_year');
     }
     if (count($rows) < 1) {
         return warn_screen($title, do_lang_tempcode('NO_DATA'));
     }
     // Gather data
     $demographics = array();
     $demographics[do_lang('UNKNOWN')] = 0;
     for ($i = 0; $i < 30; $i++) {
         $demographics[strval($i)] = 0;
     }
     for ($i = 30; $i < 100; $i += 5) {
         $demographics[strval($i) . '-' . strval($i + 4)] = 0;
     }
     $demographics['100+'] = 0;
     list($current_day, $current_month, $current_year) = explode(' ', date('j m Y', utctime_to_usertime(time())));
     foreach ($rows as $i => $row) {
         $day = 1;
         $month = 1;
         $year = $row['m_dob_year'];
         if (!is_null($year)) {
             $age = intval($current_year) - $year;
             if ($age < 0) {
                 $age = 0;
             }
             if ($age >= 100) {
                 $age_string = '100+';
             } elseif ($age >= 30) {
                 $age_string = strval(intval($age / 5) * 5) . '-' . strval(intval($age / 5) * 5 + 4);
             } else {
                 $age_string = strval($age);
             }
             $demographics[$age_string] += array_key_exists('cnt', $row) ? $row['cnt'] : 1;
         } else {
             $demographics[do_lang('UNKNOWN')] += array_key_exists('cnt', $row) ? $row['cnt'] : 1;
         }
     }
     $start = 0;
     $max = 1000;
     // Little trick, as we want all to fit
     $sortables = array();
     require_code('templates_results_table');
     $fields_title = results_field_title(array(do_lang_tempcode('AGE'), do_lang_tempcode('COUNT_TOTAL')), $sortables);
     $fields = new ocp_tempcode();
     $i = 0;
     foreach ($demographics as $_age => $value) {
         if (is_integer($_age)) {
             $_age = strval($_age);
         }
         $percent = round(100.0 * floatval($value) / floatval(count($rows)), 2);
         $fields->attach(results_entry(array(escape_html($_age), escape_html(integer_format($value) . ' (' . float_format($percent) . '%)'))));
         $i++;
     }
     $list = results_table(do_lang_tempcode('DEMOGRAPHICS'), $start, 'start', $max, 'max', count($demographics), $fields_title, $fields, $sortables, '', '', 'sort', new ocp_tempcode());
     $output = create_bar_chart($demographics, do_lang('AGE'), do_lang('COUNT_TOTAL'), '', '');
     $ob->save_graph('Global-Demographics', $output);
     $graph = do_template('STATS_GRAPH', array('GRAPH' => get_custom_base_url() . '/data_custom/modules/admin_stats/Global-Demographics.xml', 'TITLE' => do_lang_tempcode('DEMOGRAPHICS'), 'TEXT' => do_lang_tempcode('DESCRIPTION_DEMOGRAPHICS')));
     return do_template('STATS_SCREEN', array('TITLE' => $title, 'NO_CSV' => '1', 'GRAPH' => $graph, 'STATS' => $list));
 }
コード例 #20
0
ファイル: pop3.php プロジェクト: erico-deh/ocPortal
 /**
  * Standard stage of pointstore item purchase.
  *
  * @return tempcode		The UI
  */
 function _buyquota()
 {
     if (get_option('is_on_pop3_buy') == '0') {
         return new ocp_tempcode();
     }
     $title = get_page_title('TITLE_QUOTA');
     $member_id = get_member();
     $pointsleft = available_points($member_id);
     $price = intval(get_option('quota'));
     $quota = post_param_integer('quota');
     $details = $GLOBALS['SITE_DB']->query_select('sales', array('details', 'details2'), array('memberid' => $member_id, 'purchasetype' => 'pop3'), '', 1);
     $prefix = $details[0]['details'];
     $suffix = $details[0]['details2'];
     // If we don't own a POP3 account, stop right here.
     if (!array_key_exists(0, $details)) {
         return warn_screen($title, do_lang_tempcode('NO_POP3'));
     }
     // Stop if we can't afford this much quota
     if ($quota * $price > $pointsleft && !has_specific_permission(get_member(), 'give_points_self')) {
         return warn_screen($title, do_lang_tempcode('CANT_AFFORD'));
     }
     // Mail off the order form
     $quota_url = get_option('quota_url');
     $_price = $quota * $price;
     $encoded_reason = do_lang('TITLE_QUOTA');
     $message_raw = do_template('POINTSTORE_QUOTA_MAIL', array('_GUID' => '5a4e0bb5e53e6ccf8e57581c377557f4', 'ENCODED_REASON' => $encoded_reason, 'QUOTA' => integer_format($quota), 'EMAIL' => $prefix . $suffix, 'QUOTA_URL' => $quota_url, 'PRICE' => integer_format($_price)));
     require_code('notifications');
     dispatch_notification('pointstore_request_quota', 'quota_' . uniqid('', true), do_lang('MAIL_REQUEST_QUOTA', NULL, NULL, NULL, get_site_default_lang()), $message_raw->evaluate(get_site_default_lang(), false), NULL, NULL, 3, true);
     $url = build_url(array('page' => '_SELF', 'type' => 'misc'), '_SELF');
     return redirect_screen($title, $url, do_lang_tempcode('ORDER_QUOTA_DONE'));
 }
コード例 #21
0
ファイル: mail.php プロジェクト: erico-deh/ocPortal
/**
 * Attempt to send an e-mail to the specified recipient. The mail will be forwarding to the CC address specified in the options (if there is one, and if not specified not to cc).
 * The mail will be sent in dual HTML/text format, where the text is the unconverted comcode source: if a member does not read HTML mail, they may wish to fallback to reading that.
 *
 * @param  string			The subject of the mail in plain text
 * @param  LONG_TEXT		The message, as Comcode
 * @param  ?array			The destination (recipient) e-mail addresses [array of strings] (NULL: site staff address)
 * @param  ?mixed			The recipient name. Array or string. (NULL: site name)
 * @param  EMAIL			The from address (blank: site staff address)
 * @param  string			The from name (blank: site name)
 * @param  integer		The message priority (1=urgent, 3=normal, 5=low)
 * @range  1 5
 * @param  ?array			An list of attachments (each attachment being a map, path=>filename) (NULL: none)
 * @param  boolean		Whether to NOT CC to the CC address
 * @param  ?MEMBER		Convert comcode->tempcode as this member (a privilege thing: we don't want people being able to use admin rights by default!) (NULL: guest)
 * @param  boolean		Replace above with arbitrary admin
 * @param  boolean		HTML-only
 * @param  boolean		Whether to bypass queueing, because this code is running as a part of the queue management tools
 * @param  ID_TEXT		The template used to show the email
 * @param  boolean		Whether to bypass queueing
 * @return ?tempcode		A full page (not complete XHTML) piece of tempcode to output (NULL: it worked so no tempcode message)
 */
function mail_wrap($subject_tag, $message_raw, $to_email = NULL, $to_name = NULL, $from_email = '', $from_name = '', $priority = 3, $attachments = NULL, $no_cc = false, $as = NULL, $as_admin = false, $in_html = false, $coming_out_of_queue = false, $mail_template = 'MAIL', $bypass_queue = false)
{
    if (running_script('stress_test_loader')) {
        return NULL;
    }
    global $EMAIL_ATTACHMENTS;
    $EMAIL_ATTACHMENTS = array();
    require_code('site');
    require_code('mime_types');
    $bypass_queue = $bypass_queue || $priority < 3 || strpos(serialize($attachments), 'tmpfile') !== false;
    if (is_null($as)) {
        $as = $GLOBALS['FORUM_DRIVER']->get_guest_id();
    }
    if (!$coming_out_of_queue) {
        $GLOBALS['SITE_DB']->query('DELETE FROM ' . get_table_prefix() . 'logged_mail_messages WHERE m_date_and_time<' . strval(time() - 60 * 60 * 24 * 14) . ' AND m_queued=0');
        // Log it all for 2 weeks, then delete
        $through_queue = !$bypass_queue && (get_option('mail_queue_debug') === '1' || get_option('mail_queue') === '1' && cron_installed());
        $GLOBALS['SITE_DB']->query_insert('logged_mail_messages', array('m_subject' => substr($subject_tag, 0, 255), 'm_message' => $message_raw, 'm_to_email' => serialize($to_email), 'm_to_name' => serialize($to_name), 'm_from_email' => $from_email, 'm_from_name' => $from_name, 'm_priority' => $priority, 'm_attachments' => serialize($attachments), 'm_no_cc' => $no_cc ? 1 : 0, 'm_as' => $as, 'm_as_admin' => $as_admin ? 1 : 0, 'm_in_html' => $in_html ? 1 : 0, 'm_date_and_time' => time(), 'm_member_id' => get_member(), 'm_url' => get_self_url(true), 'm_queued' => $through_queue ? 1 : 0, 'm_template' => $mail_template), false, !$through_queue);
        // No errors if we don't NEED this to work
        if ($through_queue) {
            return NULL;
        }
    }
    if (count($attachments) == 0) {
        $attachments = NULL;
    }
    global $SENDING_MAIL;
    if ($SENDING_MAIL) {
        return NULL;
    }
    $SENDING_MAIL = true;
    // To and from, and language
    $staff_address = get_option('staff_address');
    if (is_null($to_email)) {
        $to_email = array($staff_address);
    }
    $to_email_new = array();
    foreach ($to_email as $test_address) {
        if ($test_address != '') {
            $to_email_new[] = $test_address;
        }
    }
    $to_email = $to_email_new;
    if ($to_email == array()) {
        $SENDING_MAIL = false;
        return NULL;
    }
    if ($to_email[0] == $staff_address) {
        $lang = get_site_default_lang();
    } else {
        $lang = user_lang();
        if (method_exists($GLOBALS['FORUM_DRIVER'], 'get_member_from_email_address')) {
            $member_id = $GLOBALS['FORUM_DRIVER']->get_member_from_email_address($to_email[0]);
            if (!is_null($member_id)) {
                $lang = get_lang($member_id);
            }
        }
    }
    if (is_null($to_name)) {
        if ($to_email[0] == $staff_address) {
            $to_name = get_site_name();
        } else {
            $to_name = '';
        }
    }
    if ($from_email == '') {
        $from_email = get_option('staff_address');
    }
    if ($from_name == '') {
        $from_name = get_site_name();
    }
    $from_email = str_replace("\r", '', $from_email);
    $from_email = str_replace("\n", '', $from_email);
    $from_name = str_replace("\r", '', $from_name);
    $from_name = str_replace("\n", '', $from_name);
    $theme = method_exists($GLOBALS['FORUM_DRIVER'], 'get_theme') ? $GLOBALS['FORUM_DRIVER']->get_theme() : 'default';
    if ($theme == 'default') {
        $theme = $GLOBALS['FORUM_DRIVER']->get_theme('');
        // ... So get theme of welcome zone
    }
    // Line termination is fiddly. It is safer to rely on sendmail supporting \n than undetectable-qmail/postfix-masquerading-as-sendmail not supporting the correct \r\n
    /*$sendmail_path=ini_get('sendmail_path');
    	if ((strpos($sendmail_path,'qmail')!==false) || (strpos($sendmail_path,'sendmail')!==false))
    		$line_term="\n";
    	else
    		$line_term="\r\n";
    	*/
    if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN' || get_option('smtp_sockets_use') == '1') {
        $line_term = "\r\n";
        /*} elseif (strtoupper(substr(PHP_OS,0,3))=='MAC')
        	{
        		$line_term="\r";*/
    } else {
        $line_term = "\n";
    }
    // We use the boundary to seperate message parts
    $_boundary = uniqid('ocPortal', true);
    $boundary = $_boundary . '_1';
    $boundary2 = $_boundary . '_2';
    $boundary3 = $_boundary . '_3';
    // Our subject
    $subject = do_template('MAIL_SUBJECT', array('_GUID' => '44a57c666bb00f96723256e26aade9e5', 'SUBJECT_TAG' => $subject_tag), $lang, false, NULL, '.tpl', 'templates', $theme);
    $tightened_subject = $subject->evaluate($lang);
    // Note that this is slightly against spec, because characters aren't forced to be printable us-ascii. But it's better we allow this (which works in practice) than risk incompatibility via charset-base64 encoding.
    $tightened_subject = str_replace(chr(10), '', $tightened_subject);
    $tightened_subject = str_replace(chr(13), '', $tightened_subject);
    $regexp = '#^[\\x' . dechex(32) . '-\\x' . dechex(126) . ']*$#';
    if (preg_match($regexp, $tightened_subject) == 0) {
        $tightened_subject = '=?' . do_lang('charset', NULL, NULL, NULL, $lang) . '?B?' . base64_encode($tightened_subject) . "?=";
    }
    if (preg_match($regexp, $from_name) == 0) {
        $from_name = '=?' . do_lang('charset', NULL, NULL, NULL, $lang) . '?B?' . base64_encode($from_name) . "?=";
    }
    if (is_array($to_name)) {
        foreach ($to_name as $i => $_to_name) {
            if (preg_match($regexp, $_to_name) == 0) {
                $to_name[$i] = '=?' . do_lang('charset', NULL, NULL, NULL, $lang) . '?B?' . base64_encode($_to_name) . "?=";
            }
        }
    } else {
        if (preg_match($regexp, $to_name) == 0) {
            $to_name = '=?' . do_lang('charset', NULL, NULL, NULL, $lang) . '?B?' . base64_encode($to_name) . "?=";
        }
    }
    $simplify_when_can = true;
    // Used for testing. Not actually needed
    // Evaluate message. Needs doing early so we know if we have any headers
    $GLOBALS['NO_LINK_TITLES'] = true;
    global $LAX_COMCODE;
    $temp = $LAX_COMCODE;
    $LAX_COMCODE = true;
    $html_content = comcode_to_tempcode($message_raw, $as, $as_admin);
    $LAX_COMCODE = $temp;
    $GLOBALS['NO_LINK_TITLES'] = false;
    $attachments = array_merge(is_null($attachments) ? array() : $attachments, $EMAIL_ATTACHMENTS);
    // Headers
    $website_email = get_option('website_email');
    if ($website_email == '') {
        $website_email = $from_email;
    }
    if (get_value('use_true_from') !== '1') {
        $headers = 'From: "' . $from_name . '" <' . $website_email . '>' . $line_term;
    } else {
        $headers = 'From: <' . $from_email . '>' . $line_term;
    }
    $headers .= 'Reply-To: <' . $from_email . '>' . $line_term;
    $headers .= 'Return-Path: <' . $website_email . '>' . $line_term;
    $headers .= 'X-Sender: <' . $website_email . '>' . $line_term;
    $cc_address = $no_cc ? '' : get_option('cc_address');
    if ($cc_address != '' && !in_array($cc_address, $to_email)) {
        $headers .= (get_option('bcc') == '1' ? 'Bcc: <' : 'Cc: <') . $cc_address . '>' . $line_term;
    }
    $headers .= 'Message-ID: <' . $_boundary . '@' . get_domain() . '>' . $line_term;
    $headers .= 'X-Priority: ' . strval($priority) . $line_term;
    $brand_name = get_value('rebrand_name');
    if (is_null($brand_name)) {
        $brand_name = 'ocPortal';
    }
    $headers .= 'X-Mailer: ' . $brand_name . $line_term;
    $headers .= 'MIME-Version: 1.0' . $line_term;
    if (!is_null($attachments) || !$simplify_when_can) {
        $headers .= 'Content-Type: multipart/mixed;' . "\n\t" . 'boundary="' . $boundary . '"';
    } else {
        $headers .= 'Content-Type: multipart/alternative;' . "\n\t" . 'boundary="' . $boundary2 . '"';
    }
    $sending_message = '';
    $sending_message .= 'This is a multi-part message in MIME format.' . $line_term . $line_term;
    if (!is_null($attachments) || !$simplify_when_can) {
        $sending_message .= '--' . $boundary . $line_term;
        $sending_message .= 'Content-Type: multipart/alternative;' . "\n\t" . 'boundary="' . $boundary2 . '"' . $line_term . $line_term . $line_term;
    }
    global $CID_IMG_ATTACHMENT;
    $CID_IMG_ATTACHMENT = array();
    // Message starts (actually: it is kind of in header form also as it uses mime multi-part)
    if (!$in_html) {
        $_html_content = $html_content->evaluate($lang);
        $_html_content = preg_replace('#(keep|for)_session=[\\d\\w]*#', 'filtered=1', $_html_content);
        $message_html = strpos($_html_content, '<html') !== false ? make_string_tempcode($_html_content) : do_template($mail_template, array('_GUID' => 'b23069c20202aa59b7450ebf8d49cde1', 'CSS' => '{CSS}', 'LOGOURL' => get_logo_url(''), 'LANG' => $lang, 'TITLE' => $subject, 'CONTENT' => $_html_content), $lang, false, NULL, '.tpl', 'templates', $theme);
        $css = css_tempcode(true, true, $message_html->evaluate($lang), $theme);
        $_css = $css->evaluate($lang);
        if (get_option('allow_ext_images') != '1') {
            $_css = preg_replace_callback('#url\\(["\']?(http://[^"]*)["\']?\\)#U', '_mail_css_rep_callback', $_css);
        }
        $html_evaluated = $message_html->evaluate($lang);
        $html_evaluated = str_replace('{CSS}', $_css, $html_evaluated);
        // Cleanup the Comcode a bit
        $message_plain = comcode_to_clean_text($message_raw);
    } else {
        $html_evaluated = $message_raw;
    }
    $base64_encode = get_value('base64_emails') === '1';
    // More robust, but more likely to be spam-blocked, and some servers can scramble it.
    // Plain version
    if (!$in_html) {
        $sending_message .= '--' . $boundary2 . $line_term;
        $sending_message .= 'Content-Type: text/plain; charset=' . (preg_match($regexp, $message_plain) == 0 ? do_lang('charset', NULL, NULL, NULL, $lang) : 'us-ascii') . $line_term;
        // '; name="message.txt"'.	Outlook doesn't like: makes it think it's an attachment
        if ($base64_encode) {
            $sending_message .= 'Content-Transfer-Encoding: base64' . $line_term . $line_term;
            $sending_message .= chunk_split(base64_encode(unixify_line_format($message_plain)) . $line_term, 76, $line_term);
        } else {
            $sending_message .= 'Content-Transfer-Encoding: 8bit' . $line_term . $line_term;
            $sending_message .= wordwrap(str_replace(chr(10), $line_term, unixify_line_format($message_plain)) . $line_term, 998, $line_term);
        }
    }
    // HTML version
    $sending_message .= '--' . $boundary2 . $line_term;
    $sending_message .= 'Content-Type: multipart/related;' . "\n\t" . 'type="text/html";' . "\n\t" . 'boundary="' . $boundary3 . '"' . $line_term . $line_term . $line_term;
    $sending_message .= '--' . $boundary3 . $line_term;
    $sending_message .= 'Content-Type: text/html; charset=' . (preg_match($regexp, $html_evaluated) == 0 ? do_lang('charset', NULL, NULL, NULL, $lang) : 'us-ascii') . $line_term;
    // .'; name="message.html"'.	Outlook doesn't like: makes it think it's an attachment
    if (get_option('allow_ext_images') != '1') {
        $html_evaluated = preg_replace_callback('#<img\\s([^>]*)src="(http://[^"]*)"#U', '_mail_img_rep_callback', $html_evaluated);
        $matches = array();
        foreach (array('#<([^"<>]*\\s)style="([^"]*)"#', '#<style( [^<>]*)?' . '>(.*)</style>#Us') as $over) {
            $num_matches = preg_match_all($over, $html_evaluated, $matches);
            for ($i = 0; $i < $num_matches; $i++) {
                $altered_inner = preg_replace_callback('#url\\(["\']?(http://[^"]*)["\']?\\)#U', '_mail_css_rep_callback', $matches[2][$i]);
                if ($matches[2][$i] != $altered_inner) {
                    $altered_outer = str_replace($matches[2][$i], $altered_inner, $matches[0][$i]);
                    $html_evaluated = str_replace($matches[0][$i], $altered_outer, $html_evaluated);
                }
            }
        }
    }
    if ($base64_encode) {
        $sending_message .= 'Content-Transfer-Encoding: base64' . $line_term . $line_term;
        $sending_message .= chunk_split(base64_encode(unixify_line_format($html_evaluated)) . $line_term, 76, $line_term);
    } else {
        $sending_message .= 'Content-Transfer-Encoding: 8bit' . $line_term . $line_term;
        // Requires RFC 1652
        $sending_message .= wordwrap(str_replace(chr(10), $line_term, unixify_line_format($html_evaluated)) . $line_term, 998, $line_term);
    }
    $total_filesize = 0;
    foreach ($CID_IMG_ATTACHMENT as $id => $img) {
        $sending_message .= '--' . $boundary3 . $line_term;
        $file_path_stub = convert_url_to_path($img);
        $mime_type = get_mime_type(get_file_extension($img));
        $filename = basename($img);
        if (!is_null($file_path_stub)) {
            $total_filesize += @filesize($file_path_stub);
            if ($total_filesize > 1024 * 1024 * 5) {
                continue;
            }
            // Too large to process into an email
            $file_contents = @file_get_contents($file_path_stub);
        } else {
            $file_contents = http_download_file($img, NULL, false);
            $total_filesize += strlen($file_contents);
            if ($total_filesize >= 1024 * 1024 * 5) {
                continue;
            }
            // Too large to process into an email
            if (!is_null($GLOBALS['HTTP_DOWNLOAD_MIME_TYPE'])) {
                $mime_type = $GLOBALS['HTTP_DOWNLOAD_MIME_TYPE'];
            }
            if (!is_null($GLOBALS['HTTP_FILENAME'])) {
                $filename = $GLOBALS['HTTP_FILENAME'];
            }
        }
        $sending_message .= 'Content-Type: ' . str_replace("\r", '', str_replace("\n", '', $mime_type)) . $line_term;
        $sending_message .= 'Content-ID: <' . $id . '>' . $line_term;
        $sending_message .= 'Content-Disposition: inline; filename="' . str_replace("\r", '', str_replace("\n", '', $filename)) . '"' . $line_term;
        $sending_message .= 'Content-Transfer-Encoding: base64' . $line_term . $line_term;
        if (is_string($file_contents)) {
            $sending_message .= chunk_split(base64_encode($file_contents), 76, $line_term);
        }
    }
    $sending_message .= $line_term . '--' . $boundary3 . '--' . $line_term . $line_term;
    $sending_message .= $line_term . '--' . $boundary2 . '--' . $line_term . $line_term;
    // Attachments
    if (!is_null($attachments)) {
        foreach ($attachments as $path => $filename) {
            $sending_message .= '--' . $boundary . $line_term;
            $sending_message .= 'Content-Type: ' . get_mime_type(get_file_extension($filename)) . $line_term;
            // .'; name="'.str_replace("\r",'',str_replace("\n",'',$filename)).'"'   http://www.imc.org/ietf-822/old-archive2/msg02121.html
            $sending_message .= 'Content-Transfer-Encoding: base64' . $line_term;
            $sending_message .= 'Content-Disposition: attachment; filename="' . str_replace("\r", '', str_replace("\n", '', $filename)) . '"' . $line_term . $line_term;
            if (strpos($path, '://') === false) {
                $sending_message .= chunk_split(base64_encode(file_get_contents($path)), 76, $line_term);
            } else {
                require_code('files');
                $sending_message .= chunk_split(base64_encode(http_download_file($path)), 76, $line_term);
            }
        }
        $sending_message .= $line_term . '--' . $boundary . '--' . $line_term;
    }
    // Support for SMTP sockets rather than PHP mail()
    $error = NULL;
    if (get_option('smtp_sockets_use') == '1') {
        $worked = false;
        $host = get_option('smtp_sockets_host');
        $port = intval(get_option('smtp_sockets_port'));
        $errno = 0;
        $errstr = '';
        foreach ($to_email as $i => $to) {
            $socket = @fsockopen($host, $port, $errno, $errstr, 30.0);
            if ($socket !== false) {
                $rcv = fread($socket, 1024);
                $base_url = parse_url(get_base_url());
                $domain = $base_url['host'];
                // Login if necessary
                $username = get_option('smtp_sockets_username');
                $password = get_option('smtp_sockets_password');
                if ($username != '') {
                    fwrite($socket, 'EHLO ' . $domain . "\r\n");
                    $rcv = fread($socket, 1024);
                    fwrite($socket, "AUTH LOGIN\r\n");
                    $rcv = fread($socket, 1024);
                    if (strtolower(substr($rcv, 0, 3)) == '334') {
                        fwrite($socket, base64_encode($username) . "\r\n");
                        $rcv = fread($socket, 1024);
                        if (strtolower(substr($rcv, 0, 3)) == '235' || strtolower(substr($rcv, 0, 3)) == '334') {
                            fwrite($socket, base64_encode($password) . "\r\n");
                            $rcv = fread($socket, 1024);
                            if (strtolower(substr($rcv, 0, 3)) == '235') {
                            } else {
                                $error = do_lang('MAIL_ERROR_CONNECT_PASSWORD') . ' (' . str_replace($password, '*', $rcv) . ')';
                            }
                        } else {
                            $error = do_lang('MAIL_ERROR_CONNECT_USERNAME') . ' (' . $rcv . ')';
                        }
                    } else {
                        $error = do_lang('MAIL_ERROR_CONNECT_AUTH') . ' (' . $rcv . ')';
                    }
                } else {
                    fwrite($socket, 'HELO ' . $domain . "\r\n");
                    $rcv = fread($socket, 1024);
                }
                if (is_null($error)) {
                    $smtp_from_address = get_option('smtp_from_address');
                    if ($smtp_from_address == '') {
                        $smtp_from_address = $from_email;
                    }
                    fwrite($socket, 'MAIL FROM:<' . $website_email . ">\r\n");
                    $rcv = fread($socket, 1024);
                    if (strtolower(substr($rcv, 0, 3)) == '250' || strtolower(substr($rcv, 0, 3)) == '251') {
                        $sent_one = false;
                        fwrite($socket, "RCPT TO:<" . $to_email[$i] . ">\r\n");
                        $rcv = fread($socket, 1024);
                        if (strtolower(substr($rcv, 0, 3)) != '250' && strtolower(substr($rcv, 0, 3)) != '251') {
                            $error = do_lang('MAIL_ERROR_TO') . ' (' . $rcv . ')' . ' ' . $to_email[$i];
                        } else {
                            $sent_one = true;
                        }
                        if ($sent_one) {
                            fwrite($socket, "DATA\r\n");
                            $rcv = fread($socket, 1024);
                            if (strtolower(substr($rcv, 0, 3)) == '354') {
                                $attractive_date = strftime('%d %B %Y  %H:%M:%S', time());
                                $_to_name = preg_replace('#@.*$#', '', is_array($to_name) ? $to_name[$i] : $to_name);
                                // preg_replace is because some servers may reject sending names that look like e-mail addresses. ocP tries this from recommend module.
                                if (count($to_email) == 1) {
                                    if ($_to_name == '') {
                                        fwrite($socket, 'To: ' . $to_email[$i] . "\r\n");
                                    } else {
                                        fwrite($socket, 'To: ' . $_to_name . ' <' . $to_email[$i] . '>' . "\r\n");
                                    }
                                } else {
                                    fwrite($socket, 'To: ' . $_to_name . "\r\n");
                                }
                                fwrite($socket, 'Subject: ' . $tightened_subject . "\r\n");
                                fwrite($socket, 'Date: ' . $attractive_date . "\r\n");
                                $headers = preg_replace('#^\\.#m', '..', $headers);
                                $sending_message = preg_replace('#^\\.#m', '..', $sending_message);
                                fwrite($socket, $headers . "\r\n");
                                fwrite($socket, $sending_message);
                                fwrite($socket, "\r\n.\r\n");
                                $rcv = fread($socket, 1024);
                                fwrite($socket, "QUIT\r\n");
                                $rcv = fread($socket, 1024);
                            } else {
                                $error = do_lang('MAIL_ERROR_DATA') . ' (' . $rcv . ')';
                            }
                        }
                    } else {
                        $error = do_lang('MAIL_ERROR_FROM') . ' (' . $rcv . ')';
                    }
                    if (@fwrite($socket, "RSET\r\n") === false) {
                        @fclose($socket);
                        $socket = NULL;
                    } else {
                        $rcv = fread($socket, 1024);
                    }
                }
                if (!is_null($socket)) {
                    fclose($socket);
                }
                if (is_null($error)) {
                    $worked = true;
                }
            } else {
                $error = do_lang('MAIL_ERROR_CONNECT', $host, strval($port));
            }
        }
    } else {
        $worked = false;
        foreach ($to_email as $i => $to) {
            //exit($headers.chr(10).$sending_message);
            $GLOBALS['SUPPRESS_ERROR_DEATH'] = true;
            $additional = '';
            if (get_option('enveloper_override') == '1') {
                $additional = '-f ' . $website_email;
            }
            $_to_name = preg_replace('#@.*$#', '', is_array($to_name) ? $to_name[$i] : $to_name);
            // preg_replace is because some servers may reject sending names that look like e-mail addresses. ocP tries this from recommend module.
            if ($_to_name == '' || strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
                $to_line = $to;
            } else {
                $to_line = '"' . $_to_name . '" <' . $to . '>';
            }
            //if (function_exists('mb_language')) mb_language('en');	Stop overridden mbstring mail function from messing and base64'ing stuff. Actually we don't need this as we make sure to pass through as headers with blank message, bypassing any filtering.
            if (str_replace(array('on', 'true', 'yes'), array('1', '1', '1'), strtolower(ini_get('safe_mode'))) == '1') {
                $worked = mail($to_line, $tightened_subject, $sending_message, $headers);
            } else {
                $worked = mail($to_line, $tightened_subject, $sending_message, $headers, $additional);
            }
            if (!$worked && isset($php_errormsg)) {
                $error = $php_errormsg;
            }
            $GLOBALS['SUPPRESS_ERROR_DEATH'] = false;
        }
    }
    if (!$worked) {
        $SENDING_MAIL = false;
        if (get_param_integer('keep_hide_mail_failure', 0) == 0) {
            require_code('site');
            attach_message(!is_null($error) ? make_string_tempcode($error) : do_lang_tempcode('MAIL_FAIL', escape_html(get_option('staff_address'))), 'warn');
        } else {
            return warn_screen(get_page_title('ERROR_OCCURRED'), do_lang_tempcode('MAIL_FAIL', escape_html(get_option('staff_address'))));
        }
    }
    $SENDING_MAIL = false;
    return NULL;
}
コード例 #22
0
ファイル: banners.php プロジェクト: erico-deh/ocPortal
 /**
  * Standard stage of pointstore item purchase.
  *
  * @return tempcode		The UI
  */
 function _upgradebanner()
 {
     if (get_option('is_on_banner_buy') == '0') {
         return new ocp_tempcode();
     }
     $title = get_page_title('TITLE_BANNER_UPGRADE');
     $member_id = get_member();
     $pointsleft = available_points($member_id);
     $myrow = $this->handle_has_no_banner();
     $curhit = $myrow['campaign_remaining'];
     $curimp = $myrow['importance_modulus'];
     $name = $myrow['name'];
     //So we don't have to call these big ugly names, again...
     $futhit = post_param_integer('hits');
     $futimp = post_param_integer('importance');
     //Checking to be sure we've ordered numbers that are positive
     if (!($futimp >= 0 && $futhit >= 0)) {
         return warn_screen($title, do_lang_tempcode('BAD_INPUT'));
     }
     //Checking to be sure we haven't ordered nothing...
     if ($futimp == 0 && $futhit == 0) {
         return warn_screen($title, do_lang_tempcode('SILLY_INPUT'));
     }
     //How many importance and hits will we have after this?
     $afthit = $curhit + $futhit;
     $aftimp = $curimp + $futimp;
     //Getting the prices of hits and importance...
     $impprice = intval(get_option('banner_imp'));
     $hitprice = intval(get_option('banner_hit'));
     //Figuring out the price of importance and hits, depedning on how many they bought.
     $impcost = $futimp * $impprice;
     $hitcost = $futhit * $hitprice;
     $total_price = $hitcost + $impcost;
     $points_after = $pointsleft - $total_price;
     //Check to see this isn't costing us more than we can afford
     if ($points_after < 0 && !has_specific_permission(get_member(), 'give_points_self')) {
         return warn_screen($title, do_lang_tempcode('CANT_AFFORD'));
     }
     //If this is *not* our first time through, do a confirmation screen. Else, make the purchase.
     $ord = post_param_integer('ord', 0);
     if ($ord == 0) {
         $proceed_url = build_url(array('page' => '_SELF', 'type' => '_upgradebanner', 'id' => 'banners'), '_SELF');
         $keep = new ocp_tempcode();
         $keep->attach(form_input_hidden('hits', strval($futhit)));
         $keep->attach(form_input_hidden('importance', strval($futimp)));
         $keep->attach(form_input_hidden('ord', '1'));
         $action = do_lang_tempcode('BANNER_UPGRADE_CONFIRM', integer_format($futimp), integer_format($futhit));
         return do_template('POINTSTORE_CONFIRM_SCREEN', array('_GUID' => 'acdde0bd41ccd1459bbd7a1e9ca5ed68', 'TITLE' => $title, 'MESSAGE' => $action, 'ACTION' => '', 'COST' => integer_format($total_price), 'POINTS_AFTER' => integer_format($points_after), 'CANCEL_URL' => build_url(array('page' => '_SELF'), '_SELF'), 'PROCEED_URL' => $proceed_url, 'KEEP' => $keep));
     }
     // Our Query
     $GLOBALS['SITE_DB']->query_update('banners', array('campaign_remaining' => $afthit, 'importance_modulus' => $aftimp), array('name' => $name), '', 1);
     //Charge the user for their purchase
     require_code('points2');
     charge_member($member_id, $total_price, do_lang('BANNER_UPGRADE_LINE', integer_format($futhit), integer_format($futimp)));
     $url = build_url(array('page' => '_SELF', 'type' => 'misc'), '_SELF');
     return redirect_screen($title, $url, do_lang_tempcode('BANNER_UPGRADED'));
 }
コード例 #23
0
ファイル: catalogues.php プロジェクト: erico-deh/ocPortal
/**
 * Display a catalogue entry
 *
 * @param  AUTO_LINK		Entry ID
 * @param  boolean		Whether to skip rendering a title
 * @return tempcode		Tempcode interface to display an entry
 */
function render_catalogue_entry_screen($id, $no_title = false)
{
    require_code('feedback');
    if (addon_installed('ecommerce')) {
        require_code('ecommerce');
    }
    require_code('images');
    require_css('catalogues');
    require_lang('catalogues');
    $entries = $GLOBALS['SITE_DB']->query_select('catalogue_entries', array('*'), array('id' => $id), '', 1);
    if (!array_key_exists(0, $entries)) {
        return warn_screen(get_page_title('CATALOGUES'), do_lang_tempcode('MISSING_RESOURCE'));
    }
    $entry = $entries[0];
    $categories = $GLOBALS['SITE_DB']->query_select('catalogue_categories', array('*'), array('id' => $entry['cc_id']), '', 1);
    if (!array_key_exists(0, $categories)) {
        warn_exit(do_lang_tempcode('CAT_NOT_FOUND', strval($entry['cc_id'])));
    }
    $category = $categories[0];
    $GLOBALS['FEED_URL'] = find_script('backend') . '?mode=catalogues&filter=' . strval($entry['cc_id']);
    $catalogue_name = $category['c_name'];
    $catalogues = $GLOBALS['SITE_DB']->query_select('catalogues', array('*'), array('c_name' => $catalogue_name), '', 1);
    if (!array_key_exists(0, $catalogues)) {
        warn_exit(do_lang_tempcode('CATALOGUE_NOT_FOUND', $catalogue_name));
    }
    $catalogue = $catalogues[0];
    // Permission for here?
    if (!has_category_access(get_member(), 'catalogues_catalogue', $catalogue_name)) {
        access_denied('CATALOGUE_ACCESS');
    }
    if (get_value('disable_cat_cat_perms') !== '1' && !has_category_access(get_member(), 'catalogues_category', strval($entry['cc_id']))) {
        access_denied('CATEGORY_ACCESS');
    }
    $ecommerce = is_ecommerce_catalogue($catalogue_name);
    if ($ecommerce) {
        $tpl_set = 'products';
    } else {
        $tpl_set = $catalogue_name;
    }
    $root = get_param_integer('root', NULL);
    $map = get_catalogue_entry_map($entry, $catalogue, 'PAGE', $tpl_set, $root, NULL, NULL, true, true);
    if (get_db_type() != 'xml') {
        $entry['ce_views']++;
        $GLOBALS['SITE_DB']->query_update('catalogue_entries', array('ce_views' => $entry['ce_views']), array('id' => $id), '', 1, NULL, false, true);
    }
    // Validation
    if ($entry['ce_validated'] == 0) {
        if (!has_specific_permission(get_member(), 'jump_to_unvalidated')) {
            access_denied('SPECIFIC_PERMISSION', 'jump_to_unvalidated');
        }
        $map['WARNINGS'] = do_template('WARNING_TABLE', array('_GUID' => 'bf604859a572ca53e969bec3d91f9cfb', 'WARNING' => do_lang_tempcode(get_param_integer('redirected', 0) == 1 ? 'UNVALIDATED_TEXT_NON_DIRECT' : 'UNVALIDATED_TEXT')));
    } else {
        $map['WARNINGS'] = '';
    }
    //Finding any hook exists for this product--------------------
    if (addon_installed('ecommerce')) {
        $object = find_product(strval($id));
        if (is_object($object) && method_exists($object, 'get_custom_product_map_fields')) {
            $object->get_custom_product_map_fields($id, $map);
        }
    }
    //------------------------------------------------------------
    $map['ENTRY'] = do_template('CATALOGUE_' . $tpl_set . '_ENTRY', $map, NULL, false, 'CATALOGUE_DEFAULT_ENTRY');
    $map['ADD_DATE'] = get_timezoned_date($entry['ce_add_date']);
    $map['ADD_DATE_RAW'] = strval($entry['ce_add_date']);
    $map['EDIT_DATE'] = is_null($entry['ce_edit_date']) ? '' : get_timezoned_date($entry['ce_edit_date']);
    $map['EDIT_DATE_RAW'] = is_null($entry['ce_edit_date']) ? '' : strval($entry['ce_edit_date']);
    $map['VIEWS'] = integer_format($entry['ce_views']);
    $title_to_use = do_lang_tempcode($catalogue_name . '__CATALOGUE_ENTRY', $map['FIELD_0']);
    $title_to_use_2 = do_lang($catalogue_name . '__CATALOGUE_ENTRY', $map['FIELD_0_PLAIN'], NULL, NULL, NULL, false);
    if (is_null($title_to_use_2)) {
        $title_to_use = do_lang_tempcode('DEFAULT__CATALOGUE_ENTRY', $map['FIELD_0']);
        $title_to_use_2 = do_lang('DEFAULT__CATALOGUE_ENTRY', $map['FIELD_0_PLAIN']);
    }
    if ($no_title) {
        $map['TITLE'] = new ocp_tempcode();
    } else {
        if (addon_installed('awards')) {
            require_code('awards');
            $awards = find_awards_for('catalogue_entry', strval($id));
        } else {
            $awards = array();
        }
        $map['TITLE'] = get_page_title($title_to_use, false, NULL, NULL, $awards);
    }
    $map['SUBMITTER'] = strval($entry['ce_submitter']);
    require_code('seo2');
    if (is_object($title_to_use_2)) {
        $title_to_use_2 = $title_to_use_2->evaluate();
    }
    seo_meta_load_for('catalogue_entry', strval($id), strip_tags($title_to_use_2));
    if ($map['TREE'] === '') {
        $map['TREE'] = new ocp_tempcode();
        $url = build_url(array('page' => '_SELF', 'type' => 'index', 'id' => $catalogue_name), '_SELF');
        $map['TREE']->attach(hyperlink($url, escape_html(get_translated_text($catalogue['c_title'])), false, false, do_lang('INDEX')));
        $map['TREE']->attach(do_template('BREADCRUMB_ESCAPED'));
        $url = build_url(array('page' => '_SELF', 'type' => 'category', 'id' => $category['id']), '_SELF');
        $map['TREE']->attach(hyperlink($url, escape_html(get_translated_text($category['cc_title'])), false, false, do_lang('GO_BACKWARDS_TO', get_translated_text($category['cc_title'])), NULL, NULL, 'up'));
    }
    $map['CATEGORY_TITLE'] = get_translated_text($category['cc_title']);
    $map['CAT'] = strval($entry['cc_id']);
    $map['TAGS'] = get_loaded_tags('catalogue_entries');
    breadcrumb_add_segment($map['TREE'], $title_to_use);
    if (is_null($root)) {
        breadcrumb_set_parents(array(array('_SELF:_SELF:misc' . ($ecommerce ? ':ecommerce=1' : ''), do_lang('CATALOGUES'))));
    }
    $GLOBALS['META_DATA'] += array('created' => date('Y-m-d', $entry['ce_add_date']), 'creator' => $GLOBALS['FORUM_DRIVER']->get_username($entry['ce_submitter']), 'publisher' => '', 'modified' => is_null($entry['ce_edit_date']) ? '' : date('Y-m-d', $entry['ce_edit_date']), 'type' => get_translated_text($catalogue['c_title']) . ' entry', 'title' => comcode_escape($title_to_use_2), 'identifier' => '_SEARCH:catalogues:entry:' . strval($id), 'description' => '');
    return do_template('CATALOGUE_' . $tpl_set . '_ENTRY_SCREEN', $map, NULL, false, 'CATALOGUE_DEFAULT_ENTRY_SCREEN');
}
コード例 #24
0
ファイル: site.php プロジェクト: erico-deh/ocPortal
/**
 * This is it - the start of rendering of a website page.
 * Take in all inputs, sends them to the correct functions to process, gathers up all the outputs, sticks them together and echoes them.
 */
function do_site()
{
    // More SEO redirection (monikers)
    // Does this URL arrangement support monikers?
    $url_id = get_param('id', NULL, true);
    if ($url_id !== NULL && url_monikers_enabled()) {
        $type = get_param('type', 'misc');
        $looking_for = '_SEARCH:' . get_page_name() . ':' . $type . ':_WILD';
        $hooks = find_all_hooks('systems', 'content_meta_aware');
        $ob_info = NULL;
        foreach (array_keys($hooks) as $hook) {
            require_code('hooks/systems/content_meta_aware/' . filter_naughty($hook));
            $ob = object_factory('Hook_content_meta_aware_' . $hook, true);
            if ($ob === NULL) {
                continue;
            }
            $ob_info = $ob->info();
            $ob_info['view_pagelink_pattern'] = preg_replace('#:[^:]*$#', ':_WILD', $ob_info['view_pagelink_pattern']);
            if ($ob_info['view_pagelink_pattern'] == $looking_for && $ob_info['support_url_monikers']) {
                if (is_numeric($url_id)) {
                    $correct_moniker = find_id_moniker(array('page' => get_page_name(), 'type' => get_param('type', 'misc'), 'id' => $url_id));
                    if ($correct_moniker !== NULL && $correct_moniker != $url_id && count($_POST) == 0) {
                        header('HTTP/1.0 301 Moved Permanently');
                        $_new_url = build_url(array('page' => '_SELF', 'id' => $correct_moniker), '_SELF', NULL, true);
                        $new_url = $_new_url->evaluate();
                        header('Location: ' . $new_url);
                        exit;
                    }
                } else {
                    // See if it is deprecated
                    if (strpos(get_db_type(), 'mysql') !== false) {
                        $monikers = $GLOBALS['SITE_DB']->query_select('url_id_monikers USE INDEX (uim_moniker)', array('m_resource_id', 'm_deprecated'), array('m_resource_page' => get_page_name(), 'm_resource_type' => get_param('type', 'misc'), 'm_moniker' => $url_id));
                    } else {
                        $monikers = $GLOBALS['SITE_DB']->query_select('url_id_monikers', array('m_resource_id', 'm_deprecated'), array('m_resource_page' => get_page_name(), 'm_resource_type' => get_param('type', 'misc'), 'm_moniker' => $url_id));
                    }
                    if (!array_key_exists(0, $monikers)) {
                        warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
                    }
                    $deprecated = $monikers[0]['m_deprecated'] == 1;
                    if ($deprecated && count($_POST) == 0) {
                        $correct_moniker = find_id_moniker(array('page' => get_page_name(), 'type' => get_param('type', 'misc'), 'id' => $monikers[0]['m_resource_id']));
                        header('HTTP/1.0 301 Moved Permanently');
                        $_new_url = build_url(array('page' => '_SELF', 'id' => $correct_moniker), '_SELF', NULL, true);
                        $new_url = $_new_url->evaluate();
                        header('Location: ' . $new_url);
                        exit;
                    } else {
                        $_GET['id'] = $monikers[0]['m_resource_id'];
                        // We need to know the ID number rather than the moniker
                    }
                }
                break;
            }
        }
    }
    // Any messages to output?
    if (get_param_integer('redirected', 0) == 1) {
        $messages = $GLOBALS['SITE_DB']->query_select('messages_to_render', array('r_message', 'r_type'), array('r_session_id' => get_session_id()), 'ORDER BY r_time DESC');
        foreach ($messages as $message) {
            if ($GLOBALS['XSS_DETECT']) {
                ocp_mark_as_escaped($message['r_message']);
            }
            attach_message(protect_from_escaping($message['r_message']), $message['r_type']);
        }
        if (count($messages) != 0) {
            $GLOBALS['SITE_DB']->query('DELETE FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'messages_to_render WHERE r_session_id=' . strval((int) get_session_id()) . ' OR r_time<' . strval(time() - 60 * 60));
        }
    }
    if (in_safe_mode()) {
        $disable_safe_mode_url = get_self_url(true, true, array('keep_safe_mode' => NULL));
        attach_message(do_lang_tempcode('CURRENTLY_HAS_KEEP_SAFE_MODE', escape_html($disable_safe_mode_url)), 'notice');
    }
    if (get_param_integer('keep_fatalistic', 0) == 1) {
        $disable_fatalistic_url = get_self_url(true, true, array('keep_fatalistic' => NULL));
        attach_message(do_lang_tempcode('CURRENTLY_HAS_KEEP_FATALISTIC', escape_html($disable_fatalistic_url)), 'notice');
    }
    $special_page_type = get_param('special_page_type', 'view');
    global $ZONE;
    $keep_markers = get_param_integer('keep_markers', 0);
    $show_edit_links = get_param_integer('show_edit_links', 0);
    global $KEEP_MARKERS, $SHOW_EDIT_LINKS;
    $KEEP_MARKERS = $keep_markers == 1 || $special_page_type == 'show_markers';
    if ($KEEP_MARKERS && !headers_sent()) {
        header('Content-type: text/html; charset=' . get_charset());
    }
    $SHOW_EDIT_LINKS = $show_edit_links == 1 || $special_page_type == 'show_edit_links';
    $out_evaluated = NULL;
    if ($special_page_type != 'view' && $special_page_type != 'show_markers') {
        require_code('view_modes');
        initialise_special_page_types($special_page_type);
    }
    // Set up Xdebug profiling
    if ($special_page_type == 'profile') {
        if (function_exists('xdebug_start_profiling')) {
            xdebug_start_profiling();
        }
        // xdebug 1 style
        if (ini_get('xdebug.profiler_enable') != '1') {
            attach_message(escape_html('Profiling must be enabled in php.ini'), 'warn');
        }
        // xdebug 2 style
        if (!is_writable_wrap(ini_get('xdebug.profiler_output_dir'))) {
            attach_message(escape_html('xdebug.profiler_output_dir needs setting to a writable directory'), 'warn');
        }
    }
    // Allow the site to be closed
    $site_closed = get_option('site_closed');
    if ($site_closed == '1' && !has_specific_permission(get_member(), 'access_closed_site') && !$GLOBALS['IS_ACTUALLY_ADMIN']) {
        require_code('site2');
        closed_site();
    }
    // Work out which page we're viewing
    global $PAGE;
    $PAGE = get_page_name();
    $doing_special_page_type = $special_page_type != 'view' && $special_page_type != 'show_markers' && $special_page_type != 'show_edit_links' && $special_page_type != 'memory' && (has_specific_permission(get_member(), 'view_profiling_modes') || $GLOBALS['IS_ACTUALLY_ADMIN']);
    // Load up our frames into strings. Note that the header and the footer are fixed already.
    $middle = request_page($PAGE, true);
    global $CYCLES;
    $CYCLES = array();
    // Here we reset some Tempcode environmental stuff, because template compilation or preprocessing may have dirtied things
    if ($middle === NULL || $middle->is_definitely_empty()) {
        $GLOBALS['HTTP_STATUS_CODE'] = '404';
        if (!headers_sent()) {
            if (!browser_matches('ie') && strpos(ocp_srv('SERVER_SOFTWARE'), 'IIS') === false) {
                header('HTTP/1.0 404 Not Found');
            }
        }
        $title = get_page_title('ERROR_OCCURRED');
        $text = do_lang_tempcode('NO_PAGE_OUTPUT');
        $middle = warn_screen($title, $text, false);
    }
    // Extra stuff we can tag on (like messages)
    $additional = new ocp_tempcode();
    $site_closed = get_option('site_closed');
    // May have been JUST changed in page load - think Setup Wizard
    if ($site_closed == '1' && $PAGE != 'login' && $PAGE != 'join' && get_param_integer('wide_high', 0) == 0) {
        $additional->attach(do_template('ADDITIONAL', array('_GUID' => '03a41a91606b3ad05330e7d6f3e741c1', 'TYPE' => 'notice', 'MESSAGE' => do_lang_tempcode(has_specific_permission(get_member(), 'access_closed_site') ? 'SITE_SPECIAL_ACCESS' : 'SITE_SPECIAL_ACCESS_SU'))));
    }
    if ($GLOBALS['IS_ACTUALLY_ADMIN']) {
        $unsu_link = get_self_url(true, true, array('keep_su' => NULL));
        $su_username = $GLOBALS['FORUM_DRIVER']->get_username(get_member());
        $additional->attach(do_template('ADDITIONAL', array('_GUID' => '13a41a91606b3ad05330e7d6f3e741c1', 'TYPE' => 'notice', 'MESSAGE' => do_lang_tempcode('USING_SU', escape_html($unsu_link), escape_html($su_username)))));
    }
    $out = new ocp_tempcode();
    // This is important - it makes sure the tempcode tree appears nicely
    $middle->handle_symbol_preprocessing();
    // Due to the '->evaluate()' below, plus so that some symbol preprocessing can be passed into header
    $out->attach(do_header());
    if (function_exists('memory_get_usage') && get_param('special_page_type', '') == 'memory') {
        if (function_exists('memory_get_peak_usage')) {
            $memory_usage = memory_get_peak_usage();
        } else {
            $memory_usage = memory_get_usage();
        }
        $additional->attach(do_template('ADDITIONAL', array('_GUID' => 'd605c0d111742a8cd2d4ef270a1e5fe1', 'TYPE' => 'inform', 'MESSAGE' => do_lang_tempcode('MEMORY_USAGE', float_format(round(floatval($memory_usage) / 1024.0 / 1024.0, 2))))));
    }
    // Whack it into our global template
    global $ATTACHED_MESSAGES;
    $global_template = 'GLOBAL';
    if (get_option('show_docs') == '0') {
        $GLOBALS['HELPER_PANEL_TUTORIAL'] = '';
    }
    $helper_panel_pic = $GLOBALS['HELPER_PANEL_PIC'];
    if ($helper_panel_pic != '') {
        if (find_theme_image($helper_panel_pic, true) == '') {
            $helper_panel_pic = '';
        }
    }
    $global = do_template($global_template, array('HELPER_PANEL_TUTORIAL' => $GLOBALS['HELPER_PANEL_TUTORIAL'], 'HELPER_PANEL_HTML' => $GLOBALS['HELPER_PANEL_HTML'], 'HELPER_PANEL_TEXT' => $GLOBALS['HELPER_PANEL_TEXT'], 'HELPER_PANEL_PIC' => $helper_panel_pic, 'MIDDLE' => $doing_special_page_type ? $middle : $middle->evaluate(), 'MESSAGE_TOP' => $ATTACHED_MESSAGES, 'MESSAGE' => $additional, 'BREADCRUMBS' => breadcrumbs()));
    unset($middle);
    $out->attach($global);
    $out->attach(do_footer());
    $out->handle_symbol_preprocessing();
    if (get_value('xhtml_strict') === '1') {
        $out = make_xhtml_strict($out);
    }
    // Validation
    $novalidate = get_param_integer('keep_novalidate', get_param_integer('novalidate', 0));
    $show_edit_links = get_param_integer('show_edit_links', 0);
    if ((in_array(ocp_srv('HTTP_HOST'), array('localhost', 'test.ocportal.com')) || $GLOBALS['FORUM_DRIVER']->is_staff(get_member())) && ($special_page_type == 'code' || $novalidate == 0 && get_option('validation') == '1') && $GLOBALS['REFRESH_URL'][0] == '' && $show_edit_links == 0) {
        require_code('view_modes');
        $out_evaluated = $out->evaluate(NULL, false);
        do_xhtml_validation($out_evaluated, $special_page_type == 'code' && get_param_integer('preview_mode', NULL) === NULL, get_param_integer('preview_mode', 0));
    }
    // Cacheing for spiders
    if (running_script('index') && count($_POST) == 0 && isset($GLOBALS['SITE_INFO']['fast_spider_cache']) && $GLOBALS['SITE_INFO']['fast_spider_cache'] == '1' && is_guest()) {
        $bot_type = get_bot_type();
        if (($bot_type !== NULL || isset($GLOBALS['SITE_INFO']['any_guest_cached_too']) && $GLOBALS['SITE_INFO']['any_guest_cached_too'] == '1') && can_fast_spider_cache()) {
            $fast_cache_path = get_custom_file_base() . '/persistant_cache/' . md5(serialize(get_self_url_easy()));
            if ($bot_type === NULL) {
                $fast_cache_path .= '__non-bot';
            }
            if (!array_key_exists('js_on', $_COOKIE)) {
                $fast_cache_path .= '__no-js';
            }
            if (is_mobile()) {
                $fast_cache_path .= '_mobile';
            }
            $fast_cache_path .= '.gcd';
            if (!is_dir(get_custom_file_base() . '/persistant_cache/')) {
                if (@mkdir(get_custom_file_base() . '/persistant_cache/', 0777)) {
                    fix_permissions(get_custom_file_base() . '/persistant_cache/', 0777);
                    sync_file(get_custom_file_base() . '/persistant_cache/');
                } else {
                    intelligent_write_error($fast_cache_path);
                }
            }
            $out_evaluated = $out->evaluate(NULL, false);
            $myfile = @fopen($fast_cache_path, 'wb') or intelligent_write_error($fast_cache_path);
            if (function_exists('gzencode')) {
                fwrite($myfile, gzencode($out_evaluated, 9));
            } else {
                fwrite($myfile, $out_evaluated);
            }
            fclose($myfile);
            fix_permissions($fast_cache_path);
            sync_file($fast_cache_path);
        }
    }
    if ($doing_special_page_type) {
        special_page_types($special_page_type, $out, $out_evaluated);
    }
    // We calculated the time before outputting so that latency and bandwidth do not adversely affect the result
    global $PAGE_START_TIME, $PAGE_STRING;
    $page_generation_time = microtime_diff($PAGE_START_TIME, microtime(false));
    if (!$GLOBALS['QUICK_REDIRECT']) {
        if ($out_evaluated !== NULL) {
            echo $out_evaluated;
        } else {
            $GLOBALS['FINISHING_OUTPUT'] = true;
            $out->evaluate_echo();
        }
    }
    // Finally, stats
    if ($PAGE_STRING !== NULL) {
        log_stats($PAGE_STRING, intval($page_generation_time));
    }
    // When someone hits the Admin Zone front page.
    if ($ZONE['zone_name'] == 'adminzone' && get_page_name() == 'start') {
        // Security feature admins can turn on
        require_code('notifications');
        $current_username = $GLOBALS['FORUM_DRIVER']->get_username(get_member());
        $subject = do_lang('AFA_NOTIFICATION_MAIL_SUBJECT', $current_username, get_site_name(), get_ip_address());
        $mail = do_lang('AFA_NOTIFICATION_MAIL', comcode_escape(get_site_name()), comcode_escape($current_username), comcode_escape(get_ip_address()));
        dispatch_notification('adminzone_frontpage_accessed', NULL, $subject, $mail);
        // Track very basic details of what sites use ocPortal. You can remove if you like.
        if (preg_match('#^localhost[\\.\\:$]?#', ocp_srv('HTTP_HOST')) == 0) {
            global $EXPIRE, $KEY;
            $timeout_before = @ini_get('default_socket_timeout');
            @ini_set('default_socket_timeout', '3');
            http_download_file('http://ocportal.com/user.php?url=' . urlencode(get_base_url()) . '&name=' . urlencode(get_site_name()) . '&registered=2&key=' . ($KEY === NULL ? '' : strval($KEY)) . '&expire=' . ($EXPIRE === NULL ? '' : strval($EXPIRE)) . '&version=' . urlencode(ocp_version_full()), NULL, false);
            @ini_set('default_socket_timeout', $timeout_before);
        }
    }
    // Little disk space check
    $last_space_check = get_value('last_space_check');
    if ($last_space_check === NULL || intval($last_space_check) < time() - 60 * 60 * 3) {
        set_value('last_space_check', strval(time()));
        $low_space_check = intval(get_option('low_space_check')) * 1024 * 1024;
        $disk_space = @disk_free_space(get_file_base());
        if (is_integer($disk_space) && $disk_space < $low_space_check) {
            require_code('notifications');
            $subject = do_lang('LOW_DISK_SPACE_SUBJECT', NULL, NULL, NULL, get_site_default_lang());
            $message = do_lang('LOW_DISK_SPACE_MAIL', strval(intval(round($disk_space / 1024 / 1024))), NULL, NULL, get_site_default_lang());
            dispatch_notification('low_disk_space', NULL, $subject, $message, NULL, A_FROM_SYSTEM_PRIVILEGED);
        }
    }
    //exit();
}
コード例 #25
0
ファイル: cms_chat.php プロジェクト: erico-deh/ocPortal
 /**
  * The actualiser for deleting a message.
  *
  * @return tempcode	The UI.
  */
 function _chat_delete_message()
 {
     $title = get_page_title('DELETE_MESSAGE');
     $message_id = get_param_integer('id');
     $rows = $GLOBALS['SITE_DB']->query_select('chat_messages', array('the_message', 'room_id'), array('id' => $message_id));
     if (!array_key_exists(0, $rows)) {
         return warn_screen($title, do_lang_tempcode('MISSING_RESOURCE'));
     }
     $myrow = $rows[0];
     $message = $myrow['the_message'];
     $room_id = $myrow['room_id'];
     check_chatroom_access($room_id);
     $room_details = $GLOBALS['SITE_DB']->query_select('chat_rooms', array('*'), array('id' => $room_id), '', 1);
     if (!array_key_exists(0, $room_details)) {
         warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
     }
     $row = $room_details[0];
     $has_mod_access = has_specific_permission(get_member(), 'edit_lowrange_content', 'cms_chat', array('chat', $room_id)) || $row['room_owner'] == get_member() && has_specific_permission(get_member(), 'moderate_my_private_rooms');
     if (!$has_mod_access) {
         access_denied('SPECIFIC_PERMISSION', 'edit_lowrange_content');
     }
     $GLOBALS['SITE_DB']->query_delete('chat_messages', array('id' => $message_id), '', 1);
     decache('side_shoutbox');
     $message2 = get_translated_tempcode($message);
     delete_lang($message);
     log_it('DELETE_MESSAGE', strval($message_id), $message2->evaluate());
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('CHOOSE')), array('_SELF:_SELF:room:id=' . strval($room_id), do_lang_tempcode('CHAT_MOD_PANEL'))));
     require_code('templates_donext');
     return do_next_manager($title, do_lang_tempcode('SUCCESS'), NULL, NULL, NULL, NULL, array('_SELF', array('type' => 'room', 'id' => $room_id), '_SELF'), NULL, array('_SELF', array(), '_SELF'), NULL, NULL, NULL, NULL, NULL, array(has_actual_page_access(get_member(), 'admin_chat') ? array('chatrooms', array('admin_chat', array('type' => 'misc'), get_module_zone('admin_chat')), do_lang('SETUP')) : NULL));
 }
コード例 #26
0
ファイル: admin_stats.php プロジェクト: erico-deh/ocPortal
 /**
  * The UI to show page view statistics.
  *
  * @return tempcode		The UI
  */
 function page_stats()
 {
     //This will show a plain bar chart with all the pages listed
     // Handle time range
     if (get_param_integer('dated', 0) == 0) {
         $title = get_page_title('PAGES_STATISTICS');
         return $this->get_between($title, true);
     }
     $time_start = get_input_date('time_start', true);
     $time_end = get_input_date('time_end', true);
     if (!is_null($time_end)) {
         $time_end += 60 * 60 * 24 - 1;
     }
     // So it is end of day not start
     if (is_null($time_start)) {
         $time_start = 0;
     }
     if (is_null($time_end)) {
         $time_end = time();
     }
     $first_stat = $GLOBALS['SITE_DB']->query_value_null_ok('stats', 'MIN(date_and_time)');
     if ($time_end < $first_stat) {
         warn_exit(do_lang_tempcode('NO_DATA_SPECIFIC'));
     }
     $start = get_param_integer('start', 0);
     $max = get_param_integer('max', 30);
     $csv = get_param_integer('csv', 0) == 1;
     if ($csv) {
         if (function_exists('set_time_limit')) {
             @set_time_limit(0);
         }
         $start = 0;
         $max = 10000;
         /*$time_start=0;		Actually, this is annoying. We have legitimate reason to filter, and cannot re-filter the data in Excel retro-actively
         		$time_end=time();*/
     }
     $title = get_page_title('PAGES_STATISTICS_RANGE', true, array(escape_html(get_timezoned_date($time_start, false)), escape_html(get_timezoned_date($time_end, false))));
     $rows = $GLOBALS['SITE_DB']->query_select('stats', array('the_page'), NULL, 'GROUP BY the_page ORDER BY COUNT(*) DESC', 3000);
     if (count($rows) < 1) {
         return warn_screen($title, do_lang_tempcode('NO_DATA'));
     }
     $views = array(do_lang('_ALL') => 0);
     $total = 0;
     foreach ($rows as $row) {
         $page = $row['the_page'];
         $matches = array();
         if (preg_match('#^/?([^/]+)/pages/([^/]+)/(\\w\\w/)?([^/\\.]+)\\.(php|txt|htm)$#', $page, $matches) == 1 && $matches[4] == 'catalogues' && addon_installed('catalogues') && $GLOBALS['SITE_DB']->query_value('catalogue_categories', 'COUNT(*)', NULL, '', true) < 300) {
             require_lang('catalogues');
             $categories = $GLOBALS['SITE_DB']->query_select('catalogue_categories', array('id', 'cc_title'), NULL, '', NULL, NULL, true);
             foreach ($categories as $cat) {
                 $where = db_string_equal_to('the_page', $page);
                 if (substr($page, 0, 6) == 'pages/') {
                     $where .= ' OR ' . db_string_equal_to('the_page', '/' . $page);
                 }
                 // Legacy compatibility
                 $count = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'stats WHERE (' . $where . ') AND s_get LIKE \'' . db_encode_like('<param>page=catalogues</param>\\n<param>type=category</param>\\n<param>id=' . strval($cat['id']) . '</param>%') . '\' AND date_and_time>' . strval((int) $time_start) . ' AND date_and_time<' . strval((int) $time_end));
                 $views[do_lang('CATALOGUE_CATEGORY') . ': ' . get_translated_text($cat['cc_title'])] = array($count, $page);
                 $total += $count;
             }
             continue;
         } else {
             $page2 = page_path_to_pagelink($page);
             if ($page2 == '') {
                 $page2 = $page;
             }
         }
         $where = db_string_equal_to('the_page', $page);
         if (substr($page, 0, 6) == 'pages/') {
             $where .= ' OR ' . db_string_equal_to('the_page', '/' . $page);
         }
         // Legacy compatibility
         $views[$page2] = array($GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'stats WHERE (' . $where . ') AND date_and_time>' . strval((int) $time_start) . ' AND date_and_time<' . strval((int) $time_end)), $page);
         $total += $views[$page2][0];
     }
     $views[do_lang('_ALL')] = array($total, NULL);
     $sortables = array('views' => do_lang_tempcode('COUNT_VIEWS'));
     $test = explode(' ', get_param('sort', 'views DESC'), 2);
     if (count($test) == 1) {
         $test[1] = 'DESC';
     }
     list($sortable, $sort_order) = $test;
     if (strtoupper($sort_order) != 'ASC' && strtoupper($sort_order) != 'DESC' || !array_key_exists($sortable, $sortables)) {
         log_hack_attack_and_exit('ORDERBY_HACK');
     }
     global $NON_CANONICAL_PARAMS;
     $NON_CANONICAL_PARAMS[] = 'sort';
     global $M_SORT_KEY;
     $M_SORT_KEY = 0;
     uasort($views, 'multi_sort');
     if ($sort_order == 'DESC') {
         $views = array_reverse($views, true);
     }
     require_code('templates_results_table');
     $fields_title = results_field_title(array(do_lang_tempcode('URL'), do_lang_tempcode('COUNT_VIEWS')), $sortables, 'sort', $sortable . ' ' . $sort_order);
     $fields = new ocp_tempcode();
     $i = 0;
     $real_data = array();
     foreach ($views as $url => $_value) {
         if ($i < $start) {
             $i++;
             continue;
         } elseif ($i >= $start + $max) {
             break;
         }
         list($value, $page) = $_value;
         $real_data[] = array('Page/URL' => is_null($page) ? $url : $page, 'Tally' => $value);
         $fields->attach(results_entry(array(is_null($page) ? make_string_tempcode(escape_html($url)) : hyperlink(build_url(array('page' => '_SELF', 'type' => '_page', 'iscreen' => $page), '_SELF'), escape_html($url)), escape_html(integer_format($value)))));
         $i++;
     }
     unset($views['(' . do_lang('ALL') . ')']);
     $list = results_table(do_lang_tempcode('PAGES_STATISTICS'), $start, 'start', $max, 'max', count($views), $fields_title, $fields, $sortables, $sortable, $sort_order, 'sort', new ocp_tempcode());
     if ($csv) {
         make_csv($real_data, 'page_stats.csv');
     }
     $output = create_bar_chart(array_slice($views, $start, $max), do_lang('PAGE'), do_lang('COUNT_VIEWS'), '', '');
     $this->save_graph('Global-Views', $output);
     $graph = do_template('STATS_GRAPH', array('_GUID' => 'ea79fdc013046ef94992daeab961f2da', 'GRAPH' => get_custom_base_url() . '/data_custom/modules/admin_stats/Global-Views.xml', 'TITLE' => do_lang_tempcode('PAGES_STATISTICS'), 'TEXT' => do_lang_tempcode('DESCRIPTION_PAGES_STATISTICS')));
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('SITE_STATISTICS'))));
     return do_template('STATS_SCREEN', array('_GUID' => 'cfe7d5aee8aa3c0d3a54bd3bf2d09e7f', 'TITLE' => $title, 'GRAPH' => $graph, 'STATS' => $list));
 }
コード例 #27
0
 /**
  * The UI to send a newsletter.
  *
  * @param  LONG_TEXT		Default newsletter to put in
  * @return tempcode		The UI
  */
 function send_gui($_existing = '')
 {
     // If this is a periodic newsletter, we make some changes to the regular
     // language strings.
     $periodic_action_raw = post_param('periodic_choice', '');
     $periodic_subject = '';
     $defaults = mixed();
     switch (preg_replace('#\\_\\d+$#', '', $periodic_action_raw)) {
         case 'remove_existing':
             // Remove whatever is already set. We don't need any changes for
             // this, but we do need a hidden form field.
             $periodic_action = 'remove';
             break;
         case 'replace_existing':
             // Make the current newsletter periodic. This requires language
             // fiddling.
             $periodic_action = 'replace';
             $periodic_subject = do_lang('PERIODIC_SUBJECT_HELP');
             $periodic_id = intval(preg_replace('#^[^\\d]+#', '', $periodic_action_raw));
             $_defaults = $GLOBALS['SITE_DB']->query_select('newsletter_periodic', array('*'), array('id' => $periodic_id), '', 1);
             if (!array_key_exists(0, $_defaults)) {
                 warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
             }
             $defaults = $_defaults[0];
             break;
         case 'make_periodic':
             // Make the current newsletter periodic. This requires language
             // fiddling.
             $periodic_action = 'make';
             $periodic_subject = do_lang('PERIODIC_SUBJECT_HELP');
             break;
         case 'no_change':
         default:
             // The default action is to leave the current settings as-is.
             $periodic_action = 'none';
             break;
     }
     $title = get_page_title('NEWSLETTER_SEND');
     $lang = choose_language($title);
     if (is_object($lang)) {
         return $lang;
     }
     $comcode_given = $_existing != '' && strpos($_existing, '<html') !== false;
     $_existing = post_param('message', $_existing);
     if ($_existing == '') {
         $from_news = get_param_integer('from_news', -1);
         if ($from_news != -1 && addon_installed('news')) {
             $rows = $GLOBALS['SITE_DB']->query_select('news', array('*'), array('id' => $from_news), 'ORDER BY id DESC', 1);
             if (!array_key_exists(0, $rows)) {
                 require_lang('news');
                 return warn_screen(get_page_title('NEWS'), do_lang_tempcode('MISSING_RESOURCE'));
             }
             $myrow = $rows[0];
             $_existing = get_translated_text($myrow['news_article'], NULL, $lang);
             if ($_existing == '') {
                 $_existing = get_translated_text($myrow['news'], NULL, $lang);
             }
         }
         $existing = do_template('NEWSLETTER_DEFAULT', array('_GUID' => '53c02947915806e519fe14c318813f42', 'CONTENT' => $_existing, 'LANG' => $lang));
     } else {
         $default = do_template('NEWSLETTER_DEFAULT', array('_GUID' => '53c02947915806e519fe14c318813f44', 'CONTENT' => $_existing, 'LANG' => $lang));
         if (strpos($default->evaluate(), '<html') !== false) {
             if ($comcode_given) {
                 $default = do_template('NEWSLETTER_DEFAULT', array('_GUID' => '53c02947915806e519fe14c318813f46', 'CONTENT' => comcode_to_tempcode($_existing), 'LANG' => $lang));
             }
             $existing = $default;
         } else {
             $existing = make_string_tempcode($_existing);
         }
     }
     $post_url = build_url(array('page' => '_SELF', 'type' => 'confirm', 'old_type' => get_param('type', '')), '_SELF');
     $submit_name = do_lang_tempcode('PREVIEW');
     $hidden = new ocp_tempcode();
     $hidden->attach(form_input_hidden('lang', $lang));
     // Build up form
     $fields = new ocp_tempcode();
     require_code('form_templates');
     $default_subject = get_option('newsletter_title');
     if (!is_null($defaults)) {
         $default_subject = $defaults['np_subject'];
     }
     if ($periodic_action != 'make' && $periodic_action != 'replace') {
         $default_subject .= ' - ' . get_timezoned_date(time(), false, false, false, true);
     }
     $default_subject = post_param('subject', $default_subject);
     $fields->attach(form_input_line_comcode(do_lang_tempcode('SUBJECT'), do_lang_tempcode('NEWSLETTER_DESCRIPTION_TITLE', $periodic_subject), 'subject', $default_subject, true));
     $in_full = post_param_integer('in_full', 0);
     $chosen_categories = post_param('chosen_categories', '');
     if ($periodic_action == 'make' || $periodic_action == 'replace') {
         // We are making a periodic newsletter. This means we need to pass
         // through the chosen categories
         if (!is_null($defaults)) {
             $chosen_categories = $defaults['np_message'];
             $in_full = $defaults['np_in_full'];
             $fields->attach(form_input_tick(do_lang_tempcode('EMBED_FULL_ARTICLES'), do_lang_tempcode('DESCRIPTION_EMBED_FULL_ARTICLES'), 'in_full', $in_full == 1));
             $fields->attach(form_input_huge(do_lang_tempcode('NEWSLETTER_CONTENT'), do_lang('NEWSLETTER_CONTENT_SELECT'), 'chosen_categories', $chosen_categories, true));
         } else {
             $hidden->attach(form_input_hidden('chosen_categories', $chosen_categories));
             $hidden->attach(form_input_hidden('in_full', strval($in_full)));
         }
         $hidden->attach(form_input_hidden('cutoff_day', post_param('cutoff_day')));
         $hidden->attach(form_input_hidden('cutoff_month', post_param('cutoff_month')));
         $hidden->attach(form_input_hidden('cutoff_year', post_param('cutoff_year')));
         $hidden->attach(form_input_hidden('cutoff_hour', post_param('cutoff_hour')));
         $hidden->attach(form_input_hidden('cutoff_minute', post_param('cutoff_minute')));
         $hidden->attach(form_input_hidden('message', $existing->evaluate()));
     } else {
         $hidden->attach(form_input_hidden('in_full', strval($in_full)));
         if (strpos($existing->evaluate(), '<html') === false) {
             $fields->attach(form_input_huge_comcode(do_lang_tempcode('MESSAGE'), do_lang_tempcode('DESCRIPTION_MESSAGE_NEWSLETTER'), 'message', $existing->evaluate(), true));
         } else {
             $fields->attach(form_input_huge(do_lang_tempcode('MESSAGE'), do_lang_tempcode('DESCRIPTION_MESSAGE_NEWSLETTER'), 'message', $existing->evaluate(), true));
         }
     }
     if (addon_installed('calendar') && $periodic_action == 'none' && cron_installed()) {
         $fields->attach(form_input_date__scheduler(do_lang_tempcode('DEFER_TIME'), do_lang_tempcode('DESCRIPTION_DEFER_TIME'), 'schedule', true, true, true));
     }
     $from_email = post_param('from_email', get_option('staff_address'));
     if (!is_null($defaults)) {
         $from_email = post_param('from_email', $defaults['np_from_email']);
     }
     $fields->attach(form_input_email(do_lang_tempcode('FROM_EMAIL'), do_lang_tempcode('DESCRIPTION_NEWSLETTER_FROM_EMAIL'), 'from_email', $from_email, true));
     $from_name = post_param('from_name', get_site_name());
     if (!is_null($defaults)) {
         $from_name = post_param('from_name', $defaults['np_from_name']);
     }
     $fields->attach(form_input_line(do_lang_tempcode('FROM_NAME'), do_lang_tempcode('DESCRIPTION_NEWSLETTER_FROM_NAME'), 'from_name', $from_name, true));
     $_html_only = post_param_integer('html_only', NULL);
     if (is_null($_html_only)) {
         $html_only = strpos($existing->evaluate(), '<html') !== false;
         if (!is_null($defaults)) {
             $html_only = $defaults['np_html_only'];
         }
     } else {
         $html_only = $_html_only == 1;
     }
     if (get_value('force_html_only') === '1') {
         $hidden->attach(form_input_hidden('html_only', '1'));
     } else {
         $fields->attach(form_input_tick(do_lang_tempcode('HTML_ONLY'), do_lang_tempcode('DESCRIPTION_HTML_ONLY'), 'html_only', $html_only));
     }
     $l = new ocp_tempcode();
     $priority = post_param_integer('priority', 3);
     if (!is_null($defaults)) {
         $priority = post_param_integer('priority', $defaults['np_priority']);
     }
     for ($i = 1; $i <= 5; $i++) {
         $l->attach(form_input_list_entry(strval($i), $i == $priority, do_lang_tempcode('PRIORITY_' . strval($i))));
     }
     $fields->attach(form_input_list(do_lang_tempcode('PRIORITY'), do_lang_tempcode('DESCRIPTION_NEWSLETTER_PRIORITY'), 'priority', $l));
     // Where to send to
     $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang_tempcode('CHOOSE_SEND_TO'))));
     $newsletters = $GLOBALS['SITE_DB']->query_select('newsletters', array('*'));
     foreach ($newsletters as $newsletter) {
         $level = post_param_integer(strval($newsletter['id']), post_param_integer('level', -1));
         $c4 = $this->count_level($newsletter['id'], 4, $lang);
         $c3 = $this->count_level($newsletter['id'], 3, $lang);
         $c2 = $this->count_level($newsletter['id'], 2, $lang);
         $c1 = $this->count_level($newsletter['id'], 1, $lang);
         if ($c1 != 0) {
             $newsletter_title = get_translated_text($newsletter['title']);
             $newsletter_description = get_translated_text($newsletter['description']);
             if ($c1 == $c2 && $c1 == $c3 && $c1 == $c4) {
                 $fields->attach(form_input_tick(do_lang_tempcode('NEWSLETTER_PREFIX', escape_html($newsletter_title)), do_lang_tempcode('DESCRIPTION_NOSUBSCRIPTION_LEVEL', escape_html(integer_format($c4)), escape_html($newsletter_description)), strval($newsletter['id']), $level >= 1, NULL, '4'));
             } else {
                 $l = new ocp_tempcode();
                 $l->attach(form_input_list_entry('0', $level == 0, do_lang_tempcode('NNR', do_lang_tempcode('NEWSLETTER_0_ALT'), do_lang_tempcode('NUM_READERS', integer_format(0)))));
                 $l->attach(form_input_list_entry('1', $level == 1, do_lang_tempcode('NNR', do_lang_tempcode('NEWSLETTER_1'), do_lang_tempcode('NUM_READERS', integer_format($c1)))));
                 $l->attach(form_input_list_entry('2', $level == 2, do_lang_tempcode('NNR', do_lang_tempcode('NEWSLETTER_2'), do_lang_tempcode('NUM_READERS', integer_format($c2)))));
                 $l->attach(form_input_list_entry('3', $level == 3, do_lang_tempcode('NNR', do_lang_tempcode('NEWSLETTER_3'), do_lang_tempcode('NUM_READERS', integer_format($c3)))));
                 $l->attach(form_input_list_entry('4', $level == 4, do_lang_tempcode('NNR', do_lang_tempcode('NEWSLETTER_4'), do_lang_tempcode('NUM_READERS', integer_format($c4)))));
                 $fields->attach(form_input_list(do_lang_tempcode('SUBSCRIPTION_LEVEL_FOR', escape_html($newsletter_title)), do_lang_tempcode('DESCRIPTION_SUBSCRIPTION_LEVEL', escape_html($newsletter_description)), strval($newsletter['id']), $l));
             }
         }
     }
     if (get_forum_type() == 'ocf') {
         $c5 = $this->count_level(-1, 5, $lang);
         $fields->attach(form_input_tick(do_lang_tempcode('NEWSLETTER_OCF'), do_lang_tempcode('NUM_READERS', integer_format($c5)), '-1', false));
         $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list();
         foreach ($groups as $group_id => $group) {
             if ($group_id != db_get_first_id()) {
                 $map = array();
                 $map['g' . strval($group_id)] = 1;
                 $_c = newsletter_who_send_to($map, $lang, 0, 0);
                 $c6 = $_c[6]['g' . strval($group_id)];
                 if ($c6 != 0) {
                     $fields->attach(form_input_tick(do_lang_tempcode('THIS_WITH', do_lang_tempcode('GROUP'), make_string_tempcode(escape_html($group))), do_lang_tempcode('NUM_READERS', integer_format($c6)), 'g' . strval($group_id), post_param_integer('g' . strval($group_id), 0) == 1));
                 }
             }
         }
     }
     $fields->attach(form_input_upload(do_lang_tempcode('UPLOAD'), do_lang_tempcode('DESCRIPTION_UPLOAD_CSV'), 'file', false, NULL, NULL, true, 'csv,txt'));
     //if ($fields->is_empty()) inform_exit(do_lang_tempcode('NOBODY_TO_SEND_TO'));
     handle_max_file_size($hidden);
     $template_choices = new ocp_tempcode();
     $dh = opendir(get_custom_file_base() . '/themes/default/templates_custom');
     while (($f = readdir($dh)) !== false) {
         if (preg_match('#^MAIL.*\\.tpl$#', $f) != 0) {
             $tpl = basename($f, '.tpl');
             $template_choices->attach(form_input_list_entry($tpl, post_param('template', 'MAIL') == $tpl, $tpl));
         }
     }
     if (!file_exists(get_custom_file_base() . '/themes/default/templates_custom/MAIL.tpl')) {
         $template_choices->attach(form_input_list_entry('MAIL', true, 'MAIL'));
     }
     closedir($dh);
     $fields->attach(form_input_list(do_lang_tempcode('NEWSLETTER_TEMPLATE'), do_lang_tempcode('DESCRIPTION_NEWSLETTER_TEMPLATE'), 'template', $template_choices, NULL, false, true));
     // If we're making a periodic newsletter then we need to know when it
     // should be sent
     if ($periodic_action == 'make' || $periodic_action == 'replace') {
         $hidden->attach(form_input_hidden('make_periodic', '1'));
         $hidden->attach(form_input_hidden('periodic_choice', post_param('periodic_choice')));
         $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang('PERIODIC_WHEN'), 'HELP' => do_lang('PERIODIC_WHEN_HELP'))));
         // The choices are given as radio buttons: weekly or bi-weekly or monthly?
         // In the labels for these radio buttons, we put a dropdown for day of
         // the week and day of the month.
         $frequency = post_param('periodic_when', 'weekly');
         if (!is_null($defaults)) {
             $frequency = post_param('periodic_when', $defaults['np_frequency']);
         }
         $current_day_weekly = post_param_integer('periodic_weekly', 5);
         if (!is_null($defaults)) {
             $current_day_weekly = post_param_integer('periodic_weekly', $defaults['np_day']);
         }
         $current_day_biweekly = post_param_integer('periodic_biweekly', 5);
         if (!is_null($defaults)) {
             $current_day_biweekly = post_param_integer('periodic_biweekly', $defaults['np_day']);
         }
         $current_day_of_month = post_param_integer('periodic_monthly', 1);
         if (!is_null($defaults)) {
             $current_day_of_month = post_param_integer('periodic_monthly', $defaults['np_day']);
         }
         $radios = new ocp_tempcode();
         $week_days_weekly = new ocp_tempcode();
         $week_days_biweekly = new ocp_tempcode();
         require_lang('dates');
         $week_days = array(1 => do_lang('MONDAY'), 2 => do_lang('TUESDAY'), 3 => do_lang('WEDNESDAY'), 4 => do_lang('THURSDAY'), 5 => do_lang('FRIDAY'), 6 => do_lang('SATURDAY'), 7 => do_lang('SUNDAY'));
         foreach ($week_days as $i => $this_day) {
             $week_days_weekly->attach(form_input_list_entry(strval($i), $i == $current_day_weekly, $this_day, false, false));
             $week_days_biweekly->attach(form_input_list_entry(strval($i), $i == $current_day_biweekly, $this_day, false, false));
         }
         $weekly_desc = new ocp_tempcode();
         $weekly_desc->attach(do_lang('PERIODIC_WEEKLY_ON'));
         $weekly_desc->attach(do_template('FORM_SCREEN_INPUT_LIST', array('TABINDEX' => strval(get_form_field_tabindex(NULL)), 'REQUIRED' => '0', 'NAME' => 'periodic_weekday_weekly', 'CONTENT' => $week_days_weekly, 'INLINE_LIST' => '0')));
         $radios->attach(form_input_radio_entry('periodic_when', 'weekly', $frequency == 'weekly', $weekly_desc, NULL, ''));
         $weekly_desc = new ocp_tempcode();
         $weekly_desc->attach(do_lang('PERIODIC_BIWEEKLY_ON'));
         $weekly_desc->attach(do_template('FORM_SCREEN_INPUT_LIST', array('TABINDEX' => strval(get_form_field_tabindex(NULL)), 'REQUIRED' => '0', 'NAME' => 'periodic_weekday_biweekly', 'CONTENT' => $week_days_biweekly, 'INLINE_LIST' => '0')));
         $radios->attach(form_input_radio_entry('periodic_when', 'biweekly', $frequency == 'biweekly', $weekly_desc, NULL, ''));
         $month_days = new ocp_tempcode();
         foreach (range(1, 28) as $this_day) {
             $suffix = gmdate('S', gmmktime(0, 0, 0, 1, $this_day, 1990));
             $month_days->attach(form_input_list_entry(strval($this_day), $this_day == 1, strval($this_day) . $suffix, $current_day_of_month == $this_day));
         }
         $monthly_desc = new ocp_tempcode();
         $monthly_desc->attach(do_lang('PERIODIC_MONTHLY_ON'));
         $monthly_desc->attach(do_template('FORM_SCREEN_INPUT_LIST', array('TABINDEX' => strval(get_form_field_tabindex(NULL)), 'REQUIRED' => '0', 'NAME' => 'periodic_monthly', 'CONTENT' => $month_days, 'INLINE_LIST' => '0')));
         $radios->attach(form_input_radio_entry('periodic_when', 'monthly', $frequency == 'monthly', $monthly_desc, NULL, ''));
         $fields->attach(form_input_radio(do_lang('PERIODIC_WHEN_CHOICE'), '', 'periodic_when', $radios, true));
         $radios = new ocp_tempcode();
         $radios->attach(form_input_radio_entry('periodic_for', 'all', false, do_lang_tempcode('CREATE_PERIODIC_FOR_ALL'), NULL, ''));
         $radios->attach(form_input_radio_entry('periodic_for', 'future', true, do_lang_tempcode('CREATE_PERIODIC_FOR_FUTURE'), NULL, ''));
         $fields->attach(form_input_radio(do_lang('CREATE_PERIODIC_FOR'), '', 'periodic_for', $radios, true));
     }
     return do_template('FORM_SCREEN', array('_GUID' => '0b2a4825ec586d9ff557026d9a1e0cca', 'TITLE' => $title, 'TEXT' => $periodic_action == 'make' || $periodic_action == 'replace' ? do_lang_tempcode('PERIODIC_NO_EDIT') : do_lang_tempcode('NEWSLETTER_SEND_TEXT'), 'HIDDEN' => $hidden, 'FIELDS' => $fields->evaluate(), 'SUBMIT_NAME' => $submit_name, 'URL' => $post_url));
 }
コード例 #28
0
ファイル: topic_pin.php プロジェクト: erico-deh/ocPortal
 /**
  * Standard actualisation stage of pointstore item purchase.
  *
  * @return tempcode		The UI
  */
 function action_done()
 {
     $class = str_replace('hook_pointstore_', '', strtolower(get_class($this)));
     if (get_option('is_on_' . $class . '_buy') == '0') {
         return new ocp_tempcode();
     }
     $topic_id = post_param_integer('select_topic_id', -1);
     if ($topic_id == -1) {
         $_topic_id = post_param('manual_topic_id');
         $topic_id = intval($_topic_id);
     }
     $title = get_page_title('TOPIC_PINNING');
     // Check points
     $cost = intval(get_option($class));
     $points_left = available_points(get_member());
     if ($points_left < $cost && !has_specific_permission(get_member(), 'give_points_self')) {
         return warn_screen($title, do_lang_tempcode('_CANT_AFFORD', integer_format($cost), integer_format($points_left)));
     }
     // Actuate
     $GLOBALS['FORUM_DRIVER']->pin_topic($topic_id);
     require_code('points2');
     charge_member(get_member(), $cost, do_lang('TOPIC_PINNING'));
     $GLOBALS['SITE_DB']->query_insert('sales', array('date_and_time' => time(), 'memberid' => get_member(), 'purchasetype' => 'TOPIC_PINNING', 'details' => strval($topic_id), 'details2' => ''));
     // Show message
     $url = build_url(array('page' => '_SELF', 'type' => 'misc'), '_SELF');
     return redirect_screen($title, $url, do_lang_tempcode('ORDER_GENERAL_DONE'));
 }
コード例 #29
0
ファイル: flagrant.php プロジェクト: erico-deh/ocPortal
 /**
  * Standard stage of pointstore item purchase.
  *
  * @return tempcode		The UI
  */
 function ___text()
 {
     if (get_option('is_on_flagrant_buy') == '0') {
         return new ocp_tempcode();
     }
     $title = get_page_title('TITLE_NEWTEXT');
     // Define variables
     $member_id = get_member();
     $message = post_param('message');
     $days = post_param_integer('days');
     $points_left = available_points($member_id);
     // First we need to know the price of the number of days we ordered. After that, compare that price with our users current number of points.
     $dayprice = intval(get_option('text'));
     $total = $dayprice * $days;
     if ($points_left < $total && !has_specific_permission(get_member(), 'give_points_self')) {
         return warn_screen($title, do_lang_tempcode('FLAGRANT_LACK_POINTS', integer_format($days), integer_format($total), integer_format($points_left)));
     }
     // Add this to the database
     $GLOBALS['SITE_DB']->query_insert('text', array('notes' => '', 'activation_time' => NULL, 'active_now' => 0, 'user_id' => $member_id, 'the_message' => insert_lang_comcode($message, 2), 'days' => $days, 'order_time' => time()));
     // Mail off the notice
     require_code('notifications');
     $_url = build_url(array('page' => 'admin_flagrant'), 'adminzone', NULL, false, false, true);
     $manage_url = $_url->evaluate();
     dispatch_notification('pointstore_request_flagrant', NULL, do_lang('TITLE_NEWTEXT', NULL, NULL, NULL, get_site_default_lang()), do_lang('MAIL_FLAGRANT_TEXT', $message, comcode_escape($manage_url), NULL, get_site_default_lang()));
     // Now, deduct the points from our user's account
     require_code('points2');
     charge_member($member_id, $total, do_lang('PURCHASED_FLAGRANT'));
     $url = build_url(array('page' => '_SELF', 'type' => 'misc'), '_SELF');
     return redirect_screen($title, $url, do_lang_tempcode('ORDER_FLAGRANT_DONE'));
 }
コード例 #30
0
ファイル: bank.php プロジェクト: erico-deh/ocPortal
 /**
  * Standard actualisation stage of pointstore item purchase.
  *
  * @return tempcode		The UI
  */
 function action_done()
 {
     $class = str_replace('hook_pointstore_', '', strtolower(get_class($this)));
     //if (get_option('is_on_'.$class.'_buy')=='0')  return new ocp_tempcode();
     $amount = post_param_integer('amount', 0);
     $bank_dividend = intval(get_option('bank_divident'));
     $title = get_page_title('BANKING');
     // Check points
     $points_left = available_points(get_member());
     if (!has_specific_permission(get_member(), 'give_points_self')) {
         if ($points_left < $amount) {
             return warn_screen($title, do_lang_tempcode('_CANT_AFFORD_BANK'));
         }
     }
     // Actuate
     require_code('points2');
     charge_member(get_member(), $amount, do_lang('BANKING'));
     $GLOBALS['SITE_DB']->query_insert('bank', array('add_time' => time(), 'user_id' => get_member(), 'amount' => strval($amount), 'divident' => $bank_dividend));
     // Show message
     $result = do_lang_tempcode('BANKING_CONGRATULATIONS', integer_format($amount), integer_format($bank_dividend));
     $url = build_url(array('page' => '_SELF', 'type' => 'misc'), '_SELF');
     return redirect_screen($title, $url, $result);
 }