/** * Gets the filpath provided a file object. * * @param type $file * @return type */ private function getPath($file) { // If the url is set, then just return it. if (!empty($file->url)) { return $file->url; } // If the path is set, then just return it. if (!empty($file->path)) { // Check to see if this is a URI. if (file_valid_uri($file->path)) { return file_create_url($file->path); } else { return $file->path; } } // If the uri is set, then just return it. if (!empty($file->uri)) { if (preg_match('/^http(s)?\\:\\/\\//', $file->uri)) { return $file->uri; } else { return file_create_url($file->uri); } } // If the value is set, then just return it. if (!empty($file->value)) { return $file->value; } // If the value is input, then just return it. if (!empty($file->input)) { return $file->input; } // Return nothing. return ''; }
/** * Implements theme_preprocess_page(). */ function townsquare_bootstrap_preprocess_page(&$vars) { global $user; $vars['primary_local_tasks'] = menu_primary_local_tasks(); $vars['secondary_local_tasks'] = menu_secondary_local_tasks(); // The following menu stuff is lame foreach ($vars['main_menu'] as $item => $options) { $vars['main_menu'][$item]['html'] = TRUE; $vars['main_menu'][$item]['attributes']['id'] = 'menu-link-' . drupal_clean_css_identifier($options['href']); } $admin_menu = menu_tree_all_data('management'); $children = array_pop($admin_menu); if ($children) { foreach ($children['below'] as $key => $value) { $children['below'][$key]['below'] = array(); } $vars['admin_menu'] = menu_tree_output($children['below']); } // Add user picture if logged in if ($user->uid) { $vars['user_name'] = check_plain($user->name); if (!empty($user->picture)) { if (is_numeric($user->picture)) { $user->picture = file_load($user->picture); } if (!empty($user->picture->uri)) { $filepath = $user->picture->uri; } } elseif (variable_get('user_picture_default', '')) { $filepath = variable_get('user_picture_default', ''); } if (isset($filepath)) { $alt = t("@user's picture", array('@user' => format_username($user))); if (module_exists('image') && file_valid_uri($filepath) && ($style = variable_get('user_picture_style', ''))) { $vars['user_picture'] = theme('image_style', array('style_name' => $style, 'path' => $filepath, 'alt' => $alt, 'title' => $alt)); } else { $vars['user_picture'] = theme('image', array('path' => $filepath, 'alt' => $alt, 'title' => $alt)); } } else { $vars['user_picture'] = '<i class="icon-user"></i>'; } } else { unset($vars['secondary_menu']); $vars['login'] = drupal_get_form('user_login_block'); } // Add Bootstrap $path = libraries_get_path('bootstrap'); drupal_add_css($path . '/css/bootstrap.css'); drupal_add_css($path . '/css/bootstrap-responsive.css'); drupal_add_js($path . '/js/bootstrap.js'); $path = libraries_get_path('font-awesome'); drupal_add_css($path . '/css/font-awesome.css'); }
/** * Implements hook_preprocess_node(). */ function alpha_preprocess_node(&$variables) { $node = $variables['elements']['#node']; if ($variables['teaser'] && $variables['type'] != 'organization' && $variables['type'] != 'simple_event') { // Add a new item into the theme_hook_suggestions array. $variables['theme_hook_suggestions'][] = 'node__teaser'; } if ($variables['view_mode'] == 'alttracker') { $variables['theme_hook_suggestions'][] = 'node__alttracker'; } $variables['timeago'] = t('@time ago', array('@time' => format_interval(time() - $node->changed))); $picture = $node->picture; if (!empty($picture)) { if (is_numeric($picture)) { $picture = file_load($picture); } if (!empty($picture->uri)) { $filepath = $picture->uri; } } elseif (variable_get('user_picture_default', '')) { $filepath = variable_get('user_picture_default', ''); } if (isset($filepath)) { $alt = $node->name; if (module_exists('image') && file_valid_uri($filepath) && ($style = variable_get('user_picture_style_node', ''))) { $variables['user_picture'] = theme('image_style', array('style_name' => $style, 'path' => $filepath, 'alt' => $alt, 'title' => $alt, 'attributes' => array('class' => array('img-circle')))); } else { $variables['user_picture'] = theme('image', array('path' => $filepath, 'alt' => $alt, 'title' => $alt, 'attributes' => array('class' => array('img-circle')))); } if (!empty($node->uid) && user_access('access user profiles')) { $attributes = array('attributes' => array('title' => t('View user profile.')), 'html' => TRUE); $variables['user_picture'] = l($variables['user_picture'], "user/{$node->uid}", $attributes); } } $variables['title_attributes'] = 'title'; if (!$variables['teaser']) { drupal_add_js(drupal_get_path('theme', 'alpha') . '/js/' . 'node-view.js'); } drupal_add_js(drupal_get_path('theme', 'alpha') . '/js/' . 'node-img-responsive.js'); // Delete Log in links from nodes. if (isset($variables['elements']['links']['comment']['#links']['comment_forbidden'])) { unset($variables['elements']['links']['comment']['#links']['comment_forbidden']); } if (isset($variables['content']['links']['comment']['#links']['comment_forbidden'])) { unset($variables['content']['links']['comment']['#links']['comment_forbidden']); } if (!empty($node->terms)) { $terms_links = array(); foreach ($node->terms as $term) { $terms_links[] = array('title' => check_plain($term->name), 'href' => url("taxonomy/term/" . $term->tid), 'html' => TRUE); } $variables['term'] = theme('links', array('links' => $terms_links)); } }
/** * Implements hook_preprocess_node(). */ function alpha_preprocess_node(&$variables) { $node = $variables['elements']['#node']; if ($variables['teaser']) { // Add a new item into the theme_hook_suggestions array. $variables['theme_hook_suggestions'][] = 'node__teaser'; } if ($variables['view_mode'] == 'alttracker') { $variables['theme_hook_suggestions'][] = 'node__alttracker'; } $variables['timeago'] = t('@time ago', array('@time' => format_interval(time() - $node->changed))); $picture = $node->picture; if (!empty($picture)) { if (is_numeric($picture)) { $picture = file_load($picture); } if (!empty($picture->uri)) { $filepath = $picture->uri; } } elseif (variable_get('user_picture_default', '')) { $filepath = variable_get('user_picture_default', ''); } if (isset($filepath)) { $alt = $node->name; if (module_exists('image') && file_valid_uri($filepath) && ($style = variable_get('user_picture_style_node', ''))) { $variables['user_picture'] = theme('image_style', array('style_name' => $style, 'path' => $filepath, 'alt' => $alt, 'title' => $alt, 'attributes' => array('class' => array('img-circle')))); } else { $variables['user_picture'] = theme('image', array('path' => $filepath, 'alt' => $alt, 'title' => $alt, 'attributes' => array('class' => array('img-circle')))); } if (!empty($node->uid) && user_access('access user profiles')) { $attributes = array('attributes' => array('title' => t('View user profile.')), 'html' => TRUE); $variables['user_picture'] = l($variables['user_picture'], "user/{$node->uid}", $attributes); } } $variables['title_attributes'] = 'title'; if (!$variables['teaser']) { drupal_add_js(drupal_get_path('theme', 'alpha') . '/js/' . 'node-view.js'); } drupal_add_js(drupal_get_path('theme', 'alpha') . '/js/' . 'node-img-responsive.js'); }
/** * Wraps file_valid_uri(). */ protected function fileValidUri($source) { return file_valid_uri($source); }
/** * template_preprocess_user_picture() */ function md_orenmode_preprocess_user_picture(&$variables) { $variables['user_picture'] = ''; if (variable_get('user_pictures', 0)) { $account = $variables['account']; if (!empty($account->picture)) { // @TODO: Ideally this function would only be passed file objects, but // since there's a lot of legacy code that JOINs the {users} table to // {node} or {comments} and passes the results into this function if we // a numeric value in the picture field we'll assume it's a file id // and load it for them. Once we've got user_load_multiple() and // comment_load_multiple() functions the user module will be able to load // the picture files in mass during the object's load process. if (is_numeric($account->picture)) { $account->picture = file_load($account->picture); } if (!empty($account->picture->uri)) { $filepath = $account->picture->uri; } } elseif (variable_get('user_picture_default', '')) { $filepath = variable_get('user_picture_default', ''); } if (isset($filepath)) { $alt = t("@user's picture", array('@user' => format_username($account))); // If the image does not have a valid Drupal scheme (for eg. HTTP), // don't load image styles. if (module_exists('image') && file_valid_uri($filepath) && ($style = variable_get('user_picture_style', ''))) { $variables['user_picture'] = theme('image_style', array('style_name' => $style, 'path' => $filepath, 'alt' => $alt, 'title' => $alt, 'attributes' => array('class' => array('thumb img-rounded')))); } else { $variables['user_picture'] = theme('image', array('path' => $filepath, 'alt' => $alt, 'title' => $alt)); } if (!empty($account->uid) && user_access('access user profiles')) { $attributes = array('attributes' => array('title' => t('View user profile.')), 'html' => TRUE); $variables['user_picture'] = l($variables['user_picture'], "user/{$account->uid}", $attributes); } } } }
/** * Overrides theme_user_picture(). */ function nuboot_radix_user_picture(&$variables) { $variables['user_picture'] = ''; if (variable_get('user_pictures', 0)) { // Load the full user object since it is not provided with nodes, comments, // or views displays. $account = module_exists('gravatar') ? _gravatar_load_account($variables['account']) : $variables['account']; $filepath = module_exists('gravatar') ? _gravatar_get_account_user_picture($account) : ''; if (!empty($filepath)) { $alt = t("@user's picture", array('@user' => format_username($account))); if (module_exists('image') && file_valid_uri($filepath) && ($style = variable_get('user_picture_style', ''))) { $variables['user_picture'] = theme('image_style', array('style_name' => $style, 'path' => $filepath, 'alt' => $alt, 'title' => $alt)); } else { $variables['user_picture'] = theme('image', array('path' => $filepath, 'alt' => $alt, 'title' => $alt)); } if ($account->uid && user_access('access user profiles')) { // Create link to the user's profile. $attributes = array('title' => t('View user profile.')); $variables['user_picture'] = l($variables['user_picture'], 'user/' . $account->uid, array('attributes' => $attributes, 'html' => TRUE)); } elseif (!empty($account->homepage)) { // If user is anonymous, create link to the commenter's homepage. $attributes = array('title' => t('View user website.'), 'rel' => 'external nofollow'); $variables['user_picture'] = l($variables['user_picture'], $account->homepage, array('attributes' => $attributes, 'html' => TRUE)); } } } }
/** * {@inheritdoc} */ public function condition($property, $value = NULL, $operator = '=', $langcode = NULL) { $key = $property . '-' . $operator; $field_storage_definitions = \Drupal::service('entity.manager')->getFieldStorageDefinitions($this->entityTypeId); /* * Ok, so what is all this: * We need to convert our conditions into some sparql compatible conditions. */ $bundle = $this->entityType->getKey('bundle'); $id = $this->entityType->getKey('id'); $label = $this->entityType->getKey('label'); switch ($key) { // @todo Limit the graphs here to the set bundles. case $bundle . '-IN': $rdf_bundles = $this->mappingHandler->getBundleUriList($this->entityType->getBundleEntityType(), $value); if ($rdf_bundles) { $this->condition->condition('?entity', '?bundlepredicate', '?type'); $this->filterAdded = TRUE; $predicates = "(<" . implode(">, <", $this->entityStorage->bundlePredicate()) . ">)"; $this->filter->filter('?bundlepredicate IN ' . $predicates); $this->filter->filter('?type IN ' . $rdf_bundles); } return $this; case $bundle . '-=': $mapping = $this->mappingHandler->getRdfBundleMappedUri($this->entityType->getBundleEntityType(), $value); $bundle = $mapping[$value]; if ($bundle) { $this->condition->condition('?entity', '?bundlepredicate', SparqlArg::uri($bundle)); $predicates = "(<" . implode(">, <", $this->entityStorage->bundlePredicate()) . ">)"; $this->filter->filter('?bundlepredicate IN ' . $predicates); $this->filterAdded = TRUE; } return $this; case $id . '-IN': if ($value) { $ids_list = "(<" . implode(">, <", $value) . ">)"; if (!$this->filterAdded) { $this->condition->condition('?entity', '?bundlepredicate', '?type'); $predicates = "(<" . implode(">, <", $this->entityStorage->bundlePredicate()) . ">)"; $this->filter->filter('?bundlepredicate IN ' . $predicates); $this->filterAdded = TRUE; } $this->filter->filter('?entity IN ' . $ids_list); } return $this; case $id . '-NOT IN': case $id . '-<>': if ($value) { if (is_array($value)) { $ids_list = "(<" . implode(">, <", $value) . ">)"; } else { $ids_list = "(<" . $value . ">)"; } if (!$this->filterAdded) { $this->condition->condition('?entity', '?bundlepredicate', '?type'); $predicates = "(<" . implode(">, <", $this->entityStorage->bundlePredicate()) . ">)"; $this->filter->filter('?bundlepredicate IN ' . $predicates); $this->filterAdded = TRUE; } $this->filter->filter('!(?entity IN ' . $ids_list . ')'); } return $this; case $id . '-=': if (!$value) { return $this; } $id = '<' . $value . '>'; if (!$this->filterAdded) { $this->condition->condition('?entity', '?bundlepredicate', '?type'); $predicates = "(<" . implode(">, <", $this->entityStorage->bundlePredicate()) . ">)"; $this->filter->filter('?bundlepredicate IN ' . $predicates); $this->filterAdded = TRUE; } $this->filter->filter('?entity IN ' . SparqlArg::literal($id)); break; case $label . '-=': preg_match('/\\((.*?)\\)/', $value, $matches); $matching = array_pop($matches); if ($matching) { $ids = "(<{$matching}>)"; $this->filter->filter('?entity IN ' . $ids); } else { if (file_valid_uri($value)) { $ids = "(<{$value}>)"; $this->filter->filter('?entity IN ' . $ids); } else { $mapping = $this->mappingHandler->getEntityTypeLabelPredicates($this->entityTypeId); $label_list = "(<" . implode(">, <", array_unique(array_keys($mapping))) . ">)"; $this->condition->condition('?entity', '?label_type', '?label'); $this->filter->filter('?label_type IN ' . $label_list); $this->filter->filter('str(?label) = "' . $value . '"'); } } return $this; case $label . '-CONTAINS': $mapping = $this->mappingHandler->getEntityTypeLabelPredicates($this->entityTypeId); $label_list = "(<" . implode(">, <", array_unique(array_keys($mapping))) . ">)"; $this->condition->condition('?entity', '?label_type', '?label'); $this->filter->filter('?label_type IN ' . $label_list); if ($value) { $this->filter->filter('regex(?label, "' . $value . '", "i")'); $this->filter->filter('(lang(?label) = "" || langMatches(lang(?label), "EN"))'); } return $this; case '_field_exists-EXISTS': case '_field_exists-NOT EXISTS': $field_rdf_name = $this->getFieldRdfPropertyName($value, $field_storage_definitions); if (!UrlHelper::isValid($field_rdf_name, TRUE) === FALSE) { $field_rdf_name = SparqlArg::uri($field_rdf_name); } if ($field_rdf_name) { $this->filter('?entity ' . $field_rdf_name . ' ?c', 'FILTER ' . $operator); } return $this; } if ($operator == '=') { if (!$value) { return $this; } // @todo this code will be handled in ISAICP-2631 if (strpos($property, '.') !== FALSE) { list($field_name, $column) = explode('.', $property); } else { $field_name = $property; } $field_rdf_name = $this->getFieldRdfPropertyName($field_name, $field_storage_definitions); if (!UrlHelper::isValid($value, TRUE) === FALSE) { $value = SparqlArg::uri($value); } else { $value = SparqlArg::literal($value); } $this->condition->condition('?entity', SparqlArg::uri($field_rdf_name), $value); } return $this; }
/** * Get the user's picture to return as an OpenID Connect claim. * * @param object $account * The user account object. * * @return string|NULL * An absolute URL to the user picture, or NULL if none is found. */ protected function getUserPicture($account) { if (!variable_get('user_pictures', 0)) { return NULL; } // This uses logic from template_preprocess_user_picture(). if (!empty($account->picture)) { if (is_numeric($account->picture)) { $account->picture = file_load($account->picture); } if (!empty($account->picture->uri)) { $picture_path = $account->picture->uri; } } else { $picture_path = variable_get('user_picture_default', NULL); } if (empty($picture_path)) { return NULL; } if (module_exists('image') && file_valid_uri($picture_path) && ($style = variable_get('user_picture_style', ''))) { $picture_url = image_style_url($style, $picture_path); } else { $picture_url = url(file_create_url($picture_path), array('absolute' => TRUE)); } return $picture_url; }