Skip to content

Commit

Permalink
68-feature-request
Browse files Browse the repository at this point in the history
  • Loading branch information
voitto committed Jun 18, 2009
1 parent a12f909 commit fd13efa
Show file tree
Hide file tree
Showing 9 changed files with 205 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ env:
collection_cache:
- posts:
duration : 0
location : cache
location : uploads
- identities:
duration : 0
location : cache
location : uploads

content_types:
- 0:
Expand Down
112 changes: 111 additions & 1 deletion app/omb/controllers/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,35 @@ function index( &$vars ) {
}
$caturl = $request->url_for(array('resource'=>'settings','id'=>$catmode->id,'action'=>'put'));
$catentry = $catmode->FirstChild('entries');

$uplmode = $Setting->find_by(array('name'=>'config.env.uploads','profile_id'=>get_profile_id()));
if (!$uplmode) {
$uplmode = $Setting->base();
$uplmode->set_value('profile_id',get_profile_id());
$uplmode->set_value('person_id',get_person_id());
$uplmode->set_value('name','config.env.uploads');
$uplmode->set_value('value',0);
$uplmode->save_changes();
$uplmode->set_etag();
$uplmode = $Setting->find($uplmode->id);
}
$uplurl = $request->url_for(array('resource'=>'settings','id'=>$uplmode->id,'action'=>'put'));
$uplentry = $uplmode->FirstChild('entries');

// n1mode = upload max size in MB, default = 4
$n1mode = $Setting->find_by(array('name'=>'config.env.max_upload_mb','profile_id'=>get_profile_id()));
if (!$n1mode) {
$n1mode = $Setting->base();
$n1mode->set_value('profile_id',get_profile_id());
$n1mode->set_value('person_id',get_person_id());
$n1mode->set_value('name','config.env.max_upload_mb');
$n1mode->set_value('value',4);
$n1mode->save_changes();
$n1mode->set_etag();
$n1mode = $Setting->find($n1mode->id);
}
$n1url = $request->url_for(array('resource'=>'settings','id'=>$n1mode->id,'action'=>'put'));
$n1entry = $n1mode->FirstChild('entries');

