Exemplo n.º 1
0
/**
 * Get a splurghified version of the specified item.
 *
 * @param  string			The name of what the key we want to reference is in our array of maps (e.g. 'id')
 * @param  array			A row of maps for data we are splurghing; this is probably just the result of $GLOBALS['SITE_DB']->query_select
 * @param  URLPATH		The stub that links will be passed through
 * @param  ID_TEXT		The page name we will be saving customised HTML under
 * @param  TIME			The time we did our last change to the data being splurghed (so it can see if we can simply decache instead of deriving)
 * @param  ?AUTO_LINK	The ID that is at the root of our tree (NULL: db_get_first_id)
 * @return string			A string of HTML that represents our splurghing (will desplurgh in the users browser)
 */
function splurgh_master_build($key_name, $map, $url_stub, $_cache_file, $last_change_time, $first_id = NULL)
{
    if (is_null($first_id)) {
        $first_id = db_get_first_id();
    }
    if (!array_key_exists($first_id, $map)) {
        return '';
    }
    if (!has_js()) {
        warn_exit(do_lang_tempcode('MSG_JS_NEEDED'));
    }
    require_javascript('javascript_splurgh');
    if (is_browser_decacheing()) {
        $last_change_time = time();
    }
    $cache_file = zone_black_magic_filterer(get_custom_file_base() . '/' . get_zone_name() . '/pages/html_custom/' . filter_naughty(user_lang()) . '/' . filter_naughty($_cache_file) . '.htm');
    if (!file_exists($cache_file) || is_browser_decacheing() || filesize($cache_file) == 0 || $last_change_time > filemtime($cache_file)) {
        $myfile = @fopen($cache_file, 'wt');
        if ($myfile === false) {
            intelligent_write_error($cache_file);
        }
        $fulltable = array();
        $splurgh = _splurgh_do_node($map, $first_id, '', $fulltable, 0);
        $page = do_template('SPLURGH', array('_GUID' => '8775edfc5a386fdf2cec69b0fc889952', 'KEY_NAME' => $key_name, 'URL_STUB' => $url_stub, 'SPLURGH' => str_replace('"', '\'', $splurgh)));
        $ev = $page->evaluate();
        if (fwrite($myfile, $ev) < strlen($ev)) {
            warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
        }
        fclose($myfile);
        fix_permissions($cache_file);
        sync_file($cache_file);
        return $ev;
    }
    return file_get_contents($cache_file, FILE_TEXT);
}
Exemplo n.º 2
0
/**
 * Log permission checks to the permission_checks.log file
 *
 * @param  MEMBER         The user checking against
 * @param  ID_TEXT        The function that was called to check a permission
 * @param  array          Parameters to this permission-checking function
 * @param  boolean        Whether the permission was held
 */
function _handle_permission_check_logging($member, $op, $params, $result)
{
    global $PERMISSION_CHECK_LOGGER;
    if ($op == 'has_specific_permission') {
        require_all_lang();
        $params[0] = $params[0] . ' ("' . do_lang('PT_' . $params[0]) . '")';
    }
    $str = $op;
    if (count($params) != 0) {
        $str .= ': ';
        foreach ($params as $i => $p) {
            if ($i != 0) {
                $str .= ',';
            }
            $str .= is_string($p) ? $p : (is_null($p) ? '' : strval($p));
        }
    }
    if ($PERMISSION_CHECK_LOGGER !== false && !$result) {
        fwrite($PERMISSION_CHECK_LOGGER, "\t" . $str);
        $username = $GLOBALS['FORUM_DRIVER']->get_username($member);
        if (is_null($username)) {
            $username = do_lang('UNKNOWN');
        }
        if ($member != get_member()) {
            fwrite($PERMISSION_CHECK_LOGGER, ' -- ' . $username);
        }
        //	fwrite($PERMISSION_CHECK_LOGGER,' --> '.($result?do_lang('YES'):do_lang('NO')).chr(10));
        fwrite($PERMISSION_CHECK_LOGGER, chr(10));
        sync_file(get_custom_file_base() . '/data_custom/permissioncheckslog.php');
    }
    if (function_exists('fb') && get_param_integer('keep_firephp', 0) == 1 && !headers_sent()) {
        fb('Permission check ' . ($result ? 'PASSED' : 'FAILED') . ': ' . $str);
    }
}
Exemplo n.º 3
0
/**
 * Delete the specified attachment
 *
 * @param  AUTO_LINK		The attachment ID to delete
 * @param  object			The database connection to use
 * @set    ocp forum
 */
function _delete_attachment($id, $connection)
{
    $connection->query_delete('attachment_refs', array('a_id' => $id));
    // Get attachment details
    $_attachment_info = $connection->query_select('attachments', array('a_url', 'a_thumb_url'), array('id' => $id), '', 1);
    if (!array_key_exists(0, $_attachment_info)) {
        return;
    }
    // Already gone
    $attachment_info = $_attachment_info[0];
    // Delete url and thumb_url if local
    if (url_is_local($attachment_info['a_url']) && substr($attachment_info['a_url'], 0, 19) == 'uploads/attachments') {
        $url = rawurldecode($attachment_info['a_url']);
        @unlink(get_custom_file_base() . '/' . $url);
        sync_file($url);
        if ($attachment_info['a_thumb_url'] != '' && strpos($attachment_info['a_thumb_url'], 'uploads/filedump/') === false) {
            $thumb_url = rawurldecode($attachment_info['a_thumb_url']);
            @unlink(get_custom_file_base() . '/' . $thumb_url);
            sync_file($thumb_url);
        }
    }
    // Delete attachment
    $connection->query_delete('attachments', array('id' => $id), '', 1);
}
Exemplo n.º 4
0
 /**
  * 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
 }
Exemplo n.º 5
0
 /**
  * Convert a WowBB database file to an ocPortal uploaded file (stored on disk).
  *
  * @param  string			The file data
  * @param  string			The optimal filename
  * @param  ID_TEXT		The upload type (e.g. ocf_photos)
  * @return URLPATH		The URL
  */
 function data_to_disk($data, $filename, $sections)
 {
     $filename = find_derivative_filename('uploads/' . $sections, $filename);
     $path = get_custom_file_base() . '/uploads/' . $sections . '/' . $filename . '.dat';
     $myfile = @fopen($path, 'wb') or warn_exit(do_lang_tempcode('WRITE_ERROR', escape_html('uploads/' . $sections . '/' . $filename . '.dat')));
     if (fwrite($myfile, $data) < strlen($data)) {
         warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
     }
     fclose($myfile);
     fix_permissions($path);
     sync_file($path);
     $url = 'uploads/' . $sections . '/' . $filename . '.dat';
     return $url;
 }
