new.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. require_once NEWSLETTER_INCLUDES_DIR . '/controls.php';
  3. $controls = new NewsletterControls();
  4. $module = NewsletterEmails::instance();
  5. if ($controls->is_action('theme')) {
  6. if ($controls->data['theme'] != 'rawhtml') {
  7. $controls->merge($module->themes->get_options($controls->data['theme']));
  8. $module->save_options($controls->data);
  9. }
  10. // If this theme has no intermediate options...
  11. if ($controls->data['theme'] == 'rawhtml' || !file_exists($module->get_current_theme_file_path('theme-options.php'))) {
  12. $email = array();
  13. $email['status'] = 'new';
  14. $email['subject'] = __('Here the email subject', 'newsletter');
  15. $email['track'] = Newsletter::instance()->options['track'];
  16. $email['token'] = $module->get_token();
  17. if ($controls->data['theme'] == 'rawhtml') {
  18. $email['editor'] = NewsletterEmails::EDITOR_HTML;
  19. $email['message'] = "<!DOCTYPE html>\n<html>\n<head>\n<title>Your email title</title>\n</head>\n<body>\n</body>\n</html>";
  20. } else {
  21. $theme_options = $module->get_current_theme_options();
  22. $theme_url = $module->get_current_theme_url();
  23. $theme_subject = '';
  24. ob_start();
  25. include $module->get_current_theme_file_path('theme.php');
  26. $email['message'] = ob_get_clean();
  27. if (!empty($theme_subject)) {
  28. $email['subject'] = $theme_subject;
  29. }
  30. $file = $module->get_current_theme_file_path('theme-text.php');
  31. if (file_exists($file)) {
  32. ob_start();
  33. include $module->get_current_theme_file_path('theme-text.php');
  34. $email['message_text'] = ob_get_clean();
  35. } else {
  36. $email['message_text'] = 'You need a modern email client to read this email. Read it online: {email_url}.';
  37. }
  38. $email['editor'] = NewsletterEmails::EDITOR_TINYMCE;
  39. }
  40. $email['type'] = 'message';
  41. $email['send_on'] = time();
  42. $email = Newsletter::instance()->save_email($email);
  43. $controls->js_redirect($module->get_editor_url($email->id, $email->editor));
  44. return;
  45. }
  46. }
  47. if ($controls->is_action('save')) {
  48. $module->save_options($controls->data);
  49. //$controls->messages = 'Saved.';
  50. }
  51. if ($controls->is_action('create')) {
  52. $module->save_options($controls->data);
  53. $email = array();
  54. $email['status'] = 'new';
  55. $email['subject'] = __('Here the email subject', 'newsletter');
  56. $email['track'] = Newsletter::instance()->options['track'];
  57. $theme_options = $module->get_current_theme_options();
  58. $theme_url = $module->get_current_theme_url();
  59. $theme_subject = '';
  60. ob_start();
  61. include $module->get_current_theme_file_path('theme.php');
  62. $email['message'] = ob_get_clean();
  63. if (!empty($theme_subject)) {
  64. $email['subject'] = $theme_subject;
  65. }
  66. ob_start();
  67. include $module->get_current_theme_file_path('theme-text.php');
  68. $email['message_text'] = ob_get_clean();
  69. $email['type'] = 'message';
  70. $email['send_on'] = time();
  71. $email = Newsletter::instance()->save_email($email);
  72. ?>
  73. <script>
  74. location.href = "<?php echo $module->get_admin_page_url('edit'); ?>&id=<?php echo $email->id; ?>";
  75. </script>
  76. <div class="wrap">
  77. <p><a href="<?php echo $module->get_admin_page_url('edit'); ?>&id=<?php echo $email->id; ?>">click here to proceed</a>.</p>
  78. </div>
  79. <?php
  80. return;
  81. }
  82. if ($controls->data == null) {
  83. $controls->data = $module->get_options();
  84. }
  85. function newsletter_emails_update_options($options) {
  86. add_option('newsletter_emails', '', null, 'no');
  87. update_option('newsletter_emails', $options);
  88. }
  89. function newsletter_emails_update_theme_options($theme, $options) {
  90. $x = strrpos($theme, '/');
  91. if ($x !== false) {
  92. $theme = substr($theme, $x + 1);
  93. }
  94. add_option('newsletter_emails_' . $theme, '', null, 'no');
  95. update_option('newsletter_emails_' . $theme, $options);
  96. }
  97. function newsletter_emails_get_options() {
  98. $options = get_option('newsletter_emails', array());
  99. return $options;
  100. }
  101. function newsletter_emails_get_theme_options($theme) {
  102. $x = strrpos($theme, '/');
  103. if ($x !== false) {
  104. $theme = substr($theme, $x + 1);
  105. }
  106. $options = get_option('newsletter_emails_' . $theme, array());
  107. return $options;
  108. }
  109. ?>
  110. <div class="wrap tnp-emails tnp-emails-new" id="tnp-wrap">
  111. <?php include NEWSLETTER_DIR . '/tnp-header.php'; ?>
  112. <div id="tnp-heading">
  113. <h2><?php _e('Create a newsletter', 'newsletter') ?>
  114. <a class="tnp-btn-h1" href="<?php echo NewsletterEmails::instance()->get_admin_page_url('theme'); ?>"><?php _e('Back to newsletter themes', 'newsletter') ?></a>
  115. </h2>
  116. <br>
  117. <p>Theme options are saved for next time you'll use this theme.</p>
  118. </div>
  119. <div id="tnp-body" class="tnp-body-lite">
  120. <form method="post" action="">
  121. <?php $controls->init(); ?>
  122. <?php $controls->hidden('theme'); ?>
  123. <table style="width: 100%; border-collapse: collapse">
  124. <tr>
  125. <td style="text-align: left; vertical-align: top; border-bottom: 1px solid #ddd; padding-bottom: 10px">
  126. <div style="float: right; margin-left: 15px;"><?php $controls->button_primary('save', __('Refresh the preview', 'newsletter')); ?></div>
  127. </td>
  128. <td style="text-align: left; vertical-align: top; border-bottom: 1px solid #ddd; padding-bottom: 10px">
  129. <div style="float: right"><?php $controls->button_primary('create', 'Proceed to edit &raquo;', 'this.form.action=\'' . home_url('/', is_ssl() ? 'https' : 'http') . '?na=emails-create\';this.form.submit()'); ?></div>
  130. <img style="position: relative; left: 5px; top: 10px;"src="<?php echo plugins_url('newsletter') ?>/images/arrow.png" height="35">
  131. </td>
  132. </tr>
  133. <tr>
  134. <td style="width: 500px; vertical-align: top;">
  135. <div class="tnp-emails-theme-options">
  136. <?php @include $module->get_current_theme_file_path('theme-options.php'); ?>
  137. </div>
  138. </td>
  139. <td style="vertical-align: top; padding-top: 15px; padding-left: 15px">
  140. <iframe src="<?php echo wp_nonce_url(home_url('/', is_ssl() ? 'https' : 'http') . '?na=emails-preview&ts=' . time(), 'view'); ?>" height="700" style="width: 100%; border: 1px solid #ccc"></iframe>
  141. </td>
  142. </tr>
  143. </table>
  144. </form>
  145. </div>
  146. <?php include NEWSLETTER_DIR . '/tnp-footer.php'; ?>
  147. </div>