本文整理汇总了PHP中SPRequest::now方法的典型用法代码示例。如果您正苦于以下问题:PHP SPRequest::now方法的具体用法?PHP SPRequest::now怎么用?PHP SPRequest::now使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SPRequest
的用法示例。
在下文中一共展示了SPRequest::now方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: storeData
/**
* @param $entry
* @param $request
* @param $files
* @return SPdb
* @throws SPException
*/
protected function storeData(&$entry, $request, $files)
{
/* @var SPdb $db */
$db =& SPFactory::db();
$this->verify($entry, $request);
$time = SPRequest::now();
$IP = SPRequest::ip('REMOTE_ADDR', 0, 'SERVER');
$uid = Sobi::My('id');
/* if we are here, we can save these data */
/* collect the needed params */
$save = count($files) ? SPConfig::serialize($files) : null;
$params = array();
$params['publishUp'] = $entry->get('publishUp');
$params['publishDown'] = $entry->get('publishDown');
$params['fid'] = $this->fid;
$params['sid'] = $entry->get('id');
$params['section'] = Sobi::Reg('current_section');
$params['lang'] = Sobi::Lang();
$params['enabled'] = $entry->get('state');
$params['baseData'] = $db->escape($save);
$params['approved'] = $entry->get('approved');
$params['confirmed'] = $entry->get('confirmed');
/* if it is the first version, it is new entry */
if ($entry->get('version') == 1) {
$params['createdTime'] = $time;
$params['createdBy'] = $uid;
$params['createdIP'] = $IP;
}
$params['updatedTime'] = $time;
$params['updatedBy'] = $uid;
$params['updatedIP'] = $IP;
$params['copy'] = !$entry->get('approved');
if (Sobi::My('id') == $entry->get('owner')) {
--$this->editLimit;
}
$params['editLimit'] = $this->editLimit;
/* save it */
try {
$db->insertUpdate('spdb_field_data', $params);
return $db;
} catch (SPException $x) {
Sobi::Error($this->name(), SPLang::e('CANNOT_SAVE_FIELDS_DATA_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
return $db;
}
return $db;
}
示例2: saveData
/**
* Gets the data for a field and save it in the database
* @param SPEntry $entry
* @param string $request
* @return bool
*/
public function saveData(&$entry, $request = 'POST')
{
if (!$this->enabled) {
return false;
}
/* @var SPdb $db */
$db = SPFactory::db();
$save = $this->verify($entry, $request);
$time = SPRequest::now();
$IP = SPRequest::ip('REMOTE_ADDR', 0, 'SERVER');
$uid = Sobi::My('id');
/* collect the needed params */
$params = array();
$params['publishUp'] = $entry->get('publishUp');
$params['publishDown'] = $entry->get('publishDown');
$params['fid'] = $this->fid;
$params['sid'] = $entry->get('id');
$params['section'] = Sobi::Reg('current_section');
$params['lang'] = Sobi::Lang();
$params['enabled'] = $entry->get('state');
$params['baseData'] = $db->escape(SPConfig::serialize($save));
$params['approved'] = $entry->get('approved');
$params['confirmed'] = $entry->get('confirmed');
/* if it is the first version, it is new entry */
if ($entry->get('version') == 1) {
$params['createdTime'] = $time;
$params['createdBy'] = $uid;
$params['createdIP'] = $IP;
}
$params['updatedTime'] = $time;
$params['updatedBy'] = $uid;
$params['updatedIP'] = $IP;
$params['copy'] = !$entry->get('approved');
if (Sobi::My('id') == $entry->get('owner')) {
--$this->editLimit;
}
$params['editLimit'] = $this->editLimit;
/* save it */
try {
/* Notices:
* If it was new entry - insert
* If it was an edit and the field wasn't filled before - insert
* If it was an edit and the field was filled before - update
* " ... " and changes are not autopublish it should be insert of the copy .... but
* " ... " if a copy already exist it is update again
* */
$db->insertUpdate('spdb_field_data', $params);
} catch (SPException $x) {
Sobi::Error(__CLASS__, SPLang::e('CANNOT_SAVE_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
}
/* if it wasn't edited in the default language, we have to try to insert it also for def lang */
if (Sobi::Lang() != Sobi::DefLang()) {
$params['lang'] = Sobi::DefLang();
try {
$db->insert('spdb_field_data', $params, true, true);
} catch (SPException $x) {
Sobi::Error(__CLASS__, SPLang::e('CANNOT_SAVE_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
}
}
}
示例3: saveData
/**
* Gets the data for a field and save it in the database
* @param SPEntry $entry
* @param string $request
* @return bool
*/
public function saveData(&$entry, $request = 'POST')
{
if (!$this->enabled) {
return false;
}
$data = $this->fetchData($this->multi ? SPRequest::arr($this->nid, array(), $request) : SPRequest::word($this->nid, null, $request), $request);
$cdata = $this->verify($entry, $request, $data);
$time = SPRequest::now();
$IP = SPRequest::ip('REMOTE_ADDR', 0, 'SERVER');
$uid = Sobi::My('id');
/* @var SPdb $db */
$db =& SPFactory::db();
/* if we are here, we can save these data */
if ($cdata) {
if ($this->dependency) {
return $this->saveDependencyField($entry, $data, $request);
}
$options = array();
$params = array();
$params['publishUp'] = $entry->get('publishUp');
$params['publishDown'] = $entry->get('publishDown');
$params['fid'] = $this->fid;
$params['sid'] = $entry->get('id');
$params['section'] = Sobi::Reg('current_section');
$params['lang'] = Sobi::Lang();
$params['enabled'] = $entry->get('state');
$params['approved'] = $entry->get('approved');
$params['confirmed'] = $entry->get('confirmed');
/* if it is the first version, it is new entry */
if ($entry->get('version') == 1) {
$params['createdTime'] = $time;
$params['createdBy'] = $uid;
$params['createdIP'] = $IP;
}
$params['updatedTime'] = $time;
$params['updatedBy'] = $uid;
$params['updatedIP'] = $IP;
$params['copy'] = 0;
$params['baseData'] = null;
$params['copy'] = (int) (!$entry->get('approved'));
if (Sobi::My('id') == $entry->get('owner')) {
--$this->editLimit;
}
$params['editLimit'] = $this->editLimit;
/* save it */
try {
$db->insertUpdate('spdb_field_data', $params);
} catch (SPException $x) {
Sobi::Error(__CLASS__, SPLang::e('CANNOT_SAVE_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
}
foreach ($data as $selected) {
/* collect the needed params */
$params['baseData'] = strip_tags($db->escape($selected));
$options[] = array('fid' => $this->fid, 'sid' => $entry->get('id'), 'optValue' => $selected, 'copy' => $params['copy'], 'params' => null);
}
/* delete old selected values */
try {
$db->delete('spdb_field_option_selected', array('fid' => $this->fid, 'sid' => $entry->get('id'), 'copy' => $params['copy']));
} catch (SPException $x) {
Sobi::Error(__CLASS__, SPLang::e('CANNOT_DELETE_PREVIOUS_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
}
/* insert new selected value */
try {
$db->insertArray('spdb_field_option_selected', $options);
} catch (SPException $x) {
Sobi::Error(__CLASS__, SPLang::e('CANNOT_SAVE_SELECTED_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
}
} elseif ($entry->get('version') > 1) {
if (!$entry->get('approved')) {
try {
$db->update('spdb_field_option_selected', array('copy' => 1), array('fid' => $this->fid, 'sid' => $entry->get('id')));
} catch (SPException $x) {
Sobi::Error(__CLASS__, SPLang::e('CANNOT_UPDATE_PREVIOUS_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
}
} else {
/* delete old selected values */
try {
$db->delete('spdb_field_option_selected', array('fid' => $this->fid, 'sid' => $entry->get('id')));
} catch (SPException $x) {
Sobi::Error(__CLASS__, SPLang::e('CANNOT_DELETE_PREVIOUS_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
}
}
}
}
示例4: saveData
/**
* Gets the data for a field and save it in the database
* @param SPEntry $entry
* @param string $request
* @return bool
*/
public function saveData(&$entry, $request = 'POST')
{
if (!$this->enabled) {
return false;
}
$data = $this->verify($entry, $request);
$time = SPRequest::now();
$IP = SPRequest::ip('REMOTE_ADDR', 0, 'SERVER');
$uid = Sobi::My('id');
/* if we are here, we can save these data */
/* @var SPdb $db */
$db =& SPFactory::db();
if ($this->allowHtml) {
/* filter data */
if (count($this->allowedAttributes)) {
SPRequest::setAttributesAllowed($this->allowedAttributes);
}
if (count($this->allowedTags)) {
SPRequest::setTagsAllowed($this->allowedTags);
}
$data = SPRequest::string($this->nid, null, $this->allowHtml, $request);
SPRequest::resetFilter();
if (!$this->editor && $this->maxLength && strlen($data) > $this->maxLength) {
$data = substr($data, 0, $this->maxLength);
}
} else {
$data = strip_tags($data);
}
/* collect the needed params */
$params = array();
$params['publishUp'] = $entry->get('publishUp');
$params['publishDown'] = $entry->get('publishDown');
$params['fid'] = $this->fid;
$params['sid'] = $entry->get('id');
$params['section'] = Sobi::Reg('current_section');
$params['lang'] = Sobi::Lang();
$params['enabled'] = $entry->get('state');
$params['params'] = null;
$params['options'] = null;
$params['baseData'] = $data;
$params['approved'] = $entry->get('approved');
$params['confirmed'] = $entry->get('confirmed');
/* if it is the first version, it is new entry */
if ($entry->get('version') == 1) {
$params['createdTime'] = $time;
$params['createdBy'] = $uid;
$params['createdIP'] = $IP;
}
$params['updatedTime'] = $time;
$params['updatedBy'] = $uid;
$params['updatedIP'] = $IP;
$params['copy'] = !$entry->get('approved');
if (Sobi::My('id') == $entry->get('owner')) {
--$this->editLimit;
}
$params['editLimit'] = $this->editLimit;
/* save it */
try {
$db->insertUpdate('spdb_field_data', $params);
} catch (SPException $x) {
Sobi::Error(__CLASS__, SPLang::e('CANNOT_SAVE_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
}
/* if it wasn't edited in the default language, we have to try to insert it also for def lang */
if (Sobi::Lang() != Sobi::DefLang()) {
$params['lang'] = Sobi::DefLang();
try {
$db->insert('spdb_field_data', $params, true, true);
} catch (SPException $x) {
Sobi::Error(__CLASS__, SPLang::e('CANNOT_SAVE_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
}
}
}
示例5: saveData
/**
* Gets the data for a field and save it in the database
* @param SPEntry $entry
* @param string $request
* @throws SPException
* @return bool
*/
public function saveData(&$entry, $request = 'POST')
{
if (!$this->enabled) {
return false;
}
if ($this->method == 'fixed') {
$fixed = $this->fixedCid;
$fixed = explode(',', $fixed);
$data = array();
if (count($fixed)) {
foreach ($fixed as $cid) {
$data[] = trim($cid);
}
}
if (!count($data)) {
throw new SPException(SPLang::e('FIELD_CC_FIXED_CID_NOT_SELECTED', $this->name));
}
} else {
$data = $this->verify($entry, $request);
}
$time = SPRequest::now();
$IP = SPRequest::ip('REMOTE_ADDR', 0, 'SERVER');
$uid = Sobi::My('id');
/* if we are here, we can save these data */
/* @var SPdb $db */
$db = SPFactory::db();
/* collect the needed params */
$params = array();
$params['publishUp'] = $entry->get('publishUp');
$params['publishDown'] = $entry->get('publishDown');
$params['fid'] = $this->fid;
$params['sid'] = $entry->get('id');
$params['section'] = Sobi::Reg('current_section');
$params['lang'] = Sobi::Lang();
$params['enabled'] = $entry->get('state');
$params['params'] = null;
$params['options'] = null;
$params['baseData'] = SPConfig::serialize($data);
$params['approved'] = $entry->get('approved');
$params['confirmed'] = $entry->get('confirmed');
/* if it is the first version, it is new entry */
if ($entry->get('version') == 1) {
$params['createdTime'] = $time;
$params['createdBy'] = $uid;
$params['createdIP'] = $IP;
}
$params['updatedTime'] = $time;
$params['updatedBy'] = $uid;
$params['updatedIP'] = $IP;
$params['copy'] = !$entry->get('approved');
if (Sobi::My('id') == $entry->get('owner')) {
--$this->editLimit;
}
$params['editLimit'] = $this->editLimit;
/* save it */
try {
/* Notices:
* If it was new entry - insert
* If it was an edit and the field wasn't filled before - insert
* If it was an edit and the field was filled before - update
* " ... " and changes are not autopublish it should be insert of the copy .... but
* " ... " if a copy already exist it is update again
* */
$db->insertUpdate('spdb_field_data', $params);
} catch (SPException $x) {
Sobi::Error(__CLASS__, SPLang::e('CANNOT_SAVE_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
}
/* if it wasn't edited in the default language, we have to try to insert it also for def lang */
if (Sobi::Lang() != Sobi::DefLang()) {
$params['lang'] = Sobi::DefLang();
try {
$db->insert('spdb_field_data', $params, true, true);
} catch (SPException $x) {
Sobi::Error(__CLASS__, SPLang::e('CANNOT_SAVE_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
}
}
/** Last important thing - join selected categories */
$cats = SPFactory::registry()->get('request_categories', array());
$cats = array_unique(array_merge($cats, $data));
SPFactory::registry()->set('request_categories', $cats);
if ($this->method == 'select' && $this->isPrimary) {
$db->update('spdb_object', array('parent' => $data[0]), array('id' => $params['sid']));
}
}
示例6: save
/**
*/
public function save($request = 'post')
{
$this->version++;
/* get current data */
$this->updatedTime = SPRequest::now();
$this->updaterIP = SPRequest::ip('REMOTE_ADDR', 0, 'SERVER');
$this->updater = Sobi::My('id');
$this->nid = SPLang::nid($this->nid, true);
if (!$this->nid) {
$this->nid = SPLang::nid($this->name, true);
}
/* get THIS class properties */
$properties = get_class_vars(__CLASS__);
/* if new object */
if (!$this->id) {
/** @var the notification App is using it to recognise if it is a new entry or an update */
$this->createdTime = $this->updatedTime;
$this->owner = $this->owner ? $this->owner : $this->updater;
$this->ownerIP = $this->updaterIP;
} else {
/** Fri, Dec 19, 2014 19:33:52
* When storing it we should actually get already UTC unix time stamp
* so there is not need to remove it again
*/
// $this->createdTime = $this->createdTime && is_numeric( $this->createdTime ) ? gmdate( Sobi::Cfg( 'db.date_format', 'Y-m-d H:i:s' ), $this->createdTime - SPFactory::config()->getTimeOffset() ) : $this->createdTime;
$this->createdTime = $this->createdTime && is_numeric($this->createdTime) ? gmdate(Sobi::Cfg('db.date_format', 'Y-m-d H:i:s'), $this->createdTime) : $this->createdTime;
$obj = SPFactory::object($this->id);
if ($obj->oType != $this->oType) {
Sobi::Error('Object Save', sprintf('Serious security violation. Trying to save an object which claims to be an %s but it is a %s. Task was %s', $this->oType, $obj->oType, SPRequest::task()), SPC::ERROR, 403, __LINE__, __FILE__);
exit;
}
}
if (is_numeric($this->validUntil)) {
// $this->validUntil = $this->validUntil ? gmdate( Sobi::Cfg( 'db.date_format', 'Y-m-d H:i:s' ), $this->validUntil - SPFactory::config()->getTimeOffset() ) : null;
$this->validUntil = $this->validUntil ? gmdate(Sobi::Cfg('db.date_format', 'Y-m-d H:i:s'), $this->validUntil) : null;
}
if (is_numeric($this->validSince)) {
$this->validSince = $this->validSince ? gmdate(Sobi::Cfg('db.date_format', 'Y-m-d H:i:s'), $this->validSince) : null;
}
/* @var SPdb $db */
$db = SPFactory::db();
$db->transaction();
/* get database columns and their ordering */
$cols = $db->getColumns('spdb_object');
$values = array();
/*
* @todo: manage own is not implemented yet
*/
//$this->approved = Sobi::Can( $this->type(), 'manage', 'own' );
/* if not published, check if user can manage own and if yes, publish it */
if (!$this->state && !defined('SOBIPRO_ADM')) {
$this->state = Sobi::Can($this->type(), 'publish', 'own');
}
if (!defined('SOBIPRO_ADM')) {
$this->approved = Sobi::Can($this->type(), 'publish', 'own');
}
// elseif ( defined( 'SOBIPRO_ADM' ) ) {
// $this->approved = Sobi::Can( $this->type(), 'publish', 'own' );
// }
/* and sort the properties in the same order */
foreach ($cols as $col) {
$values[$col] = array_key_exists($col, $properties) ? $this->{$col} : '';
}
/* trigger plugins */
Sobi::Trigger('save', $this->name(), array(&$this));
/* try to save */
try {
/* if new object */
if (!$this->id) {
$db->insert('spdb_object', $values);
$this->id = $db->insertid();
} else {
$db->update('spdb_object', $values, array('id' => $this->id));
}
} catch (SPException $x) {
$db->rollback();
Sobi::Error($this->name(), SPLang::e('CANNOT_SAVE_OBJECT_DB_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
}
/* get translatable properties */
$attributes = array_merge($this->translatable(), self::$translatable);
$labels = array();
$defLabels = array();
foreach ($attributes as $attr) {
if ($this->has($attr)) {
$labels[] = array('sKey' => $attr, 'sValue' => $this->{$attr}, 'language' => Sobi::Lang(), 'id' => $this->id, 'oType' => $this->type(), 'fid' => 0);
if (Sobi::Lang() != Sobi::DefLang()) {
$defLabels[] = array('sKey' => $attr, 'sValue' => $this->{$attr}, 'language' => Sobi::DefLang(), 'id' => $this->id, 'oType' => $this->type(), 'fid' => 0);
}
}
}
/* save translatable properties */
if (count($labels)) {
try {
if (Sobi::Lang() != Sobi::DefLang()) {
$db->insertArray('spdb_language', $defLabels, false, true);
}
$db->insertArray('spdb_language', $labels, true);
} catch (SPException $x) {
//.........这里部分代码省略.........
示例7: saveData
//.........这里部分代码省略.........
$files['data']['exif'] = $orgImage->exif();
$this->cleanExif($files['data']['exif']);
if (Sobi::Cfg('image_field.fix_rotation', true)) {
if ($orgImage->fixRotation()) {
$orgImage->save();
}
}
if ($this->resize) {
$image = clone $orgImage;
try {
$image->resample($this->resizeWidth, $this->resizeHeight, false);
$files['image'] = $this->parseName($entry, $orgName, $this->imageName, true);
$image->saveAs($path . $files['image']);
} catch (SPException $x) {
Sobi::Error($this->name(), SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
$image->delete();
throw new SPException(SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()));
}
}
if ($this->generateThumb) {
$thumb = clone $orgImage;
try {
$thumb->resample($this->thumbWidth, $this->thumbHeight, false);
$files['thumb'] = $this->parseName($entry, $orgName, $this->thumbName, true);
$thumb->saveAs($path . $files['thumb']);
} catch (SPException $x) {
Sobi::Error($this->name(), SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
$thumb->delete();
throw new SPException(SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()));
}
}
$ico = clone $orgImage;
try {
$icoSize = explode(':', Sobi::Cfg('image.ico_size', '80:80'));
$ico->resample($icoSize[0], $icoSize[1], false);
$files['ico'] = $this->parseName($entry, strtolower($orgName), 'ico_{orgname}', true);
$ico->saveAs($path . $files['ico']);
} catch (SPException $x) {
Sobi::Error($this->name(), SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
$ico->delete();
throw new SPException(SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()));
}
if (!$this->keepOrg) {
$orgImage->delete();
} else {
$files['original'] = $this->parseName($entry, $orgName, '{orgname}', true);
}
foreach ($files as $i => $file) {
if ($i == 'data') {
continue;
}
$files[$i] = $sPath . $file;
}
} elseif ($del) {
$this->delImgs();
$files = array();
} else {
return true;
}
/* @var SPdb $db */
$db =& SPFactory::db();
$this->verify($entry, $request);
$time = SPRequest::now();
$IP = SPRequest::ip('REMOTE_ADDR', 0, 'SERVER');
$uid = Sobi::My('id');
/* if we are here, we can save these data */
/* collect the needed params */
$save = count($files) ? SPConfig::serialize($files) : null;
$params = array();
$params['publishUp'] = $entry->get('publishUp');
$params['publishDown'] = $entry->get('publishDown');
$params['fid'] = $this->fid;
$params['sid'] = $entry->get('id');
$params['section'] = Sobi::Reg('current_section');
$params['lang'] = Sobi::Lang();
$params['enabled'] = $entry->get('state');
$params['baseData'] = $db->escape($save);
$params['approved'] = $entry->get('approved');
$params['confirmed'] = $entry->get('confirmed');
/* if it is the first version, it is new entry */
if ($entry->get('version') == 1) {
$params['createdTime'] = $time;
$params['createdBy'] = $uid;
$params['createdIP'] = $IP;
}
$params['updatedTime'] = $time;
$params['updatedBy'] = $uid;
$params['updatedIP'] = $IP;
$params['copy'] = !$entry->get('approved');
if (Sobi::My('id') == $entry->get('owner')) {
--$this->editLimit;
}
$params['editLimit'] = $this->editLimit;
/* save it */
try {
$db->insertUpdate('spdb_field_data', $params);
} catch (SPException $x) {
Sobi::Error($this->name(), SPLang::e('CANNOT_SAVE_FIELDS_DATA_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
}
}