Exemplo n.º 6
0
<?php

//print_r($_SESSION);
if (isset($_SESSION["userid"])) {
    db_connect();
    show_connection_details();
    if ($_POST["submit_filter"]) {
        process_submission();
    }
    if ($_POST["submit_export"]) {
        //print_r($_POST);
        sync_file();
    }
} else {
    echo "<font color='red'>Unauthorized access to this page. Please log in.</font>";
    echo "<br><a href='{$_SERVER['PHP_SELF']}'>Try Again</a>";
}
function db_connect()
{
    $db_conn = mysql_connect('localhost', $_SESSION["dbuser"], $_SESSION["dbpass"]) or die("Cannot query 14: " . mysql_error());
    mysql_select_db($_SESSION["dbname"], $db_conn) or die("Cannot query 15: " . mysql_error());
}
function show_connection_details()
{
    $q_user = mysql_query("SELECT user_lastname, user_firstname, user_id FROM game_user ORDER by user_lastname ASC, user_firstname ASC");
    $q_brgy = mysql_query("SELECT barangay_id, barangay_name FROM m_lib_barangay") or die("Cannot query 21: " . mysql_error());
    echo "<form action='{$_SERVER['PHP_SELF']}' method='POST'>";
    echo "<table border='1' width='50%' style='margin: 0 auto'>";
    echo "<tr><td>Current active database: </td><td>" . $_SESSION["dbname"] . "</td></tr>";
    echo "<tr><td>Select End User Account to Sync</td>";
    echo "<td><select name='sel_user'>";
Exemplo n.º 7
0
 /**
  * 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'));
 }
Exemplo n.º 8
0
/**
 * Create a video thumbnail.
 *
 * @param  URLPATH		Video to get thumbail from (must be local)
 * @param  ?PATH			Where to save to (NULL: decide for ourselves)
 * @return URLPATH		Thumbnail, only valid if expected_output_path was passed as NULL (blank: could not generate)
 */
function create_video_thumb($src_url, $expected_output_path = NULL)
{
    // Audio ones should have automatic thumbnails
    require_code('mime_types');
    $file_ext = get_file_extension($src_url);
    $input_mime_type = get_mime_type($file_ext);
    if (preg_match('#audio\\/#i', $input_mime_type) != 0) {
        $ret = find_theme_image('audio_thumb', true);
        if ($ret != '') {
            if (!is_null($expected_output_path)) {
                require_code('files');
                $_expected_output_path = fopen($expected_output_path, 'wb');
                http_download_file($ret, NULL, true, false, 'ocPortal', NULL, NULL, NULL, NULL, NULL, $_expected_output_path);
                fclose($_expected_output_path);
            }
        }
        return $ret;
    }
    // Try one of the hooks for video types
    $ve_hooks = find_all_hooks('systems', 'video_embed');
    foreach (array_keys($ve_hooks) as $ve_hook) {
        require_code('hooks/systems/video_embed/' . $ve_hook);
        $ve_ob = object_factory('Hook_video_embed_' . $ve_hook);
        $thumbnail = $ve_ob->get_video_thumbnail($src_url);
        if (!is_null($thumbnail)) {
            return $thumbnail;
        }
    }
    // Ok, gonna try hard using what FFMPEG techniques we can...
    if (substr($src_url, 0, strlen(get_custom_base_url() . '/')) == get_custom_base_url() . '/') {
        $src_url = substr($src_url, strlen(get_custom_base_url() . '/'));
    }
    if (!url_is_local($src_url)) {
        return '';
    }
    $src_file = get_custom_file_base() . '/' . rawurldecode($src_url);
    $src_file = preg_replace('#(\\\\|/)#', DIRECTORY_SEPARATOR, $src_file);
    if (class_exists('ffmpeg_movie')) {
        $filename = 'thumb_' . md5(uniqid('', true)) . '1.jpg';
        if (is_null($expected_output_path)) {
            $expected_output_path = get_custom_file_base() . '/uploads/galleries/' . $filename;
        }
        if (file_exists($expected_output_path)) {
            return 'uploads/galleries/' . rawurlencode(basename($expected_output_path));
        }
        $movie = @new ffmpeg_movie($src_file, false);
        if ($movie !== false) {
            if ($movie->getFrameCount() == 0) {
                return '';
            }
            $frame = $movie->getFrame(min($movie->getFrameCount(), 25));
            if (method_exists($frame, 'toGDImage')) {
                $gd_img = $frame->toGDImage();
                @imagejpeg($gd_img, $expected_output_path);
            } else {
                $frame->save($expected_output_path);
                // New-style
            }
            if (file_exists($expected_output_path)) {
                require_code('images');
                if (get_option('is_on_gd') == '1' && function_exists('imagecreatefromstring')) {
                    convert_image($expected_output_path, $expected_output_path, -1, -1, intval(get_option('thumb_width')), true, NULL, true);
                }
                return 'uploads/galleries/' . rawurlencode(basename($expected_output_path));
            }
        }
    }
    $ffmpeg_path = get_option('ffmpeg_path');
    if ($ffmpeg_path != '' && strpos(@ini_get('disable_functions'), 'shell_exec') === false) {
        $filename = 'thumb_' . md5(uniqid(strval(post_param_integer('thumbnail_auto_position', 1)), true)) . '%d.jpg';
        $dest_file = get_custom_file_base() . '/uploads/galleries/' . $filename;
        if (is_null($expected_output_path)) {
            $expected_output_path = str_replace('%d', '1', $dest_file);
        }
        if (file_exists($dest_file) && is_null(post_param_integer('thumbnail_auto_position', NULL))) {
            return 'uploads/galleries/' . rawurlencode(basename($expected_output_path));
        }
        @unlink($dest_file);
        // So "if (@filesize($expected_output_path)) break;" will definitely fail if error
        $dest_file = preg_replace('#(\\\\|/)#', DIRECTORY_SEPARATOR, $dest_file);
        $at = display_seconds_period(post_param_integer('thumbnail_auto_position', 1));
        if (strlen($at) == 5) {
            $at = '00:' . $at;
        }
        $shell_command = '"' . $ffmpeg_path . 'ffmpeg" -i ' . @escapeshellarg($src_file) . ' -an -ss ' . $at . ' -r 1 -vframes 1 -y ' . @escapeshellarg($dest_file);
        $shell_commands = array($shell_command, $shell_command . ' -map 0.0:0.0', $shell_command . ' -map 0.1:0.0');
        foreach ($shell_commands as $shell_command) {
            shell_exec($shell_command);
            if (@filesize($expected_output_path)) {
                break;
            }
        }
        if (file_exists(str_replace('%d', '1', $dest_file))) {
            require_code('images');
            if (get_option('is_on_gd') == '1' && function_exists('imagecreatefromstring')) {
                convert_image(str_replace('%d', '1', $dest_file), $expected_output_path, -1, -1, intval(get_option('thumb_width')), true, NULL, true);
            } else {
                copy(str_replace('%d', '1', $dest_file), $expected_output_path);
                fix_permissions($expected_output_path);
                sync_file($expected_output_path);
            }
            return 'uploads/galleries/' . rawurlencode(basename($expected_output_path));
        }
    }
    return '';
}
Exemplo n.º 9
0
 /**
  * Convert a AEF database file to an ocPortal uploaded file (stored on disk).
  *
  * @param  string			The file data
  * @param  string			The optimal filename
  * @param  ID_TEXT		The upload type (e.g. ocf_photos)
  * @param  PATH			The base directory we are importing from
  * @return array			Pair: The URL, the thumb url
  */
 function data_to_disk($data, $filename, $sections, $file_base)
 {
     $globals = array();
     require $file_base . '/universal.php';
     $attachments_dir = $globals['server_url'] . '/uploads/attachments/';
     //forum attachments directory
     $file_path = $attachments_dir . $filename;
     $data = $data == '' ? file_get_contents($file_path) : $data;
     $filename = find_derivative_filename('uploads/' . $sections, $filename);
     $path = get_custom_file_base() . '/uploads/' . $sections . '/' . $filename;
     $myfile = @fopen($path, 'wb') or warn_exit(do_lang_tempcode('WRITE_ERROR', escape_html('uploads/' . $sections . '/' . $filename)));
     if (fwrite($myfile, $data) < strlen($data)) {
         warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
     }
     fclose($myfile);
     fix_permissions($path);
     sync_file($path);
     $url = 'uploads/' . $sections . '/' . $filename;
     return array($url, $url);
 }
Exemplo n.º 10
0
 /**
  * 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'));
 }
Exemplo n.º 11
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;
}
Exemplo n.º 12
0
 /**
  * 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_news_and_categories($db, $table_prefix, $old_base_dir)
 {
     require_code('news');
     $fields = collapse_1d_complexity('id', $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('id'), array('c_name' => 'news')));
     $categories = $db->query("SELECT id,title,description,image FROM " . $table_prefix . "sections WHERE title='News'");
     foreach ($categories as $category) {
         $title = $category['title'];
         $cat_id = $GLOBALS['SITE_DB']->query_select('news_categories', array('id'), array('nc_title' => $title), '', 1);
         if (count($cat_id) == 0) {
             $cat_title = $category['title'];
             $category_id = $GLOBALS['SITE_DB']->query("SELECT N.id FROM " . $GLOBALS['SITE_DB']->get_table_prefix() . "translate  AS T INNER JOIN  " . $GLOBALS['SITE_DB']->get_table_prefix() . "news_categories AS N ON T.id=N.nc_title AND " . db_string_equal_to('T.text_original', $cat_title));
             if (count($category_id) == 0) {
                 $desc = html_to_comcode($category['description']);
                 $id = add_news_category($category['title'], $category['image'], $desc, NULL, NULL);
             } else {
                 $id = $category_id[0]['id'];
             }
         } else {
             $id = $cat_id[0]['id'];
         }
         $rows = $db->query('SELECT * FROM ' . $table_prefix . 'content WHERE sectionid=' . strval($category['id']));
         foreach ($rows as $row) {
             $val = $row['title'];
             $news_id = $GLOBALS['SITE_DB']->query("SELECT N.id FROM " . $GLOBALS['SITE_DB']->get_table_prefix() . "translate  AS T INNER JOIN  " . $GLOBALS['SITE_DB']->get_table_prefix() . "news AS N ON T.id=N.title AND " . db_string_equal_to('T.text_original', $val) . " AND news_category=" . strval($id) . " AND news_category<>''");
             if (count($news_id) == 0) {
                 $title = $row['title'];
                 $news = html_to_comcode($row['introtext']);
                 $author = $db->query_value_null_ok('users', 'name', array('id' => $row['created_by']));
                 if (is_null($author)) {
                     $author = do_lang('UNKNOWN');
                 }
                 $access = $row['access'];
                 if ($access == 0) {
                     $validated = 1;
                 } else {
                     $validated = 0;
                 }
                 $allow_rating = 1;
                 $allow_comments = 1;
                 $allow_trackbacks = 1;
                 $notes = '';
                 $news_article = '';
                 $main_news_category = $id;
                 $news_category = NULL;
                 $datetimearr = explode(' ', $row['created']);
                 $datearr = explode('-', $datetimearr[0]);
                 $timearr = explode(':', $datetimearr[1]);
                 $date = intval($datearr[2]);
                 $month = intval($datearr[1]);
                 $year = intval($datearr[0]);
                 $hour = intval($timearr[0]);
                 $min = intval($timearr[1]);
                 $sec = intval($timearr[2]);
                 $time = mktime($hour, $min, $sec, $month, $date, $year);
                 $submitter = import_id_remap_get('member', strval($row['created_by']));
                 $views = $row['hits'];
                 $datetimearr = explode(' ', $row['modified']);
                 $datearr = explode('-', $datetimearr[0]);
                 $timearr = explode(':', $datetimearr[1]);
                 $date = intval($datearr[2]);
                 $month = intval($datearr[1]);
                 $year = intval($datearr[0]);
                 $hour = intval($timearr[0]);
                 $min = intval($timearr[1]);
                 $sec = intval($timearr[2]);
                 $edit_date = mktime($hour, $min, $sec, $month, $date, $year);
                 $nid = NULL;
                 $image = 'newscats/' . preg_replace('#\\..*$#', '', $row['images']);
                 @mkdir(get_custom_file_base() . '/themes/default/images_custom/newscats', 0777);
                 fix_permissions(get_custom_file_base() . '/themes/default/images_custom/newscats', 0777);
                 sync_file(get_custom_file_base() . '/themes/default/images_custom/newscats');
                 $newimagepath = get_custom_file_base() . '/themes/default/images_custom/newscats/' . rawurldecode($row['images']);
                 $oldimagepath = $old_base_dir . "/images/stories/" . rawurldecode($row['images']);
                 @copy($oldimagepath, $newimagepath);
                 fix_permissions($newimagepath);
                 sync_file($newimagepath);
                 add_news($title, $news, $author, $validated, $allow_rating, $allow_comments, $allow_trackbacks, $notes, $news_article, $main_news_category, $news_category, $time, $submitter, $views, $edit_date, $nid, $image);
             }
         }
     }
 }
Exemplo n.º 13
0
 /**
  * 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;
 }
Exemplo n.º 14
0
 /**
  * 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());
 }
Exemplo n.º 15
0
/**
 * 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();
    }
}
Exemplo n.º 16
0
 /**
  * Standard import function. Note that this is designed for a very popular phpBB mod, and will exit silently if the mod hasn't been installed.
  *
  * @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_ocf_post_files($db, $table_prefix, $file_base)
 {
     global $STRICT_FILE;
     require_code('attachments2');
     require_code('attachments3');
     $options = $db->query('SELECT * FROM ' . $table_prefix . 'attachments_config WHERE ' . db_string_equal_to('config_name', 'upload_dir') . ' OR ' . db_string_equal_to('config_name', 'max_attachments') . ' OR ' . db_string_equal_to('config_name', 'use_gd2'), NULL, NULL, true);
     if (is_null($options)) {
         return;
     }
     $upload_dir = $options[0]['config_value'];
     $row_start = 0;
     $rows = array();
     do {
         $rows = $db->query('SELECT * FROM ' . $table_prefix . 'attachments a LEFT JOIN ' . $table_prefix . 'attachments_desc d ON a.attach_id=d.attach_id ORDER BY attach_id', 200, $row_start);
         foreach ($rows as $row) {
             if (import_check_if_imported('post_files', strval($row['attach_id']))) {
                 continue;
             }
             if ($row['post_id'] == 0) {
                 $post_id = import_id_remap_get('pt', strval($row['privmsgs_id']));
             } else {
                 $post_id = import_id_remap_get('post', strval($row['post_id']));
             }
             $post_row = $GLOBALS['FORUM_DB']->query_select('f_posts p LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON p.p_post=t.id', array('p_time', 'text_original', 'p_poster', 'p_post'), array('p.id' => $post_id), '', 1);
             if (!array_key_exists(0, $post_row)) {
                 import_id_remap_put('post_files', strval($row['attach_id']), 1);
                 continue;
                 // Orphaned post
             }
             $post = $post_row[0]['text_original'];
             $lang_id = $post_row[0]['p_post'];
             $member_id = import_id_remap_get('member', strval($row['user_id_1']), true);
             if (is_null($member_id)) {
                 $member_id = $post_row[0]['p_poster'];
             }
             $source_path = $file_base . '/' . $upload_dir . '/' . $row['physical_filename'];
             $new_filename = find_derivative_filename('attachments', $row['physical_filename']);
             $target_path = get_custom_file_base() . '/uploads/attachments/' . $new_filename;
             if (@rename($source_path, $target_path)) {
                 sync_file($target_path);
                 $url = 'uploads/attachments/' . urlencode($new_filename);
                 $thumb_url = '';
                 $a_id = $GLOBALS['SITE_DB']->query_insert('attachments', array('a_member_id' => $member_id, 'a_file_size' => $row['filesize'], 'a_url' => $url, 'a_thumb_url' => $thumb_url, 'a_original_filename' => $row['real_filename'], 'a_num_downloads' => $row['download_count'], 'a_last_downloaded_time' => NULL, 'a_add_time' => $row['filetime'], 'a_description' => ''), true);
                 $GLOBALS['SITE_DB']->query_insert('attachment_refs', array('r_referer_type' => 'ocf_post', 'r_referer_id' => strval($post_id), 'a_id' => $a_id));
                 $post .= "\n\n" . '[attachment="' . $row['comment'] . '"]' . strval($a_id) . '[/attachment]';
                 ocf_over_msn();
                 update_lang_comcode_attachments($lang_id, $post, 'ocf_post', strval($post_id));
                 ocf_over_local();
             }
             import_id_remap_put('post_files', strval($row['attach_id']), 1);
         }
         $row_start += 200;
     } while (count($rows) > 0);
 }
Exemplo n.º 17
0
/**
 * 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;
}
Exemplo n.º 18
0
 /**
  * The actualiser for super debranding.
  *
  * @return tempcode		The UI
  */
 function actual()
 {
     require_code('config2');
     if (get_file_base() == get_custom_file_base()) {
         require_code('abstract_file_manager');
         force_have_afm_details();
     }
     set_value('rebrand_name', post_param('rebrand_name'));
     set_value('rebrand_base_url', post_param('rebrand_base_url'));
     set_value('company_name', post_param('company_name'));
     set_option('show_docs', post_param('show_docs', '0'));
     require_code('database_action');
     //set_option('allow_member_integration','off');
     foreach (array(get_file_base() . '/pages/comcode_custom/' . get_site_default_lang(), get_file_base() . '/adminzone/pages/comcode_custom/' . get_site_default_lang()) as $dir) {
         if (!file_exists($dir)) {
             require_code('files');
             if (@mkdir($dir, 0777) === false) {
                 warn_exit(do_lang_tempcode('WRITE_ERROR_DIRECTORY_REPAIR', escape_html($dir)));
             }
             fix_permissions($dir, 0777);
             sync_file($dir);
         }
     }
     $keyboard_map_path = get_file_base() . '/pages/comcode_custom/' . get_site_default_lang() . '/keymap.txt';
     $myfile = @fopen($keyboard_map_path, 'wb');
     if ($myfile === false) {
         intelligent_write_error($keyboard_map_path);
     }
     $km = post_param('keyboard_map');
     if (fwrite($myfile, $km) < strlen($km)) {
         warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
     }
     fclose($myfile);
     fix_permissions($keyboard_map_path);
     sync_file($keyboard_map_path);
     $adminguide_path = get_file_base() . '/adminzone/pages/comcode_custom/' . get_site_default_lang() . '/website.txt';
     $adminguide = post_param('adminguide');
     $adminguide = str_replace('__company__', post_param('company_name'), $adminguide);
     $myfile = @fopen($adminguide_path, 'wb');
     if ($myfile === false) {
         intelligent_write_error($adminguide_path);
     }
     if (fwrite($myfile, $adminguide) < strlen($adminguide)) {
         warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
     }
     fclose($myfile);
     fix_permissions($adminguide_path);
     sync_file($adminguide_path);
     $start_path = get_file_base() . '/adminzone/pages/comcode_custom/' . get_site_default_lang() . '/start.txt';
     if (!file_exists($start_path)) {
         $start = post_param('start_page');
         $myfile = @fopen($start_path, 'wb');
         if ($myfile === false) {
             intelligent_write_error($start_path);
         }
         if (fwrite($myfile, $start) < strlen($start)) {
             warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
         }
         fclose($myfile);
         fix_permissions($start_path);
         sync_file($start_path);
     }
     if (get_file_base() == get_custom_file_base()) {
         $critical_errors = file_get_contents(get_file_base() . '/sources/critical_errors.php');
         $critical_errors = str_replace('ocPortal', post_param('rebrand_name'), $critical_errors);
         $critical_errors = str_replace('http://ocportal.com', post_param('rebrand_base_url'), $critical_errors);
         $critical_errors = str_replace('ocProducts', 'ocProducts/' . post_param('company_name'), $critical_errors);
         $critical_errors_path = 'sources_custom/critical_errors.php';
         afm_make_file($critical_errors_path, $critical_errors, false);
     }
     $save_header_path = get_file_base() . '/themes/' . $GLOBALS['FORUM_DRIVER']->get_theme() . '/templates_custom/HEADER.tpl';
     $header_path = $save_header_path;
     if (!file_exists($header_path)) {
         $header_path = get_file_base() . '/themes/default/templates/HEADER.tpl';
     }
     $header_tpl = file_get_contents($header_path);
     $header_tpl = str_replace('Copyright ocProducts Limited', '', $header_tpl);
     $myfile = @fopen($save_header_path, 'wb');
     if ($myfile === false) {
         intelligent_write_error($save_header_path);
     }
     if (fwrite($myfile, $header_tpl) < strlen($header_tpl)) {
         warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
     }
     fclose($myfile);
     fix_permissions($save_header_path);
     sync_file($save_header_path);
     if (post_param_integer('churchy', 0) == 1) {
         if (is_object($GLOBALS['FORUM_DB'])) {
             $GLOBALS['FORUM_DB']->query_delete('f_emoticons', array('e_code' => ':devil:'), '', 1);
         } else {
             $GLOBALS['SITE_DB']->query_delete('f_emoticons', array('e_code' => ':devil:'), '', 1);
         }
     }
     // Make sure some stuff is disabled for non-admin staff
     $staff_groups = $GLOBALS['FORUM_DRIVER']->get_moderator_groups();
     $disallowed_pages = array('admin_setupwizard', 'admin_addons', 'admin_backup', 'admin_errorlog', 'admin_import', 'admin_occle', 'admin_phpinfo', 'admin_debrand');
     foreach (array_keys($staff_groups) as $id) {
         foreach ($disallowed_pages as $page) {
             $GLOBALS['SITE_DB']->query_delete('group_page_access', array('page_name' => $page, 'zone_name' => 'adminzone', 'group_id' => $id), '', 1);
             // in case already exists
             $GLOBALS['SITE_DB']->query_insert('group_page_access', array('page_name' => $page, 'zone_name' => 'adminzone', 'group_id' => $id));
         }
     }
     // Clean up the theme images
     //  background-image
     $theme = $GLOBALS['FORUM_DRIVER']->get_theme();
     find_theme_image('background_image');
     //$GLOBALS['SITE_DB']->query_update('theme_images',array('path'=>'themes/default/images/blank.gif'),array('id'=>'background-image','theme'=>$theme),'',1); No longer ocp-specific
     //  logo/*
     if (addon_installed('zone_logos')) {
         find_theme_image('logo/adminzone-logo');
         find_theme_image('logo/cms-logo');
         find_theme_image('logo/collaboration-logo');
         $main_logo_url = find_theme_image('logo/-logo', false, true);
         $GLOBALS['SITE_DB']->query_update('theme_images', array('path' => $main_logo_url), array('id' => 'logo/adminzone-logo', 'theme' => $theme), '', 1);
         $GLOBALS['SITE_DB']->query_update('theme_images', array('path' => $main_logo_url), array('id' => 'logo/cms-logo', 'theme' => $theme), '', 1);
         $GLOBALS['SITE_DB']->query_update('theme_images', array('path' => $main_logo_url), array('id' => 'logo/collaboration-logo', 'theme' => $theme), '', 1);
     }
     // Various other icons
     require_code('uploads');
     $path = get_url('', 'favicon', 'themes/default/images_custom');
     if ($path[0] != '') {
         $GLOBALS['SITE_DB']->query_update('theme_images', array('path' => $path[0]), array('id' => 'favicon'));
     }
     $path = get_url('', 'appleicon', 'themes/default/images_custom');
     if ($path[0] != '') {
         $GLOBALS['SITE_DB']->query_update('theme_images', array('path' => $path[0]), array('id' => 'appleicon'));
     }
     if (addon_installed('ocf_avatars')) {
         $path = get_url('', 'system_avatar', 'themes/default/images_custom');
         if ($path[0] != '') {
             $GLOBALS['SITE_DB']->query_update('theme_images', array('path' => $path[0]), array('id' => 'ocf_default_avatars/default_set/ocp_fanatic'));
         }
     }
     $title = get_page_title('SUPER_DEBRAND');
     // Redirect them back to editing screen
     $url = build_url(array('page' => '_SELF', 'type' => 'misc'), '_SELF');
     return redirect_screen($title, $url, do_lang_tempcode('SUCCESS'));
 }
Exemplo n.º 19
0
// List of TA/graders json
$code_exts = array('py', 'php', 'xml', 'csv', 'html', 'xhtml', 'css', 'js', 'sql', 'java', 'json');
$image_exts = array('jpg', 'jpeg', 'tiff', 'png', 'gif', 'bmp');
$validation_exts = array('php', 'css', 'html', 'xhtml');
$assignments = get_assignments($admin_path, $assignment_filename, 'noSubmit');
$restricted_assignments = get_restricted_assignments($admin_path, $assignment_filename, 'noSubmit');
$sync = array("{$bob_url}/bin/admin_{$crn}" => "{$admin_path}/admin.php", "{$bob_url}/json/{$assignment_filename}" => "{$admin_path}/{$assignment_filename}", "{$bob_url}/json/{$privileged_filename}" => "{$admin_path}/{$privileged_filename}");
$body = array();
$title = "ADMIN:";
// If there are no get statements then just list all available assignments.
// Also try to synchronize our files.
if (empty($_GET)) {
    $title .= " Listing Assignments";
    $body[] = list_assignments($assignments, $class_path);
    foreach ($sync as $remote => $local) {
        $body[] = sync_file($remote, $local);
    }
    $body[] = update_admin_htaccess($admin_path, $privileged_filename, $restricted_assignments);
    $body[] = create_class_htaccess($class_path);
}
// If a folder is requested then display its contents
if (isset($_GET['folder'])) {
    $title .= " Listing Folder Contents";
    $folder = clean_path(filter_input(INPUT_GET, 'folder', FILTER_SANITIZE_SPECIAL_CHARS));
    $file_paths = bob_scandir("{$class_path}/{$folder}", $admin_path, false);
    if ($file_paths === False) {
        $body[] = "<p class=\"error\">Folder does not exist. You should create it!</p>";
    } else {
        $body[] = list_files($file_paths, $class_path, $class_folder, $code_exts, $validation_exts, $assignments[$folder]);
    }
}
Exemplo n.º 20
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);
 }
