function filter_init()
 {
     global $conf, $user;
     // Inject values into the $conf array - will apply to all sites.
     // This can be a useful place to apply generic development settings.
     $conf_inject = unserialize(urldecode(runserver_env('RUNSERVER_CONF')));
     // Merge in the injected conf, overriding existing items.
     $conf = array_merge($conf, $conf_inject);
     // Log in user if needed.
     if (isset($_GET['login'])) {
         $uid = runserver_env('RUNSERVER_USER');
         if (!empty($uid) && $user->uid !== $uid) {
             // If a user was provided, log in as this user.
             $user = user_load($uid);
             if (function_exists('drupal_session_regenerate')) {
                 // Drupal 7
                 drupal_session_regenerate();
             } else {
                 // Drupal 6
                 sess_regenerate();
             }
         }
         // Refresh the page (in case access denied has been called already).
         drupal_goto($_GET['q']);
     }
 }
function mortgagespeak_menu_link(array $variables)
{
    global $user;
    $show_purple_tooltip = 0;
    $user_info = user_load($user->uid);
    if (isset($user_info->field_show_got_it_box) && !empty($user_info->field_show_got_it_box)) {
        $show_purple_tooltip = $user_info->field_show_got_it_box['und'][0]['value'];
    }
    $sub_menu = '';
    $element = $variables['element'];
    if ($element['#below']) {
        $sub_menu = drupal_render($element['#below']);
    }
    $variables['element']['#attributes']['class'][] = 'active';
    $variables['element']['#localized_options']['attributes']['class'][] = 'active';
    $output = l($element['#title'], $element['#href'], $options = $element['#localized_options']);
    if ($show_purple_tooltip == 1) {
        if ($element['#original_link']['menu_name'] == 'main-menu' && $element['#href'] == 'my-page/tracked-news') {
            return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . "<div id='purple-tooltip' class='purple-main-container'><div class='purple-inner'><div class='purple-text'>Access your Custom News Page here.</div><div class='purple-button'>ok, Got it</div></div></div></li>\n";
        } else {
            return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
        }
    } else {
        return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
    }
}
/**
 * Changes the permission a user has on the meta tags being edited.
 *
 * @param &$permission
 *   TRUE, if the user can edit the current meta tag.
 * @param $object
 *   An array describing the object to which the meta tag are associated.
 * @param $tag_name
 *   The name of the meta tag.
 * @param $tag_info
 *   An array describing the meta tag.
 */
