本文整理汇总了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;
}
示例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);