block.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <?php
  2. /*
  3. * Name: Last posts
  4. * Section: content
  5. * Description: Last posts list with different layouts
  6. * Type: dynamic
  7. */
  8. /* @var $options array */
  9. /* @var $wpdb wpdb */
  10. $defaults = array(
  11. 'title' => 'Last news',
  12. 'color' => '#999999',
  13. 'font_family' => 'Helvetica, Arial, sans-serif',
  14. 'font_size' => '16',
  15. 'font_color' => '#333333',
  16. 'title_font_family' => 'Helvetica, Arial, sans-serif',
  17. 'title_font_size' => '25',
  18. 'title_font_color' => ' #333333',
  19. 'max' => 4,
  20. 'button_label' => __('Read more...', 'newsletter'),
  21. 'categories' => '',
  22. 'tags' => '',
  23. 'block_background' => '#ffffff',
  24. 'layout' => 'one',
  25. 'language' => '',
  26. 'button_background' => '#256F9C',
  27. 'button_font_color' => '#ffffff',
  28. 'button_font_family' => 'Helvetica, Arial, sans-serif',
  29. 'button_font_size' => 16,
  30. 'block_padding_left' => 15,
  31. 'block_padding_right' => 15,
  32. 'block_padding_top' => 15,
  33. 'block_padding_bottom' => 15
  34. );
  35. $options = array_merge($defaults, $options);
  36. $font_family = $options['font_family'];
  37. $font_size = $options['font_size'];
  38. $title_font_family = $options['title_font_family'];
  39. $title_font_size = $options['title_font_size'];
  40. $show_image = !empty($options['show_image']);
  41. $filters = array();
  42. $filters['posts_per_page'] = (int) $options['max'];
  43. if (!empty($options['categories'])) {
  44. $filters['category__in'] = $options['categories'];
  45. }
  46. if (!empty($options['tags'])) {
  47. $filters['tag'] = $options['tags'];
  48. }
  49. // Filter by time?
  50. //$options['block_last_run'] = time();
  51. if (!empty($context['last_run'])) {
  52. $filters['date_query'] = array(
  53. 'after' => gmdate('c', $context['last_run'])
  54. );
  55. }
  56. $posts = Newsletter::instance()->get_posts($filters, $options['language']);
  57. if ($context['type'] == 'automated') {
  58. // No new posts
  59. if (empty($posts)) {
  60. if (isset($options['automated_required'])) {
  61. $out['return_empty_message'] = true;
  62. }
  63. return;
  64. }
  65. if ($options['automated_include'] == 'max') {
  66. unset($filters['date_query']);
  67. $posts = Newsletter::instance()->get_posts($filters, $options['language']);
  68. }
  69. }
  70. $out['subject'] = $posts[0]->post_title;
  71. $button_background = $options['button_background'];
  72. $button_label = $options['button_label'];
  73. $button_font_family = $options['button_font_family'];
  74. $button_font_size = $options['button_font_size'];
  75. $button_color = $options['button_font_color'];
  76. $alternative = plugins_url('newsletter') . '/emails/blocks/posts/images/blank.png';
  77. $alternative_2 = plugins_url('newsletter') . '/emails/blocks/posts/images/blank-240x160.png';
  78. remove_all_filters('excerpt_more');
  79. ?>
  80. <?php if ($options['layout'] == 'one') { ?>
  81. <style>
  82. .posts-post-date {
  83. padding: 0 0 5px 25px;
  84. font-size: 13px;
  85. font-family: <?php echo $font_family ?>;
  86. font-weight: normal;
  87. color: #aaaaaa;
  88. }
  89. .posts-post-title {
  90. padding: 0 0 5px 25px;
  91. font-size: <?php echo $title_font_size ?>px;
  92. font-family: <?php echo $title_font_family ?>;
  93. font-weight: normal;
  94. color: <?php echo $options['title_font_color'] ?>;
  95. line-height: normal;
  96. }
  97. .posts-post-excerpt {
  98. padding: 10px 0 15px 25px;
  99. font-family: <?php echo $font_family ?>;
  100. color: <?php echo $options['font_color'] ?>;
  101. font-size: <?php echo $font_size ?>px;
  102. line-height: 1.5em;
  103. }
  104. .posts-button-table {
  105. background-color: <?php echo $button_background ?>;
  106. /*border:1px solid #353535;*/
  107. border-radius:5px;
  108. align: right;
  109. }
  110. .posts-button-td {
  111. color: <?php echo $button_color ?>;
  112. font-family:<?php echo $font_family ?>;
  113. font-size:<?php echo $button_font_size ?>px;
  114. font-weight:normal;
  115. letter-spacing:normal;
  116. line-height:normal;
  117. padding-top:15px;
  118. padding-right:30px;
  119. padding-bottom:15px;
  120. padding-left:30px;
  121. text-align: right;
  122. }
  123. .posts-button-a {
  124. color:<?php echo $button_color ?>;
  125. font-size:<?php echo $button_font_size ?>px;
  126. font-weight:normal;
  127. text-decoration:none;
  128. }
  129. </style>
  130. <!-- COMPACT ARTICLE SECTION -->
  131. <table border="0" cellpadding="0" cellspacing="0" width="100%" class="responsive-table">
  132. <?php foreach ($posts as $post) { ?>
  133. <?php
  134. $url = tnp_post_permalink($post);
  135. ?>
  136. <tr>
  137. <?php if ($show_image) { ?>
  138. <td valign="top" style="padding: 30px 0 0 0; width: 105px!important" class="mobile-hide">
  139. <a href="<?php echo tnp_post_permalink($post) ?>" target="_blank">
  140. <img src="<?php echo tnp_post_thumbnail_src($post, array(105, 105, true), $alternative) ?>" width="105" height="105" alt="Image" border="0" style="display: block; font-family: Arial; color: #666666; font-size: 14px; min-width: 105px!important; width: 105px!important;">
  141. </a>
  142. </td>
  143. <?php } ?>
  144. <td style="padding: 30px 0 0 0;" class="no-padding">
  145. <!-- ARTICLE -->
  146. <table border="0" cellspacing="0" cellpadding="0" width="100%">
  147. <?php if (!empty($options['show_date'])) { ?>
  148. <tr>
  149. <td align="left" inline-class="posts-post-date" class="padding-meta">
  150. <?php echo tnp_post_date($post) ?>
  151. </td>
  152. </tr>
  153. <?php } ?>
  154. <tr>
  155. <td align="left" inline-class="posts-post-title" class="padding-copy tnpc-row-edit" data-type="title">
  156. <?php echo tnp_post_title($post) ?>
  157. </td>
  158. </tr>
  159. <tr>
  160. <td align="left" inline-class="posts-post-excerpt" class="padding-copy tnpc-row-edit" data-type="text">
  161. <?php echo tnp_post_excerpt($post) ?>
  162. </td>
  163. </tr>
  164. <tr>
  165. <td align="left" class="padding">
  166. <table border="0" cellpadding="0" cellspacing="0" inline-class="posts-button-table" align="right">
  167. <tr>
  168. <td align="center" valign="middle" inline-class="posts-button-td">
  169. <a href="<?php echo esc_attr($url) ?>" target="_blank" inline-class="posts-button-a"><?php echo $button_label ?></a>
  170. </td>
  171. </tr>
  172. </table>
  173. </td>
  174. </tr>
  175. </table>
  176. </td>
  177. </tr>
  178. <?php } ?>
  179. </table>
  180. <?php } else { ?>
  181. <style>
  182. .posts-post-date {
  183. padding: 10px 0 0 15px;
  184. font-size: 13px;
  185. font-family: <?php echo $font_family ?>;
  186. font-weight: normal;
  187. color: #aaaaaa;
  188. }
  189. .posts-post-title {
  190. padding: 15px 0 0 0;
  191. font-family: <?php echo $title_font_family ?>;
  192. color: <?php echo $options['title_font_color'] ?>;
  193. font-size: <?php echo $title_font_size ?>px;
  194. line-height: 1.3em;
  195. }
  196. .posts-post-excerpt {
  197. padding: 5px 0 0 0;
  198. font-family: <?php echo $font_family ?>;
  199. color: <?php echo $options['font_color'] ?>;
  200. font-size: <?php echo $font_size ?>px;
  201. line-height: 1.4em;
  202. }
  203. .posts-button-table {
  204. background-color: <?php echo $button_background ?>;
  205. /*border:1px solid #353535;*/
  206. border-radius:5px;
  207. align: right;
  208. }
  209. .posts-button-td {
  210. color: <?php echo $button_color ?>;
  211. font-family:<?php echo $font_family ?>;
  212. font-size:<?php echo $button_font_size ?>px;
  213. font-weight:normal;
  214. letter-spacing:normal;
  215. line-height:normal;
  216. padding-top:15px;
  217. padding-right:30px;
  218. padding-bottom:15px;
  219. padding-left:30px;
  220. text-align: right;
  221. }
  222. .posts-button-a {
  223. color:<?php echo $button_color ?>;
  224. font-size:<?php echo $button_font_size ?>px;
  225. font-weight:normal;
  226. text-decoration:none;
  227. }
  228. </style>
  229. <!-- TWO COLUMN SECTION -->
  230. <!-- TWO COLUMNS -->
  231. <table cellspacing="0" cellpadding="0" border="0" width="100%">
  232. <?php foreach (array_chunk($posts, 2) AS $row) { ?>
  233. <tr>
  234. <td valign="top" style="padding: 10px;" class="mobile-wrapper">
  235. <!-- LEFT COLUMN -->
  236. <table cellpadding="0" cellspacing="0" border="0" width="47%" align="left" class="responsive-table">
  237. <tr>
  238. <td style="padding: 20px 0 40px 0;">
  239. <table cellpadding="0" cellspacing="0" border="0" width="100%">
  240. <?php if ($show_image) { ?>
  241. <tr>
  242. <td align="center" valign="middle" class="tnpc-row-edit" data-type="image">
  243. <a href="<?php echo tnp_post_permalink($row[0]) ?>" target="_blank">
  244. <img src="<?php echo tnp_post_thumbnail_src($row[0], array(240, 160, true), $alternative_2) ?>" alt="Image" width="240" height="160" border="0" class="img-max">
  245. </a>
  246. </td>
  247. </tr>
  248. <?php } ?>
  249. <tr>
  250. <td align="center" inline-class="posts-post-title" class="tnpc-row-edit" data-type="title"><?php echo tnp_post_title($row[0]) ?></td>
  251. </tr>
  252. <?php if (!empty($options['show_date'])) { ?>
  253. <tr>
  254. <td align="center" inline-class="posts-post-date">
  255. <?php echo tnp_post_date($row[0]) ?>
  256. </td>
  257. </tr>
  258. <?php } ?>
  259. <tr>
  260. <td align="center" inline-class="posts-post-excerpt" class="tnpc-row-edit" data-type="text"><?php echo tnp_post_excerpt($row[0]) ?></td>
  261. </tr>
  262. <tr>
  263. <td align="center">
  264. <br>
  265. <table border="0" cellpadding="0" cellspacing="0" inline-class="posts-button-table" align="center">
  266. <tr>
  267. <td align="center" valign="middle" inline-class="posts-button-td">
  268. <a href="<?php echo tnp_post_permalink($row[0]) ?>" target="_blank" inline-class="posts-button-a"><?php echo $button_label ?></a>
  269. </td>
  270. </tr>
  271. </table>
  272. </td>
  273. </tr>
  274. </table>
  275. </td>
  276. </tr>
  277. </table>
  278. <?php if (!empty($row[1])) { ?>
  279. <!-- RIGHT COLUMN -->
  280. <table cellpadding="0" cellspacing="0" border="0" width="47%" align="right" class="responsive-table">
  281. <tr>
  282. <td style="padding: 20px 0 40px 0;">
  283. <table cellpadding="0" cellspacing="0" border="0" width="100%">
  284. <?php if ($show_image) { ?>
  285. <tr>
  286. <td align="center" valign="middle" class="tnpc-row-edit" data-type="image">
  287. <a href="<?php echo tnp_post_permalink($row[1]) ?>" target="_blank">
  288. <img src="<?php echo tnp_post_thumbnail_src($row[1], array(240, 160, true), $alternative_2) ?>" alt="Image" width="240" height="160" border="0" class="img-max">
  289. </a>
  290. </td>
  291. </tr>
  292. <?php } ?>
  293. <tr>
  294. <td align="center" inline-class="posts-post-title" class="tnpc-row-edit" data-type="title"><?php echo tnp_post_title($row[1]) ?></td>
  295. </tr>
  296. <?php if (!empty($options['show_date'])) { ?>
  297. <tr>
  298. <td align="center" inline-class="posts-post-date">
  299. <?php echo tnp_post_date($row[1]) ?>
  300. </td>
  301. </tr>
  302. <?php } ?>
  303. <tr>
  304. <td align="center" inline-class="posts-post-excerpt" class="tnpc-row-edit" data-type="text"><?php echo tnp_post_excerpt($row[1]) ?></td>
  305. </tr>
  306. <tr>
  307. <td align="center">
  308. <br>
  309. <table border="0" cellpadding="0" cellspacing="0" inline-class="posts-button-table" align="center">
  310. <tr>
  311. <td align="center" valign="middle" inline-class="posts-button-td">
  312. <a href="<?php echo tnp_post_permalink($row[1]) ?>" target="_blank" inline-class="posts-button-a"><?php echo $button_label ?></a>
  313. </td>
  314. </tr>
  315. </table>
  316. </td>
  317. </tr>
  318. </table>
  319. </td>
  320. </tr>
  321. </table>
  322. <?php } ?>
  323. </td>
  324. </tr>
  325. <?php } ?>
  326. </table>
  327. <?php } ?>