function hook_nodewords_tags_permission_alter(&$permission, $object, $tag_name, $tag_info)
{
    global $user;
    if (user_access('administer meta tags')) {
        $permission = TRUE;
        return;
    }
    if ($object['type'] == 'node' && ($node = node_load($options['id']))) {
        if ($user->uid == $node->uid && user_access("edit one's own node meta tags")) {
            $permission = TRUE;
            return;
        }
        if (user_access('edit any node meta tags')) {
            $permission = TRUE;
        } else {
            $permission = FALSE;
        }
    } elseif ($object['type'] == 'user' && ($account = user_load($object['id']))) {
        if ($user->uid == $account->uid && user_access("edit one's own user profile meta tags")) {
            $permission = TRUE;
            return;
        }
        if (user_access('edit any user profile meta tags')) {
            $permission = TRUE;
        } else {
            $permission = FALSE;
        }
    }
}
Exemple #4
0
 public function getLuid($account = NULL, $site = 0)
 {
     // Load user if needed...
     if (is_int($account)) {
         $account = user_load(array('uid' => $account));
     } else {
         if (!$account) {
             global $user;
             $account = $user;
         }
     }
     // Set default value for site if necessary.
     if (!$site) {
         $site = variable_get('dissue_local_site', 1);
     }
     // Fetch the local user id for the account
     $luid = db_result(db_query("SELECT luid\n      FROM {dissue_user}\n      WHERE sid = %d\n      AND uid = %d", array(':sid' => $site, ':uid' => $account->uid)));
     // Create a dissue entry for the user if it didn't have one
     if (!$luid) {
         $values = array('name' => $account->name, 'sid' => $site, 'uid' => $account->uid);
         drupal_write_record('dissue_user', $values);
         $luid = $values['luid'];
     }
     return $luid;
 }
 public function actionHome($sid, $uid)
 {
     if (user_load($uid)) {
         $voteself = taxonomy_term_load($sid);
         if ($voteself) {
             $query = new EntityFieldQuery();
             $query->entityCondition('entity_type', 'node')->fieldCondition('field_zhuanti', 'tid', $sid)->entityCondition('bundle', '_xuanxiang')->propertyCondition('status', 1)->propertyOrderBy('nid', 'DESC');
             $result = $query->execute();
             if (isset($result['node'])) {
                 $vnids = array_keys($result['node']);
                 $nodes = node_load_multiple($vnids);
             }
             //var_dump($voteself);
             $criteria = new CDbCriteria();
             $criteria->condition = 'uid=:uid AND sid=:sid';
             $criteria->params = array(':uid' => $uid, ':sid' => $sid);
             $vote = Vote::model()->findAll($criteria);
             if ($vote) {
                 $this->renderPartial('result', array('model' => $voteself, 'voteitems' => $nodes));
             } else {
                 $this->renderPartial('vote', array('model' => $voteself, 'uid' => $uid, 'voteitems' => $nodes));
             }
         }
     } else {
         $this->renderPartial('error', array('error_code' => '2', 'sid' => $sid));
     }
 }
 public function load_data($ar_data = null)
 {
     $result = array();
     $query = new EntityFieldQuery();
     $query->entityCondition('entity_type', 'node')->entityCondition('bundle', 'sito_parcheggio')->propertyCondition('status', 1)->addMetaData('account', user_load(1));
     $qryres = $query->execute();
     if (isset($qryres['node'])) {
         $items_nids = array_keys($qryres['node']);
         $items = entity_load('node', $items_nids);
         $first = true;
         foreach ($items as $nodo => $elem) {
             if ($first) {
                 $result[0]['codice'] = 0;
                 $result[0]['descrizione'] = 'Selezionare un parcheggio';
                 $first = false;
             }
             $result[$nodo]['codice'] = $elem->field_sp_codice[LANGUAGE_NONE][0]['value'];
             $result[$nodo]['descrizione'] = $elem->title;
             $result[$nodo]['indirizzo']['indirizzo'] = $elem->field_sp_indirizzo[LANGUAGE_NONE][0]['thoroughfare'];
             $result[$nodo]['indirizzo']['cap'] = $elem->field_sp_indirizzo[LANGUAGE_NONE][0]['postal_code'];
             $result[$nodo]['indirizzo']['localita'] = $elem->field_sp_indirizzo[LANGUAGE_NONE][0]['locality'];
             $result[$nodo]['indirizzo']['provincia'] = $elem->field_sp_indirizzo[LANGUAGE_NONE][0]['administrative_area'];
         }
     }
     $this->ar_lista = $result;
 }
 /**
  * Override parent deliver() function.
  */
 public function deliver(array $output = array())
 {
     $plugin = $this->plugin;
     $message = $this->message;
     $options = $plugin['options'];
     $account = user_load($message->uid);
     $mail = !empty($options['mail']) ? $options['mail'] : $account->mail;
     $languages = language_list();
     if (!$options['language override']) {
         $lang = !empty($account->language) && $account->language != LANGUAGE_NONE ? $languages[$account->language] : language_default();
     } else {
         $lang = $languages[$message->language];
     }
     // The subject in an email can't be with HTML, so strip it.
     $output['message_notify_email_subject'] = strip_tags($output['message_notify_email_subject']);
     // Allow for overriding the 'from' of the message.
     $from = isset($options['from']) ? $options['from'] : NULL;
     $from_account = !empty($message->user->uid) ? user_load($message->user->uid) : $account;
     $mimemail_name = variable_get('mimemail_name', t('Atrium'));
     $from = array('name' => oa_core_realname($from_account) . ' (' . $mimemail_name . ')', 'mail' => is_array($from) ? $from['mail'] : $from);
     // Pass the message entity along to hook_drupal_mail().
     $output['message_entity'] = $message;
     if (!empty($message->email_attachments)) {
         $output['attachments'] = isset($output['attachments']) ? $output['attachments'] : array();
         $output['attachments'] = array_merge($message->email_attachments, $output['attachments']);
     }
     return drupal_mail('message_notify', $message->type, $mail, $lang, $output, $from);
 }