Exemplo n.º 21
0
/**
 * 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);
}
            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>';
Exemplo n.º 23
0
 /**
  * The actualiser for uploading a file.
  *
  * @return tempcode	The UI.
  */
 function module_do_upload()
 {
     if (!has_specific_permission(get_member(), 'upload_filedump')) {
         access_denied('I_ERROR');
     }
     $title = get_page_title('FILEDUMP_UPLOAD');
     if (function_exists('set_time_limit')) {
         @set_time_limit(0);
     }
     // Slowly uploading a file can trigger time limit, on some servers
     $place = filter_naughty(post_param('place'));
     require_code('uploads');
     if (!is_swf_upload(true) && (!array_key_exists('file', $_FILES) || !is_uploaded_file($_FILES['file']['tmp_name']))) {
         $attach_name = 'file';
         $max_size = get_max_file_size();
         if (isset($_FILES[$attach_name]) && ($_FILES[$attach_name]['error'] == 1 || $_FILES[$attach_name]['error'] == 2)) {
             warn_exit(do_lang_tempcode('FILE_TOO_BIG', integer_format($max_size)));
         } elseif (isset($_FILES[$attach_name]) && ($_FILES[$attach_name]['error'] == 3 || $_FILES[$attach_name]['error'] == 6 || $_FILES[$attach_name]['error'] == 7)) {
             warn_exit(do_lang_tempcode('ERROR_UPLOADING_' . strval($_FILES[$attach_name]['error'])));
         } else {
             warn_exit(do_lang_tempcode('ERROR_UPLOADING'));
         }
     }
     $file = $_FILES['file']['name'];
     if (get_magic_quotes_gpc()) {
         $file = stripslashes($file);
     }
     if (!has_specific_permission(get_member(), 'upload_anything_filedump') || get_file_base() != get_custom_file_base()) {
         check_extension($file);
     }
     $file = str_replace('.', '-', basename($file, '.' . get_file_extension($file))) . '.' . get_file_extension($file);
     if (!file_exists(get_custom_file_base() . '/uploads/filedump' . $place . $file)) {
         $max_size = get_max_file_size();
         if ($_FILES['file']['size'] > $max_size) {
             warn_exit(do_lang_tempcode('FILE_TOO_BIG', integer_format(intval($max_size))));
         }
         $full = get_custom_file_base() . '/uploads/filedump' . $place . $file;
         if (is_swf_upload(true)) {
             @rename($_FILES['file']['tmp_name'], $full) or warn_exit(do_lang_tempcode('FILE_MOVE_ERROR', escape_html($file), escape_html('uploads/filedump' . $place)));
         } else {
             @move_uploaded_file($_FILES['file']['tmp_name'], $full) or warn_exit(do_lang_tempcode('FILE_MOVE_ERROR', escape_html($file), escape_html('uploads/filedump' . $place)));
         }
         fix_permissions($full);
         sync_file($full);
         $return_url = build_url(array('page' => '_SELF', 'place' => $place), '_SELF');
         $test = $GLOBALS['SITE_DB']->query_value_null_ok('filedump', 'description', array('name' => $file, 'path' => $place));
         if (!is_null($test)) {
             delete_lang($test);
         }
         $GLOBALS['SITE_DB']->query_delete('filedump', array('name' => $file, 'path' => $place), '', 1);
         $description = post_param('description');
         $GLOBALS['SITE_DB']->query_insert('filedump', array('name' => $file, 'path' => $place, 'the_member' => get_member(), 'description' => insert_lang_comcode($description, 3)));
         require_code('notifications');
         $subject = do_lang('FILEDUMP_NOTIFICATION_MAIL_SUBJECT', get_site_name(), $file, $place);
         $mail = do_lang('FILEDUMP_NOTIFICATION_MAIL', comcode_escape(get_site_name()), comcode_escape($file), array(comcode_escape($place), comcode_escape($description)));
         dispatch_notification('filedump', $place, $subject, $mail);
         log_it('FILEDUMP_UPLOAD', $file, $place);
         if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), get_page_name(), get_zone_name())) {
             syndicate_described_activity('filedump:ACTIVITY_FILEDUMP_UPLOAD', $place . '/' . $file, '', '', '', '', '', 'filedump');
         }
         return redirect_screen($title, $return_url, do_lang_tempcode('SUCCESS'));
     } else {
         warn_exit(do_lang_tempcode('OVERWRITE_ERROR'));
     }
     return new ocp_tempcode();
 }
