Example #1
0
function cstark_preprocess_node(&$variables)
{
    if (user_access('administer nodes')) {
        $variables['edit_link'] = l(t('Edit'), 'node/' . $variables['nid'] . '/edit');
        if ($variables['type'] == 'painting') {
            $title = $variables['promote'] ? t('Remove from front page') : t('Add to front page');
            $variables['set_as_main_link'] = l($title, 'set-as-main/' . $variables['nid']);
            // Facebook share.
            $url = url('node/' . $variables['nid'], array('absolute' => TRUE));
            $variables['share_link'] = l(t('Share'), "http://www.facebook.com/sharer.php?u={$url}", array('attributes' => array('class' => array('facebook'))));
        }
    }
    if ($variables['type'] == 'painting') {
        $wrapper = entity_metadata_wrapper('node', $variables['nid']);
        if ($image = $wrapper->field_image->value()) {
            $element = array('#tag' => 'meta', '#attributes' => array('property' => 'og:image', 'content' => file_create_url($image['uri'])));
            drupal_add_html_head($element, 'cstark_painting_image');
            $element = array('#tag' => 'meta', '#attributes' => array('property' => 'og:title', 'content' => $wrapper->label()));
            drupal_add_html_head($element, 'cstark_painting_title');
        }
    }
    if ($variables['type'] == 'painting' && !drupal_is_front_page()) {
        $variables['pager'] = shapira_get_painting_pager($variables['nid']);
    }
    if ($variables['type'] != 'news') {
        $variables['hide_title'] = true;
    }
    if ($variables['type'] == 'painting') {
        if ($variables['field_image']) {
            $info = image_get_info(image_style_path('painting', $variables['field_image'][0]['uri']));
            $variables['node_width'] = $info['width'];
        }
    }
}
 /**
  * Build the search row description.
  *
  * If there is a "result_description", run it thro token_replace.
  *
  * @param object $data
  *   An entity object that will be used in the token_place function.
  *
  * @see token_replace()
  */
 function buildDescription($data)
 {
     $description_array = array();
     //Get image info.
     $imageinfo = image_get_info($data->uri);
     if ($this->conf['image_extra_info']['thumbnail']) {
         $image = $imageinfo ? theme_image_style(array('width' => $imageinfo['width'], 'height' => $imageinfo['height'], 'style_name' => 'linkit_thumb', 'path' => $data->uri)) : '';
     }
     if ($this->conf['image_extra_info']['dimensions'] && !empty($imageinfo)) {
         $description_array[] = $imageinfo['width'] . 'x' . $imageinfo['height'] . 'px';
     }
     $description_array[] = parent::buildDescription($data);
     if ($this->conf['show_scheme']) {
         $description_array[] = file_uri_scheme($data->uri) . '://';
     }
     $description = (isset($image) ? $image : '') . implode('<br />', $description_array);
     return $description;
 }
Example #3
0
/**
 * Scale an image to the specified size using GD.
 */
function image_gd_resize($source, $destination, $width, $height)
{
    if (!file_exists($source)) {
        return false;
    }
    $info = image_get_info($source);
    if (!$info) {
        return false;
    }
    $im = image_gd_open($source, $info['extension']);
    if (!$im) {
        return false;
    }
    $res = imageCreateTrueColor($width, $height);
    imageCopyResampled($res, $im, 0, 0, 0, 0, $width, $height, $info['width'], $info['height']);
    $result = image_gd_close($res, $destination, $info['extension']);
    imageDestroy($res);
    imageDestroy($im);
    return $result;
}
Example #4
0
 function image_file_download($file)
 {
     $size = image_get_info(file_create_path($file));
     if ($size) {
         $modified = filemtime(file_create_path($file));
         //apache only
         $request = getallheaders();
         if (isset($request['If-Modified-Since'])) {
             //remove information after the semicolon and form a timestamp
             $request_modified = explode(';', $request['If-Modified-Since']);
             $request_modified = strtotime($request_modified[0]);
         }
         // Compare the mtime on the request to the mtime of the image file
         if ($modified <= $request_modified) {
             header('HTTP/1.1 304 Not Modified');
             exit;
         }
         //enable caching on this url for proxy servers
         $headers = array('Content-Type: ' . $size['mime_type'], 'Last-Modified: ' . gmdate('D, d M Y H:i:s', $modified) . ' GMT', 'Cache-Control: public');
         return $headers;
     }
 }
Example #5
0
/**
 * Implements theme_icon_RENDER_HOOK().
 *
 * Return an image of the requested icon.
 *
 * @param array $variables
 *   An associative array containing:
 *   - attributes: Associative array of HTML attributes.
 *   - bundle: An associative array containing various properties.
 *   - icon: Name of the icon requested from the above bundle.
 *
 * @return string
 *   HTML markup for the requested icon.
 *
 * @see hook_icon_bundles()
 * @see theme_icon_image()
 */
