/framework/modules/blog/models/blog.php

https://github.com/exponentcms/exponent-cms · PHP · 138 lines · 51 code · 13 blank · 74 comment · 14 complexity · 83a2d23657c1f64110703b8ad0f769df MD5 · raw file

  1. <?php
  2. ##################################################
  3. #
  4. # Copyright (c) 2004-2021 OIC Group, Inc.
  5. #
  6. # This file is part of Exponent
  7. #
  8. # Exponent is free software; you can redistribute
  9. # it and/or modify it under the terms of the GNU
  10. # General Public License as published by the Free
  11. # Software Foundation; either version 2 of the
  12. # License, or (at your option) any later version.
  13. #
  14. # GPL: http://www.gnu.org/licenses/gpl.txt
  15. #
  16. ##################################################
  17. /**
  18. * @subpackage Models
  19. * @package Modules
  20. */
  21. class blog extends expRecord {
  22. protected $attachable_item_types = array(
  23. 'content_expCats'=>'expCat',
  24. 'content_expFiles'=>'expFile',
  25. 'content_expTags'=>'expTag',
  26. 'content_expComments'=>'expComment'
  27. );
  28. public $validates = array(
  29. 'presence_of'=>array(
  30. 'title'=>array('message'=>'Title is a required field.'),
  31. 'body'=>array('message'=>'Post Content is a required field.'),
  32. )
  33. );
  34. public $supports_revisions = true;
  35. // public function __construct($params=null, $get_assoc=true, $get_attached=true) {
  36. // parent::__construct($params, $get_assoc, $get_attached);
  37. //
  38. // if (!empty($this->publish)) {
  39. // $this->publish_date = $this->publish;
  40. // } elseif (!empty($this->edited_at)) {
  41. // $this->publish_date = $this->edited_at;
  42. // } elseif (!empty($this->created_at)) {
  43. // $this->publish_date = $this->created_at;
  44. // }
  45. //
  46. // }
  47. function __construct($params = null, $get_assoc = true, $get_attached = true) {
  48. parent::__construct($params, $get_assoc, $get_attached);
  49. if (!empty($this->meta_fb))
  50. $this->meta_fb = expUnserialize($this->meta_fb);
  51. if (!empty($this->meta_fb['fbimage']) && !empty($this->meta_fb['fbimage'][0]))
  52. $this->meta_fb['fbimage'][0] = new expFile($this->meta_fb['fbimage'][0]);
  53. if (!empty($this->meta_tw))
  54. $this->meta_tw = expUnserialize($this->meta_tw);
  55. if (!empty($this->meta_tw['twimage']) && !empty($this->meta_tw['twimage'][0]))
  56. $this->meta_tw['twimage'][0] = new expFile($this->meta_tw['twimage'][0]);
  57. }
  58. public function beforeSave() {
  59. if (empty($this->publish) || $this->publish === 'on') {
  60. $this->publish = time();
  61. }
  62. parent::beforeSave();
  63. }
  64. // public function find($range='all', $where=null, $order=null, $limit=null, $limitstart=0, $get_assoc=true, $get_attached=true, $except=array(), $cascade_except = false) {
  65. // global $db, $user;
  66. //
  67. // if (is_numeric($range)) {
  68. // $where = $this->identifier.'='.(int)($range); // If we hit this then we are expecting just a simple id
  69. // $range = 'first';
  70. // }
  71. //
  72. // $sql = empty($where) ? 1 : $where;
  73. // //eDebug("Supports Revisions:" . $this->supports_revisions);
  74. // if ($this->supports_revisions && $range != 'revisions') $sql .= " AND revision_id=(SELECT MAX(revision_id) FROM `" . $db->prefix .$this->tablename."` WHERE $where)";
  75. // $sql .= empty($order) ? '' : ' ORDER BY '.$order;
  76. //// $where .= " private=0 ";
  77. //
  78. // if (strcasecmp($range, 'all') == 0 || strcasecmp($range, 'revisions') == 0) {
  79. // $sql .= empty($limit) ? '' : ' LIMIT '.$limitstart.','.$limit;
  80. // return $db->selectExpObjects($this->tablename, $sql, $this->classname, $get_assoc, $get_attached);
  81. // } elseif (strcasecmp($range, 'first') == 0) {
  82. // $sql .= ' LIMIT 0,1';
  83. // $records = $db->selectExpObjects($this->tablename, $sql, $this->classname, $get_assoc, $get_attached);
  84. // return empty($records) ? null : $records[0];
  85. // } elseif (strcasecmp($range, 'bytitle') == 0) {
  86. // $records = $db->selectExpObjects($this->tablename, "title='".$where."' OR sef_url='".$where."'", $this->classname, $get_assoc, $get_attached);
  87. // return empty($records) ? null : $records[0];
  88. // } elseif (strcasecmp($range, 'count') == 0) {
  89. // return $db->countObjects($this->tablename, $sql);
  90. // } elseif (strcasecmp($range, 'in') == 0) {
  91. // if (!is_array($where)) return array();
  92. // foreach ($where as $id) $records[] = new $this->classname($id);
  93. // return $records;
  94. // } elseif (strcasecmp($range, 'bytag') == 0) {
  95. // $sql = 'SELECT DISTINCT m.id FROM '.DB_TABLE_PREFIX.'_'.$this->table.' m ';
  96. // $sql .= 'JOIN '.DB_TABLE_PREFIX.'_content_expTags ct ';
  97. // $sql .= 'ON m.id = ct.content_id WHERE ct.exptag_id='.$where." AND ct.content_type='".$this->classname."'";
  98. // if ($this->supports_revisions) $sql .= " AND revision_id=(SELECT MAX(revision_id) FROM `" . $db->prefix .$this->tablename."` WHERE ct.exptag_id=".$where." AND ct.content_type='".$this->classname."'";
  99. // $tag_assocs = $db->selectObjectsBySql($sql);
  100. // $records = array();
  101. // foreach ($tag_assocs as $assoc) {
  102. // $records[] = new $this->classname($assoc->id);
  103. // }
  104. // return $records;
  105. // }
  106. // }
  107. public function update($params = array()) {
  108. if (isset($params['expFile']['fbimage'][0]) && is_numeric($params['expFile']['fbimage'][0]))
  109. $params['fb']['fbimage'][0] = $params['expFile']['fbimage'][0];
  110. unset ($params['expFile']['fbimage']);
  111. if (isset($params['fb'])) {
  112. $params['meta_fb'] = serialize($params['fb']);
  113. unset ($params['fb']);
  114. }
  115. if (isset($params['expFile']['twimage'][0]) && is_numeric($params['expFile']['twimage'][0]))
  116. $params['tw']['twimage'][0] = $params['expFile']['twimage'][0];
  117. unset ($params['expFile']['twimage']);
  118. if (isset($params['tw'])) {
  119. $params['meta_tw'] = serialize($params['tw']);
  120. unset ($params['tw']);
  121. }
  122. parent::update($params);
  123. }
  124. }
  125. ?>