scratch – Diff between revs 103 and 125

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 103 Rev 125
Line 83... Line 83...
83 die('Internal server error.'); 83 die('Internal server error.');
84 } 84 }
Line 85... Line 85...
85   85  
86 #### Store the file. 86 #### Store the file.
-   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 }
Line 87... Line 129...
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)) {
92 case 'MP4': 134 case 'MP4':
93 case 'GIF': 135 case 'GIF':
94 $opengraph = TRUE; 136 $opengraph = TRUE;
95 break; 137 break;
96 } 138 }
97   139
98 ### Return the URL to the file. 140 ### Return the URL to the file.
99 header('Content-Type: text/plain; charset=utf-8'); 141 header('Content-Type: text/plain; charset=utf-8');
100 echo json_encode( 142 echo json_encode(