function _bbcom_subscribe_to_thread($uid, $nid)
{
    $account = user_load($uid);
    $subscription = array('type' => 'thread', 'uid' => $uid, 'fields' => array('nid' => $nid), 'send_method' => notifications_user_setting('send_method', $account), 'send_interval' => notifications_user_setting('send_interval', $account), 'event_type' => 'node');
    $subscription = notifications_build_subscription($subscription);
    $ret = notifications_save_subscription($subscription);
}
function _scratchpadify_install_configure_form_submit($form, &$form_state)
{
    global $user;
    variable_set('site_name', $form_state['values']['site_name']);
    variable_set('site_mail', $form_state['values']['site_mail']);
    variable_set('date_default_timezone', $form_state['values']['date_default_timezone']);
    // Enable update.module if this option was selected.
    if ($form_state['values']['update_status_module'][1]) {
        // Stop enabling the update module, it's a right royal pain in the arse.
        //drupal_install_modules(array('update'));
    }
    // Turn this off temporarily so that we can pass a password through.
    variable_set('user_email_verification', FALSE);
    $form_state['old_values'] = $form_state['values'];
    $form_state['values'] = $form_state['values']['account'];
    // We precreated user 1 with placeholder values. Let's save the real values.
    $account = user_load(1);
    $merge_data = array('init' => $form_state['values']['mail'], 'roles' => array(), 'status' => 0);
    user_save($account, array_merge($form_state['values'], $merge_data));
    // Log in the first user.
    user_authenticate($form_state['values']);
    $form_state['values'] = $form_state['old_values'];
    unset($form_state['old_values']);
    variable_set('user_email_verification', TRUE);
    if (isset($form_state['values']['clean_url'])) {
        variable_set('clean_url', $form_state['values']['clean_url']);
    }
    // The user is now logged in, but has no session ID yet, which
    // would be required later in the request, so remember it.
    $user->sid = session_id();
    // Record when this install ran.
    variable_set('install_time', time());
}
  /**
   * Implements RestfulAuthenticationInterface::authenticate().
   */
  public function authenticate(array $request = array(), $method = \RestfulInterface::GET) {
    if (!drupal_session_started() && !$this->isCli()) {
      return;
    }

    global $user;
    $account = user_load($user->uid);

    if (!\RestfulBase::isWriteMethod($method) || empty($request['__application']['rest_call'])) {
      // Request is done via API not CURL, or not a write operation, so we don't
      // need to check for a CSRF token.
      return $account;
    }

    if (empty($request['__application']['csrf_token'])) {
      throw new \RestfulBadRequestException('No CSRF token passed in the HTTP header.');
    }

    if (!drupal_valid_token($request['__application']['csrf_token'], \RestfulBase::TOKEN_VALUE)) {
      throw new \RestfulForbiddenException('CSRF token validation failed.');
    }

    // CSRF validation passed.
    return $account;
  }
/**
 * Try to authenticate the user using any method
 * At the moment there is only one method available: 'password'
 *
 * @param GuifiAPI $gapi GuifiAPI object
 * @param $parameters Parameters to login
 * @return boolean Whether the user authenticated or not
 */
