/** * Standard modular run function. * * @param MEMBER The ID of the member we are getting link hooks for * @return array List of tuples for results. Each tuple is: type,title,url */ function get_sections($member_id) { require_lang('ocgifts'); $rows = $GLOBALS['SITE_DB']->query_select('members_gifts', array('*'), array('to_user_id' => $member_id), '', NULL, 0, true); if (is_null($rows)) { return array(); } $gifts = array(); foreach ($rows as $gift) { $gift_info = $GLOBALS['SITE_DB']->query_select('ocgifts', array('*'), array('id' => $gift['gift_id'])); if (strlen($gift_info[0]['name']) > 0) { if ($gift['is_anonymous'] == 0) { $sender_name = $GLOBALS['FORUM_DRIVER']->get_username($gift['from_user_id']); $sender_link = $GLOBALS['FORUM_DRIVER']->member_profile_url($gift['from_user_id']); $gift_explanation = do_lang('GIFT_EXPLANATION1', $sender_name, $gift_info[0]['name'], $sender_link); } else { $gift_explanation = do_lang('GIFT_EXPLANATION2', $gift_info[0]['name']); } $image_url = ''; if (is_file(get_file_base() . '/' . urldecode($gift_info[0]['image']))) { $image_url = get_custom_base_url() . '/' . $gift_info[0]['image']; } $gifts[] = array('GIFT_EXPLANATION' => $gift_explanation, 'IMAGE_URL' => $image_url); } } $gifts_block = do_template('OCF_MEMBER_SCREEN_GIFTS_WRAP', array('_GUID' => 'fd4b5344b3b16cdf129e49bae903cbb2', 'GIFTS' => $gifts)); return array($gifts_block); }
/** * Get the list of files that need CHmodding for write access. * * @return array The list of files */ function get_chmod_array() { global $LANG; // if ((function_exists('ocp_enterprise')) && (ocp_enterprise())) // { $extra_files = array('collaboration/pages/html_custom', 'collaboration/pages/html_custom/' . $LANG, 'collaboration/pages/comcode_custom', 'collaboration/pages/comcode_custom/' . $LANG); // } else $extra_files=array(); if (function_exists('find_all_hooks')) { $hooks = find_all_hooks('systems', 'addon_registry'); $hook_keys = array_keys($hooks); foreach ($hook_keys as $hook) { //require_code('hooks/systems/addon_registry/'.filter_naughty_harsh($hook)); //$object=object_factory('Hook_addon_registry_'.filter_naughty_harsh($hook)); //$extra_files=array_merge($extra_files,$object->get_chmod_array()); // Save memory compared to above commented code... $path = get_custom_file_base() . '/sources/hooks/systems/addon_registry/' . filter_naughty_harsh($hook) . '.php'; if (!file_exists($path)) { $path = get_file_base() . '/sources/hooks/systems/addon_registry/' . filter_naughty_harsh($hook) . '.php'; } $matches = array(); if (preg_match('#function get_chmod_array\\(\\)\\s*\\{([^\\}]*)\\}#', file_get_contents($path), $matches) != 0) { if (!defined('HIPHOP_PHP')) { $extra_files = array_merge($extra_files, eval($matches[1])); } else { require_code('hooks/systems/addon_registry/' . $hook); $hook = object_factory('Hook_addon_registry_' . $hook); $extra_files = array_merge($extra_files, $hook->get_chmod_array()); } } } } return array_merge($extra_files, array('safe_mode_temp', 'persistant_cache', 'data_custom/modules/admin_backup', 'data_custom/modules/chat', 'data_custom/fields.xml', 'data_custom/breadcrumbs.xml', 'data_custom/modules/admin_stats', 'data_custom/spelling/write.log', 'data_custom/spelling/output.log', 'data_custom/spelling/personal_dicts', 'themes/map.ini', 'text_custom', 'text_custom/' . $LANG, 'data_custom/modules/chat/chat_last_msg.dat', 'data_custom/modules/chat/chat_last_event.dat', 'lang_cached', 'lang_cached/' . $LANG, 'lang_custom', 'lang_custom/' . $LANG, 'data_custom/errorlog.php', 'ocp_sitemap.xml', 'data_custom/permissioncheckslog.php', 'pages/html_custom', 'site/pages/html_custom', 'docs/pages/html_custom', 'adminzone/pages/html_custom', 'forum/pages/html_custom', 'cms/pages/html_custom', 'pages/html_custom/' . $LANG, 'site/pages/html_custom/' . $LANG, 'docs/pages/html_custom/' . $LANG, 'adminzone/pages/html_custom/' . $LANG, 'forum/pages/html_custom/' . $LANG, 'cms/pages/html_custom/' . $LANG, 'pages/comcode_custom', 'site/pages/comcode_custom', 'docs/pages/comcode_custom', 'adminzone/pages/comcode_custom', 'forum/pages/comcode_custom', 'cms/pages/comcode_custom', 'pages/comcode_custom/' . $LANG, 'site/pages/comcode_custom/' . $LANG, 'docs/pages/comcode_custom/' . $LANG, 'adminzone/pages/comcode_custom/' . $LANG, 'forum/pages/comcode_custom/' . $LANG, 'cms/pages/comcode_custom/' . $LANG, 'themes/default/css_custom', 'themes/default/images_custom', 'themes/default/templates_custom', 'themes/default/templates_cached', 'themes/default/templates_cached/' . $LANG, 'themes/default/theme.ini', 'uploads/incoming', 'uploads/website_specific', 'uploads/personal_sound_effects', 'uploads/banners', 'uploads/downloads', 'uploads/galleries', 'uploads/watermarks', 'uploads/grepimages', 'uploads/galleries_thumbs', 'uploads/iotds', 'uploads/iotds_thumbs', 'uploads/catalogues', 'uploads/attachments', 'uploads/attachments_thumbs', 'uploads/auto_thumbs', 'uploads/ocf_avatars', 'uploads/ocf_cpf_upload', 'uploads/ocf_photos', 'uploads/ocf_photos_thumbs', 'uploads/filedump', 'info.php', 'exports/backups', 'exports/file_backups', 'exports/mods', 'imports/mods', 'site/pages/html_custom/' . $LANG . '/download_tree_made.htm', 'site/pages/html_custom/' . $LANG . '/cedi_tree_made.htm')); }
/** * Standard modular run function. * * @param array A map of parameters. * @return tempcode The result of execution. */ function run($map) { require_code('type_validation'); require_lang('phpdoc'); require_code('php'); require_css('adminzone'); disable_php_memory_limit(); $filename = (array_key_exists('param', $map) ? $map['param'] : 'sources/global2') . '.php'; if (substr($filename, -8) == '.php.php') { $filename = substr($filename, 0, strlen($filename) - 4); } $full_path = (get_file_base() != '' ? get_file_base() . '/' : '') . filter_naughty($filename); if (!file_exists($full_path)) { return paragraph(do_lang_tempcode('MISSING_RESOURCE')); } $_classes = get_php_file_api($filename); $classes = new ocp_tempcode(); foreach ($_classes as $class) { if ($class['name'] == '__global') { $class['name'] = do_lang('GLOBAL_FUNCTIONS') . '_' . basename($filename); } $function_summaries = new ocp_tempcode(); $functions = new ocp_tempcode(); foreach ($class['functions'] as $function) { $ret = render_php_function($function, $class); $functions->attach($ret[0]); $function_summaries->attach($ret[1]); } $classes->attach(do_template('PHP_CLASS', array('_GUID' => '5d58fc42c5fd3a5dd190f3f3699610c2', 'CLASS_NAME' => $class['name'], 'FUNCTION_SUMMARIES' => $function_summaries, 'FUNCTIONS' => $functions))); } return do_template('PHP_FILE', array('_GUID' => '6f422e6a6e846d49864d7325b212109f', 'FILENAME' => $filename, 'CLASSES' => $classes)); }
function init__users() { //if (addon_installed('Facebook Support',true)) if (is_file(get_file_base() . '/sources/facebook_connect.php')) { require_code('facebook_connect'); } }
/** * Get a fields hook, from a given codename. * * @param ID_TEXT Codename * @return object Hook object */ function get_fields_hook($type) { static $fields_hook_cache = array(); if (isset($fields_hook_cache[$type])) { return $fields_hook_cache[$type]; } $path = 'hooks/systems/fields/' . filter_naughty($type); if (!in_array($type, array('author', 'auto_increment', 'codename', 'color', 'content_link', 'date', 'email', 'float', 'guid', 'integer', 'just_date', 'just_time', 'list', 'long_text', 'long_trans', 'page_link', 'password', 'picture', 'video', 'posting_field', 'radiolist', 'random', 'reference', 'short_text', 'short_trans', 'theme_image', 'tick', 'upload', 'url', 'user')) && !is_file(get_file_base() . '/sources/' . $path . '.php') && !is_file(get_file_base() . '/sources_custom/' . $path . '.php')) { $hooks = find_all_hooks('systems', 'fields'); foreach (array_keys($hooks) as $hook) { $path = 'hooks/systems/fields/' . filter_naughty($hook); require_code($path); $ob = object_factory('Hook_fields_' . filter_naughty($hook)); if (method_exists($ob, 'get_field_types')) { if (array_key_exists($type, $ob->get_field_types())) { $fields_hook_cache[$type] = $ob; return $ob; } } } } require_code($path); $ob = object_factory('Hook_fields_' . filter_naughty($type), true); if (is_null($ob)) { return get_fields_hook('short_text'); } $fields_hook_cache[$type] = $ob; return $ob; }
/** * Remove ocPortal's strictness, to help integration of third-party code. * * @param boolean Whether to also set the content type to plain-HTML * @param boolean Whether to destrictify MySQL commands over the ocPortal database driver */ function destrictify($change_content_type = true, $mysql_too = false) { // Turn off strictness if (!headers_sent() && $change_content_type) { @header('Content-type: text/html; charset=' . get_charset()); } $GLOBALS['SCREEN_TEMPLATE_CALLED'] = ''; $GLOBALS['TITLE_CALLED'] = true; error_reporting(E_ALL ^ E_NOTICE); if (function_exists('set_time_limit')) { @set_time_limit(200); } if (get_forum_type() == 'ocf' && $mysql_too) { $GLOBALS['SITE_DB']->query('SET sql_mode=\'\'', NULL, NULL, true); } @ini_set('ocproducts.type_strictness', '0'); global $PREVIOUS_XSS_STATE; array_push($PREVIOUS_XSS_STATE, ini_get('ocproducts.xss_detect')); $include_path = './'; $include_path .= PATH_SEPARATOR . get_file_base() . '/'; $include_path .= PATH_SEPARATOR . get_file_base() . '/sources_custom/'; $include_path .= PATH_SEPARATOR . get_file_base() . '/uploads/website_specific/'; if (get_zone_name() != '') { $include_path .= PATH_SEPARATOR . get_file_base() . '/' . get_zone_name() . '/'; } @ini_set('include_path', $include_path); //disable_php_memory_limit(); Don't do this, recipe for disaster @ini_set('allow_url_fopen', '1'); @ini_set('suhosin.executor.disable_emodifier', '0'); @ini_set('suhosin.executor.multiheader', '0'); $GLOBALS['NO_DB_SCOPE_CHECK'] = true; $GLOBALS['NO_QUERY_LIMIT'] = true; }
/** * Extend breadcrumbs for the Admin Zone (called by breadcrumbs_get_default_stub). * * @param tempcode Reference to the breadcrumbs stub we're assembling */ function adminzone_extend_breadcrumbs(&$stub) { global $BREADCRUMB_SET_PARENTS; if (count($BREADCRUMB_SET_PARENTS) > 0 && !is_object($BREADCRUMB_SET_PARENTS[0][0])) { // Works by finding where our oldest ancestor connects on to the do-next menus, and carries from there list($zone, $attributes, ) = page_link_decode($BREADCRUMB_SET_PARENTS[0][0]); $type = array_key_exists('type', $attributes) ? $attributes['type'] : 'misc'; $page = $attributes['page']; if ($page == '_SELF') { $page = get_page_name(); } if ($zone == '_SEARCH') { $zone = get_module_zone($page); } if ($zone == '_SELF') { $zone = get_zone_name(); } } else { // Works by finding where we connect on to the do-next menus, and carries from there $type = get_param('type', 'misc'); $page = get_page_name(); $zone = get_zone_name(); } if ($page != 'admin' && $page != 'cms') { // Loop over menus, hunting for connection $hooks = find_all_hooks('systems', 'do_next_menus'); $_hooks = array(); $page_looking = $page; $page_looking = preg_replace('#^(cms|admin)\\_#', '', $page_looking); if (array_key_exists($page_looking, $hooks)) { $_hooks[$page_looking] = $hooks[$page_looking]; unset($hooks[$page_looking]); $hooks = array_merge($_hooks, $hooks); } foreach ($hooks as $hook => $sources_dir) { $run_function = extract_module_functions(get_file_base() . '/' . $sources_dir . '/hooks/systems/do_next_menus/' . $hook . '.php', array('run')); if ($run_function[0] !== NULL) { $info = is_array($run_function[0]) ? call_user_func_array($run_function[0][0], $run_function[0][1]) : eval($run_function[0]); foreach ($info as $i) { if ($i === NULL) { continue; } if ($page == $i[2][0] && (!array_key_exists('type', $i[2][1]) && $type == 'misc' || array_key_exists('type', $i[2][1]) && ($type == $i[2][1]['type'] || $i[2][1]['type'] == 'misc')) && $zone == $i[2][2]) { if ($i[0] == 'cms') { $url = build_url(array('page' => 'cms', 'type' => $i[0] == 'cms' ? NULL : $i[0]), 'cms'); } else { $url = build_url(array('page' => 'admin', 'type' => $i[0]), 'adminzone'); } require_lang('menus'); require_lang('security'); $stub->attach(hyperlink($url, do_lang_tempcode(strtoupper($i[0])), false, false, do_lang_tempcode('GO_BACKWARDS_TO', @html_entity_decode(strip_tags(do_lang(strtoupper($i[0]))), ENT_QUOTES, get_charset())))); //if ((!array_key_exists('type',$i[2][1])) || ($type==$i[2][1]['type'])) break; return; } } } } } }
/** * (Plug-in replacement for memcache API) Delete data from the persistant cache. * * @param mixed Key name */ function delete($key) { // Update list of e-objects global $ECACHE_OBJECTS; unset($ECACHE_OBJECTS[$key]); @apc_store(get_file_base() . 'ECACHE_OBJECTS', $ECACHE_OBJECTS, 0); apc_delete($key); }
/** * (Plug-in replacement for memcache API) Delete data from the persistant cache. * * @param mixed Key name */ function delete($key) { // Update list of e-objects global $ECACHE_OBJECTS; unset($ECACHE_OBJECTS[$key]); xcache_set(get_file_base() . 'ECACHE_OBJECTS', $ECACHE_OBJECTS, 0); xcache_unset($key); }
/** * Standard modular run function for snippet hooks. Generates XHTML to insert into a page using AJAX. * * @return tempcode The snippet */ function run() { $val = get_param('name'); $test = file_exists(get_file_base() . '/themes/' . $val) || file_exists(get_custom_file_base() . '/themes/' . $val); if (!$test) { return new ocp_tempcode(); } return make_string_tempcode(str_replace(array('‘', '’', '“', '”'), array('"', '"', '"', '"'), html_entity_decode(do_lang('ALREADY_EXISTS', escape_html($val)), ENT_QUOTES))); }
function testBotListInSync() { require_code('files'); $file_bots = better_parse_ini_file(get_file_base() . '/text/bots.txt'); ksort($file_bots); global $BOT_MAP; ksort($BOT_MAP); $this->assertTrue($BOT_MAP == $file_bots); }
/** * 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; }
/** * (Plug-in replacement for memcache API) Put data into the persistent 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) { $key = serialize($_key); // Update list of e-objects global $ECACHE_OBJECTS; if (!array_key_exists($key, $ECACHE_OBJECTS)) { $ECACHE_OBJECTS[$key] = 1; $this->set(get_file_base() . 'ECACHE_OBJECTS', $ECACHE_OBJECTS, 0, 0); } parent::set($key, serialize(array(time(), $data)), $flags, $expire_secs); }
/** * Find the mime type for the given file extension. It does not take into account whether the file type has been white-listed or not, and returns a binary download mime type for any unknown extensions. * * @param string The file extension (no dot) * @return string The MIME type */ function get_mime_type($extension) { $mime_types = array('1st' => 'text/plain', 'txt' => 'text/plain', '' => 'text/plain', 'pdf' => 'application/pdf', 'rtf' => 'text/richtext', 'ps' => 'application/postscript', 'html' => 'application/octet-stream', 'htm' => 'application/octet-stream', 'odt' => 'application/vnd.oasis.opendocument.text', 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', 'odp' => 'application/vnd.oasis.opendocument.presentation', 'doc' => 'application/msword', 'mdb' => 'application/x-msaccess', 'xls' => 'application/vnd.ms-excel', 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'xml' => 'application/octet-stream', 'rss' => 'application/octet-stream', 'atom' => 'application/octet-stream', 'ppt' => 'application/powerpoint', 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'svg' => 'application/octet-stream', 'wrl' => 'model/vrml', 'vrml' => 'model/vrml', 'swf' => 'application/octet-stream', 'png' => 'image/png', 'gif' => 'image/gif', 'jpg' => 'image/jpeg', 'jpe' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'psd' => 'image/x-photoshop', 'bmp' => 'image/x-MS-bmp', 'tga' => 'image/x-targa', 'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'pcx' => 'image/x-pcx', 'ico' => 'image/vnd.microsoft.icon', 'avi' => 'video/mpeg', 'mpg' => 'video/mpeg', 'mpe' => 'video/mpeg', '3gp' => 'video/3gpp', 'mp4' => 'video/mp4', 'm4v' => 'video/mp4', 'mpeg' => 'video/mpeg', 'ogv' => 'video/ogg', 'webm' => 'video/webm', 'mov' => 'video/quicktime', 'qt' => 'video/quicktime', 'wmv' => 'video/x-ms-wmv', 'ram' => 'audio/x-pn-realaudio', 'rm' => 'audio/x-pn-realaudio', 'asf' => 'video/x-ms-asf', 'ra' => 'audio/x-pn-realaudio-plugin', 'wma' => 'audio/x-ms-wma', 'wav' => 'audio/x-wav', 'mp3' => 'audio/x-mpeg', 'ogg' => 'audio/ogg', 'mid' => 'audio/midi', 'torrent' => 'application/x-bittorrent'); if (file_exists(get_file_base() . '/data/flvplayer.swf')) { $mime_types['flv'] = 'video/x-flv'; } if (array_key_exists($extension, $mime_types)) { return $mime_types[$extension]; } return 'application/octet-stream'; }
/** * Standard modular run function for snippet hooks. Generates XHTML to insert into a page using AJAX. * * @return tempcode The snippet */ function run() { if (get_file_base() != get_custom_file_base()) { warn_exit(do_lang_tempcode('SHARED_INSTALL_PROHIBIT')); } if (has_actual_page_access(get_member(), 'admin_occle')) { require_code('occle'); require_lang('occle'); $title = get_page_title('OCCLE'); return do_template('OCCLE_MAIN', array('COMMANDS' => '', 'SUBMIT_URL' => build_url(array('page' => 'admin_occle'), 'adminzone'), 'PROMPT' => do_lang_tempcode('COMMAND_PROMPT', escape_html($GLOBALS['FORUM_DRIVER']->get_username(get_member()))))); } return new ocp_tempcode(); }
function setUp() { parent::setUp(); require_code('rss'); $rssfeed = get_file_base() . "/_tests/tests/testrss.cms"; $atomfeed = get_file_base() . "/_tests/tests/testatom.cms"; $rss = new rss($rssfeed, true); $atom = new rss($atomfeed, true); $rsstitle = $rss->gleamed_items[0]['title']; $atomtitle = $atom->gleamed_items[0]['title']; $this->assertTrue('Item Example' == $rsstitle); $this->assertTrue('Atom-Powered Robots Run Amok' == $atomtitle); }
/** * Standard modular run function for snippet hooks. Generates XHTML to insert into a page using AJAX. * * @return tempcode The snippet */ function run() { $zone = get_param('name'); $test = file_exists(get_file_base() . '/' . $zone); if (!$test) { return new ocp_tempcode(); } $test = $GLOBALS['SITE_DB']->query_value_null_ok('zones', 'zone_header_text', array('zone_name' => $zone)); if (is_null($test)) { return new ocp_tempcode(); } return make_string_tempcode(str_replace(array('‘', '’', '“', '”'), array('"', '"', '"', '"'), html_entity_decode(do_lang('ALREADY_EXISTS', escape_html($zone)), ENT_QUOTES))); }
/** * Standard modular run function for CRON hooks. Searches for tasks to perform. */ function run() { //if (!addon_installed('octhief')) return; require_lang('insults'); // ensure it is done once per week $time = time(); $last_time = intval(get_value('last_insult_time')); if ($last_time > time() - 24 * 60 * 60) { return; } // run it once a day set_value('last_insult_time', strval($time)); // how many points a correct response will give $_insult_points = get_option('insult_points', true); if (is_null($_insult_points)) { // add option and default value if not installed yet require_code('database_action'); add_config_option('INSULT_POINTS', 'insult_points', 'integer', 'return \'10\';', 'POINTS', 'INSULT_TITLE'); } $insult_points = isset($_insult_points) && is_numeric($_insult_points) ? intval($_insult_points) : 10; // who to insult? $selected_members = $GLOBALS['FORUM_DB']->query('SELECT id FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_members WHERE id <> ' . strval($GLOBALS['FORUM_DRIVER']->get_guest_id()) . ' ORDER BY RAND( ) ', 2, NULL, true); $selected_member1 = isset($selected_members[0]['id']) && $selected_members[0]['id'] > 0 ? $selected_members[0]['id'] : 0; $selected_member2 = isset($selected_members[1]['id']) && $selected_members[1]['id'] > 0 ? $selected_members[1]['id'] : 0; // send insult to picked members if ($selected_member1 != 0 && $selected_member2 != 0) { $get_insult = ''; if (is_file(get_file_base() . '/text_custom/' . user_lang() . '/insults.txt')) { $insults = file(get_file_base() . '/text_custom/' . user_lang() . '/insults.txt'); $insults_array = array(); foreach ($insults as $insult) { $x = explode('=', $insult); $insults_array[] = $x[0]; } $rand_key = array_rand($insults_array, 1); $rand_key = is_array($rand_key) ? $rand_key[0] : $rand_key; $get_insult = $insults_array[$rand_key]; } if ($get_insult != '') { global $SITE_INFO; $insult_pt_topic_post = do_lang('INSULT_EXPLANATION', get_site_name(), $get_insult, $insult_points); $subject = do_lang('INSULT_PT_TOPIC', $GLOBALS['FORUM_DRIVER']->get_username($selected_member2), $GLOBALS['FORUM_DRIVER']->get_username($selected_member1)); require_code('ocf_topics_action'); $topic_id = ocf_make_topic(NULL, $subject, '', 1, 1, 0, 0, 0, $selected_member2, $selected_member1, true, 0, NULL, ''); require_code('ocf_posts_action'); $post_id = ocf_make_post($topic_id, $subject, $insult_pt_topic_post, 0, true, 1, 0, do_lang('SYSTEM'), NULL, NULL, $GLOBALS['FORUM_DRIVER']->get_guest_id(), NULL, NULL, NULL, false, true, NULL, true, $subject, 0, NULL, true, true, true); require_code('ocf_topics_action2'); send_pt_notification($post_id, $subject, $topic_id, $selected_member2, $selected_member1); } } }
/** * Find what field types this hook can serve. This method only needs to be defined if it is not serving a single field type with a name corresponding to the hook itself. * * @return array Map of field type to field type title */ function get_field_types() { $hooks = find_all_hooks('systems', 'ajax_tree'); $ret = array(); foreach (array_keys($hooks) as $hook) { if (substr($hook, 0, 7) == 'choose_' && $hook != 'catalogue_entry') { $_hook = preg_replace('#^choose_#', '', $hook); if ($_hook == 'forum_topic' || is_file(get_file_base() . '/sources_custom/hooks/systems/content_meta_aware/' . $_hook . '.php') || is_file(get_file_base() . '/sources/hooks/systems/content_meta_aware/' . $_hook . '.php')) { $ret['at_' . $hook] = do_lang_tempcode('FIELD_TYPE_content_link_x', escape_html($_hook)); } } } return $ret; }
/** * Standard modular run function. * * @return array An array of tuples: The task row to show, the number of seconds until it is due (or NULL if not on a timer), the number of things to sort out (or NULL if not on a queue), The name of the config option that controls the schedule (or NULL if no option). */ function run() { $award_types = $GLOBALS['SITE_DB']->query_select('award_types', array('*')); $out = array(); foreach ($award_types as $award) { // Find out how many submissions we've had since the last award was given if (!file_exists(get_file_base() . '/sources/hooks/systems/awards/' . filter_naughty_harsh($award['a_content_type']) . '.php') && !file_exists(get_file_base() . '/sources_custom/hooks/systems/awards/' . filter_naughty_harsh($award['a_content_type']) . '.php')) { continue; } require_code('hooks/systems/awards/' . $award['a_content_type']); $hook_object = object_factory('Hook_awards_' . $award['a_content_type'], true); if (is_null($hook_object)) { continue; } $details = $hook_object->info(); if (!is_null($details)) { $date = $GLOBALS['SITE_DB']->query_value_null_ok('award_archive', 'date_and_time', array('a_type_id' => $award['id']), 'ORDER BY date_and_time DESC'); $seconds_ago = mixed(); $limit_hours = $award['a_update_time_hours']; if (!is_null($date)) { $seconds_ago = time() - $date; $status = $seconds_ago > $limit_hours * 60 * 60 ? 0 : 1; } else { $status = 0; } $config_url = build_url(array('page' => 'admin_awards', 'type' => '_ed', 'id' => $award['id']), get_module_zone('admin_awards')); $_status = $status == 0 ? do_template('BLOCK_MAIN_STAFF_CHECKLIST_ITEM_STATUS_0') : do_template('BLOCK_MAIN_STAFF_CHECKLIST_ITEM_STATUS_1'); $url = $details['add_url']; if (is_object($url)) { $url = $url->evaluate(); } $url = str_replace('=!', '_ignore=1', $url); $task = escape_html(get_translated_text($award['a_title'])); if (!is_null($date) && !is_null($details['date_field'])) { $where = filter_naughty_harsh($details['date_field']) . '>' . strval(intval($date)); $num_queue = $details['connection']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . $details['connection']->get_table_prefix() . str_replace('1=1', $where, $details['table']) . ' r WHERE ' . $where); $_num_queue = integer_format($num_queue); $num_new_since = do_lang_tempcode('NUM_NEW_SINCE', $_num_queue); } else { $num_new_since = new ocp_tempcode(); } list($info, $seconds_due_in) = staff_checklist_time_ago_and_due($seconds_ago, $limit_hours); $info->attach($num_new_since); $tpl = do_template('BLOCK_MAIN_STAFF_CHECKLIST_ITEM', array('_GUID' => '4049affae5a6f38712ee3e0237a2e18e', 'CONFIG_URL' => $config_url, 'URL' => $url, 'STATUS' => $_status, 'TASK' => $task, 'INFO' => $info)); $out[] = array($tpl, $seconds_due_in, NULL, NULL); } } return $out; }
function testValidCode() { if (function_exists('set_time_limit')) { @set_time_limit(0); } require_code('files2'); $php_path = find_php_path(); $contents = get_directory_contents(get_file_base()); foreach ($contents as $c) { if (substr($c, -4) == '.php' && basename($c) != 'errorlog.php' && basename($c) != 'phpstub.php' && basename($c) != 'permissioncheckslog.php') { $message = shell_exec($php_path . ' -l ' . $c); $this->assertTrue(strpos($message, 'No syntax errors detected') !== false, $message . ' (' . $c . ')'); } } }
/** * Standard modular run function. * * @return tempcode Results */ function run() { $GLOBALS['SITE_DB']->query('DELETE FROM ' . get_table_prefix() . 'theme_images WHERE path LIKE \'themes/%/images/%\''); persistant_cache_delete('THEME_IMAGES'); $paths = $GLOBALS['SITE_DB']->query_select('theme_images', array('path', 'id')); foreach ($paths as $path) { if ($path['path'] == '') { $GLOBALS['SITE_DB']->query_delete('theme_images', $path, '', 1); } elseif (preg_match('#^themes/[^/]+/images_custom/+' . str_replace('#', '\\#', preg_quote($path['id'])) . '\\.#', $path['path']) != 0) { if (!file_exists(get_custom_file_base() . '/' . $path['path']) && !file_exists(get_file_base() . '/' . $path['path'])) { $GLOBALS['SITE_DB']->query_delete('theme_images', $path, '', 1); } } } return new ocp_tempcode(); }
/** * Standard modular install function. * * @param ?integer What version we're upgrading from (NULL: new install) * @param ?integer What hack version we're upgrading from (NULL: new-install/not-upgrading-from-a-hacked-version) */ function install($upgrade_from = NULL, $upgrade_from_hack = NULL) { if (is_null($upgrade_from)) { $GLOBALS['SITE_DB']->create_table('redirects', array('r_from_page' => '*ID_TEXT', 'r_from_zone' => '*ID_TEXT', 'r_to_page' => 'ID_TEXT', 'r_to_zone' => 'ID_TEXT', 'r_is_transparent' => 'BINARY')); $GLOBALS['SITE_DB']->query_insert('redirects', array('r_from_page' => 'rules', 'r_from_zone' => 'site', 'r_to_page' => 'rules', 'r_to_zone' => '', 'r_is_transparent' => 1)); $GLOBALS['SITE_DB']->query_insert('redirects', array('r_from_page' => 'rules', 'r_from_zone' => 'forum', 'r_to_page' => 'rules', 'r_to_zone' => '', 'r_is_transparent' => 1)); $GLOBALS['SITE_DB']->query_insert('redirects', array('r_from_page' => 'authors', 'r_from_zone' => 'collaboration', 'r_to_page' => 'authors', 'r_to_zone' => 'site', 'r_is_transparent' => 1)); } if (is_null($upgrade_from) || $upgrade_from < 4) { $zones = find_all_zones(); foreach ($zones as $zone) { if (!file_exists(get_file_base() . '/' . $zone . '/pages/comcode/' . fallback_lang() . '/panel_top.txt')) { $GLOBALS['SITE_DB']->query_insert('redirects', array('r_from_page' => 'panel_top', 'r_from_zone' => $zone, 'r_to_page' => 'panel_top', 'r_to_zone' => '', 'r_is_transparent' => 1)); } } } }
/** * Standard modular run function for do_next_menu hooks. They find links to put on standard navigation menus of the system. * * @return array Array of links and where to show */ function run() { $has_langs = false; $_dir = opendir(get_file_base() . '/lang/'); $_langs = array(); while (false !== ($file = readdir($_dir))) { if ($file == fallback_lang()) { continue; } if (!should_ignore_file('lang/' . $file, IGNORE_ACCESS_CONTROLLERS) && strlen($file) <= 5) { if (is_dir(get_file_base() . '/lang/' . $file)) { $has_langs = true; } } } closedir($_dir); if (!in_safe_mode()) { $_dir = @opendir(get_custom_file_base() . '/lang_custom/'); if ($_dir !== false) { while (false !== ($file = readdir($_dir))) { if ($file == fallback_lang()) { continue; } if (!should_ignore_file('lang_custom/' . $file, IGNORE_ACCESS_CONTROLLERS) && strlen($file) <= 5) { if (is_dir(get_custom_file_base() . '/lang_custom/' . $file)) { $has_langs = true; } } } closedir($_dir); } if (get_custom_file_base() != get_file_base()) { $_dir = opendir(get_file_base() . '/lang_custom/'); while (false !== ($file = readdir($_dir))) { if ($file == fallback_lang()) { continue; } if (!should_ignore_file('lang_custom/' . $file, IGNORE_ACCESS_CONTROLLERS) && strlen($file) <= 5) { $has_langs = true; } } closedir($_dir); } } return array(array('style', 'language', array('admin_lang', array('type' => 'misc'), get_module_zone('admin_lang')), do_lang_tempcode('TRANSLATE_CODE'), 'DOC_TRANSLATE'), multi_lang() ? array('style', 'language', array('admin_lang', array('type' => 'content'), get_module_zone('admin_lang')), do_lang_tempcode('TRANSLATE_CONTENT'), 'DOC_TRANSLATE_CONTENT') : NULL, !$has_langs ? NULL : array('style', 'criticise_language', array('admin_lang', array('type' => 'criticise'), get_module_zone('admin_lang')), do_lang_tempcode('CRITICISE_LANGUAGE_PACK'), 'DOC_CRITICISE_LANGUAGE_PACK')); }
/** * An option has dissappeared somehow - find it via searching our code-base for it's install code. It doesn't get returned, just loaded up. This function will produce a fatal error if we cannot find it. * * @param ID_TEXT The name of the value */ function find_lost_option($name) { global $OPTIONS; // In the dark dark past, we'd bomb out... if (function_exists('find_all_zones') && !defined('HIPHOP_PHP')) { // However times are pleasant, the grass is green, the sun high is the summer sky. Let's perform some voodoo magic... $all_zones = find_all_zones(); $search = array(); $types = array('modules_custom', 'modules'); foreach ($all_zones as $zone) { foreach ($types as $type) { $pages = find_all_pages($zone, $type); foreach ($pages as $page => $type2) { $search[] = zone_black_magic_filterer(get_file_base() . '/' . $zone . ($zone != '' ? '/' : '') . 'pages/' . $type2 . '/' . $page . '.php'); } } } require_code('zones2'); require_code('zones3'); $all_blocks = find_all_blocks(); foreach ($all_blocks as $block => $type) { $search[] = get_file_base() . '/' . $type . '/blocks/' . $block . '.php'; } if (file_exists(get_file_base() . '/sources_custom/ocf_install.php')) { $search[] = get_file_base() . '/sources_custom/ocf_install.php'; } $search[] = get_file_base() . '/sources/ocf_install.php'; $matches = array(); foreach ($search as $s) { // echo $s.'<br />'; $code = file_get_contents($s); if (preg_match('#add_config_option\\(\'\\w+\',\'' . str_replace('#', '\\#', preg_quote($name)) . '\',\'\\w+\',\'.+\',\'\\w+\',\'\\w+\'(,1)?\\);#', $code, $matches) > 0) { require_code('database_action'); $upgrade_from = NULL; // In case referenced in add_config_option line eval($matches[0]); load_options(); break; // fatal_exit(do_ lang_tempcode('CONFIG_OPTION_FETCHED',escape_html($name))); CONFIG_OPTION_FETCHED=A config option ({1}) was missing, but has been hunted down and installed. This is an unexpected inconsistency, please refresh the page, and hopefully it has been permanently corrected. } } } if (!array_key_exists($name, $OPTIONS)) { fatal_exit(do_lang_tempcode('_MISSING_OPTION', escape_html($name))); } }
function get_dropbox_dir() { require_code('developer_tools'); destrictify(); //get/set login details $hash = get_param('hash'); $dbemail = get_value('db_username_' . $hash); $dbpassword = get_value('db_password_' . $hash); $sub_dir = get_value('db_sub_dir_' . $hash); $sub_dir_new = get_param('sub_dir', ''); $sub_dir = isset($sub_dir_new) && strlen($sub_dir_new) > 0 ? $sub_dir_new : $sub_dir; $dbdir = ''; set_value('db_username_' . $hash, $dbemail); set_value('db_password_' . $hash, $dbpassword); set_value('db_sub_dir_' . $hash, $sub_dir); //include DropboxConnection class if (file_exists(get_file_base() . '/sources_custom/DropboxConnection.php')) { require get_file_base() . '/sources_custom/DropboxConnection.php'; } //remove "/" at the end of $sub_dir if any while (preg_match('/\\/$/', $sub_dir)) { $sub_dir = substr($sub_dir, 0, mb_strlen($sub_dir) - 1); } echo "You are here: " . $sub_dir . "<hr>"; try { $db_connection = new DropboxConnection($dbemail, $dbpassword); $directories = $db_connection->getdirs($dbdir . "/" . $sub_dir); if (isset($sub_dir)) { $parent_dir_array = explode("/", $sub_dir); $parent_dir = ''; for ($x = 0; $x < count($parent_dir_array) - 1; $x++) { $parent_dir .= $parent_dir_array[$x] . "/"; } echo "<a href='" . find_script('dropbox_list') . "?sub_dir=" . $parent_dir . "&hash=" . $hash . "'>../</a><br>"; } foreach ($directories as $directory) { echo "DIR - <a href='" . find_script('dropbox_list') . "?hash=" . $hash . "&sub_dir=" . $sub_dir . "/" . $directory . "'>" . $directory . "</a><br>"; } $files = $db_connection->getfiles($dbdir . "/" . $sub_dir); foreach ($files as $file) { echo "<a href='" . find_script('dropbox_get') . "?hash=" . $hash . "&get=" . $sub_dir . "/" . $file[0] . "&w=" . $file[1] . "'>" . $file[0] . "</a><br>"; } } catch (Exception $e) { echo '<span style="color: red">Error: ' . htmlspecialchars($e->getMessage()) . '</span>'; } }
function testMissingBlockParams() { $need = array(); $dh = opendir(get_file_base() . '/sources/blocks'); while ($f = readdir($dh)) { if (substr($f, -4) == '.php') { $contents = file_get_contents(get_file_base() . '/sources/blocks/' . $f); $matches = array(); $count = preg_match_all('/\\$map\\[\'([^\']+)\'\\]/', $contents, $matches); for ($i = 0; $i < $count; $i++) { if ($matches[1][$i] == 'block') { continue; } // Check param defined in block definition if (preg_match('/\\$info\\[\'parameters\'\\]=array\\([^\\n]*\'' . preg_quote($matches[1][$i]) . '\'[^\\n]*\\);/', $contents) == 0) { $this->assertTrue(false, 'Missing block param: <strong>' . basename($f, '.php') . '</strong>/' . $matches[1][$i]); } $need[] = 'BLOCK_' . basename($f, '.php') . '_PARAM_' . $matches[1][$i]; $need[] = 'BLOCK_TRANS_NAME_' . basename($f, '.php'); // Check for cacheing if (strpos($contents, '$info[\'cache_on\']') !== false && strpos($contents, '$info[\'cache_on\']=array(') === false) { $pattern = '/\\$info\\[\'cache_on\'\\]=\'[^\\n]*array\\([^\\n]*\\\\\'' . preg_quote($matches[1][$i]) . '\\\\\'/'; if (preg_match($pattern, $contents) == 0) { $this->assertTrue(false, 'Block param not cached: <strong>' . basename($f, '.php') . '</strong>/' . $matches[1][$i]); } } } } } $dh = opendir(get_file_base() . '/lang/EN'); while ($f = readdir($dh)) { if (substr($f, -4) == '.ini') { $contents = file_get_contents(get_file_base() . '/lang/EN/' . $f); foreach ($need as $i => $x) { if (strpos($contents, $x . '=') !== false) { unset($need[$i]); } } } } foreach ($need as $i => $x) { $this->assertTrue(false, 'Missing lang string: ' . $x); } }
function setUp() { parent::setUp(); $this->establish_admin_session(); require_code('feedback'); require_code('files2'); require_code('autosave'); require_code('permissions2'); $this->access_mapping = array(db_get_first_id() => 4); // Creating cms catalogues object if (file_exists(get_file_base() . '/cms/pages/modules_custom/cms_galleries.php')) { require_code('cms/pages/modules_custom/cms_galleries.php'); } else { require_code('cms/pages/modules/cms_galleries.php'); } $this->cms_gal = new Module_cms_galleries(); $this->cms_gal->run_start('misc'); $this->cms_gal_alt = new Module_cms_galleries_alt(); $this->cms_gal_category = new Module_cms_galleries_cat(); }
function testMissingColourEquations() { $dh = opendir(get_file_base() . '/themes/default/css'); while ($f = readdir($dh)) { if (substr($f, -4) == '.css') { if (in_array($f, array('swfupload.css', 'occle.css', 'ocworld.css', 'install.css', 'htmlarea.css', 'colour_picker.css', 'date_chooser.css', 'phpinfo.css'))) { continue; } $contents = file_get_contents(get_file_base() . '/themes/default/css/' . $f); $matches = array(); $count = preg_match_all('/^.+(\\#[0-9A-Fa-f]{3,6}).*$/m', $contents, $matches); for ($i = 0; $i < $count; $i++) { if (strpos($matches[0][$i], '{$,') === false) { $line = substr_count(substr($contents, 0, strpos($contents, $matches[0][$i])), chr(10)) + 1; $this->assertTrue(false, 'Missing colour equation in ' . $f . ':' . $line . ' for ' . $matches[1][$i]); } } } } }
function testCSS() { $dh = opendir(get_file_base() . '/themes/default/css'); while (($f = readdir($dh)) !== false) { if (substr($f, -4) == '.css' && $f != 'svg.css' && $f != 'quizzes.css') { $path = css_enforce(basename($f, '.css'), 'default', false); $contents = file_get_contents($path); $errors = check_css($contents); if (!is_null($errors) && $errors['errors'] == array()) { $errors = NULL; } // Normalise $this->assertTrue(is_null($errors), 'Bad CSS in ' . $f); if (!is_null($errors)) { var_dump($errors['errors']); var_dump($contents); } } } }