Last active
August 29, 2015 14:08
-
-
Save n0m4dz/cdfac4ef1986d3153e2d to your computer and use it in GitHub Desktop.
Laracasa example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class LaracasaController extends BaseController | |
{ | |
public function index() { | |
$result = Laracasa::getAlbum(); | |
return View::make('picasa')->with('albumFeed', $result); | |
} | |
public function getPhoto($photo) { | |
$photoFeed = Laracasa::getPhotoById($photo); | |
echo "<h2>Photo Feed for: " . $photoFeed->getTitle() . "</h2>"; | |
$photos = array( | |
'thumbnail' => $photoFeed->mediaGroup->thumbnail[2]->url, | |
'fullsize' => $photoFeed->mediaGroup->content[0]->url | |
); | |
echo "<img src='" . $photos['fullsize'] . "' />"; | |
} | |
public function uploadPhoto(){ | |
$result = Laracasa::addPhoto($_FILES['photo']); | |
if($result['state']){ | |
return Redirect::to('picasa')->with('flash_notice', 'Uploaded successfully. Photo ID: '.$result['id'])->with('state', true); | |
} else{ | |
return Redirect::to('picasa')->with('flash_notice', 'Error occured while uploading photo. Please try again')->with('state', false); | |
} | |
} | |
public function removePhoto($id) | |
{ | |
Laracasa::deletePhoto($id); | |
return Redirect::to('picasa')->with('flash_notice', 'Deleted successfully'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Laracasa demo</title> | |
<style type="text/css"> | |
.clear{ | |
clear: both; | |
} | |
.notif{ | |
border:solid 1px #3498db; | |
color: #3498db; | |
margin: 20px; | |
padding: 10px; | |
} | |
h3{ | |
text-transform: uppercase; | |
color: #666666; | |
} | |
ul { | |
color: #191D1D; | |
margin: 20px; | |
padding: 20px; | |
border: 1px solid #ababab; | |
display: block; | |
} | |
li{ | |
display: block; | |
float: left; | |
margin: 5px; | |
padding: 5px; | |
text-align: center; | |
background-color: #ecf0f1; | |
border: 1px solid #cccccc; | |
border-radius: 4px; | |
} | |
a { | |
color: #3498db; | |
text-decoration: none; | |
display: block; | |
} | |
a.delete{ | |
color: #e74c3c !important; | |
border-top: solid 1px #cccccc; | |
margin-top: 10px; | |
padding-top: 10px; | |
} | |
a:hover { | |
color: #2980b9; | |
} | |
a.delete:hover{ | |
color: #c0392b; | |
} | |
div.menuForm { | |
margin: 10px; | |
padding: 0px 10px; | |
background-color: #E0EAFF; | |
border: 1px solid #515B5C; | |
} | |
form.deleteForm { | |
padding-left: 10px; | |
display: inline; | |
} | |
img.thumb { | |
margin: 5px; | |
border: 0px; | |
} | |
.uploadForm{ | |
clear: both; | |
margin: 50px 20px 20px 20px; | |
border: solid 1px #ababab; | |
padding: 30px; | |
background: #ecf0f1; | |
} | |
</style> | |
</head> | |
<body> | |
@if(Session::has('flash_notice')) | |
<div class="notif"> | |
{{ Session::get('flash_notice'); }} | |
</div> | |
@endif | |
<ul> | |
<h3>Album name: {{$albumFeed->getTitle()}} </h3> | |
@foreach ($albumFeed as $entry) | |
@if ($entry instanceof Zend_Gdata_Photos_PhotoEntry) | |
<li> | |
<a href='/picasa/{{ $entry->getGphotoId() }}'> | |
<img class='thumb' src='{{ $entry->getMediaGroup()->getThumbnail()[1]->getUrl() }}' /><br /> | |
{{ $entry->getTitle() }} | |
<a href='/picasa/delete/{{ $entry->getGphotoId() }}' class="delete"> delete </a> | |
</a> | |
</li> | |
@endif | |
@endforeach | |
<div class="clear"></div> | |
</ul> | |
<form action="/picasa/upload" method="post" enctype="multipart/form-data" class="uploadForm"> | |
<h3>Add a Photo</h3> | |
<input type="file" name="photo"/> | |
<input type="submit" value="upload photo"> | |
</form> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Route::get('/picasa', array('uses' => 'LaracasaController@index')); | |
Route::get('/picasa/{photos}', array('uses' => 'LaracasaController@getphoto')); | |
Route::post('/picasa/upload', array('uses' => 'LaracasaController@uploadPhoto')); | |
Route::get('/picasa/delete/{id}', array('uses' => 'LaracasaController@removePhoto')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment