Skip to content

Commit

Permalink
#94 #69 #23 #27 #58
Browse files Browse the repository at this point in the history
  • Loading branch information
voitto committed Jul 22, 2009
1 parent c9722e0 commit a4b44d0
Show file tree
Hide file tree
Showing 28 changed files with 389 additions and 637 deletions.
5 changes: 4 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,12 @@ OTHER DOCUMENTATION
The /app/omb/views/categories/_block.js file can be edited to change this setting.
At the top of this file the $category_count variable is set to 10 by default.

2. login timeout can be set by changing "cookielife" in config.yml

3. creating a Contact Page/Impressum/About page: as an administrator you will have an app called "Pages"
use this app to add new pages, links to these will appear in the footer of your P2-themed site


4. to change the allowed file-types for uploads, in config.yml is the "upload_types" list



Expand Down
14 changes: 13 additions & 1 deletion app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ env:
- streams
- translate
- facebook
- pages

installed:
- password
Expand All @@ -88,6 +89,7 @@ env:
- identica
- translate
- facebook
- pages

boot: omb

Expand Down Expand Up @@ -146,7 +148,7 @@ env:
ldap_user_field:

ping_server: http://dejafeed.com/?submit

blocks:
-pages
-categories
Expand All @@ -159,6 +161,16 @@ env:
duration : 0
location : uploads

cookielife: 1209600

upload_types:
-png
-gif
-jpg
-mp3
-mov
-avi

content_types:
- 0:
id : xhtml
Expand Down
20 changes: 19 additions & 1 deletion app/omb/controllers/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,21 @@ function index( &$vars ) {
}
$n2url = $request->url_for(array('resource'=>'settings','id'=>$n2mode->id,'action'=>'put'));
$n2entry = $n2mode->FirstChild('entries');

// n3mode = image upload thumbnail size
$n3mode = $Setting->find_by(array('name'=>'config.env.max_pixels','profile_id'=>get_profile_id()));
if (!$n3mode) {
$n3mode = $Setting->base();
$n3mode->set_value('profile_id',get_profile_id());
$n3mode->set_value('person_id',get_person_id());
$n3mode->set_value('name','config.env.max_pixels');
$n3mode->set_value('value',200);
$n3mode->save_changes();
$n3mode->set_etag();
$n3mode = $Setting->find($n3mode->id);
}
$n3url = $request->url_for(array('resource'=>'settings','id'=>$n3mode->id,'action'=>'put'));
$n3entry = $n3mode->FirstChild('entries');

