<commit_before><?php
if ($diary)
{
  $title = __('Edit the diary');
  $diaryId    = $diary->getId();
  $diaryTitle = $diary->getTitle();
  $diaryBody  = $diary->getBody();
  $publicFlag = $diary->getPublicFlag();
}
else
{
  $title = __('Post a diary');
  $diaryId    = '';
  $diaryTitle = '';
  $diaryBody  = '';
  $publicFlag = 1;
}
use_helper('opAsset', 'opDiary');
op_smt_use_stylesheet('/opDiaryPlugin/css/smt-diary.css', 'last');
op_smt_use_javascript('jquery-ui.min.js', 'last');
op_smt_use_javascript('/opDiaryPlugin/js/jquery.upload-1.0.2.min.js', 'last');
op_smt_use_javascript('op_emoji.js', 'last');
op_smt_use_javascript('Selection.js', 'last');
op_smt_use_javascript('decoration.js', 'last');
?>

<script id="successMessageTemplate" type="text/x-jquery-tmpl">
    投稿しました<br/>
    <a href="<?php echo public_path('diary') ?>/${id}">日記を見る</a>
</script>

<script type="text/javascript">
function op_get_relative_uri_root()
{
  return "<?php echo $relativeUrlRoot;?>";
}

function getParams()
{
  var query = $('form').serializeArray(),
  json = {apiKey: openpne.apiKey};
  for (i in query)
  {
    json[query[i].name] = query[i].value
  }

  $('input[type="file"]').each(function() {
    if ($(this).val())
    {
      json[$(this).attr('name')] = $(this).val();
    }
  });

  return json;
}

function toggleSubmitState()
{
  $('#loading').toggle();
  $('input[name=submit]').toggle();
}

$(function(){
  $("#diary_body").opEmoji();

  $("#post_diary").click(function()
  {
    $('#successMessage').html('');
    toggleSubmitState();
    var params = getParams();
    var form = $('form');
    var fd = new FormData(form[0]);

    for (i in params)
    {
      fd.append(i, params[i]);
    }

    $.ajax({
      url: openpne.apiBase + "diary/post.json",
      type: 'POST',
      processData: false,
      contentType: false,
      data: fd,
      dataType: 'json',
      success: function(res) {
        if (params['id'] == '')
        {
          $('#id').val('');
          $('#title').val('');
          $('#diary_body').val('');
          $('#diary_public_flag_1').attr('checked', true);
          $('#diary_photo_1').val('');
          $('#diary_photo_2').val('');
          $('#diary_photo_3').val('');
        }
        var _mes = $('#successMessageTemplate').tmpl(res['data']);
        $('#successMessage').html(_mes);
      },
      error: function(e) {
        var em = e.responseText;
        if (-1 !== em.indexOf('Invalid mime type'))
        {
          alert('ファイル形式が間違っています。');
        }
        else if (-1 !== em.indexOf('File is too large'))
        {
          alert('ファイルサイズが大きすぎます。');
        }
        else if (-1 !== em.indexOf('File upload stopped by extension'))
        {
          alert('ファイル拡張子が対応していません。');
        }
        else
        {
          alert('ファイルアップロードに失敗しました。');
        }
        //alert(e.responseText);
      },
      complete: function() {
        toggleSubmitState();
      }
    });
  });
})
</script>

<div class="row">
  <div class="gadget_header span12"><?php echo __($title) ?></div><commit_msg>Remove unnecessary branch and comment.<commit_after><?php
if ($diary)
{
  $title = __('Edit the diary');
  $diaryId    = $diary->getId();
  $diaryTitle = $diary->getTitle();
  $diaryBody  = $diary->getBody();
  $publicFlag = $diary->getPublicFlag();
}
else
{
  $title = __('Post a diary');
  $diaryId    = '';
  $diaryTitle = '';
  $diaryBody  = '';
  $publicFlag = 1;
}
use_helper('opAsset', 'opDiary');
op_smt_use_stylesheet('/opDiaryPlugin/css/smt-diary.css', 'last');
op_smt_use_javascript('jquery-ui.min.js', 'last');
op_smt_use_javascript('/opDiaryPlugin/js/jquery.upload-1.0.2.min.js', 'last');
op_smt_use_javascript('op_emoji.js', 'last');
op_smt_use_javascript('Selection.js', 'last');
op_smt_use_javascript('decoration.js', 'last');
?>

<script id="successMessageTemplate" type="text/x-jquery-tmpl">
    投稿しました<br/>
    <a href="<?php echo public_path('diary') ?>/${id}">日記を見る</a>
</script>

<script type="text/javascript">
function op_get_relative_uri_root()
{
  return "<?php echo $relativeUrlRoot;?>";
}

function getParams()
{
  var query = $('form').serializeArray(),
  json = {apiKey: openpne.apiKey};
  for (i in query)
  {
    json[query[i].name] = query[i].value
  }

  $('input[type="file"]').each(function() {
    if ($(this).val())
    {
      json[$(this).attr('name')] = $(this).val();
    }
  });

  return json;
}

function toggleSubmitState()
{
  $('#loading').toggle();
  $('input[name=submit]').toggle();
}

$(function(){
  $("#diary_body").opEmoji();

  $("#post_diary").click(function()
  {
    $('#successMessage').html('');
    toggleSubmitState();
    var params = getParams();
    var form = $('form');
    var fd = new FormData(form[0]);

    for (i in params)
    {
      fd.append(i, params[i]);
    }

    $.ajax({
      url: openpne.apiBase + "diary/post.json",
      type: 'POST',
      processData: false,
      contentType: false,
      data: fd,
      dataType: 'json',
      success: function(res) {
        if (params['id'] == '')
        {
          $('#id').val('');
          $('#title').val('');
          $('#diary_body').val('');
          $('#diary_public_flag_1').attr('checked', true);
          $('#diary_photo_1').val('');
          $('#diary_photo_2').val('');
          $('#diary_photo_3').val('');
        }
        var _mes = $('#successMessageTemplate').tmpl(res['data']);
        $('#successMessage').html(_mes);
      },
      error: function(e) {
        var em = e.responseText;
        if (-1 !== em.indexOf('Invalid mime type'))
        {
          alert('ファイル形式が間違っています。');
        }
        else if (-1 !== em.indexOf('File is too large'))
        {
          alert('ファイルサイズが大きすぎます。');
        }
        else
        {
          alert('ファイルアップロードに失敗しました。');
        }
      },
      complete: function() {
        toggleSubmitState();
      }
    });
  });
})
</script>

<div class="row">
  <div class="gadget_header span12"><?php echo __($title) ?></div>
{'fraction_non_alphanumeric': 0.21576486305945225, 'fraction_numerical': 0.0045090180360721445, 'mean_word_length': 2.8638709677419354, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3869704', 'n_tokens_mistral': 2177, 'n_tokens_neox': 2180, 'n_words': 345}