Exemplo n.º 1
0
 /**
  * Standard modular run function for realtime-rain hooks.
  *
  * @param  TIME			Start of time range.
  * @param  TIME			End of time range.
  * @return array			A list of template parameter sets for rendering a 'drop'.
  */
 function run($from, $to)
 {
     $drops = array();
     if (has_actual_page_access(get_member(), 'polls')) {
         $rows = $GLOBALS['SITE_DB']->query('SELECT b.option1,b.option2,b.option3,b.option4,b.option5,b.option6,b.option7,b.option8,b.option9,b.option10,b.votes1,b.votes2,b.votes3,b.votes4,b.votes5,b.votes6,b.votes7,b.votes8,b.votes9,b.votes10,b.question,b.id,b.submitter AS member_id,a.date_and_time AS timestamp FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'poll a LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'poll b ON a.date_and_time>b.date_and_time WHERE NOT EXISTS(SELECT * FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'poll x WHERE x.id<>a.id AND x.id<>b.id AND x.date_and_time BETWEEN b.date_and_time AND a.date_and_time) AND b.date_and_time IS NOT NULL AND b.date_and_time BETWEEN ' . strval($from) . ' AND ' . strval($to));
         foreach ($rows as $row) {
             require_lang('polls');
             $timestamp = $row['timestamp'];
             $member_id = $row['member_id'];
             $best = NULL;
             $best_num = -1;
             for ($i = 1; $i <= 10; $i++) {
                 if ($row['votes' . strval($i)] > $best_num) {
                     $best = $row['option' . strval($i)];
                     $best_num = $row['votes' . strval($i)];
                 }
             }
             if ($best_num == -1) {
                 continue;
             }
             $ticker_text = do_lang('VOTES_ARE_IN', strip_comcode(get_translated_text($row['question'])), strip_comcode(get_translated_text($best)));
             $drops[] = rain_get_special_icons(NULL, $timestamp, NULL, $ticker_text) + array('TYPE' => 'polls', 'FROM_MEMBER_ID' => strval($member_id), 'TO_MEMBER_ID' => NULL, 'TITLE' => rain_truncate_for_title(get_translated_text($row['question'])), 'IMAGE' => find_theme_image('bigicons/polls'), 'TIMESTAMP' => strval($timestamp), 'RELATIVE_TIMESTAMP' => strval($timestamp - $from), 'TICKER_TEXT' => $ticker_text, 'URL' => build_url(array('page' => 'polls', 'type' => 'view', 'id' => $row[1]['id']), '_SEARCH'), 'IS_POSITIVE' => false, 'IS_NEGATIVE' => false, 'FROM_ID' => 'member_' . strval($member_id), 'TO_ID' => NULL, 'GROUP_ID' => 'poll_' . strval($row['id']));
         }
     }
     return $drops;
 }
Exemplo n.º 2
0
/**
 * Regenerate all the theme image paths in the database.
 *
 * @param  ID_TEXT	The theme we're searching in.
 * @param  ?array		A map of languages (lang=>1) (NULL: find it in-function).
 * @param  ?ID_TEXT  The theme we're storing in (NULL: same as $theme).
 */
function regen_theme_images($theme, $langs = NULL, $target_theme = NULL)
{
    if (is_null($langs)) {
        $langs = find_all_langs(true);
    }
    if (is_null($target_theme)) {
        $target_theme = $theme;
    }
    $images = array_merge(find_images_do_dir($theme, 'images/', $langs), find_images_do_dir($theme, 'images_custom/', $langs));
    foreach (array_keys($langs) as $lang) {
        $existing = $GLOBALS['SITE_DB']->query_select('theme_images', array('id', 'path'), array('lang' => $lang, 'theme' => $target_theme));
        foreach ($images as $id => $path) {
            $found = false;
            foreach ($existing as $e) {
                if ($e['path'] == $path || $e['id'] == $id) {
                    $found = true;
                    break;
                }
            }
            if (!$found) {
                $nql_backup = $GLOBALS['NO_QUERY_LIMIT'];
                $GLOBALS['NO_QUERY_LIMIT'] = true;
                $correct_path = find_theme_image($id, false, true, $theme, $lang);
                $GLOBALS['SITE_DB']->query_insert('theme_images', array('id' => $id, 'lang' => $lang, 'theme' => $target_theme, 'path' => $correct_path), false, true);
                // race conditions
                $GLOBALS['NO_QUERY_LIMIT'] = $nql_backup;
            }
        }
    }
    persistant_cache_delete('THEME_IMAGES');
}
Exemplo n.º 3
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));
 }
Exemplo n.º 4
0
 /**
  * Standard modular run function for realtime-rain hooks.
  *
  * @param  TIME			Start of time range.
  * @param  TIME			End of time range.
  * @return array			A list of template parameter sets for rendering a 'drop'.
  */
 function run($from, $to)
 {
     $drops = array();
     if (has_actual_page_access(get_member(), 'admin_stats')) {
         $rows = $GLOBALS['SITE_DB']->query('SELECT s_primary,s_member_id AS member_id,s_time AS timestamp FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'searches_logged WHERE s_time BETWEEN ' . strval($from) . ' AND ' . strval($to));
         foreach ($rows as $row) {
             $timestamp = $row['timestamp'];
             $member_id = $row['member_id'];
             $drops[] = rain_get_special_icons(NULL, $timestamp) + array('TYPE' => 'search', 'FROM_MEMBER_ID' => strval($member_id), 'TO_MEMBER_ID' => NULL, 'TITLE' => rain_truncate_for_title($row['s_primary']), 'IMAGE' => find_theme_image('bigicons/search'), 'TIMESTAMP' => strval($timestamp), 'RELATIVE_TIMESTAMP' => strval($timestamp - $from), 'TICKER_TEXT' => NULL, 'URL' => build_url(array('page' => 'search', 'type' => 'misc', 'content' => $row['s_primary']), '_SEARCH'), 'IS_POSITIVE' => false, 'IS_NEGATIVE' => false, 'FROM_ID' => 'member_' . strval($member_id), 'TO_ID' => NULL, 'GROUP_ID' => 'search_' . $row['s_primary']);
         }
     }
     return $drops;
 }
Exemplo n.º 5
0
 /**
  * Standard modular run function for realtime-rain hooks.
  *
  * @param  TIME			Start of time range.
  * @param  TIME			End of time range.
  * @return array			A list of template parameter sets for rendering a 'drop'.
  */
 function run($from, $to)
 {
     $drops = array();
     if (has_actual_page_access(get_member(), 'admin_ocf_join') && get_forum_type() == 'ocf') {
         $rows = $GLOBALS['FORUM_DB']->query('SELECT i_email_address,i_inviter AS member_id,i_time AS timestamp FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_invites WHERE i_time BETWEEN ' . strval($from) . ' AND ' . strval($to));
         foreach ($rows as $row) {
             $timestamp = $row['timestamp'];
             $member_id = $row['member_id'];
             $invited_member = $GLOBALS['FORUM_DB']->query_value_null_ok('f_members', 'id', array('m_email_address' => $row['i_email_address']));
             $drops[] = rain_get_special_icons(NULL, $timestamp) + array('TYPE' => 'recommend', 'FROM_MEMBER_ID' => strval($member_id), 'TO_MEMBER_ID' => is_null($invited_member) ? '' : strval($invited_member), 'TITLE' => do_lang('RECOMMEND_SITE'), 'IMAGE' => is_guest($member_id) ? find_theme_image('recommend') : $GLOBALS['FORUM_DRIVER']->get_member_avatar_url($member_id), 'TIMESTAMP' => strval($timestamp), 'RELATIVE_TIMESTAMP' => strval($timestamp - $from), 'TICKER_TEXT' => NULL, 'URL' => build_url(array('page' => 'points', 'type' => 'member', 'id' => $member_id), '_SEARCH'), 'IS_POSITIVE' => true, 'IS_NEGATIVE' => false, 'FROM_ID' => 'member_' . strval($member_id), 'TO_ID' => is_null($invited_member) ? '' : 'member_' . strval($invited_member), 'GROUP_ID' => NULL);
         }
     }
     return $drops;
 }
Exemplo n.º 6
0
 /**
  * Standard modular run function for realtime-rain hooks.
  *
  * @param  TIME			Start of time range.
  * @param  TIME			End of time range.
  * @return array			A list of template parameter sets for rendering a 'drop'.
  */
 function run($from, $to)
 {
     $drops = array();
     if (has_actual_page_access(get_member(), 'news')) {
         $rows = $GLOBALS['SITE_DB']->query('SELECT title,n.id,nc_img,submitter AS member_id,date_and_time AS timestamp,news_category FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news n LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news_categories c ON c.id=n.news_category WHERE date_and_time BETWEEN ' . strval($from) . ' AND ' . strval($to));
         foreach ($rows as $row) {
             if (!has_category_access(get_member(), 'news', $row['news_category'])) {
                 continue;
             }
             $timestamp = $row['timestamp'];
             $member_id = $row['member_id'];
             $image = find_theme_image($row['nc_img']);
             $ticker_text = strip_comcode(get_translated_text($row['title']));
             $drops[] = rain_get_special_icons(NULL, $timestamp, NULL, $ticker_text) + array('TYPE' => 'news', 'FROM_MEMBER_ID' => strval($member_id), 'TO_MEMBER_ID' => NULL, 'TITLE' => rain_truncate_for_title(get_translated_text($row['title'])), 'IMAGE' => $image, 'TIMESTAMP' => strval($timestamp), 'RELATIVE_TIMESTAMP' => strval($timestamp - $from), 'TICKER_TEXT' => $ticker_text, 'URL' => build_url(array('page' => 'news', 'type' => 'view', 'id' => $row['id']), '_SEARCH'), 'IS_POSITIVE' => false, 'IS_NEGATIVE' => false, 'FROM_ID' => 'member_' . strval($member_id), 'TO_ID' => NULL, 'GROUP_ID' => 'news_' . strval($row['id']));
         }
     }
     return $drops;
 }
Exemplo n.º 7
0
    /**
     * Standard modular run function. Creates custom graphics from parameters.
     *
     * @param  array		Map of hook parameters (relayed from block parameters map).
     * @param  object		The block itself (contains utility methods).
     * @return tempcode	HTML to output.
     */
    function run($map, &$block)
    {
        if (!function_exists('imagettftext') || !array_key_exists('FreeType Support', gd_info()) || @imagettfbbox(26.0, 0.0, get_file_base() . '/data/fonts/Vera.ttf', 'test') === false) {
            return do_lang_tempcode('REQUIRES_TTF');
        }
        if (!array_key_exists('img1', $map)) {
            $map['img1'] = 'button1';
        }
        $img_path_1 = find_theme_image($map['img1'], true, true);
        if ($img_path_1 == '') {
            return do_lang_tempcode('NO_SUCH_THEME_IMAGE', $map['img1']);
        }
        $cache_id_1 = 'rollover1_' . md5(serialize($map));
        $url_1 = $block->_do_image($cache_id_1, $map, $img_path_1);
        if (is_object($url_1)) {
            return $url_1;
        }
        if (!array_key_exists('img2', $map)) {
            $map['img2'] = 'button2';
        }
        $img_path_2 = find_theme_image($map['img2'], true, true);
        if ($img_path_2 == '') {
            return do_lang_tempcode('NO_SUCH_THEME_IMAGE', $map['img2']);
        }
        $cache_id_2 = 'rollover2_' . md5(serialize($map));
        $url_2 = $block->_do_image($cache_id_2, $map, $img_path_2);
        if (is_object($url_2)) {
            return $url_2;
        }
        $comb_id = 'rollover_' . uniqid('', true);
        $ret = '<img id="' . php_addslashes($comb_id) . '" class="gfx_text_overlay" alt="' . str_replace(chr(10), ' ', escape_html($map['data'])) . '" src="' . escape_html($url_1) . '" />';
        $ret .= '
			<script type="text/javascript">// <![CDATA[
				create_rollover("' . php_addslashes($comb_id) . '","' . php_addslashes($url_2) . '");
			//]]></script>
		';
        if (function_exists('ocp_mark_as_escaped')) {
            ocp_mark_as_escaped($ret);
        }
        return make_string_tempcode($ret);
    }
Exemplo n.º 8
0
 /**
  * Standard modular run function for realtime-rain hooks.
  *
  * @param  TIME			Start of time range.
  * @param  TIME			End of time range.
  * @return array			A list of template parameter sets for rendering a 'drop'.
  */
 function run($from, $to)
 {
     $drops = array();
     if (has_actual_page_access(get_member(), 'admin_ecommerce')) {
         $rows = $GLOBALS['SITE_DB']->query('SELECT amount,item,t_time AS timestamp FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'transactions WHERE t_time BETWEEN ' . strval($from) . ' AND ' . strval($to));
         foreach ($rows as $row) {
             require_code('ecommerce');
             list($product, ) = find_product_row($row['item']);
             if (!is_null($product)) {
                 $title = $product[4];
             } else {
                 require_lang('ecommerce');
                 $title = do_lang('SALE_MADE');
             }
             $timestamp = $row['timestamp'];
             $ticker_text = do_lang('KA_CHING', ecommerce_get_currency_symbol(), $row['amount']);
             $drops[] = rain_get_special_icons(NULL, $timestamp, NULL, $ticker_text) + array('TYPE' => 'ecommerce', 'FROM_MEMBER_ID' => NULL, 'TO_MEMBER_ID' => NULL, 'TITLE' => $title, 'IMAGE' => find_theme_image('bigicons/ecommerce'), 'TIMESTAMP' => strval($timestamp), 'RELATIVE_TIMESTAMP' => strval($timestamp - $from), 'TICKER_TEXT' => $ticker_text, 'URL' => NULL, 'IS_POSITIVE' => true, 'IS_NEGATIVE' => false, 'FROM_ID' => NULL, 'TO_ID' => NULL, 'GROUP_ID' => 'product_' . $row['item']);
         }
     }
     return $drops;
 }
Exemplo n.º 9
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);
 }
Exemplo n.º 10
0
 /**
  * Standard modular run function. Creates custom graphics from parameters.
  *
  * @param  array		Map of hook parameters (relayed from block parameters map).
  * @param  object		The block itself (contains utility methods).
  * @return tempcode	HTML to output.
  */
 function run($map, &$block)
 {
     if (!function_exists('imagettftext') || !array_key_exists('FreeType Support', gd_info()) || @imagettfbbox(26.0, 0.0, get_file_base() . '/data/fonts/Vera.ttf', 'test') === false) {
         return do_lang_tempcode('REQUIRES_TTF');
     }
     if (!array_key_exists('img', $map)) {
         $map['img'] = 'button1';
     }
     $img_path = find_theme_image($map['img'], true, true);
     if ($img_path == '') {
         return do_lang_tempcode('NO_SUCH_THEME_IMAGE', $map['img']);
     }
     $cache_id = 'text_overlay_' . md5(serialize($map));
     $url = $block->_do_image($cache_id, $map, $img_path);
     if (is_object($url)) {
         return $url;
     }
     $ret = '<img class="gfx_text_overlay" alt="' . str_replace(chr(10), ' ', escape_html($map['data'])) . '" src="' . escape_html($url) . '" />';
     if (function_exists('ocp_mark_as_escaped')) {
         ocp_mark_as_escaped($ret);
     }
     return make_string_tempcode($ret);
 }
Exemplo n.º 11
0
/**
 * Get an addon icon.
 *
 * @param  ID_TEXT		The name of the addon
 * @return URLPATH		Addon icon (blank: could not find one)
 */
function find_addon_icon($hook)
{
    if ($hook == '') {
        return '';
    }
    static $addon_icons_cache = array();
    if (isset($addon_icons_cache[$hook])) {
        return $addon_icons_cache[$hook];
    }
    $path = get_file_base() . '/sources_custom/hooks/systems/addon_registry/' . filter_naughty_harsh($hook) . '.php';
    if (!file_exists($path)) {
        $path = get_file_base() . '/sources/hooks/systems/addon_registry/' . filter_naughty_harsh($hook) . '.php';
    }
    if (!file_exists($path)) {
        return '';
    }
    $hook_file = file_get_contents($path);
    $matches = array();
    if (preg_match('#function get_file_list\\(\\)\\s*\\{([^\\}]*)\\}#', $hook_file, $matches) != 0) {
        if (!defined('HIPHOP_PHP')) {
            $addon_files = eval($matches[1]);
        } else {
            require_code('hooks/systems/addon_registry/' . $hook);
            $hook_ob = object_factory('Hook_addon_registry_' . $hook);
            $addon_files = $hook_ob->get_file_list();
        }
        foreach ($addon_files as $file) {
            if (substr($file, 0, 31) == 'themes/default/images/bigicons/') {
                $addon_icons_cache[$hook] = find_theme_image('bigicons/' . basename($file, '.png'), false, true);
                return $addon_icons_cache[$hook];
            }
        }
    }
    $addon_icons_cache[$hook] = '';
    return '';
}
Exemplo n.º 12
0
 /**
  * The UI for an "regular mode" gallery.
  *
  * @param  tempcode		Rating area
  * @param  tempcode		Commenting area
  * @param  ID_TEXT		Our gallery ID
  * @param  ID_TEXT		Virtual root gallery
  * @param  tempcode		The description of the gallery
  * @param  tempcode		The tempcode for our visible child galleries
  * @param  boolean		Whether may "download this gallery"
  * @param  tempcode		The URL to "edit this gallery"
  * @param  tempcode		The URL to "add a gallery"
  * @param  tempcode		The URL to "submit an image to this gallery"
  * @param  tempcode		The URL to "submit a video to this gallery"
  * @param  tempcode		The title of the page (our of get_page_title)
  * @param  string			The gallery title
  * @param  tempcode		Sorting UI
  * @return tempcode		The UI
  */
 function do_gallery_regular_mode($rating_details, $comment_details, $cat, $root, $description, $children, $may_download, $edit_url, $add_gallery_url, $submit_image_url, $submit_video_url, $title, $fullname, $sorting)
 {
     $max = get_param_integer('max', get_default_gallery_max());
     $start = get_param_integer('start', 0);
     if ($max < 1) {
         $max = 1;
     }
     $page_num = $max == 0 ? 0 : intval(floor(floatval($start) / floatval($max))) + 1;
     // Work out totals
     $num_images = $GLOBALS['SITE_DB']->query_value('images', 'COUNT(*)', array('cat' => $cat));
     $num_videos = $GLOBALS['SITE_DB']->query_value('videos', 'COUNT(*)', array('cat' => $cat));
     $total_rows = $num_images + $num_videos;
     $total_pages = $max == 0 ? 1 : intval(ceil(floatval($total_rows) / floatval($max)));
     if ($total_pages == 0) {
         $total_pages = 1;
     }
     list($sort, $sort_backwards, $sql_suffix_images, $sql_suffix_videos) = $this->get_sort_order();
     $where = db_string_equal_to('cat', $cat);
     if (!has_specific_permission(get_member(), 'see_unvalidated')) {
         $where .= ' AND validated=1';
     }
     if (get_param('days', '') != '') {
         $where .= ' AND add_date>' . strval(time() - get_param_integer('days') * 60 * 60 * 24);
     }
     $rows = $GLOBALS['SITE_DB']->query('SELECT *' . $sql_suffix_videos . ' FROM ' . get_table_prefix() . 'videos e WHERE ' . $where . ' ORDER BY ' . $sort, $max, $start);
     if (count($rows) < $max) {
         $where = db_string_equal_to('cat', $cat);
         if (!has_specific_permission(get_member(), 'see_unvalidated')) {
             $where .= ' AND validated=1';
         }
         $rows2 = $GLOBALS['SITE_DB']->query('SELECT *' . $sql_suffix_images . ' FROM ' . get_table_prefix() . 'images e WHERE ' . $where . ' ORDER BY ' . $sort, $max - count($rows), max(0, $start - $num_videos));
     } else {
         $rows2 = array();
     }
     $entries = new ocp_tempcode();
     $image_select = get_param('select', '*');
     $video_select = get_param('video_select', '*');
     // Display videos
     foreach ($rows as $row_video) {
         $view_url = build_url(array('page' => '_SELF', 'type' => 'video', 'root' => $root == 'root' ? NULL : $root, 'wide' => 1, 'id' => $row_video['id'], 'start' => $start == 0 ? NULL : $start, 'max' => $start == get_default_gallery_max() ? NULL : $max, 'days' => get_param('days', '') == '' ? NULL : get_param('days'), 'sort' => $sort == 'add_date DESC' ? NULL : $sort, 'select' => $image_select == '*' ? NULL : $image_select, 'video_select' => $video_select == '*' ? NULL : $video_select), '_SELF');
         $thumb_url = ensure_thumbnail($row_video['url'], $row_video['thumb_url'], 'galleries', 'videos', $row_video['id']);
         if ($thumb_url == '') {
             $thumb_url = find_theme_image('na');
         }
         $thumb = do_image_thumb($thumb_url, '', true);
         $this_full_url = $row_video['url'];
         if (url_is_local($this_full_url)) {
             $this_full_url = get_custom_base_url() . '/' . $this_full_url;
         }
         $entry_rating_details = $row_video['allow_rating'] == 1 ? display_rating(get_self_url(true), get_translated_text($row_video['title']), 'videos', strval($row_video['id']), 'RATING_INLINE_STATIC', $row_video['submitter']) : NULL;
         $map = array('_GUID' => '395f0aa1212e69da5752d228a6efe54d', 'RATING_DETAILS' => $entry_rating_details, 'TITLE' => get_translated_text($row_video['title']), 'DESCRIPTION' => get_translated_tempcode($row_video['comments']), 'CAT' => $cat, 'THUMB_URL' => $thumb_url, 'FULL_URL' => $this_full_url, 'ID' => strval($row_video['id']), 'VIEWS' => strval($row_video['video_views']), 'ADD_DATE_RAW' => strval($row_video['add_date']), 'EDIT_DATE_RAW' => is_null($row_video['edit_date']) ? '' : strval($row_video['edit_date']), 'SUBMITTER' => strval($row_video['submitter']), 'THUMB' => $thumb, 'VIEW_URL' => $view_url, 'VIDEO_DETAILS' => show_video_details($row_video));
         $entry = do_template('GALLERY_VIDEO', $map);
         $entries->attach(do_template('GALLERY_ENTRY_WRAP', array('_GUID' => 'bc0d3de5d0160b00e3250d78658888c1', 'ENTRY' => $entry) + $map));
     }
     // Display images
     foreach ($rows2 as $row_image) {
         $view_url = build_url(array('page' => '_SELF', 'type' => 'image', 'root' => $root == 'root' ? NULL : $root, 'wide' => 1, 'id' => $row_image['id'], 'start' => $start == 0 ? NULL : $start, 'max' => $max == get_default_gallery_max() ? NULL : $max, 'days' => get_param('days', '') == '' ? NULL : get_param('days'), 'sort' => $sort == 'add_date DESC' ? NULL : $sort, 'select' => $image_select == '*' ? NULL : $image_select, 'video_select' => $video_select == '*' ? NULL : $video_select), '_SELF');
         $thumb_url = ensure_thumbnail($row_image['url'], $row_image['thumb_url'], 'galleries', 'images', $row_image['id']);
         $thumb = do_image_thumb($thumb_url, '', true);
         $this_full_url = $row_image['url'];
         if (url_is_local($this_full_url)) {
             $file_size = file_exists(get_custom_file_base() . '/' . rawurldecode($this_full_url)) ? strval(filesize(get_custom_file_base() . '/' . rawurldecode($this_full_url))) : '';
             $this_full_url = get_custom_base_url() . '/' . $this_full_url;
         } else {
             $file_size = '';
         }
         $entry_rating_details = $row_image['allow_rating'] == 1 ? display_rating(get_self_url(true), get_translated_text($row_image['title']), 'images', strval($row_image['id']), 'RATING_INLINE_STATIC', $row_image['submitter']) : NULL;
         $map = array('_GUID' => 'aa70f543297e25379c49fa25d6dbcac0', 'RATING_DETAILS' => $entry_rating_details, 'TITLE' => get_translated_text($row_image['title']), 'DESCRIPTION' => get_translated_tempcode($row_image['comments']), 'FILE_SIZE' => $file_size, 'CAT' => $cat, 'THUMB_URL' => $thumb_url, 'FULL_URL' => $this_full_url, 'ID' => strval($row_image['id']), 'VIEWS' => strval($row_image['image_views']), 'ADD_DATE_RAW' => strval($row_image['add_date']), 'EDIT_DATE_RAW' => is_null($row_image['edit_date']) ? '' : strval($row_image['edit_date']), 'SUBMITTER' => strval($row_image['submitter']), 'THUMB' => $thumb, 'VIEW_URL' => $view_url);
         $entry = do_template('GALLERY_IMAGE', $map);
         $entries->attach(do_template('GALLERY_ENTRY_WRAP', array('_GUID' => 'ea12d7acf47eab493b6fb4658b3c0346', 'ENTRY' => $entry) + $map));
     }
     // Member gallery?
     $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);
     // Results browser
     require_code('templates_results_browser');
     $_selectors = array_map('intval', explode(',', get_option('gallery_selectors')));
     $results_browser = results_browser(do_lang('ENTRY'), $cat, $start, 'start', $max, 'max', $total_rows, $root, 'misc', true, false, 10, $_selectors);
     return do_template('GALLERY_REGULAR_MODE_SCREEN', array('_GUID' => 'cec405597f47f5079b7c7f581fa6b5c2', 'SORTING' => $sorting, '_TITLE' => $fullname, 'MEMBER_ID' => is_null($member_id) ? '' : strval($member_id), 'RESULTS_BROWSER' => $results_browser, 'TAGS' => get_loaded_tags('galleries'), 'CAT' => $cat, 'MEMBER_DETAILS' => $member_details, 'RATING_DETAILS' => $rating_details, 'COMMENT_DETAILS' => $comment_details, 'ADD_GALLERY_URL' => $add_gallery_url, 'EDIT_URL' => $edit_url, 'CHILDREN' => $children, 'TITLE' => $title, 'DESCRIPTION' => $description, 'IMAGE_URL' => $submit_image_url, 'VIDEO_URL' => $submit_video_url, 'MAY_DOWNLOAD' => $may_download, 'ENTRIES' => $entries));
 }
