Skip to content

Commit

Permalink
flickr app
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Hendrickson committed Oct 17, 2009
1 parent c8e5c63 commit 0f933f0
Show file tree
Hide file tree
Showing 5 changed files with 286 additions and 0 deletions.
96 changes: 96 additions & 0 deletions app/flickr/controllers/flickr_users.php
@@ -0,0 +1,96 @@
<?php


function get( &$vars ) {
extract( $vars );
switch ( count( $collection->members )) {
case ( 1 ) :
if ($request->id && $request->entry_url())
render( 'action', 'entry' );
default :
render( 'action', 'index' );
}
}




function flickr_oauth_login_test(&$vars) {
extract($vars);
$success = false;

if ($success)
echo 1;
else
echo 0;

exit;

}



function _doctype( &$vars ) {
// doctype controller
}



function index( &$vars ) {
extract( $vars );
$theme = environment('theme');
$blocks = environment('blocks');
$atomfeed = $request->feed_url();
return vars(
array(
&$blocks,
&$profile,
&$collection,
&$atomfeed,
&$theme
),
get_defined_vars()
);
}




function _edit( &$vars ) {
extract( $vars );

if (!(class_exists('Services_JSON')))
lib_include('json');

$stat = $Setting->find_by(array('name'=>'flickr_status','profile_id'=>get_profile_id()));

if (!$stat) {
$stat = $Setting->base();
$stat->set_value('profile_id',get_profile_id());
$stat->set_value('person_id',get_person_id());
$stat->set_value('name','flickr_status');
$stat->set_value('value','enabled');
$stat->save_changes();
$stat->set_etag();
$stat = $Setting->find($stat->id);
}

// get the one-to-one-related child-record from "entries"
$sEntry =& $stat->FirstChild('entries');

$staturl = $request->url_for(array('resource'=>'settings','id'=>$stat->id,'action'=>'put'));

$status = $stat->value;

$aktwitter_tw_text_options = array(
'disabled'=>'disabled',
'enabled'=>'enabled'
);

return vars(
array( &$aktwitter_tw_text_options,&$status,&$staturl,&$sEntry,&$profile ),
get_defined_vars()
);

}

29 changes: 29 additions & 0 deletions app/flickr/flickr.php
@@ -0,0 +1,29 @@
<?php





function flickr_init() {
include 'wp-content/language/lang_chooser.php'; //Loads the language-file

app_register_init( 'flickr_users', 'edit.html', 'Connect to Flickr', 'flickr', 2 );

}

function flickr_status_disabled() {

}

function flickr_status_enabled() {

global $db,$request;

$Setting =& $db->model('Setting');

$stat = $Setting->find_by(array('name'=>'flickr_frob','profile_id'=>get_profile_id()));

if (!$stat)
echo "<script type=\"text/javascript\">\ntop.location.href = \"".$request->url_for('flickr_login')."\";\n</script>";

}
12 changes: 12 additions & 0 deletions app/flickr/models/FlickrUser.php
@@ -0,0 +1,12 @@
<?php

class FlickrUser extends Model {

function FlickrUser() {

$this->auto_field('id');

}

}

87 changes: 87 additions & 0 deletions app/flickr/plugins/flickr.php
@@ -0,0 +1,87 @@
<?php

after_filter( 'send_to_flickr', 'insert_from_post' );

before_filter( 'copy_posted_blob_flickr', 'insert_from_post' );

function copy_posted_blob_flickr( &$model, &$req ) {

if (!get_profile_id())
return;

if (get_option('flickr_status') != 'enabled')
return;

if (!file_exists($_FILES['post']['tmp_name']['attachment']))
return;

$tmp = 'cache'.DIRECTORY_SEPARATOR.make_token().extension_for(type_of($_FILES['post']['name']['attachment']));
$result = copy ( $_FILES['post']['tmp_name']['attachment'] , $tmp );
$_SESSION['copied_blob_flickr'] = $tmp;

}

function send_to_flickr( &$model, &$rec ) {

global $db;

$key = environment( 'flickrKey' );
$secret = environment( 'flickrSecret' );

if (empty($key))
return;

if (!get_profile_id())
return;

if (!$rec->table == 'posts')
return;

if (!(isset($rec->title)) || !(isset($rec->uri)))
return;

if (get_option('flickr_status') != 'enabled')
return;

global $db,$prefix;

$notice_content = $rec->attributes['title'];

if (extension_for(type_of($_FILES['post']['name']['attachment'])) == 'jpg'
&& (file_exists($_SESSION['copied_blob_flickr']))){

add_include_path(library_path()."phpFlickr");

include('phpFlickr.php');

$f = new phpFlickr( $key, $secret );

$Setting =& $db->model('Setting');

$stat = $Setting->find_by(array('name'=>'flickr_frob','profile_id'=>get_profile_id()));

if (!empty($stat->value)) {
$f->setToken($stat->value);
$f->sync_upload(
$_SESSION['copied_blob_flickr'],
$notice_content,
'',
null,
1,
1,
1
);
unlink($_SESSION['copied_blob_flickr']);
unset($_SESSION['copied_blob_flickr']);

//$photo,
//$title = null,
//$description = null,
//$tags = null,
//$is_public = null,
//$is_friend = null,
//$is_family = null

}
}
}
62 changes: 62 additions & 0 deletions app/flickr/views/flickr_users/_edit.html
@@ -0,0 +1,62 @@
<?php include 'wp-content/language/lang_chooser.php'; //Loads the language-file ?>

<script src="<?php base_path(); ?>resource/jeditable/jquery.jeditable.js" type="text/javascript"></script>
<script src="<?php base_path(); ?>resource/jeditable/jquery.highlightFade.js" type="text/javascript"></script>

<script type="text/javascript">
// <![CDATA[


$(document).ready(function() {

var submit_to = "<?php echo $staturl; ?>";

$(".editable_select_fb_text").mouseover(function() {
$(this).highlightFade({end:'#def'});
});
$(".editable_select_fb_text").mouseout(function() {
$(this).highlightFade({end:'#fff', speed:200});
});
$(".editable_select_fb_text").editable(submit_to, {
indicator : "<img src='<?php base_path(); ?>resource/jeditable/indicator.gif'>",
data : '<?php $json = new Services_JSON(); echo $json->encode( $aktwitter_tw_text_options ); ?>',
submitdata : function() {
return {"entry[etag]" : "<?php echo $sEntry->etag; ?>"};
},
name : "setting[value]",
type : "select",
<?php if (!empty($status)) : ?>
placeholder : "<?php echo $status; ?>",
<?php endif; ?>
noappend : "true",
submit : "<?php echo $txt['flickr_settings_ok']; ?>",
tooltip : "<?php echo $txt['flickr_settings_click_edit']; ?>",
cancel : "<?php echo $txt['flickr_settings_cancel']; ?>",
callback : function(value, settings) {
$(this).html(settings['jsonarr'][value-0]);
return(value);
}
});



});

// ]]>
</script>




<div id="twitterbox">
<br />
<h3><?php echo $txt['flickr_settings_post_to_flickr']; ?></h3>
<br />
<br />
<h4><?php echo $txt['flickr_settings_status']; ?>:</h4>
<p class="editable_select_fb_text" id="editable_select_fb_text"><?php echo $status; ?></p>
<br />

</div>

<br /><br />

0 comments on commit 0f933f0

Please sign in to comment.