content_profile.module

Tracking 6.x-1.x branch
  1. drupal
    1. 6 contributions/content_profile/content_profile.module

Marks content types as profiles.

Functions & methods

NameDescription
content_profile_admin_settingsMenu callback; content profile settings.
content_profile_admin_settings_submit
content_profile_content_profile_settingsImplementation of hook_content_profile_settings().
content_profile_ctools_plugin_directoryImplementation of hook_ctools_plugin_directory().
content_profile_field_formatter_infoImplementation of hook_field_formatter_info().
content_profile_form_alterImplementation of hook_form_alter().
content_profile_get_settingsReturns the content_profiles' settings.
content_profile_get_typesBuilds a list of available content types that are marked as content_profiles, and returns an array of content profile content types in the specified format.
content_profile_helpImplementation of hook_help().
content_profile_loadLoads the node, like node_load but makes sure the results are cached.
content_profile_menuImplementation of hook_menu().
content_profile_menu_alterImplementation of hook_menu_alter(). Take over menu items generated by the user module for our categories.
content_profile_nodeapiImplementation of hook_nodeapi().
content_profile_node_typeImplementation of hook_node_type(). Rename or delete the settings variable if a type changes.
content_profile_pageroute_infoImplementation of hook_pageroute_info() for Pageroute integration.
content_profile_page_access
content_profile_page_editPresents a node editing or adding form for the given content profile.
content_profile_profile_existsChecks whether a node of this type exists already for the author
content_profile_settings_infoReturns an array, which defines the available settings and their default value.
content_profile_set_settingsSaves the content_profile settings of a content type.
content_profile_show_profilesReturns an array suitable for use with drupal_render, that shows all content_profiles as configured by the admin.
content_profile_simpletestImplementation of hook_simpletest().
content_profile_template_preprocessAdds $content_profile variable if we can find a $uid.
content_profile_themeImplementation of hook_theme().
content_profile_theme_registry_alterImplementation of hook_theme_registry_alter(). Adds our own preprocess functions to some templates. Further templates can be set in $conf['content_profile_extra_templates'] in settings.php.
content_profile_userImplementation of hook_user().
content_profile_views_apiImplementation of hook_views_api().
is_content_profileDetermine if a given node is a content_profile.
_content_profile_node_deleteThe original node_delete() function uses node_load() to get the $node object. Unfortunately, when a hook_user('delete') is called, node_load() doesn't work anymore because the user has already been deleted, and node_load() still expects…

File