Exemplo n.º 13
0
/**
 * Add a member.
 *
 * @param  SHORT_TEXT		The username.
 * @param  SHORT_TEXT		The password.
 * @param  SHORT_TEXT		The e-mail address.
 * @param  ?array				A list of usergroups (NULL: default/current usergroups).
 * @param  ?integer			Day of date of birth (NULL: unknown).
 * @param  ?integer			Month of date of birth (NULL: unknown).
 * @param  ?integer			Year of date of birth (NULL: unknown).
 * @param  array				A map of custom field values (field-id=>value).
 * @param  ?ID_TEXT			The member timezone (NULL: auto-detect).
 * @param  ?GROUP				The member's primary (NULL: default).
 * @param  BINARY				Whether the profile has been validated.
 * @param  ?TIME				When the member joined (NULL: now).
 * @param  ?TIME				When the member last visited (NULL: now).
 * @param  ID_TEXT			The member's default theme.
 * @param  ?URLPATH			The URL to the member's avatar (blank: none) (NULL: choose one automatically).
 * @param  LONG_TEXT			The member's signature (blank: none).
 * @param  BINARY				Whether the member is permanently banned.
 * @param  BINARY				Whether posts are previewed before they are made.
 * @param  BINARY				Whether the member's age may be shown.
 * @param  SHORT_TEXT		The member's title (blank: get from primary).
 * @param  URLPATH			The URL to the member's photo (blank: none).
 * @param  URLPATH			The URL to the member's photo thumbnail (blank: none).
 * @param  BINARY				Whether the member sees signatures in posts.
 * @param  ?BINARY			Whether the member automatically is enabled for notifications for content they contribute to (NULL: get default from config).
 * @param  ?LANGUAGE_NAME	The member's language (NULL: auto detect).
 * @param  BINARY				Whether the member allows e-mails via the site.
 * @param  BINARY				Whether the member allows e-mails from staff via the site.
 * @param  LONG_TEXT			Personal notes of the member.
 * @param  ?IP					The member's IP address (NULL: IP address of current user).
 * @param  SHORT_TEXT		The code required before the account becomes active (blank: already entered).
 * @param  boolean			Whether to check details for correctness.
 * @param  ?ID_TEXT			The compatibility scheme that the password operates in (blank: none) (NULL: none [meaning normal ocPortal salted style] or plain, depending on whether passwords are encrypted).
 * @param  SHORT_TEXT		The password salt (blank: password compatibility scheme does not use a salt / auto-generate).
 * @param  BINARY				Whether the member likes to view zones without menus, when a choice is available.
 * @param  ?TIME				The time the member last made a submission (NULL: set to now).
 * @param  ?AUTO_LINK		Force an ID (NULL: don't force an ID)
 * @param  BINARY				Whether the member username will be highlighted.
 * @param  SHORT_TEXT		Usergroups that may PT the member.
 * @param  LONG_TEXT			Rules that other members must agree to before they may start a PT with the member.
 * @return AUTO_LINK			The ID of the new member.
 */
function ocf_make_member($username, $password, $email_address, $secondary_groups, $dob_day, $dob_month, $dob_year, $custom_fields, $timezone = NULL, $primary_group = NULL, $validated = 1, $join_time = NULL, $last_visit_time = NULL, $theme = '', $avatar_url = NULL, $signature = '', $is_perm_banned = 0, $preview_posts = 0, $reveal_age = 1, $title = '', $photo_url = '', $photo_thumb_url = '', $views_signatures = 1, $auto_monitor_contrib_content = NULL, $language = NULL, $allow_emails = 1, $allow_emails_from_staff = 1, $personal_notes = '', $ip_address = NULL, $validated_email_confirm_code = '', $check_correctness = true, $password_compatibility_scheme = NULL, $salt = '', $zone_wide = 1, $last_submit_time = NULL, $id = NULL, $highlighted_name = 0, $pt_allow = '*', $pt_rules_text = '')
{
    if (is_null($auto_monitor_contrib_content)) {
        $auto_monitor_contrib_content = get_value('no_auto_notifications') === '1' ? 0 : 1;
    }
    if (is_null($password_compatibility_scheme)) {
        if (get_value('no_password_hashing') === '1') {
            $password_compatibility_scheme = 'plain';
        } else {
            $password_compatibility_scheme = '';
        }
    }
    if (is_null($language)) {
        $language = '';
    }
    if (is_null($signature)) {
        $signature = '';
    }
    if (is_null($title)) {
        $title = '';
    }
    if (is_null($timezone)) {
        $timezone = get_site_timezone();
    }
    if (is_null($allow_emails)) {
        $allow_emails = 1;
    }
    if (is_null($allow_emails_from_staff)) {
        $allow_emails_from_staff = 1;
    }
    if (is_null($personal_notes)) {
        $personal_notes = '';
    }
    if (is_null($avatar_url)) {
        if ($GLOBALS['IN_MINIKERNEL_VERSION'] == 1 || !addon_installed('ocf_member_avatars')) {
            $avatar_url = '';
        } else {
            if (get_option('random_avatars') == '1' && !running_script('stress_test_loader')) {
                require_code('themes2');
                $codes = get_all_image_ids_type('ocf_default_avatars/default_set', false, $GLOBALS['FORUM_DB']);
                shuffle($codes);
                $results = array();
                foreach ($codes as $code) {
                    if (strpos($code, 'ocp_fanatic') !== false) {
                        continue;
                    }
                    $count = $GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT SUM(m_cache_num_posts) FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_members WHERE ' . db_string_equal_to('m_avatar_url', find_theme_image($code, false, true)));
                    if (is_null($count)) {
                        $count = 0;
                    }
                    $results[$code] = $count;
                }
                @asort($results);
                // @'d as type checker fails for some odd reason
                $found_avatars = array_keys($results);
                $avatar_url = find_theme_image(array_shift($found_avatars), true, true);
            }
            if (is_null($avatar_url)) {
                $GLOBALS['SITE_DB']->query_delete('theme_images', array('id' => 'ocf_default_avatars/default', 'path' => ''));
                // In case failure cached, gets very confusing
                $avatar_url = find_theme_image('ocf_default_avatars/default', true, true);
                if (is_null($avatar_url)) {
                    $avatar_url = '';
                }
            }
        }
    }
    if ($check_correctness) {
        if (!in_array($password_compatibility_scheme, array('ldap', 'httpauth'))) {
            ocf_check_name_valid($username, NULL, $password_compatibility_scheme == '' ? $password : NULL);
        }
        if (!function_exists('has_actual_page_access') || !has_actual_page_access(get_member(), 'admin_ocf_join')) {
            require_code('type_validation');
            if (!is_valid_email_address($email_address) && $email_address != '') {
                warn_exit(do_lang_tempcode('_INVALID_EMAIL_ADDRESS', escape_html($email_address)));
            }
        }
    }
    require_code('ocf_members');
    require_code('ocf_groups');
    if (is_null($last_submit_time)) {
        $last_submit_time = time();
    }
    if (is_null($join_time)) {
        $join_time = time();
    }
    if (is_null($last_visit_time)) {
        $last_visit_time = time();
    }
    if (is_null($primary_group)) {
        $primary_group = get_first_default_group();
        // This is members
    }
    if (is_null($secondary_groups)) {
        $secondary_groups = ocf_get_all_default_groups(false);
    }
    foreach ($secondary_groups as $_g_id => $g_id) {
        if ($g_id == $primary_group) {
            unset($secondary_groups[$_g_id]);
        }
    }
    if (is_null($ip_address)) {
        $ip_address = get_ip_address();
    }
    if ($password_compatibility_scheme == '' && get_value('no_password_hashing') === '1') {
        $password_compatibility_scheme = 'plain';
        $salt = '';
    }
    if ($salt == '' && $password_compatibility_scheme == '') {
        $salt = produce_salt();
        $password_salted = md5($salt . md5($password));
    } else {
        $password_salted = $password;
    }
    // Supplement custom field values given with defaults, and check constraints
    $all_fields = list_to_map('id', ocf_get_all_custom_fields_match($secondary_groups));
    require_code('fields');
    foreach ($all_fields as $field) {
        $field_id = $field['id'];
        if (array_key_exists($field_id, $custom_fields)) {
            if ($check_correctness && $field[array_key_exists('cf_show_on_join_form', $field) ? 'cf_show_on_join_form' : 'cf_required'] == 0 && $field['cf_owner_set'] == 0 && !has_actual_page_access(get_member(), 'admin_ocf_join')) {
                access_denied('I_ERROR');
            }
        } else {
            $custom_fields[$field_id] = '';
        }
    }
    if (!addon_installed('unvalidated')) {
        $validated = 1;
    }
    $map = array('m_username' => $username, 'm_pass_hash_salted' => $password_salted, 'm_pass_salt' => $salt, 'm_theme' => $theme, 'm_avatar_url' => $avatar_url, 'm_validated' => $validated, 'm_validated_email_confirm_code' => $validated_email_confirm_code, 'm_cache_num_posts' => 0, 'm_cache_warnings' => 0, 'm_max_email_attach_size_mb' => 5, 'm_join_time' => $join_time, 'm_timezone_offset' => $timezone, 'm_primary_group' => $primary_group, 'm_last_visit_time' => $last_visit_time, 'm_last_submit_time' => $last_submit_time, 'm_signature' => insert_lang_comcode($signature, 4, $GLOBALS['FORUM_DB']), 'm_is_perm_banned' => $is_perm_banned, 'm_preview_posts' => $preview_posts, 'm_notes' => $personal_notes, 'm_dob_day' => $dob_day, 'm_dob_month' => $dob_month, 'm_dob_year' => $dob_year, 'm_reveal_age' => $reveal_age, 'm_email_address' => $email_address, 'm_title' => $title, 'm_photo_url' => $photo_url, 'm_photo_thumb_url' => $photo_thumb_url, 'm_views_signatures' => $views_signatures, 'm_auto_monitor_contrib_content' => $auto_monitor_contrib_content, 'm_highlighted_name' => $highlighted_name, 'm_pt_allow' => $pt_allow, 'm_pt_rules_text' => insert_lang_comcode($pt_rules_text, 4, $GLOBALS['FORUM_DB']), 'm_language' => $language, 'm_ip_address' => $ip_address, 'm_zone_wide' => $zone_wide, 'm_allow_emails' => $allow_emails, 'm_allow_emails_from_staff' => $allow_emails_from_staff, 'm_password_change_code' => '', 'm_password_compat_scheme' => $password_compatibility_scheme, 'm_on_probation_until' => NULL);
    if (!is_null($id)) {
        $map['id'] = $id;
    }
    $member_id = $GLOBALS['FORUM_DB']->query_insert('f_members', $map, true);
    if ($check_correctness) {
        // If it was an invite/recommendation, award the referrer
        if (addon_installed('recommend')) {
            $inviter = $GLOBALS['FORUM_DB']->query_value_null_ok('f_invites', 'i_inviter', array('i_email_address' => $email_address), 'ORDER BY i_time');
            if (!is_null($inviter)) {
                if (addon_installed('points')) {
                    require_code('points2');
                    require_lang('recommend');
                    system_gift_transfer(do_lang('RECOMMEND_SITE_TO', $username, get_site_name()), intval(get_option('points_RECOMMEND_SITE')), $inviter);
                }
                if (addon_installed('chat')) {
                    require_code('chat2');
                    buddy_add($inviter, $member_id);
                    buddy_add($member_id, $inviter);
                }
            }
        }
    }
    $value = mixed();
    // Store custom fields
    $row = array('mf_member_id' => $member_id);
    $all_fields_types = collapse_2d_complexity('id', 'cf_type', $all_fields);
    foreach ($custom_fields as $field_num => $value) {
        if (!array_key_exists($field_num, $all_fields_types)) {
            continue;
        }
        // Trying to set a field we're not allowed to (doesn't apply to our group)
        $ob = get_fields_hook($all_fields_types[$field_num]);
        list(, , $storage_type) = $ob->get_field_value_row_bits($all_fields[$field_num]);
        if (strpos($storage_type, '_trans') !== false) {
            $value = insert_lang($value, 3, $GLOBALS['FORUM_DB']);
        }
        $row['field_' . strval($field_num)] = $value;
    }
    // Set custom field row
    $all_fields_regardless = $GLOBALS['FORUM_DB']->query_select('f_custom_fields', array('id', 'cf_type'));
    foreach ($all_fields_regardless as $field) {
        if (!array_key_exists('field_' . strval($field['id']), $row)) {
            $ob = get_fields_hook($field['cf_type']);
            list(, , $storage_type) = $ob->get_field_value_row_bits($field);
            $value = '';
            if (strpos($storage_type, '_trans') !== false) {
                $value = insert_lang($value, 3, $GLOBALS['FORUM_DB']);
            }
            $row['field_' . strval($field['id'])] = $value;
        }
    }
    $GLOBALS['FORUM_DB']->query_insert('f_member_custom_fields', $row);
    // Any secondary work
    foreach ($secondary_groups as $g) {
        if ($g != $primary_group) {
            $GLOBALS['FORUM_DB']->query_delete('f_group_members', array('gm_member_id' => $member_id, 'gm_group_id' => $g), '', 1);
            $GLOBALS['FORUM_DB']->query_insert('f_group_members', array('gm_group_id' => $g, 'gm_member_id' => $member_id, 'gm_validated' => 1));
        }
    }
    if ($check_correctness) {
        if (function_exists('decache')) {
            decache('side_stats');
        }
    }
    return $member_id;
}
Exemplo n.º 14
0
 function testAddImageActualiser()
 {
     //Test data add to POST
     $_POST = array('title' => 'A test image', 'require__title' => 0, 'cat' => 'a_test_gallery_for_ut', 'require__cat' => 1, 'require__file' => 0, 'hidFileID_file' => -1, 'url' => find_theme_image('bottom/loading'), 'require__url' => 1, 'require__file2' => 1, 'hidFileID_file2' => -1, 'file2' => '', 'comcode__comments' => 1, 'comments' => 'test description', 'comments_parsed' => '', 'validated' => 1, 'tick_on_form__validated' => 0, 'require__validated' => 0, 'tick_on_form__rep_image' => 0, 'require__rep_image' => 0, 'allow_rating' => 1, 'tick_on_form__allow_rating' => 0, 'require__allow_rating' => 0, 'allow_comments' => 1, 'require__allow_comments' => 1, 'allow_trackbacks' => 1, 'tick_on_form__allow_trackbacks' => 0, 'require__allow_trackbacks' => 0, 'notes' => '', 'pre_f_notes' => 1, 'require__notes' => 0, 'meta_keywords' => '', 'require__meta_keywords' => 0, 'meta_description' => '', 'require__meta_description' => 0, 'comments__is_wysiwyg' => 1);
     return $this->cms_gal->_ad();
 }
Exemplo n.º 15
0
/**
 * Create a video thumbnail.
 *
 * @param  URLPATH		Video to get thumbail from (must be local)
 * @param  ?PATH			Where to save to (NULL: decide for ourselves)
 * @return URLPATH		Thumbnail, only valid if expected_output_path was passed as NULL (blank: could not generate)
 */
function create_video_thumb($src_url, $expected_output_path = NULL)
{
    // Audio ones should have automatic thumbnails
    require_code('mime_types');
    $file_ext = get_file_extension($src_url);
    $input_mime_type = get_mime_type($file_ext);
    if (preg_match('#audio\\/#i', $input_mime_type) != 0) {
        $ret = find_theme_image('audio_thumb', true);
        if ($ret != '') {
            if (!is_null($expected_output_path)) {
                require_code('files');
                $_expected_output_path = fopen($expected_output_path, 'wb');
                http_download_file($ret, NULL, true, false, 'ocPortal', NULL, NULL, NULL, NULL, NULL, $_expected_output_path);
                fclose($_expected_output_path);
            }
        }
        return $ret;
    }
    // Try one of the hooks for video types
    $ve_hooks = find_all_hooks('systems', 'video_embed');
    foreach (array_keys($ve_hooks) as $ve_hook) {
        require_code('hooks/systems/video_embed/' . $ve_hook);
        $ve_ob = object_factory('Hook_video_embed_' . $ve_hook);
        $thumbnail = $ve_ob->get_video_thumbnail($src_url);
        if (!is_null($thumbnail)) {
            return $thumbnail;
        }
    }
    // Ok, gonna try hard using what FFMPEG techniques we can...
    if (substr($src_url, 0, strlen(get_custom_base_url() . '/')) == get_custom_base_url() . '/') {
        $src_url = substr($src_url, strlen(get_custom_base_url() . '/'));
    }
    if (!url_is_local($src_url)) {
        return '';
    }
    $src_file = get_custom_file_base() . '/' . rawurldecode($src_url);
    $src_file = preg_replace('#(\\\\|/)#', DIRECTORY_SEPARATOR, $src_file);
    if (class_exists('ffmpeg_movie')) {
        $filename = 'thumb_' . md5(uniqid('', true)) . '1.jpg';
        if (is_null($expected_output_path)) {
            $expected_output_path = get_custom_file_base() . '/uploads/galleries/' . $filename;
        }
        if (file_exists($expected_output_path)) {
            return 'uploads/galleries/' . rawurlencode(basename($expected_output_path));
        }
        $movie = @new ffmpeg_movie($src_file, false);
        if ($movie !== false) {
            if ($movie->getFrameCount() == 0) {
                return '';
            }
            $frame = $movie->getFrame(min($movie->getFrameCount(), 25));
            if (method_exists($frame, 'toGDImage')) {
                $gd_img = $frame->toGDImage();
                @imagejpeg($gd_img, $expected_output_path);
            } else {
                $frame->save($expected_output_path);
                // New-style
            }
            if (file_exists($expected_output_path)) {
                require_code('images');
                if (get_option('is_on_gd') == '1' && function_exists('imagecreatefromstring')) {
                    convert_image($expected_output_path, $expected_output_path, -1, -1, intval(get_option('thumb_width')), true, NULL, true);
                }
                return 'uploads/galleries/' . rawurlencode(basename($expected_output_path));
            }
        }
    }
    $ffmpeg_path = get_option('ffmpeg_path');
    if ($ffmpeg_path != '' && strpos(@ini_get('disable_functions'), 'shell_exec') === false) {
        $filename = 'thumb_' . md5(uniqid(strval(post_param_integer('thumbnail_auto_position', 1)), true)) . '%d.jpg';
        $dest_file = get_custom_file_base() . '/uploads/galleries/' . $filename;
        if (is_null($expected_output_path)) {
            $expected_output_path = str_replace('%d', '1', $dest_file);
        }
        if (file_exists($dest_file) && is_null(post_param_integer('thumbnail_auto_position', NULL))) {
            return 'uploads/galleries/' . rawurlencode(basename($expected_output_path));
        }
        @unlink($dest_file);
        // So "if (@filesize($expected_output_path)) break;" will definitely fail if error
        $dest_file = preg_replace('#(\\\\|/)#', DIRECTORY_SEPARATOR, $dest_file);
        $at = display_seconds_period(post_param_integer('thumbnail_auto_position', 1));
        if (strlen($at) == 5) {
            $at = '00:' . $at;
        }
        $shell_command = '"' . $ffmpeg_path . 'ffmpeg" -i ' . @escapeshellarg($src_file) . ' -an -ss ' . $at . ' -r 1 -vframes 1 -y ' . @escapeshellarg($dest_file);
        $shell_commands = array($shell_command, $shell_command . ' -map 0.0:0.0', $shell_command . ' -map 0.1:0.0');
        foreach ($shell_commands as $shell_command) {
            shell_exec($shell_command);
            if (@filesize($expected_output_path)) {
                break;
            }
        }
        if (file_exists(str_replace('%d', '1', $dest_file))) {
            require_code('images');
            if (get_option('is_on_gd') == '1' && function_exists('imagecreatefromstring')) {
                convert_image(str_replace('%d', '1', $dest_file), $expected_output_path, -1, -1, intval(get_option('thumb_width')), true, NULL, true);
            } else {
                copy(str_replace('%d', '1', $dest_file), $expected_output_path);
                fix_permissions($expected_output_path);
                sync_file($expected_output_path);
            }
            return 'uploads/galleries/' . rawurlencode(basename($expected_output_path));
        }
    }
    return '';
}
Exemplo n.º 16
0
 /**
  * Standard aed_module list function.
  *
  * @return tempcode		The selection list
  */
 function nice_get_radio_entries()
 {
     $_m = $GLOBALS['FORUM_DB']->query_select('f_emoticons', array('e_code', 'e_theme_img_code'));
     $entries = array();
     $first = true;
     foreach ($_m as $m) {
         $url = find_theme_image($m['e_theme_img_code']);
         $entries[] = do_template('FORM_SCREEN_INPUT_RADIO_LIST_ENTRY_PICTURE_3', array('_GUID' => 'f7f64637d1c4984881f7acc68c2fe6c7', 'PRETTY' => $m['e_code'], 'CHECKED' => $first, 'NAME' => 'id', 'CODE' => $m['e_code'], 'URL' => $url));
         $first = false;
     }
     $_entries = wrap_image_radio_list($entries);
     return $_entries;
 }
