2 /***************************************************************************
4 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
5 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
6 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
7 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
11 * Copyright (C) 2009 Jonas Häggqvist
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
23 require_once('preconfig.inc.php');
25 function checkuploadfields(&$site, &$err) {
26 $lcd = $site->target2lcd($_REQUEST['target']);
28 foreach($_REQUEST as $field => $value) {
31 if (strpos($value, ' ') === false) {
32 $err[$field] = sprintf("This doesn't look like a proper full name (should contain at least one whitespace character): %s", $value);
36 if (!preg_match("/.*@.*\..*/", $value)) {
37 $err[$field] = sprintf("This doesn't look like an email I can reach: %s", $value);
41 if (trim($value) == '') {
42 $err[$field] = "You need to provide a theme name";
44 elseif ($site->themenameexists($value, $lcd['mainlcd'])) {
45 $err[$field] = sprintf("A theme with the name '%s' already exists for this target", $value);
49 if ($value !== "on") {
50 $err[$field] = "You need to accept to license your work under the Creative Commons Attribution Share Alike license to share your work here.";
55 /* These can't really be wrong */
59 if (!isset($_REQUEST['ccbysa'])) {
60 $err['ccbysa'] = "You need to accept to license your work under the Creative Commons Attribution Share Alike license to share your work here.";
64 function checkuploadfiles(&$site, &$err) {
65 $lcd = $site->target2lcd($_REQUEST['target']);
66 $requiredfiles = array('themefile', 'sshot_wps');
67 foreach($requiredfiles as $field) {
68 if (!isset($_FILES[$field]) ||
empty($_FILES[$field]['tmp_name'])) {
69 $err[$field] = array("You must provide this file");
72 foreach($_FILES as $name => $values) {
73 if (isset($err[$name]) ||
empty($_FILES[$field]['tmp_name'])) {
74 if (!empty($values['name'])) {
75 $err[$name][] = "Looks like upload failed. Was the file too large?";
82 $result = $site->validatezip($values);
83 $test = $site->checkwps($values['tmp_name'], $lcd['mainlcd'], $lcd['remotelcd']);
85 /* See if the wps passed at least one target/version combination */
86 foreach($test as $version => $targets) {
87 foreach($targets as $target => $results) {
88 if ($results['pass']) {
91 elseif (!empty($results['output'])) {
92 $output = $results['output'];
96 /* If not, reject with an error */
98 $result[] = sprintf("Your wps didn't pass checkwps. Here's some output: %s", $output);
103 if (isset($values['tmp_name']) && trim($values['tmp_name']) != "") {
104 $result = $site->validatesshot($values, $lcd['mainlcd']);
108 if (count($result) > 0) {
109 $err[$name] = $result;
114 if (isset($_REQUEST['author'])) {
116 /* First we do some checking of the uploaded data */
117 checkuploadfields($site, $err);
118 checkuploadfiles($site, $err);
119 if (count($err) > 0) {
120 $t->assign('errors', $err);
122 /* If that went wrong, go on and include the theme */
125 * At this stage, the theme has been validated, any possible errors
128 $lcd = $site->target2lcd($_REQUEST['target']);
131 * Figure out a decent shortname. Use the zipfile name and add some
132 * numbers if that exists.
136 $shortname = sprintf("%s%s",
137 basename(str_replace(' ', '_', strtolower($_FILES['themefile']['name'])), '.zip'),
140 $destdir = sprintf("%s/%s/%s", config
::datadir
, $lcd['mainlcd'], $shortname);
142 } while (file_exists($destdir));
144 $result = $site->addtheme(
145 $_REQUEST['themename'],
150 $lcd['remotelcd'] == '' ?
false : $lcd['remotelcd'],
151 $_REQUEST['description'],
152 $_FILES['themefile'],
153 $_FILES['sshot_wps'],
154 isset($_FILES['sshot_menu']) ?
$_FILES['sshot_menu'] : false
156 if (is_array($result)) {
157 $t->assign('general_errors', $result);
161 $site->prepareverification($insertid, $_REQUEST['email'], $_REQUEST['author']);
162 $template = "uploadcomplete.tpl";
167 * If no template is set, it either means this is the first load, or upload
170 if (!isset($template)) {
171 $template = "upload.tpl";
172 $targets = $site->listtargets();
173 foreach($targets as $target) {
174 $values['targets'][$target['shortname']] = $target['fullname'];
178 $t->render($template, $values);