name, (int)7); if ((int)xmlrpc_errno() > 0) { drupal_set_message(t('The following error occured: '. xmlrpc_error_msg()), 'error'); } else { drupal_set_message(t('Successfully joined community.')); } drupal_goto('communities/'. $community_name); } /** * Leave a community. * * @param String $community_name Community name */ function origo_home_community_leave($community_name) { global $user; origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'community.change_group', $community_name, $user->name, (int)0); if ((int)xmlrpc_errno() > 0) { drupal_set_message(t('The following error occured: '. xmlrpc_error_msg()), 'error'); } else { drupal_set_message(t('Community membership successfully cancelled.')); } drupal_goto('communities/'. $community_name); } /** * Promote a member to admin. * * @param String $community_name Community name * @param String $user_name User name */ function origo_home_community_promote($community_name, $user_name) { origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'community.change_group', $community_name, $user_name, (int)6); if ((int)xmlrpc_errno() > 0) { drupal_set_message(t('The following error occured: '. xmlrpc_error_msg()), 'error'); } else { drupal_set_message(t('User successfully promoted.')); } drupal_goto('communities/'. $community_name); } /** * Demote an admin to member. * * @param String $community_name Community name * @param String $user_name User name */ function origo_home_community_demote($community_name, $user_name) { origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'community.change_group', $community_name, $user_name, (int)7); if ((int)xmlrpc_errno() > 0) { drupal_set_message(t('The following error occured: '. xmlrpc_error_msg()), 'error'); } else { drupal_set_message(t('User successfully demoted.')); } drupal_goto('communities/'. $community_name); } /** * Delete a community page. * * @param String $community_name Community name * @return String Page */ function origo_home_community_delete_page($community_name) { drupal_set_title('Are you sure you want to delete the community '. $community_name .'?'); $output = t('This step can not be undone.
'); $output .= drupal_get_form('origo_home_community_delete_form', $community_name); return $output; } /** * Form to delete a community. * * @param String $community_name Community name */ function origo_home_community_delete_form(&$form_state, $community_name) { $form['community_name'] = array( '#type' => 'hidden', '#value' => $community_name ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Delete'), ); return $form; } /** * Submit hook for community delete form. * * @param String $form_id Name of the form * @param Array $form_value Form values */ function origo_home_community_delete_form_submit($form, &$form_state) { origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'community.delete', $form_state['values']['community_name']); if ((int)xmlrpc_errno() > 0) { drupal_set_message(t('The following error occured: '. xmlrpc_error_msg()), 'error'); } else { drupal_set_message(t('Community successfully deleted.')); } drupal_goto('communities'); } /** * Show all communities. * For Origo admins - show special operations. * * @return String Communities page */ function origo_home_communities_page() { global $user; drupal_set_title('Origo - Communities'); drupal_set_breadcrumb(''); $origo_admin = user_access('origo admin access'); $output = ''; $output .= t('A FAQ regarding communities is here: '); $output .= l('Community FAQ', 'http://'. variable_get('origo_web_domain', '') .'/wiki/community_faq', array('absolute' => TRUE, 'alias' => TRUE)); $output .= t('
'); // Origo API call to get communities $communities = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'community.list'); if ((int)xmlrpc_errno() > 0) { drupal_set_message(t('The following error occured: '. xmlrpc_error_msg()), 'error'); } else { $header = array(array('data' => t('Community'), 'colspan' => '2')); $rows = array(); usort($communities, "_cmp_names"); foreach ($communities as $community) { $link = l($community['name'], 'communities/'. $community['name']); if ($origo_admin) { $delete_link = l('[Delete]', 'communities/'. $community['name'] .'/delete'); } else { $delete_link = ''; } $row = array(); $row[] = array( 'data' => $link, // 'style' => 'height:35px' ); $row[] = array( 'data' => $delete_link, // 'style' => 'height:35px' ); $rows[] = $row; } // Show table $output .= theme('table', $header, $rows, array('style' => 'width:100%')); } return $output; } /** * Display main page of a community. * * @param String $community_name Community name * @return Community main üage */ function origo_home_community_main_page($community_name) { // access permissions (were moved here from the menu-definition in `origo_home.module') $is_community_admin = origo_home_community_is_community_admin($community_name); $is_origo_admin = origo_home_community_is_origo_admin(); $is_member = origo_home_community_is_community_member($community_name); // extract visitor object from global variables $visitor = $GLOBALS['user']; drupal_set_breadcrumb(array('Communities')); $error = ''; // get specific data for this community $community_info = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'community.retrieve', $community_name); if ((int)xmlrpc_errno() > 0) { $error .= t(xmlrpc_error_msg() .'
'); } // get all administrators for this community $admins = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'community.list_members', $community_name, (int)6); if ((int)xmlrpc_errno() > 0) { $error .= t(xmlrpc_error_msg() .'
'); } else { usort($admins, "_cmp_names"); } // get all members for this community $members = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'community.list_members', $community_name, (int)7); if ((int)xmlrpc_errno() > 0) { $error .= t(xmlrpc_error_msg() .'
'); } else { usort($members, "_cmp_names"); } // get all projects associated with this community $projects = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'community.list_projects', $community_name); if ((int)xmlrpc_errno() > 0) { $error .= t(xmlrpc_error_msg() .'
'); } else { usort($projects, "_cmp_names"); } // get all wiki pages for this community $wiki_pages = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'community.list_wiki_pages', $community_name); if ((int)xmlrpc_errno() > 0) { $error .= t(xmlrpc_error_msg() .'
'); } else { usort($wiki_pages, "_cmp_titles"); } // check if any xmlrpc errors occured if (drupal_strlen($error) > 0) { $error_msg = t('The following error(s) occured:
'); $error_msg .= t($error); drupal_set_message($error_msg, 'error'); return ''; } $output = t('
'); $output .= t('
'); // display description $output .= t('
'); $output .= t('
'); $output .= check_markup($community_info['description'], 'wiki', FALSE); $output .= t('
'); $output .= t('
'); // display wiki pages if (sizeof($wiki_pages) > 0) { $output .= t('
Wiki Pages
'); $output .= t('
'); foreach ($wiki_pages as $wiki_page) { $output .= t('
'); $output .= l($wiki_page['title'], 'communities/'. $community_name .'/wiki/'. $wiki_page['title']); if ($is_community_admin || $is_origo_admin) { $output .= l('[delete]', 'communities/'. $community_name .'/wiki/'. $wiki_page['title'] .'/delete', array('attributes' => array('style' => 'margin-left:20px'))); } $output .= t('
'); } $output .= t('
'); } $output .= t('
'); // end colleft $output .= t('
'); $output .= t('
'); // TODO marcozi path to community icon - like user // if ($community_info['logo'] != 'no') { // $image_path = 'http://pictures.origo.ethz.ch/' . $username . '/' . $user_information['icon']; // } // else { $image_path = base_path() . drupal_get_path('module', 'origo_home') .'/img/user_m_big.png"'; // } $output .= t(''. $username .''); $output .= t('
'); // Show [Join] and [Leave] according to status if (!$is_community_admin && !$is_member) { $output .= t('
'); $output .= l('[Join Community]', 'communities/'. $community_name .'/join'); $output .= t('
'); } else { $output .= t('
'); $output .= l('[Leave Community]', 'communities/'. $community_name .'/leave'); $output .= t('
'); } // show [Add Wiki Page] only if visitor has rights to do so if ($is_member || $is_community_admin || $is_origo_admin) { $output .= t('
'); $output .= l('[Add Wiki Page]', 'communities/'. $community_name .'/wiki/add'); $output .= t('
'); } // show [Add Project] only if visitor has rights to do so if ($is_community_admin || $is_origo_admin) { $output .= t('
'); $output .= l('[Add Project]', 'communities/'. $community_name .'/add_project'); $output .= t('
'); } // show [Change Description] only if visitor has rights to do so if ($is_community_admin || $is_origo_admin) { $output .= t('
'); $output .= l('[Change Description]', 'communities/'. $community_name .'/change_description'); $output .= t('
'); } // show [Change Logo] only if visitor has rights to do so // if ($is_admin) { // $output .= t('
'); // $output .= l('[Change Logo]', 'communities/' . $community_name . '/change_logo'); // $output .= t('
'); // } if (sizeof($admins) > 0) { $output .= t('
Administrators
'); $output .= t('
'); foreach ($admins as $admin) { $output .= t('
'); $output .= l($admin['name'], 'users/'. $admin['name']); if ($is_community_admin || $is_origo_admin) { $output .= l('[demote]', 'communities/'. $community_name .'/demote/'. $admin['name'], array('attributes' => array('style' => 'margin-left:20px'))); } $output .= t('
'); } $output .= t('
'); } if (sizeof($members) > 0) { $output .= t('
Members
'); $output .= t('
'); foreach ($members as $member) { $output .= t('
'); $output .= l($member['name'], 'users/'. $member['name']); if ($is_community_admin || $is_origo_admin) { $output .= l('[promote]', 'communities/'. $community_name .'/promote/'. $member['name'], array('attributes' => array('style' => 'margin-left:20px'))); } $output .= t('
'); } $output .= t('
'); } if (sizeof($projects) > 0) { $output .= t('
Associated Projects
'); $output .= t('
'); foreach ($projects as $project) { $output .= t('
'); $output .= l($project['name'], get_origo_project_link($project['name'])); if ($is_community_admin || $is_origo_admin) { $output .= l('[remove]', 'communities/'. $community_name .'/remove_project/'. $project['name'], array('attributes' => array('style' => 'margin-left:20px'))); } $output .= t('
'); } $output .= t('
'); } $output .= t('
'); // end colright $output .= t('
'); // end community return $output; } /** * Display form to add a project to a community. * * @param String $community_name Community name * @return String Form */ function origo_home_community_add_project_page($community_name) { $output = drupal_get_form('origo_home_community_add_project_form', $community_name); return $output; } /** * Form to add a project to a community. * * @param String $community_name Community name */ function origo_home_community_add_project_form(&$form_state, $community_name) { $form['community_name'] = array( '#type' => 'hidden', '#value' => $community_name, ); $form['project_name'] = array( '#type' => 'textfield', '#title' => t('Project Name'), '#size' => 60, '#maxlength' => 50, '#description' => t('Project to be associated with this community'), '#attributes' => NULL, '#required' => TRUE, ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Add Project'), ); return $form; } /** * Submit hook for form to add a project to a community. * * @param String $form_id Form name * @param Array $edit Form values */ function origo_home_community_add_project_form_submit($form, &$form_state) { $result = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'community.add_project', $form_state['values']['community_name'], $form_state['values']['project_name']); if ((int)xmlrpc_errno() > 0) { form_set_error('project_name', t(xmlrpc_error_msg())); } else { drupal_set_message(t('Project successfully added.')); drupal_goto('communities/'. $form_state['values']['community_name']); } } /** * Remove a project from a community. * * @param String $community_name Community name * @param String $project_name Project name */ function origo_home_community_remove_project($community_name, $project_name) { $result = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'community.remove_project', $community_name, $project_name); if ((int)xmlrpc_errno() > 0) { drupal_set_message(t('The following error occured: '. xmlrpc_error_msg()), 'error'); drupal_goto('communities/'. $community_name); } else { drupal_set_message(t('Project successfully removed.')); drupal_goto('communities/'. $community_name); } } /** * Display form to edit a community description. * * @return String Page */ function origo_home_community_change_description_page($community_name) { $output = drupal_get_form('origo_home_community_change_description_form', $community_name); return $output; } /** * Form to edit community description. * * @param String $community_name Community name * @return String Form */ function origo_home_community_change_description_form(&$form_state, $community_name) { $community = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'community.retrieve', $community_name); $form['community_name'] = array( '#type' => 'hidden', '#value' => $community_name, ); $form['description'] = array( '#type' => 'textarea', '#title' => t('Community Description'), '#default_value' => t($community['description']), '#description' => t('You can use wiki syntax.'), '#required' => TRUE, '#cols' => 60, '#rows' => 20, ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Save'), ); return $form; } /** * Submit hook for community edit description form. * * @param String $form_id Form name * @param Array $form_values Form values */ function origo_home_community_change_description_form_submit($form, &$form_state) { origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'community.change_description', $form_state['values']['community_name'], $form_state['values']['description']); if ((int)xmlrpc_errno() > 0) { form_set_error('description', t('The following error occured: '. xmlrpc_error_msg())); } else { drupal_set_message(t('Description saved.')); drupal_goto('communities/'. $form_state['values']['community_name']); } } /** * Show all wiki pages of a community. * * @param String $community_name Community name * @return String List of all wiki pages */ function origo_home_community_list_wiki_page($community_name) { global $user; drupal_set_title('Wiki pages for '. drupal_ucfirst($community_name) .' Community'); $output = ''; // get all wiki pages for this community $wiki_pages = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'community.list_wiki_pages', $community_name); if ((int)xmlrpc_errno() > 0) { drupal_set_message(t('The following error occured: '. xmlrpc_error_msg()), 'error'); } else { usort($wiki_pages, "_cmp_titles"); $header = array(array('data' => t('Wiki Page'), 'colspan' => '2')); $rows = array(); foreach ($wiki_pages as $wiki_page) { $link = l($wiki_page['title'], 'communities/'. $community_name .'/wiki/'. $wiki_page['title']); if (origo_home_community_is_origo_admin() || origo_home_community_is_community_admin($community_name)) { $delete_link = l('[delete]', 'communities/'. $community_name .'/wiki/'. $wiki_page['title'] .'/delete'); } else { $delete_link = ''; } $row = array(); $row[] = array( 'data' => $link, // 'style' => 'height:35px' ); $row[] = array( 'data' => $delete_link, // 'style' => 'height:35px' ); $rows[] = $row; } // Show table $output .= theme('table', $header, $rows, array('style' => 'width:100%')); } return $output; } /** * Display a wiki page of a community. * * @param String $community_name Community name * @param String $wiki_page Wiki page title * @return String Wiki page */ function origo_home_community_show_wiki_page($community_name, $wiki_page) { // get data from backend $wiki_page = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'community.retrieve_wiki_page', $community_name, $wiki_page); if ((int)xmlrpc_errno() > 0) { drupal_set_message(t('The following error occured: '. xmlrpc_error_msg()), 'error'); return ''; } if ($wiki_page['is_private']) { drupal_set_title($wiki_page['title'] .' Private Page'); } else { drupal_set_title($wiki_page['title']); } $output = check_markup($wiki_page['text'], 'wiki', FALSE); return $output; } /** * Display form to edit a wiki page. * * @param String $community_name Community name * @param String $wiki_page Wiki page title * @return String Form */ function origo_home_community_edit_wiki_page($community_name, $wiki_page) { $output = drupal_get_form('origo_home_community_edit_wiki_form', $community_name, $wiki_page); return $output; } /** * Form to edit a wiki page. * * @param String $community_name Community name * @param String $wiki_page Wiki page name * @return String Form */ function origo_home_community_edit_wiki_form(&$form_state, $community_name, $wiki_page) { $community = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'community.retrieve_wiki_page', $community_name, $wiki_page); $form['community_name'] = array( '#type' => 'hidden', '#value' => $community_name, ); $form['old_title'] = array( '#type' => 'hidden', '#value' => $wiki_page, ); $form['old_text'] = array( '#type' => 'hidden', '#value' => $community['text'], ); $form['old_private'] = array( '#type' => 'hidden', '#value' => $community['is_private'], ); $form['title'] = array( '#type' => 'textfield', '#title' => t('Title'), '#default_value' => t($community['title']), '#required' => TRUE, '#maxlength' => 250, ); $form['text'] = array( '#type' => 'textarea', '#title' => t('Body'), '#default_value' => t($community['text']), '#cols' => 60, '#rows' => 20, ); $form['private'] = array( '#type' => 'checkbox', '#title' => t('Private'), '#description' => t('Check here if this content should be set private and only shown to community administrators and members.'), '#default_value' => t($community['is_private']), ); // $form['preview'] = array( // '#type' => 'button', // '#value' => t('Preview'), // ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit'), ); $form['delete'] = array( '#type' => 'button', '#value' => t('Delete'), ); return $form; } /** * Validate hook for edit wiki page form. * * @param String $form_id Form name * @param Array $form_values Form values */ function origo_home_community_edit_wiki_form_validate($form, &$form_state) { // check for operation switch ($form_state['values']['op']) { // case 'Preview': // break; case 'Submit': // check if title changed $title = $form_state['values']['old_title']; if ($form_state['values']['old_title'] != $form_state['values']['title']) { origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'community.rename_wiki_page', $form_state['values']['community_name'], $form_state['values']['old_title'], $form_state['values']['title']); if ((int)xmlrpc_errno() > 0) { form_set_error('title', t('The following error occured: '. xmlrpc_error_msg())); } // update title $title = $form_state['values']['title']; } // edit wiki page if necessary $private = FALSE; if ($form_state['values']['private'] == 1) { $private = TRUE; } if ($form_state['values']['old_text'] != $form_state['values']['text'] || $form_state['values']['old_private'] != $private) { origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'community.edit_wiki_page', $form_state['values']['community_name'], $title, $form_state['values']['text'], $private); if ((int)xmlrpc_errno() > 0) { form_set_error('text', t('The following error occured: '. xmlrpc_error_msg())); } else { drupal_set_message(t('The Wiki Page has been updated.')); } } drupal_goto('communities/'. $form_state['values']['community_name'] .'/wiki/'. $form_state['values']['title']); break; case 'Delete': // go to delete handler drupal_goto('communities/'. $form_state['values']['community_name'] .'/wiki/'. $form_state['values']['title'] .'/delete'); break; default: drupal_set_message(t('Something went wrong.'), 'error'); break; } } /** * Delete a wiki page. * * @param String $community_name Community name * @param String $wiki_page Wiki page name * @return String Page */ function origo_home_community_delete_wiki_page($community_name, $wiki_page) { drupal_set_title('Are you sure you want to delete '. $wiki_page .'?'); $output = t('This action can not be undone.
'); $output .= drupal_get_form('origo_home_community_delete_wiki_form', $community_name, $wiki_page); return $output; } /** * Form to delete a wiki page. * * @param String $community_name Community name * @param String $wiki_page Wiki page name */ function origo_home_community_delete_wiki_form(&$form_state, $community_name, $wiki_page) { $form['community_name'] = array( '#type' => 'hidden', '#value' => $community_name, ); $form['wiki_page'] = array( '#type' => 'hidden', '#value' => $wiki_page, ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Delete') ); return $form; } /** * Submit hook for wiki page delete form. * * @param String $form_id Name of the form * @param Array $form_value Form values */ function origo_home_community_delete_wiki_form_submit($form, &$form_state) { origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'community.delete_wiki_page', $form_state['values']['community_name'], $form_state['values']['wiki_page']); if ((int)xmlrpc_errno() > 0) { drupal_set_message(t('The following error occured: '. xmlrpc_error_msg()), 'error'); } else { drupal_set_message(t('Wiki page successfully deleted.')); } drupal_goto('communities/'. $form_state['values']['community_name']); } /** * Display form to add a wiki page. * * @param String $community_name Community name * @return String Form */ function origo_home_community_add_wiki_page($community_name) { $output = drupal_get_form('origo_home_community_add_wiki_form', $community_name); return $output; } /** * Form to edit a wiki page. * * @param String $community_name Community name * @return String Form */ function origo_home_community_add_wiki_form(&$form_state, $community_name) { $form['community_name'] = array( '#type' => 'hidden', '#value' => $community_name, ); $form['title'] = array( '#type' => 'textfield', '#title' => t('Title'), '#required' => TRUE, '#maxlength' => 250, ); $form['text'] = array( '#type' => 'textarea', '#title' => t('Body'), '#cols' => 60, '#rows' => 20, ); $form['private'] = array( '#type' => 'checkbox', '#title' => t('Private'), '#description' => t('Check here if this content should be set private and only shown to community administrators and members.'), ); // $form['preview'] = array( // '#type' => 'button', // '#value' => t('Preview'), // ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit'), ); return $form; } /** * Validate hook for community add wiki form. * * @param String $form_id Form name * @param Array $form_state['values'] Form values */ function origo_home_community_add_wiki_form_validate($form, &$form_state) { // check for operation switch ($form_state['values']['op']) { // case 'Preview': // break; case 'Submit': $private = FALSE; if ($form_state['values']['private'] == 1) { $private = TRUE; } origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'community.add_wiki_page', $form_state['values']['community_name'], $form_state['values']['title'], $form_state['values']['text'], $private); if ((int)xmlrpc_errno() > 0) { form_set_error('title', t('The following error occured: '. xmlrpc_error_msg())); } else { drupal_set_message(t('The Wiki Page has been created.')); drupal_goto('communities/'. $form_state['values']['community_name'] .'/wiki/'. $form_state['values']['title']); } break; default: drupal_set_message(t('Something went wrong.'), 'error'); break; } } /** * Utility function for checking if the user currently logged-in is an Origo-admin. * @return Boolean */ function origo_home_community_is_origo_admin() { return user_access('origo admin access'); } /** * Utility function for checking if the user currently logged-in has * admin-rights on the community $community_name. * @param $community_name String denoting the name of the community of interest. * @return Boolean */ function origo_home_community_is_community_admin($community_name) { // is user admin of current community? $is_community_admin = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'authorization.is_allowed_community', 'is_community_admin' , $community_name); if ((int)xmlrpc_errno() > 0) { drupal_set_message(t('The following error occured: '. xmlrpc_error_msg()), 'error'); } return $is_community_admin; } /** * Utility function for checking if the user currently logged-in is a member of * the community $community_name. * @param $community_name String denoting the name of the community of interest. * @return Boolean */ function origo_home_community_is_community_member($community_name) { $is_member = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'authorization.is_allowed_community', 'is_community_member' , $community_name); if ((int)xmlrpc_errno() > 0) { drupal_set_message(t('The following error occured: '. xmlrpc_error_msg()), 'error'); } return $is_member; }