Exemplo n.º 17
0
 /**
  * The UI for doing a quiz.
  *
  * @return tempcode	The result of execution.
  */
 function do_quiz()
 {
     $id = get_param_integer('id');
     $quizzes = $GLOBALS['SITE_DB']->query_select('quizzes', array('*'), array('id' => $id), '', 1);
     if (!array_key_exists(0, $quizzes)) {
         warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
     }
     $quiz = $quizzes[0];
     $this->enforcement_checks($quiz);
     if (addon_installed('awards')) {
         require_code('awards');
         $awards = find_awards_for('quiz', strval($id));
     } else {
         $awards = array();
     }
     $quiz_name = get_translated_text($quiz['q_name']);
     $title_to_use = do_lang_tempcode('THIS_WITH', do_lang_tempcode($quiz['q_type']), make_string_tempcode(escape_html($quiz_name)));
     $title_to_use_2 = do_lang('THIS_WITH_SIMPLE', do_lang($quiz['q_type']), $quiz_name);
     $title = get_page_title($title_to_use, false, NULL, NULL, $awards);
     seo_meta_load_for('quiz', strval($id), $title_to_use_2);
     $last_visit_time = $GLOBALS['SITE_DB']->query_value_null_ok('quiz_member_last_visit', 'v_time', array('v_quiz_id' => $id, 'v_member_id' => get_member()), 'ORDER BY v_time DESC');
     if (!is_null($last_visit_time)) {
         $timer_offset = time() - $last_visit_time;
         if (is_null($quiz['q_timeout']) || $timer_offset >= $quiz['q_timeout'] * 60) {
             $GLOBALS['SITE_DB']->query_delete('quiz_member_last_visit', array('v_member_id' => get_member(), 'v_quiz_id' => $id));
             $GLOBALS['SITE_DB']->query_insert('quiz_member_last_visit', array('v_quiz_id' => $id, 'v_time' => time(), 'v_member_id' => get_member()));
             $timer_offset = 0;
         }
     } else {
         $GLOBALS['SITE_DB']->query_insert('quiz_member_last_visit', array('v_quiz_id' => $id, 'v_time' => time(), 'v_member_id' => get_member()));
         $timer_offset = 0;
     }
     $questions = $GLOBALS['SITE_DB']->query_select('quiz_questions', array('*'), array('q_quiz' => $id), 'ORDER BY q_order');
     // If a test/quiz, randomly order questions
     //		if ($quiz['q_type']!='SURVEY') shuffle($questions);			No, could cause problems
     foreach ($questions as $i => $question) {
         $answers = $GLOBALS['SITE_DB']->query_select('quiz_question_answers', array('*'), array('q_question' => $question['id']), 'ORDER BY q_order');
         // If a test/quiz, randomly order answers
         if ($quiz['q_type'] != 'SURVEY') {
             shuffle($answers);
         }
         $questions[$i]['answers'] = $answers;
     }
     require_code('quiz');
     $fields = render_quiz($questions);
     breadcrumb_set_self(make_string_tempcode(escape_html(get_translated_text($quiz['q_name']))));
     // Validation
     if ($quiz['q_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('WARNING' => do_lang_tempcode(get_param_integer('redirected', 0) == 1 ? 'UNVALIDATED_TEXT_NON_DIRECT' : 'UNVALIDATED_TEXT')));
     } else {
         $warning_details = new ocp_tempcode();
     }
     $type = 'Quiz';
     switch ($quiz['q_type']) {
         case 'COMPETITION':
             $type = 'Competition';
             break;
         case 'SURVEY':
             $type = 'Survey';
             break;
         case 'TEST':
             $type = 'Test';
             break;
     }
     $GLOBALS['META_DATA'] += array('created' => date('Y-m-d', $quiz['q_add_date']), 'creator' => $GLOBALS['FORUM_DRIVER']->get_username($quiz['q_submitter']), 'publisher' => '', 'modified' => '', 'type' => $type, 'title' => get_translated_text($quiz['q_name']), 'identifier' => '_SEARCH:quiz:do:' . strval($id), 'description' => get_translated_text($quiz['q_start_text']), 'image' => find_theme_image('bigicons/quiz'));
     $edit_url = new ocp_tempcode();
     if (has_actual_page_access(NULL, 'cms_quiz', NULL, NULL) && has_edit_permission('mid', get_member(), $quiz['q_submitter'], 'cms_quiz', array('quiz', $id))) {
         $edit_url = build_url(array('page' => 'cms_quiz', 'type' => '_ed', 'id' => $id), get_module_zone('cms_quiz'));
     }
     // Display UI: start text, questions. Including timeout
     $start_text = get_translated_tempcode($quiz['q_start_text']);
     $post_url = build_url(array('page' => '_SELF', 'type' => '_do', 'id' => $id), '_SELF');
     return do_template('QUIZ_SCREEN', array('_GUID' => 'f390877672938ba62f79f9528bef742f', 'EDIT_URL' => $edit_url, 'TAGS' => get_loaded_tags('quiz'), 'ID' => strval($id), 'WARNING_DETAILS' => $warning_details, 'URL' => $post_url, 'TITLE' => $title, 'START_TEXT' => $start_text, 'FIELDS' => $fields, 'TIMEOUT' => is_null($quiz['q_timeout']) ? '' : strval($quiz['q_timeout'] * 60 - $timer_offset)));
 }
Exemplo n.º 18
0
/**
 * Get a map of details relating to the view of a certain forum of a certain member.
 *
 * @param  integer	The start row for getting details of topics in the forum (i.e. 0 is newest, higher is starting further back in time).
 * @param  ?integer	The maximum number of topics to get detail of (NULL: default).
 * @param  ?MEMBER	The member viewing (NULL: current member).
 * @return array		The details.
 */
function ocf_get_forum_view($start = 0, $max = NULL, $forum_id = NULL)
{
    if (is_null($max)) {
        $max = intval(get_option('forum_topics_per_page'));
    }
    $member_id = get_member();
    load_up_all_module_category_permissions($member_id, 'forums');
    if (is_null($forum_id)) {
        /*$forum_info[0]['f_name']=do_lang('ROOT_FORUM'); This optimisation was more trouble that it was worth, and constraining
        		$forum_info[0]['f_description']='';
        		$forum_info[0]['f_parent_forum']=NULL;*/
        $forum_id = db_get_first_id();
    }
    $forum_info = $GLOBALS['FORUM_DB']->query_select('f_forums f', array('f_redirection', 'f_intro_question', 'f_intro_answer', 'f_order_sub_alpha', 'f_parent_forum', 'f_name', 'f_description', 'f_order'), array('f.id' => $forum_id), '', 1, NULL, false, array('f_description', 'f_intro_question'));
    if (!array_key_exists(0, $forum_info)) {
        warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
    }
    if ($forum_info[0]['f_redirection'] != '' && looks_like_url($forum_info[0]['f_redirection'])) {
        header('Location: ' . $forum_info[0]['f_redirection']);
        exit;
    }
    if (!is_null($forum_id)) {
        if (!has_category_access($member_id, 'forums', strval($forum_id))) {
            access_denied('CATEGORY_ACCESS_LEVEL');
        }
        // We're only allowed to view it existing from a parent forum, or nothing at all -- so access denied brother!
    }
    // Find our subforums first
    $order = $forum_info[0]['f_order_sub_alpha'] ? 'f_name' : 'f_position';
    $_max_forum_detail = get_value('max_forum_detail');
    $max_forum_detail = is_null($_max_forum_detail) ? 100 : intval($_max_forum_detail);
    $huge_forums = $GLOBALS['FORUM_DB']->query_value('f_forums', 'COUNT(*)') > $max_forum_detail;
    if ($huge_forums) {
        $_max_forum_inspect = get_value('max_forum_inspect');
        $max_forum_inspect = is_null($_max_forum_inspect) ? 300 : intval($_max_forum_inspect);
        $subforum_rows = $GLOBALS['FORUM_DB']->query('SELECT f.* FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_forums f WHERE f.id=' . strval($forum_id) . ' OR f_parent_forum=' . strval($forum_id) . ' ORDER BY f_parent_forum,' . $order, $max_forum_inspect, NULL, false, false, array('f_description', 'f_intro_question'));
        if (count($subforum_rows) == $max_forum_inspect) {
            $subforum_rows = array();
        }
        // Will cause performance breakage
    } else {
        $subforum_rows = $GLOBALS['FORUM_DB']->query_select('f_forums f', array('f.*'), NULL, 'ORDER BY f_parent_forum,' . $order, NULL, NULL, false, array('f_description', 'f_intro_question'));
    }
    $unread_forums = array();
    if (!is_null($forum_id) && get_member() != $GLOBALS['OCF_DRIVER']->get_guest_id()) {
        // Where are there unread topics in subforums?
        $tree = array();
        $subforum_rows_copy = $subforum_rows;
        $tree = ocf_organise_into_tree($subforum_rows_copy, $forum_id);
        if ($forum_id != db_get_first_id()) {
            $child_or_list = ocf_get_all_subordinate_forums($forum_id, 't_forum_id', $tree);
        } else {
            $child_or_list = '';
        }
        if ($child_or_list != '') {
            $child_or_list .= ' AND ';
        }
        $query = 'SELECT DISTINCT t_forum_id,t.id FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics t LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_read_logs l ON (t.id=l_topic_id AND l_member_id=' . strval((int) get_member()) . ') WHERE ' . $child_or_list . 't_cache_last_time>' . strval(time() - 60 * 60 * 24 * intval(get_option('post_history_days'))) . ' AND (l_time<t_cache_last_time OR l_time IS NULL)';
        if (!has_specific_permission(get_member(), 'jump_to_unvalidated')) {
            $query .= ' AND t_validated=1';
        }
        $unread_forums = collapse_2d_complexity('t_forum_id', 'id', $GLOBALS['FORUM_DB']->query($query));
    }
    // Find all the categories that are used
    $categories = array();
    $or_list = '';
    foreach ($subforum_rows as $tmp_key => $subforum_row) {
        if ($subforum_row['f_parent_forum'] != $forum_id) {
            continue;
        }
        if (!has_category_access($member_id, 'forums', strval($subforum_row['id']))) {
            unset($subforum_rows[$tmp_key]);
            continue;
        }
        $category_id = $subforum_row['f_category_id'];
        if (!array_key_exists($category_id, $categories)) {
            $categories[$category_id] = array('subforums' => array());
            if ($or_list != '') {
                $or_list .= ' OR ';
            }
            $or_list .= 'id=' . strval((int) $category_id);
        }
    }
    if ($or_list != '') {
        $category_rows = $GLOBALS['FORUM_DB']->query('SELECT * FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_categories WHERE ' . $or_list);
        foreach ($category_rows as $category_row) {
            $category_id = $category_row['id'];
            $title = $category_row['c_title'];
            $description = $category_row['c_description'];
            $expanded_by_default = $category_row['c_expanded_by_default'];
            $categories[$category_id]['title'] = $title;
            $categories[$category_id]['description'] = $description;
            $categories[$category_id]['expanded_by_default'] = $expanded_by_default;
        }
        $categories[NULL]['title'] = '';
        $categories[NULL]['description'] = '';
        $categories[NULL]['expanded_by_default'] = true;
        foreach ($subforum_rows as $subforum_row) {
            if ($subforum_row['f_parent_forum'] != $forum_id) {
                continue;
            }
            $category_id = $subforum_row['f_category_id'];
            //			if (!array_key_exists('position',$categories[$category_id])) $categories[$category_id]['position']=$subforum_row['f_position'];
            $subforum = array();
            $subforum['id'] = $subforum_row['id'];
            $subforum['name'] = $subforum_row['f_name'];
            $subforum['description'] = get_translated_tempcode($subforum_row['f_description'], $GLOBALS['FORUM_DB']);
            $subforum['redirection'] = $subforum_row['f_redirection'];
            $subforum['intro_question'] = get_translated_tempcode($subforum_row['f_intro_question'], $GLOBALS['FORUM_DB']);
            $subforum['intro_answer'] = $subforum_row['f_intro_answer'];
            if (is_numeric($subforum_row['f_redirection'])) {
                $subforum_row = $GLOBALS['FORUM_DB']->query_select('f_forums', array('*'), array('id' => intval($subforum_row['f_redirection'])), '', 1);
                $subforum_row = $subforum_row[0];
            }
            if ($subforum_row['f_redirection'] == '' || is_numeric($subforum_row['f_redirection'])) {
                $subforum['num_topics'] = $subforum_row['f_cache_num_topics'];
                $subforum['num_posts'] = $subforum_row['f_cache_num_posts'];
                $subforum['has_new'] = false;
                if (get_member() != $GLOBALS['OCF_DRIVER']->get_guest_id()) {
                    $subforums_recurse = ocf_get_all_subordinate_forums($subforum['id'], NULL, $tree[$subforum['id']]['children']);
                    foreach ($subforums_recurse as $subforum_potential) {
                        if (array_key_exists($subforum_potential, $unread_forums)) {
                            $subforum['has_new'] = true;
                        }
                    }
                }
                if (is_null($subforum_row['f_cache_last_forum_id']) || has_category_access($member_id, 'forums', strval($subforum_row['f_cache_last_forum_id']))) {
                    $subforum['last_topic_id'] = $subforum_row['f_cache_last_topic_id'];
                    $subforum['last_title'] = $subforum_row['f_cache_last_title'];
                    $subforum['last_time'] = $subforum_row['f_cache_last_time'];
                    $subforum['last_username'] = $subforum_row['f_cache_last_username'];
                    $subforum['last_member_id'] = $subforum_row['f_cache_last_member_id'];
                    $subforum['last_forum_id'] = $subforum_row['f_cache_last_forum_id'];
                } else {
                    $subforum['protected_last_post'] = true;
                }
                // Subsubforums
                $subforum['children'] = array();
                foreach ($subforum_rows as $tmp_key_2 => $subforum_row2) {
                    if ($subforum_row2['f_parent_forum'] == $subforum_row['id'] && has_category_access($member_id, 'forums', strval($subforum_row2['id']))) {
                        $subforum['children'][$subforum_row2['f_name'] . '__' . strval($subforum_row2['id'])] = array('id' => $subforum_row2['id'], 'name' => $subforum_row2['f_name'], 'redirection' => $subforum_row2['f_redirection']);
                    }
                }
                global $M_SORT_KEY;
                $M_SORT_KEY = 'name';
                uasort($subforum['children'], 'multi_sort');
            }
            $categories[$category_id]['subforums'][] = $subforum;
        }
    }
    // Find topics
    $extra = '';
    if (!has_specific_permission(get_member(), 'see_unvalidated') && !ocf_may_moderate_forum($forum_id, $member_id)) {
        $extra = 't_validated=1 AND ';
    }
    if (is_null($forum_info[0]['f_parent_forum'])) {
        $where = $extra . ' (t_forum_id=' . strval((int) $forum_id) . ')';
    } else {
        $extra2 = '';
        $parent_or_list = ocf_get_forum_parent_or_list($forum_id, $forum_info[0]['f_parent_forum']);
        if ($parent_or_list != '') {
            $extra2 = 'AND (' . $parent_or_list . ')';
        }
        $where = $extra . ' (t_forum_id=' . strval((int) $forum_id) . ' OR (t_cascading=1 ' . $extra2 . '))';
    }
    $order = get_param('order', $forum_info[0]['f_order']);
    $order2 = 't_cache_last_time DESC';
    if ($order == 'first_post') {
        $order2 = 't_cache_first_time DESC';
    } elseif ($order == 'title') {
        $order2 = 't_cache_first_title ASC';
    }
    if (get_value('disable_sunk') !== '1') {
        $order2 = 't_sunk ASC,' . $order2;
    }
    if (is_guest()) {
        $query = 'SELECT ttop.*,t.text_parsed AS _trans_post,NULL AS l_time FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics ttop LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON ' . db_string_equal_to('language', user_lang()) . ' AND ttop.t_cache_first_post=t.id WHERE ' . $where . ' ORDER BY t_cascading DESC,t_pinned DESC,' . $order2;
    } else {
        $query = 'SELECT ttop.*,t.text_parsed AS _trans_post,l_time FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics ttop LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_read_logs l ON (ttop.id=l.l_topic_id AND l.l_member_id=' . strval((int) get_member()) . ') LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON ' . db_string_equal_to('language', user_lang()) . ' AND ttop.t_cache_first_post=t.id WHERE ' . $where . ' ORDER BY t_cascading DESC,t_pinned DESC,' . $order2;
    }
    $topic_rows = $GLOBALS['FORUM_DB']->query($query, $max, $start);
    if ($start == 0 && count($topic_rows) < $max) {
        $max_rows = $max;
    } else {
        $max_rows = $GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics WHERE ' . $where);
    }
    $topics = array();
    $hot_topic_definition = intval(get_option('hot_topic_definition'));
    $or_list = '';
    foreach ($topic_rows as $topic_row) {
        if ($or_list != '') {
            $or_list .= ' OR ';
        }
        $or_list .= 'p_topic_id=' . strval((int) $topic_row['id']);
    }
    if ($or_list != '' && !is_guest()) {
        $involved = $GLOBALS['FORUM_DB']->query('SELECT DISTINCT p_topic_id FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts WHERE (' . $or_list . ') AND p_poster=' . strval((int) get_member()));
        $involved = collapse_1d_complexity('p_topic_id', $involved);
    } else {
        $involved = array();
    }
    foreach ($topic_rows as $topic_row) {
        $topics[] = ocf_get_topic_array($topic_row, $member_id, $hot_topic_definition, in_array($topic_row['id'], $involved));
    }
    $description = get_translated_tempcode($forum_info[0]['f_description'], $GLOBALS['FORUM_DB']);
    $description_text = get_translated_text($forum_info[0]['f_description'], $GLOBALS['FORUM_DB']);
    $out = array('name' => $forum_info[0]['f_name'], 'description' => $description, 'categories' => $categories, 'topics' => $topics, 'max_rows' => $max_rows, 'order' => $order, 'parent_forum' => $forum_info[0]['f_parent_forum']);
    $GLOBALS['META_DATA'] += array('created' => '', 'creator' => '', 'publisher' => '', 'modified' => '', 'type' => 'Forum', 'title' => $forum_info[0]['f_name'], 'identifier' => '_SEARCH:forumview:misc:' . strval($forum_id), 'description' => $description_text, 'image' => find_theme_image('bigicons/forums'));
    // Is there a question/answer situation?
    $question = get_translated_tempcode($forum_info[0]['f_intro_question'], $GLOBALS['FORUM_DB']);
    if (!$question->is_empty()) {
        $is_guest = $member_id == $GLOBALS['OCF_DRIVER']->get_guest_id();
        $test = $GLOBALS['FORUM_DB']->query_value_null_ok('f_forum_intro_ip', 'i_ip', array('i_forum_id' => $forum_id, 'i_ip' => get_ip_address(3)));
        if (is_null($test) && !$is_guest) {
            $test = $GLOBALS['FORUM_DB']->query_value_null_ok('f_forum_intro_member', 'i_member_id', array('i_forum_id' => $forum_id, 'i_member_id' => $member_id));
        }
        if (is_null($test)) {
            $out['question'] = $question;
            $out['answer'] = $forum_info[0]['f_intro_answer'];
        }
    }
    if (ocf_may_post_topic($forum_id, $member_id)) {
        $out['may_post_topic'] = 1;
    }
    if (ocf_may_moderate_forum($forum_id, $member_id)) {
        $out['may_change_max'] = 1;
        $out['may_move_topics'] = 1;
        if (has_specific_permission(get_member(), 'multi_delete_topics')) {
            $out['may_delete_topics'] = 1;
        }
        // Only super admins can casually delete topics - other staff are expected to trash them. At least deleted posts or trashed topics can be restored!
    }
    return $out;
}
Exemplo n.º 19
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('AVATAR');
     $order = 20;
     // Actualiser
     if (post_param_integer('submitting_avatar_tab', 0) == 1) {
         require_code('uploads');
         if (has_specific_permission($member_id_viewing, 'own_avatars')) {
             if (!(is_swf_upload(true) && array_key_exists('avatar_file', $_FILES) || array_key_exists('avatar_file', $_FILES) && is_uploaded_file($_FILES['avatar_file']['tmp_name']))) {
                 $urls = array();
                 $stock = post_param('avatar_alt_url', '');
                 if ($stock == '') {
                     $stock = post_param('avatar_stock', NULL);
                     if (!is_null($stock)) {
                         $urls[0] = $stock == '' ? '' : find_theme_image($stock, false, true);
                     } else {
                         $urls[0] = '';
                     }
                     // None
                 } else {
                     if (url_is_local($stock) && !$GLOBALS['FORUM_DRIVER']->is_super_admin($member_id_viewing)) {
                         $old = $GLOBALS['FORUM_DB']->query_value('f_members', 'm_avatar_url', array('id' => $member_id_of));
                         if ($old != $stock) {
                             access_denied('ASSOCIATE_EXISTING_FILE');
                         }
                     }
                     $urls[0] = $stock;
                     // URL
                 }
             } else {
                 // We have chosen an upload. Note that we will not be looking at alt_url at this point, even though it is specified below for canonical reasons
                 $urls = get_url('avatar_alt_url', 'avatar_file', file_exists(get_custom_file_base() . '/uploads/avatars') ? 'uploads/avatars' : 'uploads/ocf_avatars', 0, OCP_UPLOAD_IMAGE, false, '', '', false, true);
                 if ((get_base_url() != get_forum_base_url() || array_key_exists('on_msn', $GLOBALS['SITE_INFO']) && $GLOBALS['SITE_INFO']['on_msn'] == '1') && $urls[0] != '' && url_is_local($urls[0])) {
                     $urls[0] = get_custom_base_url() . '/' . $urls[0];
                 }
             }
             $avatar_url = $urls[0];
         } else {
             $stock = post_param('avatar_stock');
             $avatar_url = $stock == '' ? '' : find_theme_image($stock, false, true);
         }
         require_code('ocf_members_action');
         require_code('ocf_members_action2');
         ocf_member_choose_avatar($avatar_url, $member_id_of);
         attach_message(do_lang_tempcode('SUCCESS_SAVE'), 'inform');
     }
     if ($leave_to_ajax_if_possible) {
         return NULL;
     }
     // UI fields
     $avatar_url = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_avatar_url');
     require_javascript('javascript_multi');
     $fields = new ocp_tempcode();
     require_code('form_templates');
     require_code('themes2');
     $ids = get_all_image_ids_type('ocf_default_avatars', true);
     $found_it = false;
     foreach ($ids as $id) {
         $pos = strpos($avatar_url, '/' . $id);
         $selected = $pos !== false;
         if ($selected) {
             $found_it = true;
         }
     }
     $hidden = new ocp_tempcode();
     if (has_specific_permission($member_id_viewing, 'own_avatars')) {
         $javascript = 'standardAlternateFields(\'avatar_file\',\'avatar_alt_url\',\'avatar_stock*\',true);';
         $fields->attach(form_input_upload(do_lang_tempcode('UPLOAD'), do_lang_tempcode('DESCRIPTION_UPLOAD'), 'avatar_file', false, NULL, NULL, true, str_replace(' ', '', get_option('valid_images'))));
         handle_max_file_size($hidden, 'image');
         $fields->attach(form_input_line(do_lang_tempcode('ALT_FIELD', do_lang_tempcode('URL')), do_lang_tempcode('DESCRIPTION_ALTERNATE_URL'), 'avatar_alt_url', $found_it ? '' : $avatar_url, false));
         $fields->attach(form_input_picture_choose_specific(do_lang_tempcode('ALT_FIELD', do_lang_tempcode('STOCK')), do_lang_tempcode('DESCRIPTION_ALTERNATE_STOCK'), 'avatar_stock', $ids, $avatar_url, NULL, NULL, true));
     } else {
         $javascript = '';
         $fields->attach(form_input_picture_choose_specific(do_lang_tempcode('STOCK'), '', 'avatar_stock', $ids, $avatar_url, NULL, NULL, true));
     }
     if ($avatar_url != '') {
         if (url_is_local($avatar_url)) {
             $avatar_url = get_complex_base_url($avatar_url) . '/' . $avatar_url;
         }
         $avatar = do_template('OCF_TOPIC_POST_AVATAR', array('_GUID' => '50a5902f3ab7e384d9cf99577b222cc8', 'AVATAR' => $avatar_url));
     } else {
         $avatar = do_lang_tempcode('NONE_EM');
     }
     $width = ocf_get_member_best_group_property($member_id_of, 'max_avatar_width');
     $height = ocf_get_member_best_group_property($member_id_of, 'max_avatar_height');
     $text = do_template('OCF_EDIT_AVATAR_TAB', array('_GUID' => 'dbdac6ca3bc752b54d2a24a4c6e69c7c', 'MEMBER_ID' => strval($member_id_of), 'USERNAME' => $GLOBALS['FORUM_DRIVER']->get_username($member_id_of), 'AVATAR' => $avatar, 'WIDTH' => integer_format($width), 'HEIGHT' => integer_format($height)));
     $hidden = new ocp_tempcode();
     $hidden->attach(form_input_hidden('submitting_avatar_tab', '1'));
     return array($title, $fields, $text, $javascript, $order, $hidden);
 }
