By crinch on
Hi Guys,
I have created a new module, it is working fine on local machine but when I uploaded on the server, it is not being shown in the admin side for activation.
I am not getting understand why it is like this.......
If you want to check the code, I have put it down.
newsite.info file.............
; $Id: newsite.info,v 1.3 2007/08/03 04:33:36 dries Exp $
name = newsite
description = "Enable users to create 'New Site', if the users have no login on this site"
package = "newsite"
version = "5.x-1.x-dev"
project = "newsite"
newsite.module file.....
// $Id: newsite.module,v 1.18 2007/04/24 19:55:09 btmash Exp $
// Selective groups states. chosen by the group admin
define ('nsite_OPEN', 0);
define ('nsite_MODERATED', 1);
define ('nsite_INVITE_ONLY', 2);
define ('nsite_CLOSED', 3);
// visibility states for nodes within groups. site admin chooses in og_settings()
define('nsite_VISIBLE_GROUPONLY', 0);
define('nsite_VISIBLE_BOTH', 1);
define('nsite_VISIBLE_CHOOSE_PUBLIC', 2);
define('nsite_VISIBLE_CHOOSE_PRIVATE', 3);
// site admin chooses in og_settings() whether group creator can put his group on the registration form
define('nsite_REGISTRATION_NEVER', 0);
define('nsite_REGISTRATION_ALWAYS', 1);
define('nsite_REGISTRATION_CHOOSE_TRUE', 2);
define('nsite_REGISTRATION_CHOOSE_FALSE', 3);
//site admin chooses in og_settings() whether group creator can put his group in the Groups directory
define('nsite_DIRECTORY_NEVER', 0);
define('nsite_DIRECTORY_ALWAYS', 1);
define('nsite_DIRECTORY_CHOOSE_TRUE', 2);
define('nsite_DIRECTORY_CHOOSE_FALSE', 3);
// site admin chooses in og_admin_settings() whether new registrants receive group email notifications by default
define('nsite_NOTIFICATION_NEVER', 0);
define('nsite_NOTIFICATION_ALWAYS', 1);
define('nsite_NOTIFICATION_SELECTIVE', 2);
/**
* @file
* Enables the user registration/newsite, if not already login.
*/
define('USERNAME_MAX_LENGTH', 60);
define('EMAIL_MAX_LENGTH', 64);
/**
* Invokes hook_user() in every module.
*
* We cannot use module_invoke() for this, because the arguments need to
* be passed by reference.
*/
function newsite_help($section) {
// this help has been taken from the acidfree.module file.
switch ($section) {
case 'admin/settings/modules#description':
// This description is shown in the listing at admin/settings/modules.
return t('The newsite module information will be displayed in case1.');
case 'node/add#acidfree':
// This description shows up when users click "create content."
return t('The newsite module information will be displayed here for case 2');
case 'admin/help/newsite':
return t('<p>The newsite module information will be displayed here for case3</p>');
case 'admin/help#newsite':
return t('The newsite module information will be displayed here for case 4');
case 'admin/settings/newsite':
return t('Change these settings to however you like. You are w00t, afterall, this is just for the newsite module for case 5');
case 'admin/content/types/newsite':
return t("The newsite module information will be displayed here for case 6");
default:
return "";
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*function newsite_perm() {
// has been taken from the net as create new module: onthisdate_perm
//return array('access newsite content', 'administer newsite');
return array('access newsite', 'create newsite', 'administer newsite');
} // function newsite_perm*/
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function newsite_block($op = 'list', $delta = 0, $edit = array()) {
// this has been taken from onthisdate_block, drupal example
// listing of blocks, such as on the admin/block page
if ($op == "list") {
$block[0]["info"] = t("New Site");
return $block;
} else if ($op == 'view') {
// our block content
// content variable that will be returned for display
$block_content = '';
// Get today's date
$today = getdate();
// calculate midnight one week ago
$start_time = mktime(0, 0, 0,$today['mon'],
($today['mday'] - 7), $today['year']);
// we want items that occur only on the day in question, so
//calculate 1 day
$end_time = $start_time + 86400;
// 60 * 60 * 24 = 86400 seconds in a day
$limitnum = variable_get("newsite_maxdisp", 3);
$query = "SELECT nid, title, created FROM " .
"{node} WHERE created >= '" . $start_time .
"' AND created <= '". $end_time . "' LIMIT " . $limitnum;
// get the links
$queryResult = db_query($query);
while ($links = db_fetch_object($queryResult)) {
$block_content .= l($links->title, 'node/'.$links->nid) . '<br />';
}
// check to see if there was any content before setting up the block
if ($block_content == '') {
// no content from a week ago, return nothing.
return;
}
// set up the block
$block_content .=
"<div class=\"more-link\">".
l(
t("more"),
"newsite",
array(
"title" => t("More events on this day.")
)
)."</div>";
$block['subject'] = 'New Site';
$block['content'] = $block_content;
return $block;
}
} // end of newsite_block function
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function newsite_admin() {
$form['newsite_maxdisp'] = array(
'#type' => 'textfield',
'#title' => t('Maximum number of links'),
'#default_value' => variable_get('newsite_maxdisp', 3),
'#size' => 2,
'#maxlength' => 2,
'#description' => t("The maximum number of links to display in the block.")
);
return system_settings_form($form);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function newsite_menu($may_cache) {
$items = array();
$items[] = array(
'path' => 'admin/settings/newsite',
'title' => t('New Site module settings'),
'description' => t('Description of your New Site settings control'),
'callback' => 'drupal_get_form',
'callback arguments' => 'newsite_admin',
// 'access' => newsite_user_access('access administration pages'),
'access' => user_access('access administration pages'),
'type' => MENU_NORMAL_ITEM,
);
$items[] = array(
'path' => 'user/newsite',
'title' => t('Create Site'),
'description' => t('Description of what is this'),
'callback' => 'drupal_get_form',
'callback arguments' => 'newsite_form',
// 'pid' => variable_get('menu_primary_menu', 0)
'access' => TRUE,
'type' => MENU_NORMAL_ITEM,
);
$items[] = array(
'path' => 'newsite/menu',
'title' => t('My Menu'),
'callback' => 'drupal_get_form',
'callback arguments' => array('newsite_all_forms'),
// 'callback arguments' => array('test_page'),
// 'callback' => 'test_page',
'access' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function newsite_form($form_values = NULL){
global $user;
if(!$user->uid || $user->uid==''){
// $edit = $_POST['edit'];
if (!isset($form_values)) {
$step = 1;
}
if($form_values['op'] == 'Back') {
$step = $form_values['step'] - 1;
}
if($form_values['op'] == 'Next') {
$step = $form_values['step'] + 1;
}
$form['step'] = array(
'#type' => 'hidden',
'#value' => t($step),
);
$row = Array();
if($user->uid)
$row['uid'] = $user->uid;
else
$row['uid'] = '0';
$row['name'] = '';
$row['type'] = 'group';
$row['comment'] = '0';
$row['status'] = '1';
$row['promot'] = '';
$row['sticky'] = '';
$row['revision'] = '';
$group_type = 'group';
$sql = "SELECT * from node_type where type='group'";
$result = db_query($sql, $types);
$row = db_fetch_object($result);
drupal_set_title(t('Create $row->name', array('$row->name' => $row->name)));
$form['#id'] = 'step';
switch($step) {
case 1: // ----------------------------------------------------------------
//start of hidden field for case 2
$form['profile_fullname'] = array(
'#type' => 'hidden',
'#value' => $form_values['profile_fullname'],
);
$form['user_registration_help'] = array(
'#type' => 'hidden',
'#value' => $form_values['user_registration_help'],
);
$form['affiliates'] = array(
'#type' => 'hidden',
'#value' => $form_values['affiliates'],
);
$form['notify'] = array(
'#type' => 'hidden',
'#value' => $form_values['account']['notify'],
);
$form['destination'] = array(
'#type' => 'hidden',
'#value' => $form_values['destination'],
);
$form['name'] = array(
'#type' => 'hidden',
'#value' => $form_values['name'],
);
$form['mail'] = array(
'#type' => 'hidden',
'#value' => $form_values['mail'],
);
$form['pass[pass1]'] = array(
'#type' => 'hidden',
'#value' => $form_values['pass[pass1]'],
);
$form['pass[pass2]'] = array(
'#type' => 'hidden',
'#value' => $form_values['pass[pass2]'],
);
$form['status'] = array(
'#type' => 'hidden',
'#value' => $form_values['status'],
);
$form['roles'] = array(
'#type' => 'hidden',
'#value' => $form_values['roles'],
);
$form['legal_accept'] = array(
'#type' => 'hidden',
'#value' => $form_values['legal_accept'],
);
//end of hidden fields for case 2
$form['step1'] = array('#type' => 'fieldset',
'#title' => t('Site information'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['step1']['og_public'] = array('#type' => 'value', '#value' => TRUE);
$form['nsite_help'] = array(
'#type' => 'item',
'#value' => t($row->help),
'#weight' => -5,
'#prefix' => '<div class="help">',
'#suffix' => '</div>',
);
$form['step1'] = array_merge_recursive($form['step1'], node_invoke($group_type, 'form', $form_values));
// this upper line creates the title and body fields for this module.
// all group home pages are publically accessible as far as og is concerned. their posts may or may not be.
// change this via hook_form_alter() if you want subscriber only group home pages. this may become part of og.module one day
$form['step1']['og_public'] = array('#type' => 'value', '#value' => TRUE);
$form['step1']['og_description'] = array('#type' => 'textfield', '#title' => t('Description'), '#default_value' => $node->og_description, '#size' => 70, '#maxlength' => 150, '#required' => true, '#description' => t('A brief description for the group details block and the group directory.'), '#weight' => -4);
// $form['step1']['og_website'] = array('#type' => 'textfield', '#title' => t('Group website'), '#default_value' => $node->og_website, '#description' => t('If your group has its own website, enter the address here.'));
if ($node->nid) {
$default = $node->og_selective;
}
else {
// $default = nsite_OPEN;
$default = nsite_MODERATED;
}
// $form['step1']['og_selective'] = array('#type' => 'radios', '#title' => t('Subscription requests'), '#default_value' => $default, '#options' => array(t('open - subscription requests are accepted immediately.'), t('moderated - subscription requests must be approved.'), t('invite only - subscriptions must be created by an administrator.'), t('closed - subscriptions are fully administered by an administrator.')), '#description' => t('How should subscription requests be handled in this group? When you select <em>closed</em>, users will not be able to subscribe <strong>or</strong> unsubscribe.'));
$form['og_selective'] = array('#type' => 'hidden', '#default_value' => $default, '#options' => array(t('open - subscription requests are accepted immediately.'), t('moderated - subscription requests must be approved.'), t('invite only - subscriptions must be created by an administrator.'), t('closed - subscriptions are fully administered by an administrator.')), '#description' => t('How should subscription requests be handled in this group? When you select <em>closed</em>, users will not be able to subscribe <strong>or</strong> unsubscribe.'));
// directory checkbox
$visibility = variable_get('nsite_visibility_directory', nsite_DIRECTORY_CHOOSE_FALSE);
// override for admins - get right default
if (user_access('administer nodes')) {
$visibility = in_array($visibility, array(nsite_DIRECTORY_NEVER, nsite_DIRECTORY_CHOOSE_FALSE)) ? nsite_DIRECTORY_CHOOSE_FALSE : nsite_DIRECTORY_CHOOSE_TRUE;
}
$default = FALSE;
switch ($visibility) {
case nsite_DIRECTORY_NEVER:
$form['step1']['og_directory'] = array('#type' => 'value', '#value' => 0);
break;
case nsite_DIRECTORY_ALWAYS:
$form['step1']['og_directory'] = array('#type' => 'value', '#value' => 1);
break;
case nsite_DIRECTORY_CHOOSE_TRUE:
$default = TRUE;
// fall through
case nsite_DIRECTORY_CHOOSE_FALSE:
$form['step1']['og_directory'] = array('#type' => 'checkbox', '#title' => t('list in groups directory'), '#default_value' => $node->nid ? $node->og_directory : $default, '#description' => t('Should this group appear on the !page?', array('!page' => l(t('list of groups page'),'og'))));
break;
}
// language
if (module_exists('locale') && $languages = locale_supported_languages()) {
if (count($languages['name']) > 1) {
$languages['name'] = array_map('check_plain', $languages['name']);
$form['step1']['locale']['og_language'] = array('#type' => 'radios',
'#title' => t('Language'),
'#default_value' => $node->og_language,
'#options' => $languages['name'],
'#description' => t('Selecting a different locale will change the interface language of the group. Users who have chosen a preferred language always see their chosen language.'),
);
}
}
$subs = og_get_subscriptions($row->uid);
foreach ($subs as $key => $val) {
$groups[$key] = $val['title'];
}
$cnt = count($groups);
// show multi-select. if less than 20 choices, use checkboxes.
$form['step1']['og_author'] = array('#type' => 'select',
'#title' => t('Author group'),
'#options' => $groups,
'#required' => $required,
'#description' => t('Select the group that will be authoring this post.'),
'#required' => $required,
'#multiple' => FALSE);
$form['step1']['back'] = array(
'#type' => 'hidden',
'#value' => 'Back',
);
$form['step1']['next'] = array(
'#type' => 'submit',
'#value' => 'Next',
);
break;
case 2: // ----------------------------------------------------------------
//start of hidden fields for case 1
$form['title'] = array(
'#type' => 'hidden',
'#value' => $form_values['title'],
);
$form['og_description'] = array(
'#type' => 'hidden',
'#value' => $form_values['og_description'],
);
$form['body'] = array(
'#type' => 'hidden',
'#value' => $form_values['body'],
);
$form['og_website'] = array(
'#type' => 'hidden',
'#value' => $form_values['og_website'],
);
$form['og_selective'] = array(
'#type' => 'hidden',
'#value' => $form_values['og_selective'],
);
$form['og_directory'] = array(
'#type' => 'hidden',
'#value' => $form_values['og_directory'],
);
$form['og_author'] = array(
'#type' => 'hidden',
'#value' => $form_values['og_author'],
);
$form['og_public'] = array(
'#type' => 'hidden',
'#value' => $form_values['og_public'],
);
//end of fields fields for case 1
$form['step2'] = array('#type' => 'fieldset',
'#title' => t('User Information'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#weight' => '0',
);
//$admin = newsite_user_access('administer users');
$admin = user_access('administer users');
// If we aren't admin but already logged on, go to the user page instead.
if (!$admin && $user->uid) {
drupal_goto('user/'. $user->uid);
}
if (!$admin) {
$form['step2']['user_registration_help'] = array('#value' => filter_xss_admin(variable_get('user_registration_help', '')));
}
$affiliates = user_auth_help_links();
if (!$admin && count($affiliates) > 0) {
$affiliates = implode(', ', $affiliates);
$form['step2']['affiliates'] = array('#value' => '<p>'. t('Note: if you have an account with one of our affiliates (!s), you may <a href="@login_uri">login now</a> instead of registering.', array('!s' => $affiliates, '@login_uri' => url('user'))) .'</p>');
}
$form['step2'] = array_merge($form['step2'], user_edit_form(NULL, NULL, TRUE));
if ($admin) {
$form['step2']['account']['notify'] = array(
'#type' => 'checkbox',
'#title' => t('Notify user of new account')
);
// Redirect back to page which initiated the create request; usually admin/user/user/create
$form['step2']['destination'] = array('#type' => 'hidden', '#value' => $_GET['q']);
}
$null = NULL;
$extra = _user_forms($null, NULL, NULL, 'register');
if (!$extra) {
$form['step2']['name'] = $form['account']['name'];
$form['step2']['mail'] = $form['account']['mail'];
$form['step2']['pass'] = $form['account']['pass'];
$form['step2']['status'] = $form['account']['status'];
$form['step2']['roles'] = $form['account']['roles'];
$form['step2']['notify'] = $form['account']['notify'];
unset($form['account']);
}
else {
$form['step2'] = array_merge($form['step2'], $extra);
}
$form['step2']['back'] = array(
'#type' => 'button',
'#value' => 'Back',
'#weight' => 40,
);
$form['step2']['finish'] = array(
'#type' => 'submit',
'#value' => 'Finish',
'#weight' => 45,
);
break;
}//end of switch
$form['#multistep'] = TRUE;
$form['#redirect'] = FALSE;
$form['#base'] = 'newsite_form';
$form['og_theme'] = system_theme_select_form(t('Selecting a different theme will change the look and feel of the group.'), $edit['theme'] ? $edit['theme'] : $node->nsite_theme, 2);;
return $form;
}// end of if for !user
else{
drupal_goto('node/add/group');
}
} // end of function newsite_form
//***************************************************** VALIDATION********************************************************//
function newsite_form_validate($form_id, $form_values){
if($form_values['step']!='' && !empty($form_values['step']) && $form_values['step']=='2'){
newsite_module_invoke('validate', $form_values, $form_values, 'account');
}
elseif($form_values['step']!='' && !empty($form_values['step']) && $form_values['step']=='1'){
if (isset($form_values['nsite_website']) && !empty($form_values['nsite_website'])) {
if (!valid_url($form_values['nsite_website'], TRUE)) {
form_set_error('nsite_website', t('Please enter a valid URL for group website, such as http://www.example.com/'));
}
}
}
} // end of function newsite_form_validate
//**************************************************** END VALIDATEION ******************************************************//
//***************************************************** SUBMISSION *********************************************************//
function newsite_form_submit($form_id, $form_values){
global $user;
//////////////////// start of account submission ///////////////////////////////////////
global $base_url;
$admin = newsite_user_access('administer users');
$mail = $form_values['mail'];
$name = $form_values['name'];
if (!variable_get('user_email_verification', TRUE) || $admin) {
$pass = $form_values['pass'];
}
else {
$pass = newsite_user_password();
};
$notify = $form_values['notify'];
$from = variable_get('site_mail', ini_get('sendmail_from'));
if (isset($form_values['roles'])) {
$roles = array_filter($form_values['roles']); // Remove unset roles
}
if (!$admin && array_intersect(array_keys($form_values), array('uid', 'roles', 'init', 'session', 'status'))) {
watchdog('security', t('Detected malicious attempt to alter protected user fields.'), WATCHDOG_WARNING);
return 'user/register';
}
//the unset below is needed to prevent these form values from being saved as user data
unset($form_values['form_token'], $form_values['submit'], $form_values['op'], $form_values['notify'], $form_values['form_id'], $form_values['affiliates'], $form_values['destination']);
$merge_data = array('pass' => $pass, 'init' => $mail, 'roles' => $roles);
if (!$admin) {
// Set the user's status because it was not displayed in the form.
$merge_data['status'] = variable_get('user_register', 1) == 1; //it should be changed.
}
$account = newsite_user_save('', array_merge($form_values, $merge_data));
watchdog('user', t('New user: %name %email.', array('%name' => $name, '%email' => '<'. $mail .'>')), WATCHDOG_NOTICE, l(t('edit'), 'user/'. $account->uid .'/edit'));
$variables = array('!username' => $name, '!site' => variable_get('site_name', 'Drupal'), '!password' => $pass, '!uri' => $base_url, '!uri_brief' => substr($base_url, strlen('http://')), '!mailto' => $mail, '!date' => format_date(time()), '!login_uri' => url('user', NULL, NULL, TRUE), '!edit_uri' => url('user/'. $account->uid .'/edit', NULL, NULL, TRUE), '!login_url' => newsite_user_pass_reset_url($account));
// The first user may login immediately, and receives a customized welcome e-mail.
if ($account->uid == 1) {
drupal_mail('user-register-admin', $mail, t('Drupal user account details for !s', array('!s' => $name)), strtr(t("!username,\n\nYou may now login to !uri using the following username and password:\n\n username: !username\n password: !password\n\n!edit_uri\n\n--drupal"), $variables), $from);
drupal_set_message(t('<p>Welcome to Drupal. You are user #1, which gives you full and immediate access. All future registrants will receive their passwords via e-mail, so please make sure your website e-mail address is set properly under the general settings on the <a href="@settings">site information settings page</a>.</p><p> Your password is <strong>%pass</strong>. You may change your password below.</p>', array('%pass' => $pass, '@settings' => url('admin/settings/site-information'))));
newsite_user_authenticate($account->name, trim($pass));
return 'user/1/edit';
}
else {
if ($admin && !$notify) {
drupal_set_message(t('Created a new user account. No e-mail has been sent.'));
}
else if (!variable_get('user_email_verification', TRUE) && $account->status && !$admin) {
// No e-mail verification is required, create new user account, and login user immediately.
$subject = newsite_user_mail_text('welcome_subject', $variables);
$body = newsite_user_mail_text('welcome_body', $variables);
drupal_mail('user-register-welcome', $mail, $subject, $body, $from);
newsite_user_authenticate($account->name, trim($pass));
//drupal_goto();
}
else if ($account->status || $notify) {
drupal_set_message(t('I am in else if condition2'));
// Create new user account, no administrator approval required.
$subject = $notify ? newsite_user_mail_text('admin_subject', $variables) : newsite_user_mail_text('welcome_subject', $variables);
$body = $notify ? newsite_user_mail_text('admin_body', $variables) : newsite_user_mail_text('welcome_body', $variables);
drupal_mail(($notify ? 'user-register-notify' : 'user-register-welcome'), $mail, $subject, $body, $from);
if ($notify) {
drupal_set_message(t('Password and further instructions have been e-mailed to the new user %user.', array('%user' => $name)));
}
else {
drupal_set_message(t('I am in else condidtion1'));
drupal_set_message(t('Your password and further instructions have been sent to your e-mail address.'));
return '';
}
}
else {
drupal_set_message(t('I am in else condidtion2'));
// Create new user account, administrator approval required.
$subject = newsite_user_mail_text('approval_subject', $variables);
$body = newsite_user_mail_text('approval_body', $variables);
drupal_mail('user-register-approval-user', $mail, $subject, $body, $from);
drupal_mail('user-register-approval-admin', $from, $subject, t("!username has applied for an account.\n\n!edit_uri", $variables), $from);
drupal_set_message(t('Thank you for applying for an account. Your account is currently pending approval by the site administrator.<br />In the meantime, your password and further instructions have been sent to your e-mail address.'));
}
}
///////////////////////////////////////// end of account submission /////////////////////////////////////////////////////
//////////////////////////////////////// start of newsite submission //////////////////////////////////////////////////
if(isset($user->uid))
{
//$node = Array();
//$node['uid'] = $user->uid;
$form_values['uid'] = $user->uid;
//$node['name'] = $user->name;
$form_values['name'] = $user->name;
//$node['type'] = 'group';
$form_values['type'] = 'group';
//$node = (object)$node;
node_object_prepare($node);
if (!isset($form_values['created'])) {
$form_values['created'] = time();
}
if (!isset($form_vlaues['date'])) {
$form_values['date'] = format_date($form_values['created'], 'custom', 'Y-m-d H:i:s O');
}
//node_invoke($node, 'prepare');
//node_invoke_nodeapi($node, 'prepare');
$node_options = variable_get('node_options_'. $form_values['type'], array('status', 'promote'));
if (!isset($form_values['nid'])) {
foreach (array('status', 'promote', 'sticky', 'revision') as $key) {
$form_values[$key] = in_array($key, $node_options);
}
$form_values['uid'] = $user->uid;
}
else {
// Nodes being edited should always be preset with the default revision setting.
$form_values['revision'] = in_array('revision', $node_options);
}
if (og_is_group_type($form_values['type'])) {
$form_values['comment'] = COMMENT_NODE_DISABLED;
}
// Reset to follow site default theme if user selects the site default
if ($form_values['og_theme'] == variable_get('theme_default', 'bluemarine')) {
$form_values['og_theme'] = NULL;
}
// Normalize og_groups array
if (is_array($form_values['og_groups'])) {
$form_values['og_groups'] = array_filter($form_values['og_groups']);
$form_values['og_groups'] = array_keys($form_values['og_groups']);
}
// start of node_form_submit//
$node = node_submit($form_values);
// Prepare the node's body:
if ($node->nid) {
node_save($node);
// module_invoke_all('init');
watchdog('content', t('@type: updated %title.', array('@type' => t($node->type), '%title' => $node->title)), WATCHDOG_NOTICE, l(t('view'), 'node/'. $node->nid));
drupal_set_message(t('The %post has been updated.', array('%post' => node_get_types('name', $node))));
}
else {
node_save($node);
// module_invoke_all('init');
watchdog('content', t('@type: added %title.', array('@type' => t($node->type), '%title' => $node->title)), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid"));
drupal_set_message(t('Your %post has been created.', array('%post' => node_get_types('name', $node))));
}
// end//
//if op=insert//
if (og_is_group_type($node->type)) {
newsite_insert_group($node);
// make sure the node owner is a full powered subscriber
og_save_subscription($node->nid, $node->uid, array('is_active' => 1, 'is_admin' => 1));
$account = user_load(array('uid' => $node->uid));
$variables = array(
'@group' => $node->title,
'!group_url' => url("node/$node->nid", NULL, NULL, TRUE),
'@username' => $account->name,
'!invite_url' => url("og/invite/$node->nid", NULL, NULL, TRUE)
);
// alert the user that they are now the admin of the group
$from = variable_get('site_mail', ini_get('sendmail_from'));
drupal_mail('og_new_admin', $account->mail, _og_user_mail_text('og_new_admin_subject', $variables), _og_user_mail_text('og_new_admin_body', $variables), $from);
}
elseif (!og_is_omitted_type($node->type)) {
og_save_ancestry($node);
}
// TODO: move this to cron to help give time to fix typos, and help scaling. create new module
// implementing an SMTP library that uses cron.
if (!module_exists('og2list')) {
if ($node->status && og_node_type_notify($node->type)) {
$node->msgid = "$node->nid-0". og_msgid_server();
og_mail(node_get_types('name', $node), $node);
}
}
////////////////////start of block///////////////////////////
db_query('INSERT INTO {node_counter} (nid, daycount, totalcount, timestamp) VALUES (%d, 1, 1, %d)', $node->nid, time());
if ((variable_get('statistics_enable_access_log', 0)) && (module_invoke('throttle', 'status') == 0)) {
// Log this page access.
db_query("INSERT INTO {accesslog} (title, path, url, hostname, uid, sid, timer, timestamp) values('%s', '%s', '%s', '%s', %d, '%s', %d, %d)", strip_tags(drupal_get_title()), $_GET['q'], referer_uri(), $_SERVER['REMOTE_ADDR'], $user->uid, session_id(), timer_read('page'), time());
}
/////////////end of block //////////////////////////////////
$node = node_load($node->nid);
drupal_goto("newsite/menu/$node->nid");
//$node->title = str_replace('/','',$node->title);
//$node->title = str_replace(':','-',$node->title);
//drupal_goto(str_replace('.','-',$node->title));
/*
$groupPath = pathauto_cleanstring($node->title);
drupal_goto($groupPath);
*/
/*
$group_node=og_get_group_context();
$urlname = strtolower($group_node->title); // Convert to lowercase
$urlname = ereg_replace("[//:]", " ", $urlname); // Remove punctuation
$urlname = str_replace(".", " ", $urlname); // Remove punctuation
$urlname = ereg_replace(" +", " ", $urlname); //Remove multiple spaces
$urlname = str_replace(" ", "-", $urlname); //Convert spaces to hyphens
$urlname = ereg_replace("[^a-zA-Z0-9-]", "", $urlname); //I don't remember
$groupurl=$urlname;
$groupPath = pathauto_cleanstring($node->title);
drupal_goto($groupPath);
/*
$group_node=og_get_group_context();
$urlname = strtolower($group_node->title); // Convert to lowercase
$urlname = ereg_replace("[//:]", " ", $urlname); // Remove punctuation
$urlname = str_replace(".", " ", $urlname); // Remove punctuation
$urlname = ereg_replace(" +", " ", $urlname); //Remove multiple spaces
$urlname = str_replace(" ", "-", $urlname); //Convert spaces to hyphens
$urlname = ereg_replace("[^a-zA-Z0-9-]", "", $urlname); //I don't remember
$groupurl=$urlname;
drupal_goto($groupurl);
*/
} // end of if for user->uid
///////////////////////////////////////// end of newsite submission ////////////////////////////////////////////////////
}// end of function of newsite_form_submit
//***************************************************** END SUBMISSION ******************************************************//
function newsite_module_invoke($type, &$array, &$user, $category = NULL) {
foreach (module_list() as $module) {
$function = $module .'_user';
if (function_exists($function)) {
$function($type, $array, $user, $category);
}
}
} // end of function newsite_module_invoke
function newsite_user($type, &$edit, &$user, $category = NULL) {
if ($type == 'view') {
$items['history'] = array('title' => t('Member for'),
'value' => format_interval(time() - $user->created),
'class' => 'member',
);
return array(t('History') => $items);
}
if ($type == 'form' && $category == 'account') {
return user_edit_form(arg(1), $edit);
}
if ($type == 'validate' && $category == 'account') {
return _newsite_edit_validate(arg(1), $edit);
}
if ($type == 'submit' && $category == 'account') {
return _newsite_edit_submit(arg(1), $edit);
}
if ($type == 'categories') {
return array(array('name' => 'account', 'title' => t('Account settings'), 'weight' => 1));
}
}// end of function newsite_user
function _newsite_edit_validate($uid, &$edit) {
$user = newsite_user_load(array('uid' => $uid));
// Validate the username:
if (newsite_user_access('change own username') || newsite_user_access('administer users') || arg(1) == 'register') {
if ($error = newsite_user_validate_name($edit['name'])) {
form_set_error('name', $error);
}
else if (db_num_rows(db_query("SELECT uid FROM {users} WHERE uid != %d AND LOWER(name) = LOWER('%s')", $uid, $edit['name'])) > 0) {
form_set_error('name', t('The name %name is already taken.', array('%name' => $edit['name'])));
}
else if (drupal_is_denied('user', $edit['name'])) {
form_set_error('name', t('The name %name has been denied access.', array('%name' => $edit['name'])));
}
}
// Validate the e-mail address:
if ($error = newsite_user_validate_mail($edit['mail'])) {
form_set_error('mail', $error);
}
else if (db_num_rows(db_query("SELECT uid FROM {users} WHERE uid != %d AND LOWER(mail) = LOWER('%s')", $uid, $edit['mail'])) > 0) {
form_set_error('mail', t('The e-mail address %email is already registered. <a href="@password">Have you forgotten your password?</a>', array('%email' => $edit['mail'], '@password' => url('user/password'))));
}
else if (drupal_is_denied('mail', $edit['mail'])) {
form_set_error('mail', t('The e-mail address %email has been denied access.', array('%email' => $edit['mail'])));
}
// If required, validate the uploaded picture.
if ($file = file_check_upload('picture_upload')) {
newsite_user_validate_picture($file, $edit, $user);
}
} // end of function _newsite_edit_validate
function newsite_user_load($array = array()) {
// Dynamically compose a SQL query:
$query = array();
$params = array();
foreach ($array as $key => $value) {
if ($key == 'uid' || $key == 'status') {
$query[] = "$key = %d";
$params[] = $value;
}
else if ($key == 'pass') {
$query[] = "pass = '%s'";
$params[] = md5($value);
}
else {
$query[]= "LOWER($key) = LOWER('%s')";
$params[] = $value;
}
}
$result = db_query('SELECT * FROM {users} u WHERE '. implode(' AND ', $query), $params);
if (db_num_rows($result)) {
$user = db_fetch_object($result);
$user = drupal_unpack($user);
$user->roles = array();
if ($user->uid) {
$user->roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user';
}
else {
$user->roles[DRUPAL_ANONYMOUS_RID] = 'anonymous user';
}
$result = db_query('SELECT r.rid, r.name FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid = %d', $user->uid);
while ($role = db_fetch_object($result)) {
$user->roles[$role->rid] = $role->name;
}
newsite_module_invoke('load', $array, $user);
}
else {
$user = FALSE;
}
return $user;
} // end of function newsite_user_load
function newsite_user_validate_name($name) {
if (!strlen($name)) return t('You must enter a username.');
if (substr($name, 0, 1) == ' ') return t('The username cannot begin with a space.');
if (substr($name, -1) == ' ') return t('The username cannot end with a space.');
if (strpos($name, ' ') !== FALSE) return t('The username cannot contain multiple spaces in a row.');
if (ereg("[^\x80-\xF7 [:alnum:]@_.-]", $name)) return t('The username contains an illegal character.');
if (preg_match('/[\x{80}-\x{A0}'. // Non-printable ISO-8859-1 + NBSP
'\x{AD}'. // Soft-hyphen
'\x{2000}-\x{200F}'. // Various space characters
'\x{2028}-\x{202F}'. // Bidirectional text overrides
'\x{205F}-\x{206F}'. // Various text hinting characters
'\x{FEFF}'. // Byte order mark
'\x{FF01}-\x{FF60}'. // Full-width latin
'\x{FFF9}-\x{FFFD}'. // Replacement characters
'\x{0}]/u', // NULL byte
$name)) {
return t('The username contains an illegal character.');
}
if (strpos($name, '@') !== FALSE && !eregi('@([0-9a-z](-?[0-9a-z])*.)+[a-z]{2}([zmuvtg]|fo|me)?$', $name)) return t('The username is not a valid authentication ID.');
if (strlen($name) > USERNAME_MAX_LENGTH) return t('The username %name is too long: it must be %max characters or less.', array('%name' => $name, '%max' => USERNAME_MAX_LENGTH));
} // end of function newsite_user_validate_name
function newsite_user_validate_mail($mail) {
if (!$mail) return t('You must enter an e-mail address.');
if (!valid_email_address($mail)) {
return t('The e-mail address %mail is not valid.', array('%mail' => $mail));
}
} // end of function newsite_user_validate_mail
function newsite_user_validate_picture($file, &$edit, $user) {
global $form_values;
// Initialize the picture:
$form_values['picture'] = $user->picture;
// Check that uploaded file is an image, with a maximum file size
// and maximum height/width.
$info = image_get_info($file->filepath);
list($maxwidth, $maxheight) = explode('x', variable_get('user_picture_dimensions', '85x85'));
if (!$info || !$info['extension']) {
form_set_error('picture_upload', t('The uploaded file was not an image.'));
}
else if (image_get_toolkit()) {
image_scale($file->filepath, $file->filepath, $maxwidth, $maxheight);
}
else if (filesize($file->filepath) > (variable_get('user_picture_file_size', '30') * 1000)) {
form_set_error('picture_upload', t('The uploaded image is too large; the maximum file size is %size kB.', array('%size' => variable_get('user_picture_file_size', '30'))));
}
else if ($info['width'] > $maxwidth || $info['height'] > $maxheight) {
form_set_error('picture_upload', t('The uploaded image is too large; the maximum dimensions are %dimensions pixels.', array('%dimensions' => variable_get('user_picture_dimensions', '85x85'))));
}
if (!form_get_errors()) {
if ($file = file_save_upload('picture_upload', variable_get('user_picture_path', 'pictures') .'/picture-'. $user->uid .'.'. $info['extension'], 1)) {
$form_values['picture'] = $file->filepath;
}
else {
form_set_error('picture_upload', t("Failed to upload the picture image; the %directory directory doesn't exist.", array('%directory' => variable_get('user_picture_path', 'pictures'))));
}
}
} // end of function newsite_user_validate_picture
function _newsite_edit_submit($uid, &$edit) {
$user = newsite_user_load(array('uid' => $uid));
// Delete picture if requested, and if no replacement picture was given.
if ($edit['picture_delete']) {
if ($user->picture && file_exists($user->picture)) {
file_delete($user->picture);
}
$edit['picture'] = '';
}
if (isset($edit['roles'])) {
$edit['roles'] = array_filter($edit['roles']);
}
}// end of function _newsite_edit_submit
function newsite_user_access($string, $account = NULL) {
global $user;
static $perm = array();
if (is_null($account)) {
$account = $user;
}
// User #1 has all privileges:
if ($account->uid == 1) {
return TRUE;
}
// To reduce the number of SQL queries, we cache the user's permissions
// in a static variable.
if (!isset($perm[$account->uid])) {
$result = db_query("SELECT DISTINCT(p.perm) FROM {role} r INNER JOIN {permission} p ON p.rid = r.rid WHERE r.rid IN (%s)", implode(',', array_keys($account->roles)));
$perm[$account->uid] = '';
while ($row = db_fetch_object($result)) {
$perm[$account->uid] .= "$row->perm, ";
}
}
if (isset($perm[$account->uid])) {
return strpos($perm[$account->uid], "$string, ") !== FALSE;
}
return FALSE;
}// end of function newsite_access
//******************************************************************************************************************************//
function newsite_user_password($length = 10) {
// This variable contains the list of allowable characters for the
// password. Note that the number 0 and the letter 'O' have been
// removed to avoid confusion between the two. The same is true
// of 'I', 1, and l.
$allowable_characters = 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789';
// Zero-based count of characters in the allowable list:
$len = strlen($allowable_characters) - 1;
// Declare the password as a blank string.
$pass = '';
// Loop the number of times specified by $length.
for ($i = 0; $i < $length; $i++) {
// Each iteration, pick a random character from the
// allowable string and append it to the password:
$pass .= $allowable_characters[mt_rand(0, $len)];
}
return $pass;
}// end of function newsite_user_password
function newsite_user_save($account, $array = array(), $category = 'account') {
// Dynamically compose a SQL query:
$user_fields = user_fields();
if ($account->uid) {
newsite_module_invoke('update', $array, $account, $category);
$data = unserialize(db_result(db_query('SELECT data FROM {users} WHERE uid = %d', $account->uid)));
foreach ($array as $key => $value) {
if ($key == 'pass' && !empty($value)) {
$query .= "$key = '%s', ";
$v[] = md5($value);
}
else if ((substr($key, 0, 4) !== 'auth') && ($key != 'pass')) {
if (in_array($key, $user_fields)) {
// Save standard fields
$query .= "$key = '%s', ";
$v[] = $value;
}
else if ($key != 'roles') {
// Roles is a special case: it used below.
if ($value === NULL) {
unset($data[$key]);
}
else {
$data[$key] = $value;
}
}
}
}
$query .= "data = '%s' ";
$v[] = serialize($data);
db_query("UPDATE {users} SET $query WHERE uid = %d", array_merge($v, array($account->uid)));
// Reload user roles if provided
if (is_array($array['roles'])) {
db_query('DELETE FROM {users_roles} WHERE uid = %d', $account->uid);
foreach (array_keys($array['roles']) as $rid) {
if (!in_array($rid, array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID))) {
db_query('INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)', $account->uid, $rid);
}
}
}
// Delete a blocked user's sessions to kick them if they are online.
if (isset($array['status']) && $array['status'] == 0) {
sess_destroy_uid($account->uid);
}
// Refresh user object
$user = newsite_user_load(array('uid' => $account->uid));
newsite_module_invoke('after_update', $array, $user, $category);
}
else {
$array['uid'] = db_next_id('{users}_uid');
if (!isset($array['created'])) { // Allow 'created' to be set by hook_auth
$array['created'] = time();
}
// Note, we wait with saving the data column to prevent module-handled
// fields from being saved there. We cannot invoke hook_user('insert') here
// because we don't have a fully initialized user object yet.
foreach ($array as $key => $value) {
switch ($key) {
case 'pass':
$fields[] = $key;
$values[] = md5($value);
$s[] = "'%s'";
break;
case 'uid': case 'mode': case 'sort':
case 'threshold': case 'created': case 'access':
case 'login': case 'status':
$fields[] = $key;
$values[] = $value;
$s[] = "%d";
break;
default:
if (substr($key, 0, 4) !== 'auth' && in_array($key, $user_fields)) {
$fields[] = $key;
$values[] = $value;
$s[] = "'%s'";
}
break;
}
}
db_query('INSERT INTO {users} ('. implode(', ', $fields) .') VALUES ('. implode(', ', $s) .')', $values);
// Build the initial user object.
$user = newsite_user_load(array('uid' => $array['uid']));
newsite_module_invoke('insert', $array, $user, $category);
// Build and save the serialized data field now
$data = array();
foreach ($array as $key => $value) {
if ((substr($key, 0, 4) !== 'auth') && ($key != 'roles') && (!in_array($key, $user_fields)) && ($value !== NULL)) {
$data[$key] = $value;
}
}
db_query("UPDATE {users} SET data = '%s' WHERE uid = %d", serialize($data), $user->uid);
// Save user roles (delete just to be safe).
if (is_array($array['roles'])) {
db_query('DELETE FROM {users_roles} WHERE uid = %d', $array['uid']);
foreach (array_keys($array['roles']) as $rid) {
if (!in_array($rid, array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID))) {
db_query('INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)', $array['uid'], $rid);
}
}
}
// Build the finished user object.
$user = newsite_user_load(array('uid' => $array['uid']));
}
// Save distributed authentication mappings
$authmaps = array();
foreach ($array as $key => $value) {
if (substr($key, 0, 4) == 'auth') {
$authmaps[$key] = $value;
}
}
if (sizeof($authmaps) > 0) {
newsite_user_set_authmaps($user, $authmaps);
}
return $user;
} // end of newsite_user_save
function newsite_user_set_authmaps($account, $authmaps) {
foreach ($authmaps as $key => $value) {
$module = explode('_', $key, 2);
if ($value) {
db_query("UPDATE {authmap} SET authname = '%s' WHERE uid = %d AND module = '%s'", $value, $account->uid, $module[1]);
if (!db_affected_rows()) {
db_query("INSERT INTO {authmap} (authname, uid, module) VALUES ('%s', %d, '%s')", $value, $account->uid, $module[1]);
}
}
else {
db_query("DELETE FROM {authmap} WHERE uid = %d AND module = '%s'", $account->uid, $module[1]);
}
}
}// end of function newsite_user_set_authmaps
function newsite_user_pass_reset_url($account) {
$timestamp = time();
return url("user/reset/$account->uid/$timestamp/".newsite_user_pass_rehash($account->pass, $timestamp, $account->login), NULL, NULL, TRUE);
}// end of function newsite_user_pass_reset_url
function newsite_user_pass_rehash($password, $timestamp, $login) {
return md5($timestamp . $password . $login);
}
function newsite_user_authenticate($name, $pass) {
global $user;
// Try to log in the user locally. Don't set $user unless successful.
if ($account = newsite_user_load(array('name' => $name, 'pass' => $pass, 'status' => 1))) {
$user = $account;
return $user;
}
// Strip name and server from ID:
if ($server = strrchr($name, '@')) {
$name = substr($name, 0, strlen($name) - strlen($server));
$server = substr($server, 1);
}
// When possible, determine corresponding external auth source. Invoke
// source, and log in user if successful:
if ($server && ($result = newsite_user_get_authmaps("$name@$server"))) {
if (module_invoke(key($result), 'auth', $name, $pass, $server)) {
$user = newsite_user_external_load("$name@$server");
watchdog('user', t('External load by %user using module %module.', array('%user' => $name .'@'. $server, '%module' => key($result))));
}
}
// Try each external authentication source in series. Register user if
// successful.
else {
foreach (module_implements('auth') as $module) {
if (module_invoke($module, 'auth', $name, $pass, $server)) {
if ($server) {
$name .= '@'. $server;
}
$user = newsite_user_load(array('name' => $name));
if (!$user->uid) { // Register this new user.
$userinfo = array('name' => $name, 'pass' => user_password(), 'init' => $name, 'status' => 1);
if ($server) {
$userinfo["authname_$module"] = $name;
}
$user = newsite_user_save('', $userinfo);
watchdog('user', t('New external user: %user using module %module.', array('%user' => $name, '%module' => $module)), WATCHDOG_NOTICE, l(t('edit'), 'user/'. $user->uid .'/edit'));
break;
}
}
}
}
return $user;
}// end of function newsite_user_authenticate
function newsite_user_get_authmaps($authname = NULL) {
$result = db_query("SELECT authname, module FROM {authmap} WHERE authname = '%s'", $authname);
if (db_num_rows($result) > 0) {
while ($authmap = db_fetch_object($result)) {
$authmaps[$authmap->module] = $authmap->authname;
}
return $authmaps;
}
else {
return 0;
}
}// end of function newsite_user_get_authmaps
function newsite_user_external_load($authname) {
$result = db_query("SELECT uid FROM {authmap} WHERE authname = '%s'", $authname);
if ($user = db_fetch_array($result)) {
return newsite_user_load($user);
}
else {
return 0;
}
}// end of function newsite_user_external_load
function newsite_user_mail_text($messageid, $variables = array()) {
// Check if an admin setting overrides the default string.
if ($admin_setting = variable_get('user_mail_'. $messageid, FALSE)) {
return strtr($admin_setting, $variables);
}
// No override, return with default strings.
else {
switch ($messageid) {
case 'welcome_subject':
return t('Account details for !username at !site', $variables);
case 'welcome_body':
return t("!username,\n\nThank you for registering at !site. You may now log in to !login_uri using the following username and password:\n\nusername: !username\npassword: !password\n\nYou may also log in by clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.\n\n\n-- !site team", $variables);
case 'admin_subject':
return t('An administrator created an account for you at !site', $variables);
case 'admin_body':
return t("!username,\n\nA site administrator at !site has created an account for you. You may now log in to !login_uri using the following username and password:\n\nusername: !username\npassword: !password\n\nYou may also log in by clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.\n\n\n-- !site team", $variables);
case 'approval_subject':
return t('Account details for !username at !site (pending admin approval)', $variables);
case 'approval_body':
return t("!username,\n\nThank you for registering at !site. Your application for an account is currently pending approval. Once it has been granted, you may log in to !login_uri using the following username and password:\n\nusername: !username\npassword: !password\n\nYou may also log in by clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once.\n\nAfter logging in, you may wish to change your password at !edit_uri\n\n\n-- !site team", $variables);
case 'pass_subject':
return t('Replacement login information for !username at !site', $variables);
case 'pass_body':
return t("!username,\n\nA request to reset the password for your account has been made at !site.\n\nYou may now log in to !uri_brief clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once. It expires after one day and nothing will happen if it's not used.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.", $variables);
}
}
} // end of function newsite_user_mail_text
//******************************************************************************************************************************//
//****************************************************************************************************************************//
function newsite_insert_group($node) {
$sql = "INSERT INTO {og} (nid, theme, selective, description, website, register, directory, notification, language) VALUES (%d, '%s', %d, '%s', '%s', %d, %d, %d, '%s')";
db_query($sql, $node->nid, $node->og_theme, $node->og_selective, $node->og_description, $node->og_website, $node->og_register, $node->og_directory, $node->og_notification, $node->og_language);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function newsite_all(){
global $user;
if(!$user->uid){
$message = 'User Login....................No';
}else{
drupal_set_message(t(''));
drupal_set_message(t(''));
drupal_set_message(t(''));
drupal_set_message(t(''));
drupal_set_message(t(''));
drupal_set_message(t(''));
$result_menu = db_query('SELECT nid FROM {node} WHERE uid='.$user->uid);
$row = db_fetch_object($result_menu);
$node = node_load($row->nid);
/*$message = 'User Login........................'.$user->name;
//$links = Array();
$links = l('Post a blog entry now?', "node/add/blog/gids=".$node->nid);
$links .= l('Would you start your photo album now?', "node/add/acidfree/gids=".$node->nid);
$links .= l('Add images to your Photo Album', "node/add/image/gids=".$node->nid);
$links .= l('Post a story now', "node/add/story/gids=".$node->nid);
$links .= l('Add an entry to Calender now', "node/add/event/gids=".$node->nid);
$links .= l('update your profile', "user/$user->uid");
$links .= l('Invite other to your sites', "og/invite/".$node->nid);
$links .= l('Just Go to my site', "user/$user->uid", array('type' => MENU_LOCAL_TASK));
*/
}
//drupal_set_message(t($page_content));
//print theme('page', $links);
// $links = Array();
$links = newsite_newsite_create_links($node);
//print $links;
return theme('item_list', $links);
// $types = node_get_types();
// print theme('page', $links);
}
//function newsite_newsite_create_links($group) {
function newsite_all_forms($gid = NULL) {
$form_array = Array('0','1','2','3','4');
global $user;
$gids[]=$gid;
//$gids = $gid;
//$gids = array($gids);
$row_blog_form = Array();
if($user->uid)
$row_blog_form['uid'] = $user->uid;
else
$row_blog_form['uid'] = '0';
$group_type = 'blog';
$sql = "SELECT * from node_type where type='blog'";
$result = db_query($sql);
$row_blog_form = db_fetch_object($result);
// $form['#id'] = 'newsite_blog';
$form['#id'] = 'node-form';
$form['newsite_blog'] = array('#type' => 'fieldset',
'#title' => t('Post a blog entry now?'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#prefix' => '<div class="node-form">',
'#suffix' => '</div>',
);
$form['newsite_blog']['gid'] = array('#type' => 'hidden',
'#title' => t(''),
'#value' => $gid,
);
$form['newsite_blog'] = array_merge_recursive($form['newsite_blog'], node_invoke($row_blog_form->type, 'form', $gids));
$c = db_query(db_rewrite_sql("SELECT v.* FROM {vocabulary} v INNER JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE n.type = '%s' ORDER BY v.weight, v.name", 'v', 'vid'), $group_type);
while ($vocabulary = db_fetch_object($c)) {
if ($vocabulary->tags) {
$typed_terms = array();
foreach ($terms as $term) {
// Extract terms belonging to the vocabulary in question.
if ($term->vid == $vocabulary->vid) {
// Commas and quotes in terms are special cases, so encode 'em.
if (strpos($term->name, ',') !== FALSE || strpos($term->name, '"') !== FALSE) {
$term->name = '"'.str_replace('"', '""', $term->name).'"';
}
$typed_terms[] = $term->name;
}
}
$typed_string = implode(', ', $typed_terms) . (array_key_exists('tags', $terms) ? $terms['tags'][$vocabulary->vid] : NULL);
if ($vocabulary->help) {
$help = $vocabulary->help;
}
else {
$help = t('A comma-separated list of terms describing this content. Example: funny, bungee jumping, "Company, Inc.".');
}
$form['newsite_blog']['taxonomy']['tags'][$vocabulary->vid] = array('#type' => 'textfield',
'#title' => $vocabulary->name,
'#description' => $help,
'#required' => $vocabulary->required,
'#default_value' => $typed_string,
'#autocomplete_path' => 'taxonomy/autocomplete/'. $vocabulary->vid,
'#weight' => $vocabulary->weight,
'#maxlength' => 255,
);
}
else {
// Extract terms belonging to the vocabulary in question.
$default_terms = array();
foreach ($terms as $term) {
if ($term->vid == $vocabulary->vid) {
$default_terms[$term->tid] = $term;
}
}
$form['newsite_blog']['taxonomy'][$vocabulary->vid] = taxonomy_form($vocabulary->vid, array_keys($default_terms), $vocabulary->help);
$form['newsite_blog']['taxonomy'][$vocabulary->vid]['#weight'] = $vocabulary->weight;
$form['newsite_blog']['taxonomy'][$vocabulary->vid]['#required'] = $vocabulary->required;
}
}
if (is_array($form['newsite_blog']['taxonomy']) && !empty($form['newsite_blog']['taxonomy'])) {
if (count($form['newsite_blog']['taxonomy']) > 1) { // Add fieldset only if form has more than 1 element.
$form['newsite_blog']['taxonomy'] += array(
'#type' => 'fieldset',
'#title' => t('Categories'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
}
$form['newsite_blog']['taxonomy']['#weight'] = -3;
$form['newsite_blog']['taxonomy']['#tree'] = TRUE;
}
///////////////////////////////////////////////getting from og/////////////////////////////////
$required = variable_get('og_audience_required', 0) && !user_access('administer nodes');
if (user_access('administer nodes')) {
$options = og_all_groups_options();
}
else {
$subs = og_get_subscriptions($user->uid); //changed
foreach ($subs as $key => $val) {
$options[$key] = $val['title'];
}
}
$vis = variable_get('og_visibility', 0);
if (user_access('administer organic groups') && $vis < 2) {
$vis = $vis == OG_VISIBLE_GROUPONLY ? OG_VISIBLE_CHOOSE_PRIVATE : OG_VISIBLE_CHOOSE_PUBLIC;
}
elseif (!count($options)) {
// don't show checkbox if no subscriptions. must be public.
$vis = OG_VISIBLE_BOTH;
}
switch ($vis) {
case OG_VISIBLE_BOTH:
$form['newsite_blog']['og_public'] = array('#type' => 'value', '#value' => 1);
break;
case OG_VISIBLE_GROUPONLY:
$form['newsite_blog']['og_public'] = array('#type' => 'value', '#value' => 0);
break;
//user decides how public the post is.
case OG_VISIBLE_CHOOSE_PUBLIC:
$form['newsite_blog']['visible']['og_public'] = array('#type' => 'checkbox', '#title' => t('Public'), '#default_value' => $node->nid ? $node->og_public : 1, '#description' => t('Show this post to everyone, or only to subscribers of the groups checked above. Posts without any groups are always <em>Public</em>.'), '#weight' => 2);
break;
case OG_VISIBLE_CHOOSE_PRIVATE:
$form['newsite_blog']['visible']['og_public'] = array('#type' => 'checkbox', '#title' => t('Public'), '#default_value' => $node->nid ? $node->og_public : 0, '#description' => t('Show this post to everyone, or only to subscribers of the groups checked above. Posts without any groups are always <em>Public</em>.'), '#weight' => 2);
break;
}
$simple = !user_access('administer organic groups') && !variable_get('og_audience_checkboxes', TRUE) && count($gids);
if (count($options) == 1 && $required) {
$gids = array_keys($options);
$gid = $gids[0];
$groups = array($gid);
// also show read only mode if user has 1 option and we are in required mode
$simple = TRUE;
}
elseif ($gids) {
// populate field from the querystring if sent
$groups = $gids;
if (!user_access('administer nodes')) {
// filter out any groups where author is not a member. we cannot rely on fapi to do this when in simple mode.
$groups = array_intersect($gids, array_keys($options));
}
}
elseif ($node->nid || $node->og_groups) {
$groups = $node->og_groups;
}
else {
$groups = array();
}
if ($simple) {
// 'simple' mode. read only.
if (count($groups)) {
foreach ($groups as $gid) {
$titles[] = $options[$gid];
$item_value = implode(', ', $titles);
}
$form['newsite_blog']['visible']['og_groups_visible'] = array('#type' => 'item', '#title' => t('Audience'), '#value' => $item_value);
$assoc_groups = drupal_map_assoc($groups);
// this hidden element persists audience values during a Preview cycle. avoids errors on Preview.
$form['newsite_blog']['invisible']['og_groups_hidden'] = array('#type' => 'hidden', '#value' => serialize($assoc_groups));
// this 'value' element persists the audience value during submit process
$form['newsite_blog']['invisible']['og_groups'] = array('#type' => 'value', '#value' => $assoc_groups);
}
}
elseif ($cnt = count($options)) {
drupal_add_js(drupal_get_path('module', 'og'). '/og.js');
// show multi-select. if less than 20 choices, use checkboxes.
$type = $cnt >= 20 ? 'select' : 'checkboxes';
$form['newsite_blog']['visible']['og_groups'] = array(
'#type' => $type,
'#title' => t('Audience'),
'#attributes' => array('class' => 'og-audience'),
'#options' => $options,
'#required' => $required,
'#description' => format_plural(count($options), 'Show this post in this group.', 'Show this post in these groups.'),
'#default_value' => $gids,
'#required' => $required,
'#multiple' => TRUE);
}
else if ($required) {
form_set_error('title', t('You must !join before posting a %type.', array('!join' => l(t('join a group'), 'og'), '%type' => node_get_types('name', $node->type))));
}
if (count($form['newsite_blog']['visible']) > 1) {
$form['newsite_blog']['#type'] = 'fieldset';
$form['newsite_blog']['#title'] = t('Groups');
$form['newsite_blog']['#collapsible'] = TRUE;
$form['newsite_blog']['#collapsed'] = $gids ? TRUE : FALSE;
}
$form['newsite_blog']['author']['og_author'] = array('#type' => 'select',
'#title' => t('Author group'),
'#options' => $options,
'#required' => $required,
'#description' => t('Select the group that will be authoring this post.'),
'#required' => $required,
'#multiple' => FALSE);
$form['newsite_blog']['author']['#type'] = 'fieldset';
$form['newsite_blog']['author']['#title'] = t('Author group');
$form['newsite_blog']['author']['#collapsible'] = TRUE;
$form['newsite_blog']['author']['#weight'] = 1;
//////////////////////////////////////////////end /////////////////////////////////////////////
//////////////////////////////////////start upload module////////////////////////////////////////////////////////////////////
drupal_add_js('misc/progress.js');
drupal_add_js('misc/upload.js');
$form['newsite_blog']['attachments'] = array(
'#type' => 'fieldset',
'#access' => user_access('upload files'),
'#title' => t('File attachments'),
'#collapsible' => TRUE,
'#collapsed' => empty($node->files),
'#description' => t('Changes made to the attachments are not permanent until you save this post. The first "listed" file will be included in RSS feeds.'),
'#prefix' => '<div class="attachments">',
'#suffix' => '</div>',
'#weight' => 30,
);
// Wrapper for fieldset contents (used by upload JS).
$form['newsite_blog']['attachments']['wrapper'] = array(
'#prefix' => '<div id="attach-wrapper">',
'#suffix' => '</div>',
);
// Make sure necessary directories for upload.module exist and are
// writable before displaying the attachment form.
$path = file_directory_path();
$temp = file_directory_temp();
// Note: pass by reference
if (!file_check_directory($path, FILE_CREATE_DIRECTORY) || !file_check_directory($temp, FILE_CREATE_DIRECTORY)) {
$form['newsite_blog']['attachments']['#description'] = t('File attachments are disabled. The file directories have not been properly configured.');
if (user_access('administer site configuration')) {
drupal_set_message(t('I am in fifth if condition'));
$form['newsite_blog']['attachments']['#description'] .= ' '. t('Please visit the <a href="@admin-file-system">file system configuration page</a>.', array('@admin-file-system' => url('admin/settings/file-system')));
}
else {
$form['newsite_blog']['attachments']['#description'] .= ' '. t('Please contact the site administrator.');
}
}
else {
$form['newsite_blog']['attachments']['wrapper'] += _upload_form($node);
$form['newsite_blog']['#attributes']['enctype'] = 'multipart/form-data';
}
//////////////////////////////////////////////end /////////////////////////////////////////////
$form['newsite_blog']['Submit'] = array(
'#type' => 'submit',
'#value' => 'Submit Blog',
'#weight' => 45,
);
$form['newsite_album'] = array(
'#type' => 'fieldset',
'#title' => t('Would you start your photo album now?'),
'#weight' => 3,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#prefix' => '<div class="node-form">',
'#suffix' => '</div>',
'#tree' => TRUE,
);
$form['newsite_album']['description'] = array(
'#type' => 'textarea',
'#title' => t('Description'),
'#default_value' => $edit['description'],
'#cols' => 60,
'#rows' => 5,
);
$form['newsite_album']['Submit']= array(
'#type' => 'submit',
'#value' => 'Submit Album',
'#weight' => 45,
);
return $form;
/*
$form['newsite_album'] = array('#type' => 'fieldset',
'#title' => t('Would you like to start your photo album now?'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#prefix' => '<div class="node-form">',
'#suffix' => '</div>',
);
$options = array('1' => t('Enabled'), '0' => t('Disabled'));
$form['newsite_album']['log'] = array(
'#type' => 'radios',
'#title' => t('Log'),
'#default_value' => variable_get('log', 0),
'#options' => $options,
'#description' => t('The log.'),
);
$form['newsite_album']['Submit'] = array(
'#type' => 'submit',
'#value' => 'Submit Album',
'#weight' => 45,
);
return $form['newsite_album'];
*/
} // end of function newsite_newsite_create_links
function newsite_all_forms_submit($form_id, $form_values){
global $user;
if($user->uid)
{
$form_values['uid'] = $user->uid;
$form_values['name'] = $user->name;
$form_values['type'] = 'blog';
$form_values['grant_view'] = '1';
$form_values['comment'] = '2';
//$node = (object)$node;
node_object_prepare($node);
if (!isset($form_values['created'])) {
$form_values['created'] = time();
}
if (!isset($form_vlaues['date'])) {
$form_values['date'] = format_date($form_values['created'], 'custom', 'Y-m-d H:i:s O');
}
//node_invoke($node, 'prepare');
//node_invoke_nodeapi($node, 'prepare');
$node_options = variable_get('node_options_'. $form_values['type'], array('status', 'promote'));
if (!isset($form_values['nid'])) {
foreach (array('status', 'promote', 'sticky', 'revision') as $key) {
$form_values[$key] = in_array($key, $node_options);
}
$form_values['uid'] = $user->uid;
}
else {
// Nodes being edited should always be preset with the default revision setting.
$form_values['revision'] = in_array('revision', $node_options);
}
if (og_is_group_type($form_values['type'])) {
$form_values['comment'] = COMMENT_NODE_DISABLED;
}
// Reset to follow site default theme if user selects the site default
if ($form_values['og_theme'] == variable_get('theme_default', 'bluemarine')) {
$form_values['og_theme'] = NULL;
}
/*
// Normalize og_groups array
if (is_array($form_values['og_groups'])) {
$form_values['og_groups'] = array_filter($form_values['og_groups']);
$form_values['og_groups'] = array_keys($form_values['og_groups']);
}
*/
// start of node_form_submit//
$node = node_submit($form_values);
for($j=0; $j<count($node->og_groups); $j++){
drupal_set_message(t('May it is the value of the OG Group.........'.$node->og_groups[$j]));
}
// Prepare the node's body:
if ($node->nid) {
node_save($node);
watchdog('content', t('@type: updated %title.', array('@type' => t($node->type), '%title' => $node->title)), WATCHDOG_NOTICE, l(t('view'), 'node/'. $node->nid));
drupal_set_message(t('The %post has been updated.', array('%post' => node_get_types('name', $node))));
}
else {
node_save($node);
watchdog('content', t('@type: added %title.', array('@type' => t($node->type), '%title' => $node->title)), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid"));
drupal_set_message(t('Your %post has been created.', array('%post' => node_get_types('name', $node))));
}
// end//
//if op=insert//
if (og_is_group_type($node->type)) {
newsite_insert_group($node);
// make sure the node owner is a full powered subscriber
og_save_subscription($node->nid, $node->uid, array('is_active' => 1, 'is_admin' => 1));
$account = user_load(array('uid' => $node->uid));
$variables = array(
'@group' => $node->title,
'!group_url' => url("node/$node->nid", NULL, NULL, TRUE),
'@username' => $account->name,
'!invite_url' => url("og/invite/$node->nid", NULL, NULL, TRUE)
);
// alert the user that they are now the admin of the group
$from = variable_get('site_mail', ini_get('sendmail_from'));
drupal_mail('og_new_admin', $account->mail, _og_user_mail_text('og_new_admin_subject', $variables), _og_user_mail_text('og_new_admin_body', $variables), $from);
}
elseif (!og_is_omitted_type($node->type)) {
og_save_ancestry($node);
}
// TODO: move this to cron to help give time to fix typos, and help scaling. create new module
// implementing an SMTP library that uses cron.
if (!module_exists('og2list')) {
if ($node->status && og_node_type_notify($node->type)) {
$node->msgid = "$node->nid-0". og_msgid_server();
og_mail(node_get_types('name', $node), $node);
}
}
//drupal_goto("newsite/menu/$node->og_groups");
//drupal_goto("newsite/menu/$node->nid");
//return 'newsite/menu';
// end of op=insert //
} // end of if for user->uid
} // end of function newsite_all_forms_submit
function newsite_all_forms_validate_adfasdasdfasdf($form_id, $form_values){
global $user;
$form_values['uid'] = $user->uid;
$form_values['name'] = $user->name;
$form_values['type'] = 'blog';
node_object_prepare($node);
if (!isset($form_values['created'])) {
$form_values['created'] = time();
}
if (!isset($form_vlaues['date'])) {
$form_values['date'] = format_date($form_values['created'], 'custom', 'Y-m-d H:i:s O');
}
$node_options = variable_get('node_options_'. $form_values['type'], array('status', 'promote'));
if (!isset($form_values['nid'])) {
foreach (array('status', 'promote', 'sticky', 'revision') as $key) {
$form_values[$key] = in_array($key, $node_options);
}
$form_values['uid'] = $user->uid;
}
else {
// Nodes being edited should always be preset with the default revision setting.
$form_values['revision'] = in_array('revision', $node_options);
}
if (og_is_group_type($form_values['type'])) {
$form_values['comment'] = COMMENT_NODE_DISABLED;
}
// Reset to follow site default theme if user selects the site default
if ($form_values['og_theme'] == variable_get('theme_default', 'bluemarine')) {
$form_values['og_theme'] = NULL;
}
// Normalize og_groups array
if (is_array($form_values['og_groups'])) {
$form_values['og_groups'] = array_filter($form_values['og_groups']);
$form_values['og_groups'] = array_keys($form_values['og_groups']);
}
drupal_set_message(t('The creating time is...........'.$form_values['created']));
drupal_set_message(t('The date is...........'.$form_values['date']));
/*
drupal_set_message(t('I am here in validation function'));
drupal_set_message(t($form_values['title']));
if (is_array($form_values['og_groups'])) {
foreach ($form_values['og_groups'] as $gid) {
drupal_set_message(t($gid."<br />"));
}
}
*/
}
///////////////////////////////////////////////// Multiple instances of one Form ///////////////////////////////////////////////
/*function mymodule_view($things = array()) {
# we change our example to use an array of things which may vary from
# at any time. We use our counter $i to prefix our form id, so that
# drupal_get_form() can create a new form with a unique id.
for ($i=0; $i < count($things); $i++) {
$output = drupal_get_form("mymodule_thing_form" . $i, $things[$i]);
}
return $output;
} // end of function mymodule_view*/
function test_page($gid = NULL) {
$forms_arr = array('blog','album','story','article');
for($i=0; $i<count($forms_arr); $i++){
$output .= drupal_get_form('test_form', $forms_arr[$i], $gid);
}
return $output;
}
function test_form($cat_arr, $gids) {
global $user;
$gids = $gid;
$gids = array($gids);
$group_type = $cat_arr;
switch($cat_arr){
case "blog":
$row_blog_form = Array();
if($user->uid)
$row_blog_form['uid'] = $user->uid;
else
$row_blog_form['uid'] = '0';
$sql = "SELECT * from node_type where type='blog'";
$result = db_query($sql);
$row_blog_form = db_fetch_object($result);
$form['#id'] = 'test_form_'.$cat_arr;
$form['#base'] = 'test_form';
$form['newsite_blog'] = array('#type' => 'fieldset',
'#title' => t('Post a blog entry now?'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#prefix' => '<div class="node-form">',
'#suffix' => '</div>',
);
$form['newsite_blog']['gid'] = array('#type' => 'hidden',
'#title' => t(''),
'#value' => $gids,
);
$form['newsite_blog'] = array_merge_recursive($form['newsite_blog'], node_invoke($row_blog_form->type, 'form', $gids));
$c = db_query(db_rewrite_sql("SELECT v.* FROM {vocabulary} v INNER JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE n.type = '%s' ORDER BY v.weight, v.name", 'v', 'vid'), $group_type);
while ($vocabulary = db_fetch_object($c)) {
if ($vocabulary->tags) {
$typed_terms = array();
foreach ($terms as $term) {
// Extract terms belonging to the vocabulary in question.
if ($term->vid == $vocabulary->vid) {
// Commas and quotes in terms are special cases, so encode 'em.
if (strpos($term->name, ',') !== FALSE || strpos($term->name, '"') !== FALSE) {
$term->name = '"'.str_replace('"', '""', $term->name).'"';
}
$typed_terms[] = $term->name;
}
}
$typed_string = implode(', ', $typed_terms) . (array_key_exists('tags', $terms) ? $terms['tags'][$vocabulary->vid] : NULL);
if ($vocabulary->help) {
$help = $vocabulary->help;
}
else {
$help = t('A comma-separated list of terms describing this content. Example: funny, bungee jumping, "Company, Inc.".');
}
$form['newsite_blog']['taxonomy']['tags'][$vocabulary->vid] = array('#type' => 'textfield',
'#title' => $vocabulary->name,
'#description' => $help,
'#required' => $vocabulary->required,
'#default_value' => $typed_string,
'#autocomplete_path' => 'taxonomy/autocomplete/'. $vocabulary->vid,
'#weight' => $vocabulary->weight,
'#maxlength' => 255,
);
}
else {
// Extract terms belonging to the vocabulary in question.
$default_terms = array();
foreach ($terms as $term) {
if ($term->vid == $vocabulary->vid) {
$default_terms[$term->tid] = $term;
}
}
$form['newsite_blog']['taxonomy'][$vocabulary->vid] = taxonomy_form($vocabulary->vid, array_keys($default_terms), $vocabulary->help);
$form['newsite_blog']['taxonomy'][$vocabulary->vid]['#weight'] = $vocabulary->weight;
$form['newsite_blog']['taxonomy'][$vocabulary->vid]['#required'] = $vocabulary->required;
}
}
if (is_array($form['newsite_blog']['taxonomy']) && !empty($form['newsite_blog']['taxonomy'])) {
if (count($form['newsite_blog']['taxonomy']) > 1) { // Add fieldset only if form has more than 1 element.
$form['newsite_blog']['taxonomy'] += array(
'#type' => 'fieldset',
'#title' => t('Categories'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
}
$form['newsite_blog']['taxonomy']['#weight'] = -3;
$form['newsite_blog']['taxonomy']['#tree'] = TRUE;
}
///////////////////////////////////////////////getting from og/////////////////////////////////
$required = variable_get('og_audience_required', 0) && !user_access('administer nodes');
if (user_access('administer nodes')) {
$options = og_all_groups_options();
}
else {
$subs = og_get_subscriptions($user->uid); //changed
foreach ($subs as $key => $val) {
$options[$key] = $val['title'];
}
}
$vis = variable_get('og_visibility', 0);
if (user_access('administer organic groups') && $vis < 2) {
$vis = $vis == OG_VISIBLE_GROUPONLY ? OG_VISIBLE_CHOOSE_PRIVATE : OG_VISIBLE_CHOOSE_PUBLIC;
}
elseif (!count($options)) {
// don't show checkbox if no subscriptions. must be public.
$vis = OG_VISIBLE_BOTH;
}
switch ($vis) {
case OG_VISIBLE_BOTH:
$form['newsite_blog']['og_public'] = array('#type' => 'value', '#value' => 1);
break;
case OG_VISIBLE_GROUPONLY:
$form['newsite_blog']['og_public'] = array('#type' => 'value', '#value' => 0);
break;
//user decides how public the post is.
case OG_VISIBLE_CHOOSE_PUBLIC:
$form['newsite_blog']['visible']['og_public'] = array('#type' => 'checkbox', '#title' => t('Public'), '#default_value' => $node->nid ? $node->og_public : 1, '#description' => t('Show this post to everyone, or only to subscribers of the groups checked above. Posts without any groups are always <em>Public</em>.'), '#weight' => 2);
break;
case OG_VISIBLE_CHOOSE_PRIVATE:
$form['newsite_blog']['visible']['og_public'] = array('#type' => 'checkbox', '#title' => t('Public'), '#default_value' => $node->nid ? $node->og_public : 0, '#description' => t('Show this post to everyone, or only to subscribers of the groups checked above. Posts without any groups are always <em>Public</em>.'), '#weight' => 2);
break;
}
$simple = !user_access('administer organic groups') && !variable_get('og_audience_checkboxes', TRUE) && count($gids);
if (count($options) == 1 && $required) {
$gids = array_keys($options);
$gid = $gids[0];
$groups = array($gid);
// also show read only mode if user has 1 option and we are in required mode
$simple = TRUE;
}
elseif ($gids) {
// populate field from the querystring if sent
$groups = $gids;
if (!user_access('administer nodes')) {
// filter out any groups where author is not a member. we cannot rely on fapi to do this when in simple mode.
$groups = array_intersect($gids, array_keys($options));
}
}
elseif ($node->nid || $node->og_groups) {
$groups = $node->og_groups;
}
else {
$groups = array();
}
if ($simple) {
// 'simple' mode. read only.
if (count($groups)) {
foreach ($groups as $gid) {
$titles[] = $options[$gid];
$item_value = implode(', ', $titles);
}
$form['newsite_blog']['visible']['og_groups_visible'] = array('#type' => 'item', '#title' => t('Audience'), '#value' => $item_value);
$assoc_groups = drupal_map_assoc($groups);
// this hidden element persists audience values during a Preview cycle. avoids errors on Preview.
$form['newsite_blog']['invisible']['og_groups_hidden'] = array('#type' => 'hidden', '#value' => serialize($assoc_groups));
// this 'value' element persists the audience value during submit process
$form['newsite_blog']['invisible']['og_groups'] = array('#type' => 'value', '#value' => $assoc_groups);
}
}
elseif ($cnt = count($options)) {
drupal_add_js(drupal_get_path('module', 'og'). '/og.js');
// show multi-select. if less than 20 choices, use checkboxes.
$type = $cnt >= 20 ? 'select' : 'checkboxes';
$form['newsite_blog']['visible']['og_groups'] = array(
'#type' => $type,
'#title' => t('Audience'),
'#attributes' => array('class' => 'og-audience'),
'#options' => $options,
'#required' => $required,
'#description' => format_plural(count($options), 'Show this post in this group.', 'Show this post in these groups.'),
'#default_value' => $gids,
'#required' => $required,
'#multiple' => TRUE);
}
else if ($required) {
form_set_error('title', t('You must !join before posting a %type.', array('!join' => l(t('join a group'), 'og'), '%type' => node_get_types('name', $node->type))));
}
if (count($form['newsite_blog']['visible']) > 1) {
$form['newsite_blog']['#type'] = 'fieldset';
$form['newsite_blog']['#title'] = t('Groups');
$form['newsite_blog']['#collapsible'] = TRUE;
$form['newsite_blog']['#collapsed'] = $gids ? TRUE : FALSE;
}
$form['newsite_blog']['author']['og_author'] = array('#type' => 'select',
'#title' => t('Author group'),
'#options' => $options,
'#required' => $required,
'#description' => t('Select the group that will be authoring this post.'),
'#required' => $required,
'#multiple' => FALSE);
$form['newsite_blog']['author']['#type'] = 'fieldset';
$form['newsite_blog']['author']['#title'] = t('Author group');
$form['newsite_blog']['author']['#collapsible'] = TRUE;
$form['newsite_blog']['author']['#weight'] = 1;
//////////////////////////////////////////////end /////////////////////////////////////////////
//////////////////////////////////////start upload module////////////////////////////////////////////////////////////////////
drupal_add_js('misc/progress.js');
drupal_add_js('misc/upload.js');
$form['newsite_blog']['attachments'] = array(
'#type' => 'fieldset',
'#access' => user_access('upload files'),
'#title' => t('File attachments'),
'#collapsible' => TRUE,
'#collapsed' => empty($node->files),
'#description' => t('Changes made to the attachments are not permanent until you save this post. The first "listed" file will be included in RSS feeds.'),
'#prefix' => '<div class="attachments">',
'#suffix' => '</div>',
'#weight' => 30,
);
// Wrapper for fieldset contents (used by upload JS).
$form['newsite_blog']['attachments']['wrapper'] = array(
'#prefix' => '<div id="attach-wrapper">',
'#suffix' => '</div>',
);
// Make sure necessary directories for upload.module exist and are
// writable before displaying the attachment form.
$path = file_directory_path();
$temp = file_directory_temp();
// Note: pass by reference
if (!file_check_directory($path, FILE_CREATE_DIRECTORY) || !file_check_directory($temp, FILE_CREATE_DIRECTORY)) {
$form['newsite_blog']['attachments']['#description'] = t('File attachments are disabled. The file directories have not been properly configured.');
if (user_access('administer site configuration')) {
drupal_set_message(t('I am in fifth if condition'));
$form['newsite_blog']['attachments']['#description'] .= ' '. t('Please visit the <a href="@admin-file-system">file system configuration page</a>.', array('@admin-file-system' => url('admin/settings/file-system')));
}
else {
$form['newsite_blog']['attachments']['#description'] .= ' '. t('Please contact the site administrator.');
}
}
else {
$form['newsite_blog']['attachments']['wrapper'] += _upload_form($node);
$form['newsite_blog']['#attributes']['enctype'] = 'multipart/form-data';
}
//////////////////////////////////////////////end /////////////////////////////////////////////
$form['newsite_blog']['Submit'] = array(
'#type' => 'submit',
'#value' => 'Submit Blog',
'#weight' => 45,
);
return $form;
break;
case "album":
$form['newsite_album'] = array(
'#type' => 'fieldset',
'#title' => t('Would you start your photo album now?'),
'#weight' => 3,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#prefix' => '<div class="node-form">',
'#suffix' => '</div>',
'#tree' => TRUE,
);
$form['newsite_album']['description'] = array(
'#type' => 'textarea',
'#title' => t('Description'),
'#default_value' => $edit['description'],
'#cols' => 60,
'#rows' => 5,
);
$form['newsite_album']['Submit']= array(
'#type' => 'submit',
'#value' => 'Submit Album',
'#weight' => 45,
);
return $form;
break;
case "story":
echo "You want to create story form";
break;
case "article";
echo "you want to create article form";
break;
} //end of switch
} // end of fuction
function newsite_node_access_records($node) {
// don't write records if og access control is disabled or the node type is omitted or node is a group
// if you want group nodes to be protected too, see http://drupal.org/node/83005
if (newsite_is_omitted_type($node->type) || !variable_get('og_enabled', FALSE) || og_is_group_type($node->type)) {
return;
}
if (is_array($node->og_groups)) {
foreach ($node->og_groups as $gid) {
// we write a broad grant here but og_node_grants() only issues it selectively.
$grants[] = array('realm' => 'og_subscriber', 'gid' => $gid, 'grant_view' => 1, 'grant_update' => 1, 'grant_delete' => 1);
}
}
if ($node->og_public) {
$grants[] = array('realm' => 'og_public', 'gid' => 0, 'grant_view' => 1, 'grant_update' => 0, 'grant_delete' => 0);
}
return $grants;
} // end of fucntion newsite_node_access_records
function newsite_is_omitted_type($type) {
return in_array($type, variable_get('og_omitted', array()));
} // end of function blog_
//////////////////////////////////////////////// End //////////////////////////////////////////////////////////////////////////
I am very much thankful to you for this help..........
Thanks
CRINCH
Comments
Is there a problem
Is there a problem explaining more details. Which version of Drupal? what module? where exactly you have copied (extracted) the module files?
--
Cheers,
Sivanandhan, P. (a.k.a. apsivam)