Exemplo n.º 24
0
 /**
  * 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'));
 }
Exemplo n.º 25
0
 function testNoMissingParams()
 {
     global $ATTACHED_MESSAGES, $ATTACHED_MESSAGES_RAW;
     $lists = find_all_previews__by_screen();
     foreach ($lists as $function => $tpls) {
         $template = $tpls[0];
         $hook = NULL;
         if (is_file(get_file_base() . '/_tests/screens_tested/nonemissing__' . $function)) {
             continue;
         }
         // To make easier to debug through
         if (function_exists('set_time_limit')) {
             @set_time_limit(0);
         }
         $ATTACHED_MESSAGES = new ocp_tempcode();
         $ATTACHED_MESSAGES_RAW = array();
         $out1 = render_screen_preview($template, $hook, $function);
         $put_out = !$ATTACHED_MESSAGES->is_empty() || count($ATTACHED_MESSAGES_RAW) > 0;
         $this->assertFalse($put_out, 'Messages put out by ' . $function . '  (' . strip_tags($ATTACHED_MESSAGES->evaluate()) . ')');
         if (!$put_out) {
             fclose(fopen(get_file_base() . '/_tests/screens_tested/nonemissing__' . $function, 'wb'));
             sync_file(get_file_base() . '/_tests/screens_tested/nonemissing__' . $function);
             fix_permissions(get_file_base() . '/_tests/screens_tested/nonemissing__' . $function);
         }
         unset($out1);
     }
 }
Exemplo n.º 26
0
 /**
  * Convert an SMF database file to an ocPortal uploaded file (stored on disk).
  *
  * @param  string			The file data
  * @param  string			The optimal filename
  * @param  ID_TEXT		The upload type (e.g. ocf_photos)
  * @param  object			The DB connection to import from
  * @param  string			The table prefix the target prefix is using
  * @param  string			The filename to output to
  * @param  PATH			The base directory we are importing from
  * @param  string			Attachment ID
  * @return URLPATH		The URL
  */
 function data_to_disk($data, $filename, $sections, $db, $table_prefix = '', $output_filename = '', $file_base = '', $attachment_id = '', $ext = '.png')
 {
     $boardurl = '';
     $boarddir = '';
     require $file_base . '/Settings.php';
     $homeurl = $boardurl;
     $forum_dir = preg_replace('#\\\\#', '/', $boarddir);
     //full path to the forum folder
     $attachments_dir = $forum_dir . '/attachments/';
     //forum attachments directory
     $filename_fixed = $filename . $ext;
     $file_path = $attachments_dir . $filename;
     $data = $data == '' ? @file_get_contents($file_path) : $data;
     $filename = $output_filename == '' ? $filename_fixed : $output_filename;
     $filename = find_derivative_filename('uploads/' . $sections, $filename);
     $path = get_custom_file_base() . '/uploads/' . $sections . '/' . $filename;
     $myfile = @fopen($path, 'wb') or warn_exit(do_lang_tempcode('WRITE_ERROR', escape_html('uploads/' . $sections . '/' . $filename)));
     fwrite($myfile, $data);
     fclose($myfile);
     fix_permissions($path);
     sync_file($path);
     $url = 'uploads/' . $sections . '/' . $filename;
     return $url;
 }