function theme_icon_RENDER_HOOK($variables)
{
    $output = '';
    $bundle = $variables['bundle'];
    $icon = $variables['icon'];
    $image = $bundle['path'] . '/' . $icon . '.' . $bundle['settings']['extension'];
    if (file_exists($image) && ($info = image_get_info($image))) {
        $output = theme('image', array('path' => $image, 'height' => $info['height'], 'width' => $info['width'], 'attributes' => $variables['attributes']));
    }
    return $output;
}
Example #6
0
$base = $GLOBALS['base_url'] . '/';
$path = current_path();
$alias = drupal_lookup_path('alias', $path);
if ($alias) {
    $url = $base . $alias;
} else {
    $url = $base . $path;
}
?>
<meta property="og:url" content="<?php 
print $url;
?>
">
<?php 
if ($thumbnail_image) {
    $result = image_get_info($thumbnail_image);
    ?>
<!--
  <PageMap>
    <DataObject type="thumbnail">
      <Attribute name="src" value="<?php 
    print file_create_url($thumbnail_image);
    ?>
"/>
      <Attribute name="width" value="<?php 
    print $result['width'];
    ?>
"/>
      <Attribute name="height" value="<?php 
    print $result['height'];
    ?>
Example #7
0
 /**
  * @param ldap entry array $ldap_entry
  *
  * @return drupal file object image user's thumbnail or FALSE if none present or ERROR happens.
  */
 public function userPictureFromLdapEntry($ldap_entry, $drupal_username = FALSE)
 {
     if ($ldap_entry && $this->picture_attr) {
         //Check if ldap entry has been provisioned.
         $thumb = isset($ldap_entry[$this->picture_attr][0]) ? $ldap_entry[$this->picture_attr][0] : FALSE;
         if (!$thumb) {
             return FALSE;
         }
         //Create md5 check.
         $md5thumb = md5($thumb);
         /**
          * If existing account already has picture check if it has changed if so remove old file and create the new one
          * If picture is not set but account has md5 something is wrong exit.
          */
         if ($drupal_username && ($account = user_load_by_name($drupal_username))) {
             if ($account->uid == 0 || $account->uid == 1) {
                 return FALSE;
             }
             if (isset($account->picture)) {
                 // Check if image has changed
                 if (isset($account->data['ldap_user']['init']['thumb5md']) && $md5thumb === $account->data['ldap_user']['init']['thumb5md']) {
                     //No change return same image
                     return $account->picture;
                 } else {
                     //Image is different check wether is obj/str and remove fileobject
                     if (is_object($account->picture)) {
                         file_delete($account->picture, TRUE);
                     } elseif (is_string($account->picture)) {
                         $file = file_load(intval($account->picture));
                         file_delete($file, TRUE);
                     }
                 }
             } elseif (isset($account->data['ldap_user']['init']['thumb5md'])) {
                 watchdog('ldap_server', "Some error happened during thumbnailPhoto sync");
                 return FALSE;
             }
         }
         //Create tmp file to get image format.
         $filename = uniqid();
         $fileuri = file_directory_temp() . '/' . $filename;
         $size = file_put_contents($fileuri, $thumb);
         $info = image_get_info($fileuri);
         unlink($fileuri);
         // create file object
         $file = file_save_data($thumb, 'public://' . variable_get('user_picture_path') . '/' . $filename . '.' . $info['extension']);
         $file->md5Sum = $md5thumb;
         // standard Drupal validators for user pictures
         $validators = array('file_validate_is_image' => array(), 'file_validate_image_resolution' => array(variable_get('user_picture_dimensions', '85x85')), 'file_validate_size' => array(variable_get('user_picture_file_size', '30') * 1024));
         $errors = file_validate($file, $validators);
         if (empty($errors)) {
             return $file;
         } else {
             foreach ($errors as $err => $err_val) {
                 watchdog('ldap_server', "Error storing picture: %{$err}", "%{$err_val}", WATCHDOG_ERROR);
             }
             return FALSE;
         }
     }
 }
Example #8
0
function tfd_image_size($filepath, $preset, $asHtml = TRUE)
{
    if (is_array($filepath)) {
        $filepath = $filepath['filepath'];
    }
    $info = image_get_info(image_style_url($preset, $filepath));
    $attr = array('width' => (string) $info['width'], 'height' => (string) $info['height']);
    if ($asHtml) {
        return drupal_attributes($attr);
    } else {
        return $attr;
    }
}
    }
    if ($show_left_sidebar) {
        $style = 'v2_big';
    } else {
        $style = 'v2_article_large';
    }
}
$field_main_image = field_get_items('node', $node, 'field_main_image');
$image_style = image_style_load($style);
$width = '100%';
$height = '100%';
$w = array();
$h = array();
//$path = file_create_url($field_main_image[0]['uri']);
$path = image_style_path($style, $field_main_image[0]['uri']);
$image_info = image_get_info($path);
if (!empty($image_info['width'])) {
    $w[] = (int) $image_info['width'];
}
if (!empty($image_info['height'])) {
    $h[] = (int) $image_info['height'];
}
foreach ($image_style['effects'] as $effect) {
    if (!empty($effect['data']['width'])) {
        $w[] = (int) $effect['data']['width'];
    }
    if (!empty($effect['data']['height'])) {
        $h[] = (int) $effect['data']['height'];
    }
}
if (!empty($h)) {
 /**
  * Helper function to get all the images from the configured folder.
  */
 private function getImages()
 {
     if ($files = cache_get('devel_image_provider_local')) {
         return $files->data;
     }
     $files = array();
     $count = 1;
     // Limiting number of images to find to 100.
     // @TODO: add this as a setting.
     $max_count = 100;
     // Remove trailing slash.
     $dir = rtrim($this->settings['devel_image_provider_path'], '/');
     if (is_dir($dir) && ($handle = opendir($dir))) {
         while (FALSE !== ($filename = readdir($handle)) && $count <= $max_count) {
             $path = "{$dir}/{$filename}";
             if ($filename[0] != '.' && preg_match('/.*\\.(jpg|jpeg|png)$/i', $filename) && ($image = image_get_info($path))) {
                 $file = new stdClass();
                 $file->uri = file_stream_wrapper_uri_normalize($path);
                 $file->filename = $filename;
                 $file->filemime = $image['mime_type'];
                 $file->name = pathinfo($filename, PATHINFO_FILENAME);
                 $files[$file->uri] = $file;
                 $count++;
             }
         }
         closedir($handle);
     }
     cache_set('devel_image_provider_local', $files, 'cache', CACHE_TEMPORARY);
     return $files;
 }
 /**
  * @see \ResponsiveImages\SrcsetGeneratorInterface
  *
  * @param string    $uri
  *   Drupal URI to the original image file.
  * @param RImg\Size $size
  *
  * @return RImg\Src[]
  */
 public function listFor($uri, RImg\Size $size)
 {
     $styles = $this->stylesMatchingSize($size);
     # By default Drupal doesn't provide an image style that crops an image to
     # an aspect ratio without potentially upscaling it. If the original image is
     # smaller than the styles that are returned we aren't providing any better
     # quality. Better to just allow only one larger than the original, or even
     # the original if it matches the aspect ratio.
     $image = image_get_info($uri);
     if ($image) {
         $styles = F\partition($styles, function ($style) use($image, $size) {
             return $style->width < $image['width'];
         });
         if ($size->matchesAspectRatio($image['width'] / $image['height']) and (!empty($styles[1]) and F\head($styles[1])->width != $image['width'] or $image['width'] <= $size->getMaxWidth() * 2)) {
             $styles[0][] = (object) ['name' => null, 'width' => $image['width'], 'height' => $image['height'], 'firm' => true];
         } else {
             if (!empty($styles[1])) {
                 $styles[0][] = F\head($styles[1]);
             }
         }
         $styles = $styles[0];
     }
     return F\map($styles, function ($style) use($uri) {
         $url = $style->name ? image_style_url($style->name, $uri) : file_create_url($uri);
         return new RImg\Src($url, $style->width);
     });
 }
Example #12
0
function beats_imagecache($presetname, $path, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE) {


  if((in_array($presetname, array('user_avatar','48x48','189x245' , 'celebrity_80x80'
  )) || !$presetname) && (!file_exists($path) || !$path)){


    $path = drupal_get_path('theme','3beats').'/images/defaults_img.png';
  }
  // Check is_null() so people can intentionally pass an empty array of
  // to override the defaults completely.
  if (is_null($attributes)) {
    $attributes = array('class' => 'imagecache imagecache-'. $presetname);
  }
  if ($getsize && ($image = image_get_info(imagecache_create_path($presetname, $path)))) {
    $attributes['width'] = $image['width'];
    $attributes['height'] = $image['height'];
  }

  $attributes = drupal_attributes($attributes);

  $imagecache_url = $presetname ? imagecache_create_url($presetname, $path) : $path;
  return '<img src="'. $imagecache_url .'" alt="'. check_plain($alt) .'" title="'. check_plain($title) .'" '. $attributes .' />';
}
<?php

$name = $fields['name']->content;
$job = $fields['field_job_position']->content;
$email = $fields['mail']->content;
$colour = $fields['field_colour']->content;
$uri = $fields['uri'];
$imageinfo = image_get_info($uri->raw);
$variables = array('style_name' => 'our_people', 'path' => $uri->raw, 'width' => $imageinfo['width'], 'height' => $imageinfo['height'], 'alt' => strip_tags($name));
$photo = theme_image_style($variables);
?>
<div class="teamBlock column <?php 
print $zebra;
?>
">
      <div class="teamImage" style="background-color:<?php 
print $colour;
?>
"><?php 
print $photo;
?>
        <div class="teamName">
        	<h2><?php 
print $name;
?>
</h2>
		    <h3><?php 
print $job;
?>
</h3>
		    <ul class="socialLinksTeam">
Example #14
0
    <!--start parallax 6-->
    <?php 
    if ($file = file_load(theme_get_setting('parallax_bg_region6_image', 'surreal'))) {
        ?>
    <div id="parallax-6" class="parallax fixed" style="background: url('<?php 
        print file_create_url($file->uri);
        ?>
')"> 
      <div class="quoteWrap">
        <div class="quote">
          <div class="container">
            <?php 
        if ($file = file_load(theme_get_setting('parallax_fg_region6_image', 'surreal'))) {
            ?>
            <?php 
            $fileinfo = image_get_info(file_create_url($file->uri));
            ?>
            <div class="sixteen columns"> 
              <img height="<?php 
            print $fileinfo['height'];
            ?>
" width="<?php 
            print $fileinfo['width'];
            ?>
" class="cutout" src="<?php 
            print file_create_url($file->uri);
            ?>
" />
            </div>
            <?php 
        }
Example #15
0
/**
 * Support for image_annotate on img_assist inserted images
 *
 */
function phptemplate_img_assist_inline($node, $size, $attributes)
{
    $caption = '';
    if ($attributes['title'] && $attributes['desc']) {
        $caption = '<strong>' . $attributes['title'] . ': </strong>' . $attributes['desc'];
    } elseif ($attributes['title']) {
        $caption = '<strong>' . $attributes['title'] . '</strong>';
    } elseif ($attributes['desc']) {
        $caption = $attributes['desc'];
    }
    // Change the node title because img_assist_display() uses the node title for
    // alt and title.
    $node->title = strip_tags($caption);
    // --------------------------
    if (user_access('view image annotations') || user_access('create image annotations') || user_access('administer image annotations')) {
        // Retrieve all the annotations for that image field
        // We sort by area (height*width) to make sure small annotations are always on the top and avoid having some unhoverable ones
        $result = db_query('SELECT i.*, c.uid, c.comment, u.name FROM {image_annotate} i INNER JOIN {comments} c ON i.cid = c.cid JOIN {users} u ON c.uid = u.uid WHERE c.nid = %d ORDER BY (i.size_height*i.size_width) ASC', $node->nid);
        // Build the array of notes settings
        global $user;
        $notes = array();
        while ($note = db_fetch_object($result)) {
            $editable = user_access('administer image annotations') || user_access('create image annotations') && $note->uid && $note->uid == $user->uid;
            $author = theme('username', $note);
            $text = check_plain($note->comment);
            // . '"<span class="author"> '. t('by') .' '. $author . '</span>';
            //      if (user_access('access comments')) {
            //        $text .= '<span class="actions"> » '. l(t('View comment'), $_GET['q'], array('fragment'=>'comment-'. $note->cid)) .'</span>';
            //      }
            $notes[] = array('aid' => $note->aid, 'cid' => $note->cid, 'uid' => $note->uid, 'height' => $note->size_height, 'width' => $note->size_width, 'top' => $note->position_top, 'left' => $note->position_left, 'text' => $text, 'editable' => FALSE);
        }
        // Build the field settings
        $settings = array(array('nid' => $node->nid, 'field' => 'image', 'notes' => $notes, 'editable' => user_access('administer image annotations') || user_access('create image annotations')));
        module_load_include('module', 'jquery_ui');
        // Load all the JS and CSS magic
        drupal_add_js(array('imageAnnotate' => $settings), 'setting');
        jquery_ui_add(array('ui.resizable', 'ui.draggable'));
        drupal_add_js('misc/collapse.js');
        drupal_add_js(drupal_get_path('module', 'image_annotate') . '/tag.js');
        drupal_add_css(drupal_get_path('module', 'image_annotate') . '/tag.css');
        //BVDM 13/09/09: substitute image-annotate-image for image-annotate-nid-$node->nid to create a unique class per inserted image
        $class = 'imagefield imagefield-image image-annotate-nid-' . $node->nid;
        $img_tag = img_assist_display($node, $size, array('class' => $class));
    } else {
        $img_tag = img_assist_display($node, $size);
    }
    // -----------------------
    // Always define an alignment class, even if it is 'none'.
    $output = '<span class="inline inline-' . $attributes['align'] . '">';
    $link = $attributes['link'];
    $url = '';
    // Backwards compatibility: Also parse link/url in the format link=url,foo.
    if (strpos($link, ',') !== FALSE) {
        list($link, $url) = explode(',', $link, 2);
    } elseif (isset($attributes['url'])) {
        $url = $attributes['url'];
    }
    if ($link == 'node') {
        $output .= l($img_tag, 'node/' . $node->nid, array('html' => TRUE));
    } elseif ($link == 'popup') {
        $popup_size = variable_get('img_assist_popup_label', IMAGE_PREVIEW);
        $info = image_get_info(file_create_path($node->images[$popup_size]));
        $width = $info['width'];
        $height = $info['height'];
        $popup_url = file_create_url($node->images[variable_get('img_assist_popup_label', IMAGE_PREVIEW)]);
        $output .= l($img_tag, $popup_url, array('attributes' => array('onclick' => "launch_popup({$node->nid}, {$width}, {$height}); return false;", 'target' => '_blank'), 'html' => TRUE));
    } elseif ($link == 'url') {
        $output .= l($img_tag, $url, array('html' => TRUE));
    } else {
        $output .= $img_tag;
    }
    if ($caption) {
        if ($attributes['align'] != 'center') {
            $info = image_get_info(file_create_path($node->images[$size['key']]));
            // Reduce the caption width slightly so the variable width of the text
            // doesn't ever exceed image width.
            $width = $info['width'] - 2;
            $output .= '<span class="caption" style="width: ' . $width . 'px;">' . $caption . '</span>';
        } else {
            $output .= '<span class="caption">' . $caption . '</span>';
        }
    }
    $output .= '</span>';
    return $output;
}
Example #16
0
/**
 * upload 1 file
 * 
 * @param file $_FILES: global file
 * @param string $dirUpload: duong dan se luu file
 * @return json: kieu du lieu tra ve
 */
function upload_image($__FILES, $dirUpload = '')
{
    $ci =& get_instance();
    $data = array();
    $_FILES = $__FILES;
    foreach ($_FILES as $fileId => $file) {
        $fileName = uniqid() . '_' . time();
        if ($file["error"] > 0) {
            if ($file["error"] == 1) {
                $data['error'] = 1;
                $data['message'] = $ci->lang->line('admin.content.file.toobig');
            }
        } else {
            $info = image_get_info($file["tmp_name"]);
            if (is_array($info)) {
                //neu la file duoc support
                if (!file_exists($dirUpload)) {
                    mkdirs($dirUpload);
                }
                $uploadFile = $dirUpload . '/' . $fileName . '.' . $info["extension"];
                if (move_uploaded_file($file["tmp_name"], $uploadFile)) {
                    $fileNameReturn = $fileName . '.' . $info["extension"];
                    $data['error'] = 0;
                    $data['fileName'] = $fileNameReturn;
                    $data['message'] = "";
                    //resize_image_gd2($uploadFile, $uploadFile);
                }
            } else {
                $data['error'] = 10;
                $data['message'] = $ci->lang->line('admin.content.file.notsuport');
            }
        }
    }
    return $data;
}
/**
 * Implements theme_preprocess_node().
 */
function cuemail_preprocess_node(&$vars)
{
    $vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__' . $vars['view_mode'];
    $url = url('node/' . $vars['nid'], array('absolute' => TRUE, 'alias' => TRUE, 'https' => FALSE));
    $vars['node_url'] = $url;
    if ($vars['type'] == 'newsletter') {
        if (!empty($vars['content']['field_newsletter_intro_image'])) {
            $vars['content']['field_newsletter_intro_image'][0]['#image_style'] = 'email_medium';
        }
        $list = array();
        foreach ($vars['content']['field_newsletter_section']['#items'] as $key => $item) {
            $key_2 = key($vars['content']['field_newsletter_section'][$key]['entity']['field_collection_item']);
            $articles = $vars['content']['field_newsletter_section'][$key]['entity']['field_collection_item'][$key_2]['field_newsletter_articles']['#items'];
            foreach ($articles as $article) {
                $node = node_load($article['target_id']);
                $list[] = $node->title;
            }
        }
        $newsletter_logo_image_style_uri = image_style_path('medium', $vars['newsletter_logo_uri']);
        if (!file_exists($newsletter_logo_image_style_uri)) {
            image_style_create_derivative(image_style_load('medium'), $vars['newsletter_logo_uri'], $newsletter_logo_image_style_uri);
        }
        $image_info = image_get_info($newsletter_logo_image_style_uri);
        $vars['newsletter_logo_width'] = round($image_info['width'] * 0.46333);
        $vars['newsletter_logo_height'] = round($image_info['height'] * 0.46333);
        $vars['content']['list'] = theme('item_list', array('items' => $list, 'type' => 'ul', 'attributes' => array('class' => array('bullet-list'))));
    }
    if ($vars['type'] == 'article') {
        if (!empty($vars['content']['field_article_thumbnail'][0])) {
            $vars['content']['field_article_thumbnail'][0]['#path']['options']['absolute'] = TRUE;
        }
        if ($vars['view_mode'] == 'email_feature') {
            $vars['content']['field_article_thumbnail'][0]['#image_style'] = 'email_feature_thumbnail';
        }
        if (isset($vars['field_article_categories'])) {
            foreach ($vars['field_article_categories'] as $tid) {
                if (isset($tid['tid'])) {
                    $tids[] = $tid['tid'];
                }
            }
        }
        if (isset($tids)) {
            $terms = taxonomy_term_load_multiple($tids);
            foreach ($terms as $term) {
                if (isset($term->name)) {
                    $tag = $term->name;
                    if ($term->field_category_display[LANGUAGE_NONE][0]['value'] == 'show') {
                        if (!empty($term->field_category_term_page_link)) {
                            $new_tags[] = l($tag, $term->field_category_term_page_link[LANGUAGE_NONE][0]['url'], array('absolute' => TRUE, 'alias' => TRUE, 'https' => FALSE));
                        } else {
                            $new_tags[] = $tag;
                        }
                    }
                }
            }
            $markup = implode(' ', $new_tags);
            unset($vars['content']['field_article_categories']);
            $vars['content']['field_article_categories'][0]['#markup'] = '<p>' . $markup . '</p>';
        }
    }
}
Example #18
0
/**
 * Theme the attachment form.
 * Note: required to output prefix/suffix.
 *
 * @ingroup themeable
 */
function phptemplate_upload_form_new($form)
{
    // add wysiwyg insert buttons
    foreach (element_children($form['files']) as $key) {
        $filepath = $form['files'][$key]['filepath']['#value'];
        $fid = $form['files'][$key]['fid']['#value'];
        if (image_get_info($filepath)) {
            $thumb_path = 'sites/default/files/imagecache/small_thumb/' . $filepath;
            /* The javascript for this is in imc_alba module */
            $form['files'][$key]['insertbutton'] = array('#type' => 'markup', '#value' => '<button type="button" class="insertimg" id="' . file_create_url($filepath) . '">Big</button>' . '<button type="button" class="insertthumb" id="' . file_create_url($thumb_path) . '">Small</button>');
        }
    }
    drupal_add_tabledrag('upload-attachments', 'order', 'sibling', 'upload-weight');
    $output = drupal_render($form);
    return $output;
}
Example #19
0
 /**
  * Creates an input array based on file object and information.
  *
  * @param object $file
  *   File object.
  * @param $file_info
  *   File information array.
  *
  * @return array
  *   Input array that can be sent in the form POST.
  */
 protected static function createInput($file, $file_info)
 {
     $image_info = image_get_info($file->uri);
     $input = array('fid' => $file->fid, 'width' => $image_info['width'], 'height' => $image_info['height']);
     if (!empty($file_info['alt'])) {
         $input['alt'] = $file_info['alt'];
     }
     if (!empty($file_info['title'])) {
         $input['title'] = $file_info['title'];
     }
     return $input;
 }
Example #20
0
/**
 * Additional comment variables
 */
function marinelli_preprocess_comment(&$vars)
{
    $vars['classes_array'][] = $vars['zebra'];
    $user_image = array('width' => 0);
    if (isset($vars['user']->picture)) {
        // No.. I don't use style
        if (!variable_get('user_picture_style')) {
            $size = variable_get('user_picture_dimensions');
            $size = explode('x', $size);
            $user_image['width'] = $size[0];
        } else {
            //Yes... I use style
            if ($picture = file_load($vars['comment']->picture->fid)) {
                $user_image = image_get_info(image_style_path(variable_get('user_picture_style'), $picture->uri));
            }
        }
    }
    $vars['image_width'] = $user_image['width'] + 25;
}
Example #21
0
/**
 * Control access to private file downloads and specify HTTP headers.
 *
 * This hook allows modules enforce permissions on file downloads when the
 * private file download method is selected. Modules can also provide headers
 * to specify information like the file's name or MIME type.
 *
 * @param $uri
 *   The URI of the file.
 * @return
 *   If the user does not have permission to access the file, return -1. If the
 *   user has permission, return an array with the appropriate headers. If the
 *   file is not controlled by the current module, the return value should be
 *   NULL.
 *
 * @see file_download()
 */
function hook_file_download($uri)
{
    // Check if the file is controlled by the current module.
    if (!file_prepare_directory($uri)) {
        $uri = FALSE;
    }
    if (strpos(file_uri_target($uri), variable_get('user_picture_path', 'pictures') . '/picture-') === 0) {
        if (!user_access('access user profiles')) {
            // Access to the file is denied.
            return -1;
        } else {
            $info = image_get_info($uri);
            return array('Content-Type' => $info['mime_type']);
        }
    }
}
 *   CSS. It can be manipulated through the variable $classes_array from
 *   preprocess functions. By default the following classes are available, where
 *   the parts enclosed by {} are replaced by the appropriate values:
 *   - entity-{ENTITY_TYPE}
 *   - {ENTITY_TYPE}-{BUNDLE}
 *
 * Other variables:
 * - $classes_array: Array of html class attribute values. It is flattened
 *   into a string within the variable $classes.
 *
 * @see template_preprocess()
 * @see template_preprocess_entity()
 * @see template_process()
 */
$image_path = file_create_url($content['field_image'][0]['#item']['uri']);
$info = image_get_info($content['field_image'][0]['#item']['uri']);
?>

<a class="<?php 
print $classes;
?>
 "<?php 
print $attributes;
?>
 style="background-image: url(<?php 
print $image_path;
?>
); height: <?php 
print $info['height'];
?>
px" href="<?php 
 protected function validateFileIsImage(File $file)
 {
     $errors = array();
     $info = image_get_info($file->getFileUri());
     if (!$info || empty($info['extension'])) {
         $errors[] = "只运行上传JPG、PNG、GIF格式的图片文件。";
     }
     return $errors;
 }
Example #24
0
function kr2011_preprocess_node(&$vars)
{
    if ($vars['type'] == 'Article') {
        if (strlen($vars['field_article_fakta'][0]['value']) > 4) {
            $vars['fakta'] = $vars['field_article_fakta'][0]['safe'];
        }
        if (strlen($vars['field_teaser'][0]['value']) > 2) {
            $vars['ingress'] = 1;
            $vars['ingress_value'] = $vars['field_teaser'][0]['safe'];
        }
        foreach ($vars['field_sitat'] as $sitatlinje) {
            $sitater .= '<div class="sitat-line"><span>' . $sitatlinje['value'] . '</span></div>';
            if (strlen($sitatlinje['value']) > 2) {
                $vars['sitat'] = 1;
            }
        }
        $vars['sitat_content'] = '<div class="sitat-wrapper">' . $sitater . '</div>';
        $updated = format_date($vars['node']->changed, 'medium');
        if ($vars['node']->changed != $vars['node']->created) {
            $vars['node_updated_rdfa'] = _openpublish_get_rdfa_date($vars['node']->changed, $updated);
        }
        //  $vars['node_created_rdfa'] = _openpublish_get_rdfa_date($vars['node']->created, $vars['node_created']);
        //  $vars['node_created_rdfa'] .= _openpublish_get_rdfa_date($vars['node']->updated, $updated);
        drupal_add_js(drupal_get_path('theme', 'kr2011') . '/js/kr2011.js', 'theme', 'footer');
        //	print_R($vars['node']);
    } elseif ($vars['type'] == 'bildegalleri') {
        drupal_add_js(drupal_get_path('theme', 'kr2011') . '/flex/jquery.min.js');
        drupal_add_js(drupal_get_path('theme', 'kr2011') . '/flex/jquery-noconflict.js');
        drupal_add_js(drupal_get_path('theme', 'kr2011') . '/flex/jquery.flexslider.js', 'theme', 'header');
        drupal_add_js(drupal_get_path('theme', 'kr2011') . '/flex/jquery.colorbox.js', 'theme', 'header');
        drupal_add_css(drupal_get_path('theme', 'kr2011') . '/flex/flexslider.css');
        drupal_add_css(drupal_get_path('theme', 'kr2011') . '/flex/kr-flex.css');
        drupal_add_css(drupal_get_path('theme', 'kr2011') . '/flex/colorbox.css');
        drupal_add_js(drupal_get_path('theme', 'kr2011') . '/flex/bilde.js', 'theme', 'header');
        $hidden = '<div class="colorbox-images-container">';
        $html = '<div class="flexslider">
        <ul class="slides">';
        foreach ($vars['field_galleri_bilde'] as $delta => $item) {
            $html .= '<li>';
            $html .= '<a class="colorboks1" href="#bilde_' . $vars['nid'] . '_' . $delta . '">';
            $html .= $item['view'];
            if ($vars['field_galleri_desc'][$delta]['safe'] && $vars['field_galleri_kredit'][$delta]['safe']) {
                $html .= '<p>' . $vars['field_galleri_desc'][$delta]['safe'];
                $html .= '<span class="kredit">' . $vars['field_galleri_kredit'][$delta]['safe'] . '</span></p>';
            } elseif ($vars['field_galleri_desc'][$delta]['safe']) {
                $html .= '<p>' . $vars['field_galleri_desc'][$delta]['safe'] . '</p>';
            } elseif ($vars['field_galleri_kredit'][$delta]['safe']) {
                $html .= '<p><span class="kredit">' . $vars['field_galleri_kredit'][$delta]['safe'] . '</span></p>';
            }
            $html .= '</a>';
            $html .= '</li>';
            $image = image_get_info(imagecache_create_path('slider_stort', $vars['field_galleri_bilde'][$delta]['filepath']));
            //<img src="'.imagecache_create_path('slider_stort', $vars['field_galleri_bilde'][$delta]['filepath']).'">
            $hidden .= '<div id="bilde_' . $vars['nid'] . '_' . $delta . '" class="cimage">
      ' . theme_imagecache('slider_stort', $vars['field_galleri_bilde'][$delta]['filepath']) . '
      
      <div class="caption">' . $vars['field_galleri_desc'][$delta]['safe'] . '</div>
      </div>';
        }
        $html .= '</ul></div>';
        $hidden .= '</div>';
        $vars['content'] = $html;
        $vars['content'] .= $hidden;
    } elseif ($vars['type'] == 'eksternt_blogginnlegg') {
        $blogcontent = node_load($vars['nid']);
        $blog = node_load($blogcontent->feeds_node_item->feed_nid);
        $html = '<div class="bloginfo">';
        $html .= '<div class="section-date-author">';
        $date_label = date('d. ', $blogcontent->created) . t(date('M', $blogcontent->created)) . date(' Y - H:i', $blogcontent->created);
        $html .= _openpublish_get_rdfa_date($blogcontent->created, $date_label);
        $html .= ' | Fra bloggen: ' . l($blog->title, 'node/' . $blog->nid);
        $html .= '</div></div>';
        $html2 = '<div class="bloggfooter">Dette blogginnlegget er hentet fra: ' . l($blogcontent->feeds_node_item->url, $blogcontent->feeds_node_item->url) . '</div>';
        $vars['content'] = $html . $vars['content'] . $html2;
    }
}
Example #25
0
/**
 * This is a hook used by node modules. It is called after load but before the
 * node is shown on the add/edit form.
 *
 * @param $node
 *   The node being saved.
 *
 * For a usage example, see image.module.
 */
function hook_prepare($node)
{
    if ($file = file_check_upload($field_name)) {
        $file = file_save_upload($field_name, _image_filename($file->filename, NULL, TRUE));
        if ($file) {
            if (!image_get_info($file->uri)) {
                form_set_error($field_name, t('Uploaded file is not a valid image'));
                return;
            }
        } else {
            return;
        }
        $node->images['_original'] = $file->uri;
        _image_build_derivatives($node, TRUE);
        $node->new_file = TRUE;
    }
}
<?php print theme('wistar_callout_header_single', $node); ?>
<div class="vertical_tab_container">
	<div class="vertical_tab_elements">
		<?php print theme('wistar_vertical_tabs');?>
		<div class="content">			
			<?php print theme('wistar_content_heading', $node);?>
			<div id="node-<?php print $node->nid;?>" class="node">
				<?php if(isset($node->field_intro_text[0]['value']) && $node->field_intro_text[0]['value']): ?>
					<div class="section first">
						<?php print $node->field_intro_text[0]['value'] ?>
					</div>
				<?php endif;?>
				<div class="section">
					<?php $infographic_dim = image_get_info($node->field_infographic_image[0]['filepath']); ?>
					<div class="infographic" style="height: <?php print $infographic_dim['height'] . 'px';?>; width: <?php print $infographic_dim['width'] . 'px';?>; background: url('/<?php print $node->field_infographic_image[0]['filepath']; ?>') 0 0 no-repeat;">
						<?php foreach($node->field_number_labels as $idx => $label): ?>
							<div class="label label-<?php print $idx?>">
								<?php print $label['value']; ?>
							</div>
						<?php endforeach; ?>
					</div>
				</div>
				<?php print theme('wistar_content_callouts', $node); ?>									
			</div>
		</div>
	</div>
</div>