function guifi_api_auth_login($gapi, $parameters)
{
    global $user;
    //  if (!guifi_api_check_fields($gapi, array('method' ), $parameters)) {
    //    return FALSE;
    //  }
    if (!empty($parameters['method'])) {
        $method = $parameters['method'];
    } else {
        $method = 'password';
    }
    switch ($method) {
        case 'password':
            if (!guifi_api_check_fields($gapi, array('username', 'password'), $parameters)) {
                return FALSE;
            }
            $account = user_load(array('name' => $parameters['username'], 'pass' => trim($parameters['password']), 'status' => 1));
            if ($account->uid) {
                $user = $account;
                $time = time();
                $rand_key = rand(100000, 999999);
                $token = base64_encode($user->uid . ':' . md5($user->mail . $user->pass . $user->created . $user->uid . $time . $rand_key) . ':' . $time);
                db_query("DELETE FROM {guifi_api_tokens} WHERE uid = %d", $user->uid);
                db_query("INSERT INTO {guifi_api_tokens} (uid, token, created, rand_key) VALUES (%d, '%s', FROM_UNIXTIME(%d), %d)", $user->uid, $token, $time, $rand_key);
                $gapi->addResponseField('authToken', $token);
                return TRUE;
            } else {
                $gapi->addError(403, "Either the supplied username or password are not correct");
                return FALSE;
            }
            break;
    }
    return FALSE;
}
 /**
  * Create a new session or update an open session.
  */
 public function createOrUpdateWorkSession()
 {
     $request = $this->getRequest();
     $account = $this->getAccount();
     if (!user_access('timewatch punch')) {
         throw new RestfulForbiddenException('No punch access.');
     }
     if (empty($request['pincode'])) {
         throw new \RestfulBadRequestException('Pincode is required');
     }
     $uid = timewatch_session_get_uid_by_pincode($request['pincode']);
     if (!$uid) {
         throw new \RestfulBadRequestException('Wrong pincode');
     }
     $employee_account = user_load($uid);
     // Find an existing session with no end date.
     $query = new EntityFieldQuery();
     $result = $query->entityCondition('entity_type', 'node')->entityCondition('bundle', 'work_session')->propertyCondition('status', NODE_PUBLISHED)->fieldCondition('field_employee', 'target_id', $uid)->fieldCondition('field_session_date', 'value2', NULL)->range(0, 1)->execute();
     if (empty($result['node'])) {
         // When there's no open session, create a new one.
         $values = array('type' => 'work_session', 'uid' => $account->uid, 'status' => NODE_PUBLISHED, 'title' => format_string('@date - @user', array('@date' => date('d/m/y'), '@user' => $employee_account->name)));
         $node = entity_create('node', $values);
         $wrapper = entity_metadata_wrapper('node', $node);
         $wrapper->field_employee->set($uid);
         $wrapper->field_session_date->value->set(REQUEST_TIME);
     } else {
         // Otherwise set the end date of the open session.
         $wrapper = entity_metadata_wrapper('node', key($result['node']));
         $wrapper->field_session_date->value2->set(REQUEST_TIME);
     }
     $wrapper->save();
     return $this->viewEntity($wrapper->getIdentifier());
 }
 private function loadConvenzioneFromTarga($ar_data)
 {
     $query = new EntityFieldQuery();
     $query->entityCondition('entity_type', 'node')->entityCondition('bundle', 'parkauto')->propertyCondition('status', 1)->fieldCondition('field_p_targa_auto_cliente', 'value', trim($ar_data['rc_targa_auto_cliente']), '=')->fieldCondition('field_p_sito_parking', 'nid', trim($ar_data['sito']))->range(0, 1)->addMetaData('account', user_load(1));
     $qryres = $query->execute();
     return $qryres;
 }
Exemple #14
0
function custom_export_download_answers_form_submit()
{
    $select = db_select('quiz_short_answer_user_answers', 'qsa');
    $select->addJoin('inner', 'node', 'node', 'node.nid = qsa.question_nid and node.vid = qsa.question_vid');
    $select->addJoin('inner', 'quiz_node_results_answers', 'qnr', 'qnr.result_id = qsa.result_id and qnr.question_nid = qsa.question_nid and qnr.question_vid = qsa.question_vid');
    $select->addJoin('inner', 'users', 'users', 'qnr.uid = users.uid');
    $select->addField('qsa', 'answer');
    $select->addField('node', 'title');
    $select->addField('users', 'name');
    $select->addField('users', 'uid');
    $select->orderBy('qnr.result_id', 'desc');
    $res = $select->execute();
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header('Content-Description: File Transfer');
    header("Content-type: text/csv; charset=utf-8");
    header("Content-Disposition: attachment; filename=quiz_answers.csv");
    header("Expires: 0");
    header("Pragma: public");
    $fh = @fopen('php://output', 'w');
    //write the header row.
    //name	password	email	phone	ean code
    fputcsv($fh, array('answer', 'question', 'name', 'uid', 'eancode', 'store name'));
    while ($row = $res->fetchObject()) {
        if ($eancode = _custom_get_eancode_from_account(user_load($row->uid))) {
            if ($pos_node = _custom_get_node_by_eancode($eancode)) {
                $pos_name = $pos_node->title;
                fputcsv($fh, array($row->answer, $row->title, $row->name, $row->uid, $eancode, $pos_name));
            }
        }
    }
    // Close the file
    fclose($fh);
    // Make sure nothing else is sent, our file is done
    exit;
}
 /**
  * {@inheritdoc}
  */
 public function authenticate(RequestInterface $request)
 {
     // Access token may be on the request, or in the headers.
     if (!($token = $this->extractToken($request))) {
         return NULL;
     }
     // Check if there is a token that has not expired yet.
     $query = new \EntityFieldQuery();
     $result = $query->entityCondition('entity_type', 'restful_token_auth')->entityCondition('bundle', 'access_token')->propertyCondition('token', $token)->range(0, 1)->execute();
     if (empty($result['restful_token_auth'])) {
         // No token exists.
         return NULL;
     }
     $id = key($result['restful_token_auth']);
     $auth_token = entity_load_single('restful_token_auth', $id);
     if (!empty($auth_token->expire) && $auth_token->expire < REQUEST_TIME) {
         // Token is expired.
         if (variable_get('restful_token_auth_delete_expired_tokens', TRUE)) {
             // Token has expired, so we can delete this token.
             $auth_token->delete();
         }
         return NULL;
     }
     return user_load($auth_token->uid);
 }