Exemplo n.º 27
0
 /**
  * Convert a VB database file to an ocPortal uploaded file (stored on disk).
  *
  * @param  string			The file data
  * @param  string			The optimal filename
  * @param  ID_TEXT		The upload type (e.g. ocf_photos)
  * @param  boolean		Whether to create a thumbnail for it
  * @param  string			Thumbnail data (blank: no thumbnail / generate one if asked)
  * @param  boolean		Whether to obfuscate the file type
  * @return array			A tuple containing the URL, and if requested, the thumbnail
  */
 function data_to_disk($data, $filename, $sections, $thumbnail = true, $thumbnail_data = '', $obfuscate = false)
 {
     if ($filename == '') {
         $filetype = '';
         if (substr($data, 4, 4) == 'JFIF') {
             $filetype = 'jpg';
         } elseif (substr($data, 0, 3) == 'GIF') {
             $filetype = 'gif';
         } elseif (substr($data, 1, 3) == 'PNG') {
             $filetype = 'png';
         }
         if ($filetype != '') {
             $filename = uniqid('', true) . '.' . $filetype;
         }
     }
     //if ((substr($filename,-4,4)=='.gif') && ($thumbnail)) $filename.='.png';
     if ($filename != '') {
         $filename = find_derivative_filename('uploads/' . $sections, $filename);
         $path = get_custom_file_base() . '/uploads/' . $sections . '/' . $filename . ($obfuscate ? '.dat' : '');
         $myfile = @fopen($path, 'wb') or warn_exit(do_lang_tempcode('WRITE_ERROR', escape_html('uploads/' . $sections . '/' . $filename . ($obfuscate ? '.dat' : ''))));
         if (fwrite($myfile, $data) < strlen($data)) {
             warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
         }
         fclose($myfile);
         fix_permissions($path);
         sync_file($path);
         $url = 'uploads/' . $sections . '/' . $filename . ($obfuscate ? '.dat' : '');
         if ($thumbnail_data == '') {
             if ($thumbnail) {
                 $t_filename = $filename;
                 $thumb_url = 'uploads/' . $sections . '_thumbs/' . find_derivative_filename('_thumbs', $t_filename, true);
                 require_code('images');
                 convert_image(get_custom_base_url() . '/' . $url, $thumb_url, -1, -1, intval(get_option('thumb_width')), false, NULL, true);
                 return array($url, $thumb_url);
             } else {
                 return array($url, '');
             }
         } else {
             $thumb_filename = find_derivative_filename('uploads/' . $sections . '_thumbs', $filename);
             $path = get_custom_file_base() . '/uploads/' . $sections . '_thumbs/' . $thumb_filename;
             $myfile = @fopen($path, 'wb') or warn_exit(do_lang_tempcode('WRITE_ERROR', escape_html('uploads/' . $sections . '_thumbs/' . $thumb_filename)));
             if (fwrite($myfile, $thumbnail_data) < strlen($thumbnail_data)) {
                 warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
             }
             fclose($myfile);
             $thumb_url = 'uploads/' . $sections . '/' . $thumb_filename;
             fix_permissions($path);
             sync_file($path);
             return array($url, $thumb_url);
         }
     }
     return array('', '');
 }
