Skip to content

Commit

Permalink
orchestra.io support from pull request #277 and issue #293
Browse files Browse the repository at this point in the history
Merge branch 'master' of https://github.com/duggan/frontend into duggan

Conflicts:
	src/html/index.php
	src/libraries/controllers/ApiPhotoController.php
	src/libraries/controllers/SetupController.php
	src/libraries/models/Photo.php
	src/libraries/routes.php
	src/templates/setup.php
  • Loading branch information
jmathai committed Jan 6, 2012
2 parents a421a53 + 1c1232a commit f1f9673
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 41 deletions.
1 change: 1 addition & 0 deletions src/configs/openphoto-SUSE-vhost.conf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
ExpiresByType image/gif "A604800"
ExpiresByType image/jpg "A604800"
ExpiresByType image/jpeg "A604800"
ExpiresByType image/jpe "A604800"
ExpiresByType image/png "A604800"

Header set Cache-Control "must-revalidate"
Expand Down
1 change: 1 addition & 0 deletions src/configs/openphoto-vhost.conf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
ExpiresByType image/gif "A604800"
ExpiresByType image/jpg "A604800"
ExpiresByType image/jpeg "A604800"
ExpiresByType image/jpe "A604800"
ExpiresByType image/png "A604800"

Header set Cache-Control "must-revalidate"
Expand Down
2 changes: 2 additions & 0 deletions src/html/assets/themes/default/stylesheets/setup.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ div#setup h3{ font-size:1em; margin:15px 0 5px 0; }
div#setup ul.errors, div#setup p.error{ color:#ca1616; }
div#setup form em{ font-size:.75em; }
div#setup label{ font-size:1.15em; color:#404040; display:block; position:relative; }
div#setup p{ font-size:1.0em; color:#404040; display:block; position:relative; margin-bottom:20px; }
div#setup p code{ font-size:1.0em; font-family: monospace, sans-serif; background-color:#ddd; border: 1px solid #eee; color:#404040; display:block; position:relative; }
div#setup label em{ font-size:.6em; position:relative; top:-2px; left:3px; }
div#setup label + input, div#setup label + textarea, div#setup label + select{ margin-bottom:20px; display:block; }
div#setup{ width:400px; margin:auto; }
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/controllers/ApiPhotoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public function upload()
{
unset($attributes['photo']);
$localFile = tempnam($this->config->paths->temp, 'opme');
$name = basename($localFile).'.jpg';
$name = basename($localFile).'.jpe';
file_put_contents($localFile, base64_decode($_POST['photo']));
$photoId = $this->photo->upload($localFile, $name, $attributes);
}
Expand Down
111 changes: 74 additions & 37 deletions src/libraries/controllers/SetupController.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
/**
* Setup controller for HTML endpoints
* This controls the setup flow when the software is first installed.
* The main purpose of this flow is to generate settings.ini.
*
* @author Jaisen Mathai <[email protected]>
* @author Kevin Hornschemeier <[email protected]>
*/
* Setup controller for HTML endpoints
* This controls the setup flow when the software is first installed.
* The main purpose of this flow is to generate settings.ini.
*
* @author Jaisen Mathai <[email protected]>
* @author Kevin Hornschemeier <[email protected]>
*/
class SetupController extends BaseController
{
/**
Expand Down Expand Up @@ -55,10 +55,23 @@ public function setup()

$errors = $this->verifyRequirements($imageLibs);

if(count($errors) > 0)
$step = 0;
else
$errors = '';
$skipConfig = 0;
foreach ($errors as $error => $message)
{
switch ($error)
{
case 'config_not_writable':
$skipConfig = 1;
$step = 1;
break;
case 'cannot_create_generated':
case 'generated_not_writable':
case 'no_image_lib':
default:
$step = 0;
break;
}
}

$email = '';
if(getConfig()->get('user') != null)
Expand Down Expand Up @@ -178,11 +191,12 @@ public function setupDropboxPost()
*/
public function setupPost()
{
$step = 1;
$appId = isset($_POST['appId']) ? $_POST['appId'] : '';
$email = isset($_POST['email']) ? $_POST['email'] : '';
$theme = isset($_POST['theme']) ? $_POST['theme'] : '';
$input = array(
$step = 1;
$appId = isset($_POST['appId']) ? $_POST['appId'] : '';
$email = isset($_POST['email']) ? $_POST['email'] : '';
$theme = isset($_POST['theme']) ? $_POST['theme'] : '';
$skipConfig = isset($_POST['skipConfig']) ? $_POST['skipConfig'] : '';
$input = array(
array('Email', $email, 'required')
);

Expand All @@ -193,6 +207,7 @@ public function setupPost()
getSession()->set('appId', $appId);
getSession()->set('ownerEmail', $email);
getSession()->set('theme', $theme);
getSession()->set('skipConfig', $skipConfig);

$qs = '';
if(isset($_GET['edit']))
Expand Down Expand Up @@ -553,7 +568,9 @@ public function setup3Post()
$fsObj = getFs();
$dbObj = getDb();

$serverUser = exec("whoami");
$serverUser = @exec("whoami");
if(empty($serverUser))
$serverUser = 'unknown';
if(!$fsObj->initialize($isEditMode))
{
if($usesAws)
Expand All @@ -577,8 +594,9 @@ public function setup3Post()

if($fsErrors === false && $dbErrors === false)
{
$writeError = $this->writeConfigFile();
if($writeErrors === false)
// we negate this because writeConfigFile returns status
$writeStatus = ($this->writeConfigFile() === false);
if($writeStatus === true)
{
if(isset($_GET['edit']))
{
Expand Down Expand Up @@ -617,6 +635,9 @@ public function setup3Post()
if(isset($_GET['edit']))
$qs = '?edit';

if(isset($writeStatus) && $writeStatus === false)
$step = 4;

$template = sprintf('%s/setup.php', getConfig()->get('paths')->templates);
// copied to/from setup3()
$body = $this->template->get($template, array('step' => $step, 'themes' => $themes, 'usesAws' => $usesAws, 'usesMySql' => $usesMySql,
Expand Down Expand Up @@ -674,36 +695,40 @@ private function getDefaultConfigParams()
*/
private function verifyRequirements($imageLibs)
{
$errors = array();
$warnings = array();
$configDir = $this->utility->getBaseDir() . '/userdata';
$generatedDir = "{$configDir}/configs";

if(file_exists($generatedDir) && is_writable($generatedDir) && !empty($imageLibs))
# No errors, return empty array
return $errors;
return $warnings;

$user = exec("whoami");
$user = @exec("whoami");
if(empty($user))
$user = 'Apache user';

if(!is_writable($configDir))
$errors[] = "Insufficient privileges to complete setup.<ul><li>Make sure the user <em>{$user}</em> can write to <em>{$configDir}</em>.</li></ul>";

if(!file_exists($generatedDir))
{
$createDir = mkdir($generatedDir, 0700);
if(!$createDir)
$errors[] = "Could not create configuration directory.<ul><li>Make sure the user <em>{$user}</em> can write to <em>{$generatedDir}</em>.</li></ul>";
$warnings['config_not_writable'] = "<em>{$configDir}</em> is not writable. <ul><li>You can either make the directory writable by <em>{$user}</em> or,</li><li>manually upload the config at the end of the setup.</li></ul>";
}
elseif(!is_writable($generatedDir))
else
{
$errors[] = "Directory exist but is not writable.<ul><li>Make sure the user <em>{$user}</em> can write to <em>{$generatedDir}</em>.</li></ul>";
}
if(!file_exists($generatedDir))
{
$createDir = mkdir($generatedDir, 0700);
if(!$createDir)
$warnings['cannot_create_generated'] = "Could not create configuration directory.<ul><li>Make sure the user <em>{$user}</em> can write to <em>{$generatedDir}</em>.</li></ul>";
}
elseif(!is_writable($generatedDir))
{
$warnings['generated_not_writable'] = "Directory exist but is not writable.<ul><li>Make sure the user <em>{$user}</em> can write to <em>{$generatedDir}</em>.</li></ul>";
}

if(empty($imageLibs))
$errors[] = 'No suitable image library exists.<ul><li>Make sure that one of the following are installed: <em><a href="http://php.net/imagick">Imagick</a></em>, <em><a href="http://php.net/gmagick">Gmagick</a></em>, or <em><a href="http://php.net/gd">GD</a></em>.</li></ul>';
if(empty($imageLibs))
$warnings['no_image_lib'] = 'No suitable image library exists.<ul><li>Make sure that one of the following are installed: <em><a href="http://php.net/imagick">Imagick</a></em>, <em><a href="http://php.net/gmagick">Gmagick</a></em>, or <em><a href="http://php.net/gd">GD</a></em>.</li></ul>';
}

return $errors;
return $warnings;
}

/**
Expand Down Expand Up @@ -775,9 +800,21 @@ private function writeConfigFile()
file_get_contents("{$configDir}/template.ini")
);

$iniWritten = file_put_contents(sprintf("%s/userdata/configs/%s.ini", $baseDir, getenv('HTTP_HOST')), $generatedIni);
if(!$iniWritten)
return false;
if (getSession()->get('skipConfig') == 1)
{
$step = 4;
$iniName = sprintf("%s.ini", getenv('HTTP_HOST'));
$generatedDir = $configDir . '/generated/';
// Output config to a text box for copying.
$template = sprintf('%s/setup.php', getConfig()->get('paths')->templates);
$body = getTemplate()->get($template, array('step' => $step, 'generatedIni' => $generatedIni, 'iniName' => $iniName, 'generatedDir' => $generatedDir));
getTheme()->display('template.php', array('body' => $body, 'page' => 'setup'));
}
else {
$iniWritten = file_put_contents(sprintf("%s/userdata/configs/%s.ini", $baseDir, getenv('HTTP_HOST')), $generatedIni);
if(!$iniWritten)
return false;
}

// clean up the session
foreach($session as $key => $val)
Expand Down
21 changes: 21 additions & 0 deletions src/libraries/initialize.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@
// TODO, remove these
date_default_timezone_set('America/Los_Angeles');

// If custom route is not being used, try some more common routing cases
// See pull request #277 and issue #293
if (!isset($_GET['__route__']))
{
if (isset($_SERVER['PATH_INFO']))
{
$_GET['__route__'] = $_SERVER['PATH_INFO'];
}
else if (isset($_SERVER['REQUEST_URI']))
{
if ($request_uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))
{
$_GET['__route__'] = $request_uri;
}
}
else if (isset($_SERVER['PHP_SELF']))
{
$_GET['__route__'] = $_SERVER['PHP_SELF'];
}
}

if(isset($_GET['__route__']) && strstr($_GET['__route__'], '.json'))
header('Content-type: application/json');

Expand Down
2 changes: 1 addition & 1 deletion src/libraries/models/Photo.php
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ private function generateCustomUrl($basePath, $width, $height, $options)
$fragment = $this->generateFragment($width, $height, $options);
$customPath = preg_replace('#^/base/#', '/custom/', $basePath);
$customName = substr($customPath, 0, strrpos($customPath, '.'));
return "{$customName}_{$fragment}.jpg";
return "{$customName}_{$fragment}.jpe";
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/libraries/plugins/FacebookConnectPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,3 @@ public function onBodyEnd()
MKP;
}
}

2 changes: 1 addition & 1 deletion src/libraries/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* /photo/{id}[/{additional}]
*/
getRoute()->get('/photo/([a-zA-Z0-9]+)/edit', array('PhotoController', 'edit')); // edit form for a photo (/photo/{id}/edit)
getRoute()->get('/photo/([a-zA-Z0-9]+)/create/([a-z0-9]+)/([0-9]+)x([0-9]+)x?(.*).jpg', array('PhotoController', 'create')); // create a version of a photo (/photo/create/{id}/{options}.jpg)
getRoute()->get('/photo/([a-zA-Z0-9]+)/create/([a-z0-9]+)/([0-9]+)x([0-9]+)x?(.*).jpe', array('PhotoController', 'create')); // create a version of a photo (/photo/create/{id}/{options}.jpg)
getRoute()->get('/photo/([a-zA-Z0-9]+)/?(.+)?/view', array('PhotoController', 'view')); // view a photo (/photo/{id}/view[/{options}])
getRoute()->post('/photo/([a-zA-Z0-9]+)/update', array('PhotoController', 'update')); // update a photo (/photo/{id}/update
getRoute()->post('/photo/upload', array('PhotoController', 'uploadPost')); // upload a photo
Expand Down
9 changes: 9 additions & 0 deletions src/templates/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<button type="submit">Continue to Step 2</button>
</div>
<input type="hidden" name="appId" id="appId" <?php if(isset($appId)) { ?>value="<?php $this->utility->safe($appId); ?>"<?php } ?>>
<input type="hidden" name="skipConfig" id="skipConfig" <?php if(isset($skipConfig) && $skipConfig == 1) { ?>value="<?php $this->utility->safe($skipConfig); ?>"<?php } ?>>
</form>
</div>
<div id="setup-step-2"<?php echo ($step != 2) ? ' class="hidden"' : ''?>>
Expand Down Expand Up @@ -186,4 +187,12 @@
</div>
</form>
</div>
<?php if(isset($iniName) && isset($generatedIni)) { ?>
<div id="setup-step-4"<?php echo ($step != 4) ? ' class="hidden"' : ''?>>
<h2>Configuration</h2>
<p>Copy and paste the details below into a file named <code><?php $this->utility->safe($iniName); ?></code> in the folder <code><?php $this->utility->safe($generatedDir); ?></code> (you may have to create this folder)</p>
<textarea cols="80" rows="65"><?php $this->utility->safe($generatedIni) ?></textarea>
<p>Once the configuration is in place, <a href="/">you're done!</a>.</p>
</div>
<?php } ?>
</div>

0 comments on commit f1f9673

Please sign in to comment.