function fetchPlaylists($userId, $parent) { $url = "http://gdata.youtube.com/feeds/api/users/" . $userId . "/playlists?v=2&alt=json"; $data = json_decode(file_get_contents($url), true); $info = $data["feed"]; $video = $info["entry"]; $nVideo = count($video); $userName = $info['author'][0]['name']['$t']; $authorId = insertAuthor($userId, $userName); echo "Channel Name: " . $info["title"]['$t'] . '<br/>Author:' . $authorId . '<br><br>'; for ($i = 0; $i < $nVideo; $i++) { $title = $video[$i]['title']['$t']; $description = $video[$i]['summary']['$t']; $ytPlaylistId = $video[$i]['yt$playlistId']['$t']; $tags = ''; $playlistId = insertPlaylist($ytPlaylistId, $title, $description, $authorId, $tags, $parent); if ($playlistId != 0) { fetchPlaylist($ytPlaylistId, $authorId, $playlistId); } echo "Name: " . $title . '<br/>'; echo "Link: " . $ytPlaylistId . '<br/>'; echo "Description: " . $description . '<br/><br/>'; } }
$surname = isset($_REQUEST['surname']) ? $_REQUEST['surname'] : ''; //Validazione lato server $name_pattern = '/^[a-zA-Z ]{3,}+$/'; if (!preg_match($name_pattern, $name)) { $author['err_name'] = "Nome non valido. Lunghezza minima 3 caratteri o caratteri non validi."; } $surname_pattern = '/^[a-zA-Z ]{3,}+$/'; if (!preg_match($surname_pattern, $surname)) { $author['err_surname'] = "Cognome non valido. Lunghezza minima 3 caratteri o caratteri non validi."; } if (count($author) > 0) { $author['res'] = false; echo json_encode($author); //echo $msg; } else { $author = insertAuthor($name, $surname); $author['res'] = true; echo json_encode($author); // insertAuthor($name, $surname); } break; case 'delete_author': $id_author = isset($_REQUEST['id_author']) ? $_REQUEST['id_author'] : ''; //validazione del dato proveniente dal javascript... potrebbe essere modificato dal DOM if (!filter_var($id_author, FILTER_VALIDATE_INT) === false) { //int $author_deleted = deleteAuthor($id_author); if (!$author_deleted) { $author['res'] = false; $author['authorfree'] = "Impossibile cancellare autore perchè è associato ad un libro."; echo json_encode($author);
if (isset($_GET['author_id'])) { $author_id = (int) $_GET['author_id']; $_SESSION['author_id'] = $author_id; header('Location:author_books.php'); exit; } if ($_POST) { $author_name = trim($_POST['author_name']); if (mb_strlen($author_name) < 3) { echo '<p>Невалидно име на автора</p>'; } else { $author_esc = mysqli_real_escape_string($link, $author_name); if (authorExist($link, $author_esc)) { echo '<p>Този автор вече съществува в БД.</p>'; } else { if (insertAuthor($link, $author_esc)) { echo '<p>Записа е успешен</p>'; } } } } $q = mysqli_query($link, 'SELECT * FROM authors'); if (mysqli_errno($link)) { echo mysqli_error($link); } $rezult = array(); while ($row = mysqli_fetch_assoc($q)) { $rezult[$row['author_id']]['author_id'] = $row['author_id']; $rezult[$row['author_id']]['author_name'] = $row['author_name']; } ?>