/**
 * Prepare variables for the drawer layout template file.
 */
function template_preprocess_layout__double_fixed_inner_rev(&$variables)
{
    if ($variables['content']['sidebar'] && $variables['content']['drawer']) {
        $variables['classes'][] = 'layout-both-sidebars';
    } elseif ($variables['content']['sidebar'] || $variables['content']['drawer']) {
        $variables['classes'][] = 'layout-one-sidebar';
        if ($variables['content']['sidebar']) {
            $variables['classes'][] = 'layout-has-sidebar';
        } else {
            $variables['classes'][] = 'layout-has-drawer';
        }
    } else {
        $variables['classes'][] = 'layout-no-sidebars';
    }
    // Special handling for header image.
    $variables['main_attributes'] = array('class' => array('l-content'));
    if (arg(0) == 'user' && is_numeric(arg(1)) && !arg(2)) {
        // We are on the user profile page.
        $variables['main_attributes']['class'][] = 'account-page';
        // Check to see if there is a profile image.
        $account = user_load(arg(1));
        // Entity cache should save us here?
        if (isset($account->field_header_photo[LANGUAGE_NONE][0]['uri'])) {
            // Generate an image at the correct size.
            $image = image_style_url('header', $account->field_header_photo[LANGUAGE_NONE][0]['uri']);
            $variables['main_attributes']['style'] = 'background-image: url(' . $image . ')';
            // Add an addidional class.
            $variables['main_attributes']['class'][] = 'has-background';
        }
    }
}
Exemple #17
0
 /**
  * (non-PHPdoc)
  * @see Entity::_constructDependencies()
  */
 protected function _constructDependencies($node)
 {
     // Dependency on content type.
     $this->addDependency('content', $node->type);
     // Dependency on user, only if exists.
     if ($node->uid && ($user = user_load($node->uid))) {
         $user_uuid = $this->addDependency('user', $user->uid);
         $this->setData('user', $user_uuid);
     }
     // Dependency on terms.
     $terms = array();
     foreach ($node->taxonomy as $term) {
         $term_uuid = $this->addDependency('term', $term->tid);
         $terms[] = $term_uuid;
     }
     $this->setData('terms', $terms);
     // Handle node reference fields.
     $nodes = array();
     foreach ($node as $field_name => &$value) {
         if (substr($field_name, 0, 6) == 'field_' && isset($value[0]['nid'])) {
             $nodes[$field_name] = array();
             foreach ($value as $index => $referenced) {
                 if (!empty($referenced['nid'])) {
                     $node_uuid = $this->addDependency('node', $referenced['nid']);
                     $nodes[$field_name][$index] = $node_uuid;
                 }
             }
         }
     }
     $this->setData('nodes', $nodes);
     // TODO handle file and media fields, for this, we need abstract file
     // fetching through our entity parser.
 }
 /**
  * {@inheritdoc}
  */
 public static function getNodeGrants($account = NULL, $op = 'view')
 {
     if (empty($account)) {
         global $user;
         $account = user_load($user->uid);
     }
     if (!$account->uid) {
         // Anonymous user.
         return array();
     }
     if ($op != 'view') {
         // Not a view operation.
         return array();
     }
     $realms = array();
     $domain = explode('@', $account->mail);
     $query = db_select('node', 'n');
     $query->join('field_data_c4m_domain', 'd', 'd.entity_id = n.nid');
     $query->condition('n.status', 1, '=')->condition('n.type', 'organisation', '=')->condition('d.c4m_domain_domain', $domain[1]);
     $query->fields('n', array('title', 'nid'));
     $organisations = $query->execute()->fetchAll();
     foreach ($organisations as $organisation) {
         // The "realm" name is the plugin name.
         // The "gid" is always 1, as it just indicates the user has the email
         // domain.
         $realm = 'organisation::' . $organisation->nid;
         $realms[$realm] = array(1);
     }
     return $realms;
 }
/**
 * Format submitted by in articles
 */
