Server : Apache/2 System : Linux vps.sdns.vn 3.10.0-1160.15.2.el7.x86_64 #1 SMP Wed Feb 3 15:06:38 UTC 2021 x86_64 User : phatdatpq ( 1022) PHP Version : 7.2.34 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/phatdatpq/public_html/wp-content/plugins/loco-translate/src/ajax/ |
Upload File : |
<?php /** * Ajax "diff" route, for rendering PO/POT file diffs */ class Loco_ajax_DiffController extends Loco_mvc_AjaxController { /** * {@inheritdoc} */ public function render(){ $post = $this->validate(); // require x2 valid files for diffing if( ! $post->lhs || ! $post->rhs ){ throw new InvalidArgumentException('Path parameters required'); } $dir = loco_constant('WP_CONTENT_DIR'); $lhs = new Loco_fs_File( $post->lhs ); $lhs->normalize($dir); $rhs = new Loco_fs_File( $post->rhs ); $rhs->normalize($dir); // avoid diffing non Gettext source files $exts = array_flip( array( 'pot', 'pot~', 'po', 'po~' ) ); /* @var $file Loco_fs_File */ foreach( array($lhs,$rhs) as $file ){ if( ! $file->exists() ){ throw new InvalidArgumentException('File paths must exist'); } if( ! $file->underContentDirectory() ){ throw new InvalidArgumentException('Files must be under '.basename($dir) ); } $ext = $file->extension(); if( ! isset($exts[$ext]) ){ throw new InvalidArgumentException('Disallowed file extension'); } } // OK to diff files as HTML table $renderer = new Loco_output_DiffRenderer; $emptysrc = $renderer->_startDiff().$renderer->_endDiff(); $tablesrc = $renderer->renderFiles( $rhs, $lhs ); if( $tablesrc === $emptysrc ){ // translators: Where %s is a file name $message = __('Revisions are identical, you can delete %s','loco-translate'); $this->set( 'error', sprintf( $message, $rhs->basename() ) ); } else { $this->set( 'html', $tablesrc ); } return parent::render(); } }