PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/motopress-content-editor-lite/includes/ce/Template.php

https://gitlab.com/vanafroo/landingpage
PHP | 86 lines | 54 code | 8 blank | 24 comment | 5 complexity | 0dde99bbecd91918741b9dfc627d2baa MD5 | raw file
  1. <?php
  2. /**
  3. * Class MPCETemplate
  4. */
  5. class MPCETemplate extends MPCEBaseElement {
  6. public $content;
  7. protected $errors = array(
  8. 'id' => array(),
  9. 'name' => array(),
  10. 'icon' => array(),
  11. 'content' => array()
  12. );
  13. const ICON_DIR = 'template';
  14. /**
  15. * @param $id
  16. * @param $name
  17. * @param $content
  18. * @param string $icon [optional]
  19. */
  20. function __construct($id, $name, $content, $icon = 'no-template.png') {
  21. $this->setId($id);
  22. $this->setName($name);
  23. if (empty($icon)) {
  24. $icon = 'no-template.png';
  25. }
  26. $this->setIcon($icon); //size 85x142 px
  27. $this->setContent($content);
  28. }
  29. /**
  30. * @param string $icon
  31. */
  32. public function setIcon($icon) {
  33. parent::icon($icon, self::ICON_DIR);
  34. }
  35. /**
  36. * @return string
  37. */
  38. public function getContent() {
  39. return $this->content;
  40. }
  41. /**
  42. * @param string $content
  43. */
  44. public function setContent($content) {
  45. global $motopressCELang;
  46. if (is_string($content)) {
  47. $content = trim($content);
  48. if (!empty($content)) {
  49. $content = filter_var($content, FILTER_UNSAFE_RAW);
  50. $this->content = $content;
  51. } else {
  52. $this->addError('content', $motopressCELang->CEEmpty);
  53. }
  54. } else {
  55. $this->addError('content', strtr($motopressCELang->CEInvalidArgumentType, array('%name%' => gettype($content))));
  56. }
  57. }
  58. /**
  59. * @return boolean
  60. */
  61. public function isValid() {
  62. return (
  63. empty($this->errors['id']) &&
  64. empty($this->errors['name']) &&
  65. empty($this->errors['icon']) &&
  66. empty($this->errors['content'])
  67. ) ? true : false;
  68. }
  69. /**
  70. * @return string
  71. */
  72. public function __toString() {
  73. $str = 'id: ' . $this->getId() . ', ';
  74. $str .= 'name: ' . $this->getName() . ', ';
  75. $str .= 'icon: ' . $this->getIcon();
  76. return $str;
  77. }
  78. }