PageRenderTime 26ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/newscoop/admin-files/system_pref/do_edit.php

https://github.com/strogo/Newscoop
PHP | 247 lines | 187 code | 32 blank | 28 comment | 46 complexity | e950d23d90480bdfe2acbacf8beacbd8 MD5 | raw file
  1. <?php
  2. camp_load_translation_strings("system_pref");
  3. require_once($GLOBALS['g_campsiteDir']."/classes/SystemPref.php");
  4. require_once($GLOBALS['g_campsiteDir'].'/classes/Input.php');
  5. require_once($GLOBALS['g_campsiteDir'].'/classes/Log.php');
  6. if (!SecurityToken::isValid()) {
  7. camp_html_display_error(getGS('Invalid security token!'));
  8. exit;
  9. }
  10. // Check permissions
  11. if (!$g_user->hasPermission('ChangeSystemPreferences')) {
  12. camp_html_display_error(getGS("You do not have the right to change system preferences."));
  13. exit;
  14. }
  15. $f_campsite_online = Input::Get('f_campsite_online');
  16. $f_site_title = strip_tags(Input::Get('f_site_title'));
  17. $f_site_metakeywords = strip_tags(Input::Get('f_site_metakeywords'));
  18. $f_site_metadescription = strip_tags(Input::Get('f_site_metadescription'));
  19. $f_time_zone = Input::Get('f_time_zone');
  20. $f_cache_engine = Input::Get('f_cache_engine');
  21. $f_template_cache_handler = Input::Get('f_template_cache_handler');
  22. $f_secret_key = strip_tags(Input::Get('f_secret_key'));
  23. $f_session_lifetime = Input::Get('f_session_lifetime', 'int');
  24. $f_imagecache_lifetime = Input::Get('f_imagecache_lifetime', 'int');
  25. $f_keyword_separator = strip_tags(Input::Get('f_keyword_separator'));
  26. $f_login_num = Input::Get('f_login_num', 'int');
  27. $f_max_upload_filesize = strip_tags(Input::Get('f_max_upload_filesize'));
  28. $f_smtp_host = strip_tags(Input::Get('f_smtp_host'));
  29. $f_smtp_port = Input::Get('f_smtp_port', 'int');
  30. $f_editor_image_ratio = Input::Get('f_editor_image_ratio', 'int', null, true);
  31. $f_editor_image_width = Input::Get('f_editor_image_width', 'int', null, true);
  32. $f_editor_image_height = Input::Get('f_editor_image_height', 'int', null, true);
  33. $f_editor_image_zoom = Input::Get('f_editor_image_zoom');
  34. $f_use_replication = Input::Get('f_use_replication');
  35. $f_db_repl_host = strip_tags(Input::Get('f_db_repl_host'));
  36. $f_db_repl_user = strip_tags(Input::Get('f_db_repl_user'));
  37. $f_db_repl_pass = strip_tags(Input::Get('f_db_repl_pass'));
  38. $f_db_repl_port = Input::Get('f_db_repl_port', 'int');
  39. $f_use_campcaster = Input::Get('f_use_campcaster');
  40. $f_cc_hostname = strip_tags(Input::Get('f_cc_hostname'));
  41. $f_cc_hostport = Input::Get('f_cc_hostport', 'int');
  42. $f_cc_xrpcpath = strip_tags(Input::Get('f_cc_xrpcpath'));
  43. $f_cc_xrpcfile = strip_tags(Input::Get('f_cc_xrpcfile'));
  44. $f_external_subs_management = Input::Get('f_external_subs_management');
  45. $f_password_recovery = Input::Get('f_password_recovery');
  46. if ($f_external_subs_management != 'Y' && $f_external_subs_management != 'N') {
  47. $f_external_subs_management = SystemPref::Get('ExternalSubscriptionManagement');
  48. }
  49. $f_template_filter = Input::Get('f_template_filter', '', 'string', true);
  50. $f_external_cron_management = Input::Get('f_external_cron_management');
  51. if ($f_external_cron_management != 'Y' && $f_external_cron_management != 'N') {
  52. $f_external_cron_management = SystemPref::Get('ExternalCronManagement');
  53. }
  54. if ($f_external_cron_management == 'N'
  55. && !is_readable(CS_INSTALL_DIR.DIR_SEP.'cron_jobs'.DIR_SEP.'all_at_once')) {
  56. $f_external_cron_management = 'Y';
  57. }
  58. // geolocation
  59. $f_geo = array(
  60. 'map_center_latitude_default' => Input::Get('f_map_center_latitude_default', 'float'),
  61. 'map_center_longitude_default' => Input::Get('f_map_center_longitude_default', 'float'),
  62. 'map_display_resolution_default' => Input::Get('f_map_display_resolution_default', 'int'),
  63. 'map_view_width_default' => Input::Get('f_map_view_width_default', 'int', 600, true),
  64. 'map_view_height_default' => Input::Get('f_map_view_height_default', 'int', 400, true),
  65. 'map_provider_available_google_v3' => Input::Get('f_map_provider_available_google_v3', 'int', 0, true),
  66. 'map_provider_available_map_quest' => Input::Get('f_map_provider_available_map_quest', 'int', 0, true),
  67. 'map_provider_available_oSM' => Input::Get('f_map_provider_available_oSM', 'int', 0, true),
  68. 'map_provider_default' => Input::Get('f_map_provider_default', 'string'),
  69. 'map_marker_directory' => Input::Get('f_map_marker_directory', 'string'),
  70. 'map_marker_source_default' => Input::Get('f_map_marker_source_default', 'string'),
  71. 'map_popup_width_min' => Input::Get('f_map_popup_width_min', 'int'),
  72. 'map_popup_height_min' => Input::Get('f_map_popup_height_min', 'int'),
  73. 'map_video_width_you_tube' => Input::Get('f_map_video_width_you_tube', 'int'),
  74. 'map_video_height_you_tube' => Input::Get('f_map_video_height_you_tube', 'int'),
  75. 'map_video_width_vimeo' => Input::Get('f_map_video_width_vimeo', 'int'),
  76. 'map_video_height_vimeo' => Input::Get('f_map_video_height_vimeo', 'int'),
  77. 'map_video_width_flash' => Input::Get('f_map_video_width_flash', 'int'),
  78. 'map_video_height_flash' => Input::Get('f_map_video_height_flash', 'int'),
  79. 'flash_server' => Input::Get('f_flash_server', 'string'),
  80. 'flash_directory' => Input::Get('f_flash_directory', 'string'),
  81. );
  82. if (!Input::IsValid()) {
  83. camp_html_display_error(getGS('Invalid input: $1', Input::GetErrorString()), $_SERVER['REQUEST_URI']);
  84. exit;
  85. }
  86. $msg_ok = 1;
  87. // Site On-line
  88. SystemPref::Set('SiteOnline', $f_campsite_online);
  89. // Allow Password Recovery
  90. SystemPref::Set('PasswordRecovery', $f_password_recovery);
  91. // Site title
  92. SystemPref::Set('SiteTitle', $f_site_title);
  93. // Site Meta Keywords
  94. SystemPref::Set('SiteMetaKeywords', $f_site_metakeywords);
  95. // Site Meta Description
  96. SystemPref::Set('SiteMetaDescription', $f_site_metadescription);
  97. // Site Time Zone
  98. SystemPref::Set('TimeZone', $f_time_zone);
  99. // DB Caching
  100. if (SystemPref::Get('DBCacheEngine') != $f_cache_engine) {
  101. if (!$f_cache_engine || CampCache::IsSupported($f_cache_engine)) {
  102. SystemPref::Set('DBCacheEngine', $f_cache_engine);
  103. CampCache::singleton()->clear('user');
  104. CampCache::singleton()->clear();
  105. } else {
  106. $msg_ok = 0;
  107. camp_html_add_msg(getGS('Invalid: You need PHP $1 enabled in order to use the caching system.', $f_cache_engine));
  108. }
  109. }
  110. // Template Caching
  111. if (SystemPref::Get('TemplateCacheHandler') != $f_template_cache_handler && $f_template_cache_handler) {
  112. $handler = CampTemplateCache::factory($f_template_cache_handler);
  113. if ($handler && CampTemplateCache::factory($f_template_cache_handler)->isSupported()) {
  114. SystemPref::Set('TemplateCacheHandler', $f_template_cache_handler);
  115. CampTemplateCache::factory($f_template_cache_handler)->clean();
  116. } else {
  117. $msg_ok = 0;
  118. camp_html_add_msg(getGS('Invalid: You need PHP $1 enabled in order to use the template caching system.'
  119. , $f_template_cache_handler));
  120. }
  121. } else {
  122. SystemPref::Set('TemplateCacheHandler', $f_template_cache_handler);
  123. }
  124. // Image cache lifetime
  125. SystemPref::Set('ImagecacheLifetime', $f_imagecache_lifetime);
  126. // Secret key
  127. SystemPref::Set('SiteSecretKey', $f_secret_key);
  128. // Session life time
  129. SystemPref::Set('SiteSessionLifeTime', $f_session_lifetime);
  130. // Keyword Separator
  131. SystemPref::Set("KeywordSeparator", $f_keyword_separator);
  132. // Number of failed login attempts
  133. if ($f_login_num >= 0) {
  134. SystemPref::Set("LoginFailedAttemptsNum", $f_login_num);
  135. }
  136. // Max Upload File Size
  137. $max_upload_filesize_bytes = camp_convert_bytes($f_max_upload_filesize);
  138. if ($max_upload_filesize_bytes > 0 &&
  139. $max_upload_filesize_bytes <= min(camp_convert_bytes(ini_get('post_max_size')), camp_convert_bytes(ini_get('upload_max_filesize')))) {
  140. SystemPref::Set("MaxUploadFileSize", $f_max_upload_filesize);
  141. } else {
  142. $msg_ok = 0;
  143. camp_html_add_msg(getGS('Invalid Max Upload File Size value submitted'));
  144. }
  145. // SMTP Host/Port
  146. if (empty($f_smtp_host)) {
  147. $f_smtp_host = 'localhost';
  148. }
  149. SystemPref::Set('SMTPHost', $f_smtp_host);
  150. if ($f_smtp_port <= 0) {
  151. $f_smtp_port = 25;
  152. }
  153. SystemPref::Set('SMTPPort', $f_smtp_port);
  154. // Image resizing for WYSIWYG editor
  155. if ($f_editor_image_ratio < 1 || $f_editor_image_ratio > 100) {
  156. $f_editor_image_ratio = 100;
  157. }
  158. SystemPref::Set('EditorImageRatio', $f_editor_image_ratio);
  159. SystemPref::Set('EditorImageResizeWidth', $f_editor_image_width);
  160. SystemPref::Set('EditorImageResizeHeight', $f_editor_image_height);
  161. SystemPref::Set('EditorImageZoom', $f_editor_image_zoom);
  162. // External subscription management
  163. SystemPref::Set('ExternalSubscriptionManagement', $f_external_subs_management);
  164. // Replication
  165. if ($f_use_replication == 'Y') {
  166. // Database Replication Host, User and Password
  167. if (!empty($f_db_repl_host) && !empty($f_db_repl_user)) {
  168. SystemPref::Set("DBReplicationHost", $f_db_repl_host);
  169. SystemPref::Set("DBReplicationUser", $f_db_repl_user);
  170. SystemPref::Set("DBReplicationPass", $f_db_repl_pass);
  171. SystemPref::Set("UseDBReplication", $f_use_replication);
  172. } else {
  173. $msg_ok = 0;
  174. camp_html_add_msg(getGS("Database Replication data incomplete"));
  175. }
  176. // Database Replication Port
  177. if (empty($f_db_repl_port) || !is_int($f_db_repl_port)) {
  178. $f_db_repl_port = 3306;
  179. }
  180. SystemPref::Set("DBReplicationPort", $f_db_repl_port);
  181. } else {
  182. SystemPref::Set("UseDBReplication", 'N');
  183. }
  184. // Campcaster integrity
  185. if ($f_use_campcaster == 'Y') {
  186. // Campcaster Server
  187. SystemPref::Set("CampcasterHostName", $f_cc_hostname);
  188. SystemPref::Set("CampcasterHostPort", $f_cc_hostport);
  189. SystemPref::Set("CampcasterXRPCPath", $f_cc_xrpcpath);
  190. SystemPref::Set("CampcasterXRPCFile", $f_cc_xrpcfile);
  191. SystemPref::Set("UseCampcasterAudioclips", $f_use_campcaster);
  192. } else {
  193. SystemPref::Set("UseCampcasterAudioclips", 'N');
  194. }
  195. // template filter
  196. SystemPref::Set("TemplateFilter", $f_template_filter);
  197. // External cron management
  198. SystemPref::Set('ExternalCronManagement', $f_external_cron_management);
  199. // geolocation
  200. foreach ($f_geo as $key => $value) {
  201. $name = '';
  202. foreach (explode('_', $key) as $part) {
  203. $name .= ucfirst($part);
  204. }
  205. SystemPref::Set($name, $value);
  206. }
  207. $logtext = getGS('System preferences updated');
  208. Log::Message($logtext, $g_user->getUserId(), 171);
  209. // Success message if everything was ok
  210. if ($msg_ok == 1) {
  211. camp_html_add_msg(getGS("System preferences updated."), "ok");
  212. }
  213. CampPlugin::PluginAdminHooks(__FILE__);
  214. camp_html_goto_page("/$ADMIN/system_pref/");
  215. ?>