View source
  1. <?php
  2. /**
  3. * @file
  4. * Marks content types as profiles.
  5. */
  6. require_once dirname(__FILE__) . '/content_profile.theme_vars.inc';
  7. /**
  8. * Implementation of hook_ctools_plugin_directory().
  9. */
  10. function content_profile_ctools_plugin_directory($module, $plugin) {
  11. if ($module == 'ctools' && $plugin == 'relationships') {
  12. return 'panels/' . $plugin;
  13. }
  14. }
  15. /**
  16. * Implementation of hook_menu().
  17. */
  18. function content_profile_menu() {
  19. $items = array();
  20. //Register a path for each content profile type
  21. foreach (content_profile_get_types('names') as $type => $typename) {
  22. $items['admin/content/node-type/'. str_replace('_', '-', $type) .'/edit'] = array(
  23. 'title' => 'Edit',
  24. 'type' => MENU_DEFAULT_LOCAL_TASK,
  25. );
  26. $items['admin/content/node-type/'. str_replace('_', '-', $type) .'/profile'] = array(
  27. 'title' => 'Content profile',
  28. 'description' => 'Configure the display and management of this content profile.',
  29. 'page callback' => 'drupal_get_form',
  30. 'page arguments' => array('content_profile_admin_settings', $type),
  31. 'access callback' => 'user_access',
  32. 'access arguments' => array('administer nodes'),
  33. 'type' => MENU_LOCAL_TASK,
  34. 'weight' => 1,
  35. );
  36. }
  37. foreach (content_profile_get_types('names') as $type => $type_name) {
  38. $items['user/%user/profile/'. $type] = array(
  39. 'title callback' => 'check_plain',
  40. 'title' => drupal_ucfirst($type_name),
  41. 'page callback' => 'content_profile_page_edit',
  42. 'page arguments' => array($type, 1),
  43. 'access callback' => 'content_profile_page_access',
  44. 'access arguments' => array($type, 1),
  45. 'weight' => content_profile_get_settings($type, 'weight'),
  46. 'file' => 'node.pages.inc',
  47. 'file path' => drupal_get_path('module', 'node'),
  48. 'type' => content_profile_get_settings($type, 'edit_tab') == 'top' ? MENU_LOCAL_TASK : MENU_CALLBACK,
  49. );
  50. }
  51. return $items;
  52. }
  53. /**
  54. * Implementation of hook_menu_alter().
  55. * Take over menu items generated by the user module for our categories.
  56. */
  57. function content_profile_menu_alter(&$items) {
  58. foreach (content_profile_get_types('names', 'edit_tab', 'sub') as $type => $type_name) {
  59. if (!empty($items['user/%user_category/edit/'. $type])) {
  60. $item = &$items['user/%user_category/edit/'. $type];
  61. $item = array(
  62. 'page callback' => 'content_profile_page_edit',
  63. 'page arguments' => array($type, 1),
  64. 'access callback' => 'content_profile_page_access',
  65. 'access arguments' => array($type, 1),
  66. 'file' => 'node.pages.inc',
  67. 'file path' => drupal_get_path('module', 'node'),
  68. ) + $item;
  69. }
  70. }
  71. }
  72. function content_profile_page_access($type, $account) {
  73. if ($node = content_profile_load($type, $account->uid)) {
  74. return node_access('update', $node);
  75. }
  76. // Else user may view the page when they are going to create their own profile
  77. // or have permission to create it for others.
  78. global $user;
  79. if ($user->uid == $account->uid || user_access('administer nodes') ){
  80. return node_access('create', $type);
  81. }
  82. return FALSE;
  83. }
  84. /**
  85. * Presents a node editing or adding form for the given content profile.
  86. */
  87. function content_profile_page_edit($type, $account) {
  88. drupal_set_title(check_plain($account->name));
  89. $node = content_profile_load($type, $account->uid);
  90. if (!$node) {
  91. $node = array('uid' => $account->uid, 'name' => (isset($account->name) ? $account->name : ''), 'type' => $type, 'language' => '');
  92. }
  93. return drupal_get_form($type .'_node_form', $node);
  94. }
  95. /**
  96. * Implementation of hook_views_api().
  97. */
  98. function content_profile_views_api() {
  99. return array(
  100. 'api' => 2,
  101. 'path' => drupal_get_path('module', 'content_profile') .'/views',
  102. );
  103. }
  104. /**
  105. * Menu callback; content profile settings.
  106. */
  107. function content_profile_admin_settings(&$form_state, $type) {
  108. $form_state['type'] = $type;
  109. $form['weight'] = array(
  110. '#type' => 'weight',
  111. '#title' => t("Weight"),
  112. '#default_value' => content_profile_get_settings($type, 'weight'),
  113. '#description' => t('The weight of content of this content type where ever they appear - this applies to the input form integration as well to the display integration.'),
  114. '#weight' => 5,
  115. );
  116. $form['display'] = array(
  117. '#type' => 'fieldset',
  118. '#title' => t('Display settings'),
  119. '#description' => t('Customize the display of this content profile.'),
  120. '#collapsible' => TRUE,
  121. );
  122. $form['display']['user_display'] = array(
  123. '#type' => 'radios',
  124. '#title' => t("User page display style"),
  125. '#default_value' => content_profile_get_settings($type, 'user_display'),
  126. '#options' => array(
  127. 0 => t("Don't display this content profile on the user account page"),
  128. 'link' => t('Display it as link to the profile content'),
  129. 'full' => t('Display the full content'),
  130. 'teaser' => t("Display the content's teaser"),
  131. ),
  132. );
  133. $form['display']['edit_link'] = array(
  134. '#type' => 'checkbox',
  135. '#title' => t("Include an edit link to the display"),
  136. '#default_value' => content_profile_get_settings($type, 'edit_link'),
  137. );
  138. $form['display']['add_link'] = array(
  139. '#type' => 'checkbox',
  140. '#title' => t("Show a link to the content profile creation page, if there is no profile."),
  141. '#default_value' => content_profile_get_settings($type, 'add_link'),
  142. '#description' => t("If selected and the user has no profile of this type yet, a link to add one is shown on the user page."),
  143. );
  144. $form['display']['edit_tab'] = array(
  145. '#type' => 'radios',
  146. '#title' => t("Profile edit tab"),
  147. '#default_value' => content_profile_get_settings($type, 'edit_tab'),
  148. '#options' => array(
  149. 0 => t('None'),
  150. 'top' => t("Show a tab at the user's page"),
  151. 'sub' => t("Show a secondary tab below the user's edit tab"),
  152. ),
  153. );
  154. $form['submit'] = array(
  155. '#type' => 'submit',
  156. '#value' => t('Submit'),
  157. '#weight' => 10,
  158. );
  159. return $form;
  160. }
  161. function content_profile_admin_settings_submit($form, &$form_state) {
  162. $settings = content_profile_get_settings($form_state['type']);
  163. foreach (content_profile_settings_info() as $setting => $default) {
  164. if (isset($form_state['values'][$setting])) {
  165. $settings[$setting] = $form_state['values'][$setting];
  166. }
  167. }
  168. content_profile_set_settings($form_state['type'], $settings);
  169. drupal_set_message('Your changes have been saved.');
  170. menu_rebuild();
  171. }
  172. /**
  173. * Determine if a given node is a content_profile.
  174. * @param $type
  175. * The node object or the node's type
  176. */
  177. function is_content_profile($type) {
  178. if (is_object($type)) {
  179. $type = $type->type;
  180. }
  181. return variable_get('content_profile_use_'. $type, FALSE);
  182. }
  183. /**
  184. * Builds a list of available content types that are marked as content_profiles,
  185. * and returns an array of content profile content types in the specified format.
  186. *
  187. * @param $op
  188. * When set to 'types', content profile content types are returned
  189. * as type objects. When set to 'names', only their type names are returned.
  190. * @param $setting
  191. * If set, only content types that have this setting activated are returned.
  192. * Leave it NULL to get all content profile types.
  193. * @param $value
  194. * The value to compare the given setting too.
  195. */
  196. function content_profile_get_types($op = 'types', $setting = NULL , $value = TRUE) {
  197. $types = array();
  198. foreach (node_get_types($op) as $type => $info) {
  199. if (is_content_profile($type) && (!isset($setting) || content_profile_get_settings($type, $setting) == $value)) {
  200. $types[$type] = $info;
  201. }
  202. }
  203. return $types;
  204. }
  205. /**
  206. * Implementation of hook_node_type().
  207. * Rename or delete the settings variable if a type changes.
  208. */
  209. function content_profile_node_type($op, $info) {
  210. switch ($op) {
  211. case 'delete':
  212. variable_del('content_profile_use_'. $info->type);
  213. variable_del('content_profile_'. $info->type);
  214. break;
  215. case 'update':
  216. if (!empty($info->old_type) && $info->old_type != $info->type) {
  217. if (is_content_profile($info->old_type)) {
  218. $settings = variable_get('content_profile_'. $info->old_type, array());
  219. variable_del('content_profile_use_'. $info->old_type);
  220. variable_del('content_profile_'. $info->old_type);
  221. variable_set('content_profile_use_'. $info->type, 1);
  222. variable_set('content_profile_'. $info->type, $settings);
  223. }
  224. }
  225. break;
  226. }
  227. }
  228. /**
  229. * Implementation of hook_form_alter().
  230. */
  231. function content_profile_form_alter(&$form, $form_state, $form_id) {
  232. if ($form_id == 'node_type_form') {
  233. $form['content_profile'] = array(
  234. '#type' => 'fieldset',
  235. '#title' => t('Content Profile'),
  236. '#group' => 'additional_settings',
  237. '#collapsible' => TRUE,
  238. '#collapsed' => TRUE,
  239. '#weight' => 32,
  240. );
  241. $form['content_profile']['content_profile_use'] = array(
  242. '#type' => 'checkbox',
  243. '#title' => t('Use this content type as a content profile for users'),
  244. '#default_value' => variable_get('content_profile_use_'. $form['#node_type']->type, FALSE),
  245. );
  246. }
  247. elseif (isset($form['#node']) && $form['#node']->type .'_node_form' == $form_id && is_content_profile($form['#node'])) {
  248. // Customize the redirect target and buttons of our own node forms.
  249. if (arg(0) == 'user' && is_numeric(arg(1)) && arg(2) == 'edit' || arg(2) == 'profile') {
  250. $form['buttons']['preview']['#access'] = FALSE;
  251. $form['buttons']['delete']['#access'] = FALSE;
  252. $form['#redirect'] = arg(2) == 'profile' ? 'user/'. $form['#node']->uid : $_GET['q'];
  253. }
  254. // Set the author value - note that this works only for admins.
  255. if (!empty($_GET['uid']) && ($uid = intval($_GET['uid'])) && ($user = user_load($uid))) {
  256. $form['author']['name']['#default_value'] = $user->name;
  257. }
  258. }
  259. }
  260. /**
  261. * Implementation of hook_user().
  262. */
  263. function content_profile_user($op, &$edit, &$account, $category = NULL) {
  264. global $user;
  265. switch ($op) {
  266. case 'categories':
  267. $data = array();
  268. foreach (content_profile_get_types('names', 'edit_tab', 'sub') as $type => $type_name) {
  269. $data[] = array(
  270. 'name' => $type,
  271. 'title' => drupal_ucfirst($type_name),
  272. 'weight' => content_profile_get_settings($type, 'weight') + 1,
  273. );
  274. }
  275. return $data;
  276. case 'view':
  277. $account->content['content_profile'] = content_profile_show_profiles($account->uid);
  278. break;
  279. case 'delete':
  280. // Retrieve all profile nodes (in any language) for this user by issueing an SQL query.
  281. if ($types = content_profile_get_types()) {
  282. $condition = array_fill(0, count($types), "type = '%s'");
  283. $arguments = array_merge(array_keys($types), array($account->uid));
  284. $result = db_query("SELECT * FROM {node} WHERE (". implode(' OR ', $condition) .") AND uid = %d", $arguments);
  285. while ($node = db_fetch_object($result)) {
  286. _content_profile_node_delete($node);
  287. }
  288. }
  289. break;
  290. }
  291. }
  292. /**
  293. * The original node_delete() function uses node_load() to get the $node object.
  294. * Unfortunately, when a hook_user('delete') is called, node_load() doesn't
  295. * work anymore because the user has already been deleted, and node_load()
  296. * still expects the user to exist in the {user} table.
  297. *
  298. * So this is a modified copy of node_delete() that deletes a node without
  299. * calling node_load(), taking the full $node object (as retrieved by a simple
  300. * "SELECT * FROM {node}" query) instead of just the $nid.
  301. */
  302. function _content_profile_node_delete($node) {
  303. // Copied over from node_load(), so that node_invoke('delete') gets
  304. // the fully extended node object, like modules would expect:
  305. if ($node->nid) {
  306. // Call the node specific callback (if any) and piggy-back the
  307. // results to the node or overwrite some values.
  308. if ($extra = node_invoke($node, 'load')) {
  309. foreach ($extra as $key => $value) {
  310. $node->$key = $value;
  311. }
  312. }
  313. if ($extra = node_invoke_nodeapi($node, 'load')) {
  314. foreach ($extra as $key => $value) {
  315. $node->$key = $value;
  316. }
  317. }
  318. }
  319. // Copied over from node_delete():
  320. db_query('DELETE FROM {node} WHERE nid = %d', $node->nid);
  321. db_query('DELETE FROM {node_revisions} WHERE nid = %d', $node->nid);
  322. // Call the node-specific callback (if any):
  323. node_invoke($node, 'delete');
  324. node_invoke_nodeapi($node, 'delete');
  325. // Clear the cache so an anonymous poster can see the node being deleted.
  326. cache_clear_all();
  327. // Remove this node from the search index if needed.
  328. if (function_exists('search_wipe')) {
  329. search_wipe($node->nid, 'node');
  330. }
  331. watchdog('content', '@type: deleted %title.', array('@type' => $node->type, '%title' => $node->title));
  332. drupal_set_message(t('@type %title has been deleted.', array('@type' => node_get_types('name', $node), '%title' => $node->title)));
  333. }
  334. /**
  335. * Implementation of hook_nodeapi().
  336. */
  337. function content_profile_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  338. if ($op == 'prepare' && is_content_profile($node) && !isset($node->nid) && $node->uid && !user_access('administer nodes') && arg(0) != 'admin') {
  339. // Check if this nodetype already exists
  340. if ($nid = content_profile_profile_exists($node, $node->uid)) {
  341. // This node already exists, redirect to edit page
  342. drupal_goto('node/'. $nid .'/edit', 'destination=user/'. $node->uid);
  343. }
  344. }
  345. elseif ($op == 'validate' && is_content_profile($node) && user_access('administer nodes')) {
  346. $form = $a3;
  347. // Only validate if the user-name changed or we add a new node
  348. if (!empty($node->nid) && $form['author']['name']['#default_value'] == $node->name) {
  349. return;
  350. }
  351. //check whether the selected user has already a profile
  352. $uid = db_result(db_query("SELECT uid FROM {users} WHERE name = '%s'", $node->name));
  353. if ($uid && content_profile_profile_exists($node, $uid)) {
  354. form_set_error('name', t('This user already has a content profile of this type. You can only create one profile per user.'));
  355. }
  356. }
  357. elseif ($op == 'prepare translation' && is_content_profile($node->translation_source)) {
  358. // Make sure the translated profile belongs to the same user.
  359. $node->uid = $node->translation_source->uid;
  360. $node->name = $node->translation_source->name;
  361. }
  362. }
  363. /**
  364. * Checks whether a node of this type exists already for the author
  365. *
  366. * @param $node
  367. * The node, which is to be created.
  368. * @param $uid
  369. * The user to check for.
  370. * @return If a node exists, the node id, FALSE else.
  371. */
  372. function content_profile_profile_exists($node, $uid) {
  373. $query = "SELECT n.nid AS nid FROM {node} n WHERE n.type = '%s' AND n.uid = %d ";
  374. if (module_exists('translation') && translation_supported_type($node->type)) {
  375. $query .= "AND n.language = '%s'";
  376. }
  377. return db_result(db_query($query, $node->type, $uid, $node->language));
  378. }
  379. /**
  380. * Returns the content_profiles' settings.
  381. * @param $type
  382. * The content type to return settings for.
  383. * @param $return
  384. * 'all' or one of the content_profile_available_settings(),
  385. * e.g. user_edit, register or weight.
  386. */
  387. function content_profile_get_settings($type, $return = 'all') {
  388. $settings = variable_get('content_profile_'. $type, array());
  389. $settings += content_profile_settings_info();
  390. if ($return == 'all') {
  391. return $settings;
  392. }
  393. return $settings[$return];
  394. }
  395. /**
  396. * Saves the content_profile settings of a content type.
  397. */
  398. function content_profile_set_settings($type, $settings) {
  399. variable_set('content_profile_'. $type, $settings);
  400. }
  401. /**
  402. * Returns an array, which defines the available settings
  403. * and their default value.
  404. */
  405. function content_profile_settings_info() {
  406. return module_invoke_all('content_profile_settings');
  407. }
  408. /**
  409. * Implementation of hook_content_profile_settings().
  410. *
  411. * Defines content profile settings and their default value.
  412. */
  413. function content_profile_content_profile_settings() {
  414. return array(
  415. 'weight' => 0,
  416. 'user_display' => 'full',
  417. 'edit_link' => 0,
  418. 'edit_tab' => 'sub',
  419. 'add_link' => 1,
  420. );
  421. }
  422. /**
  423. * Loads the node, like node_load but makes sure the results are cached.
  424. *
  425. * @param $type
  426. * The content profile's type.
  427. * @param $uid
  428. * The profile owner's user id.
  429. * @param $lang
  430. * Optional. If translation is enabled, the language of the profile to return.
  431. * @param $reset
  432. * Optional. If set, the cache is reset.
  433. */
  434. function content_profile_load($type, $uid, $lang = '', $reset = NULL) {
  435. static $cache = array();
  436. if (!isset($cache[$type][$uid][$lang]) || $reset) {
  437. $cache[$type][$uid][$lang] = FALSE;
  438. $params = array('type' => $type, 'uid' => $uid);
  439. if ($node = node_load($lang ? $params + array('language' => $lang) : $params, NULL, $reset)) {
  440. $cache[$type][$uid][$lang] = $node->nid;
  441. }
  442. return $node;
  443. }
  444. return !empty($cache[$type][$uid][$lang]) ? node_load($cache[$type][$uid][$lang]) : FALSE;
  445. }
  446. /**
  447. * Implementation of hook_help().
  448. *
  449. * Show node submission guidelines for content profile node forms.
  450. */
  451. function content_profile_help($path, $arg) {
  452. if (preg_match('/user\/\%\/(profile|edit)\/(.*)/', $path, $matches)) {
  453. foreach (content_profile_get_types('names') as $type => $typename) {
  454. if ($type == $matches[2]) {
  455. $node = content_profile_load($type, $arg[1]);
  456. if ($node) {
  457. return node_help('node/%/edit', array(1 => $node->nid));
  458. }
  459. else {
  460. return node_help('node/add/'. $type, array('node', 'add', $type));
  461. }
  462. }
  463. }
  464. }
  465. }
  466. /**
  467. * Returns an array suitable for use with drupal_render,
  468. * that shows all content_profiles as configured by the admin.
  469. */
  470. function content_profile_show_profiles($uid) {
  471. global $user;
  472. $content = array();
  473. foreach (content_profile_get_types('names') as $type => $type_name) {
  474. $node = content_profile_load($type, $uid);
  475. if (($style = content_profile_get_settings($type, 'user_display')) && $node && node_access('view', $node)) {
  476. $content['content_profile_'. $type] = array(
  477. '#theme' => ($style == 'link') ? 'content_profile_display_link' : 'content_profile_display_view',
  478. '#edit_link' => content_profile_get_settings($type, 'edit_link'),
  479. '#uid' => $uid,
  480. '#style' => $style,
  481. '#content_type' => $type,
  482. '#weight' => content_profile_get_settings($type, 'weight'),
  483. '#suffix' => '<br />',
  484. );
  485. // Working around the bug described at http://drupal.org/node/302873
  486. module_load_include('inc', 'content_profile', 'content_profile.theme');
  487. }
  488. elseif (user_access('create '. $type .' content') && content_profile_get_settings($type, 'add_link') && !$node && ($uid == $user->uid || user_access('administer nodes'))) {
  489. $content['content_profile_'. $type] = array(
  490. '#admin' => $uid != $user->uid,
  491. '#theme' => 'content_profile_display_add_link',
  492. '#uid' => $uid,
  493. '#content_type' => $type,
  494. '#weight' => content_profile_get_settings($type, 'weight'),
  495. '#suffix' => '<br />',
  496. );
  497. }
  498. }
  499. if ($content) {
  500. $content['#prefix'] = '<p id="content-profile-view">';
  501. $content['#suffix'] = '</p>';
  502. }
  503. return $content;
  504. }
  505. /**
  506. * Implementation of hook_theme().
  507. */
  508. function content_profile_theme() {
  509. $return = array(
  510. 'content_profile_display_view' => array(
  511. 'template' => 'content_profile-display-view',
  512. 'arguments' => array('element' => NULL),
  513. 'file' => 'content_profile.theme.inc',
  514. ),
  515. 'content_profile_display_add_link' => array(
  516. 'file' => 'content_profile.theme.inc',
  517. ),
  518. 'content_profile_display_link' => array(
  519. 'file' => 'content_profile.theme.inc',
  520. ),
  521. 'content_profile_display_tab_view' => array(
  522. 'file' => 'content_profile.theme.inc',
  523. ),
  524. 'content_profile_display_tab_edit' => array(
  525. 'file' => 'content_profile.theme.inc',
  526. ),
  527. );
  528. if (module_exists('pageroute')) {
  529. $return['content_profile_pageroute_empty'] = array(
  530. 'arguments' => array('type_name' => NULL),
  531. 'file' => 'content_profile.pageroute.inc',
  532. );
  533. }
  534. // Imagecache presets to link to user profile page.
  535. if (module_exists('imagecache')) {
  536. foreach (imagecache_presets() as $preset) {
  537. $return['content_profile_formatter_'. $preset['presetname'] .'_userlink'] = array(
  538. 'arguments' => array('element' => NULL),
  539. 'function' => 'theme_content_profile_imagecache_formatter_userlink',
  540. 'file' => 'content_profile.theme.inc',
  541. );
  542. }
  543. }
  544. return $return;
  545. }
  546. /**
  547. * Implementation of hook_field_formatter_info().
  548. *
  549. * Imagecache formatters are named as $presetname_$style
  550. * $style is used to determine how the preset should be rendered.
  551. * If you are implementing custom imagecache formatters please treat _ as
  552. * reserved.
  553. *
  554. * These presets allow linking the image to the user profile page, rather than
  555. * the profile node.
  556. */
  557. function content_profile_field_formatter_info() {
  558. $formatters = array();
  559. if (module_exists('imagecache')) {
  560. foreach (imagecache_presets() as $preset) {
  561. $formatters[$preset['presetname'] .'_userlink'] = array(
  562. 'label' => t('@preset image linked to user profile', array('@preset' => $preset['presetname'])),
  563. 'field types' => array('image', 'filefield'),
  564. );
  565. }
  566. }
  567. return $formatters;
  568. }
  569. /**
  570. * Implementation of hook_theme_registry_alter().
  571. * Adds our own preprocess functions to some templates. Further templates can be set in
  572. * $conf['content_profile_extra_templates'] in settings.php.
  573. */
  574. function content_profile_theme_registry_alter(&$items) {
  575. $templates = array_merge(array(
  576. 'author_pane',
  577. 'comment',
  578. 'node',
  579. 'page',
  580. 'search_result',
  581. 'username',
  582. 'user_profile',
  583. 'user_signature',
  584. ), variable_get('content_profile_extra_templates', array()));
  585. foreach ($templates as $key) {
  586. if (isset($items[$key])) {
  587. $items[$key] += array('preprocess functions' => array());
  588. $items[$key]['preprocess functions'][] = 'content_profile_template_preprocess';
  589. }
  590. }
  591. }
  592. /**
  593. * Adds $content_profile variable if we can find a $uid.
  594. */
  595. function content_profile_template_preprocess(&$variables, $hook) {
  596. // Search the uid
  597. foreach (array('account_id', 'uid', 'account', 'node', 'comment', 'user') as $name) {
  598. if (isset($variables[$name])) {
  599. $uid = is_object($variables[$name]) ? $variables[$name]->uid : $variables[$name];
  600. $variables['content_profile'] = new content_profile_theme_variables($uid);
  601. break;
  602. }
  603. }
  604. }
  605. /**
  606. * Implementation of hook_simpletest().
  607. */
  608. function content_profile_simpletest() {
  609. // Scan through content_profile/tests directory for any .test files to tell SimpleTest module.
  610. $tests = file_scan_directory(drupal_get_path('module', 'content_profile') .'/tests', '\.test');
  611. return array_keys($tests);
  612. }
  613. /**
  614. * Implementation of hook_pageroute_info() for Pageroute integration.
  615. */
  616. function content_profile_pageroute_info() {
  617. return array(
  618. 'content_profile' => array(
  619. 'viewprofile' => 'content_profile.pageroute',
  620. 'editprofile' => 'content_profile.pageroute',
  621. )
  622. );
  623. }