return vars(
array(
Expand All @@ -105,7 +134,13 @@ function index( &$vars ) {
&$threadentry,
&$catmode,
&$caturl,
&$catentry
&$catentry,
&$uplmode,
&$uplurl,
&$uplentry,
&$n1mode,
&$n1url,
&$n1entry
),
get_defined_vars()
);
Expand All @@ -127,3 +162,78 @@ function _index( &$vars ) {



function setting_widget_text_helper($nam,$nammode,$namurl,$namentry) {
echo '
var submit_to = "'. url_for(array(
'resource'=>'settings',
'id'=>$nammode->id,
'action'=>'put'
)).'";
var submit_to = "'. $namurl.'";
$(".jeditable_'.$nam.'").mouseover(function() {
$(this).highlightFade({end:\'#def\'});
});
$(".jeditable_'.$nam.'").mouseout(function() {
$(this).highlightFade({end:\'#fff\', speed:200});
});
$(".jeditable_'.$nam.'").editable(submit_to, {
indicator : "<img src=\''. base_path().'resource/jeditable/indicator.gif\'>",
submitdata : function() {
return {"entry[etag]" : "'.$namentry->etag.'"};
},
name : "setting[value]",
type : "textarea",
noappend : "true",
submit : "OK",
tooltip : "Click to edit...",
cancel : "Cancel",
callback : function(value, settings) {
return(value);
}
}); ';


};

function setting_widget_helper($nam,$nammode,$namurl,$namentry) {

echo '
var submit_to = "'. url_for(array(
'resource'=>'settings',
'id'=>$nammode->id,
'action'=>'put'
)).'";
var submit_to = "'. $namurl.'";
$(".editable_select_'.$nam.'_text").mouseover(function() {
$(this).highlightFade({end:\'#def\'});
});
$(".editable_select_'.$nam.'_text").mouseout(function() {
$(this).highlightFade({end:\'#fff\', speed:200});
});
$(".editable_select_'.$nam.'_text").editable(submit_to, {
indicator : "<img src=\''. base_path().'resource/jeditable/indicator.gif\'>",
data : \'';
if (!class_exists("Services_JSON")) lib_include("json"); $json = new Services_JSON(); echo $json->encode( $aktwitter_tw_text_options );
echo '\',
submitdata : function() {
return {"entry[etag]" : "'.$namentry->etag.'"};
},
name : "setting[value]",
type : "select",
placeholder : "'.$nammode->value.'",
noappend : "true",
submit : "OK",
tooltip : "Click to edit...",
cancel : "Cancel",
callback : function(value, settings) {
$(this).html(settings[\'jsonarr\'][value-0]);
return(value);
}
}); ';

}

57 changes: 57 additions & 0 deletions app/omb/views/admin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,42 @@
});


var submit_to = "<?php url_for(array(
'resource'=>'settings',
'id'=>$uplmode->id,
'action'=>'put'
)); ?>";

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

$(".editable_select_upl_text").mouseover(function() {
$(this).highlightFade({end:'#def'});
});
$(".editable_select_upl_text").mouseout(function() {
$(this).highlightFade({end:'#fff', speed:200});
});
$(".editable_select_upl_text").editable(submit_to, {
indicator : "<img src='<?php base_path(); ?>resource/jeditable/indicator.gif'>",
data : '<?php if (!class_exists("Services_JSON")) lib_include("json"); $json = new Services_JSON(); echo $json->encode( $aktwitter_tw_text_options ); ?>',
submitdata : function() {
return {"entry[etag]" : "<?php echo $uplentry->etag; ?>"};
},
name : "setting[value]",
type : "select",
placeholder : "<?php echo $uplmode->value; ?>",
noappend : "true",
submit : "OK",
tooltip : "Click to edit...",
cancel : "Cancel",
callback : function(value, settings) {
$(this).html(settings['jsonarr'][value-0]);
return(value);
}
});


<?php setting_widget_text_helper('uplmax',$n1mode,$n1url,$n1entry); ?>


});
// ]]>
Expand All @@ -149,6 +185,7 @@
</p>
<p>
<table cellpadding="10" border="0">

<tr>
<td>
<h4>Tags:</h4>
Expand All @@ -157,6 +194,7 @@ <h4>Tags:</h4>
<div class="editable_select_cat_text" id="editable_select_cat_text"></div>
</td>
</tr>

<tr>
<td>
<h4>Threaded:</h4>
Expand All @@ -166,6 +204,25 @@ <h4>Threaded:</h4>
</td>
</tr>

<tr>
<td>
<h4>Uploads:</h4>
</td>
<td>
<div class="editable_select_upl_text" id="editable_select_upl_text"></div>
</td>
</tr>

<tr>
<td>
<h4>Max Upload Size (in Megabytes):</h4>
</td>
<td>
<p class="jeditable_uplmax" id="jeditable_uplmax"><?php echo $n1mode->value; ?></p>
</td>
</tr>


</table>


Expand Down
3 changes: 2 additions & 1 deletion app/omb/views/posts/_upload.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
global $request;
$post = strtolower(classify($request->resource));

?>

?>
<?php if (!environment('uploads')) return; ?>

<form action="<?php url_for( $request->resource ); ?>" method="post" name="<?php url_for( $request->resource ); ?>" id="<?php url_for( $request->resource ); ?>" enctype="multipart/form-data">
<div>
Expand Down
3 changes: 3 additions & 0 deletions db/boot.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@
* overrides from config.php
*/

if (isset($env['max_upload_mb']))
$db->max_upload_megabytes($env['max_upload_mb']);

if (INTRANET)
$env['authentication'] = 'password';

Expand Down
14 changes: 14 additions & 0 deletions db/library/dbscript/mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ function quoted_insert_value( &$rec, $modified_field ) {
}
function pre_insert( &$rec, $modified_field, $datatype ) {
trigger_before( 'pre_insert', $rec, $this );


global $request;
$req =& $request;
if (isset($this->models[$rec->table]->field_attrs[$modified_field]['required'])) {
Expand All @@ -332,6 +334,12 @@ function pre_insert( &$rec, $modified_field, $datatype ) {
if ($datatype == 'time' && !(strlen($rec->attributes[$modified_field]) > 0))
$rec->attributes[$modified_field] = date("Y-m-d H:i:s",strtotime("now"));
if ($datatype == 'blob' && !(empty($req->params[strtolower(classify($rec->table))][$modified_field]))) {
if (environment('max_upload_mb')) {
$max = 1048576*environment('max_upload_mb');
$size = filesize($rec->attributes[$modified_field]);
if ($size >$max)
trigger_error('Sorry but that file is too big, the limit is '.environment('max_upload_mb').' megabytes', E_USER_ERROR);
}
$coll = environment('collection_cache');
if (isset($coll[$request->resource]) && $coll[$request->resource]['location'] == 'aws') {
$this->file_upload = array($modified_field,$rec->attributes[$modified_field]);
Expand Down Expand Up @@ -373,6 +381,12 @@ function pre_update( &$rec, $modified_field, $datatype ) {
}
if ($datatype == 'blob' && !(empty($req->params[strtolower(classify($rec->table))][$modified_field]))) {
if ( strlen( $rec->attributes[$modified_field] ) > 0 ) {
if (environment('max_upload_mb')) {
$max = 1048576*environment('max_upload_mb');
$size = filesize($rec->attributes[$modified_field]);
if ($size >$max)
trigger_error('Sorry but that file is too big, the limit is '.environment('max_upload_mb').' megabytes', E_USER_ERROR);
}
$coll = environment('collection_cache');
if (isset($coll[$request->resource]) && $coll[$request->resource]['location'] == 'aws') {
$this->file_upload = array($modified_field,$rec->attributes[$modified_field]);
Expand Down
12 changes: 12 additions & 0 deletions db/library/dbscript/postgresql.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,12 @@ function pre_insert( &$rec, $modified_field, $datatype ) {
if ($datatype == 'time' && !(strlen($rec->attributes[$modified_field]) > 0))
$rec->attributes[$modified_field] = date("Y-m-d H:i:s",strtotime("now"));
if ($datatype == 'blob' && strlen($rec->attributes[$modified_field]) > 0) {
if (environment('max_upload_mb')) {
$max = 1048576*environment('max_upload_mb');
$size = filesize($rec->attributes[$modified_field]);
if ($size >$max)
trigger_error('Sorry but that file is too big, the limit is '.environment('max_upload_mb').' megabytes', E_USER_ERROR);
}
$coll = environment('collection_cache');
if (isset($coll[$request->resource]) && $coll[$request->resource]['location'] == 'aws') {
$this->file_upload = array($modified_field,$rec->attributes[$modified_field]);
Expand Down Expand Up @@ -343,6 +349,12 @@ function pre_update( &$rec, $modified_field, $datatype ) {
trigger_error( "Sorry, that $modified_field has already been taken.", E_USER_ERROR );
}
if ($datatype == 'blob' && (strlen( $rec->attributes[$modified_field] ) > 0 )) {
if (environment('max_upload_mb')) {
$max = 1048576*environment('max_upload_mb');
$size = filesize($rec->attributes[$modified_field]);
if ($size >$max)
trigger_error('Sorry but that file is too big, the limit is '.environment('max_upload_mb').' megabytes', E_USER_ERROR);
}
global $request;
$coll = environment('collection_cache');
if (isset($coll[$request->resource]) && $coll[$request->resource]['location'] == 'aws') {
Expand Down
2 changes: 2 additions & 0 deletions wp-content/themes/p2/post-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
</div>
</form>
<div class="clear"></div>
<?php if (environment('uploads')) : ?>
<?php if (environment('use_uploadify')) : ?>
<form action="<?php bloginfo( 'url' ); ?>">
<div id="fileUpload">You have a problem with your javascript</div>
Expand All @@ -35,4 +36,5 @@
<?php else : ?>
<p>Add:&nbsp; <a href="<?php url_for(array('resource'=>'posts','action'=>'upload')); ?>">Photos</a></p>
<?php endif; ?>
<?php endif; ?>
</div> <!-- // postbox -->
4 changes: 2 additions & 2 deletions wp-content/themes/prologue-theme/post-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

<label for="posttext">Hi, <?php echo $first_name; ?>. Whatcha up to?</label>
<textarea name="posttext" id="posttext" rows="3" cols="60" maxlength="140"></textarea>

<?php if (environment('uploads')) : ?>
<label for="postfile">File <span style="font-size: .8em;">(optional)</span></label>
<input name="MAX_FILE_SIZE" value="65536000" type="hidden" />
<input name="postfile" id="postfile" type="file" />

<?php endif; ?>
<label for="link">Link <span style="font-size: .8em;">(optional)</span></label>
<input id="link" name="link[href]" />

Expand Down

0 comments on commit fd13efa

Please sign in to comment.