コード例 #1
0
  /**
   * Add CSS information to the renderer.
   *
   * To facilitate previews over Views, CSS can now be added in a manner
   * that does not necessarily mean just using drupal_add_css. Therefore,
   * during the panel rendering process, this method can be used to add
   * css and make certain that ti gets to the proper location.
   *
   * The arguments should exactly match drupal_add_css().
   *
   * @see drupal_add_css
   */
  function add_css($filename, $type = 'module', $media = 'all', $preprocess = TRUE) {
    $path = file_create_path($filename);
    switch ($this->meta_location) {
      case 'standard':
        if ($path) {
          // Use CTools CSS add because it can handle temporary CSS in private
          // filesystem.
          ctools_include('css');
          ctools_css_add_css($filename, $type, $media, $preprocess);
        }
        else {
          drupal_add_css($filename, $type, $media, $preprocess);
        }
        break;
      case 'inline':
        if ($path) {
          $url = file_create_url($filename);
        }
        else {
          $url = base_path() . $filename;
        }

        $this->prefix .= '<link type="text/css" rel="stylesheet" media="' . $media . '" href="' . $url . '" />'."\n";
        break;
    }
  }
コード例 #2
0
ファイル: template.php プロジェクト: upei/drupal6-cms
function sunshine_build_css_cache($css_files)
{
    $data = '';
    // Create the css/ within the files folder.
    $csspath = file_create_path('css');
    $orgpath = drupal_get_path('theme', 'sunshine') . '/css/';
    file_check_directory($csspath, FILE_CREATE_DIRECTORY);
    // Build aggregate CSS file.
    foreach ($css_files as $key => $file) {
        $contents = drupal_load_stylesheet($orgpath . $file, TRUE);
        // Return the path to where this CSS file originated from.
        $base = base_path() . $orgpath;
        _drupal_build_css_path(NULL, $base);
        // Prefix all paths within this CSS file, ignoring external and absolute paths.
        $data .= preg_replace_callback('/url\\([\'"]?(?![a-z]+:|\\/+)([^\'")]+)[\'"]?\\)/i', '_drupal_build_css_path', $contents);
    }
    // Per the W3C specification at http://www.w3.org/TR/REC-CSS2/cascade.html#at-import,
    // @import rules must proceed any other style, so we move those to the top.
    $regexp = '/@import[^;]+;/i';
    preg_match_all($regexp, $data, $matches);
    $data = preg_replace($regexp, '', $data);
    $data = implode('', $matches[0]) . $data;
    $checksum = md5($data);
    $filename_cache = 'sunshine.cache.css';
    // Create the CSS file.
    if (!file_exists($csspath . '/' . $filename_cache) || md5(file_get_contents($csspath . '/' . $filename_cache)) != $checksum) {
        // drupal_set_message('Sunshine CSS cache has been rebuilt.');
        file_save_data($data, $csspath . '/' . $filename_cache, FILE_EXISTS_REPLACE);
    }
    return $csspath . '/' . $filename_cache;
}
コード例 #3
0
 /**
  * Transforms a path into a path within the site files folder, if needed.
  *
  * Eg, turns 'foo' into 'sites/default/foo'.
  * Absolute paths are unchanged.
  */
 function directoryPath(&$directory)
 {
     if (substr($directory, 0, 1) != '/') {
         // Relative, and so assumed to be in Drupal's files folder: prepend this to
         // the given directory.
         // sanity check. need to verify /files exists before we do anything. see http://drupal.org/node/367138
         $files = file_create_path();
         file_check_directory($files, FILE_CREATE_DIRECTORY);
         $directory = file_create_path($directory);
     }
 }
コード例 #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;
     }
 }
コード例 #5
0
?>
    
 
<div class="ppy" id="ppy1">
            <ul class="ppy-imglist">

			<?php 
