where('meta_key', $key) ->first(); if ($exist) { return $exist->value; } return $default; }); } public static function getFeaturesConfig() { static $features = null; if ($features) { return $features; } $features = self::getOption('fluent_community_features', []); $defaults = [ 'leader_board_module' => 'yes', 'course_module' => 'yes', 'giphy_module' => 'no', 'giphy_api_key' => '', 'emoji_module' => 'yes', 'cloud_storage' => 'no', 'invitation' => 'yes', 'user_badge' => 'yes', ]; if (defined('FLUENT_COMMUNITY_CLOUD_STORAGE') && FLUENT_COMMUNITY_CLOUD_STORAGE) { $features['cloud_storage'] = 'yes'; } $features = wp_parse_args($features, $defaults); $hasPro = defined('FLUENT_COMMUNITY_PRO') && FLUENT_COMMUNITY_PRO; if (!$hasPro) { $features['leader_board_module'] = 'no'; $features['giphy_module'] = 'no'; $features['emoji_module'] = 'no'; $features['cloud_storage'] = 'no'; $features['user_badge'] = 'no'; } return $features; } /** * Update Global Fluent Community Option * @param string $key The option name * @param mixed $value the value of the option * @return \FluentCommunity\App\Models\Meta */ public static function updateOption($key, $value) { $exist = \FluentCommunity\App\Models\Meta::where('object_type', 'option') ->where('meta_key', $key) ->first(); if ($exist) { $exist->value = $value; $exist->save(); } else { $exist = \FluentCommunity\App\Models\Meta::create([ 'meta_key' => $key, 'object_type' => 'option', 'value' => $value ]); } self::setCache('option_' . $key, $value); return $exist; } /** * @param $key * @param $callback * @param $expire * @return false|mixed * @internal Internal Function */ public static function getFromCache($key, $callback = false, $expire = 3600) { $key = 'focm_' . $key; $value = wp_cache_get($key, 'fluent_community'); if ($value !== false) { return $value; } if ($callback) { $value = $callback(); if ($value) { wp_cache_set($key, $value, 'fluent_community', $expire); } } return $value; } /** * @param $key * @param $value * @param $expire * @return bool * @internal Internal Function */ public static function setCache($key, $value, $expire = 600) { $key = 'focm_' . $key; return wp_cache_set($key, $value, 'fluent_community', $expire); } /** * @param $key * @return bool * @internal Internal Function */ public static function forgetCache($key) { $key = 'focm_' . $key; return wp_cache_delete($key, 'fluent_community'); } public static function getCustomizationSettings() { static $settings; if ($settings) { return $settings; } $defaults = [ 'dark_mode' => 'yes', 'fixed_page_header' => 'yes', 'show_powered_by' => 'yes', 'feed_link_on_sidebar' => 'yes', 'fixed_sidebar' => 'no', 'icon_on_header_menu' => 'no', 'affiliate_id' => '', 'rich_post_layout' => 'classic', 'post_title_pref' => 'optional', 'a11y_enhancement_style' => 'no', ]; $settings = self::getOption('customization_settings', $defaults); $settings = wp_parse_args($settings, $defaults); if (!defined('FLUENT_COMMUNITY_PRO')) { $settings['show_powered_by'] = 'yes'; $settings['affiliate_id'] = ''; $settings['rich_post_layout'] = 'classic'; } return $settings; } public static function getCustomizationSetting($key) { $settings = self::getCustomizationSettings(); return Arr::get($settings, $key); } public static function updateCustomizationSettings($settings) { $preSettings = self::getCustomizationSettings(); $settings = Arr::only($settings, array_keys($preSettings)); self::updateOption('customization_settings', $settings); return $settings; } public static function getPrivacySettings() { static $settings; if ($settings) { return $settings; } $settings = self::getFromCache('privacy_settings', function () { $defaults = [ 'members_page_status' => 'everybody', // everybody, logged_in, admin_only 'can_customize_username' => 'no', 'show_last_activity' => 'yes', 'user_space_visibility' => 'everybody', // everybody, logged_in, admin_only ]; $settings = self::getOption('privacy_settings', $defaults); $settings = wp_parse_args($settings, $defaults); if (!defined('FLUENT_COMMUNITY_PRO')) { $settings['can_customize_username'] = 'no'; } return $settings; }); return $settings; } public static function canViewMembersPage() { $pageStatus = self::getPrivacySetting('members_page_status'); if ($pageStatus == 'everybody') { return apply_filters('fluent_community/can_view_members_page', true, $pageStatus); } if ($pageStatus == 'logged_in') { return apply_filters('fluent_community/can_view_members_page', is_user_logged_in(), $pageStatus); } return apply_filters('fluent_community/can_view_members_page', Helper::isModerator(), $pageStatus); } public static function getPrivacySetting($key) { $settings = self::getPrivacySettings(); return Arr::get($settings, $key); } public static function updatePrivacySettings($settings) { $preSettings = self::getPrivacySettings(); $settings = Arr::only($settings, array_keys($preSettings)); self::updateOption('privacy_settings', $settings); self::forgetCache('privacy_settings'); return $settings; } public static function isCustomizationEnabled($key, $matchingValue = 'yes') { $settings = self::getCustomizationSettings(); return isset($settings[$key]) && $settings[$key] === $matchingValue; } public static function getProductUrl($isPowered = false) { $url = 'https://fluentcommunity.co/'; if ($isPowered) { $params = [ 'utm_source' => 'power_footer', 'utm_medium' => 'site', 'utm_campaign' => 'powered_by' ]; $settings = self::getCustomizationSettings(); $affId = Arr::get($settings, 'affiliate_id'); if ($affId) { $params['ref'] = $affId; } $url = add_query_arg($params, $url); } return add_query_arg([ 'utm_source' => 'plugin', 'utm_medium' => 'site', 'utm_campaign' => 'pligin_ui' ], $url); } /** * Get the email notification settings. * * @return array The email notification settings. */ public static function getEmailNotificationSettings() { static $settings; if ($settings) { return $settings; } $default = [ 'com_my_post_mail' => 'yes', 'reply_my_com_mail' => 'yes', 'mention_mail' => 'yes', 'digest_email_status' => 'no', 'digest_mail_day' => 'tue', 'daily_digest_time' => '09:00', 'send_from_email' => '', 'send_from_name' => '', 'reply_to_email' => '', 'reply_to_name' => '', 'email_footer' => 'You are getting this email because you are a member of {{site_name_with_url}}.'.PHP_EOL.PHP_EOL.'{{manage_email_notification_url|Manage Your Email Notifications Preference}}.', 'disable_powered_by' => 'no', ]; $settings = array_filter(self::getOption('global_email_settings', $default)); $settings = wp_parse_args($settings, $default); if (!defined('FLUENT_COMMUNITY_PRO')) { $settings['disable_powered_by'] = 'no'; } if (empty($settings['email_footer_rendered']) && !empty($settings['email_footer'])) { $settings['email_footer_rendered'] = FeedsHelper::mdToHtml($settings['email_footer']); } return $settings; } public static function postTitlePref() { $pref = self::getCustomizationSetting('post_title_pref'); if ($pref == 'disabled') { $pref = ''; } return apply_filters('fluent_community/has_post_title', $pref); } public static function getSpaces($byGroups = false) { if ($byGroups) { return SpaceGroup::orderBy('serial', 'ASC')->with('spaces', function ($q) { $q->orderBy('serial', 'ASC') ->where('type', 'community'); })->all(); } return Space::where('type', 'community')->orderBy('serial', 'ASC')->get(); } public static function getCourses($byGroups = false) { if ($byGroups) { return SpaceGroup::orderBy('serial', 'ASC')->with('spaces', function ($q) { $q->orderBy('serial', 'ASC') ->where('type', 'course'); })->all(); } return Course::orderBy('serial', 'ASC')->get(); } public static function getTopics() { static $topics; if ($topics) { return $topics; } $key = 'fluent_community_post_topics'; $topics = self::getFromCache($key, function () { $topics = Term::where('taxonomy_name', 'post_topic')->orderBy('title', 'ASC')->get(); /* * object_id = term_id * meta_key = space_id */ $topicSpaceRelations = Meta::select(['id', 'object_id', 'meta_key'])->where('object_type', 'term_space_relation') ->get(); $relations = []; foreach ($topicSpaceRelations as $relation) { if (!isset($relations[$relation->object_id])) { $relations[$relation->object_id] = []; } $relations[$relation->object_id][] = $relation->meta_key; } $formattedTopics = []; foreach ($topics as $topic) { $formattedTopics[] = [ 'id' => $topic->id, 'title' => $topic->title, 'description' => $topic->description, 'slug' => $topic->slug, 'admin_only' => Arr::get($topic->settings, 'admin_only', 'no'), 'space_ids' => isset($relations[$topic->id]) ? $relations[$topic->id] : [] ]; } return $formattedTopics; }, MONTH_IN_SECONDS); return $topics; } public static function getTopicsBySpaceId($spaceId) { $topics = self::getTopics(); $topics = array_filter($topics, function ($topic) use ($spaceId) { return in_array($spaceId, $topic['space_ids']); }); return $topics; } public static function getMaxRunTime() { if (function_exists('ini_get')) { $maxRunTime = (int)ini_get('max_execution_time'); if ($maxRunTime === 0) { $maxRunTime = 60; } } else { $maxRunTime = 30; } if ($maxRunTime > 58) { $maxRunTime = 58; } $maxRunTime = $maxRunTime - 3; return apply_filters('fluent_communutt/max_execution_time', $maxRunTime); } }