Jump to content

Chrisj

Members
  • Posts

    551
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by Chrisj

  1. The php web video script that I'm using has two Forms. One for uploading videos, and one for editing the Form (in the User account > My Channel > Manage > edit-video).

    When I complete the edit-video Form and then select Publish, the Publish button changes to 'Please Wait'. But, when I select "Publish" on the Upload Form nothing appears to happen, for a while until the video is finished uploading. But the line of code seems to be the same in each of the files:

    $('#submit-btn').val("{{LANG please_wait}}");

    I'd like help so as to when the Upload Form "Publish button is selected it changes to Please Wait as, the edit-video Form does. Here is the edit-video Form <script> code:

    <script>
    $(function () {
    	$('.edit-thumb').on('click', function(event) {
    		$('#thumbnail').trigger('click');
    	});
    	$('#thumbnail').on('change', function(event) {
    		readURL(this);
    	});
    	$('#description').keyup(function(event) {
          str = $(this).val().replace(/(?:\r\n|\r|\n)/g, '<br />');
          $('.video-description p').html(str);
       });
       $('#title').keyup(function(event) {
          $('.video-title p').html($(this).val());
       });
    	$("#mySingleFieldTags").tagit({
    		allowSpaces: true
    	});
    	$('#edit-form form').ajaxForm({
    	    url: '{{LINK aj/edit-video}}' + '?hash=' + $('.main_session').val(),
    	    beforeSend: function() {
    	    	$('#submit-btn').attr('disabled', true);
    	    	$('#submit-btn').text("{{LANG please_wait}}");
    	    },
    	    success: function(data) {
    	    	if (data.status == 200) {
    	    		$('#video-success').html(data.message);
              window.location.href = '/manage-videos/';
               //window.location.href = '{{URL}}';
    	    	} else {
    	    		$('#submit-btn').attr('disabled', false);
    	    	    $('#submit-btn').html('<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-check-circle"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path><polyline points="22 4 12 14.01 9 11.01"></polyline></svg> {{LANG publish}}');
    	    		$('.errors').removeClass('hidden').html(data.message);
    	    	}
    	    }
    	});
    });
    </script>

    Here is the Upload video Form <script> code:

     

    <script>
    $(function () {
    
       var video_drop_block = $("[data-block='video-drop-zone']");
    
       if (typeof(window.FileReader)){
          video_drop_block[0].ondragover = function() {
             video_drop_block.addClass('hover');
             return false;
          };
    
          video_drop_block[0].ondragleave = function() {
             video_drop_block.removeClass('hover');
             return false;
          };
    
          video_drop_block[0].ondrop = function(event) {
             event.preventDefault();
             video_drop_block.removeClass('hover');
             var file = event.dataTransfer.files;
             $('#upload-video').find('input').prop('files', file);
          };
       }
    
    	$("#mySingleFieldTags").tagit({
          allowSpaces: true
       });
    	var bar         = $('.bar');
       var percent     = $('.percent');
       var prcsvdo		= $('.pt_prcs_vdo');
       var is_uploaded = false;
       var video_thumb = Array();
    
    	$('#upload-video').submit(function(event) {
          let file_size = $(".upload-video-file").prop('files')[0].size;
          if (file_size > "{{CONFIG max_upload}}") {
             swal({
                title: '{{LANG error}}',
                text:  "{{LANG file_is_too_big}} <?php echo pt_size_format($pt->config->max_upload); ?>",
                type: 'error',
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: 'OK',
                buttonsStyling: true,
                confirmButtonClass: 'btn btn-success',
             }).then(function(){
                swal.close();
                $('.upload-video-file').val('');
             },
             function() {
                swal.close();
                $('.upload-video-file').val('');
             });
             return false;
          }
          else{
             var filename = $('.upload').val().split('\\').pop();
             $('#title').val(filename);
             $('#upload-form').removeClass('hidden');
             $('.upload').addClass('hidden');
          }
       });
    
       $('#choose-thumnail-cr').bind('slid.bs.carousel', function (e) {
          var vsthumb = video_thumb[$(this).find('.active').index()];
          $("#video-thumnail").val(vsthumb);
       });
    
       $('#upload-video').ajaxForm({
          url: '{{LINK aj/upload-video-ffmpeg}}?hash=' + $('.main_session').val(),
          dataType:'json',
          beforeSend: function() {
             $('.progress').removeClass('hidden');
             var percentVal = '0%';
             bar.width(percentVal);
             percent.html(percentVal);
          },
          uploadProgress: function(event, position, total, percentComplete) {
             if(percentComplete > 50) {
                percent.addClass('white');
             }
             var percentVal = percentComplete + '%';
             bar.width(percentVal);
             percent.html(percentVal);
    
             if (percentComplete == 100) {
                prcsvdo.html('<svg width="30" height="10" viewBox="0 0 120 30" xmlns="http://www.w3.org/2000/svg" fill="#000"><circle cx="15" cy="15" r="15"><animate attributeName="r" from="15" to="15" begin="0s" dur="0.8s" values="15;9;15" calcMode="linear" repeatCount="indefinite" /><animate attributeName="fill-opacity" from="1" to="1" begin="0s" dur="0.8s" values="1;.5;1" calcMode="linear" repeatCount="indefinite" /></circle><circle cx="60" cy="15" r="9" fill-opacity="0.3"><animate attributeName="r" from="9" to="9" begin="0s" dur="0.8s" values="9;15;9" calcMode="linear" repeatCount="indefinite" /><animate attributeName="fill-opacity" from="0.5" to="0.5" begin="0s" dur="0.8s" values=".5;1;.5" calcMode="linear" repeatCount="indefinite" /></circle><circle cx="105" cy="15" r="15"><animate attributeName="r" from="15" to="15" begin="0s" dur="0.8s" values="15;9;15" calcMode="linear" repeatCount="indefinite" /><animate attributeName="fill-opacity" from="1" to="1" begin="0s" dur="0.8s" values="1;.5;1" calcMode="linear" repeatCount="indefinite" /></circle></svg> {{LANG porcessing_video}}');
                $('.progress').find('.bar').removeClass('upload-progress-bar');
             }
          },
          success: function(data) {
    	    	percentVal = '0%';
    	    	bar.width(percentVal);
             $('.progress').addClass('hidden');
    
             if (data.status == 200) {
             	$('#video-location').val(data.file_path);
             	Snackbar.show({text: '<i class="fa fa-check"></i> ' + data.file_name + ' {{LANG successfully_uplaoded}}'});
             	$('#submit-btn').attr('disabled', false);
             	$('.upload-video-file').val('');
    			$('#title').val(data.file_name);
                $("#video-thumnails").removeClass('hidden');
    
                var i       = 0;
                var url     = '{img}';
                video_thumb = data.images;
    
                $("#video-thumnails").find('.item').each(function(index, el) {
                   if (i == 0) {
                      $("#video-thumnail").val(data.images[i]);
                   }
    
                   $(el).html($("<img>",{
                      src:url.replace('{img}',data.images[i])
                   }));
                   i++;
                });
             }
             else if(data.status == 401){
                swal({
                   title: '{{LANG oops}}!',
                   text: "{{LANG upload_limit_reached}}!",
                   type: 'info',
                   showCancelButton: true,
                   confirmButtonColor: '#3085d6',
                   cancelButtonColor: '#d33',
                   confirmButtonText: '{{LANG upgrade_now}}',
                   cancelButtonText: '{{LANG cancel}}',
                   confirmButtonClass: 'btn btn-success margin-right',
                   cancelButtonClass: 'btn',
                   buttonsStyling: false
                }).then(function(){
                   window.location.href = '{{LINK go_pro}}';
                },
                function() {
                   window.location.href = '{{LINK }}';
                });
             }
             else if(data.status == 402){
                swal({
                   title: '{{LANG error}}',
                   text: data.message,
                   type: 'error',
                   confirmButtonColor: '#3085d6',
                   cancelButtonColor: '#d33',
                   confirmButtonText: 'OK',
                   buttonsStyling: true,
                   confirmButtonClass: 'btn btn-success',
                }).then(function(){
                   swal.close();
                   $('.upload-video-file').val('');
                },
                function() {
                   swal.close();
                   $('.upload-video-file').val('');
                });
             }
             else {
             	Snackbar.show({showAction: false,backgroundColor: '#e22e40',text: '<div>'+ data.error +'</div>'});
             }
    	    }
    	});
    
    	$('#upload-form form').ajaxForm({
          url: '{{LINK aj/ffmpeg-submit}}'+'?hash=' + $('.main_session').val(),
          beforeSend: function() {
             $('#submit-btn').attr('disabled', true);
             $('#submit-btn').val("{{LANG please_wait}}");
          },
    
          success: function(data) {
    	    	if (data.status == 200) {
    	    		window.location.href = data.link;
    	    	}
             else if(data.status == 402){
                swal({
                   title: '{{LANG error}}',
                   text: data.message,
                   type: 'error',
                   confirmButtonColor: '#3085d6',
                   cancelButtonColor: '#d33',
                   confirmButtonText: 'OK',
                   buttonsStyling: true,
                   confirmButtonClass: 'btn btn-success',
                }).then(function(){
                   window.location.href = '{{LINK upload-video}}';
                },
                function() {
                   window.location.href = '{{LINK }}';
                });
             }
             else {
    	    		$('#submit-btn').attr('disabled', false);
    	    	    $('#submit-btn').val('{{LANG publish}}');
    	    		Snackbar.show({text: '<div>'+ data.message +'</div>'});
    	    	}
          }
    	});
    
    	$('.upload-video-file').on('change', function() {
       	$('#upload-video').submit();
    	});
    });
    
    function PT_OpenUploadForm() {
    	$('#upload-video').find('input').trigger('click');
    }
    </script>
    
    
    
    
    
    
    
    
    

    Any help will be appreciated

  2. I have added a spinning gif successfully to this web page, now I am seeking help so that it only appears when the Form submit button is selected. Any help will be appreciated.

    <div class="wo_about_wrapper_parent">
    	<div class="wo_about_wrapper">
    		<div class="hero hero-overlay" style="background-color: #d84c47;">
    			<div class="container">
    				<h1 class="text-center">{{LANG upload_new_video}}</h1>
    			</div>
    		</div>
    		<svg id="wave" viewBox="0 0 100 15"><path fill="#d84c47" opacity="0.5" d="M0 30 V15 Q30 3 60 15 V30z"></path><path fill="#d84c47" d="M0 30 V12 Q30 17 55 12 T100 11 V30z"></path></svg>
    	</div>
    </div>
    <div class="col-md-2"></div>
    <div class="col-md-8 pt_page_margin">
    	<div class="content pt_shadow">
    		<div class="col-md-12 pt_upload_vdo">
    			<?php if ($pt->user->admin == 1) { ?>
    				<div class="alert alert-warning">
    					<h4>Just admins can see this message</h4>
    					<p>Note: Your server max upload size is: <?php echo ini_get('upload_max_filesize')?>, means you can't upload files that are larger than: <?php echo ini_get('upload_max_filesize')?><br><br> If you want to increase the limit or If you can't upload large files, go to Admin Settings > Settings > Site Settings > Max upload size and increase the value, if you still can't upload large files, please contact your host provider and let them increase the upload limit and max_execution_time.</p>
    				</div>
    			<?php } ?>
    			<div class="upload upload-video" data-block="video-drop-zone">
    				<div>
    					<svg fill="currentColor" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg" class="feather feather-upload"><path d="M14,13V17H10V13H7L12,8L17,13M19.35,10.03C18.67,6.59 15.64,4 12,4C9.11,4 6.6,5.64 5.35,8.03C2.34,8.36 0,10.9 0,14A6,6 0 0,0 6,20H19A5,5 0 0,0 24,15C24,12.36 21.95,10.22 19.35,10.03Z" /></svg>
    					<h4>{{LANG darg_drop_video}}</h4>
    					<p>{{LANG or}} {{LANG click_2choose_file}}</p>
    					<button class="btn btn-main">{{LANG upload}}</button>
    				</div>
    			</div>
    			<div class="progress hidden">
    				<span class="percent">0%</span>
    				<div class="progress_bar_parent">
    					<div class="bar upload-progress-bar progress-bar active"></div>
    				</div>
    				<div class="clear"></div>
    				<div class="text-center pt_prcs_vdo"></div>
    			</div>
    
    <style>
    .form-group1.hidden {
      visibility:hidden;
    }
    .form-group1.hidden {  /*this is being used, it overrides the previous rule*/
      position:absolute;
      left:-999em;
    }
    p {margin:0}
    </style>
    
    			<form action="" method="POST" id="upload-video" style="visibility: hidden;">
    				<input type="file" name="video" accept="video/*" class="upload-video-file">
    			</form>
    			<div class="fluid upload-ffmpeg-mode hidden" id="upload-form">
    				<div class="col-md-12">
    					<form action="" class="form-horizontal setting-panel pt_forms" method="POST">
    						<div class="form-group">
    							<label class="col-md-12" for="title">{{LANG video_title}}</label>
    							<div class="col-md-12">
    								<input id="title" name="title" type="text" placeholder="" class="form-control input-md">
    								<span class="help-block">{{LANG video_title_help}}</span>
    							</div>
    						</div>
    						<div class="form-group">
    							<label class="col-md-12" for="description">{{LANG video_description}}</label>
    							<div class="col-md-12">
    								<textarea name="description" id="description" cols="30" rows="5" class="form-control"></textarea>
    							</div>
    						</div>
    						<div class="form-group">
    							<label class="col-md-12" for="category_id">{{LANG category}}</label>
    							<div class="col-md-12">
    								<select name="category_id" id="category_id" class="form-control">
    									<?php foreach($pt->categories as $key => $category) {?>
    									<option value="<?php echo $key?>"><?php echo $category?></option>
    									<?php } ?>
    								</select>
    							</div>
    						</div>
                      <!--<div class="form-group1">--><div class="form-group1 hidden">
                         <!--<label class="col-md-12" for="privacy">{{LANG privacy}}</label>-->
                         <!--<div class="col-md-12">-->
                            <select name="privacy" id="privacy" class="form-control">
                                  <option hidden value="0">public</option>
    						      <option hidden value="1">private</option>
        						  <option selected value="2"></option>
                                   <!--<option value="2">{{LANG unlisted}}</option>-->
                            </select>
                         <!--</div>-->
                      </div>
                      <div class="form-group1 hidden">
                            <!--<label class="col-md-12" for="age_restriction">{{LANG age_restriction}}</label>-->
                            <!--<div class="col-md-12">-->
                               <select name="age_restriction" id="age_restriction" class="form-control">
                                  <option selected value="1">{{LANG all_ages}}</option>
                                  <option hidden value="2"></option>
                               </select>
                            <!--</div>-->
                         </div>
    						<div class="form-group">
    							<label class="col-md-12" for="tags">{{LANG tags}}</label>
    							<div class="col-md-12">
    								<input id="mySingleFieldTags" name="tags" type="text" placeholder="" class="form-control input-md">
    								<span class="help-block">{{LANG tags_help}}</span>
    							</div>
    						</div>
    
    						<div class="form-group hidden" id="video-thumnails">
    							<label class="col-md-12" for="thumbnail">{{LANG thumbnail}}</label>
    							<div class="col-md-12">
    								<div class="fluid">
    									<div class="carousel slide" id="choose-thumnail-cr" data-interval="false" style="cursor: pointer">
    										<div class="carousel-inner">
    											<div class="item active"></div>
    										</div>
    										<div class="fluid choose-thumnail-control">
    											<span class="pull-left">{{LANG video_thumbs}}</span>
    											<span class="pull-right">
    												<a class="btn btn-default" href="#choose-thumnail-cr" data-slide="prev">
    													<i class="fa fa-caret-left"></i>
    												</a>
    												<a class="btn btn-default" href="#choose-thumnail-cr"  data-slide="next">
    													<i class="fa fa-caret-right"></i>
    												</a>
    											</span>
    										</div>
    									</div>
    								</div>
    							</div>
    						</div>
    						<div class="last-sett-btn modal-footer" style="margin: 0px -40px -10px -40px;">
    							<button type="submit" id="submit-btn" class="btn btn-main setting-panel-mdbtn" disabled><svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-check-circle'><path d='M22 11.08V12a10 10 0 1 1-5.93-9.14'></path><polyline points='22 4 12 14.01 9 11.01'></polyline></svg> {{LANG publish}}</button>
    						</div>
    						<input type="hidden" name="video-location" id="video-location" value="">
    						<input type="hidden" name="video-thumnail" id="video-thumnail" value="">
    
    					</form>
    				</div>
    			</div>
    			<div class="clear"></div>
    		</div>
    		<div class="clear"></div>
    	</div>
    </div>
    <form action="" id="thumbnail-form" method="POST">
       <input id="thumbnail" name="thumbnail" type="file" style="visibility: hidden;" accept="image/*">
       <div class="loading-spinner"></div>
    </form>
    <div class="col-md-2"></div>
    
    <style>
    .loading-spinner {
      -webkit-animation-play-state: running;
              animation-play-state: running;
      opacity: 1;
      position: relative;
      height: 100vh;
    }
    @-webkit-keyframes spinner {
      0% {
        -webkit-transform: translate3d(-50%, -50%, 0) rotate(0deg);
                transform: translate3d(-50%, -50%, 0) rotate(0deg);
      }
      100% {
        -webkit-transform: translate3d(-50%, -50%, 0) rotate(360deg);
                transform: translate3d(-50%, -50%, 0) rotate(360deg);
      }
    }
    @keyframes spinner {
      0% {
        -webkit-transform: translate3d(-50%, -50%, 0) rotate(0deg);
                transform: translate3d(-50%, -50%, 0) rotate(0deg);
      }
      100% {
        -webkit-transform: translate3d(-50%, -50%, 0) rotate(360deg);
                transform: translate3d(-50%, -50%, 0) rotate(360deg);
      }
    }
    .loading-spinner.-paused {
      -webkit-animation-play-state: paused;
              animation-play-state: paused;
      opacity: 0.2;
      transition: opacity linear 0.1s;
    }
    .loading-spinner::before {
      -webkit-animation: 1.5s linear infinite spinner;
              animation: 1.5s linear infinite spinner;
      -webkit-animation-play-state: inherit;
              animation-play-state: inherit;
      border: solid 3px #dedede;
      border-bottom-color: #EF6565;
      border-radius: 50%;
      content: "";
      height: 40px;
      left: 50%;
      opacity: inherit;
      position: absolute;
      top: 50%;
      -webkit-transform: translate3d(-50%, -50%, 0);
              transform: translate3d(-50%, -50%, 0);
      width: 40px;
      will-change: transform;
    }
    </style>
    
    
    
    <script>
    var video_thumb = Array();
    $(document).on('click', '.carousel-inner', function(event) {
    
       $('#thumbnail').trigger('click');
    });
    $('#thumbnail').change(function(event) {
       $.ajax({
            type: 'POST',
            url: "{{LINK aj/upload-thumbnail}}?hash=" + $('.main_session').val() ,
            data: new FormData($("#thumbnail-form")[0]),
            processData: false,
            contentType: false,
            success: function(data) {
                $('.carousel-inner').append('<div class="item"><img src="' + data.thumbnail + '"></div>');
                video_thumb.push(data.thumbnail);
                $('#video-thumnail').val(data.thumbnail);
                $(".carousel-inner").find('.item').removeClass('active');
                $(".carousel-inner").find('.item:last').addClass('active');
            }
        });
    });
    $(function () {
    
       var video_drop_block = $("[data-block='video-drop-zone']");
    
       if (typeof(window.FileReader)){
          video_drop_block[0].ondragover = function() {
             video_drop_block.addClass('hover');
             return false;
          };
    
          video_drop_block[0].ondragleave = function() {
             video_drop_block.removeClass('hover');
             return false;
          };
    
          video_drop_block[0].ondrop = function(event) {
             event.preventDefault();
             video_drop_block.removeClass('hover');
             var file = event.dataTransfer.files;
             $('#upload-video').find('input').prop('files', file);
          };
       }
    
    	$("#mySingleFieldTags").tagit({
          allowSpaces: true
       });
    	var bar         = $('.bar');
       var percent     = $('.percent');
       var prcsvdo		= $('.pt_prcs_vdo');
       var is_uploaded = false;
    
    
    	$('#upload-video').submit(function(event) {
          var file_size = $(".upload-video-file").prop('files')[0].size;
          if (file_size > "{{CONFIG max_upload}}") {
             swal({
                title: '{{LANG error}}',
                text:  "{{LANG file_is_too_big}} <?php echo pt_size_format($pt->config->max_upload); ?>",
                type: 'error',
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: 'OK',
                buttonsStyling: true,
                confirmButtonClass: 'btn btn-success',
             }).then(function(){
                swal.close();
                $('.upload-video-file').val('');
             },
             function() {
                swal.close();
                $('.upload-video-file').val('');
             });
             return false;
          }
          else{
             var filename = $('.upload').val().split('\\').pop();
             $('#title').val(filename);
             $('#upload-form').removeClass('hidden');
             $('.upload').addClass('hidden');
          }
       });
    
       $('#choose-thumnail-cr').bind('slid.bs.carousel', function (e) {
          console.log(video_thumb);
          var vsthumb = video_thumb[$(this).find('.active').index()];
          console.log(vsthumb);
          $("#video-thumnail").val(vsthumb);
       });
    
       $('#upload-video').ajaxForm({
          url: '{{LINK aj/upload-video-ffmpeg}}?hash=' + $('.main_session').val(),
          dataType:'json',
          beforeSend: function() {
             $('.progress').removeClass('hidden');
             var percentVal = '0%';
             bar.width(percentVal);
             percent.html(percentVal);
          },
          uploadProgress: function(event, position, total, percentComplete) {
             if(percentComplete > 50) {
                percent.addClass('white');
             }
             var percentVal = percentComplete + '%';
             bar.width(percentVal);
             percent.html(percentVal);
    
             if (percentComplete == 100) {
                prcsvdo.html('<svg width="30" height="10" viewBox="0 0 120 30" xmlns="http://www.w3.org/2000/svg" fill="#000"><circle cx="15" cy="15" r="15"><animate attributeName="r" from="15" to="15" begin="0s" dur="0.8s" values="15;9;15" calcMode="linear" repeatCount="indefinite" /><animate attributeName="fill-opacity" from="1" to="1" begin="0s" dur="0.8s" values="1;.5;1" calcMode="linear" repeatCount="indefinite" /></circle><circle cx="60" cy="15" r="9" fill-opacity="0.3"><animate attributeName="r" from="9" to="9" begin="0s" dur="0.8s" values="9;15;9" calcMode="linear" repeatCount="indefinite" /><animate attributeName="fill-opacity" from="0.5" to="0.5" begin="0s" dur="0.8s" values=".5;1;.5" calcMode="linear" repeatCount="indefinite" /></circle><circle cx="105" cy="15" r="15"><animate attributeName="r" from="15" to="15" begin="0s" dur="0.8s" values="15;9;15" calcMode="linear" repeatCount="indefinite" /><animate attributeName="fill-opacity" from="1" to="1" begin="0s" dur="0.8s" values="1;.5;1" calcMode="linear" repeatCount="indefinite" /></circle></svg> {{LANG processing_video}}');
                $('.progress').find('.bar').removeClass('upload-progress-bar');
             }
          },
          success: function(data) {
    	    	percentVal = '0%';
    	    	bar.width(percentVal);
             $('.progress').addClass('hidden');
    
             if (data.status == 200) {
             	$('#video-location').val(data.file_path);
             	Snackbar.show({text: '<i class="fa fa-check"></i> ' + data.file_name + ' {{LANG successfully_uploaded}}'});
             	$('#submit-btn').attr('disabled', false);
             	$('.upload-video-file').val('');
    			   $('#title').val(data.file_name);
                $("#video-thumnails").removeClass('hidden');
    
                var i       = 0;
                var url     = '{img}';
                video_thumb = data.images;
    
                $('.carousel-inner').html('');
                $.each(video_thumb, function( index, value ) {
                    $('.carousel-inner').append('<div class="item"><img src="' + value + '"></div>');
                    i++;
                });
                $(".carousel-inner").find('.item:first-child').addClass('active');
                $("#video-thumnail").val(video_thumb[0]);
                $('.carousel').carousel({
                  interval: false
                });
    

     

  3. Thanks again for your reply.

    No, the videos don't upload with the added part to watermark the video:

     

    -i /home/user/public_html/watermark.png -filter_complex 'overlay=10:10'

    without that, the videos upload successfully.

    The Media Error shown on my original posting, appears over the video player on the web page.

    It may not be a message from PHP, it may be a message from ffmpeg

     

    Any additional help will be appreciated

  4. Thanks for that. I'm not sure how to do that. Does this look correct?

     if ($video_res >= 854 || $video_res == 0) {
    error_log($shell     = shell_exec("$ffmpeg_b -y -i $video_file_full_path -i /home/user/public_html/watermark.jpg -filter_complex 'overlay=x=(main_w-overlay_w)/2:y=(main_h-overlay_h)/2' -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=854:-2 -crf 26 $video_output_full_path_480 2>&1"));
    $upload_s3 = PT_UploadToS3($filepath . "_480p_converted.mp4");
    $db->where('id', $insert);
     $db->update(T_VIDEOS, array(
    '480p' => 1
     ));
    }

     

  5. The php web video script that I'm using, has ffmpeg, and it uploads videos succesfully.

    I'm trying to add the ability to add a watermark onto the video upon upload. However, what I've added 

    -i /home/user/public_html/watermark.png -filter_complex 'overlay=10:10'

    shows N ERROR:

    Media error: Format(s) not supported or sources not found
    mejs.download-file: https://…com/upload/videos/2018/08/6SWCpSImGQrsVXGgIh7A_24_549ebe0d36bccb10faf72b81e303ce50_video_360p_converted.mp4

    mejs.download-file: https://…com/upload/videos/2018/08/Ubud1OqKHK7MPjvtbHw5_24_cdab9c4bc2a4eccc7c478526abb530d8_video_240p_converted.mp4

    Any suggestion/solution will be appreciated. Here's the entire file code:

    <?php
    if (IS_LOGGED == false || $pt->config->upload_system != 'on') {
        $data = array(
            'status' => 400,
            'error' => 'Not logged in'
        );
        echo json_encode($data);
        exit();
    } else if ($pt->config->ffmpeg_system != 'on') {
        $data = array(
            'status' => 402
        );
        echo json_encode($data);
        exit();
    } else {
        $getID3    = new getID3;
        $featured  = ($user->is_pro == 1) ? 1 : 0;
        $filesize  = 0;
        $error     = false;
        $request   = array();
        $request[] = (empty($_POST['title']) || empty($_POST['description']));
        $request[] = (empty($_POST['tags']) || empty($_POST['video-thumnail']));
        if (in_array(true, $request)) {
            $error = $lang->please_check_details;
        } else if (empty($_POST['video-location'])) {
            $error = $lang->video_not_found_please_try_again;
        } else {
            $request   = array();
            $request[] = (!in_array($_POST['video-location'], $_SESSION['uploads']['videos']));
            $request[] = (!in_array($_POST['video-thumnail'], $_SESSION['uploads']['images']));
            $request[] = (!file_exists($_POST['video-location']));
            if (in_array(true, $request)) {
                $error = $lang->error_msg;
            }
        }
        if (empty($error)) {
            $file     = $getID3->analyze($_POST['video-location']);
            $duration = '00:00';
            if (!empty($file['playtime_string'])) {
                $duration = PT_Secure($file['playtime_string']);
            }
            if (!empty($file['filesize'])) {
                $filesize = $file['filesize'];
            }
            $video_res = (!empty($file['video']['resolution_x'])) ? $file['video']['resolution_x'] : 0;
            $video_id        = PT_GenerateKey(15, 15);
            $check_for_video = $db->where('video_id', $video_id)->getValue(T_VIDEOS, 'count(*)');
            if ($check_for_video > 0) {
                $video_id = PT_GenerateKey(15, 15);
            }
            $thumbnail = PT_Secure($_POST['video-thumnail'], 0);
            if (file_exists($thumbnail)) {
                $upload = PT_UploadToS3($thumbnail);
            }
            $category_id = 0;
            $convert     = true;
            $thumbnail   = substr($thumbnail, strpos($thumbnail, "upload"), 120);
            if (!empty($_POST['category_id'])) {
                if (in_array($_POST['category_id'], array_keys($categories))) {
                    $category_id = PT_Secure($_POST['category_id']);
                }
            }
            $link_regex = '/(http\:\/\/|https\:\/\/|www\.)([^\ ]+)/i';
            $i          = 0;
            preg_match_all($link_regex, PT_Secure($_POST['description']), $matches);
            foreach ($matches[0] as $match) {
                $match_url            = strip_tags($match);
                $syntax               = '[a]' . urlencode($match_url) . '[/a]';
                $_POST['description'] = str_replace($match, $syntax, $_POST['description']);
            }
            $video_privacy = 0;
            if (!empty($_POST['privacy'])) {
                if (in_array($_POST['privacy'], array(0, 1, 2))) {
                    $video_privacy = PT_Secure($_POST['privacy']);
                }
            }
            $age_restriction = 1;
            if (!empty($_POST['age_restriction'])) {
                if (in_array($_POST['age_restriction'], array(1, 2))) {
                    $age_restriction = PT_Secure($_POST['age_restriction']);
                }
            }
            $data_insert = array(
                'video_id' => $video_id,
                'user_id' => $user->id,
                'title' => PT_Secure($_POST['title']),
                'description' => PT_Secure($_POST['description']),
                'tags' => PT_Secure($_POST['tags']),
                'duration' => $duration,
                'video_location' => '',
                'category_id' => $category_id,
                'thumbnail' => $thumbnail,
                'time' => time(),
                'registered' => date('Y') . '/' . intval(date('m')),
                'featured' => $featured,
                'converted' => '2',
                'size' => $filesize,
                'privacy' => $video_privacy,
                'age_restriction' => $age_restriction
            );
            if ($pt->config->approve_videos == 'on' && !PT_IsAdmin()) {
                $data_insert['approved'] = 0;
            }
            $insert      = $db->insert(T_VIDEOS, $data_insert);
            if ($insert) {
                $data = array(
                    'status' => 200,
                    'video_id' => $video_id,
                    'link' => PT_Link("watch/$video_id")
                );
                ob_end_clean();
                header("Content-Encoding: none");
                header("Connection: close");
                ignore_user_abort();
                ob_start();
                header('Content-Type: application/json');
                echo json_encode($data);
                $size = ob_get_length();
                header("Content-Length: $size");
                ob_end_flush();
                flush();
                session_write_close();
                if (is_callable('fastcgi_finish_request')) {
                    fastcgi_finish_request();
                }
                $ffmpeg_b                   = $pt->config->ffmpeg_binary_file;
                $filepath                   = explode('.', $_POST['video-location'])[0];
                $time                       = time();
                $full_dir                   = str_replace('ajax', '/', __DIR__);
    
                $video_output_full_path_240 = $full_dir . $filepath . "_240p_converted.mp4";
                $video_output_full_path_360 = $full_dir . $filepath . "_360p_converted.mp4";
                $video_output_full_path_480 = $full_dir . $filepath . "_480p_converted.mp4";
                $video_output_full_path_720 = $full_dir . $filepath . "_720p_converted.mp4";
                $video_output_full_path_1080 = $full_dir . $filepath . "_1080p_converted.mp4";
                $video_output_full_path_2048 = $full_dir . $filepath . "_2048p_converted.mp4";
                $video_output_full_path_4096 = $full_dir . $filepath . "_4096p_converted.mp4";
    
                $video_file_full_path       = $full_dir . $_POST['video-location'];
    
                $shell     = shell_exec("$ffmpeg_b -y -i $video_file_full_path -i /home/user/public_html/watermark.png -filter_complex 'overlay=10:10' -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=426:-2 -crf 26 $video_output_full_path_240 2>&1");
                $upload_s3 = PT_UploadToS3($filepath . "_240p_converted.mp4");
                $db->where('id', $insert);
                $db->update(T_VIDEOS, array(
                    'converted' => 1,
                    '240p' => 1,
                    'video_location' => $filepath . "_240p_converted.mp4"
                ));
    
                if ($video_res >= 640 || $video_res == 0) {
                    $shell   = shell_exec("$ffmpeg_b -y -i $video_file_full_path -i /home/user/public_html/watermark.png -filter_complex 'overlay=10:10' -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=640:-2 -crf 26 $video_output_full_path_360 2>&1");
                    $upload_s3                  = PT_UploadToS3($filepath . "_360p_converted.mp4");
                    $db->where('id', $insert);
                    $db->update(T_VIDEOS, array(
                        '360p' => 1,
                    ));
                }
    
                if ($video_res >= 854 || $video_res == 0) {
                    $shell     = shell_exec("$ffmpeg_b -y -i $video_file_full_path -i /home/user/public_html/watermark.png -filter_complex 'overlay=10:10' -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=854:-2 -crf 26 $video_output_full_path_480 2>&1");
                    $upload_s3 = PT_UploadToS3($filepath . "_480p_converted.mp4");
                    $db->where('id', $insert);
                    $db->update(T_VIDEOS, array(
                        '480p' => 1
                    ));
                }
    
                if ($video_res >= 1280 || $video_res == 0) {
                    $shell     = shell_exec("$ffmpeg_b -y -i $video_file_full_path -i /home/user/public_html/watermark.png -filter_complex 'overlay=10:10' -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=1280:-2 -crf 26 $video_output_full_path_720 2>&1");
                    $upload_s3 = PT_UploadToS3($filepath . "_720p_converted.mp4");
                    $db->where('id', $insert);
                    $db->update(T_VIDEOS, array(
                        '720p' => 1
                    ));
                }
    
                if ($video_res >= 1920 || $video_res == 0) {
                    $shell     = shell_exec("$ffmpeg_b -y -i $video_file_full_path -i /home/user/public_html/watermark.png -filter_complex 'overlay=10:10' -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=1920:-2 -crf 26 $video_output_full_path_1080 2>&1");
                    $upload_s3 = PT_UploadToS3($filepath . "_1080p_converted.mp4");
                    $db->where('id', $insert);
                    $db->update(T_VIDEOS, array(
                        '1080p' => 1
                    ));
                }
    
                if ($video_res >= 2048) {
                    $shell     = shell_exec("$ffmpeg_b -y -i $video_file_full_path -i /home/user/public_html/watermark.png -filter_complex 'overlay=10:10' -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=2048:-2 -crf 26 $video_output_full_path_2048 2>&1");
                    $upload_s3 = PT_UploadToS3($filepath . "_2048p_converted.mp4");
                    $db->where('id', $insert);
                    $db->update(T_VIDEOS, array(
                        '2048p' => 1
                    ));
                }
    
                if ($video_res >= 3840) {
                    $shell     = shell_exec("$ffmpeg_b -y -i $video_file_full_path -i /home/user/public_html/watermark.png -filter_complex 'overlay=10:10' -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=3840:-2 -crf 26 $video_output_full_path_4096 2>&1");
                    $upload_s3 = PT_UploadToS3($filepath . "_4096p_converted.mp4");
                    $db->where('id', $insert);
                    $db->update(T_VIDEOS, array(
                        '4096p' => 1
                    ));
                }
    
    
                if (file_exists($_POST['video-location'])) {
                    unlink($_POST['video-location']);
                }
    
                if (!empty($_SESSION['uploads']['images'])) {
                    if (is_array($_SESSION['uploads']['images'])) {
                        foreach ($_SESSION['uploads']['images'] as $key => $file) {
                            if ($thumbnail == $file) {
                                unset($_SESSION['uploads']['images'][$key]);
                            } else {
                                //@unlink($file);
                            }
                        }
                        $_SESSION['uploads']['images'] = array();
                    }
                }
    
                pt_push_channel_notifiations($video_id);
                $_SESSION['uploads'] = array();
                exit();
            }
        } else {
            $data = array(
                'status' => 400,
                'message' => $error_icon . $error
            );
        }
    }
    

     

     

     

     

     

  6. The contact Form mails successfully to the $youremail part of this code,

    but I'd like the message to also mail to the submitter's entered email address,

    which I believe is: E-Mail: $_POST    I tried this without success:

     

    <?php
    
    // if the url field is empty
    //if(isset($_POST['url']) && $_POST['url'] == '')
    {
    
    	$youremail = '[email protected]';
    	$body = "UploadForm-M:
    	Name:  $_POST[name]
    	E-Mail: $_POST[email]
    	Message: $_POST[message]";
    
    	if( $_POST['email'] && !preg_match( "/[\r\n]/", $_POST['email']) ) {
    	  $headers = "From: $_POST[email]";
    	  $headers = "From: $youremail";
    	}
    	mail($youremail, 'Contact Form', $body, $headers );
    	mail(email, 'Contact Form', $body, $headers );
    }
    if(empty($error))
    {
    header('Location: http://...com');
    exit;
    }
    ?>

    Any additional help will be appreciated.

  7. Thanks for your reply regarding "blob". I can't comment on that, as I didn't write the javascript, I only know that it works successfully.

    I am hoping for help to add code each time to automatically add the User's Form-entered email address and file name link, to the emailing

  8. Thanks for your reply.
    The script sends the file to the storage folder, via this file code:

    <?php
    
    foreach(array('video', 'audio') as $type) {
    
    if (isset($_FILES["${type}-blob"])) {
    
    $fileName = $_POST["${type}-filename"];
    
    $uploadDirectory = 'uploadWC/'.$fileName;
    
    if (!move_uploaded_file($_FILES["${type}-blob"]["tmp_name"], $uploadDirectory)) {
    
    echo(" problem moving uploaded file");
    
    }
    echo($fileName);
    }
    }
    ?>

    And after the file uploads, the User is directed to a Form, and this file sends the Form:

    <?php
    //check if form was sent
    if($_POST){
    	$to = '[email protected]';
    	$subject = 'WebCamForm';
    
    	$name = $_POST['name'];
    	$email = $_POST['email'];
    	$message = $_POST['message'];
    	$headers = $name;
    	$message .= "\r\n\r\n" . $name;
    
    if( empty($_POST["some_place"]) or $_POST['some_place'] != "glory" )
    {
       header("HTTP/1.0 403 Forbidden");
       	}else{
       		mail( $to, $subject, $message, $email, $headers );
       	}
    		header('Location: http://www....com/ThankYou.html');
       exit;
    }
    ?>

    So, regarding the question "what's stopping you", the answer is I don't know how to add code each time to automatically add the User's Form-entered email address and file name link, to the emailing. Any help will be appreciated.

     

     

  9. This script (code below) successfully records a webcam.
    After recording, when 'upload" is selected:

    1. the recorded file is directed (by a php file) to upload to a /Folder destination.
    2. and the the User is directed to a Form page (to complete - requiring the Users’ email address).
    When the User completes the Form, and selects “send”, I receive the Form contents (via email).

    How can I receive a link to the the recorded file, with the Form contents, via email?
    How can the User receive a unique link to the recorded file, to the email address he entered into the Form?

    Any ideas/suggestions will be appreciated.

     <script>
                const video = document.querySelector('video')
                const startvideo = document.querySelector('.start')
                const upload = document.querySelector('.upload')
                const initRecorder = stream => {
                let blob
                  video.srcObject = stream
                  startvideo.removeAttribute('disabled')
                  video.addEventListener('loadedmetadata', () => {
                  video.play()
                  })
                  recorder.addEventListener('dataavailable', ({ data }) => {
                  video.srcObject = null
                  video.src = URL.createObjectURL(data)
                  // Create a blob from the data for upload
                  blob = new Blob([data], { type: 'video/webm' })
                  })
    
                  startvideo.addEventListener('click', () => {
                  stopvideo.removeAttribute('disabled')
    
                  show()
                  reset()
                  start()
                  recorder.start()
    		 				  // Get the video element with id="myVideo"
    							document.getElementsByTagName("span")[0].removeAttribute("class")
    							document.getElementsByTagName("span")[0].setAttribute("class", "colorred")
    		        	//document.getElementById("demo").innerHTML ="Recording...."
    							})
    
    							stopvideo.addEventListener('click', () => {
                  upload.removeAttribute('disabled')
                  recorder.stop()
                  stop()
    							document.getElementsByTagName("span")[0].removeAttribute("class")
    							document.getElementsByTagName("span")[0].setAttribute("class", "colorgreen")
    							//document.getElementById("demo").innerHTML ="recorded Successfully ..."
                  video.setAttribute("controls","controls")
    							})
    
    							// Upload the video blob as form data ............................
                  upload.addEventListener('click', () => {
                  uploadBlob(blob)
                })
              }
    
               ///////////////////////////////////////////////////
    
    		  		  //Reset the Camera
    		  		             function resetCamera(){
    		  		                location.reload();
    		  		              }
    
    /////////////////////////////////////////////////////////
    
    					  //   uploading functionality
    
                	var blob, fileName, fileObject;
                  function uploadBlob(blob) {
                      prepareBlob(blob);
                			InitUploading();
                  }
                //////////////////////////////////preparing blob metadat////////////////////
                function prepareBlob(blob){
                	    	// generating a random file name
                			 fileName = getFileName('webm');
                			 // we need to upload "File" --- not "Blob"
                			 fileObject = new File([blob], fileName, {
                			 type: 'video/webm'
                		 });
                }
                function InitUploading()
                			 {
                					 uploadToPHPServer(fileObject, function (response, fileDownloadURL) {
                							 if (response !== 'ended') {
                									 document.getElementById('header').innerHTML = response; // upload progress
                									 return;
                							 }
                							 document.getElementById('header').innerHTML = '<a href="' + fileDownloadURL +
                									 '" target="_blank">' +
                									 fileDownloadURL + '</a>';
                							 //alert('Successfully uploaded recorded blob.');
                							 // preview uploaded file
                							 video.src = fileDownloadURL;
                							 // open uploaded file in a new tab
                							 window.open(fileDownloadURL);
                					 });
                			 }
    
                  ///////////////////////////////////////////////////////////////////////////////////
    
                        function makeXMLHttpRequest(url, data, callback) {
                            var request = new XMLHttpRequest();
                            request.onreadystatechange = function () {
                                if (request.readyState == 4 && request.status == 200) {
                                    if (request.responseText === 'success') {
                                        callback('Upload Complete');
                                        return;
                                    }
                                    //alert(request.responseText);
    
    								window.location.href = '../uploadWC.html';
    
                        return;
    
                                }
                            };
                            request.upload.onloadstart = function () {
                                callback('Upload Begins...');
                            };
                            request.upload.onprogress = function (event) {
                                callback('Upload Progress ' + Math.round(event.loaded / event.total * 100) + "%");
                            };
                            request.upload.onload = function () {
                                callback('Progress Ending');
                            };
                            request.upload.onload = function () {
                                callback('Upload Complete');
                            };
                            request.upload.onerror = function (error) {
                                callback('Upload Failed.');
                            };
                            request.upload.onabort = function (error) {
                                callback('Upload Aborted.');
                            };
                            request.open('POST', url);
                            request.send(data);
                        }
                        // this function is used to generate random file name
                        function getFileName(fileExtension) {
                            var d = new Date();
                            var year = d.getUTCFullYear();
                            var month = d.getUTCMonth() +1;
                            var date = d.getUTCDate();
                            return 'VTH-' + year + month + date + '-' + getRandomString() + '.' + fileExtension;
                        }
    
                        function getRandomString() {
                            if (window.crypto && window.crypto.getRandomValues && navigator.userAgent.indexOf('Safari') === -1) {
                                var a = window.crypto.getRandomValues(new Uint32Array(3)),
                                    token = '';
                                for (var i = 0, l = a.length; i < l; i++) {
                                    token += a[i].toString(36);
                                }
                                return token;
                            } else {
                                return (Math.random() * new Date().getTime()).toString(36).replace(/\./g, '');
                            }
    
    					}
    					}
    }
    
                  navigator
                    .mediaDevices
                    .getUserMedia({audio: true, video: true })
                    .then(initRecorder)
                    .catch(console.error)
    
             </script>

     

  10. Thanks again for the replies.

    Your "missing a curly bracket" helped, now this no longer prevents internal messaging (but no emails sent, yet):

    $insert = $db->insert(T_MESSAGES, $insert_message);
    			if ($insert) {
    				$pt->message = PT_GetMessageData($insert);
    				$data = array(
    					'status' => 200,
    					'message_id' => $_POST['message_id'],
    					'message' => PT_LoadPage('messages/ajax/outgoing', array(
    						'ID' => $pt->message->id,
    						'TEXT' => $pt->message->text
    					))
    );
    
    
    
    				if ($pt->config->validation == 'on') {
    				$link = $email_code . '/' . $email;
    				$data['EMAIL_CODE'] = $link;
    				$data['USERNAME'] = $username;
    				$send_email_data = array(
    				'from_email' => $pt->config->email,
    				'from_name' => $pt->config->name,
    				'to_email' => $pt->user_two->e-mail,
    				'to_name' => $username,
    				'subject' => 'Message Waiting',
    				'charSet' => 'UTF-8',
    				'message_body' => PT_LoadPage('emails/message-alert', $data),
    				'is_html' => true
    				);
    				$send_message = PT_SendMessage($send_email_data);
    }
    			}
    		}
    	}
    }

    So, that is a step in the right direction.

    Because this script's registration file confirms the registering Users' email, I had taken this code:

                    if ($pt->config->validation == 'on') {
                         $link = $email_code . '/' . $email; 
                         $data['EMAIL_CODE'] = $link;
                         $data['USERNAME']   = $username;
                         $send_email_data = array(
                            'from_email' => $pt->config->email,
                            'from_name' => $pt->config->name,
                            'to_email' => $email,
                            'to_name' => $username,
                            'subject' => 'Confirm your account',
                            'charSet' => 'UTF-8',
                            'message_body' => PT_LoadPage('emails/confirm-account', $data),
                            'is_html' => true
                        );
                        $send_message = PT_SendMessage($send_email_data);

    from the registration file code (starting at line 111), to attempt to add in to the messages code, to get a message to (possibly) send a notification, here's the registration code:

    <?php
    if (IS_LOGGED == true || $pt->config->user_registration != 'on') {
        header("Location: " . PT_Link(''));
        exit();
    }
    
    $color1      = '2ec0bc';
    $color2      = '8ef9f6';
    $errors      = array();
    $erros_final = '';
    $username    = '';
    $email       = '';
    $success     = '';
    $recaptcha   = '<div class="g-recaptcha" data-sitekey="' . $pt->config->recaptcha_key . '"></div>';
    $pt->custom_fields = $db->where('registration_page','1')->get(T_FIELDS);
    $field_data        = array();
    if ($pt->config->recaptcha != 'on') {
        $recaptcha = '';
    }
    if (!empty($_POST)) {
        if (empty($_POST['username']) || empty($_POST['password']) || empty($_POST['email']) || empty($_POST['c_password']) || empty($_POST['gender'])) {
            $errors[] = $lang->please_check_details;
        } else {
            $username        = PT_Secure($_POST['username']);
            $password        = PT_Secure($_POST['password']);
            $c_password      = PT_Secure($_POST['c_password']);
            $password_hashed = sha1($password);
            $email           = PT_Secure($_POST['email']);
            $gender          = PT_Secure($_POST['gender']);
            if ($gender != 'female' && $gender != 'male') {
                $errors[] = $lang->gender_is_invalid;
            }
            if (PT_UsernameExists($_POST['username'])) {
                $errors[] = $lang->username_is_taken;
            }
            if (strlen($_POST['username']) < 4 || strlen($_POST['username']) > 32) {
                $errors[] = $lang->username_characters_length;
            }
            if (!preg_match('/^[\w]+$/', $_POST['username'])) {
                $errors[] = $lang->username_invalid_characters;
            }
            if (PT_UserEmailExists($_POST['email'])) {
                $errors[] = $lang->email_exists;
            }
            if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
                $errors[] = $lang->email_invalid_characters;
            }
            if ($password != $c_password) {
                $errors[] = $lang->password_not_match;
            }
            if (strlen($password) < 4) {
                $errors[] = $lang->password_is_short;
            }
            if ($pt->config->recaptcha == 'on') {
                if (!isset($_POST['g-recaptcha-response']) || empty($_POST['g-recaptcha-response'])) {
                    $errors[] = $lang->reCaptcha_error;
                }
            }
    
            if (empty($_POST['terms'])) {
                $errors[] = $lang->terms_accept;
            } elseif ($_POST['terms'] != 'on') {
                $errors[] = $lang->terms_accept;
            }
            
    
            if (!empty($pt->custom_fields) && count($pt->custom_fields) > 0) {
                foreach ($pt->custom_fields as $field) {
                    $field_id   = $field->id;
                    $field->fid = "fid_$field_id";
    
                    if (!empty($_POST[$field->fid])) {
                        $name = $field->fid;
                        if (!empty($_POST[$name])) {
                            $field_data[] = array(
                                $name => $_POST[$name]
                            );
                        }
                    }
                }
            }
    
    
            $active = ($pt->config->validation == 'on') ? 0 : 1;
            if (empty($errors)) {
                $email_code = sha1(time() + rand(111,999));
                $insert_data = array(
                    'username' => $username,
                    'password' => $password_hashed,
                    'email' => $email,
                    'ip_address' => get_ip_address(),
                    'gender' => $gender,
                    'active' => $active,
                    'email_code' => $email_code,
                    'last_active' => time(),
                    'registered' => date('Y') . '/' . intval(date('m'))
                );
                $insert_data['language'] = $pt->config->language;
                if (!empty($_SESSION['lang'])) {
                    if (in_array($_SESSION['lang'], $langs)) {
                        $insert_data['language'] = $_SESSION['lang'];
                    }
                }
                $user_id             = $db->insert(T_USERS, $insert_data);
                if (!empty($user_id)) {
                    if (!empty($field_data)) {
                        PT_UpdateUserCustomData($user_id,$field_data,false);
                    }
    
    
                    if ($pt->config->validation == 'on') {
                         $link = $email_code . '/' . $email; 
                         $data['EMAIL_CODE'] = $link;
                         $data['USERNAME']   = $username;
                         $send_email_data = array(
                            'from_email' => $pt->config->email,
                            'from_name' => $pt->config->name,
                            'to_email' => $email,
                            'to_name' => $username,
                            'subject' => 'Confirm your account',
                            'charSet' => 'UTF-8',
                            'message_body' => PT_LoadPage('emails/confirm-account', $data),
                            'is_html' => true
                        );
                        $send_message = PT_SendMessage($send_email_data);
                        $success = $success_icon . $lang->successfully_joined_desc;
                    } 
    
                    else {
                        $session_id          = sha1(rand(11111, 99999)) . time() . md5(microtime());
                        $insert_data         = array(
                            'user_id' => $user_id,
                            'session_id' => $session_id,
                            'time' => time()
                        );
                        $insert              = $db->insert(T_SESSIONS, $insert_data);
                        $_SESSION['user_id'] = $session_id;
                        setcookie("user_id", $session_id, time() + (10 * 365 * 24 * 60 * 60), "/");
                        $pt->loggedin = true;
                        header("Location: $site_url");
                        exit();
                    }
                }
            }
        }
    }
    $pt->page          = 'login';
    $pt->title         = $lang->register . ' | ' . $pt->config->title;
    $pt->description   = $pt->config->description;
    $pt->keyword       = $pt->config->keyword;
    $custom_fields     = "";
    if (!empty($errors)) {
        foreach ($errors as $key => $error) {
            $erros_final .= $error_icon . $error . "<br>";
        }
    }
    if (!empty($pt->custom_fields)) {
        foreach ($pt->custom_fields as $field) {
            $field_id       = $field->id;
            $fid            = "fid_$field_id";
            $pt->filed      = $field;
            $custom_fields .= PT_LoadPage('auth/register/custom-fields',array(
                'NAME'      => $field->name,
                'FID'       => $fid
            ));
        }
    }
    
    $pt->content     = PT_LoadPage('auth/register/content', array(
        'COLOR1' => $color1,
        'COLOR2' => $color2,
        'ERRORS' => $erros_final,
        'USERNAME' => $username,
        'EMAIL' => $email,
        'SUCCESS' => $success,
        'RECAPTCHA' => $recaptcha,
        'CUSTOM_FIELDS' => $custom_fields
    ));

    Any additional guidance will be welcomed. Much thanks again.

     

  11. Thanks for your reply and great questions.

    1. No, I didn't write this script. The author is weeks out for any modifications.

    2. "not work" means when (and where) I added in the code the internal messaging was no longer sending or receiving messages, and no emails were sent. When I removed the added code, internal messaging resumed working successfully.

    3. No debugging done. No, I don't know if the call to send email is actually working. I don't know how to do those things. Any guidance will be appreciated.

  12. Thanks for your replies.

    The php web script that I'm using allows Users' to send messages internally. I received some guidance as to how to add the ability to notify a User, via email, when he receives a web message. I was told to add this code, after line 44 (to the existing code below) but it doesn't currently work, any help/suggestions will be appreciated.:

    if ($pt->config->validation == 'on') {
    $link = $email_code . '/' . $email; 
    $data['EMAIL_CODE'] = $link;
    $data['USERNAME'] = $username;
    $send_email_data = array(
    'from_email' => $pt->config->email,
    'from_name' => $pt->config->name,
    'to_email' => $pt->user_two->e-mail 
    'to_name' => $username,
    'subject' => 'Message Waiting',
    'charSet' => 'UTF-8',
    'message_body' => PT_LoadPage('emails/confirm-account', $data),
    'is_html' => true
    );
    $send_message = PT_SendMessage($send_email_data);

    Existing code:

    <?php  
    if (IS_LOGGED == false) {
        $data = array(
            'status' => 400,
            'error' => 'Not logged in'
        );
        echo json_encode($data);
        exit();
    }
    
    if ($first == 'new') {
        if (!empty($_POST['id']) && !empty($_POST['new-message'])) {
            $link_regex = '/(http\:\/\/|https\:\/\/|www\.)([^\ ]+)/i';
            $i          = 0;
            preg_match_all($link_regex, PT_Secure($_POST['new-message']), $matches);
            foreach ($matches[0] as $match) {
                $match_url           = strip_tags($match);
                $syntax              = '[a]' . urlencode($match_url) . '[/a]';
                $_POST['new-message'] = str_replace($match, $syntax, $_POST['new-message']);
            }
            $new_message = PT_Secure($_POST['new-message']);
            $id = PT_Secure($_POST['id']);
            if ($id != $pt->user->id) {
                $chat_exits = $db->where("user_one", $pt->user->id)->where("user_two", $id)->getValue(T_CHATS, 'count(*)');
                if (!empty($chat_exits)) {
                    $db->where("user_two", $pt->user->id)->where("user_one", $id)->update(T_CHATS, array('time' => time()));
                    $db->where("user_one", $pt->user->id)->where("user_two", $id)->update(T_CHATS, array('time' => time()));
                    if ($db->where("user_two", $pt->user->id)->where("user_one", $id)->getValue(T_CHATS, 'count(*)') == 0) {
                        $db->insert(T_CHATS, array('user_two' => $pt->user->id, 'user_one' => $id,'time' => time()));
                    }
                } else {
                    $db->insert(T_CHATS, array('user_one' => $pt->user->id, 'user_two' => $id,'time' => time()));
                    if (empty($db->where("user_two", $pt->user->id)->where("user_one", $id)->getValue(T_CHATS, 'count(*)'))) {
                        $db->insert(T_CHATS, array('user_two' => $pt->user->id, 'user_one' => $id,'time' => time()));
                    }
                }
                $insert_message = array(
                    'from_id' => $pt->user->id,
                    'to_id' => $id,
                    'text' => $new_message,
                    'time' => time()
                );
                $insert = $db->insert(T_MESSAGES, $insert_message);
                if ($insert) {
                    $pt->message = PT_GetMessageData($insert);
                    $data = array(
                        'status' => 200,
                        'message_id' => $_POST['message_id'],
                        'message' => PT_LoadPage('messages/ajax/outgoing', array(
                            'ID' => $pt->message->id,
                            'TEXT' => $pt->message->text
                        ))
                    );
                }
            }
        }
    }
    
    if ($first == 'fetch') {
        if (empty($_POST['last_id'])) {
            $_POST['last_id'] = 0;
        }
        if (empty($_POST['id'])) {
            $_POST['id'] = 0;
        }
        if (empty($_POST['first_id'])) {
            $_POST['first_id'] = 0;
        }
        $messages_html = PT_GetMessages($_POST['id'], array('last_id' => $_POST['last_id'], 'first_id' => $_POST['first_id'], 'return_method' => 'html'));
        if (!empty($messages_html)) {
            $html = PT_LoadPage("messages/{$pt->config->server}/messages", array('MESSAGES' => $messages_html));
        } else {
            $html = PT_LoadPage("messages/ajax/no-messages");
        }
    
        $users_html = PT_GetMessagesUserList(array('return_method' => 'html'));
    
        if (!empty($messages_html) || !empty($users_html)) {
            $data = array('status' => 200, 'message' => $messages_html, 'users' => $users_html);
        }
    }
    
    if ($first == 'search') {
        $keyword = '';
        $users_html = '<p class="text-center">' . $lang->no_match_found . '</p>';
        if (isset($_POST['keyword'])) {
            $users_html = PT_GetMessagesUserList(array('return_method' => 'html', 'keyword' => $_POST['keyword']));
        }
        $data = array('status' => 200, 'users' => $users_html);
    }
    
    if ($first == 'delete_chat') {
        if (!empty($_POST['id'])) {
            $id = PT_Secure($_POST['id']);
            $messages = $db->where("(from_id = {$pt->user->id} AND to_id = {$id}) OR (from_id = {$id} AND to_id = {$pt->user->id})")->get(T_MESSAGES);
            $update1 = array();
            $update2 = array();
            $erase = array();
            foreach ($messages as $key => $message) {
                if ($message->from_deleted == 1 || $message->to_deleted == 1) {
                    $erase[] = $message->id;
                } else {
                    if ($message->to_id == $pt->user->id) {
                        $update2[] = $message->id;
                    } else {
                        $update1[] = $message->id;
                    }
                }
            }
            if (!empty($erase)) {
                $erase = implode(',', $erase);
                $final_query = "DELETE FROM " . T_MESSAGES . " WHERE id IN ($erase)";
                $db->rawQuery($final_query);
            }
            if (!empty($update1)) {
                $update1 = implode(',', $update1);
                $final_query = "UPDATE " . T_MESSAGES . " set `from_deleted` = '1' WHERE `id` IN({$update1}) ";
                $db->rawQuery($final_query);
            }
            if (!empty($update2)) {
                $update2 = implode(',', $update2);
                $final_query = "UPDATE " . T_MESSAGES . " set `to_deleted` = '1' WHERE `id` IN({$update2}) ";
                $db->rawQuery($final_query);
            }
            $delete_chats = $db->rawQuery("DELETE FROM " . T_CHATS . " WHERE user_one = {$pt->user->id} AND user_two = $id");
        }
    }
    ?>

     

  13. 			$insert = $db->insert(T_MESSAGES, $insert_message);
    			if ($insert) {
    				$pt->message = PT_GetMessageData($insert);
    				$data = array(
    					'status' => 200,
    					'message_id' => $_POST['message_id'],
    					'message' => PT_LoadPage('messages/ajax/outgoing', array(
    						'ID' => $pt->message->id,
    						'TEXT' => $pt->message->text
    					))
    );
    				if ($pt->config->validation == 'on') {
    				$link = $email_code . '/' . $email;
    				$data['EMAIL_CODE'] = $link;
    				$data['USERNAME'] = $username;
    				$send_email_data = array(
    				'from_email' => $pt->config->email,
    				'from_name' => $pt->config->name,
    				'to_email' => $pt->user_two->e-mail,
    				'to_name' => $username,
    				'subject' => 'Message Waiting',
    				'charSet' => 'UTF-8',
    				'message_body' => PT_LoadPage('emails/message-alert', $data),
    				'is_html' => true
    				);
    				$send_message = PT_SendMessage($send_email_data;

     

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.