system.admin.inc 113 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213
  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 drupal_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 drupal_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 drupal_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 ($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 ($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 ($file = $values['logo_upload']) {
  649. unset($values['logo_upload']);
  650. $filename = file_unmanaged_copy($file->uri);
  651. $values['default_logo'] = 0;
  652. $values['logo_path'] = $filename;
  653. $values['toggle_logo'] = 1;
  654. }
  655. if ($file = $values['favicon_upload']) {
  656. unset($values['favicon_upload']);
  657. $filename = file_unmanaged_copy($file->uri);
  658. $values['default_favicon'] = 0;
  659. $values['favicon_path'] = $filename;
  660. $values['toggle_favicon'] = 1;
  661. }
  662. // If the user entered a path relative to the system files directory for
  663. // a logo or favicon, store a public:// URI so the theme system can handle it.
  664. if (!empty($values['logo_path'])) {
  665. $values['logo_path'] = _system_theme_settings_validate_path($values['logo_path']);
  666. }
  667. if (!empty($values['favicon_path'])) {
  668. $values['favicon_path'] = _system_theme_settings_validate_path($values['favicon_path']);
  669. }
  670. if (empty($values['default_favicon']) && !empty($values['favicon_path'])) {
  671. $values['favicon_mimetype'] = file_get_mimetype($values['favicon_path']);
  672. }
  673. variable_set($key, $values);
  674. drupal_set_message(t('The configuration options have been saved.'));
  675. cache_clear_all();
  676. }
  677. /**
  678. * Recursively check compatibility.
  679. *
  680. * @param $incompatible
  681. * An associative array which at the end of the check contains all
  682. * incompatible files as the keys, their values being TRUE.
  683. * @param $files
  684. * The set of files that will be tested.
  685. * @param $file
  686. * The file at which the check starts.
  687. * @return
  688. * Returns TRUE if an incompatible file is found, NULL (no return value)
  689. * otherwise.
  690. */
  691. function _system_is_incompatible(&$incompatible, $files, $file) {
  692. if (isset($incompatible[$file->name])) {
  693. return TRUE;
  694. }
  695. // Recursively traverse required modules, looking for incompatible modules.
  696. foreach ($file->requires as $requires) {
  697. if (isset($files[$requires]) && _system_is_incompatible($incompatible, $files, $files[$requires])) {
  698. $incompatible[$file->name] = TRUE;
  699. return TRUE;
  700. }
  701. }
  702. }
  703. /**
  704. * Menu callback; provides module enable/disable interface.
  705. *
  706. * The list of modules gets populated by module.info files, which contain each
  707. * module's name, description, and information about which modules it requires.
  708. * See drupal_parse_info_file() for information on module.info descriptors.
  709. *
  710. * Dependency checking is performed to ensure that a module:
  711. * - can not be enabled if there are disabled modules it requires.
  712. * - can not be disabled if there are enabled modules which depend on it.
  713. *
  714. * @param $form_state
  715. * An associative array containing the current state of the form.
  716. *
  717. * @return
  718. * The form array.
  719. *
  720. * @ingroup forms
  721. * @see theme_system_modules()
  722. * @see system_modules_submit()
  723. */
  724. function system_modules($form, $form_state = array()) {
  725. // Get current list of modules.
  726. $files = system_rebuild_module_data();
  727. // Remove hidden modules from display list.
  728. $visible_files = $files;
  729. foreach ($visible_files as $filename => $file) {
  730. if (!empty($file->info['hidden'])) {
  731. unset($visible_files[$filename]);
  732. }
  733. }
  734. uasort($visible_files, 'system_sort_modules_by_info_name');
  735. // If the modules form was submitted, then system_modules_submit() runs first
  736. // and if there are unfilled required modules, then $form_state['storage'] is
  737. // filled, triggering a rebuild. In this case we need to display a
  738. // confirmation form.
  739. if (!empty($form_state['storage'])) {
  740. return system_modules_confirm_form($visible_files, $form_state['storage']);
  741. }
  742. $modules = array();
  743. $form['modules'] = array('#tree' => TRUE);
  744. // Used when checking if module implements a help page.
  745. $help_arg = module_exists('help') ? drupal_help_arg() : FALSE;
  746. // Used when displaying modules that are required by the installation profile.
  747. require_once DRUPAL_ROOT . '/includes/install.inc';
  748. $distribution_name = check_plain(drupal_install_profile_distribution_name());
  749. // Iterate through each of the modules.
  750. foreach ($visible_files as $filename => $module) {
  751. $extra = array();
  752. $extra['enabled'] = (bool) $module->status;
  753. if (!empty($module->info['required'] )) {
  754. $extra['disabled'] = TRUE;
  755. $extra['required_by'][] = $distribution_name . (!empty($module->info['explanation']) ? ' ('. $module->info['explanation'] .')' : '');
  756. }
  757. // If this module requires other modules, add them to the array.
  758. foreach ($module->requires as $requires => $v) {
  759. if (!isset($files[$requires])) {
  760. $extra['requires'][$requires] = t('@module (<span class="admin-missing">missing</span>)', array('@module' => drupal_ucfirst($requires)));
  761. $extra['disabled'] = TRUE;
  762. }
  763. // Only display visible modules.
  764. elseif (isset($visible_files[$requires])) {
  765. $requires_name = $files[$requires]->info['name'];
  766. // Disable this module if it is incompatible with the dependency's version.
  767. if ($incompatible_version = drupal_check_incompatibility($v, str_replace(DRUPAL_CORE_COMPATIBILITY . '-', '', $files[$requires]->info['version']))) {
  768. $extra['requires'][$requires] = t('@module (<span class="admin-missing">incompatible with</span> version @version)', array(
  769. '@module' => $requires_name . $incompatible_version,
  770. '@version' => $files[$requires]->info['version'],
  771. ));
  772. $extra['disabled'] = TRUE;
  773. }
  774. // Disable this module if the dependency is incompatible with this
  775. // version of Drupal core.
  776. elseif ($files[$requires]->info['core'] != DRUPAL_CORE_COMPATIBILITY) {
  777. $extra['requires'][$requires] = t('@module (<span class="admin-missing">incompatible with</span> this version of Drupal core)', array(
  778. '@module' => $requires_name,
  779. ));
  780. $extra['disabled'] = TRUE;
  781. }
  782. elseif ($files[$requires]->status) {
  783. $extra['requires'][$requires] = t('@module (<span class="admin-enabled">enabled</span>)', array('@module' => $requires_name));
  784. }
  785. else {
  786. $extra['requires'][$requires] = t('@module (<span class="admin-disabled">disabled</span>)', array('@module' => $requires_name));
  787. }
  788. }
  789. }
  790. // Generate link for module's help page, if there is one.
  791. if ($help_arg && $module->status && in_array($filename, module_implements('help'))) {
  792. if (module_invoke($filename, 'help', "admin/help#$filename", $help_arg)) {
  793. $extra['links']['help'] = array(
  794. '#type' => 'link',
  795. '#title' => t('Help'),
  796. '#href' => "admin/help/$filename",
  797. '#options' => array('attributes' => array('class' => array('module-link', 'module-link-help'), 'title' => t('Help'))),
  798. );
  799. }
  800. }
  801. // Generate link for module's permission, if the user has access to it.
  802. if ($module->status && user_access('administer permissions') && in_array($filename, module_implements('permission'))) {
  803. $extra['links']['permissions'] = array(
  804. '#type' => 'link',
  805. '#title' => t('Permissions'),
  806. '#href' => 'admin/people/permissions',
  807. '#options' => array('fragment' => 'module-' . $filename, 'attributes' => array('class' => array('module-link', 'module-link-permissions'), 'title' => t('Configure permissions'))),
  808. );
  809. }
  810. // Generate link for module's configuration page, if the module provides
  811. // one.
  812. if ($module->status && isset($module->info['configure'])) {
  813. $configure_link = menu_get_item($module->info['configure']);
  814. if ($configure_link['access']) {
  815. $extra['links']['configure'] = array(
  816. '#type' => 'link',
  817. '#title' => t('Configure'),
  818. '#href' => $configure_link['href'],
  819. '#options' => array('attributes' => array('class' => array('module-link', 'module-link-configure'), 'title' => $configure_link['description'])),
  820. );
  821. }
  822. }
  823. // If this module is required by other modules, list those, and then make it
  824. // impossible to disable this one.
  825. foreach ($module->required_by as $required_by => $v) {
  826. // Hidden modules are unset already.
  827. if (isset($visible_files[$required_by])) {
  828. if ($files[$required_by]->status == 1 && $module->status == 1) {
  829. $extra['required_by'][] = t('@module (<span class="admin-enabled">enabled</span>)', array('@module' => $files[$required_by]->info['name']));
  830. $extra['disabled'] = TRUE;
  831. }
  832. else {
  833. $extra['required_by'][] = t('@module (<span class="admin-disabled">disabled</span>)', array('@module' => $files[$required_by]->info['name']));
  834. }
  835. }
  836. }
  837. $form['modules'][$module->info['package']][$filename] = _system_modules_build_row($module->info, $extra);
  838. }
  839. // Add basic information to the fieldsets.
  840. foreach (element_children($form['modules']) as $package) {
  841. $form['modules'][$package] += array(
  842. '#type' => 'fieldset',
  843. '#title' => t($package),
  844. '#collapsible' => TRUE,
  845. '#theme' => 'system_modules_fieldset',
  846. '#header' => array(
  847. array('data' => t('Enabled'), 'class' => array('checkbox')),
  848. t('Name'),
  849. t('Version'),
  850. t('Description'),
  851. array('data' => t('Operations'), 'colspan' => 3),
  852. ),
  853. // Ensure that the "Core" package fieldset comes first.
  854. '#weight' => $package == 'Core' ? -10 : NULL,
  855. );
  856. }
  857. // Lastly, sort all fieldsets by title.
  858. uasort($form['modules'], 'element_sort_by_title');
  859. $form['actions'] = array('#type' => 'actions');
  860. $form['actions']['submit'] = array(
  861. '#type' => 'submit',
  862. '#value' => t('Save configuration'),
  863. );
  864. $form['#action'] = url('admin/modules/list/confirm');
  865. return $form;
  866. }
  867. /**
  868. * Array sorting callback; sorts modules or themes by their name.
  869. */
  870. function system_sort_modules_by_info_name($a, $b) {
  871. return strcasecmp($a->info['name'], $b->info['name']);
  872. }
  873. /**
  874. * Array sorting callback; sorts modules or themes by their name.
  875. */
  876. function system_sort_themes($a, $b) {
  877. if ($a->is_default) {
  878. return -1;
  879. }
  880. if ($b->is_default) {
  881. return 1;
  882. }
  883. return strcasecmp($a->info['name'], $b->info['name']);
  884. }
  885. /**
  886. * Build a table row for the system modules page.
  887. */
  888. function _system_modules_build_row($info, $extra) {
  889. // Add in the defaults.
  890. $extra += array(
  891. 'requires' => array(),
  892. 'required_by' => array(),
  893. 'disabled' => FALSE,
  894. 'enabled' => FALSE,
  895. 'links' => array(),
  896. );
  897. $form = array(
  898. '#tree' => TRUE,
  899. );
  900. // Set the basic properties.
  901. $form['name'] = array(
  902. '#markup' => $info['name'],
  903. );
  904. $form['description'] = array(
  905. '#markup' => t($info['description']),
  906. );
  907. $form['version'] = array(
  908. '#markup' => $info['version'],
  909. );
  910. $form['#requires'] = $extra['requires'];
  911. $form['#required_by'] = $extra['required_by'];
  912. // Check the compatibilities.
  913. $compatible = TRUE;
  914. $status_short = '';
  915. $status_long = '';
  916. // Check the core compatibility.
  917. if (!isset($info['core']) || $info['core'] != DRUPAL_CORE_COMPATIBILITY) {
  918. $compatible = FALSE;
  919. $status_short .= t('Incompatible with this version of Drupal core.');
  920. $status_long .= t('This version is not compatible with Drupal !core_version and should be replaced.', array('!core_version' => DRUPAL_CORE_COMPATIBILITY));
  921. }
  922. // Ensure this module is compatible with the currently installed version of PHP.
  923. if (version_compare(phpversion(), $info['php']) < 0) {
  924. $compatible = FALSE;
  925. $status_short .= t('Incompatible with this version of PHP');
  926. $php_required = $info['php'];
  927. if (substr_count($info['php'], '.') < 2) {
  928. $php_required .= '.*';
  929. }
  930. $status_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()));
  931. }
  932. // If this module is compatible, present a checkbox indicating
  933. // this module may be installed. Otherwise, show a big red X.
  934. if ($compatible) {
  935. $form['enable'] = array(
  936. '#type' => 'checkbox',
  937. '#title' => t('Enable'),
  938. '#default_value' => $extra['enabled'],
  939. );
  940. if ($extra['disabled']) {
  941. $form['enable']['#disabled'] = TRUE;
  942. }
  943. }
  944. else {
  945. $form['enable'] = array(
  946. '#markup' => theme('image', array('path' => 'misc/watchdog-error.png', 'alt' => $status_short, 'title' => $status_short)),
  947. );
  948. $form['description']['#markup'] .= theme('system_modules_incompatible', array('message' => $status_long));
  949. }
  950. // Build operation links.
  951. foreach (array('help', 'permissions', 'configure') as $key) {
  952. $form['links'][$key] = (isset($extra['links'][$key]) ? $extra['links'][$key] : array());
  953. }
  954. return $form;
  955. }
  956. /**
  957. * Display confirmation form for required modules.
  958. *
  959. * @param $modules
  960. * Array of module file objects as returned from system_rebuild_module_data().
  961. * @param $storage
  962. * The contents of $form_state['storage']; an array with two
  963. * elements: the list of required modules and the list of status
  964. * form field values from the previous screen.
  965. * @ingroup forms
  966. */
  967. function system_modules_confirm_form($modules, $storage) {
  968. $items = array();
  969. $form['validation_modules'] = array('#type' => 'value', '#value' => $modules);
  970. $form['status']['#tree'] = TRUE;
  971. foreach ($storage['more_required'] as $info) {
  972. $t_argument = array(
  973. '@module' => $info['name'],
  974. '@required' => implode(', ', $info['requires']),
  975. );
  976. $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);
  977. }
  978. foreach ($storage['missing_modules'] as $name => $info) {
  979. $t_argument = array(
  980. '@module' => $name,
  981. '@depends' => implode(', ', $info['depends']),
  982. );
  983. $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);
  984. }
  985. $form['text'] = array('#markup' => theme('item_list', array('items' => $items)));
  986. if ($form) {
  987. // Set some default form values
  988. $form = confirm_form(
  989. $form,
  990. t('Some required modules must be enabled'),
  991. 'admin/modules',
  992. t('Would you like to continue with the above?'),
  993. t('Continue'),
  994. t('Cancel'));
  995. return $form;
  996. }
  997. }
  998. /**
  999. * Submit callback; handles modules form submission.
  1000. */
  1001. function system_modules_submit($form, &$form_state) {
  1002. include_once DRUPAL_ROOT . '/includes/install.inc';
  1003. // Builds list of modules.
  1004. $modules = array();
  1005. // If we're not coming from the confirmation form, build the list of modules.
  1006. if (empty($form_state['storage'])) {
  1007. // If we're not coming from the confirmation form, build the module list.
  1008. foreach ($form_state['values']['modules'] as $group_name => $group) {
  1009. foreach ($group as $module => $enabled) {
  1010. $modules[$module] = array('group' => $group_name, 'enabled' => $enabled['enable']);
  1011. }
  1012. }
  1013. }
  1014. else {
  1015. // If we are coming from the confirmation form, fetch
  1016. // the modules out of $form_state.
  1017. $modules = $form_state['storage']['modules'];
  1018. }
  1019. // Collect data for all modules to be able to determine dependencies.
  1020. $files = system_rebuild_module_data();
  1021. // Sorts modules by weight.
  1022. $sort = array();
  1023. foreach (array_keys($modules) as $module) {
  1024. $sort[$module] = $files[$module]->sort;
  1025. }
  1026. array_multisort($sort, $modules);
  1027. // Makes sure all required modules are set to be enabled.
  1028. $more_required = array();
  1029. $missing_modules = array();
  1030. foreach ($modules as $name => $module) {
  1031. if ($module['enabled']) {
  1032. // Checks that all dependencies are set to be enabled. Stores the ones
  1033. // that are not in $dependencies variable so that the user can be alerted
  1034. // in the confirmation form that more modules need to be enabled.
  1035. $dependencies = array();
  1036. foreach (array_keys($files[$name]->requires) as $required) {
  1037. if (empty($modules[$required]['enabled'])) {
  1038. if (isset($files[$required])) {
  1039. $dependencies[] = $files[$required]->info['name'];
  1040. $modules[$required]['enabled'] = TRUE;
  1041. }
  1042. else {
  1043. $missing_modules[$required]['depends'][] = $name;
  1044. $modules[$name]['enabled'] = FALSE;
  1045. }
  1046. }
  1047. }
  1048. // Stores additional modules that need to be enabled in $more_required.
  1049. if (!empty($dependencies)) {
  1050. $more_required[$name] = array(
  1051. 'name' => $files[$name]->info['name'],
  1052. 'requires' => $dependencies,
  1053. );
  1054. }
  1055. }
  1056. }
  1057. // Redirects to confirmation form if more modules need to be enabled.
  1058. if ((!empty($more_required) || !empty($missing_modules)) && !isset($form_state['values']['confirm'])) {
  1059. $form_state['storage'] = array(
  1060. 'more_required' => $more_required,
  1061. 'modules' => $modules,
  1062. 'missing_modules' => $missing_modules,
  1063. );
  1064. $form_state['rebuild'] = TRUE;
  1065. return;
  1066. }
  1067. // Invokes hook_requirements('install'). If failures are detected, makes sure
  1068. // the dependent modules aren't installed either.
  1069. foreach ($modules as $name => $module) {
  1070. // Only invoke hook_requirements() on modules that are going to be installed.
  1071. if ($module['enabled'] && drupal_get_installed_schema_version($name) == SCHEMA_UNINSTALLED) {
  1072. if (!drupal_check_module($name)) {
  1073. $modules[$name]['enabled'] = FALSE;
  1074. foreach (array_keys($files[$name]->required_by) as $required_by) {
  1075. $modules[$required_by]['enabled'] = FALSE;
  1076. }
  1077. }
  1078. }
  1079. }
  1080. // Initializes array of actions.
  1081. $actions = array(
  1082. 'enable' => array(),
  1083. 'disable' => array(),
  1084. 'install' => array(),
  1085. );
  1086. // Builds arrays of modules that need to be enabled, disabled, and installed.
  1087. foreach ($modules as $name => $module) {
  1088. if ($module['enabled']) {
  1089. if (drupal_get_installed_schema_version($name) == SCHEMA_UNINSTALLED) {
  1090. $actions['install'][] = $name;
  1091. $actions['enable'][] = $name;
  1092. }
  1093. elseif (!module_exists($name)) {
  1094. $actions['enable'][] = $name;
  1095. }
  1096. }
  1097. elseif (module_exists($name)) {
  1098. $actions['disable'][] = $name;
  1099. }
  1100. }
  1101. // Gets list of modules prior to install process, unsets $form_state['storage']
  1102. // so we don't get redirected back to the confirmation form.
  1103. $pre_install_list = module_list();
  1104. unset($form_state['storage']);
  1105. // Reverse the 'enable' list, to order dependencies before dependents.
  1106. krsort($actions['enable']);
  1107. // Installs, enables, and disables modules.
  1108. module_enable($actions['enable'], FALSE);
  1109. module_disable($actions['disable'], FALSE);
  1110. // Gets module list after install process, flushes caches and displays a
  1111. // message if there are changes.
  1112. $post_install_list = module_list(TRUE);
  1113. if ($pre_install_list != $post_install_list) {
  1114. drupal_flush_all_caches();
  1115. drupal_set_message(t('The configuration options have been saved.'));
  1116. }
  1117. $form_state['redirect'] = 'admin/modules';
  1118. }
  1119. /**
  1120. * Uninstall functions
  1121. */
  1122. /**
  1123. * Builds a form of currently disabled modules.
  1124. *
  1125. * @ingroup forms
  1126. * @see system_modules_uninstall_validate()
  1127. * @see system_modules_uninstall_submit()
  1128. * @param $form_state['values']
  1129. * Submitted form values.
  1130. * @return
  1131. * A form array representing the currently disabled modules.
  1132. */
  1133. function system_modules_uninstall($form, $form_state = NULL) {
  1134. // Make sure the install API is available.
  1135. include_once DRUPAL_ROOT . '/includes/install.inc';
  1136. // Display the confirm form if any modules have been submitted.
  1137. if (!empty($form_state['storage']) && $confirm_form = system_modules_uninstall_confirm_form($form_state['storage'])) {
  1138. return $confirm_form;
  1139. }
  1140. // Get a list of disabled, installed modules.
  1141. $all_modules = system_rebuild_module_data();
  1142. $disabled_modules = array();
  1143. foreach ($all_modules as $name => $module) {
  1144. if (empty($module->status) && $module->schema_version > SCHEMA_UNINSTALLED) {
  1145. $disabled_modules[$name] = $module;
  1146. }
  1147. }
  1148. // Only build the rest of the form if there are any modules available to
  1149. // uninstall.
  1150. if (!empty($disabled_modules)) {
  1151. $profile = drupal_get_profile();
  1152. uasort($disabled_modules, 'system_sort_modules_by_info_name');
  1153. $form['uninstall'] = array('#tree' => TRUE);
  1154. foreach ($disabled_modules as $module) {
  1155. $module_name = $module->info['name'] ? $module->info['name'] : $module->name;
  1156. $form['modules'][$module->name]['#module_name'] = $module_name;
  1157. $form['modules'][$module->name]['name']['#markup'] = $module_name;
  1158. $form['modules'][$module->name]['description']['#markup'] = t($module->info['description']);
  1159. $form['uninstall'][$module->name] = array(
  1160. '#type' => 'checkbox',
  1161. '#title' => t('Uninstall @module module', array('@module' => $module_name)),
  1162. '#title_display' => 'invisible',
  1163. );
  1164. // All modules which depend on this one must be uninstalled first, before
  1165. // we can allow this module to be uninstalled. (The installation profile
  1166. // is excluded from this list.)
  1167. foreach (array_keys($module->required_by) as $dependent) {
  1168. if ($dependent != $profile && drupal_get_installed_schema_version($dependent) != SCHEMA_UNINSTALLED) {
  1169. $dependent_name = isset($all_modules[$dependent]->info['name']) ? $all_modules[$dependent]->info['name'] : $dependent;
  1170. $form['modules'][$module->name]['#required_by'][] = $dependent_name;
  1171. $form['uninstall'][$module->name]['#disabled'] = TRUE;
  1172. }
  1173. }
  1174. }
  1175. $form['actions'] = array('#type' => 'actions');
  1176. $form['actions']['submit'] = array(
  1177. '#type' => 'submit',
  1178. '#value' => t('Uninstall'),
  1179. );
  1180. $form['#action'] = url('admin/modules/uninstall/confirm');
  1181. }
  1182. else {
  1183. $form['modules'] = array();
  1184. }
  1185. return $form;
  1186. }
  1187. /**
  1188. * Confirm uninstall of selected modules.
  1189. *
  1190. * @ingroup forms
  1191. * @param $storage
  1192. * An associative array of modules selected to be uninstalled.
  1193. * @return
  1194. * A form array representing modules to confirm.
  1195. */
  1196. function system_modules_uninstall_confirm_form($storage) {
  1197. // Nothing to build.
  1198. if (empty($storage)) {
  1199. return;
  1200. }
  1201. // Construct the hidden form elements and list items.
  1202. foreach (array_filter($storage['uninstall']) as $module => $value) {
  1203. $info = drupal_parse_info_file(drupal_get_path('module', $module) . '/' . $module . '.info');
  1204. $uninstall[] = $info['name'];
  1205. $form['uninstall'][$module] = array('#type' => 'hidden',
  1206. '#value' => 1,
  1207. );
  1208. }
  1209. // Display a confirm form if modules have been selected.
  1210. if (isset($uninstall)) {
  1211. $form['#confirmed'] = TRUE;
  1212. $form['uninstall']['#tree'] = TRUE;
  1213. $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)));
  1214. $form = confirm_form(
  1215. $form,
  1216. t('Confirm uninstall'),
  1217. 'admin/modules/uninstall',
  1218. t('Would you like to continue with uninstalling the above?'),
  1219. t('Uninstall'),
  1220. t('Cancel'));
  1221. return $form;
  1222. }
  1223. }
  1224. /**
  1225. * Validates the submitted uninstall form.
  1226. */
  1227. function system_modules_uninstall_validate($form, &$form_state) {
  1228. // Form submitted, but no modules selected.
  1229. if (!count(array_filter($form_state['values']['uninstall']))) {
  1230. drupal_set_message(t('No modules selected.'), 'error');
  1231. drupal_goto('admin/modules/uninstall');
  1232. }
  1233. }
  1234. /**
  1235. * Processes the submitted uninstall form.
  1236. */
  1237. function system_modules_uninstall_submit($form, &$form_state) {
  1238. // Make sure the install API is available.
  1239. include_once DRUPAL_ROOT . '/includes/install.inc';
  1240. if (!empty($form['#confirmed'])) {
  1241. // Call the uninstall routine for each selected module.
  1242. $modules = array_keys($form_state['values']['uninstall']);
  1243. drupal_uninstall_modules($modules);
  1244. drupal_set_message(t('The selected modules have been uninstalled.'));
  1245. $form_state['redirect'] = 'admin/modules/uninstall';
  1246. }
  1247. else {
  1248. $form_state['storage'] = $form_state['values'];
  1249. $form_state['rebuild'] = TRUE;
  1250. }
  1251. }
  1252. /**
  1253. * Menu callback. Display blocked IP addresses.
  1254. *
  1255. * @param $default_ip
  1256. * Optional IP address to be passed on to drupal_get_form() for
  1257. * use as the default value of the IP address form field.
  1258. */
  1259. function system_ip_blocking($default_ip = '') {
  1260. $rows = array();
  1261. $header = array(t('Blocked IP addresses'), t('Operations'));
  1262. $result = db_query('SELECT * FROM {blocked_ips}');
  1263. foreach ($result as $ip) {
  1264. $rows[] = array(
  1265. $ip->ip,
  1266. l(t('delete'), "admin/config/people/ip-blocking/delete/$ip->iid"),
  1267. );
  1268. }
  1269. $build['system_ip_blocking_form'] = drupal_get_form('system_ip_blocking_form', $default_ip);
  1270. $build['system_ip_blocking_table'] = array(
  1271. '#theme' => 'table',
  1272. '#header' => $header,
  1273. '#rows' => $rows,
  1274. '#empty' => t('No blocked IP addresses available.'),
  1275. );
  1276. return $build;
  1277. }
  1278. /**
  1279. * Define the form for blocking IP addresses.
  1280. *
  1281. * @ingroup forms
  1282. * @see system_ip_blocking_form_validate()
  1283. * @see system_ip_blocking_form_submit()
  1284. */
  1285. function system_ip_blocking_form($form, $form_state, $default_ip) {
  1286. $form['ip'] = array(
  1287. '#title' => t('IP address'),
  1288. '#type' => 'textfield',
  1289. '#size' => 48,
  1290. '#maxlength' => 40,
  1291. '#default_value' => $default_ip,
  1292. '#description' => t('Enter a valid IP address.'),
  1293. );
  1294. $form['actions'] = array('#type' => 'actions');
  1295. $form['actions']['submit'] = array(
  1296. '#type' => 'submit',
  1297. '#value' => t('Add'),
  1298. );
  1299. $form['#submit'][] = 'system_ip_blocking_form_submit';
  1300. $form['#validate'][] = 'system_ip_blocking_form_validate';
  1301. return $form;
  1302. }
  1303. function system_ip_blocking_form_validate($form, &$form_state) {
  1304. $ip = trim($form_state['values']['ip']);
  1305. if (db_query("SELECT * FROM {blocked_ips} WHERE ip = :ip", array(':ip' => $ip))->fetchField()) {
  1306. form_set_error('ip', t('This IP address is already blocked.'));
  1307. }
  1308. elseif ($ip == ip_address()) {
  1309. form_set_error('ip', t('You may not block your own IP address.'));
  1310. }
  1311. elseif (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE) == FALSE) {
  1312. form_set_error('ip', t('Enter a valid IP address.'));
  1313. }
  1314. }
  1315. function system_ip_blocking_form_submit($form, &$form_state) {
  1316. $ip = trim($form_state['values']['ip']);
  1317. db_insert('blocked_ips')
  1318. ->fields(array('ip' => $ip))
  1319. ->execute();
  1320. drupal_set_message(t('The IP address %ip has been blocked.', array('%ip' => $ip)));
  1321. $form_state['redirect'] = 'admin/config/people/ip-blocking';
  1322. return;
  1323. }
  1324. /**
  1325. * IP deletion confirm page.
  1326. *
  1327. * @see system_ip_blocking_delete_submit()
  1328. */
  1329. function system_ip_blocking_delete($form, &$form_state, $iid) {
  1330. $form['blocked_ip'] = array(
  1331. '#type' => 'value',
  1332. '#value' => $iid,
  1333. );
  1334. 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'));
  1335. }
  1336. /**
  1337. * Process system_ip_blocking_delete form submissions.
  1338. */
  1339. function system_ip_blocking_delete_submit($form, &$form_state) {
  1340. $blocked_ip = $form_state['values']['blocked_ip'];
  1341. db_delete('blocked_ips')
  1342. ->condition('iid', $blocked_ip['iid'])
  1343. ->execute();
  1344. watchdog('user', 'Deleted %ip', array('%ip' => $blocked_ip['ip']));
  1345. drupal_set_message(t('The IP address %ip was deleted.', array('%ip' => $blocked_ip['ip'])));
  1346. $form_state['redirect'] = 'admin/config/people/ip-blocking';
  1347. }
  1348. /**
  1349. * Form builder; The general site information form.
  1350. *
  1351. * @ingroup forms
  1352. * @see system_settings_form()
  1353. */
  1354. function system_site_information_settings() {
  1355. $form['site_information'] = array(
  1356. '#type' => 'fieldset',
  1357. '#title' => t('Site details'),
  1358. );
  1359. $form['site_information']['site_name'] = array(
  1360. '#type' => 'textfield',
  1361. '#title' => t('Site name'),
  1362. '#default_value' => variable_get('site_name', 'Drupal'),
  1363. '#required' => TRUE
  1364. );
  1365. $form['site_information']['site_slogan'] = array(
  1366. '#type' => 'textfield',
  1367. '#title' => t('Slogan'),
  1368. '#default_value' => variable_get('site_slogan', ''),
  1369. '#description' => t("How this is used depends on your site's theme."),
  1370. );
  1371. $form['site_information']['site_mail'] = array(
  1372. '#type' => 'textfield',
  1373. '#title' => t('E-mail address'),
  1374. '#default_value' => variable_get('site_mail', ini_get('sendmail_from')),
  1375. '#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.)"),
  1376. '#required' => TRUE,
  1377. );
  1378. $form['front_page'] = array(
  1379. '#type' => 'fieldset',
  1380. '#title' => t('Front page'),
  1381. );
  1382. $form['front_page']['default_nodes_main'] = array(
  1383. '#type' => 'select', '#title' => t('Number of posts on front page'),
  1384. '#default_value' => variable_get('default_nodes_main', 10),
  1385. '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)),
  1386. '#description' => t('The maximum number of posts displayed on overview pages such as the front page.')
  1387. );
  1388. $form['front_page']['site_frontpage'] = array(
  1389. '#type' => 'textfield',
  1390. '#title' => t('Default front page'),
  1391. '#default_value' => (variable_get('site_frontpage')!='node'?drupal_get_path_alias(variable_get('site_frontpage', 'node')):''),
  1392. '#size' => 40,
  1393. '#description' => t('Optionally, specify a relative URL to display as the front page. Leave blank to display the default content feed.'),
  1394. '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='),
  1395. );
  1396. $form['error_page'] = array(
  1397. '#type' => 'fieldset',
  1398. '#title' => t('Error pages'),
  1399. );
  1400. $form['error_page']['site_403'] = array(
  1401. '#type' => 'textfield',
  1402. '#title' => t('Default 403 (access denied) page'),
  1403. '#default_value' => variable_get('site_403', ''),
  1404. '#size' => 40,
  1405. '#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.'),
  1406. '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q=')
  1407. );
  1408. $form['error_page']['site_404'] = array(
  1409. '#type' => 'textfield',
  1410. '#title' => t('Default 404 (not found) page'),
  1411. '#default_value' => variable_get('site_404', ''),
  1412. '#size' => 40,
  1413. '#description' => t('This page is displayed when no other content matches the requested document. Leave blank to display a generic "page not found" page.'),
  1414. '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q=')
  1415. );
  1416. $form['#validate'][] = 'system_site_information_settings_validate';
  1417. return system_settings_form($form);
  1418. }
  1419. /**
  1420. * Validates the submitted site-information form.
  1421. */
  1422. function system_site_information_settings_validate($form, &$form_state) {
  1423. // Validate the e-mail address.
  1424. if ($error = user_validate_mail($form_state['values']['site_mail'])) {
  1425. form_set_error('site_mail', $error);
  1426. }
  1427. // Check for empty front page path.
  1428. if (empty($form_state['values']['site_frontpage'])) {
  1429. // Set to default "node".
  1430. form_set_value($form['front_page']['site_frontpage'], 'node', $form_state);
  1431. }
  1432. else {
  1433. // Get the normal path of the front page.
  1434. form_set_value($form['front_page']['site_frontpage'], drupal_get_normal_path($form_state['values']['site_frontpage']), $form_state);
  1435. }
  1436. // Validate front page path.
  1437. if (!drupal_valid_path($form_state['values']['site_frontpage'])) {
  1438. 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'])));
  1439. }
  1440. // Get the normal paths of both error pages.
  1441. if (!empty($form_state['values']['site_403'])) {
  1442. form_set_value($form['error_page']['site_403'], drupal_get_normal_path($form_state['values']['site_403']), $form_state);
  1443. }
  1444. if (!empty($form_state['values']['site_404'])) {
  1445. form_set_value($form['error_page']['site_404'], drupal_get_normal_path($form_state['values']['site_404']), $form_state);
  1446. }
  1447. // Validate 403 error path.
  1448. if (!empty($form_state['values']['site_403']) && !drupal_valid_path($form_state['values']['site_403'])) {
  1449. 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'])));
  1450. }
  1451. // Validate 404 error path.
  1452. if (!empty($form_state['values']['site_404']) && !drupal_valid_path($form_state['values']['site_404'])) {
  1453. 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'])));
  1454. }
  1455. }
  1456. /**
  1457. * Form builder; Cron form.
  1458. *
  1459. * @see system_settings_form()
  1460. * @ingroup forms
  1461. */
  1462. function system_cron_settings() {
  1463. global $base_url;
  1464. $form['description'] = array(
  1465. '#markup' => '<p>' . t('Cron takes care of running periodic tasks like checking for updates and indexing content for search.') . '</p>',
  1466. );
  1467. $form['run'] = array(
  1468. '#type' => 'submit',
  1469. '#value' => t('Run cron'),
  1470. '#submit' => array('system_run_cron_submit'),
  1471. );
  1472. $status = '<p>' . t('Last run: %cron-last ago.', array('%cron-last' => format_interval(REQUEST_TIME - variable_get('cron_last')),)) . '</p>';
  1473. $form['status'] = array(
  1474. '#markup' => $status,
  1475. );
  1476. $form['cron_url'] = array(
  1477. '#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>',
  1478. );
  1479. $form['cron'] = array(
  1480. '#type' => 'fieldset',
  1481. );
  1482. $form['cron']['cron_safe_threshold'] = array(
  1483. '#type' => 'select',
  1484. '#title' => t('Run cron every'),
  1485. '#default_value' => variable_get('cron_safe_threshold', DRUPAL_CRON_DEFAULT_THRESHOLD),
  1486. '#options' => array(0 => t('Never')) + drupal_map_assoc(array(3600, 10800, 21600, 43200, 86400, 604800), 'format_interval'),
  1487. );
  1488. return system_settings_form($form);
  1489. }
  1490. /**
  1491. * Submit callback; run cron.
  1492. *
  1493. * @ingroup forms
  1494. */
  1495. function system_run_cron_submit($form, &$form_state) {
  1496. // Run cron manually from Cron form.
  1497. if (drupal_cron_run()) {
  1498. drupal_set_message(t('Cron run successfully.'));
  1499. }
  1500. else {
  1501. drupal_set_message(t('Cron run failed.'), 'error');
  1502. }
  1503. drupal_goto('admin/config/system/cron');
  1504. }
  1505. /**
  1506. * Form builder; Configure error reporting settings.
  1507. *
  1508. * @ingroup forms
  1509. * @see system_settings_form()
  1510. */
  1511. function system_logging_settings() {
  1512. $form['error_level'] = array(
  1513. '#type' => 'radios',
  1514. '#title' => t('Error messages to display'),
  1515. '#default_value' => variable_get('error_level', ERROR_REPORTING_DISPLAY_ALL),
  1516. '#options' => array(
  1517. ERROR_REPORTING_HIDE => t('None'),
  1518. ERROR_REPORTING_DISPLAY_SOME => t('Errors and warnings'),
  1519. ERROR_REPORTING_DISPLAY_ALL => t('All messages'),
  1520. ),
  1521. '#description' => t('It is recommended that sites running on production environments do not display any errors.'),
  1522. );
  1523. return system_settings_form($form);
  1524. }
  1525. /**
  1526. * Form builder; Configure site performance settings.
  1527. *
  1528. * @ingroup forms
  1529. * @see system_settings_form()
  1530. */
  1531. function system_performance_settings() {
  1532. drupal_add_js(drupal_get_path('module', 'system') . '/system.js');
  1533. $form['clear_cache'] = array(
  1534. '#type' => 'fieldset',
  1535. '#title' => t('Clear cache'),
  1536. );
  1537. $form['clear_cache']['clear'] = array(
  1538. '#type' => 'submit',
  1539. '#value' => t('Clear all caches'),
  1540. '#submit' => array('system_clear_cache_submit'),
  1541. );
  1542. $form['caching'] = array(
  1543. '#type' => 'fieldset',
  1544. '#title' => t('Caching'),
  1545. );
  1546. $cache = variable_get('cache', 0);
  1547. $form['caching']['cache'] = array(
  1548. '#type' => 'checkbox',
  1549. '#title' => t('Cache pages for anonymous users'),
  1550. '#default_value' => $cache,
  1551. '#weight' => -2,
  1552. );
  1553. $period = drupal_map_assoc(array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400), 'format_interval');
  1554. $period[0] = '<' . t('none') . '>';
  1555. $form['caching']['cache_lifetime'] = array(
  1556. '#type' => 'select',
  1557. '#title' => t('Minimum cache lifetime'),
  1558. '#default_value' => variable_get('cache_lifetime', 0),
  1559. '#options' => $period,
  1560. '#description' => t('Cached pages will not be re-created until at least this much time has elapsed.')
  1561. );
  1562. $form['caching']['page_cache_maximum_age'] = array(
  1563. '#type' => 'select',
  1564. '#title' => t('Expiration of cached pages'),
  1565. '#default_value' => variable_get('page_cache_maximum_age', 0),
  1566. '#options' => $period,
  1567. '#description' => t('The maximum time an external cache can use an old version of a page.')
  1568. );
  1569. $directory = 'public://';
  1570. $is_writable = is_dir($directory) && is_writable($directory);
  1571. $disabled = !$is_writable;
  1572. $disabled_message = '';
  1573. if (!$is_writable) {
  1574. $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')));
  1575. }
  1576. $form['bandwidth_optimization'] = array(
  1577. '#type' => 'fieldset',
  1578. '#title' => t('Bandwidth optimization'),
  1579. '#description' => t('External resources can be optimized automatically, which can reduce both the size and number of requests made to your website.') . $disabled_message,
  1580. );
  1581. $js_hide = $cache ? '' : ' class="js-hide"';
  1582. $form['bandwidth_optimization']['page_compression'] = array(
  1583. '#type' => 'checkbox',
  1584. '#title' => t('Compress cached pages.'),
  1585. '#default_value' => variable_get('page_compression', TRUE),
  1586. '#prefix' => '<div id="page-compression-wrapper"' . $js_hide . '>',
  1587. '#suffix' => '</div>',
  1588. );
  1589. $form['bandwidth_optimization']['preprocess_css'] = array(
  1590. '#type' => 'checkbox',
  1591. '#title' => t('Aggregate and compress CSS files.'),
  1592. '#default_value' => intval(variable_get('preprocess_css', 0) && $is_writable),
  1593. '#disabled' => $disabled,
  1594. );
  1595. $form['bandwidth_optimization']['preprocess_js'] = array(
  1596. '#type' => 'checkbox',
  1597. '#title' => t('Aggregate JavaScript files.'),
  1598. '#default_value' => intval(variable_get('preprocess_js', 0) && $is_writable),
  1599. '#disabled' => $disabled,
  1600. );
  1601. $form['#submit'][] = 'drupal_clear_css_cache';
  1602. $form['#submit'][] = 'drupal_clear_js_cache';
  1603. // This form allows page compression settings to be changed, which can
  1604. // invalidate the page cache, so it needs to be cleared on form submit.
  1605. $form['#submit'][] = 'system_clear_page_cache_submit';
  1606. return system_settings_form($form);
  1607. }
  1608. /**
  1609. * Submit callback; clear system caches.
  1610. *
  1611. * @ingroup forms
  1612. */
  1613. function system_clear_cache_submit($form, &$form_state) {
  1614. drupal_flush_all_caches();
  1615. drupal_set_message(t('Caches cleared.'));
  1616. }
  1617. /**
  1618. * Submit callback; clear the page cache.
  1619. *
  1620. * @ingroup forms
  1621. */
  1622. function system_clear_page_cache_submit($form, &$form_state) {
  1623. cache_clear_all('*', 'cache_page', TRUE);
  1624. }
  1625. /**
  1626. * Form builder; Configure the site file handling.
  1627. *
  1628. * @ingroup forms
  1629. * @see system_settings_form()
  1630. */
  1631. function system_file_system_settings() {
  1632. $form['file_public_path'] = array(
  1633. '#type' => 'textfield',
  1634. '#title' => t('Public file system path'),
  1635. '#default_value' => variable_get('file_public_path', conf_path() . '/files'),
  1636. '#maxlength' => 255,
  1637. '#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.'),
  1638. '#after_build' => array('system_check_directory'),
  1639. );
  1640. $form['file_private_path'] = array(
  1641. '#type' => 'textfield',
  1642. '#title' => t('Private file system path'),
  1643. '#default_value' => variable_get('file_private_path', ''),
  1644. '#maxlength' => 255,
  1645. '#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')),
  1646. '#after_build' => array('system_check_directory'),
  1647. );
  1648. $form['file_temporary_path'] = array(
  1649. '#type' => 'textfield',
  1650. '#title' => t('Temporary directory'),
  1651. '#default_value' => variable_get('file_temporary_path', file_directory_temp()),
  1652. '#maxlength' => 255,
  1653. '#description' => t('A local file system path where temporary files will be stored. This directory should not be accessible over the web.'),
  1654. '#after_build' => array('system_check_directory'),
  1655. );
  1656. // Any visible, writeable wrapper can potentially be used for the files
  1657. // directory, including a remote file system that integrates with a CDN.
  1658. foreach (file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE) as $scheme => $info) {
  1659. $options[$scheme] = check_plain($info['description']);
  1660. }
  1661. if (!empty($options)) {
  1662. $form['file_default_scheme'] = array(
  1663. '#type' => 'radios',
  1664. '#title' => t('Default download method'),
  1665. '#default_value' => variable_get('file_default_scheme', isset($options['public']) ? 'public' : key($options)),
  1666. '#options' => $options,
  1667. '#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.'),
  1668. );
  1669. }
  1670. return system_settings_form($form);
  1671. }
  1672. /**
  1673. * Form builder; Configure site image toolkit usage.
  1674. *
  1675. * @ingroup forms
  1676. * @see system_settings_form()
  1677. */
  1678. function system_image_toolkit_settings() {
  1679. $toolkits_available = image_get_available_toolkits();
  1680. $current_toolkit = image_get_toolkit();
  1681. if (count($toolkits_available) == 0) {
  1682. variable_del('image_toolkit');
  1683. $form['image_toolkit_help'] = array(
  1684. '#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'))),
  1685. );
  1686. return $form;
  1687. }
  1688. if (count($toolkits_available) > 1) {
  1689. $form['image_toolkit'] = array(
  1690. '#type' => 'radios',
  1691. '#title' => t('Select an image processing toolkit'),
  1692. '#default_value' => variable_get('image_toolkit', $current_toolkit),
  1693. '#options' => $toolkits_available
  1694. );
  1695. }
  1696. else {
  1697. variable_set('image_toolkit', key($toolkits_available));
  1698. }
  1699. // Get the toolkit's settings form.
  1700. $function = 'image_' . $current_toolkit . '_settings';
  1701. if (function_exists($function)) {
  1702. $form['image_toolkit_settings'] = $function();
  1703. }
  1704. return system_settings_form($form);
  1705. }
  1706. /**
  1707. * Form builder; Configure how the site handles RSS feeds.
  1708. *
  1709. * @ingroup forms
  1710. * @see system_settings_form()
  1711. */
  1712. function system_rss_feeds_settings() {
  1713. $form['feed_description'] = array(
  1714. '#type' => 'textarea',
  1715. '#title' => t('Feed description'),
  1716. '#default_value' => variable_get('feed_description', ''),
  1717. '#description' => t('Description of your site, included in each feed.')
  1718. );
  1719. $form['feed_default_items'] = array(
  1720. '#type' => 'select',
  1721. '#title' => t('Number of items in each feed'),
  1722. '#default_value' => variable_get('feed_default_items', 10),
  1723. '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)),
  1724. '#description' => t('Default number of items to include in each feed.')
  1725. );
  1726. $form['feed_item_length'] = array(
  1727. '#type' => 'select',
  1728. '#title' => t('Feed content'),
  1729. '#default_value' => variable_get('feed_item_length', 'fulltext'),
  1730. '#options' => array('title' => t('Titles only'), 'teaser' => t('Titles plus teaser'), 'fulltext' => t('Full text')),
  1731. '#description' => t('Global setting for the default display of content items in each feed.')
  1732. );
  1733. return system_settings_form($form);
  1734. }
  1735. /**
  1736. * Form builder; Configure the site regional settings.
  1737. *
  1738. * @ingroup forms
  1739. * @see system_settings_form()
  1740. * @see system_regional_settings_submit()
  1741. */
  1742. function system_regional_settings() {
  1743. include_once DRUPAL_ROOT . '/includes/locale.inc';
  1744. $countries = country_get_list();
  1745. // Date settings:
  1746. $zones = system_time_zones();
  1747. $form['locale'] = array(
  1748. '#type' => 'fieldset',
  1749. '#title' => t('Locale'),
  1750. );
  1751. $form['locale']['site_default_country'] = array(
  1752. '#type' => 'select',
  1753. '#title' => t('Default country'),
  1754. '#empty_value' => '',
  1755. '#default_value' => variable_get('site_default_country', ''),
  1756. '#options' => $countries,
  1757. '#attributes' => array('class' => array('country-detect')),
  1758. );
  1759. $form['locale']['date_first_day'] = array(
  1760. '#type' => 'select',
  1761. '#title' => t('First day of week'),
  1762. '#default_value' => variable_get('date_first_day', 0),
  1763. '#options' => array(0 => t('Sunday'), 1 => t('Monday'), 2 => t('Tuesday'), 3 => t('Wednesday'), 4 => t('Thursday'), 5 => t('Friday'), 6 => t('Saturday')),
  1764. );
  1765. $form['timezone'] = array(
  1766. '#type' => 'fieldset',
  1767. '#title' => t('Time zones'),
  1768. );
  1769. $form['timezone']['date_default_timezone'] = array(
  1770. '#type' => 'select',
  1771. '#title' => t('Default time zone'),
  1772. '#default_value' => variable_get('date_default_timezone', date_default_timezone_get()),
  1773. '#options' => $zones,
  1774. );
  1775. $configurable_timezones = variable_get('configurable_timezones', 1);
  1776. $form['timezone']['configurable_timezones'] = array(
  1777. '#type' => 'checkbox',
  1778. '#title' => t('Users may set their own time zone.'),
  1779. '#default_value' => $configurable_timezones,
  1780. );
  1781. $form['timezone']['configurable_timezones_wrapper'] = array(
  1782. '#type' => 'container',
  1783. '#states' => array(
  1784. // Hide the user configured timezone settings when users are forced to use
  1785. // the default setting.
  1786. 'invisible' => array(
  1787. 'input[name="configurable_timezones"]' => array('checked' => FALSE),
  1788. ),
  1789. ),
  1790. );
  1791. $form['timezone']['configurable_timezones_wrapper']['empty_timezone_message'] = array(
  1792. '#type' => 'checkbox',
  1793. '#title' => t('Remind users at login if their time zone is not set.'),
  1794. '#default_value' => variable_get('empty_timezone_message', 0),
  1795. '#description' => t('Only applied if users may set their own time zone.')
  1796. );
  1797. $form['timezone']['configurable_timezones_wrapper']['user_default_timezone'] = array(
  1798. '#type' => 'radios',
  1799. '#title' => t('Time zone for new users'),
  1800. '#default_value' => variable_get('user_default_timezone', DRUPAL_USER_TIMEZONE_DEFAULT),
  1801. '#options' => array(
  1802. DRUPAL_USER_TIMEZONE_DEFAULT => t('Default time zone.'),
  1803. DRUPAL_USER_TIMEZONE_EMPTY => t('Empty time zone.'),
  1804. DRUPAL_USER_TIMEZONE_SELECT => t('Users may set their own time zone at registration.'),
  1805. ),
  1806. '#description' => t('Only applied if users may set their own time zone.')
  1807. );
  1808. return system_settings_form($form);
  1809. }
  1810. /**
  1811. * Form builder; Configure the site date and time settings.
  1812. *
  1813. * @ingroup forms
  1814. * @see system_settings_form()
  1815. */
  1816. function system_date_time_settings() {
  1817. // Get list of all available date types.
  1818. drupal_static_reset('system_get_date_types');
  1819. $format_types = system_get_date_types();
  1820. // Get list of all available date formats.
  1821. $all_formats = array();
  1822. drupal_static_reset('system_get_date_formats');
  1823. $date_formats = system_get_date_formats(); // Call this to rebuild the list, and to have default list.
  1824. foreach ($date_formats as $type => $format_info) {
  1825. $all_formats = array_merge($all_formats, $format_info);
  1826. }
  1827. $custom_formats = system_get_date_formats('custom');
  1828. if (!empty($format_types)) {
  1829. foreach ($format_types as $type => $type_info) {
  1830. // If a system type, only show the available formats for that type and
  1831. // custom ones.
  1832. if ($type_info['locked'] == 1) {
  1833. $formats = system_get_date_formats($type);
  1834. if (empty($formats)) {
  1835. $formats = $all_formats;
  1836. }
  1837. elseif (!empty($custom_formats)) {
  1838. $formats = array_merge($formats, $custom_formats);
  1839. }
  1840. }
  1841. // If a user configured type, show all available date formats.
  1842. else {
  1843. $formats = $all_formats;
  1844. }
  1845. $choices = array();
  1846. foreach ($formats as $f => $format) {
  1847. $choices[$f] = format_date(REQUEST_TIME, 'custom', $f);
  1848. }
  1849. reset($formats);
  1850. $default = variable_get('date_format_' . $type, key($formats));
  1851. // Get date type info for this date type.
  1852. $type_info = system_get_date_types($type);
  1853. $form['formats']['#theme'] = 'system_date_time_settings';
  1854. // Show date format select list.
  1855. $form['formats']['format']['date_format_' . $type] = array(
  1856. '#type' => 'select',
  1857. '#title' => check_plain($type_info['title']),
  1858. '#attributes' => array('class' => array('date-format')),
  1859. '#default_value' => (isset($choices[$default]) ? $default : 'custom'),
  1860. '#options' => $choices,
  1861. );
  1862. // If this isn't a system provided type, allow the user to remove it from
  1863. // the system.
  1864. if ($type_info['locked'] == 0) {
  1865. $form['formats']['delete']['date_format_' . $type . '_delete'] = array(
  1866. '#type' => 'link',
  1867. '#title' => t('delete'),
  1868. '#href' => 'admin/config/regional/date-time/types/' . $type . '/delete',
  1869. );
  1870. }
  1871. }
  1872. }
  1873. // Display a message if no date types configured.
  1874. $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')));
  1875. return system_settings_form($form);
  1876. }
  1877. /**
  1878. * Returns HTML for the date settings form.
  1879. *
  1880. * @param $variables
  1881. * An associative array containing:
  1882. * - form: A render element representing the form.
  1883. *
  1884. * @ingroup themeable
  1885. */
  1886. function theme_system_date_time_settings($variables) {
  1887. $form = $variables['form'];
  1888. $header = array(
  1889. t('Date type'),
  1890. t('Format'),
  1891. t('Operations'),
  1892. );
  1893. foreach (element_children($form['format']) as $key) {
  1894. $delete_key = $key . '_delete';
  1895. $row = array();
  1896. $row[] = $form['format'][$key]['#title'];
  1897. $form['format'][$key]['#title_display'] = 'invisible';
  1898. $row[] = array('data' => drupal_render($form['format'][$key]));
  1899. $row[] = array('data' => drupal_render($form['delete'][$delete_key]));
  1900. $rows[] = $row;
  1901. }
  1902. $output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'system-date-types')));
  1903. $output .= drupal_render_children($form);
  1904. return $output;
  1905. }
  1906. /**
  1907. * Add new date type.
  1908. *
  1909. * @ingroup forms
  1910. * @ingroup system_add_date_format_type_form_validate()
  1911. * @ingroup system_add_date_format_type_form_submit()
  1912. */
  1913. function system_add_date_format_type_form($form, &$form_state) {
  1914. $form['date_type'] = array(
  1915. '#title' => t('Date type'),
  1916. '#type' => 'textfield',
  1917. '#required' => TRUE,
  1918. );
  1919. $form['machine_name'] = array(
  1920. '#type' => 'machine_name',
  1921. '#machine_name' => array(
  1922. 'exists' => 'system_get_date_types',
  1923. 'source' => array('date_type'),
  1924. ),
  1925. );
  1926. // Get list of all available date formats.
  1927. $formats = array();
  1928. drupal_static_reset('system_get_date_formats');
  1929. $date_formats = system_get_date_formats(); // Call this to rebuild the list, and to have default list.
  1930. foreach ($date_formats as $type => $format_info) {
  1931. $formats = array_merge($formats, $format_info);
  1932. }
  1933. $custom_formats = system_get_date_formats('custom');
  1934. if (!empty($custom_formats)) {
  1935. $formats = array_merge($formats, $custom_formats);
  1936. }
  1937. $choices = array();
  1938. foreach ($formats as $f => $format) {
  1939. $choices[$f] = format_date(REQUEST_TIME, 'custom', $f);
  1940. }
  1941. // Show date format select list.
  1942. $form['date_format'] = array(
  1943. '#type' => 'select',
  1944. '#title' => t('Date format'),
  1945. '#attributes' => array('class' => array('date-format')),
  1946. '#options' => $choices,
  1947. '#required' => TRUE,
  1948. );
  1949. $form['actions'] = array('#type' => 'actions');
  1950. $form['actions']['submit'] = array(
  1951. '#type' => 'submit',
  1952. '#value' => t('Add date type'),
  1953. );
  1954. $form['#validate'][] = 'system_add_date_format_type_form_validate';
  1955. $form['#submit'][] = 'system_add_date_format_type_form_submit';
  1956. return $form;
  1957. }
  1958. /**
  1959. * Validate system_add_date_format_type form submissions.
  1960. */
  1961. function system_add_date_format_type_form_validate($form, &$form_state) {
  1962. if (!empty($form_state['values']['machine_name']) && !empty($form_state['values']['date_type'])) {
  1963. if (!preg_match("/^[a-zA-Z0-9_]+$/", trim($form_state['values']['machine_name']))) {
  1964. form_set_error('machine_name', t('The date type must contain only alphanumeric characters and underscores.'));
  1965. }
  1966. $types = system_get_date_types();
  1967. if (in_array(trim($form_state['values']['machine_name']), array_keys($types))) {
  1968. form_set_error('machine_name', t('This date type already exists. Enter a unique type.'));
  1969. }
  1970. }
  1971. }
  1972. /**
  1973. * Process system_add_date_format_type form submissions.
  1974. */
  1975. function system_add_date_format_type_form_submit($form, &$form_state) {
  1976. $machine_name = trim($form_state['values']['machine_name']);
  1977. $format_type = array();
  1978. $format_type['title'] = trim($form_state['values']['date_type']);
  1979. $format_type['type'] = $machine_name;
  1980. $format_type['locked'] = 0;
  1981. $format_type['is_new'] = 1;
  1982. system_date_format_type_save($format_type);
  1983. variable_set('date_format_' . $machine_name, $form_state['values']['date_format']);
  1984. drupal_set_message(t('New date type added successfully.'));
  1985. $form_state['redirect'] = 'admin/config/regional/date-time';
  1986. }
  1987. /**
  1988. * Return the date for a given format string via Ajax.
  1989. */
  1990. function system_date_time_lookup() {
  1991. $result = format_date(REQUEST_TIME, 'custom', $_GET['format']);
  1992. drupal_json_output($result);
  1993. }
  1994. /**
  1995. * Form builder; Configure the site's maintenance status.
  1996. *
  1997. * @ingroup forms
  1998. * @see system_settings_form()
  1999. */
  2000. function system_site_maintenance_mode() {
  2001. $form['maintenance_mode'] = array(
  2002. '#type' => 'checkbox',
  2003. '#title' => t('Put site into maintenance mode'),
  2004. '#default_value' => variable_get('maintenance_mode', 0),
  2005. '#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'))),
  2006. );
  2007. $form['maintenance_mode_message'] = array(
  2008. '#type' => 'textarea',
  2009. '#title' => t('Maintenance mode message'),
  2010. '#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')))),
  2011. '#description' => t('Message to show visitors when the site is in maintenance mode.')
  2012. );
  2013. return system_settings_form($form);
  2014. }
  2015. /**
  2016. * Form builder; Configure clean URL settings.
  2017. *
  2018. * @ingroup forms
  2019. * @see system_settings_form()
  2020. */
  2021. function system_clean_url_settings($form, &$form_state) {
  2022. $available = FALSE;
  2023. $conflict = FALSE;
  2024. // If the request URI is a clean URL, clean URLs must be available.
  2025. // Otherwise, run a test.
  2026. if (strpos(request_uri(), '?q=') === FALSE && strpos(request_uri(), '&q=') === FALSE) {
  2027. $available = TRUE;
  2028. }
  2029. else {
  2030. $request = drupal_http_request($GLOBALS['base_url'] . '/admin/config/search/clean-urls/check');
  2031. // If the request returns HTTP 200, clean URLs are available.
  2032. if (isset($request->code) && $request->code == 200) {
  2033. $available = TRUE;
  2034. // If the user started the clean URL test, provide explicit feedback.
  2035. if (isset($form_state['input']['clean_url_test_execute'])) {
  2036. drupal_set_message(t('The clean URL test passed.'));
  2037. }
  2038. }
  2039. else {
  2040. // If the test failed while clean URLs are enabled, make sure clean URLs
  2041. // can be disabled.
  2042. if (variable_get('clean_url', 0)) {
  2043. $conflict = TRUE;
  2044. // Warn the user of a conflicting situation, unless after processing
  2045. // a submitted form.
  2046. if (!isset($form_state['input']['op'])) {
  2047. drupal_set_message(t('Clean URLs are enabled, but the clean URL test failed. Uncheck the box below to disable clean URLs.'), 'warning');
  2048. }
  2049. }
  2050. // If the user started the clean URL test, provide explicit feedback.
  2051. elseif (isset($form_state['input']['clean_url_test_execute'])) {
  2052. drupal_set_message(t('The clean URL test failed.'), 'warning');
  2053. }
  2054. }
  2055. }
  2056. // Show the enable/disable form if clean URLs are available or if the user
  2057. // must be able to resolve a conflicting setting.
  2058. if ($available || $conflict) {
  2059. $form['clean_url'] = array(
  2060. '#type' => 'checkbox',
  2061. '#title' => t('Enable clean URLs'),
  2062. '#default_value' => variable_get('clean_url', 0),
  2063. '#description' => t('Use URLs like <code>example.com/user</code> instead of <code>example.com/?q=user</code>.'),
  2064. );
  2065. $form = system_settings_form($form);
  2066. if ($conflict) {
  2067. // $form_state['redirect'] needs to be set to the non-clean URL,
  2068. // otherwise the setting is not saved.
  2069. $form_state['redirect'] = url('', array('query' => array('q' => '/admin/config/search/clean-urls')));
  2070. }
  2071. }
  2072. // Show the clean URLs test form.
  2073. else {
  2074. drupal_add_js(drupal_get_path('module', 'system') . '/system.js');
  2075. $form_state['redirect'] = url('admin/config/search/clean-urls');
  2076. $form['clean_url_description'] = array(
  2077. '#type' => 'markup',
  2078. '#markup' => '<p>' . t('Use URLs like <code>example.com/user</code> instead of <code>example.com/?q=user</code>.'),
  2079. );
  2080. // Explain why the user is seeing this page and what to expect after
  2081. // clicking the 'Run the clean URL test' button.
  2082. $form['clean_url_test_result'] = array(
  2083. '#type' => 'markup',
  2084. '#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>',
  2085. );
  2086. $form['actions'] = array(
  2087. '#type' => 'actions',
  2088. 'clean_url_test' => array(
  2089. '#type' => 'submit',
  2090. '#value' => t('Run the clean URL test'),
  2091. ),
  2092. );
  2093. $form['clean_url_test_execute'] = array(
  2094. '#type' => 'hidden',
  2095. '#value' => 1,
  2096. );
  2097. }
  2098. return $form;
  2099. }
  2100. /**
  2101. * Menu callback: displays the site status report. Can also be used as a pure check.
  2102. *
  2103. * @param $check
  2104. * If true, only returns a boolean whether there are system status errors.
  2105. */
  2106. function system_status($check = FALSE) {
  2107. // Load .install files
  2108. include_once DRUPAL_ROOT . '/includes/install.inc';
  2109. drupal_load_updates();
  2110. // Check run-time requirements and status information.
  2111. $requirements = module_invoke_all('requirements', 'runtime');
  2112. usort($requirements, '_system_sort_requirements');
  2113. if ($check) {
  2114. return drupal_requirements_severity($requirements) == REQUIREMENT_ERROR;
  2115. }
  2116. // MySQL import might have set the uid of the anonymous user to autoincrement
  2117. // value. Let's try fixing it. See http://drupal.org/node/204411
  2118. db_update('users')
  2119. ->expression('uid', 'uid - uid')
  2120. ->condition('name', '')
  2121. ->condition('pass', '')
  2122. ->condition('status', 0)
  2123. ->execute();
  2124. return theme('status_report', array('requirements' => $requirements));
  2125. }
  2126. /**
  2127. * Menu callback: run cron manually.
  2128. */
  2129. function system_run_cron() {
  2130. // Run cron manually
  2131. if (drupal_cron_run()) {
  2132. drupal_set_message(t('Cron ran successfully.'));
  2133. }
  2134. else {
  2135. drupal_set_message(t('Cron run failed.'), 'error');
  2136. }
  2137. drupal_goto('admin/reports/status');
  2138. }
  2139. /**
  2140. * Menu callback: return information about PHP.
  2141. */
  2142. function system_php() {
  2143. phpinfo();
  2144. drupal_exit();
  2145. }
  2146. /**
  2147. * Default page callback for batches.
  2148. */
  2149. function system_batch_page() {
  2150. require_once DRUPAL_ROOT . '/includes/batch.inc';
  2151. $output = _batch_page();
  2152. if ($output === FALSE) {
  2153. drupal_access_denied();
  2154. }
  2155. elseif (isset($output)) {
  2156. // Force a page without blocks or messages to
  2157. // display a list of collected messages later.
  2158. drupal_set_page_content($output);
  2159. $page = element_info('page');
  2160. $page['#show_messages'] = FALSE;
  2161. return $page;
  2162. }
  2163. }
  2164. /**
  2165. * Returns HTML for an administrative block for display.
  2166. *
  2167. * @param $variables
  2168. * An associative array containing:
  2169. * - block: An array containing information about the block:
  2170. * - show: A Boolean whether to output the block. Defaults to FALSE.
  2171. * - title: The block's title.
  2172. * - content: (optional) Formatted content for the block.
  2173. * - description: (optional) Description of the block. Only output if
  2174. * 'content' is not set.
  2175. *
  2176. * @ingroup themeable
  2177. */
  2178. function theme_admin_block($variables) {
  2179. $block = $variables['block'];
  2180. $output = '';
  2181. // Don't display the block if it has no content to display.
  2182. if (empty($block['show'])) {
  2183. return $output;
  2184. }
  2185. $output .= '<div class="admin-panel">';
  2186. if (!empty($block['title'])) {
  2187. $output .= '<h3>' . $block['title'] . '</h3>';
  2188. }
  2189. if (!empty($block['content'])) {
  2190. $output .= '<div class="body">' . $block['content'] . '</div>';
  2191. }
  2192. else {
  2193. $output .= '<div class="description">' . $block['description'] . '</div>';
  2194. }
  2195. $output .= '</div>';
  2196. return $output;
  2197. }
  2198. /**
  2199. * Returns HTML for the content of an administrative block.
  2200. *
  2201. * @param $variables
  2202. * An associative array containing:
  2203. * - content: An array containing information about the block. Each element
  2204. * of the array represents an administrative menu item, and must at least
  2205. * contain the keys 'title', 'href', and 'localized_options', which are
  2206. * passed to l(). A 'description' key may also be provided.
  2207. *
  2208. * @ingroup themeable
  2209. */
  2210. function theme_admin_block_content($variables) {
  2211. $content = $variables['content'];
  2212. $output = '';
  2213. if (!empty($content)) {
  2214. $class = 'admin-list';
  2215. if ($compact = system_admin_compact_mode()) {
  2216. $class .= ' compact';
  2217. }
  2218. $output .= '<dl class="' . $class . '">';
  2219. foreach ($content as $item) {
  2220. $output .= '<dt>' . l($item['title'], $item['href'], $item['localized_options']) . '</dt>';
  2221. if (!$compact && isset($item['description'])) {
  2222. $output .= '<dd>' . filter_xss_admin($item['description']) . '</dd>';
  2223. }
  2224. }
  2225. $output .= '</dl>';
  2226. }
  2227. return $output;
  2228. }
  2229. /**
  2230. * Returns HTML for an administrative page.
  2231. *
  2232. * @param $variables
  2233. * An associative array containing:
  2234. * - blocks: An array of blocks to display. Each array should include a
  2235. * 'title', a 'description', a formatted 'content' and a 'position' which
  2236. * will control which container it will be in. This is usually 'left' or
  2237. * 'right'.
  2238. *
  2239. * @ingroup themeable
  2240. */
  2241. function theme_admin_page($variables) {
  2242. $blocks = $variables['blocks'];
  2243. $stripe = 0;
  2244. $container = array();
  2245. foreach ($blocks as $block) {
  2246. if ($block_output = theme('admin_block', array('block' => $block))) {
  2247. if (empty($block['position'])) {
  2248. // perform automatic striping.
  2249. $block['position'] = ++$stripe % 2 ? 'left' : 'right';
  2250. }
  2251. if (!isset($container[$block['position']])) {
  2252. $container[$block['position']] = '';
  2253. }
  2254. $container[$block['position']] .= $block_output;
  2255. }
  2256. }
  2257. $output = '<div class="admin clearfix">';
  2258. $output .= theme('system_compact_link');
  2259. foreach ($container as $id => $data) {
  2260. $output .= '<div class="' . $id . ' clearfix">';
  2261. $output .= $data;
  2262. $output .= '</div>';
  2263. }
  2264. $output .= '</div>';
  2265. return $output;
  2266. }
  2267. /**
  2268. * Returns HTML for the output of the dashboard page.
  2269. *
  2270. * @param $variables
  2271. * An associative array containing:
  2272. * - menu_items: An array of modules to be displayed.
  2273. *
  2274. * @ingroup themeable
  2275. */
  2276. function theme_system_admin_index($variables) {
  2277. $menu_items = $variables['menu_items'];
  2278. $stripe = 0;
  2279. $container = array('left' => '', 'right' => '');
  2280. $flip = array('left' => 'right', 'right' => 'left');
  2281. $position = 'left';
  2282. // Iterate over all modules.
  2283. foreach ($menu_items as $module => $block) {
  2284. list($description, $items) = $block;
  2285. // Output links.
  2286. if (count($items)) {
  2287. $block = array();
  2288. $block['title'] = $module;
  2289. $block['content'] = theme('admin_block_content', array('content' => $items));
  2290. $block['description'] = t($description);
  2291. $block['show'] = TRUE;
  2292. if ($block_output = theme('admin_block', array('block' => $block))) {
  2293. if (!isset($block['position'])) {
  2294. // Perform automatic striping.
  2295. $block['position'] = $position;
  2296. $position = $flip[$position];
  2297. }
  2298. $container[$block['position']] .= $block_output;
  2299. }
  2300. }
  2301. }
  2302. $output = '<div class="admin clearfix">';
  2303. $output .= theme('system_compact_link');
  2304. foreach ($container as $id => $data) {
  2305. $output .= '<div class="' . $id . ' clearfix">';
  2306. $output .= $data;
  2307. $output .= '</div>';
  2308. }
  2309. $output .= '</div>';
  2310. return $output;
  2311. }
  2312. /**
  2313. * Returns HTML for the status report.
  2314. *
  2315. * @param $variables
  2316. * An associative array containing:
  2317. * - requirements: An array of requirements.
  2318. *
  2319. * @ingroup themeable
  2320. */
  2321. function theme_status_report($variables) {
  2322. $requirements = $variables['requirements'];
  2323. $severities = array(
  2324. REQUIREMENT_INFO => array(
  2325. 'title' => t('Info'),
  2326. 'class' => 'info',
  2327. ),
  2328. REQUIREMENT_OK => array(
  2329. 'title' => t('OK'),
  2330. 'class' => 'ok',
  2331. ),
  2332. REQUIREMENT_WARNING => array(
  2333. 'title' => t('Warning'),
  2334. 'class' => 'warning',
  2335. ),
  2336. REQUIREMENT_ERROR => array(
  2337. 'title' => t('Error'),
  2338. 'class' => 'error',
  2339. ),
  2340. );
  2341. $output = '<table class="system-status-report">';
  2342. foreach ($requirements as $requirement) {
  2343. if (empty($requirement['#type'])) {
  2344. $severity = $severities[isset($requirement['severity']) ? (int) $requirement['severity'] : 0];
  2345. $severity['icon'] = '<div title="' . $severity['title'] . '"><span class="element-invisible">' . $severity['title'] . '</span></div>';
  2346. // Output table row(s)
  2347. if (!empty($requirement['description'])) {
  2348. $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>';
  2349. $output .= '<tr class="' . $severity['class'] . ' merge-up"><td colspan="3" class="status-description">' . $requirement['description'] . '</td></tr>';
  2350. }
  2351. else {
  2352. $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>';
  2353. }
  2354. }
  2355. }
  2356. $output .= '</table>';
  2357. return $output;
  2358. }
  2359. /**
  2360. * Returns HTML for the modules form.
  2361. *
  2362. * @param $variables
  2363. * An associative array containing:
  2364. * - form: A render element representing the form.
  2365. *
  2366. * @ingroup themeable
  2367. */
  2368. function theme_system_modules_fieldset($variables) {
  2369. $form = $variables['form'];
  2370. // Individual table headers.
  2371. $rows = array();
  2372. // Iterate through all the modules, which are
  2373. // children of this fieldset.
  2374. foreach (element_children($form) as $key) {
  2375. // Stick it into $module for easier accessing.
  2376. $module = $form[$key];
  2377. $row = array();
  2378. unset($module['enable']['#title']);
  2379. $row[] = array('class' => array('checkbox'), 'data' => drupal_render($module['enable']));
  2380. $label = '<label';
  2381. if (isset($module['enable']['#id'])) {
  2382. $label .= ' for="' . $module['enable']['#id'] . '"';
  2383. }
  2384. $row[] = $label . '><strong>' . drupal_render($module['name']) . '</strong></label>';
  2385. $row[] = drupal_render($module['version']);
  2386. // Add the description, along with any modules it requires.
  2387. $description = drupal_render($module['description']);
  2388. if ($module['#requires']) {
  2389. $description .= '<div class="admin-requirements">' . t('Requires: !module-list', array('!module-list' => implode(', ', $module['#requires']))) . '</div>';
  2390. }
  2391. if ($module['#required_by']) {
  2392. $description .= '<div class="admin-requirements">' . t('Required by: !module-list', array('!module-list' => implode(', ', $module['#required_by']))) . '</div>';
  2393. }
  2394. $row[] = array('data' => $description, 'class' => array('description'));
  2395. // Display links (such as help or permissions) in their own columns.
  2396. foreach (array('help', 'permissions', 'configure') as $key) {
  2397. $row[] = array('data' => drupal_render($module['links'][$key]), 'class' => array($key));
  2398. }
  2399. $rows[] = $row;
  2400. }
  2401. return theme('table', array('header' => $form['#header'], 'rows' => $rows));
  2402. }
  2403. /**
  2404. * Returns HTML for a message about incompatible modules.
  2405. *
  2406. * @param $variables
  2407. * An associative array containing:
  2408. * - message: The form array representing the currently disabled modules.
  2409. *
  2410. * @ingroup themeable
  2411. */
  2412. function theme_system_modules_incompatible($variables) {
  2413. return '<div class="incompatible">' . $variables['message'] . '</div>';
  2414. }
  2415. /**
  2416. * Returns HTML for a table of currently disabled modules.
  2417. *
  2418. * @param $variables
  2419. * An associative array containing:
  2420. * - form: A render element representing the form.
  2421. *
  2422. * @ingroup themeable
  2423. */
  2424. function theme_system_modules_uninstall($variables) {
  2425. $form = $variables['form'];
  2426. // No theming for the confirm form.
  2427. if (isset($form['confirm'])) {
  2428. return drupal_render($form);
  2429. }
  2430. // Table headers.
  2431. $header = array(t('Uninstall'),
  2432. t('Name'),
  2433. t('Description'),
  2434. );
  2435. // Display table.
  2436. $rows = array();
  2437. foreach (element_children($form['modules']) as $module) {
  2438. if (!empty($form['modules'][$module]['#required_by'])) {
  2439. $disabled_message = format_plural(count($form['modules'][$module]['#required_by']),
  2440. 'To uninstall @module, the following module must be uninstalled first: @required_modules',
  2441. 'To uninstall @module, the following modules must be uninstalled first: @required_modules',
  2442. array('@module' => $form['modules'][$module]['#module_name'], '@required_modules' => implode(', ', $form['modules'][$module]['#required_by'])));
  2443. $disabled_message = '<div class="admin-requirements">' . $disabled_message . '</div>';
  2444. }
  2445. else {
  2446. $disabled_message = '';
  2447. }
  2448. $rows[] = array(
  2449. array('data' => drupal_render($form['uninstall'][$module]), 'align' => 'center'),
  2450. '<strong><label for="' . $form['uninstall'][$module]['#id'] . '">' . drupal_render($form['modules'][$module]['name']) . '</label></strong>',
  2451. array('data' => drupal_render($form['modules'][$module]['description']) . $disabled_message, 'class' => array('description')),
  2452. );
  2453. }
  2454. $output = theme('table', array('header' => $header, 'rows' => $rows, 'empty' => t('No modules are available to uninstall.')));
  2455. $output .= drupal_render_children($form);
  2456. return $output;
  2457. }
  2458. /**
  2459. * Returns HTML for the Appearance page.
  2460. *
  2461. * @param $variables
  2462. * An associative array containing:
  2463. * - theme_groups: An associative array containing groups of themes.
  2464. *
  2465. * @ingroup themeable
  2466. */
  2467. function theme_system_themes_page($variables) {
  2468. $theme_groups = $variables['theme_groups'];
  2469. $output = '<div id="system-themes-page">';
  2470. foreach ($variables['theme_group_titles'] as $state => $title) {
  2471. if (!count($theme_groups[$state])) {
  2472. // Skip this group of themes if no theme is there.
  2473. continue;
  2474. }
  2475. // Start new theme group.
  2476. $output .= '<div class="system-themes-list system-themes-list-'. $state .' clearfix"><h2>'. $title .'</h2>';
  2477. foreach ($theme_groups[$state] as $theme) {
  2478. // Theme the screenshot.
  2479. $screenshot = $theme->screenshot ? theme('image', $theme->screenshot) : '<div class="no-screenshot">' . t('no screenshot') . '</div>';
  2480. // Localize the theme description.
  2481. $description = t($theme->info['description']);
  2482. // Style theme info
  2483. $notes = count($theme->notes) ? ' (' . join(', ', $theme->notes) . ')' : '';
  2484. $theme->classes[] = 'theme-selector';
  2485. $theme->classes[] = 'clearfix';
  2486. $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>';
  2487. // Make sure to provide feedback on compatibility.
  2488. if (!empty($theme->incompatible_core)) {
  2489. $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>';
  2490. }
  2491. elseif (!empty($theme->incompatible_php)) {
  2492. if (substr_count($theme->info['php'], '.') < 2) {
  2493. $theme->info['php'] .= '.*';
  2494. }
  2495. $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>';
  2496. }
  2497. else {
  2498. $output .= theme('links', array('links' => $theme->operations, 'attributes' => array('class' => array('operations', 'clearfix'))));
  2499. }
  2500. $output .= '</div></div>';
  2501. }
  2502. $output .= '</div>';
  2503. }
  2504. $output .= '</div>';
  2505. return $output;
  2506. }
  2507. /**
  2508. * Menu callback; present a form for deleting a date format.
  2509. */
  2510. function system_date_delete_format_form($form, &$form_state, $dfid) {
  2511. $form['dfid'] = array(
  2512. '#type' => 'value',
  2513. '#value' => $dfid,
  2514. );
  2515. $format = system_get_date_format($dfid);
  2516. $output = confirm_form($form,
  2517. t('Are you sure you want to remove the format %format?', array('%format' => format_date(REQUEST_TIME, 'custom', $format->format))),
  2518. 'admin/config/regional/date-time/formats',
  2519. t('This action cannot be undone.'),
  2520. t('Remove'), t('Cancel'),
  2521. 'confirm'
  2522. );
  2523. return $output;
  2524. }
  2525. /**
  2526. * Delete a configured date format.
  2527. */
  2528. function system_date_delete_format_form_submit($form, &$form_state) {
  2529. if ($form_state['values']['confirm']) {
  2530. $format = system_get_date_format($form_state['values']['dfid']);
  2531. system_date_format_delete($form_state['values']['dfid']);
  2532. drupal_set_message(t('Removed date format %format.', array('%format' => format_date(REQUEST_TIME, 'custom', $format->format))));
  2533. $form_state['redirect'] = 'admin/config/regional/date-time/formats';
  2534. }
  2535. }
  2536. /**
  2537. * Menu callback; present a form for deleting a date type.
  2538. */
  2539. function system_delete_date_format_type_form($form, &$form_state, $format_type) {
  2540. $form['format_type'] = array(
  2541. '#type' => 'value',
  2542. '#value' => $format_type,
  2543. );
  2544. $type_info = system_get_date_types($format_type);
  2545. $output = confirm_form($form,
  2546. t('Are you sure you want to remove the date type %type?', array('%type' => $type_info['title'])),
  2547. 'admin/config/regional/date-time',
  2548. t('This action cannot be undone.'),
  2549. t('Remove'), t('Cancel'),
  2550. 'confirm'
  2551. );
  2552. return $output;
  2553. }
  2554. /**
  2555. * Delete a configured date type.
  2556. */
  2557. function system_delete_date_format_type_form_submit($form, &$form_state) {
  2558. if ($form_state['values']['confirm']) {
  2559. $type_info = system_get_date_types($form_state['values']['format_type']);
  2560. system_date_format_type_delete($form_state['values']['format_type']);
  2561. drupal_set_message(t('Removed date type %type.', array('%type' => $type_info['title'])));
  2562. $form_state['redirect'] = 'admin/config/regional/date-time';
  2563. }
  2564. }
  2565. /**
  2566. * Displays the date format strings overview page.
  2567. */
  2568. function system_date_time_formats() {
  2569. $header = array(t('Format'), array('data' => t('Operations'), 'colspan' => '2'));
  2570. $rows = array();
  2571. drupal_static_reset('system_get_date_formats');
  2572. $formats = system_get_date_formats('custom');
  2573. if (!empty($formats)) {
  2574. foreach ($formats as $format) {
  2575. $row = array();
  2576. $row[] = array('data' => format_date(REQUEST_TIME, 'custom', $format['format']));
  2577. $row[] = array('data' => l(t('edit'), 'admin/config/regional/date-time/formats/' . $format['dfid'] . '/edit'));
  2578. $row[] = array('data' => l(t('delete'), 'admin/config/regional/date-time/formats/' . $format['dfid'] . '/delete'));
  2579. $rows[] = $row;
  2580. }
  2581. }
  2582. $build['date_formats_table'] = array(
  2583. '#theme' => 'table',
  2584. '#header' => $header,
  2585. '#rows' => $rows,
  2586. '#empty' => t('No custom date formats available. <a href="@link">Add date format</a>.', array('@link' => url('admin/config/regional/date-time/formats/add'))),
  2587. );
  2588. return $build;
  2589. }
  2590. /**
  2591. * Allow users to add additional date formats.
  2592. */
  2593. function system_configure_date_formats_form($form, &$form_state, $dfid = 0) {
  2594. $js_settings = array(
  2595. 'type' => 'setting',
  2596. 'data' => array(
  2597. 'dateTime' => array(
  2598. 'date-format' => array(
  2599. 'text' => t('Displayed as'),
  2600. 'lookup' => url('admin/config/regional/date-time/formats/lookup'),
  2601. ),
  2602. ),
  2603. ),
  2604. );
  2605. if ($dfid) {
  2606. $form['dfid'] = array(
  2607. '#type' => 'value',
  2608. '#value' => $dfid,
  2609. );
  2610. $format = system_get_date_format($dfid);
  2611. }
  2612. $now = ($dfid ? t('Displayed as %date', array('%date' => format_date(REQUEST_TIME, 'custom', $format->format))) : '');
  2613. $form['date_format'] = array(
  2614. '#type' => 'textfield',
  2615. '#title' => t('Format string'),
  2616. '#maxlength' => 100,
  2617. '#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')),
  2618. '#default_value' => ($dfid ? $format->format : ''),
  2619. '#field_suffix' => ' <small id="edit-date-format-suffix">' . $now . '</small>',
  2620. '#attached' => array(
  2621. 'js' => array(drupal_get_path('module', 'system') . '/system.js', $js_settings),
  2622. ),
  2623. '#required' => TRUE,
  2624. );
  2625. $form['actions'] = array('#type' => 'actions');
  2626. $form['actions']['update'] = array(
  2627. '#type' => 'submit',
  2628. '#value' => ($dfid ? t('Save format') : t('Add format')),
  2629. );
  2630. $form['#validate'][] = 'system_add_date_formats_form_validate';
  2631. $form['#submit'][] = 'system_add_date_formats_form_submit';
  2632. return $form;
  2633. }
  2634. /**
  2635. * Validate new date format string submission.
  2636. */
  2637. function system_add_date_formats_form_validate($form, &$form_state) {
  2638. $formats = system_get_date_formats('custom');
  2639. $format = trim($form_state['values']['date_format']);
  2640. if (!empty($formats) && in_array($format, array_keys($formats)) && (!isset($form_state['values']['dfid']) || $form_state['values']['dfid'] != $formats[$format]['dfid'])) {
  2641. form_set_error('date_format', t('This format already exists. Enter a unique format string.'));
  2642. }
  2643. }
  2644. /**
  2645. * Process new date format string submission.
  2646. */
  2647. function system_add_date_formats_form_submit($form, &$form_state) {
  2648. $format = array();
  2649. $format['format'] = trim($form_state['values']['date_format']);
  2650. $format['type'] = 'custom';
  2651. $format['locked'] = 0;
  2652. if (!empty($form_state['values']['dfid'])) {
  2653. system_date_format_save($format, $form_state['values']['dfid']);
  2654. drupal_set_message(t('Custom date format updated.'));
  2655. }
  2656. else {
  2657. $format['is_new'] = 1;
  2658. system_date_format_save($format);
  2659. drupal_set_message(t('Custom date format added.'));
  2660. }
  2661. $form_state['redirect'] = 'admin/config/regional/date-time/formats';
  2662. }
  2663. /**
  2664. * Menu callback; Displays an overview of available and configured actions.
  2665. */
  2666. function system_actions_manage() {
  2667. actions_synchronize();
  2668. $actions = actions_list();
  2669. $actions_map = actions_actions_map($actions);
  2670. $options = array();
  2671. $unconfigurable = array();
  2672. foreach ($actions_map as $key => $array) {
  2673. if ($array['configurable']) {
  2674. $options[$key] = $array['label'] . '...';
  2675. }
  2676. else {
  2677. $unconfigurable[] = $array;
  2678. }
  2679. }
  2680. $row = array();
  2681. $instances_present = db_query("SELECT aid FROM {actions} WHERE parameters <> ''")->fetchField();
  2682. $header = array(
  2683. array('data' => t('Action type'), 'field' => 'type'),
  2684. array('data' => t('Label'), 'field' => 'label'),
  2685. array('data' => $instances_present ? t('Operations') : '', 'colspan' => '2')
  2686. );
  2687. $query = db_select('actions')->extend('PagerDefault')->extend('TableSort');
  2688. $result = $query
  2689. ->fields('actions')
  2690. ->limit(50)
  2691. ->orderByHeader($header)
  2692. ->execute();
  2693. foreach ($result as $action) {
  2694. $row[] = array(
  2695. array('data' => $action->type),
  2696. array('data' => check_plain($action->label)),
  2697. array('data' => $action->parameters ? l(t('configure'), "admin/config/system/actions/configure/$action->aid") : ''),
  2698. array('data' => $action->parameters ? l(t('delete'), "admin/config/system/actions/delete/$action->aid") : '')
  2699. );
  2700. }
  2701. if ($row) {
  2702. $pager = theme('pager');
  2703. if (!empty($pager)) {
  2704. $row[] = array(array('data' => $pager, 'colspan' => '3'));
  2705. }
  2706. $build['system_actions_header'] = array('#markup' => '<h3>' . t('Available actions:') . '</h3>');
  2707. $build['system_actions_table'] = array('#markup' => theme('table', array('header' => $header, 'rows' => $row)));
  2708. }
  2709. if ($actions_map) {
  2710. $build['system_actions_manage_form'] = drupal_get_form('system_actions_manage_form', $options);
  2711. }
  2712. return $build;
  2713. }
  2714. /**
  2715. * Define the form for the actions overview page.
  2716. *
  2717. * @param $form_state
  2718. * An associative array containing the current state of the form; not used.
  2719. * @param $options
  2720. * An array of configurable actions.
  2721. * @return
  2722. * Form definition.
  2723. *
  2724. * @ingroup forms
  2725. * @see system_actions_manage_form_submit()
  2726. */
  2727. function system_actions_manage_form($form, &$form_state, $options = array()) {
  2728. $form['parent'] = array(
  2729. '#type' => 'fieldset',
  2730. '#title' => t('Create an advanced action'),
  2731. '#attributes' => array('class' => array('container-inline')),
  2732. );
  2733. $form['parent']['action'] = array(
  2734. '#type' => 'select',
  2735. '#title' => t('Action'),
  2736. '#title_display' => 'invisible',
  2737. '#options' => $options,
  2738. '#empty_option' => t('Choose an advanced action'),
  2739. );
  2740. $form['parent']['actions'] = array('#type' => 'actions');
  2741. $form['parent']['actions']['submit'] = array(
  2742. '#type' => 'submit',
  2743. '#value' => t('Create'),
  2744. );
  2745. return $form;
  2746. }
  2747. /**
  2748. * Process system_actions_manage form submissions.
  2749. *
  2750. * @see system_actions_manage_form()
  2751. */
  2752. function system_actions_manage_form_submit($form, &$form_state) {
  2753. if ($form_state['values']['action']) {
  2754. $form_state['redirect'] = 'admin/config/system/actions/configure/' . $form_state['values']['action'];
  2755. }
  2756. }
  2757. /**
  2758. * Menu callback; Creates the form for configuration of a single action.
  2759. *
  2760. * We provide the "Description" field. The rest of the form is provided by the
  2761. * action. We then provide the Save button. Because we are combining unknown
  2762. * form elements with the action configuration form, we use an 'actions_' prefix
  2763. * on our elements.
  2764. *
  2765. * @param $action
  2766. * Hash of an action ID or an integer. If it is a hash, we are
  2767. * creating a new instance. If it is an integer, we are editing an existing
  2768. * instance.
  2769. * @return
  2770. * A form definition.
  2771. *
  2772. * @see system_actions_configure_validate()
  2773. * @see system_actions_configure_submit()
  2774. */
  2775. function system_actions_configure($form, &$form_state, $action = NULL) {
  2776. if ($action === NULL) {
  2777. drupal_goto('admin/config/system/actions');
  2778. }
  2779. $actions_map = actions_actions_map(actions_list());
  2780. $edit = array();
  2781. // Numeric action denotes saved instance of a configurable action.
  2782. if (is_numeric($action)) {
  2783. $aid = $action;
  2784. // Load stored parameter values from database.
  2785. $data = db_query("SELECT * FROM {actions} WHERE aid = :aid", array(':aid' => $aid))->fetch();
  2786. $edit['actions_label'] = $data->label;
  2787. $edit['actions_type'] = $data->type;
  2788. $function = $data->callback;
  2789. $action = drupal_hash_base64($data->callback);
  2790. $params = unserialize($data->parameters);
  2791. if ($params) {
  2792. foreach ($params as $name => $val) {
  2793. $edit[$name] = $val;
  2794. }
  2795. }
  2796. }
  2797. // Otherwise, we are creating a new action instance.
  2798. else {
  2799. $function = $actions_map[$action]['callback'];
  2800. $edit['actions_label'] = $actions_map[$action]['label'];
  2801. $edit['actions_type'] = $actions_map[$action]['type'];
  2802. }
  2803. $form['actions_label'] = array(
  2804. '#type' => 'textfield',
  2805. '#title' => t('Label'),
  2806. '#default_value' => $edit['actions_label'],
  2807. '#maxlength' => '255',
  2808. '#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.'),
  2809. '#weight' => -10
  2810. );
  2811. $action_form = $function . '_form';
  2812. $form = array_merge($form, $action_form($edit));
  2813. $form['actions_type'] = array(
  2814. '#type' => 'value',
  2815. '#value' => $edit['actions_type'],
  2816. );
  2817. $form['actions_action'] = array(
  2818. '#type' => 'hidden',
  2819. '#value' => $action,
  2820. );
  2821. // $aid is set when configuring an existing action instance.
  2822. if (isset($aid)) {
  2823. $form['actions_aid'] = array(
  2824. '#type' => 'hidden',
  2825. '#value' => $aid,
  2826. );
  2827. }
  2828. $form['actions_configured'] = array(
  2829. '#type' => 'hidden',
  2830. '#value' => '1',
  2831. );
  2832. $form['actions'] = array('#type' => 'actions');
  2833. $form['actions']['submit'] = array(
  2834. '#type' => 'submit',
  2835. '#value' => t('Save'),
  2836. '#weight' => 13
  2837. );
  2838. return $form;
  2839. }
  2840. /**
  2841. * Validate system_actions_configure() form submissions.
  2842. */
  2843. function system_actions_configure_validate($form, &$form_state) {
  2844. $function = actions_function_lookup($form_state['values']['actions_action']) . '_validate';
  2845. // Hand off validation to the action.
  2846. if (function_exists($function)) {
  2847. $function($form, $form_state);
  2848. }
  2849. }
  2850. /**
  2851. * Process system_actions_configure() form submissions.
  2852. */
  2853. function system_actions_configure_submit($form, &$form_state) {
  2854. $function = actions_function_lookup($form_state['values']['actions_action']);
  2855. $submit_function = $function . '_submit';
  2856. // Action will return keyed array of values to store.
  2857. $params = $submit_function($form, $form_state);
  2858. $aid = isset($form_state['values']['actions_aid']) ? $form_state['values']['actions_aid'] : NULL;
  2859. actions_save($function, $form_state['values']['actions_type'], $params, $form_state['values']['actions_label'], $aid);
  2860. drupal_set_message(t('The action has been successfully saved.'));
  2861. $form_state['redirect'] = 'admin/config/system/actions/manage';
  2862. }
  2863. /**
  2864. * Create the form for confirmation of deleting an action.
  2865. *
  2866. * @see system_actions_delete_form_submit()
  2867. * @ingroup forms
  2868. */
  2869. function system_actions_delete_form($form, &$form_state, $action) {
  2870. $form['aid'] = array(
  2871. '#type' => 'hidden',
  2872. '#value' => $action->aid,
  2873. );
  2874. return confirm_form($form,
  2875. t('Are you sure you want to delete the action %action?', array('%action' => $action->label)),
  2876. 'admin/config/system/actions/manage',
  2877. t('This cannot be undone.'),
  2878. t('Delete'),
  2879. t('Cancel')
  2880. );
  2881. }
  2882. /**
  2883. * Process system_actions_delete form submissions.
  2884. *
  2885. * Post-deletion operations for action deletion.
  2886. */
  2887. function system_actions_delete_form_submit($form, &$form_state) {
  2888. $aid = $form_state['values']['aid'];
  2889. $action = actions_load($aid);
  2890. actions_delete($aid);
  2891. watchdog('user', 'Deleted action %aid (%action)', array('%aid' => $aid, '%action' => $action->label));
  2892. drupal_set_message(t('Action %action was deleted', array('%action' => $action->label)));
  2893. $form_state['redirect'] = 'admin/config/system/actions/manage';
  2894. }
  2895. /**
  2896. * Post-deletion operations for deleting action orphans.
  2897. *
  2898. * @param $orphaned
  2899. * An array of orphaned actions.
  2900. */
  2901. function system_action_delete_orphans_post($orphaned) {
  2902. foreach ($orphaned as $callback) {
  2903. drupal_set_message(t("Deleted orphaned action (%action).", array('%action' => $callback)));
  2904. }
  2905. }
  2906. /**
  2907. * Remove actions that are in the database but not supported by any enabled module.
  2908. */
  2909. function system_actions_remove_orphans() {
  2910. actions_synchronize(TRUE);
  2911. drupal_goto('admin/config/system/actions/manage');
  2912. }