function resizePictures($input) { $this->destination = ACYMAILING_MEDIA . 'resized' . DS; acymailing::createDir($this->destination); $content = acymailing::absoluteURL($input); preg_match_all('#<img([^>]*)>#Ui', $content, $results); if (empty($results[1])) { return $input; } $replace = array(); foreach ($results[1] as $onepicture) { if (!preg_match('#src="([^"]*)"#Ui', $onepicture, $path)) { continue; } $imageUrl = $path[1]; if (strpos($imageUrl, ACYMAILING_LIVE) !== false) { $imageUrl = str_replace(array(ACYMAILING_LIVE, '/'), array(ACYMAILING_ROOT, DS), $imageUrl); } $newPicture = $this->generateThumbnail($imageUrl); if (!$newPicture) { continue; } $newPicture['file'] = str_replace(array(ACYMAILING_ROOT, DS), array(ACYMAILING_LIVE, '/'), $newPicture['file']); $replaceImage = array(); $replaceImage[$path[1]] = $newPicture['file']; if (preg_match_all('#(width|height)(:|=) *"?([0-9]+)#i', $onepicture, $resultsSize)) { foreach ($resultsSize[0] as $i => $oneArg) { $newVal = strtolower($resultsSize[1][$i]) == 'width' ? $newPicture['width'] : $newPicture['height']; if ($newVal > $resultsSize[3][$i]) { continue; } $replaceImage[$oneArg] = str_replace($resultsSize[3][$i], $newVal, $oneArg); } } $replace[$onepicture] = str_replace(array_keys($replaceImage), $replaceImage, $onepicture); } if (!empty($replace)) { $input = str_replace(array_keys($replace), $replace, $content); } return $input; }
function createTemplateFile($id) { if (file_exists(ACYMAILING_TEMPLATE . 'css' . DS . 'template_' . $id . '.css')) { return ACYMAILING_TEMPLATE . 'css' . DS . 'template_' . $id . '.css'; } $classTemplate = acymailing::get('class.template'); $template = $classTemplate->get($id); if (empty($template->tempid)) { return ''; } $css = $classTemplate->buildCSS($template->styles, $template->stylesheet); if (empty($css)) { return ''; } jimport('joomla.filesystem.file'); acymailing::createDir(ACYMAILING_TEMPLATE . 'css'); if (JFile::write(ACYMAILING_TEMPLATE . 'css' . DS . 'template_' . $id . '.css', $css)) { return ACYMAILING_TEMPLATE . 'css' . DS . 'template_' . $id . '.css'; } else { acymailing::display('Could not create the file ' . ACYMAILING_TEMPLATE . 'css' . DS . 'template_' . $id . '.css', 'error'); return ''; } }
function copyFolder($from, $to) { $return = true; $allFiles = JFolder::files($from); foreach ($allFiles as $oneFile) { if (file_exists($to . DS . 'index.html') and $oneFile == 'index.html') { continue; } if (JFile::copy($from . DS . $oneFile, $to . DS . $oneFile) !== true) { $this->errors[] = 'Could not copy the file from ' . $from . DS . $oneFile . ' to ' . $to . DS . $oneFile; $return = false; } } $allFolders = JFolder::folders($from); if (!empty($allFolders)) { foreach ($allFolders as $oneFolder) { if (!acymailing::createDir($to . DS . $oneFolder)) { continue; } if (!$this->copyFolder($from . DS . $oneFolder, $to . DS . $oneFolder)) { $return = false; } } } return $return; }
function saveForm() { $app =& JFactory::getApplication(); $db =& JFactory::getDBO(); $config =& acymailing::config(); $mail = null; $mail->mailid = acymailing::getCID('mailid'); $formData = JRequest::getVar('data', array(), '', 'array'); foreach ($formData['mail'] as $column => $value) { if ($app->isAdmin() or in_array($column, $this->allowedFields)) { acymailing::secureField($column); if ($column == 'params') { $mail->{$column} = $value; } else { $mail->{$column} = strip_tags($value); } } } $mail->body = JRequest::getVar('editor_body', '', '', 'string', JREQUEST_ALLOWRAW); $pregreplace = array(); $pregreplace['#<tr([^>"]*>([^<]*<td[^>]*>[ \\n\\s]*<img[^>]*>[ \\n\\s]*</ *td[^>]*>[ \\n\\s]*)*</ *tr)#Uis'] = '<tr style="line-height: 0px;" $1'; $pregreplace['#<td(((?!style|>).)*>[ \\n\\s]*<img[^>]*>[ \\n\\s]*</ *td)#Uis'] = '<td style="line-height: 0px;" $1'; $pregreplace['#<xml>.*</xml>#Uis'] = ''; $newbody = preg_replace(array_keys($pregreplace), $pregreplace, $mail->body); if (!empty($newbody)) { $mail->body = $newbody; } $mail->attach = array(); $attachments = JRequest::getVar('attachments', array(), 'files', 'array'); if (!empty($attachments['name'][0]) or !empty($attachments['name'][1])) { jimport('joomla.filesystem.file'); $allowedFiles = explode(',', strtolower($config->get('allowedfiles'))); $uploadFolder = JPath::clean(html_entity_decode($config->get('uploadfolder'))); $uploadFolder = trim($uploadFolder, DS . ' ') . DS; $uploadPath = JPath::clean(ACYMAILING_ROOT . $uploadFolder); acymailing::createDir($uploadPath, true); if (!is_writable($uploadPath)) { @chmod($uploadPath, '0755'); if (!is_writable($uploadPath)) { $app->enqueueMessage(JText::sprintf('WRITABLE_FOLDER', $uploadPath), 'notice'); } } foreach ($attachments['name'] as $id => $filename) { if (empty($filename)) { continue; } $attachment = null; $attachment->filename = strtolower(JFile::makeSafe($filename)); $attachment->size = $attachments['size'][$id]; $attachment->extension = strtolower(substr($attachment->filename, strrpos($attachment->filename, '.') + 1)); if (!in_array($attachment->extension, $allowedFiles)) { $app->enqueueMessage(JText::sprintf('ACCEPTED_TYPE', $attachment->extension, $config->get('allowedfiles')), 'notice'); continue; } if (!JFile::upload($attachments['tmp_name'][$id], $uploadPath . $attachment->filename)) { if (!move_uploaded_file($attachments['tmp_name'][$id], $uploadPath . $attachment->filename)) { $app->enqueueMessage(JText::sprintf('FAIL_UPLOAD', $attachments['tmp_name'][$id], $uploadPath . $attachment->filename), 'error'); continue; } } $mail->attach[] = $attachment; } } $toggleHelper = acymailing::get('helper.toggle'); if (!empty($mail->type) && $mail->type == 'followup' && !empty($mail->mailid)) { $oldMail = $this->get($mail->mailid); if (!empty($mail->published) and !$oldMail->published) { $text = JText::_('FOLLOWUP_PUBLISHED_INFORMED'); $text .= ' ' . $toggleHelper->toggleText('add', $mail->mailid, 'followup', JText::_('FOLLOWUP_PUBLISHED')); $app->enqueueMessage($text, 'notice'); } if ($oldMail->senddate != $mail->senddate) { $text = JText::_('FOLLOWUP_CHANGED_DELAY_INFORMED'); $text .= ' ' . $toggleHelper->toggleText('update', $mail->mailid, 'followup', JText::_('FOLLOWUP_CHANGED_DELAY')); $app->enqueueMessage($text, 'notice'); } } $mailid = $this->save($mail); if (!$mailid) { return false; } JRequest::setVar('mailid', $mailid); if (!empty($mail->type) && $mail->type == 'followup' && empty($mail->mailid) && !empty($mail->published)) { $text = JText::_('FOLLOWUP_PUBLISHED_INFORMED'); $text .= ' ' . $toggleHelper->toggleText('add', $mailid, 'followup', JText::_('FOLLOWUP_PUBLISHED')); $app->enqueueMessage($text, 'notice'); } $status = true; if (!empty($formData['listmail'])) { $receivers = array(); $remove = array(); foreach ($formData['listmail'] as $listid => $receiveme) { if (!empty($receiveme)) { $receivers[] = $listid; } else { $remove[] = $listid; } } $listMailClass = acymailing::get('class.listmail'); $status = $listMailClass->save($mailid, $receivers, $remove); } return $status; }
function file() { $app =& JFactory::getApplication(); $importFile = JRequest::getVar('importfile', array(), 'files', 'array'); if (empty($importFile['name'])) { $app->enqueueMessage(JText::_('BROWSE_FILE'), 'notice'); return false; } $this->forceconfirm = JRequest::getInt('import_confirmed'); $this->charsetConvert = JRequest::getString('charsetconvert', ''); $this->generatename = JRequest::getInt('generatename'); $this->overwrite = JRequest::getInt('overwriteexisting'); jimport('joomla.filesystem.file'); $config =& acymailing::config(); $allowedFiles = explode(',', strtolower($config->get('allowedfiles'))); $uploadFolder = JPath::clean(html_entity_decode($config->get('uploadfolder'))); $uploadFolder = trim($uploadFolder, DS . ' ') . DS; $uploadPath = JPath::clean(ACYMAILING_ROOT . $uploadFolder); acymailing::createDir($uploadPath); if (!is_writable($uploadPath)) { @chmod($uploadPath, '0755'); if (!is_writable($uploadPath)) { $app->enqueueMessage(JText::sprintf('WRITABLE_FOLDER', $uploadPath), 'notice'); } } $attachment = null; $attachment->filename = strtolower(JFile::makeSafe($importFile['name'])); $attachment->size = $importFile['size']; $attachment->extension = strtolower(substr($attachment->filename, strrpos($attachment->filename, '.') + 1)); if (!in_array($attachment->extension, $allowedFiles)) { $app->enqueueMessage(JText::sprintf('ACCEPTED_TYPE', $attachment->extension, $config->get('allowedfiles')), 'notice'); return false; } if (!JFile::upload($importFile['tmp_name'], $uploadPath . $attachment->filename)) { if (!move_uploaded_file($importFile['tmp_name'], $uploadPath . $attachment->filename)) { $app->enqueueMessage(JText::sprintf('FAIL_UPLOAD', $importFile['tmp_name'], $uploadPath . $attachment->filename), 'error'); } } $contentFile = file_get_contents($uploadPath . $attachment->filename); if (!$contentFile) { $app->enqueueMessage(JText::sprintf('FAIL_OPEN', $uploadPath . $attachment->filename), 'error'); return false; } unlink($uploadPath . $attachment->filename); return $this->_handleContent($contentFile); }