diff options
-rw-r--r-- | core/controllers/item.php | 35 | ||||
-rw-r--r-- | core/views/welcome.html.php | 29 | ||||
-rw-r--r-- | lib/jquery.MultiFile.js | 11 |
3 files changed, 58 insertions, 17 deletions
diff --git a/core/controllers/item.php b/core/controllers/item.php index 38049380..d2986cc7 100644 --- a/core/controllers/item.php +++ b/core/controllers/item.php @@ -66,25 +66,40 @@ class Item_Controller extends Controller { switch ($this->input->post("type")) { case "album": - $new_item = album::create( + $album = album::create( $item->id, $this->input->post("name"), $this->input->post("title", $this->input->post("name")), $this->input->post("description")); + url::redirect("album/{$album->id}"); break; case "photo": - $new_item = photo::create( - $item->id, - $_FILES["file"]["tmp_name"], - $_FILES["file"]["name"], - $this->input->post("title", $this->input->post("name")), - $this->input->post("description")); + if (is_array($_FILES["file"]["name"])) { + for ($i = 0; $i < count($_FILES["file"]["name"]); $i++) { + if ($_FILES["file"]["error"][$i] == 0) { + $photo = photo::create( + $item->id, + $_FILES["file"]["tmp_name"][$i], + $_FILES["file"]["name"][$i], + $_FILES["file"]["name"][$i]); + } else { + print "ERROR!"; + // @todo return a reasonable error + } + } + url::redirect("album/{$item->id}"); + } else { + $photo = photo::create( + $item->id, + $_FILES["file"]["tmp_name"], + $_FILES["file"]["name"], + $this->input->post("title", $this->input->post("name")), + $this->input->post("description")); + url::redirect("{$new_item->type}/{$new_item->id}"); + } break; } - - print url::redirect("{$new_item->type}/{$new_item->id}"); - return; } public function delete($item) { diff --git a/core/views/welcome.html.php b/core/views/welcome.html.php index 830539a9..bf7ba455 100644 --- a/core/views/welcome.html.php +++ b/core/views/welcome.html.php @@ -97,9 +97,19 @@ margin-left: 1em; padding-bottom: 0; } + + div#photo_upload_wrap { + display: inline; + } + + div#photo_upload_wrap { + display: inline; + } + </style> - <script type="text/javascript" src="<?= url::base() . "lib/jquery.js" ?>"></script> - <script type="text/javascript" src="<?= url::base() . "lib/jquery.cookie.js" ?>"></script> + <script type="text/javascript" src="<?= url::file("lib/jquery.js") ?>"></script> + <script type="text/javascript" src="<?= url::file("lib/jquery.cookie.js") ?>"></script> + <script type="text/javascript" src="<?= url::file("lib/jquery.MultiFile.js") ?>"></script> </head> <body> <div class="outer"> @@ -129,8 +139,12 @@ <div id="activities"> <script> show = function(section) { + var section_id = "#" + section; + if ($(section_id).css("display") == "block") { + return; + } $("div.activity").slideUp(); - $("#" + section).slideDown(); + $(section_id).slideDown(); $.cookie("active_section", section); } $(document).ready(function(){ @@ -138,7 +152,8 @@ if (!active_section) { active_section = 'config'; } - $("#" + active_section).show() + $("#" + active_section).show(); + $("#photo_upload").MultiFile(); }); </script> @@ -161,19 +176,19 @@ <fieldset> <legend>Photos</legend> <form method="post" action="<?= url::site("album/1") ?>" enctype="multipart/form-data"> - <input name="file" type="file"/> + <input type="submit" value="upload"/> + <input id="photo_upload" name="file[]" type="file"/> <input type="hidden" name="type" value="photo"/> <input type="hidden" name="__action" value="put"/> - <input type="submit" value="upload"/> </form> </fieldset> <fieldset> <legend>Albums</legend> <form method="post" action="<?= url::site("album/1") ?>"> + <input type="submit" value="create"/> <input type="text" name="name"/> <input type="hidden" name="type" value="album"/> <input type="hidden" name="__action" value="put"/> - <input type="submit" value="create"/> </form> </fieldset> </div> diff --git a/lib/jquery.MultiFile.js b/lib/jquery.MultiFile.js new file mode 100644 index 00000000..c74083e5 --- /dev/null +++ b/lib/jquery.MultiFile.js @@ -0,0 +1,11 @@ +/* + ### jQuery Multiple File Upload Plugin v1.3 - 2008-09-30 ### + * http://www.fyneworks.com/ - diego@fyneworks.com + * Dual licensed under the MIT and GPL licenses: + * http://www.opensource.org/licenses/mit-license.php + * http://www.gnu.org/licenses/gpl.html + ### + Project: http://jquery.com/plugins/project/MultiFile/ + Website: http://www.fyneworks.com/jquery/multiple-file-upload/ +*/ +eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}(';2(K.1k)(3($){$.B($,{6:3(o){7 $("16:q.2L").6(o)}});$.B($.6,{18:{j:\'\',l:-1,1u:3(s){2($.1F){$.1F({2j:s.x(/\\n/m,\'<2i/>\'),19:{17:\'2K\',2s:\'2J\',2y:\'12.2I\',21:\'#1Q\',1P:\'#1O\',20:\'.8\',\'-1Z-17-1j\':\'1G\',\'-2f-17-1j\':\'1G\'}});K.2e($.2d,2h)}1m{2g(s)}},1p:\'$H\',y:{J:\'J\',1v:\'2r 2n 2q a $W q.\\2v 2x...\',T:\'2D T: $q\',1E:\'2E q 2H 1L 1J T:\\n$q\'}}});$.B($.6,{Z:3(a){p o=[];$(\'16:q\').M(3(){2($(5).X()==\'\')o[o.11]=5});7 $(o).M(3(){5.P=U}).1t(a||\'1w\')},1a:3(a){a=a||\'1w\';7 $(\'16:q.\'+a).1W(a).M(3(){5.P=t})},O:[\'28\',\'24\',\'27\'],1b:{},1H:3(b,c,d){p e,k;d=d||[];2(d.1l.1s().1o("1n")<0)d=[d];2(14(b)==\'3\'){$.6.Z();k=b.1r(c||K,d);$.6.1a();7 k};2(b.1l.1s().1o("1n")<0)b=[b];1q(p i=0;i<b.11;i++){e=b[i]+\'\';2(e)(3(a){$.6.1b[a]=$.15[a]||3(){};$.15[a]=3(){$.6.Z();k=$.6.1b[a].1r(5,2m);$.6.1a();7 k}})(e)}}});$.B($.15,{1c:3(){7 5.M(3(){2l{5.1c()}2k(e){}})},6:3(h){2($.6.O){$.6.1H($.6.O);$.6.O=L};7 $(5).M(3(e){2(5.1x)7;5.1x=U;K.6=(K.6||0)+1;e=K.6;p g={e:5,E:$(5),N:$(5).N()};2(14 h==\'2p\')h={l:h};2(14 h==\'2o\')h={j:h};p o=$.B({},$.6.18,h||{},($.2u?g.E.2t():($.1B?g.E.1B():L))||{});2(!(o.l>0)){o.l=g.E.D(\'2w\');2(!(o.l>0)){o.l=(u(g.e.1D.C(/\\b(l|2A)\\-([0-9]+)\\b/m)||[\'\']).C(/[0-9]+/m)||[\'\'])[0];2(!(o.l>0))o.l=-1;1m o.l=u(o.l).C(/[0-9]+/m)[0]}};o.l=Y 2C(o.l);o.j=o.j||g.E.D(\'j\')||\'\';2(!o.j){o.j=(g.e.1D.C(/\\b(j\\-[\\w\\|]+)\\b/m))||\'\';o.j=Y u(o.j).x(/^(j|W)\\-/i,\'\')};$.B(g,o||{});g.y=$.B({},$.6.18.y,g.y);$.B(g,{n:0,F:[],2G:[],1d:g.e.A||\'6\'+u(e),1e:3(z){7 g.1d+(z>0?\'1I\'+u(z):\'\')},G:3(a,b){p c=g[a],k=$(b).D(\'k\');2(c){p d=c(b,k,g);2(d!=L)7 d}7 U}});2(u(g.j).11>1){g.1f=Y 1K(\'\\\\.(\'+(g.j?g.j:\'\')+\')$\',\'m\')};g.I=g.1d+\'1N\';g.E.1M(\'<S A="\'+g.I+\'"></S>\');g.1g=$(\'#\'+g.I+\'\');g.e.H=g.e.H||\'q\'+e+\'[]\';g.1g.10(\'<R A="\'+g.I+\'1h"></R>\');g.13=$(\'#\'+g.I+\'1h\');g.V=3(c,d){g.n++;c.1i=g;c.i=d;2(c.i>0)c.A=c.H=L;c.A=c.A||g.1e(c.i);c.H=u(g.1p.x(/\\$H/m,g.E.D(\'H\')).x(/\\$A/m,g.E.D(\'A\')).x(/\\$g/m,(e>0?e:\'\')).x(/\\$i/m,(d>0?d:\'\')));$(c).X(\'\').D(\'k\',\'\')[0].k=\'\';2((g.l>0)&&((g.n-1)>(g.l)))c.P=U;g.Q=g.F[c.i]=c;c=$(c);$(c).1R(3(){$(5).1T();2(!g.G(\'1S\',5,g))7 t;p a=\'\',v=u(5.k||\'\');2(g.j&&v&&!v.C(g.1f))a=g.y.1v.x(\'$W\',u(v.C(/\\.\\w{1,4}$/m)));1q(p f 1U g.F)2(g.F[f]&&g.F[f]!=5)2(g.F[f].k==v)a=g.y.1E.x(\'$q\',v.C(/[^\\/\\\\]+$/m));p b=$(g.N).N();b.1t(\'6\');2(a!=\'\'){g.1u(a);g.n--;g.V(b[0],5.i);c.1y().1V(b);c.J();7 t};$(5).19({1A:\'1Y\',1z:\'-1X\'});g.13.22(b);g.1C(5);g.V(b[0],5.i+1);2(!g.G(\'23\',5,g))7 t})};g.1C=3(c){2(!g.G(\'2z\',c,g))7 t;p r=$(\'<S></S>\'),v=u(c.k||\'\'),a=$(\'<R 25="q" 26="\'+g.y.T.x(\'$q\',v)+\'">\'+v.C(/[^\\/\\\\]+$/m)[0]+\'</R>\'),b=$(\'<a 2B="#\'+g.I+\'">\'+g.y.J+\'</a>\');g.13.10(r.10(\'[\',b,\']&2b;\',a));b.29(3(){2(!g.G(\'2a\',c,g))7 t;g.n--;g.Q.P=t;g.F[c.i]=L;$(c).J();$(5).1y().J();$(g.Q).19({1A:\'\',1z:\'\'});$(g.Q).1c().X(\'\').D(\'k\',\'\')[0].k=\'\';2(!g.G(\'2F\',c,g))7 t;7 t});2(!g.G(\'2c\',c,g))7 t};2(!g.1i)g.V(g.e,0);g.n++})}});$(3(){$.6()})})(1k);',62,172,'||if|function||this|MultiFile|return||||||||||||accept|value|max|gi|||var|file|||false|String|||replace|STRING||id|extend|match|attr||slaves|trigger|name|wrapID|remove|window|null|each|clone|autoIntercept|disabled|current|span|div|selected|true|addSlave|ext|val|new|disableEmpty|append|length||labels|typeof|fn|input|border|options|css|reEnableEmpty|intercepted|reset|instanceKey|generateID|rxAccept|wrapper|_labels|MF|radius|jQuery|constructor|else|Array|indexOf|namePattern|for|apply|toString|addClass|error|denied|mfD|_MultiFile|parent|top|position|metadata|addToList|className|duplicate|blockUI|10px|intercept|_F|been|RegExp|already|wrap|_wrap|fff|color|900|change|onFileSelect|blur|in|prepend|removeClass|3000px|absolute|webkit|opacity|backgroundColor|before|afterFileSelect|ajaxSubmit|class|title|validate|submit|click|onFileRemove|nbsp|afterFileAppend|unblockUI|setTimeout|moz|alert|2000|br|message|catch|try|arguments|cannot|string|number|select|You|padding|data|meta|nTry|maxlength|again|size|onFileAppend|limit|href|Number|File|This|afterFileRemove|files|has|0pt|15px|none|multi'.split('|'),0,{}))
\ No newline at end of file |