return vars(
array(
Expand All @@ -165,7 +180,10 @@ function index( &$vars ) {
&$n2mode,
&$n2url,
&$n2entry,
&$n2list
&$n2list,
&$n3mode,
&$n3url,
&$n3entry
),
get_defined_vars()
);
Expand Down
56 changes: 37 additions & 19 deletions app/omb/controllers/identities.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,36 @@



function validate_identities_photo( $value ) {


before_filter('resize_uploaded_image','pre_insert');
before_filter('resize_uploaded_image','pre_update');

function resize_uploaded_image( &$rec, &$db ) {

// this happens before validate_identities_photo

if (!(is_upload('identities','photo')))
return true;
return;

$size = filesize($_FILES['identity']['tmp_name']['photo']);

if (!$size || $size > 409600) {
if (file_exists($_FILES['identity']['tmp_name']['photo']))
unlink($_FILES['identity']['tmp_name']['photo']);
trigger_error( "That photo is too big. Please find one that is smaller than 400K.", E_USER_ERROR );
}
if (!is_jpg($_FILES['identity']['tmp_name']['photo']))
trigger_error( "Sorry for the trouble, but your photo must be a JPG file.", E_USER_ERROR );
return true;
}


before_filter('resize_uploaded_jpg','pre_insert');
before_filter('resize_uploaded_jpg','pre_update');

function resize_uploaded_jpg( &$rec, &$db ) {

if (!(is_upload('identities','photo')))
return;
$upl = $_FILES['identity']['tmp_name']['photo'];

$ext = '.'.type_of_image($upl);

$orig = $rec->attributes['photo'];
$newthumb = tempnam( "/tmp", "new".$rec->id.".jpg" );
photoCreateCropThumb( $newthumb, $orig, 96 );
if (!$ext)
trigger_error( "Sorry for the trouble, but your photo must be a JPG, PNG or GIF file.", E_USER_ERROR );

$orig = $_FILES['identity']['tmp_name']['photo'];
$newthumb = tempnam( "/tmp", "new".$rec->id.$ext );
photoCreateCropThumb( $newthumb, $orig, 96, 100, $upl );
$rec->attributes['photo'] = $newthumb;

}
Expand Down Expand Up @@ -174,17 +178,31 @@ function put( &$vars ) {
if (is_upload('identities','photo')) {
$sql = "SELECT photo FROM ".$prefix."identities WHERE id = ".$db->escape_string($request->id);
$result = $db->get_result($sql);

$upl = $_FILES['identity']['tmp_name']['photo'];

$ext = '.'.type_of_image($upl);

if (!$ext)
trigger_error( "Sorry for the trouble, but your photo must be a JPG, PNG or GIF file.", E_USER_ERROR );

$content_type = type_of($ext);

if ($blobval = $db->result_value($result,0,"photo"))
$rec->set_value( 'avatar', $request->url_for(array('resource'=>"_".$rec->id)) . ".jpg" );
$rec->set_value( 'avatar', $request->url_for(array('resource'=>"_".$rec->id)) . $ext );
elseif (exists_uploads_blob( 'identities',$rec->id ))
$rec->set_value( 'avatar', $request->url_for(array('resource'=>"_".$rec->id)) . ".jpg" );
$rec->set_value( 'avatar', $request->url_for(array('resource'=>"_".$rec->id)) . $ext );
else
$rec->set_value( 'avatar', '' );
if (empty($rec->profile))
$rec->set_value( 'profile', $request->url_for(array('resource'=>"_".$rec->id)));
if (empty($rec->profile_url))
$rec->set_value( 'profile_url', $request->url_for(array('resource'=>"".$rec->nickname)));

$rec->save_changes();

$atomentry = $Identity->set_metadata($rec,$content_type,$rec->table,'id');

}

broadcast_omb_profile_update();
Expand Down
71 changes: 70 additions & 1 deletion app/omb/controllers/posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ function post( &$vars ) {
$atomentry = $Post->set_metadata($rec,$content_type,$table,'id');
$Post->set_categories($rec,$request,$atomentry);
if ((is_upload('posts','attachment'))) {

$upload_types = environment('upload_types');

if (!$upload_types)
$upload_types = array('jpg','jpeg','png','gif');

$ext = extension_for( type_of($_FILES[strtolower(classify($table))]['name']['attachment']));

if (!(in_array($ext,$upload_types)))
trigger_error('Sorry, this site only allows the following file types: '.implode(',',$upload_types), E_USER_ERROR);

$url = $request->url_for(array(
'resource'=>'posts',
'id'=>$rec->id
Expand All @@ -51,10 +62,27 @@ function post( &$vars ) {
else
$rec->set_value('title',$title." ".$url);
$rec->save_changes();

$tmp = $_FILES[strtolower(classify($table))]['tmp_name']['attachment'];

if (is_jpg($tmp)) {
$thumbsize = environment('max_pixels');
$Thumbnail =& $db->model('Thumbnail');
$t = $Thumbnail->base();
$newthumb = tempnam( "/tmp", "new".$rec->id.".jpg" );
resize_jpeg($tmp,$newthumb,$thumbsize);
$t->set_value('target_id',$atomentry->id);
$t->save_changes();
update_uploadsfile( 'thumbnails', $t->id, $newthumb );
$t->set_etag();
}

}

trigger_after( 'insert_from_post', $Post, $rec );
header_status( '201 Created' );
redirect_to( $request->base );

}


Expand Down Expand Up @@ -262,7 +290,7 @@ function _oembed( &$vars ) {
$url = $request->url_for(array(
'resource'=>'posts',
'id'=>$id,
'action'=>'attachment.'.extension_for($e->content_type)
'action'=>'preview'
));

return vars(
Expand Down Expand Up @@ -329,3 +357,44 @@ function _apps( &$vars ) {
get_defined_vars()
);
}


function preview( &$vars ) {
extract($vars);
$p = $Post->find($request->id);
$e = $p->FirstChild('entries');
$t = $Thumbnail->find_by('target_id',$e->id);
if ($t) {
$request->set_param('resource','thumbnails');
$request->set_param('id',$t->id);
render_blob($t->attachment,extension_for($e->content_type));
} else {
render_blob($p->attachment,extension_for($e->content_type));
}
}

function _pagelist( &$vars ) {
extract( $vars );
return vars(
array( &$collection, &$profile ),
get_defined_vars()
);
}

function _pagenew( &$vars ) {
extract( $vars );
$model =& $db->get_table( $request->resource );
$Member = $model->base();
return vars(
array( &$Member, &$profile ),
get_defined_vars()
);
}

function _pagespan( &$vars ) {
extract( $vars );
return vars(
array( &$collection, &$profile ),
get_defined_vars()
);
}
2 changes: 2 additions & 0 deletions app/omb/models/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ function Page() {

$this->let_access( 'all:administrators' );

$this->use_templates_from( 'posts' );

}

}
Expand Down
35 changes: 35 additions & 0 deletions app/omb/models/Thumbnail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

class Thumbnail extends Model {

function Thumbnail() {

// fields

$this->file_field( 'attachment' );

$this->time_field( 'created' );
$this->time_field( 'modified' );

$this->int_field( 'target_id' );

$this->int_field( 'entry_id' );

$this->auto_field( 'id' );

// relationships

$this->has_one( 'entry' );

// permissions

$this->let_read( 'all:everyone' );
$this->let_access( 'all:administrators' );

$this->set_hidden();

}

}

?>
11 changes: 11 additions & 0 deletions app/omb/views/admin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@

<?php setting_widget_helper('tz',$n2mode,$n2url,$n2entry,$n2list); ?>

<?php setting_widget_text_helper('imgmax',$n3mode,$n3url,$n3entry); ?>

});
// ]]>
</script>
Expand Down Expand Up @@ -246,6 +248,15 @@ <h4>Max Upload Size (in Megabytes):</h4>
</td>
</tr>

<tr>
<td>
<h4>Preview Image Size (in pixels):</h4>
</td>
<td>
<p class="jeditable_imgmax" id="jeditable_imgmax"><?php echo $n3mode->value; ?></p>
</td>
</tr>


</table>

Expand Down
33 changes: 0 additions & 33 deletions app/omb/views/pages/_block.js

This file was deleted.

0 comments on commit a4b44d0

Please sign in to comment.