コード例 #1
0
ファイル: find_function.php プロジェクト: erico-deh/ocPortal
/**
 * Make the functions.dat file
 */
function make_functions_dat()
{
    $files = make_functions_dat_do_dir(get_custom_file_base());
    $classes = array();
    $global = array();
    foreach ($files as $filename) {
        if (strpos($filename, '_custom') !== false) {
            continue;
        }
        $_filename = substr($filename, strlen(get_custom_file_base()) + 1);
        if ($_filename == 'sources/minikernel.php') {
            continue;
        }
        $result = get_php_file_api($_filename, false);
        foreach ($result as $i => $r) {
            if ($r['name'] == '__global') {
                $global = array_merge($global, $r['functions']);
                unset($result[$i]);
            }
        }
        $classes = array_merge($classes, $result);
    }
    $classes['__global'] = array('functions' => $global);
    $myfile = @fopen(get_custom_file_base() . '/data_custom/functions.dat', 'wt') or intelligent_write_error(get_custom_file_base() . '/data_custom/functions.dat');
    if (fwrite($myfile, serialize($classes)) == 0) {
        warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
    }
    fclose($myfile);
}
コード例 #2
0
ファイル: splurgh.php プロジェクト: erico-deh/ocPortal
/**
 * Get a splurghified version of the specified item.
 *
 * @param  string			The name of what the key we want to reference is in our array of maps (e.g. 'id')
 * @param  array			A row of maps for data we are splurghing; this is probably just the result of $GLOBALS['SITE_DB']->query_select
 * @param  URLPATH		The stub that links will be passed through
 * @param  ID_TEXT		The page name we will be saving customised HTML under
 * @param  TIME			The time we did our last change to the data being splurghed (so it can see if we can simply decache instead of deriving)
 * @param  ?AUTO_LINK	The ID that is at the root of our tree (NULL: db_get_first_id)
 * @return string			A string of HTML that represents our splurghing (will desplurgh in the users browser)
 */
function splurgh_master_build($key_name, $map, $url_stub, $_cache_file, $last_change_time, $first_id = NULL)
{
    if (is_null($first_id)) {
        $first_id = db_get_first_id();
    }
    if (!array_key_exists($first_id, $map)) {
        return '';
    }
    if (!has_js()) {
        warn_exit(do_lang_tempcode('MSG_JS_NEEDED'));
    }
    require_javascript('javascript_splurgh');
    if (is_browser_decacheing()) {
        $last_change_time = time();
    }
    $cache_file = zone_black_magic_filterer(get_custom_file_base() . '/' . get_zone_name() . '/pages/html_custom/' . filter_naughty(user_lang()) . '/' . filter_naughty($_cache_file) . '.htm');
    if (!file_exists($cache_file) || is_browser_decacheing() || filesize($cache_file) == 0 || $last_change_time > filemtime($cache_file)) {
        $myfile = @fopen($cache_file, 'wt');
        if ($myfile === false) {
            intelligent_write_error($cache_file);
        }
        $fulltable = array();
        $splurgh = _splurgh_do_node($map, $first_id, '', $fulltable, 0);
        $page = do_template('SPLURGH', array('_GUID' => '8775edfc5a386fdf2cec69b0fc889952', 'KEY_NAME' => $key_name, 'URL_STUB' => $url_stub, 'SPLURGH' => str_replace('"', '\'', $splurgh)));
        $ev = $page->evaluate();
        if (fwrite($myfile, $ev) < strlen($ev)) {
            warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
        }
        fclose($myfile);
        fix_permissions($cache_file);
        sync_file($cache_file);
        return $ev;
    }
    return file_get_contents($cache_file, FILE_TEXT);
}
コード例 #3
0
function run()
{
    $file = basename(rawurldecode($_GET['url']));
    //get old media file data
    $get_old_file = $GLOBALS['SITE_DB']->query('SELECT url FROM ' . get_table_prefix() . 'videos WHERE url LIKE "uploads/galleries/' . rawurlencode(basename(basename($file, '.m4v'), '.mp3')) . '%"');
    $type = 'galleries';
    if (!array_key_exists(0, $get_old_file)) {
        $get_old_file = $GLOBALS['SITE_DB']->query('SELECT a_url AS url FROM ' . get_table_prefix() . 'attachments WHERE a_url LIKE "uploads/attachments/' . rawurlencode(basename(basename($file, '.m4v'), '.mp3')) . '%"');
        $type = 'attachments';
        if (!array_key_exists(0, $get_old_file)) {
            $get_old_file = $GLOBALS['SITE_DB']->query('SELECT cv_value AS url FROM ' . get_table_prefix() . 'catalogue_efv_short WHERE cv_value LIKE "uploads/catalogues/' . rawurlencode(basename(basename($file, '.m4v'), '.mp3')) . '%"');
            $type = 'catalogues';
        }
    }
    require_code('files');
    $file_handle = @fopen(get_custom_file_base() . '/uploads/' . $type . '/' . $file, 'wb') or intelligent_write_error(get_custom_file_base() . '/uploads/' . $type . '/' . $file);
    http_download_file($_GET['url'], NULL, false, false, 'ocPortal', NULL, NULL, NULL, NULL, NULL, $file_handle, NULL, NULL, 6.0);
    fclose($file_handle);
    //move the old media file to the archive directory - '/uploads/'.$type.'/archive/'
    $new_url = 'uploads/' . $type . '/' . rawurlencode($file);
    if (isset($get_old_file[0]['url']) && is_string($get_old_file[0]['url']) && $get_old_file[0]['url'] != $new_url && strlen($get_old_file[0]['url']) > 0) {
        $movedir = dirname(str_replace('/uploads/' . $type . '/', '/uploads/' . $type . '_archive_addon/', str_replace('\\', '/', get_custom_file_base()) . '/' . rawurldecode($get_old_file[0]['url'])));
        @mkdir($movedir, 0777);
        require_code('files');
        fix_permissions($movedir, 0777);
        rename(str_replace('\\', '/', get_custom_file_base()) . '/' . rawurldecode($get_old_file[0]['url']), str_replace('/uploads/' . $type . '/', '/uploads/' . $type . '_archive_addon/', str_replace('\\', '/', get_custom_file_base()) . '/' . rawurldecode($get_old_file[0]['url'])));
    }
    switch ($type) {
        case 'galleries':
            $GLOBALS['SITE_DB']->query('UPDATE ' . get_table_prefix() . 'videos SET video_width=600,video_height=400,url="' . db_escape_string($new_url) . '" WHERE url LIKE "uploads/' . $type . '/' . db_escape_string(rawurlencode(basename(basename($file, '.m4v'), '.mp3'))) . '%"');
            // Replaces row that referenced $file without .m4v on the end (the original filename) with row that references the new $file we just copied
            break;
        case 'attachments':
            $GLOBALS['SITE_DB']->query('UPDATE ' . get_table_prefix() . 'attachments SET a_url="' . db_escape_string($new_url) . '" WHERE a_url LIKE "uploads/' . $type . '/' . db_escape_string(rawurlencode(basename(basename($file, '.m4v'), '.mp3'))) . '%"');
            // Replaces row that referenced $file without .m4v on the end (the original filename) with row that references the new $file we just copied
            break;
        case 'catalogues':
            $GLOBALS['SITE_DB']->query('UPDATE ' . get_table_prefix() . 'catalogue_efv_short SET cv_value="' . db_escape_string($new_url) . '" WHERE cv_value LIKE "uploads/' . $type . '/' . db_escape_string(rawurlencode(basename(basename($file, '.m4v'), '.mp3'))) . '%"');
            // Replaces row that referenced $file without .m4v on the end (the original filename) with row that references the new $file we just copied
            break;
    }
    $transcoding_server = get_option('transcoding_server', true);
    if (is_null($transcoding_server)) {
        //add option and default value
        add_config_option('TRANSCODING_SERVER', 'transcoding_server', 'line', 'return \'http://localhost/convertor\';', 'FEATURE', 'GALLERIES');
        $transcoding_server = get_option('transcoding_server', true);
    }
    file_get_contents($transcoding_server . '/move_to_sent.php?file=' . $_GET['url']);
}
コード例 #4
0
ファイル: admin_import.php プロジェクト: erico-deh/ocPortal
 /**
  * Special import-esque function to aid switching to OCF after importing forum previously served by a forum driver.
  *
  * @return tempcode	Information about progress
  */
 function ocf_switch()
 {
     $out = new ocp_tempcode();
     $todos = array('USER' => array('member', db_get_first_id(), NULL), 'GROUP' => array('group', NULL, 'group_id'));
     foreach ($todos as $db_abstraction => $definition) {
         list($import_code, $default_id, $field_name_also) = $definition;
         $count = 0;
         $extra = is_null($field_name_also) ? '' : ' OR ' . db_string_equal_to('m_name', $field_name_also);
         $fields = $GLOBALS['SITE_DB']->query('SELECT m_table,m_name FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'db_meta WHERE (NOT (m_table LIKE \'' . db_encode_like('f_%') . '\')) AND (' . db_string_equal_to('m_type', $db_abstraction) . ' OR ' . db_string_equal_to('m_type', '*' . $db_abstraction) . ' OR ' . db_string_equal_to('m_type', '?' . $db_abstraction) . $extra . ')');
         foreach ($fields as $field) {
             if ($field['m_table'] == 'stats') {
                 continue;
             }
             // Lots of data and it's not important
             //echo '(working) '.$field['m_table'].'/'.$field['m_name'].'<br />';
             $values = $GLOBALS['SITE_DB']->query_select($field['m_table'], array('*'));
             foreach ($values as $value) {
                 $current = $value[$field['m_name']];
                 $remapped = import_id_remap_get($import_code, $current, true);
                 if (is_null($remapped)) {
                     $remapped = $default_id;
                 }
                 if (!is_null($remapped)) {
                     $value2 = $value;
                     $value2[$field['m_name']] = -$remapped;
                     $c = $GLOBALS['SITE_DB']->query_update($field['m_table'], $value2, $value, '', NULL, NULL, true, true);
                     if (is_null($c)) {
                         $GLOBALS['SITE_DB']->query_delete($field['m_table'], $value);
                     } else {
                         $count += $c;
                     }
                 } else {
                     $GLOBALS['SITE_DB']->query_delete($field['m_table'], $value);
                 }
             }
             $GLOBALS['SITE_DB']->query('UPDATE ' . $GLOBALS['SITE_DB']->get_table_prefix() . $field['m_table'] . ' SET ' . $field['m_name'] . '=-' . $field['m_name'] . ' WHERE ' . $field['m_name'] . '<0');
         }
         $out->attach(paragraph(do_lang_tempcode('OCF_CONVERTED_' . $db_abstraction, $count == 0 ? '?' : strval($count))));
     }
     // info.php
     global $FILE_BASE;
     $info_file = (file_exists('use_comp_name') ? array_key_exists('COMPUTERNAME', $_ENV) ? $_ENV['COMPUTERNAME'] : $_SERVER['SERVER_NAME'] : 'info') . '.php';
     $info = @fopen($FILE_BASE . '/' . $info_file, 'wt') or intelligent_write_error($FILE_BASE . '/' . $info_file);
     fwrite($info, "<" . "?php\n");
     global $SITE_INFO;
     $SITE_INFO['forum_type'] = 'ocf';
     $SITE_INFO['ocf_table_prefix'] = $SITE_INFO['table_prefix'];
     $SITE_INFO['db_forums'] = $SITE_INFO['db_site'];
     $SITE_INFO['db_forums_host'] = array_key_exists('db_site_host', $SITE_INFO) ? $SITE_INFO['db_site_host'] : 'localhost';
     $SITE_INFO['db_forums_user'] = $SITE_INFO['db_site_user'];
     $SITE_INFO['db_forums_password'] = $SITE_INFO['db_site_password'];
     $SITE_INFO['board_prefix'] = get_base_url();
     foreach ($SITE_INFO as $key => $val) {
         $_val = str_replace('\\', '\\\\', $val);
         fwrite($info, '$SITE_INFO[\'' . $key . '\']=\'' . $_val . "';\n");
     }
     fwrite($info, "?" . ">\n");
     fclose($info);
     fix_permissions($FILE_BASE . '/' . $info_file);
     sync_file($FILE_BASE . '/' . $info_file);
     $out->attach(paragraph(do_lang_tempcode('OCF_CONVERTED_INFO')));
     $LANG = get_site_default_lang();
     $trans5 = insert_lang(do_lang('FORUM'), 1, NULL, false, NULL, $LANG);
     $GLOBALS['SITE_DB']->query_insert('zones', array('zone_name' => 'forum', 'zone_title' => insert_lang(do_lang('SECTION_FORUMS'), 1), 'zone_default_page' => 'forumview', 'zone_header_text' => $trans5, 'zone_theme' => '-1', 'zone_wide' => NULL, 'zone_require_session' => 0, 'zone_displayed_in_menu' => 1));
     require_code('menus2');
     add_menu_item_simple('zone_menu', NULL, 'SECTION_FORUMS', 'forum' . ':forumview', 0, 1);
     return $out;
 }
コード例 #5
0
ファイル: news2.php プロジェクト: erico-deh/ocPortal
/**
 * Import wordpress db
 */
function import_wordpress_db()
{
    disable_php_memory_limit();
    $data = get_wordpress_data();
    $is_validated = post_param_integer('wp_auto_validate', 0);
    $to_own_account = post_param_integer('wp_add_to_own', 0);
    // Create members
    require_code('ocf_members_action');
    require_code('ocf_groups');
    $def_grp_id = get_first_default_group();
    $cat_id = array();
    $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('nc_owner' => NULL));
    $NEWS_CATS = list_to_map('id', $NEWS_CATS);
    foreach ($data as $values) {
        if (get_forum_type() == 'ocf') {
            $member_id = $GLOBALS['FORUM_DB']->query_value_null_ok('f_members', 'id', array('m_username' => $values['user_login']));
            if (is_null($member_id)) {
                if (post_param_integer('wp_import_wordpress_users', 0) == 1) {
                    $member_id = ocf_make_member($values['user_login'], $values['user_pass'], '', NULL, NULL, NULL, NULL, array(), NULL, $def_grp_id, 1, time(), time(), '', NULL, '', 0, 0, 1, '', '', '', 1, 0, '', 1, 1, '', NULL, '', false, 'wordpress');
                } else {
                    $member_id = $GLOBALS['FORUM_DRIVER']->get_member_from_username('admin');
                    // Set admin as owner
                    if (is_null($member_id)) {
                        $member_id = $GLOBALS['FORUM_DRIVER']->get_guest_id() + 1;
                    }
                }
            }
        } else {
            $member_id = $GLOBALS['FORUM_DRIVER']->get_guest_id();
        }
        // Guest user
        // If post should go to own account
        if ($to_own_account == 1) {
            $member_id = get_member();
        }
        if (array_key_exists('POSTS', $values)) {
            // Create posts in blog
            foreach ($values['POSTS'] as $post_id => $post) {
                if (array_key_exists('category', $post)) {
                    $cat_id = array();
                    foreach ($post['category'] as $cat_code => $category) {
                        $cat_code = NULL;
                        if ($category == 'Uncategorized') {
                            continue;
                        }
                        // Skip blank category creation
                        foreach ($NEWS_CATS as $id => $existing_cat) {
                            if (get_translated_text($existing_cat['nc_title']) == $category) {
                                $cat_code = $id;
                            }
                        }
                        if (is_null($cat_code)) {
                            $cat_code = add_news_category($category, 'newscats/community', $category);
                            $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'));
                            $NEWS_CATS = list_to_map('id', $NEWS_CATS);
                        }
                        $cat_id = array_merge($cat_id, array($cat_code));
                    }
                }
                $owner_category_id = $GLOBALS['SITE_DB']->query_value_null_ok('news_categories', 'id', array('nc_owner' => $member_id));
                if ($post['post_type'] == 'post') {
                    $id = add_news($post['post_title'], html_to_comcode($post['post_content']), NULL, $is_validated, 1, $post['comment_status'] == 'closed' ? 0 : 1, 1, '', html_to_comcode($post['post_content']), $owner_category_id, $cat_id, NULL, $member_id, 0, time(), NULL, '');
                } elseif ($post['post_type'] == 'page') {
                    // If dont have permission to write comcode page, skip the post
                    if (!has_submit_permission('high', get_member(), get_ip_address(), NULL, NULL)) {
                        continue;
                    }
                    require_code('comcode');
                    // Save articles as new comcode pages
                    $zone = filter_naughty(post_param('zone', 'site'));
                    $lang = filter_naughty(post_param('lang', 'EN'));
                    $file = preg_replace('/[^A-Za-z0-9]/', '_', $post['post_title']);
                    // Filter non alphanumeric charactors
                    $parent_page = post_param('parent_page', '');
                    $fullpath = zone_black_magic_filterer(get_custom_file_base() . '/' . $zone . '/pages/comcode_custom/' . $lang . '/' . $file . '.txt');
                    // Check existancy of new page
                    $submiter = $GLOBALS['SITE_DB']->query_value_null_ok('comcode_pages', 'p_submitter', array('the_zone' => $zone, 'the_page' => $file));
                    if (!is_null($submiter)) {
                        continue;
                    }
                    // Skip existing titled articles	- may need change
                    require_code('submit');
                    give_submit_points('COMCODE_PAGE_ADD');
                    if (!addon_installed('unvalidated')) {
                        $is_validated = 1;
                    }
                    $GLOBALS['SITE_DB']->query_insert('comcode_pages', array('the_zone' => $zone, 'the_page' => $file, 'p_parent_page' => $parent_page, 'p_validated' => $is_validated, 'p_edit_date' => NULL, 'p_add_date' => strtotime($post['post_date']), 'p_submitter' => $member_id, 'p_show_as_edit' => 0));
                    if (!file_exists($fullpath)) {
                        $_content = html_to_comcode($post['post_content']);
                        $myfile = @fopen($fullpath, 'wt');
                        if ($myfile === false) {
                            intelligent_write_error($fullpath);
                        }
                        if (fwrite($myfile, $_content) < strlen($_content)) {
                            warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
                        }
                        fclose($myfile);
                        sync_file($fullpath);
                    }
                    require_code('seo2');
                    seo_meta_set_for_explicit('comcode_page', $zone . ':' . $file, post_param('meta_keywords', ''), post_param('meta_description', ''));
                    require_code('permissions2');
                    set_page_permissions_from_environment($zone, $file);
                }
                $content_url = build_url(array('page' => 'news', 'type' => 'view', 'id' => $id), get_module_zone('news'), NULL, false, false, true);
                $content_title = $post['post_title'];
                // Add comments
                if (post_param_integer('wp_import_blog_comments', 0) == 1) {
                    if (array_key_exists('COMMENTS', $post)) {
                        $submitter = NULL;
                        foreach ($post['COMMENTS'] as $comment) {
                            $submitter = $GLOBALS['FORUM_DB']->query_value_null_ok('f_members', 'id', array('m_username' => $comment['comment_author']));
                            if (is_null($submitter)) {
                                $submitter = $GLOBALS['FORUM_DRIVER']->get_guest_id();
                            }
                            // If comment is made by a non-member, assign comment to guest account
                            $forum = is_null(get_value('comment_forum__news')) ? get_option('comments_forum_name') : get_value('comment_forum__news');
                            $result = $GLOBALS['FORUM_DRIVER']->make_post_forum_topic($forum, 'news_' . strval($id), $submitter, $post['post_title'], $comment['comment_content'], $content_title, do_lang('COMMENT'), $content_url, NULL, NULL, 1, 1, false);
                        }
                    }
                }
            }
        }
    }
}
コード例 #6
0
ファイル: install.php プロジェクト: erico-deh/ocPortal
/**
 * Test whether a file exists and is writable.
 *
 * @param  PATH			The file path
 */
function test_writable($file)
{
    if (!is_writable_wrap($file) && file_exists($file)) {
        intelligent_write_error($file);
    }
}
コード例 #7
0
 /**
  * UI for a logo wizard step (set).
  *
  * @return tempcode		The UI
  */
 function __make_logo()
 {
     $title = get_page_title('_LOGOWIZARD', true, array(integer_format(3), integer_format(3)));
     $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/logowizard';
     $theme = post_param('theme');
     // Do it
     require_code('themes2');
     $rand = uniqid('', true);
     foreach (array($theme, 'default') as $logo_save_theme) {
         $path = 'themes/' . $logo_save_theme . '/images_custom/' . $rand . '.png';
         $img = generate_logo(post_param('name'), post_param('title'), false, $logo_save_theme, 'logo-template');
         @imagepng($img, get_custom_file_base() . '/' . $path) or intelligent_write_error($path);
         imagedestroy($img);
         actual_edit_theme_image('logo/-logo', $logo_save_theme, user_lang(), 'logo/-logo', $path);
         if (addon_installed('collaboration_zone')) {
             actual_edit_theme_image('logo/collaboration-logo', $logo_save_theme, user_lang(), 'logo/collaboration-logo', $path);
         }
         $rand = uniqid('', true);
         $path = 'themes/' . $logo_save_theme . '/images_custom/' . $rand . '.png';
         $img = generate_logo(post_param('name'), post_param('title'), false, NULL, 'trimmed-logo-template');
         @imagepng($img, get_custom_file_base() . '/' . $path) or intelligent_write_error($path);
         imagedestroy($img);
         actual_edit_theme_image('logo/trimmed-logo', $logo_save_theme, user_lang(), 'logo/trimmed-logo', $path);
     }
     persistant_cache_delete('THEME_IMAGES');
     breadcrumb_set_parents(array(array('_SELF:_SELF:make_logo', do_lang_tempcode('START'))));
     $message = do_lang_tempcode('LOGOWIZARD_3_DESCRIBE', escape_html($theme));
     return inform_screen($title, $message);
 }
コード例 #8
0
ファイル: admin_config.php プロジェクト: erico-deh/ocPortal
 /**
  * The UI actualiser edit the breadcrumbs XML file.
  *
  * @return tempcode		The UI
  */
 function _xml_breadcrumbs()
 {
     $title = get_page_title('BREADCRUMB_OVERRIDES');
     $myfile = @fopen(get_custom_file_base() . '/data_custom/breadcrumbs.xml', 'wt');
     if ($myfile === false) {
         intelligent_write_error(get_custom_file_base() . '/data_custom/breadcrumbs.xml');
     }
     $xml = post_param('xml');
     if (fwrite($myfile, $xml) < strlen($xml)) {
         warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
     }
     fclose($myfile);
     fix_permissions(get_custom_file_base() . '/data_custom/breadcrumbs.xml');
     sync_file(get_custom_file_base() . '/data_custom/breadcrumbs.xml');
     return inform_screen($title, do_lang_tempcode('SUCCESS'));
 }
コード例 #9
0
ファイル: filedump.php プロジェクト: erico-deh/ocPortal
 /**
  * The actualiser for deleting a file.
  *
  * @return tempcode	The UI.
  */
 function module_do_delete_file()
 {
     $title = get_page_title('FILEDUMP_DELETE_FILE');
     $file = filter_naughty(get_param('file'));
     $place = filter_naughty(get_param('place'));
     breadcrumb_set_parents(array(array('_SELF:_SELF', do_lang_tempcode('FILE_DUMP'))));
     if (post_param_integer('confirmed', 0) != 1) {
         $url = get_self_url();
         $text = do_lang_tempcode('CONFIRM_DELETE', $file);
         breadcrumb_set_self(do_lang_tempcode('CONFIRM'));
         $hidden = build_keep_post_fields();
         $hidden->attach(form_input_hidden('confirmed', '1'));
         return do_template('CONFIRM_SCREEN', array('_GUID' => '19503cf5dc795b9c85d26702b79e3202', 'TITLE' => $title, 'FIELDS' => $hidden, 'PREVIEW' => $text, 'URL' => $url));
     }
     $owner = $GLOBALS['SITE_DB']->query_value_null_ok('filedump', 'the_member', array('name' => $file, 'path' => $place));
     if (!is_null($owner) && $owner == get_member() || has_specific_permission(get_member(), 'delete_anything_filedump')) {
         $test = $GLOBALS['SITE_DB']->query_value_null_ok('filedump', 'description', array('name' => $file, 'path' => $place));
         if (!is_null($test)) {
             delete_lang($test);
         }
         $path = get_custom_file_base() . '/uploads/filedump' . $place . $file;
         @unlink($path) or intelligent_write_error($path);
         sync_file('uploads/filedump/' . $file);
     } else {
         access_denied('I_ERROR');
     }
     $return_url = build_url(array('page' => '_SELF', 'type' => 'misc', 'place' => $place), '_SELF');
     log_it('FILEDUMP_DELETE_FILE', $file, $place);
     return redirect_screen($title, $return_url, do_lang_tempcode('SUCCESS'));
 }
コード例 #10
0
 /**
  * The actualiser to import in bulk from an archive file.
  *
  * @return tempcode		The UI
  */
 function _import()
 {
     post_param('test');
     // To pick up on max file size exceeded errors
     require_code('uploads');
     require_code('images');
     is_swf_upload(true);
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('EMOTICONS')), array('_SELF:_SELF:import', do_lang_tempcode('CHOOSE')), array('_SELF:_SELF:import', do_lang_tempcode('IMPORT_EMOTICONS'))));
     foreach ($_FILES as $attach_name => $__file) {
         $tmp_name = $__file['tmp_name'];
         $file = $__file['name'];
         switch (get_file_extension($file)) {
             case 'zip':
                 if (!function_exists('zip_open') && get_option('unzip_cmd') == '') {
                     warn_exit(do_lang_tempcode('ZIP_NOT_ENABLED'));
                 }
                 if (!function_exists('zip_open')) {
                     require_code('m_zip');
                     $mzip = true;
                 } else {
                     $mzip = false;
                 }
                 $myfile = zip_open($tmp_name);
                 if (!is_integer($myfile)) {
                     while (false !== ($entry = zip_read($myfile))) {
                         // Load in file
                         zip_entry_open($myfile, $entry);
                         $_file = zip_entry_name($entry);
                         if (is_image($_file)) {
                             if (file_exists(get_file_base() . '/themes/default/images/emoticons/index.html')) {
                                 $path = get_custom_file_base() . '/themes/default/images_custom/emoticons__' . basename($_file);
                             } else {
                                 $path = get_custom_file_base() . '/themes/default/images_custom/ocf_emoticons__' . basename($_file);
                             }
                             $outfile = @fopen($path, 'wb') or intelligent_write_error($path);
                             $more = mixed();
                             do {
                                 $more = zip_entry_read($entry);
                                 if (fwrite($outfile, $more) < strlen($more)) {
                                     warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
                                 }
                             } while ($more !== false && $more != '');
                             fclose($outfile);
                             fix_permissions($path);
                             sync_file($path);
                             $this->_import_emoticon($path);
                         }
                         zip_entry_close($entry);
                     }
                     zip_close($myfile);
                 } else {
                     require_code('failure');
                     warn_exit(zip_error($myfile, $mzip));
                 }
                 break;
             case 'tar':
                 require_code('tar');
                 $myfile = tar_open($tmp_name, 'rb');
                 if ($myfile !== false) {
                     $directory = tar_get_directory($myfile);
                     foreach ($directory as $entry) {
                         // Load in file
                         $_file = $entry['path'];
                         if (is_image($_file)) {
                             if (file_exists(get_file_base() . '/themes/default/images/emoticons/index.html')) {
                                 $path = get_custom_file_base() . '/themes/default/images_custom/emoticons__' . basename($_file);
                             } else {
                                 $path = get_custom_file_base() . '/themes/default/images_custom/ocf_emoticons__' . basename($_file);
                             }
                             $_in = tar_get_file($myfile, $entry['path'], false, $path);
                             $this->_import_emoticon($path);
                         }
                     }
                     tar_close($myfile);
                 }
                 break;
             default:
                 if (is_image($file)) {
                     $urls = get_url('', $attach_name, 'themes/default/images_custom');
                     $path = $urls[0];
                     $this->_import_emoticon($path);
                 } else {
                     attach_message(do_lang_tempcode('BAD_ARCHIVE_FORMAT'), 'warn');
                 }
         }
     }
     $title = get_page_title('IMPORT_EMOTICONS');
     log_it('IMPORT_EMOTICONS');
     return $this->do_next_manager($title, do_lang_tempcode('SUCCESS'), NULL);
 }
