summaryrefslogtreecommitdiffstats
path: root/lib/functions.stories.inc.php
blob: 8f35e27dc9470b617a7bdf429a3c3122d39f9b6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/*
 * functions.stories.php
 */
 

function visibleName($nameWithUnderscore) {
    //return str_replace('_', ' ', $nameWithUnderscore);
    return urldecode($nameWithUnderscore);
}

function generateDirectoryName($name) {
    return urlencode($name);
}

function saveEntity($path, $description, $file, $filename) {
    // create description file
    if (file_put_contents($path.DIRECTORY_SEPARATOR.'description.txt', $description) === FALSE) {
        // Error on writing description file
    }
    // move uploaded logo
    if (NULL === $file || move_uploaded_file($file['tmp_name'], $path.DIRECTORY_SEPARATOR.$filename) || $file['error'] == UPLOAD_ERR_NO_FILE) {
        return TRUE;
    } else {
        return 3;
    }
}

function editEntity($path, $description, $file, $filename) {
    if (dir_exists($path)) {
        return saveEntity($path, $description, $file, $filename);
    }
}

function createEntity($path, $description, $file, $filename) {
    if (!dir_exists($path)) {
        // create directory for story
        if (mkdir($path)) {
            return saveEntity($path, $description, $file, $filename);
        } else {
            // Error on directory creation
            // return 'Could not create directory "'.$path;
            return 2;
        }
    } else {
        return 1;
    }
}
?>