Skip to content

Commit

Permalink
save all changes for upload
Browse files Browse the repository at this point in the history
  • Loading branch information
declanmaher committed Feb 9, 2014
0 parents commit 76a9c31
Show file tree
Hide file tree
Showing 18 changed files with 1,265 additions and 0 deletions.
32 changes: 32 additions & 0 deletions ajax.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Instagram PHP API
*/

require_once 'instagram.class.php';

require 'instagram.config.php';

// Receive AJAX request and create call object
$tag = $_GET['tag'];
$maxID = $_GET['max_id'];
$clientID = $instagram->getApiKey();

$call = new stdClass;
$call->pagination->next_max_id = $maxID;
$call->pagination->next_url = "https://api.instagram.com/v1/tags/{$tag}/media/recent?client_id={$clientID}&max_tag_id={$maxID}";

// Receive new data
$media = $instagram->getTagMedia($tag,$auth=false,array('max_tag_id'=>$maxID));

// Collect everything for json output
$images = array();
foreach ($media->data as $data) {
$images[] = $data->images->thumbnail->url;
}

echo json_encode(array(
'next_id' => $media->pagination->next_max_id,
'images' => $images
));
?>
70 changes: 70 additions & 0 deletions approvedImages.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

/**
* Instagram Image Approval class
* API Documentation: non
*
* @author Declan Maher
* @since 7.02.2014
* @copyright Declan Maher 2014
* @version 1.0
* @license BSD http://www.opensource.org/licenses/bsd-license.php
*/

class approvedImages {


public function get_approved_images() {
// images saved in txt file

if(file_exists('approvedImages.txt')){
try {
$lines = file("approvedImages.txt");

return $lines;

}
catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), " \n";
}

}

}

function insert_approved_images($savedImages) {

if(!empty($savedImages)) {
$pieces = explode(",", $savedImages);
//var_dump($pieces);
} else {
echo 'No images to save.Please go back and save Images';
}

if(file_exists('approvedImages.txt')){

try{
if(!empty($pieces)) {
//set file name to be written to
$file ="approvedImages.txt";
// Open the file to get existing content
$fh = fopen($file, 'w') or die("can't open file");

foreach($pieces as $currentImage) {
$stringnl = $currentImage . PHP_EOL;// add new line
// Write the contents back to the file
fwrite($fh, $stringnl);
}
fclose($fh);
}
}
catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), " \n";
}

}
}

}

?>
Empty file added approvedImages.txt
Empty file.
14 changes: 14 additions & 0 deletions db.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

/*Your Server Name: mulroyphotography.netfirmsmysql.com
Database Name: dreamtimetheatre
Database Username: dreamtimetheatre
Database Password: ******** */

define('DB_SERVER', 'mulroyphotography.netfirmsmysql.com');
define('DB_USERNAME', 'dreamtimetheatre');
define('DB_PASSWORD', 'fidelmas99');
define('DB_DATABASE', 'dreamtimetheatre');
$connection = mysql_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD) or die(mysql_error());
$database = mysql_select_db(DB_DATABASE) or die(mysql_error());
?>
99 changes: 99 additions & 0 deletions header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<html>
<head>
<meta charset="utf-8" />
<title>Instagram Approval App</title>

<link rel="stylesheet" href="style.css" type="text/css" media="all" />

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('#more').click(function() {
var tag = $(this).data('tag'),
maxid = $(this).data('maxid');
console.log(maxid);

$.ajax({
type: 'GET',
url: 'ajax.php',
data: {
tag: tag,
max_id: maxid
},
dataType: 'json',
cache: false,
success: function(data) {
// Output data
$.each(data.images, function(i, src) {
$('ul#photos').append('<li><img src="' + src + '"></li>');
});

// Store new maxid
$('#more').data('maxid', data.next_id);
}
});
});

// if no images selected then don't allow form submit
$("form:first").submit(function(){
if(document.getElementById("savedImages").value == '')
{
alert('Please select at least one image before saving.');
return false; }
});
// set array for photos approved
var allVals = [];

