system.admin.inc 113 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228
  1. <?php
  2. /**
  3. * @file
  4. * Admin page callbacks for the system module.
  5. */
  6. /**
  7. * Menu callback; Provide the administration overview page.
  8. */
  9. function system_admin_config_page() {
  10. // Check for status report errors.
  11. if (system_status(TRUE) && user_access('administer site configuration')) {
  12. drupal_set_message(t('One or more problems were detected with your Drupal installation. Check the <a href="@status">status report</a> for more information.', array('@status' => url('admin/reports/status'))), 'error');
  13. }
  14. $blocks = array();
  15. if ($admin = db_query("SELECT menu_name, mlid FROM {menu_links} WHERE link_path = 'admin/config' AND module = 'system'")->fetchAssoc()) {
  16. $result = db_query("
  17. SELECT m.*, ml.*
  18. FROM {menu_links} ml
  19. INNER JOIN {menu_router} m ON ml.router_path = m.path
  20. WHERE ml.link_path <> 'admin/help' AND menu_name = :menu_name AND ml.plid = :mlid AND hidden = 0", $admin, array('fetch' => PDO::FETCH_ASSOC));
  21. foreach ($result as $item) {
  22. _menu_link_translate($item);
  23. if (!$item['access']) {
  24. continue;
  25. }
  26. // The link description, either derived from 'description' in hook_menu()
  27. // or customized via menu module is used as title attribute.
  28. if (!empty($item['localized_options']['attributes']['title'])) {
  29. $item['description'] = $item['localized_options']['attributes']['title'];
  30. unset($item['localized_options']['attributes']['title']);
  31. }
  32. $block = $item;
  33. $block['content'] = '';
  34. $block['content'] .= theme('admin_block_content', array('content' => system_admin_menu_block($item)));
  35. if (!empty($block['content'])) {
  36. $block['show'] = TRUE;
  37. }
  38. // Prepare for sorting as in function _menu_tree_check_access().
  39. // The weight is offset so it is always positive, with a uniform 5-digits.
  40. $blocks[(50000 + $item['weight']) . ' ' . $item['title'] . ' ' . $item['mlid']] = $block;
  41. }
  42. }
  43. if ($blocks) {
  44. ksort($blocks);
  45. return theme('admin_page', array('blocks' => $blocks));
  46. }
  47. else {
  48. return t('You do not have any administrative items.');
  49. }
  50. }
  51. /**
  52. * Provide a single block from the administration menu as a page.
  53. *
  54. * This function is often a destination for these blocks.
  55. * For example, 'admin/structure/types' needs to have a destination to be valid
  56. * in the Drupal menu system, but too much information there might be
  57. * hidden, so we supply the contents of the block.
  58. *
  59. * @return
  60. * The output HTML.
  61. */
  62. function system_admin_menu_block_page() {
  63. $item = menu_get_item();
  64. if ($content = system_admin_menu_block($item)) {
  65. $output = theme('admin_block_content', array('content' => $content));
  66. }
  67. else {
  68. $output = t('You do not have any administrative items.');
  69. }
  70. return $output;
  71. }
  72. /**
  73. * Menu callback; prints a listing of admin tasks, organized by module.
  74. */
  75. function system_admin_index() {
  76. $module_info = system_get_info('module');
  77. foreach ($module_info as $module => $info) {
  78. $module_info[$module] = new stdClass();
  79. $module_info[$module]->info = $info;
  80. }
  81. uasort($module_info, 'system_sort_modules_by_info_name');
  82. $menu_items = array();
  83. foreach ($module_info as $module => $info) {
  84. // Only display a section if there are any available tasks.
  85. if ($admin_tasks = system_get_module_admin_tasks($module, $info->info)) {
  86. // Sort links by title.
  87. uasort($admin_tasks, 'drupal_sort_title');
  88. // Move 'Configure permissions' links to the bottom of each section.
  89. $permission_key = "admin/people/permissions#module-$module";
  90. if (isset($admin_tasks[$permission_key])) {
  91. $permission_task = $admin_tasks[$permission_key];
  92. unset($admin_tasks[$permission_key]);
  93. $admin_tasks[$permission_key] = $permission_task;
  94. }
  95. $menu_items[$info->info['name']] = array($info->info['description'], $admin_tasks);
  96. }
  97. }
  98. return theme('system_admin_index', array('menu_items' => $menu_items));
  99. }
  100. /**
  101. * Displays the configuration overview page.
  102. *
  103. * This menu callback implementation is a legacy function that used to display
  104. * the configuration overview page at admin/config. It is currently unused and
  105. * will be removed in Drupal 8. The page at admin/config is now generated by
  106. * system_admin_config_page().
  107. *
  108. * @deprecated
  109. * @see system_admin_config_page()
  110. */
  111. function system_settings_overview() {
  112. // Check database setup if necessary
  113. if (function_exists('db_check_setup') && empty($_POST)) {
  114. db_check_setup();
  115. }
  116. $item = menu_get_item('admin/config');
  117. $content = system_admin_menu_block($item);
  118. $output = theme('admin_block_content', array('content' => $content));
  119. return $output;
  120. }
  121. /**
  122. * Menu callback; displays a listing of all themes.
  123. */
  124. function system_themes_page() {
  125. // Get current list of themes.
  126. $themes = system_rebuild_theme_data();
  127. uasort($themes, 'system_sort_modules_by_info_name');
  128. $theme_default = variable_get('theme_default', 'bartik');
  129. $theme_groups = array();
  130. foreach ($themes as &$theme) {
  131. if (!empty($theme->info['hidden'])) {
  132. continue;
  133. }
  134. $admin_theme_options[$theme->name] = $theme->info['name'];
  135. $theme->is_default = ($theme->name == $theme_default);
  136. // Identify theme screenshot.
  137. $theme->screenshot = NULL;
  138. // Create a list which includes the current theme and all its base themes.
  139. if (isset($themes[$theme->name]->base_themes)) {
  140. $theme_keys = array_keys($themes[$theme->name]->base_themes);
  141. $theme_keys[] = $theme->name;
  142. }
  143. else {
  144. $theme_keys = array($theme->name);
  145. }
  146. // Look for a screenshot in the current theme or in its closest ancestor.
  147. foreach (array_reverse($theme_keys) as $theme_key) {
  148. if (isset($themes[$theme_key]) && file_exists($themes[$theme_key]->info['screenshot'])) {
  149. $theme->screenshot = array(
  150. 'path' => $themes[$theme_key]->info['screenshot'],
  151. 'alt' => t('Screenshot for !theme theme', array('!theme' => $theme->info['name'])),
  152. 'title' => t('Screenshot for !theme theme', array('!theme' => $theme->info['name'])),
  153. 'attributes' => array('class' => array('screenshot')),
  154. );
  155. break;
  156. }
  157. }
  158. if (empty($theme->status)) {
  159. // Ensure this theme is compatible with this version of core.
  160. // Require the 'content' region to make sure the main page
  161. // content has a common place in all themes.
  162. $theme->incompatible_core = !isset($theme->info['core']) || ($theme->info['core'] != DRUPAL_CORE_COMPATIBILITY) || (!isset($theme->info['regions']['content']));
  163. $theme->incompatible_php = version_compare(phpversion(), $theme->info['php']) < 0;
  164. }
  165. $query['token'] = drupal_get_token('system-theme-operation-link');
  166. $theme->operations = array();
  167. if (!empty($theme->status) || !$theme->incompatible_core && !$theme->incompatible_php) {
  168. // Create the operations links.
  169. $query['theme'] = $theme->name;
  170. if (drupal_theme_access($theme)) {
  171. $theme->operations[] = array(
  172. 'title' => t('Settings'),
  173. 'href' => 'admin/appearance/settings/' . $theme->name,
  174. 'attributes' => array('title' => t('Settings for !theme theme', array('!theme' => $theme->info['name']))),
  175. );
  176. }
  177. if (!empty($theme->status)) {
  178. if (!$theme->is_default) {
  179. $theme->operations[] = array(
  180. 'title' => t('Disable'),
  181. 'href' => 'admin/appearance/disable',
  182. 'query' => $query,
  183. 'attributes' => array('title' => t('Disable !theme theme', array('!theme' => $theme->info['name']))),
  184. );
  185. $theme->operations[] = array(
  186. 'title' => t('Set default'),
  187. 'href' => 'admin/appearance/default',
  188. 'query' => $query,
  189. 'attributes' => array('title' => t('Set !theme as default theme', array('!theme' => $theme->info['name']))),
  190. );
  191. }
  192. }
  193. else {
  194. $theme->operations[] = array(
  195. 'title' => t('Enable'),
  196. 'href' => 'admin/appearance/enable',
  197. 'query' => $query,
  198. 'attributes' => array('title' => t('Enable !theme theme', array('!theme' => $theme->info['name']))),
  199. );
  200. $theme->operations[] = array(
  201. 'title' => t('Enable and set default'),
  202. 'href' => 'admin/appearance/default',
  203. 'query' => $query,
  204. 'attributes' => array('title' => t('Enable !theme as default theme', array('!theme' => $theme->info['name']))),
  205. );
  206. }
  207. }
  208. // Add notes to default and administration theme.
  209. $theme->notes = array();
  210. $theme->classes = array();
  211. if ($theme->is_default) {
  212. $theme->classes[] = 'theme-default';
  213. $theme->notes[] = t('default theme');
  214. }
  215. // Sort enabled and disabled themes into their own groups.
  216. $theme_groups[$theme->status ? 'enabled' : 'disabled'][] = $theme;
  217. }
  218. // There are two possible theme groups.
  219. $theme_group_titles = array(
  220. 'enabled' => format_plural(count($theme_groups['enabled']), 'Enabled theme', 'Enabled themes'),
  221. );
  222. if (!empty($theme_groups['disabled'])) {
  223. $theme_group_titles['disabled'] = format_plural(count($theme_groups['disabled']), 'Disabled theme', 'Disabled themes');
  224. }
  225. uasort($theme_groups['enabled'], 'system_sort_themes');
  226. drupal_alter('system_themes_page', $theme_groups);
  227. $admin_form = drupal_get_form('system_themes_admin_form', $admin_theme_options);
  228. return theme('system_themes_page', array('theme_groups' => $theme_groups, 'theme_group_titles' => $theme_group_titles)) . drupal_render($admin_form);
  229. }
  230. /**
  231. * Form to select the administration theme.
  232. *
  233. * @ingroup forms
  234. * @see system_themes_admin_form_submit()
  235. */
  236. function system_themes_admin_form($form, &$form_state, $theme_options) {
  237. // Administration theme settings.
  238. $form['admin_theme'] = array(
  239. '#type' => 'fieldset',
  240. '#title' => t('Administration theme'),
  241. );
  242. $form['admin_theme']['admin_theme'] = array(
  243. '#type' => 'select',
  244. '#options' => array(0 => t('Default theme')) + $theme_options,
  245. '#title' => t('Administration theme'),
  246. '#description' => t('Choose "Default theme" to always use the same theme as the rest of the site.'),
  247. '#default_value' => variable_get('admin_theme', 0),
  248. );
  249. $form['admin_theme']['node_admin_theme'] = array(
  250. '#type' => 'checkbox',
  251. '#title' => t('Use the administration theme when editing or creating content'),
  252. '#default_value' => variable_get('node_admin_theme', '0'),
  253. );
  254. $form['admin_theme']['actions'] = array('#type' => 'actions');
  255. $form['admin_theme']['actions']['submit'] = array(
  256. '#type' => 'submit',
  257. '#value' => t('Save configuration'),
  258. );
  259. return $form;
  260. }
  261. /**
  262. * Process system_themes_admin_form form submissions.
  263. */
  264. function system_themes_admin_form_submit($form, &$form_state) {
  265. drupal_set_message(t('The configuration options have been saved.'));
  266. variable_set('admin_theme', $form_state['values']['admin_theme']);
  267. variable_set('node_admin_theme', $form_state['values']['node_admin_theme']);
  268. }
  269. /**
  270. * Menu callback; Enables a theme.
  271. */
  272. function system_theme_enable() {
  273. if (isset($_REQUEST['theme']) && isset($_REQUEST['token']) && drupal_valid_token($_REQUEST['token'], 'system-theme-operation-link')) {
  274. $theme = $_REQUEST['theme'];
  275. // Get current list of themes.
  276. $themes = list_themes();
  277. // Check if the specified theme is one recognized by the system.
  278. if (!empty($themes[$theme])) {
  279. theme_enable(array($theme));
  280. drupal_set_message(t('The %theme theme has been enabled.', array('%theme' => $themes[$theme]->info['name'])));
  281. }
  282. else {
  283. drupal_set_message(t('The %theme theme was not found.', array('%theme' => $theme)), 'error');
  284. }
  285. drupal_goto('admin/appearance');
  286. }
  287. return MENU_ACCESS_DENIED;
  288. }
  289. /**
  290. * Menu callback; Disables a theme.
  291. */
  292. function system_theme_disable() {
  293. if (isset($_REQUEST['theme']) && isset($_REQUEST['token']) && drupal_valid_token($_REQUEST['token'], 'system-theme-operation-link')) {
  294. $theme = $_REQUEST['theme'];
  295. // Get current list of themes.
  296. $themes = list_themes();
  297. // Check if the specified theme is one recognized by the system.
  298. if (!empty($themes[$theme])) {
  299. if ($theme == variable_get('theme_default', 'bartik')) {
  300. // Don't disable the default theme.
  301. drupal_set_message(t('%theme is the default theme and cannot be disabled.', array('%theme' => $themes[$theme]->info['name'])), 'error');
  302. }
  303. else {
  304. theme_disable(array($theme));
  305. drupal_set_message(t('The %theme theme has been disabled.', array('%theme' => $themes[$theme]->info['name'])));
  306. }
  307. }
  308. else {
  309. drupal_set_message(t('The %theme theme was not found.', array('%theme' => $theme)), 'error');
  310. }
  311. drupal_goto('admin/appearance');
  312. }
  313. return MENU_ACCESS_DENIED;
  314. }
  315. /**
  316. * Menu callback; Set the default theme.
  317. */
  318. function system_theme_default() {
  319. if (isset($_REQUEST['theme']) && isset($_REQUEST['token']) && drupal_valid_token($_REQUEST['token'], 'system-theme-operation-link')) {
  320. $theme = $_REQUEST['theme'];
  321. // Get current list of themes.
  322. $themes = list_themes();
  323. // Check if the specified theme is one recognized by the system.
  324. if (!empty($themes[$theme])) {
  325. // Enable the theme if it is currently disabled.
  326. if (empty($themes[$theme]->status)) {
  327. theme_enable(array($theme));
  328. }
  329. // Set the default theme.
  330. variable_set('theme_default', $theme);
  331. // Rebuild the menu. This duplicates the menu_rebuild() in theme_enable().
  332. // However, modules must know the current default theme in order to use
  333. // this information in hook_menu() or hook_menu_alter() implementations,
  334. // and doing the variable_set() before the theme_enable() could result
  335. // in a race condition where the theme is default but not enabled.
  336. menu_rebuild();
  337. // The status message depends on whether an admin theme is currently in use:
  338. // a value of 0 means the admin theme is set to be the default theme.
  339. $admin_theme = variable_get('admin_theme', 0);
  340. if ($admin_theme != 0 && $admin_theme != $theme) {
  341. drupal_set_message(t('Please note that the administration theme is still set to the %admin_theme theme; consequently, the theme on this page remains unchanged. All non-administrative sections of the site, however, will show the selected %selected_theme theme by default.', array(
  342. '%admin_theme' => $themes[$admin_theme]->info['name'],
  343. '%selected_theme' => $themes[$theme]->info['name'],
  344. )));
  345. }
  346. else {
  347. drupal_set_message(t('%theme is now the default theme.', array('%theme' => $themes[$theme]->info['name'])));
  348. }
  349. }
  350. else {
  351. drupal_set_message(t('The %theme theme was not found.', array('%theme' => $theme)), 'error');
  352. }
  353. drupal_goto('admin/appearance');
  354. }
  355. return MENU_ACCESS_DENIED;
  356. }
  357. /**
  358. * Form builder; display theme configuration for entire site and individual themes.
  359. *
  360. * @param $key
  361. * A theme name.
  362. * @return
  363. * The form structure.
  364. * @ingroup forms
  365. * @see system_theme_settings_submit()
  366. */
  367. function system_theme_settings($form, &$form_state, $key = '') {
  368. // Default settings are defined in theme_get_setting() in includes/theme.inc
  369. if ($key) {
  370. $var = 'theme_' . $key . '_settings';
  371. $themes = list_themes();
  372. $features = $themes[$key]->info['features'];
  373. }
  374. else {
  375. $var = 'theme_settings';
  376. }
  377. $form['var'] = array('#type' => 'hidden', '#value' => $var);
  378. // Toggle settings
  379. $toggles = array(
  380. 'logo' => t('Logo'),
  381. 'name' => t('Site name'),
  382. 'slogan' => t('Site slogan'),
  383. 'node_user_picture' => t('User pictures in posts'),
  384. 'comment_user_picture' => t('User pictures in comments'),
  385. 'comment_user_verification' => t('User verification status in comments'),
  386. 'favicon' => t('Shortcut icon'),
  387. 'main_menu' => t('Main menu'),
  388. 'secondary_menu' => t('Secondary menu'),
  389. );
  390. // Some features are not always available
  391. $disabled = array();
  392. if (!variable_get('user_pictures', 0)) {
  393. $disabled['toggle_node_user_picture'] = TRUE;
  394. $disabled['toggle_comment_user_picture'] = TRUE;
  395. }
  396. if (!module_exists('comment')) {
  397. $disabled['toggle_comment_user_picture'] = TRUE;
  398. $disabled['toggle_comment_user_verification'] = TRUE;
  399. }
  400. $form['theme_settings'] = array(
  401. '#type' => 'fieldset',
  402. '#title' => t('Toggle display'),
  403. '#description' => t('Enable or disable the display of certain page elements.'),
  404. );
  405. foreach ($toggles as $name => $title) {
  406. if ((!$key) || in_array($name, $features)) {
  407. $form['theme_settings']['toggle_' . $name] = array('#type' => 'checkbox', '#title' => $title, '#default_value' => theme_get_setting('toggle_' . $name, $key));
  408. // Disable checkboxes for features not supported in the current configuration.
  409. if (isset($disabled['toggle_' . $name])) {
  410. $form['theme_settings']['toggle_' . $name]['#disabled'] = TRUE;
  411. }
  412. }
  413. }
  414. if (!element_children($form['theme_settings'])) {
  415. // If there is no element in the theme settings fieldset then do not show
  416. // it -- but keep it in the form if another module wants to alter.
  417. $form['theme_settings']['#access'] = FALSE;
  418. }
  419. // Logo settings
  420. if ((!$key) || in_array('logo', $features)) {
  421. $form['logo'] = array(
  422. '#type' => 'fieldset',
  423. '#title' => t('Logo image settings'),
  424. '#description' => t('If toggled on, the following logo will be displayed.'),
  425. '#attributes' => array('class' => array('theme-settings-bottom')),
  426. );
  427. $form['logo']['default_logo'] = array(
  428. '#type' => 'checkbox',
  429. '#title' => t('Use the default logo'),
  430. '#default_value' => theme_get_setting('default_logo', $key),
  431. '#tree' => FALSE,
  432. '#description' => t('Check here if you want the theme to use the logo supplied with it.')
  433. );
  434. $form['logo']['settings'] = array(
  435. '#type' => 'container',
  436. '#states' => array(
  437. // Hide the logo settings when using the default logo.
  438. 'invisible' => array(
  439. 'input[name="default_logo"]' => array('checked' => TRUE),
  440. ),
  441. ),
  442. );
  443. $form['logo']['settings']['logo_path'] = array(
  444. '#type' => 'textfield',
  445. '#title' => t('Path to custom logo'),
  446. '#description' => t('The path to the file you would like to use as your logo file instead of the default logo.'),
  447. '#default_value' => theme_get_setting('logo_path', $key),
  448. );
  449. $form['logo']['settings']['logo_upload'] = array(
  450. '#type' => 'file',
  451. '#title' => t('Upload logo image'),
  452. '#maxlength' => 40,
  453. '#description' => t("If you don't have direct file access to the server, use this field to upload your logo.")
  454. );
  455. }
  456. if ((!$key) || in_array('favicon', $features)) {
  457. $form['favicon'] = array(
  458. '#type' => 'fieldset',
  459. '#title' => t('Shortcut icon settings'),
  460. '#description' => t("Your shortcut icon, or 'favicon', is displayed in the address bar and bookmarks of most browsers."),
  461. );
  462. $form['favicon']['default_favicon'] = array(
  463. '#type' => 'checkbox',
  464. '#title' => t('Use the default shortcut icon.'),
  465. '#default_value' => theme_get_setting('default_favicon', $key),
  466. '#description' => t('Check here if you want the theme to use the default shortcut icon.')
  467. );
  468. $form['favicon']['settings'] = array(
  469. '#type' => 'container',
  470. '#states' => array(
  471. // Hide the favicon settings when using the default favicon.
  472. 'invisible' => array(
  473. 'input[name="default_favicon"]' => array('checked' => TRUE),
  474. ),
  475. ),
  476. );
  477. $form['favicon']['settings']['favicon_path'] = array(
  478. '#type' => 'textfield',
  479. '#title' => t('Path to custom icon'),
  480. '#description' => t('The path to the image file you would like to use as your custom shortcut icon.'),
  481. '#default_value' => theme_get_setting('favicon_path', $key),
  482. );
  483. $form['favicon']['settings']['favicon_upload'] = array(
  484. '#type' => 'file',
  485. '#title' => t('Upload icon image'),
  486. '#description' => t("If you don't have direct file access to the server, use this field to upload your shortcut icon.")
  487. );
  488. }
  489. // Inject human-friendly values for logo and favicon.
  490. foreach (array('logo' => 'logo.png', 'favicon' => 'favicon.ico') as $type => $default) {
  491. if (isset($form[$type]['settings'][$type . '_path'])) {
  492. $element = &$form[$type]['settings'][$type . '_path'];
  493. // If path is a public:// URI, display the path relative to the files
  494. // directory; stream wrappers are not end-user friendly.
  495. $original_path = $element['#default_value'];
  496. $friendly_path = NULL;
  497. if (file_uri_scheme($original_path) == 'public') {
  498. $friendly_path = file_uri_target($original_path);
  499. $element['#default_value'] = $friendly_path;
  500. }
  501. }
  502. }
  503. if ($key) {
  504. // Call engine-specific settings.
  505. $function = $themes[$key]->prefix . '_engine_settings';
  506. if (function_exists($function)) {
  507. $form['engine_specific'] = array(
  508. '#type' => 'fieldset',
  509. '#title' => t('Theme-engine-specific settings'),
  510. '#description' => t('These settings only exist for the themes based on the %engine theme engine.', array('%engine' => $themes[$key]->prefix)),
  511. );
  512. $function($form, $form_state);
  513. }
  514. // Create a list which includes the current theme and all its base themes.
  515. if (isset($themes[$key]->base_themes)) {
  516. $theme_keys = array_keys($themes[$key]->base_themes);
  517. $theme_keys[] = $key;
  518. }
  519. else {
  520. $theme_keys = array($key);
  521. }
  522. // Save the name of the current theme (if any), so that we can temporarily
  523. // override the current theme and allow theme_get_setting() to work
  524. // without having to pass the theme name to it.
  525. $default_theme = !empty($GLOBALS['theme_key']) ? $GLOBALS['theme_key'] : NULL;
  526. $GLOBALS['theme_key'] = $key;
  527. // Process the theme and all its base themes.
  528. foreach ($theme_keys as $theme) {
  529. // Include the theme-settings.php file.
  530. $filename = DRUPAL_ROOT . '/' . str_replace("/$theme.info", '', $themes[$theme]->filename) . '/theme-settings.php';
  531. if (file_exists($filename)) {
  532. require_once $filename;
  533. }
  534. // Call theme-specific settings.
  535. $function = $theme . '_form_system_theme_settings_alter';
  536. if (function_exists($function)) {
  537. $function($form, $form_state);
  538. }
  539. }
  540. // Restore the original current theme.
  541. if (isset($default_theme)) {
  542. $GLOBALS['theme_key'] = $default_theme;
  543. }
  544. else {
  545. unset($GLOBALS['theme_key']);
  546. }
  547. }
  548. $form = system_settings_form($form);
  549. // We don't want to call system_settings_form_submit(), so change #submit.
  550. array_pop($form['#submit']);
  551. $form['#submit'][] = 'system_theme_settings_submit';
  552. $form['#validate'][] = 'system_theme_settings_validate';
  553. return $form;
  554. }
  555. /**
  556. * Validator for the system_theme_settings() form.
  557. */
  558. function system_theme_settings_validate($form, &$form_state) {
  559. // Handle file uploads.
  560. $validators = array('file_validate_is_image' => array());
  561. // Check for a new uploaded logo.
  562. $file = file_save_upload('logo_upload', $validators);
  563. if (isset($file)) {
  564. // File upload was attempted.
  565. if ($file) {
  566. // Put the temporary file in form_values so we can save it on submit.
  567. $form_state['values']['logo_upload'] = $file;
  568. }
  569. else {
  570. // File upload failed.
  571. form_set_error('logo_upload', t('The logo could not be uploaded.'));
  572. }
  573. }
  574. $validators = array('file_validate_extensions' => array('ico png gif jpg jpeg apng svg'));
  575. // Check for a new uploaded favicon.
  576. $file = file_save_upload('favicon_upload', $validators);
  577. if (isset($file)) {
  578. // File upload was attempted.
  579. if ($file) {
  580. // Put the temporary file in form_values so we can save it on submit.
  581. $form_state['values']['favicon_upload'] = $file;
  582. }
  583. else {
  584. // File upload failed.
  585. form_set_error('favicon_upload', t('The favicon could not be uploaded.'));
  586. }
  587. }
  588. // If the user provided a path for a logo or favicon file, make sure a file
  589. // exists at that path.
  590. if (!empty($form_state['values']['logo_path'])) {
  591. $path = _system_theme_settings_validate_path($form_state['values']['logo_path']);
  592. if (!$path) {
  593. form_set_error('logo_path', t('The custom logo path is invalid.'));
  594. }
  595. }
  596. if (!empty($form_state['values']['favicon_path'])) {
  597. $path = _system_theme_settings_validate_path($form_state['values']['favicon_path']);
  598. if (!$path) {
  599. form_set_error('favicon_path', t('The custom favicon path is invalid.'));
  600. }
  601. }
  602. }
  603. /**
  604. * Helper function for the system_theme_settings form.
  605. *
  606. * Attempts to validate normal system paths, paths relative to the public files
  607. * directory, or stream wrapper URIs. If the given path is any of the above,
  608. * returns a valid path or URI that the theme system can display.
  609. *
  610. * @param $path
  611. * A path relative to the Drupal root or to the public files directory, or
  612. * a stream wrapper URI.
  613. * @return mixed
  614. * A valid path that can be displayed through the theme system, or FALSE if
  615. * the path could not be validated.
  616. */
  617. function _system_theme_settings_validate_path($path) {
  618. // Absolute local file paths are invalid.
  619. if (drupal_realpath($path) == $path) {
  620. return FALSE;
  621. }
  622. // A path relative to the Drupal root or a fully qualified URI is valid.
  623. if (is_file($path)) {
  624. return $path;
  625. }
  626. // Prepend 'public://' for relative file paths within public filesystem.
  627. if (file_uri_scheme($path) === FALSE) {
  628. $path = 'public://' . $path;
  629. }
  630. if (is_file($path)) {
  631. return $path;
  632. }
  633. return FALSE;
  634. }
  635. /**
  636. * Process system_theme_settings form submissions.
  637. */
  638. function system_theme_settings_submit($form, &$form_state) {
  639. // Exclude unnecessary elements before saving.
  640. form_state_values_clean($form_state);
  641. $values = $form_state['values'];
  642. // Extract the name of the theme from the submitted form values, then remove
  643. // it from the array so that it is not saved as part of the variable.
  644. $key = $values['var'];
  645. unset($values['var']);
  646. // If the user uploaded a new logo or favicon, save it to a permanent location
  647. // and use it in place of the default theme-provided file.
  648. if (!empty($values['logo_upload'])) {
  649. $file = $values['logo_upload'];
  650. unset($values['logo_upload']);
  651. $filename = file_unmanaged_copy($file->uri);
  652. $values['default_logo'] = 0;
  653. $values['logo_path'] = $filename;
  654. $values['toggle_logo'] = 1;
  655. }
  656. if (!empty($values['favicon_upload'])) {
  657. $file = $values['favicon_upload'];
  658. unset($values['favicon_upload']);
  659. $filename = file_unmanaged_copy($file->uri);
  660. $values['default_favicon'] = 0;
  661. $values['favicon_path'] = $filename;
  662. $values['toggle_favicon'] = 1;
  663. }
  664. // If the user entered a path relative to the system files directory for
  665. // a logo or favicon, store a public:// URI so the theme system can handle it.
  666. if (!empty($values['logo_path'])) {
  667. $values['logo_path'] = _system_theme_settings_validate_path($values['logo_path']);
  668. }
  669. if (!empty($values['favicon_path'])) {
  670. $values['favicon_path'] = _system_theme_settings_validate_path($values['favicon_path']);
  671. }
  672. if (empty($values['default_favicon']) && !empty($values['favicon_path'])) {
  673. $values['favicon_mimetype'] = file_get_mimetype($values['favicon_path']);
  674. }
  675. variable_set($key, $values);
  676. drupal_set_message(t('The configuration options have been saved.'));
  677. cache_clear_all();
  678. }
  679. /**
  680. * Recursively check compatibility.
  681. *
  682. * @param $incompatible
  683. * An associative array which at the end of the check contains all
  684. * incompatible files as the keys, their values being TRUE.
  685. * @param $files
  686. * The set of files that will be tested.
  687. * @param $file
  688. * The file at which the check starts.
  689. * @return
  690. * Returns TRUE if an incompatible file is found, NULL (no return value)
  691. * otherwise.
  692. */
  693. function _system_is_incompatible(&$incompatible, $files, $file) {
  694. if (isset($incompatible[$file->name])) {
  695. return TRUE;
  696. }
  697. // Recursively traverse required modules, looking for incompatible modules.
  698. foreach ($file->requires as $requires) {
  699. if (isset($files[$requires]) && _system_is_incompatible($incompatible, $files, $files[$requires])) {
  700. $incompatible[$file->name] = TRUE;
  701. return TRUE;
  702. }
  703. }
  704. }
  705. /**
  706. * Menu callback; provides module enable/disable interface.
  707. *
  708. * The list of modules gets populated by module.info files, which contain each
  709. * module's name, description, and information about which modules it requires.
  710. * See drupal_parse_info_file() for information on module.info descriptors.
  711. *
  712. * Dependency checking is performed to ensure that a module:
  713. * - can not be enabled if there are disabled modules it requires.
  714. * - can not be disabled if there are enabled modules which depend on it.
  715. *
  716. * @param $form_state
  717. * An associative array containing the current state of the form.
  718. *
  719. * @return
  720. * The form array.
  721. *
  722. * @ingroup forms
  723. * @see theme_system_modules()
  724. * @see system_modules_submit()
  725. */
  726. function system_modules($form, $form_state = array()) {
  727. // Get current list of modules.
  728. $files = system_rebuild_module_data();
  729. // Remove hidden modules from display list.
  730. $visible_files = $files;
  731. foreach ($visible_files as $filename => $file) {
  732. if (!empty($file->info['hidden'])) {
  733. unset($visible_files[$filename]);
  734. }
  735. }
  736. uasort($visible_files, 'system_sort_modules_by_info_name');
  737. // If the modules form was submitted, then system_modules_submit() runs first
  738. // and if there are unfilled required modules, then $form_state['storage'] is
  739. // filled, triggering a rebuild. In this case we need to display a
  740. // confirmation form.
  741. if (!empty($form_state['storage'])) {
  742. return system_modules_confirm_form($visible_files, $form_state['storage']);
  743. }
  744. $modules = array();
  745. $form['modules'] = array('#tree' => TRUE);
  746. // Used when checking if module implements a help page.
  747. $help_arg = module_exists('help') ? drupal_help_arg() : FALSE;
  748. // Used when displaying modules that are required by the installation profile.
  749. require_once DRUPAL_ROOT . '/includes/install.inc';
  750. $distribution_name = check_plain(drupal_install_profile_distribution_name());
  751. // Iterate through each of the modules.
  752. foreach ($visible_files as $filename => $module) {
  753. $extra = array();
  754. $extra['enabled'] = (bool) $module->status;
  755. if (!empty($module->info['required'] )) {
  756. $extra['disabled'] = TRUE;
  757. $extra['required_by'][] = $distribution_name . (!empty($module->info['explanation']) ? ' ('. $module->info['explanation'] .')' : '');
  758. }
  759. // If this module requires other modules, add them to the array.
  760. foreach ($module->requires as $requires => $v) {
  761. if (!isset($files[$requires])) {
  762. $extra['requires'][$requires] = t('@module (<span class="admin-missing">missing</span>)', array('@module' => drupal_ucfirst($requires)));
  763. $extra['disabled'] = TRUE;
  764. }
  765. // Only display visible modules.
  766. elseif (isset($visible_files[$requires])) {
  767. $requires_name = $files[$requires]->info['name'];
  768. // Disable this module if it is incompatible with the dependency's version.
  769. if ($incompatible_version = drupal_check_incompatibility($v, str_replace(DRUPAL_CORE_COMPATIBILITY . '-', '', $files[$requires]->info['version']))) {
  770. $extra['requires'][$requires] = t('@module (<span class="admin-missing">incompatible with</span> version @version)', array(
  771. '@module' => $requires_name . $incompatible_version,
  772. '@version' => $files[$requires]->info['version'],
  773. ));
  774. $extra['disabled'] = TRUE;
  775. }
  776. // Disable this module if the dependency is incompatible with this
  777. // version of Drupal core.
  778. elseif ($files[$requires]->info['core'] != DRUPAL_CORE_COMPATIBILITY) {
  779. $extra['requires'][$requires] = t('@module (<span class="admin-missing">incompatible with</span> this version of Drupal core)', array(
  780. '@module' => $requires_name,
  781. ));
  782. $extra['disabled'] = TRUE;
  783. }
  784. elseif ($files[$requires]->status) {
  785. $extra['requires'][$requires] = t('@module (<span class="admin-enabled">enabled</span>)', array('@module' => $requires_name));
  786. }
  787. else {
  788. $extra['requires'][$requires] = t('@module (<span class="admin-disabled">disabled</span>)', array('@module' => $requires_name));
  789. }
  790. }
  791. }
  792. // Generate link for module's help page, if there is one.
  793. if ($help_arg && $module->status && in_array($filename, module_implements('help'))) {
  794. if (module_invoke($filename, 'help', "admin/help#$filename", $help_arg)) {
  795. $extra['links']['help'] = array(
  796. '#type' => 'link',
  797. '#title' => t('Help'),
  798. '#href' => "admin/help/$filename",
  799. '#options' => array('attributes' => array('class' => array('module-link', 'module-link-help'), 'title' => t('Help'))),
  800. );
  801. }
  802. }
  803. // Generate link for module's permission, if the user has access to it.
  804. if ($module->status && user_access('administer permissions') && in_array($filename, module_implements('permission'))) {
  805. $extra['links']['permissions'] = array(
  806. '#type' => 'link',
  807. '#title' => t('Permissions'),
  808. '#href' => 'admin/people/permissions',
  809. '#options' => array('fragment' => 'module-' . $filename, 'attributes' => array('class' => array('module-link', 'module-link-permissions'), 'title' => t('Configure permissions'))),
  810. );
  811. }
  812. // Generate link for module's configuration page, if the module provides
  813. // one.
  814. if ($module->status && isset($module->info['configure'])) {
  815. $configure_link = menu_get_item($module->info['configure']);
  816. if ($configure_link['access']) {
  817. $extra['links']['configure'] = array(
  818. '#type' => 'link',
  819. '#title' => t('Configure'),
  820. '#href' => $configure_link['href'],
  821. '#options' => array('attributes' => array('class' => array('module-link', 'module-link-configure'), 'title' => $configure_link['description'])),
  822. );
  823. }
  824. }
  825. // If this module is required by other modules, list those, and then make it
  826. // impossible to disable this one.
  827. foreach ($module->required_by as $required_by => $v) {
  828. // Hidden modules are unset already.
  829. if (isset($visible_files[$required_by])) {
  830. if ($files[$required_by]->status == 1 && $module->status == 1) {
  831. $extra['required_by'][] = t('@module (<span class="admin-enabled">enabled</span>)', array('@module' => $files[$required_by]->info['name']));
  832. $extra['disabled'] = TRUE;
  833. }
  834. else {
  835. $extra['required_by'][] = t('@module (<span class="admin-disabled">disabled</span>)', array('@module' => $files[$required_by]->info['name']));
  836. }
  837. }
  838. }
  839. $form['modules'][$module->info['package']][$filename] = _system_modules_build_row($module->info, $extra);
  840. }
  841. // Add basic information to the fieldsets.
  842. foreach (element_children($form['modules']) as $package) {
  843. $form['modules'][$package] += array(
  844. '#type' => 'fieldset',
  845. '#title' => t($package),
  846. '#collapsible' => TRUE,
  847. '#theme' => 'system_modules_fieldset',
  848. '#header' => array(
  849. array('data' => t('Enabled'), 'class' => array('checkbox')),
  850. t('Name'),
  851. t('Version'),
  852. t('Description'),
  853. array('data' => t('Operations'), 'colspan' => 3),
  854. ),
  855. // Ensure that the "Core" package fieldset comes first.
  856. '#weight' => $package == 'Core' ? -10 : NULL,
  857. );
  858. }
  859. // Lastly, sort all fieldsets by title.
  860. uasort($form['modules'], 'element_sort_by_title');
  861. $form['actions'] = array('#type' => 'actions');
  862. $form['actions']['submit'] = array(
  863. '#type' => 'submit',
  864. '#value' => t('Save configuration'),
  865. );
  866. $form['#action'] = url('admin/modules/list/confirm');
  867. return $form;
  868. }
  869. /**
  870. * Array sorting callback; sorts modules or themes by their name.
  871. */
  872. function system_sort_modules_by_info_name($a, $b) {
  873. return strcasecmp($a->info['name'], $b->info['name']);
  874. }
  875. /**
  876. * Sorts themes by their names, with the default theme listed first.
  877. *
  878. * Callback for uasort() within system_themes_page().
  879. *
  880. * @see system_sort_modules_by_info_name().
  881. */
  882. function system_sort_themes($a, $b) {
  883. if ($a->is_default) {
  884. return -1;
  885. }
  886. if ($b->is_default) {
  887. return 1;
  888. }
  889. return strcasecmp($a->info['name'], $b->info['name']);
  890. }
  891. /**
  892. * Build a table row for the system modules page.
  893. */
  894. function _system_modules_build_row($info, $extra) {
  895. // Add in the defaults.
  896. $extra += array(
  897. 'requires' => array(),
  898. 'required_by' => array(),
  899. 'disabled' => FALSE,
  900. 'enabled' => FALSE,
  901. 'links' => array(),
  902. );
  903. $form = array(
  904. '#tree' => TRUE,
  905. );
  906. // Set the basic properties.
  907. $form['name'] = array(
  908. '#markup' => $info['name'],
  909. );
  910. $form['description'] = array(
  911. '#markup' => t($info['description']),
  912. );
  913. $form['version'] = array(
  914. '#markup' => $info['version'],
  915. );
  916. $form['#requires'] = $extra['requires'];
  917. $form['#required_by'] = $extra['required_by'];
  918. // Check the compatibilities.
  919. $compatible = TRUE;
  920. $status_short = '';
  921. $status_long = '';
  922. // Initialize empty arrays of long and short reasons explaining why the
  923. // module is incompatible.
  924. // Add each reason as a separate element in both the arrays.
  925. $reasons_short = array();
  926. $reasons_long = array();
  927. // Check the core compatibility.
  928. if (!isset($info['core']) || $info['core'] != DRUPAL_CORE_COMPATIBILITY) {
  929. $compatible = FALSE;
  930. $reasons_short[] = t('Incompatible with this version of Drupal core.');
  931. $reasons_long[] = t('This version is not compatible with Drupal !core_version and should be replaced.', array('!core_version' => DRUPAL_CORE_COMPATIBILITY));
  932. }
  933. // Ensure this module is compatible with the currently installed version of PHP.
  934. if (version_compare(phpversion(), $info['php']) < 0) {
  935. $compatible = FALSE;
  936. $reasons_short[] = t('Incompatible with this version of PHP');
  937. $php_required = $info['php'];
  938. if (substr_count($info['php'], '.') < 2) {
  939. $php_required .= '.*';
  940. }
  941. $reasons_long[] = t('This module requires PHP version @php_required and is incompatible with PHP version !php_version.', array('@php_required' => $php_required, '!php_version' => phpversion()));
  942. }
  943. // If this module is compatible, present a checkbox indicating
  944. // this module may be installed. Otherwise, show a big red X.
  945. if ($compatible) {
  946. $form['enable'] = array(
  947. '#type' => 'checkbox',
  948. '#title' => t('Enable'),
  949. '#default_value' => $extra['enabled'],
  950. );
  951. if ($extra['disabled']) {
  952. $form['enable']['#disabled'] = TRUE;
  953. }
  954. }
  955. else {
  956. $status_short = implode(' ', $reasons_short);
  957. $status_long = implode(' ', $reasons_long);
  958. $form['enable'] = array(
  959. '#markup' => theme('image', array('path' => 'misc/watchdog-error.png', 'alt' => $status_short, 'title' => $status_short)),
  960. );
  961. $form['description']['#markup'] .= theme('system_modules_incompatible', array('message' => $status_long));
  962. }
  963. // Build operation links.
  964. foreach (array('help', 'permissions', 'configure') as $key) {
  965. $form['links'][$key] = (isset($extra['links'][$key]) ? $extra['links'][$key] : array());
  966. }
  967. return $form;
  968. }
  969. /**
  970. * Display confirmation form for required modules.
  971. *
  972. * @param $modules
  973. * Array of module file objects as returned from system_rebuild_module_data().
  974. * @param $storage
  975. * The contents of $form_state['storage']; an array with two
  976. * elements: the list of required modules and the list of status
  977. * form field values from the previous screen.
  978. * @ingroup forms
  979. */
  980. function system_modules_confirm_form($modules, $storage) {
  981. $items = array();
  982. $form['validation_modules'] = array('#type' => 'value', '#value' => $modules);
  983. $form['status']['#tree'] = TRUE;
  984. foreach ($storage['more_required'] as $info) {
  985. $t_argument = array(
  986. '@module' => $info['name'],
  987. '@required' => implode(', ', $info['requires']),
  988. );
  989. $items[] = format_plural(count($info['requires']), 'You must enable the @required module to install @module.', 'You must enable the @required modules to install @module.', $t_argument);
  990. }
  991. foreach ($storage['missing_modules'] as $name => $info) {
  992. $t_argument = array(
  993. '@module' => $name,
  994. '@depends' => implode(', ', $info['depends']),
  995. );
  996. $items[] = format_plural(count($info['depends']), 'The @module module is missing, so the following module will be disabled: @depends.', 'The @module module is missing, so the following modules will be disabled: @depends.', $t_argument);
  997. }
  998. $form['text'] = array('#markup' => theme('item_list', array('items' => $items)));
  999. if ($form) {
  1000. // Set some default form values
  1001. $form = confirm_form(
  1002. $form,
  1003. t('Some required modules must be enabled'),
  1004. 'admin/modules',
  1005. t('Would you like to continue with the above?'),
  1006. t('Continue'),
  1007. t('Cancel'));
  1008. return $form;
  1009. }
  1010. }
  1011. /**
  1012. * Submit callback; handles modules form submission.
  1013. */
  1014. function system_modules_submit($form, &$form_state) {
  1015. include_once DRUPAL_ROOT . '/includes/install.inc';
  1016. // Builds list of modules.
  1017. $modules = array();
  1018. // If we're not coming from the confirmation form, build the list of modules.
  1019. if (empty($form_state['storage'])) {
  1020. // If we're not coming from the confirmation form, build the module list.
  1021. foreach ($form_state['values']['modules'] as $group_name => $group) {
  1022. foreach ($group as $module => $enabled) {
  1023. $modules[$module] = array('group' => $group_name, 'enabled' => $enabled['enable']);
  1024. }
  1025. }
  1026. }
  1027. else {
  1028. // If we are coming from the confirmation form, fetch
  1029. // the modules out of $form_state.
  1030. $modules = $form_state['storage']['modules'];
  1031. }
  1032. // Collect data for all modules to be able to determine dependencies.
  1033. $files = system_rebuild_module_data();
  1034. // Sorts modules by weight.
  1035. $sort = array();
  1036. foreach (array_keys($modules) as $module) {
  1037. $sort[$module] = $files[$module]->sort;
  1038. }
  1039. array_multisort($sort, $modules);
  1040. // Makes sure all required modules are set to be enabled.
  1041. $more_required = array();
  1042. $missing_modules = array();
  1043. foreach ($modules as $name => $module) {
  1044. if ($module['enabled']) {
  1045. // Checks that all dependencies are set to be enabled. Stores the ones
  1046. // that are not in $dependencies variable so that the user can be alerted
  1047. // in the confirmation form that more modules need to be enabled.
  1048. $dependencies = array();
  1049. foreach (array_keys($files[$name]->requires) as $required) {
  1050. if (empty($modules[$required]['enabled'])) {
  1051. if (isset($files[$required])) {
  1052. $dependencies[] = $files[$required]->info['name'];
  1053. $modules[$required]['enabled'] = TRUE;
  1054. }
  1055. else {
  1056. $missing_modules[$required]['depends'][] = $name;
  1057. $modules[$name]['enabled'] = FALSE;
  1058. }
  1059. }
  1060. }
  1061. // Stores additional modules that need to be enabled in $more_required.
  1062. if (!empty($dependencies)) {
  1063. $more_required[$name] = array(
  1064. 'name' => $files[$name]->info['name'],
  1065. 'requires' => $dependencies,
  1066. );
  1067. }
  1068. }
  1069. }
  1070. // Redirects to confirmation form if more modules need to be enabled.
  1071. if ((!empty($more_required) || !empty($missing_modules)) && !isset($form_state['values']['confirm'])) {
  1072. $form_state['storage'] = array(
  1073. 'more_required' => $more_required,
  1074. 'modules' => $modules,
  1075. 'missing_modules' => $missing_modules,
  1076. );
  1077. $form_state['rebuild'] = TRUE;
  1078. return;
  1079. }
  1080. // Invokes hook_requirements('install'). If failures are detected, makes sure
  1081. // the dependent modules aren't installed either.
  1082. foreach ($modules as $name => $module) {
  1083. // Only invoke hook_requirements() on modules that are going to be installed.
  1084. if ($module['enabled'] && drupal_get_installed_schema_version($name) == SCHEMA_UNINSTALLED) {
  1085. if (!drupal_check_module($name)) {
  1086. $modules[$name]['enabled'] = FALSE;
  1087. foreach (array_keys($files[$name]->required_by) as $required_by) {
  1088. $modules[$required_by]['enabled'] = FALSE;
  1089. }
  1090. }
  1091. }
  1092. }
  1093. // Initializes array of actions.
  1094. $actions = array(
  1095. 'enable' => array(),
  1096. 'disable' => array(),
  1097. 'install' => array(),
  1098. );
  1099. // Builds arrays of modules that need to be enabled, disabled, and installed.
  1100. foreach ($modules as $name => $module) {
  1101. if ($module['enabled']) {
  1102. if (drupal_get_installed_schema_version($name) == SCHEMA_UNINSTALLED) {
  1103. $actions['install'][] = $name;
  1104. $actions['enable'][] = $name;
  1105. }
  1106. elseif (!module_exists($name)) {
  1107. $actions['enable'][] = $name;
  1108. }
  1109. }
  1110. elseif (module_exists($name)) {
  1111. $actions['disable'][] = $name;
  1112. }
  1113. }
  1114. // Gets list of modules prior to install process, unsets $form_state['storage']
  1115. // so we don't get redirected back to the confirmation form.
  1116. $pre_install_list = module_list();
  1117. unset($form_state['storage']);
  1118. // Reverse the 'enable' list, to order dependencies before dependents.
  1119. krsort($actions['enable']);
  1120. // Installs, enables, and disables modules.
  1121. module_enable($actions['enable'], FALSE);
  1122. module_disable($actions['disable'], FALSE);
  1123. // Gets module list after install process, flushes caches and displays a
  1124. // message if there are changes.
  1125. $post_install_list = module_list(TRUE);
  1126. if ($pre_install_list != $post_install_list) {
  1127. drupal_flush_all_caches();
  1128. drupal_set_message(t('The configuration options have been saved.'));
  1129. }
  1130. $form_state['redirect'] = 'admin/modules';
  1131. }
  1132. /**
  1133. * Uninstall functions
  1134. */
  1135. /**
  1136. * Builds a form of currently disabled modules.
  1137. *
  1138. * @ingroup forms
  1139. * @see system_modules_uninstall_validate()
  1140. * @see system_modules_uninstall_submit()
  1141. * @param $form_state['values']
  1142. * Submitted form values.
  1143. * @return
  1144. * A form array representing the currently disabled modules.
  1145. */
  1146. function system_modules_uninstall($form, $form_state = NULL) {
  1147. // Make sure the install API is available.
  1148. include_once DRUPAL_ROOT . '/includes/install.inc';
  1149. // Display the confirm form if any modules have been submitted.
  1150. if (!empty($form_state['storage']) && $confirm_form = system_modules_uninstall_confirm_form($form_state['storage'])) {
  1151. return $confirm_form;
  1152. }
  1153. // Get a list of disabled, installed modules.
  1154. $all_modules = system_rebuild_module_data();
  1155. $disabled_modules = array();
  1156. foreach ($all_modules as $name => $module) {
  1157. if (empty($module->status) && $module->schema_version > SCHEMA_UNINSTALLED) {
  1158. $disabled_modules[$name] = $module;
  1159. }
  1160. }
  1161. // Only build the rest of the form if there are any modules available to
  1162. // uninstall.
  1163. if (!empty($disabled_modules)) {
  1164. $profile = drupal_get_profile();
  1165. uasort($disabled_modules, 'system_sort_modules_by_info_name');
  1166. $form['uninstall'] = array('#tree' => TRUE);
  1167. foreach ($disabled_modules as $module) {
  1168. $module_name = $module->info['name'] ? $module->info['name'] : $module->name;
  1169. $form['modules'][$module->name]['#module_name'] = $module_name;
  1170. $form['modules'][$module->name]['name']['#markup'] = $module_name;
  1171. $form['modules'][$module->name]['description']['#markup'] = t($module->info['description']);
  1172. $form['uninstall'][$module->name] = array(
  1173. '#type' => 'checkbox',
  1174. '#title' => t('Uninstall @module module', array('@module' => $module_name)),
  1175. '#title_display' => 'invisible',
  1176. );
  1177. // All modules which depend on this one must be uninstalled first, before
  1178. // we can allow this module to be uninstalled. (The installation profile
  1179. // is excluded from this list.)
  1180. foreach (array_keys($module->required_by) as $dependent) {
  1181. if ($dependent != $profile && drupal_get_installed_schema_version($dependent) != SCHEMA_UNINSTALLED) {
  1182. $dependent_name = isset($all_modules[$dependent]->info['name']) ? $all_modules[$dependent]->info['name'] : $dependent;
  1183. $form['modules'][$module->name]['#required_by'][] = $dependent_name;
  1184. $form['uninstall'][$module->name]['#disabled'] = TRUE;
  1185. }
  1186. }
  1187. }
  1188. $form['actions'] = array('#type' => 'actions');
  1189. $form['actions']['submit'] = array(
  1190. '#type' => 'submit',
  1191. '#value' => t('Uninstall'),
  1192. );
  1193. $form['#action'] = url('admin/modules/uninstall/confirm');
  1194. }
  1195. else {
  1196. $form['modules'] = array();
  1197. }
  1198. return $form;
  1199. }
  1200. /**
  1201. * Confirm uninstall of selected modules.
  1202. *
  1203. * @ingroup forms
  1204. * @param $storage
  1205. * An associative array of modules selected to be uninstalled.
  1206. * @return
  1207. * A form array representing modules to confirm.
  1208. */
  1209. function system_modules_uninstall_confirm_form($storage) {
  1210. // Nothing to build.
  1211. if (empty($storage)) {
  1212. return;
  1213. }
  1214. // Construct the hidden form elements and list items.
  1215. foreach (array_filter($storage['uninstall']) as $module => $value) {
  1216. $info = drupal_parse_info_file(drupal_get_path('module', $module) . '/' . $module . '.info');
  1217. $uninstall[] = $info['name'];
  1218. $form['uninstall'][$module] = array('#type' => 'hidden',
  1219. '#value' => 1,
  1220. );
  1221. }
  1222. // Display a confirm form if modules have been selected.
  1223. if (isset($uninstall)) {
  1224. $form['#confirmed'] = TRUE;
  1225. $form['uninstall']['#tree'] = TRUE;
  1226. $form['modules'] = array('#markup' => '<p>' . t('The following modules will be completely uninstalled from your site, and <em>all data from these modules will be lost</em>!') . '</p>' . theme('item_list', array('items' => $uninstall)));
  1227. $form = confirm_form(
  1228. $form,
  1229. t('Confirm uninstall'),
  1230. 'admin/modules/uninstall',
  1231. t('Would you like to continue with uninstalling the above?'),
  1232. t('Uninstall'),
  1233. t('Cancel'));
  1234. return $form;
  1235. }
  1236. }
  1237. /**
  1238. * Validates the submitted uninstall form.
  1239. */
  1240. function system_modules_uninstall_validate($form, &$form_state) {
  1241. // Form submitted, but no modules selected.
  1242. if (!count(array_filter($form_state['values']['uninstall']))) {
  1243. drupal_set_message(t('No modules selected.'), 'error');
  1244. drupal_goto('admin/modules/uninstall');
  1245. }
  1246. }
  1247. /**
  1248. * Processes the submitted uninstall form.
  1249. */
  1250. function system_modules_uninstall_submit($form, &$form_state) {
  1251. // Make sure the install API is available.
  1252. include_once DRUPAL_ROOT . '/includes/install.inc';
  1253. if (!empty($form['#confirmed'])) {
  1254. // Call the uninstall routine for each selected module.
  1255. $modules = array_keys($form_state['values']['uninstall']);
  1256. drupal_uninstall_modules($modules);
  1257. drupal_set_message(t('The selected modules have been uninstalled.'));
  1258. $form_state['redirect'] = 'admin/modules/uninstall';
  1259. }
  1260. else {
  1261. $form_state['storage'] = $form_state['values'];
  1262. $form_state['rebuild'] = TRUE;
  1263. }
  1264. }
  1265. /**
  1266. * Menu callback. Display blocked IP addresses.
  1267. *
  1268. * @param $default_ip
  1269. * Optional IP address to be passed on to drupal_get_form() for
  1270. * use as the default value of the IP address form field.
  1271. */
  1272. function system_ip_blocking($default_ip = '') {
  1273. $rows = array();
  1274. $header = array(t('Blocked IP addresses'), t('Operations'));
  1275. $result = db_query('SELECT * FROM {blocked_ips}');
  1276. foreach ($result as $ip) {
  1277. $rows[] = array(
  1278. $ip->ip,
  1279. l(t('delete'), "admin/config/people/ip-blocking/delete/$ip->iid"),
  1280. );
  1281. }
  1282. $build['system_ip_blocking_form'] = drupal_get_form('system_ip_blocking_form', $default_ip);
  1283. $build['system_ip_blocking_table'] = array(
  1284. '#theme' => 'table',
  1285. '#header' => $header,
  1286. '#rows' => $rows,
  1287. '#empty' => t('No blocked IP addresses available.'),
  1288. );
  1289. return $build;
  1290. }
  1291. /**
  1292. * Define the form for blocking IP addresses.
  1293. *
  1294. * @ingroup forms
  1295. * @see system_ip_blocking_form_validate()
  1296. * @see system_ip_blocking_form_submit()
  1297. */
  1298. function system_ip_blocking_form($form, $form_state, $default_ip) {
  1299. $form['ip'] = array(
  1300. '#title' => t('IP address'),
  1301. '#type' => 'textfield',
  1302. '#size' => 48,
  1303. '#maxlength' => 40,
  1304. '#default_value' => $default_ip,
  1305. '#description' => t('Enter a valid IP address.'),
  1306. );
  1307. $form['actions'] = array('#type' => 'actions');
  1308. $form['actions']['submit'] = array(
  1309. '#type' => 'submit',
  1310. '#value' => t('Add'),
  1311. );
  1312. $form['#submit'][] = 'system_ip_blocking_form_submit';
  1313. $form['#validate'][] = 'system_ip_blocking_form_validate';
  1314. return $form;
  1315. }
  1316. function system_ip_blocking_form_validate($form, &$form_state) {
  1317. $ip = trim($form_state['values']['ip']);
  1318. if (db_query("SELECT * FROM {blocked_ips} WHERE ip = :ip", array(':ip' => $ip))->fetchField()) {
  1319. form_set_error('ip', t('This IP address is already blocked.'));
  1320. }
  1321. elseif ($ip == ip_address()) {
  1322. form_set_error('ip', t('You may not block your own IP address.'));
  1323. }
  1324. elseif (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE) == FALSE) {
  1325. form_set_error('ip', t('Enter a valid IP address.'));
  1326. }
  1327. }
  1328. function system_ip_blocking_form_submit($form, &$form_state) {
  1329. $ip = trim($form_state['values']['ip']);
  1330. db_insert('blocked_ips')
  1331. ->fields(array('ip' => $ip))
  1332. ->execute();
  1333. drupal_set_message(t('The IP address %ip has been blocked.', array('%ip' => $ip)));
  1334. $form_state['redirect'] = 'admin/config/people/ip-blocking';
  1335. return;
  1336. }
  1337. /**
  1338. * IP deletion confirm page.
  1339. *
  1340. * @see system_ip_blocking_delete_submit()
  1341. */
  1342. function system_ip_blocking_delete($form, &$form_state, $iid) {
  1343. $form['blocked_ip'] = array(
  1344. '#type' => 'value',
  1345. '#value' => $iid,
  1346. );
  1347. return confirm_form($form, t('Are you sure you want to delete %ip?', array('%ip' => $iid['ip'])), 'admin/config/people/ip-blocking', t('This action cannot be undone.'), t('Delete'), t('Cancel'));
  1348. }
  1349. /**
  1350. * Process system_ip_blocking_delete form submissions.
  1351. */
  1352. function system_ip_blocking_delete_submit($form, &$form_state) {
  1353. $blocked_ip = $form_state['values']['blocked_ip'];
  1354. db_delete('blocked_ips')
  1355. ->condition('iid', $blocked_ip['iid'])
  1356. ->execute();
  1357. watchdog('user', 'Deleted %ip', array('%ip' => $blocked_ip['ip']));
  1358. drupal_set_message(t('The IP address %ip was deleted.', array('%ip' => $blocked_ip['ip'])));
  1359. $form_state['redirect'] = 'admin/config/people/ip-blocking';
  1360. }
  1361. /**
  1362. * Form builder; The general site information form.
  1363. *
  1364. * @ingroup forms
  1365. * @see system_settings_form()
  1366. */
  1367. function system_site_information_settings() {
  1368. $form['site_information'] = array(
  1369. '#type' => 'fieldset',
  1370. '#title' => t('Site details'),
  1371. );
  1372. $form['site_information']['site_name'] = array(
  1373. '#type' => 'textfield',
  1374. '#title' => t('Site name'),
  1375. '#default_value' => variable_get('site_name', 'Drupal'),
  1376. '#required' => TRUE
  1377. );
  1378. $form['site_information']['site_slogan'] = array(
  1379. '#type' => 'textfield',
  1380. '#title' => t('Slogan'),
  1381. '#default_value' => variable_get('site_slogan', ''),
  1382. '#description' => t("How this is used depends on your site's theme."),
  1383. );
  1384. $form['site_information']['site_mail'] = array(
  1385. '#type' => 'textfield',
  1386. '#title' => t('E-mail address'),
  1387. '#default_value' => variable_get('site_mail', ini_get('sendmail_from')),
  1388. '#description' => t("The <em>From</em> address in automated e-mails sent during registration and new password requests, and other notifications. (Use an address ending in your site's domain to help prevent this e-mail being flagged as spam.)"),
  1389. '#required' => TRUE,
  1390. );
  1391. $form['front_page'] = array(
  1392. '#type' => 'fieldset',
  1393. '#title' => t('Front page'),
  1394. );
  1395. $form['front_page']['default_nodes_main'] = array(
  1396. '#type' => 'select', '#title' => t('Number of posts on front page'),
  1397. '#default_value' => variable_get('default_nodes_main', 10),
  1398. '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)),
  1399. '#description' => t('The maximum number of posts displayed on overview pages such as the front page.')
  1400. );
  1401. $form['front_page']['site_frontpage'] = array(
  1402. '#type' => 'textfield',
  1403. '#title' => t('Default front page'),
  1404. '#default_value' => (variable_get('site_frontpage')!='node'?drupal_get_path_alias(variable_get('site_frontpage', 'node')):''),
  1405. '#size' => 40,
  1406. '#description' => t('Optionally, specify a relative URL to display as the front page. Leave blank to display the default content feed.'),
  1407. '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='),
  1408. );
  1409. $form['error_page'] = array(
  1410. '#type' => 'fieldset',
  1411. '#title' => t('Error pages'),
  1412. );
  1413. $form['error_page']['site_403'] = array(
  1414. '#type' => 'textfield',
  1415. '#title' => t('Default 403 (access denied) page'),
  1416. '#default_value' => variable_get('site_403', ''),
  1417. '#size' => 40,
  1418. '#description' => t('This page is displayed when the requested document is denied to the current user. Leave blank to display a generic "access denied" page.'),
  1419. '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q=')
  1420. );
  1421. $form['error_page']['site_404'] = array(
  1422. '#type' => 'textfield',
  1423. '#title' => t('Default 404 (not found) page'),
  1424. '#default_value' => variable_get('site_404', ''),
  1425. '#size' => 40,
  1426. '#description' => t('This page is displayed when no other content matches the requested document. Leave blank to display a generic "page not found" page.'),
  1427. '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q=')
  1428. );
  1429. $form['#validate'][] = 'system_site_information_settings_validate';
  1430. return system_settings_form($form);
  1431. }
  1432. /**
  1433. * Validates the submitted site-information form.
  1434. */
  1435. function system_site_information_settings_validate($form, &$form_state) {
  1436. // Validate the e-mail address.
  1437. if ($error = user_validate_mail($form_state['values']['site_mail'])) {
  1438. form_set_error('site_mail', $error);
  1439. }
  1440. // Check for empty front page path.
  1441. if (empty($form_state['values']['site_frontpage'])) {
  1442. // Set to default "node".
  1443. form_set_value($form['front_page']['site_frontpage'], 'node', $form_state);
  1444. }
  1445. else {
  1446. // Get the normal path of the front page.
  1447. form_set_value($form['front_page']['site_frontpage'], drupal_get_normal_path($form_state['values']['site_frontpage']), $form_state);
  1448. }
  1449. // Validate front page path.
  1450. if (!drupal_valid_path($form_state['values']['site_frontpage'])) {
  1451. form_set_error('site_frontpage', t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state['values']['site_frontpage'])));
  1452. }
  1453. // Get the normal paths of both error pages.
  1454. if (!empty($form_state['values']['site_403'])) {
  1455. form_set_value($form['error_page']['site_403'], drupal_get_normal_path($form_state['values']['site_403']), $form_state);
  1456. }
  1457. if (!empty($form_state['values']['site_404'])) {
  1458. form_set_value($form['error_page']['site_404'], drupal_get_normal_path($form_state['values']['site_404']), $form_state);
  1459. }
  1460. // Validate 403 error path.
  1461. if (!empty($form_state['values']['site_403']) && !drupal_valid_path($form_state['values']['site_403'])) {
  1462. form_set_error('site_403', t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state['values']['site_403'])));
  1463. }
  1464. // Validate 404 error path.
  1465. if (!empty($form_state['values']['site_404']) && !drupal_valid_path($form_state['values']['site_404'])) {
  1466. form_set_error('site_404', t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state['values']['site_404'])));
  1467. }
  1468. }
  1469. /**
  1470. * Form builder; Cron form.
  1471. *
  1472. * @see system_settings_form()
  1473. * @ingroup forms
  1474. */
  1475. function system_cron_settings() {
  1476. global $base_url;
  1477. $form['description'] = array(
  1478. '#markup' => '<p>' . t('Cron takes care of running periodic tasks like checking for updates and indexing content for search.') . '</p>',
  1479. );
  1480. $form['run'] = array(
  1481. '#type' => 'submit',
  1482. '#value' => t('Run cron'),
  1483. '#submit' => array('system_run_cron_submit'),
  1484. );
  1485. $status = '<p>' . t('Last run: %cron-last ago.', array('%cron-last' => format_interval(REQUEST_TIME - variable_get('cron_last')),)) . '</p>';
  1486. $form['status'] = array(
  1487. '#markup' => $status,
  1488. );
  1489. $form['cron_url'] = array(
  1490. '#markup' => '<p>' . t('To run cron from outside the site, go to <a href="!cron">!cron</a>', array('!cron' => url($base_url . '/cron.php', array('external' => TRUE, 'query' => array('cron_key' => variable_get('cron_key', 'drupal')))))) . '</p>',
  1491. );
  1492. $form['cron'] = array(
  1493. '#type' => 'fieldset',
  1494. );
  1495. $form['cron']['cron_safe_threshold'] = array(
  1496. '#type' => 'select',
  1497. '#title' => t('Run cron every'),
  1498. '#description' => t('More information about setting up scheduled tasks can be found by <a href="@url">reading the cron tutorial on drupal.org</a>.', array('@url' => url('http://drupal.org/cron'))),
  1499. '#default_value' => variable_get('cron_safe_threshold', DRUPAL_CRON_DEFAULT_THRESHOLD),
  1500. '#options' => array(0 => t('Never')) + drupal_map_assoc(array(3600, 10800, 21600, 43200, 86400, 604800), 'format_interval'),
  1501. );
  1502. return system_settings_form($form);
  1503. }
  1504. /**
  1505. * Submit callback; run cron.
  1506. *
  1507. * @ingroup forms
  1508. */
  1509. function system_run_cron_submit($form, &$form_state) {
  1510. // Run cron manually from Cron form.
  1511. if (drupal_cron_run()) {
  1512. drupal_set_message(t('Cron run successfully.'));
  1513. }
  1514. else {
  1515. drupal_set_message(t('Cron run failed.'), 'error');
  1516. }
  1517. drupal_goto('admin/config/system/cron');
  1518. }
  1519. /**
  1520. * Form builder; Configure error reporting settings.
  1521. *
  1522. * @ingroup forms
  1523. * @see system_settings_form()
  1524. */
  1525. function system_logging_settings() {
  1526. $form['error_level'] = array(
  1527. '#type' => 'radios',
  1528. '#title' => t('Error messages to display'),
  1529. '#default_value' => variable_get('error_level', ERROR_REPORTING_DISPLAY_ALL),
  1530. '#options' => array(
  1531. ERROR_REPORTING_HIDE => t('None'),
  1532. ERROR_REPORTING_DISPLAY_SOME => t('Errors and warnings'),
  1533. ERROR_REPORTING_DISPLAY_ALL => t('All messages'),
  1534. ),
  1535. '#description' => t('It is recommended that sites running on production environments do not display any errors.'),
  1536. );
  1537. return system_settings_form($form);
  1538. }
  1539. /**
  1540. * Form builder; Configure site performance settings.
  1541. *
  1542. * @ingroup forms
  1543. * @see system_settings_form()
  1544. */
  1545. function system_performance_settings() {
  1546. drupal_add_js(drupal_get_path('module', 'system') . '/system.js');
  1547. $form['clear_cache'] = array(
  1548. '#type' => 'fieldset',
  1549. '#title' => t('Clear cache'),
  1550. );
  1551. $form['clear_cache']['clear'] = array(
  1552. '#type' => 'submit',
  1553. '#value' => t('Clear all caches'),
  1554. '#submit' => array('system_clear_cache_submit'),
  1555. );
  1556. $form['caching'] = array(
  1557. '#type' => 'fieldset',
  1558. '#title' => t('Caching'),
  1559. );
  1560. $cache = variable_get('cache', 0);
  1561. $form['caching']['cache'] = array(
  1562. '#type' => 'checkbox',
  1563. '#title' => t('Cache pages for anonymous users'),
  1564. '#default_value' => $cache,
  1565. '#weight' => -2,
  1566. );
  1567. $period = drupal_map_assoc(array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400), 'format_interval');
  1568. $period[0] = '<' . t('none') . '>';
  1569. $form['caching']['cache_lifetime'] = array(
  1570. '#type' => 'select',
  1571. '#title' => t('Minimum cache lifetime'),
  1572. '#default_value' => variable_get('cache_lifetime', 0),
  1573. '#options' => $period,
  1574. '#description' => t('Cached pages will not be re-created until at least this much time has elapsed.')
  1575. );
  1576. $form['caching']['page_cache_maximum_age'] = array(
  1577. '#type' => 'select',
  1578. '#title' => t('Expiration of cached pages'),
  1579. '#default_value' => variable_get('page_cache_maximum_age', 0),
  1580. '#options' => $period,
  1581. '#description' => t('The maximum time an external cache can use an old version of a page.')
  1582. );
  1583. $directory = 'public://';
  1584. $is_writable = is_dir($directory) && is_writable($directory);
  1585. $disabled = !$is_writable;
  1586. $disabled_message = '';
  1587. if (!$is_writable) {
  1588. $disabled_message = ' ' . t('<strong class="error">Set up the <a href="!file-system">public files directory</a> to make these optimizations available.</strong>', array('!file-system' => url('admin/config/media/file-system')));
  1589. }
  1590. $form['bandwidth_optimization'] = array(
  1591. '#type' => 'fieldset',
  1592. '#title' => t('Bandwidth optimization'),
  1593. '#description' => t('External resources can be optimized automatically, which can reduce both the size and number of requests made to your website.') . $disabled_message,
  1594. );
  1595. $js_hide = $cache ? '' : ' class="js-hide"';
  1596. $form['bandwidth_optimization']['page_compression'] = array(
  1597. '#type' => 'checkbox',
  1598. '#title' => t('Compress cached pages.'),
  1599. '#default_value' => variable_get('page_compression', TRUE),
  1600. '#prefix' => '<div id="page-compression-wrapper"' . $js_hide . '>',
  1601. '#suffix' => '</div>',
  1602. );
  1603. $form['bandwidth_optimization']['preprocess_css'] = array(
  1604. '#type' => 'checkbox',
  1605. '#title' => t('Aggregate and compress CSS files.'),
  1606. '#default_value' => intval(variable_get('preprocess_css', 0) && $is_writable),
  1607. '#disabled' => $disabled,
  1608. );
  1609. $form['bandwidth_optimization']['preprocess_js'] = array(
  1610. '#type' => 'checkbox',
  1611. '#title' => t('Aggregate JavaScript files.'),
  1612. '#default_value' => intval(variable_get('preprocess_js', 0) && $is_writable),
  1613. '#disabled' => $disabled,
  1614. );
  1615. $form['#submit'][] = 'drupal_clear_css_cache';
  1616. $form['#submit'][] = 'drupal_clear_js_cache';
  1617. // This form allows page compression settings to be changed, which can
  1618. // invalidate the page cache, so it needs to be cleared on form submit.
  1619. $form['#submit'][] = 'system_clear_page_cache_submit';
  1620. return system_settings_form($form);
  1621. }
  1622. /**
  1623. * Submit callback; clear system caches.
  1624. *
  1625. * @ingroup forms
  1626. */
  1627. function system_clear_cache_submit($form, &$form_state) {
  1628. drupal_flush_all_caches();
  1629. drupal_set_message(t('Caches cleared.'));
  1630. }
  1631. /**
  1632. * Submit callback; clear the page cache.
  1633. *
  1634. * @ingroup forms
  1635. */
  1636. function system_clear_page_cache_submit($form, &$form_state) {
  1637. cache_clear_all('*', 'cache_page', TRUE);
  1638. }
  1639. /**
  1640. * Form builder; Configure the site file handling.
  1641. *
  1642. * @ingroup forms
  1643. * @see system_settings_form()
  1644. */
  1645. function system_file_system_settings() {
  1646. $form['file_public_path'] = array(
  1647. '#type' => 'textfield',
  1648. '#title' => t('Public file system path'),
  1649. '#default_value' => variable_get('file_public_path', conf_path() . '/files'),
  1650. '#maxlength' => 255,
  1651. '#description' => t('A local file system path where public files will be stored. This directory must exist and be writable by Drupal. This directory must be relative to the Drupal installation directory and be accessible over the web.'),
  1652. '#after_build' => array('system_check_directory'),
  1653. );
  1654. $form['file_private_path'] = array(
  1655. '#type' => 'textfield',
  1656. '#title' => t('Private file system path'),
  1657. '#default_value' => variable_get('file_private_path', ''),
  1658. '#maxlength' => 255,
  1659. '#description' => t('An existing local file system path for storing private files. It should be writable by Drupal and not accessible over the web. See the online handbook for <a href="@handbook">more information about securing private files</a>.', array('@handbook' => 'http://drupal.org/documentation/modules/file')),
  1660. '#after_build' => array('system_check_directory'),
  1661. );
  1662. $form['file_temporary_path'] = array(
  1663. '#type' => 'textfield',
  1664. '#title' => t('Temporary directory'),
  1665. '#default_value' => variable_get('file_temporary_path', file_directory_temp()),
  1666. '#maxlength' => 255,
  1667. '#description' => t('A local file system path where temporary files will be stored. This directory should not be accessible over the web.'),
  1668. '#after_build' => array('system_check_directory'),
  1669. );
  1670. // Any visible, writeable wrapper can potentially be used for the files
  1671. // directory, including a remote file system that integrates with a CDN.
  1672. foreach (file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE) as $scheme => $info) {
  1673. $options[$scheme] = check_plain($info['description']);
  1674. }
  1675. if (!empty($options)) {
  1676. $form['file_default_scheme'] = array(
  1677. '#type' => 'radios',
  1678. '#title' => t('Default download method'),
  1679. '#default_value' => variable_get('file_default_scheme', isset($options['public']) ? 'public' : key($options)),
  1680. '#options' => $options,
  1681. '#description' => t('This setting is used as the preferred download method. The use of public files is more efficient, but does not provide any access control.'),
  1682. );
  1683. }
  1684. return system_settings_form($form);
  1685. }
  1686. /**
  1687. * Form builder; Configure site image toolkit usage.
  1688. *
  1689. * @ingroup forms
  1690. * @see system_settings_form()
  1691. */
  1692. function system_image_toolkit_settings() {
  1693. $toolkits_available = image_get_available_toolkits();
  1694. $current_toolkit = image_get_toolkit();
  1695. if (count($toolkits_available) == 0) {
  1696. variable_del('image_toolkit');
  1697. $form['image_toolkit_help'] = array(
  1698. '#markup' => t("No image toolkits were detected. Drupal includes support for <a href='!gd-link'>PHP's built-in image processing functions</a> but they were not detected on this system. You should consult your system administrator to have them enabled, or try using a third party toolkit.", array('gd-link' => url('http://php.net/gd'))),
  1699. );
  1700. return $form;
  1701. }
  1702. if (count($toolkits_available) > 1) {
  1703. $form['image_toolkit'] = array(
  1704. '#type' => 'radios',
  1705. '#title' => t('Select an image processing toolkit'),
  1706. '#default_value' => variable_get('image_toolkit', $current_toolkit),
  1707. '#options' => $toolkits_available
  1708. );
  1709. }
  1710. else {
  1711. variable_set('image_toolkit', key($toolkits_available));
  1712. }
  1713. // Get the toolkit's settings form.
  1714. $function = 'image_' . $current_toolkit . '_settings';
  1715. if (function_exists($function)) {
  1716. $form['image_toolkit_settings'] = $function();
  1717. }
  1718. return system_settings_form($form);
  1719. }
  1720. /**
  1721. * Form builder; Configure how the site handles RSS feeds.
  1722. *
  1723. * @ingroup forms
  1724. * @see system_settings_form()
  1725. */
  1726. function system_rss_feeds_settings() {
  1727. $form['feed_description'] = array(
  1728. '#type' => 'textarea',
  1729. '#title' => t('Feed description'),
  1730. '#default_value' => variable_get('feed_description', ''),
  1731. '#description' => t('Description of your site, included in each feed.')
  1732. );
  1733. $form['feed_default_items'] = array(
  1734. '#type' => 'select',
  1735. '#title' => t('Number of items in each feed'),
  1736. '#default_value' => variable_get('feed_default_items', 10),
  1737. '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)),
  1738. '#description' => t('Default number of items to include in each feed.')
  1739. );
  1740. $form['feed_item_length'] = array(
  1741. '#type' => 'select',
  1742. '#title' => t('Feed content'),
  1743. '#default_value' => variable_get('feed_item_length', 'fulltext'),
  1744. '#options' => array('title' => t('Titles only'), 'teaser' => t('Titles plus teaser'), 'fulltext' => t('Full text')),
  1745. '#description' => t('Global setting for the default display of content items in each feed.')
  1746. );
  1747. return system_settings_form($form);
  1748. }
  1749. /**
  1750. * Form builder; Configure the site regional settings.
  1751. *
  1752. * @ingroup forms
  1753. * @see system_settings_form()
  1754. * @see system_regional_settings_submit()
  1755. */
  1756. function system_regional_settings() {
  1757. include_once DRUPAL_ROOT . '/includes/locale.inc';
  1758. $countries = country_get_list();
  1759. // Date settings:
  1760. $zones = system_time_zones();
  1761. $form['locale'] = array(
  1762. '#type' => 'fieldset',
  1763. '#title' => t('Locale'),
  1764. );
  1765. $form['locale']['site_default_country'] = array(
  1766. '#type' => 'select',
  1767. '#title' => t('Default country'),
  1768. '#empty_value' => '',
  1769. '#default_value' => variable_get('site_default_country', ''),
  1770. '#options' => $countries,
  1771. '#attributes' => array('class' => array('country-detect')),
  1772. );
  1773. $form['locale']['date_first_day'] = array(
  1774. '#type' => 'select',
  1775. '#title' => t('First day of week'),
  1776. '#default_value' => variable_get('date_first_day', 0),
  1777. '#options' => array(0 => t('Sunday'), 1 => t('Monday'), 2 => t('Tuesday'), 3 => t('Wednesday'), 4 => t('Thursday'), 5 => t('Friday'), 6 => t('Saturday')),
  1778. );
  1779. $form['timezone'] = array(
  1780. '#type' => 'fieldset',
  1781. '#title' => t('Time zones'),
  1782. );
  1783. $form['timezone']['date_default_timezone'] = array(
  1784. '#type' => 'select',
  1785. '#title' => t('Default time zone'),
  1786. '#default_value' => variable_get('date_default_timezone', date_default_timezone_get()),
  1787. '#options' => $zones,
  1788. );
  1789. $configurable_timezones = variable_get('configurable_timezones', 1);
  1790. $form['timezone']['configurable_timezones'] = array(
  1791. '#type' => 'checkbox',
  1792. '#title' => t('Users may set their own time zone.'),
  1793. '#default_value' => $configurable_timezones,
  1794. );
  1795. $form['timezone']['configurable_timezones_wrapper'] = array(
  1796. '#type' => 'container',
  1797. '#states' => array(
  1798. // Hide the user configured timezone settings when users are forced to use
  1799. // the default setting.
  1800. 'invisible' => array(
  1801. 'input[name="configurable_timezones"]' => array('checked' => FALSE),
  1802. ),
  1803. ),
  1804. );
  1805. $form['timezone']['configurable_timezones_wrapper']['empty_timezone_message'] = array(
  1806. '#type' => 'checkbox',
  1807. '#title' => t('Remind users at login if their time zone is not set.'),
  1808. '#default_value' => variable_get('empty_timezone_message', 0),
  1809. '#description' => t('Only applied if users may set their own time zone.')
  1810. );
  1811. $form['timezone']['configurable_timezones_wrapper']['user_default_timezone'] = array(
  1812. '#type' => 'radios',
  1813. '#title' => t('Time zone for new users'),
  1814. '#default_value' => variable_get('user_default_timezone', DRUPAL_USER_TIMEZONE_DEFAULT),
  1815. '#options' => array(
  1816. DRUPAL_USER_TIMEZONE_DEFAULT => t('Default time zone.'),
  1817. DRUPAL_USER_TIMEZONE_EMPTY => t('Empty time zone.'),
  1818. DRUPAL_USER_TIMEZONE_SELECT => t('Users may set their own time zone at registration.'),
  1819. ),
  1820. '#description' => t('Only applied if users may set their own time zone.')
  1821. );
  1822. return system_settings_form($form);
  1823. }
  1824. /**
  1825. * Form builder; Configure the site date and time settings.
  1826. *
  1827. * @ingroup forms
  1828. * @see system_settings_form()
  1829. */
  1830. function system_date_time_settings() {
  1831. // Get list of all available date types.
  1832. drupal_static_reset('system_get_date_types');
  1833. $format_types = system_get_date_types();
  1834. // Get list of all available date formats.
  1835. $all_formats = array();
  1836. drupal_static_reset('system_get_date_formats');
  1837. $date_formats = system_get_date_formats(); // Call this to rebuild the list, and to have default list.
  1838. foreach ($date_formats as $type => $format_info) {
  1839. $all_formats = array_merge($all_formats, $format_info);
  1840. }
  1841. $custom_formats = system_get_date_formats('custom');
  1842. if (!empty($format_types)) {
  1843. foreach ($format_types as $type => $type_info) {
  1844. // If a system type, only show the available formats for that type and
  1845. // custom ones.
  1846. if ($type_info['locked'] == 1) {
  1847. $formats = system_get_date_formats($type);
  1848. if (empty($formats)) {
  1849. $formats = $all_formats;
  1850. }
  1851. elseif (!empty($custom_formats)) {
  1852. $formats = array_merge($formats, $custom_formats);
  1853. }
  1854. }
  1855. // If a user configured type, show all available date formats.
  1856. else {
  1857. $formats = $all_formats;
  1858. }
  1859. $choices = array();
  1860. foreach ($formats as $f => $format) {
  1861. $choices[$f] = format_date(REQUEST_TIME, 'custom', $f);
  1862. }
  1863. reset($formats);
  1864. $default = variable_get('date_format_' . $type, key($formats));
  1865. // Get date type info for this date type.
  1866. $type_info = system_get_date_types($type);
  1867. $form['formats']['#theme'] = 'system_date_time_settings';
  1868. // Show date format select list.
  1869. $form['formats']['format']['date_format_' . $type] = array(
  1870. '#type' => 'select',
  1871. '#title' => check_plain($type_info['title']),
  1872. '#attributes' => array('class' => array('date-format')),
  1873. '#default_value' => (isset($choices[$default]) ? $default : 'custom'),
  1874. '#options' => $choices,
  1875. );
  1876. // If this isn't a system provided type, allow the user to remove it from
  1877. // the system.
  1878. if ($type_info['locked'] == 0) {
  1879. $form['formats']['delete']['date_format_' . $type . '_delete'] = array(
  1880. '#type' => 'link',
  1881. '#title' => t('delete'),
  1882. '#href' => 'admin/config/regional/date-time/types/' . $type . '/delete',
  1883. );
  1884. }
  1885. }
  1886. }
  1887. // Display a message if no date types configured.
  1888. $form['#empty_text'] = t('No date types available. <a href="@link">Add date type</a>.', array('@link' => url('admin/config/regional/date-time/types/add')));
  1889. return system_settings_form($form);
  1890. }
  1891. /**
  1892. * Returns HTML for the date settings form.
  1893. *
  1894. * @param $variables
  1895. * An associative array containing:
  1896. * - form: A render element representing the form.
  1897. *
  1898. * @ingroup themeable
  1899. */
  1900. function theme_system_date_time_settings($variables) {
  1901. $form = $variables['form'];
  1902. $header = array(
  1903. t('Date type'),
  1904. t('Format'),
  1905. t('Operations'),
  1906. );
  1907. foreach (element_children($form['format']) as $key) {
  1908. $delete_key = $key . '_delete';
  1909. $row = array();
  1910. $row[] = $form['format'][$key]['#title'];
  1911. $form['format'][$key]['#title_display'] = 'invisible';
  1912. $row[] = array('data' => drupal_render($form['format'][$key]));
  1913. $row[] = array('data' => drupal_render($form['delete'][$delete_key]));
  1914. $rows[] = $row;
  1915. }
  1916. $output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'system-date-types')));
  1917. $output .= drupal_render_children($form);
  1918. return $output;
  1919. }
  1920. /**
  1921. * Add new date type.
  1922. *
  1923. * @ingroup forms
  1924. * @ingroup system_add_date_format_type_form_validate()
  1925. * @ingroup system_add_date_format_type_form_submit()
  1926. */
  1927. function system_add_date_format_type_form($form, &$form_state) {
  1928. $form['date_type'] = array(
  1929. '#title' => t('Date type'),
  1930. '#type' => 'textfield',
  1931. '#required' => TRUE,
  1932. );
  1933. $form['machine_name'] = array(
  1934. '#type' => 'machine_name',
  1935. '#machine_name' => array(
  1936. 'exists' => 'system_get_date_types',
  1937. 'source' => array('date_type'),
  1938. ),
  1939. );
  1940. // Get list of all available date formats.
  1941. $formats = array();
  1942. drupal_static_reset('system_get_date_formats');
  1943. $date_formats = system_get_date_formats(); // Call this to rebuild the list, and to have default list.
  1944. foreach ($date_formats as $type => $format_info) {
  1945. $formats = array_merge($formats, $format_info);
  1946. }
  1947. $custom_formats = system_get_date_formats('custom');
  1948. if (!empty($custom_formats)) {
  1949. $formats = array_merge($formats, $custom_formats);
  1950. }
  1951. $choices = array();
  1952. foreach ($formats as $f => $format) {
  1953. $choices[$f] = format_date(REQUEST_TIME, 'custom', $f);
  1954. }
  1955. // Show date format select list.
  1956. $form['date_format'] = array(
  1957. '#type' => 'select',
  1958. '#title' => t('Date format'),
  1959. '#attributes' => array('class' => array('date-format')),
  1960. '#options' => $choices,
  1961. '#required' => TRUE,
  1962. );
  1963. $form['actions'] = array('#type' => 'actions');
  1964. $form['actions']['submit'] = array(
  1965. '#type' => 'submit',
  1966. '#value' => t('Add date type'),
  1967. );
  1968. $form['#validate'][] = 'system_add_date_format_type_form_validate';
  1969. $form['#submit'][] = 'system_add_date_format_type_form_submit';
  1970. return $form;
  1971. }
  1972. /**
  1973. * Validate system_add_date_format_type form submissions.
  1974. */
  1975. function system_add_date_format_type_form_validate($form, &$form_state) {
  1976. if (!empty($form_state['values']['machine_name']) && !empty($form_state['values']['date_type'])) {
  1977. if (!preg_match("/^[a-zA-Z0-9_]+$/", trim($form_state['values']['machine_name']))) {
  1978. form_set_error('machine_name', t('The date type must contain only alphanumeric characters and underscores.'));
  1979. }
  1980. $types = system_get_date_types();
  1981. if (in_array(trim($form_state['values']['machine_name']), array_keys($types))) {
  1982. form_set_error('machine_name', t('This date type already exists. Enter a unique type.'));
  1983. }
  1984. }
  1985. }
  1986. /**
  1987. * Process system_add_date_format_type form submissions.
  1988. */
  1989. function system_add_date_format_type_form_submit($form, &$form_state) {
  1990. $machine_name = trim($form_state['values']['machine_name']);
  1991. $format_type = array();
  1992. $format_type['title'] = trim($form_state['values']['date_type']);
  1993. $format_type['type'] = $machine_name;
  1994. $format_type['locked'] = 0;
  1995. $format_type['is_new'] = 1;
  1996. system_date_format_type_save($format_type);
  1997. variable_set('date_format_' . $machine_name, $form_state['values']['date_format']);
  1998. drupal_set_message(t('New date type added successfully.'));
  1999. $form_state['redirect'] = 'admin/config/regional/date-time';
  2000. }
  2001. /**
  2002. * Return the date for a given format string via Ajax.
  2003. */
  2004. function system_date_time_lookup() {
  2005. $result = format_date(REQUEST_TIME, 'custom', $_GET['format']);
  2006. drupal_json_output($result);
  2007. }
  2008. /**
  2009. * Form builder; Configure the site's maintenance status.
  2010. *
  2011. * @ingroup forms
  2012. * @see system_settings_form()
  2013. */
  2014. function system_site_maintenance_mode() {
  2015. $form['maintenance_mode'] = array(
  2016. '#type' => 'checkbox',
  2017. '#title' => t('Put site into maintenance mode'),
  2018. '#default_value' => variable_get('maintenance_mode', 0),
  2019. '#description' => t('When enabled, only users with the "Use the site in maintenance mode" <a href="@permissions-url">permission</a> are able to access your site to perform maintenance; all other visitors see the maintenance mode message configured below. Authorized users can log in directly via the <a href="@user-login">user login</a> page.', array('@permissions-url' => url('admin/people/permissions'), '@user-login' => url('user'))),
  2020. );
  2021. $form['maintenance_mode_message'] = array(
  2022. '#type' => 'textarea',
  2023. '#title' => t('Maintenance mode message'),
  2024. '#default_value' => variable_get('maintenance_mode_message', t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('@site' => variable_get('site_name', 'Drupal')))),
  2025. '#description' => t('Message to show visitors when the site is in maintenance mode.')
  2026. );
  2027. return system_settings_form($form);
  2028. }
  2029. /**
  2030. * Form builder; Configure clean URL settings.
  2031. *
  2032. * @ingroup forms
  2033. * @see system_settings_form()
  2034. */
  2035. function system_clean_url_settings($form, &$form_state) {
  2036. $available = FALSE;
  2037. $conflict = FALSE;
  2038. // If the request URI is a clean URL, clean URLs must be available.
  2039. // Otherwise, run a test.
  2040. if (strpos(request_uri(), '?q=') === FALSE && strpos(request_uri(), '&q=') === FALSE) {
  2041. $available = TRUE;
  2042. }
  2043. else {
  2044. $request = drupal_http_request($GLOBALS['base_url'] . '/admin/config/search/clean-urls/check');
  2045. // If the request returns HTTP 200, clean URLs are available.
  2046. if (isset($request->code) && $request->code == 200) {
  2047. $available = TRUE;
  2048. // If the user started the clean URL test, provide explicit feedback.
  2049. if (isset($form_state['input']['clean_url_test_execute'])) {
  2050. drupal_set_message(t('The clean URL test passed.'));
  2051. }
  2052. }
  2053. else {
  2054. // If the test failed while clean URLs are enabled, make sure clean URLs
  2055. // can be disabled.
  2056. if (variable_get('clean_url', 0)) {
  2057. $conflict = TRUE;
  2058. // Warn the user of a conflicting situation, unless after processing
  2059. // a submitted form.
  2060. if (!isset($form_state['input']['op'])) {
  2061. drupal_set_message(t('Clean URLs are enabled, but the clean URL test failed. Uncheck the box below to disable clean URLs.'), 'warning');
  2062. }
  2063. }
  2064. // If the user started the clean URL test, provide explicit feedback.
  2065. elseif (isset($form_state['input']['clean_url_test_execute'])) {
  2066. drupal_set_message(t('The clean URL test failed.'), 'warning');
  2067. }
  2068. }
  2069. }
  2070. // Show the enable/disable form if clean URLs are available or if the user
  2071. // must be able to resolve a conflicting setting.
  2072. if ($available || $conflict) {
  2073. $form['clean_url'] = array(
  2074. '#type' => 'checkbox',
  2075. '#title' => t('Enable clean URLs'),
  2076. '#default_value' => variable_get('clean_url', 0),
  2077. '#description' => t('Use URLs like <code>example.com/user</code> instead of <code>example.com/?q=user</code>.'),
  2078. );
  2079. $form = system_settings_form($form);
  2080. if ($conflict) {
  2081. // $form_state['redirect'] needs to be set to the non-clean URL,
  2082. // otherwise the setting is not saved.
  2083. $form_state['redirect'] = url('', array('query' => array('q' => '/admin/config/search/clean-urls')));
  2084. }
  2085. }
  2086. // Show the clean URLs test form.
  2087. else {
  2088. drupal_add_js(drupal_get_path('module', 'system') . '/system.js');
  2089. $form_state['redirect'] = url('admin/config/search/clean-urls');
  2090. $form['clean_url_description'] = array(
  2091. '#type' => 'markup',
  2092. '#markup' => '<p>' . t('Use URLs like <code>example.com/user</code> instead of <code>example.com/?q=user</code>.'),
  2093. );
  2094. // Explain why the user is seeing this page and what to expect after
  2095. // clicking the 'Run the clean URL test' button.
  2096. $form['clean_url_test_result'] = array(
  2097. '#type' => 'markup',
  2098. '#markup' => '<p>' . t('Clean URLs cannot be enabled. If you are directed to this page or to a <em>Page not found (404)</em> error after testing for clean URLs, see the <a href="@handbook">online handbook</a>.', array('@handbook' => 'http://drupal.org/node/15365')) . '</p>',
  2099. );
  2100. $form['actions'] = array(
  2101. '#type' => 'actions',
  2102. 'clean_url_test' => array(
  2103. '#type' => 'submit',
  2104. '#value' => t('Run the clean URL test'),
  2105. ),
  2106. );
  2107. $form['clean_url_test_execute'] = array(
  2108. '#type' => 'hidden',
  2109. '#value' => 1,
  2110. );
  2111. }
  2112. return $form;
  2113. }
  2114. /**
  2115. * Menu callback: displays the site status report. Can also be used as a pure check.
  2116. *
  2117. * @param $check
  2118. * If true, only returns a boolean whether there are system status errors.
  2119. */
  2120. function system_status($check = FALSE) {
  2121. // Load .install files
  2122. include_once DRUPAL_ROOT . '/includes/install.inc';
  2123. drupal_load_updates();
  2124. // Check run-time requirements and status information.
  2125. $requirements = module_invoke_all('requirements', 'runtime');
  2126. usort($requirements, '_system_sort_requirements');
  2127. if ($check) {
  2128. return drupal_requirements_severity($requirements) == REQUIREMENT_ERROR;
  2129. }
  2130. // MySQL import might have set the uid of the anonymous user to autoincrement
  2131. // value. Let's try fixing it. See http://drupal.org/node/204411
  2132. db_update('users')
  2133. ->expression('uid', 'uid - uid')
  2134. ->condition('name', '')
  2135. ->condition('pass', '')
  2136. ->condition('status', 0)
  2137. ->execute();
  2138. return theme('status_report', array('requirements' => $requirements));
  2139. }
  2140. /**
  2141. * Menu callback: run cron manually.
  2142. */
  2143. function system_run_cron() {
  2144. // Run cron manually
  2145. if (drupal_cron_run()) {
  2146. drupal_set_message(t('Cron ran successfully.'));
  2147. }
  2148. else {
  2149. drupal_set_message(t('Cron run failed.'), 'error');
  2150. }
  2151. drupal_goto('admin/reports/status');
  2152. }
  2153. /**
  2154. * Menu callback: return information about PHP.
  2155. */
  2156. function system_php() {
  2157. phpinfo();
  2158. drupal_exit();
  2159. }
  2160. /**
  2161. * Default page callback for batches.
  2162. */
  2163. function system_batch_page() {
  2164. require_once DRUPAL_ROOT . '/includes/batch.inc';
  2165. $output = _batch_page();
  2166. if ($output === FALSE) {
  2167. drupal_access_denied();
  2168. }
  2169. elseif (isset($output)) {
  2170. // Force a page without blocks or messages to
  2171. // display a list of collected messages later.
  2172. drupal_set_page_content($output);
  2173. $page = element_info('page');
  2174. $page['#show_messages'] = FALSE;
  2175. return $page;
  2176. }
  2177. }
  2178. /**
  2179. * Returns HTML for an administrative block for display.
  2180. *
  2181. * @param $variables
  2182. * An associative array containing:
  2183. * - block: An array containing information about the block:
  2184. * - show: A Boolean whether to output the block. Defaults to FALSE.
  2185. * - title: The block's title.
  2186. * - content: (optional) Formatted content for the block.
  2187. * - description: (optional) Description of the block. Only output if
  2188. * 'content' is not set.
  2189. *
  2190. * @ingroup themeable
  2191. */
  2192. function theme_admin_block($variables) {
  2193. $block = $variables['block'];
  2194. $output = '';
  2195. // Don't display the block if it has no content to display.
  2196. if (empty($block['show'])) {
  2197. return $output;
  2198. }
  2199. $output .= '<div class="admin-panel">';
  2200. if (!empty($block['title'])) {
  2201. $output .= '<h3>' . $block['title'] . '</h3>';
  2202. }
  2203. if (!empty($block['content'])) {
  2204. $output .= '<div class="body">' . $block['content'] . '</div>';
  2205. }
  2206. else {
  2207. $output .= '<div class="description">' . $block['description'] . '</div>';
  2208. }
  2209. $output .= '</div>';
  2210. return $output;
  2211. }
  2212. /**
  2213. * Returns HTML for the content of an administrative block.
  2214. *
  2215. * @param $variables
  2216. * An associative array containing:
  2217. * - content: An array containing information about the block. Each element
  2218. * of the array represents an administrative menu item, and must at least
  2219. * contain the keys 'title', 'href', and 'localized_options', which are
  2220. * passed to l(). A 'description' key may also be provided.
  2221. *
  2222. * @ingroup themeable
  2223. */
  2224. function theme_admin_block_content($variables) {
  2225. $content = $variables['content'];
  2226. $output = '';
  2227. if (!empty($content)) {
  2228. $class = 'admin-list';
  2229. if ($compact = system_admin_compact_mode()) {
  2230. $class .= ' compact';
  2231. }
  2232. $output .= '<dl class="' . $class . '">';
  2233. foreach ($content as $item) {
  2234. $output .= '<dt>' . l($item['title'], $item['href'], $item['localized_options']) . '</dt>';
  2235. if (!$compact && isset($item['description'])) {
  2236. $output .= '<dd>' . filter_xss_admin($item['description']) . '</dd>';
  2237. }
  2238. }
  2239. $output .= '</dl>';
  2240. }
  2241. return $output;
  2242. }
  2243. /**
  2244. * Returns HTML for an administrative page.
  2245. *
  2246. * @param $variables
  2247. * An associative array containing:
  2248. * - blocks: An array of blocks to display. Each array should include a
  2249. * 'title', a 'description', a formatted 'content' and a 'position' which
  2250. * will control which container it will be in. This is usually 'left' or
  2251. * 'right'.
  2252. *
  2253. * @ingroup themeable
  2254. */
  2255. function theme_admin_page($variables) {
  2256. $blocks = $variables['blocks'];
  2257. $stripe = 0;
  2258. $container = array();
  2259. foreach ($blocks as $block) {
  2260. if ($block_output = theme('admin_block', array('block' => $block))) {
  2261. if (empty($block['position'])) {
  2262. // perform automatic striping.
  2263. $block['position'] = ++$stripe % 2 ? 'left' : 'right';
  2264. }
  2265. if (!isset($container[$block['position']])) {
  2266. $container[$block['position']] = '';
  2267. }
  2268. $container[$block['position']] .= $block_output;
  2269. }
  2270. }
  2271. $output = '<div class="admin clearfix">';
  2272. $output .= theme('system_compact_link');
  2273. foreach ($container as $id => $data) {
  2274. $output .= '<div class="' . $id . ' clearfix">';
  2275. $output .= $data;
  2276. $output .= '</div>';
  2277. }
  2278. $output .= '</div>';
  2279. return $output;
  2280. }
  2281. /**
  2282. * Returns HTML for the output of the dashboard page.
  2283. *
  2284. * @param $variables
  2285. * An associative array containing:
  2286. * - menu_items: An array of modules to be displayed.
  2287. *
  2288. * @ingroup themeable
  2289. */
  2290. function theme_system_admin_index($variables) {
  2291. $menu_items = $variables['menu_items'];
  2292. $stripe = 0;
  2293. $container = array('left' => '', 'right' => '');
  2294. $flip = array('left' => 'right', 'right' => 'left');
  2295. $position = 'left';
  2296. // Iterate over all modules.
  2297. foreach ($menu_items as $module => $block) {
  2298. list($description, $items) = $block;
  2299. // Output links.
  2300. if (count($items)) {
  2301. $block = array();
  2302. $block['title'] = $module;
  2303. $block['content'] = theme('admin_block_content', array('content' => $items));
  2304. $block['description'] = t($description);
  2305. $block['show'] = TRUE;
  2306. if ($block_output = theme('admin_block', array('block' => $block))) {
  2307. if (!isset($block['position'])) {
  2308. // Perform automatic striping.
  2309. $block['position'] = $position;
  2310. $position = $flip[$position];
  2311. }
  2312. $container[$block['position']] .= $block_output;
  2313. }
  2314. }
  2315. }
  2316. $output = '<div class="admin clearfix">';
  2317. $output .= theme('system_compact_link');
  2318. foreach ($container as $id => $data) {
  2319. $output .= '<div class="' . $id . ' clearfix">';
  2320. $output .= $data;
  2321. $output .= '</div>';
  2322. }
  2323. $output .= '</div>';
  2324. return $output;
  2325. }
  2326. /**
  2327. * Returns HTML for the status report.
  2328. *
  2329. * @param $variables
  2330. * An associative array containing:
  2331. * - requirements: An array of requirements.
  2332. *
  2333. * @ingroup themeable
  2334. */
  2335. function theme_status_report($variables) {
  2336. $requirements = $variables['requirements'];
  2337. $severities = array(
  2338. REQUIREMENT_INFO => array(
  2339. 'title' => t('Info'),
  2340. 'class' => 'info',
  2341. ),
  2342. REQUIREMENT_OK => array(
  2343. 'title' => t('OK'),
  2344. 'class' => 'ok',
  2345. ),
  2346. REQUIREMENT_WARNING => array(
  2347. 'title' => t('Warning'),
  2348. 'class' => 'warning',
  2349. ),
  2350. REQUIREMENT_ERROR => array(
  2351. 'title' => t('Error'),
  2352. 'class' => 'error',
  2353. ),
  2354. );
  2355. $output = '<table class="system-status-report">';
  2356. foreach ($requirements as $requirement) {
  2357. if (empty($requirement['#type'])) {
  2358. $severity = $severities[isset($requirement['severity']) ? (int) $requirement['severity'] : REQUIREMENT_OK];
  2359. $severity['icon'] = '<div title="' . $severity['title'] . '"><span class="element-invisible">' . $severity['title'] . '</span></div>';
  2360. // Output table row(s)
  2361. if (!empty($requirement['description'])) {
  2362. $output .= '<tr class="' . $severity['class'] . ' merge-down"><td class="status-icon">' . $severity['icon'] . '</td><td class="status-title">' . $requirement['title'] . '</td><td class="status-value">' . $requirement['value'] . '</td></tr>';
  2363. $output .= '<tr class="' . $severity['class'] . ' merge-up"><td colspan="3" class="status-description">' . $requirement['description'] . '</td></tr>';
  2364. }
  2365. else {
  2366. $output .= '<tr class="' . $severity['class'] . '"><td class="status-icon">' . $severity['icon'] . '</td><td class="status-title">' . $requirement['title'] . '</td><td class="status-value">' . $requirement['value'] . '</td></tr>';
  2367. }
  2368. }
  2369. }
  2370. $output .= '</table>';
  2371. return $output;
  2372. }
  2373. /**
  2374. * Returns HTML for the modules form.
  2375. *
  2376. * @param $variables
  2377. * An associative array containing:
  2378. * - form: A render element representing the form.
  2379. *
  2380. * @ingroup themeable
  2381. */
  2382. function theme_system_modules_fieldset($variables) {
  2383. $form = $variables['form'];
  2384. // Individual table headers.
  2385. $rows = array();
  2386. // Iterate through all the modules, which are
  2387. // children of this fieldset.
  2388. foreach (element_children($form) as $key) {
  2389. // Stick it into $module for easier accessing.
  2390. $module = $form[$key];
  2391. $row = array();
  2392. unset($module['enable']['#title']);
  2393. $row[] = array('class' => array('checkbox'), 'data' => drupal_render($module['enable']));
  2394. $label = '<label';
  2395. if (isset($module['enable']['#id'])) {
  2396. $label .= ' for="' . $module['enable']['#id'] . '"';
  2397. }
  2398. $row[] = $label . '><strong>' . drupal_render($module['name']) . '</strong></label>';
  2399. $row[] = drupal_render($module['version']);
  2400. // Add the description, along with any modules it requires.
  2401. $description = drupal_render($module['description']);
  2402. if ($module['#requires']) {
  2403. $description .= '<div class="admin-requirements">' . t('Requires: !module-list', array('!module-list' => implode(', ', $module['#requires']))) . '</div>';
  2404. }
  2405. if ($module['#required_by']) {
  2406. $description .= '<div class="admin-requirements">' . t('Required by: !module-list', array('!module-list' => implode(', ', $module['#required_by']))) . '</div>';
  2407. }
  2408. $row[] = array('data' => $description, 'class' => array('description'));
  2409. // Display links (such as help or permissions) in their own columns.
  2410. foreach (array('help', 'permissions', 'configure') as $key) {
  2411. $row[] = array('data' => drupal_render($module['links'][$key]), 'class' => array($key));
  2412. }
  2413. $rows[] = $row;
  2414. }
  2415. return theme('table', array('header' => $form['#header'], 'rows' => $rows));
  2416. }
  2417. /**
  2418. * Returns HTML for a message about incompatible modules.
  2419. *
  2420. * @param $variables
  2421. * An associative array containing:
  2422. * - message: The form array representing the currently disabled modules.
  2423. *
  2424. * @ingroup themeable
  2425. */
  2426. function theme_system_modules_incompatible($variables) {
  2427. return '<div class="incompatible">' . $variables['message'] . '</div>';
  2428. }
  2429. /**
  2430. * Returns HTML for a table of currently disabled modules.
  2431. *
  2432. * @param $variables
  2433. * An associative array containing:
  2434. * - form: A render element representing the form.
  2435. *
  2436. * @ingroup themeable
  2437. */
  2438. function theme_system_modules_uninstall($variables) {
  2439. $form = $variables['form'];
  2440. // No theming for the confirm form.
  2441. if (isset($form['confirm'])) {
  2442. return drupal_render($form);
  2443. }
  2444. // Table headers.
  2445. $header = array(t('Uninstall'),
  2446. t('Name'),
  2447. t('Description'),
  2448. );
  2449. // Display table.
  2450. $rows = array();
  2451. foreach (element_children($form['modules']) as $module) {
  2452. if (!empty($form['modules'][$module]['#required_by'])) {
  2453. $disabled_message = format_plural(count($form['modules'][$module]['#required_by']),
  2454. 'To uninstall @module, the following module must be uninstalled first: @required_modules',
  2455. 'To uninstall @module, the following modules must be uninstalled first: @required_modules',
  2456. array('@module' => $form['modules'][$module]['#module_name'], '@required_modules' => implode(', ', $form['modules'][$module]['#required_by'])));
  2457. $disabled_message = '<div class="admin-requirements">' . $disabled_message . '</div>';
  2458. }
  2459. else {
  2460. $disabled_message = '';
  2461. }
  2462. $rows[] = array(
  2463. array('data' => drupal_render($form['uninstall'][$module]), 'align' => 'center'),
  2464. '<strong><label for="' . $form['uninstall'][$module]['#id'] . '">' . drupal_render($form['modules'][$module]['name']) . '</label></strong>',
  2465. array('data' => drupal_render($form['modules'][$module]['description']) . $disabled_message, 'class' => array('description')),
  2466. );
  2467. }
  2468. $output = theme('table', array('header' => $header, 'rows' => $rows, 'empty' => t('No modules are available to uninstall.')));
  2469. $output .= drupal_render_children($form);
  2470. return $output;
  2471. }
  2472. /**
  2473. * Returns HTML for the Appearance page.
  2474. *
  2475. * @param $variables
  2476. * An associative array containing:
  2477. * - theme_groups: An associative array containing groups of themes.
  2478. *
  2479. * @ingroup themeable
  2480. */
  2481. function theme_system_themes_page($variables) {
  2482. $theme_groups = $variables['theme_groups'];
  2483. $output = '<div id="system-themes-page">';
  2484. foreach ($variables['theme_group_titles'] as $state => $title) {
  2485. if (!count($theme_groups[$state])) {
  2486. // Skip this group of themes if no theme is there.
  2487. continue;
  2488. }
  2489. // Start new theme group.
  2490. $output .= '<div class="system-themes-list system-themes-list-'. $state .' clearfix"><h2>'. $title .'</h2>';
  2491. foreach ($theme_groups[$state] as $theme) {
  2492. // Theme the screenshot.
  2493. $screenshot = $theme->screenshot ? theme('image', $theme->screenshot) : '<div class="no-screenshot">' . t('no screenshot') . '</div>';
  2494. // Localize the theme description.
  2495. $description = t($theme->info['description']);
  2496. // Style theme info
  2497. $notes = count($theme->notes) ? ' (' . join(', ', $theme->notes) . ')' : '';
  2498. $theme->classes[] = 'theme-selector';
  2499. $theme->classes[] = 'clearfix';
  2500. $output .= '<div class="'. join(' ', $theme->classes) .'">' . $screenshot . '<div class="theme-info"><h3>' . $theme->info['name'] . ' ' . (isset($theme->info['version']) ? $theme->info['version'] : '') . $notes . '</h3><div class="theme-description">' . $description . '</div>';
  2501. // Make sure to provide feedback on compatibility.
  2502. if (!empty($theme->incompatible_core)) {
  2503. $output .= '<div class="incompatible">' . t('This version is not compatible with Drupal !core_version and should be replaced.', array('!core_version' => DRUPAL_CORE_COMPATIBILITY)) . '</div>';
  2504. }
  2505. elseif (!empty($theme->incompatible_php)) {
  2506. if (substr_count($theme->info['php'], '.') < 2) {
  2507. $theme->info['php'] .= '.*';
  2508. }
  2509. $output .= '<div class="incompatible">' . t('This theme requires PHP version @php_required and is incompatible with PHP version !php_version.', array('@php_required' => $theme->info['php'], '!php_version' => phpversion())) . '</div>';
  2510. }
  2511. else {
  2512. $output .= theme('links', array('links' => $theme->operations, 'attributes' => array('class' => array('operations', 'clearfix'))));
  2513. }
  2514. $output .= '</div></div>';
  2515. }
  2516. $output .= '</div>';
  2517. }
  2518. $output .= '</div>';
  2519. return $output;
  2520. }
  2521. /**
  2522. * Menu callback; present a form for deleting a date format.
  2523. */
  2524. function system_date_delete_format_form($form, &$form_state, $dfid) {
  2525. $form['dfid'] = array(
  2526. '#type' => 'value',
  2527. '#value' => $dfid,
  2528. );
  2529. $format = system_get_date_format($dfid);
  2530. $output = confirm_form($form,
  2531. t('Are you sure you want to remove the format %format?', array('%format' => format_date(REQUEST_TIME, 'custom', $format->format))),
  2532. 'admin/config/regional/date-time/formats',
  2533. t('This action cannot be undone.'),
  2534. t('Remove'), t('Cancel'),
  2535. 'confirm'
  2536. );
  2537. return $output;
  2538. }
  2539. /**
  2540. * Delete a configured date format.
  2541. */
  2542. function system_date_delete_format_form_submit($form, &$form_state) {
  2543. if ($form_state['values']['confirm']) {
  2544. $format = system_get_date_format($form_state['values']['dfid']);
  2545. system_date_format_delete($form_state['values']['dfid']);
  2546. drupal_set_message(t('Removed date format %format.', array('%format' => format_date(REQUEST_TIME, 'custom', $format->format))));
  2547. $form_state['redirect'] = 'admin/config/regional/date-time/formats';
  2548. }
  2549. }
  2550. /**
  2551. * Menu callback; present a form for deleting a date type.
  2552. */
  2553. function system_delete_date_format_type_form($form, &$form_state, $format_type) {
  2554. $form['format_type'] = array(
  2555. '#type' => 'value',
  2556. '#value' => $format_type,
  2557. );
  2558. $type_info = system_get_date_types($format_type);
  2559. $output = confirm_form($form,
  2560. t('Are you sure you want to remove the date type %type?', array('%type' => $type_info['title'])),
  2561. 'admin/config/regional/date-time',
  2562. t('This action cannot be undone.'),
  2563. t('Remove'), t('Cancel'),
  2564. 'confirm'
  2565. );
  2566. return $output;
  2567. }
  2568. /**
  2569. * Delete a configured date type.
  2570. */
  2571. function system_delete_date_format_type_form_submit($form, &$form_state) {
  2572. if ($form_state['values']['confirm']) {
  2573. $type_info = system_get_date_types($form_state['values']['format_type']);
  2574. system_date_format_type_delete($form_state['values']['format_type']);
  2575. drupal_set_message(t('Removed date type %type.', array('%type' => $type_info['title'])));
  2576. $form_state['redirect'] = 'admin/config/regional/date-time';
  2577. }
  2578. }
  2579. /**
  2580. * Displays the date format strings overview page.
  2581. */
  2582. function system_date_time_formats() {
  2583. $header = array(t('Format'), array('data' => t('Operations'), 'colspan' => '2'));
  2584. $rows = array();
  2585. drupal_static_reset('system_get_date_formats');
  2586. $formats = system_get_date_formats('custom');
  2587. if (!empty($formats)) {
  2588. foreach ($formats as $format) {
  2589. $row = array();
  2590. $row[] = array('data' => format_date(REQUEST_TIME, 'custom', $format['format']));
  2591. $row[] = array('data' => l(t('edit'), 'admin/config/regional/date-time/formats/' . $format['dfid'] . '/edit'));
  2592. $row[] = array('data' => l(t('delete'), 'admin/config/regional/date-time/formats/' . $format['dfid'] . '/delete'));
  2593. $rows[] = $row;
  2594. }
  2595. }
  2596. $build['date_formats_table'] = array(
  2597. '#theme' => 'table',
  2598. '#header' => $header,
  2599. '#rows' => $rows,
  2600. '#empty' => t('No custom date formats available. <a href="@link">Add date format</a>.', array('@link' => url('admin/config/regional/date-time/formats/add'))),
  2601. );
  2602. return $build;
  2603. }
  2604. /**
  2605. * Allow users to add additional date formats.
  2606. */
  2607. function system_configure_date_formats_form($form, &$form_state, $dfid = 0) {
  2608. $js_settings = array(
  2609. 'type' => 'setting',
  2610. 'data' => array(
  2611. 'dateTime' => array(
  2612. 'date-format' => array(
  2613. 'text' => t('Displayed as'),
  2614. 'lookup' => url('admin/config/regional/date-time/formats/lookup'),
  2615. ),
  2616. ),
  2617. ),
  2618. );
  2619. if ($dfid) {
  2620. $form['dfid'] = array(
  2621. '#type' => 'value',
  2622. '#value' => $dfid,
  2623. );
  2624. $format = system_get_date_format($dfid);
  2625. }
  2626. $now = ($dfid ? t('Displayed as %date', array('%date' => format_date(REQUEST_TIME, 'custom', $format->format))) : '');
  2627. $form['date_format'] = array(
  2628. '#type' => 'textfield',
  2629. '#title' => t('Format string'),
  2630. '#maxlength' => 100,
  2631. '#description' => t('A user-defined date format. See the <a href="@url">PHP manual</a> for available options.', array('@url' => 'http://php.net/manual/function.date.php')),
  2632. '#default_value' => ($dfid ? $format->format : ''),
  2633. '#field_suffix' => ' <small id="edit-date-format-suffix">' . $now . '</small>',
  2634. '#attached' => array(
  2635. 'js' => array(drupal_get_path('module', 'system') . '/system.js', $js_settings),
  2636. ),
  2637. '#required' => TRUE,
  2638. );
  2639. $form['actions'] = array('#type' => 'actions');
  2640. $form['actions']['update'] = array(
  2641. '#type' => 'submit',
  2642. '#value' => ($dfid ? t('Save format') : t('Add format')),
  2643. );
  2644. $form['#validate'][] = 'system_add_date_formats_form_validate';
  2645. $form['#submit'][] = 'system_add_date_formats_form_submit';
  2646. return $form;
  2647. }
  2648. /**
  2649. * Validate new date format string submission.
  2650. */
  2651. function system_add_date_formats_form_validate($form, &$form_state) {
  2652. $formats = system_get_date_formats('custom');
  2653. $format = trim($form_state['values']['date_format']);
  2654. if (!empty($formats) && in_array($format, array_keys($formats)) && (!isset($form_state['values']['dfid']) || $form_state['values']['dfid'] != $formats[$format]['dfid'])) {
  2655. form_set_error('date_format', t('This format already exists. Enter a unique format string.'));
  2656. }
  2657. }
  2658. /**
  2659. * Process new date format string submission.
  2660. */
  2661. function system_add_date_formats_form_submit($form, &$form_state) {
  2662. $format = array();
  2663. $format['format'] = trim($form_state['values']['date_format']);
  2664. $format['type'] = 'custom';
  2665. $format['locked'] = 0;
  2666. if (!empty($form_state['values']['dfid'])) {
  2667. system_date_format_save($format, $form_state['values']['dfid']);
  2668. drupal_set_message(t('Custom date format updated.'));
  2669. }
  2670. else {
  2671. $format['is_new'] = 1;
  2672. system_date_format_save($format);
  2673. drupal_set_message(t('Custom date format added.'));
  2674. }
  2675. $form_state['redirect'] = 'admin/config/regional/date-time/formats';
  2676. }
  2677. /**
  2678. * Menu callback; Displays an overview of available and configured actions.
  2679. */
  2680. function system_actions_manage() {
  2681. actions_synchronize();
  2682. $actions = actions_list();
  2683. $actions_map = actions_actions_map($actions);
  2684. $options = array();
  2685. $unconfigurable = array();
  2686. foreach ($actions_map as $key => $array) {
  2687. if ($array['configurable']) {
  2688. $options[$key] = $array['label'] . '...';
  2689. }
  2690. else {
  2691. $unconfigurable[] = $array;
  2692. }
  2693. }
  2694. $row = array();
  2695. $instances_present = db_query("SELECT aid FROM {actions} WHERE parameters <> ''")->fetchField();
  2696. $header = array(
  2697. array('data' => t('Action type'), 'field' => 'type'),
  2698. array('data' => t('Label'), 'field' => 'label'),
  2699. array('data' => $instances_present ? t('Operations') : '', 'colspan' => '2')
  2700. );
  2701. $query = db_select('actions')->extend('PagerDefault')->extend('TableSort');
  2702. $result = $query
  2703. ->fields('actions')
  2704. ->limit(50)
  2705. ->orderByHeader($header)
  2706. ->execute();
  2707. foreach ($result as $action) {
  2708. $row[] = array(
  2709. array('data' => $action->type),
  2710. array('data' => check_plain($action->label)),
  2711. array('data' => $action->parameters ? l(t('configure'), "admin/config/system/actions/configure/$action->aid") : ''),
  2712. array('data' => $action->parameters ? l(t('delete'), "admin/config/system/actions/delete/$action->aid") : '')
  2713. );
  2714. }
  2715. if ($row) {
  2716. $pager = theme('pager');
  2717. if (!empty($pager)) {
  2718. $row[] = array(array('data' => $pager, 'colspan' => '3'));
  2719. }
  2720. $build['system_actions_header'] = array('#markup' => '<h3>' . t('Available actions:') . '</h3>');
  2721. $build['system_actions_table'] = array('#markup' => theme('table', array('header' => $header, 'rows' => $row)));
  2722. }
  2723. if ($actions_map) {
  2724. $build['system_actions_manage_form'] = drupal_get_form('system_actions_manage_form', $options);
  2725. }
  2726. return $build;
  2727. }
  2728. /**
  2729. * Define the form for the actions overview page.
  2730. *
  2731. * @param $form_state
  2732. * An associative array containing the current state of the form; not used.
  2733. * @param $options
  2734. * An array of configurable actions.
  2735. * @return
  2736. * Form definition.
  2737. *
  2738. * @ingroup forms
  2739. * @see system_actions_manage_form_submit()
  2740. */
  2741. function system_actions_manage_form($form, &$form_state, $options = array()) {
  2742. $form['parent'] = array(
  2743. '#type' => 'fieldset',
  2744. '#title' => t('Create an advanced action'),
  2745. '#attributes' => array('class' => array('container-inline')),
  2746. );
  2747. $form['parent']['action'] = array(
  2748. '#type' => 'select',
  2749. '#title' => t('Action'),
  2750. '#title_display' => 'invisible',
  2751. '#options' => $options,
  2752. '#empty_option' => t('Choose an advanced action'),
  2753. );
  2754. $form['parent']['actions'] = array('#type' => 'actions');
  2755. $form['parent']['actions']['submit'] = array(
  2756. '#type' => 'submit',
  2757. '#value' => t('Create'),
  2758. );
  2759. return $form;
  2760. }
  2761. /**
  2762. * Process system_actions_manage form submissions.
  2763. *
  2764. * @see system_actions_manage_form()
  2765. */
  2766. function system_actions_manage_form_submit($form, &$form_state) {
  2767. if ($form_state['values']['action']) {
  2768. $form_state['redirect'] = 'admin/config/system/actions/configure/' . $form_state['values']['action'];
  2769. }
  2770. }
  2771. /**
  2772. * Menu callback; Creates the form for configuration of a single action.
  2773. *
  2774. * We provide the "Description" field. The rest of the form is provided by the
  2775. * action. We then provide the Save button. Because we are combining unknown
  2776. * form elements with the action configuration form, we use an 'actions_' prefix
  2777. * on our elements.
  2778. *
  2779. * @param $action
  2780. * Hash of an action ID or an integer. If it is a hash, we are
  2781. * creating a new instance. If it is an integer, we are editing an existing
  2782. * instance.
  2783. * @return
  2784. * A form definition.
  2785. *
  2786. * @see system_actions_configure_validate()
  2787. * @see system_actions_configure_submit()
  2788. */
  2789. function system_actions_configure($form, &$form_state, $action = NULL) {
  2790. if ($action === NULL) {
  2791. drupal_goto('admin/config/system/actions');
  2792. }
  2793. $actions_map = actions_actions_map(actions_list());
  2794. $edit = array();
  2795. // Numeric action denotes saved instance of a configurable action.
  2796. if (is_numeric($action)) {
  2797. $aid = $action;
  2798. // Load stored parameter values from database.
  2799. $data = db_query("SELECT * FROM {actions} WHERE aid = :aid", array(':aid' => $aid))->fetch();
  2800. $edit['actions_label'] = $data->label;
  2801. $edit['actions_type'] = $data->type;
  2802. $function = $data->callback;
  2803. $action = drupal_hash_base64($data->callback);
  2804. $params = unserialize($data->parameters);
  2805. if ($params) {
  2806. foreach ($params as $name => $val) {
  2807. $edit[$name] = $val;
  2808. }
  2809. }
  2810. }
  2811. // Otherwise, we are creating a new action instance.
  2812. else {
  2813. $function = $actions_map[$action]['callback'];
  2814. $edit['actions_label'] = $actions_map[$action]['label'];
  2815. $edit['actions_type'] = $actions_map[$action]['type'];
  2816. }
  2817. $form['actions_label'] = array(
  2818. '#type' => 'textfield',
  2819. '#title' => t('Label'),
  2820. '#default_value' => $edit['actions_label'],
  2821. '#maxlength' => '255',
  2822. '#description' => t('A unique label for this advanced action. This label will be displayed in the interface of modules that integrate with actions, such as Trigger module.'),
  2823. '#weight' => -10
  2824. );
  2825. $action_form = $function . '_form';
  2826. $form = array_merge($form, $action_form($edit));
  2827. $form['actions_type'] = array(
  2828. '#type' => 'value',
  2829. '#value' => $edit['actions_type'],
  2830. );
  2831. $form['actions_action'] = array(
  2832. '#type' => 'hidden',
  2833. '#value' => $action,
  2834. );
  2835. // $aid is set when configuring an existing action instance.
  2836. if (isset($aid)) {
  2837. $form['actions_aid'] = array(
  2838. '#type' => 'hidden',
  2839. '#value' => $aid,
  2840. );
  2841. }
  2842. $form['actions_configured'] = array(
  2843. '#type' => 'hidden',
  2844. '#value' => '1',
  2845. );
  2846. $form['actions'] = array('#type' => 'actions');
  2847. $form['actions']['submit'] = array(
  2848. '#type' => 'submit',
  2849. '#value' => t('Save'),
  2850. '#weight' => 13
  2851. );
  2852. return $form;
  2853. }
  2854. /**
  2855. * Validate system_actions_configure() form submissions.
  2856. */
  2857. function system_actions_configure_validate($form, &$form_state) {
  2858. $function = actions_function_lookup($form_state['values']['actions_action']) . '_validate';
  2859. // Hand off validation to the action.
  2860. if (function_exists($function)) {
  2861. $function($form, $form_state);
  2862. }
  2863. }
  2864. /**
  2865. * Process system_actions_configure() form submissions.
  2866. */
  2867. function system_actions_configure_submit($form, &$form_state) {
  2868. $function = actions_function_lookup($form_state['values']['actions_action']);
  2869. $submit_function = $function . '_submit';
  2870. // Action will return keyed array of values to store.
  2871. $params = $submit_function($form, $form_state);
  2872. $aid = isset($form_state['values']['actions_aid']) ? $form_state['values']['actions_aid'] : NULL;
  2873. actions_save($function, $form_state['values']['actions_type'], $params, $form_state['values']['actions_label'], $aid);
  2874. drupal_set_message(t('The action has been successfully saved.'));
  2875. $form_state['redirect'] = 'admin/config/system/actions/manage';
  2876. }
  2877. /**
  2878. * Create the form for confirmation of deleting an action.
  2879. *
  2880. * @see system_actions_delete_form_submit()
  2881. * @ingroup forms
  2882. */
  2883. function system_actions_delete_form($form, &$form_state, $action) {
  2884. $form['aid'] = array(
  2885. '#type' => 'hidden',
  2886. '#value' => $action->aid,
  2887. );
  2888. return confirm_form($form,
  2889. t('Are you sure you want to delete the action %action?', array('%action' => $action->label)),
  2890. 'admin/config/system/actions/manage',
  2891. t('This cannot be undone.'),
  2892. t('Delete'),
  2893. t('Cancel')
  2894. );
  2895. }
  2896. /**
  2897. * Process system_actions_delete form submissions.
  2898. *
  2899. * Post-deletion operations for action deletion.
  2900. */
  2901. function system_actions_delete_form_submit($form, &$form_state) {
  2902. $aid = $form_state['values']['aid'];
  2903. $action = actions_load($aid);
  2904. actions_delete($aid);
  2905. watchdog('user', 'Deleted action %aid (%action)', array('%aid' => $aid, '%action' => $action->label));
  2906. drupal_set_message(t('Action %action was deleted', array('%action' => $action->label)));
  2907. $form_state['redirect'] = 'admin/config/system/actions/manage';
  2908. }
  2909. /**
  2910. * Post-deletion operations for deleting action orphans.
  2911. *
  2912. * @param $orphaned
  2913. * An array of orphaned actions.
  2914. */
  2915. function system_action_delete_orphans_post($orphaned) {
  2916. foreach ($orphaned as $callback) {
  2917. drupal_set_message(t("Deleted orphaned action (%action).", array('%action' => $callback)));
  2918. }
  2919. }
  2920. /**
  2921. * Remove actions that are in the database but not supported by any enabled module.
  2922. */
  2923. function system_actions_remove_orphans() {
  2924. actions_synchronize(TRUE);
  2925. drupal_goto('admin/config/system/actions/manage');
  2926. }