public function beforeValidate()
{
$attrs = [ 'time', 'testing', 'call' ];
foreach ( $attrs as $attr ) {
$time = \DateTime::createFromFormat( 'Y-m-d H:i:s', $this->$attr );
if ( !$time ) continue;
$this->$attr = $time->format( 'U' );
}
parent::beforeValidate();
return true;
}
$i = 0;
foreach ($arr AS $item){
if ( !$i ) {
mysql_query("INSERT INTO `item` (text, first) VALUES ('$item', 1)");
} else {
mysql_query("INSERT INTO `item` (text, first) VALUES ('$item', 0)");
}
$i++;
}
<?php
const MP3_DIR = '/drive2/Dropbox/backup/mp3/';
require_once __DIR__ . '/vendor/autoload.php';
$curl = new \Zelenin\Curl();
$playlist_url = 'http://music.yandex.ru/?ncrnd=6537#!/users/Muz-winamp/playlists/1046';
preg_match_all( '/users\/(.*)\/playlists\/(.*)/isu', $playlist_url, $matches );
$owner = $matches[1][0];
$playlist_id = $matches[2][0];
$response = $curl->get( 'http://music.yandex.ru/get/playlist2.xml?kinds=' . $playlist_id . '&owner=' . $owner );
$playlist = json_decode( $response['body'], true );
$playlist_title = $playlist['playlists'][0]['title'];
$tracks = implode( ',', $playlist['playlists'][0]['tracks'] );
$response = $curl->get( 'http://music.yandex.ru/get/tracks.xml?tracks=' . urlencode( $tracks ) );
$tracks = json_decode( $response['body'], true );
$tracks = $tracks['tracks'];
$playlist_dir = MP3_DIR . $playlist_title;
if ( !file_exists( $playlist_dir ) && !is_dir( $playlist_dir ) ) {
mkdir( $playlist_dir );
}
foreach ( $tracks as $track ) {
$artist = $track['artist'];
$title = $track['title'];
$response = $curl->get( 'http://storage.music.yandex.ru/download-info/' . $track['storage_dir'] . '/2.mp3' );
$xml = new DOMDocument();
$xml->loadXML( $response['body'] );
$host = $xml->getElementsByTagName( 'host' )->item(0)->nodeValue;
$ts = $xml->getElementsByTagName( 'ts' )->item(0)->nodeValue;
$path = $xml->getElementsByTagName( 'path' )->item(0)->nodeValue;
$s = $xml->getElementsByTagName( 's' )->item(0)->nodeValue;
$n = md5( 'XGRlBW9FXlekgbPrRHuSiA' . substr( $path, 1 ) . $s );
$mp3_url = 'http://' . $host . '/get-mp3/' . $n . '/' . $ts . $path;
//echo $mp3_url . PHP_EOL;
$response = $curl->get( $mp3_url );
$mp3_name = addslashes( $artist . ' - ' . $title . '.mp3' );
echo $mp3_name . PHP_EOL;
file_put_contents( MP3_DIR . $playlist_title . '/' . $mp3_name, $response['body'] );
}
<?php
$custom_query = 'posts_query';
$args = array(
'post_type' => 'post',
'posts_per_page' => -1,
);
${$custom_query} = new WP_Query( $args );
while ( ${$custom_query}->have_posts() ) : ${$custom_query}->the_post();
?>
<?php
endwhile;
wp_reset_postdata();
?>
<?php
$year = '';
if (have_posts()) : while (have_posts()) : the_post();
$current_year = get_the_date( 'Y' );
if ( $year != $current_year ) echo '<h4>---' . $current_year . '---</h4>';
?>
<article <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
</article>
<?php
$year = $current_year;
endwhile; endif; ?>
$year = '';
while ( .... ) :
$current_year = get_the_date( 'Y' );
if ( $year != $current_year ) {
echo '<h4>---' . $current_year . '---</h4>';
// .....
}
$year = $current_year;
endwhile;
function parseResponse( $response )
{
$response_parts = explode( "\r\n\r\n", $response, 2 );
$response = array();
$cookie = array();
$response['header'] = explode( "\r\n", $response_parts[0] );
if ( preg_match_all( '/Set-Cookie: (.*?)=(.*?)(\n|;)/i', $response_parts[0], $matches ) ) {
if ( !empty( $matches ) ) {
foreach ( $matches[1] as $key => $value ) {
$cookie[] = $value . '=' . $matches[2][$key] . ';';
}
$response['cookie'] = $cookie;
}
}
$response['body'] = $response_parts[1];
return $response;
}
$url = 'http://www.cbr.ru/scripts/XML_daily.asp?date_req=10/12/2013';
$request = curl_init( $url );
$options = array(
CURLOPT_HEADER => true,
CURLOPT_NOBODY => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0',
);
curl_setopt_array( $request, $options );
$result = curl_exec( $request );
if ( $result ) {
$info = curl_getinfo( $request );
$response = parseResponse( $result );
$response['info'] = $info;
} else {
$response = array(
'number' => curl_errno( $request ),
'error' => curl_error( $request ),
'info' => curl_getinfo( $request )
);
}
curl_close( $request );
print_r( $response );