system.admin.inc 115 KB

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