Example #1
0
/**
 * Pop-up some rules.
 */
function rules_script()
{
    $id = get_param_integer('id', NULL);
    if (is_null($id)) {
        require_code('site');
        $output = request_page('rules', true);
        $title = do_lang_tempcode('RULES');
    } else {
        if (!has_category_access(get_member(), 'forums', strval($id))) {
            warn_exit(do_lang_tempcode('ACCESS_DENIED'));
        }
        $forum_rows = $GLOBALS['FORUM_DB']->query_select('f_forums', array('*'), array('id' => $id), '', 1);
        if (!array_key_exists(0, $forum_rows)) {
            warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
        }
        $forum_row = $forum_rows[0];
        require_lang('ocf');
        $question = get_translated_tempcode($forum_row['f_intro_question'], $GLOBALS['FORUM_DB']);
        $answer = $forum_row['f_intro_answer'];
        $output = do_template('OCF_FORUM_INTRO_QUESTION_POPUP', array('_GUID' => '6f2dc12b616219ff982654b73ef979b2', 'QUESTION' => $question, 'ANSWER' => $answer));
        $title = $answer == '' ? do_lang_tempcode('FORUM_RULES') : do_lang_tempcode('INTRO_QUESTION');
    }
    $tpl = do_template('POPUP_HTML_WRAP', array('_GUID' => '26c4dbc7a4737310f089583f1048cb13', 'TITLE' => $title, 'TARGET' => '_top', 'CONTENT' => $output));
    $tpl->evaluate_echo();
}
Example #2
0
 /**
  * Standard modular run function for award hooks. Renders a content box for an award/randomisation.
  *
  * @param  array		The database row for the content
  * @param  ID_TEXT	The zone to display in
  * @return tempcode	Results
  */
 function run($row, $zone)
 {
     $url = build_url(array('page' => 'news', 'type' => 'view', 'id' => $row['id']), $zone);
     $title = get_translated_tempcode($row['title']);
     $title_plain = get_translated_text($row['title']);
     $news_cat_rows = $GLOBALS['SITE_DB']->query_select('news_categories', array('nc_title', 'nc_img'), array('id' => $row['news_category']), '', 1);
     if (!array_key_exists(0, $news_cat_rows)) {
         warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
     }
     $news_cat_row = $news_cat_rows[0];
     $category = get_translated_text($news_cat_row['nc_title']);
     $img = find_theme_image($news_cat_row['nc_img']);
     if ($row['news_image'] != '') {
         $img = $row['news_image'];
         if (url_is_local($img)) {
             $img = get_base_url() . '/' . $img;
         }
     }
     $news = get_translated_tempcode($row['news']);
     if ($news->is_empty()) {
         $news = get_translated_tempcode($row['news_article']);
         $truncate = true;
     } else {
         $truncate = false;
     }
     $author_url = addon_installed('authors') ? build_url(array('page' => 'authors', 'type' => 'misc', 'id' => $row['author']), get_module_zone('authors')) : new ocp_tempcode();
     $author = $row['author'];
     require_css('news');
     $seo_bits = seo_meta_get_for('news', strval($row['id']));
     $map = array('_GUID' => 'jd89f893jlkj9832gr3uyg2u', 'TAGS' => get_loaded_tags('news', explode(',', $seo_bits[0])), 'TRUNCATE' => $truncate, 'AUTHOR' => $author, 'BLOG' => false, 'AUTHOR_URL' => $author_url, 'CATEGORY' => $category, 'IMG' => $img, 'NEWS' => $news, 'ID' => strval($row['id']), 'SUBMITTER' => strval($row['submitter']), 'DATE' => get_timezoned_date($row['date_and_time']), 'DATE_RAW' => strval($row['date_and_time']), 'FULL_URL' => $url, 'NEWS_TITLE' => $title, 'NEWS_TITLE_PLAIN' => $title_plain);
     if (get_option('is_on_comments') == '1' && !has_no_forum() && $row['allow_comments'] >= 1) {
         $map['COMMENT_COUNT'] = '1';
     }
     return put_in_standard_box(do_template('NEWS_PIECE_SUMMARY', $map));
 }
Example #3
0
/**
 * Find whether a member may attach a poll to a detailed topic.
 *
 * @param  AUTO_LINK The topic.
 * @param  ?MEMBER	The topic owner (NULL: ask the DB for it).
 * @param  ?boolean  Whether the topic already has a poll (NULL: ask the DB for it).
 * @param  ?MEMBER	The forum the topic is in (NULL: ask the DB for it).
 * @param  ?MEMBER	The member we are checking for (NULL: current member).
 * @return boolean	The answer.
 */
function ocf_may_attach_poll($topic_id, $topic_owner = NULL, $has_poll_already = NULL, $forum_id = NULL, $member_id = NULL)
{
    if (is_null($topic_owner)) {
        $topic_info = $GLOBALS['FORUM_DB']->query_select('f_topics', array('*'), array('id' => $topic_id), '', 1);
        if (!array_key_exists(0, $topic_info)) {
            warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
        }
        $topic_owner = $topic_info[0]['t_cache_first_member_id'];
        $has_poll_already = !is_null($topic_info[0]['t_poll_id']);
        $forum_id = $topic_info[0]['t_forum_id'];
    }
    if (is_null($member_id)) {
        $member_id = get_member();
    }
    if ($has_poll_already) {
        return false;
    }
    if ($topic_owner == $member_id && !is_guest($member_id)) {
        return true;
    }
    if (ocf_may_moderate_forum($forum_id, $member_id)) {
        return true;
    }
    return false;
}
Example #4
0
/**
 * Make the functions.dat file
 */