Exemplo n.º 20
0
/**
 * Delete a theme image used for a resource that was added, but only if the theme image is now unused.
 *
 * @param  ?ID_TEXT		The new theme image (NULL: no new one)
 * @param  ID_TEXT		The old theme image we might be tidying up
 * @param  ID_TEXT		Table to check against
 * @param  ID_TEXT		Field in table
 * @param  ?object		Database connection to check against (NULL: site database)
 */
function tidy_theme_img_code($new, $old, $table, $field, $db = NULL)
{
    if ($new === $old) {
        return;
    }
    // Still being used
    $path = find_theme_image($old, true, true);
    if (is_null($path) || $path == '') {
        return;
    }
    if (strpos($path, '/images_custom/') !== false && $GLOBALS['SITE_DB']->query_value('theme_images', 'COUNT(DISTINCT id)', array('path' => $path)) == 1) {
        if (is_null($db)) {
            $db = $GLOBALS['SITE_DB'];
        }
        $count = $db->query_value($table, 'COUNT(*)', array($field => $old));
        if ($count == 0) {
            @unlink(get_custom_file_base() . '/' . $path);
            $GLOBALS['SITE_DB']->query_delete('theme_images', array('id' => $old));
        }
    }
}
Exemplo n.º 21
0
 /**
  * The UI to either show an existing ticket and allow a reply, or to start a new ticket.
  *
  * @return tempcode		The UI
  */
 function do_ticket()
 {
     require_lang('comcode');
     $id = get_param('id', NULL);
     if ($id == '') {
         $id = NULL;
     }
     if (!is_null($id)) {
         $_temp = explode('_', $id);
         if (!isset($_temp[1])) {
             warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
         }
         // Normal topic, not a ticket!
         $ticket_owner = intval($_temp[0]);
         $ticket_id = $_temp[1];
         if (is_guest()) {
             access_denied('NOT_AS_GUEST');
         }
         $this->check_id($id);
     } else {
         $ticket_owner = get_member();
         $ticket_id = uniqid('', true);
     }
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('SUPPORT_TICKETS'))));
     $poster = '';
     $new = true;
     $serialized_options = mixed();
     $hash = mixed();
     if (!is_guest() || is_null($id)) {
         $member = get_member();
         $new = is_null($id);
         $num_to_show_limit = get_param_integer('max_comments', intval(get_option('comments_to_show_in_thread')));
         $start = get_param_integer('start_comments', 0);
         if ($new) {
             $id = strval($member) . '_' . $ticket_id;
             $title = get_page_title('ADD_TICKET');
         } else {
             $ticket_type = $GLOBALS['SITE_DB']->query_value_null_ok('tickets', 'ticket_type', array('ticket_id' => $id));
             $ticket_type_text = get_translated_text($ticket_type);
             $ticket_type_details = get_ticket_type($ticket_type);
             $forum = 1;
             $topic_id = 1;
             $_ticket_type = 1;
             // These will be returned by reference
             $_comments = get_ticket_posts($id, $forum, $topic_id, $_ticket_type, $start, $num_to_show_limit);
             $_comments_all = get_ticket_posts($id, $forum, $topic_id, $_ticket_type);
             if (!is_array($_comments) || !array_key_exists(0, $_comments)) {
                 warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
             }
             $ticket_title = $_comments[0]['title'];
             if ($ticket_title == '') {
                 $ticket_title = do_lang('UNKNOWN');
             }
             $title = get_page_title('_VIEW_SUPPORT_TICKET', true, array(escape_html($ticket_title), escape_html($ticket_type_text)));
             breadcrumb_set_self($ticket_title);
         }
         $ticket_page_text = comcode_to_tempcode(get_option('ticket_text'), NULL, true);
         $staff_details = new ocp_tempcode();
         $types = $this->build_types_list(get_param('default', ''));
         $results_browser = NULL;
         if (!$new) {
             require_code('templates_internalise_screen');
             $test_tpl = internalise_own_screen($title, 30, $_comments_all);
             if (is_object($test_tpl)) {
                 return $test_tpl;
             }
             if (is_null($_comments)) {
                 warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
             }
             if (has_specific_permission(get_member(), 'support_operator')) {
                 $staff_details = make_string_tempcode($GLOBALS['FORUM_DRIVER']->topic_url($topic_id, escape_html(get_option('ticket_forum_name'))));
             } else {
                 $staff_details = new ocp_tempcode();
             }
             require_code('topics');
             $renderer = new OCP_Topic();
             $renderer->_inject_posts_for_scoring_algorithm($_comments);
             $renderer->topic_id = $topic_id;
             // Posts
             $max_thread_depth = get_param_integer('max_thread_depth', intval(get_option('max_thread_depth')));
             list($comments, $serialized_options, $hash) = $renderer->render_posts($num_to_show_limit, $max_thread_depth, true, $ticket_owner, array(), $forum);
             // Pagination
             if (!$renderer->is_threaded) {
                 if (count($_comments_all) > $num_to_show_limit) {
                     require_code('templates_results_browser');
                     $results_browser = results_browser(do_lang_tempcode('COMMENTS'), NULL, $start, 'start_comments', $num_to_show_limit, 'max_comments', count($_comments_all), NULL, NULL, true);
                 }
             }
             $GLOBALS['META_DATA'] += array('created' => date('Y-m-d', $_comments[0]['date']), 'creator' => $GLOBALS['FORUM_DRIVER']->get_username($_comments[0]['user']), 'publisher' => '', 'modified' => '', 'type' => 'Support ticket', 'title' => $_comments[0]['title'], 'identifier' => '_SEARCH:tickets:ticket:' . $id, 'description' => '', 'image' => find_theme_image('bigicons/tickets'));
             // "Staff only reply" tickbox
             if (get_forum_type() == 'ocf' && $GLOBALS['FORUM_DRIVER']->is_staff(get_member())) {
                 require_code('form_templates');
                 $staff_only = form_input_tick(do_lang('TICKET_STAFF_ONLY'), do_lang('TICKET_STAFF_ONLY_DESCRIPTION'), 'staff_only', false);
             } else {
                 $staff_only = new ocp_tempcode();
             }
         } else {
             $comments = new ocp_tempcode();
             $staff_only = new ocp_tempcode();
             $ticket_type_details = get_ticket_type(NULL);
         }
         if ($poster == '' || $GLOBALS['FORUM_DRIVER']->get_guest_id() != intval($poster)) {
             $em = $GLOBALS['FORUM_DRIVER']->get_emoticon_chooser();
             require_javascript('javascript_editing');
             require_javascript('javascript_validation');
             require_javascript('javascript_posting');
             require_javascript('javascript_swfupload');
             require_css('swfupload');
             require_code('form_templates');
             list($attachments, $attach_size_field) = get_forum_type() == 'ocf' ? get_attachments('post') : array(NULL, NULL);
             if (addon_installed('captcha')) {
                 require_code('captcha');
                 $use_captcha = get_option('captcha_on_feedback') == '1' && use_captcha();
                 if ($use_captcha) {
                     generate_captcha();
                 }
             } else {
                 $use_captcha = false;
             }
             $comment_form = do_template('COMMENTS_POSTING_FORM', array('_GUID' => 'aaa32620f3eb68d9cc820b18265792d7', 'JOIN_BITS' => '', 'FIRST_POST_URL' => '', 'FIRST_POST' => '', 'USE_CAPTCHA' => $use_captcha, 'ATTACHMENTS' => $attachments, 'ATTACH_SIZE_FIELD' => $attach_size_field, 'POST_WARNING' => '', 'COMMENT_TEXT' => '', 'GET_EMAIL' => is_guest(), 'EMAIL_OPTIONAL' => is_guest() && $ticket_type_details['guest_emails_mandatory'], 'GET_TITLE' => true, 'EM' => $em, 'DISPLAY' => 'block', 'COMMENT_URL' => '', 'SUBMIT_NAME' => do_lang_tempcode('MAKE_POST'), 'TITLE' => do_lang_tempcode($new ? 'CREATE_TICKET_MAKE_POST' : 'MAKE_POST')));
         } else {
             $comment_form = new ocp_tempcode();
         }
         $post_url = build_url(array('page' => '_SELF', 'id' => $id, 'type' => 'post', 'redirect' => get_param('redirect', NULL)), '_SELF');
         require_code('form_templates');
         require_code('feedback');
         list($warning_details, $ping_url) = handle_conflict_resolution(NULL, true);
         $other_tickets = new ocp_tempcode();
         $our_topic = NULL;
         if (!is_guest($ticket_owner)) {
             $tickets_of_member = get_tickets($ticket_owner, NULL, true);
             if (!is_null($tickets_of_member)) {
                 foreach ($tickets_of_member as $topic) {
                     $ticket_id = extract_topic_identifier($topic['description']);
                     if ($id != $ticket_id) {
                         $url = build_url(array('page' => '_SELF', 'type' => 'ticket', 'id' => $ticket_id), '_SELF');
                         $_title = $topic['firsttitle'];
                         $date = get_timezoned_date($topic['lasttime']);
                         $ticket_owner_name = $GLOBALS['FORUM_DRIVER']->get_username($ticket_owner);
                         if (is_null($ticket_owner_name)) {
                             $profile_link = '';
                         } else {
                             $profile_link = $GLOBALS['FORUM_DRIVER']->member_profile_url($ticket_owner, false, true);
                         }
                         $last_poster = $topic['lastusername'];
                         $unclosed = !$GLOBALS['FORUM_DRIVER']->is_staff($topic['lastmemberid']);
                         $params = array('NUM_POSTS' => integer_format($topic['num'] - 1), 'CLOSED' => strval($topic['closed']), 'URL' => $url, 'TITLE' => $_title, 'DATE' => $date, 'DATE_RAW' => strval($topic['lasttime']), 'PROFILE_LINK' => $profile_link, 'LAST_POSTER' => $last_poster, 'UNCLOSED' => $unclosed);
                         $other_tickets->attach(do_template('SUPPORT_TICKET_LINK', $params));
                     } else {
                         $our_topic = $topic;
                     }
                 }
             }
         }
         $toggle_ticket_closed_url = NULL;
         if (get_forum_type() == 'ocf' && !$new) {
             $toggle_ticket_closed_url = build_url(array('page' => '_SELF', 'type' => 'toggle_ticket_closed', 'id' => $id), '_SELF');
         }
         $map = array('page' => '_SELF', 'type' => 'ticket');
         if (get_param('default', '') != '') {
             $map['default'] = get_param('default');
         }
         $add_ticket_url = build_url($map, '_SELF');
         return do_template('SUPPORT_TICKET_SCREEN', array('_GUID' => 'd21a9d161008c6c44fe7309a14be2c5b', 'SERIALIZED_OPTIONS' => $serialized_options, 'HASH' => $hash, 'TOGGLE_TICKET_CLOSED_URL' => $toggle_ticket_closed_url, 'CLOSED' => is_null($our_topic) ? '0' : strval($our_topic['closed']), 'OTHER_TICKETS' => $other_tickets, 'USERNAME' => $GLOBALS['FORUM_DRIVER']->get_username($ticket_owner), 'PING_URL' => $ping_url, 'WARNING_DETAILS' => $warning_details, 'NEW' => $new, 'TICKET_PAGE_TEXT' => $ticket_page_text, 'TYPES' => $types, 'STAFF_ONLY' => $staff_only, 'POSTER' => $poster, 'TITLE' => $title, 'COMMENTS' => $comments, 'COMMENT_FORM' => $comment_form, 'STAFF_DETAILS' => $staff_details, 'URL' => $post_url, 'ADD_TICKET_URL' => $add_ticket_url, 'RESULTS_BROWSER' => $results_browser));
     } else {
         return inform_screen(get_page_title('ADD_TICKET'), do_lang_tempcode('SUCCESS'));
     }
 }