$files = upload_load(node_load($nid));
$rows = array();
foreach ($files as $file) {
    if ($file->list) {
        $mime = explode('/', file_get_mimetype($file->filename));
        $type = $mime[0];
        switch ($type) {
            case 'image':
                $href = $file->fid ? file_create_url($file->filepath) : url(file_create_filename($file->filename, file_create_path()));
                ?>
 
                        <li>
                        <a href="<?php 
                print $href;
                ?>
">
                            <img src="<?php 
                print $href;
                ?>
" alt="<?php 
                print $file->description;
                ?>
" />
                        </a>
コード例 #6
0
ファイル: system.api.php プロジェクト: rolfington/drupal
/**
 * 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 $filepath
 *   String of the file's path.
 * @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()
 * @see upload_file_download()
 */
function hook_file_download($filepath)
{
    // Check if the file is controlled by the current module.
    $filepath = file_create_path($filepath);
    $result = db_query("SELECT f.* FROM {files} f INNER JOIN {upload} u ON f.fid = u.fid WHERE filepath = '%s'", $filepath);
    if ($file = db_fetch_object($result)) {
        if (!user_access('view uploaded files')) {
            return -1;
        }
        return array('Content-Type' => $file->filemime, 'Content-Length' => $file->filesize);
    }
}
コード例 #7
0
ファイル: FileFetcher.php プロジェクト: pounard/yamm
 /**
  * (non-PHPdoc)
  * @see Yamm_FileFetcherInterface::fetchArbitraryFile()
  */
 public function fetchArbitraryFile($filepath, $dest = 0, $replace = FALSE)
 {
     throw new Yamm_FileFetcher_CouldNotFetchException("Yamm_FileFetcherInterface::fetchArbitraryFile() must be rewritten.");
     // Fetch the real file as a temporary file.
     $src = $this->_fetch($filepath);
     $filename = end(explode('/', $filepath));
     // Create the new file destination. Use the $replace boolean to compute a
     // new file name if the the user asked for no file replace.
     $dest = file_destination(file_create_path($dest) . '/' . $filename, $replace ? FILE_EXISTS_REPLACE : FILE_EXISTS_RENAME);
     // Copy the temporary file as the real file.
     $error = !file_copy($src, $dest, $replace ? FILE_EXISTS_REPLACE : FILE_EXISTS_ERROR);
     // Throw our exception in case of any error.
     if ($error) {
         throw new Yamm_FileFetcher_CouldNotSaveException("File " . $src . " could not copied to " . $dest);
     }
     // In all case, remove the temporary file. Be silent here, whatever happens.
     // In case of unlink failure, only put a warning message in watchdog.
     if (!@unlink($src)) {
         watchdog('yamm', "Temporary file " . $src . " could not be deleted", NULL, WATCHDOG_WARNING);
     }
     // Return new file full path.
     return $dest;
 }
コード例 #8
0
ファイル: template.php プロジェクト: radpants/n2e
/**
* Displays file attachments as list items instead of in table
*/
function phptemplate_upload_attachments($files)
{
    $rows = array();
    foreach ($files as $file) {
        if ($file->list) {
            $href = $file->fid ? file_create_url($file->filepath) : url(file_create_filename($file->filename, file_create_path()));
            $text = $file->description ? $file->description : $file->filename;
            $rows[] = array(l($text, $href), format_size($file->filesize));
        }
    }
    foreach ($rows as $row) {
        $listfiles .= '<li>' . $row[0] . ' <em>(' . $row[1] . ')</em>' . '</li>';
    }
    return '<ul>' . $listfiles . '</ul>';
}
コード例 #9
0
ファイル: mniblogpub.php プロジェクト: freighthouse/code
/**
 * Moves a PDF file to the appropriate location
 *
 * @param string $filename
 */
function move_pdf($filename)
{
    global $mniblogpub_props;
    // Get all our names and directories
    $full_src = $mniblogpub_props["mniblogpub.shared"]["bloghome"] . "/pdfs/" . $filename;
    $orig_src = $full_src;
    $dst_dir = file_directory_path() . "/" . $mniblogpub_props["mniblogpub.php"]["dir.pdf.drupal"];
    $full_dst = $dst_dir . "/" . $filename;
    $dir_perms = !is_dir($dst_dir);
    // Check our path
    $p = file_create_path($dst_dir);
    if (!file_check_directory($p, FILE_CREATE_DIRECTORY)) {
        if (!file_check_directory($p, FILE_MODIFY_PERMISSIONS)) {
            print "ERROR: Could create pdfs directory at: " . $dst_dir . "\n";
            exit(5);
        }
    }
    if ($dir_perms) {
        if (!chgrp($dst_dir, "www-data")) {
            print "WARN: Could not change dir to www-data group. " . $dst_dir . "\n";
        }
        if (!chmod($dst_dir, 0775)) {
            print "WARN: Could not change permissions for dir. " . $dst_dir . "\n";
        }
    }
    // Error Checking
    if (!file_copy($full_src, $full_dst, FILE_EXISTS_REPLACE)) {
        print "ERROR: Could not move file " . $full_src . "\n";
        exit(5);
    }
    if (!file_exists($full_dst)) {
        print "ERROR: File not actually moved. " . $full_src . "\n";
        exit(5);
    }
    if (!chgrp($full_dst, "www-data")) {
        print "WARN: Could not change file to www-data group. " . $full_dst . "\n";
    }
    if (!chmod($full_dst, 0664)) {
        print "WARN: Could not change permissions for file. " . $full_dst . "\n";
    }
    $details = stat($full_dst);
    $file = new stdClass();
    $file->filename = basename($full_dst);
    $file->filepath = $full_dst;
    $file->filemime = file_get_mimetype($full_dst);
    $file->filesize = $details['size'];
    $file->filesource = basename($full_dst);
    $file->uid = $mniblogpub_props["mniblogpub.php"]["user.use"] == 1 ? $mniblogpub_props["mniblogpub.php"]["user.id"] : 1;
    $file->status = FILE_STATUS_PERMANENT;
    $file->timestamp = time();
    $file->list = 1;
    $file->new = true;
    drupal_write_record('files', $file);
    if ($file != null && $file) {
        if (!unlink($orig_src)) {
            // !!! NOTE:
            // I don't think it's necessary to exit out here. I'm
            // commenting this out for now. If it causes errors later,
            // come back here. -Gerg
            // print "ERROR: Could not remove src file at: " . $orig_src;
            // exit(5);
            print "WARN: Could not remove src file at: " . $orig_src . "\n";
        }
    } else {
        print "ERROR: Error saving file object in Drupal. " . $full_src . "\n";
        exit(5);
    }
    file_set_status($file, 1);
    return $file;
}
コード例 #10
0
ファイル: template.php プロジェクト: haxelsson/flm02
/**
 * 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;
}
コード例 #11
0
 /**
  * Attaches a file to the image node
  *
  * @param int $nid ["path","0"]
  *  The nid of the image to update
  * @param object $file ["data"]
  *  The file object
  * @return object
  *
  * @Access(callback='DocuWalkPictureResource::access', args={'update'}, appendArgs=true)
  * @RESTRequestParser(mime='image/*', parser='RESTServer::fileRecieve')
  */
 public static function uploadFile($nid, $file)
 {
     global $user;
     $node = node_load($nid);
     // Mark old file as temporary, then it'll be removed on next cron run, and we don't have to bother
     // ourselves with the business of deleting the file and the database entry for it
     if (!empty($node->field_picture) && $node->field_picture[0]['fid']) {
         $old_file = (object) $node->field_picture[0];
         file_set_status($old_file, FILE_STATUS_TEMPORARY);
     }
     $dir = file_directory_path() . '/pictures';
     if (!file_exists($dir)) {
         mkdir($dir);
     }
     $file->uid = $user->uid;
     $file->status = FILE_STATUS_PERMANENT;
     $destination = file_destination(file_create_path($dir . '/' . $file->filename));
     rename($file->filepath, $destination);
     $file->filepath = $destination;
     drupal_write_record('files', $file, array('fid'));
     $node->field_picture = array((array) $file);
     node_save($node);
     return $file;
 }
コード例 #12
0
<?php

/**
 * Copy this file to your drupal installation root and run from a web browser
 *
 * BACK UP YOUR IMAGES FIRST!
 */
include_once 'includes/bootstrap.inc';
include_once 'includes/common.inc';
$fields = array('thumb_path' => 'thumbnail', 'preview_path' => 'preview', 'image_path' => '_original');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
if (function_exists('_image_insert')) {
    $result = db_query("SELECT * FROM {image}");
    while ($old_image = db_fetch_object($result)) {
        foreach ($fields as $old => $new) {
            $old_file = '';
            if (file_exists($old_image->{$old})) {
                $old_file = $old_image->{$old};
            } else {
                $old_file = file_create_path($old_image->{$old});
            }
            if ($old_file && $old_image->{$old} != '' && db_num_rows(db_query("SELECT fid FROM {files} WHERE nid=%d and filename='%s'", $old_image->nid, $new)) == 0) {
                _image_insert($old_image, $new, $old_file);
            }
        }
    }
}