コード例 #1
0
 function testYoutubeVideoId()
 {
     $youtube_urls = [['url' => 'http://youtu.be/HKK5-uIfh2I', 'id' => 'HKK5-uIfh2I'], ['url' => 'https://youtu.be/_UZ92FPv_Ko', 'id' => '_UZ92FPv_Ko'], ['url' => 'http://www.youtube.com/watch?v=XVH2ZFkqjSU&feature=mfu_in_order&list=UL', 'id' => 'XVH2ZFkqjSU'], ['url' => 'https://www.youtube.com/watch?v=fe7y9X3-GIU&feature=youtu.be', 'id' => 'fe7y9X3-GIU'], ['url' => 'http://www.youtube.com/watch?v=VV0dBqapdkc', 'id' => 'VV0dBqapdkc'], ['url' => 'http://www.youtube.com/embed/mz4vWHLwbPE', 'id' => 'mz4vWHLwbPE'], ['url' => 'https://www.youtube.com/embed/1NUbUYrVuPA', 'id' => '1NUbUYrVuPA'], ['url' => 'http://www.youtube.com/v/OaYtF1HTYC0', 'id' => 'OaYtF1HTYC0'], ['url' => 'http://www.vistabee.com/en/v/q6h9ok', 'id' => '']];
     foreach ($youtube_urls as $test) {
         $this->assertEquals($test['id'], youtube_video_id($test['url']));
     }
 }
コード例 #2
0
ファイル: string.php プロジェクト: m1ke/easy-site-utils
function make_youtube_video($url, $protocol = 'http')
{
    $parse = parse_url_imp($url);
    if (empty($parse)) {
        $html .= '<!-- this link would not parse and is invalid : ' . $url . '-->';
    }
    switch ($parse['domain']) {
        case 'youtu.':
        case 'youtube.':
            // creates the variable $v. if YouTube ever change url scheme for 'watch' this will need altering
            $v = youtube_video_id($url, false);
            $html .= '<object type="application/x-shockwave-flash" style="width:480px; height:385px;" data="' . $protocol . '://www.youtube.com/v/' . $v . '&color1=0x006699&color2=0x54abd6"><param name="movie" value="' . $protocol . '://www.youtube.com/v/' . $v . '&color1=0x006699&color2=0x54abd6"/></object>';
            break;
        default:
            $html .= '<!-- this link does not correspond to a supported domain : ' . $url . '-->';
    }
    return $html;
}
コード例 #3
0
 /**
  * converter_para_banco
  * 
  * Converte a string para o formato do db
  * quando houver necessidade
  * 
  *
  * @access	private
  * @param	$string, $string, $string, $string, $array
  * @return	$string
  */
 private function converter_para_banco($valor, $tipo, $name = null, $id = null, $miniaturas = null)
 {
     switch ($tipo) {
         case 'data':
             $valor = implode('-', array_reverse(explode('/', $valor)));
             break;
         case 'video-youtube':
             // Chama a função do helper
             $valor = youtube_video_id($valor);
             break;
         case 'video-vimeo':
             // Chama a função do helper
             $valor = vimeo_video_id($valor);
             break;
         case 'imagem':
             if (file_exists($_FILES[$name]['tmp_name'])) {
                 $valor = $this->codemin->imagem_upload($name, $id, $miniaturas);
             } else {
                 $valor = null;
             }
             break;
         case 'monetario':
             if (empty($valor)) {
                 $valor = '0.00';
             } else {
                 $valor = str_replace('.', '', $valor);
                 $valor = str_replace(',', '.', $valor);
                 $valor = number_format($valor, 2, '.', '');
             }
             break;
     }
     return $valor;
 }