diff options
| author | Christian Weiske <cweiske@cweiske.de> | 2012-04-03 20:15:57 +0200 |
|---|---|---|
| committer | Christian Weiske <cweiske@cweiske.de> | 2012-04-03 20:15:57 +0200 |
| commit | 2b4b34a76f42841e964a549fc64c02ba4f60a3f4 (patch) | |
| tree | c83a973cae8d45e01384dabe4ad33dc40c09a5d1 /src/Phorkie/Repository/Post.php | |
| parent | 7dcd592544ae0b55d0e205ff83631067a0d0aa6b (diff) | |
| download | phorkie-2b4b34a76f42841e964a549fc64c02ba4f60a3f4.tar.gz phorkie-2b4b34a76f42841e964a549fc64c02ba4f60a3f4.zip | |
rename Phorkie to phorkie (lowercase)
Diffstat (limited to 'src/Phorkie/Repository/Post.php')
| -rw-r--r-- | src/Phorkie/Repository/Post.php | 130 |
1 files changed, 0 insertions, 130 deletions
diff --git a/src/Phorkie/Repository/Post.php b/src/Phorkie/Repository/Post.php deleted file mode 100644 index d2cab25..0000000 --- a/src/Phorkie/Repository/Post.php +++ /dev/null @@ -1,130 +0,0 @@ -<?php -namespace Phorkie; - -class Repository_Post -{ - public $repo; - - public function __construct(Repository $repo = null) - { - $this->repo = $repo; - } - - /** - * Processes the POST data, changes description and files - * - * @return boolean True if the post was successful - */ - public function process($postData) - { - if (!isset($postData['files'])) { - return false; - } - - if (!$this->repo) { - $this->repo = $this->createRepo(); - } - - $vc = $this->repo->getVc(); - $this->repo->setDescription($postData['description']); - - $bChanged = false; - foreach ($postData['files'] as $arFile) { - if ($arFile['content'] == '' && $arFile['name'] == '') { - //empty (new) file - continue; - } - - $orignalName = $this->sanitizeFilename($arFile['original_name']); - $name = $this->sanitizeFilename($arFile['name']); - - if ($name == '') { - $name = $this->getNextNumberedFile('phork') - . '.' . $arFile['type']; - } - - $bNew = false; - if (!isset($orignalName) || $orignalName == '') { - //new file - $bNew = true; - } else if (!$this->repo->hasFile($orignalName)) { - //unknown file - //FIXME: Show error message - continue; - } else if ($orignalName != $name) { - //FIXME: what to do with overwrites? - $vc->getCommand('mv') - ->addArgument($orignalName) - ->addArgument($name) - ->execute(); - $bChanged = true; - } - - $file = $this->repo->getFileByName($name, false); - if ($bNew || $file->getContent() != $arFile['content']) { - file_put_contents($file->getPath(), $arFile['content']); - $command = $vc->getCommand('add') - ->addArgument($file->getFilename()) - ->execute(); - $bChanged = true; - } - } - - if ($bChanged) { - $vc->getCommand('commit') - ->setOption('message', '') - ->setOption('allow-empty-message') - ->setOption('author', 'Anonymous <anonymous@phorkie>') - ->execute(); - } - - return true; - } - - public function createRepo() - { - $rs = new Repositories(); - $repo = $rs->createNew(); - $vc = $repo->getVc(); - $vc->initRepository(); - foreach (glob($repo->repoDir . '/.git/hooks/*') as $hookfile) { - unlink($hookfile); - } - return $repo; - } - - public function getNextNumberedFile($prefix) - { - $num = -1; - do { - ++$num; - $files = glob($this->repo->repoDir . '/' . $prefix . $num . '.*'); - } while (count($files)); - - return $prefix . $num; - } - - /** - * Removes malicious parts from a file name - * - * @param string $file File name from the user - * - * @return string Fixed and probably secure filename - */ - public function sanitizeFilename($file) - { - $file = trim($file); - $file = str_replace(array('\\', '//'), '/', $file); - $file = str_replace('/../', '/', $file); - if (substr($file, 0, 3) == '../') { - $file = substr($file, 3); - } - if (substr($file, 0, 1) == '../') { - $file = substr($file, 1); - } - - return $file; - } -} - -?> |
