standard.install 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the standard installation profile.
  5. */
  6. /**
  7. * Implements hook_install().
  8. *
  9. * Perform actions to set up the site for this profile.
  10. *
  11. * @see system_install()
  12. */
  13. function standard_install() {
  14. // Add text formats.
  15. $filtered_html_format = array(
  16. 'format' => 'filtered_html',
  17. 'name' => 'Filtered HTML',
  18. 'weight' => 0,
  19. 'filters' => array(
  20. // URL filter.
  21. 'filter_url' => array(
  22. 'weight' => 0,
  23. 'status' => 1,
  24. ),
  25. // HTML filter.
  26. 'filter_html' => array(
  27. 'weight' => 1,
  28. 'status' => 1,
  29. ),
  30. // Line break filter.
  31. 'filter_autop' => array(
  32. 'weight' => 2,
  33. 'status' => 1,
  34. ),
  35. // HTML corrector filter.
  36. 'filter_htmlcorrector' => array(
  37. 'weight' => 10,
  38. 'status' => 1,
  39. ),
  40. ),
  41. );
  42. $filtered_html_format = (object) $filtered_html_format;
  43. filter_format_save($filtered_html_format);
  44. $full_html_format = array(
  45. 'format' => 'full_html',
  46. 'name' => 'Full HTML',
  47. 'weight' => 1,
  48. 'filters' => array(
  49. // URL filter.
  50. 'filter_url' => array(
  51. 'weight' => 0,
  52. 'status' => 1,
  53. ),
  54. // Line break filter.
  55. 'filter_autop' => array(
  56. 'weight' => 1,
  57. 'status' => 1,
  58. ),
  59. // HTML corrector filter.
  60. 'filter_htmlcorrector' => array(
  61. 'weight' => 10,
  62. 'status' => 1,
  63. ),
  64. ),
  65. );
  66. $full_html_format = (object) $full_html_format;
  67. filter_format_save($full_html_format);
  68. // Enable some standard blocks.
  69. $default_theme = variable_get('theme_default', 'bartik');
  70. $admin_theme = 'seven';
  71. $blocks = array(
  72. array(
  73. 'module' => 'system',
  74. 'delta' => 'main',
  75. 'theme' => $default_theme,
  76. 'status' => 1,
  77. 'weight' => 0,
  78. 'region' => 'content',
  79. 'pages' => '',
  80. 'cache' => -1,
  81. ),
  82. array(
  83. 'module' => 'search',
  84. 'delta' => 'form',
  85. 'theme' => $default_theme,
  86. 'status' => 1,
  87. 'weight' => -1,
  88. 'region' => 'sidebar_first',
  89. 'pages' => '',
  90. 'cache' => -1,
  91. ),
  92. array(
  93. 'module' => 'node',
  94. 'delta' => 'recent',
  95. 'theme' => $admin_theme,
  96. 'status' => 1,
  97. 'weight' => 10,
  98. 'region' => 'dashboard_main',
  99. 'pages' => '',
  100. 'cache' => -1,
  101. ),
  102. array(
  103. 'module' => 'user',
  104. 'delta' => 'login',
  105. 'theme' => $default_theme,
  106. 'status' => 1,
  107. 'weight' => 0,
  108. 'region' => 'sidebar_first',
  109. 'pages' => '',
  110. 'cache' => -1,
  111. ),
  112. array(
  113. 'module' => 'system',
  114. 'delta' => 'navigation',
  115. 'theme' => $default_theme,
  116. 'status' => 1,
  117. 'weight' => 0,
  118. 'region' => 'sidebar_first',
  119. 'pages' => '',
  120. 'cache' => -1,
  121. ),
  122. array(
  123. 'module' => 'system',
  124. 'delta' => 'powered-by',
  125. 'theme' => $default_theme,
  126. 'status' => 1,
  127. 'weight' => 10,
  128. 'region' => 'footer',
  129. 'pages' => '',
  130. 'cache' => -1,
  131. ),
  132. array(
  133. 'module' => 'system',
  134. 'delta' => 'help',
  135. 'theme' => $default_theme,
  136. 'status' => 1,
  137. 'weight' => 0,
  138. 'region' => 'help',
  139. 'pages' => '',
  140. 'cache' => -1,
  141. ),
  142. array(
  143. 'module' => 'system',
  144. 'delta' => 'main',
  145. 'theme' => $admin_theme,
  146. 'status' => 1,
  147. 'weight' => 0,
  148. 'region' => 'content',
  149. 'pages' => '',
  150. 'cache' => -1,
  151. ),
  152. array(
  153. 'module' => 'system',
  154. 'delta' => 'help',
  155. 'theme' => $admin_theme,
  156. 'status' => 1,
  157. 'weight' => 0,
  158. 'region' => 'help',
  159. 'pages' => '',
  160. 'cache' => -1,
  161. ),
  162. array(
  163. 'module' => 'user',
  164. 'delta' => 'login',
  165. 'theme' => $admin_theme,
  166. 'status' => 1,
  167. 'weight' => 10,
  168. 'region' => 'content',
  169. 'pages' => '',
  170. 'cache' => -1,
  171. ),
  172. array(
  173. 'module' => 'user',
  174. 'delta' => 'new',
  175. 'theme' => $admin_theme,
  176. 'status' => 1,
  177. 'weight' => 0,
  178. 'region' => 'dashboard_sidebar',
  179. 'pages' => '',
  180. 'cache' => -1,
  181. ),
  182. array(
  183. 'module' => 'search',
  184. 'delta' => 'form',
  185. 'theme' => $admin_theme,
  186. 'status' => 1,
  187. 'weight' => -10,
  188. 'region' => 'dashboard_sidebar',
  189. 'pages' => '',
  190. 'cache' => -1,
  191. ),
  192. );
  193. $query = db_insert('block')->fields(array('module', 'delta', 'theme', 'status', 'weight', 'region', 'pages', 'cache'));
  194. foreach ($blocks as $block) {
  195. $query->values($block);
  196. }
  197. $query->execute();
  198. // Insert default pre-defined node types into the database. For a complete
  199. // list of available node type attributes, refer to the node type API
  200. // documentation at: http://api.drupal.org/api/HEAD/function/hook_node_info.
  201. $types = array(
  202. array(
  203. 'type' => 'page',
  204. 'name' => st('Basic page'),
  205. 'base' => 'node_content',
  206. 'description' => st("Use <em>basic pages</em> for your static content, such as an 'About us' page."),
  207. 'custom' => 1,
  208. 'modified' => 1,
  209. 'locked' => 0,
  210. ),
  211. array(
  212. 'type' => 'article',
  213. 'name' => st('Article'),
  214. 'base' => 'node_content',
  215. 'description' => st('Use <em>articles</em> for time-sensitive content like news, press releases or blog posts.'),
  216. 'custom' => 1,
  217. 'modified' => 1,
  218. 'locked' => 0,
  219. ),
  220. );
  221. foreach ($types as $type) {
  222. $type = node_type_set_defaults($type);
  223. node_type_save($type);
  224. node_add_body_field($type);
  225. }
  226. // Insert default pre-defined RDF mapping into the database.
  227. $rdf_mappings = array(
  228. array(
  229. 'type' => 'node',
  230. 'bundle' => 'page',
  231. 'mapping' => array(
  232. 'rdftype' => array('foaf:Document'),
  233. ),
  234. ),
  235. array(
  236. 'type' => 'node',
  237. 'bundle' => 'article',
  238. 'mapping' => array(
  239. 'field_image' => array(
  240. 'predicates' => array('og:image', 'rdfs:seeAlso'),
  241. 'type' => 'rel',
  242. ),
  243. 'field_tags' => array(
  244. 'predicates' => array('dc:subject'),
  245. 'type' => 'rel',
  246. ),
  247. ),
  248. ),
  249. );
  250. foreach ($rdf_mappings as $rdf_mapping) {
  251. rdf_mapping_save($rdf_mapping);
  252. }
  253. // Default "Basic page" to not be promoted and have comments disabled.
  254. variable_set('node_options_page', array('status'));
  255. variable_set('comment_page', COMMENT_NODE_HIDDEN);
  256. // Don't display date and author information for "Basic page" nodes by default.
  257. variable_set('node_submitted_page', FALSE);
  258. // Enable user picture support and set the default to a square thumbnail option.
  259. variable_set('user_pictures', '1');
  260. variable_set('user_picture_dimensions', '1024x1024');
  261. variable_set('user_picture_file_size', '800');
  262. variable_set('user_picture_style', 'thumbnail');
  263. // Allow visitor account creation with administrative approval.
  264. variable_set('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL);
  265. // Create a default vocabulary named "Tags", enabled for the 'article' content type.
  266. $description = st('Use tags to group articles on similar topics into categories.');
  267. $help = st('Enter a comma-separated list of words to describe your content.');
  268. $vocabulary = (object) array(
  269. 'name' => st('Tags'),
  270. 'description' => $description,
  271. 'machine_name' => 'tags',
  272. 'help' => $help,
  273. );
  274. taxonomy_vocabulary_save($vocabulary);
  275. $field = array(
  276. 'field_name' => 'field_' . $vocabulary->machine_name,
  277. 'type' => 'taxonomy_term_reference',
  278. // Set cardinality to unlimited for tagging.
  279. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  280. 'settings' => array(
  281. 'allowed_values' => array(
  282. array(
  283. 'vocabulary' => $vocabulary->machine_name,
  284. 'parent' => 0,
  285. ),
  286. ),
  287. ),
  288. );
  289. field_create_field($field);
  290. $instance = array(
  291. 'field_name' => 'field_' . $vocabulary->machine_name,
  292. 'entity_type' => 'node',
  293. 'label' => 'Tags',
  294. 'bundle' => 'article',
  295. 'description' => $vocabulary->help,
  296. 'widget' => array(
  297. 'type' => 'taxonomy_autocomplete',
  298. 'weight' => -4,
  299. ),
  300. 'display' => array(
  301. 'default' => array(
  302. 'type' => 'taxonomy_term_reference_link',
  303. 'weight' => 10,
  304. ),
  305. 'teaser' => array(
  306. 'type' => 'taxonomy_term_reference_link',
  307. 'weight' => 10,
  308. ),
  309. ),
  310. );
  311. field_create_instance($instance);
  312. // Create an image field named "Image", enabled for the 'article' content type.
  313. // Many of the following values will be defaulted, they're included here as an illustrative examples.
  314. // See http://api.drupal.org/api/function/field_create_field/7
  315. $field = array(
  316. 'field_name' => 'field_image',
  317. 'type' => 'image',
  318. 'cardinality' => 1,
  319. 'locked' => FALSE,
  320. 'indexes' => array('fid' => array('fid')),
  321. 'settings' => array(
  322. 'uri_scheme' => 'public',
  323. 'default_image' => FALSE,
  324. ),
  325. 'storage' => array(
  326. 'type' => 'field_sql_storage',
  327. 'settings' => array(),
  328. ),
  329. );
  330. field_create_field($field);
  331. // Many of the following values will be defaulted, they're included here as an illustrative examples.
  332. // See http://api.drupal.org/api/function/field_create_instance/7
  333. $instance = array(
  334. 'field_name' => 'field_image',
  335. 'entity_type' => 'node',
  336. 'label' => 'Image',
  337. 'bundle' => 'article',
  338. 'description' => st('Upload an image to go with this article.'),
  339. 'required' => FALSE,
  340. 'settings' => array(
  341. 'file_directory' => 'field/image',
  342. 'file_extensions' => 'png gif jpg jpeg',
  343. 'max_filesize' => '',
  344. 'max_resolution' => '',
  345. 'min_resolution' => '',
  346. 'alt_field' => TRUE,
  347. 'title_field' => '',
  348. ),
  349. 'widget' => array(
  350. 'type' => 'image_image',
  351. 'settings' => array(
  352. 'progress_indicator' => 'throbber',
  353. 'preview_image_style' => 'thumbnail',
  354. ),
  355. 'weight' => -1,
  356. ),
  357. 'display' => array(
  358. 'default' => array(
  359. 'label' => 'hidden',
  360. 'type' => 'image',
  361. 'settings' => array('image_style' => 'large', 'image_link' => ''),
  362. 'weight' => -1,
  363. ),
  364. 'teaser' => array(
  365. 'label' => 'hidden',
  366. 'type' => 'image',
  367. 'settings' => array('image_style' => 'medium', 'image_link' => 'content'),
  368. 'weight' => -1,
  369. ),
  370. ),
  371. );
  372. field_create_instance($instance);
  373. // Enable default permissions for system roles.
  374. $filtered_html_permission = filter_permission_name($filtered_html_format);
  375. user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access content', 'access comments', $filtered_html_permission));
  376. user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('access content', 'access comments', 'post comments', 'skip comment approval', $filtered_html_permission));
  377. // Create a default role for site administrators, with all available permissions assigned.
  378. $admin_role = new stdClass();
  379. $admin_role->name = 'administrator';
  380. $admin_role->weight = 2;
  381. user_role_save($admin_role);
  382. user_role_grant_permissions($admin_role->rid, array_keys(module_invoke_all('permission')));
  383. // Set this as the administrator role.
  384. variable_set('user_admin_role', $admin_role->rid);
  385. // Assign user 1 the "administrator" role.
  386. db_insert('users_roles')
  387. ->fields(array('uid' => 1, 'rid' => $admin_role->rid))
  388. ->execute();
  389. // Create a Home link in the main menu.
  390. $item = array(
  391. 'link_title' => st('Home'),
  392. 'link_path' => '<front>',
  393. 'menu_name' => 'main-menu',
  394. );
  395. menu_link_save($item);
  396. // Update the menu router information.
  397. menu_rebuild();
  398. // Enable the admin theme.
  399. db_update('system')
  400. ->fields(array('status' => 1))
  401. ->condition('type', 'theme')
  402. ->condition('name', 'seven')
  403. ->execute();
  404. variable_set('admin_theme', 'seven');
  405. variable_set('node_admin_theme', '1');
  406. }