// This function saves the images clicked by user
$('#photos').on( "click","img", function() {
allVals.push($(this).attr('src'));
$(this).css("border","2px solid red");
$(this).css('margin', '-2px');
$('#savedImages').val(allVals)
});

// reset all the image borders
$(document).on("click", "input[type='reset']", function(){
$("#photos img").each(function (i) {
$(this).css("border","2px solid white");
$(this).css('margin', '-2px');
});

});

// toggle the help info
$( "#help" ).click(function() {
$( "p" ).slideToggle( "slow" );
});

});
</script>
</head>
<body>


<div id="header-container">
<div id="header">
<div id="header2">

<div id="navigation">
<h2 >
Instagram Approval App
</h2>

<?php // don't show on login page
if(basename($_SERVER['PHP_SELF']) != 'index.php' ) { ?>
<ul>
<li id="home-nav"><a href="home.php">Approve Images</a></li>
<li id="about-nav"><a href="viewImages.php">View Approved Images</a></li>
<li id="news-nav"><a href='home.php?id=logout'>Logout of App</a></li>

</ul>

<?php } ?>
</div>
</div>
</div>
</div>


78 changes: 78 additions & 0 deletions home.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<!DOCTYPE html>
<?php
/*
Shows the Images for Approval and allows User to select Images for approval
*/
session_start();

// logut user
if($_GET['id']=='logout')
{
unset($_SESSION['userdetails']);
session_destroy();
}
require 'db.php';
require 'instagram.class.php';
require 'instagram.config.php';
require 'approvedImages.class.php';

if (!empty($_SESSION['userdetails']))
{
$data=$_SESSION['userdetails'];

// Store user access token
$instagram->setAccessToken($data);
}
else
{
header('Location: index.php');
}

//get header
require 'header.php';
// Get the tag to search for - set in config file
$tag = $instagram->getTagtoSearchFor();


?>
<div class="main">
<h3>Approve Photos <?php echo '(#'.$tag. ')';
echo '<input type="button" id="help" value="?">'; ?></h3>
<p style="display: none">
Click on images below to select as an Approved Image. Click on the 'Load More...'button to view more images.<br>
When you have selected all your approved images, click on 'Save Approved Images' button to save.<br>
You can clear all the selected images by clicking the 'Reset' button.
</p>

<!--- When User clicks on the images the image src is saved to this textarea.
Form is then submitted to save approved Images. --->
<form action="saveApprovedImages.php" method="post">
<textarea hidden="" name="savedImages" id="savedImages"></textarea>
<input type="submit" class="button" value="Save Approved Images">
<input type="reset" class="button" id="reset" value="Reset to clear all Images">


</form>

<?php


// Get recently tagged media
$media = $instagram->getTagMedia($tag);

// Display first set of results (future sets displayed with ajax)
echo '<ul id="photos">';

foreach ($media->data as $data)
{
echo '<li><img id="image" src="'.$data->images->thumbnail->url.'">';
//echo "<input type=\"checkbox\" name=\"image[]\" value=\"{$data->images->thumbnail->url}\"></li>";
}
echo '</ul>';

// Show 'load more' button
echo '<br><button id="more" data-maxid="'.$media->pagination->next_max_id.'" data-tag="'.$tag.'">Load more ...</button>';
?>
</div>
</body>
</html>
24 changes: 24 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
session_start();
//get header
require 'header.php';
?>
<div style='text-align:center; padding: 100px'>


<?php
if (!empty($_SESSION['userdetails']))
{
header('Location: home.php');
}
require 'instagram.class.php';
require 'instagram.config.php';

// Display the login button
$loginUrl = $instagram->getLoginUrl();
echo "<a href=\"$loginUrl\" class=\"button\">Sign in with Instagram</a>";
?>

</body>

</html>
Loading

0 comments on commit 76a9c31

Please sign in to comment.