standard.install 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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. $vocabulary = (object) array(
  268. 'name' => st('Tags'),
  269. 'description' => $description,
  270. 'machine_name' => 'tags',
  271. );
  272. taxonomy_vocabulary_save($vocabulary);
  273. $field = array(
  274. 'field_name' => 'field_' . $vocabulary->machine_name,
  275. 'type' => 'taxonomy_term_reference',
  276. // Set cardinality to unlimited for tagging.
  277. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  278. 'settings' => array(
  279. 'allowed_values' => array(
  280. array(
  281. 'vocabulary' => $vocabulary->machine_name,
  282. 'parent' => 0,
  283. ),
  284. ),
  285. ),
  286. );
  287. field_create_field($field);
  288. $help = st('Enter a comma-separated list of words to describe your content.');
  289. $instance = array(
  290. 'field_name' => 'field_' . $vocabulary->machine_name,
  291. 'entity_type' => 'node',
  292. 'label' => 'Tags',
  293. 'bundle' => 'article',
  294. 'description' => $help,
  295. 'widget' => array(
  296. 'type' => 'taxonomy_autocomplete',
  297. 'weight' => -4,
  298. ),
  299. 'display' => array(
  300. 'default' => array(
  301. 'type' => 'taxonomy_term_reference_link',
  302. 'weight' => 10,
  303. ),
  304. 'teaser' => array(
  305. 'type' => 'taxonomy_term_reference_link',
  306. 'weight' => 10,
  307. ),
  308. ),
  309. );
  310. field_create_instance($instance);
  311. // Create an image field named "Image", enabled for the 'article' content type.
  312. // Many of the following values will be defaulted, they're included here as an illustrative examples.
  313. // See http://api.drupal.org/api/function/field_create_field/7
  314. $field = array(
  315. 'field_name' => 'field_image',
  316. 'type' => 'image',
  317. 'cardinality' => 1,
  318. 'locked' => FALSE,
  319. 'indexes' => array('fid' => array('fid')),
  320. 'settings' => array(
  321. 'uri_scheme' => 'public',
  322. 'default_image' => FALSE,
  323. ),
  324. 'storage' => array(
  325. 'type' => 'field_sql_storage',
  326. 'settings' => array(),
  327. ),
  328. );
  329. field_create_field($field);
  330. // Many of the following values will be defaulted, they're included here as an illustrative examples.
  331. // See http://api.drupal.org/api/function/field_create_instance/7
  332. $instance = array(
  333. 'field_name' => 'field_image',
  334. 'entity_type' => 'node',
  335. 'label' => 'Image',
  336. 'bundle' => 'article',
  337. 'description' => st('Upload an image to go with this article.'),
  338. 'required' => FALSE,
  339. 'settings' => array(
  340. 'file_directory' => 'field/image',
  341. 'file_extensions' => 'png gif jpg jpeg',
  342. 'max_filesize' => '',
  343. 'max_resolution' => '',
  344. 'min_resolution' => '',
  345. 'alt_field' => TRUE,
  346. 'title_field' => '',
  347. ),
  348. 'widget' => array(
  349. 'type' => 'image_image',
  350. 'settings' => array(
  351. 'progress_indicator' => 'throbber',
  352. 'preview_image_style' => 'thumbnail',
  353. ),
  354. 'weight' => -1,
  355. ),
  356. 'display' => array(
  357. 'default' => array(
  358. 'label' => 'hidden',
  359. 'type' => 'image',
  360. 'settings' => array('image_style' => 'large', 'image_link' => ''),
  361. 'weight' => -1,
  362. ),
  363. 'teaser' => array(
  364. 'label' => 'hidden',
  365. 'type' => 'image',
  366. 'settings' => array('image_style' => 'medium', 'image_link' => 'content'),
  367. 'weight' => -1,
  368. ),
  369. ),
  370. );
  371. field_create_instance($instance);
  372. // Enable default permissions for system roles.
  373. $filtered_html_permission = filter_permission_name($filtered_html_format);
  374. user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access content', 'access comments', $filtered_html_permission));
  375. user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('access content', 'access comments', 'post comments', 'skip comment approval', $filtered_html_permission));
  376. // Create a default role for site administrators, with all available permissions assigned.
  377. $admin_role = new stdClass();
  378. $admin_role->name = 'administrator';
  379. $admin_role->weight = 2;
  380. user_role_save($admin_role);
  381. user_role_grant_permissions($admin_role->rid, array_keys(module_invoke_all('permission')));
  382. // Set this as the administrator role.
  383. variable_set('user_admin_role', $admin_role->rid);
  384. // Assign user 1 the "administrator" role.
  385. db_insert('users_roles')
  386. ->fields(array('uid' => 1, 'rid' => $admin_role->rid))
  387. ->execute();
  388. // Create a Home link in the main menu.
  389. $item = array(
  390. 'link_title' => st('Home'),
  391. 'link_path' => '<front>',
  392. 'menu_name' => 'main-menu',
  393. );
  394. menu_link_save($item);
  395. // Update the menu router information.
  396. menu_rebuild();
  397. // Enable the admin theme.
  398. db_update('system')
  399. ->fields(array('status' => 1))
  400. ->condition('type', 'theme')
  401. ->condition('name', 'seven')
  402. ->execute();
  403. variable_set('admin_theme', 'seven');
  404. variable_set('node_admin_theme', '1');
  405. }