function simpleclean_preprocess_node(&$vars)
{
    $node = $vars['node'];
    $vars['date'] = format_date($node->created, 'custom', 'd M Y');
    if (variable_get('node_submitted_' . $node->type, TRUE)) {
        $vars['display_submitted'] = TRUE;
        $vars['submitted'] = t('By @username on !datetime', array('@username' => strip_tags(theme('username', array('account' => $node))), '!datetime' => $vars['date']));
        $vars['user_picture'] = theme_get_setting('toggle_node_user_picture') ? theme('user_picture', array('account' => $node)) : '';
        // Add a footer for post
        $account = user_load($vars['node']->uid);
        $vars['simpleclean_postfooter'] = '';
        if (!empty($account->signature)) {
            $postfooter = "<div class='post-footer'>" . $vars['user_picture'] . "<h3>" . check_plain(format_username($account)) . "</h3>";
            $cleansignature = strip_tags($account->signature);
            $postfooter .= "<p>" . check_plain($cleansignature) . "</p>";
            $postfooter .= "</div>";
            $vars['simpleclean_postfooter'] = $postfooter;
        }
    } else {
        $vars['display_submitted'] = FALSE;
        $vars['submitted'] = '';
        $vars['user_picture'] = '';
    }
    // Remove Add new comment from teasers on frontpage
    if ($vars['is_front']) {
        unset($vars['content']['links']['comment']['#links']['comment-add']);
        unset($vars['content']['links']['comment']['#links']['comment_forbidden']);
    }
}
Exemple #20
0
function banner_status($uid = 0, $profile = NULL)
{
    // User account banner status
    if (!$profile && !$uid) {
        global $user;
    }
    if ($uid) {
        $user = user_load($uid);
    }
    if ($profile) {
        $user = user_load($profile->uid);
    }
    $max = array('BA49' => 49, 'BA75' => 75, 'BA100' => 100, 'BAINF' => 10000);
    $umax = 0;
    foreach ($max as $key => $val) {
        if (in_array($key, array_values($user->roles))) {
            $umax = $val;
        }
    }
    $r = db_query("select distinct `nid`, `status` from node where uid = :uid and `type` = 'banner_ad'", array(":uid" => $user->uid));
    $pub = 0;
    $unPub = 0;
    while ($obj = $r->fetchObject()) {
        if ($obj->status == 1) {
            $pub++;
        } else {
            $unPub++;
        }
    }
    return array('max' => $umax, 'published' => $pub, 'unpublished' => $unPub, 'balance' => $umax - $pub);
}
 public function authenticate(&$message, $mailbox)
 {
     // Check and parse messageid for parameters.  URL will be encoded.
     $force_user_lookup = FALSE;
     $identifier = _mailcomment_get_signature(rawurldecode($message['body_html']));
     // Failed to find signature in body -- replicate mailhandler functionality to find node->threading
     if (!$identifier) {
         if (!empty($message['header']->references)) {
             // we want the final element in references header, watching out for white space
             $identifier = drupal_substr(strrchr($message['header']->references, '<'), 0);
         } elseif (!empty($message['header']->in_reply_to)) {
             // Some MUAs send more info in this header.
             $identifier = str_replace(strstr($message['header']->in_reply_to, '>'), '>', $message['header']->in_reply_to);
         }
         if (isset($identifier)) {
             $identifier = rtrim(ltrim($identifier, '<'), '>');
             $force_user_lookup = TRUE;
         }
     }
     $params = mailcomment_check_messageparams($identifier);
     if ($force_user_lookup) {
         // get uid from email address because we are using the header information to load the params
         // these contain the uid of the person who's post you are responding to
         $sender = $message['header']->from[0]->mailbox . '@' . $message['header']->from[0]->host;
         $params['uid'] = user_load(array('mail' => $sender))->uid;
     }
     if ($params['uid']) {
         $account = user_load($params['uid']);
         $message['authenticated_uid'] = $account->uid;
     } else {
         $message['authenticated_uid'] = 0;
     }
 }
Exemple #22
0
/**
 * Allows overriding of the selected entity list for cloning.
 *
 * @param $ids
 *   An array of entity ids currently selected.
 * @return
 *   An array of entity ids after processing.
 */
