-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a11007f
commit 2e90cb6
Showing
3 changed files
with
87 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| All Emoncms code is released under the GNU Affero General Public License. | ||
| See COPYRIGHT.txt and LICENSE.txt. | ||
| --------------------------------------------------------------------- | ||
| Emoncms - open source energy visualisation | ||
| Part of the OpenEnergyMonitor project: | ||
| http://openenergymonitor.org | ||
| */ | ||
|
|
||
| // no direct access | ||
| defined('EMONCMS_EXEC') or die('Restricted access'); | ||
|
|
||
| class PostProcess | ||
| { | ||
| private $mysqli; | ||
|
|
||
| public function __construct($mysqli) | ||
| { | ||
| $this->mysqli = $mysqli; | ||
| } | ||
|
|
||
| public function set($userid,$data) | ||
| { | ||
| $userid = (int) $userid; | ||
| // $data = preg_replace('/[^\w\s-.",:#{}\[\]]/','',$data); | ||
| $data = json_encode($data); | ||
|
|
||
| if ($this->get($userid)===false) { | ||
| $stmt = $this->mysqli->prepare("INSERT INTO postprocess ( userid, data ) VALUES (?,?)"); | ||
| $stmt->bind_param("is", $userid, $data); | ||
| if ($stmt->execute()) return true; | ||
| } else { | ||
| $stmt = $this->mysqli->prepare("UPDATE postprocess SET `data`=? WHERE userid=?"); | ||
| $stmt->bind_param("si", $data, $userid); | ||
| if ($stmt->execute()) return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public function get($userid) | ||
| { | ||
| $userid = (int) $userid; | ||
| $result = $this->mysqli->query("SELECT data FROM postprocess WHERE `userid`='$userid'"); | ||
| if ($result->num_rows > 0) { | ||
| if ($row = $result->fetch_object()) { | ||
| $data = json_decode($row->data); | ||
| if (!$data || $data==null) $data = array(); | ||
| return $data; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <?php | ||
|
|
||
| $schema['postprocess'] = array( | ||
| 'userid' => array('type' => 'int(11)'), | ||
| 'data' => array('type' => 'text') | ||
| ); |