/** * Returns a list of upgrade files relative to the $upgrade_path dir. * * @param string $upgrade_path The directory that has upgrade scripts * @return array|false * @access private * * @todo the wire and groups plugins and the installer are using this */ function elgg_get_upgrade_files($upgrade_path = null) { if (!$upgrade_path) { $upgrade_path = elgg_get_root_path() . 'engine/lib/upgrades/'; } $upgrade_path = sanitise_filepath($upgrade_path); $handle = opendir($upgrade_path); if (!$handle) { return false; } $upgrade_files = array(); while ($upgrade_file = readdir($handle)) { // make sure this is a well formed upgrade. if (is_dir($upgrade_path . '$upgrade_file')) { continue; } $upgrade_version = elgg_get_upgrade_file_version($upgrade_file); if (!$upgrade_version) { continue; } $upgrade_files[] = $upgrade_file; } sort($upgrade_files); return $upgrade_files; }
/** * Read a folder structure for a zip file * * @param ElggObject $folder the folder to read * @param string $prepend current prefix * * @return array */ function file_tools_get_zip_structure($folder, $prepend) { $entries = []; if (!empty($prepend)) { $prepend = ltrim(sanitise_filepath($prepend), '/'); } if (empty($folder)) { $parent_guid = 0; } else { $parent_guid = $folder->getGUID(); } // get subfolder of this folder $entities = new ElggBatch('elgg_get_entities_from_metadata', ['type' => 'object', 'subtype' => FILE_TOOLS_SUBTYPE, 'limit' => false, 'metadata_name_value_pairs' => ['parent_guid' => $parent_guid]]); /* @var $subfolder ElggObject */ foreach ($entities as $subfolder) { $path = $prepend . $subfolder->title; $entries[] = ['directory' => $path, 'files' => file_tools_has_files($subfolder->getGUID())]; $entries = array_merge($entries, file_tools_get_zip_structure($subfolder, $path)); } return $entries; }
/** * Loads the plugin by GUID or path. * * @warning Unlike other ElggEntity objects, you cannot null instantiate * ElggPlugin. You must point it to an actual plugin GUID or location. * * @param mixed $plugin The GUID of the ElggPlugin object or the path of the plugin to load. * * @throws PluginException */ public function __construct($plugin) { if (!$plugin) { throw new PluginException(elgg_echo("PluginException:NullInstantiated")); } // ElggEntity can be instantiated with a guid or an object. // @todo plugins w/id 12345 if (is_numeric($plugin) || is_object($plugin)) { ElggObject::__construct($plugin); $this->path = elgg_get_plugins_path() . $this->getID(); } else { $plugin_path = elgg_get_plugins_path(); // not a full path, so assume an id // use the default path if (strpos($plugin, $plugin_path) !== 0) { $plugin = $plugin_path . $plugin; } // path checking is done in the package $plugin = sanitise_filepath($plugin); $this->path = $plugin; $path_parts = explode("/", rtrim($plugin, "/")); $plugin_id = array_pop($path_parts); $this->pluginID = $plugin_id; // check if we're loading an existing plugin $existing_plugin = elgg_get_plugin_from_id($this->pluginID); $existing_guid = null; if ($existing_plugin) { $existing_guid = $existing_plugin->guid; } // load the rest of the plugin ElggObject::__construct($existing_guid); } if ($this->site_guid == elgg_get_site_entity()->getGUID()) { _elgg_cache_plugin_by_id($this); } }
/** * When given a full path, finds translation files for a language and loads them * * This function was added in 1.9.4 to make it possible to load translations * for individual languages on-demand. This is needed in order to send * notifications in the recipient's language (see #3151 and #7241). * * @todo Replace this function in 1.10 by adding $language as the third parameter * to register_translations(). * * @access private * @since 1.9.4 * * @param string $path Full path of the directory (with trailing slash) * @param string $language Language code * @return bool success */ function _elgg_register_translations_for_language($path, $language) { global $CONFIG; $path = sanitise_filepath($path); // Make a note of this path just in case we need to register this language later if (!isset($CONFIG->language_paths)) { $CONFIG->language_paths = array(); } $CONFIG->language_paths[$path] = true; $language_file = "{$path}{$language}.php"; if (!file_exists($language_file)) { elgg_log("Could not find language file: {$language_file}", 'NOTICE'); return false; } $result = (include_once $language_file); elgg_log("Translations loaded from: {$language_file}", "INFO"); // The old (< 1.9) translation files call add_translation() independently. // The new ones however just return the translations array. In this case // we need to add the translation here. if (is_array($result)) { return add_translation($language, $result); } return true; }
/** * When given a full path, finds translation files and loads them * * @param string $path Full path * @param bool $load_all If true all languages are loaded, if * false only the current language + en are loaded * * @return bool success */ function registerTranslations($path, $load_all = false) { $path = sanitise_filepath($path); // Make a note of this path just incase we need to register this language later if (!isset($GLOBALS['_ELGG']->language_paths)) { $GLOBALS['_ELGG']->language_paths = array(); } $GLOBALS['_ELGG']->language_paths[$path] = true; // Get the current language based on site defaults and user preference $current_language = $this->getCurrentLanguage(); _elgg_services()->logger->info("Translations loaded from: {$path}"); // only load these files unless $load_all is true. $load_language_files = array('en.php', "{$current_language}.php"); $load_language_files = array_unique($load_language_files); $handle = opendir($path); if (!$handle) { _elgg_services()->logger->error("Could not open language path: {$path}"); return false; } $return = true; while (false !== ($language = readdir($handle))) { // ignore bad files if (substr($language, 0, 1) == '.' || substr($language, -4) !== '.php') { continue; } if (in_array($language, $load_language_files) || $load_all) { $result = (include_once $path . $language); if ($result === false) { $return = false; continue; } elseif (is_array($result)) { $this->addTranslation(basename($language, '.php'), $result); } } } return $return; }
/** * Serves up screenshots for plugins from * admin_plugin_screenshot/<plugin_id>/<size>/<ss_name>.<ext> * * @param array $pages The pages array * @return bool * @access private */ function _elgg_admin_plugin_screenshot_page_handler($pages) { set_input('plugin_id', elgg_extract(0, $pages)); set_input('size', elgg_extract(1, $pages, 'thumbnail')); // the rest of the string is the filename $filename_parts = array_slice($pages, 2); $filename = implode('/', $filename_parts); $filename = sanitise_filepath($filename, false); set_input('filename', $filename); echo elgg_view_resource('admin/plugin_screenshot.img'); return true; }
/** * A default page handler * Tries to locate a suitable file to include. Only works for core pages, not plugins. * * @param array $page The page URL elements * @param string $handler The base handler * * @return true|false Depending on success * @deprecated 1.8 */ function default_page_handler($page, $handler) { global $CONFIG; elgg_deprecated_notice("default_page_handler is deprecated", "1.8"); $page = implode('/', $page); // protect against including arbitary files $page = str_replace("..", "", $page); $callpath = $CONFIG->path . $handler . "/" . $page; if (is_dir($callpath)) { $callpath = sanitise_filepath($callpath); $callpath .= "index.php"; if (file_exists($callpath)) { if (include $callpath) { return TRUE; } } } else { if (file_exists($callpath)) { include $callpath; return TRUE; } } return FALSE; }
/** * Returns the plugin's full path with trailing slash. * * @return string */ public function getPath() { return sanitise_filepath($this->path); }
/** * Loads configuration related to Elgg as an application * * This runs on the engine boot and loads from the datalists database table. * * @see _elgg_engine_boot() * * @access private */ function _elgg_load_application_config() { global $CONFIG; $install_root = str_replace("\\", "/", dirname(dirname(dirname(__FILE__)))); $defaults = array('path' => "{$install_root}/", 'plugins_path' => "{$install_root}/mod/", 'language' => 'en', 'pluginspath' => "{$install_root}/mod/"); foreach ($defaults as $name => $value) { if (empty($CONFIG->{$name})) { $CONFIG->{$name} = $value; } } $GLOBALS['_ELGG']->view_path = "{$install_root}/views/"; // set cookie values for session and remember me _elgg_configure_cookies($CONFIG); if (!is_memcache_available()) { _elgg_services()->datalist->loadAll(); } // allow sites to set dataroot and simplecache_enabled in settings.php if (isset($CONFIG->dataroot)) { $CONFIG->dataroot = sanitise_filepath($CONFIG->dataroot); $GLOBALS['_ELGG']->dataroot_in_settings = true; } else { $dataroot = datalist_get('dataroot'); if (!empty($dataroot)) { $CONFIG->dataroot = $dataroot; } $GLOBALS['_ELGG']->dataroot_in_settings = false; } if (isset($CONFIG->simplecache_enabled)) { $GLOBALS['_ELGG']->simplecache_enabled_in_settings = true; } else { $simplecache_enabled = datalist_get('simplecache_enabled'); if ($simplecache_enabled !== false) { $CONFIG->simplecache_enabled = $simplecache_enabled; } else { $CONFIG->simplecache_enabled = 1; } $GLOBALS['_ELGG']->simplecache_enabled_in_settings = false; } $system_cache_enabled = datalist_get('system_cache_enabled'); if ($system_cache_enabled !== false) { $CONFIG->system_cache_enabled = $system_cache_enabled; } else { $CONFIG->system_cache_enabled = 1; } // needs to be set before system, init for links in html head $CONFIG->lastcache = (int) datalist_get("simplecache_lastupdate"); $GLOBALS['_ELGG']->i18n_loaded_from_cache = false; // this must be synced with the enum for the entities table $CONFIG->entity_types = array('group', 'object', 'site', 'user'); }
* @subpackage Core * @author Curverider Ltd * @link http://elgg.org/ */ define('INSTALLING', TRUE); elgg_set_viewtype('failsafe'); // Set failsafe again incase we get an exception thrown if (is_installed()) { forward(); } if (get_input('settings') == 'go') { if (!datalist_get('default_site')) { // Sanitise $path = sanitise_filepath(get_input('path')); $dataroot = sanitise_filepath(get_input('dataroot')); $url = sanitise_filepath(get_input('wwwroot')); // Blank? if ($dataroot == "/") { throw new InstallationException(elgg_echo('InstallationException:DatarootBlank')); } // That it's valid if (stripos($dataroot, $path) !== false) { throw new InstallationException(sprintf(elgg_echo('InstallationException:DatarootUnderPath'), $dataroot)); } // Check data root is writable if (!is_writable($dataroot)) { throw new InstallationException(sprintf(elgg_echo('InstallationException:DatarootNotWritable'), $dataroot)); } $site = new ElggSite(); $site->name = get_input('sitename'); $site->url = $url;
/** * Returns a list of upgrade files relative to the $upgrade_path dir. * * @param string $upgrade_path The up * @return array|false */ protected function getUpgradeFiles($upgrade_path = null) { if (!$upgrade_path) { $upgrade_path = _elgg_services()->config->get('path') . 'engine/lib/upgrades/'; } $upgrade_path = sanitise_filepath($upgrade_path); $handle = opendir($upgrade_path); if (!$handle) { return false; } $upgrade_files = array(); while ($upgrade_file = readdir($handle)) { // make sure this is a wellformed upgrade. if (is_dir($upgrade_path . '$upgrade_file')) { continue; } $upgrade_version = $this->getUpgradeFileVersion($upgrade_file); if (!$upgrade_version) { continue; } $upgrade_files[] = $upgrade_file; } sort($upgrade_files); return $upgrade_files; }
<?php $current_dir = elgg_extract('current_dir', $vars); $current_dir = sanitise_filepath($current_dir); $root_dir = elgg_get_data_path() . $current_dir; if (!is_dir($root_dir)) { echo elgg_format_element('div', [], elgg_echo('dataroot_browser:list:invalid_dir')); return; } $dir_data = scandir($root_dir); // breadcrumb echo elgg_view('dataroot_browser/breadcrumb', ['current_dir' => $current_dir]); // go through all folders/file in this dir $dir_items = []; $file_items = []; $dir_classes = ['dataroot_browser_name', 'dataroot_browser_folder']; $file_classes = ['dataroot_browser_name', 'dataroot_browser_file']; $posix_getpwuid = is_callable('posix_getpwuid'); $base_url = 'admin/administer_utilities/dataroot_browser'; $download_url = 'action/dataroot_browser/download'; $delete_url = 'action/dataroot_browser/delete_file'; $dh = new DirectoryIterator($root_dir); foreach ($dh as $file) { $cells = []; if ($file->isDot()) { continue; } $last_modified = date('Y/m/d H:i:s', $file->getMTime()); if ($posix_getpwuid) { $owner = posix_getpwuid($file->getOwner()); $owner = elgg_extract('name', $owner, $file->getOwner());
/** * Loads configuration related to Elgg as an application * * This runs on the engine boot and loads from the datalists database table. * * @see _elgg_engine_boot() * * @access private */ function _elgg_load_application_config() { global $CONFIG, $DATALIST_CACHE; $install_root = str_replace("\\", "/", dirname(dirname(dirname(__FILE__)))); $defaults = array('path' => "{$install_root}/", 'view_path' => "{$install_root}/views/", 'plugins_path' => "{$install_root}/mod/", 'language' => 'en', 'viewpath' => "{$install_root}/views/", 'pluginspath' => "{$install_root}/mod/"); foreach ($defaults as $name => $value) { if (empty($CONFIG->{$name})) { $CONFIG->{$name} = $value; } } // set cookie values for session and remember me if (!isset($CONFIG->cookies)) { $CONFIG->cookies = array(); } if (!isset($CONFIG->cookies['session'])) { $CONFIG->cookies['session'] = array(); } $session_defaults = session_get_cookie_params(); $session_defaults['name'] = 'Elgg'; $CONFIG->cookies['session'] = array_merge($session_defaults, $CONFIG->cookies['session']); if (!isset($CONFIG->cookies['remember_me'])) { $CONFIG->cookies['remember_me'] = array(); } $session_defaults['name'] = 'elggperm'; $session_defaults['expire'] = strtotime("+30 days"); $CONFIG->cookies['remember_me'] = array_merge($session_defaults, $CONFIG->cookies['remember_me']); // load entire datalist // This can cause OOM problems when the datalists table is large // @todo make a list of datalists that we want to get in one grab if (!is_memcache_available()) { $result = get_data("SELECT * FROM {$CONFIG->dbprefix}datalists"); if ($result) { foreach ($result as $row) { $DATALIST_CACHE[$row->name] = $row->value; } } } $path = datalist_get('path'); if (!empty($path)) { $CONFIG->path = $path; } // allow sites to set dataroot and simplecache_enabled in settings.php if (isset($CONFIG->dataroot)) { $CONFIG->dataroot = sanitise_filepath($CONFIG->dataroot); $CONFIG->dataroot_in_settings = true; } else { $dataroot = datalist_get('dataroot'); if (!empty($dataroot)) { $CONFIG->dataroot = $dataroot; } $CONFIG->dataroot_in_settings = false; } if (isset($CONFIG->simplecache_enabled)) { $CONFIG->simplecache_enabled_in_settings = true; } else { $simplecache_enabled = datalist_get('simplecache_enabled'); if ($simplecache_enabled !== false) { $CONFIG->simplecache_enabled = $simplecache_enabled; } else { $CONFIG->simplecache_enabled = 1; } $CONFIG->simplecache_enabled_in_settings = false; } $system_cache_enabled = datalist_get('system_cache_enabled'); if ($system_cache_enabled !== false) { $CONFIG->system_cache_enabled = $system_cache_enabled; } else { $CONFIG->system_cache_enabled = 1; } // initialize context here so it is set before the first get_input call $CONFIG->context = array(); // needs to be set before system, init for links in html head $CONFIG->lastcache = (int) datalist_get("simplecache_lastupdate"); $CONFIG->i18n_loaded_from_cache = false; // this must be synced with the enum for the entities table $CONFIG->entity_types = array('group', 'object', 'site', 'user'); }
<?php translation_editor_gatekeeper(); $language = get_input('language'); if (empty($language)) { register_error(elgg_echo('error:missing_data')); forward(REFERER); } $base_path = elgg_get_data_path() . 'translation_editor' . DIRECTORY_SEPARATOR; $filename = $base_path . $language . DIRECTORY_SEPARATOR . 'translation_editor_cleanup.json'; $filename = sanitise_filepath($filename, false); if (!file_exists($filename)) { register_error(elgg_echo('translation_editor:action:cleanup:remove:error:no_file')); forward(REFERER); } $contents = file_get_contents($filename); $removed = json_decode($contents, true); $fh = tmpfile(); fputcsv($fh, ['Plugin ID', 'key', 'translation'], ';'); foreach ($removed as $plugin_id => $translations) { if (!is_array($translations)) { continue; } foreach ($translations as $key => $value) { fputcsv($fh, [$plugin_id, $key, $value], ';'); } } // read the csv in to a var before output $contents = ''; rewind($fh); while (!feof($fh)) {
/** * Returns array of all plugin files * * @param array $valid_extensions array of extensions of files that will be returned * * @return \SplFileInfo[] */ private function getPluginFiles($valid_extensions = ['php', 'html', 'js']) { $skip_folders = ['.git', 'vendor', 'vendors', '.svn']; $files = []; $base_path = sanitise_filepath(elgg_get_plugins_path() . $this->plugin->getID()); $directory = new \RecursiveDirectoryIterator($base_path, \RecursiveDirectoryIterator::SKIP_DOTS); $iterator = new \RecursiveIteratorIterator($directory); foreach ($iterator as $file) { $file_folder = sanitise_filepath($file->getPath()); $file_folder = str_replace($base_path, '', $file_folder); foreach ($skip_folders as $skip) { if (strpos($file_folder, $skip) === 0) { continue 2; } } if (!in_array($file->getExtension(), $valid_extensions)) { continue; } $files[] = $file; } return $files; }
/** * Initialize the site including site entity, plugins, and configuration * * @param array $submissionVars Submitted vars * * @return bool */ protected function saveSiteSettings($submissionVars) { // ensure that file path, data path, and www root end in / $submissionVars['dataroot'] = sanitise_filepath($submissionVars['dataroot']); $submissionVars['wwwroot'] = sanitise_filepath($submissionVars['wwwroot']); $site = new ElggSite(); $site->name = strip_tags($submissionVars['sitename']); $site->url = $submissionVars['wwwroot']; $site->access_id = ACCESS_PUBLIC; $site->email = $submissionVars['siteemail']; $guid = $site->save(); if (!$guid) { register_error(_elgg_services()->translator->translate('install:error:createsite')); return FALSE; } // bootstrap site info $this->CONFIG->site_guid = $guid; $this->CONFIG->site_id = $guid; $this->CONFIG->site = $site; _elgg_services()->datalist->set('installed', time()); _elgg_services()->datalist->set('dataroot', $submissionVars['dataroot']); _elgg_services()->datalist->set('default_site', $site->getGUID()); _elgg_services()->datalist->set('version', elgg_get_version()); _elgg_services()->datalist->set('simplecache_enabled', 1); _elgg_services()->datalist->set('system_cache_enabled', 1); _elgg_services()->datalist->set('simplecache_lastupdate', time()); // @todo plugins might use this, but core doesn't. remove in 2.0 _elgg_services()->datalist->set('path', $this->CONFIG->path); // new installations have run all the upgrades $upgrades = elgg_get_upgrade_files("{$this->CONFIG->path}engine/lib/upgrades/"); _elgg_services()->datalist->set('processed_upgrades', serialize($upgrades)); _elgg_services()->configTable->set('view', 'default', $site->getGUID()); _elgg_services()->configTable->set('language', 'en', $site->getGUID()); _elgg_services()->configTable->set('default_access', $submissionVars['siteaccess'], $site->getGUID()); _elgg_services()->configTable->set('allow_registration', TRUE, $site->getGUID()); _elgg_services()->configTable->set('walled_garden', FALSE, $site->getGUID()); _elgg_services()->configTable->set('allow_user_default_access', '', $site->getGUID()); _elgg_services()->configTable->set('default_limit', 10, $site->getGUID()); $this->setSubtypeClasses(); $this->enablePlugins(); return TRUE; }
<?php $file = get_input('file'); $file = sanitise_filepath($file, false); // no file if (empty($file)) { forward(REFERER); } $file_path = elgg_get_data_path() . $file; // file doesn't exist or is directory if (!file_exists($file_path) || is_dir($file_path)) { forward(REFERER); } $contents = file_get_contents($file_path); // empty file if (empty($contents)) { forward(REFERER); } $filename = basename($file_path); $mimetype = 'application/octet-stream'; if (is_callable('finfo_open')) { $finfo = finfo_open(FILEINFO_MIME_TYPE); $mimetype = finfo_file($finfo, $file_path); } header("Pragma: public"); header("Content-type: {$mimetype}"); header("Content-Disposition: attachment; filename=\"{$filename}\""); header("Content-Length: " . strlen($contents)); echo $contents; exit;
/** * When given a full path, finds translation files and loads them * * @param string $path Full path * @param bool $load_all If true all languages are loaded, if * false only the current language + en are loaded * * @return void */ function register_translations($path, $load_all = false) { global $CONFIG; $path = sanitise_filepath($path); // Make a note of this path just incase we need to register this language later if (!isset($CONFIG->language_paths)) { $CONFIG->language_paths = array(); } $CONFIG->language_paths[$path] = true; // Get the current language based on site defaults and user preference $current_language = get_current_language(); elgg_log("Translations loaded from: {$path}"); // only load these files unless $load_all is true. $load_language_files = array('en.php', "{$current_language}.php"); $load_language_files = array_unique($load_language_files); $handle = opendir($path); if (!$handle) { elgg_log("Could not open language path: {$path}", 'ERROR'); return false; } $return = true; while (false !== ($language = readdir($handle))) { // ignore bad files if (substr($language, 0, 1) == '.' || substr($language, -4) !== '.php') { continue; } if (in_array($language, $load_language_files) || $load_all) { if (!(include_once $path . $language)) { $return = false; continue; } } } return $return; }
*/ global $CONFIG; // block non-admin users admin_gatekeeper(); if (get_input('settings') == 'go') { if (datalist_get('default_site')) { $site = get_entity(datalist_get('default_site')); if (!$site instanceof ElggSite) { throw new InstallationException(elgg_echo('InvalidParameterException:NonElggSite')); } $site->description = get_input('sitedescription'); $site->name = get_input('sitename'); $site->email = get_input('siteemail'); $site->url = get_input('wwwroot'); datalist_set('path', sanitise_filepath(get_input('path'))); datalist_set('dataroot', sanitise_filepath(get_input('dataroot'))); if (get_input('simplecache_enabled')) { elgg_view_enable_simplecache(); } else { elgg_view_disable_simplecache(); } if (get_input('viewpath_cache_enabled')) { elgg_enable_filepath_cache(); } else { elgg_disable_filepath_cache(); } set_config('language', get_input('language'), $site->getGUID()); set_config('default_access', get_input('default_access'), $site->getGUID()); if (get_input('allow_user_default_access')) { set_config('allow_user_default_access', 1, $site->getGUID()); } else {
/** * Update the user profile icon based on profile_sync data * * @param string $event the name of the event * @param string $type the type of the event * @param mixed $object supplied object * * @return void */ function theme_haarlem_intranet_profile_sync_profile_icon($event, $type, $object) { if (empty($object) || !is_array($object)) { return; } $user = elgg_extract('entity', $object); if (empty($user) || !elgg_instanceof($user, 'user')) { return; } // handle icons $datasource = elgg_extract('datasource', $object); $source_row = elgg_extract('source_row', $object); if (empty($datasource) || empty($source_row)) { return; } // handle custom icon $fh = new ElggFile(); $fh->owner_guid = $user->getGUID(); $icon_sizes = elgg_get_config('icon_sizes'); $icon_path = elgg_extract('profielfoto', $source_row); $icon_path = profile_sync_filter_var($icon_path); if (empty($icon_path)) { // remove icon foreach ($icon_sizes as $size => $info) { $fh->setFilename("haarlem_icon/{$size}.jpg"); if ($fh->exists()) { $fh->delete(); } } unset($user->haarlem_icontime); return; } $csv_location = $datasource->csv_location; if (empty($csv_location)) { return; } $csv_filename = basename($csv_location); $base_location = rtrim(str_ireplace($csv_filename, "", $csv_location), DIRECTORY_SEPARATOR); $icon_path = sanitise_filepath($icon_path, false); // prevent abuse (like ../../......) $icon_path = ltrim($icon_path, DIRECTORY_SEPARATOR); // remove beginning / $icon_path = $base_location . DIRECTORY_SEPARATOR . $icon_path; // concat base location and rel path // icon exists if (!file_exists($icon_path)) { return; } // was csv image updated $csv_iconsize = @filesize($icon_path); if ($csv_iconsize !== false) { $csv_iconsize = md5($csv_iconsize); $icontime = $user->haarlem_icontime; if ($csv_iconsize === $icontime) { // icons are the same return; } } // try to get the user icon $icon_contents = file_get_contents($icon_path); if (empty($icon_contents)) { return; } // make sure we have a hash to save if ($csv_iconsize === false) { $csv_iconsize = strlen($icon_contents); $csv_iconsize = md5($csv_iconsize); } // write icon to a temp location for further handling $tmp_icon = tempnam(sys_get_temp_dir(), $user->getGUID()); file_put_contents($tmp_icon, $icon_contents); // resize icon $icon_updated = false; foreach ($icon_sizes as $size => $icon_info) { $icon_contents = get_resized_image_from_existing_file($tmp_icon, $icon_info["w"], $icon_info["h"], $icon_info["square"], 0, 0, 0, 0, $icon_info["upscale"]); if (empty($icon_contents)) { continue; } $fh->setFilename("haarlem_icon/{$size}.jpg"); $fh->open("write"); $fh->write($icon_contents); $fh->close(); $icon_updated = true; } // did we have a successfull icon upload? if ($icon_updated) { $user->haarlem_icontime = $csv_iconsize; } // cleanup unlink($tmp_icon); }
/** * Initialize the site including site entity, plugins, and configuration * * @param array $submissionVars Submitted vars * * @return bool */ protected function saveSiteSettings($submissionVars) { // ensure that file path, data path, and www root end in / $submissionVars['dataroot'] = sanitise_filepath($submissionVars['dataroot']); $submissionVars['wwwroot'] = sanitise_filepath($submissionVars['wwwroot']); $site = new ElggSite(); $site->name = strip_tags($submissionVars['sitename']); $site->url = $submissionVars['wwwroot']; $site->access_id = ACCESS_PUBLIC; $site->email = $submissionVars['siteemail']; $guid = $site->save(); if (!$guid) { register_error(_elgg_services()->translator->translate('install:error:createsite')); return FALSE; } // bootstrap site info $this->CONFIG->site_guid = $guid; $this->CONFIG->site = $site; _elgg_services()->configTable->set('installed', time()); _elgg_services()->configTable->set('dataroot', $submissionVars['dataroot']); _elgg_services()->configTable->set('default_site', $site->getGUID()); _elgg_services()->configTable->set('version', elgg_get_version()); _elgg_services()->configTable->set('simplecache_enabled', 1); _elgg_services()->configTable->set('system_cache_enabled', 1); _elgg_services()->configTable->set('simplecache_lastupdate', time()); // new installations have run all the upgrades $upgrades = elgg_get_upgrade_files(\Elgg\Application::elggDir()->getPath("/engine/lib/upgrades/")); _elgg_services()->configTable->set('processed_upgrades', $upgrades); _elgg_services()->configTable->set('view', 'default', $site->getGUID()); _elgg_services()->configTable->set('language', 'en', $site->getGUID()); _elgg_services()->configTable->set('default_access', $submissionVars['siteaccess'], $site->getGUID()); _elgg_services()->configTable->set('allow_registration', TRUE, $site->getGUID()); _elgg_services()->configTable->set('walled_garden', FALSE, $site->getGUID()); _elgg_services()->configTable->set('allow_user_default_access', '', $site->getGUID()); _elgg_services()->configTable->set('default_limit', 10, $site->getGUID()); _elgg_services()->configTable->set('security_protect_upgrade', true, $site->getGUID()); _elgg_services()->configTable->set('security_notify_admins', true, $site->getGUID()); _elgg_services()->configTable->set('security_notify_user_password', true, $site->getGUID()); _elgg_services()->configTable->set('security_email_require_password', true, $site->getGUID()); $this->setSubtypeClasses(); $this->enablePlugins(); return TRUE; }
* Options are saved among metadata on the site object, entries * in the datalist table, and entries in the config table. * * @package Elgg.Core * @subpackage Administration.Site */ $site = elgg_get_site_entity(); if (!$site) { throw new InstallationException("The system is missing an ElggSite entity!"); } if (!$site instanceof ElggSite) { throw new InstallationException("Passing a non-ElggSite to an ElggSite constructor!"); } $site->url = rtrim(get_input('wwwroot', '', false), '/') . '/'; datalist_set('path', sanitise_filepath(get_input('path', '', false))); $dataroot = sanitise_filepath(get_input('dataroot', '', false)); // check for relative paths if (stripos(PHP_OS, 'win') === 0) { if (strpos($dataroot, ':') !== 1) { $msg = elgg_echo('admin:configuration:dataroot:relative_path', array($dataroot)); register_error($msg); forward(REFERER); } } else { if (strpos($dataroot, '/') !== 0) { $msg = elgg_echo('admin:configuration:dataroot:relative_path', array($dataroot)); register_error($msg); forward(REFERER); } } datalist_set('dataroot', $dataroot);
<?php $path = get_input('path'); $path = sanitise_filepath($path, false); if (empty($path)) { register_error(elgg_echo('error:missing_data')); forward(REFERER); } $logging_base_dir = elgg_get_data_path() . 'elasticsearch/'; // check if the requested file exists $filename = $logging_base_dir . $path; if (!file_exists($filename)) { register_error(elgg_echo('error:404:content')); forward(REFERER); } // get contents $contents = file_get_contents($filename); // begin download header('Pragma: public'); header('Content-Type: text/plain'); header('Content-Disposition: Attachment; filename=' . basename($filename)); header('Content-Length: ' . strlen($contents)); echo $contents; exit;
/** * Returns the plugin's full path with trailing slash. * * @return string */ public function getPath() { $result = false; if ($this->path) { $result = sanitise_filepath($this->path); } else { $result = elgg_get_plugins_path() . $this->getID(); $result = sanitise_filepath($result); $this->path = $result; } return $result; }
/** * Initialize the site including site entity, plugins, and configuration * * @param array $submissionVars Submitted vars * * @return bool */ protected function saveSiteSettings($submissionVars) { global $CONFIG; // ensure that file path, data path, and www root end in / $submissionVars['path'] = sanitise_filepath($submissionVars['path']); $submissionVars['dataroot'] = sanitise_filepath($submissionVars['dataroot']); $submissionVars['wwwroot'] = sanitise_filepath($submissionVars['wwwroot']); $site = new ElggSite(); $site->name = $submissionVars['sitename']; $site->url = $submissionVars['wwwroot']; $site->access_id = ACCESS_PUBLIC; $site->email = $submissionVars['siteemail']; $guid = $site->save(); if (!$guid) { register_error(elgg_echo('install:error:createsite')); return FALSE; } // bootstrap site info $CONFIG->site_guid = $guid; $CONFIG->site = $site; datalist_set('installed', time()); datalist_set('path', $submissionVars['path']); datalist_set('dataroot', $submissionVars['dataroot']); datalist_set('default_site', $site->getGUID()); datalist_set('version', get_version()); datalist_set('simplecache_enabled', 1); datalist_set('system_cache_enabled', 1); // new installations have run all the upgrades $upgrades = elgg_get_upgrade_files($submissionVars['path'] . 'engine/lib/upgrades/'); datalist_set('processed_upgrades', serialize($upgrades)); set_config('view', 'default', $site->getGUID()); set_config('language', 'en', $site->getGUID()); set_config('default_access', $submissionVars['siteaccess'], $site->getGUID()); set_config('allow_registration', TRUE, $site->getGUID()); set_config('walled_garden', FALSE, $site->getGUID()); set_config('allow_user_default_access', '', $site->getGUID()); $this->enablePlugins(); return TRUE; }
/** * Serves up screenshots for plugins from * admin_plugin_screenshot/<plugin_id>/<size>/<ss_name>.<ext> * * @param array $pages The pages array * @return bool * @access private */ function admin_plugin_screenshot_page_handler($pages) { // only admins can use this for security admin_gatekeeper(); $plugin_id = elgg_extract(0, $pages); // only thumbnail or full. $size = elgg_extract(1, $pages, 'thumbnail'); // the rest of the string is the filename $filename_parts = array_slice($pages, 2); $filename = implode('/', $filename_parts); $filename = sanitise_filepath($filename, false); $plugin = new ElggPlugin($plugin_id); if (!$plugin) { $file = elgg_get_root_path() . '_graphics/icons/default/medium.png'; } else { $file = $plugin->getPath() . $filename; if (!file_exists($file)) { $file = elgg_get_root_path() . '_graphics/icons/default/medium.png'; } } header("Content-type: image/jpeg"); // resize to 100x100 for thumbnails switch ($size) { case 'thumbnail': echo get_resized_image_from_existing_file($file, 100, 100, true); break; case 'full': default: echo file_get_contents($file); break; } return true; }
/** * Load a plugin package from mod/$id or by full path. * * @param string $plugin The ID (directory name) or full path of the plugin. * @param bool $validate Automatically run isValid()? * * @throws PluginException */ public function __construct($plugin, $validate = true) { $plugin_path = elgg_get_plugins_path(); // @todo wanted to avoid another is_dir() call here. // should do some profiling to see how much it affects if (strpos($plugin, $plugin_path) === 0 || is_dir($plugin)) { // this is a path $path = sanitise_filepath($plugin); // the id is the last element of the array $path_array = explode('/', trim($path, '/')); $id = array_pop($path_array); } else { // this is a plugin id // strict plugin names if (preg_match('/[^a-z0-9\\.\\-_]/i', $plugin)) { throw new PluginException(elgg_echo('PluginException:InvalidID', array($plugin))); } $path = "{$plugin_path}{$plugin}/"; $id = $plugin; } if (!is_dir($path)) { throw new PluginException(elgg_echo('PluginException:InvalidPath', array($path))); } $this->path = $path; $this->id = $id; if ($validate && !$this->isValid()) { if ($this->errorMsg) { throw new PluginException(elgg_echo('PluginException:InvalidPlugin:Details', array($plugin, $this->errorMsg))); } else { throw new PluginException(elgg_echo('PluginException:InvalidPlugin', array($plugin))); } } return true; }
* * @package Elgg * @subpackage Core * @author Curverider Ltd * @link http://elgg.org/ */ elgg_set_viewtype('failsafe'); // Set failsafe again incase we get an exception thrown if (is_installed()) { forward(); } if (get_input('settings') == 'go') { if (!datalist_get('default_site')) { // Sanitise $path = sanitise_filepath(get_input('path')); $dataroot = sanitise_filepath(get_input('dataroot')); // Blank? if ($dataroot == "/") { throw new InstallationException(elgg_echo('InstallationException:DatarootBlank')); } // That it's valid if (stripos($dataroot, $path) !== false) { throw new InstallationException(sprintf(elgg_echo('InstallationException:DatarootUnderPath'), $dataroot)); } // Check data root is writable if (!is_writable($dataroot)) { throw new InstallationException(sprintf(elgg_echo('InstallationException:DatarootNotWritable'), $dataroot)); } $site = new ElggSite(); $site->name = get_input('sitename'); $site->url = get_input('wwwroot');
/** * Returns a list of files in $directory. * * Only returns files. Does not recurse into subdirs. * * @param string $directory Directory to look in * @param array $exceptions Array of filenames to ignore * @param array $list Array of files to append to * @param mixed $extensions Array of extensions to allow, NULL for all. Use a dot: array('.php'). * * @return array Filenames in $directory, in the form $directory/filename. */ function elgg_get_file_list($directory, $exceptions = array(), $list = array(), $extensions = NULL) { $directory = sanitise_filepath($directory); if ($handle = opendir($directory)) { while (($file = readdir($handle)) !== FALSE) { if (!is_file($directory . $file) || in_array($file, $exceptions)) { continue; } if (is_array($extensions)) { if (in_array(strrchr($file, '.'), $extensions)) { $list[] = $directory . $file; } } else { $list[] = $directory . $file; } } closedir($handle); } return $list; }
/** * Run the profile synchronization based on the provided configuration * * @param ElggObject $sync_config The sync configuration * * @return void */ function profile_sync_proccess_configuration(ElggObject $sync_config) { if (!elgg_instanceof($sync_config, 'object', 'profile_sync_config')) { return; } $datasource = $sync_config->getContainerEntity(); if (!elgg_instanceof($datasource, 'object', 'profile_sync_datasource')) { return; } $sync_match = json_decode($sync_config->sync_match, true); $datasource_id = $sync_config->datasource_id; $profile_id = $sync_config->profile_id; $lastrun = (int) $sync_config->lastrun; $ban_user = (bool) $sync_config->ban_user; $unban_user = (bool) $sync_config->unban_user; profile_sync_log($sync_config->getGUID(), "Last run timestamp: {$lastrun} (" . date(elgg_echo('friendlytime:date_format'), $lastrun) . ")" . PHP_EOL); $profile_fields = elgg_get_config('profile_fields'); if (!$ban_user && !$unban_user && empty($sync_match) || $datasource_id === '' || empty($profile_id)) { profile_sync_log($sync_config->getGUID(), 'Configuration error', true); return; } if (!in_array($profile_id, ['name', 'username', 'email']) && !array_key_exists($profile_id, $profile_fields)) { profile_sync_log($sync_config->getGUID(), "Invalid profile identifier: {$profile_id}", true); return; } switch ($datasource->datasource_type) { case 'mysql': $sync_source = new ProfileSyncMySQL($datasource, $lastrun); break; case 'csv': $sync_source = new ProfileSyncCSV($datasource, $lastrun); break; default: profile_sync_log($sync_config->getGUID(), "Invalid datasource type: {$datasource->datasource_type}", true); return; break; } if (!$sync_source->connect()) { profile_sync_log($sync_config->getGUID(), 'Unable to connect to the datasource', true); return; } $datasource_id_fallback = $sync_config->datasource_id_fallback; $profile_id_fallback = $sync_config->profile_id_fallback; $create_user = (bool) $sync_config->create_user; $notify_user = (bool) $sync_config->notify_user; $create_user_name = false; $create_user_email = false; $create_user_username = false; if ($create_user) { profile_sync_log($sync_config->getGUID(), 'User creation is allowed'); foreach ($sync_match as $datasource_col => $datasource_config) { list($datasource_col) = explode(PROFILE_SYNC_DATASOURCE_COL_SEPERATOR, $datasource_col); switch ($datasource_config['profile_field']) { case 'name': $create_user_name = $datasource_col; break; case 'email': $create_user_email = $datasource_col; break; case 'username': $create_user_username = $datasource_col; break; } } if ($create_user_name === false || $create_user_username === false || $create_user_email === false) { profile_sync_log($sync_config->getGUID(), 'Missing information to create users'); profile_sync_log($sync_config->getGUID(), "- name: {$create_user_name}"); profile_sync_log($sync_config->getGUID(), "- email: {$create_user_email}"); profile_sync_log($sync_config->getGUID(), "- username: {$create_user_username}"); $create_user = false; } } if ($ban_user) { profile_sync_log($sync_config->getGUID(), 'Matching users will be banned'); } if ($unban_user) { profile_sync_log($sync_config->getGUID(), 'Matching users will be unbanned'); } if ($ban_user && $create_user) { profile_sync_log($sync_config->getGUID(), 'Both create and ban users is allowed, don\'t know what to do', true); return; } if ($unban_user && $create_user) { profile_sync_log($sync_config->getGUID(), 'Both create and unban users is allowed, don\'t know what to do', true); return; } if ($ban_user && $unban_user) { profile_sync_log($sync_config->getGUID(), 'Both ban and unban users is allowed, don\'t know what to do', true); return; } // start the sync process set_time_limit(0); _elgg_services()->db->disableQueryCache(); $default_access = get_default_access(); $ia = elgg_set_ignore_access(true); $site = elgg_get_site_entity(); // we want to cache entity metadata on first __get() $metadata_cache = _elgg_services()->metadataCache; if ($metadata_cache instanceof ElggVolatileMetadataCache) { // elgg 1.10 $metadata_cache->setIgnoreAccess(false); } $counters = ['source rows' => 0, 'empty source id' => 0, 'duplicate email' => 0, 'duplicate name' => 0, 'duplicate profile field' => 0, 'user not found' => 0, 'user created' => 0, 'user banned' => 0, 'user unbanned' => 0, 'empty attributes' => 0, 'invalid profile field' => 0, 'invalid source field' => 0, 'processed users' => 0]; $base_location = ''; if ($sync_source instanceof ProfileSyncCSV) { // get base path $csv_location = $datasource->csv_location; $csv_filename = basename($csv_location); $base_location = rtrim(str_ireplace($csv_filename, '', $csv_location), DIRECTORY_SEPARATOR); } while (($source_row = $sync_source->fetchRow()) !== false) { $counters['source rows']++; // let other plugins change the row data $params = ['datasource' => $datasource, 'sync_config' => $sync_config, 'source_row' => $source_row]; $source_row = elgg_trigger_plugin_hook('source_row', 'profile_sync', $params, $source_row); if (!is_array($source_row) || empty($source_row[$datasource_id])) { $counters["empty source id"]++; continue; } // find user $datasource_used_id = $datasource_id; $profile_used_id = $profile_id; $datasource_unique_id = elgg_extract($datasource_id, $source_row); $user = profile_sync_find_user($profile_id, $datasource_unique_id, $sync_config, $counters); // fallback user if (empty($user) && $datasource_id_fallback !== '' && !empty($source_row[$datasource_id_fallback]) && !empty($profile_id_fallback)) { // profile_sync_log($sync_config->getGUID(), "User not found: {$profile_id} => {$datasource_unique_id} trying fallback"); $profile_used_id = $profile_id_fallback; $datasource_used_id = $datasource_id_fallback; $datasource_unique_id = elgg_extract($datasource_id_fallback, $source_row); $user = profile_sync_find_user($profile_id_fallback, $datasource_unique_id, $sync_config, $counters); } // check if we need to create a user if (empty($user) && $create_user) { $pwd = generate_random_cleartext_password(); try { // convert to utf-8 $username = profile_sync_filter_var($source_row[$create_user_username]); $name = profile_sync_filter_var($source_row[$create_user_name]); $email = profile_sync_filter_var($source_row[$create_user_email]); $user_guid = register_user($username, $pwd, $name, $email); if (!empty($user_guid)) { $counters['user created']++; profile_sync_log($sync_config->getGUID(), "Created user: {$name}"); $user = get_user($user_guid); if ($notify_user) { $subject = elgg_echo('useradd:subject'); $body = elgg_echo('useradd:body', [$user->name, $site->name, $site->url, $user->username, $pwd]); notify_user($user->getGUID(), $site->getGUID(), $subject, $body); } } } catch (RegistrationException $r) { $name = profile_sync_filter_var($source_row[$create_user_name]); profile_sync_log($sync_config->getGUID(), "Failure creating user: {$name} - {$r->getMessage()}"); } } // did we get a user if (empty($user)) { $counters['user not found']++; profile_sync_log($sync_config->getGUID(), "User not found: {$profile_used_id} => {$datasource_unique_id}"); continue; } else { $counters['processed users']++; } // ban the user if ($ban_user) { // already banned? if (!$user->isBanned()) { $counters['user banned']++; $user->ban("Profile Sync: {$sync_config->title}"); profile_sync_log($sync_config->getGUID(), "User banned: {$user->name} ({$user->username})"); } continue; } // unban the user if ($unban_user) { // already banned? if ($user->isBanned()) { $counters['user unbanned']++; $user->unban(); profile_sync_log($sync_config->getGUID(), "User unbanned: {$user->name} ({$user->username})"); } continue; } // start of profile sync $special_sync_fields = ['name', 'username', 'email', 'user_icon_relative_path', 'user_icon_full_path']; foreach ($sync_match as $datasource_col => $profile_config) { list($datasource_col) = explode(PROFILE_SYNC_DATASOURCE_COL_SEPERATOR, $datasource_col); $profile_field = elgg_extract('profile_field', $profile_config); $access = (int) elgg_extract('access', $profile_config, $default_access); $override = (bool) elgg_extract('always_override', $profile_config, true); if (!in_array($profile_field, $special_sync_fields) && !array_key_exists($profile_field, $profile_fields)) { $counters['invalid profile field']++; continue; } if (!isset($source_row[$datasource_col])) { $counters['invalid source field']++; continue; } $value = elgg_extract($datasource_col, $source_row); $value = profile_sync_filter_var($value); switch ($profile_field) { case 'email': if (!is_email_address($value)) { continue 2; } case 'username': if ($override && $user->username !== $value) { // new username, check for availability if (get_user_by_username($value)) { // already taken profile_sync_log($sync_config->getGUID(), "New username: {$value} for {$user->name} is already taken"); continue 2; } } case 'name': if (empty($value)) { $counters['empty attributes']++; profile_sync_log($sync_config->getGUID(), "Empty user attribute: {$datasource_col} for user {$user->name}"); continue 2; } if (isset($user->{$profile_field}) && !$override) { // don't override profile field // profile_sync_log($sync_config->getGUID(), "Profile field already set: {$profile_field} for user {$user->name}"); continue 2; } // check for the same value if ($user->{$profile_field} === $value) { // same value, no need to update continue 2; } // save user attribute $user->{$profile_field} = $value; $user->save(); break; case 'user_icon_relative_path': // get a user icon based on a relative file path/url // only works with file based datasources (eg. csv) if (!$sync_source instanceof ProfileSyncCSV) { profile_sync_log($sync_config->getGUID(), "Can't fetch relative user icon path in non CSV datasouces: trying user {$user->name}"); continue 2; } // make new icon path if (!empty($value)) { $value = sanitise_filepath($value, false); // prevent abuse (like ../../......) $value = ltrim($value, DIRECTORY_SEPARATOR); // remove beginning / $value = $base_location . DIRECTORY_SEPARATOR . $value; // concat base location and rel path } case 'user_icon_full_path': // get a user icon based on a full file path/url if (!empty($user->icontime) && !$override) { // don't override icon // profile_sync_log($sync_config->getGUID(), "User already has an icon: {$user->name}"); continue 2; } // upload new icon $icon_sizes = elgg_get_config('icon_sizes'); $fh = new ElggFile(); $fh->owner_guid = $user->getGUID(); if (empty($value) && $user->icontime) { // no icon, so unset current icon profile_sync_log($sync_config->getGUID(), "Removing icon for user: {$user->name}"); foreach ($icon_sizes as $size => $icon_info) { $fh->setFilename("profile/{$user->getGUID()}{$size}.jpg"); $fh->delete(); } unset($user->icontime); unset($fh); // on to the next field continue 2; } // try to get the user icon $icon_contents = file_get_contents($value); if (empty($icon_contents)) { profile_sync_log($sync_config->getGUID(), "Unable to fetch user icon: {$value} for user {$user->name}"); continue 2; } // was csv image updated $csv_icontime = @filemtime($value); if ($csv_icontime !== false && isset($user->icontime)) { $csv_icontime = sanitise_int($csv_icontime); $icontime = sanitise_int($user->icontime); if ($csv_icontime === $icontime) { // base image has same modified time as user icontime, so skipp // profile_sync_log($sync_config->getGUID(), "No need to update user icon for user: {$user->name}"); continue 2; } } if ($csv_icontime === false) { $csv_icontime = time(); } // write icon to a temp location for further handling $tmp_icon = tempnam(sys_get_temp_dir(), $user->getGUID()); file_put_contents($tmp_icon, $icon_contents); // resize icon $icon_updated = false; foreach ($icon_sizes as $size => $icon_info) { $icon_contents = get_resized_image_from_existing_file($tmp_icon, $icon_info['w'], $icon_info['h'], $icon_info['square'], 0, 0, 0, 0, $icon_info['upscale']); if (empty($icon_contents)) { continue; } $fh->setFilename("profile/{$user->getGUID()}{$size}.jpg"); $fh->open('write'); $fh->write($icon_contents); $fh->close(); $icon_updated = true; } // did we have a successfull icon upload? if ($icon_updated) { $user->icontime = $csv_icontime; } // cleanup unlink($tmp_icon); unset($fh); break; default: // check overrides if (isset($user->{$profile_field}) && !$override) { // don't override profile field // profile_sync_log($sync_config->getGUID(), "Profile field already set: {$profile_field} for user {$user->name}"); continue 2; } // convert tags if ($profile_fields[$profile_field] === 'tags') { $value = string_to_tag_array($value); } // remove existing value if (empty($value)) { if (isset($user->{$profile_field})) { unset($user->{$profile_field}); } continue 2; } // check for the same value if ($user->{$profile_field} === $value) { // same value, no need to update continue 2; } // profile_sync_log($sync_config->getGUID(), "Updating {$profile_field} with value {$value} old value {$user->$profile_field}"); // get the access of existing profile data $access = profile_sync_get_profile_field_access($user->getGUID(), $profile_field, $access); // save new value $user->setMetadata($profile_field, $value, '', false, $user->getGUID(), $access); break; } } // let others know we updated the user $update_event_params = ['entity' => $user, 'source_row' => $source_row, 'sync_config' => $sync_config, 'datasource' => $datasource]; elgg_trigger_event('update_user', 'profile_sync', $update_event_params); // cache cleanup _elgg_services()->entityCache->remove($user->getGUID()); $metadata_cache->clear($user->getGUID()); } profile_sync_log($sync_config->getGUID(), PHP_EOL . 'End processing: ' . date(elgg_echo('friendlytime:date_format')) . PHP_EOL); foreach ($counters as $name => $count) { profile_sync_log($sync_config->getGUID(), "{$name}: {$count}"); } // close logfile profile_sync_log($sync_config->getGUID(), null, true); // save last run $sync_config->lastrun = time(); // cleanup datasource cache $sync_source->cleanup(); // re-enable db caching _elgg_services()->db->enableQueryCache(); // restore access elgg_set_ignore_access($ia); if ($metadata_cache instanceof ElggVolatileMetadataCache) { // elgg 1.10 $metadata_cache->unsetIgnoreAccess(); } elseif ($metadata_cache instanceof \Elgg\Cache\MetadataCache) { // elgg 1.11+ $metadata_cache->clearAll(); } }