'. t('View Origo Home.') .'
'; return $o; } } /** * Implementation of hook_perm(). * Define the permissions this module uses. */ function origo_home_perm() { return array( 'access content', 'origo admin access', 'origo project settings', 'origo create project', 'origo request application key', 'origo create release', 'origo delete release' ); } /** * Implementation of hook_theme(). */ function origo_home_theme() { return array( 'origo_home_project_settings_navigation_form' => array( 'arguments' => array('form' => NULL) ), 'origo_home_settings_subscriptions_form' => array( 'arguments' => array('form' => NULL) ), 'origo_home_settings_user_icon_form' => array( 'arguments' => array('form' => NULL) ), 'origo_home_settings_personal_information_form' => array( 'arguments' => array('form' => NULL) ), 'origo_home_settings_contact_information_form' => array( 'arguments' => array('form' => NULL) ), 'origo_home_additional_settings_form' => array( 'arguments' => array('form' => NULL) ), 'origo_home_create_release_form' => array( 'arguments' => array('form' => NULL) ), 'origo_home_project_information_form' => array( 'arguments' => array('form' => NULL) ), 'origo_home_project_settings_members_page' => array( 'arguments' => array('values' => NULL) ), 'dashboard_workitems_tabs' => array( 'arguments' => array('tabs' => NULL) ), 'dashboard_workitems_read_link' => array( 'arguments' => array('project_name' => NULL, 'unread_only' => NULL) ), 'dashboard_workitems_mark_read_and_feed_link' => array( 'arguments' => array('project' => NULL, 'feed_url' => NULL) ), 'dashboard_settings' => array( 'arguments' => array('itmes' => NULL) ), 'origo_home_menu' => array( 'arguments' => array('menu' => NULL) ), 'origo_home_repository_links' => array( 'arguments' => array('content' => NULL) ), 'origo_home_access_matrix' => array( 'arguments' => array('$headers' => NULL, 'data' => NULL) ), ); } // -------------------------------------------------------------------------------------- /** * Title callback for menu paths to "/dashboard". * Displays the project name of the currently selected project. * @param $title The project name passed in the URL. * @return String The appropriate title string. */ function dashboard_workitems_title_callback($project_name) { if (!isset($project_name) || $project_name == '') { $project_name = variable_get('origo_project_name', 'Error retrieving project name'); } return "Work Items for Project ". $project_name; } /** * Access callback for links that only existing users may access. * @return Boolean denoting if $user is a registered user. */ function origo_home_existing_user_access() { global $user; // Note: anonymous users have uid 0. return $user->uid > 0; } /** * Access callback for menu paths into a user's profile. * Existing user may access pages, while anonymous users only get access if * anonymous access is specified in the $username's profile. * * @param $username Name of the user's profile that is requested. * @return Boolean denoting if $user is a registered user. */ function origo_home_profile_visible_access($username) { global $user; $profile_visible = 1; if ($user->uid <= 0) { $ret = origo_auth_xml_rpc(variable_get('origo_api', ''), 'user.profile_visible', $username); $profile_visible = $ret['profile_visible']; } return $profile_visible; } /** * Access callback for testing access of the logged-in user against * user-specific pages, e.g. user-account pages. * @param $username Name of the affected user. * @return Boolean denoting if access is granted. */ function origo_home_user_account_access($username) { global $user; if (strcmp($user->name, $username) == 0) { return TRUE; } } /** * Access callback for testing access of the logged-in user against * admin-priviledges of the community $community_name. * @param $community_name Name of the community of interest. * @return Boolean denoting if access is granted. */ function origo_home_community_admin_access($community_name) { if (!is_string($community_name)) { return FALSE; } return (origo_home_community_is_origo_admin() || origo_home_community_is_community_admin($community_name)); } /** * Access callback for testing access of the logged-in user against * community membership of the community $community_name. * @param $community_name Name of the community of interest. * @return Boolean denoting if access is granted. */ function origo_home_community_member_access($community_name) { if (!is_string($community_name)) { return FALSE; } $is_community_member = origo_home_community_is_community_member($community_name); return ($is_community_member || origo_home_community_admin_access($community_name)); } /** * Loader function for menu-paths containing Origo-usernames. * @param $username String denoting an Origo-username. * @return The Origo-username or FALSE. */ function origo_username_load($username) { //TODO: can usernames be just numbers? like "1337"? if (!is_string($username)) { return FALSE; } // TODO: Here we could query Origo's backend to check if the username's valid, // but this will most likely be done by the menu-access function. // Thus, for now, we just return the string. return $username; } /* Loader function for menu-path containing Users Group_ID * @param $group_id Integer denoting an Users Group_ID * @return Users Group_ID or FALSE */ function origo_group_id_load($group_id) { $gid = (int) $group_id; if (!is_int($gid)) { return FALSE; } // TODO: Here we could query Origo's backend to check if the Group ID is valid, // but this will most likely be done by the menu-access function. // Thus, for now, we just return the ID. return $gid; } /** * Loader function for menu-paths containing Origo project IDs. * @param $project_id Integer denoting an Origo project ID. * @return The Origo project ID or FALSE. */ function origo_project_id_load($project_id) { $pid = (int)$project_id; if (!is_int($pid)) { return FALSE; } // TODO: Here we could query Origo's backend to check if the project ID is valid, // but this will most likely be done by the menu-access function. // Thus, for now, we just return the ID. return $pid; } /** * Loader function for menu-paths containing Origo project names. * @param $project_name String denoting an Origo project name. * @return The Origo project name or FALSE. */ function origo_project_name_load($project_name) { if (!is_string($project_name)) { return FALSE; } // TODO: Here we could query Origo's backend to check if the project name is valid, // but this will most likely be done by the menu-access function. // Thus, for now, we just return the name. return $project_name; } /** * Loader function for menu-paths containing Origo release IDs. * NOTE: The functionality is - for now - identical to `origo_project_id_load', * but is contained in a separate function for consistency's sake. Also, an * eventual backend-check would have to be separated. * @param $release_id Integer denoting an Origo release ID. * @return The Origo release ID or FALSE. */ function origo_release_id_load($release_id) { $id = (int)$release_id; if (!is_int($id)) { return FALSE; } // TODO: Here we could query Origo's backend to check if the release ID is valid, // but this will most likely be done by the menu-access function. // Thus, for now, we just return the ID. return $id; } /** * Loader function for menu-paths containing Origo workitem IDs. * NOTE: The functionality is - for now - identical to `origo_release_id_load', * but is contained in a separate function for consistency's sake. Also, an * eventual backend-check would have to be separated. * @param $workitem_id Integer denoting an Origo workitem ID. * @return The Origo workitem ID or FALSE. */ function origo_workitem_id_load($workitem_id) { $id = (int)$workitem_id; if (!is_int($id)) { return FALSE; } // TODO: Here we could query Origo's backend to check if the workitem ID is valid, // but this will most likely be done by the menu-access function. // Thus, for now, we just return the ID. return $id; } /** * Loader function for menu-paths containing Origo revision numbers. * @param $revision Integer denoting an Origo revision number. * @return The Origo revision number or FALSE. */ function origo_revision_load($revision) { $rev = (int)$revision; if (!is_int($rev)) { return FALSE; } // TODO: Here we could query Origo's backend to check if the revision number is valid, // but this will most likely be done by the menu-access function. // Thus, for now, we just return the revision. return $rev; } /** * Loader function for menu-paths containing Origo wiki-page names. * @param $wiki_page String denoting an Origo wiki-page name. * @return The name of the wiki-page or FALSE. */ function origo_wiki_page_load($wiki_page) { if (!is_string($wiki_page)) { return FALSE; } return $wiki_page; } /** * Loader function for menu-paths containing Origo community names. * @param $community_name String denoting an Origo community name. * @return The name of the wiki-page or FALSE. */ function origo_community_name_load($community_name) { if (!is_string($community_name)) { return FALSE; } // TODO: Here we could query Origo's backend to check if the community name is valid, // but this will most likely be done by the menu-access function. // Thus, for now, we just return the community name. return $community_name; } /** * Loader function for retrieving menu-paths containing Origo-Feeds. * NOTE: Such a path may contain an optional part specifying the project's ID. * @param $feed_auth An encrypted string containing the authentication data. * @param $project_id An optional parameter denoting a project ID. * @return unknown_type */ function origo_feed_string_load($feed_auth, $project_id = NULL) { if (!is_string($feed_auth)) { return FALSE; } if (isset($project_id)) { // check the project-ID using another loader-function $val = origo_project_id_load($project_id); if ($val == FALSE) { return FALSE; } } return $feed_auth; } // -------------------------------------------------------------------------------------- /** * Implementation of hook_menu(). * * Defines Menu entries and path callbacks. */ function origo_home_menu() { global $user; // Workitem Dashboard (former Origo Home) $items['dashboard'] = array( 'title' => '', 'title callback' => 'dashboard_workitems_title_callback', 'file' => 'dashboard/workitem/dashboard_workitem.inc', 'page callback' => 'dashboard_workitems_project', 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); // Workitem Dashboard (former Origo Home) $items['dashboard/%'] = array( 'title' => 'Work Items for @project', 'title arguments' => array('@project' => 1), 'file' => 'dashboard/workitem/dashboard_workitem.inc', 'page callback' => 'dashboard_workitems_project', 'page arguments' => array(1), 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); // AJAX callback for retrieving a workitem's details $items['ajax/get_workitem/%'] = array( 'page callback' => 'retrieve_workitem_details', 'page arguments' => array(2), 'file' => 'dashboard/workitem/dashboard_workitem.inc', 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK ); // Origo Home - Create Project $items['origo_home/create_project'] = array( 'title' => 'Request Project', 'page callback' => 'origo_home_create_project_page', 'access callback' => 'user_access', 'access arguments' => array('origo create project'), 'type' => MENU_CALLBACK, ); // AHAH callback for project creation. $items['origo_home/create_project_ahah'] = array( 'page callback' => 'origo_admin_create_project_ahah', 'access arguments' => array('origo create project'), 'type' => MENU_CALLBACK, ); // Origo Home - Create Project $items['origo_home/settings'] = array( 'title' => 'Settings', 'page callback' => 'origo_home_settings_dashboard_page', 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // Origo Home - Settings - Origo Web - Workitem Browser Settings $items['origo_home/settings/workitems'] = array( 'title' => 'Workitem Settings', 'page callback' => 'drupal_get_form', 'page arguments' => array('origo_home_settings_workitem_settings_form'), 'file' => 'origo_settings.inc', 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // Origo Home - Settings - Origo Web - Workitem Browser Settings $items['origo_home/settings/issues'] = array( 'title' => 'Issue Settings', 'page callback' => 'drupal_get_form', 'page arguments' => array('origo_home_settings_issues_form'), 'file' => 'origo_settings.inc', 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // Origo Home - Settings - Workitem Subscriptions $items['origo_home/settings/subscriptions'] = array( 'title' => 'Subscriptions', 'page callback' => 'drupal_get_form', 'page arguments' => array('origo_home_settings_subscriptions_form'), 'file' => 'origo_settings.inc', 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // Origo Home - Settings - Bookmarks $items['origo_home/settings/bookmarks'] = array( 'title' => 'Bookmarks', 'page callback' => 'origo_home_settings_bookmarks_page', 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // Origo Home - Settings - User Key $items['origo_home/settings/userkey'] = array( 'title' => 'User Key', 'page callback' => 'origo_home_settings_userkey_page', 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // Origo Home - Settings - Password $items['origo_home/settings/password'] = array( 'title' => 'Password', 'page callback' => 'drupal_get_form', 'page arguments' => array('origo_home_settings_password_form'), 'file' => 'origo_settings.inc', 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // Origo Home - Settings - User Icon $items['origo_home/settings/user_icon'] = array( 'title' => 'Account Details', 'page callback' => 'origo_home_settings_user_icon_page', 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // Origo Home - Settings - Personal Information $items['origo_home/settings/personal_information'] = array( 'title' => 'Account Details', 'page callback' => 'origo_home_settings_personal_information_page', 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // Origo Home - Settings - Contact Information $items['origo_home/settings/contact_information'] = array( 'title' => 'Account Details', 'page callback' => 'origo_home_settings_contact_information_page', 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // Origo Home - Settings - Privacy Settings $items['origo_home/settings/additional_settings'] = array( 'title' => 'Account Details', 'page callback' => 'origo_home_additional_settings_page', 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // Origo Home - Settings - Disable Account $items['origo_home/settings/disable_account'] = array( 'title' => 'Disable Account', 'page callback' => 'origo_home_settings_disable_account_page', 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // Origo Home - Settings - Communities $items['origo_home/settings/communities'] = array( 'title' => 'Communities', 'page callback' => 'origo_home_settings_communities_page', 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // ------------------------------------------------------------------------------------------------ // Origo Home - User page $items['users/%origo_username'] = array( 'title' => arg(1), 'page callback' => 'origo_home_user_page', 'page arguments' => array(1), 'access callback' => 'origo_home_profile_visible_access', 'access arguments' => array(1), 'type' => MENU_CALLBACK, ); // Origo Home - User vCard page $items['users/%origo_username/vcard'] = array( 'title' => 'vCard Download', 'page callback' => 'origo_home_vcard_page', 'page arguments' => array(1), 'access callback' => 'origo_home_profile_visible_access', 'access arguments' => array(1), 'type' => MENU_CALLBACK, ); // Origo Home - User icon editing $items['users/%origo_username/edit_user_icon'] = array( 'title' => 'Edit User Icon', 'page callback' => 'origo_home_settings_user_icon_page', 'access callback' => 'origo_home_user_account_access', 'access arguments' => array(1), 'weight' => 0, 'type' => MENU_CALLBACK, ); // Origo Home - Personal information editing $items['users/%origo_username/edit_personal_information'] = array( 'title' => 'Edit Personal Information', 'page callback' => 'origo_home_settings_personal_information_page', 'access callback' => 'origo_home_user_account_access', 'access arguments' => array(1), 'weight' => 2, 'type' => MENU_CALLBACK, ); // Origo Home - Contact information editing $items['users/%origo_username/edit_contact_information'] = array( 'title' => 'Edit Contact Information', 'page callback' => 'origo_home_settings_contact_information_page', 'access callback' => 'origo_home_user_account_access', 'access arguments' => array(1), 'weight' => 4, 'type' => MENU_CALLBACK, ); // Origo Home - privacy settings editing $items['users/%origo_username/additional_settings'] = array( 'title' => 'Edit Privacy Settings', 'page callback' => 'origo_home_additional_settings_page', 'access callback' => 'origo_home_user_account_access', 'access arguments' => array(1), 'weight' => 6, 'type' => MENU_CALLBACK, ); // ------------------------------------------------------------------------------------------------ // Origo Home - Bookmark Add $items['origo_home/bookmarks/add/%origo_project_id'] = array( 'title' => 'Bookmark Adding', 'page callback' => 'origo_home_bookmark_add', 'page arguments' => array(3), 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // Origo Home - Bookmark Remove $items['origo_home/bookmarks/remove/%origo_project_id'] = array( 'title' => 'Bookmark Removal', 'page callback' => 'origo_home_bookmark_remove', 'page arguments' => array(3), 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // Origo Home - Global Search $items['search_global'] = array( 'title' => 'Global Search', 'page callback' => 'origo_home_global_search_page', 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); // Origo Home - Request application key $items['origo_home/request_appkey'] = array( 'title' => 'Request application key', 'page callback' => 'origo_home_request_appkey_page', 'access callback' => 'user_access', 'access arguments' => array('origo request application key'), 'type' => MENU_CALLBACK, ); // Origo Home - DOAP file $items['doap'] = array( 'title' => 'DOAP file', 'file' => 'origo_doap.inc', // include doap.inc 'page callback' => 'origo_home_print_doap', 'access callback' => TRUE, 'type' => MENU_CALLBACK, ); // Origo Home - Releases $items['download'] = array( 'title' => 'Download', 'page callback' => 'origo_home_release_page', 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); // Origo Home - Release Details $items['download/%origo_release_id'] = array( 'title' => 'Download', 'page callback' => 'origo_home_release_detail_page', 'page arguments' => array(1), 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); // Origo Home - Create Release $items['create_release'] = array( 'title' => 'Create Release', 'page callback' => 'origo_home_create_release_page', 'access callback' => 'user_access', 'access arguments' => array('origo create release'), 'type' => MENU_CALLBACK, ); // Origo Home - Delete Release $items['download/delete/%origo_release_id'] = array( 'title' => 'Delete Release', 'page callback' => 'origo_home_release_delete_page', 'page arguments' => array(2), 'access callback' => 'user_access', 'access arguments' => array('origo delete release'), 'type' => MENU_CALLBACK, ); // Origo Home - Feeds $items['origo_feed/%origo_feed_string'] = array( 'title' => 'Origo Feed', 'page callback' => 'origo_feed_page', 'page arguments' => array(1, 2), 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); // Origo Home - Mark Workitem Read $items['origo_home/mark_read/%origo_workitem_id'] = array( 'file' => 'dashboard/workitem/dashboard_workitem.inc', 'page callback' => 'origo_home_mark_read', 'page arguments' => array(2), 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // Origo Home - Mark Workitem unread $items['origo_home/mark_unread/%origo_workitem_id'] = array( 'file' => 'dashboard/workitem/dashboard_workitem.inc', 'page callback' => 'origo_home_mark_unread', 'page arguments' => array(2), 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // Origo Home - Mark all workitems read $items['origo_home/mark_all_read/%origo_workitem_id'] = array( 'file' => 'dashboard/workitem/dashboard_workitem.inc', 'page callback' => 'origo_home_mark_read_project', 'page arguments' => array(2), 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // Origo Home - Workitem redirect $items['origo_home/workitem/%origo_workitem_id'] = array( 'page callback' => 'origo_home_workitem_page', 'page arguments' => array(2), 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // Origo Home - Reported Issues $items['origo_home/reported_issues'] = array( 'file' => 'origo_home_reported_issues.inc', 'title' => 'Reported Issues', 'page callback' => 'origo_home_reported_issues_page', 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // Origo Home - Invite Friend to Origo $items['origo_home/invite_friends'] = array( 'title' => 'Invite your Friends to Origo', 'page callback' => 'origo_home_invite_friends_page', 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // -------------------------------------------------------------------------------------- // Origo Admin $items['origo_admin'] = array( 'title' => 'Origo Admin', 'page callback' => 'origo_admin_page', 'access callback' => 'user_access', 'access arguments' => array('origo admin access'), 'type' => MENU_CALLBACK, ); // Origo Admin - Mass Mail $items['origo_admin/massmail'] = array( 'title' => 'Mass Mail', 'page callback' => 'origo_admin_massmail_page', 'access callback' => 'user_access', 'access arguments' => array('origo admin access'), 'type' => MENU_CALLBACK, ); // Origo Admin - System Status $items['origo_admin/status'] = array( 'title' => 'System Status', 'page callback' => 'origo_admin_status_page', 'access callback' => 'user_access', 'access arguments' => array('origo admin access'), 'type' => MENU_CALLBACK, ); // Origo Admin - Create Project $items['origo_admin/create_project'] = array( 'title' => 'Create Project', 'page callback' => 'origo_admin_create_project_page', 'access callback' => 'user_access', 'access arguments' => array('origo admin access'), 'type' => MENU_CALLBACK, ); // Origo Admin - Create Project from request $items['origo_admin/create_project/%'] = array( 'title' => 'Create Project', 'page callback' => 'origo_admin_create_project_page', 'page arguments' => array(2), 'access callback' => 'user_access', 'access arguments' => array('origo admin access'), 'type' => MENU_CALLBACK, ); // Origo Admin - Remove Project $items['origo_admin/remove_project'] = array( 'title' => 'Remove Project', 'page callback' => 'origo_admin_remove_project_page', 'access callback' => 'user_access', 'access arguments' => array('origo admin access'), 'type' => MENU_CALLBACK, ); // Origo Admin - Change Project $items['origo_admin/change_project_type'] = array( 'title' => 'Change Project Type', 'page callback' => 'drupal_get_form', 'page arguments' => array('origo_admin_change_project_type_form'), 'access callback' => 'user_access', 'access arguments' => array('origo admin access'), 'type' => MENU_CALLBACK, ); $items['ajax/ahah-change-project'] = array( 'page callback' => 'ahah_change_project_callback', 'access arguments' => array('origo admin access'), 'type' => MENU_CALLBACK, ); // Origo Admin - Disable a user account $items['origo_admin/disable_account/%'] = array( 'title' => 'Disable Account', 'page callback' => 'origo_admin_disable_user_page', 'page arguments' => array(2), 'access callback' => 'user_access', 'access arguments' => array('origo admin access'), 'type' => MENU_CALLBACK, ); // -------------------------------------------------------------------------------------- // Project settings - for everyone with special form for project owner $items['project_settings'] = array( 'title' => 'Project Settings', 'page callback' => 'origo_home_project_settings_members_page', 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); // Project settings - Confirm form if want to remove yourself as last owner $items['project_settings/confirm/%origo_project_id/%origo_group_id/%origo_username'] = array( 'title' => 'Confirm Change User Group', 'page callback' => 'drupal_get_form', 'page arguments' => array('origo_home_project_change_group_confirm_form', 2, 3, 4), 'access callback' => 'user_access', 'access arguments' => array('origo project settings'), 'type' => MENU_CALLBACK, ); // Project settings for owners - Remove Member $items['project_settings/members/remove/%origo_username/%origo_project_id'] = array( 'page callback' => 'origo_home_project_settings_members_remove_validate', 'page arguments' => array(3, 4), 'access callback' => 'user_access', 'access arguments' => array('origo project settings'), 'type' => MENU_CALLBACK, ); // Project settings - Confirm form if want to remove the last owner $items['project_settings/confirm/%origo_project_id/%origo_username'] = array( 'title' => 'Confirm remove from User Group', 'page callback' => 'drupal_get_form', 'page arguments' => array('origo_home_project_settings_members_remove_confirm_form', 2, 3), 'access callback' => 'user_access', 'access arguments' => array('origo project settings'), 'type' => MENU_CALLBACK, ); // Project settings - for everyone with special form for project owner - Members $items['project_settings/members'] = array( 'title' => 'Members', 'page callback' => 'origo_home_project_settings_members_page', 'access callback' => 'user_access', 'access arguments' => array('access content'), 'weight' => -8, 'type' => MENU_DEFAULT_LOCAL_TASK, ); // Project settings for owners - Description $items['project_settings/information'] = array( 'title' => 'Information', 'page callback' => 'origo_home_project_information_page', 'access callback' => 'user_access', 'access arguments' => array('origo project settings'), 'weight' => -6, 'type' => MENU_LOCAL_TASK, ); // Project settings for owners - Logo $items['project_settings/logo'] = array( 'title' => 'Logo', 'page callback' => 'origo_home_project_settings_logo_page', 'access callback' => 'user_access', 'access arguments' => array('origo project settings'), 'weight' => -4, 'type' => MENU_LOCAL_TASK, ); // Project settings for owners - Navigation $items['project_settings/navigation'] = array( 'file' => 'origo_home_project_settings.inc', 'title' => 'Navigation', 'page callback' => 'drupal_get_form', 'page arguments' => array('origo_home_project_settings_navigation_form'), 'access callback' => 'user_access', 'access arguments' => array('origo project settings'), 'weight' => -2, 'type' => MENU_LOCAL_TASK, ); // Project settings for owners - project pretty name $items['project_settings/project_prettyname'] = array( 'title' => 'Pretty Name', 'page callback' => 'origo_home_project_settings_project_prettyname_page', 'access callback' => 'user_access', 'access arguments' => array('origo project settings'), 'weight' => -2, 'type' => MENU_LOCAL_TASK, ); // -------------------------------------------------------------------------------------- // Wiki Diff redirect $items['wiki_diff/%origo_wiki_page/%origo_revision/%origo_revision'] = array( 'title' => 'Wiki Diff', 'page callback' => 'origo_home_wiki_diff_page', 'page arguments' => array(1, 2, 3), 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); // Blog Diff redirect $items['blog_diff/%origo_username/%origo_wiki_page/%origo_revision/%origo_revision'] = array( 'title' => 'Blog Diff', 'page callback' => 'origo_home_blog_diff_page', 'page arguments' => array(1, 2, 3, 4), 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); // Send message to user $items['message/%origo_username'] = array( // Title is string with placeholder, callback not defined, so falls back to the default t() 'title' => 'Send Message to @recipient', 'title arguments' => array('@recipient' => 1), 'page callback' => 'origo_home_message_page', 'page arguments' => array(1), 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // Friends overview page $items['friends/%origo_username'] = array( // Title is string with placeholder, callback not defined, so falls back to the default t() 'title' => '@friend\'s friends', 'title arguments' => array('@friend' => 1), 'page callback' => 'origo_home_friends_page', 'page arguments' => array(1), 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // Request Friendship $items['add_friend/%origo_username'] = array( 'title' => 'Add @friend as your friend', 'title arguments' => array('@friend' => 1), 'page callback' => 'origo_home_request_friendship_page', 'page arguments' => array(1), 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // Remove Friendship $items['remove_friend/%origo_username'] = array( 'title' => 'Remove @friend from your friends', 'title arguments' => array('@friend' => 1), 'page callback' => 'origo_home_remove_friendship_page', 'page arguments' => array(1), 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // Confirm Friendship $items['confirm_friend/%origo_username'] = array( 'title' => 'Confirm Friendship Request', 'page callback' => 'origo_home_confirm_friendship_page', 'page arguments' => array(1), 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // -------------------------------------------------------------------------------------- // List all communities $items['communities'] = array( 'title' => 'Origo - Communities', 'page callback' => 'origo_home_communities_page', 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // Community Main Page $items['communities/%origo_community_name'] = array( // Title is string with placeholder, callback not defined, so falls back to the default t() 'title' => '!community_name Community', 'title arguments' => array('!community_name' => 1), 'page callback' => 'origo_home_community_main_page', 'page arguments' => array(1), 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // Join a communtiy $items['communities/%origo_community_name/join'] = array( 'page callback' => 'origo_home_community_join', 'page arguments' => array(1), 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // Leave a community $items['communities/%origo_community_name/leave'] = array( 'page callback' => 'origo_home_community_leave', 'page arguments' => array(1), 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // Delete a community $items['communities/%origo_community_name/delete'] = array( 'page callback' => 'origo_home_community_delete_page', 'page arguments' => array(1), 'access callback' => 'user_access', 'access arguments' => array('origo admin access'), 'type' => MENU_CALLBACK, ); // Promote a member to admin $items['communities/%origo_community_name/promote/%origo_username'] = array( 'page callback' => 'origo_home_community_promote', 'page arguments' => array(1, 3), 'access callback' => 'origo_home_community_admin_access', 'access arguments' => array(1), 'type' => MENU_CALLBACK, ); // Demote an admin to member $items['communities/%origo_community_name/demote/%origo_username'] = array( 'page callback' => 'origo_home_community_demote', 'page arguments' => array(1, 3), 'access callback' => 'origo_home_community_admin_access', 'access arguments' => array(1), 'type' => MENU_CALLBACK, ); // Add a project to a community $items['communities/%origo_community_name/add_project'] = array( 'page callback' => 'origo_home_community_add_project_page', 'page arguments' => array(1), 'access callback' => 'origo_home_community_admin_access', 'access arguments' => array(1), 'type' => MENU_CALLBACK, ); // Remove a project from a community $items['communities/%origo_community_name/remove_project/%origo_project_name'] = array( 'page callback' => 'origo_home_community_remove_project', 'page arguments' => array(1, 3), 'access callback' => 'origo_home_community_admin_access', 'access arguments' => array(1), 'type' => MENU_CALLBACK, ); // Change community description $items['communities/%origo_community_name/change_description'] = array( 'page callback' => 'origo_home_community_change_description_page', 'page arguments' => array(1), 'access callback' => 'origo_home_community_admin_access', 'access arguments' => array(1), 'type' => MENU_CALLBACK, ); // List all wiki pages of a community $items['communities/%origo_community_name/wiki'] = array( 'title' => 'Wiki Pages', 'page callback' => 'origo_home_community_list_wiki_page', 'page arguments' => array(1), 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // Display a wiki page $items['communities/%origo_community_name/wiki/%origo_wiki_page'] = array( // Title is string with placeholder, callback not defined, so falls back to the default t() 'title' => '@wikipage_name', 'title arguments' => array('@wikipage_name' => 3), 'page callback' => 'origo_home_community_show_wiki_page', 'page arguments' => array(1, 3), 'access callback' => 'origo_home_existing_user_access', 'type' => MENU_CALLBACK, ); // Display a wiki page $items['communities/%origo_community_name/wiki/%origo_wiki_page/view'] = array( 'title' => 'View', 'page callback' => 'origo_home_community_show_wiki_page', 'page arguments' => array(1, 3), 'access callback' => 'origo_home_community_member_access', 'access arguments' => array(1), 'type' => MENU_DEFAULT_LOCAL_TASK, ); // Edit a wiki page $items['communities/%origo_community_name/wiki/%origo_wiki_page/edit'] = array( 'title' => 'Edit', 'page callback' => 'origo_home_community_edit_wiki_page', 'page arguments' => array(1, 3), 'access callback' => 'origo_home_community_member_access', 'access arguments' => array(1), 'weight' => 2, 'type' => MENU_LOCAL_TASK, ); // Add a wiki page $items['communities/%origo_community_name/wiki/add'] = array( 'title' => 'Edit', 'page callback' => 'origo_home_community_add_wiki_page', 'page arguments' => array(1), 'access callback' => 'origo_home_community_member_access', 'access arguments' => array(1), 'type' => MENU_CALLBACK, ); // Delete a wiki page $items['communities/%origo_community_name/wiki/%origo_wiki_page/delete'] = array( 'title' => 'Delete', 'page callback' => 'origo_home_community_delete_wiki_page', 'page arguments' => array(1, 3), 'access callback' => 'origo_home_community_admin_access', 'access arguments' => array(1), 'type' => MENU_CALLBACK, ); return $items; } /** * Redirect to workitem and mark as read * * @param $workitem_id workitem id */ function origo_home_workitem_page($workitem_id) { origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'workitem.set_read_status', (int)$workitem_id, TRUE); drupal_goto(base64_decode($_GET['target'])); } /** * Add bookmark to project * * @param $project_id Project id */ function origo_home_bookmark_add($project_id) { //add bookmark $project = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'user.add_bookmark', (int)$project_id); drupal_goto('origo_home/settings/bookmarks'); } /** * Remove bookmark to project * * @param $project_id Project id */ function origo_home_bookmark_remove($project_id) { //remove bookmark $project = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'user.remove_bookmark', (int)$project_id); drupal_goto('origo_home/settings/bookmarks'); } /** * Redirects to global search page * */ function origo_home_global_search_page() { drupal_goto('search/google'); } /** * Redirects to the node diff page * * @param $page name of the wiki page * @param $old_revision old revision * @param $revision new revision */ function origo_home_wiki_diff_page($page, $old_revision, $revision) { $result = db_query("SELECT src FROM {url_alias} WHERE LOWER(dst) = LOWER('%s')", 'wiki/'. $page); $found_nodes = array(); while ($node = db_fetch_object($result)) { $found_nodes[] = $node; } if (count($found_nodes) == 1) { drupal_goto($found_nodes[0]->src .'/revisions/view/'. $old_revision .'/'. $revision); } } /** * Redirects to the node diff page * * @param $user name of the blog user * @param $page name of the blog page * @param $old_revision old revision * @param $revision new revision */ function origo_home_blog_diff_page($user, $page, $old_revision, $revision) { $result = db_query("SELECT src FROM {url_alias} WHERE LOWER(dst) = LOWER('%s')", 'blog/'. $user .'/'. $page); $found_nodes = array(); while ($node = db_fetch_object($result)) { $found_nodes[] = $node; } if (count($found_nodes) == 1) { drupal_goto($found_nodes[0]->src .'/revisions/view/'. $old_revision .'/'. $revision); } } /** * Create form to add users to a project * * @param $project_id id of project * @param $admin_mode was project settings page in admin mode */ function origo_home_project_user_add_form(&$form_state, $project_id, $admin_mode = FALSE) { $form['project_id'] = array('#type' => 'value', '#value' => $project_id); $form['admin_mode'] = array('#type' => 'value', '#value' => $admin_mode); $form['username'] = array( '#type' => 'textfield', '#title' => t('Username'), '#size' => 60, '#maxlength' => 64, '#description' => NULL, '#attributes' => NULL, '#required' => TRUE, ); $options = array('4' => t('Project Member'), '3' => t('Project Owner')); // the indices are the back-end's group_id's for these roles. $form['type'] = array( '#type' => 'radios', '#title' => t('Type'), '#default_value' => 1, '#options' => $options, '#description' => NULL, '#attributes' => NULL, '#required' => TRUE, ); // optional field for Drupal roles that differ from the back-end. $form['drupal_role'] = array( '#type' => 'hidden', '#value' => NULL, ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Apply changes') ); return $form; } /* Validate that you aren't removing yourself as admin when you add yourself as member if there's just one admin. */ function origo_home_project_user_add_form_validate($form, &$form_state) { // Create Structure $values = array(); $values["stakeholders"] = array(); $values["project_id"] = variable_get('origo_project_id', 0); // Get owners $values["stakeholders"]["owners"] = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'project.members', (int)$values["project_id"], 3); // Check for Error && Check if there is just one owner && if userToAdd is equal the owner if ((int)xmlrpc_errno() > 0) { drupal_set_message(xmlrpc_error_msg()); } else { $messages = form_get_errors(); if (count($values['stakeholders']['owners']) == 1 ) { $usernameOwner = current($values['stakeholders']['owners']); $usertoAdd = $form_state['values']['username']; if ($usernameOwner['name'] === $usertoAdd && !isset($messages['type'])) { drupal_goto('project_settings/confirm/' . $form_state['values']['project_id'] . '/' . $form_state['values']['type'] . '/' . $form_state['values']['username']); } } } } /** * Create the confirm form. */ function origo_home_project_change_group_confirm_form($form_state, $pid, $gid, $username) { // Write values which are needed in confirm_form_submit in the storage. $form = array(); $form_state['storage']['project_id'] = (int) $pid; $form_state['storage']['group_id'] = (int) $gid; $form_state['storage']['username'] = $username; $form_state['storage']['drupal_role'] = (int) $gid; // Create array with form information. It gets built from drupal_get_form from the menu callback. return confirm_form($form, t('Are you sure you want to remove the last Owner?'), 'project_settings', t('This will remove the last Owner of the Project.'), t('I\'m sure'), t('Cancel')); } /** * Submit the changes which I accepted in the confirm form. */ function origo_home_project_change_group_confirm_form_submit($form, $form_state) { if (user_access('origo project settings')) { // Import global $user variable global $user; $group_id = (int) $form_state['storage']['group_id']; // Origo API Call to change group of user origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'project.change_group', (int) ($form_state['storage']['project_id']), $form_state['storage']['username'], (int) $group_id); if ((int) xmlrpc_errno() > 0) { form_set_error('username', t(xmlrpc_error_msg())); } else { drupal_set_message(t('User ' . $form_state['storage']['username'] . ' has been added.')); // if the field 'drupal_role' was set, use it for assigning the front-end's user-role (should client group be showed?) if (isset($form_state['storage']['drupal_role']) && $form_state['storage']['drupal_role'] > 0) { // higher priority for form_value '#drupal_role', if it is set. $group_id = (int) $form_state['storage']['drupal_role']; } // make user role change instant // only assign 'owner' or 'developer' if user is not admin $user = user_load(array('name' => $form_state['storage']['username'])); if (!array_key_exists(5, $user->roles)) { // remove previous owner or member status unset($user->roles['4']); unset($user->roles['3']); // add the new status $user->roles[group_id] = TRUE; user_save($user, array('roles' => $user->roles)); } // the cache has to be cleared db_query("TRUNCATE TABLE {cache_menu}"); } drupal_goto('project_settings'); } } /** * Submit form handler to add user to a project */ function origo_home_project_user_add_form_submit($form, &$form_state) { if (user_access('origo project settings')) { global $user; $group_id = (int)$form_state['values']['type']; // Origo API call to change group of user origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'project.change_group', (int)($form_state['values']['project_id']), $form_state['values']['username'], (int)$group_id); if ((int)xmlrpc_errno() > 0) { form_set_error('username', t(xmlrpc_error_msg())); } else { drupal_set_message(t('User '. $form_state['values']['username'] .' has been added.')); // if the field 'drupal_role' was set, use it for assigning the front-end's user role. if (isset($form_state['values']['drupal_role']) && $form_state['values']['drupal_role'] > 0) { // higher priority for form value '#drupal_role', if it is set. $group_id = (int)$form_state['values']['drupal_role']; } // make user role change instant // only assign 'owner' or 'developer' if user is not admin $user = user_load(array('name' => $form_state['values']['username'])); if (!array_key_exists(5, $user->roles)) { // remove previous 'owner' or 'member' status unset($user->roles['4']); unset($user->roles['3']); // add the new status $user->roles[$group_id] = TRUE; user_save($user, array('roles' => $user->roles)); } // the cache has to be cleared db_query("TRUNCATE TABLE {cache_menu}"); } if ($form_state['values']['admin_mode']) { drupal_goto('origo_admin/project/'. $form_state['values']['project_id']); } else { drupal_goto('project_settings'); } } } /** * Encrypt auth data for feed urls. * @param $auth an array with name and user. * @return the encoded auth data. */ function _encrypt($auth) { $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); $enc = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, variable_get('origo_feed_key', ''), serialize($auth), MCRYPT_MODE_ECB, $iv); $enc = strtr(base64_encode($enc), '+/', '-_'); return $enc; } /** * gets a list with all subscribed projects of the specified users. the list contains * all projects the user participates as member or owner and then all bookmarked projects * (both sorted per se in alphabetically ascending order). projects in which the user * participates AND has a bookmark will only be listed once in the list of participating * projects. * * @param string $username username * @return array[struct['id'=>project id, 'name'=>project name]] */ function _getSubscribedProjectsList($username) { $projects_own = array(); $projects_bookmarked = array(); // get own projects $own_projects = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'project.list_of_user', $username); if ((int)xmlrpc_errno() == 0) { foreach ($own_projects as $project) { $new_project['id'] = $project['project_id']; $new_project['name'] = $project['project_name']; $projects_own[$new_project['name']] = $new_project; } } ksort($projects_own); // get bookmarked projects $bookmarked_projects = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'user.list_bookmark', $username); if ((int)xmlrpc_errno() == 0) { foreach ($bookmarked_projects as $project) { $new_project['id'] = $project['project_id']; $new_project['name'] = $project['name']; if (!array_key_exists($new_project['name'], $projects_own)) { $projects_bookmarked[$new_project['name']] = $new_project; } } } ksort($projects_bookmarked); return array_merge($projects_own, $projects_bookmarked); } /** * Show form to create a new project */ function origo_home_create_project_page() { $output = ''; $output .= 'To request a new project on Origo use the following form.