[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

/gp-includes/routes/ -> note.php (source)

   1  <?php
   2  /**
   3   * Routes: GP_Route_Note class
   4   *
   5   * @package GlotPress
   6   * @subpackage Routes
   7   * @since 3.0.0
   8   */
   9  
  10  /**
  11   * Class for all note related actions
  12   *
  13   * @since 3.0.0
  14   */
  15  class GP_Route_Note extends GP_Route_Main {
  16  
  17      /**
  18       * Processes the note set action to set on the translation.
  19       *
  20       * @since 3.0.0
  21       *
  22       * @return string $html The new row.
  23       */
  24  	public function new_post() {
  25          $translation_id = gp_post( 'translation_id' );
  26          $note           = gp_post( 'note' );
  27          $translation    = GP::$translation->get( $translation_id );
  28          $admin          = GP::$permission->current_user_can( 'approve', 'translation', $translation_id, array( 'translation' => $translation ) );
  29  
  30          if ( get_current_user_id() !== (int) $translation->user_id && ! $admin ) {
  31              return $this->die_with_error( __( 'Sorry, you are not allowed to create this note.', 'glotpress' ), 403 );
  32          }
  33  
  34          if ( ! $this->verify_nonce( 'new-note-' . $translation_id ) ) {
  35              return $this->die_with_error( __( 'An error has occurred. Please try again.', 'glotpress' ), 403 );
  36          }
  37  
  38          $this->notices[] = __( 'The note was created!', 'glotpress' );
  39          $note            = GP::$notes->save();
  40  
  41          $this->tmpl( 'note', get_defined_vars() );
  42  
  43          return $note;
  44      }
  45  
  46      /**
  47       * Processes the note set action to set on the translation.
  48       *
  49       * @since 3.0.0
  50       *
  51       * @return string $html The updated row.
  52       */
  53  	public function edit_post() {
  54          $translation_id = gp_post( 'translation_id' );
  55          $note           = gp_post( 'note' );
  56          $note_id        = gp_post( 'note_id' );
  57          $translation    = GP::$translation->get( $translation_id );
  58          $note_object    = GP::$notes->get( $note_id );
  59          $admin          = GP::$permission->current_user_can( 'approve', 'translation', $translation_id, array( 'translation' => $translation ) );
  60  
  61          if ( get_current_user_id() !== (int) $note_object->user_id && ! $admin ) {
  62              return $this->die_with_error( __( 'Sorry, you are not allowed to edit this note.', 'glotpress' ), 403 );
  63          }
  64  
  65          if ( ! $this->verify_nonce( 'edit-note-' . $note_id ) ) {
  66              return $this->die_with_error( __( 'An error has occurred. Please try again.', 'glotpress' ), 403 );
  67          }
  68  
  69          $this->notices[] = __( 'The note was updated!', 'glotpress' );
  70          $translation     = GP::$translation->get( $translation_id );
  71          $note            = GP::$notes->edit( $note_id, $note, $translation );
  72  
  73          $this->tmpl( 'note', get_defined_vars() );
  74      }
  75  
  76      /**
  77       * Processes the note set action to set on the translation.
  78       *
  79       * @since 3.0.0
  80       *
  81       * @return bool
  82       */
  83  	public function delete_post() {
  84          $translation_id = gp_post( 'translation_id' );
  85          $note_id        = gp_post( 'note_id' );
  86          $translation    = new GP_Translation( array( 'id' => $translation_id ) );
  87          $note_object    = GP::$notes->get( $note_id );
  88          $admin          = GP::$permission->current_user_can( 'approve', 'translation', $translation_id, array( 'translation' => $translation ) );
  89  
  90          if ( get_current_user_id() !== (int) $note_object->user_id && ! $admin ) {
  91              return $this->die_with_error( __( 'Sorry, you are not allowed to delete this note.', 'glotpress' ), 403 );
  92          }
  93  
  94          if ( ! $this->verify_nonce( 'delete-note-' . $note_id ) ) {
  95              return $this->die_with_error( __( 'An error has occurred. Please try again.', 'glotpress' ), 403 );
  96          }
  97  
  98          $this->notices[] = __( 'The note was deleted!', 'glotpress' );
  99          GP::$notes->delete_all( array( 'id' => $note_id ) );
 100  
 101          return true;
 102      }
 103  }


Generated: Sat Aug 17 01:01:56 2019 Cross-referenced by PHPXref 0.7.1