コード例 #11
0
ファイル: admin_zones.php プロジェクト: erico-deh/ocPortal
 /**
  * The actualiser to edit a zone (via zone editor).
  *
  * @return tempcode		The UI
  */
 function __editor()
 {
     $title = get_page_title('ZONE_EDITOR');
     $lang = choose_language($title, true);
     if (is_object($lang)) {
         return $lang;
     }
     $id = get_param('id', '');
     // Edit settings
     $_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);
     actual_edit_zone($id, $_title, $default_page, $header_text, $theme, $wide, $require_session, $displayed_in_menu, $id);
     if ($id != '') {
         $this->set_permissions($id);
     }
     // Edit pages
     foreach (array('panel_left', 'start', 'panel_right') as $for) {
         $redirect = post_param('redirect_' . $for, NULL);
         if (!is_null($redirect)) {
             if (addon_installed('redirects_editor')) {
                 $GLOBALS['SITE_DB']->query_delete('redirects', array('r_from_page' => $for, 'r_from_zone' => $id), '', 1);
                 if ($redirect != $id) {
                     $GLOBALS['SITE_DB']->query_insert('redirects', array('r_from_page' => $for, 'r_from_zone' => $id, 'r_to_page' => $for, 'r_to_zone' => $redirect, 'r_is_transparent' => 1), false, true);
                     // Avoid problem when same key entered twice
                 } else {
                     $redirect = NULL;
                 }
             } else {
                 $redirect = NULL;
             }
         }
         $comcode = post_param($for, NULL);
         if (!is_null($comcode)) {
             // Where to save to
             $fullpath = zone_black_magic_filterer(get_custom_file_base() . ((is_null($redirect) ? $id : $redirect) == '' ? '' : '/') . (is_null($redirect) ? $id : $redirect) . '/pages/comcode_custom/' . $lang . '/' . $for . '.txt');
             // Make dir if needed
             if (!file_exists(dirname($fullpath))) {
                 if (@mkdir(dirname($fullpath), 0777) === false) {
                     warn_exit(do_lang_tempcode('WRITE_ERROR_DIRECTORY_REPAIR', escape_html(basename(dirname($fullpath))), escape_html(dirname(dirname($fullpath)))));
                 }
                 fix_permissions(dirname($fullpath), 0777);
                 sync_file(dirname($fullpath));
             }
             // Store revision
             if (file_exists($fullpath) && get_option('store_revisions') == '1') {
                 $time = time();
                 @copy($fullpath, $fullpath . '.' . strval($time)) or intelligent_write_error($fullpath . '.' . strval($time));
                 fix_permissions($fullpath . '.' . strval($time));
                 sync_file($fullpath . '.' . strval($time));
             }
             // Save
             $myfile = @fopen($fullpath, 'wt') or intelligent_write_error($fullpath);
             if (fwrite($myfile, $comcode) < strlen($comcode)) {
                 warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
             }
             fclose($myfile);
             fix_permissions($fullpath);
             sync_file($fullpath);
             // De-cache
             $caches = $GLOBALS['SITE_DB']->query_select('cached_comcode_pages', array('string_index'), array('the_zone' => is_null($redirect) ? $id : $redirect, 'the_page' => $for));
             foreach ($caches as $cache) {
                 delete_lang($cache['string_index']);
             }
             $GLOBALS['SITE_DB']->query_delete('cached_comcode_pages', array('the_zone' => is_null($redirect) ? $id : $redirect, 'the_page' => $for));
         }
     }
     persistant_cache_empty();
     // Redirect
     $url = get_param('redirect');
     return redirect_screen($title, $url, do_lang_tempcode('SUCCESS'));
 }
コード例 #12
0
ファイル: global2.php プロジェクト: erico-deh/ocPortal
/**
 * Get tempcode to tie in (to the HTML, in <head>) all the Javascript files that have been required.
 *
 * @param  ?string		Position to get Javascript for (NULL: all positions)
 * @set NULL header footer
 * @return tempcode		The tempcode to tie in the Javascript files
 */
function javascript_tempcode($position = NULL)
{
    global $JAVASCRIPTS, $JAVASCRIPT;
    $js = new ocp_tempcode();
    $minify = get_param_integer('keep_no_minify', 0) == 0;
    $https = get_option('enable_https', true) == '1' && function_exists('is_page_https') && function_exists('get_zone_name') && (tacit_https() || is_page_https(get_zone_name(), get_page_name()));
    $mobile = is_mobile();
    // Special merge operation for staff. In truth it's to get a better score on Google Page Speed ;)
    $to_merge = array('javascript_staff', 'javascript_button_occle', 'javascript_fractional_edit');
    $good_to_merge = true;
    foreach ($to_merge as $j) {
        if (!array_key_exists($j, $JAVASCRIPTS)) {
            $good_to_merge = false;
        }
    }
    if ($good_to_merge) {
        $j = 'javascript_staff___merged';
        if (!$minify) {
            $j .= '_non_minified';
        }
        if ($https) {
            $j .= '_ssl';
        }
        if ($mobile) {
            $j .= '_mobile';
        }
        $theme = filter_naughty($GLOBALS['FORUM_DRIVER']->get_theme());
        $dir = get_custom_file_base() . '/themes/' . $theme . '/templates_cached/' . filter_naughty(user_lang());
        $write_path = $dir . '/' . filter_naughty_harsh($j);
        $write_path .= '.js';
        /*$rebuild=false;	Performance hit
        		foreach ($to_merge as $j2)
        		{
        			$merge_from=javascript_enforce($j2);
        			if (filemtime($merge_from)==time()) $rebuild=true; // Hmm, just recalculated
        		}*/
        if (!is_file($write_path)) {
            $data = '';
            foreach ($to_merge as $j2) {
                $merge_from = javascript_enforce($j2);
                if (is_file($merge_from)) {
                    $data .= unixify_line_format(file_get_contents($merge_from, FILE_TEXT));
                } else {
                    $good_to_merge = false;
                    break;
                }
            }
            if ($good_to_merge) {
                $myfile = @fopen($write_path, 'wb') or intelligent_write_error($write_path);
                // Intentionally wb to stop line ending conversions on Windows
                fwrite($myfile, $data);
                fclose($myfile);
                fix_permissions($write_path, 0777);
                sync_file($write_path);
            }
        }
        if ($good_to_merge) {
            if ($position != 'header') {
                $js->attach(do_template('JAVASCRIPT_NEED', array('CODE' => $j)));
            }
        }
    }
    // Our main loop
    $bottom_ones = array('javascript_staff' => 1, 'javascript_button_occle' => 1, 'javascript_fractional_edit' => 1, 'javascript_thumbnails' => 1, 'javascript_button_realtime_rain' => 1);
    foreach (array_keys($JAVASCRIPTS) as $j) {
        if ($good_to_merge && in_array($j, $to_merge)) {
            continue;
        }
        if ($position !== NULL) {
            $bottom = isset($bottom_ones[$j]);
            // TODO: progmattic way of saying this at point of calls
            if ($position == 'header' && $bottom) {
                continue;
            }
            if ($position == 'footer' && !$bottom) {
                continue;
            }
        }
        $temp = javascript_enforce($j);
        if ($temp != '') {
            if (!$minify) {
                $j .= '_non_minified';
            }
            if ($https) {
                $j .= '_ssl';
            }
            if ($mobile) {
                $j .= '_mobile';
            }
            $js->attach(do_template('JAVASCRIPT_NEED', array('_GUID' => 'b5886d9dfc4d528b7e1b0cd6f0eb1670', 'CODE' => $j)));
        }
    }
    if (!is_null($JAVASCRIPT)) {
        $js->attach($JAVASCRIPT);
    }
    return $js;
}
コード例 #13
0
/**
 * A template has not been structurally cached, so compile it and store in the cache.
 *
 * @param  ID_TEXT			The theme the template is in the context of
 * @param  PATH				The path to the template file
 * @param  ID_TEXT			The codename of the template (e.g. foo)
 * @param  ID_TEXT			The actual codename to use for the template (e.g. foo_mobile)
 * @param  LANGUAGE_NAME	The language the template is in the context of
 * @param  string				File type suffix of template file (e.g. .tpl)
 * @param  ?ID_TEXT			The theme to cache in (NULL: main theme)
 * @return tempcode			The compiled tempcode
 */