function make_functions_dat()
{
    $files = make_functions_dat_do_dir(get_custom_file_base());
    $classes = array();
    $global = array();
    foreach ($files as $filename) {
        if (strpos($filename, '_custom') !== false) {
            continue;
        }
        $_filename = substr($filename, strlen(get_custom_file_base()) + 1);
        if ($_filename == 'sources/minikernel.php') {
            continue;
        }
        $result = get_php_file_api($_filename, false);
        foreach ($result as $i => $r) {
            if ($r['name'] == '__global') {
                $global = array_merge($global, $r['functions']);
                unset($result[$i]);
            }
        }
        $classes = array_merge($classes, $result);
    }
    $classes['__global'] = array('functions' => $global);
    $myfile = @fopen(get_custom_file_base() . '/data_custom/functions.dat', 'wt') or intelligent_write_error(get_custom_file_base() . '/data_custom/functions.dat');
    if (fwrite($myfile, serialize($classes)) == 0) {
        warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
    }
    fclose($myfile);
}
Example #5
0
 /**
  * Standard modular run function.
  *
  * @return tempcode	The result of execution.
  */
 function run()
 {
     require_lang('leader_board');
     require_code('points');
     require_css('points');
     $title = get_page_title('POINT_LEADERBOARD');
     $start_date = intval(get_option('leaderboard_start_date'));
     $weeks = $GLOBALS['SITE_DB']->query('SELECT DISTINCT date_and_time FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'leader_board WHERE date_and_time>=' . strval($start_date) . ' ORDER BY date_and_time DESC');
     if (count($weeks) == 0) {
         warn_exit(do_lang_tempcode('NO_ENTRIES'));
     }
     $first_week = $weeks[count($weeks) - 1]['date_and_time'];
     $weeks = collapse_1d_complexity('date_and_time', $weeks);
     $out = new ocp_tempcode();
     foreach ($weeks as $week) {
         $rows = collapse_2d_complexity('lb_member', 'lb_points', $GLOBALS['SITE_DB']->query_select('leader_board', array('lb_member', 'lb_points'), array('date_and_time' => $week)));
         $week_tpl = new ocp_tempcode();
         foreach ($rows as $member => $points) {
             $points_url = build_url(array('page' => 'points', 'type' => 'member', 'id' => $member), get_module_zone('points'));
             $profile_url = $GLOBALS['FORUM_DRIVER']->member_profile_url($member, false, true);
             $name = $GLOBALS['FORUM_DRIVER']->get_username($member);
             if (is_null($name)) {
                 $name = do_lang('UNKNOWN');
             }
             $week_tpl->attach(do_template('POINTS_LEADERBOARD_ROW', array('_GUID' => '6d323b4b5abea0e82a14cb4745c4af4f', 'POINTS_URL' => $points_url, 'PROFILE_URL' => $profile_url, 'POINTS' => integer_format($points), 'NAME' => $name, 'ID' => strval($member))));
         }
         $nice_week = intval(($week - $first_week) / (7 * 24 * 60 * 60) + 1);
         $out->attach(do_template('POINTS_LEADERBOARD_WEEK', array('_GUID' => '3a0f71bf20f9098e5711e85cf25f6549', 'WEEK' => integer_format($nice_week), 'ROWS' => $week_tpl)));
     }
     return do_template('POINTS_LEADERBOARD_SCREEN', array('_GUID' => 'bab5f7b661435b83800532d3eebd0d54', 'TITLE' => $title, 'WEEKS' => $out));
 }
Example #6
0
 /**
  * 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'));
 }
Example #7
0
 /**
  * Standard modular run function for preview hooks.
  *
  * @return array			A pair: The preview, the updated post Comcode
  */
 function run()
 {
     require_code('uploads');
     $urls = get_url('', 'file', 'uploads/iotds', 0, OCP_UPLOAD_IMAGE, true, '', 'file2');
     if ($urls[0] == '') {
         if (!is_null(post_param_integer('id', NULL))) {
             $rows = $GLOBALS['SITE_DB']->query_select('iotds', array('url', 'thumb_url'), array('id' => post_param_integer('id')), '', 1);
             $urls = $rows[0];
             $url = $urls['url'];
             $thumb_url = $urls['thumb_url'];
         } else {
             warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN_UPLOAD'));
         }
     } else {
         $url = $urls[0];
         $thumb_url = $urls[1];
     }
     $caption = comcode_to_tempcode(post_param('caption', ''));
     $title = comcode_to_tempcode(post_param('title', ''));
     require_code('images');
     $thumb = do_image_thumb(url_is_local($thumb_url) ? get_custom_base_url() . '/' . $thumb_url : $thumb_url, $caption, true);
     $url = url_is_local($url) ? get_custom_base_url() . '/' . $url : $url;
     $preview = do_template('IOTD', array('ID' => '', 'IMAGE_URL' => $url, 'SUBMITTER' => strval(get_member()), 'VIEW_URL' => $url, 'IMAGE' => $thumb, 'CAPTION' => $title));
     return array($preview, NULL);
 }
Example #8
0
 /**
  * Standard modular render function for profile tabs edit hooks.
  *
  * @param  MEMBER			The ID of the member who is being viewed
  * @param  MEMBER			The ID of the member who is doing the viewing
  * @param  boolean		Whether to leave the tab contents NULL, if tis hook supports it, so that AJAX can load it later
  * @return ?array			A tuple: The tab title, the tab body text (may be blank), the tab fields, extra Javascript (may be blank) the suggested tab order, hidden fields (optional) (NULL: if $leave_to_ajax_if_possible was set)
  */
 function render_tab($member_id_of, $member_id_viewing, $leave_to_ajax_if_possible = false)
 {
     $title = do_lang_tempcode('DELETE_MEMBER');
     $order = 200;
     // Actualiser
     $delete_account = post_param_integer('delete', 0);
     if ($delete_account == 1) {
         if (is_guest($member_id_of)) {
             warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
         }
         ocf_delete_member($member_id_of);
         inform_exit(do_lang_tempcode('SUCCESS'));
     }
     if ($leave_to_ajax_if_possible) {
         return NULL;
     }
     // UI fields
     $username = $GLOBALS['FORUM_DRIVER']->get_username($member_id_of);
     $text = do_lang_tempcode('_DELETE_MEMBER' . ($member_id_of == get_member() ? '_SUICIDAL' : ''), escape_html($username));
     $fields = new ocp_tempcode();
     require_code('form_templates');
     $fields->attach(form_input_tick(do_lang_tempcode('DELETE'), do_lang_tempcode('DESCRIPTION_DELETE'), 'delete', false));
     $javascript = '';
     return array($title, $fields, $text, $javascript, $order);
 }
Example #9
0
/**
 * Top level function to (re)generate a Sitemap (xml file, Google-style).
 */
function sitemaps_build()
{
    $GLOBALS['NO_QUERY_LIMIT'] = true;
    $path = get_custom_file_base() . '/ocp_sitemap.xml';
    if (!file_exists($path)) {
        if (!is_writable_wrap(dirname($path))) {
            warn_exit(do_lang_tempcode('WRITE_ERROR_CREATE', escape_html('/')));
        }
    } else {
        if (!is_writable_wrap($path)) {
            warn_exit(do_lang_tempcode('WRITE_ERROR', escape_html('ocp_sitemap.xml')));
        }
    }
    // Runs via a callback mechanism, so we don't need to load an arbitrary complex structure into memory.
    sitemaps_xml_initialise($path);
    spawn_page_crawl('pagelink_to_sitemapsxml', $GLOBALS['FORUM_DRIVER']->get_guest_id(), NULL, DEPTH__ENTRIES);
    sitemaps_xml_finished();
    // Ping search engines
    if (get_option('auto_submit_sitemap') == '1') {
        $ping = true;
        $base_url = get_base_url();
        $not_local = substr($base_url, 0, 16) != 'http://localhost' && substr($base_url, 0, 16) != 'http://127.0.0.1' && substr($base_url, 0, 15) != 'http://192.168.' && substr($base_url, 0, 10) != 'http://10.';
        if ($ping && get_option('site_closed') == '0' && $not_local) {
            // Submit to search engines
            $services = array('http://www.google.com/webmasters/tools/ping?sitemap=', 'http://submissions.ask.com/ping?sitemap=', 'http://www.bing.com/webmaster/ping.aspx?siteMap=', 'http://search.yahooapis.com/SiteExplorerService/V1/updateNotification?appid=SitemapWriter&url=');
            foreach ($services as $service) {
                http_download_file($service . urlencode(get_custom_base_url() . '/ocp_sitemap.xml'), NULL, false);
            }
        }
    }
}
Example #10
0
/**
 * Get a splurghified version of the specified item.
 *
 * @param  string			The name of what the key we want to reference is in our array of maps (e.g. 'id')
 * @param  array			A row of maps for data we are splurghing; this is probably just the result of $GLOBALS['SITE_DB']->query_select
 * @param  URLPATH		The stub that links will be passed through
 * @param  ID_TEXT		The page name we will be saving customised HTML under
 * @param  TIME			The time we did our last change to the data being splurghed (so it can see if we can simply decache instead of deriving)
 * @param  ?AUTO_LINK	The ID that is at the root of our tree (NULL: db_get_first_id)
 * @return string			A string of HTML that represents our splurghing (will desplurgh in the users browser)
 */
function splurgh_master_build($key_name, $map, $url_stub, $_cache_file, $last_change_time, $first_id = NULL)
{
    if (is_null($first_id)) {
        $first_id = db_get_first_id();
    }
    if (!array_key_exists($first_id, $map)) {
        return '';
    }
    if (!has_js()) {
        warn_exit(do_lang_tempcode('MSG_JS_NEEDED'));
    }
    require_javascript('javascript_splurgh');
    if (is_browser_decacheing()) {
        $last_change_time = time();
    }
    $cache_file = zone_black_magic_filterer(get_custom_file_base() . '/' . get_zone_name() . '/pages/html_custom/' . filter_naughty(user_lang()) . '/' . filter_naughty($_cache_file) . '.htm');
    if (!file_exists($cache_file) || is_browser_decacheing() || filesize($cache_file) == 0 || $last_change_time > filemtime($cache_file)) {
        $myfile = @fopen($cache_file, 'wt');
        if ($myfile === false) {
            intelligent_write_error($cache_file);
        }
        $fulltable = array();
        $splurgh = _splurgh_do_node($map, $first_id, '', $fulltable, 0);
        $page = do_template('SPLURGH', array('_GUID' => '8775edfc5a386fdf2cec69b0fc889952', 'KEY_NAME' => $key_name, 'URL_STUB' => $url_stub, 'SPLURGH' => str_replace('"', '\'', $splurgh)));
        $ev = $page->evaluate();
        if (fwrite($myfile, $ev) < strlen($ev)) {
            warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
        }
        fclose($myfile);
        fix_permissions($cache_file);
        sync_file($cache_file);
        return $ev;
    }
    return file_get_contents($cache_file, FILE_TEXT);
}
Example #11
0
/**
 * Check to see if the member already has an account of this type. If so, an error message is shown, as you can only own of each type.
 *
 * @param  ID_TEXT		The type of mail domain
 * @set    pop3 forw
 */
function pointstore_handle_error_already_has($type)
{
    $userid = get_member();
    // If we already own a forwarding account, inform our users.
    $has_one_already = $GLOBALS['SITE_DB']->query_value_null_ok('sales', 'memberid', array('memberid' => $userid, 'purchasetype' => $type));
    if (!is_null($has_one_already)) {
        warn_exit(do_lang_tempcode('ALREADY_HAVE'));
    }
}
Example #12
0
/**
 * Make an emoticon.
 *
 * @param  SHORT_TEXT	The textual code entered to make the emoticon appear.
 * @param  ID_TEXT		The image code used for the emoticon.
 * @param  integer		The relevance level.
 * @range  0 4
 * @param  BINARY			Whether this may be used as a topic emoticon.
 * @param  BINARY			Whether this may only be used by privileged members
 */
function ocf_make_emoticon($code, $theme_img_code, $relevance_level = 1, $use_topics = 1, $is_special = 0)
{
    $test = $GLOBALS['FORUM_DB']->query_value_null_ok('f_emoticons', 'e_code', array('e_code' => $code));
    if (!is_null($test)) {
        warn_exit(do_lang_tempcode('CONFLICTING_EMOTICON_CODE', escape_html($test)));
    }
    $GLOBALS['FORUM_DB']->query_insert('f_emoticons', array('e_code' => $code, 'e_theme_img_code' => $theme_img_code, 'e_relevance_level' => $relevance_level, 'e_use_topics' => $use_topics, 'e_is_special' => $is_special));
    log_it('ADD_EMOTICON', $code, $theme_img_code);
}
/**
 * A template has not been structurally cached, so compile it and store in the cache.
 *
 * @param  ID_TEXT			The theme the template is in the context of
 * @param  PATH				The path to the template file
 * @param  ID_TEXT			The codename of the template (e.g. foo)
 * @param  ID_TEXT			The actual codename to use for the template (e.g. thin_foo)
 * @param  LANGUAGE_NAME	The language the template is in the context of
 * @param  string				File type suffix of template file
 * @param  ?ID_TEXT			The theme to cache in (NULL: main theme)
 * @return tempcode			The compiled tempcode
 */
function _do_template($theme, $path, $codename, $_codename, $lang, $suffix, $theme_orig = NULL)
{
    if (is_null($theme_orig)) {
        $theme_orig = $theme;
    }
    $base_dir = ($theme == 'default' && ($suffix != '.css' || strpos($path, '/css_custom') === false) ? get_file_base() : get_custom_file_base()) . '/themes/';
    global $CACHE_TEMPLATES, $FILE_ARRAY, $TEMPLATE_PREVIEW_OP, $MEM_CACHE;
    if (isset($FILE_ARRAY)) {
        $html = unixify_line_format(file_array_get('themes/' . $theme . $path . $codename . $suffix));
    } else {
        $html = unixify_line_format(file_get_contents($base_dir . filter_naughty($theme . $path . $codename) . $suffix, FILE_TEXT));
    }
    if (strpos($html, '{$,Parser hint: pure}') !== false) {
        return make_string_tempcode(preg_replace('#\\{\\$,.*\\}#U', '/*no minify*/', $html));
    }
    if ($GLOBALS['SEMI_DEBUG_MODE'] && strpos($html, '.innerHTML') !== false && strpos($html, 'Parser hint: .innerHTML okay') === false) {
        require_code('site');
        attach_message('Do not use the .innerHTML property in your Javascript because it will not work in true XHTML (when the browsers real XML parser is in action). Use ocPortal\'s global setInnerHTML/getInnerHTML functions.', 'warn');
    }
    // Strip off trailing final lines from single lines templates. Editors often put these in, and it causes annoying "visible space" issues
    if (substr($html, -1, 1) == chr(10) && substr_count($html, chr(10)) == 1) {
        $html = substr($html, 0, strlen($html) - 1);
    }
    if ($TEMPLATE_PREVIEW_OP) {
        $test = post_param($codename, NULL);
        if (!is_null($test)) {
            $html = post_param($test . '_new');
        }
    }
    $result = template_to_tempcode($html, 0, false, $codename, $theme, $lang);
    if ($CACHE_TEMPLATES && ($suffix == '.tpl' || $codename == 'no_cache')) {
        if (!is_null($MEM_CACHE)) {
            persistant_cache_set(array('TEMPLATE', $theme, $lang, $_codename), $result->to_assembly(), strpos($path, 'default/templates/') !== false);
        } else {
            $path2 = get_custom_file_base() . '/themes/' . $theme_orig . '/templates_cached/' . filter_naughty($lang) . '/';
            $myfile = @fopen($path2 . filter_naughty($_codename) . $suffix . '.tcd', 'wb');
            if ($myfile === false) {
                if (@mkdir($path2, 0777)) {
                    require_code('files');
                    fix_permissions($path2, 0777);
                } else {
                    if (file_exists($path2 . filter_naughty($_codename) . $suffix . '.tcd')) {
                        warn_exit(do_lang_tempcode('WRITE_ERROR', $path2 . filter_naughty($_codename) . $suffix . '.tcd'));
                    } else {
                        warn_exit(do_lang_tempcode('WRITE_ERROR_CREATE', $path2 . filter_naughty($_codename) . $suffix . '.tcd'));
                    }
                }
            } else {
                fwrite($myfile, $result->to_assembly($lang));
                fclose($myfile);
                fix_permissions($path2 . filter_naughty($_codename) . $suffix . '.tcd');
            }
        }
    }
    return $result;
}
Example #14
0
 /**
  * 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);
 }
Example #15
0
/**
 * Check a POST inputted date for validity, and get the Unix timestamp for the inputted date.
 *
 * @param  ID_TEXT		The stub of the parameter name (stub_year, stub_month, stub_day, stub_hour, stub_minute)
 * @param  boolean		Whether to allow over get parameters also
 * @return ?TIME			The timestamp of the date (NULL: no input date was chosen)
 */
function _get_input_date($stub, $get_also = false)
{
    $timezone = post_param('timezone', get_users_timezone());
    if ($get_also) {
        //		if (either_param_integer($stub,0)==0) return NULL; // NULL was chosen		Doesn't work like this now
        $year = either_param_integer($stub . '_year', NULL);
        if (is_null($year)) {
            return NULL;
        }
        $month = either_param_integer($stub . '_month', NULL);
        if (is_null($month)) {
            return NULL;
        }
        $day = either_param_integer($stub . '_day', NULL);
        if (is_null($day)) {
            return NULL;
        }
        $hour = either_param_integer($stub . '_hour', NULL);
        $minute = either_param_integer($stub . '_minute', NULL);
    } else {
        //		if (post_param_integer($stub,0)==0) return NULL; // NULL was chosen		Doesn't work like this now
        $year = post_param_integer($stub . '_year', NULL);
        if (is_null($year)) {
            return NULL;
        }
        $month = post_param_integer($stub . '_month', NULL);
        if (is_null($month)) {
            return NULL;
        }
        $day = post_param_integer($stub . '_day', NULL);
        if (is_null($day)) {
            return NULL;
        }
        $hour = post_param_integer($stub . '_hour', NULL);
        $minute = post_param_integer($stub . '_minute', NULL);
    }
    if (!checkdate($month, $day, $year)) {
        warn_exit(do_lang_tempcode('INVALID_DATE_GIVEN'));
    }
    if (is_null($hour)) {
        if (strpos($stub, 'end') !== false) {
            $hour = 23;
            $minute = 59;
        } else {
            $hour = 0;
            $minute = 0;
        }
    }
    $time = mktime($hour, $minute, 0, $month, $day, $year);
    if ($year >= 1970 || @strftime('%Y', @mktime(0, 0, 0, 1, 1, 1963)) == '1963') {
        $amount_forward = tz_time($time, $timezone) - $time;
        $time = $time - $amount_forward;
    }
    return $time;
}
Example #16
0
/**
 * Get a member's position.
 *
 * @param  MEMBER		The member
 * @param  boolean	Whether it's excusable if the member does not exist (i.e. doesn't exit with error)
 * @return ?array		Tuple: Realm, X ordinate, Y ordinate (NULL: no such member)
 */
function get_loc_details($member_id, $null_ok = false)
{
    $rows = $GLOBALS['SITE_DB']->query_select('w_members', array('location_realm', 'location_x', 'location_y'), array('id' => $member_id), '', 1);
    if (!array_key_exists(0, $rows)) {
        if ($null_ok) {
            return NULL;
        }
        warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
    }
    return array($rows[0]['location_realm'], $rows[0]['location_x'], $rows[0]['location_y']);
}
Example #17
0
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     $file = array_key_exists('param', $map) ? $map['param'] : 'ocprocks';
     require_code('textfiles');
     require_lang('ocprocks');
     $place = _find_text_file_path($file, '');
     if (!file_exists($place)) {
         warn_exit(do_lang_tempcode('DIRECTORY_NOT_FOUND', escape_html($place)));
     }
     $edit_url = new ocp_tempcode();
     return do_template('BLOCK_MAIN_OCPROCKS', array('FILE' => $file, 'CONTENT' => apply_emoticons($this->get_random_line($place))));
 }
