scratch – Diff between revs 103 and 125
?pathlinks?
Rev 103 | Rev 125 | |||
---|---|---|---|---|
Line 84... | Line 84... | |||
84 | } |
84 | } |
|
Line 85... | Line 85... | |||
85 | |
85 | |
|
86 | #### Store the file. |
86 | #### Store the file. |
|
Line -... | Line 87... | |||
- | 87 | $timestamp = atomized_put_contents($userPath.'.'.$fileExtension, $data); |
||
- | 88 | |
||
- | 89 | ### Process any sent tags. |
||
- | 90 | if(isset($_POST['tags'])) { |
||
- | 91 | $tags = json_decode( |
||
- | 92 | stripslashes( |
||
- | 93 | $_POST['tags'] |
||
- | 94 | ) |
||
- | 95 | ); |
||
- | 96 | |
||
- | 97 | ## If we have any tags then insert them into the database. |
||
- | 98 | if(!empty($tags)) { |
||
- | 99 | try { |
||
- | 100 | ## Connect or create the scratch database. |
||
- | 101 | $db = new PDO('sqlite:db/scratch.sqlite3'); |
||
- | 102 | ## Set the error mode to exceptions. |
||
- | 103 | $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
||
- | 104 | |
||
- | 105 | ## Begin the transaction |
||
- | 106 | $db->beginTransaction(); |
||
- | 107 | |
||
- | 108 | ## Create the tags table if it does not exist. |
||
- | 109 | $db->query('CREATE TABLE IF NOT EXISTS "tags" ("hash" text NOT NULL COLLATE NOCASE, "tag" text COLLATE NOCASE)'); |
||
- | 110 | |
||
- | 111 | ## Insert all the tags for the file. |
||
- | 112 | foreach($tags as $tag) { |
||
- | 113 | $q = $db->prepare("INSERT INTO tags(hash, tag) VALUES(:hash, :tag)"); |
||
- | 114 | $q->execute( |
||
- | 115 | array( |
||
- | 116 | ':hash' => $file, |
||
- | 117 | ':name' => $tag |
||
- | 118 | ) |
||
- | 119 | ); |
||
- | 120 | } |
||
- | 121 | |
||
- | 122 | ## Commit the transaction. |
||
- | 123 | $db->commit(); |
||
- | 124 | } catch (Exception $e) { |
||
- | 125 | ## Rollback. |
||
- | 126 | $db->rollback(); |
||
- | 127 | } |
||
- | 128 | } |
||
87 | $timestamp = atomized_put_contents($userPath.'.'.$fileExtension, $data); |
129 | } |
|
88 | |
130 | |
|
89 | ### Hook for various file extensions. |
131 | ### Hook for various file extensions. |
|
90 | $opengraph = FALSE; |
132 | $opengraph = FALSE; |
|
91 | switch(strtoupper($fileExtension)) { |
133 | switch(strtoupper($fileExtension)) { |