function _do_template($theme, $path, $codename, $_codename, $lang, $suffix, $theme_orig = NULL)
{
    if (is_null($theme_orig)) {
        $theme_orig = $theme;
    }
    if (is_null($GLOBALS['CURRENT_SHARE_USER'])) {
        $base_dir = ($theme == 'default' && ($suffix != '.css' || strpos($path, '/css_custom') === false) ? get_file_base() : get_custom_file_base()) . '/themes/';
    } else {
        $base_dir = get_custom_file_base() . '/themes/';
        if (!is_file($base_dir . $theme . $path . $codename . $suffix)) {
            $base_dir = get_file_base() . '/themes/';
        }
    }
    global $CACHE_TEMPLATES, $FILE_ARRAY, $TEMPLATE_PREVIEW_OP, $MEM_CACHE;
    if (isset($FILE_ARRAY)) {
        $html = unixify_line_format(file_array_get('themes/' . $theme . $path . $codename . $suffix));
    } else {
        $html = unixify_line_format(file_get_contents($base_dir . filter_naughty($theme . $path . $codename) . $suffix, FILE_TEXT));
    }
    if ($GLOBALS['SEMI_DEBUG_MODE'] && strpos($html, '.innerHTML') !== false && !running_script('install') && strpos($html, 'Parser hint: .innerHTML okay') === false) {
        attach_message('Do not use the .innerHTML property in your Javascript because it will not work in true XHTML (when the browsers real XML parser is in action). Use ocPortal\'s global setInnerHTML/getInnerHTML functions.', 'warn');
    }
    // Strip off trailing final lines from single lines templates. Editors often put these in, and it causes annoying "visible space" issues
    if (substr($html, -1, 1) == chr(10) && substr_count($html, chr(10)) == 1) {
        $html = substr($html, 0, strlen($html) - 1);
    }
    if ($TEMPLATE_PREVIEW_OP) {
        $test = post_param($codename, NULL);
        if (!is_null($test)) {
            $html = post_param($test . '_new');
        }
    }
    $result = template_to_tempcode($html, 0, false, $suffix != '.tpl' ? '' : $codename, $theme_orig, $lang);
    if ($CACHE_TEMPLATES && !$TEMPLATE_PREVIEW_OP && ($suffix == '.tpl' || $codename == 'no_cache')) {
        $path2 = get_custom_file_base() . '/themes/' . $theme_orig . '/templates_cached/' . filter_naughty($lang) . '/';
        $myfile = @fopen($path2 . filter_naughty($_codename) . $suffix . '.tcp', 'wb');
        if ($myfile === false) {
            @mkdir(dirname($path2), 0777);
            fix_permissions(dirname($path2), 0777);
            sync_file(dirname($path2));
            if (@mkdir($path2, 0777)) {
                fix_permissions($path2, 0777);
                sync_file($path2);
            } else {
                if ($codename == 'SCREEN_TITLE') {
                    critical_error('PASSON', do_lang('WRITE_ERROR', escape_html($path2 . filter_naughty($_codename) . $suffix . '.tcp')));
                }
                // Bail out hard if would cause a loop
                intelligent_write_error($path2 . filter_naughty($_codename) . $suffix . '.tcp');
            }
        } else {
            $data_to_write = '<' . '?php' . chr(10) . $result->to_assembly($lang) . chr(10) . '?' . '>';
            if (fwrite($myfile, $data_to_write) >= strlen($data_to_write)) {
                // Success
                fclose($myfile);
                require_code('files');
                fix_permissions($path2 . filter_naughty($_codename) . $suffix . '.tcp');
            } else {
                // Failure
                fclose($myfile);
                @unlink($path2 . filter_naughty($_codename) . $suffix . '.tcp');
                // Can't leave this around, would cause problems
            }
        }
    }
    return $result;
}
コード例 #14
0
ファイル: mkportal.php プロジェクト: erico-deh/ocPortal
 /**
  * Standard import function.
  *
  * @param  object			The DB connection to import from
  * @param  string			The table prefix the target prefix is using
  * @param  PATH			The base directory we are importing from
  */
 function import_blocks($db, $table_prefix, $old_base_dir)
 {
     require_code('menus2');
     //start importing PHP blocks
     $rows = $db->query('SELECT * FROM ' . $table_prefix . 'blocks WHERE ' . db_string_not_equal_to('file', '') . ' AND ' . db_string_equal_to('active', 'checked') . ' ORDER BY progressive ASC');
     foreach (array('', '/site') as $zone) {
         $left_panel = get_file_base() . $zone . '/pages/comcode_custom/' . get_site_default_lang() . '/panel_left.txt';
         $right_panel = get_file_base() . $zone . '/pages/comcode_custom/' . get_site_default_lang() . '/panel_right.txt';
         $center_panel = get_file_base() . $zone . '/pages/comcode_custom/' . get_site_default_lang() . '/start.txt';
         //ensure that there is custom left panel
         if (!file_exists($left_panel)) {
             $source_path = get_file_base() . $zone . '/pages/comcode/' . get_site_default_lang() . '/panel_left.txt';
             if (file_exists($source_path)) {
                 copy($source_path, $left_panel);
             } else {
                 //create file
                 $myfile = @fopen($left_panel, 'w');
                 if ($myfile !== false) {
                     fwrite($myfile, '');
                     fclose($myfile);
                 }
             }
         }
         //ensure that there is custom right panel
         if (!file_exists($right_panel)) {
             $source_path = get_file_base() . $zone . '/pages/comcode/' . get_site_default_lang() . '/panel_right.txt';
             if (file_exists($source_path)) {
                 copy($source_path, $right_panel);
             } else {
                 //create file
                 $myfile = @fopen($right_panel, 'w');
                 if ($myfile !== false) {
                     fwrite($myfile, '');
                     fclose($myfile);
                 }
             }
         }
         //ensure that there is custom start panel
         if (!file_exists($center_panel)) {
             $source_path = get_file_base() . $zone . '/pages/comcode/' . get_site_default_lang() . '/start.txt';
             if (file_exists($source_path)) {
                 copy($source_path, $center_panel);
             } else {
                 //create file
                 $myfile = @fopen($center_panel, 'wt');
                 if ($myfile !== false) {
                     fwrite($myfile, '');
                     fclose($myfile);
                 }
             }
         }
         //blocks remap array
         $blocks_remap = array('Online Users' => 'side_users_online', 'online_home' => 'side_users_online', 'Calendar' => 'side_calendar', 'last_downloads' => 'main_recent_downloads', 'Latest News' => 'main_news', 'Site Stats' => 'side_stats', 'Random Image' => 'main_iotd', 'random_quote' => 'main_quotes', 'poll' => 'main_poll', 'search' => 'main_search', 'Lang' => 'side_language', 'Boardnews' => 'main_forum_news', 'Last Shouts' => 'side_shoutbox');
         //go through all of the PHP blocks
         foreach ($rows as $row) {
             //find whether it is left (position=sinistra), center (position=centro), or right (position=destra).
             $position = $row['position'] == 'sinistra' ? $left_panel : ($row['position'] == 'destra' ? $right_panel : $center_panel);
             $middle = $position == $center_panel;
             $orig_block = $row['title'];
             //ignore blocks that could not be remapped
             if (!isset($blocks_remap[$row['title']]) || strlen($blocks_remap[$row['title']]) == 0) {
                 $exceptions = array('Board Menu', 'Personal Menu', 'last_blog_post', 'last_forum_post', 'Latest News');
                 //skip next steps, if not needed
                 if (!in_array($orig_block, $exceptions)) {
                     continue;
                 }
                 //board menu
                 if ($orig_block == 'Board Menu') {
                     //get position block content
                     $contents = @file_get_contents($position);
                     if ($contents === false) {
                         continue;
                     }
                     //if the block is not set we need to include it at the end
                     if (preg_match('/forum_features/im', $contents) == 0) {
                         $myfile = @fopen($position, 'at+');
                         if ($myfile === false) {
                             continue;
                         }
                         $out = '';
                         $out .= chr(10) . ($middle ? chr(10) : '') . '[block="forum_features" type="tree" caption="Forums"]side_stored_menu[/block]';
                         fwrite($myfile, $out);
                         //add block to the appropiate position in the end of the file
                         fclose($myfile);
                     }
                 }
                 //personal menu
                 if ($orig_block == 'Personal Menu') {
                     //get position block content
                     $contents = @file_get_contents($position);
                     if ($contents === false) {
                         continue;
                     }
                     //if the block is not set we need to include it at the end
                     if (preg_match('/pc_features/im', $contents) == 0) {
                         $myfile = @fopen($position, 'at+');
                         if ($myfile === false) {
                             continue;
                         }
                         $out = '';
                         $out .= chr(10) . ($middle ? chr(10) : '') . '[block="pc_features" type="tree" caption="My stuff"]side_stored_menu[/block]';
                         fwrite($myfile, $out);
                         //add block to the appropiate position in the end of the file
                         fclose($myfile);
                     }
                     //if the block is not set we need to include it at the end
                     if (preg_match('/pc_edit/im', $contents) == 0) {
                         $myfile = @fopen($position, 'at+');
                         if ($myfile === false) {
                             continue;
                         }
                         $out = '';
                         $out .= chr(10) . ($middle ? chr(10) : '') . '[block="pc_edit" type="tree" caption="Settings" silent_failure="1"]side_stored_menu[/block]';
                         fwrite($myfile, $out);
                         //add block to the appropiate position in the end of the file
                         fclose($myfile);
                     }
                 }
                 //last blog post
                 if ($orig_block == 'last_blog_post') {
                     //get position block content
                     $contents = @file_get_contents($position);
                     if ($contents === false) {
                         continue;
                     }
                     //if the block is not set we need to include it at the end
                     if (preg_match('/Last\\sblog\\spost/im', $contents) == 0) {
                         $myfile = @fopen($position, 'at+');
                         if ($myfile === false) {
                             continue;
                         }
                         $out = '';
                         $out .= chr(10) . ($middle ? chr(10) : '') . '[block="1" blogs="1" title="Last blog post"]side_news[/block]';
                         fwrite($myfile, $out);
                         //add block to the appropiate position in the end of the file
                         fclose($myfile);
                     }
                 }
                 //news
                 if ($orig_block == 'Latest News') {
                     //get position block content
                     $contents = @file_get_contents($position);
                     if ($contents === false) {
                         continue;
                     }
                     //if the block is not set we need to include it at the end
                     if (preg_match('/main\\_news/', $contents) == 0) {
                         $myfile = @fopen($position, 'at+');
                         if ($myfile === false) {
                             continue;
                         }
                         $out = '';
                         $out .= chr(10) . ($middle ? chr(10) : '') . '[block blogs="0"]main_news[/block]';
                         fwrite($myfile, $out);
                         //add block to the appropiate position in the end of the file
                         fclose($myfile);
                     }
                 }
                 //last forum posts
                 if ($orig_block == 'last_forum_post') {
                     //get position block content
                     $contents = @file_get_contents($position);
                     if ($contents === false) {
                         continue;
                     }
                     //if the block is not set we need to include it at the end
                     if (preg_match('/Last\\sforum\\spost/im', $contents) == 0) {
                         $myfile = @fopen($position, 'at+');
                         if ($myfile === false) {
                             continue;
                         }
                         $out = '';
                         $out .= chr(10) . ($middle ? chr(10) : '') . '[block="General chat" title="Last forum post"]main_forum_topics[/block]';
                         fwrite($myfile, $out);
                         //add block to the appropiate position in the end of the file
                         fclose($myfile);
                     }
                 }
                 continue;
             }
             $remapped_block = $blocks_remap[$row['title']];
             $contents = @file_get_contents($position);
             if ($contents === false) {
                 continue;
             }
             //if the block is not set we need to include it at the end
             if (preg_match('/' . $remapped_block . '/im', $contents) == 0) {
                 $myfile = @fopen($position, 'at+');
                 if ($myfile === false) {
                     continue;
                 }
                 $out = '';
                 $out .= chr(10) . ($middle ? chr(10) : '') . '[block]' . $remapped_block . '[/block]';
                 fwrite($myfile, $out);
                 //add block to the appropiate position in the end of the file
                 fclose($myfile);
             }
         }
         //get pinned category id
         $pinned_news_cat_id = $this->get_news_category_id(do_lang('PINNED_NEWS'), '');
         $pinned_news = $GLOBALS['SITE_DB']->query_value_null_ok('news', 'id', array('news_category' => $pinned_news_cat_id));
         if (!is_null($pinned_news)) {
             //add pinned news module at the top of the center panel (start.txt)
             $contents = @file_get_contents($center_panel);
             if ($contents === false) {
                 $contents = '';
             }
             $myfile = @fopen($center_panel, 'wt+');
             if ($myfile !== false) {
                 //prepare the content to be written
                 $out = '';
                 //just to ensure
                 $out .= '[block="10000" blogs="0" filter="' . $pinned_news_cat_id . '" title="' . do_lang('PINNED_NEWS') . '"]main_news[/block]' . (chr(10) . ($middle ? chr(10) : '')) . $contents;
                 //fseek($myfile, 0); //set the pointer at the start of the file
                 fwrite($myfile, $out);
                 //write the content of the from it's start
                 fclose($myfile);
                 //close file
             }
         }
         fix_permissions($left_panel);
         fix_permissions($right_panel);
         fix_permissions($center_panel);
         sync_file($left_panel);
         sync_file($right_panel);
         sync_file($center_panel);
     }
     //start importing PHP blocks
     $rows = $db->query('SELECT * FROM ' . $table_prefix . 'blocks WHERE ' . db_string_equal_to('file', '') . ' AND ' . db_string_equal_to('active', 'checked') . ' ORDER BY progressive ASC');
     //go through all of the non-PHP blocks
     foreach ($rows as $row) {
         if (preg_match('/class="mkicon"/im', $row['content']) != 0) {
             //it is a links block
             $matches = array();
             preg_match_all('/href=\\"(.*)\\".*>(.*)<\\/a>/Uim', $row['content'], $matches);
             $matches_url = isset($matches[1]) && is_array($matches[1]) ? $matches[1] : array();
             $matches_titles = isset($matches[2]) && is_array($matches[2]) ? $matches[2] : array();
             $block_title = @html_entity_decode($row['title'], ENT_QUOTES, get_charset());
             $out = chr(10) . '[block="mkp_block_' . strval($row['id']) . '" type="tree" caption="' . comcode_escape($block_title) . '"]side_stored_menu[/block]';
             $left_panel_contents = file_get_contents($left_panel);
             if (strpos($left_panel_contents, $out) === false) {
                 $myfile = @fopen($left_panel, 'at');
                 if ($myfile !== false) {
                     fwrite($myfile, $out);
                     //write the content of the from it's start
                     fclose($myfile);
                     //close file
                 }
                 fix_permissions($left_panel);
                 sync_file($left_panel);
             }
             //if there are urls to be changed
             if (count($matches_url) > 0) {
                 foreach ($matches_url as $key => $url) {
                     $link_title = isset($matches_titles[$key]) && strlen($matches_titles[$key]) > 0 ? $matches_titles[$key] : '';
                     $_url_match = array();
                     preg_match('/pid=.*/i', $url, $_url_match);
                     $url_match = isset($_url_match[0]) && strlen($_url_match[0]) > 0 ? $_url_match[0] : '';
                     $url_match = preg_replace('/pid=/', '', $url_match);
                     add_menu_item_simple('mkp_block_' . strval($row['id']), NULL, html_entity_decode($link_title, ENT_QUOTES, get_charset()), ':pn' . $url_match);
                 }
             }
         } else {
             //it is not a links block, so we write it into a new page
             $page_title = $row['title'];
             $page = '';
             $c_dir = get_custom_file_base() . '/pages/comcode_custom/' . get_site_default_lang() . '/';
             $comcode_pages_title = do_lang('COMCODE_PAGES');
             //get other custom comcode pages names
             $older_comcode_files = array();
             $d = opendir($c_dir);
             while (false !== ($entry = readdir($d))) {
                 if (preg_match('/pn.*\\.txt/', $entry) != 0) {
                     $arr_index = intval(preg_replace('/pn|\\.txt/', '', $entry));
                     $older_comcode_files[$arr_index] = $arr_index;
                 }
             }
             closedir($d);
             ksort($older_comcode_files);
             //get the highest comcode page id
             $max_index = end($older_comcode_files);
             $max_index = is_null($max_index) ? 1 : $max_index;
             $page .= ' - [page caption="' . $page_title . '"]pn' . strval($max_index + 1) . '[/page]' . chr(10);
             $page2 = do_template('IMPORT_MKPORTAL_FCOMCODEPAGE', array('TITLE' => $page_title, 'SUBTITLE' => '', 'PAGE_HEADER' => '', 'TEXT' => $page, 'PAGE_FOOTER' => '', 'SIGNATURE' => ''));
             //save the comcode file
             $path = $c_dir . 'pn' . strval($max_index + 1) . '.txt';
             $myfile = @fopen($path, 'at');
             if ($myfile === false) {
                 intelligent_write_error($path);
             }
             fwrite($myfile, $page2->evaluate());
             fclose($myfile);
             fix_permissions($path);
             sync_file($path);
             //add info about comcode file
             $path = $c_dir . 'pnindex.txt';
             $myfile = @fopen($path, 'at');
             if ($myfile === false) {
                 intelligent_write_error($path);
             }
             fwrite($myfile, $page);
             fclose($myfile);
             fix_permissions($path);
             sync_file($path);
         }
     }
 }
