public function update($nodeid, $data) { // parse options array if (isset($data['options'])) { if (is_array($data['options'])) { $data['options'] = $this->buildChannelOptions($nodeid, $data['options']); } else { // should we accept raw ints as updates? unset($data['options']); } } $success = parent::update($nodeid, $data); // Update page title for the channel if (!empty($data['title'])) { $existingRouteId = (int) vB::getDbAssertor()->getField('vBForum:node', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, vB_dB_Query::COLUMNS_KEY => array('routeid'), vB_dB_Query::CONDITIONS_KEY => array(array('field' => 'nodeid', 'value' => $nodeid, 'operator' => vB_dB_Query::OPERATOR_EQ)))); if ($existingRouteId > 0) { $existingPage = vB::getDbAssertor()->getRow('page', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, vB_dB_Query::CONDITIONS_KEY => array(array('field' => 'routeid', 'value' => $existingRouteId, 'operator' => vB_dB_Query::OPERATOR_EQ)))); vB::getDbAssertor()->update('page', array('title' => $data['title']), array('pageid' => $existingPage['pageid'])); vB::getDbAssertor()->update('page', array('title' => $data['title']), array('parentid' => $existingPage['pageid'])); // Update title phrase $phraseLib = vB_Library::instance('phrase'); $guidforphrase = vB_Library::instance('phrase')->cleanGuidForPhrase($existingPage['guid']); $phraseLib->save('pagemeta', 'page_' . $guidforphrase . '_title', array('text' => array($data['title']), 'product' => $existingPage['product'], 'oldvarname' => 'page_' . $guidforphrase . '_title', 'oldfieldname' => 'global', 'skipdebug' => 1)); if (isset($data['description'])) { $phraseLib->save('pagemeta', 'page_' . $guidforphrase . '_metadesc', array('text' => array($data['description']), 'product' => $existingPage['product'], 'oldvarname' => 'page_' . $guidforphrase . '_metadesc', 'oldfieldname' => 'global', 'skipdebug' => 1)); } } } vB_Cache::instance()->event('vB_ChannelStructure_chg'); vB::getUserContext()->rebuildGroupAccess(); vB_Channel::rebuildChannelTypes(); return $success; }
public function update($nodeid, $data) { $existing = $this->assertor->getRow('vBForum:attach', array('nodeid' => $nodeid)); $existingNode = $this->nodeApi->getNode($nodeid); //todo -- lock the caption to the description until we collapse the fields. Remove when caption goes away if (isset($data['caption'])) { $data['description'] = $data['caption']; } else { if (isset($data['description'])) { $data['caption'] = $data['description']; } } if (parent::update($nodeid, $data)) { //We need to update the filedata ref counts if (!empty($data['filedataid']) and $existing['filedataid'] != $data['filedataid']) { //Remove the existing $filedata = vB::getDbAssertor()->getRow('filedata', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'filedataid' => $existing['filedataid'])); if ($filedata['refcount'] > 1) { $params = array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_UPDATE, 'filedataid' => $existing['filedataid'], 'refcount' => $filedata['refcount'] - 1); } else { $params = array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_DELETE, 'filedataid' => $existing['filedataid']); $this->assertor->assertQuery('vBForum:filedataresize', $params); } $this->assertor->assertQuery('filedata', $params); //add the new $filedata = vB::getDbAssertor()->getRow('filedata', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'filedataid' => $data['filedataid'])); if (!empty($filedata) and empty($filedata['errors'])) { $params = array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_UPDATE, 'filedataid' => $data['filedataid'], 'refcount' => $filedata['refcount'] + 1); $this->assertor->assertQuery('filedata', $params); } } } $nodesToClear = array($nodeid, $existingNode['parentid']); if (isset($data['parentid']) and $data['parentid'] != $existingNode['parentid']) { $nodesToClear[] = $data['parentid']; } $this->nodeApi->clearCacheEvents($nodesToClear); }
/** * Updates a text node. * * @param int The node ID for the node that is being updated * @param array Array of flags and new data for this node. * DATA: This array can contain new values for any of the fields * in the node table, and any of the fields in any of the extended * tables for the content type for this node (see the $tablename property). * FLAGS: This array may also contain flags that affect behavior, but are * not part of the data saved to the tables. Flags: (may not be a complete list) * * nl2br - if true, converts any new lines in rawtext to <br /> * @param bool Flag instructing us to convert rawtext from WYSIWYG editor markup to BBCode. * * @return boolean */ public function update($nodeid, $data, $convertWysiwygTextToBbcode = true) { // html permission already checked in the api if (isset($data['htmlstate']) and $data['htmlstate'] == 'on' and isset($data['disable_bbcode']) and $data['disable_bbcode'] == 1) { // article 'static html' type $convertWysiwygTextToBbcode = false; if (isset($data['nl2br'])) { $data['nl2br'] = false; } } $node = $this->assertor->getRow('vBForum:node', array('nodeid' => $nodeid)); //We may need to update the "last" counts. if (isset($data['publishdate']) or isset($data['unpublishdate']) or isset($data['showpublished'])) { $updates = array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_STORED, 'lastauthorid' => $node['userid'], 'nodeid' => $nodeid); if (!isset($data['publishdate'])) { $updates['lastcontent'] = $node['publishdate']; } else { $updates['lastcontent'] = $data['publishdate']; } if (empty($data['lastcontentauthor'])) { $updates['lastcontentauthor'] = $node['authorname']; } else { $updates['lastcontentauthor'] = $data['authorname']; } if (empty($data['lastauthorid'])) { $updates['lastauthorid'] = $node['userid']; } } if (isset($data['rawtext']) and !empty($data['rawtext'])) { // Needed for converting new lines for the mobile app VBV-9886 // Also converts new lines for the web app, when CKEditor is not in use (plain text area) VBV-11279 if (isset($data['nl2br']) and $data['nl2br']) { $data['rawtext'] = nl2br($data['rawtext']); } if ($convertWysiwygTextToBbcode) { $parents = vB_Library::instance('node')->getParents($node['parentid']); $parents = array_reverse($parents); $channelType = vB_Types::instance()->getContentTypeId('vBForum_Channel'); // check if we can autoparselinks $options['autoparselinks'] = true; foreach ($parents as $parent) { // currently only groups and blogs seem to disallow this if (($parent['contenttypeid'] == $channelType and vB_Api::instanceInternal('socialgroup')->isSGNode($parent['nodeid']) or vB_Api::instanceInternal('blog')->isBlogNode($parent['nodeid'])) and $channelOptions = vB_Library::instance('node')->getNodeOptions($parent['nodeid'])) { $options['autoparselinks'] = $channelOptions['autoparselinks']; } } $data['rawtext'] = vB_Api::instanceInternal('bbcode')->convertWysiwygTextToBbcode($data['rawtext'], $options); if (empty($data['description'])) { $data['description'] = vB_String::getPreviewText($this->parseAndStrip($data['rawtext']), 155); } else { $data['description'] = vB_String::getPreviewText($this->parseAndStrip($data['description'])); } } if (!isset($data['pagetext'])) { $data['pagetext'] = ''; } if (!isset($data['previewtext'])) { $data['previewtext'] = ''; } //Set the "hasvideo" value; $filter = '~\\[video.*\\[\\/video~i'; $matches = array(); $count = preg_match_all($filter, $data['rawtext'], $matches); if ($count > 0) { $data['hasvideo'] = 1; } else { $data['hasvideo'] = 0; } } else { if (empty($data['description'])) { // when editing, and title & text have not changed, rawtext, title, and description can all be empty if (!empty($data['title'])) { $data['description'] = vB_String::getPreviewText($this->parseAndStrip($data['title'])); } } else { $data['description'] = vB_String::getPreviewText($this->parseAndStrip($data['description'])); } } $published = $this->isPublished($data); // TODO: It appears that parent::update does not accept/use a third parameter? $result = parent::update($nodeid, $data, $published); if (isset($node) and $published != $node['showpublished']) { //We don't need to update the counts- that gets done in the parent class. if ($published) { //we might have loaded this already above, but we don't want to load it //if we don't need it so we can't just pull it out into global space. if (!isset($parents)) { $parents = vB_Library::instance('node')->getParents($node['parentid']); $parents = array_reverse($parents); } $parentids = array(); foreach ($parents as $node) { $parentids[] = $node['nodeid']; } $updates['parentlist'] = $parentids; $updates['lastcontentid'] = $nodeid; $this->assertor->assertQuery('vBForum:setLastDataParentList', $updates); } } $this->nodeApi->clearCacheEvents(array($nodeid, $node['parentid'])); return $result; }