/** * Constructs a FeedsEnclosure object. * * @param string $uri * A path to a local file or a URL to a remote document. * @param string $mime_type * (optional) The mime type of the resource. If not provided, the mime type * will be guessed based on the file name. */ public function __construct($uri, $mime_type = NULL) { $this->uri = $uri; if ($mime_type) { $this->mimeType = $mime_type; } else { $this->mimeType = file_get_mimetype($uri); } }
public function actionCreate() { if (isset($_POST['phone']) & isset($_POST['title']) & isset($_POST['content']) & isset($_POST['place']) & isset($_POST['create_time']) & isset($_POST['uid'])) { //用户积分修改 $u = user_load($_POST['uid']); $edit = array('field_jifen' => array('und' => array(0 => array('value' => $u->field_jifen['und'][0]['value'] + 3)))); user_save($u, $edit); $node->title = $_POST['title']; $node->field_phone['und'][0]['value'] = $_POST['phone']; $node->type = "sr"; $node->body['und'][0]['value'] = $_POST['content']; $node->uid = $_POST['uid']; $node->language = 'zh-hans'; $node->status = 0; //(1 or 0): published or not $node->promote = 0; //(1 or 0): promoted to front page $node->comment = 2; // 0 = comments disabled, 1 = read only, 2 = read/write //$node->field_riq['und'][0]['value'] =date('Y:m:d H:i:s'); $node->field_riq['und'][0]['value'] = $_POST['create_time']; $node->field_src['und'][0]['value'] = $_POST['place']; $node->field_status['und'][0]['value'] = '处理中'; //默认为匿名 if (isset($_POST['name'])) { $node->field_shimin['und'][0]['value'] = $_POST['name']; } $image = CUploadedFile::getInstanceByName('img'); if (is_object($image) && get_class($image) === 'CUploadedFile') { $dir = Yii::getPathOfAlias('webroot') . '/assets/urban/'; //$ext = $image->getExtensionName(); $fileName = uniqid() . '.jpg'; $name = $dir . $fileName; $image->saveAs($name, true); $file = (object) array('uid' => $_POST['uid'], 'uri' => $name, 'filemime' => file_get_mimetype($filepath), 'status' => 1); $file = file_copy($file, 'public://pictures/urban'); $node->field_tux['und'][0] = (array) $file; } $node = node_submit($node); // Prepare node for saving node_save($node); $basic = new basic(); $basic->error_code = 0; //$basic->error_msg="no input parameters"; $jsonObj = CJSON::encode($basic); echo $jsonObj; } else { $basic = new basic(); $basic->error_code = 1; $basic->error_msg = "no input parameters"; $jsonObj = CJSON::encode($basic); echo $jsonObj; } }
/** * Convert a URI into a file object. * * @param string $uri * A file URI. * * @return object * A file object with the uri, filemime, and filesize properties defined. */ public static function getFileFromUri($uri) { // Allow the URI to be altered. drupal_alter('favicon_file_uri', $uri); $file = new stdClass(); $file->uri = $uri; $file->filemime = file_get_mimetype($uri); $file->filesize = @filesize($uri); static::validateFile($file); // Allow modules to alter the generated favicon file. drupal_alter('favicon_file', $file); return $file; }
/** * Implements hook_html_head_alter(). */ function carbon_html_head_alter(&$head_elements) { // If the theme's info file contains the custom theme setting // default_favicon_path, change the favicon <link> tag to reflect that path. if (($default_favicon_path = theme_get_setting('default_favicon_path')) && theme_get_setting('default_favicon')) { $favicon_url = file_create_url(path_to_theme() . '/' . $default_favicon_path); } else { if (module_exists('gardens_misc')) { $favicon_url = file_create_url(drupal_get_path('module', 'gardens_misc') . '/images/gardens.ico'); } } if (!empty($favicon_url)) { $favicon_mimetype = file_get_mimetype($favicon_url); foreach ($head_elements as &$element) { if (isset($element['#attributes']['rel']) && $element['#attributes']['rel'] == 'shortcut icon') { $element['#attributes']['href'] = $favicon_url; $element['#attributes']['type'] = $favicon_mimetype; } } } }
public function actionCreate() { if (isset($_POST['phone']) & isset($_POST['title']) & isset($_POST['content']) & isset($_POST['place']) & isset($_POST['create_time'])) { $node->title = $_POST['title']; $node->field_phone['und'][0]['value'] = $_POST['phone']; $node->type = "sr"; $node->body['und'][0]['value'] = $_POST['content']; $node->uid = 1; $node->language = 'zh-hans'; $node->status = 0; //(1 or 0): published or not $node->promote = 0; //(1 or 0): promoted to front page $node->comment = 2; // 0 = comments disabled, 1 = read only, 2 = read/write $node->field_riq['und'][0]['value'] = date('Y:m:d H:i:s'); $node->field_src['und'][0]['value'] = $_POST['place']; $node->field_status['und'][0]['value'] = '处理中'; if (isset($_POST['name'])) { $node->field_shimin['und'][0]['value'] = $_POST['name']; } $image = CUploadedFile::getInstanceByName('img'); if (is_object($image) && get_class($image) === 'CUploadedFile') { $dir = Yii::getPathOfAlias('webroot') . '/assets/pic/'; //$ext = $image->getExtensionName(); $fileName = uniqid() . '.jpg'; $name = $dir . $fileName; $image->saveAs($name, true); $file = (object) array('uid' => 1, 'uri' => $name, 'filemime' => file_get_mimetype($filepath), 'status' => 1); $file = file_copy($file, 'public://pictures/'); $node->field_tux['und'][0] = (array) $file; } $node = node_submit($node); // Prepare node for saving node_save($node); echo '1'; } else { echo '0'; } }
function sp2015_file_link($variables) { $file = $variables['file']; $icon_directory = $variables['icon_directory']; $url = file_create_url($file->uri); // Human-readable names, for use as text-alternatives to icons. $mime_name = array('application/msword' => t('Microsoft Office document icon'), 'application/vnd.ms-excel' => t('Office spreadsheet icon'), 'application/vnd.ms-powerpoint' => t('Office presentation icon'), 'application/pdf' => t('PDF icon'), 'video/quicktime' => t('Movie icon'), 'audio/mpeg' => t('Audio icon'), 'audio/wav' => t('Audio icon'), 'image/jpeg' => t('Image icon'), 'image/png' => t('Image icon'), 'image/gif' => t('Image icon'), 'application/zip' => t('Package icon'), 'text/html' => t('HTML icon'), 'text/plain' => t('Plain text icon'), 'application/octet-stream' => t('Binary Data')); $fileclass = substr($file->filename, -3); $mimetype = file_get_mimetype($file->uri); $icon = theme('file_icon', array('file' => $file, 'icon_directory' => $icon_directory, 'alt' => !empty($mime_name[$mimetype]) ? $mime_name[$mimetype] : t('File'))); // Set options as per anchor format described at // http://microformats.org/wiki/file-format-examples $options = array('attributes' => array('type' => $file->filemime . '; length=' . $file->filesize)); // Use the description as the link text if available. if (empty($file->description)) { $link_text = $file->filename . ' (' . format_size($file->filesize) . ')'; } else { $link_text = $file->description . format_size($file->filesize); $options['attributes']['title'] = check_plain($file->filename); } return '<span class="file ' . $fileclass . '">' . l($link_text, $url, $options) . '</span>'; }
/** * Funzione che consente di creare automaticamente un contenuto drupal con le immagini jpg caricate in temp_img * e i dati exif ricavati da esse. * * @param $lat * @param $lng * @param $fileName * */ function createContentFromImage($lat, $lng, $fileName) { $node = new stdClass(); // Create a new node object Or page, or whatever content type you like $node->type = "exif_data"; // Set some default values node_object_prepare($node); $node->language = "en"; $node->uid = 1; $coords = (object) array('lat' => $lat, 'lng' => $lng); $node->field_posizione['und'][0] = (array) $coords; //@ToDo here you have to substitute the path $file_path = "/var/www/.." . $fileName; $count_photo = count($file_path); for ($i = 0; $i < $count_photo; $i++) { if (getimagesize($file_path)) { $file_gallery = (object) array('uid' => 0, 'uri' => $file_path, 'filemime' => file_get_mimetype($file_path), 'status' => 1); //substitute "your_destination_folder" with a folder name try { file_copy($file_gallery, 'public://your_destination_folder'); $node->field_image['und'][0] = (array) $file_gallery; echo "File correctly copied"; } catch (Exception $e) { echo $e->getMessage(); } } } //$node = node_submit($node); // Prepare node for saving if ($node = node_submit($node)) { // Prepare node for saving node_save($node); //Drupal node saving function call $status = "Content created correctly" . ""; } else { $status = "Something went wrong during the node submitting"; } echo $status; }
/** * {@inheritdoc} */ public static function preCreate(EntityStorageInterface $storage, array &$values) { // Automatically detect filename if not set. if (!isset($values['filename']) && isset($values['uri'])) { $values['filename'] = drupal_basename($values['uri']); } // Automatically detect filemime if not set. if (!isset($values['filemime']) && isset($values['uri'])) { $values['filemime'] = file_get_mimetype($values['uri']); } }
/** * Send the e-mail message. * * @see drupal_mail() * * @param $message * A message array, as described in hook_mail_alter(). * @return * TRUE if the mail was successfully accepted, otherwise FALSE. */ public function mail(array $message) { $to = $message['to']; $from = $message['from']; $body = $message['body']; $headers = $message['headers']; $subject = $message['subject']; // Create a new PHPMailer object - autoloaded from registry. $mailer = new PHPMailer(); // Turn on debugging, if requested. if ($this->smtpConfig->get('smtp_debugging') == 1) { $mailer->SMTPDebug = TRUE; } // Set the from name. $from_name = $this->smtpConfig->get('smtp_fromname'); if (empty($from_name)) { // If value is not defined in settings, use site_name. $from_name = \Drupal::config('system.site')->get('name'); } // Set SMTP module email from. if (\Drupal::service('email.validator')->isValid($this->smtpConfig->get('smtp_from'))) { $from = $this->smtpConfig->get('smtp_from'); $headers['Sender'] = $from; $headers['Return-Path'] = $from; $headers['Reply-To'] = $from; } // Defines the From value to what we expect. $mailer->From = $from; $mailer->FromName = $from_name; $mailer->Sender = $from; // Create the list of 'To:' recipients. $torecipients = explode(',', $to); foreach ($torecipients as $torecipient) { $to_comp = $this->_get_components($torecipient); $mailer->AddAddress($to_comp['email'], $to_comp['name']); } // Parse the headers of the message and set the PHPMailer object's settings // accordingly. foreach ($headers as $key => $value) { //watchdog('error', 'Key: ' . $key . ' Value: ' . $value); switch (strtolower($key)) { case 'from': if ($from == NULL or $from == '') { // If a from value was already given, then set based on header. // Should be the most common situation since drupal_mail moves the // from to headers. $from = $value; $mailer->From = $value; // then from can be out of sync with from_name ! $mailer->FromName = ''; $mailer->Sender = $value; } break; case 'content-type': // Parse several values on the Content-type header, storing them in an array like // key=value -> $vars['key']='value' $vars = explode(';', $value); foreach ($vars as $i => $var) { if ($cut = strpos($var, '=')) { $new_var = trim(strtolower(substr($var, $cut + 1))); $new_key = trim(substr($var, 0, $cut)); unset($vars[$i]); $vars[$new_key] = $new_var; } } // Set the charset based on the provided value, otherwise set it to UTF-8 (which is Drupals internal default). $mailer->CharSet = isset($vars['charset']) ? $vars['charset'] : 'UTF-8'; // If $vars is empty then set an empty value at index 0 to avoid a PHP warning in the next statement $vars[0] = isset($vars[0]) ? $vars[0] : ''; switch ($vars[0]) { case 'text/plain': // The message includes only a plain text part. $mailer->IsHTML(FALSE); $content_type = 'text/plain'; break; case 'text/html': // The message includes only an HTML part. $mailer->IsHTML(TRUE); $content_type = 'text/html'; break; case 'multipart/related': // Get the boundary ID from the Content-Type header. $boundary = $this->_get_substring($value, 'boundary', '"', '"'); // The message includes an HTML part w/inline attachments. $mailer->ContentType = $content_type = 'multipart/related; boundary="' . $boundary . '"'; break; case 'multipart/alternative': // The message includes both a plain text and an HTML part. $mailer->ContentType = $content_type = 'multipart/alternative'; // Get the boundary ID from the Content-Type header. $boundary = $this->_get_substring($value, 'boundary', '"', '"'); break; case 'multipart/mixed': // The message includes one or more attachments. $mailer->ContentType = $content_type = 'multipart/mixed'; // Get the boundary ID from the Content-Type header. $boundary = $this->_get_substring($value, 'boundary', '"', '"'); break; default: // Everything else is unsuppored by PHPMailer. drupal_set_message(t('The %header of your message is not supported by PHPMailer and will be sent as text/plain instead.', array('%header' => "Content-Type: {$value}")), 'error'); watchdog('smtp', 'The %header of your message is not supported by PHPMailer and will be sent as text/plain instead.', array('%header' => "Content-Type: {$value}"), WATCHDOG_ERROR); // Force the Content-Type to be text/plain. $mailer->IsHTML(FALSE); $content_type = 'text/plain'; } break; case 'reply-to': // Only add a "reply-to" if it's not the same as "return-path". if ($value != $headers['Return-Path']) { $reply_to_comp = $this->_get_components($value); $mailer->AddReplyTo($reply_to_comp['email'], $reply_to_comp['name']); } break; case 'content-transfer-encoding': $mailer->Encoding = $value; break; case 'return-path': $mailer->Sender = $value; break; case 'mime-version': case 'x-mailer': // Let PHPMailer specify these. break; case 'errors-to': $mailer->AddCustomHeader('Errors-To: ' . $value); break; case 'cc': $ccrecipients = explode(',', $value); foreach ($ccrecipients as $ccrecipient) { $cc_comp = $this->_get_components($ccrecipient); $mailer->AddCC($cc_comp['email'], $cc_comp['name']); } break; case 'bcc': $bccrecipients = explode(',', $value); foreach ($bccrecipients as $bccrecipient) { $bcc_comp = $this->_get_components($bccrecipient); $mailer->AddBCC($bcc_comp['email'], $bcc_comp['name']); } break; default: // The header key is not special - add it as is. $mailer->AddCustomHeader($key . ': ' . $value); } } /** * TODO * Need to figure out the following. * * Add one last header item, but not if it has already been added. * $errors_to = FALSE; * foreach ($mailer->CustomHeader as $custom_header) { * if ($custom_header[0] = '') { * $errors_to = TRUE; * } * } * if ($errors_to) { * $mailer->AddCustomHeader('Errors-To: '. $from); * } */ // Add the message's subject. $mailer->Subject = $subject; // Processes the message's body. switch ($content_type) { case 'multipart/related': $mailer->Body = $body; // TODO: Figure out if there is anything more to handling this type. break; case 'multipart/alternative': // Split the body based on the boundary ID. $body_parts = $this->_boundary_split($body, $boundary); foreach ($body_parts as $body_part) { // If plain/text within the body part, add it to $mailer->AltBody. if (strpos($body_part, 'text/plain')) { // Clean up the text. $body_part = trim($this->_remove_headers(trim($body_part))); // Include it as part of the mail object. $mailer->AltBody = $body_part; } elseif (strpos($body_part, 'text/html')) { // Clean up the text. $body_part = trim($this->_remove_headers(trim($body_part))); // Include it as part of the mail object. $mailer->Body = $body_part; } } break; case 'multipart/mixed': // Split the body based on the boundary ID. $body_parts = $this->_boundary_split($body, $boundary); // Determine if there is an HTML part for when adding the plain text part. $text_plain = FALSE; $text_html = FALSE; foreach ($body_parts as $body_part) { if (strpos($body_part, 'text/plain')) { $text_plain = TRUE; } if (strpos($body_part, 'text/html')) { $text_html = TRUE; } } foreach ($body_parts as $body_part) { // If test/plain within the body part, add it to either // $mailer->AltBody or $mailer->Body, depending on whether there is // also a text/html part ot not. if (strpos($body_part, 'multipart/alternative')) { // Get boundary ID from the Content-Type header. $boundary2 = $this->_get_substring($body_part, 'boundary', '"', '"'); // Clean up the text. $body_part = trim($this->_remove_headers(trim($body_part))); // Split the body based on the boundary ID. $body_parts2 = $this->_boundary_split($body_part, $boundary2); foreach ($body_parts2 as $body_part2) { // If plain/text within the body part, add it to $mailer->AltBody. if (strpos($body_part2, 'text/plain')) { // Clean up the text. $body_part2 = trim($this->_remove_headers(trim($body_part2))); // Include it as part of the mail object. $mailer->AltBody = $body_part2; $mailer->ContentType = 'multipart/mixed'; } elseif (strpos($body_part2, 'text/html')) { // Get the encoding. $body_part2_encoding = $this->_get_substring($body_part2, 'Content-Transfer-Encoding', ' ', "\n"); // Clean up the text. $body_part2 = trim($this->_remove_headers(trim($body_part2))); // Check whether the encoding is base64, and if so, decode it. if (Unicode::strtolower($body_part2_encoding) == 'base64') { // Include it as part of the mail object. $mailer->Body = base64_decode($body_part2); // Ensure the whole message is recoded in the base64 format. $mailer->Encoding = 'base64'; } else { // Include it as part of the mail object. $mailer->Body = $body_part2; } $mailer->ContentType = 'multipart/mixed'; } } } elseif (strpos($body_part, 'text/plain')) { // Clean up the text. $body_part = trim($this->_remove_headers(trim($body_part))); if ($text_html) { $mailer->AltBody = $body_part; $mailer->IsHTML(TRUE); $mailer->ContentType = 'multipart/mixed'; } else { $mailer->Body = $body_part; $mailer->IsHTML(FALSE); $mailer->ContentType = 'multipart/mixed'; } } elseif (strpos($body_part, 'text/html')) { // Clean up the text. $body_part = trim($this->_remove_headers(trim($body_part))); // Include it as part of the mail object. $mailer->Body = $body_part; $mailer->IsHTML(TRUE); $mailer->ContentType = 'multipart/mixed'; } elseif (strpos($body_part, 'Content-Disposition: attachment;') && !isset($message['params']['attachments'])) { $file_path = $this->_get_substring($body_part, 'filename=', '"', '"'); $file_name = $this->_get_substring($body_part, ' name=', '"', '"'); $file_encoding = $this->_get_substring($body_part, 'Content-Transfer-Encoding', ' ', "\n"); $file_type = $this->_get_substring($body_part, 'Content-Type', ' ', ';'); if (file_exists($file_path)) { if (!$mailer->AddAttachment($file_path, $file_name, $file_encoding, $file_type)) { drupal_set_message(t('Attahment could not be found or accessed.')); } } else { // Clean up the text. $body_part = trim($this->_remove_headers(trim($body_part))); if (Unicode::strtolower($file_encoding) == 'base64') { $attachment = base64_decode($body_part); } elseif (Unicode::strtolower($file_encoding) == 'quoted-printable') { $attachment = quoted_printable_decode($body_part); } else { $attachment = $body_part; } $attachment_new_filename = \Drupal::service('file_system')->tempnam('temporary://', 'smtp'); $file_path = file_save_data($attachment, $attachment_new_filename, FILE_EXISTS_REPLACE); $real_path = \Drupal::service('file_system')->realpath($file_path->uri); if (!$mailer->AddAttachment($real_path, $file_name)) { drupal_set_message(t('Attachment could not be found or accessed.')); } } } } break; default: $mailer->Body = $body; break; } // Process mimemail attachments, which are prepared in mimemail_mail(). if (isset($message['params']['attachments'])) { foreach ($message['params']['attachments'] as $attachment) { if (isset($attachment['filecontent'])) { $mailer->AddStringAttachment($attachment['filecontent'], $attachment['filename'], 'base64', $attachment['filemime']); } if (isset($attachment['filepath'])) { $filename = isset($attachment['filename']) ? $attachment['filename'] : basename($attachment['filepath']); $filemime = isset($attachment['filemime']) ? $attachment['filemime'] : file_get_mimetype($attachment['filepath']); $mailer->AddAttachment($attachment['filepath'], $filename, 'base64', $filemime); } } } // Set the authentication settings. $username = $this->smtpConfig->get('smtp_username'); $password = $this->smtpConfig->get('smtp_password'); // If username and password are given, use SMTP authentication. if ($username != '' && $password != '') { $mailer->SMTPAuth = TRUE; $mailer->Username = $username; $mailer->Password = $password; } // Set the protocol prefix for the smtp host. switch ($this->smtpConfig->get('smtp_protocol')) { case 'ssl': $mailer->SMTPSecure = 'ssl'; break; case 'tls': $mailer->SMTPSecure = 'tls'; break; default: $mailer->SMTPSecure = ''; } // Set other connection settings. $mailer->Host = $this->smtpConfig->get('smtp_host') . ';' . $this->smtpConfig->get('smtp_hostbackup'); $mailer->Port = $this->smtpConfig->get('smtp_port'); $mailer->Mailer = 'smtp'; $mailerArr = array('mailer' => $mailer, 'to' => $to, 'from' => $from); if ($this->smtpConfig->get('smtp_queue')) { watchdog('smtp', 'Queue sending mail to: @to', array('@to' => $to)); smtp_send_queue($mailerArr); } else { return _smtp_mailer_send($mailerArr); } return TRUE; }
//dd($items); ?> <?php static $videojs_sources; ?> <?php $codecs = array('video/mp4' => 'avc1.42E01E, mp4a.40.2', 'video/webm' => 'vp8, vorbis', 'video/ogg' => 'theora, vorbis', 'video/ogv' => 'theora, vorbis', 'video/quicktime' => 'avc1.42E01E, mp4a.40.2'); ?> <?php foreach ($video->files as $filetype => $file) { ?> <?php $filepath = $file->url; ?> <?php $mimetype = file_get_mimetype($file->filename); ?> <?php if (array_key_exists($mimetype, $codecs)) { ?> <?php $mimetype = $mimetype == 'video/quicktime' ? 'video/mp4' : $mimetype; ?> <?php if ($mimetype == 'video/mp4' || $mimetype == 'video/flv') { $flash = $filepath; } ?> <?php $videojs_sources .= "<source src=\"{$filepath}\" type='{$mimetype}; codecs=\"" . $codecs[$mimetype] . "\"' />"; ?>
/** * An adaptation of file_save_upload() that includes more verbose errors. * * @param string $source * A string specifying the filepath or URI of the uploaded file to save. * * @return stdClass * The saved file object. * * @throws \RestfulBadRequestException * @throws \RestfulServiceUnavailable * * @see file_save_upload() */ protected function fileSaveUpload($source) { static $upload_cache; $account = $this->getAccount(); $options = $this->getPluginKey('options'); $validators = $options['validators']; $destination = $options['scheme'] . "://"; $replace = $options['replace']; // Return cached objects without processing since the file will have // already been processed and the paths in _FILES will be invalid. if (isset($upload_cache[$source])) { return $upload_cache[$source]; } // Make sure there's an upload to process. if (empty($_FILES['files']['name'][$source])) { return NULL; } // Check for file upload errors and return FALSE if a lower level system // error occurred. For a complete list of errors: // See http://php.net/manual/features.file-upload.errors.php. switch ($_FILES['files']['error'][$source]) { case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: $message = format_string('The file %file could not be saved, because it exceeds %maxsize, the maximum allowed size for uploads.', array('%file' => $_FILES['files']['name'][$source], '%maxsize' => format_size(file_upload_max_size()))); throw new \RestfulBadRequestException($message); case UPLOAD_ERR_PARTIAL: case UPLOAD_ERR_NO_FILE: $message = format_string('The file %file could not be saved, because the upload did not complete.', array('%file' => $_FILES['files']['name'][$source])); throw new \RestfulBadRequestException($message); case UPLOAD_ERR_OK: // Final check that this is a valid upload, if it isn't, use the // default error handler. if (is_uploaded_file($_FILES['files']['tmp_name'][$source])) { break; } // Unknown error default: $message = format_string('The file %file could not be saved. An unknown error has occurred.', array('%file' => $_FILES['files']['name'][$source])); throw new \RestfulServiceUnavailable($message); } // Begin building file object. $file = new stdClass(); $file->uid = $account->uid; $file->status = 0; $file->filename = trim(drupal_basename($_FILES['files']['name'][$source]), '.'); $file->uri = $_FILES['files']['tmp_name'][$source]; $file->filemime = file_get_mimetype($file->filename); $file->filesize = $_FILES['files']['size'][$source]; $extensions = ''; if (isset($validators['file_validate_extensions'])) { if (isset($validators['file_validate_extensions'][0])) { // Build the list of non-munged extensions if the caller provided them. $extensions = $validators['file_validate_extensions'][0]; } else { // If 'file_validate_extensions' is set and the list is empty then the // caller wants to allow any extension. In this case we have to remove the // validator or else it will reject all extensions. unset($validators['file_validate_extensions']); } } else { // No validator was provided, so add one using the default list. // Build a default non-munged safe list for file_munge_filename(). $extensions = 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp'; $validators['file_validate_extensions'] = array(); $validators['file_validate_extensions'][0] = $extensions; } if (!empty($extensions)) { // Munge the filename to protect against possible malicious extension hiding // within an unknown file type (ie: filename.html.foo). $file->filename = file_munge_filename($file->filename, $extensions); } // Rename potentially executable files, to help prevent exploits (i.e. will // rename filename.php.foo and filename.php to filename.php.foo.txt and // filename.php.txt, respectively). Don't rename if 'allow_insecure_uploads' // evaluates to TRUE. if (!variable_get('allow_insecure_uploads', 0) && preg_match('/\.(php|pl|py|cgi|asp|js)(\.|$)/i', $file->filename) && (substr($file->filename, -4) != '.txt')) { $file->filemime = 'text/plain'; $file->uri .= '.txt'; $file->filename .= '.txt'; // The .txt extension may not be in the allowed list of extensions. We have // to add it here or else the file upload will fail. if (!empty($extensions)) { $validators['file_validate_extensions'][0] .= ' txt'; // Unlike file_save_upload() we don't need to let the user know that // for security reasons, your upload has been renamed, since RESTful // will return the file name in the response. } } // If the destination is not provided, use the temporary directory. if (empty($destination)) { $destination = 'temporary://'; } // Assert that the destination contains a valid stream. $destination_scheme = file_uri_scheme($destination); if (!$destination_scheme || !file_stream_wrapper_valid_scheme($destination_scheme)) { $message = format_string('The file could not be uploaded, because the destination %destination is invalid.', array('%destination' => $destination)); throw new \RestfulServiceUnavailable($message); } $file->source = $source; // A URI may already have a trailing slash or look like "public://". if (substr($destination, -1) != '/') { $destination .= '/'; } $file->destination = file_destination($destination . $file->filename, $replace); // If file_destination() returns FALSE then $replace == FILE_EXISTS_ERROR and // there's an existing file so we need to bail. if ($file->destination === FALSE) { $message = format_string('The file %source could not be uploaded because a file by that name already exists in the destination %directory.', array('%source' => $source, '%directory' => $destination)); throw new \RestfulServiceUnavailable($message); } // Add in our check of the the file name length. $validators['file_validate_name_length'] = array(); // Call the validation functions specified by this function's caller. $errors = file_validate($file, $validators); // Check for errors. if (!empty($errors)) { $message = format_string('The specified file %name could not be uploaded.', array('%name' => $file->filename)); if (count($errors) > 1) { $message .= theme('item_list', array('items' => $errors)); } else { $message .= ' ' . array_pop($errors); } throw new \RestfulServiceUnavailable($message); } // Move uploaded files from PHP's upload_tmp_dir to Drupal's temporary // directory. This overcomes open_basedir restrictions for future file // operations. $file->uri = $file->destination; if (!drupal_move_uploaded_file($_FILES['files']['tmp_name'][$source], $file->uri)) { watchdog('file', 'Upload error. Could not move uploaded file %file to destination %destination.', array('%file' => $file->filename, '%destination' => $file->uri)); $message = 'File upload error. Could not move uploaded file.'; throw new \RestfulServiceUnavailable($message); } // Set the permissions on the new file. drupal_chmod($file->uri); // If we are replacing an existing file re-use its database record. if ($replace == FILE_EXISTS_REPLACE) { $existing_files = file_load_multiple(array(), array('uri' => $file->uri)); if (count($existing_files)) { $existing = reset($existing_files); $file->fid = $existing->fid; } } // If we made it this far it's safe to record this file in the database. if ($file = file_save($file)) { // Add file to the cache. $upload_cache[$source] = $file; return $file; } // Something went wrong, so throw a general exception. throw new \RestfulServiceUnavailable('Unknown error has occurred.'); }
* Theme file to handle HTML5 output. * * Variables passed. * $video is the video object. * $node is the node object. * * @TODO : Fallback to flash should be done nicely * */ ?> <!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --> <video width="<?php echo $video->player_width; ?>" autobuffer="<?php print $video->autobuffering; ?>" height="<?php echo $video->player_height; ?>" controls="controls" preload="auto" poster="<?php echo $video->thumbnail->url; ?>"> <?php //dd($items); ?> <?php static $videojs_sources; ?> <?php $codecs = array('video/mp4' => 'avc1.42E01E, mp4a.40.2', 'video/webm' => 'vp8, vorbis', 'video/ogg' => 'theora, vorbis', 'application/ogg' => 'theora, vorbis', 'video/ogv' => 'theora, vorbis', 'video/quicktime' => 'avc1.42E01E, mp4a.40.2'); ?> <?php foreach ($video->files as $filetype => $file): ?> <?php $filepath = $file->url; ?> <?php $mimetype = file_get_mimetype($file->filepath); ?> <?php if (array_key_exists($mimetype, $codecs)): ?> <?php $mimetype = ($mimetype == 'video/quicktime') ? 'video/mp4' : $mimetype; ?> <?php if ($mimetype == 'video/mp4' || $mimetype == 'video/flv') $flash = $filepath; ?> <?php $videojs_sources .= "<source src=\"$filepath\" type='$mimetype; codecs=\"" . $codecs[$mimetype] . "\"' />"; ?> <?php endif; ?> <?php endforeach; ?> <?php print $videojs_sources; ?> <!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --> <?php $video->player = 'flv'; ?> <?php $video->files->flv->url = $flash; ?> <?php echo theme('video_flv', array('video' => $video)); ?> </video>
/** * Update the DB with the new file info for a given release node. * * @param $nid * The node ID of the release node to update. * @param $files * Array of files to add to the release node. * @param $package_contents * Optional. Array of nids of releases contained in a release package. */ function package_release_update_node($nid, $files, $package_contents = array()) { global $drupal_root, $dest_root, $task; // PHP will cache the results of stat() and give us stale answers // here, unless we manually tell it otherwise! clearstatcache(); // Make sure we're back at the webroot so node_load() and node_save() // can always find any files they (and the hooks they invoke) need. if (!drupal_chdir($drupal_root)) { return FALSE; } // If the site is using DB replication, force this node_load() to use the // primary database to avoid node_load() failures. if (function_exists('db_set_ignore_slave')) { db_set_ignore_slave(); } // We don't want to waste too much RAM by leaving all these loaded nodes // in RAM, so we reset the node_load() cache each time we call it. $node = node_load($nid, NULL, TRUE); if (empty($node->nid)) { wd_err('node_load(@nid) failed', array('@nid' => $nid)); return FALSE; } foreach ($files as $file_path) { // Compute the metadata for this file that we care about. $full_path = $dest_root . '/' . $file_path; $file_name = basename($file_path); $file_date = filemtime($full_path); $file_size = filesize($full_path); $file_hash = md5_file($full_path); $file_mime = file_get_mimetype($full_path); // First, see if we already have this file for this release node $file_data = db_fetch_object(db_query("SELECT prf.* FROM {project_release_file} prf INNER JOIN {files} f ON prf.fid = f.fid WHERE prf.nid = %d AND f.filename = '%s'", $node->nid, $file_name)); // Insert or update the record in the DB as need. if (empty($file_data)) { // Don't have this file, insert a new record. db_query("INSERT INTO {files} (uid, filename, filepath, filemime, filesize, status, timestamp) VALUES (%d, '%s', '%s', '%s', %d, %d, %d)", $node->uid, $file_name, $file_path, $file_mime, $file_size, FILE_STATUS_PERMANENT, $file_date); $fid = db_last_insert_id('files', 'fid'); db_query("INSERT INTO {project_release_file} (fid, nid, filehash) VALUES (%d, %d, '%s')", $fid, $node->nid, $file_hash); } else { // Already have this file for this release, update it. db_query("UPDATE {files} SET uid = %d, filename = '%s', filepath = '%s', filemime = '%s', filesize = %d, status = %d, timestamp = %d WHERE fid = %d", $node->uid, $file_name, $file_path, $file_mime, $file_size, FILE_STATUS_PERMANENT, $file_date, $file_data->fid); db_query("UPDATE {project_release_file} SET filehash = '%s' WHERE fid = %d", $file_hash, $file_data->fid); } } // Store package contents if necessary. if (!empty($package_contents) && module_exists('project_package')) { foreach ($package_contents as $item_nid) { db_query("INSERT INTO {project_package_local_release_item} (package_nid, item_nid) VALUES (%d, %d)", $nid, $item_nid); } } // Don't auto-publish security updates. $security_update_tid = variable_get('project_release_security_update_tid', 0); if ($task == 'tag' && !empty($node->taxonomy[$security_update_tid])) { watchdog('package_security', 'Not auto-publishing security update release.', array(), WATCHDOG_NOTICE, l(t('view'), 'node/' . $node->nid)); return; } // Finally publish the node if it is currently unpublished. Instead of // directly updating {node}.status, we use node_save() so that other modules // which implement hook_nodeapi() will know that this node is now published. if (empty($node->status)) { $node->status = 1; node_save($node); } }
public function actionPic() { if (!isset($_POST['uid'])) { $basic = new basic(); $basic->error_code = 1; $basic->error_msg = "请登录"; $jsonObj = CJSON::encode($basic); echo $jsonObj; die(0); } $image = CUploadedFile::getInstanceByName('img'); if (is_object($image) && get_class($image) === 'CUploadedFile') { $dir = Yii::getPathOfAlias('webroot') . '/assets/upic/'; $fileName = uniqid() . '.jpg'; $name = $dir . $fileName; $image->saveAs($name, true); $account = user_load($_POST['uid']); $file = (object) array('uid' => $_POST['uid'], 'uri' => $name, 'filemime' => file_get_mimetype($filepath), 'status' => 1); $file = file_copy($file, 'public://pictures/upic'); $edit['picture'] = $file; user_save($account, $edit); $pic->error_code = 0; $pic->userheadimg = str_replace("public://", BigImg, $account->picture->uri); $pic->error_code = 0; } else { $pic->error_code = 2; $pic->error_msg = "上传头像失败"; } $jsonObj = CJSON::encode($pic); echo $jsonObj; }
$tplVars['feedlink'] = $GLOBALS['root']; $tplVars['feeddescription'] = sprintf(T_('Recent bookmarks posted to %s'), $GLOBALS['sitename']); $bookmarks =& $bookmarkservice->getBookmarks(0, 15, $userid, $cat, NULL, getSortOrder(), $watchlist); $bookmarks_tmp =& filter($bookmarks['bookmarks']); $bookmarks_tpl = array(); foreach (array_keys($bookmarks_tmp) as $key) { $row =& $bookmarks_tmp[$key]; $_link = $row['bAddress']; // Redirection option if ($GLOBALS['useredir']) { $_link = $GLOBALS['url_redir'] . $_link; } $_pubdate = date("r", strtotime($row['bDatetime'])); $uriparts = explode('.', $_link); $extension = end($uriparts); unset($uriparts); $enclosure = array(); if ($keys = multi_array_search($extension, $GLOBALS['filetypes'])) { $enclosure['mime'] = file_get_mimetype($_link); $enclosure['length'] = file_get_filesize($_link); } $bookmarks_tpl[] = array('title' => $row['bTitle'], 'link' => $_link, 'description' => $row['bDescription'], 'creator' => $row['username'], 'pubdate' => $_pubdate, 'tags' => $row['tags'], 'enclosure_mime' => $enclosure['mime'], 'enclosure_length' => $enclosure['length']); } unset($bookmarks_tmp); unset($bookmarks); $tplVars['bookmarks'] =& $bookmarks_tpl; $templateservice->loadTemplate('rss.tpl', $tplVars); if ($usecache) { // Cache output if existing copy has expired $cacheservice->End($hash); }
static function getAttachmentStruct($path) { $struct = array(); try { if (!@is_file($path)) { throw new Exception($path . ' is not a valid file.'); } $filename = basename($path); if (!function_exists('get_magic_quotes')) { function get_magic_quotes() { return FALSE; } } if (!function_exists('set_magic_quotes')) { function set_magic_quotes($value) { return TRUE; } } if (strnatcmp(phpversion(), '6') >= 0) { $magic_quotes = get_magic_quotes_runtime(); set_magic_quotes_runtime(0); } $file_buffer = file_get_contents($path); $file_buffer = chunk_split(base64_encode($file_buffer), 76, "\n"); if (strnatcmp(phpversion(), '6') >= 0) { set_magic_quotes_runtime($magic_quotes); } $mime_type = file_get_mimetype($path); if (!Mandrill::isValidContentType($mime_type)) { throw new Exception($mime_type . ' is not a valid content type (it should be ' . implode('*,', self::getValidContentTypes()) . ').'); } $struct['type'] = $mime_type; $struct['name'] = $filename; $struct['content'] = $file_buffer; } catch (Exception $e) { throw new Mandrill_Exception('Error creating the attachment structure: ' . $e->getMessage()); } return $struct; }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { parent::submitForm($form, $form_state); $config = $this->config($form_state['values']['config_key']); // Exclude unnecessary elements before saving. form_state_values_clean($form_state); unset($form_state['values']['var']); unset($form_state['values']['config_key']); $values = $form_state['values']; // If the user uploaded a new logo or favicon, save it to a permanent location // and use it in place of the default theme-provided file. if ($this->moduleHandler->moduleExists('file')) { if ($file = $values['logo_upload']) { unset($values['logo_upload']); $filename = file_unmanaged_copy($file->getFileUri()); $values['default_logo'] = 0; $values['logo_path'] = $filename; $values['toggle_logo'] = 1; } if ($file = $values['favicon_upload']) { unset($values['favicon_upload']); $filename = file_unmanaged_copy($file->getFileUri()); $values['default_favicon'] = 0; $values['favicon_path'] = $filename; $values['toggle_favicon'] = 1; } // If the user entered a path relative to the system files directory for // a logo or favicon, store a public:// URI so the theme system can handle it. if (!empty($values['logo_path'])) { $values['logo_path'] = $this->validatePath($values['logo_path']); } if (!empty($values['favicon_path'])) { $values['favicon_path'] = $this->validatePath($values['favicon_path']); } if (empty($values['default_favicon']) && !empty($values['favicon_path'])) { $values['favicon_mimetype'] = file_get_mimetype($values['favicon_path']); } } theme_settings_convert_to_config($values, $config)->save(); // Invalidate either the theme-specific cache tag or the global theme // settings cache tag, depending on whose settings were actually changed. if (isset($values['theme'])) { Cache::invalidateTags(array('theme' => $values['theme'])); } else { Cache::invalidateTags(array('theme_global_settings' => TRUE)); } }
/** * Sends the file's binary data to a user via HTTP and updates the database. * * @param $file_user * The file_user object from the uc_file_users. * @param $ip * The string containing the IP address the download is going to. */ protected function transferDownload($file_user, $ip) { // Create the response. $response = new BinaryFileResponse(); // Check if any hook_uc_file_transfer_alter() calls alter the download. $module_handler = $this->moduleHandler(); foreach ($module_handler->getImplementations('uc_file_transfer_alter') as $module) { $name = $module . '_uc_file_transfer_alter'; $file_user->full_path = $name($file_user, $ip, $file_user->fid, $file_user->full_path); } // This could get clobbered, so make a copy. $filename = $file_user->filename; // Gather relevant info about the file. $size = filesize($file_user->full_path); $mimetype = file_get_mimetype($filename); // Workaround for IE filename bug with multiple periods / multiple dots // in filename that adds square brackets to filename - // eg. setup.abc.exe becomes setup[1].abc.exe if (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) { $filename = preg_replace('/\\./', '%2e', $filename, substr_count($filename, '.') - 1); } // Check if HTTP_RANGE is sent by browser (or download manager). $range = NULL; if (isset($_SERVER['HTTP_RANGE'])) { if (substr($_SERVER['HTTP_RANGE'], 0, 6) == 'bytes=') { // Multiple ranges could be specified at the same time, // but for simplicity only serve the first range // See http://tools.ietf.org/id/draft-ietf-http-range-retrieval-00.txt list($range, $extra_ranges) = explode(',', substr($_SERVER['HTTP_RANGE'], 6), 2); } else { $response->headers->set('Status', '416 Requested Range Not Satisfiable'); $response->headers->set('Content-Range', 'bytes */' . $size); return $response; } } // Figure out download piece from range (if set). if (isset($range)) { list($seek_start, $seek_end) = explode('-', $range, 2); } // Set start and end based on range (if set), // else set defaults and check for invalid ranges. $seek_end = intval(empty($seek_end) ? $size - 1 : min(abs(intval($seek_end)), $size - 1)); $seek_start = intval(empty($seek_start) || $seek_end < abs(intval($seek_start)) ? 0 : max(abs(intval($seek_start)), 0)); // Only send partial content header if downloading a piece of the file (IE // workaround). if ($seek_start > 0 || $seek_end < $size - 1) { $response->headers->set('Status', '206 Partial Content'); } // Standard headers, including content-range and length $response->headers->set('Pragma', 'public'); $response->headers->set('Cache-Control', 'cache, must-revalidate'); $response->headers->set('Accept-Ranges', 'bytes'); $response->headers->set('Content-Range', 'bytes ' . $seek_start . '-' . $seek_end . '/' . $size); $response->headers->set('Content-Type', $mimetype); $response->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"'); $response->headers->set('Content-Length', $seek_end - $seek_start + 1); // Last-Modified is required for content served dynamically. $response->headers->set('Last-Modified', gmdate("D, d M Y H:i:s", filemtime($file_user->full_path)) . " GMT"); // Etag header is required for Firefox3 and other managers. $response->headers->set('ETag', md5($file_user->full_path)); // Open the file and seek to starting byte. $fp = fopen($file_user->full_path, 'rb'); fseek($fp, $seek_start); // Start buffered download. while (!feof($fp)) { // Reset time limit for large files. drupal_set_time_limit(0); // Push the data to the client. print fread($fp, UC_FILE_BYTE_SIZE); flush(); // Suppress PHP notice that occurs when output buffering isn't enabled. // The ob_flush() is needed because if output buffering *is* enabled, // clicking on the file download link won't download anything if the buffer // isn't flushed. @ob_flush(); } // Finished serving the file, close the stream and log the download // to the user table. fclose($fp); $this->logDownload($file_user, $ip); }
/** * Update the DB with the new file info for a given release node. * * @todo This assumes 1:1 relationship of release nodes to files. */ function package_release_update_node($nid, $file_path) { global $dest_root, $task; $full_path = $dest_root . '/' . $file_path; // PHP will cache the results of stat() and give us stale answers // here, unless we manually tell it otherwise! clearstatcache(); // Now that we have the official file, compute some metadata: $file_name = basename($file_path); $file_date = filemtime($full_path); $file_size = filesize($full_path); $file_hash = md5_file($full_path); $file_mime = file_get_mimetype($full_path); $uid = db_result(db_query("SELECT n.uid FROM {node} n WHERE n.nid = %d", $nid)); // Finally, save this file to the DB. // First, see if we already have a file for this release node $file_data = db_fetch_object(db_query("SELECT * FROM {project_release_file} WHERE nid = %d GROUP BY nid ORDER BY fid DESC", $nid)); if (empty($file_data)) { // Don't have an file data for this release, insert a new record. db_query("INSERT INTO {files} (uid, filename, filepath, filemime, filesize, status, timestamp) VALUES (%d, '%s', '%s', '%s', %d, %d, %d)", $uid, $file_name, $file_path, $file_mime, $file_size, FILE_STATUS_PERMANENT, $file_date); $fid = db_last_insert_id('files', 'fid'); db_query("INSERT INTO {project_release_file} (fid, nid, filehash) VALUES (%d, %d, '%s')", $fid, $nid, $file_hash); } else { // Already have a file for this release, update it. db_query("UPDATE {files} SET uid = %d, filename = '%s', filepath = '%s', filemime = '%s', filesize = %d, status = %d, timestamp = %d WHERE fid = %d", $uid, $file_name, $file_path, $file_mime, $file_size, FILE_STATUS_PERMANENT, $file_date, $file_data->fid); db_query("UPDATE {project_release_file} SET filehash = '%s' WHERE fid = %d", $file_hash, $file_data->fid); } // Don't auto-publish security updates. if ($task == 'tag' && db_result(db_query("SELECT COUNT(*) FROM {term_node} WHERE nid = %d AND tid = %d", $nid, SECURITY_UPDATE_TID))) { watchdog('package_security', "Not auto-publishing security update release.", array(), WATCHDOG_NOTICE, l(t('view'), 'node/' . $nid)); return; } // Finally publish the node if it is currently unpublished. Instead of // directly updating {node}.status, we use node_save() so that other modules // which implement hook_nodeapi() will know that this node is now published. // However, we don't want to waste too much RAM by leaving all these loaded // nodes in RAM, so we reset the node_load() cache each time we call it. $status = db_result(db_query("SELECT status from {node} WHERE nid = %d", $nid)); if (empty($status)) { // If the site is using DB replication, force this node_load() to use the // primary database to avoid node_load() failures. if (function_exists('db_set_ignore_slave')) { db_set_ignore_slave(); } $node = node_load($nid, NULL, TRUE); if (!empty($node->nid)) { $node->status = 1; node_save($node); } else { wd_err('node_load(@nid) failed', array('@nid' => $nid)); } } }
/** * 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; }
/** * Look in the content model for rules to run on the specified datastream. * * @param string $pid * @param string $dsid * @return boolean */ function get_and_do_datastream_rules($pid, $dsid, $file = '') { if (!user_access('ingest new fedora objects')) { drupal_set_message(t('You do not have permission to add datastreams.')); return FALSE; } $collection_object = new CollectionClass(); $content_model_list = $this->get_content_models_list($pid); foreach ($content_model_list as $content_model) { $content_model_xml = $this->getStream($content_model, variable_get('Islandora_Content_Model_DSID', 'ISLANDORACM'), 1); if (!empty($content_model_xml->display_in_fieldset->datastream)) { foreach ($content_model_xml->display_in_fieldset->datastream as $datastream) { if ($datastream['id'] == $dsid) { $collection_object->callMethods($file, $datastream->add_datastream_method); break; } } } if (!empty($_SESSION['fedora_ingest_files'])) { foreach ($_SESSION['fedora_ingest_files'] as $dsid => $createdFile) { $file_obj = new stdClass(); // $file->uid = $user->uid; $file_obj->status = 0; $file_obj->filename = substr($createdFile, strrpos($createdFile, '/')); $file_obj->filepath = $createdFile; $file_obj->filemime = file_get_mimetype($createdFile); $this->addStream($pid, $dsid, $file_obj); file_delete($createdFile); } $_SESSION['fedora_ingest_files'] = ''; } } }
?> </span>--> <?php } ?> <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
/** * Formats a message composed by drupal_mail(). * * @see http://api.drupal.org/api/drupal/includes--mail.inc/interface/MailSystemInterface/7 * * @param array $message * A message array holding all relevant details for the message. * * @return string * The message as it should be sent. */ public function format(array $message) { // Get default mail line endings and merge all lines in the e-mail body // separated by the mail line endings. $line_endings = Settings::get('mail_line_endings', PHP_EOL); $message['body'] = SafeMarkup::set(implode($line_endings, $message['body'])); // Get applicable format. $applicable_format = $this->getApplicableFormat($message); // Theme message if format is set to be HTML. if ($applicable_format == SWIFTMAILER_FORMAT_HTML) { $render = array('#theme' => isset($message['params']['theme']) ? $message['params']['theme'] : 'swiftmailer', '#message' => $message); $message['body'] = $this->renderer->renderRoot($render); if ($this->config['message']['convert_mode'] || !empty($message['params']['convert'])) { $converter = new Html2Text($message['body']); $message['plain'] = $converter->get_text(); } } // Process any images specified by 'image:' which are to be added later // in the process. All we do here is to alter the message so that image // paths are replaced with cid's. Each image gets added to the array // which keeps track of which images to embed in the e-mail. $embeddable_images = array(); preg_match_all('/"image:([^"]+)"/', $message['body'], $embeddable_images); for ($i = 0; $i < count($embeddable_images[0]); $i++) { $image_id = $embeddable_images[0][$i]; $image_path = trim($embeddable_images[1][$i]); $image_name = basename($image_path); if (Unicode::substr($image_path, 0, 1) == '/') { $image_path = Unicode::substr($image_path, 1); } $image = new stdClass(); $image->uri = $image_path; $image->filename = $image_name; $image->filemime = file_get_mimetype($image_path); $image->cid = rand(0, 9999999999.0); $message['params']['images'][] = $image; $message['body'] = preg_replace($image_id, 'cid:' . $image->cid, $message['body']); } return $message; }