function hook_get_group_content_ids_alter(&$ids)
{
    // array of content types to remove from cloning
    $content_types = array('cle_submission');
    // pull out nodes for testing as this could have other entities
    foreach ($ids as $key => $id) {
        if ($id['entity_type'] == 'node') {
            $id_key[$key] = $id['etid'];
        }
    }
    // Don't allow submissions to be cloned
    $query = new EntityFieldQuery();
    // select all nodes
    $query->entityCondition('entity_type', 'node')->entityCondition('bundle', $content_types, 'IN')->propertyCondition('nid', $id_key, 'IN')->addMetaData('account', user_load(1));
    $result = $query->execute();
    // verify that we have results
    if (isset($result['node'])) {
        // test the node array against the nodes in the clone array
        foreach ($result['node'] as $node) {
            // if the node selected is in the array, remove it from the ids
            if (in_array($node->nid, $id_key)) {
                unset($ids[array_search($node->nid, $id_key)]);
            }
        }
    }
}
Exemple #23
0
 /**
  * {@inheritdoc}
  */
 public function nodeCreate($node)
 {
     $current_path = getcwd();
     chdir(DRUPAL_ROOT);
     // Set original if not set.
     if (!isset($node->original)) {
         $node->original = clone $node;
     }
     // Assign authorship if none exists and `author` is passed.
     if (!isset($node->uid) && !empty($node->author) && ($user = user_load(array('name' => $node->author)))) {
         $node->uid = $user->uid;
     }
     // Convert properties to expected structure.
     $this->expandEntityProperties($node);
     // Attempt to decipher any fields that may be specified.
     $this->expandEntityFields('node', $node);
     // Set defaults that haven't already been set.
     $defaults = clone $node;
     module_load_include('inc', 'node', 'node.pages');
     node_object_prepare($defaults);
     $node = (object) array_merge((array) $defaults, (array) $node);
     node_save($node);
     chdir($current_path);
     return $node;
 }
 /**
  * Tests contact link.
  */
 public function testContactLink()
 {
     $accounts = array();
     $accounts['root'] = user_load(1);
     // Create an account with access to all contact pages.
     $admin_account = $this->drupalCreateUser(array('administer users'));
     $accounts['admin'] = $admin_account;
     // Create an account with no access to contact pages.
     $no_contact_account = $this->drupalCreateUser();
     $accounts['no_contact'] = $no_contact_account;
     // Create an account with access to contact pages.
     $contact_account = $this->drupalCreateUser(array('access user contact forms'));
     $accounts['contact'] = $contact_account;
     $this->drupalLogin($admin_account);
     $this->drupalGet('test-contact-link');
     // The admin user has access to all contact links beside his own.
     $this->assertContactLinks($accounts, array('root', 'no_contact', 'contact'));
     $this->drupalLogin($no_contact_account);
     $this->drupalGet('test-contact-link');
     // Ensure that the user without the permission doesn't see any link.
     $this->assertContactLinks($accounts, array());
     $this->drupalLogin($contact_account);
     $this->drupalGet('test-contact-link');
     $this->assertContactLinks($accounts, array('root', 'admin', 'no_contact'));
     // Disable contact link for no_contact.
     $this->userData->set('contact', $no_contact_account->id(), 'enabled', FALSE);
     $this->drupalGet('test-contact-link');
     $this->assertContactLinks($accounts, array('root', 'admin'));
 }
Exemple #25
0
/**
 * Returns a formatted list of recent comments to be displayed in the comment block.
 *
 * @return
 *   The comment list HTML.
 * @ingroup themeable
 */
