/** * check upload capability * * This function checks surfer overall capability against actual * server configuration (PHP parameter 'file_uploads') and also * against the parameter [code]users_without_uploads[/code] * set in the configuration panel for users. * * @see users/configure.php * * @param string actual capability, for possible impersonation (see services/blog.php) * @return TRUE if the surfer is allowed to upload files, FALSE otherwise */ public static function may_upload($capability = NULL) { global $context; // sanity check if (!$capability) { $capability = Surfer::get_capability(); } // server limitation if (!ini_get('file_uploads')) { return FALSE; } // administrative permission has not been set if (!isset($context['users_without_uploads'])) { return TRUE; } // even associates may not upload files if ($context['users_without_uploads'] == 'Y') { return FALSE; } // only associates may upload files if ($context['users_without_uploads'] == 'R' && !Surfer::is_associate() && $capability != 'A') { return FALSE; } // surfers are encouraged to share files and images return TRUE; }
/** * put something into the cache * * You can store an array or another kind of structured object, but after * serialization. * * The default caching period is 20 minutes (actually, 20m*60s = 1,200s) * * @param string the id of this item * @param string the content to store * @param string the topic related to this item * @param int the maximum time before expiration, in seconds */ public static function put($id, &$text, $topic = 'global', $duration = 1200, $f_capa = true, $f_lang = true, $f_gmt_off = true) { global $context; // maybe we don't have to cache if (isset($context['without_cache']) && $context['without_cache'] == 'Y') { return; } // cache has been poisoned if (isset($context['cache_has_been_poisoned']) && $context['cache_has_been_poisoned']) { return; } // the sql back-end may be not available during software updates or on NO_MODEL_PRELOAD if (!is_callable(array('SQL', 'query'))) { return; } // cached content depends on surfer capability if ($f_capa) { $id .= '/' . Surfer::get_capability(); } // cached content depends on selected language if ($f_lang) { $id .= '/' . $context['language']; } // cached content depends on time offset if ($f_gmt_off) { $id .= '/' . Surfer::get_gmt_offset(); } // don't cache more than expected $expiry = gmstrftime('%Y-%m-%d %H:%M:%S', time() + $duration); // cache also empty content if (!$text) { $text = ' '; } // update the database; do not report on error $query = "REPLACE INTO " . SQL::table_name('cache') . " SET" . " id='" . SQL::escape($id) . "'," . " text='" . SQL::escape($text) . "'," . " topic='" . SQL::escape($topic) . "'," . " expiry_date='" . $expiry . "'," . " edit_date='" . gmstrftime('%Y-%m-%d %H:%M:%S') . "'"; SQL::query($query, TRUE); }