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('
');
}
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.