Jump to content
php.lv forumi

ziedinjsh

Reģistrētie lietotāji
  • Content Count

    789
  • Joined

  • Last visited

Posts posted by ziedinjsh


  1. sveiki, meiģinu panākt, ka jquery ielādē elemntus kad rulēju uz leju lapu, ielādē tik daudz kas ir redzams ekrānāna, bet šobrīd nekas rulējot nenotiek!

    jQuery(function(){
    
    var count = jQuery('#am-container a').size();
    var lastScroll = 0;
    
    jQuery('#show').text(count);
    jQuery('#am-container a').hide();
    jQuery('#am-container a').slice(0, 16).fadeIn(500);
    
    jQuery(window).scroll(function(event){
            var st = jQuery(this).scrollTop();
            if (st > lastScroll){
    jQuery('#am-container a:hidden').slice(0, 16).fadeIn(500);
            }
    lastScroll = st;
    });
    });
    

  2. Sveiki, es bišķ aizdomājos un tad īsti nevaru saprast kā tad īsti ir!

     

    Lielākā daļa lapās ir:

    copyright © 2014 domens.lv
    

    ar to tekstu priekšā man īsti nepatīk, simpātiskāk ir:

    © 2014 domens.lv
    

    Kāda tam ir atšķirība? copy simbols tā pat nocīmē to pāsu copyright! vai tad ne?


  3. Sveiki!

    Kādu laiku domāju izveidot ne pārāk sarežģītu portālu cilvēkiem, kuriem patīk braukāt pa Latviju.

    Esmu taisījis vairākus variantus/versijas, bet nevaru pabeigt, jo ierobežo programmēšanas zināšanas.

    Programmēšana man ir kā hobijs. Šis piedāvajums ir kā bezmaksas sadarbība, vairāk domāts

    iesācējiem, kas darbojas ar php, mysqli, html, css un jquery. Varēsiet pievienot savam portfolio, ja vēlaties! Ja ar laiku portālam izveidosies

    kaut kāda peļnas perspektīve tad protams peļņa tiks dalīta!

     

    Ja esi ieinteresēts(-a) tad droši raksti man uz gzieds@gmail.com ar tēmu: sadarbības projekts vai arī

    šeit sūti PM. :)

     

    P.S. Ja kādam ir kas sakāms nelabvēlīgs va nicināms, lūdzu, paturiet to pie sevis.


  4. Sveiki! Man ir neliela ķibele. Ir kods kurš augšupielādējot izveidot mp3 faila waveform bildi. Funkcija strādā, bildi izveidot un parāda, bet ir lieta tādā, ka viņa nesaglabājās! Cik pa google vandījos tad tas esot jādara šādi imagepng($bilde, $vieta_kur_saglabāt); bet tas nestrādā!

     

    Kods:

    <?php
      function waveform($id, $file){
      ini_set("max_execution_time", "30000");
      
      // how much detail we want. Larger number means less detail
      // (basically, how many bytes/frames to skip processing)
      // the lower the number means longer processing time
      define("DETAIL", 1);
      
      define("DEFAULT_WIDTH", 600);
      define("DEFAULT_HEIGHT", 50);
      define("DEFAULT_FOREGROUND", "#666666");
      define("DEFAULT_BACKGROUND", "#FFFFFF");
      
      /**
       * GENERAL FUNCTIONS
       */
      function findValues($byte1, $byte2){
        $byte1 = hexdec(bin2hex($byte1));                        
        $byte2 = hexdec(bin2hex($byte2));                        
        return ($byte1 + ($byte2*256));
      }
      
      /**
       * Great function slightly modified as posted by Minux at
       * http://forums.clantemplates.com/showthread.php?t=133805
       */
      function html2rgb($input) {
        $input=($input[0]=="#")?substr($input, 1,6):substr($input, 0,6);
        return array(
         hexdec(substr($input, 0, 2)),
         hexdec(substr($input, 2, 2)),
         hexdec(substr($input, 4, 2))
        );
      }   
      
    
      
        /**
         * PROCESS THE FILE
         */
      
        // temporary file name
        $tmpname = substr(md5(time()), 0, 10);
        
        // copy from temp upload directory to current
        copy($file, "{$tmpname}_o.mp3");
        
    		// support for stereo waveform?
        $stereo = isset($_POST["stereo"]) && $_POST["stereo"] == "on" ? true : false;
       
    		// array of wavs that need to be processed
        $wavs_to_process = array();
        
        /**
         * convert mp3 to wav using lame decoder
         * First, resample the original mp3 using as mono (-m m), 16 bit (-b 16), and 8 KHz (--resample 8)
         * Secondly, convert that resampled mp3 into a wav
         * We don't necessarily need high quality audio to produce a waveform, doing this process reduces the WAV
         * to it's simplest form and makes processing significantly faster
         */
        if ($stereo) {
    			// scale right channel down (a scale of 0 does not work)
          exec("lame {$tmpname}_o.mp3 --scale-r 0.1 -m m -S -f -b 16 --resample 8 {$tmpname}.mp3 && lame -S --decode {$tmpname}.mp3 {$tmpname}_l.wav");
    			// same as above, left channel
          exec("lame {$tmpname}_o.mp3 --scale-l 0.1 -m m -S -f -b 16 --resample 8 {$tmpname}.mp3 && lame -S --decode {$tmpname}.mp3 {$tmpname}_r.wav");
          $wavs_to_process[] = "{$tmpname}_l.wav";
          $wavs_to_process[] = "{$tmpname}_r.wav";
        } else {
          exec("lame {$tmpname}_o.mp3 -m m -S -f -b 16 --resample 8 {$tmpname}.mp3 && lame -S --decode {$tmpname}.mp3 {$tmpname}.wav");
          $wavs_to_process[] = "{$tmpname}.wav";
        }
        
        // delete temporary files
        unlink("{$tmpname}_o.mp3");
        unlink("{$tmpname}.mp3");
        
        // get user vars from form
        $width = isset($_POST["width"]) ? (int) $_POST["width"] : DEFAULT_WIDTH;
        $height = isset($_POST["height"]) ? (int) $_POST["height"] : DEFAULT_HEIGHT;
        $foreground = isset($_POST["foreground"]) ? $_POST["foreground"] : DEFAULT_FOREGROUND;
        $background = isset($_POST["background"]) ? $_POST["background"] : DEFAULT_BACKGROUND;
        $draw_flat = isset($_POST["flat"]) && $_POST["flat"] == "on" ? true : false;
    
        $img = false;
    
        // generate foreground color
        list($r, $g, $b) = html2rgb($foreground);
        
        // process each wav individually
        for($wav = 1; $wav <= sizeof($wavs_to_process); $wav++) {
     
          $filename = $wavs_to_process[$wav - 1];
        
          $handle = fopen($filename, "r");
          // wav file header retrieval
          $heading[] = fread($handle, 4);
          $heading[] = bin2hex(fread($handle, 4));
          $heading[] = fread($handle, 4);
          $heading[] = fread($handle, 4);
          $heading[] = bin2hex(fread($handle, 4));
          $heading[] = bin2hex(fread($handle, 2));
          $heading[] = bin2hex(fread($handle, 2));
          $heading[] = bin2hex(fread($handle, 4));
          $heading[] = bin2hex(fread($handle, 4));
          $heading[] = bin2hex(fread($handle, 2));
          $heading[] = bin2hex(fread($handle, 2));
          $heading[] = fread($handle, 4);
          $heading[] = bin2hex(fread($handle, 4));
          
          // wav bitrate 
          $peek = hexdec(substr($heading[10], 0, 2));
          $byte = $peek / 8;
          
          // checking whether a mono or stereo wav
          $channel = hexdec(substr($heading[6], 0, 2));
          
          $ratio = ($channel == 2 ? 40 : 80);
          
          // start putting together the initial canvas
          // $data_size = (size_of_file - header_bytes_read) / skipped_bytes + 1
          $data_size = floor((filesize($filename) - 44) / ($ratio + $byte) + 1);
          $data_point = 0;
          
          // now that we have the data_size for a single channel (they both will be the same)
          // we can initialize our image canvas
          if (!$img) {
            // create original image width based on amount of detail
    				// each waveform to be processed with be $height high, but will be condensed
    				// and resized later (if specified)
            $img = imagecreatetruecolor($data_size / DETAIL, $height * sizeof($wavs_to_process));
            
            // fill background of image
            if ($background == "") {
              // transparent background specified
              imagesavealpha($img, true);
              $transparentColor = imagecolorallocatealpha($img, 0, 0, 0, 127);
              imagefill($img, 0, 0, $transparentColor);
            } else {
              list($br, $bg, $bb) = html2rgb($background);
              imagefilledrectangle($img, 0, 0, (int) ($data_size / DETAIL), $height * sizeof($wavs_to_process), imagecolorallocate($img, $br, $bg, $bb));
            }
          }
    
          while(!feof($handle) && $data_point < $data_size){
            if ($data_point++ % DETAIL == 0) {
              $bytes = array();
              
              // get number of bytes depending on bitrate
              for ($i = 0; $i < $byte; $i++)
                $bytes[$i] = fgetc($handle);
              
              switch($byte){
                // get value for 8-bit wav
                case 1:
                  $data = findValues($bytes[0], $bytes[1]);
                  break;
                // get value for 16-bit wav
                case 2:
                  if(ord($bytes[1]) & 128)
                    $temp = 0;
                  else
                    $temp = 128;
                  $temp = chr((ord($bytes[1]) & 127) + $temp);
                  $data = floor(findValues($bytes[0], $temp) / 256);
                  break;
              }
              
              // skip bytes for memory optimization
              fseek($handle, $ratio, SEEK_CUR);
              
              // draw this data point
              // relative value based on height of image being generated
              // data values can range between 0 and 255
              $v = (int) ($data / 255 * $height);
              
              // don't print flat values on the canvas if not necessary
              if (!($v / $height == 0.5 && !$draw_flat))
                // draw the line on the image using the $v value and centering it vertically on the canvas
                imageline(
                  $img,
                  // x1
                  (int) ($data_point / DETAIL),
                  // y1: height of the image minus $v as a percentage of the height for the wave amplitude
                  $height * $wav - $v,
                  // x2
                  (int) ($data_point / DETAIL),
                  // y2: same as y1, but from the bottom of the image
                  $height * $wav - ($height - $v),
                  imagecolorallocate($img, $r, $g, $b)
                );         
              
            } else {
              // skip this one due to lack of detail
              fseek($handle, $ratio + $byte, SEEK_CUR);
            }
          }
          
          // close and cleanup
          fclose($handle);
    
          // delete the processed wav file
          unlink($filename);
          
        }
        
        header("Content-Type: image/png");
    	chmod('../../mp3/',0777);
      
        // want it resized?
        if ($width) {
          // resample the image to the proportions defined in the form
          $rimg = imagecreatetruecolor($width, $height);
          // save alpha from original image
          imagesavealpha($rimg, true);
          imagealphablending($rimg, false);
          // copy to resized
          imagecopyresampled($rimg, $img, 0, 0, 0, 0, $width, $height, imagesx($img), imagesy($img));
          imagepng($rimg);
          imagedestroy($rimg);
        } else {
          imagepng($img, '../../mp3/');
        }
        imagedestroy($img);
    
      }
    

    P.S. Paldies jau iepriekš


  5. Labdien, man ir tāda lieta, ka izveidoju kodu:

    jQuery(function(){
    
    	document.title = 'Braucam';
    
    	jQuery('.menu li a').on('click', function(e){
    	e.preventDefault();
    	
    	var url = jQuery(this).attr('href');
    		jQuery.ajax({
    			url:url, 
    			success: function(data){
    				var page_content = jQuery(data);
    				var page_title = page_content.find('.data-title').text();
    				var get_content = page_content.find('.data-content').html();
    				
    					jQuery('div#page').html(get_content);
    					document.title = page_title;
    					
    					jQuery('.menu li.current').removeClass('current');
    					jQuery(this).parent('li').addClass('current');
    
    			}, 
    			error: function(){
    				alert('ups!');
    			}
    			});
    			
    		if(url!=window.location){
    			window.history.pushState({path:url}, '', url);
    		}		
    	});
    	return false;
    	
    	jQuery(window).bind('popstate', function(){
    		jQuery.ajax({
    			url:location.pathname, 
    			success: function(data){
    				var page_content = jQuery(data);
    				var page_title = page_content.find('.data-title').text();
    				var get_content = page_content.find('.data-content').html();
    				
    					jQuery('div#page').html(get_content);
    					document.title = page_title;	
    					
    					jQuery('.menu li.current').removeClass('current');
    					jQuery(this).closest('li').addClass('current');
    			}
    		});
    	});
    	
    
    });
    

    pārvietojoties par portālu it kā strādā, nu vismaz netiek pārlādēta lapa un saturs tiek ielādēts, bet ja es nospiežu ,back` pogu browserim tad mainās tikai url, bet ne lapas saturs. Saturs paliek tas pats.

     

    Un vēlviena neliela problēma: Es nesaprotu kapēc nestrādā addClass('current') removeClass strādā.


  6. kā tu biji to domājis? Man neiet ar to strpos

    <?php
    include('dbase.php');
    
    $data = 'kjhedkedhewlkejkswp pis wjeflk';
    
    $sql = mysql_query("SELECT * FROM bad_words") or die(mysql_error());
    
    if (mysql_num_rows($sql) > 0) {
       while($rs = mysql_fetch_assoc($sql)) {
          $bad_words[] = $rs['word'];
       }
    }
    
    
    
    $noBadWordsFound = true;
    
    foreach ($bad_words as $word) {
    
    if(strpos($data, $word)){
    $noBadWordsFound = false;
    break;
    }
     
    }
    
    if ($noBadWordsFound) { echo 'nav'; } else { echo 'ir'; }
    
    ?>
    

  7. Veidoju kko līdzīgu bad word filtram.. šinī gadījumā nevis aizvieto ar kaut ko bet paziņo ir bad word vai nav.

    <?php
    include('dbase.php');
    
    $data = 'kjhedkedhewlkejkswp pis wjeflk';
    
    global $pre;
    $sql = mysql_query("SELECT * FROM bad_words") or die(mysql_error());
    
    if (mysql_num_rows($sql) > 0) {
       while($rs = mysql_fetch_assoc($sql)) {
          $bad_words[] = $rs['word'];
       }
    }
    
    $noBadWordsFound = true;
    foreach ($bad_words as $word) {
      if (preg_match('/'.$word.'/', $data)) {
        $noBadWordsFound = false;
        break;
      }
    }
    if ($noBadWordsFound) { echo 'nav'; } else { echo 'ir'; }
    
    ?>
    

    nepieciešamo funkciju viņš dar, bet ir vēl šāda lieta kā:

    Warning: preg_match(): Compilation failed: nothing to repeat at offset 0 in /home/mydraftn/public_html/process/test.php on line 17

    Warning: preg_match(): Compilation failed: nothing to repeat at offset 0 in /home/mydraftn/public_html/process/test.php on line 17

    Warning: preg_match(): Compilation failed: nothing to repeat at offset 0 in /home/mydraftn/public_html/process/test.php on line 17

    Warning: preg_match(): Compilation failed: nothing to repeat at offset 0 in /home/mydraftn/public_html/process/test.php on line 17

    Warning: preg_match(): Compilation failed: nothing to repeat at offset 3 in /home/mydraftn/public_html/process/test.php on line 17

     

     

    es tikai nevaru saprast kas man jāpārveido vai kādi simboli ir jāliek šajā vietā '/'.$word.'/'

     

    Paldies jau iepriekš!


  8. Labdien!

     

    Man tāds jautājums:

    index.html failā ir inklūdoti js faili. ar jQuery .get funkciju es iegūstu lapas saturu

    jQuery.get('php/check_session.php', function(data){
    		jQuery('#wrap').html('uzgaidi..');
    		
    			if(data=='error'){
    				jQuery.get('front.html', function(data){
    					data = '"' + data + '"';
    					jQuery('#wrap').html(data);
    				});
    			}else if(data=='ok'){
    				jQuery.get('audio.html', function(data){
    					data = '"' + data + '"';
    					jQuery('#wrap').html(data);
    				});
    			}
    	});
    

    viss ir labi, bet ir viena lieta ko es nevaru izdomāt. Piemēram: front.html ir trigeris "enter" bet uzspiežot uz viņu nekas nenotiekas. Saprotu to ka pašā html saturā patiesībā tā front.html saturs nav (source code paskatoties nav) tapēc nenotiek attiecīgā funkcija 

    jQuery('.enter').live('click', function(){
           alert(1);
    });	
    

    Kā var panākt lai šādā veida varētu palaist citas funkcijas kas ir ar jquery iegūts saturs?

×
×
  • Create New...