예제 #1
0
    function saveEmail($args, $request)
    {
        $this->validate();
        $plugin =& $this->plugin;
        $this->setupTemplate($request);
        $locale = array_shift($args);
        if (!AppLocale::isLocaleValid($locale)) {
            $request->redirect(null, null, 'index');
        }
        $emails = TranslatorAction::getEmailTemplates($locale);
        $referenceEmails = TranslatorAction::getEmailTemplates(MASTER_LOCALE);
        $emailKey = array_shift($args);
        $targetFilename = str_replace(MASTER_LOCALE, $locale, $referenceEmails[$emailKey]['templateDataFile']);
        // FIXME: Ugly.
        if (!in_array($emailKey, array_keys($emails))) {
            // If it's not a reference or translation email, bail.
            if (!in_array($emailKey, array_keys($referenceEmails))) {
                $request->redirect(null, null, 'index');
            }
            // If it's a reference email but not a translated one,
            // create a blank file. FIXME: This is ugly.
            if (!file_exists($targetFilename)) {
                $dir = dirname($targetFilename);
                if (!file_exists($dir)) {
                    mkdir($dir);
                }
                file_put_contents($targetFilename, '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE email_texts SYSTEM "../../../../../lib/pkp/dtd/emailTemplateData.dtd">
<!--
  * emailTemplateData.xml
  *
  * Copyright (c) 2003-2013 John Willinsky
  * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
  *
  * Localized email templates XML file.
  *
  -->
<email_texts locale="' . $locale . '">
</email_texts>');
            }
        }
        import('lib.pkp.classes.file.EditableEmailFile');
        $file = new EditableEmailFile($locale, $targetFilename);
        $subject = $this->correctCr($request->getUserVar('subject'));
        $body = $this->correctCr($request->getUserVar('body'));
        $description = $this->correctCr($request->getUserVar('description'));
        if (!$file->update($emailKey, $subject, $body, $description)) {
            $file->insert($emailKey, $subject, $body, $description);
        }
        $file->write();
        if ($request->getUserVar('returnToCheck') == 1) {
            $request->redirect(null, null, 'check', $locale);
        } else {
            $request->redirect(null, null, 'edit', $locale);
        }
    }
예제 #2
0
 /**
  * Display the grid's containing page.
  * @param $args array
  * @param $request PKPRequest
  */
 function save($args, $request)
 {
     $emailData = $referenceEmailData = null;
     // Avoid scrutinizer warning
     $emailKey = $this->_getEmailData($request, $emailData, $referenceEmailData);
     $notificationManager = new NotificationManager();
     $user = $request->getUser();
     $targetFilename = str_replace(MASTER_LOCALE, $this->locale, $referenceEmailData['templateDataFile']);
     if (!isset($emailData[$emailKey]['templateDataFile'])) {
         // If it's a reference email but the translation XML file does not exist,
         // create a blank file from a template.
         if (!file_exists($targetFilename)) {
             $dir = dirname($targetFilename);
             if (!file_exists($dir)) {
                 mkdir($dir);
             }
             file_put_contents($targetFilename, strtr(file_get_contents(self::$plugin->getRegistryPath() . '/emailTemplateData.xml'), array('{$locale}' => $this->locale)));
         }
     }
     import('lib.pkp.classes.file.EditableEmailFile');
     $file = new EditableEmailFile($this->locale, $targetFilename);
     $subject = $this->correctCr($request->getUserVar('emailSubject'));
     $body = $this->correctCr($request->getUserVar('emailBody'));
     $description = $this->correctCr($request->getUserVar('emailDescription'));
     $message = new JSONMessage(true);
     if (!$file->update($emailKey, $subject, $body, $description)) {
         if (!$file->insert($emailKey, $subject, $body, $description)) {
             // Some kind of error occurred (probably garbled formatting)
             $notificationManager->createTrivialNotification($user->getId(), NOTIFICATION_TYPE_ERROR, array('contents' => __('plugins.generic.translator.errorEditingFile', array('filename' => $targetFilename))));
             return $message->getString();
         }
     }
     if ($file->write()) {
         $notificationManager->createTrivialNotification($user->getId());
     } else {
         // Could not write the file
         $notificationManager->createTrivialNotification($user->getId(), NOTIFICATION_TYPE_ERROR, array('contents' => __('plugins.generic.translator.couldNotWriteFile', array('filename' => $targetFilename))));
     }
     return $message->getString();
 }