Example #18
0
 /**
  * The UI to show topics with new posts since last visit time.
  *
  * @return array			A pair: The Title, The UI
  */
 function new_posts()
 {
     $title = do_lang('POSTS_SINCE_LAST_VISIT');
     if (!array_key_exists('last_visit', $_COOKIE)) {
         warn_exit(do_lang_tempcode('NO_LAST_VISIT'));
     }
     $condition = 't_cache_last_time>' . strval((int) $_COOKIE['last_visit']);
     $order2 = 't_cache_last_time DESC';
     if (get_value('disable_sunk') !== '1') {
         $order2 = 't_sunk ASC,' . $order2;
     }
     return array(get_page_title('POSTS_SINCE_LAST_VISIT'), $this->_vforum($title, $condition, 't_cascading DESC,t_pinned DESC,' . $order2, true));
 }
Example #19
0
 /**
  * Standard modular run function for snippet hooks. Generates XHTML to insert into a page using AJAX.
  *
  * @return tempcode  The snippet
  */
 function run()
 {
     if (get_file_base() != get_custom_file_base()) {
         warn_exit(do_lang_tempcode('SHARED_INSTALL_PROHIBIT'));
     }
     if (has_actual_page_access(get_member(), 'admin_occle')) {
         require_code('occle');
         require_lang('occle');
         $title = get_page_title('OCCLE');
         return do_template('OCCLE_MAIN', array('COMMANDS' => '', 'SUBMIT_URL' => build_url(array('page' => 'admin_occle'), 'adminzone'), 'PROMPT' => do_lang_tempcode('COMMAND_PROMPT', escape_html($GLOBALS['FORUM_DRIVER']->get_username(get_member())))));
     }
     return new ocp_tempcode();
 }
