/** * Get total number of users. * * @api * * @return int */ public static function getCount() { $user_count = Cache::fetch('user_count'); if ($user_count !== false) { return $user_count; } $stmt = self::createStatement("\n SELECT count(*)\n FROM tbl_user\n WHERE\n disabled IS FALSE AND\n visible IS TRUE\n "); $user_count = $stmt->fetchColumn(); Cache::store('user_count', $user_count, 300); return $user_count; }
/** * Return the number of distinct users which accessed the file * * @api * * @param int $file_id * @return int|false */ public static function getUserCount($file_id) { $count = Cache::fetch('file_user_count.' . $file_id); if ($count !== false) { return $count; } $stmt = self::createStatement("\n SELECT count(DISTINCT user_id)\n FROM tbl_statistic_file\n WHERE file_id = :file_id\n "); $stmt->assignId('file_id', $file_id); $count = $stmt->fetchInt(); Cache::store('file_user_count.' . $file_id, $count, 300); return $count; }
/** * Remove entry from array. Returns only false, if the entry still exists after this action. * * @internal * * @param array $user * * @return bool true if registered name does now no longer exist */ public static function delete(array $user) { if (empty($user['id'])) { return true; } // if there is no entry, it is already unregistered if (!($users = Cache::fetch(self::PREFIX . 'users'))) { return true; } // unset unset($users[$user['id']]); Cache::store(self::PREFIX . 'users', $users); return true; }
/** * Get the default privacy group for a user (or the default one as fallback). * * @api * * @param string $permission * @param int $user_id * * @return string|false false if nothing was found */ public static function getPrivacyGroup($permission, $user_id = 0) { if (empty($permission)) { return false; } $hashName = __METHOD__ . '.' . md5(serialize(func_get_args())); $privacy = Cache::fetch($hashName); if ($privacy !== false) { return $privacy; } $stmt = self::createStatement("\n SELECT COALESCE(pr.privacy_group, p.default_privacy_group) AS privacy_group\n FROM tbl_permission p\n LEFT JOIN tbl_privacy pr\n ON p.id = pr.permission_id\n AND pr.user_id = :user_id\n WHERE p.name=:permission\n "); $stmt->assign('user_id', $user_id); // may be no real id $stmt->assign('permission', $permission); $privacy = $stmt->fetchColumn(); if ($privacy !== false) { Cache::store($hashName, $privacy, 300); } return $privacy; }
/** * This function generates new .css files from the .scss files in the stylesheet folder under the condition, that * the .scss files are newer or possible dependencies are updated. Files that begin with underscore (_) are not * transformed and are only used for defining parts of rules. * * @api */ public static function update() { $sourcePath = self::getSourcePath(); $targetPath = self::getTargetPath(); if (!is_dir($targetPath)) { FileUtil::makedir($targetPath); } // check if source has changed $updated = Cache::fetch('style.update'); if ($updated !== false && $updated > filemtime($sourcePath)) { // check all files in the source folder for modifications if (Config::getDetail('stylesheet', 'check_file_level', self::$defaultConfig)) { $needUpdate = false; $dir = new \DirectoryIterator($sourcePath); foreach ($dir as $file) { /** @var \DirectoryIterator $file */ $filename = $file->getFilename(); // ignore dirs if ($file->isDot() || $file->isDir() || strpos($filename, '.#') === 0) { continue; } if ($updated < filemtime($sourcePath . $filename)) { $needUpdate = true; break; } } // foreach dir if (!$needUpdate) { return; } } else { return; } } $dir = new \DirectoryIterator($sourcePath); // remember last update (begin with this file as dependency) $lastDependencyUpdate = filemtime(__FILE__); // list of files to generate $scssFiles = []; // first step: generate list of files and get last updated dependency file foreach ($dir as $file) { /** @var \DirectoryIterator $file */ $filename = $file->getFilename(); // ignore dirs if ($file->isDot() || $file->isDir() || strpos($filename, '.#') === 0) { continue; } if (strpos($filename, '_') === 0) { $lastDependencyUpdate = max($lastDependencyUpdate, filemtime($sourcePath . $filename)); } else { $scssFiles[] = $filename; } } // foreach dir foreach ($scssFiles as $filename) { // does target exist? does it have an older timestamp? $savefile = $targetPath . str_replace('.scss', '.css', $filename); if (file_exists($savefile)) { $modified = filemtime($savefile); if (filemtime($sourcePath . $filename) <= $modified && $lastDependencyUpdate <= $modified) { continue; } } // save and set file permissions /*require_once "vendor/leafo/scssphp/scss.inc.php"; $scss = new \scssc(); $scss->addImportPath(function ($path) { if (!file_exists('stylesheet/'.$path)) { return null; } return 'stylesheet/'.$path; }); */ try { // will import `stylesheets/vanilla.css' // file_put_contents($savefile, $scss->compile('@import "'.$filename.'"')); file_put_contents($savefile, self::getParser()->toCss(file_get_contents($sourcePath . $filename), false)); chmod($savefile, Config::getDetail('stylesheet', 'file_perms', self::$defaultConfig)); } catch (\Exception $exception) { Logger::getInstance()->exception($exception); } } // foreach scssFiles Cache::store('style.update', time()); }