function mies_comment_block()
{
    $items = array();
    $output = "<table>";
    foreach (comment_get_recent(15) as $comment) {
        //print_r($comment);
        $fullComment = _comment_load($comment->cid);
        //print_r($fullComment);
        if ($fullComment->uid != "0") {
            $user = user_load($fullComment->uid);
            $username = $user->name;
        } else {
            $username = $fullComment->name;
        }
        $output .= "<tr>";
        $output .= "<td class='first-row'>";
        $output .= $username;
        $output .= "</td>";
        $output .= "<td class='second-row'>";
        $output .= l($comment->subject, 'node/' . $comment->nid, array('fragment' => 'comment-' . $comment->cid));
        $output .= "</td>";
        $output .= "<td class='third-row'>";
        //$output .= format_date($comment->timestamp, "large");
        $output .= "</td>";
        $output .= "</tr>";
    }
    $output .= "</table>";
    return $output;
}
 public function build($form, &$form_state)
 {
     // Get the remote.
     $remote = $this->getRemote($form_state);
     // Check to see if we have an entity.
     $entity = null;
     if (!empty($form_state['build_info']['args'][1]) && $form_state['build_info']['args'][1] instanceof Entity) {
         $entity = $form_state['build_info']['args'][1];
     }
     // Set a flag for admin functionality.
     $admin = user_access('send with publisher');
     // Prepare the header for the table.
     $header = array('entity_type' => array('data' => t('Entity Type'), 'field' => 't.entity_type'), 'title' => array('data' => t('Title'), 'field' => 'n.title'), 'uuid' => t('UUID'), 'vuuid' => t('Revision'), 'changed' => array('data' => t('Changed'), 'field' => 't.changed', 'sort' => 'desc'), 'user' => array('data' => t('User'), 'field' => 'u.name'), 'date_synced' => array('data' => t('Date Synced'), 'field' => 't.date_synced'));
     // Get the statuses based on whether or not an entity was supplied.
     $statuses = $this->getStatuses($header, $remote, $entity);
     // Prepare the options.
     $options = array();
     foreach ($statuses as $status) {
         $option = array('entity_type' => check_plain($status->entity_type), 'uuid' => check_plain($status->uuid), 'vuuid' => check_plain($status->vuuid), 'changed' => format_date($status->changed), 'date_synced' => 'Not Synced', 'user' => theme('username', array('account' => user_load($status->uid), 'uid' => $status->uid)));
         if (isset($status->date_sent) && $status->date_sent) {
             $option['date_synced'] = format_date($status->date_sent);
         }
         if ($status->title && $status->nid) {
             $option['title'] = array('data' => array('#type' => 'link', '#title' => $status->title, '#href' => 'node/' . $status->nid));
         } else {
             $option['title'] = '';
         }
         // Get the class based on the status.
         $status_status = 'ok';
         if (!$status->date_synced) {
             $status_status = 'warning';
         }
         if ($admin) {
             $options[$status->id] = $option;
             $options[$status->id]['#attributes'] = array('class' => array($status_status));
             if ($status_status == 'ok') {
                 $options[$status->id]['#disabled'] = true;
             }
         } else {
             $options[] = array('data' => array($option['entity_type'], $option['title'], $option['uuid'], $option['vuuid'], $option['changed'], $option['user'], $option['date_synced']), 'class' => array($status_status));
         }
     }
     // Add the overview message and the clear all button.
     if ($admin && count($options) > 0) {
         $form['send_all'] = array('#type' => 'fieldset', '#title' => t('Overview'), 'message' => array('#markup' => format_string('<p>There are currently <strong>!count</strong> ' . 'pending entities to be sent to %remote.</p>', array('!count' => count($options), '%remote' => $remote->label))), 'send_all' => array('#type' => 'submit', '#value' => t('Send all !count entities to @remote', array('@remote' => $remote->label, '!count' => count($options)))));
     }
     // Now, start building out the table.
     if ($admin) {
         $form['statuses'] = array('#type' => 'tableselect', '#header' => $header, '#options' => $options, '#empty' => t('There are currently no pending changes.'));
     } else {
         $form['statuses'] = array('#theme' => 'table', '#header' => array_values($header), '#rows' => $options, '#empty' => t('There are currently no pending changes.'));
     }
     // Add the send selected button.
     if ($admin && count($options) > 0) {
         $form['actions'] = array('#type' => 'actions');
         $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Send selected entities to @remote', array('@remote' => $remote->label)));
     }
     return $form;
 }
 protected function getHeader($destination) {
     if (count($destination) > 1) {
         return "Dear users,\n\n";
     } else {
         $account = user_load($destination[0]);
         return "Dear " . $account->fullname . ",\n\n";
     }
 }
 public function postAuthenticate() {
     $consumer = $this->getIdentity();
     if (isset($consumer)) {
         global $user;
         $user = user_load($consumer->uid);
         user_login_finalize();
     }
 }
Exemple #29
0
 /**
  * Construct
  *
  * Creates a new User object.
  *
  * @param integer $uid The UID for the user.
  */
 public function __construct($uid)
 {
     $user = user_load($uid);
     if (!$user) {
         throw new \Exception("The user ({$uid}) doesn't exist!");
     }
     $this->base = $user;
 }
 /**
  * Log the user in.
  *
  * @param object $account
  *   The user object that was retrieved by the AuthenticationManager.
  */
 public function loginUser($account)
 {
     global $user;
     // Override the global user.
     $user = user_load($account->uid);
     $login_array = array('name' => $account->name);
     user_login_finalize($login_array);
 }