當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DiscussHelper::getHash方法代碼示例

本文整理匯總了PHP中DiscussHelper::getHash方法的典型用法代碼示例。如果您正苦於以下問題:PHP DiscussHelper::getHash方法的具體用法?PHP DiscussHelper::getHash怎麽用?PHP DiscussHelper::getHash使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在DiscussHelper的用法示例。


在下文中一共展示了DiscussHelper::getHash方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: bindAttachments

 public function bindAttachments()
 {
     $mainframe = JFactory::getApplication();
     $config = DiscussHelper::getConfig();
     // @task: Do not allow file attachments if its disabled.
     if (!$config->get('attachment_questions')) {
         return false;
     }
     $allowed = explode(',', $config->get('main_attachment_extension'));
     $files = JRequest::getVar('filedata', array(), 'FILES');
     if (empty($files)) {
         return false;
     }
     $total = count($files['name']);
     // @rule: Handle empty files.
     if (empty($files['name'][0])) {
         $total = 0;
     }
     if ($total < 1) {
         return false;
     }
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.folder');
     jimport('joomla.utilities.utility');
     // @rule: Create default media path
     $path = DISCUSS_MEDIA . '/' . trim($config->get('attachment_path'), DIRECTORY_SEPARATOR);
     if (!JFolder::exists($path)) {
         JFolder::create($path);
         JFile::copy(DISCUSS_ROOT . '/index.html', $path . '/index.html');
     }
     $maxSize = (double) $config->get('attachment_maxsize') * 1024 * 1024;
     for ($i = 0; $i < $total; $i++) {
         $extension = JFile::getExt($files['name'][$i]);
         // Skip empty data's.
         if (!$extension) {
             continue;
         }
         // @rule: Check for allowed extensions
         if (!isset($extension) || !in_array(strtolower($extension), $allowed)) {
             $mainframe->enqueueMessage(JText::sprintf('COM_EASYDISCUSS_FILE_ATTACHMENTS_INVALID_EXTENSION', $files['name'][$i]), 'error');
             $this->setError(JText::sprintf('COM_EASYDISCUSS_FILE_ATTACHMENTS_INVALID_EXTENSION', $files['name'][$i]));
             return false;
         } else {
             $size = $files['size'][$i];
             // @rule: File size should not exceed maximum allowed size
             if (!empty($size) && ($size < $maxSize || $maxSize == 0)) {
                 $name = DiscussHelper::getHash($files['name'][$i] . DiscussHelper::getDate()->toMySQL());
                 $attachment = DiscussHelper::getTable('Attachments');
                 $attachment->set('path', $name);
                 $attachment->set('title', $files['name'][$i]);
                 $attachment->set('uid', $this->id);
                 $attachment->set('type', $this->getType());
                 $attachment->set('created', DiscussHelper::getDate()->toMySQL());
                 $attachment->set('published', true);
                 $attachment->set('mime', $files['type'][$i]);
                 $attachment->set('size', $size);
                 JFile::copy($files['tmp_name'][$i], $path . '/' . $name);
                 $attachment->store();
                 // Create a thumbnail if attachment is an image
                 if (DiscussHelper::getHelper('Image')->isImage($files['name'][$i])) {
                     require_once DISCUSS_CLASSES . '/simpleimage.php';
                     $image = new SimpleImage();
                     $image->load($files['tmp_name'][$i]);
                     $image->resizeToFill(160, 120);
                     $image->save($path . '/' . $name . '_thumb', $image->image_type);
                 }
             } else {
                 $mainframe->enqueueMessage(JText::sprintf('COM_EASYDISCUSS_FILE_ATTACHMENTS_MAX_SIZE_EXCLUDED', $files['name'][$i], $config->get('attachment_maxsize')), 'error');
                 $this->setError(JText::sprintf('COM_EASYDISCUSS_FILE_ATTACHMENTS_MAX_SIZE_EXCLUDED', $files['name'][$i], $config->get('attachment_maxsize')));
                 return false;
             }
         }
     }
     return true;
 }
開發者ID:pguilford,項目名稱:vcomcc,代碼行數:75,代碼來源:post.php

示例2: processEmails


//.........這裏部分代碼省略.........
                 jimport('joomla.filesystem.file');
                 jimport('joomla.filesystem.folder');
                 jimport('joomla.utilities.utility');
                 // @rule: Create default media path
                 $path = DISCUSS_MEDIA . '/' . trim($config->get('attachment_path'), DIRECTORY_SEPARATOR);
                 if (!JFolder::exists($path)) {
                     JFolder::create($path);
                     JFile::copy(DISCUSS_ROOT . '/index.html', $path . '/index.html');
                 }
                 $maxSize = (double) $config->get('attachment_maxsize') * 1024 * 1024;
                 $extension = JFile::getExt($attachment['name']);
                 // Skip empty data's.
                 if (!$extension) {
                     continue;
                 }
                 $allowed = explode(',', $config->get('main_attachment_extension'));
                 // @rule: Check for allowed extensions
                 if (!isset($extension) || !in_array(strtolower($extension), $allowed)) {
                     echo 'Invalid extension.';
                 } else {
                     $size = $attachment['size'];
                     $name = $attachment['name'];
                     $mime = $attachment['mime'];
                     $tmpName = $attachment['tmp_name'];
                     // Check the mime contains the attachment type, if not we insert our own
                     $imgExts = array('jpg', 'png', 'gif', 'JPG', 'PNG', 'GIF', 'jpeg', 'JPEG');
                     if (in_array($mime, $imgExts)) {
                         $mime = 'image/' . $mime;
                     } else {
                         $mime = 'application/' . $mime;
                     }
                     // @rule: File size should not exceed maximum allowed size
                     if (!empty($size) && $size < $maxSize) {
                         $hash = DiscussHelper::getHash($name . DiscussHelper::getDate()->toMySQL());
                         $attachment = DiscussHelper::getTable('Attachments');
                         $attachment->set('path', $hash);
                         $attachment->set('title', $name);
                         $attachment->set('uid', $post->id);
                         $attachment->set('type', $isReply ? 'replies' : 'questions');
                         $attachment->set('created', DiscussHelper::getDate()->toMySQL());
                         $attachment->set('published', true);
                         $attachment->set('mime', $mime);
                         $attachment->set('size', $size);
                         if (!JFile::copy($tmpName, $path . '/' . $hash)) {
                             echo 'Copy failed from tmp to attachment folder';
                         }
                         $attachment->store();
                         // Create a thumbnail if attachment is an image
                         if (DiscussHelper::getHelper('Image')->isImage($name)) {
                             require_once DISCUSS_CLASSES . '/simpleimage.php';
                             $image = new SimpleImage();
                             $image->load($tmpName);
                             $image->resizeToFill(160, 120);
                             $image->save($path . '/' . $hash . '_thumb', $image->image_type);
                         }
                         // @task: Once the attachment is processed, delete the temporary file.
                         JFile::delete($tmpName);
                     } else {
                         echo 'Invalid extension ' . $name;
                     }
                 }
             }
         }
         // Send notification email to the subscribers in the thread.
         if ($isReply && $post->get('published') == DISCUSS_ID_PUBLISHED) {
             self::replyNotifyUsers($post, $user, $senderName);
開發者ID:pguilford,項目名稱:vcomcc,代碼行數:67,代碼來源:mailqueue.php


注:本文中的DiscussHelper::getHash方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。