コード例 #15
0
ファイル: admin_themes.php プロジェクト: erico-deh/ocPortal
    /**
     * The actualiser to edit a template. Always saves to the most overridden version.
     *
     * @return tempcode		The UI
     */
    function __edit_templates()
    {
        // Erase cache
        $theme = filter_naughty(post_param('theme'));
        //if ((get_file_base()!=get_custom_file_base()) && ($theme=='default')) warn_exit(do_lang_tempcode('SHARED_INSTALL_PROHIBIT'));
        erase_cached_templates();
        require_code('view_modes');
        erase_tempcode_cache();
        $title = get_page_title('EDIT_TEMPLATES');
        foreach (array_keys($_REQUEST) as $_i) {
            $matches = array();
            if (preg_match('#f(\\d+)file#', $_i, $matches) != 0) {
                $i = $matches[1];
            } else {
                continue;
            }
            $_file = substr(str_replace('/default/', '/' . $theme . '/', '/' . filter_naughty(post_param('f' . $i . 'file', ''))), 1);
            if ($_file == '') {
                continue;
            }
            if (!is_null($GLOBALS['CURRENT_SHARE_USER']) && strpos($_file, 'BANNER_TYPED') !== false) {
                warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
            }
            $file = str_replace('templates/', 'templates_custom/', $_file);
            $file = str_replace('css/', 'css_custom/', $file);
            $fullpath = get_custom_file_base() . '/themes/' . $file;
            // Make backup
            if (file_exists($fullpath) && get_option('templates_store_revisions') == '1') {
                @copy($fullpath, $fullpath . '.' . strval(time())) or intelligent_write_error($fullpath . '.' . strval(time()));
                fix_permissions($fullpath . '.' . strval(time()));
                sync_file($fullpath . '.' . strval(time()));
            }
            // Save
            $new = post_param('f' . $i . '_new', false, true);
            $fullpath_orig = preg_replace('#/themes/[^/]*/(.*)(\\_custom)?/#U', '/themes/default/${1}/', $fullpath);
            if (file_exists($fullpath_orig) && $new == file_get_contents($fullpath_orig)) {
                if (file_exists($fullpath)) {
                    unlink($fullpath);
                    sync_file($fullpath);
                }
                if (file_exists($fullpath . '.editfrom')) {
                    unlink($fullpath . '.editfrom');
                    sync_file($fullpath . '.editfrom');
                }
                $_file = preg_replace('#[^/]*/(.*)(\\_custom)?/#U', 'default/${1}/', $_file);
                $file = $_file;
            } else {
                $myfile = @fopen($fullpath, 'wt');
                if ($myfile === false) {
                    intelligent_write_error($fullpath);
                }
                if (fwrite($myfile, $new) < strlen($new)) {
                    fclose($myfile);
                    unlink($fullpath);
                    warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
                }
                fclose($myfile);
                fix_permissions($fullpath);
                sync_file($fullpath);
                if (file_exists(get_file_base() . '/themes/' . post_param('f' . $i . 'file'))) {
                    // Make base-hash-thingy
                    $myfile = @fopen($fullpath . '.editfrom', 'wt');
                    if ($myfile === false) {
                        intelligent_write_error($fullpath);
                    }
                    $hash = file_get_contents(get_file_base() . '/themes/' . post_param('f' . $i . 'file'), FILE_TEXT);
                    if (fwrite($myfile, $hash) < strlen($hash)) {
                        warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
                    }
                    fclose($myfile);
                    fix_permissions($fullpath . '.editfrom');
                    sync_file($fullpath . '.editfrom');
                }
            }
            log_it('EDIT_TEMPLATES', $file, $theme);
        }
        breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('MANAGE_THEMES')), array('_SELF:_SELF:edit_templates:theme=' . $theme, do_lang_tempcode('CHOOSE')), array('_SELF:_SELF:_edit_templates:theme=' . $theme . ':file=' . $file, do_lang_tempcode('EDIT_TEMPLATES'))));
        breadcrumb_set_self(do_lang_tempcode('DONE'));
        if (get_param_integer('save_and_stay', 0) == 1) {
            return inform_screen($title, protect_from_escaping('
				<script type="text/javascript">// <![CDATA[
					window.fauxmodal_alert(\'' . addslashes(do_lang('SUCCESS')) . '\');
				//]]></script>
			'));
        }
        return $this->do_next_manager($title, do_lang_tempcode('SUCCESS'), $theme, '', 'templates', $file);
    }
コード例 #16
0
/**
 * Function to process the file upload process
 */
function incoming_uploads_script()
{
    $is_uploaded = false;
    if (!file_exists(get_custom_file_base() . '/uploads/incoming')) {
        @mkdir(get_custom_file_base() . '/uploads/incoming', 0777);
        fix_permissions(get_custom_file_base() . '/uploads/incoming', 0777);
        sync_file(get_custom_file_base() . '/uploads/incoming');
    }
    $savename = 'uploads/incoming/' . uniqid('', true) . '.dat';
    if (array_key_exists('file', $_FILES)) {
        if (is_uploaded_file($_FILES['file']['tmp_name'])) {
            $is_uploaded = true;
        } else {
            header('HTTP/1.1 500 File Upload Error');
            @error_log('ocPortal: ' . do_lang('ERROR_UPLOADING_' . strval($_FILES['file']['error'])), 0);
            exit('ocPortal: ' . do_lang('ERROR_UPLOADING_' . strval($_FILES['file']['error'])));
        }
        $name = $_FILES['file']['name'];
        if ($is_uploaded) {
            @move_uploaded_file($_FILES['file']['tmp_name'], get_custom_file_base() . '/' . $savename) or intelligent_write_error(get_custom_file_base() . '/' . $savename);
        }
    } elseif (post_param('name', '') != '') {
        header("Cache-Control: no-cache, must-revalidate");
        // HTTP/1.1
        header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
        // Date in the past
        $name = post_param('name');
        // Read binary input stream and append it to temp file
        $in = fopen('php://input', 'rb');
        if ($in !== false) {
            // Open temp file
            $out = fopen($savename, 'wb');
            if ($out !== false) {
                $is_uploaded = true;
                do {
                    $buff = fread($in, 4096);
                    fwrite($out, $buff);
                } while (!feof($out));
                fclose($out);
            }
            fclose($in);
        }
    }
    if ($is_uploaded) {
        $max_length = 255;
        $field_type_test = $GLOBALS['SITE_DB']->query_value('db_meta', 'm_type', array('m_name' => 'i_orig_filename'));
        if ($field_type_test == 'ID_TEXT') {
            $max_length = 80;
        }
        // Legacy
        $name = substr($name, max(0, strlen($name) - $max_length));
        header('Content-type: text/plain; charset=' . get_charset());
        require_code('files');
        if (get_param_integer('base64', 0) == 1) {
            $new = base64_decode(file_get_contents(get_custom_file_base() . '/' . $savename));
            $myfile = @fopen(get_custom_file_base() . '/' . $savename, 'wb') or intelligent_write_error(get_custom_file_base() . '/' . $savename);
            fwrite($myfile, $new);
            fclose($myfile);
        }
        fix_permissions(get_custom_file_base() . '/' . $savename);
        sync_file(get_custom_file_base() . '/' . $savename);
        $member_id = get_member();
        $file_db_id = $GLOBALS['SITE_DB']->query_insert('incoming_uploads', array('i_submitter' => $member_id, 'i_date_and_time' => time(), 'i_orig_filename' => $name, 'i_save_url' => $savename), true, false);
        // File is valid, and was successfully uploaded. Now see if there is any metadata to surface from the file.
        require_code('images');
        $outa = array();
        if (is_image($name)) {
            require_code('exif');
            $outa += get_exif_data(get_custom_file_base() . '/' . $savename);
        }
        $outa['upload_id'] = strval($file_db_id);
        $outa['upload_name'] = $name;
        $outa['upload_savename'] = $savename;
        @ini_set('ocproducts.xss_detect', '0');
        $outstr = '{';
        $done = 0;
        foreach ($outa as $key => $val) {
            if (is_float($val)) {
                $val = float_to_raw_string($val);
            } elseif (is_integer($val)) {
                $val = strval($val);
            }
            if (is_string($val) && $val != '') {
                $val = str_replace(chr(0), '', $val);
                if ($done != 0) {
                    $outstr .= ', ';
                }
                $outstr .= '"' . str_replace(chr(10), '\\n', addcslashes($key, "\\\\'\"&\n\r<>")) . '": "' . str_replace(chr(10), '\\n', addcslashes($val, "\\\\'\"&\n\r<>")) . '"';
                $done++;
            }
        }
        $outstr .= '}';
        echo $outstr;
    } else {
        //header('Content-type: text/plain'); @print('No file ('.serialize($_FILES).')');
        header('HTTP/1.1 500 File Upload Error');
        // Test harness
        $title = get_page_title('UPLOAD');
        $fields = new ocp_tempcode();
        require_code('form_templates');
        $fields->attach(form_input_upload(do_lang_tempcode('FILE'), '', 'file', true, NULL, NULL, false));
        $hidden = new ocp_tempcode();
        $out2 = globalise(do_template('FORM_SCREEN', array('TITLE' => $title, 'SUBMIT_NAME' => do_lang_tempcode('PROCEED'), 'TEXT' => '', 'HIDDEN' => $hidden, 'URL' => find_script('incoming_uploads', true), 'FIELDS' => $fields)), NULL, '', true);
        $out2->evaluate_echo();
    }
    exit;
}
コード例 #17
0
ファイル: files2.php プロジェクト: erico-deh/ocPortal
/**
 * Delete all the contents of a directory, and any subdirectories of that specified directory (recursively).
 *
 * @param  PATH			The pathname to the directory to delete
 * @param  boolean		Whether to preserve files there by default
 * @param  boolean		Whether to just delete files
 */
function _deldir_contents($dir, $default_preserve = false, $just_files = false)
{
    $current_dir = @opendir($dir);
    if ($current_dir !== false) {
        while (false !== ($entryname = readdir($current_dir))) {
            if ($default_preserve) {
                if ($entryname == 'index.html') {
                    continue;
                }
                if ($entryname[0] == '.') {
                    continue;
                }
                if (in_array(str_replace(get_file_base() . '/', '', $dir) . '/' . $entryname, array('uploads/banners/advertise_here.png', 'uploads/banners/donate.png', 'themes/map.ini', 'themes/default'))) {
                    continue;
                }
            }
            if (is_dir($dir . '/' . $entryname) && $entryname != '.' && $entryname != '..') {
                deldir_contents($dir . '/' . $entryname, $default_preserve, $just_files);
                if (!$just_files) {
                    $test = @rmdir($dir . '/' . $entryname);
                    if ($test === false && !$just_files) {
                        warn_exit(do_lang_tempcode('WRITE_ERROR', escape_html($dir . '/' . $entryname)));
                    }
                }
            } elseif ($entryname != '.' && $entryname != '..') {
                $test = @unlink($dir . '/' . $entryname);
                if ($test === false) {
                    intelligent_write_error($dir . '/' . $entryname);
                }
            }
            sync_file($dir . '/' . $entryname);
        }
        closedir($current_dir);
    }
}
コード例 #18
0
ファイル: attachments2.php プロジェクト: erico-deh/ocPortal
/**
 * Get an array containing new comcode, and tempcode. The function wraps the normal comcode_to_tempcode function. The function will do attachment management, including deleting of attachments that have become unused due to editing of some comcode and removing of the reference.
 *
 * @param  LONG_TEXT		The unparsed comcode that references the attachments
 * @param  ID_TEXT		The type the attachment will be used for (e.g. download)
 * @param  ID_TEXT		The ID the attachment will be used for
 * @param  boolean		Whether we are only previewing the attachments (i.e. don't store them!)
 * @param  ?object		The database connection to use (NULL: standard site connection)
 * @param  ?boolean		Whether to insert it as an admin (any comcode parsing will be carried out with admin privileges) (NULL: autodetect)
 * @param  ?MEMBER		The member to use for ownership permissions (NULL: current member)
 * @return array			A map containing 'comcode' (after substitution for tying down the new attachments) and 'tempcode'
 */
function do_comcode_attachments($original_comcode, $type, $id, $previewing_only = false, $connection = NULL, $insert_as_admin = NULL, $for_member = NULL)
{
    require_lang('comcode');
    global $COMCODE_ATTACHMENTS;
    unset($COMCODE_ATTACHMENTS[$id]);
    // In case we have some kind of conflict
    if (is_null($connection)) {
        $connection = $GLOBALS['SITE_DB'];
    }
    if ($for_member !== NULL) {
        $member = $for_member;
        if (is_null($insert_as_admin)) {
            $insert_as_admin = false;
        }
    } else {
        if (function_exists('get_member')) {
            $member = get_member();
            if (is_null($insert_as_admin)) {
                $insert_as_admin = false;
            }
        } else {
            $member = 0;
            if (is_null($insert_as_admin)) {
                $insert_as_admin = true;
            }
        }
    }
    $comcode_text = substr($original_comcode, 0, 8) != '<comcode';
    // Handle data URLs for attachment embedding
    if (function_exists('imagecreatefromstring')) {
        $matches = array();
        $matches2 = array();
        $num_matches = preg_match_all('#<img[^<>]*src="data:image/\\w+;base64,([^"]*)"[^<>]*>#', $original_comcode, $matches);
        $num_matches2 = preg_match_all('#\\[img[^\\[\\]]*\\]data:image/\\w+;base64,([^"]*)\\[/img\\]#', $original_comcode, $matches2);
        for ($i = 0; $i < $num_matches2; $i++) {
            $matches[0][$num_matches] = $matches2[0][$i];
            $matches[1][$num_matches] = $matches2[1][$i];
            $num_matches++;
        }
        for ($i = 0; $i < $num_matches; $i++) {
            if (strpos($original_comcode, $matches[0][$i]) !== false) {
                $data = @base64_decode($matches[1][$i]);
                if ($data !== false && function_exists('imagepng')) {
                    $image = @imagecreatefromstring($data);
                    if ($image !== false) {
                        do {
                            $new_filename = uniqid('', true) . '.png';
                            $new_path = get_custom_file_base() . '/uploads/attachments/' . $new_filename;
                        } while (file_exists($new_path));
                        imagepng($image, $new_path);
                        $attachment_id = $GLOBALS['SITE_DB']->query_insert('attachments', array('a_member_id' => get_member(), 'a_file_size' => strlen($data), 'a_url' => 'uploads/attachments/' . $new_filename, 'a_thumb_url' => '', 'a_original_filename' => basename($new_filename), 'a_num_downloads' => 0, 'a_last_downloaded_time' => time(), 'a_description' => '', 'a_add_time' => time()), true);
                        $GLOBALS['SITE_DB']->query_insert('attachment_refs', array('r_referer_type' => $type, 'r_referer_id' => $id, 'a_id' => $attachment_id));
                        $original_comcode = str_replace($matches[0][$i], '[attachment type="inline" thumb="0"]' . strval($attachment_id) . '[/attachment]', $original_comcode);
                    }
                }
            }
        }
    }
    global $ATTACHMENTS_ALREADY_REFERENCED;
    $old_already = $ATTACHMENTS_ALREADY_REFERENCED;
    $ATTACHMENTS_ALREADY_REFERENCED = array();
    $before = $connection->query_select('attachment_refs', array('a_id', 'id'), array('r_referer_type' => $type, 'r_referer_id' => $id));
    foreach ($before as $ref) {
        $ATTACHMENTS_ALREADY_REFERENCED[$ref['a_id']] = 1;
    }
    $has_one = false;
    $may_have_one = false;
    foreach ($_POST as $key => $value) {
        if (preg_match('#^hidFileID\\_#i', $key) != 0) {
            require_code('uploads');
            $may_have_one = is_swf_upload();
        }
    }
    if ($may_have_one) {
        require_code('uploads');
        is_swf_upload(true);
        require_code('comcode_from_html');
        $original_comcode = preg_replace_callback('#<input [^>]*class="ocp_keep_ui_controlled" [^>]*title="([^"]*)" [^>]*type="text" [^>]*value="[^"]*"[^>]*/?' . '>#siU', 'debuttonise', $original_comcode);
    }
    $myfile = mixed();
    foreach ($_FILES as $key => $file) {
        $matches = array();
        if (($may_have_one && is_swf_upload() || is_uploaded_file($file['tmp_name'])) && preg_match('#file(\\d+)#', $key, $matches) != 0) {
            $has_one = true;
            $atype = post_param('attachmenttype' . $matches[1], '');
            $is_extract = preg_match('#\\[attachment [^\\]]*type="\\w+_extract"[^\\]]*\\]new_' . $matches[1] . '\\[/#', $original_comcode) != 0 || preg_match('#<attachment [^>]*type="\\w+_extract"[^>]*>new_' . $matches[1] . '</#', $original_comcode) != 0;
            if (substr($atype, -8) == '_extract' || $is_extract) {
                require_code('uploads');
                require_code('files');
                require_code('files2');
                $thumb = preg_match('#\\[(attachment|attachment_safe) [^\\]]*thumb="1"[^\\]]*\\]new_' . $matches[1] . '\\[/#', $original_comcode) != 0 || preg_match('#<(attachment|attachment_safe) [^>]*thumb="1"[^>]*>new_' . $matches[1] . '</#', $original_comcode) != 0;
                $arcext = get_file_extension($_FILES[$key]['name']);
                if ($arcext == 'tar' || $arcext == 'zip') {
                    if ($arcext == 'tar') {
                        require_code('tar');
                        $myfile = tar_open($file['tmp_name'], 'rb');
                        $dir = tar_get_directory($myfile, true);
                    } elseif ($arcext == 'zip') {
                        if (!function_exists('zip_open') && get_option('unzip_cmd') == '') {
                            warn_exit(do_lang_tempcode('ZIP_NOT_ENABLED'));
                        }
                        if (!function_exists('zip_open')) {
                            require_code('m_zip');
                            $mzip = true;
                        } else {
                            $mzip = false;
                        }
                        $myfile = zip_open($file['tmp_name']);
                        if (is_integer($myfile)) {
                            require_code('failure');
                            warn_exit(zip_error($myfile, $mzip));
                        }
                        $dir = array();
                        while (($zip_entry = zip_read($myfile)) !== false) {
                            $dir[] = array('zip_entry' => $zip_entry, 'path' => zip_entry_name($zip_entry), 'size' => zip_entry_filesize($zip_entry));
                        }
                    }
                    if (count($dir) > 100) {
                        require_code('site');
                        attach_message(do_lang_tempcode('TOO_MANY_FILES_TO_EXTRACT'), 'warn');
                    } else {
                        foreach ($dir as $entry) {
                            if (substr($entry['path'], -1) == '/') {
                                continue;
                            }
                            // Ignore folders
                            $_file = preg_replace('#\\..*\\.#', '.', basename($entry['path']));
                            if (!check_extension($_file, false, NULL, true)) {
                                continue;
                            }
                            if (should_ignore_file($entry['path'], IGNORE_ACCESS_CONTROLLERS | IGNORE_HIDDEN_FILES)) {
                                continue;
                            }
                            $place = get_custom_file_base() . '/uploads/attachments/' . $_file;
                            $i = 2;
                            // Hunt with sensible names until we don't get a conflict
                            while (file_exists($place)) {
                                $_file = strval($i) . basename($entry['path']);
                                $place = get_custom_file_base() . '/uploads/attachments/' . $_file;
                                $i++;
                            }
                            $i = 2;
                            $_file_thumb = basename($entry['path']);
                            $place_thumb = get_custom_file_base() . '/uploads/attachments_thumbs/' . $_file_thumb;
                            // Hunt with sensible names until we don't get a conflict
                            while (file_exists($place_thumb)) {
                                $_file_thumb = strval($i) . basename($entry['path']);
                                $place_thumb = get_custom_file_base() . '/uploads/attachments_thumbs/' . $_file_thumb;
                                $i++;
                            }
                            if ($arcext == 'tar') {
                                $file_details = tar_get_file($myfile, $entry['path'], false, $place);
                            } elseif ($arcext == 'zip') {
                                zip_entry_open($myfile, $entry['zip_entry']);
                                $file_details = array('size' => $entry['size']);
                                $out_file = @fopen($place, 'wb') or intelligent_write_error($place);
                                $more = mixed();
                                do {
                                    $more = zip_entry_read($entry['zip_entry']);
                                    if ($more !== false) {
                                        if (fwrite($out_file, $more) < strlen($more)) {
                                            warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
                                        }
                                    }
                                } while ($more !== false && $more != '');
                                fclose($out_file);
                                zip_entry_close($entry['zip_entry']);
                            }
                            $description = do_lang('EXTRACTED_FILE');
                            if (strpos($entry['path'], '/') !== false) {
                                $description = do_lang('EXTRACTED_FILE_PATH', dirname($entry['path']));
                            }
                            // Thumbnail
                            $thumb_url = '';
                            require_code('images');
                            if (is_image($_file)) {
                                $gd = get_option('is_on_gd') == '1' && function_exists('imagetypes');
                                if ($gd) {
                                    require_code('images');
                                    if (!is_saveable_image($_file)) {
                                        $ext = '.png';
                                    } else {
                                        $ext = '.' . get_file_extension($_file);
                                    }
                                    $thumb_url = 'uploads/attachments_thumbs/' . $_file_thumb;
                                    convert_image(get_custom_base_url() . '/uploads/attachments/' . $_file, $place_thumb, -1, -1, intval(get_option('thumb_width')), true, NULL, false, true);
                                    if ($connection->connection_write != $GLOBALS['SITE_DB']->connection_write) {
                                        $thumb_url = get_custom_base_url() . '/' . $thumb_url;
                                    }
                                } else {
                                    $thumb_url = 'uploads/attachments/' . $_file;
                                }
                            }
                            $url = 'uploads/attachments/' . $_file;
                            if (addon_installed('galleries')) {
                                require_code('images');
                                if (is_video($url) && $connection->connection_read == $GLOBALS['SITE_DB']->connection_read) {
                                    require_code('transcoding');
                                    $url = transcode_video($url, 'attachments', 'a_url', 'a_original_filename', NULL, NULL);
                                }
                            }
                            $attachment_id = $connection->query_insert('attachments', array('a_member_id' => get_member(), 'a_file_size' => $file_details['size'], 'a_url' => $url, 'a_thumb_url' => $thumb_url, 'a_original_filename' => basename($entry['path']), 'a_num_downloads' => 0, 'a_last_downloaded_time' => time(), 'a_description' => $description, 'a_add_time' => time()), true);
                            $connection->query_insert('attachment_refs', array('r_referer_type' => $type, 'r_referer_id' => $id, 'a_id' => $attachment_id));
                            if ($comcode_text) {
                                $original_comcode .= chr(10) . chr(10) . '[attachment type="' . comcode_escape(str_replace('_extract', '', $atype)) . '" description="' . comcode_escape($description) . '" thumb="' . ($thumb ? '1' : '0') . '"]' . strval($attachment_id) . '[/attachment]';
                            } else {
                                require_code('comcode_xml');
                                //$original_comcode.=chr(10).chr(10).'<attachment type="'.comcode_escape(str_replace('_extract','',$atype)).'" thumb="'.($thumb?'1':'0').'"><attachmentDescription>'.comcode_text__to__comcode_xml($description).'</attachmentDescription>'.strval($attachment_id).'</attachment>';			Would go in bad spot
                            }
                        }
                    }
                    if ($arcext == 'tar') {
                        tar_close($myfile);
                    } elseif ($arcext == 'zip') {
                        zip_close($myfile);
                    }
                }
            } else {
                if (strpos($original_comcode, ']new_' . $matches[1] . '[/attachment]') === false && strpos($original_comcode, '>new_' . $matches[1] . '</attachment>') === false && strpos($original_comcode, ']new_' . $matches[1] . '[/attachment_safe]') === false && strpos($original_comcode, '>new_' . $matches[1] . '</attachment_safe>') === false) {
                    if (preg_match('#\\]\\d+\\[/attachment\\]#', $original_comcode) == 0 && preg_match('#>\\d+</attachment>#', $original_comcode) == 0) {
                        if ($comcode_text) {
                            $original_comcode .= chr(10) . chr(10) . '[attachment]new_' . $matches[1] . '[/attachment]';
                        } else {
                            //$original_comcode.=chr(10).chr(10).'<attachment>new_'.$matches[1].'</attachment>';		Would go in bad spot
                        }
                    }
                }
            }
        }
    }
    global $LAX_COMCODE;
    $temp = $LAX_COMCODE;
    if ($has_one) {
        $LAX_COMCODE = true;
    }
    // We don't want a simple syntax error to cause us to lose our attachments
    $tempcode = comcode_to_tempcode($original_comcode, $member, $insert_as_admin, 60, $id, $connection, false, false, false, false, false, NULL, $for_member);
    $LAX_COMCODE = $temp;
    $ATTACHMENTS_ALREADY_REFERENCED = $old_already;
    /*if ((array_key_exists($id,$COMCODE_ATTACHMENTS)) && (array_key_exists(0,$COMCODE_ATTACHMENTS[$id])))
    	{
    		$original_comcode=$COMCODE_ATTACHMENTS[$id][0]['comcode'];
    	}*/
    $new_comcode = $original_comcode;
    if (array_key_exists($id, $COMCODE_ATTACHMENTS)) {
        $ids_present = array();
        for ($i = 0; $i < count($COMCODE_ATTACHMENTS[$id]); $i++) {
            $attachment = $COMCODE_ATTACHMENTS[$id][$i];
            // If it's a new one, we need to change the comcode to reference the ID we made for it
            if ($attachment['type'] == 'new') {
                $marker = $attachment['marker'];
                //				echo $marker.'!'.$new_comcode;
                $a_id = $attachment['id'];
                $old_length = strlen($new_comcode);
                // Search backwards from $marker
                $tag_end_start = $marker - strlen('[/' . $attachment['tag_type'] . ']');
                // </attachment> would be correct if it is Comcode-XML, but they have the same length, so it's irrelevant
                $tag_start_end = $tag_end_start;
                while ($tag_start_end > 1 && (!isset($new_comcode[$tag_start_end - 1]) || $new_comcode[$tag_start_end - 1] != ']' && $new_comcode[$tag_start_end - 1] != '>')) {
                    $tag_start_end--;
                }
                $param_keep = substr($new_comcode, 0, $tag_start_end - 1);
                $end_keep = substr($new_comcode, $tag_end_start);
                if ($comcode_text) {
                    $new_comcode = $param_keep;
                    if (strpos(substr($param_keep, strrpos($param_keep, '[')), ' type=') === false) {
                        $new_comcode .= ' type="' . comcode_escape($attachment['attachmenttype']) . '"';
                    }
                    if (strpos(substr($param_keep, strrpos($param_keep, '[')), ' description=') === false) {
                        $new_comcode .= ' description="' . comcode_escape($attachment['description']) . '"';
                    }
                    $new_comcode .= ']' . strval($a_id) . $end_keep;
                } else {
                    require_code('comcode_xml');
                    $new_comcode = $param_keep;
                    if (strpos(substr($param_keep, strrpos($param_keep, '<')), ' type=') === false) {
                        $new_comcode .= ' type="' . comcode_escape($attachment['attachmenttype']);
                    }
                    $new_comcode .= '">';
                    if (strpos(substr($param_keep, strrpos($param_keep, '<')), ' description=') === false) {
                        require_code('comcode_xml');
                        $new_comcode .= '<attachmentDescription>' . comcode_text__to__comcode_xml($attachment['description'], true) . '</attachmentDescription>';
                    }
                    $new_comcode .= strval($a_id) . $end_keep;
                }
                //				echo $new_comcode.'<br />!<br />';
                // Update other attachment markers
                $dif = strlen($new_comcode) - $old_length;
                for ($j = $i + 1; $j < count($COMCODE_ATTACHMENTS[$id]); $j++) {
                    //					echo $COMCODE_ATTACHMENTS[$id][$i]['marker'].'!';
                    $COMCODE_ATTACHMENTS[$id][$j]['marker'] += $dif;
                }
                if (!is_null($type)) {
                    $connection->query_insert('attachment_refs', array('r_referer_type' => $type, 'r_referer_id' => $id, 'a_id' => $a_id));
                }
            } else {
                // (Re-)Reference it
                $connection->query_delete('attachment_refs', array('r_referer_type' => $type, 'r_referer_id' => $id, 'a_id' => $attachment['id']), '', 1);
                $connection->query_insert('attachment_refs', array('r_referer_type' => $type, 'r_referer_id' => $id, 'a_id' => $attachment['id']));
            }
            $ids_present[] = $attachment['id'];
        }
        if (!$previewing_only && get_value('disable_attachment_cleanup') !== '1') {
            // Clear any de-referenced attachments
            foreach ($before as $ref) {
                if (!in_array($ref['a_id'], $ids_present) && strpos($new_comcode, 'attachment.php?id=') === false && !multi_lang()) {
                    // Delete reference (as it's not actually in the new comcode!)
                    $connection->query_delete('attachment_refs', array('id' => $ref['id']), '', 1);
                    // Was that the last reference to this attachment? (if so -- delete attachment)
                    $test = $connection->query_value_null_ok('attachment_refs', 'id', array('a_id' => $ref['a_id']));
                    if (is_null($test)) {
                        require_code('attachments3');
                        _delete_attachment($ref['a_id'], $connection);
                    }
                }
            }
        }
    }
    return array('comcode' => $new_comcode, 'tempcode' => $tempcode);
}
コード例 #19
0
ファイル: admin_debrand.php プロジェクト: erico-deh/ocPortal
 /**
  * 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'));
 }
コード例 #20
0
/**
 * Deletes a file (NOT a directory) on the open AFM connection.
 *
 * @param  PATH		The path to the file we are deleting.
 */
function afm_delete_file($basic_path)
{
    $path = _rescope_path($basic_path);
    $conn = _ftp_info();
    if ($conn !== false) {
        $success = @ftp_delete($conn, $path);
        if (!$success) {
            if (running_script('upgrader')) {
                echo @strval($php_errormsg);
                return;
            }
            warn_exit(protect_from_escaping(@strval($php_errormsg)));
        }
        clearstatcache();
        sync_file(get_custom_file_base() . '/' . $basic_path);
    } else {
        if (!file_exists($path)) {
            return;
        }
        @unlink($path) or intelligent_write_error($path);
        sync_file($path);
    }
}
コード例 #21
0
            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)) {
                    $pos = strpos($image_code, '/');
                    if ($pos !== false || strpos($orig_path, '/EN/') !== false) {
                        afm_make_directory($composite . substr($image_code, 0, $pos), true, true);
                    }
                    @imagepng($image, $saveat) or intelligent_write_error($saveat);
                    imagedestroy($image);
                    fix_permissions($saveat);
                    sync_file($saveat);
                    actual_edit_theme_image($image_code, $theme, 'EN', $image_code, $saveat_url, true);
                    echo '<li>' . escape_html($image_code) . '</li>';
                }
            }
        }
    }
}
echo '</ul><p>Finished theme images.</p>';
コード例 #22
0
ファイル: site.php プロジェクト: erico-deh/ocPortal
/**
 * This is it - the start of rendering of a website page.
 * Take in all inputs, sends them to the correct functions to process, gathers up all the outputs, sticks them together and echoes them.
 */