Exemplo n.º 22
0
 /**
  * The actualiser for super debranding.
  *
  * @return tempcode		The UI
  */
 function actual()
 {
     require_code('config2');
     if (get_file_base() == get_custom_file_base()) {
         require_code('abstract_file_manager');
         force_have_afm_details();
     }
     set_value('rebrand_name', post_param('rebrand_name'));
     set_value('rebrand_base_url', post_param('rebrand_base_url'));
     set_value('company_name', post_param('company_name'));
     set_option('show_docs', post_param('show_docs', '0'));
     require_code('database_action');
     //set_option('allow_member_integration','off');
     foreach (array(get_file_base() . '/pages/comcode_custom/' . get_site_default_lang(), get_file_base() . '/adminzone/pages/comcode_custom/' . get_site_default_lang()) as $dir) {
         if (!file_exists($dir)) {
             require_code('files');
             if (@mkdir($dir, 0777) === false) {
                 warn_exit(do_lang_tempcode('WRITE_ERROR_DIRECTORY_REPAIR', escape_html($dir)));
             }
             fix_permissions($dir, 0777);
             sync_file($dir);
         }
     }
     $keyboard_map_path = get_file_base() . '/pages/comcode_custom/' . get_site_default_lang() . '/keymap.txt';
     $myfile = @fopen($keyboard_map_path, 'wb');
     if ($myfile === false) {
         intelligent_write_error($keyboard_map_path);
     }
     $km = post_param('keyboard_map');
     if (fwrite($myfile, $km) < strlen($km)) {
         warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
     }
     fclose($myfile);
     fix_permissions($keyboard_map_path);
     sync_file($keyboard_map_path);
     $adminguide_path = get_file_base() . '/adminzone/pages/comcode_custom/' . get_site_default_lang() . '/website.txt';
     $adminguide = post_param('adminguide');
     $adminguide = str_replace('__company__', post_param('company_name'), $adminguide);
     $myfile = @fopen($adminguide_path, 'wb');
     if ($myfile === false) {
         intelligent_write_error($adminguide_path);
     }
     if (fwrite($myfile, $adminguide) < strlen($adminguide)) {
         warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
     }
     fclose($myfile);
     fix_permissions($adminguide_path);
     sync_file($adminguide_path);
     $start_path = get_file_base() . '/adminzone/pages/comcode_custom/' . get_site_default_lang() . '/start.txt';
     if (!file_exists($start_path)) {
         $start = post_param('start_page');
         $myfile = @fopen($start_path, 'wb');
         if ($myfile === false) {
             intelligent_write_error($start_path);
         }
         if (fwrite($myfile, $start) < strlen($start)) {
             warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
         }
         fclose($myfile);
         fix_permissions($start_path);
         sync_file($start_path);
     }
     if (get_file_base() == get_custom_file_base()) {
         $critical_errors = file_get_contents(get_file_base() . '/sources/critical_errors.php');
         $critical_errors = str_replace('ocPortal', post_param('rebrand_name'), $critical_errors);
         $critical_errors = str_replace('http://ocportal.com', post_param('rebrand_base_url'), $critical_errors);
         $critical_errors = str_replace('ocProducts', 'ocProducts/' . post_param('company_name'), $critical_errors);
         $critical_errors_path = 'sources_custom/critical_errors.php';
         afm_make_file($critical_errors_path, $critical_errors, false);
     }
     $save_header_path = get_file_base() . '/themes/' . $GLOBALS['FORUM_DRIVER']->get_theme() . '/templates_custom/HEADER.tpl';
     $header_path = $save_header_path;
     if (!file_exists($header_path)) {
         $header_path = get_file_base() . '/themes/default/templates/HEADER.tpl';
     }
     $header_tpl = file_get_contents($header_path);
     $header_tpl = str_replace('Copyright ocProducts Limited', '', $header_tpl);
     $myfile = @fopen($save_header_path, 'wb');
     if ($myfile === false) {
         intelligent_write_error($save_header_path);
     }
     if (fwrite($myfile, $header_tpl) < strlen($header_tpl)) {
         warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
     }
     fclose($myfile);
     fix_permissions($save_header_path);
     sync_file($save_header_path);
     if (post_param_integer('churchy', 0) == 1) {
         if (is_object($GLOBALS['FORUM_DB'])) {
             $GLOBALS['FORUM_DB']->query_delete('f_emoticons', array('e_code' => ':devil:'), '', 1);
         } else {
             $GLOBALS['SITE_DB']->query_delete('f_emoticons', array('e_code' => ':devil:'), '', 1);
         }
     }
     // Make sure some stuff is disabled for non-admin staff
     $staff_groups = $GLOBALS['FORUM_DRIVER']->get_moderator_groups();
     $disallowed_pages = array('admin_setupwizard', 'admin_addons', 'admin_backup', 'admin_errorlog', 'admin_import', 'admin_occle', 'admin_phpinfo', 'admin_debrand');
     foreach (array_keys($staff_groups) as $id) {
         foreach ($disallowed_pages as $page) {
             $GLOBALS['SITE_DB']->query_delete('group_page_access', array('page_name' => $page, 'zone_name' => 'adminzone', 'group_id' => $id), '', 1);
             // in case already exists
             $GLOBALS['SITE_DB']->query_insert('group_page_access', array('page_name' => $page, 'zone_name' => 'adminzone', 'group_id' => $id));
         }
     }
     // Clean up the theme images
     //  background-image
     $theme = $GLOBALS['FORUM_DRIVER']->get_theme();
     find_theme_image('background_image');
     //$GLOBALS['SITE_DB']->query_update('theme_images',array('path'=>'themes/default/images/blank.gif'),array('id'=>'background-image','theme'=>$theme),'',1); No longer ocp-specific
     //  logo/*
     if (addon_installed('zone_logos')) {
         find_theme_image('logo/adminzone-logo');
         find_theme_image('logo/cms-logo');
         find_theme_image('logo/collaboration-logo');
         $main_logo_url = find_theme_image('logo/-logo', false, true);
         $GLOBALS['SITE_DB']->query_update('theme_images', array('path' => $main_logo_url), array('id' => 'logo/adminzone-logo', 'theme' => $theme), '', 1);
         $GLOBALS['SITE_DB']->query_update('theme_images', array('path' => $main_logo_url), array('id' => 'logo/cms-logo', 'theme' => $theme), '', 1);
         $GLOBALS['SITE_DB']->query_update('theme_images', array('path' => $main_logo_url), array('id' => 'logo/collaboration-logo', 'theme' => $theme), '', 1);
     }
     // Various other icons
     require_code('uploads');
     $path = get_url('', 'favicon', 'themes/default/images_custom');
     if ($path[0] != '') {
         $GLOBALS['SITE_DB']->query_update('theme_images', array('path' => $path[0]), array('id' => 'favicon'));
     }
     $path = get_url('', 'appleicon', 'themes/default/images_custom');
     if ($path[0] != '') {
         $GLOBALS['SITE_DB']->query_update('theme_images', array('path' => $path[0]), array('id' => 'appleicon'));
     }
     if (addon_installed('ocf_avatars')) {
         $path = get_url('', 'system_avatar', 'themes/default/images_custom');
         if ($path[0] != '') {
             $GLOBALS['SITE_DB']->query_update('theme_images', array('path' => $path[0]), array('id' => 'ocf_default_avatars/default_set/ocp_fanatic'));
         }
     }
     $title = get_page_title('SUPER_DEBRAND');
     // Redirect them back to editing screen
     $url = build_url(array('page' => '_SELF', 'type' => 'misc'), '_SELF');
     return redirect_screen($title, $url, do_lang_tempcode('SUCCESS'));
 }
     if (substr($expression, -1) == '*') {
         $expression = substr($expression, 0, strlen($expression) - 2);
         // remove "/*"
         $full_img_set = array_merge($full_img_set, array_keys(get_all_image_codes(get_file_base() . '/' . filter_naughty('default') . '/default/images', $expression)));
         $full_img_set = array_merge($full_img_set, array_keys(get_all_image_codes(get_file_base() . '/themes/' . filter_naughty('default') . '/images/' . fallback_lang(), $expression)));
     } else {
         $full_img_set[] = $expression;
     }
 }
 $temp_all_ids = collapse_2d_complexity('id', 'path', $GLOBALS['SITE_DB']->query_select('theme_images', array('id', 'path'), array('theme' => $theme)));
 foreach ($full_img_set as $image_code) {
     if (!in_array($image_code, $THEME_WIZARD_IMAGES_NO_WILD)) {
         if (array_key_exists($image_code, $temp_all_ids) && strpos($temp_all_ids[$image_code], $theme . '/images_custom/') !== false && (!url_is_local($temp_all_ids[$image_code]) || file_exists(get_custom_file_base() . '/' . $temp_all_ids[$image_code]))) {
             continue;
         }
         $orig_path = find_theme_image($image_code, true, true, 'default', 'EN');
         if ($orig_path == '') {
             continue;
         }
         // Theme has specified non-existent image as themewizard-compatible
         if (strpos($orig_path, '/' . fallback_lang() . '/') !== false) {
             $composite = 'themes/' . filter_naughty($theme) . '/images/EN/';
         } else {
             $composite = 'themes/' . filter_naughty($theme) . '/images/';
         }
         afm_make_directory($composite, true);
         $saveat = get_custom_file_base() . '/' . $composite . $image_code . '.png';
         $saveat_url = $composite . $image_code . '.png';
         if (!file_exists($saveat)) {
             $image = calculate_theme($seed, 'default', 'equations', $image_code, $dark, $theme_map, $theme_landscape, 'EN');
             if (!is_null($image)) {
Exemplo n.º 24
0
/**
 * Convert Semi-HTML into comcode. Cleanup where possible
 *
 * @param  LONG_TEXT		The Semi-HTML to converted
 * @param  boolean		Whether to force full conversion regardless of settings
 * @return LONG_TEXT		The equivalent comcode
 */
function semihtml_to_comcode($semihtml, $force = false)
{
    require_code('obfuscate');
    $semihtml = trim($semihtml);
    @ini_set('pcre.backtrack_limit', '10000000');
    do {
        $semihtml_before = $semihtml;
        $semihtml = preg_replace_callback('#<input [^>]*class="ocp_keep_ui_controlled" [^>]*title="([^"]*)" [^>]*type="text" [^>]*value="[^"]*"[^>]*/?' . '>#siU', 'debuttonise', $semihtml_before);
    } while ($semihtml != $semihtml_before);
    $array_html_preg_replace = array();
    $semihtml = str_replace('&#8203;', '', $semihtml);
    if (strtolower(get_charset()) == 'utf-8') {
        $semihtml = str_replace(chr(hexdec('e2')) . chr(hexdec('80')) . chr(hexdec('8b')), '', $semihtml);
    }
    $array_html_preg_replace[] = array('#^<kbd class="(ocp_keep|ocp_keep_block)"[^>]*>(.*)</kbd>$#siU', "\${2}");
    $semihtml = array_html_preg_replace('kbd', $array_html_preg_replace, $semihtml);
    $semihtml = str_replace('<!-- >', '', $semihtml);
    $semihtml = preg_replace('#<span id="cke_bm_[^"]+" style="display: none;\\s*">&nbsp;</span>#', '', $semihtml);
    require_code('xhtml');
    $semihtml = xhtmlise_html($semihtml, true);
    // Needed so we can parse it right
    $semihtml = preg_replace('#(\\[[\\w\\_]+)&nbsp;#', '${1} ', $semihtml);
    $matches = array();
    if (!$force && (get_option('eager_wysiwyg') == '0' && (substr_count($semihtml, '://') <= preg_match_all('#(href|src)="[^"]*://[^"]*"#', $semihtml, $matches) || count(find_all_hooks('systems', 'comcode_link_handlers')) == 0) && has_specific_permission(get_member(), 'allow_html')) || strpos($semihtml, '{$,page hint: no_smart_conversion}') !== false) {
        $semihtml = preg_replace_callback('#<img([^>]*) src="([^"]*)"([^>]*) />#siU', '_img_tag_fixup_raw', $semihtml);
        // Resolve relative URLs
        $semihtml = preg_replace_callback('#<img([^>]*) src="([^"]*)"([^>]*)>#siU', '_img_tag_fixup_raw', $semihtml);
        // Resolve relative URLs
        if (strpos($semihtml, 'data:') === false) {
            $count = substr_count($semihtml, '[/') + substr_count($semihtml, '{') + substr_count($semihtml, '[[') + substr_count($semihtml, '<h1');
            if ($count == 0 && strpos($semihtml, '<h1') === false) {
                return $semihtml == '' ? '' : '[html]' . $semihtml . '[/html]';
            }
            $count2 = substr_count($semihtml, '[/attachment]') + substr_count($semihtml, '<h1');
            if ($count2 == $count) {
                if ($semihtml != '') {
                    $semihtml = '[html]' . $semihtml . '[/html]';
                }
                $semihtml = preg_replace('#<h1[^>]*>\\s*<span class="inner">(.*)</span>\\s*</h1>#Us', '[/html][semihtml][title]${1}[/title][/semihtml][html]', $semihtml);
                $semihtml = preg_replace('#<h1[^>]*>(.*)</h1>#Us', '[/html][semihtml][title]${1}[/title][/semihtml][html]', $semihtml);
                $semihtml = str_replace('[attachment', '[/html][semihtml][attachment', str_replace('[/attachment]', '[/attachment][/semihtml][html]', $semihtml));
                $semihtml = str_replace('[/html][html]', '', $semihtml);
                $semihtml = str_replace('[html][/html]', '', $semihtml);
                return $semihtml;
            }
        }
        if ($semihtml != '') {
            $semihtml = '[semihtml]' . $semihtml . '[/semihtml]';
        }
        $semihtml = preg_replace('#<h1[^>]*>\\s*<span class="inner">(.*)</span>\\s*</h1>#Us', '[title]${1}[/title]', $semihtml);
        $semihtml = preg_replace('#<h1[^>]*>(.*)</h1>#Us', '[title]${1}[/title]', $semihtml);
        return $semihtml;
    }
    // Safety from if these are typed in (could cause problems)
    $semihtml = str_replace('[html', '[ html', $semihtml);
    $semihtml = str_replace('[semihtml', '[ semihtml', $semihtml);
    $semihtml = str_replace('[/html', '[ / html', $semihtml);
    $semihtml = str_replace('[/semihtml', '[ / semihtml', $semihtml);
    // Try and retain image attachments
    $semihtml = preg_replace('#<script[^>]*>(//\\s*<!\\[CDATA\\[)?(<!--)?\\s*var te_[\\d\\w\\-]*="[^"]*&for\\_session=[^"]*";\\s*(//\\]\\]>)?(-->)?</script>#', '', $semihtml);
    foreach (array('&amp;thumb=0[^"]*' => ' thumb="0"', '&amp;thumb=1[^"]*' => ' thumb="1"', '' => '') as $thumb_bit => $comcode_to) {
        $semihtml = preg_replace('#<div [^>]*class="attachment_left"[^>]*>\\s*<img src="[^"]*?id=(\\d+)[^"]*' . $thumb_bit . '(&amp;for_session=[\\w\\d]+)?" /></div>#i', '[attachment_safe' . $comcode_to . ' type="inline_left"]${1}[/attachment_safe]', $semihtml);
        $semihtml = preg_replace('#<div [^>]*class="attachment_right"[^>]*>\\s*<img src="[^"]*?id=(\\d+)[^"]*' . $thumb_bit . '(&amp;for_session=[\\w\\d]+)?" /></div>#i', '[attachment_safe' . $comcode_to . ' type="inline_right"]${1}[/attachment_safe]', $semihtml);
        $regexp = '#';
        $regexp .= $comcode_to == ' thumb="1"' ? '(<a [^>]*>)?\\s*' : '()';
        $regexp .= '<img [^>]*[^>]*src="[^"]*?id=(\\d+)[^"]*' . $thumb_bit . '(&amp;for_session=[\\w\\d]+)?" [^>]*title="([^"]*)" [^>]*/?' . '>\\s*';
        $regexp .= $comcode_to == ' thumb="1"' ? '(</a>)?' : '()';
        $regexp .= '#i';
        $semihtml = preg_replace($regexp, '[attachment_safe' . $comcode_to . ' type="inline" description="${4}"]${2}[/attachment_safe]', $semihtml);
    }
    $semihtml = preg_replace('#&amp;keep_session=[\\d]*(&amp;for_session=[\\w\\d]*)?#', '', $semihtml);
    // This is useful for generally stripping sensitive information anyway. Should be null-op if anti-leech was on, but worth doing just-in-case.
    // We must protect anything that is in CDATA from whitespace/entity cleanup (HTML or XHTML - we have to use lowest common denominator)
    $semihtml = preg_replace_callback('#(<script[^>]*>)(.*)(</script>)#siU', '_cdata_protect', $semihtml);
    $semihtml = preg_replace_callback('#(<style[^>]*>)(.*)(</style>)#siU', '_cdata_protect', $semihtml);
    $semihtml = preg_replace_callback('#(<textarea[^>]*>)(.*)(</textarea>)#siU', '_cdata_protect', $semihtml);
    $semihtml = preg_replace_callback('#(<pre[^>]*>)(.*)(</pre>)#siU', '_cdata_protect', $semihtml);
    $semihtml = preg_replace_callback('#(<![CDATA[)(.*)(]]>)#siU', '_cdata_protect', $semihtml);
    // And use same method to protect our code tags
    /*	foreach (array_keys($GLOBALS['CODE_TAGS']) as $code_tag)
    		$semihtml=preg_replace_callback('#(\['.$code_tag.'[^\]]*\])(.*)(\[/'.$code_tag.'\])#siU','_codetag_protect',$semihtml);
    Actually no, we don't want this. These tags are typed potentially to show HTML and thus the entities must get decoded
    */
    // Cleanup from certain word processors
    // LibreOffice
    $semihtml = str_replace('<h2 class="western">', '<h2>', $semihtml);
    $semihtml = preg_replace('#</(ul|ol|h1|h2|h3|h4|h5|h6)>\\s*<p style="margin-bottom: 0(cm|em|px)?">\\s*&nbsp;\\s*</p>\\s*#Us', '</${1}>', $semihtml);
    $semihtml = preg_replace('#<p style="margin-bottom: 0(cm|em|px)?">\\s*&nbsp;\\s*</p>\\s*#Us', '', $semihtml);
    $semihtml = preg_replace('#<li>\\s*<p style="margin-bottom: 0(cm|em|px)?">(.*)</p>\\s*</li>#Us', '<li>${2}</li>', $semihtml);
    $semihtml = preg_replace('#<p style="margin-bottom: 0(cm|em|px)?">(.*)</p>\\s*<(ul|ol|h1|h2|h3|h4|h5|h6)>#Us', '${2}<${3}>', $semihtml);
    $semihtml = str_replace('<p style="margin-bottom: 0cm">', '<p>', $semihtml);
    $semihtml = preg_replace('#(<style[^>]*>)(.*)(</style>)#siU', '', $semihtml);
    // We shouldn't allow this nested anyway (invalid XHTML), and word abuses it
    $semihtml = preg_replace('#<span class="Apple-style-span"[^>]*>(.*)</span>#siU', '${1}', $semihtml);
    // webkit
    $semihtml = preg_replace('#<meta[^>]*>#siU', '', $semihtml);
    // We shouldn't allow this nested anyway (invalid XHTML), and word abuses it
    $semihtml = preg_replace('#(<[^>]*) lang="[^"]*"#i', '${1}', $semihtml);
    $semihtml = preg_replace('#(<[^>]*) style="margin-right: 0\\w*;?"#i', '${1}', $semihtml);
    $semihtml = preg_replace('#(<[^>]*) dir="' . do_lang('dir') . '"#i', '${1}', $semihtml);
    $semihtml = preg_replace_callback('#<[^>"]* style="([^">]*&quot;[^">]*)*"#i', '_css_quot_fixup', $semihtml);
    $semihtml = preg_replace('#<a name="OLE_LINK1">([^<]*)</a>#siU', '${1}', $semihtml);
    $semihtml = preg_replace('#(<[^>]* align="right"[^>]*) style="(margin-right: [\\d\\.]+pt;\\s*)?text-align: right;?"#is', '${1}', $semihtml);
    // trim off redundancy
    $semihtml = preg_replace('#(<[^>]* align="center"[^>]*) style="(margin-right: [\\d\\.]+pt;\\s*)?text-align: center;?"#is', '${1}', $semihtml);
    // trim off redundancy
    $semihtml = preg_replace('#(?U)(<[^>]* style="[^"]*)(?-U);?\\s*page-break-after: avoid;?"#is', '${1}"', $semihtml);
    $semihtml = str_replace('<place>', '', $semihtml);
    $semihtml = str_replace('</place>', '', $semihtml);
    $semihtml = preg_replace('#<link [^>]*href="file://[^"]*"[^>]*/>#sU', '', $semihtml);
    $semihtml = preg_replace('#<!--\\[if(.*)-->#sU', '', $semihtml);
    $semihtml = preg_replace('#<!--(.*)\\[endif(.*)-->#sU', '', $semihtml);
    $semihtml = str_replace('<!-- >', '', $semihtml);
    $semihtml = preg_replace('#</?[ovw]:[^>]*>#s', '', $semihtml);
    $semihtml = preg_replace('#(<[^>]*) [ovw]:[^>"]*"[^"]*"([^>]*>)#s', '${1}${2}', $semihtml);
    $semihtml = preg_replace('#</?st1:[^>]*>#', '', $semihtml);
    // Word smart tags
    $semihtml = str_replace('<br class="Apple-interchange-newline" />', '<br />', $semihtml);
    $semihtml = str_replace(chr(10), ' ', $semihtml);
    // Clean some whitespace (they have a special Comcode meaning, but no special HTML meaning)
    $inline_elements = array('font', 's', 'u', 'strike', 'span', 'abbr', 'acronym', 'cite', 'code', 'dfn', 'em', 'strong', 'kbd', 'q', 'samp', 'var', 'sub', 'sup', 'tt', 'del', 'ruby', 'a', 'bdo', 'img', 'ins', 'param', 'textarea', 'button', 'input', 'select', 'object', 'caption', 'label', 'b', 'i', 'small', 'big');
    $semihtml = preg_replace('#(<(' . implode('|', $inline_elements) . ')( [^>]*)?' . '>)\\s+#', '${1}</CDATA__space>', $semihtml);
    $semihtml = preg_replace('#\\s+(</(' . implode('|', $inline_elements) . ')>)#', '</CDATA__space>${1}', $semihtml);
    $semihtml = preg_replace('#([^\\>\\s])\\s+(<(' . implode('|', $inline_elements) . ')( [^>]*)?' . '>)#', '${1}</CDATA__space>${2}', $semihtml);
    $semihtml = preg_replace('#(</(' . implode('|', $inline_elements) . ')>)\\s+#', '${1}</CDATA__space>', $semihtml);
    $semihtml = preg_replace('#>\\s+#', '>', $semihtml);
    $semihtml = preg_replace('#\\s+<#', '<', $semihtml);
    $semihtml = preg_replace('#\\s+#', ' ', $semihtml);
    // Cleanup impossible stuff in code tags
    global $CODE_TAGS;
    foreach (array_keys($CODE_TAGS) as $tag) {
        $semihtml = comcode_preg_replace($tag, '#^(\\[' . $tag . '\\])(.*)(\\[/' . $tag . '\\])$#si', array('comcode_strip_html_tags'), $semihtml);
    }
    // Cleanup how blocks are converted into a line break model. We need to clean up the case where inline leads onto block, by adding a linebreak inbetween. Note that this kind of break does not go *between* blocks, which is the reason we can't arbitrarily place it later on.
    $semihtml = preg_replace('#([^\\s<>]|</(' . implode('|', $inline_elements) . ')>)(<(div|p))#', '${1}<br />${3}', $semihtml);
    // Reorder XHTML attributes alphabetically, so our regexp's match better
    $semihtml = preg_replace_callback('#<([^>\\s]+)\\s([^>]+)>#', '_reorder_xhtml_attributes', $semihtml);
    // Reorder style properties alphabetically, so our regexp's match better
    $semihtml = preg_replace_callback('#(<[^>]*style=")([^"]*)("[^>]*>)#', '_reorder_css_properties', $semihtml);
    $semihtml = str_replace('<p  />', '<br /><br />', str_replace('<p />', '<br /><br />', $semihtml));
    // Remove proprietary stylings put in by RTF->HTML conversions performed by certain browsers
    $old_semihtml = '';
    do {
        $old_semihtml = $semihtml;
        $semihtml = preg_replace('#(<[^>]* style="(?U)[^">]*(?-U))-\\w+-[^";>]*(;\\s*)?#s', '${1}', $semihtml);
    } while ($semihtml != $old_semihtml);
    // Perform lots of conversions. We can't convert everything. Sometimes we reverse-convert what Comcode forward-converts; sometimes we match generic HTML; sometimes we match Microsoft Word or Open Office; sometimes we do lossy match
    $array_html_preg_replace = array();
    $array_html_preg_replace[] = array('#^<h1 id="screen_title">\\s*<span class="inner">(.*)</span>\\s*</h1>$#siU', '[title="1"]${1}[/title]');
    $array_html_preg_replace[] = array('#^<h1 class="screen_title">\\s*<span class="inner">(.*)</span>\\s*</h1>$#siU', '[title="1"]${1}[/title]');
    $array_html_preg_replace[] = array('#^<h1 id="screen_title" class="screen_title">\\s*<span class="inner">(.*)</span>\\s*</h1>$#siU', '[title="1"]${1}[/title]');
    $array_html_preg_replace[] = array('#^<h1 id="screen_title">(.*)</h1>$#siU', '[title="1"]${1}[/title]');
    $array_html_preg_replace[] = array('#^<h1 class="screen_title">(.*)</h1>$#siU', '[title="1"]${1}[/title]');
    $array_html_preg_replace[] = array('#^<h1 id="screen_title" class="screen_title">(.*)</h1>$#siU', '[title="1"]${1}[/title]');
    $array_html_preg_replace[] = array('#^<h1>(.*)</h1>$#siU', '[title="1"]${1}[/title]');
    $semihtml = array_html_preg_replace('h1', $array_html_preg_replace, $semihtml);
    $semihtml = preg_replace('#^\\s*<h1[^>]+>(.*)</h1>#siU', '[title="1"]${1}[/title]', $semihtml);
    for ($i = 2; $i <= 4; $i++) {
        $array_html_preg_replace = array();
        $array_html_preg_replace[] = array('#^<h' . strval($i) . '><span class="inner">(.*)</span></h' . strval($i) . '>$#siU', '[title="' . strval($i) . '"]${1}[/title]');
        $array_html_preg_replace[] = array('#^<h' . strval($i) . '>(.*)</h' . strval($i) . '>$#siU', '[title="' . strval($i) . '"]${1}[/title]');
        $semihtml = array_html_preg_replace('h' . strval($i) . '', $array_html_preg_replace, $semihtml);
    }
    $array_html_preg_replace = array();
    $array_html_preg_replace[] = array('#^<h1 id="screen_title"[^<>]*><span class="inner">(.*)</span></h1>$#siU', '[title="1"]${1}[/title]');
    $array_html_preg_replace[] = array('#^<h1 class="screen_title"[^<>]*><span class="inner">(.*)</span></h1>$#siU', '[title="1"]${1}[/title]');
    $array_html_preg_replace[] = array('#^<h1 id="screen_title" class="screen_title"><span class="inner">(.*)</span></h1>$#siU', '[title="1"]${1}[/title]');
    $array_html_preg_replace[] = array('#^<h1 id="screen_title"[^<>]*>(.*)</h1>$#siU', '[title="1"]${1}[/title]');
    $array_html_preg_replace[] = array('#^<h1 class="screen_title"[^<>]*>(.*)</h1>$#siU', '[title="1"]${1}[/title]');
    $array_html_preg_replace[] = array('#^<h1 id="screen_title" class="screen_title"[^<>]*>(.*)</h1>$#siU', '[title="1"]${1}[/title]');
    $semihtml = array_html_preg_replace('h1', $array_html_preg_replace, $semihtml);
    $semihtml = preg_replace('#^\\s*<h1[^>]+>(.*)</h1>#siU', '[title="1"]${1}[/title]', $semihtml);
    for ($i = 2; $i <= 4; $i++) {
        $array_html_preg_replace = array();
        $array_html_preg_replace[] = array('#^<h' . strval($i) . '><span class="inner">(.*)</span></h' . strval($i) . '>$#siU', '[title="' . strval($i) . '"]${1}[/title]');
        $array_html_preg_replace[] = array('#^<h' . strval($i) . '>(.*)</h' . strval($i) . '>$#siU', '[title="' . strval($i) . '"]${1}[/title]');
        $semihtml = array_html_preg_replace('h' . strval($i), $array_html_preg_replace, $semihtml);
    }
    $array_html_preg_replace = array();
    $array_html_preg_replace[] = array('#^<span>(.*)</span>$#siU', '${1}');
    $array_html_preg_replace[] = array('#^<span( charset="[^"]*")?( content="[^"]*")?( name="[^"]*")?' . '>(.*)</span>$#siU', '${4}');
    $array_html_preg_replace[] = array('#^<span style="\\s*?font-family:\\s*monospace;\\s*?font-size:\\s*[\\d\\.]*em;?">(.*)</span>$#siU', '[tt]${1}[/tt]');
    $array_html_preg_replace[] = array('#^<span style="\\s*?font-weight:\\s*bold;?">(.*)</span>$#siU', '[b]${1}[/b]');
    $array_html_preg_replace[] = array('#^<span style="\\s*?font-style:\\s*italic;?">(.*)</span>$#siU', '[i]${1}[/i]');
    $array_html_preg_replace[] = array('#^<span style="\\s*?text-decoration:\\s*underline;?">(.*)</span>$#siU', '[u]${1}[/u]');
    $array_html_preg_replace[] = array('#^<span( href="[^"]*")?( rel="[^"]*")?' . '>(.*)</span>$#siU', '${3}');
    $array_html_preg_replace[] = array('#^<span style="\\s*?font-weight:\\s*bold;?">(.*)</span>$#siU', '[b]${1}[/b]');
    $array_html_preg_replace[] = array('#^<span style="\\s*?font-style:\\s*italic;?">(.*)</span>$#siU', '[i]${1}[/i]');
    $array_html_preg_replace[] = array('#^<span style="\\s*?text-decoration:\\s*underline;?">(.*)</span>$#siU', '[u]${1}[/u]');
    $array_html_preg_replace[] = array('#^<span style="\\s*?color:\\s*?([^";]+);\\s*?font-family:\\s*?([^";]+);\\s*?font-size:\\s*?([^";]+);?"([^>]*)>(.*)</span>$#siU', '[font param="${2}" color="${1}" size="${3}"]${5}[/font]');
    $array_html_preg_replace[] = array('#^<span style="\\s*?color:\\s*?([^";]+);\\s*?font-size:\\s*?([^";]+);?"([^>]*)>(.*)</span>$#siU', '[font color="${1}" size="${2}"]${4}[/font]');
    $array_html_preg_replace[] = array('#^<span style="\\s*?color:\\s*?([^";]+);\\s*?font-family:\\s*?([^";]+);?"([^>]*)>(.*)</span>$#siU', '[font param="${2}" color="${1}"]${4}[/font]');
    $array_html_preg_replace[] = array('#^<span style="\\s*?color:\\s*?([^";]+);?\\s*?"([^>]*)>(.*)</span>$#siU', '[font color="${1}"]${3}[/font]');
    $array_html_preg_replace[] = array('#^<span style="\\s*?font-family:\\s*?([^";]+);\\s*?font-size:\\s*?([^";]+);?"([^>]*)>(.*)</span>$#siU', '[font param="${1}" size="${2}"]${4}[/font]');
    $array_html_preg_replace[] = array('#^<span style="\\s*?font-size:\\s*?([0-9\\.]+\\w\\w);?\\s*?"([^>]*)>(.*)</span>$#siU', '[font size="${1}"]${3}[/font]');
    $array_html_preg_replace[] = array('#^<span style="\\s*?font-family:\\s*?([^";]+);?\\s*?"([^>]*)>(.*)</span>$#siU', '[font param="${1}"]${3}[/font]');
    $complex_equivs = array('<span class="comcode_highlight">(.*)</span>' => 'highlight', '<span class="comcode_bold">(.*)</span>' => 'b', '<span class="comcode_italic">(.*)</span>' => 'i', '<span class="comcode_underline">(.*)</span>' => 'u');
    foreach ($complex_equivs as $from => $to) {
        $array_html_preg_replace[] = array('#^' . $from . '$#siU', '[' . $to . ']${1}[/' . $to . ']');
    }
    $semihtml = array_html_preg_replace('span', $array_html_preg_replace, $semihtml);
    $_array_html_preg_replace = array();
    foreach ($array_html_preg_replace as $i => $x) {
        $_array_html_preg_replace[$i] = array();
        $_array_html_preg_replace[$i][0] = str_replace('span', 'div', $x[0]);
        $_array_html_preg_replace[$i][1] = '<div>' . $x[1] . '</div>';
    }
    $semihtml = array_html_preg_replace('div', $_array_html_preg_replace, $semihtml);
    $_array_html_preg_replace = array();
    foreach ($array_html_preg_replace as $i => $x) {
        $_array_html_preg_replace[$i] = array();
        $_array_html_preg_replace[$i][0] = str_replace('div', 'p', $x[0]);
        $_array_html_preg_replace[$i][1] = '<p>' . $x[1] . '</p>';
    }
    $semihtml = array_html_preg_replace('p', $_array_html_preg_replace, $semihtml);
    $array_html_preg_replace = array();
    $array_html_preg_replace[] = array('#^<font>(.*)</font>$#siU', '${1}');
    $array_html_preg_replace[] = array('#^<font ([^>]*)size="(\\d+)"([^>]*)>(.*)</font>$#siU', '[font ${1}${3} size="${2}of"]${4}[/font]');
    $array_html_preg_replace[] = array('#^<font([^>]*)>(.*)</font>$#siU', '[font${1}]${2}[/font]');
    $semihtml = array_html_preg_replace('font', $array_html_preg_replace, $semihtml);
    $semihtml = preg_replace_callback('#(\\[font [^\\]]*color=")rgb\\((\\s*\\d+\\s*),(\\s*\\d+\\s*),(\\s*\\d+\\s*)\\)("[^\\]]*\\])#', '_css_color_fixup', $semihtml);
    $semihtml = preg_replace_callback('#<a ([^>]*)href="([^"]*)"([^>]*)>#', '_a_tag_link_fixup', $semihtml);
    $array_html_preg_replace = array();
    require_code('obfuscate');
    $array_html_preg_replace[] = array('#^<a ([^>]*)href="mailto:(?-U) ?(?U)([^"]+)"([^>]*)>(.*)</a>$#siU', '[email="${2}"]${4}[/email]');
    $array_html_preg_replace[] = array('#^<a ([^>]*)href="' . str_replace('#', '\\#', str_replace('&', '\\&', mailto_obfuscated())) . '([^"]+)"([^>]*)>(.*)</a>$#siU', '[email="${4}"]${2}[/email]');
    $array_html_preg_replace[] = array('#^<a ([^>]*)href="([^"]+)"([^>]*) target="([^"]*)"([^>]*)>(.*)</a>$#siU', '[url="${2}" target="${4}"]${6}[/url]');
    $array_html_preg_replace[] = array('#^<a ([^>]*)href="([^"]+)"([^>]*)>(.*)</a>$#siU', '[url="${2}"]${4}[/url]');
    $semihtml = array_html_preg_replace('a', $array_html_preg_replace, $semihtml);
    $array_html_preg_replace = array();
    $array_html_preg_replace[] = array('#^<p class="msoNormal">\\s*(.*)\\s*</p>$#siU', '${1}<br />');
    $array_html_preg_replace[] = array('#^<p align="(\\w+)" class="msoNormal">\\s*(.*)\\s*</p>$#siU', '[align="${1}"]${2}[/align]');
    $array_html_preg_replace[] = array('#^<p class="msoNormal" style="margin: \\d+pt 0[\\w;]*">\\s*(.*)\\s*</p>$#siU', '<br />${1}<br />');
    // Cleanup from Word
    $array_html_preg_replace[] = array('#^<p class="msoNormal" style="margin: 0[\\w;]* 0[\\w;]* 0[\\w;]*">\\s*(.*)\\s*</p>$#siU', '${1}<br />');
    // Cleanup from Word
    $array_html_preg_replace[] = array('#^<p style="margin: \\d+pt 0[\\w;]*">\\s*(.*)\\s*</p>$#siU', '<br />${1}<br />');
    // Cleanup from Word
    $array_html_preg_replace[] = array('#^<p style="margin: 0[\\w;]* 0[\\w;]* 0[\\w;]*">\\s*(.*)\\s*</p>$#siU', '${1}<br />');
    // Cleanup from Word
    $array_html_preg_replace[] = array('#^<p class="Mso\\w*" style="[^"]*">\\s*(.*)\\s*</p>$#siU', '<br />${1}<br />');
    // Aggressive cleanup from Word (it's here last because we want the nicer matches to get a chance to work instead. It's a shame we need to do this, as we are throwing away potentially important styling (although actually the spans etc far above will have got most of this - we only match p level styling here)- but Word throws so much into a mix it's impossible to "remove the wheat from the chaff". People will need to put it back in using the WYSIWYG editor directly.
    $array_html_preg_replace[] = array('#^<p>\\s*(.*)\\s*</p>$#siU', '${1}<br /><br />');
    $array_html_preg_replace[] = array('#^<p align="(\\w+)">\\s*(.*)\\s*</p>$#siU', '[align="${1}"]${2}[/align]');
    $semihtml = array_html_preg_replace('p', $array_html_preg_replace, $semihtml);
    $array_html_preg_replace = array();
    $array_html_preg_replace[] = array('#^<div align="justify">(.*)</div>$#siU', '[align="justify"]${1}[/align]');
    $array_html_preg_replace[] = array('#^<div style="text-align:\\s*?justify;?">(.*)</div>$#siU', '[align="justify"]${1}[/align]');
    $complex_equivs = array('<div align="right">(.*)</div>' => 'right', '<div align="left">(.*)</div>' => 'left', '<div align="center">(.*)</div>' => 'center', '<div style="text-align:\\s*?right;?">(.*)</div>' => 'right', '<div style="text-align:\\s*?left;?">(.*)</div>' => 'left', '<div style="text-align:\\s*?center;*">(.*)</div>' => 'center');
    foreach ($complex_equivs as $from => $to) {
        $array_html_preg_replace[] = array('#^' . $from . '$#siU', '[' . $to . ']${1}[/' . $to . ']');
    }
    $array_html_preg_replace[] = array('#^<div style="margin-left:\\s*?(\\d+)px;?">(.*)</div>$#siU', '[indent="${1}"]${2}[/indent]');
    $array_html_preg_replace[] = array('#^<div class="([^"]+)">(.*)</div>$#siU', '[surround="${1}"]${2}[/surround]');
    $array_html_preg_replace[] = array('#^<div>(.*)</div>$#siU', '${1}<br />');
    $semihtml = array_html_preg_replace('div', $array_html_preg_replace, $semihtml);
    $_array_html_preg_replace = array();
    foreach ($array_html_preg_replace as $i => $x) {
        $_array_html_preg_replace[$i] = array();
        $_array_html_preg_replace[$i][0] = str_replace('div', 'span', $x[0]);
        $_array_html_preg_replace[$i][1] = $x[1];
    }
    $semihtml = array_html_preg_replace('span', $_array_html_preg_replace, $semihtml);
    $_array_html_preg_replace = array();
    foreach ($array_html_preg_replace as $i => $x) {
        $_array_html_preg_replace[$i] = array();
        $_array_html_preg_replace[$i][0] = str_replace('div', 'p', $x[0]);
        $_array_html_preg_replace[$i][1] = str_replace('<br />', '<br /><br />', $x[1]);
    }
    $semihtml = array_html_preg_replace('p', $_array_html_preg_replace, $semihtml);
    $array_html_preg_replace = array();
    $array_html_preg_replace[] = array('#^<kbd>(.*)</kbd>$#siU', "[tt]\${1}[/tt]");
    $semihtml = array_html_preg_replace('kbd', $array_html_preg_replace, $semihtml);
    $array_html_preg_replace = array();
    $array_html_preg_replace[] = array('#^<ul dir="ltr">(.*)</ul>$#siU', '[list]' . '${1}[/list]');
    $array_html_preg_replace[] = array('#^<ul>(.*)</ul>$#siU', '[list]' . '${1}[/list]');
    $semihtml = array_html_preg_replace('ul', $array_html_preg_replace, $semihtml);
    $array_html_preg_replace = array();
    $array_html_preg_replace[] = array('#^<ol>(.*)</ol>$#siU', '[list="1"]' . '${1}[/list]');
    $array_html_preg_replace[] = array('#^<ol style="list-style-type:\\s*?([^";]*);?">(.*)(</ol>|<ol />)$#siU', '[list="${1}"]' . '${2}[/list]');
    $array_html_preg_replace[] = array('#^<ol type="([^"]*)">(.*)</ol>$#siU', '[list="${1}"]' . '${2}[/list]');
    $semihtml = array_html_preg_replace('ol', $array_html_preg_replace, $semihtml);
    $array_html_preg_replace = array();
    if (strpos($semihtml, '[list') !== false) {
        $array_html_preg_replace[] = array('#^<li>(.*)</li>$#siU', '[*]${1}[/*]' . chr(10));
        $semihtml = array_html_preg_replace('li', $array_html_preg_replace, $semihtml);
    }
    $semihtml = str_replace('<strong class="comcode_bold">', '<strong>', $semihtml);
    $semihtml = str_replace('<em class="comcode_italic">', '<em>', $semihtml);
    $equivs = array('blockquote' => 'indent', 'code' => 'code', 'tt' => 'tt', 'sub' => 'sub', 'sup' => 'sup', 'center' => 'center', '!abbr' => 'abbr', '!acronym' => 'acronym', 'address' => 'address', 'dfn' => 'dfn', 'cite' => 'cite', 'strong' => 'b', 'b' => 'b', 'em' => 'i', 'i' => 'i', 'u' => 'u', 'strike' => 's', 'del' => 'del', 'ins' => 'ins');
    foreach ($equivs as $from => $to) {
        $array_html_preg_replace = array();
        if ($from[0] == '!') {
            $from = substr($from, 1);
            $array_html_preg_replace[] = array('#^<' . $from . '([^>]*)>(.*)</' . $from . '>$#siU', '[' . $to . '${1}]${2}[/' . $to . ']');
        } else {
            $array_html_preg_replace[] = array('#^<' . $from . '>(.*)</' . $from . '>$#siU', '[' . $to . ']${1}[/' . $to . ']');
        }
        $semihtml = array_html_preg_replace($from, $array_html_preg_replace, $semihtml);
    }
    // Fonts that set nothing
    $test = preg_replace('#\\[font param="verdana,arial,helvetica,sans-serif"#', '', $semihtml);
    $test = preg_replace('#\\[font="verdana,arial,helvetica,sans-serif"#', '', $test);
    if (strpos($test, '[font=') === false && strpos($test, '[font param=') === false) {
        $semihtml = comcode_preg_replace('font', '#^\\[font( param)?="verdana,arial,helvetica,sans-serif"](.*)\\[/font\\]$#si', '${2}', $semihtml);
        $semihtml = str_replace(' param="verdana,arial,helvetica,sans-serif"', '', $semihtml);
        $semihtml = str_replace('="verdana,arial,helvetica,sans-serif"', '', $semihtml);
    }
    // Our cleanup loop. These optimisations trickle-through, as they depend on each other. We keep looping until we've done all we can.
    $old_semihtml = '';
    $text_formatting_tags = array('b', 'i', 'u', 'tt', 'font', 'title', 'center', 'left', 'right', 'color');
    do {
        $old_semihtml = $semihtml;
        // Empty tags
        $semihtml = preg_replace('#\\<(\\w+)\\>\\</\\1\\>#', '', $semihtml);
        $semihtml = preg_replace('#\\[font[^\\]]*\\]\\[/font\\]#', '', $semihtml);
        $semihtml = preg_replace('#\\[b[^\\]]*\\]\\[/b\\]#', '', $semihtml);
        $semihtml = preg_replace('#\\[i[^\\]]*\\]\\[/i\\]#', '', $semihtml);
        // Canonical order to make sure we can find pointless nestings. Unfortunately we can only bubble out one level due to constraints in our regexp checking (we need to make sure we don't cross-tags, but we can't in a regexp unless we make sure we have no nesting at all)
        foreach ($text_formatting_tags as $i => $tag) {
            foreach ($text_formatting_tags as $j => $tag_2) {
                if ($i < $j) {
                    $semihtml = comcode_preg_replace($tag_2, '#^(\\[' . $tag_2 . '( [^\\]]*)?\\])(\\[' . $tag . '( [^\\]]*\\])?)([^\\[\\]]*)(\\[/' . $tag . '[^\\]]*\\])(\\[/' . $tag_2 . '[^\\]]*\\])$#si', '${3}${1}${5}${7}${6}', $semihtml);
                }
            }
        }
        // Cleanup nested fonts
        $semihtml = preg_replace('#<span[^<>]*></span>#siU', '', $semihtml);
        $semihtml = comcode_preg_replace('font', '#^\\[font([^\\]]*)\\](\\s*)\\[font([^\\]]*)\\](.*)\\[/font\\](\\s*)\\[/font\\]$#si', '[font${1}${3}]${2}${4}${5}[/font]', $semihtml);
        $semihtml = preg_replace('#\\[font ([^\\]]*)face="([^"]*)"([^\\]]*)face="([^"]*)"([^\\]]*)\\]#si', '[font ${1}${3}${5} face="${4}"]', $semihtml);
        $semihtml = preg_replace('#\\[font ([^\\]]*)size="([^"]*)"([^\\]]*)size="([^"]*)"([^\\]]*)\\]#si', '[font ${1}${3}${5} size="${4}"]', $semihtml);
        // This is imperfect (due to relative font sizes), but at least it encourages cleanup
        $semihtml = preg_replace('#\\[font ([^\\]]*)color="([^"]*)"([^\\]]*)color="([^"]*)"([^\\]]*)\\]#si', '[font ${1}${3}${5} color="${4}"]', $semihtml);
        $semihtml = preg_replace('#\\[font ([^\\]]*)param="([^"]*)"([^\\]]*)param="([^"]*)"([^\\]]*)\\]#si', '[font ${1}${3}${5} param="${4}"]', $semihtml);
        $semihtml = preg_replace('#(\\[font.*)(?-U)\\s+(?U)(.*\\])#U', '${1} ${2}', $semihtml);
        // safe because no whitespace runs can be expected within a font tag
        // Cleanup other nestings / close then reopen patterns
        foreach (array('b', 'i', 'u', 'tt', 'font size="[^"]*"') as $tag) {
            $tagx = strpos($tag, ' ') !== false ? substr($tag, 0, strpos($tag, ' ')) : $tag;
            $semihtml = comcode_preg_replace($tagx, '#^(\\[' . $tag . '\\])(.*)\\1(.*)\\[/' . $tagx . '\\](.*)\\[/' . $tagx . '\\]$#si', '${1}${2}${3}${4}[/' . $tagx . ']', $semihtml);
            $semihtml = preg_replace('#(\\[' . $tag . '\\])([^\\[\\]]*)\\[/' . $tagx . '\\]((&nbsp;|</CDATA\\_\\_space>|\\s)*)\\1#si', '${1}${2}${3}', $semihtml);
            // Only works in simple case, not when there are tags nested within first tag. Can't use comcode_preg_replace as we are joining two tags (i.e. not operating over single bind)
        }
        // Cleanup lines filled with spaces/font-junk
        foreach ($text_formatting_tags as $tag) {
            $semihtml = preg_replace('#(\\[' . $tag . '[^\\]]*\\])((&nbsp;|</CDATA\\_\\_space>|\\s|<br\\s*/>|\\n)*)#i', '${2}${1}', $semihtml);
            // Tag starting unnecessarily early -> Move it back
            $semihtml = preg_replace('#((&nbsp;|</CDATA\\_\\_space>|\\s|<br\\s*/>|\\n)*)(\\[/' . $tag . '\\])#i', '${3}${1}', $semihtml);
            // Tag ending unnecessarily late -> Move it back
            $semihtml = preg_replace('#\\[' . $tag . '[^\\]]*\\]((&nbsp;|</CDATA\\_\\_space>|\\s|<br\\s*/>|\\n)*)\\[/' . $tag . '\\]#i', '${1}', $semihtml);
            // Tag wrapping whitespace -> White space
        }
        $semihtml = preg_replace('#(&nbsp;|</CDATA\\_\\_space>|\\s)*<br\\s*/>#i', '<br />', $semihtml);
        // Spaces on end of line -> (Remove)
    } while ($semihtml != $old_semihtml);
    // Undone center tagging
    $semihtml = comcode_preg_replace('left', '#^\\[left\\]\\[center\\](.*)\\[/center\\]\\[/left\\]$#si', '[left]${1}[/left]', $semihtml);
    $semihtml = comcode_preg_replace('right', '#^\\[right\\]\\[center\\](.*)\\[/center\\]\\[/right\\]$#si', '[right]${1}[/right]', $semihtml);
    $semihtml = comcode_preg_replace('center', '#^\\[center\\]\\[left\\](.*)\\[/left\\]\\[/center\\]$#si', '[center]${1}[/center]', $semihtml);
    $semihtml = comcode_preg_replace('center', '#^\\[center\\]\\[right\\](.*)\\[/right\\]\\[/center\\]$#si', '[center]${1}[/center]', $semihtml);
    // Cleanup list Comcode (nice and pretty)
    $semihtml = preg_replace('#(&nbsp;|</CDATA\\_\\_space>|\\s|<br\\s*/>|\\n)*\\[/\\*\\](&nbsp;|</CDATA\\_\\_space>|\\s|<br\\s*/>|\\n)*#', '[/*]', $semihtml);
    $semihtml = preg_replace('#(&nbsp;|</CDATA\\_\\_space>|\\s|<br\\s*/>|\\n)*\\[\\*\\](&nbsp;|</CDATA\\_\\_space>|\\s|<br\\s*/>|\\n)*#', '[*]', $semihtml);
    $semihtml = preg_replace('#\\[/\\*\\]([^\\s])#', '[/*]<ocpbr />${1}', $semihtml);
    $semihtml = preg_replace('#\\[list\\]([^\\s])#', '[list]<ocpbr />${1}', $semihtml);
    // Cleanup various blocks where we can afford a blank line
    global $BLOCK_TAGS;
    foreach (array_keys($BLOCK_TAGS) as $tag) {
        if (strpos($semihtml, '[' . $tag) !== false) {
            $semihtml = preg_replace('#( |</CDATA\\_\\_space>)*(\\[' . $tag . '[\\] ])#', '${2}', $semihtml);
            $semihtml = preg_replace('#\\[/' . $tag . '\\](?!\\[/)(?!<br)#', '[/' . $tag . ']' . ($tag == 'title' ? '<ocpbr /><ocpbr />' : '<ocpbr />'), $semihtml);
        }
    }
    // Remove our CDATA protections
    $semihtml = str_replace('</CDATA__space>', ' ', $semihtml);
    $semihtml = str_replace('</CDATA__tab>', "\t", $semihtml);
    $semihtml = str_replace('</CDATA__nl>', chr(10), $semihtml);
    $semihtml = str_replace('</CDATA__lf>', chr(13), $semihtml);
    $semihtml = str_replace('</CDATA__amp>', '&', $semihtml);
    /*// And use same method to protect our code tags
    	foreach (array_keys($GLOBALS['CODE_TAGS']) as $code_tag)
    		$semihtml=preg_replace_callback('#(\['.$code_tag.'[^\]]*\])(.*)(\[/'.$code_tag.'\])#siU','_codetag_unprotect',$semihtml);*/
    // Tempcode escaping
    /*$semihtml=str_replace('{+','\{+',$semihtml);	No - people should be able to type this if they want
    	$semihtml=str_replace('{$','\{$',$semihtml);
    	$semihtml=str_replace('{!','\{!',$semihtml);*/
    $semihtml = str_replace('[ html', '[html', $semihtml);
    $semihtml = str_replace('[ semihtml', '[semihtml', $semihtml);
    $semihtml = str_replace('[ / html', '[/html', $semihtml);
    $semihtml = str_replace('[ / semihtml', '[/semihtml', $semihtml);
    // People without comcode_dangerous have further cleanups, that might lose some quality...
    if (!has_specific_permission(get_member(), 'allow_html')) {
        $semihtml2 = $semihtml;
        $array_html_preg_replace = array();
        $array_html_preg_replace[] = array('#^<table summary="([^"]*)"([^>]*)>(.*)</table>$#siU', chr(10) . "{| \${2}\${3}'.chr(10).'|}" . chr(10));
        $array_html_preg_replace[] = array('#^<table([^>]*)>(.*)</table>$#siU', chr(10) . "{|" . chr(10) . "\${2}" . chr(10) . "|}" . chr(10));
        $semihtml2 = array_html_preg_replace('table', $array_html_preg_replace, $semihtml2);
        $array_html_preg_replace = array();
        $array_html_preg_replace[] = array('#^<thead([^>]*)>(.*)</thead>$#siU', '');
        $semihtml2 = array_html_preg_replace('thead', $array_html_preg_replace, $semihtml2);
        $array_html_preg_replace = array();
        $array_html_preg_replace[] = array('#^<tbody([^>]*)>(.*)</tbody>$#siU', '${2}');
        $semihtml2 = array_html_preg_replace('tbody', $array_html_preg_replace, $semihtml2);
        $array_html_preg_replace = array();
        $array_html_preg_replace[] = array('#^<tfoot([^>]*)>(.*)</tfoot>$#siU', '');
        $semihtml2 = array_html_preg_replace('tfoot', $array_html_preg_replace, $semihtml2);
        $array_html_preg_replace = array();
        $array_html_preg_replace[] = array('#^<tr([^>]*)>(.*)</tr>$#siU', chr(10) . "|-" . chr(10) . "\${2}");
        $semihtml2 = array_html_preg_replace('tr', $array_html_preg_replace, $semihtml2);
        $array_html_preg_replace = array();
        $array_html_preg_replace[] = array('#^<th([^>]*)>(.*)</th>$#siU', chr(10) . chr(10) . "! \${2}");
        $semihtml2 = array_html_preg_replace('th', $array_html_preg_replace, $semihtml2);
        $array_html_preg_replace = array();
        $array_html_preg_replace[] = array('#^<td([^>]*)>(.*)</td>$#siU', chr(10) . "| \${2}");
        $semihtml2 = array_html_preg_replace('td', $array_html_preg_replace, $semihtml2);
        $array_html_preg_replace = array();
        $array_html_preg_replace[] = array('#^<span style="font-family: monospace;  font-size: 1.2em;">(.*)</span>$#siU', "[tt]\${1}[/tt]");
        $semihtml2 = array_html_preg_replace('span', $array_html_preg_replace, $semihtml2);
        if (strpos($semihtml, '[code') === false) {
            $array_html_preg_replace = array();
            $array_html_preg_replace[] = array('#^<pre>(.*)</pre>$#siU', "[code]\${1}[/code]");
            $semihtml2 = array_html_preg_replace('pre', $array_html_preg_replace, $semihtml2);
        }
        $array_html_preg_replace = array();
        $array_html_preg_replace[] = array('#^<table([^>]*)>(.*)</table>$#siU', "<table class=\"bordered_table\">\${2}</table>");
        $semihtml = array_html_preg_replace('table', $array_html_preg_replace, $semihtml);
        $array_html_preg_replace = array();
        $array_html_preg_replace[] = array('#^<tr([^>]*)>(.*)</tr>$#siU', "<tr>\${2}</tr>");
        $semihtml = array_html_preg_replace('tr', $array_html_preg_replace, $semihtml);
        $array_html_preg_replace = array();
        $array_html_preg_replace[] = array('#^<th([^>]*)>(.*)</th>$#siU', "<th>\${2}</th>");
        $semihtml = array_html_preg_replace('th', $array_html_preg_replace, $semihtml);
        $array_html_preg_replace = array();
        $array_html_preg_replace[] = array('#^<td([^>]*)>(.*)</td>$#siU', "<td>\${2}</td>");
        $semihtml = array_html_preg_replace('td', $array_html_preg_replace, $semihtml);
    } else {
        $semihtml2 = $semihtml;
    }
    // Cleanup impossible stuff in code tags
    foreach (array_keys($CODE_TAGS) as $tag) {
        $semihtml2 = comcode_preg_replace($tag, '#^(\\[' . $tag . '\\])([.\\n]*)(\\[/' . $tag . '\\])$#i', array('semihtml_to_comcode_wrap'), $semihtml2);
    }
    // These can only be used outside semihtml - so we do them in a copy of our output, and only use that copy if we find we are able to do a 100% Comcode conversion
    $semihtml2 = str_replace('<ocpbr />', chr(10), $semihtml2);
    $semihtml2 = str_replace('<br />', chr(10), $semihtml2);
    $semihtml2 = str_replace('<br  />', chr(10), $semihtml2);
    $semihtml2 = str_replace('<br>', chr(10), $semihtml2);
    $semihtml2 = str_replace('<hr width="100%" size="2" />', '<hr />', $semihtml2);
    $semihtml2 = str_replace('<hr size="2" width="100%" />', '<hr />', $semihtml2);
    $semihtml2 = str_replace('<hr width="100%" />', '<hr />', $semihtml2);
    $semihtml2 = str_replace(chr(10) . '<hr />', chr(10) . "---------------" . chr(10), $semihtml2);
    $semihtml2 = str_replace(chr(10) . '<hr>', chr(10) . "---------------" . chr(10), $semihtml2);
    $semihtml2 = preg_replace('#<hr\\s*/>#', chr(10) . "---------------" . chr(10), $semihtml2);
    $semihtml2 = str_replace('<hr>', chr(10) . "---------------" . chr(10), $semihtml2);
    // We transform any HTML in there to Comcode if we can
    $smilies = $GLOBALS['FORUM_DRIVER']->find_emoticons();
    foreach ($smilies as $code => $imgcode) {
        if ($imgcode[0] == 'EMOTICON_IMG_CODE_THEMED') {
            $imgcode[1] = find_theme_image($imgcode[1], true);
            if ($imgcode[1] == '') {
                continue;
            }
            // Theme image gone missing
        }
        $imgcode[1] = str_replace(get_base_url(), '', $imgcode[1]);
        $semihtml2 = preg_replace('#<img [^>]*src="[^"]*' . str_replace('#', '\\#', preg_quote(escape_html($imgcode[1]))) . '"[^>]*>\\s*#si', $code, $semihtml2);
    }
    $semihtml2 = preg_replace_callback('#<img([^>]*) src="([^"]*)"([^>]*) />#siU', '_img_tag_fixup', $semihtml2);
    $semihtml2 = preg_replace_callback('#<img([^>]*) src="([^"]*)"([^>]*)>#siU', '_img_tag_fixup', $semihtml2);
    // Then, if there is no HTML left, we can avoid the 'semihtml' tag
    if (strpos($semihtml2, '<') === false) {
        //		$semihtml2=str_replace(array('&lt;','&gt;','&amp;'),array('___lt___','___gt___','___amp___'),$semihtml2);
        $semihtml2 = @html_entity_decode($semihtml2, ENT_QUOTES, get_charset());
        //		$semihtml2=str_replace(array('___lt___','___gt___','___amp___'),array('&lt;','&gt;','&amp;'),$semihtml2);
        return $semihtml2;
    }
    // Oh well, we couldn't do a perfect conversion, so we'll have to use semihtml.
    $semihtml = preg_replace_callback('#<img([^>]*) src="([^"]*)"([^>]*) />#siU', '_img_tag_fixup', $semihtml);
    $semihtml = preg_replace_callback('#<img([^>]*) src="([^"]*)"([^>]*)>#siU', '_img_tag_fixup', $semihtml);
    $semihtml = str_replace('<ocpbr />', chr(10), $semihtml);
    // Make it look slightly reasonable first (to the reader of the Comcode)
    $semihtml = str_replace('<br  />', '<br />', $semihtml);
    $semihtml = str_replace('<br />', '<br />' . chr(10), $semihtml);
    $semihtml = str_replace('</p>', '</p>' . chr(10), $semihtml);
    $semihtml = str_replace('[/align]', '[/align]' . chr(10), $semihtml);
    return '[semihtml]' . $semihtml . '[/semihtml]';
}
Exemplo n.º 25
0
/**
 * Show a post, isolated of the other posts in it's topic.
 *
 * @param  array		The post row.
 * @param  boolean	Whether to use the post title, as opposed to the post's topic's title.
 * @return tempcode  The isolated post.
 */
function ocf_show_isolated_post($row, $use_post_title = false)
{
    require_code('ocf_groups');
    require_css('ocf');
    // Poster title
    $primary_group = $GLOBALS['FORUM_DRIVER']->get_member_row_field($row['p_poster'], 'm_primary_group');
    if (!is_null($primary_group)) {
        if (addon_installed('ocf_member_titles')) {
            $poster_title = $GLOBALS['OCF_DRIVER']->get_member_row_field($row['p_poster'], 'm_title');
            if ($poster_title == '') {
                $poster_title = get_translated_text(ocf_get_group_property($primary_group, 'title'), $GLOBALS['FORUM_DB']);
            }
        } else {
            $poster_title = '';
        }
        $avatar = $GLOBALS['FORUM_DRIVER']->get_member_avatar_url($row['p_poster']);
        $posters_groups = $GLOBALS['FORUM_DRIVER']->get_members_groups($row['p_poster'], true);
    } else {
        $poster_title = '';
        $avatar = '';
        $posters_groups = array();
    }
    // Avatar
    if (is_guest($row['p_poster'])) {
        if ($row['p_poster_name_if_guest'] == do_lang('SYSTEM')) {
            $avatar = find_theme_image('ocf_default_avatars/default_set/ocp_fanatic', true);
        }
    }
    if ($avatar != '') {
        $post_avatar = do_template('OCF_TOPIC_POST_AVATAR', array('AVATAR' => $avatar));
    } else {
        $post_avatar = new ocp_tempcode();
    }
    // Rank images
    $rank_images = new ocp_tempcode();
    foreach ($posters_groups as $group) {
        $rank_image = ocf_get_group_property($group, 'rank_image');
        $group_leader = ocf_get_group_property($group, 'group_leader');
        $group_name = ocf_get_group_name($group);
        $rank_image_pri_only = ocf_get_group_property($group, 'rank_image_pri_only');
        if ($rank_image != '' && ($rank_image_pri_only == 0 || $group == $primary_group)) {
            $rank_images->attach(do_template('OCF_RANK_IMAGE', array('GROUP_NAME' => $group_name, 'USERNAME' => $GLOBALS['FORUM_DRIVER']->get_username($row['p_poster']), 'IMG' => $rank_image, 'IS_LEADER' => $group_leader == $row['p_poster'])));
        }
    }
    // Poster details
    if (!is_guest($row['p_poster']) && !is_null($primary_group)) {
        require_code('ocf_members2');
        $poster_details = ocf_show_member_box($row['p_poster'], false, NULL, NULL, false);
    } else {
        $custom_fields = new ocp_tempcode();
        $poster_details = new ocp_tempcode();
    }
    if (!is_guest($row['p_poster']) && !is_null($primary_group)) {
        $poster = do_template('OCF_POSTER_MEMBER', array('ONLINE' => member_is_online($row['p_poster']), 'ID' => strval($row['p_poster']), 'POSTER_DETAILS' => $poster_details, 'PROFILE_URL' => $GLOBALS['FORUM_DRIVER']->member_profile_url($row['p_poster'], false, true), 'POSTER_USERNAME' => $GLOBALS['FORUM_DRIVER']->get_username($row['p_poster']), 'HIGHLIGHT_NAME' => NULL));
    } else {
        $poster = do_template('OCF_POSTER_GUEST', array('IP_LINK' => '', 'POSTER_DETAILS' => $poster_details, 'POSTER_USERNAME' => $row['p_poster_name_if_guest'] != '' ? $row['p_poster_name_if_guest'] : do_lang('GUEST')));
    }
    // Last edited
    if (!is_null($row['p_last_edit_time'])) {
        $last_edited = do_template('OCF_TOPIC_POST_LAST_EDITED', array('LAST_EDIT_DATE_RAW' => is_null($row['p_last_edit_time']) ? '' : strval($row['p_last_edit_time']), 'LAST_EDIT_DATE' => get_timezoned_date($row['p_last_edit_time']), 'LAST_EDIT_PROFILE_URL' => is_null($row['p_last_edit_by']) ? '' : $GLOBALS['FORUM_DRIVER']->member_profile_url($row['p_last_edit_by'], false, true), 'LAST_EDIT_USERNAME' => is_null($row['p_last_edit_by']) ? '' : $GLOBALS['FORUM_DRIVER']->get_username($row['p_last_edit_by'])));
    } else {
        $last_edited = new ocp_tempcode();
    }
    $last_edited_raw = is_null($row['p_last_edit_time']) ? '' : strval($row['p_last_edit_time']);
    // Misc stuff
    $poster_id = $row['p_poster'];
    $tree = ocf_forum_breadcrumbs($row['p_cache_forum_id']);
    $post_url = build_url(array('page' => 'topicview', 'type' => 'findpost', 'id' => $row['id']), get_module_zone('topicview'));
    $post_url->attach('#post_' . strval($row['id']));
    if (get_page_name() != 'search' && array_key_exists('text_parsed', $row) && !is_null($row['text_parsed']) && $row['text_parsed'] != '' && $row['p_post'] != 0) {
        $post = new ocp_tempcode();
        if (!$post->from_assembly($row['text_parsed'], true)) {
            $post = get_translated_tempcode($row['p_post'], $GLOBALS['FORUM_DB']);
        }
    } else {
        $post = get_translated_tempcode($row['p_post'], $GLOBALS['FORUM_DB']);
    }
    $post_date = get_timezoned_date($row['p_time']);
    $post_date_raw = $row['p_time'];
    if ($use_post_title) {
        $post_title = $row['p_title'];
    } else {
        $post_title = $GLOBALS['FORUM_DB']->query_value('f_topics', 't_cache_first_title', array('id' => $row['p_topic_id']));
        if ($row['p_title'] != $post_title) {
            $post_title .= ': ' . $row['p_title'];
        }
    }
    //if ($post_title=='') $post_title=do_lang_tempcode('ISOLATED_POST_TITLE',strval($row['id']));
    $emphasis = new ocp_tempcode();
    if ($row['p_is_emphasised'] == 1) {
        $emphasis = do_lang_tempcode('IMPORTANT');
    } elseif (!is_null($row['p_intended_solely_for'])) {
        $pp_to_username = $GLOBALS['FORUM_DRIVER']->get_username($row['p_intended_solely_for']);
        if (is_null($pp_to_username)) {
            $pp_to_username = do_lang('UNKNOWN');
        }
        $emphasis = do_lang('PP_TO', $pp_to_username);
    }
    require_code('feedback');
    actualise_rating(true, 'post', strval($row['id']), get_self_url(), $row['p_title']);
    $rating = display_rating(get_self_url(), $row['p_title'], 'post', strval($row['id']), 'RATING_INLINE_DYNAMIC', $row['p_poster']);
    // Render
    return do_template('OCF_ISOLATED_POST', array('_GUID' => '9456f4fe4b8fb1bf34f606fcb2bcc9d7', 'URL' => $post_url, 'ID' => strval($row['id']), 'TREE' => $tree, 'POST' => do_template('OCF_TOPIC_POST', array('ID' => strval($row['id']), 'TOPIC_FIRST_POST_ID' => '', 'TOPIC_FIRST_POSTER' => '', 'POST_ID' => strval($row['id']), 'URL' => $post_url, 'CLASS' => $row['p_is_emphasised'] == 1 ? 'ocf_post_emphasis' : (!is_null($row['p_intended_solely_for']) ? 'ocf_post_personal' : ''), 'EMPHASIS' => $emphasis, 'FIRST_UNREAD' => '', 'POSTER_TITLE' => $poster_title, 'POST_TITLE' => $post_title, 'POST_DATE_RAW' => strval($post_date_raw), 'POST_DATE' => $post_date, 'POST' => $post, 'TOPIC_ID' => is_null($row['p_topic_id']) ? '' : strval($row['p_topic_id']), 'LAST_EDITED_RAW' => $last_edited_raw, 'LAST_EDITED' => $last_edited, 'POSTER_ID' => strval($poster_id), 'POSTER' => $poster, 'POSTER_DETAILS' => $poster_details, 'POST_AVATAR' => $post_avatar, 'RANK_IMAGES' => $rank_images, 'BUTTONS' => '', 'SIGNATURE' => '', 'UNVALIDATED' => '', 'DESCRIPTION' => '', 'PREVIEWING' => true, 'RATING' => $rating))));
}
Exemplo n.º 26
0
/**
 * Handle RSS/Atom output.
 */
function backend_script()
{
    // Closed site
    $site_closed = get_option('site_closed');
    if ($site_closed == '1' && !has_specific_permission(get_member(), 'access_closed_site') && get_ip_address() != ocp_srv('SERVER_ADDR') && !$GLOBALS['IS_ACTUALLY_ADMIN']) {
        header('Content-Type: text/plain');
        @exit(get_option('closed'));
    }
    if (get_option('is_on_rss') == '0') {
        return;
    }
    $type = get_param('type', 'RSS2');
    $mode = get_param('mode', 'opml');
    require_lang('rss');
    if ($type == 'xslt-rss') {
        // Feed stylesheet for RSS
        header('Content-Type: text/xsl');
        require_css('rss');
        $js = get_custom_base_url() . substr(javascript_enforce('JAVASCRIPT_XSL_MOPUP'), strlen(get_custom_file_base()));
        $echo = do_template('RSS_XSLT', array('_GUID' => 'c443e0195c935117cf0d9a7bc2730d7a', 'JAVASCRIPT_XSL_MOPUP' => $js));
        $echo->evaluate_echo();
        return;
    }
    if ($type == 'xslt-atom') {
        // Feed stylesheet for Atom
        header('Content-Type: text/xsl');
        require_css('rss');
        $js = get_custom_base_url() . substr(javascript_enforce('JAVASCRIPT_XSL_MOPUP'), strlen(get_custom_file_base()));
        $echo = do_template('ATOM_XSLT', array('_GUID' => '27fec456a6b3144aa847130e74463d99', 'JAVASCRIPT_XSL_MOPUP' => $js));
        $echo->evaluate_echo();
        return;
    }
    if ($type == 'xslt-opml') {
        // Feed stylesheet for Atom
        header('Content-Type: text/xsl');
        require_css('rss');
        $js = get_custom_base_url() . substr(javascript_enforce('JAVASCRIPT_XSL_MOPUP'), strlen(get_custom_file_base()));
        $echo = do_template('OPML_XSLT', array('_GUID' => 'c0c6bd1d7a0e263768a2208061f799f5', 'JAVASCRIPT_XSL_MOPUP' => $js));
        $echo->evaluate_echo();
        return;
    }
    $type = strtoupper($type);
    if ($type != 'RSS2' && $type != 'ATOM') {
        $type = 'RSS2';
    }
    if ($type == 'RSS2') {
        $prefix = 'RSS_';
    } else {
        $prefix = 'ATOM_';
    }
    /*if (get_param_integer('force_text',0)==0)
    	{
    		if ($type=='atom') header('Content-Type: text/xml+atom; charset='.get_charset());
    		else header('Content-Type: text/xml');
    	}
    	header('Content-Disposition: inline');*/
    if ($type == 'RSS2') {
        $date_string = 'r';
    } else {
        $offset_seconds = intval(date('Z'));
        $offset_minutes = abs(intval(round(floatval($offset_seconds) / 60.0)));
        $offset_hours = intval(round(floatval($offset_minutes) / 60.0));
        $offset_minutes -= $offset_hours * 60;
        $offset = sprintf('%02d:%02d', $offset_hours, $offset_minutes);
        $date_string = 'Y-m-d\\TH:i:s';
        if ($offset_seconds >= 0) {
            $date_string .= '+';
        } else {
            $date_string .= '-';
        }
        for ($i = 0; $i < strlen($offset); $i++) {
            $date_string .= '\\' . $offset[$i];
        }
    }
    $date = date($date_string);
    $site_about = xmlentities(get_option('description'));
    $logo_url = xmlentities(find_theme_image('logo/trimmed-logo'));
    $copyright = xmlentities(trim(str_replace('&copy;', '', str_replace('$CURRENT_YEAR', date('Y'), get_option('copyright')))));
    $cutoff = get_param_integer('cutoff', time() - 60 * 60 * 24 * get_param_integer('days', 30));
    $max = get_param_integer('max', 100);
    $filter = get_param('filter', '*');
    if ($filter == '') {
        $filter = '*';
    }
    if ($mode == 'opml') {
        header('Content-Type: text/xml');
        $_feeds = find_all_hooks('systems', 'rss');
        $feeds = array();
        foreach (array_keys($_feeds) as $feed) {
            if (get_forum_type() != 'ocf' && substr($feed, 0, 4) == 'ocf_') {
                continue;
            }
            $feed_title = ucwords(str_replace('_', ' ', $feed));
            // Try and get a better feed title
            require_code('hooks/systems/rss/' . filter_naughty_harsh($feed), true);
            $object = object_factory('Hook_rss_' . $feed);
            require_code('ocfiltering');
            $_content = $object->run('', time(), 'ATOM_', '', 0);
            if (is_array($_content)) {
                list(, $feed_title) = $_content;
            }
            $feeds[] = array('MODE' => $feed, 'TITLE' => $feed_title);
        }
        $echo = do_template('OPML_WRAPPER', array('_GUID' => '712b78d1b4c23aefc8a92603477f84ed', 'FEEDS' => $feeds, 'ABOUT' => $site_about, 'DATE' => $date));
        $echo->evaluate_echo();
        return;
    }
    require_code('hooks/systems/rss/' . filter_naughty_harsh($mode), true);
    $object = object_factory('Hook_rss_' . $mode);
    require_code('ocfiltering');
    $_content = $object->run($filter, $cutoff, $prefix, $date_string, $max);
    $mode_nice = $mode;
    if (is_array($_content)) {
        list($content, $mode_nice) = $_content;
    } else {
        $content = is_null($_content) ? array() : $_content;
    }
    if ($type == 'RSS2' && function_exists('xmlrpc_encode')) {
        // Change a full url into constituent parts
        $base_url = get_base_url();
        $port = 80;
        $end_protocol_pos = strpos($base_url, '://');
        $colon_pos = strpos($base_url, ':', $end_protocol_pos + 1);
        if ($colon_pos !== false) {
            $after_port_pos = strpos($base_url, '/', $colon_pos);
            if ($after_port_pos === false) {
                $after_port_pos = strlen($base_url);
            }
            $port = intval(substr($base_url, $colon_pos, $after_port_pos - $colon_pos));
        }
        $start_path_pos = strpos($base_url, '/', $end_protocol_pos + 4);
        if ($start_path_pos !== false) {
            $local_base_url = substr($base_url, $start_path_pos);
        } else {
            $local_base_url = '';
        }
        $rss_cloud = do_template('RSS_CLOUD', array('_GUID' => 'a47c40a4c137ea1e5abfc71346547313', 'TYPE' => $type == 'news' ? '' : $type, 'PORT' => strval($port), 'LOCAL_BASE_URL' => $local_base_url));
    } else {
        $rss_cloud = new ocp_tempcode();
    }
    // Firefox (and probably other browsers, but I didn't test) doesn't want to display Atom feeds inline if they're sent as text/xml+atom, even if the Content-Disposition is sent to inline :(
    header('Content-Type: text/xml');
    // application/rss+xml ?
    $echo = do_template($prefix . 'WRAPPER', array('FILTER' => $filter, 'CUTOFF' => strval($cutoff), 'MODE' => $mode, 'MODE_NICE' => $mode_nice, 'RSS_CLOUD' => $rss_cloud, 'VERSION' => ocp_version_full(), 'COPYRIGHT' => $copyright, 'DATE' => $date, 'LOGO_URL' => $logo_url, 'ABOUT' => $site_about, 'CONTENT' => $content));
    $echo->evaluate_echo();
}
Exemplo n.º 27
0
 /**
  * The UI to show a usergroup.
  *
  * @return tempcode		The UI
  */
 function usergroup()
 {
     $id = get_param_integer('id');
     if ($id == db_get_first_id()) {
         warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
     }
     $map = has_specific_permission(get_member(), 'see_hidden_groups') ? array('id' => $id) : array('id' => $id, 'g_hidden' => 0);
     $groups = $GLOBALS['FORUM_DB']->query_select('f_groups', array('*'), $map, '', 1);
     if (!array_key_exists(0, $groups)) {
         warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
     }
     $group = $groups[0];
     $club = $group['g_is_private_club'] == 1;
     $name = get_translated_text($group['g_name'], $GLOBALS['FORUM_DB']);
     $title = get_page_title($club ? 'CLUB' : 'USERGROUP', true, array(escape_html($name)));
     // Leadership
     if (!is_null($group['g_group_leader']) && !is_null($GLOBALS['FORUM_DRIVER']->get_username($group['g_group_leader']))) {
         $leader_name = $GLOBALS['FORUM_DRIVER']->get_username($group['g_group_leader']);
         if (is_null($leader_name)) {
             $leader_name = do_lang('UNKNOWN');
         }
         $leader_url = build_url(array('page' => 'members', 'type' => 'view', 'id' => $group['g_group_leader']), get_module_zone('members'));
         $leader_link = hyperlink($leader_url, $leader_name, false, true);
         $leader = paragraph(do_lang_tempcode('GROUP_LED_BY', $leader_link), 'gfgdfggdf');
     } else {
         $leader = new ocp_tempcode();
     }
     // Promotion
     if (addon_installed('points') && !is_null($group['g_promotion_threshold']) && !is_null($group['g_promotion_target'])) {
         $promote_link = ocf_get_group_link($group['g_promotion_target']);
         $promotion_info = do_lang_tempcode('OCF_PROMOTION_INFO', integer_format($group['g_promotion_threshold']), $promote_link->evaluate());
     } else {
         $promotion_info = new ocp_tempcode();
     }
     // To add
     if (ocf_may_control_group($id, get_member())) {
         $add_url = build_url(array('page' => '_SELF', 'type' => 'add_to', 'id' => $id), '_SELF');
     } else {
         $add_url = new ocp_tempcode();
     }
     // To apply
     $my_groups = $GLOBALS['FORUM_DRIVER']->get_members_groups(get_member(), false, false);
     if (is_guest()) {
         $apply_url = new ocp_tempcode();
         $apply_text = new ocp_tempcode();
     } else {
         if (!in_array($id, $my_groups)) {
             $apply_url = build_url(array('page' => '_SELF', 'type' => 'apply', 'id' => $id), '_SELF');
             $apply_text = do_lang_tempcode('APPLY_TO_GROUP');
         } elseif (ocf_get_member_primary_group(get_member()) != $id) {
             $apply_url = build_url(array('page' => '_SELF', 'type' => 'resign', 'id' => $id), '_SELF');
             $apply_text = do_lang_tempcode('RESIGN_FROM_GROUP');
         } else {
             $apply_url = new ocp_tempcode();
             $apply_text = new ocp_tempcode();
         }
     }
     require_code('templates_results_table');
     $sortables = array();
     list($sortable, $sort_order) = explode(' ', get_param('p_sort', 'date_and_time DESC'));
     // Primary members
     $start = get_param_integer('p_start', 0);
     $max = get_param_integer('p_max', 50);
     $_primary_members = ocf_get_group_members_raw($id, true, true, false, false, $max, $start);
     if (count($_primary_members) > 0) {
         $max_rows = ocf_get_group_members_raw_count($id, true, true, false, false);
         $primary_members = new ocp_tempcode();
         foreach ($_primary_members as $i => $primary_member) {
             $url = $GLOBALS['FORUM_DRIVER']->member_profile_url($primary_member['gm_member_id'], false, true);
             $temp = do_template('OCF_VIEW_GROUP_MEMBER', array('_GUID' => 'b96b674ac713e9790ecb78c15af1baab', 'NAME' => $primary_member['m_username'], 'URL' => $url));
             $primary_members->attach(results_entry(array($temp)));
         }
         $fields_title = results_field_title(array(do_lang_tempcode('PRIMARY_MEMBERS')), $sortables, 'p_sort', $sortable . ' ' . $sort_order);
         $primary_members = results_table(do_lang_tempcode('PRIMARY_MEMBERS'), $start, 'p_start', $max, 'p_max', $max_rows, $fields_title, $primary_members, $sortables, $sortable, $sort_order, 'p_sort', NULL, NULL, NULL, 6);
     } else {
         $primary_members = new ocp_tempcode();
     }
     $edit_url = new ocp_tempcode();
     $s_start = get_param_integer('s_start', 0);
     $s_max = get_param_integer('s_max', 50);
     $_secondary_members = ocf_get_group_members_raw($id, false, true, true, ocf_may_control_group($id, get_member()), $s_max, $s_start);
     $secondary_members = new ocp_tempcode();
     $prospective_members = new ocp_tempcode();
     $s_max_rows = ocf_get_group_members_raw_count($id, false, false, true, ocf_may_control_group($id, get_member()));
     $d_max_rows = ocf_get_group_members_raw_count($id, false, true, true, ocf_may_control_group($id, get_member()));
     foreach ($_secondary_members as $secondary_member) {
         $m_username = $GLOBALS['FORUM_DRIVER']->get_member_row_field($secondary_member['gm_member_id'], 'm_username');
         if (is_null($m_username)) {
             continue;
         }
         if ($secondary_member['gm_validated'] == 1) {
             $url = $GLOBALS['FORUM_DRIVER']->member_profile_url($secondary_member['gm_member_id'], false, true);
             $remove_url = build_url(array('page' => '_SELF', 'type' => 'remove_from', 'id' => $id, 'member_id' => $secondary_member['gm_member_id']), '_SELF');
             $temp = do_template('OCF_VIEW_GROUP_MEMBER' . (ocf_may_control_group($id, get_member()) ? '_SECONDARY' : ''), array('REMOVE_URL' => $remove_url, 'NAME' => $m_username, 'URL' => $url));
             $secondary_members->attach(results_entry(array($temp)));
         } elseif (!$add_url->is_empty()) {
             $url = $GLOBALS['FORUM_DRIVER']->member_profile_url($secondary_member['gm_member_id'], false, true);
             $accept_url = build_url(array('page' => '_SELF', 'type' => 'accept', 'id' => $id, 'member_id' => $secondary_member['gm_member_id']), '_SELF');
             $decline_url = build_url(array('page' => '_SELF', 'type' => 'decline', 'id' => $id, 'member_id' => $secondary_member['gm_member_id']), '_SELF');
             $temp = do_template('OCF_VIEW_GROUP_MEMBER_PROSPECTIVE', array('_GUID' => '16e93cf50a14e3b6a3bdf31525fd5e7f', 'ACCEPT_URL' => $accept_url, 'DECLINE_URL' => $decline_url, 'NAME' => $m_username, 'URL' => $url));
             $prospective_members->attach(results_entry(array($temp)));
         }
     }
     if (!$secondary_members->is_empty()) {
         $fields_title = results_field_title(array(do_lang_tempcode('SECONDARY_MEMBERS')), $sortables, 'p_sort', $sortable . ' ' . $sort_order);
         $secondary_members = results_table(do_lang_tempcode('SECONDARY_MEMBERS'), $s_start, 's_start', $s_max, 's_max', $s_max_rows, $fields_title, $secondary_members, $sortables, $sortable, $sort_order, 's_sort', NULL, NULL, NULL, 6);
     }
     if (!$prospective_members->is_empty()) {
         $fields_title = results_field_title(array(do_lang_tempcode('PROSPECTIVE_MEMBERS')), $sortables, 'p_sort', $sortable . ' ' . $sort_order);
         $prospective_members = results_table(do_lang_tempcode('PROSPECTIVE_MEMBERS'), $s_start, 's_start', $s_max, 's_max', $d_max_rows, $fields_title, $prospective_members, $sortables, $sortable, $sort_order, 'd_sort', NULL, NULL, NULL, 6);
     } elseif (has_actual_page_access(get_member(), 'cms_ocf_groups', get_module_zone('cms_ocf_groups'))) {
         $is_super_admin = $group['g_is_super_admin'];
         if (!has_specific_permission(get_member(), 'control_usergroups') || $is_super_admin == 1) {
             $leader_tmp = $group['g_group_leader'];
             if ($leader_tmp == get_member()) {
                 $edit_url = build_url(array('page' => 'cms_ocf_groups', 'type' => '_ed', 'id' => $id), get_module_zone('cms_ocf_groups'));
             }
         } else {
             $edit_url = build_url(array('page' => 'cms_ocf_groups', 'type' => '_ed', 'id' => $id), get_module_zone('cms_ocf_groups'));
         }
     }
     breadcrumb_set_self(make_string_tempcode(escape_html($name)));
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('USERGROUPS'))));
     if (has_actual_page_access(get_member(), 'admin_ocf_groups', get_module_zone('admin_ocf_groups'))) {
         $edit_url = build_url(array('page' => 'admin_ocf_groups', 'type' => '_ed', 'id' => $id), get_module_zone('admin_ocf_groups'));
     }
     $club_forum = NULL;
     if ($group['g_is_private_club'] == 1) {
         $club_forum = $GLOBALS['FORUM_DB']->query_value_null_ok('f_forums f LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON t.id=f.f_description', 'f.id', array('text_original' => do_lang('FORUM_FOR_CLUB', $name)));
     }
     $group_name = get_translated_text($group['g_name'], $GLOBALS['FORUM_DB']);
     $GLOBALS['META_DATA'] += array('created' => '', 'creator' => is_null($group['g_group_leader']) ? '' : $GLOBALS['FORUM_DRIVER']->get_username($group['g_group_leader']), 'publisher' => '', 'modified' => '', 'type' => 'Usergroup', 'title' => $group_name, 'identifier' => '_SEARCH:groups:view:' . strval($id), 'description' => '', 'image' => find_theme_image('bigicons/usergroups'));
     require_javascript('javascript_ajax');
     require_javascript('javascript_ajax_people_lists');
     $forum_id = NULL;
     if ($club) {
         $forum_id = $GLOBALS['FORUM_DB']->query_value_null_ok('f_forums', 'id', array('f_name' => $group_name, 'f_category_id' => intval(get_option('club_forum_parent_category')), 'f_parent_forum' => intval(get_option('club_forum_parent_forum'))));
     }
     return do_template('OCF_VIEW_GROUP_SCREEN', array('_GUID' => 'fc6cac5c73f92ab4410b492d58976dbe', 'GROUP_NAME' => $group_name, 'ID' => strval($id), 'FORUM' => is_null($forum_id) ? '' : strval($forum_id), 'CLUB' => $club, 'EDIT_URL' => $edit_url, 'TITLE' => $title, 'LEADER' => $leader, 'PROMOTION_INFO' => $promotion_info, 'ADD_URL' => $add_url, 'APPLY_URL' => $apply_url, 'APPLY_TEXT' => $apply_text, 'PRIMARY_MEMBERS' => $primary_members, 'SECONDARY_MEMBERS' => $secondary_members, 'PROSPECTIVE_MEMBERS' => $prospective_members));
 }
Exemplo n.º 28
0
/**
 * Get an avatar image.
 *
 * @return URLPATH		image
 */
function placeholder_avatar()
{
    return find_theme_image('ocf_default_avatars/default_set/ocp_fanatic', true);
}
Exemplo n.º 29
0
 /**
  * The actualiser to edit a zone.
  *
  * @return tempcode		The UI
  */
 function __edit_zone()
 {
     $zone = post_param('zone');
     $delete = post_param_integer('delete', 0);
     if ($delete == 1) {
         $title = get_page_title('DELETE_ZONE');
         actual_delete_zone($zone);
         // Show it worked / Refresh
         $_url = build_url(array('page' => '_SELF', 'type' => 'edit'), '_SELF');
         return redirect_screen($title, $_url, do_lang_tempcode('SUCCESS'));
     } else {
         $_title = post_param('title');
         $default_page = post_param('default_page');
         $header_text = post_param('header_text');
         $theme = post_param('theme');
         $wide = post_param_integer('wide');
         if ($wide == -1) {
             $wide = NULL;
         }
         $require_session = post_param_integer('require_session', 0);
         $displayed_in_menu = post_param_integer('displayed_in_menu', 0);
         $new_zone = post_param('new_zone');
         actual_edit_zone($zone, $_title, $default_page, $header_text, $theme, $wide, $require_session, $displayed_in_menu, $new_zone);
         if ($new_zone != '') {
             $this->set_permissions($new_zone);
         }
         $title = get_page_title('EDIT_ZONE');
         // Get title late, as we might be changing the theme this title is got from
         // Handle logos
         if (addon_installed('zone_logos')) {
             require_code('themes2');
             require_code('uploads');
             $themes = find_all_themes();
             foreach (array_keys($themes) as $theme) {
                 $iurl = '';
                 if (is_swf_upload() || array_key_exists('logo_upload_' . $theme, $_FILES) && is_uploaded_file($_FILES['logo_upload_' . $theme]['tmp_name'])) {
                     $urls = get_url('', 'logo_upload_' . $theme, 'themes/' . $theme . '/images_custom', 0, OCP_UPLOAD_IMAGE);
                     $iurl = $urls[0];
                 }
                 if ($iurl == '') {
                     $theme_img_code = post_param('logo_select_' . $theme, '');
                     if ($theme_img_code == '') {
                         continue;
                         // Probably a theme was added half-way
                         //warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN_UPLOAD'));
                     }
                     $iurl = find_theme_image($theme_img_code, false, true, $theme);
                 }
                 $GLOBALS['SITE_DB']->query_delete('theme_images', array('id' => 'logo/' . $new_zone . '-logo', 'theme' => $theme, 'lang' => get_site_default_lang()), '', 1);
                 $GLOBALS['SITE_DB']->query_insert('theme_images', array('id' => 'logo/' . $new_zone . '-logo', 'theme' => $theme, 'path' => $iurl, 'lang' => get_site_default_lang()));
                 persistant_cache_delete('THEME_IMAGES');
             }
         }
         // Show it worked / Refresh
         $url = get_param('redirect', NULL);
         if (is_null($url)) {
             $_url = build_url(array('page' => '_SELF', 'type' => 'edit'), '_SELF');
             $url = $_url->evaluate();
         }
         return redirect_screen($title, $url, do_lang_tempcode('SUCCESS'));
     }
 }
Exemplo n.º 30
0
 /**
  * Choose an emoticon for a topic.
  *
  * @param  ID_TEXT		The currently selected emoticon
  * @return tempcode		The emoticon input field
  */
 function choose_topic_emoticon($selected_path = '')
 {
     $tabindex = get_form_field_tabindex(NULL);
     $content = array();
     $extra = has_specific_permission(get_member(), 'use_special_emoticons') ? '' : ' AND e_is_special=0';
     $rows = $GLOBALS['FORUM_DB']->query('SELECT e_theme_img_code FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_emoticons WHERE e_use_topics=1' . $extra);
     $content[] = do_template('FORM_SCREEN_INPUT_RADIO_LIST_ENTRY_PICTURE_3_NA', array('_GUID' => 'd9f9399072af3f19f21695aef01168c7', 'CHECKED' => $selected_path == '', 'NAME' => 'emoticon'));
     foreach ($rows as $row) {
         $path = $row['e_theme_img_code'];
         $url = find_theme_image($path);
         $content[] = do_template('FORM_SCREEN_INPUT_RADIO_LIST_ENTRY_PICTURE_3', array('PRETTY' => '', 'CHECKED' => $path == $selected_path, 'NAME' => 'emoticon', 'CODE' => $path, 'URL' => $url));
     }
     if (count($content) == 0) {
         return new ocp_tempcode();
     }
     $_content = wrap_image_radio_list($content);
     $input = do_template('FORM_SCREEN_INPUT_RADIO_LIST', array('NAME' => 'emoticon', 'REQUIRED' => false, 'CODE' => $selected_path, 'TABINDEX' => strval($tabindex), 'CONTENT' => $_content));
     return _form_input('', do_lang_tempcode('TOPIC_EMOTICON'), '', $input, false);
 }