Commits

Anonymous committed 215eb49

#838: Add functions

Comments (0)

Files changed (2)

include/cache.php

 
 
 //
+// Generate the admins cache PHP script
+//
+function generate_admins_cache()
+{
+	global $db;
+
+	// Get admins from the DB
+	$result = $db->query('SELECT id FROM '.$db->prefix.'users WHERE group_id='.PUN_ADMIN) or error('Unable to fetch users info', __FILE__, __LINE__, $db->error());
+
+	$output = array();
+	while ($row = $db->fetch_row($result))
+		$output[] = $row[0];
+
+	// Output admin list as PHP code
+	$fh = @fopen(FORUM_CACHE_DIR.'cache_admins.php', 'wb');
+	if (!$fh)
+		error('Unable to write admins cache file to cache directory. Please make sure PHP has write access to the directory \''.pun_htmlspecialchars(FORUM_CACHE_DIR).'\'', __FILE__, __LINE__);
+
+	fwrite($fh, '<?php'."\n\n".'define(\'PUN_ADMINS_LOADED\', 1);'."\n\n".'$pun_admins = '.var_export($output, true).';'."\n\n".'?>');
+
+	fclose($fh);
+
+	if (function_exists('apc_delete_file'))
+		@apc_delete_file(FORUM_CACHE_DIR.'cache_admins.php');
+}
+
+
+//
 // Delete all feed caches
 //
 function clear_feed_cache()

include/functions.php

 	return $protocol;
 }
 
+
 //
 // Fetch the base_url, optionally support HTTPS and HTTP
 //
 
 
 //
+// Fetch admin IDs
+//
+function get_admin_ids()
+{
+	if (file_exists(FORUM_CACHE_DIR.'cache_admins.php'))
+		include FORUM_CACHE_DIR.'cache_admins.php';
+
+	if (!defined('PUN_ADMINS_LOADED'))
+	{
+		if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
+			require PUN_ROOT.'include/cache.php';
+
+		generate_admins_cache();
+		require FORUM_CACHE_DIR.'cache_admins.php';
+	}
+
+	return $pun_admins;
+}
+
+
+//
 // Fill $pun_user with default values (for guests)
 //
 function set_default_user()