PageRenderTime 71ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/baser/plugins/mail/models/mail_content.php

https://github.com/hashing/basercms
PHP | 313 lines | 189 code | 23 blank | 101 comment | 16 complexity | 32c93796307d3da220a4433618b6a77c MD5 | raw file
Possible License(s): MIT
  1. <?php
  2. /* SVN FILE: $Id$ */
  3. /**
  4. * メールコンテンツモデル
  5. *
  6. * PHP versions 5
  7. *
  8. * baserCMS : Based Website Development Project <http://basercms.net>
  9. * Copyright 2008 - 2012, baserCMS Users Community <http://sites.google.com/site/baserusers/>
  10. *
  11. * @copyright Copyright 2008 - 2012, baserCMS Users Community
  12. * @link http://basercms.net baserCMS Project
  13. * @package baser.plugins.mail.models
  14. * @since baserCMS v 0.1.0
  15. * @version $Revision$
  16. * @modifiedby $LastChangedBy$
  17. * @lastmodified $Date$
  18. * @license http://basercms.net/license/index.html
  19. */
  20. /**
  21. * メールコンテンツモデル
  22. *
  23. * @package baser.plugins.mail.models
  24. *
  25. */
  26. class MailContent extends MailAppModel {
  27. /**
  28. * クラス名
  29. *
  30. * @var string
  31. * @access public
  32. */
  33. var $name = 'MailContent';
  34. /**
  35. * behaviors
  36. *
  37. * @var array
  38. * @access public
  39. */
  40. var $actsAs = array('BcContentsManager', 'BcPluginContent', 'BcCache');
  41. /**
  42. * hasMany
  43. *
  44. * @var array
  45. * @access public
  46. */
  47. var $hasMany = array('MailField'=>
  48. array('className'=>'Mail.MailField',
  49. 'order'=>'id',
  50. 'limit'=>100,
  51. 'foreignKey'=>'mail_content_id',
  52. 'dependent'=>true,
  53. 'exclusive'=>false,
  54. 'finderQuery'=>''));
  55. /**
  56. * validate
  57. *
  58. * @var array
  59. * @access public
  60. */
  61. var $validate = array(
  62. 'name' => array(
  63. array( 'rule' => array('halfText'),
  64. 'message' => 'メールフォームアカウント名は半角のみで入力してください。',
  65. 'allowEmpty'=> false),
  66. array( 'rule' => array('notInList', array('mail')),
  67. 'message' => 'メールフォームアカウント名に「mail」は利用できません。'),
  68. array( 'rule' => array('isUnique'),
  69. 'message' => '入力されたメールフォームアカウント名は既に使用されています。'),
  70. array( 'rule' => array('maxLength', 20),
  71. 'message' => 'メールフォームアカウント名は20文字以内で入力してください。')
  72. ),
  73. 'title' => array(
  74. array( 'rule' => array('notEmpty'),
  75. 'message' => "メールフォームタイトルを入力してください。"),
  76. array( 'rule' => array('maxLength', 50),
  77. 'message' => 'メールフォームタイトルは50文字以内で入力してください。')
  78. ),
  79. 'sender_name' => array(
  80. array( 'rule' => array('notEmpty'),
  81. 'message' => "送信先名を入力してください。"),
  82. array( 'rule' => array('maxLength', 50),
  83. 'message' => '送信先名は50文字以内で入力してください。')
  84. ),
  85. 'subject_user' => array(
  86. array( 'rule' => array('notEmpty'),
  87. 'message' => "自動返信メール件名[ユーザー宛]を入力してください。"),
  88. array( 'rule' => array('maxLength', 50),
  89. 'message' => '自動返信メール件名[ユーザー宛]は50文字以内で入力してください。')
  90. ),
  91. 'subject_admin' => array(
  92. array( 'rule' => array('notEmpty'),
  93. 'message' => "自動送信メール件名[管理者宛]を入力してください。"),
  94. array( 'rule' => array('maxLength', 50),
  95. 'message' => '自動返信メール件名[管理者宛]は50文字以内で入力してください。')
  96. ),
  97. 'layout_template' => array(
  98. array( 'rule' => array('halfText'),
  99. 'message' => 'レイアウトテンプレート名は半角のみで入力してください。',
  100. 'allowEmpty'=> false),
  101. array( 'rule' => array('maxLength', 20),
  102. 'message' => 'レイアウトテンプレート名は20文字以内で入力してください。')
  103. ),
  104. 'form_template' => array(
  105. array( 'rule' => array('halfText'),
  106. 'message' => "メールフォームテンプレート名は半角のみで入力してください。",
  107. 'allowEmpty'=> false),
  108. array( 'rule' => array('maxLength', 20),
  109. 'message' => 'フォームテンプレート名は20文字以内で入力してください。')
  110. ),
  111. 'mail_template' => array(
  112. array( 'rule' => array('halfText'),
  113. 'message' => "送信メールテンプレートは半角のみで入力してください。",
  114. 'allowEmpty'=> false),
  115. array( 'rule' => array('maxLength', 20),
  116. 'message' => 'メールテンプレート名は20文字以内で入力してください。')
  117. ),
  118. 'redirect_url' => array(
  119. array( 'rule' => array('url'),
  120. 'message' => "リダイレクトURLの形式が不正です。",
  121. 'allowEmpty'=> true),
  122. array( 'rule' => array('maxLength', 255),
  123. 'message' => 'リダイレクトURLは255文字以内で入力してください。')
  124. ),
  125. 'sender_1' => array(
  126. array( 'rule' => array('email'),
  127. 'allowEmpty'=> true,
  128. 'message' => '送信先メールアドレスの形式が不正です。'),
  129. array( 'rule' => array('maxLength', 255),
  130. 'message' => '送信先メールアドレスは255文字以内で入力してください。')
  131. ),
  132. 'sender_2' => array(
  133. array( 'rule' => array('maxLength', 255),
  134. 'message' => 'CC用送信先メールアドレスは255文字以内で入力してください。')
  135. ),
  136. 'ssl_on' => array(
  137. 'rule' => 'checkSslUrl',
  138. "message" => 'SSL通信を利用するには、システム設定で、事前にSSL通信用のWebサイトURLを指定してください。'
  139. )
  140. );
  141. /**
  142. * beforeValidate
  143. *
  144. * @return boolean
  145. * @access public
  146. */
  147. function beforeValidate() {
  148. if($this->data['MailContent']['sender_1']) {
  149. $this->validate['sender_1'] = array(
  150. array( 'rule' => 'email',
  151. 'message' => '送信先メールアドレスの形式が不正です。'));
  152. }
  153. return true;
  154. }
  155. /**
  156. * SSL用のURLが設定されているかチェックする
  157. *
  158. * @param string $check チェック対象文字列
  159. * @return boolean
  160. * @access public
  161. */
  162. function checkSslUrl($check) {
  163. if($check[key($check)]) {
  164. $sslUrl = Configure::read('BcEnv.sslUrl');
  165. if(empty($sslUrl)) {
  166. return false;
  167. } else {
  168. return true;
  169. }
  170. } else {
  171. return true;
  172. }
  173. }
  174. /**
  175. * 英数チェック
  176. *
  177. * @param string $check チェック対象文字列
  178. * @return boolean
  179. * @access public
  180. */
  181. function alphaNumeric($check) {
  182. if(preg_match("/^[a-z0-9]+$/",$check[key($check)])) {
  183. return true;
  184. }else {
  185. return false;
  186. }
  187. }
  188. /**
  189. * フォームの初期値を取得する
  190. *
  191. * @return string
  192. * @access protected
  193. */
  194. function getDefaultValue() {
  195. $data['MailContent']['subject_user'] = 'お問い合わせ頂きありがとうございます';
  196. $data['MailContent']['subject_admin'] = 'お問い合わせを頂きました';
  197. $data['MailContent']['layout_template'] = 'default';
  198. $data['MailContent']['form_template'] = 'default';
  199. $data['MailContent']['mail_template'] = 'mail_default';
  200. $data['MailContent']['use_description'] = true;
  201. $data['MailContent']['auth_captcha'] = false;
  202. $data['MailContent']['ssl_on'] = false;
  203. $data['MailContent']['status'] = false;
  204. return $data;
  205. }
  206. /**
  207. * afterSave
  208. *
  209. * @return boolean
  210. * @access public
  211. */
  212. function afterSave($created) {
  213. // 検索用テーブルへの登録・削除
  214. if(!$this->data['MailContent']['exclude_search'] && $this->data['MailContent']['status'] ) {
  215. $this->saveContent($this->createContent($this->data));
  216. } else {
  217. $this->deleteContent($this->data['MailContent']['id']);
  218. }
  219. }
  220. /**
  221. * beforeDelete
  222. *
  223. * @return boolean
  224. * @access public
  225. */
  226. function beforeDelete() {
  227. return $this->deleteContent($this->id);
  228. }
  229. /**
  230. * 検索用データを生成する
  231. *
  232. * @param array $data
  233. * @return array
  234. * @access public
  235. */
  236. function createContent($data) {
  237. if(isset($data['MailContent'])) {
  238. $data = $data['MailContent'];
  239. }
  240. $_data = array();
  241. $_data['Content']['type'] = 'メール';
  242. $_data['Content']['model_id'] = $this->id;
  243. $_data['Content']['category'] = '';
  244. $_data['Content']['title'] = $data['title'];
  245. $_data['Content']['detail'] = $data['description'];
  246. $_data['Content']['url'] = '/'.$data['name'].'/index';
  247. $_data['Content']['status'] = $data['status'];
  248. return $_data;
  249. }
  250. /**
  251. * ユーザーグループデータをコピーする
  252. *
  253. * @param int $id
  254. * @param array $data
  255. * @return mixed UserGroup Or false
  256. */
  257. function copy($id, $data, $recursive = true) {
  258. if($id) {
  259. $data = $this->find('first', array('conditions' => array('MailContent.id' => $id), 'recursive' => -1));
  260. }
  261. $data['MailContent']['name'] .= '_copy';
  262. $data['MailContent']['title'] .= '_copy';
  263. unset($data['MailContent']['id']);
  264. unset($data['MailContent']['created']);
  265. unset($data['MailContent']['modified']);
  266. $this->create($data);
  267. $result = $this->save();
  268. if($result) {
  269. $result['MailContent']['id'] = $this->getInsertID();
  270. if($recursive) {
  271. $mailFields = $this->MailField->find('all', array('conditions' => array('MailField.mail_content_id' => $id), 'order' => 'MailField.sort', 'recursive' => -1));
  272. foreach($mailFields as $mailField) {
  273. $mailField['MailField']['mail_content_id'] = $result['MailContent']['id'];
  274. $this->MailField->copy(null, $mailField, array('sortUpdateOff' => true));
  275. }
  276. $Message = ClassRegistry::getObject('Message');
  277. $Message->createTable($result['MailContent']['name']);
  278. $Message->construction($result['MailContent']['id']);
  279. }
  280. return $result;
  281. } else {
  282. if(isset($this->validationErrors['name'])) {
  283. return $this->copy(null, $data, $recursive);
  284. } else {
  285. return false;
  286. }
  287. }
  288. }
  289. }
  290. ?>