public function updateFromPost(Data_User $user) { if (empty($_REQUEST['name'])) { throw new Exception('You did not type in a name for the foodle.'); } if (empty($_REQUEST['coldef'])) { throw new Exception('Did not get column definition.'); } $this->name = strip_tags($_REQUEST['name']); $this->descr = isset($_REQUEST['descr']) ? $_REQUEST['descr'] : '...'; $this->descr = preg_replace('/\\s(http[^ ]*?)\\s/', '[\\1](\\1)', $this->descr); $this->descr = preg_replace('/<(http[^>]*)>/', '[\\1](\\1)', $this->descr); // $this->descr = strip_tags($this->descr, '<h1><h2><h3><h4><h5><h6><p><a><strong><em><ul><ol><li><dd><dt><dl><hr><img><pre><code>'); $this->descr = strip_tags($this->descr); if (!empty($_REQUEST['maxentries']) && is_numeric($_REQUEST['maxentries'])) { $this->maxentries = strip_tags($_REQUEST['maxentries']); $this->maxcolumn = strip_tags($_REQUEST['maxentriescol']); } else { $this->maxentries = NULL; $this->maxcolumn = NULL; } if (array_key_exists('anon', $_REQUEST) && !empty($_REQUEST['anon'])) { $this->allowanonymous = TRUE; } else { $this->allowanonymous = FALSE; } if (!empty($_REQUEST['settimezone'])) { $this->timezone = $_REQUEST['settimezone']; } if (!empty($_REQUEST['columntype'])) { $this->columntype = $_REQUEST['columntype']; } if (!empty($_REQUEST['responsetype'])) { $this->responsetype = $_REQUEST['responsetype']; } if (!empty($_REQUEST['groups'])) { if ($_REQUEST['groups'] == '-1') { $this->groupid = NULL; } else { $this->groupid = $_REQUEST['groups']; } } $this->extrafields = array(); if (!empty($_REQUEST['extrafields_photo'])) { $this->extrafields[] = 'photo'; } if (!empty($_REQUEST['extrafields_org'])) { $this->extrafields[] = 'org'; } if (!empty($_REQUEST['extrafields_timezone'])) { $this->extrafields[] = 'timezone'; } if (!empty($_REQUEST['extrafields_location'])) { $this->extrafields[] = 'location'; } # echo '<pre>'; print_r($_REQUEST); print_r($this); exit; $this->expire = strip_tags($_REQUEST['expire']); $this->datetime = $this->getDateTimeFromPost(); $this->owner = $user->userid; $this->columns = FoodleUtils::parseOldColDef($_REQUEST['coldef']); if (empty($this->identifier)) { $this->setIdentifier(TRUE); } #echo '<pre>'; print_r($this); print_r($_REQUEST); echo '</pre>'; exit; }
public function readFoodle($id) { Data_Foodle::requireValidIdentifier($id); $sql = "\n\t\t\tSELECT *,\n\t\t\tIF(expire=0,null,UNIX_TIMESTAMP(expire)) AS expire_unix, \n\t\t\tIF(created=0,null,UNIX_TIMESTAMP(created)) AS createdu, \n\t\t\tIF(updated=0,null,UNIX_TIMESTAMP(updated)) AS updatedu \n\t\t\tFROM def WHERE id = '" . mysql_real_escape_string($id) . "'"; try { $row = $this->q1($sql); } catch (Exception $e) { throw new Exception('Could not lookup Foodle with id [' . $id . ']. May be it was deleted?'); } $foodle = new Data_Foodle($this); $foodle->identifier = $id; $foodle->name = $row['name']; $foodle->descr = stripslashes($row['descr']); $foodle->location = json_decode($row['location'], TRUE); $foodle->expire = $row['expire_unix']; $foodle->owner = $row['owner']; $foodle->allowanonymous = (bool) ($row['anon'] == '1'); $foodle->columntype = isset($row['columntype']) ? $row['columntype'] : null; $foodle->responsetype = isset($row['responsetype']) ? $row['responsetype'] : 'default'; $foodle->extrafields = Data_Foodle::decode($row['extrafields']); if (!empty($row['feed'])) { $foodle->feed = $row['feed']; } $foodle->created = $row['createdu']; $foodle->updated = $row['updatedu']; $foodle->datetime = Data_Foodle::decode($row['datetime']); if (!empty($row['timezone'])) { $foodle->timezone = $row['timezone']; } if (!empty($row['groupid'])) { $foodle->groupid = $row['groupid']; } if (self::isJSON($row['columns'][0])) { #echo 'Use new encoding format'; $foodle->columns = json_decode($row['columns'], TRUE); } else { #echo 'Using old decoding.'; $foodle->columns = FoodleUtils::parseOldColDef($row['columns']); } $maxdef = self::parseMaxDef($row['maxdef']); if (isset($row['restrictions'])) { $foodle->restrictions = json_decode($row['restrictions'], TRUE); } else { if ($maxdef[0]) { $foodle->maxentries = $maxdef[0]; $foodle->maxcolumn = $maxdef[1]; if ($foodle->maxcolumn === 0) { $foodle->restrictions = array('rows' => $maxdef[0]); } else { $foodle->restrictions = array('col' => array('col' => $maxdef[1] - 1, 'limit' => $maxdef[0])); } } } $foodle->loadedFromDB = TRUE; return $foodle; }