Example #20
0
/**
 * Give a member some points, from another member.
 *
 * @param  integer		The amount being given
 * @param  MEMBER			The member receiving the points
 * @param  MEMBER			The member sending the points
 * @param  SHORT_TEXT	The reason for the gift
 * @param  boolean		Does the sender want to remain anonymous?
 * @param  boolean		Whether to send out an email about it
 */
function give_points($amount, $recipient_id, $sender_id, $reason, $anonymous = false, $send_email = true)
{
    require_lang('points');
    require_code('points');
    $your_username = $GLOBALS['FORUM_DRIVER']->get_username($sender_id);
    $GLOBALS['SITE_DB']->query_insert('gifts', array('date_and_time' => time(), 'amount' => $amount, 'gift_from' => $sender_id, 'gift_to' => $recipient_id, 'reason' => insert_lang_comcode($reason, 4), 'anonymous' => $anonymous ? 1 : 0));
    $sender_gift_points_used = point_info($sender_id);
    $sender_gift_points_used = array_key_exists('gift_points_used', $sender_gift_points_used) ? $sender_gift_points_used['gift_points_used'] : 0;
    $GLOBALS['FORUM_DRIVER']->set_custom_field($sender_id, 'gift_points_used', strval($sender_gift_points_used + $amount));
    $temp_points = point_info($recipient_id);
    $GLOBALS['FORUM_DRIVER']->set_custom_field($recipient_id, 'points_gained_given', strval((array_key_exists('points_gained_given', $temp_points) ? $temp_points['points_gained_given'] : 0) + $amount));
    $their_username = $GLOBALS['FORUM_DRIVER']->get_username($recipient_id);
    if (is_null($their_username)) {
        warn_exit(do_lang_tempcode('_USER_NO_EXIST', $recipient_id));
    }
    $yes = $GLOBALS['FORUM_DRIVER']->get_member_email_allowed($recipient_id);
    if ($yes && $send_email) {
        $_url = build_url(array('page' => 'points', 'type' => 'member', 'id' => $recipient_id), get_module_zone('points'), NULL, false, false, true);
        $url = $_url->evaluate();
        require_code('notifications');
        if ($anonymous) {
            $message_raw = do_lang('GIVEN_POINTS_FOR_ANON', comcode_escape(get_site_name()), comcode_escape(integer_format($amount)), array(comcode_escape($reason), comcode_escape($url)), get_lang($recipient_id));
            dispatch_notification('received_points', NULL, do_lang('YOU_GIVEN_POINTS', integer_format($amount), NULL, NULL, get_lang($recipient_id)), $message_raw, array($recipient_id), A_FROM_SYSTEM_UNPRIVILEGED);
        } else {
            $message_raw = do_lang('GIVEN_POINTS_FOR', comcode_escape(get_site_name()), comcode_escape(integer_format($amount)), array(comcode_escape($reason), comcode_escape($url), comcode_escape($your_username)), get_lang($recipient_id));
            dispatch_notification('received_points', NULL, do_lang('YOU_GIVEN_POINTS', integer_format($amount), NULL, NULL, get_lang($recipient_id)), $message_raw, array($recipient_id), $sender_id);
        }
        $message_raw = do_lang('USER_GIVEN_POINTS_FOR', comcode_escape($their_username), comcode_escape(integer_format($amount)), array(comcode_escape($reason), comcode_escape($url), comcode_escape($your_username)), get_site_default_lang());
        dispatch_notification('receive_points_staff', NULL, do_lang('USER_GIVEN_POINTS', integer_format($amount), NULL, NULL, get_site_default_lang()), $message_raw, NULL, $sender_id);
    }
    global $TOTAL_POINTS_CACHE, $POINT_INFO_CACHE;
    if (array_key_exists($recipient_id, $TOTAL_POINTS_CACHE)) {
        $TOTAL_POINTS_CACHE[$recipient_id] += $amount;
    }
    if (array_key_exists($recipient_id, $POINT_INFO_CACHE) && array_key_exists('points_gained_given', $POINT_INFO_CACHE[$recipient_id])) {
        $POINT_INFO_CACHE[$recipient_id]['points_gained_given'] += $amount;
    }
    if (array_key_exists($sender_id, $POINT_INFO_CACHE) && array_key_exists('gift_points_used', $POINT_INFO_CACHE[$sender_id])) {
        $POINT_INFO_CACHE[$sender_id]['gift_points_used'] += $amount;
    }
    if (get_forum_type() == 'ocf') {
        require_code('ocf_posts_action');
        require_code('ocf_posts_action2');
        ocf_member_handle_promotion($recipient_id);
    }
    if (!$anonymous) {
        if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'points')) {
            syndicate_described_activity(is_null($recipient_id) || is_guest($recipient_id) ? 'points:_ACTIVITY_GIVE_POINTS' : 'points:ACTIVITY_GIVE_POINTS', $reason, integer_format($amount), '', '_SEARCH:points:member:' . strval($recipient_id), '', '', 'points', 1, NULL, false, $recipient_id);
        }
    }
}
/**
 * Edit an emoticon.
 *
 * @param  SHORT_TEXT	The textual code entered to make the emoticon appear.
 * @param  SHORT_TEXT	The old textual code.
 * @param  ID_TEXT		The image code used for the emoticon.
 * @param  integer		The relevance level.
 * @range  0 4
 * @param  BINARY			Whether this may be used as a topic emoticon.
 * @param  BINARY			Whether this may only be used by privileged members
 */