Exemplo n.º 28
0
 function get($url, $parameters = NULL)
 {
     $parts = array();
     if (preg_match('#([\\w-]*):([\\w-]+|[^/]|$)((:(.*))*)#', $url, $parts) != 0 && $parts[1] != 'mailto') {
         list($zone_name, $vars, $hash) = page_link_decode($url);
         $real_url = _build_url($vars, $zone_name, NULL, false, false, false, $hash);
         $ret = parent::get($real_url, $parameters);
     } else {
         $ret = parent::get($url, $parameters);
     }
     // Save, so we can run validation on it later
     $path = get_file_base() . '/_tests/html_dump/' . get_class($this);
     if (!file_exists($path)) {
         mkdir($path, 0777);
     }
     $content = $this->_browser->getContent();
     $outfile = fopen($path . '/' . url_to_filename($url) . '.htm', 'wb');
     fwrite($outfile, $content);
     fclose($outfile);
     sync_file($path . '/' . url_to_filename($url) . '.htm');
     fix_permissions($path . '/' . url_to_filename($url) . '.htm');
     // Save the text so we can run through Word's grammar checker
     $text_content = $content;
     $text_content = preg_replace('#<[^>]* title="([^"]+)"<[^>]*>#U', '\\1', $text_content);
     $text_content = preg_replace('#<[^>]* alt="([^"]+)"<[^>]*>#U', '\\1', $text_content);
     $text_content = preg_replace('#<style[^>]*>.*</style>#Us', '', $text_content);
     $text_content = preg_replace('#<script[^>]*>.*</script>#Us', '', $text_content);
     $text_content = preg_replace('#<[^>]*>#U', '', $text_content);
     $text_content = preg_replace('#\\s\\s+#', '. ', $text_content);
     $text_content = str_replace('&ndash;', '-', $text_content);
     $text_content = str_replace('&mdash;', '-', $text_content);
     $text_content = str_replace('&hellip;', '...', $text_content);
     $text_content = @html_entity_decode($text_content, ENT_QUOTES);
     $outfile = fopen($path . '/' . url_to_filename($url) . '.txt', 'wb');
     fwrite($outfile, $text_content);
     fclose($outfile);
     return $ret;
 }
 See text/EN/licence.txt for full licencing information.
 NOTE TO PROGRAMMERS:
   Do not edit this file. If you need to make changes, save your changed file to the appropriate *_custom folder
   **** If you ignore this advice, then your website upgrades (e.g. for bug fixes) will likely kill your changes ****
*/
/*
Used to generate a database schema in the form of SQL code that can be imported into MySQL Workbench

First run this, then run SQLEditor on the files created in uploads/website_specific.
*/
require_code('relations');
$all_tables = get_all_tables();
$tables_by = get_tables_by_addon();
foreach ($tables_by as $t => $ts) {
    $path = get_custom_file_base() . '/uploads/website_specific/ocportal_erd__' . $t . '.sql';
    $myfile = fopen($path, 'wt');
    $tables = array();
    foreach ($ts as $table) {
        if (!array_key_exists($table, $all_tables)) {
            continue;
        }
        // Not installed
        $tables[$table] = $all_tables[$table];
    }
    fwrite($myfile, get_innodb_table_sql($tables, $all_tables));
    fclose($myfile);
    fix_permissions($path);
    sync_file($path);
}
$GLOBALS['SCREEN_TEMPLATE_CALLED'] = '';
echo 'Done, files generated in <kbd>uploads/website_specific</kbd>.';
Exemplo n.º 30
0
 /**
  * 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);
 }