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

/baser/plugins/blog/views/elements/blog_comments.php

https://github.com/hashing/basercms
PHP | 172 lines | 135 code | 13 blank | 24 comment | 13 complexity | d83adca54b3fe5b82383e381aaa35788 MD5 | raw file
Possible License(s): MIT
  1. <?php
  2. /* SVN FILE: $Id$ */
  3. /**
  4. * [PUBLISH] ブログコメント一覧
  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.blog.views
  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. $prefix = '';
  21. if(Configure::read('BcRequest.agent')) {
  22. $prefix = '/'.Configure::read('BcRequest.agentAlias');
  23. }
  24. ?>
  25. <script type="text/javascript">
  26. $(function(){
  27. loadAuthCaptcha();
  28. $("#BlogCommentAddButton").click(function(){
  29. sendComment();
  30. return false;
  31. });
  32. });
  33. /**
  34. * コメントを送信する
  35. */
  36. function sendComment() {
  37. var msg = '';
  38. if(!$("#BlogCommentName").val()){
  39. msg += 'お名前を入力してください\n';
  40. }
  41. if(!$("#BlogCommentMessage").val()){
  42. msg += 'コメントを入力してください\n';
  43. }
  44. <?php if($blogContent['BlogContent']['auth_captcha']): ?>
  45. if(!$("#BlogCommentAuthCaptcha").val()){
  46. msg += '画象の文字を入力してください\n';
  47. }
  48. <?php endif ?>
  49. if(!msg){
  50. $.ajax({
  51. url: $("#BlogCommentAddForm").attr('action'),
  52. type: 'POST',
  53. data: $("#BlogCommentAddForm").serialize(),
  54. dataType: 'html',
  55. beforeSend: function() {
  56. $("#BlogCommentAddButton").attr('disabled', 'disabled');
  57. $("#ResultMessage").slideUp();
  58. },
  59. success: function(result){
  60. if(result){
  61. <?php if($blogContent['BlogContent']['auth_captcha']): ?>
  62. loadAuthCaptcha();
  63. <?php endif ?>
  64. $("#BlogCommentName").val('');
  65. $("#BlogCommentEmail").val('');
  66. $("#BlogCommentUrl").val('');
  67. $("#BlogCommentMessage").val('');
  68. $("#BlogCommentAuthCaptcha").val('');
  69. var resultMessage = '';
  70. <?php if($blogContent['BlogContent']['comment_approve']): ?>
  71. resultMessage = '送信が完了しました。送信された内容は確認後公開させて頂きます。';
  72. <?php else: ?>
  73. var comment = $(result);
  74. comment.hide();
  75. $("#BlogCommentList").append(comment);
  76. comment.show(500);
  77. resultMessage = 'コメントの送信が完了しました。';
  78. <?php endif ?>
  79. $("#ResultMessage").html(resultMessage);
  80. $("#ResultMessage").slideDown();
  81. }else{
  82. <?php if($blogContent['BlogContent']['auth_captcha']): ?>
  83. loadAuthCaptcha();
  84. <?php endif ?>
  85. $("#ResultMessage").html('コメントの送信に失敗しました。入力内容を見なおしてください。');
  86. $("#ResultMessage").slideDown();
  87. }
  88. },
  89. error: function(result){
  90. alert('コメントの送信に失敗しました。入力内容を見なおしてください。');
  91. },
  92. complete: function(xhr, textStatus) {
  93. $("#BlogCommentAddButton").removeAttr('disabled');
  94. }
  95. });
  96. }else{
  97. alert(msg);
  98. }
  99. }
  100. /**
  101. * キャプチャ画像を読み込む
  102. */
  103. function loadAuthCaptcha(){
  104. var src = $("#BlogCommentCaptchaUrl").html()+'?'+Math.floor( Math.random() * 100 );
  105. $("#AuthCaptchaImage").hide();
  106. $("#CaptchaLoader").show();
  107. $("#AuthCaptchaImage").load(function(){
  108. $("#CaptchaLoader").hide();
  109. $("#AuthCaptchaImage").fadeIn(1000);
  110. });
  111. $("#AuthCaptchaImage").attr('src',src);
  112. }
  113. </script>
  114. <div id="BlogCommentCaptchaUrl" class="display-none"><?php echo $bcBaser->getUrl($prefix.'/blog/blog_comments/captcha') ?></div>
  115. <?php if($blogContent['BlogContent']['comment_use']): ?>
  116. <div id="BlogComment">
  117. <h4 class="contents-head">この記事へのコメント</h4>
  118. <div id="BlogCommentList">
  119. <?php if(!empty($post['BlogComment'])): ?>
  120. <?php foreach($post['BlogComment'] as $comment): ?>
  121. <?php $bcBaser->element('blog_comment', array('dbData'=>$comment)) ?>
  122. <?php endforeach ?>
  123. <?php endif ?>
  124. </div>
  125. <h4 class="contents-head">コメントを送る</h4>
  126. <?php echo $bcForm->create('BlogComment', array('url' => $prefix.'/blog/blog_comments/add/'.$blogContent['BlogContent']['id'].'/'. $post['BlogPost']['id'], 'id' => 'BlogCommentAddForm')) ?>
  127. <table cellpadding="0" cellspacing="0" class="row-table-01">
  128. <tr>
  129. <th><?php echo $bcForm->label('BlogComment.name','お名前') ?></th>
  130. <td><?php echo $bcForm->input('BlogComment.name', array('type' => 'text')) ?></td>
  131. </tr>
  132. <tr>
  133. <th><?php echo $bcForm->label('BlogComment.email','Eメール') ?></th>
  134. <td>
  135. <?php echo $bcForm->input('BlogComment.email', array('type' => 'text', 'size'=>30)) ?>&nbsp;
  136. <small> メールは公開されません</small>
  137. </td>
  138. </tr>
  139. <tr>
  140. <th><?php echo $bcForm->label('BlogComment.url','URL') ?></th>
  141. <td><?php echo $bcForm->input('BlogComment.url',array('type' => 'text', 'size'=>30)) ?></td>
  142. </tr>
  143. <tr>
  144. <th><?php echo $bcForm->label('BlogComment.message','コメント') ?></th>
  145. <td><?php echo $bcForm->input('BlogComment.message', array('type' => 'textarea', 'rows' => 10, 'cols' => 60)) ?></td>
  146. </tr>
  147. </table>
  148. <?php if($blogContent['BlogContent']['auth_captcha']): ?>
  149. <div class="auth-captcha clearfix">
  150. <img src="" alt="認証画象" class="auth-captcha-image" id="AuthCaptchaImage" style="display:none" />
  151. <?php $bcBaser->img('/img/captcha_loader.gif', array('alt' => 'Loading...', 'class' => 'auth-captcha-image', 'id'=>'CaptchaLoader')) ?>
  152. <?php echo $bcForm->text('BlogComment.auth_captcha') ?><br />
  153. &nbsp;画像の文字を入力してください<br />
  154. </div>
  155. <?php endif ?>
  156. <?php echo $bcForm->end(array('label'=>'  送信する  ','id'=>'BlogCommentAddButton')) ?>
  157. <div id="ResultMessage" class="message" style="display:none;text-align:center">&nbsp;</div>
  158. </div>
  159. <?php endif ?>