function ocf_edit_emoticon($old_code, $code, $theme_img_code, $relevance_level, $use_topics, $is_special = 0)
{
    if ($code != $old_code) {
        $test = $GLOBALS['FORUM_DB']->query_value_null_ok('f_emoticons', 'e_code', array('e_code' => $code));
        if (!is_null($test)) {
            warn_exit(do_lang_tempcode('CONFLICTING_EMOTICON_CODE', escape_html($code)));
        }
    }
    $old_theme_img_code = $GLOBALS['FORUM_DB']->query_value('f_emoticons', 'e_theme_img_code', array('e_code' => $old_code));
    $GLOBALS['FORUM_DB']->query_update('f_emoticons', array('e_code' => $code, 'e_theme_img_code' => $theme_img_code, 'e_relevance_level' => $relevance_level, 'e_use_topics' => $use_topics, 'e_is_special' => $is_special), array('e_code' => $old_code), '', 1);
    require_code('themes2');
    tidy_theme_img_code($theme_img_code, $old_theme_img_code, 'f_emoticons', 'e_theme_img_code');
    log_it('EDIT_EMOTICON', $code, $theme_img_code);
}
Example #22
0
 /**
  * Find whether this preview hook applies.
  *
  * @return array			Quartet: Whether it applies, the attachment ID type, whether the forum DB is used [optional], list of fields to limit to [optional]
  */
 function applies()
 {
     require_lang('ocf');
     $member_id = get_param_integer('id', get_member());
     $applies = get_param('page', '') == 'members' && post_param('signature', NULL) !== NULL;
     if ($applies) {
         require_code('ocf_groups');
         $max_sig_length = ocf_get_member_best_group_property($member_id, 'max_sig_length_comcode');
         if (strlen(post_param('post', '')) > $max_sig_length) {
             warn_exit(do_lang_tempcode('SIGNATURE_TOO_BIG'));
         }
     }
     return array($applies, 'ocf_signature', true, array('post'));
 }