function do_site()
{
    // More SEO redirection (monikers)
    // Does this URL arrangement support monikers?
    $url_id = get_param('id', NULL, true);
    if ($url_id !== NULL && url_monikers_enabled()) {
        $type = get_param('type', 'misc');
        $looking_for = '_SEARCH:' . get_page_name() . ':' . $type . ':_WILD';
        $hooks = find_all_hooks('systems', 'content_meta_aware');
        $ob_info = NULL;
        foreach (array_keys($hooks) as $hook) {
            require_code('hooks/systems/content_meta_aware/' . filter_naughty($hook));
            $ob = object_factory('Hook_content_meta_aware_' . $hook, true);
            if ($ob === NULL) {
                continue;
            }
            $ob_info = $ob->info();
            $ob_info['view_pagelink_pattern'] = preg_replace('#:[^:]*$#', ':_WILD', $ob_info['view_pagelink_pattern']);
            if ($ob_info['view_pagelink_pattern'] == $looking_for && $ob_info['support_url_monikers']) {
                if (is_numeric($url_id)) {
                    $correct_moniker = find_id_moniker(array('page' => get_page_name(), 'type' => get_param('type', 'misc'), 'id' => $url_id));
                    if ($correct_moniker !== NULL && $correct_moniker != $url_id && count($_POST) == 0) {
                        header('HTTP/1.0 301 Moved Permanently');
                        $_new_url = build_url(array('page' => '_SELF', 'id' => $correct_moniker), '_SELF', NULL, true);
                        $new_url = $_new_url->evaluate();
                        header('Location: ' . $new_url);
                        exit;
                    }
                } else {
                    // See if it is deprecated
                    if (strpos(get_db_type(), 'mysql') !== false) {
                        $monikers = $GLOBALS['SITE_DB']->query_select('url_id_monikers USE INDEX (uim_moniker)', array('m_resource_id', 'm_deprecated'), array('m_resource_page' => get_page_name(), 'm_resource_type' => get_param('type', 'misc'), 'm_moniker' => $url_id));
                    } else {
                        $monikers = $GLOBALS['SITE_DB']->query_select('url_id_monikers', array('m_resource_id', 'm_deprecated'), array('m_resource_page' => get_page_name(), 'm_resource_type' => get_param('type', 'misc'), 'm_moniker' => $url_id));
                    }
                    if (!array_key_exists(0, $monikers)) {
                        warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
                    }
                    $deprecated = $monikers[0]['m_deprecated'] == 1;
                    if ($deprecated && count($_POST) == 0) {
                        $correct_moniker = find_id_moniker(array('page' => get_page_name(), 'type' => get_param('type', 'misc'), 'id' => $monikers[0]['m_resource_id']));
                        header('HTTP/1.0 301 Moved Permanently');
                        $_new_url = build_url(array('page' => '_SELF', 'id' => $correct_moniker), '_SELF', NULL, true);
                        $new_url = $_new_url->evaluate();
                        header('Location: ' . $new_url);
                        exit;
                    } else {
                        $_GET['id'] = $monikers[0]['m_resource_id'];
                        // We need to know the ID number rather than the moniker
                    }
                }
                break;
            }
        }
    }
    // Any messages to output?
    if (get_param_integer('redirected', 0) == 1) {
        $messages = $GLOBALS['SITE_DB']->query_select('messages_to_render', array('r_message', 'r_type'), array('r_session_id' => get_session_id()), 'ORDER BY r_time DESC');
        foreach ($messages as $message) {
            if ($GLOBALS['XSS_DETECT']) {
                ocp_mark_as_escaped($message['r_message']);
            }
            attach_message(protect_from_escaping($message['r_message']), $message['r_type']);
        }
        if (count($messages) != 0) {
            $GLOBALS['SITE_DB']->query('DELETE FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'messages_to_render WHERE r_session_id=' . strval((int) get_session_id()) . ' OR r_time<' . strval(time() - 60 * 60));
        }
    }
    if (in_safe_mode()) {
        $disable_safe_mode_url = get_self_url(true, true, array('keep_safe_mode' => NULL));
        attach_message(do_lang_tempcode('CURRENTLY_HAS_KEEP_SAFE_MODE', escape_html($disable_safe_mode_url)), 'notice');
    }
    if (get_param_integer('keep_fatalistic', 0) == 1) {
        $disable_fatalistic_url = get_self_url(true, true, array('keep_fatalistic' => NULL));
        attach_message(do_lang_tempcode('CURRENTLY_HAS_KEEP_FATALISTIC', escape_html($disable_fatalistic_url)), 'notice');
    }
    $special_page_type = get_param('special_page_type', 'view');
    global $ZONE;
    $keep_markers = get_param_integer('keep_markers', 0);
    $show_edit_links = get_param_integer('show_edit_links', 0);
    global $KEEP_MARKERS, $SHOW_EDIT_LINKS;
    $KEEP_MARKERS = $keep_markers == 1 || $special_page_type == 'show_markers';
    if ($KEEP_MARKERS && !headers_sent()) {
        header('Content-type: text/html; charset=' . get_charset());
    }
    $SHOW_EDIT_LINKS = $show_edit_links == 1 || $special_page_type == 'show_edit_links';
    $out_evaluated = NULL;
    if ($special_page_type != 'view' && $special_page_type != 'show_markers') {
        require_code('view_modes');
        initialise_special_page_types($special_page_type);
    }
    // Set up Xdebug profiling
    if ($special_page_type == 'profile') {
        if (function_exists('xdebug_start_profiling')) {
            xdebug_start_profiling();
        }
        // xdebug 1 style
        if (ini_get('xdebug.profiler_enable') != '1') {
            attach_message(escape_html('Profiling must be enabled in php.ini'), 'warn');
        }
        // xdebug 2 style
        if (!is_writable_wrap(ini_get('xdebug.profiler_output_dir'))) {
            attach_message(escape_html('xdebug.profiler_output_dir needs setting to a writable directory'), 'warn');
        }
    }
    // Allow the site to be closed
    $site_closed = get_option('site_closed');
    if ($site_closed == '1' && !has_specific_permission(get_member(), 'access_closed_site') && !$GLOBALS['IS_ACTUALLY_ADMIN']) {
        require_code('site2');
        closed_site();
    }
    // Work out which page we're viewing
    global $PAGE;
    $PAGE = get_page_name();
    $doing_special_page_type = $special_page_type != 'view' && $special_page_type != 'show_markers' && $special_page_type != 'show_edit_links' && $special_page_type != 'memory' && (has_specific_permission(get_member(), 'view_profiling_modes') || $GLOBALS['IS_ACTUALLY_ADMIN']);
    // Load up our frames into strings. Note that the header and the footer are fixed already.
    $middle = request_page($PAGE, true);
    global $CYCLES;
    $CYCLES = array();
    // Here we reset some Tempcode environmental stuff, because template compilation or preprocessing may have dirtied things
    if ($middle === NULL || $middle->is_definitely_empty()) {
        $GLOBALS['HTTP_STATUS_CODE'] = '404';
        if (!headers_sent()) {
            if (!browser_matches('ie') && strpos(ocp_srv('SERVER_SOFTWARE'), 'IIS') === false) {
                header('HTTP/1.0 404 Not Found');
            }
        }
        $title = get_page_title('ERROR_OCCURRED');
        $text = do_lang_tempcode('NO_PAGE_OUTPUT');
        $middle = warn_screen($title, $text, false);
    }
    // Extra stuff we can tag on (like messages)
    $additional = new ocp_tempcode();
    $site_closed = get_option('site_closed');
    // May have been JUST changed in page load - think Setup Wizard
    if ($site_closed == '1' && $PAGE != 'login' && $PAGE != 'join' && get_param_integer('wide_high', 0) == 0) {
        $additional->attach(do_template('ADDITIONAL', array('_GUID' => '03a41a91606b3ad05330e7d6f3e741c1', 'TYPE' => 'notice', 'MESSAGE' => do_lang_tempcode(has_specific_permission(get_member(), 'access_closed_site') ? 'SITE_SPECIAL_ACCESS' : 'SITE_SPECIAL_ACCESS_SU'))));
    }
    if ($GLOBALS['IS_ACTUALLY_ADMIN']) {
        $unsu_link = get_self_url(true, true, array('keep_su' => NULL));
        $su_username = $GLOBALS['FORUM_DRIVER']->get_username(get_member());
        $additional->attach(do_template('ADDITIONAL', array('_GUID' => '13a41a91606b3ad05330e7d6f3e741c1', 'TYPE' => 'notice', 'MESSAGE' => do_lang_tempcode('USING_SU', escape_html($unsu_link), escape_html($su_username)))));
    }
    $out = new ocp_tempcode();
    // This is important - it makes sure the tempcode tree appears nicely
    $middle->handle_symbol_preprocessing();
    // Due to the '->evaluate()' below, plus so that some symbol preprocessing can be passed into header
    $out->attach(do_header());
    if (function_exists('memory_get_usage') && get_param('special_page_type', '') == 'memory') {
        if (function_exists('memory_get_peak_usage')) {
            $memory_usage = memory_get_peak_usage();
        } else {
            $memory_usage = memory_get_usage();
        }
        $additional->attach(do_template('ADDITIONAL', array('_GUID' => 'd605c0d111742a8cd2d4ef270a1e5fe1', 'TYPE' => 'inform', 'MESSAGE' => do_lang_tempcode('MEMORY_USAGE', float_format(round(floatval($memory_usage) / 1024.0 / 1024.0, 2))))));
    }
    // Whack it into our global template
    global $ATTACHED_MESSAGES;
    $global_template = 'GLOBAL';
    if (get_option('show_docs') == '0') {
        $GLOBALS['HELPER_PANEL_TUTORIAL'] = '';
    }
    $helper_panel_pic = $GLOBALS['HELPER_PANEL_PIC'];
    if ($helper_panel_pic != '') {
        if (find_theme_image($helper_panel_pic, true) == '') {
            $helper_panel_pic = '';
        }
    }
    $global = do_template($global_template, array('HELPER_PANEL_TUTORIAL' => $GLOBALS['HELPER_PANEL_TUTORIAL'], 'HELPER_PANEL_HTML' => $GLOBALS['HELPER_PANEL_HTML'], 'HELPER_PANEL_TEXT' => $GLOBALS['HELPER_PANEL_TEXT'], 'HELPER_PANEL_PIC' => $helper_panel_pic, 'MIDDLE' => $doing_special_page_type ? $middle : $middle->evaluate(), 'MESSAGE_TOP' => $ATTACHED_MESSAGES, 'MESSAGE' => $additional, 'BREADCRUMBS' => breadcrumbs()));
    unset($middle);
    $out->attach($global);
    $out->attach(do_footer());
    $out->handle_symbol_preprocessing();
    if (get_value('xhtml_strict') === '1') {
        $out = make_xhtml_strict($out);
    }
    // Validation
    $novalidate = get_param_integer('keep_novalidate', get_param_integer('novalidate', 0));
    $show_edit_links = get_param_integer('show_edit_links', 0);
    if ((in_array(ocp_srv('HTTP_HOST'), array('localhost', 'test.ocportal.com')) || $GLOBALS['FORUM_DRIVER']->is_staff(get_member())) && ($special_page_type == 'code' || $novalidate == 0 && get_option('validation') == '1') && $GLOBALS['REFRESH_URL'][0] == '' && $show_edit_links == 0) {
        require_code('view_modes');
        $out_evaluated = $out->evaluate(NULL, false);
        do_xhtml_validation($out_evaluated, $special_page_type == 'code' && get_param_integer('preview_mode', NULL) === NULL, get_param_integer('preview_mode', 0));
    }
    // Cacheing for spiders
    if (running_script('index') && count($_POST) == 0 && isset($GLOBALS['SITE_INFO']['fast_spider_cache']) && $GLOBALS['SITE_INFO']['fast_spider_cache'] == '1' && is_guest()) {
        $bot_type = get_bot_type();
        if (($bot_type !== NULL || isset($GLOBALS['SITE_INFO']['any_guest_cached_too']) && $GLOBALS['SITE_INFO']['any_guest_cached_too'] == '1') && can_fast_spider_cache()) {
            $fast_cache_path = get_custom_file_base() . '/persistant_cache/' . md5(serialize(get_self_url_easy()));
            if ($bot_type === NULL) {
                $fast_cache_path .= '__non-bot';
            }
            if (!array_key_exists('js_on', $_COOKIE)) {
                $fast_cache_path .= '__no-js';
            }
            if (is_mobile()) {
                $fast_cache_path .= '_mobile';
            }
            $fast_cache_path .= '.gcd';
            if (!is_dir(get_custom_file_base() . '/persistant_cache/')) {
                if (@mkdir(get_custom_file_base() . '/persistant_cache/', 0777)) {
                    fix_permissions(get_custom_file_base() . '/persistant_cache/', 0777);
                    sync_file(get_custom_file_base() . '/persistant_cache/');
                } else {
                    intelligent_write_error($fast_cache_path);
                }
            }
            $out_evaluated = $out->evaluate(NULL, false);
            $myfile = @fopen($fast_cache_path, 'wb') or intelligent_write_error($fast_cache_path);
            if (function_exists('gzencode')) {
                fwrite($myfile, gzencode($out_evaluated, 9));
            } else {
                fwrite($myfile, $out_evaluated);
            }
            fclose($myfile);
            fix_permissions($fast_cache_path);
            sync_file($fast_cache_path);
        }
    }
    if ($doing_special_page_type) {
        special_page_types($special_page_type, $out, $out_evaluated);
    }
    // We calculated the time before outputting so that latency and bandwidth do not adversely affect the result
    global $PAGE_START_TIME, $PAGE_STRING;
    $page_generation_time = microtime_diff($PAGE_START_TIME, microtime(false));
    if (!$GLOBALS['QUICK_REDIRECT']) {
        if ($out_evaluated !== NULL) {
            echo $out_evaluated;
        } else {
            $GLOBALS['FINISHING_OUTPUT'] = true;
            $out->evaluate_echo();
        }
    }
    // Finally, stats
    if ($PAGE_STRING !== NULL) {
        log_stats($PAGE_STRING, intval($page_generation_time));
    }
    // When someone hits the Admin Zone front page.
    if ($ZONE['zone_name'] == 'adminzone' && get_page_name() == 'start') {
        // Security feature admins can turn on
        require_code('notifications');
        $current_username = $GLOBALS['FORUM_DRIVER']->get_username(get_member());
        $subject = do_lang('AFA_NOTIFICATION_MAIL_SUBJECT', $current_username, get_site_name(), get_ip_address());
        $mail = do_lang('AFA_NOTIFICATION_MAIL', comcode_escape(get_site_name()), comcode_escape($current_username), comcode_escape(get_ip_address()));
        dispatch_notification('adminzone_frontpage_accessed', NULL, $subject, $mail);
        // Track very basic details of what sites use ocPortal. You can remove if you like.
        if (preg_match('#^localhost[\\.\\:$]?#', ocp_srv('HTTP_HOST')) == 0) {
            global $EXPIRE, $KEY;
            $timeout_before = @ini_get('default_socket_timeout');
            @ini_set('default_socket_timeout', '3');
            http_download_file('http://ocportal.com/user.php?url=' . urlencode(get_base_url()) . '&name=' . urlencode(get_site_name()) . '&registered=2&key=' . ($KEY === NULL ? '' : strval($KEY)) . '&expire=' . ($EXPIRE === NULL ? '' : strval($EXPIRE)) . '&version=' . urlencode(ocp_version_full()), NULL, false);
            @ini_set('default_socket_timeout', $timeout_before);
        }
    }
    // Little disk space check
    $last_space_check = get_value('last_space_check');
    if ($last_space_check === NULL || intval($last_space_check) < time() - 60 * 60 * 3) {
        set_value('last_space_check', strval(time()));
        $low_space_check = intval(get_option('low_space_check')) * 1024 * 1024;
        $disk_space = @disk_free_space(get_file_base());
        if (is_integer($disk_space) && $disk_space < $low_space_check) {
            require_code('notifications');
            $subject = do_lang('LOW_DISK_SPACE_SUBJECT', NULL, NULL, NULL, get_site_default_lang());
            $message = do_lang('LOW_DISK_SPACE_MAIL', strval(intval(round($disk_space / 1024 / 1024))), NULL, NULL, get_site_default_lang());
            dispatch_notification('low_disk_space', NULL, $subject, $message, NULL, A_FROM_SYSTEM_PRIVILEGED);
        }
    }
    //exit();
}
コード例 #23
0
ファイル: images.php プロジェクト: erico-deh/ocPortal
/**
 * Resize an image to the specified size, but retain the aspect ratio.
 *
 * @param  URLPATH		The URL to the image to resize
 * @param  PATH			The file path (including filename) to where the resized image will be saved
 * @param  integer		The maximum width we want our new image to be (-1 means "don't factor this in")
 * @param  integer		The maximum height we want our new image to be (-1 means "don't factor this in")
 * @param  integer		This is only considered if both $width and $height are -1. If set, it will fit the image to a box of this dimension (suited for resizing both landscape and portraits fairly)
 * @param  boolean		Whether to exit ocPortal if an error occurs
 * @param  ?string		The file extension to save with (NULL: same as our input file)
 * @param  boolean		Whether $from was in fact a path, not a URL
 * @param  boolean		Whether to apply a 'never make the image bigger' rule for thumbnail creation (would affect very small images)
 * @param  ?array			This optional parameter allows us to specify cropping or padding for the image. See comments in the function. (NULL: no details passed)
 * @return boolean		Success
 */
function convert_image($from, $to, $width, $height, $box_width = -1, $exit_on_error = true, $ext2 = NULL, $using_path = false, $only_make_smaller = false, $thumb_options = NULL)
{
    disable_php_memory_limit();
    // Load
    $ext = get_file_extension($from);
    if ($using_path) {
        if (!check_memory_limit_for($from, $exit_on_error)) {
            return false;
        }
        $from_file = @file_get_contents($from);
    } else {
        $file_path_stub = convert_url_to_path($from);
        if (!is_null($file_path_stub)) {
            if (!check_memory_limit_for($file_path_stub, $exit_on_error)) {
                return false;
            }
            $from_file = @file_get_contents($file_path_stub);
        } else {
            $from_file = http_download_file($from, 1024 * 1024 * 20, false);
            if (is_null($from_file)) {
                $from_file = false;
            }
        }
    }
    if ($from_file === false) {
        if ($exit_on_error) {
            warn_exit(do_lang_tempcode('UPLOAD_PERMISSION_ERROR', escape_html($from)));
        }
        require_code('site');
        if (!file_exists(get_custom_file_base() . '/uploads/missing_ok')) {
            attach_message(do_lang_tempcode('UPLOAD_PERMISSION_ERROR', escape_html($from)), 'warn');
        }
        return false;
    }
    $source = @imagecreatefromstring($from_file);
    if (!is_null($thumb_options) || !$only_make_smaller) {
        unset($from_file);
    }
    if ($source === false) {
        if ($exit_on_error) {
            warn_exit(do_lang_tempcode('CORRUPT_FILE', escape_html($from)));
        }
        require_code('site');
        attach_message(do_lang_tempcode('CORRUPT_FILE', escape_html($from)), 'warn');
        return false;
    }
    // Derive actual width x height, for the given maximum box (maintain aspect ratio)
    // ===============================================================================
    $sx = imagesx($source);
    $sy = imagesy($source);
    $red = NULL;
    if (is_null($thumb_options)) {
        if ($width == 0) {
            $width = 1;
        }
        if ($height == 0) {
            $height = 1;
        }
        // If we're not sure if this is gonna stretch to fit a width or stretch to fit a height
        if ($width == -1 && $height == -1) {
            if ($sx > $sy) {
                $width = $box_width;
            } else {
                $height = $box_width;
            }
        }
        if ($width != -1 && $height != -1) {
            if (floatval($sx) / floatval($width) > floatval($sy) / floatval($height)) {
                $_width = $width;
                $_height = intval($sy * ($width / $sx));
            } else {
                $_height = $height;
                $_width = intval($sx * ($height / $sy));
            }
        } elseif ($height == -1) {
            $_width = $width;
            $_height = intval($width / ($sx / $sy));
        } elseif ($width == -1) {
            $_height = $height;
            $_width = intval($height / ($sy / $sx));
        }
        if ($_width > $sx && $only_make_smaller) {
            $_width = $sx;
            $_height = $sy;
            // We can just escape, nothing to do
            imagedestroy($source);
            if ($using_path && $from == $to) {
                return true;
            }
            if ($using_path) {
                copy($from, $to);
            } else {
                $_to = @fopen($to, 'wb') or intelligent_write_error($to);
                fwrite($_to, $from_file);
                fclose($_to);
            }
            fix_permissions($to);
            sync_file($to);
            return true;
        }
        if ($_width < 1) {
            $_width = 1;
        }
        if ($_height < 1) {
            $_height = 1;
        }
        // Pad out options for imagecopyresized
        // $dst_im,$src_im,$dst_x,$dst_y,$src_x,$src_y,$dst_w,$dst_h,$src_w,$src_h
        $dest_x = 0;
        $dest_y = 0;
        $source_x = 0;
        $source_y = 0;
    } else {
        // Thumbnail-specific (for the moment) behaviour. We require the ability
        // to crop (ie. window-off a section of the image), and pad (ie. provide a
        // background around the image). We keep this separate to the above code
        // because that already works well across various aspects of the site.
        //
        // Format of the array is 'type'=>'crop' or 'type'=>'pad'; 'where'=>'end',
        // 'where'=>'start' or 'where'=>'both'. For padding, there is an optional
        // 'background'=>'RRGGBBAA' or 'background'=>'RRGGBB' for colored padding
        // with or without transparency.
        // Grab the dimensions we would get if we didn't crop or scale
        $wrong_x = intval(round(floatval($sx) / $thumb_options['scale']));
        $wrong_y = intval(round(floatval($sy) / $thumb_options['scale']));
        // Handle cropping here
        if ($thumb_options['type'] == 'crop' || $thumb_options['type'] == 'pad_horiz_crop_horiz' && $wrong_x > $width || $thumb_options['type'] == 'pad_vert_crop_vert' && $wrong_y > $height) {
            // See which direction we're cropping in
            if (intval(round(floatval($sx) / $thumb_options['scale'])) != $width) {
                $crop_direction = 'x';
            } else {
                $crop_direction = 'y';
            }
            // We definitely have to crop, since symbols.php only tells us to crop
            // if it has to. Thus we know we're going to fill the output image, the
            // only question is with what part of the source image?
            // Get the amount we'll lose from the source
            if ($crop_direction == 'x') {
                $crop_off = intval($sx - $width * $thumb_options['scale']);
            } elseif ($crop_direction == 'y') {
                $crop_off = intval($sy - $height * $thumb_options['scale']);
            }
            // Now we see how much to chop off the start (we don't care about the
            // end, as this will be handled by using an appropriate window size)
            $displacement = 0;
            if ($thumb_options['where'] == 'start' || $thumb_options['where'] == 'start_if_vertical' && $crop_direction == 'y' || $thumb_options['where'] == 'start_if_horizontal' && $crop_direction == 'x') {
                $displacement = 0;
            } elseif ($thumb_options['where'] == 'end' || $thumb_options['where'] == 'end_if_vertical' && $crop_direction == 'y' || $thumb_options['where'] == 'end_if_horizontal' && $crop_direction == 'x') {
                $displacement = intval(floatval($crop_off));
            } else {
                $displacement = intval(floatval($crop_off) / 2.0);
            }
            // Now we convert this to the right x and y start locations for the
            // window
            $source_x = $crop_direction == 'x' ? $displacement : 0;
            $source_y = $crop_direction == 'y' ? $displacement : 0;
            // Now we set the width and height of our window, which will be scaled
            // versions of the width and height of the output
            $sx = intval($width * $thumb_options['scale']);
            $sy = intval($height * $thumb_options['scale']);
            // We start at the origin of our output
            $dest_x = 0;
            $dest_y = 0;
            // and it is always the full size it can be (or else we'd be cropping
            // too much)
            $_width = $width;
            $_height = $height;
        } elseif ($thumb_options['type'] == 'pad' || $thumb_options['type'] == 'pad_horiz_crop_horiz' && $wrong_x < $width || $thumb_options['type'] == 'pad_vert_crop_vert' && $wrong_y < $height) {
            // Padding code lives here. We definitely need to pad some excess space
            // because otherwise symbols.php would not call us. Thus we need a
            // background (can be transparent). Let's see if we've been given one.
            if (array_key_exists('background', $thumb_options) && !is_null($thumb_options['background'])) {
                if (substr($thumb_options['background'], 0, 1) == '#') {
                    $thumb_options['background'] = substr($thumb_options['background'], 1);
                }
                // We've been given a background, let's find out what it is
                if (strlen($thumb_options['background']) == 8) {
                    // We've got an alpha channel
                    $using_alpha = true;
                    $red_str = substr($thumb_options['background'], 0, 2);
                    $green_str = substr($thumb_options['background'], 2, 2);
                    $blue_str = substr($thumb_options['background'], 4, 2);
                    $alpha_str = substr($thumb_options['background'], 6, 2);
                } else {
                    // We've not got an alpha channel
                    $using_alpha = false;
                    $red_str = substr($thumb_options['background'], 0, 2);
                    $green_str = substr($thumb_options['background'], 2, 2);
                    $blue_str = substr($thumb_options['background'], 4, 2);
                }
                $red = intval($red_str, 16);
                $green = intval($green_str, 16);
                $blue = intval($blue_str, 16);
                if ($using_alpha) {
                    $alpha = intval($alpha_str, 16);
                }
            } else {
                // We've not got a background, so let's find a representative color
                // for the image by resampling the whole thing to 1 pixel.
                $temp_img = imagecreatetruecolor(1, 1);
                // Make an image to map on to
                imagecopyresampled($temp_img, $source, 0, 0, 0, 0, 1, 1, $sx, $sy);
                // Map the source image on to the 1x1 image
                $rgb_index = imagecolorat($temp_img, 0, 0);
                // Grab the color index of the single pixel
                $rgb_array = imagecolorsforindex($temp_img, $rgb_index);
                // Get the channels for it
                $red = $rgb_array['red'];
                // Grab the red
                $green = $rgb_array['green'];
                // Grab the green
                $blue = $rgb_array['blue'];
                // Grab the blue
                // Sort out if we're using alpha
                $using_alpha = false;
                if (array_key_exists('alpha', $rgb_array)) {
                    $using_alpha = true;
                }
                if ($using_alpha) {
                    $alpha = 255 - ($rgb_array['alpha'] * 2 + 1);
                }
                // Destroy the temporary image
                imagedestroy($temp_img);
            }
            // Now we need to work out how much padding we're giving, and where
            // The axis
            if (intval(round(floatval($sx) / $thumb_options['scale'])) != $width) {
                $pad_axis = 'x';
            } else {
                $pad_axis = 'y';
            }
            // The amount
            if ($pad_axis == 'x') {
                $padding = intval(round(floatval($width) - floatval($sx) / $thumb_options['scale']));
            } else {
                $padding = intval(round(floatval($height) - floatval($sy) / $thumb_options['scale']));
            }
            // The distribution
            if ($thumb_options['where'] == 'start' || $thumb_options['where'] == 'start_if_vertical' && $pad_axis == 'y' || $thumb_options['where'] == 'start_if_horizontal' && $pad_axis == 'x') {
                $pad_amount = 0;
            } else {
                $pad_amount = intval(floatval($padding) / 2.0);
            }
            // Now set all of the parameters needed for blitting our image
            // $sx and $sy are fine, since they cover the whole image
            $source_x = 0;
            $source_y = 0;
            $_width = $pad_axis == 'x' ? intval(round(floatval($sx) / $thumb_options['scale'])) : $width;
            $_height = $pad_axis == 'y' ? intval(round(floatval($sy) / $thumb_options['scale'])) : $height;
            $dest_x = $pad_axis == 'x' ? $pad_amount : 0;
            $dest_y = $pad_axis == 'y' ? $pad_amount : 0;
        }
    }
    // Resample/copy
    $gd_version = get_gd_version();
    if ($gd_version >= 2.0) {
        // Set the background if we have one
        if (!is_null($thumb_options) && !is_null($red)) {
            $dest = imagecreatetruecolor($width, $height);
            imagealphablending($dest, false);
            if (function_exists('imagecolorallocatealpha') && $using_alpha) {
                $back_col = imagecolorallocatealpha($dest, $red, $green, $blue, 127 - intval(floatval($alpha) / 2.0));
            } else {
                $back_col = imagecolorallocate($dest, $red, $green, $blue);
            }
            imagefilledrectangle($dest, 0, 0, $width, $height, $back_col);
            if (function_exists('imagesavealpha')) {
                imagesavealpha($dest, true);
            }
        } else {
            $dest = imagecreatetruecolor($_width, $_height);
            imagealphablending($dest, false);
            if (function_exists('imagesavealpha')) {
                imagesavealpha($dest, true);
            }
        }
        imagecopyresampled($dest, $source, $dest_x, $dest_y, $source_x, $source_y, $_width, $_height, $sx, $sy);
    } else {
        // Set the background if we have one
        if (!is_null($thumb_options) && !is_null($red)) {
            $dest = imagecreate($width, $height);
            $back_col = imagecolorallocate($dest, $red, $green, $blue);
            imagefill($dest, 0, 0, $back_col);
        } else {
            $dest = imagecreate($_width, $_height);
        }
        imagecopyresized($dest, $source, $dest_x, $dest_y, $source_x, $source_y, $_width, $_height, $sx, $sy);
    }
    // Clean up
    imagedestroy($source);
    // Save
    if (is_null($ext2)) {
        $ext2 = get_file_extension($to);
    }
    // If we've got transparency then we have to save as PNG
    if (!is_null($thumb_options) && isset($red) && $using_alpha) {
        $ext2 = 'png';
    }
    if (function_exists('imagepng') && $ext2 == 'png') {
        if (strtolower(substr($to, -4)) != '.png') {
            $to = $to . '.png';
        }
        $test = @imagepng($dest, $to);
        if (!$test) {
            if ($exit_on_error) {
                warn_exit(do_lang_tempcode('ERROR_IMAGE_SAVE', @strval($php_errormsg)));
            }
            require_code('site');
            attach_message(do_lang_tempcode('ERROR_IMAGE_SAVE', @strval($php_errormsg)), 'warn');
            return false;
        }
    } elseif (function_exists('imagejpeg') && ($ext2 == 'jpg' || $ext2 == 'jpeg')) {
        $jpeg_quality = get_value('jpeg_quality');
        if ($jpeg_quality !== NULL) {
            $test = @imagejpeg($dest, $to, intval($jpeg_quality));
        } else {
            $test = @imagejpeg($dest, $to);
        }
        if (!$test) {
            if ($exit_on_error) {
                warn_exit(do_lang_tempcode('ERROR_IMAGE_SAVE', @strval($php_errormsg)));
            }
            require_code('site');
            attach_message(do_lang_tempcode('ERROR_IMAGE_SAVE', @strval($php_errormsg)), 'warn');
            return false;
        }
    } elseif (function_exists('imagegif') && $ext2 == 'gif') {
        $test = @imagegif($dest, $to);
        if (!$test) {
            if ($exit_on_error) {
                warn_exit(do_lang_tempcode('ERROR_IMAGE_SAVE', @strval($php_errormsg)));
            }
            require_code('site');
            attach_message(do_lang_tempcode('ERROR_IMAGE_SAVE', @strval($php_errormsg)), 'warn');
            return false;
        }
    } else {
        if ($exit_on_error) {
            warn_exit(do_lang_tempcode('UNKNOWN_FORMAT', escape_html($ext2)));
        }
        require_code('site');
        attach_message(do_lang_tempcode('UNKNOWN_FORMAT', escape_html($ext2)), 'warn');
        return false;
    }
    // Clean up
    imagedestroy($dest);
    fix_permissions($to);
    sync_file($to);
    return true;
}
コード例 #24
0
ファイル: admin_stats.php プロジェクト: erico-deh/ocPortal
 /**
  * Save a graph to the server so it can be viewed client-side.
  *
  * @param  string		Name of the graph (no path or extension)
  * @param  string		SVG markup
  */
 function save_graph($path, $graph)
 {
     $path = get_custom_file_base() . '/data_custom/modules/admin_stats/' . filter_naughty_harsh($path) . '.xml';
     $file = @fopen($path, 'wt');
     if ($file === false) {
         intelligent_write_error($path);
     }
     if (fwrite($file, $graph) < strlen($graph)) {
         warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
     }
     @fclose($file);
     fix_permissions($path);
     sync_file($path);
 }
コード例 #25
0
ファイル: textfiles.php プロジェクト: erico-deh/ocPortal
/**
 * Write a text file, using the _custom system
 *
 * @param  string				The file name (without .txt)
 * @param  ?LANGUAGE_NAME	The language to write for (NULL: none) (blank: search)
 * @param  string				The data to write
 */
function write_text_file($codename, $lang, $out)
{
    $xpath = _find_text_file_path($codename, $lang);
    if ($xpath == '') {
        $xpath = get_file_base() . '/text/' . user_lang() . '/' . $codename . '.txt';
    }
    $path = str_replace(get_file_base() . '/text/', get_custom_file_base() . '/text_custom/', $xpath);
    $myfile = @fopen($path, 'wt');
    if ($myfile === false) {
        intelligent_write_error($path);
    }
    $out = unixify_line_format($out);
    if (fwrite($myfile, $out) < strlen($out)) {
        warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
    }
    fclose($myfile);
    fix_permissions($path);
    sync_file($path);
}
コード例 #26
0
ファイル: bin.php プロジェクト: erico-deh/ocPortal
 /**
  * Standard modular file writing function for OcCLE FS hooks.
  *
  * @param  array	The current meta-directory path
  * @param  string	The root node of the current meta-directory
  * @param  string	The file name
  * @param  string	The new file contents
  * @param  array	A reference to the OcCLE filesystem object
  * @return boolean	Success?
  */
 function write_file($meta_dir, $meta_root_node, $file_name, $contents, &$occle_fs)
 {
     $file_name = filter_naughty($file_name);
     $path = get_custom_file_base() . '/data/modules/admin_occle';
     foreach ($meta_dir as $meta_dir_section) {
         $path .= '/' . filter_naughty($meta_dir_section);
     }
     if (is_dir($path) && (file_exists($path . '/' . $file_name) && is_writable_wrap($path . '/' . $file_name) || !file_exists($path . '/' . $file_name) && is_writable_wrap($path))) {
         $fh = @fopen($path . '/' . $file_name, 'wt') or intelligent_write_error($path . '/' . $file_name);
         $output = fwrite($fh, $contents);
         fclose($fh);
         if ($output < strlen($contents)) {
             warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
         }
         fix_permissions($path . '/' . $file_name);
         sync_file($path . '/' . $file_name);
         return $output;
     } else {
         return false;
     }
     //File doesn't exist
 }
コード例 #27
0
ファイル: admin_lang.php プロジェクト: erico-deh/ocPortal
 /**
  * The actualiser to translate code (called externally, and may operate on many lang files).
  *
  * @return tempcode		The UI
  */
 function set_lang_code_2()
 {
     $lang = post_param('lang');
     $lang_files = get_lang_files(fallback_lang());
     foreach (array_keys($lang_files) as $lang_file) {
         $for_base_lang = get_lang_file_map(fallback_lang(), $lang_file, true);
         $for_base_lang_2 = get_lang_file_map($lang, $lang_file, false);
         $descriptions = get_lang_file_descriptions(fallback_lang(), $lang_file);
         $out = '';
         foreach ($for_base_lang_2 + $for_base_lang as $key => $now_val) {
             $val = post_param('l_' . $key, array_key_exists($key, $for_base_lang_2) ? $for_base_lang_2[$key] : $now_val);
             if (str_replace(chr(10), '\\n', $val) != $now_val || !array_key_exists($key, $for_base_lang) || $for_base_lang[$key] != $val || !file_exists(get_file_base() . '/lang/' . fallback_lang() . '/' . $lang_file . '.ini')) {
                 // if it's changed from default ocPortal, or not in default ocPortal, or was already changed in language file, or whole file is not in default ocPortal
                 $out .= $key . '=' . str_replace(chr(10), '\\n', $val) . "\n";
             }
         }
         if ($out != '') {
             $path = get_custom_file_base() . '/lang_custom/' . filter_naughty($lang) . '/' . filter_naughty($lang_file) . '.ini';
             $path_backup = $path . '.' . strval(time());
             if (file_exists($path)) {
                 @copy($path, $path_backup) or intelligent_write_error($path_backup);
                 sync_file($path_backup);
             }
             $myfile = @fopen($path, 'wt');
             if ($myfile === false) {
                 intelligent_write_error($path);
             }
             fwrite($myfile, "[descriptions]\n");
             foreach ($descriptions as $key => $description) {
                 if (fwrite($myfile, $key . '=' . $description . "\n") == 0) {
                     warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
                 }
             }
             fwrite($myfile, "\n[strings]\n");
             fwrite($myfile, $out);
             fclose($myfile);
             fix_permissions($path);
             sync_file($path);
             $path_backup2 = $path . '.latest_in_ocp_edit';
             @copy($path, $path_backup2) or intelligent_write_error($path_backup2);
             sync_file($path_backup2);
         }
     }
     $title = get_page_title('TRANSLATE_CODE');
     log_it('TRANSLATE_CODE');
     require_code('view_modes');
     erase_cached_language();
     erase_cached_templates();
     // Show it worked / Refresh
     $url = post_param('redirect', '');
     if ($url == '') {
         return inform_screen($title, do_lang_tempcode('SUCCESS'));
     }
     return redirect_screen($title, $url, do_lang_tempcode('SUCCESS'));
 }
コード例 #28
0
ファイル: themewizard.php プロジェクト: erico-deh/ocPortal
/**
 * Make a theme. Note that this will trigger the AFM.
 *
 * @param  string		Name of the theme.
 * @param  ID_TEXT	The theme it's being generated from
 * @param  ID_TEXT	The algorithm to use
 * @set equations hsv
 * @param  string		Seed colour to use.
 * @param  boolean	Whether to use the theme immediately.
 * @param  ?boolean  Whether it will be a dark theme (NULL: autodetect).
 * @param  boolean	Whether to inherit the CSS, for easier theme upgrading.
 */
function make_theme($themename, $source_theme, $algorithm, $seed, $use, $dark = false, $inherit_css = false)
{
    $GLOBALS['NO_QUERY_LIMIT'] = true;
    load_themewizard_params_from_theme($source_theme, $algorithm == 'hsv');
    if (file_exists(get_custom_file_base() . '/themes/' . $themename)) {
        require_code('abstract_file_manager');
        force_have_afm_details();
        $extending_existing = true;
    } else {
        if ($source_theme == 'default') {
            actual_add_theme($themename);
        } else {
            require_code('themes3');
            actual_copy_theme($source_theme, $themename);
        }
        $extending_existing = false;
    }
    if ($seed != find_theme_seed($source_theme) || $dark != find_theme_dark($source_theme)) {
        list($colours, $landscape) = calculate_theme($seed, $source_theme, $algorithm, 'colours', $dark);
        // Make images
        global $THEME_WIZARD_IMAGES, $THEME_WIZARD_IMAGES_NO_WILD, $IMG_CODES;
        if (function_exists('imagecolorallocatealpha')) {
            require_code('themes2');
            $full_img_set = array();
            foreach ($THEME_WIZARD_IMAGES as $expression) {
                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() . '/themes/' . filter_naughty($source_theme) . '/images', $expression)));
                    $full_img_set = array_merge($full_img_set, array_keys(get_all_image_codes(get_file_base() . '/themes/' . filter_naughty($source_theme) . '/images/' . fallback_lang(), $expression)));
                } else {
                    $full_img_set[] = $expression;
                }
            }
            if ($extending_existing) {
                $temp_all_ids = collapse_2d_complexity('id', 'path', $GLOBALS['SITE_DB']->query_select('theme_images', array('id', 'path'), array('theme' => $themename)));
            } else {
                $temp_all_ids = array();
            }
            $_langs = find_all_langs(true);
            foreach ($full_img_set as $image_code) {
                if (!in_array($image_code, $THEME_WIZARD_IMAGES_NO_WILD)) {
                    if ($extending_existing && array_key_exists($image_code, $temp_all_ids) && strpos($temp_all_ids[$image_code], $themename . '/images_custom/') !== false && (!url_is_local($temp_all_ids[$image_code]) || file_exists(get_custom_file_base() . '/' . $temp_all_ids[$image_code]))) {
                        continue;
                    }
                    foreach (array_keys($_langs) as $lang) {
                        $orig_path = find_theme_image($image_code, true, true, $source_theme, $lang);
                        if ($orig_path == '') {
                            continue;
                        }
                        // Theme has specified non-existent image as themewizard-compatible
                        if (strpos($orig_path, '/' . $lang . '/') === false && $lang != fallback_lang()) {
                            continue;
                        }
                        if (strpos($orig_path, '/' . fallback_lang() . '/') !== false) {
                            $composite = 'themes/' . filter_naughty($themename) . '/images/' . $lang . '/';
                        } else {
                            $composite = 'themes/' . filter_naughty($themename) . '/images/';
                        }
                        $saveat = get_custom_file_base() . '/' . $composite . $image_code . '.png';
                        $saveat_url = $composite . $image_code . '.png';
                        // Wipe out ones that might have been copied from source theme
                        if ($source_theme != 'default' && strpos($orig_path, 'images_custom') !== false) {
                            @unlink(str_replace('/images/', '/images_custom/', basename($saveat, '.png')) . '.png');
                            @unlink(str_replace('/images/', '/images_custom/', basename($saveat, '.png')) . '.jpg');
                            @unlink(str_replace('/images/', '/images_custom/', basename($saveat, '.png')) . '.gif');
                            @unlink(str_replace('/images/', '/images_custom/', basename($saveat, '.png')) . '.jpeg');
                        }
                        if (!file_exists($saveat) || $source_theme != 'default' || $algorithm == 'hsv') {
                            $image = calculate_theme($seed, $source_theme, $algorithm, $image_code, $dark, $colours, $landscape, $lang);
                            if (!is_null($image)) {
                                $pos = strpos($image_code, '/');
                                if ($pos !== false || strpos($orig_path, '/' . fallback_lang() . '/') !== false) {
                                    afm_make_directory($composite . substr($image_code, 0, $pos), true, true);
                                }
                                @imagepng($image, $saveat) or intelligent_write_error($saveat);
                                imagedestroy($image);
                                fix_permissions($saveat);
                                sync_file($saveat);
                                actual_edit_theme_image($image_code, $themename, $lang, $image_code, $saveat_url, true);
                                //if ($lang==fallback_lang()) $IMG_CODES['site'][$image_code]=$saveat_url;
                            }
                        } else {
                            actual_edit_theme_image($image_code, $themename, $lang, $image_code, $saveat_url, true);
                        }
                    }
                }
            }
        }
        // Make sheets
        $dh = opendir(get_file_base() . '/themes/' . filter_naughty($source_theme) . ($source_theme == 'default' ? '/css/' : '/css_custom/'));
        while (($sheet = readdir($dh)) !== false) {
            if (substr($sheet, -4) == '.css') {
                $saveat = get_custom_file_base() . '/themes/' . filter_naughty($themename) . '/css_custom/' . $sheet;
                if (!file_exists($saveat) || $source_theme != 'default' || $algorithm == 'hsv') {
                    $fp = @fopen($saveat, 'wt') or intelligent_write_error(get_custom_file_base() . '/themes/' . filter_naughty($themename) . '/css_custom/' . $sheet);
                    if ($inherit_css) {
                        $output = '{+START,CSS_INHERIT,' . basename($sheet, '.css') . ',' . filter_naughty($source_theme) . ',' . $seed . ',' . ($dark ? '1' : '0') . ',' . $algorithm . '}{+END}';
                    } else {
                        $output = theme_wizard_colours_to_sheet($sheet, $landscape, $source_theme, $algorithm, $seed);
                    }
                    if (fwrite($fp, $output) < strlen($output)) {
                        warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
                    }
                    fclose($fp);
                    fix_permissions($saveat);
                    sync_file($saveat);
                    if (!$inherit_css) {
                        $c_success = @copy(get_file_base() . '/themes/' . filter_naughty($source_theme) . '/css/' . $sheet, $saveat . '.editfrom');
                        if ($c_success !== false) {
                            fix_permissions($saveat . '.editfrom');
                            sync_file($saveat . '.editfrom');
                        }
                    } else {
                        @unlink($saveat . '.editfrom');
                    }
                }
            }
        }
    }
    // Use it, if requested
    if ($use) {
        $GLOBALS['SITE_DB']->query('UPDATE ' . get_table_prefix() . 'zones SET zone_theme=\'' . db_escape_string($themename) . '\' WHERE ' . db_string_not_equal_to('zone_name', 'cms') . ' AND ' . db_string_not_equal_to('zone_name', 'adminzone'));
        $admin_groups = $GLOBALS['FORUM_DRIVER']->get_super_admin_groups();
        $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, true);
        $GLOBALS['SITE_DB']->query_delete('group_category_access', array('module_the_name' => 'theme', 'category_name' => $themename));
        foreach (array_keys($groups) as $group_id) {
            if (in_array($group_id, $admin_groups)) {
                continue;
            }
            $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'theme', 'category_name' => $themename, 'group_id' => $group_id));
        }
        persistant_cache_empty();
    }
}
コード例 #29
0
ファイル: admin_sitetree.php プロジェクト: erico-deh/ocPortal
 /**
  * The actualiser to delete a page.
  *
  * @return tempcode		The UI
  */
 function __delete()
 {
     $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/deletepage';
     $zone = post_param('zone', NULL);
     $afm_needed = false;
     $pages = find_all_pages_wrap($zone);
     foreach ($pages as $page => $type) {
         if (is_integer($page)) {
             $page = strval($page);
         }
         if (post_param_integer('page__' . $page, 0) == 1) {
             if (get_file_base() != get_custom_file_base() && strpos($type, 'comcode_custom') !== false) {
                 warn_exit(do_lang_tempcode('SHARED_INSTALL_PROHIBIT'));
             }
             if ($type != 'comcode_custom') {
                 $afm_needed = true;
             }
         }
     }
     if ($afm_needed) {
         require_code('abstract_file_manager');
         force_have_afm_details();
     }
     foreach ($pages as $page => $type) {
         if (is_integer($page)) {
             $page = strval($page);
         }
         if (post_param_integer('page__' . $page, 0) == 1) {
             if (substr($type, 0, 7) == 'modules') {
                 $_page = $page . '.php';
             } elseif (substr($type, 0, 7) == 'comcode') {
                 $_page = $page . '.txt';
             } elseif (substr($type, 0, 4) == 'html') {
                 $_page = $page . '.htm';
             }
             $GLOBALS['SITE_DB']->query_delete('menu_items', array('i_url' => $zone . ':' . $page));
             if (substr($type, 0, 7) == 'comcode' || substr($type, 0, 4) == 'html') {
                 $type_shortened = preg_replace('#/.+#', '', $type);
                 if (substr($type, 0, 7) == 'comcode' && get_option('store_revisions') == '1') {
                     $time = time();
                     $fullpath = zone_black_magic_filterer((strpos($type, 'comcode/') !== false ? get_file_base() : get_custom_file_base()) . '/' . filter_naughty($zone) . ($zone != '' ? '/' : '') . 'pages/' . filter_naughty($type) . '/' . $_page);
                     $bs_path = zone_black_magic_filterer(str_replace('/comcode/', '/comcode_custom/', $fullpath) . '.' . strval($time));
                     @copy($fullpath, $bs_path) or intelligent_write_error($fullpath);
                     sync_file($bs_path);
                     fix_permissions($bs_path);
                 }
                 $langs = find_all_langs(true);
                 foreach (array_keys($langs) as $lang) {
                     $_path = zone_black_magic_filterer(filter_naughty($zone) . ($zone != '' ? '/' : '') . 'pages/' . filter_naughty($type_shortened) . '/' . $lang . '/' . $_page, true);
                     $path = (strpos($type, 'comcode/') !== false ? get_file_base() : get_custom_file_base()) . '/' . $_path;
                     if (file_exists($path)) {
                         if ($afm_needed) {
                             afm_delete_file($_path);
                         } else {
                             unlink(get_custom_file_base() . '/' . $_path);
                         }
                     }
                 }
                 if (substr($type, 0, 7) == 'comcode') {
                     require_code('attachments2');
                     require_code('attachments3');
                     delete_comcode_attachments('comcode_page', $zone . ':' . $page);
                     $GLOBALS['SITE_DB']->query_delete('cached_comcode_pages', array('the_page' => $page, 'the_zone' => $zone));
                     $GLOBALS['SITE_DB']->query_delete('comcode_pages', array('the_page' => $page, 'the_zone' => $zone));
                     persistant_cache_empty();
                     decache('main_comcode_page_children');
                     require_code('seo2');
                     seo_meta_erase_storage('comcode_page', $zone . ':' . $page);
                 }
             } else {
                 $_path = zone_black_magic_filterer(filter_naughty($zone) . ($zone != '' ? '/' : '') . 'pages/' . filter_naughty($type) . '/' . $_page, true);
                 $path = (strpos($type, '_custom') === false ? get_file_base() : get_custom_file_base()) . '/' . $_path;
                 if (file_exists($path)) {
                     if ($afm_needed) {
                         afm_delete_file($_path);
                     } else {
                         unlink(get_custom_file_base() . '/' . $_path);
                     }
                 }
             }
             $GLOBALS['SITE_DB']->query_delete('https_pages', array('https_page_name' => $page), '', 1);
             log_it('DELETE_PAGES', $page);
         }
     }
     persistant_cache_empty();
     decache('main_sitemap');
     $title = get_page_title('DELETE_PAGES');
     breadcrumb_set_self(do_lang_tempcode('DONE'));
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('PAGES')), array('_SELF:_SELF:delete', do_lang_tempcode('DELETE_PAGES'))));
     return $this->do_next_manager($title, NULL, $zone, new ocp_tempcode());
 }
