system.admin.inc 113 KB

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