Example #23
0
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     require_lang('quotes');
     $file = array_key_exists('param', $map) ? $map['param'] : 'quotes';
     $title = array_key_exists('title', $map) ? $map['title'] : do_lang('QUOTES');
     require_code('textfiles');
     $place = _find_text_file_path($file, '');
     if (!file_exists($place)) {
         warn_exit(do_lang_tempcode('DIRECTORY_NOT_FOUND', escape_html($place)));
     }
     $edit_url = new ocp_tempcode();
     if ($file == 'quotes' && has_actual_page_access(get_member(), 'quotes', 'adminzone')) {
         $edit_url = build_url(array('page' => 'quotes'), 'adminzone');
     }
     return do_template('BLOCK_MAIN_QUOTES', array('_GUID' => '7cab7422f603f7b1197c940de48b99aa', 'TITLE' => $title, 'EDIT_URL' => $edit_url, 'FILE' => $file, 'CONTENT' => comcode_to_tempcode($this->get_random_line($place), NULL, true)));
 }
Example #24
0
/**
 * Get the remapping for the id in the specified type. Whether it returns NULL or gives an error message depends on $fail_ok.
 *
 * @param  ID_TEXT		An importation type code, from those ocPortal has defined
 * @param  string			The source (old, original) ID of the mapping
 * @param  boolean		If it is okay to fail to find a mapping
 * @return ?AUTO_LINK	The remapping (NULL: not found)
 */
