/** * 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); }
/** * A template has not been structurally cached, so compile it and store in the cache. * * @param ID_TEXT The theme the template is in the context of * @param PATH The path to the template file * @param ID_TEXT The codename of the template (e.g. foo) * @param ID_TEXT The actual codename to use for the template (e.g. thin_foo) * @param LANGUAGE_NAME The language the template is in the context of * @param string File type suffix of template file * @param ?ID_TEXT The theme to cache in (NULL: main theme) * @return tempcode The compiled tempcode */ function _do_template($theme, $path, $codename, $_codename, $lang, $suffix, $theme_orig = NULL) { if (is_null($theme_orig)) { $theme_orig = $theme; } $base_dir = ($theme == 'default' && ($suffix != '.css' || strpos($path, '/css_custom') === false) ? get_file_base() : get_custom_file_base()) . '/themes/'; global $CACHE_TEMPLATES, $FILE_ARRAY, $TEMPLATE_PREVIEW_OP, $MEM_CACHE; if (isset($FILE_ARRAY)) { $html = unixify_line_format(file_array_get('themes/' . $theme . $path . $codename . $suffix)); } else { $html = unixify_line_format(file_get_contents($base_dir . filter_naughty($theme . $path . $codename) . $suffix, FILE_TEXT)); } if (strpos($html, '{$,Parser hint: pure}') !== false) { return make_string_tempcode(preg_replace('#\\{\\$,.*\\}#U', '/*no minify*/', $html)); } if ($GLOBALS['SEMI_DEBUG_MODE'] && strpos($html, '.innerHTML') !== false && strpos($html, 'Parser hint: .innerHTML okay') === false) { require_code('site'); attach_message('Do not use the .innerHTML property in your Javascript because it will not work in true XHTML (when the browsers real XML parser is in action). Use ocPortal\'s global setInnerHTML/getInnerHTML functions.', 'warn'); } // Strip off trailing final lines from single lines templates. Editors often put these in, and it causes annoying "visible space" issues if (substr($html, -1, 1) == chr(10) && substr_count($html, chr(10)) == 1) { $html = substr($html, 0, strlen($html) - 1); } if ($TEMPLATE_PREVIEW_OP) { $test = post_param($codename, NULL); if (!is_null($test)) { $html = post_param($test . '_new'); } } $result = template_to_tempcode($html, 0, false, $codename, $theme, $lang); if ($CACHE_TEMPLATES && ($suffix == '.tpl' || $codename == 'no_cache')) { if (!is_null($MEM_CACHE)) { persistant_cache_set(array('TEMPLATE', $theme, $lang, $_codename), $result->to_assembly(), strpos($path, 'default/templates/') !== false); } else { $path2 = get_custom_file_base() . '/themes/' . $theme_orig . '/templates_cached/' . filter_naughty($lang) . '/'; $myfile = @fopen($path2 . filter_naughty($_codename) . $suffix . '.tcd', 'wb'); if ($myfile === false) { if (@mkdir($path2, 0777)) { require_code('files'); fix_permissions($path2, 0777); } else { if (file_exists($path2 . filter_naughty($_codename) . $suffix . '.tcd')) { warn_exit(do_lang_tempcode('WRITE_ERROR', $path2 . filter_naughty($_codename) . $suffix . '.tcd')); } else { warn_exit(do_lang_tempcode('WRITE_ERROR_CREATE', $path2 . filter_naughty($_codename) . $suffix . '.tcd')); } } } else { fwrite($myfile, $result->to_assembly($lang)); fclose($myfile); fix_permissions($path2 . filter_naughty($_codename) . $suffix . '.tcd'); } } } return $result; }
function fix_permissions($ff) { $ff->setPermissions("-rwxrwxr-x"); if ($ff->isDir()) { $all_files = $ff->listFiles(); foreach ($all_files as $f) { fix_permissions($f); } } }
function run() { $file = basename(rawurldecode($_GET['url'])); //get old media file data $get_old_file = $GLOBALS['SITE_DB']->query('SELECT url FROM ' . get_table_prefix() . 'videos WHERE url LIKE "uploads/galleries/' . rawurlencode(basename(basename($file, '.m4v'), '.mp3')) . '%"'); $type = 'galleries'; if (!array_key_exists(0, $get_old_file)) { $get_old_file = $GLOBALS['SITE_DB']->query('SELECT a_url AS url FROM ' . get_table_prefix() . 'attachments WHERE a_url LIKE "uploads/attachments/' . rawurlencode(basename(basename($file, '.m4v'), '.mp3')) . '%"'); $type = 'attachments'; if (!array_key_exists(0, $get_old_file)) { $get_old_file = $GLOBALS['SITE_DB']->query('SELECT cv_value AS url FROM ' . get_table_prefix() . 'catalogue_efv_short WHERE cv_value LIKE "uploads/catalogues/' . rawurlencode(basename(basename($file, '.m4v'), '.mp3')) . '%"'); $type = 'catalogues'; } } require_code('files'); $file_handle = @fopen(get_custom_file_base() . '/uploads/' . $type . '/' . $file, 'wb') or intelligent_write_error(get_custom_file_base() . '/uploads/' . $type . '/' . $file); http_download_file($_GET['url'], NULL, false, false, 'ocPortal', NULL, NULL, NULL, NULL, NULL, $file_handle, NULL, NULL, 6.0); fclose($file_handle); //move the old media file to the archive directory - '/uploads/'.$type.'/archive/' $new_url = 'uploads/' . $type . '/' . rawurlencode($file); if (isset($get_old_file[0]['url']) && is_string($get_old_file[0]['url']) && $get_old_file[0]['url'] != $new_url && strlen($get_old_file[0]['url']) > 0) { $movedir = dirname(str_replace('/uploads/' . $type . '/', '/uploads/' . $type . '_archive_addon/', str_replace('\\', '/', get_custom_file_base()) . '/' . rawurldecode($get_old_file[0]['url']))); @mkdir($movedir, 0777); require_code('files'); fix_permissions($movedir, 0777); rename(str_replace('\\', '/', get_custom_file_base()) . '/' . rawurldecode($get_old_file[0]['url']), str_replace('/uploads/' . $type . '/', '/uploads/' . $type . '_archive_addon/', str_replace('\\', '/', get_custom_file_base()) . '/' . rawurldecode($get_old_file[0]['url']))); } switch ($type) { case 'galleries': $GLOBALS['SITE_DB']->query('UPDATE ' . get_table_prefix() . 'videos SET video_width=600,video_height=400,url="' . db_escape_string($new_url) . '" WHERE url LIKE "uploads/' . $type . '/' . db_escape_string(rawurlencode(basename(basename($file, '.m4v'), '.mp3'))) . '%"'); // Replaces row that referenced $file without .m4v on the end (the original filename) with row that references the new $file we just copied break; case 'attachments': $GLOBALS['SITE_DB']->query('UPDATE ' . get_table_prefix() . 'attachments SET a_url="' . db_escape_string($new_url) . '" WHERE a_url LIKE "uploads/' . $type . '/' . db_escape_string(rawurlencode(basename(basename($file, '.m4v'), '.mp3'))) . '%"'); // Replaces row that referenced $file without .m4v on the end (the original filename) with row that references the new $file we just copied break; case 'catalogues': $GLOBALS['SITE_DB']->query('UPDATE ' . get_table_prefix() . 'catalogue_efv_short SET cv_value="' . db_escape_string($new_url) . '" WHERE cv_value LIKE "uploads/' . $type . '/' . db_escape_string(rawurlencode(basename(basename($file, '.m4v'), '.mp3'))) . '%"'); // Replaces row that referenced $file without .m4v on the end (the original filename) with row that references the new $file we just copied break; } $transcoding_server = get_option('transcoding_server', true); if (is_null($transcoding_server)) { //add option and default value add_config_option('TRANSCODING_SERVER', 'transcoding_server', 'line', 'return \'http://localhost/convertor\';', 'FEATURE', 'GALLERIES'); $transcoding_server = get_option('transcoding_server', true); } file_get_contents($transcoding_server . '/move_to_sent.php?file=' . $_GET['url']); }
/** * 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); }
/** * 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')); }
/** * 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 }
/** * 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; }
/** * Fifth installation step: FTP upload (not used for manual installer). * * @return array A pair: progress report/ui, and number of files uploaded so far (or -1 meaning all uploaded) */ function step_5_ftp() { global $FILE_ARRAY, $DIR_ARRAY; if (count($_POST) == 0) { exit(do_lang('INST_POST_ERROR')); } if (!is_suexec_like()) { if (!function_exists('ftp_connect')) { warn_exit(do_lang_tempcode('NO_PHP_FTP')); } $ftp_domain = trim(post_param('ftp_domain')); if (strpos($ftp_domain, 'ftp://') !== false) { warn_exit(do_lang_tempcode('FTP_DOMAIN_NOT_LIKE_THIS')); } $port = 21; if (strpos($ftp_domain, ':') !== false) { list($ftp_domain, $_port) = explode(':', $ftp_domain, 2); $port = intval($_port); } $conn = false; if (function_exists('ftp_ssl_connect')) { $conn = @ftp_ssl_connect($ftp_domain, $port); } $ssl = $conn !== false; $username = trim(post_param('ftp_username')); $password = trim(post_param('ftp_password')); if ($ssl && @ftp_login($conn, $username, $password) === false) { $conn = false; $ssl = false; } if ($conn === false) { $conn = ftp_connect($ftp_domain, $port); } if ($conn === false) { warn_exit(do_lang_tempcode('NO_FTP_CONNECT')); } if (!$ssl && !@ftp_login($conn, $username, $password)) { warn_exit(do_lang_tempcode('NO_FTP_LOGIN', @strval($php_errormsg))); } $ftp_folder = post_param('ftp_folder'); if (substr($ftp_folder, -1) != '/') { $ftp_folder .= '/'; } if (!@ftp_chdir($conn, $ftp_folder)) { warn_exit(do_lang_tempcode('NO_FTP_DIR', @strval($php_errormsg), '1')); } $files = @ftp_nlist($conn, '.'); if ($files === false) { $files = array(); if (@ftp_rename($conn, 'install.php', 'install.php')) { $files = array('install.php', 'data.ocp'); } } if (!in_array('install.php', $files)) { warn_exit(do_lang_tempcode('NO_FTP_DIR', @strval($php_errormsg), '2')); } $overwrite_ok = !file_exists(get_file_base() . '/ocp_inst_tmp/tmp'); // Because if the file doesn't exist, the step completed in full - we DON'T want to overwrite if it didn't, because the step probably timed out and by refreshing we complete the step in pieces if (!file_exists('ocp_inst_tmp')) { // Make temporary directory if (!in_array('ocp_inst_tmp', $files) && !is_string(@ftp_mkdir($conn, 'ocp_inst_tmp'))) { warn_exit(do_lang_tempcode('NO_FTP_ACCESS')); } @ftp_site($conn, 'CHMOD 0777 ocp_inst_tmp'); } if (!is_writable_wrap('ocp_inst_tmp')) { warn_exit(do_lang_tempcode('MANUAL_CHMOD_TMP_FILE')); } // Test tmp file isn't currently being used by another iteration of process (race issue, causing horrible corruption) $file_size_before = @filesize(get_file_base() . '/ocp_inst_tmp/tmp'); sleep(1); $file_size_after = @filesize(get_file_base() . '/ocp_inst_tmp/tmp'); if ($file_size_before !== $file_size_after) { warn_exit(do_lang_tempcode('DATA_FILE_CONFLICT')); } // Test tmp file isn't currently being used by another iteration of process (race issue, causing horrible corruption) $lock_myfile = fopen(get_file_base() . '/ocp_inst_tmp/tmp', 'ab'); if (!defined('PHALANGER')) { if (!flock($lock_myfile, LOCK_EX)) { warn_exit(do_lang_tempcode('DATA_FILE_CONFLICT')); } } $file_size_before = @filesize(get_file_base() . '/ocp_inst_tmp/tmp'); sleep(1); $file_size_after = @filesize(get_file_base() . '/ocp_inst_tmp/tmp'); if ($file_size_before !== $file_size_after) { warn_exit(do_lang_tempcode('DATA_FILE_CONFLICT')); } fclose($lock_myfile); } else { $overwrite_ok = true; $files = array(); if (file_exists(get_file_base() . '/info.php')) { $files[] = 'info.php'; } } // Make folders $langs1 = get_dir_contents('lang'); $langs2 = get_dir_contents('lang_custom'); $langs = array_merge($langs1, $langs2); foreach ($DIR_ARRAY as $dir) { if (strpos($dir, '/' . fallback_lang()) !== false) { foreach (array_keys($langs) as $lang) { if ($lang == fallback_lang() || strpos($lang, '.') !== false) { continue; } if (is_suexec_like()) { @mkdir(get_file_base() . '/' . str_replace('/' . fallback_lang(), '/' . $lang, $dir), 0777); fix_permissions(get_file_base() . '/' . str_replace('/' . fallback_lang(), '/' . $lang, $dir), 0777); } else { @ftp_mkdir($conn, str_replace('/' . fallback_lang(), '/' . $lang, $dir)); @ftp_site($conn, 'CHMOD 755 ' . str_replace('/' . fallback_lang(), '/' . $lang, $dir)); } } } if (is_suexec_like()) { @mkdir(get_file_base() . '/' . $dir, 0777); fix_permissions(get_file_base() . '/' . $dir, 0777); } else { @ftp_mkdir($conn, $dir); if ($dir == 'exports/mods' && !is_suexec_like()) { @ftp_site($conn, 'CHMOD 777 ' . $dir); } else { @ftp_site($conn, 'CHMOD 755 ' . $dir); } } } // Upload files $count = file_array_count(); $php_perms = fileperms(get_file_base() . '/install.php'); $start_pos = get_param_integer('start_from', 0); $done_all = false; $time_start = time(); $max_time = intval(round(floatval(ini_get('max_execution_time')) / 1.5)); $max = post_param_integer('max', is_suexec_like() ? 5000 : 1000); for ($i = $start_pos; $i < $start_pos + $max; $i++) { list($filename, $contents) = file_array_get_at($i); if (is_string($contents)) { $file_size = strlen($contents); } else { list($file_size, $dump_myfile, $dump_offset) = $contents; } if ($filename != 'info.php' || !in_array('info.php', $files)) { if (($overwrite_ok || !file_exists(get_file_base() . '/' . $filename) || @filemtime(get_file_base() . '/' . $filename) < filemtime(get_file_base() . '/install.php') || filesize(get_file_base() . '/' . $filename) != $file_size) && ($filename != 'forum/index.php' || !file_exists(get_file_base() . '/' . $filename))) { if (strpos($filename, '/' . fallback_lang() . '/') !== false && is_string($contents)) { foreach (array_keys($langs) as $lang) { if ($lang == fallback_lang() || strpos($lang, '.') !== false) { continue; } if (is_suexec_like()) { $myfile = fopen(get_file_base() . '/' . str_replace('/' . fallback_lang() . '/', '/' . $lang . '/', $filename), 'wb'); fwrite($myfile, $contents); fclose($myfile); fix_permissions(get_file_base() . '/' . str_replace('/' . fallback_lang() . '/', '/' . $lang . '/', $filename), 0666); } else { @ftp_delete($conn, str_replace('/' . fallback_lang() . '/', '/' . $lang . '/', $filename)); $tmp = fopen(get_file_base() . '/ocp_inst_tmp/tmp', 'wb'); fwrite($tmp, $contents); fclose($tmp); ftp_put($conn, str_replace('/' . fallback_lang() . '/', '/' . $lang . '/', $filename), get_file_base() . '/ocp_inst_tmp/tmp', FTP_BINARY); $mask = 0; if (get_file_extension($filename) == 'php') { if (($php_perms & 0100) == 0100) { $mask = $mask | 0100; } if (($php_perms & 010) == 010) { $mask = $mask | 010; } if (($php_perms & 01) == 01) { $mask = $mask | 01; } } @ftp_site($conn, 'CHMOD 0' . decoct(0644 | $mask) . ' ' . str_replace('/' . fallback_lang() . '/', '/' . $lang . '/', $filename)); } } } if (is_suexec_like()) { $myfile = fopen(get_file_base() . '/' . $filename, 'wb'); if (is_string($contents)) { fwrite($myfile, $contents); } else { fseek($dump_myfile, $dump_offset, SEEK_SET); $amount_read = 0; while ($amount_read < $file_size) { $read_amount = min(4096, $file_size - $amount_read); $shuttle_contents = fread($dump_myfile, $read_amount); fwrite($myfile, $shuttle_contents); $amount_read += strlen($shuttle_contents); } } fclose($myfile); fix_permissions(get_file_base() . '/' . $filename, 0666); } else { @ftp_delete($conn, $filename); $tmp = fopen(get_file_base() . '/ocp_inst_tmp/tmp', 'wb'); if (is_string($contents)) { fwrite($tmp, $contents); } else { fseek($dump_myfile, $dump_offset, SEEK_SET); $amount_read = 0; while ($amount_read < $file_size) { $read_amount = min(4096, $file_size - $amount_read); $shuttle_contents = fread($dump_myfile, $read_amount); fwrite($tmp, $shuttle_contents); $amount_read += strlen($shuttle_contents); } } fclose($tmp); if (!@ftp_put($conn, $filename, get_file_base() . '/ocp_inst_tmp/tmp', FTP_BINARY)) { if (strpos(@strval($php_errormsg), 'bind() failed') !== false) { warn_exit(do_lang_tempcode('FTP_FIREWALL_ERROR')); } else { warn_exit(@strval($php_errormsg)); } } $mask = 0; if (get_file_extension($filename) == 'php') { if (($php_perms & 0100) == 0100) { $mask = $mask | 0100; } if (($php_perms & 010) == 010) { $mask = $mask | 010; } if (($php_perms & 01) == 01) { $mask = $mask | 01; } } @ftp_site($conn, 'CHMOD ' . decoct(0644 | $mask) . ' ' . $filename); } } } if ($max_time > 0 && time() - $time_start >= $max_time) { break; } if ($i + 1 == $count) { $done_all = true; break; // That's them all } } if (!is_suexec_like()) { if (!file_exists(get_file_base() . '/ocp_inst_tmp/tmp')) { warn_exit(do_lang_tempcode('DOUBLE_INSTALL_DO')); } @unlink(get_file_base() . '/ocp_inst_tmp/tmp'); } test_htaccess(is_suexec_like() ? NULL : $conn); $log = new ocp_tempcode(); if ($done_all) { // If the file user is different to the FTP user, we need to make it world writeable if (!is_suexec_like()) { // Chmod global $CHMOD_ARRAY; $no_chmod = false; foreach ($CHMOD_ARRAY as $chmod) { if (file_exists($chmod) && !@ftp_site($conn, 'CHMOD 0777 ' . $chmod)) { $no_chmod = true; } } $log->attach(do_template('INSTALLER_DONE_SOMETHING', array('_GUID' => '2e4ccdd5a0b034125ee62403d5a48319', 'SOMETHING' => do_lang_tempcode(!$no_chmod ? 'CHMOD_PASS' : 'CHMOD_FAIL')))); } } if (!is_suexec_like()) { if (function_exists('ftp_close')) { ftp_close($conn); } } $log->attach(do_template('INSTALLER_DONE_SOMETHING', array('_GUID' => '1b447cee9e9aa3ad8e24530d4dceb03f', 'SOMETHING' => do_lang_tempcode('FILES_TRANSFERRED', strval($i + 1), strval($count))))); return array($log, $done_all ? -1 : $i); }
/** * Load up a language file, compiling it (it's not cached yet). * * @param ID_TEXT The language file name * @param ?LANGUAGE_NAME The language (NULL: uses the current language) * @param ?string The language type (lang_custom, or custom) (NULL: normal priorities are used) * @set lang_custom custom * @param PATH Where we are cacheing too * @param boolean Whether to just return if there was a loading error * @return boolean Whether we FAILED to load */ function require_lang_compile($codename, $lang, $type, $cache_path, $ignore_errors = false) { global $LANGUAGE, $REQUIRE_LANG_LOOP, $LANG_LOADED_LANG; $desire_cache = function_exists('get_option') && (get_option('is_on_lang_cache', true) == '1' || get_param_integer('keep_cache', 0) == 1 || get_param_integer('cache', 0) == 1) && get_param_integer('keep_cache', NULL) !== 0 && get_param_integer('cache', NULL) !== 0; if ($desire_cache) { if ($GLOBALS['IN_MINIKERNEL_VERSION'] == 0) { global $DECACHED_COMCODE_LANG_STRINGS; // Cleanup language strings if (!$DECACHED_COMCODE_LANG_STRINGS) { $DECACHED_COMCODE_LANG_STRINGS = true; $comcode_lang_strings = $GLOBALS['SITE_DB']->query_select('cached_comcode_pages', array('string_index'), array('the_zone' => '!'), '', NULL, NULL, true); if (!is_null($comcode_lang_strings)) { $GLOBALS['SITE_DB']->query_delete('cached_comcode_pages', array('the_zone' => '!')); foreach ($comcode_lang_strings as $comcode_lang_string) { delete_lang($comcode_lang_string['string_index']); } } } } $load_target = array(); } else { $load_target =& $LANGUAGE[$lang]; } global $FILE_ARRAY; if (@is_array($FILE_ARRAY) && file_array_exists('lang/' . $lang . '/' . $codename . '.ini')) { $lang_file = 'lang/' . $lang . '/' . $codename . '.ini'; $file = file_array_get($lang_file); _get_lang_file_map($file, $load_target, NULL, true); $bad = true; } else { $bad = true; $dirty = false; // Load originals $lang_file = get_file_base() . '/lang/' . $lang . '/' . filter_naughty($codename) . '.ini'; if (file_exists($lang_file)) { _get_lang_file_map($lang_file, $load_target, NULL, false); $bad = false; } // Load overrides now if they are there if ($type != 'lang') { $lang_file = get_custom_file_base() . '/lang_custom/' . $lang . '/' . $codename . '.ini'; if (!file_exists($lang_file) && get_file_base() != get_custom_file_base()) { $lang_file = get_file_base() . '/lang_custom/' . $lang . '/' . $codename . '.ini'; } if (!file_exists($lang_file)) { $lang_file = get_custom_file_base() . '/lang_custom/' . $lang . '/' . $codename . '.po'; if (!file_exists($lang_file)) { $lang_file = get_file_base() . '/lang_custom/' . $lang . '/' . $codename . '-' . strtolower($lang) . '.po'; } } } if ($type != 'lang' && file_exists($lang_file)) { _get_lang_file_map($lang_file, $load_target, NULL, false); $bad = false; $dirty = true; // Tainted from the official pack, so can't store server wide } // NB: Merge op doesn't happen in require_lang. It happens when do_lang fails and then decides it has to force a recursion to do_lang(xx,fallback_lang()) which triggers require_lang(xx,fallback_lang()) when it sees it's not loaded if ($bad && $lang != fallback_lang()) { require_lang($codename, fallback_lang(), $type, $ignore_errors); $REQUIRE_LANG_LOOP--; $fallback_cache_path = get_custom_file_base() . '/lang_cached/' . fallback_lang() . '/' . $codename . '.lcd'; if (file_exists($fallback_cache_path)) { require_code('files'); @copy($fallback_cache_path, $cache_path); fix_permissions($cache_path); } if (!array_key_exists($lang, $LANG_LOADED_LANG)) { $LANG_LOADED_LANG[$lang] = array(); } $LANG_LOADED_LANG[$lang][$codename] = 1; return $bad; } if ($bad) { if ($ignore_errors) { return true; } if ($codename != 'critical_error' || $lang != get_site_default_lang()) { fatal_exit(do_lang_tempcode('MISSING_LANG_FILE', escape_html($codename), escape_html($lang))); } else { critical_error('CRIT_LANG'); } } } if (is_null($GLOBALS['MEM_CACHE'])) { // Cache if ($desire_cache) { $file = @fopen($cache_path, 'wt'); // Will fail if cache dir missing .. e.g. in quick installer if ($file) { if (fwrite($file, serialize($load_target)) > 0) { // Success fclose($file); require_code('files'); fix_permissions($cache_path); } else { // Failure fclose($file); @unlink($cache_path); } } } } else { persistant_cache_set(array('LANG', $lang, $codename), $load_target, !$dirty); } if ($desire_cache) { $LANGUAGE[$lang] += $load_target; } return $bad; }
/** * 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(); }
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>';
/** * 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); }
/** * 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')); }
/** * 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; }
/** * 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(); } }
/** * 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); } } } }
/** * 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); }
/** * 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 ''; }
/** * 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')); }
/** * 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')); }
/** * 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; }
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); } }
/** * 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('', ''); }
/** * (Plug-in replacement for memcache API) Put data into the persistant cache. * * @param mixed Key * @param mixed The data * @param integer Various flags (parameter not used) * @param integer The expiration time in seconds. */ function set($key, $data, $flags, $expire_secs) { unset($flags); unset($expire_secs); $path = get_custom_file_base() . '/persistant_cache/' . md5($key) . '.gcd'; $myfile = @fopen($path, 'ab'); if ($myfile === false) { return; } // Failure $to_write = serialize($data); $its = 0; // if we can't get after 10 iterations then we have to assume the OS does not support locks :( if (!defined('PHALANGER')) { while (!@flock($myfile, LOCK_EX) && $its != 10) { sleep(mt_rand(0, 100)); $its++; } } ftruncate($myfile, 0); if (fwrite($myfile, $to_write) !== false) { // Success fclose($myfile); fix_permissions($path); } else { // Failure fclose($myfile); unlink($path); } }
/** * 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()); }
/** * 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; }
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('–', '-', $text_content); $text_content = str_replace('—', '-', $text_content); $text_content = str_replace('…', '...', $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>.';
/** * 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; }