コード例 #30
0
 /**
  * The actualiser to edit a comcode page.
  *
  * @return tempcode		The UI
  */
 function __ed()
 {
     $simple_add = get_param_integer('simple_add', 0) == 1;
     $title = get_page_title($simple_add ? 'COMCODE_PAGE_ADD' : 'COMCODE_PAGE_EDIT');
     $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/comcode_page_edit';
     $file = filter_naughty(post_param('file'));
     $lang = filter_naughty(post_param('lang'));
     $zone = filter_naughty(post_param('zone'));
     if (addon_installed('page_management')) {
         $new_file = filter_naughty(has_actual_page_access(get_member(), 'admin_sitetree') ? post_param('title', $file) : $file);
     } else {
         $new_file = filter_naughty($file);
     }
     if ($file == '') {
         $file = $new_file;
     }
     require_code('type_validation');
     if (!is_alphanumeric($file, true)) {
         warn_exit(do_lang_tempcode('BAD_CODENAME'));
     }
     $fullpath = zone_black_magic_filterer(get_custom_file_base() . '/' . $zone . '/pages/comcode_custom/' . $lang . '/' . $file . '.txt');
     $renaming_page = $new_file != $file;
     if ($renaming_page) {
         if (!is_alphanumeric($new_file, true)) {
             warn_exit(do_lang_tempcode('BAD_CODENAME'));
         }
         $langs = find_all_langs(true);
         $rename_map = array();
         $afm_needed = false;
         // Actually will stay false as we don't allow renaming original-pages at the moment
         foreach (array_keys($langs) as $lang) {
             $path = zone_black_magic_filterer(filter_naughty($zone) . ($zone != '' ? '/' : '') . 'pages/comcode_custom/' . $lang . '/' . $file . '.txt', true);
             if (is_file(get_file_base() . '/' . $path)) {
                 $new_path = zone_black_magic_filterer(filter_naughty($zone) . ($zone != '' ? '/' : '') . 'pages/comcode_custom/' . $lang . '/' . $new_file . '.txt', true);
                 if (is_file($new_path)) {
                     warn_exit(do_lang_tempcode('ALREADY_EXISTS', escape_html($zone . ':' . $new_file)));
                 }
                 $rename_map[$path] = $new_path;
             }
             if (is_file(get_file_base() . '/' . str_replace('/comcode_custom/', '/comcode/', $path))) {
                 $completion_text = do_lang_tempcode('ORIGINAL_PAGE_NO_RENAME');
             }
         }
         if ($afm_needed) {
             require_code('abstract_file_manager');
             force_have_afm_details();
         }
     }
     $validated = post_param_integer('validated', 0);
     if (!has_specific_permission(get_member(), 'bypass_validation_highrange_content')) {
         $validated = 0;
     }
     $parent_page = post_param('parent_page', '');
     $show_as_edit = post_param_integer('show_as_edit', 0);
     $resource_owner = $GLOBALS['SITE_DB']->query_value_null_ok('comcode_pages', 'p_submitter', array('the_zone' => $zone, 'the_page' => $file));
     check_edit_permission('high', $resource_owner);
     if ($GLOBALS['FORUM_DRIVER']->is_super_admin(get_member())) {
         $_owner = post_param('owner', $GLOBALS['FORUM_DRIVER']->get_username(get_member()));
         $owner = $GLOBALS['FORUM_DRIVER']->get_member_from_username($_owner);
         if (is_null($owner)) {
             $owner = get_member();
         }
     } else {
         $owner = get_member();
     }
     if (is_null($resource_owner)) {
         check_submit_permission('high');
         require_code('submit');
         give_submit_points('COMCODE_PAGE_ADD');
         if (!addon_installed('unvalidated')) {
             $validated = 1;
         }
         $GLOBALS['SITE_DB']->query_insert('comcode_pages', array('the_zone' => $zone, 'the_page' => $file, 'p_parent_page' => $parent_page, 'p_validated' => $validated, 'p_edit_date' => NULL, 'p_add_date' => time(), 'p_submitter' => $owner, 'p_show_as_edit' => 0));
     } else {
         if (!has_actual_page_access(get_member(), $file, $zone)) {
             access_denied('PAGE_ACCESS');
         }
         require_code('submit');
         $just_validated = !content_validated('comcode_page', $zone . ':' . $file) && $validated == 1;
         if ($just_validated) {
             send_content_validated_notification('comcode_page', $zone . ':' . $file);
         }
         if (!addon_installed('unvalidated')) {
             $validated = 1;
         }
         $GLOBALS['SITE_DB']->query_update('comcode_pages', array('p_parent_page' => $parent_page, 'p_validated' => $validated, 'p_edit_date' => time(), 'p_submitter' => $owner, 'p_show_as_edit' => $show_as_edit), array('the_zone' => $zone, 'the_page' => $file), '', 1);
     }
     if ($validated == 0) {
         require_code('submit');
         $edit_url = build_url(array('page' => '_SELF', 'type' => '_ed', 'page_link' => $zone . ':' . $new_file), '_SELF', NULL, false, false, true);
         if (addon_installed('unvalidated')) {
             send_validation_request('COMCODE_PAGE_EDIT', 'comcode_pages', true, $zone . ':' . $new_file, $edit_url);
         }
     }
     $new = post_param('post');
     require_code('attachments2');
     $_new = do_comcode_attachments($new, 'comcode_page', $zone . ':' . $file);
     $new = $_new['comcode'];
     if (!file_exists($fullpath) || $new != file_get_contents($fullpath, FILE_TEXT)) {
         $myfile = @fopen($fullpath, 'wt');
         if ($myfile === false) {
             intelligent_write_error($fullpath);
         }
         final_attachments_from_preview($zone . ':' . $file);
         if (fwrite($myfile, $new) < strlen($new)) {
             warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
         }
         fclose($myfile);
         sync_file($fullpath);
         $file_changed = true;
     } else {
         $file_changed = false;
     }
     require_code('seo2');
     $new_keywords = post_param('meta_keywords', '');
     $new_description = post_param('meta_description', '');
     if ($new_keywords == '' && $new_description == '') {
         seo_meta_set_for_implicit('comcode_page', $zone . ':' . $file, array($new), $new);
     } else {
         seo_meta_set_for_explicit('comcode_page', $zone . ':' . $file, $new_keywords, $new_description);
     }
     $completion_text = $validated == 0 ? do_lang_tempcode('SUBMIT_UNVALIDATED') : do_lang_tempcode('SUCCESS');
     // Update cache  NO WE CAN'T - THEY'RE MULTI-THEME NOW
     /*	$string_index=$GLOBALS['SITE_DB']->query_value_null_ok('cached_comcode_pages','string_index',array('the_zone'=>$zone,'the_page'=>$file));
     		if (!is_null($string_index))
     		{
     			lang_remap_comcode($string_index,$new);
     		} else
     		{
     			$string_index=insert_lang_comcode($new,1,NULL,false,NULL,NULL,false,NULL,NULL,60,true,true);
     			$GLOBALS['SITE_DB']->query_insert('cached_comcode_pages',array('the_zone'=>$zone,'the_page'=>$file,'string_index'=>$string_index));
     		}*/
     require_code('permissions2');
     set_page_permissions_from_environment($zone, $file);
     $caches = $GLOBALS['SITE_DB']->query_select('cached_comcode_pages', array('string_index'), array('the_zone' => $zone, 'the_page' => $file));
     $GLOBALS['SITE_DB']->query_delete('cached_comcode_pages', array('the_zone' => $zone, 'the_page' => $file));
     foreach ($caches as $cache) {
         delete_lang($cache['string_index']);
     }
     persistant_cache_empty();
     persistant_cache_delete(array('PAGE_INFO'));
     decache('main_comcode_page_children');
     fix_permissions($fullpath);
     if (is_file($fullpath) && get_option('store_revisions') == '1' && $file_changed) {
         $time = time();
         @copy($fullpath, $fullpath . '.' . strval($time)) or intelligent_write_error($fullpath . '.' . strval($time));
         fix_permissions($fullpath . '.' . strval($time));
         sync_file($fullpath . '.' . strval($time));
     }
     log_it('COMCODE_PAGE_EDIT', $file, $zone);
     require_code('autosave');
     clear_ocp_autosave();
     if ($renaming_page) {
         $GLOBALS['SITE_DB']->query_delete('comcode_pages', array('the_zone' => $zone, 'the_page' => $new_file), '', 1);
         $GLOBALS['SITE_DB']->query_update('comcode_pages', array('the_page' => $new_file), array('the_zone' => $zone, 'the_page' => $file), '', 1);
         $GLOBALS['SITE_DB']->query_update('comcode_pages', array('p_parent_page' => $new_file), array('the_zone' => $zone, 'p_parent_page' => $file));
         foreach ($rename_map as $path => $new_path) {
             if ($afm_needed) {
                 afm_move($path, $new_path);
             } else {
                 rename(get_custom_file_base() . '/' . $path, get_custom_file_base() . '/' . $new_path);
             }
         }
         if (addon_installed('awards')) {
             $types = $GLOBALS['SITE_DB']->query_select('award_types', array('id'), array('a_content_type' => 'comcode_page'));
             foreach ($types as $type) {
                 $GLOBALS['SITE_DB']->query_update('award_archive', array('content_id' => $new_file), array('content_id' => $file, 'a_type_id' => $type['id']));
             }
         }
         $file = $new_file;
     }
     if (post_param_integer('delete', 0) == 1) {
         unlink(get_custom_file_base() . '/' . $path);
     }
     if (addon_installed('awards')) {
         require_code('awards');
         handle_award_setting('comcode_page', $zone . ':' . $file);
     }
     decache('main_sitemap');
     breadcrumb_set_self(do_lang_tempcode('DONE'));
     // Look for bad title semantics
     $_new['html'] = $_new['tempcode']->evaluate();
     if (substr($file, 0, 1) != '_' && substr($file, 0, 6) != 'panel_' && trim($_new['html']) != '') {
         if (strpos($_new['html'], '<h1') === false && strpos($_new['comcode'], '[title]') === false && strpos($_new['comcode'], '[title="1"]') === false) {
             attach_message(do_lang_tempcode('NO_LEVEL_1_HEADERS'), 'notice');
         }
         $matches = array();
         if (strpos($_new['html'], '<h2') === false && preg_match_all('#\\n\\[(b|font|size)\\][^\\.]+\\[/(b|font|size)\\]\\n#', $_new['comcode'], $matches) >= 2) {
             attach_message(do_lang_tempcode('NO_LEVEL_2_HEADERS'), 'inform');
         }
     }
     // Show it worked / Refresh
     $url = post_param('redirect', '');
     if ($url != '') {
         return redirect_screen($title, $url, $completion_text);
     }
     return $this->do_next_manager($title, $file, $zone, $completion_text);
 }