function import_id_remap_get($type, $id_old, $fail_ok = false)
{
    global $REMAP_CACHE;
    if (array_key_exists($type, $REMAP_CACHE) && array_key_exists($id_old, $REMAP_CACHE[$type])) {
        return $REMAP_CACHE[$type][$id_old];
    }
    $value = $GLOBALS['SITE_DB']->query_value_null_ok('import_id_remap', 'id_new', array('id_session' => get_session_id(), 'id_type' => $type, 'id_old' => $id_old));
    if (is_null($value)) {
        if ($fail_ok) {
            return NULL;
        }
        warn_exit(do_lang_tempcode('IMPORT_NOT_IMPORTED', $type, $id_old));
    }
    $REMAP_CACHE[$type][$id_old] = $value;
    return $value;
}
Example #25
0
 /**
  * Takes Salmon values from POST and handles their assimilation into the
  * site.
  */
 function handle_salmon($id)
 {
     // Find out what the type our feedback should be for
     require_code('hooks/systems/content_meta_aware/iotd');
     $cma = object_factory('Hook_content_meta_aware_iotd');
     $info = $cma->info();
     $db_id = $info['id_field_numeric'] ? intval($id) : $id;
     $_title = $GLOBALS['SITE_DB']->query_value_null_ok($info['table'], $info['title_field'], array($info['id_field'] => $db_id));
     if (is_null($_title)) {
         warn_exit('');
     }
     $title = $info['title_field_dereference'] ? get_translated_text($_title) : $_title;
     require_code('urls');
     list($zone, $attributes, $_) = page_link_decode(str_replace('_WILD', $id, $info['view_pagelink_pattern']));
     $url = build_url($attributes, $zone)->evaluate();
     require_code('salmon/salmon');
     parse_salmon_post($info['feedback_type_code'], filter_naughty($id), $url, $title);
 }
Example #26
0
/**
 * Render a member profile.
 *
 * @param  MEMBER			The ID of the member who is being viewed
 * @param  ?MEMBER		The ID of the member who is doing the viewing (NULL: current member)
 * @param  ?ID_TEXT		The username of the member who is being viewed (NULL: work out from member_id_of)
 * @return tempcode		The rendered profile
 */
function render_profile_tabset($member_id_of, $member_id_viewing = NULL, $username = NULL)
{
    if (is_null($member_id_viewing)) {
        $member_id_viewing = get_member();
    }
    $username = $GLOBALS['FORUM_DRIVER']->get_username($member_id_of);
    if (is_null($username) || is_guest($member_id_of)) {
        warn_exit(do_lang_tempcode('USER_NO_EXIST'));
    }
    $tabs = array();
    $hooks = find_all_hooks('systems', 'profiles_tabs');
    if (isset($hooks['edit'])) {
        $hooks = array('edit' => $hooks['edit']) + $hooks;
    }
    foreach (array_keys($hooks) as $hook) {
        require_code('hooks/systems/profiles_tabs/' . $hook);
        $ob = object_factory('Hook_Profiles_Tabs_' . $hook);
        if ($ob->is_active($member_id_of, $member_id_viewing)) {
            $tabs[$hook] = $ob->render_tab($member_id_of, $member_id_viewing, !browser_matches('ie6') && !browser_matches('ie7') && has_js());
        }
    }
    global $M_SORT_KEY;
    $M_SORT_KEY = 2;
    uasort($tabs, 'multi_sort');
    require_javascript('javascript_profile');
    require_javascript('javascript_ajax');
    load_up_all_self_page_permissions($member_id_viewing);
    if (addon_installed('awards')) {
        require_code('awards');
        $awards = find_awards_for('member', strval($member_id_of));
    } else {
        $awards = array();
    }
    $username = $GLOBALS['FORUM_DRIVER']->get_username($member_id_of);
    // Get it again, in case it changed
    $title = get_page_title('MEMBER_PROFILE', true, array(escape_html($username)), NULL, $awards);
    $_tabs = array();
    $i = 0;
    foreach ($tabs as $hook => $tab) {
        $_tabs[] = array('TAB_TITLE' => $tab[0], 'TAB_CODE' => $hook, 'TAB_CONTENT' => $tab[1], 'TAB_FIRST' => $i == 0, 'TAB_LAST' => !array_key_exists($i + 1, $tabs));
        $i++;
    }
    return do_template('OCF_MEMBER_PROFILE_SCREEN', array('TITLE' => $title, 'TABS' => $_tabs, 'MEMBER_ID' => strval($member_id_of)));
}
Example #27
0
 /**
  * Standard modular run function for snippet hooks. Generates XHTML to insert into a page using AJAX.
  *
  * @return tempcode  The snippet
  */
 function run()
 {
     if (get_option('is_on_comments') == '0') {
         warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
     }
     $serialized_options = get_param('serialized_options', false, true);
     $hash = get_param('hash');
     if (best_hash($serialized_options, get_site_salt()) != $hash) {
         warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
     }
     secure_serialized_data($serialized_options);
     list($topic_id, $num_to_show_limit, $allow_comments, $invisible_if_no_comments, $forum, $reverse, $may_reply, $highlight_by_user, $allow_reviews) = unserialize($serialized_options);
     $posts = array_map('intval', explode(',', get_param('ids', false, true)));
     $_parent_id = get_param('id', '');
     $parent_id = $_parent_id == '' ? mixed() : intval($_parent_id);
     require_code('topics');
     $renderer = new OCP_Topic();
     return $renderer->render_posts_from_topic($topic_id, $num_to_show_limit, $allow_comments, $invisible_if_no_comments, $forum, NULL, $reverse, $may_reply, $highlight_by_user, $allow_reviews, $posts, $parent_id);
 }
Example #28
0
/**
 * Get the forum ID for a given ticket type and member, taking the ticket_member_forums and ticket_type_forums options
 * into account.
 *
 * @param  ?AUTO_LINK		The member ID (NULL: no member)
 * @param  ?integer			The ticket type (NULL: all ticket types)
 * @param  boolean			Create the forum if it's missing
 * @param  boolean			Whether to skip showing errors, returning NULL instead
 * @return ?AUTO_LINK		Forum ID (NULL: not found)
 */
function get_ticket_forum_id($member = NULL, $ticket_type = NULL, $create = false, $silent_error_handling = false)
{
    static $fid_cache = array();
    if (isset($fid_cache[$member][$ticket_type])) {
        return $fid_cache[$member][$ticket_type];
    }
    $root_forum = get_option('ticket_forum_name');
    // Check the root ticket forum is valid
    $fid = $GLOBALS['FORUM_DRIVER']->forum_id_from_name($root_forum);
    if (is_null($fid)) {
        if ($silent_error_handling) {
            return NULL;
        }
        warn_exit(do_lang_tempcode('NO_FORUM'));
    }
    // Only the root ticket forum is supported for non-OCF installations
    if (get_forum_type() != 'ocf') {
        return $fid;
    }
    require_code('ocf_forums_action');
    require_code('ocf_forums_action2');
    $category_id = $GLOBALS['FORUM_DB']->query_value('f_forums', 'f_category_id', array('id' => $fid));
    if (!is_null($member) && get_option('ticket_member_forums') == '1') {
        $username = $GLOBALS['FORUM_DRIVER']->get_username($member);
        $rows = $GLOBALS['FORUM_DB']->query_select('f_forums', array('id'), array('f_parent_forum' => $fid, 'f_name' => $username), '', 1);
        if (count($rows) == 0) {
            $fid = ocf_make_forum($username, do_lang('SUPPORT_TICKETS_FOR_MEMBER', $username), $category_id, NULL, $fid);
        } else {
            $fid = $rows[0]['id'];
        }
    }
    if (!is_null($ticket_type) && get_option('ticket_type_forums') == '1') {
        $ticket_type_text = get_translated_text($ticket_type);
        $rows = $GLOBALS['FORUM_DB']->query_select('f_forums', array('id'), array('f_parent_forum' => $fid, 'f_name' => $ticket_type_text), '', 1);
        if (count($rows) == 0) {
            $fid = ocf_make_forum($ticket_type_text, do_lang('SUPPORT_TICKETS_FOR_TYPE', $ticket_type), $category_id, NULL, $fid);
        } else {
            $fid = $rows[0]['id'];
        }
    }
    $fid_cache[$member][$ticket_type] = $fid;
    return $fid;
}
Example #29
0
 /**
  * Standard modular run function for preview hooks.
  *
  * @return array			A pair: The preview, the updated post Comcode
  */
 function run()
 {
     require_code('uploads');
     $urls = get_url('', 'file', 'safe_mode_temp', 0, OCP_UPLOAD_IMAGE, false);
     if ($urls[0] == '') {
         if (!is_null(post_param_integer('id', NULL))) {
             $rows = $GLOBALS['SITE_DB']->query_select('calendar_types', array('t_logo'), array('id' => post_param_integer('id')), '', 1);
             $urls = $rows[0];
             $url = find_theme_image($urls['t_logo']);
         } elseif (!is_null(post_param('theme_img_code', NULL))) {
             $url = find_theme_image(post_param('theme_img_code'));
         } else {
             warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN_UPLOAD'));
         }
     } else {
         $url = $urls[0];
     }
     require_code('images');
     $preview = do_image_thumb(url_is_local($url) ? get_custom_base_url() . '/' . $url : $url, post_param('title'), true);
     return array($preview, NULL);
 }
Example #30
0
 /**
  * Standard modular run function for preview hooks.
  *
  * @return array			A pair: The preview, the updated post Comcode
  */
 function run()
 {
     require_code('uploads');
     require_lang('banners');
     // Check according to banner type
     $title_text = post_param('title_text', '');
     $direct_code = post_param('direct_code', '');
     $url_param_name = 'image_url';
     $file_param_name = 'file';
     require_code('uploads');
     $is_upload = is_swf_upload() || array_key_exists($file_param_name, $_FILES) && (array_key_exists('tmp_name', $_FILES[$file_param_name]) && is_uploaded_file($_FILES[$file_param_name]['tmp_name']));
     $_banner_type_rows = $GLOBALS['SITE_DB']->query_select('banner_types', array('*'), array('id' => post_param('b_type')), '', 1);
     if (!array_key_exists(0, $_banner_type_rows)) {
         warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
     }
     $banner_type_row = $_banner_type_rows[0];
     if ($banner_type_row['t_is_textual'] == 0) {
         if ($direct_code == '') {
             $urls = get_url($url_param_name, $file_param_name, 'uploads/banners', 0, $is_upload ? OCP_UPLOAD_IMAGE : OCP_UPLOAD_ANYTHING);
             $img_url = fixup_protocolless_urls($urls[0]);
             if ($img_url == '') {
                 warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN_UPLOAD_BANNERS'));
             }
         } else {
             $img_url = '';
         }
     } else {
         $img_url = '';
         if ($title_text == '') {
             warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN_BANNERS'));
         }
         if (strlen($title_text) > $banner_type_row['t_max_file_size']) {
             warn_exit(do_lang_tempcode('BANNER_TOO_LARGE_2', integer_format(strlen($title_text)), integer_format($banner_type_row['t_max_file_size'])));
         }
     }
     require_code('banners');
     $preview = show_banner(post_param('name'), post_param('title_text', ''), comcode_to_tempcode(post_param('caption')), $img_url, '', post_param('site_url'), post_param('b_type'));
     return array($preview, NULL);
 }