/**
  * Loads and parses an XML file into the $this->xml property.
  *
  * @param string The name of the item (page, route, pagetemplate) to load
  */
 protected function loadXmlFile($itemname)
 {
     $filename = "vbulletin-{$itemname}s.xml";
     $xml = vB_Xml_Import::parseFile("{$this->xmldir}/{$filename}");
     $items = array();
     foreach ($xml[$itemname] as $item) {
         $items[$item['guid']] = $item;
     }
     $this->fileVersions[$filename] = $xml['vbversion'];
     return $items;
 }
Example #2
0
 protected function import($onlyGuid = false)
 {
     // get all columns but the key
     $routeTable = $this->db->fetchTableStructure('routenew');
     $routeTableColumns = array_diff($routeTable['structure'], array('arguments', 'contentid', $routeTable['key']));
     if (empty($this->parsedXML['route'])) {
         $this->parsedXML['route'] = array();
     }
     $routes = is_array($this->parsedXML['route'][0]) ? $this->parsedXML['route'] : array($this->parsedXML['route']);
     foreach ($routes as $route) {
         if ($onlyGuid and $onlyGuid != $route['guid']) {
             continue;
         }
         $values = array();
         foreach ($routeTableColumns as $col) {
             if (isset($route[$col])) {
                 $values[$col] = $route[$col];
             }
         }
         if (!isset($route['class'])) {
             $values['class'] = '';
         }
         $condition = array('guid' => $route['guid']);
         $existing = $this->db->getRow('routenew', $condition);
         if ($existing and !empty($existing['routeid'])) {
             //If we have a route with this guid we leave it alone. The customer may have intentionally changed it
             //see VBV-13586.
             $routeid = $existing['routeid'];
         } else {
             $class = (isset($route['class']) and !empty($route['class']) and class_exists($route['class'])) ? $route['class'] : vB5_Route::DEFAULT_CLASS;
             $values['arguments'] = call_user_func_array(array($class, 'importArguments'), array($route['arguments']));
             $values['contentid'] = call_user_func_array(array($class, 'importContentId'), array(unserialize($values['arguments'])));
             $routeid = $this->db->insertIgnore('routenew', $values);
             //We need to make sure the name is unique. Collisions should be very rare but not impossible.
             if (is_array($routeid)) {
                 $routeid = array_pop($routeid);
             }
         }
         vB_Xml_Import::setImportedId(vB_Xml_Import::TYPE_ROUTE, $route['guid'], $routeid);
     }
 }
Example #3
0
 /**
  * Imports objects from the specified filepath
  * @param string $filepath
  * @param string $guid Only import the record associated with this guid
  */
 public function importFromFile($filepath, $guid = false)
 {
     $this->parsedXML = vB_Xml_Import::parseFile($filepath);
     $this->import($guid);
 }
Example #4
0
 protected function import()
 {
     if (empty($this->parsedXML['channel'])) {
         $this->parsedXML['channel'] = array();
     }
     $this->checkRoutes();
     $this->checkParents();
     $channels = is_array($this->parsedXML['channel'][0]) ? $this->parsedXML['channel'] : array($this->parsedXML['channel']);
     //On an upgrade from Pre-vB5 the datastore won't exist yet. So we can't get the bitfields from there.
     $parsedRaw = vB_Xml_Import::parseFile(DIR . '/includes/xml/bitfield_vbulletin.xml');
     $forumpermissions = $forumpermissions2 = $moderatorpermissions = $createpermissions = $adminpermissions = $albumpermissions = $socialgrouppermissions = array();
     foreach ($parsedRaw['bitfielddefs']['group'] as $group) {
         if ($group['name'] == 'ugp') {
             foreach ($group['group'] as $bfgroup) {
                 switch ($bfgroup['name']) {
                     case 'forumpermissions':
                         foreach ($bfgroup['bitfield'] as $bitfield) {
                             $forumpermissions[$bitfield['name']] = intval($bitfield['value']);
                         }
                         break;
                     case 'forumpermissions2':
                         foreach ($bfgroup['bitfield'] as $bitfield) {
                             $forumpermissions2[$bitfield['name']] = intval($bitfield['value']);
                         }
                         break;
                     case 'adminpermissions':
                         foreach ($bfgroup['bitfield'] as $bitfield) {
                             $adminpermissions[$bitfield['name']] = intval($bitfield['value']);
                         }
                         break;
                     case 'albumpermissions':
                         foreach ($bfgroup['bitfield'] as $bitfield) {
                             $albumpermissions[$bitfield['name']] = intval($bitfield['value']);
                         }
                         break;
                     case 'createpermissions':
                         foreach ($bfgroup['bitfield'] as $bitfield) {
                             $createpermissions[$bitfield['name']] = intval($bitfield['value']);
                         }
                         break;
                     case 'socialgrouppermissions':
                         foreach ($bfgroup['bitfield'] as $bitfield) {
                             $socialgrouppermissions[$bitfield['name']] = intval($bitfield['value']);
                         }
                 }
             }
         } else {
             if ($group['name'] == 'misc') {
                 foreach ($group['group'] as $bfgroup) {
                     if ($bfgroup['name'] == 'moderatorpermissions') {
                         foreach ($bfgroup['bitfield'] as $bitfield) {
                             $moderatorpermissions[$bitfield['name']] = intval($bitfield['value']);
                         }
                     }
                 }
             }
         }
     }
     $this->bf_administratorpermissions = $adminpermissions;
     $this->bf_moderatorpermissions = $moderatorpermissions;
     $this->bf_forumpermissions = $forumpermissions;
     $this->bf_forumpermissions2 = $forumpermissions2;
     $this->bf_albumpermissions = $albumpermissions;
     $this->bf_socialgrouppermissions = $socialgrouppermissions;
     $this->contenttypes = $createpermissions;
     $usergroups = vB::getDbAssertor()->assertQuery('usergroup', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT));
     foreach ($usergroups as $usergroup) {
         if ($usergroup['systemgroupid'] == vB_Api_UserGroup::CHANNEL_MEMBER_SYSGROUPID) {
             $blogMemberGroupId = $usergroup['usergroupid'];
         } else {
             if ($usergroup['systemgroupid'] == vB_Api_UserGroup::CHANNEL_MEMBER_SYSGROUPID) {
                 $sgMemberGroupId = $usergroup['usergroupid'];
             } else {
                 if ($usergroup['systemgroupid'] == vB_Api_UserGroup::CHANNEL_OWNER_SYSGROUPID) {
                     $channelOwnerGroupId = $usergroup['usergroupid'];
                 }
             }
         }
     }
     $registeredGroupId = 2;
     $unRegisteredGroupId = 1;
     $rootPerms = $this->buildRootPerms();
     $sgperms = array();
     foreach ($rootPerms as $ug => $value) {
         foreach ($value as $perms => $bitvalue) {
             if ($perms === 'socialgrouppermissions') {
                 $sgperms[$ug]['socialgrouppermissions'] = $bitvalue;
                 unset($rootPerms[$ug]['socialgrouppermissions']);
                 break;
             }
         }
     }
     $channelLib = vB_Library::instance('content_channel');
     $channelPerm = vB_ChannelPermission::instance();
     foreach ($channels as $channel) {
         if (isset($channel['installonly'])) {
             if (defined('VB_AREA') and VB_AREA != 'Install' and $channel['installonly']) {
                 // this channel is only added during install, so skip it
                 continue;
             }
             unset($channel['installonly']);
         }
         $data = array_merge($channel, $channel['node']);
         unset($data['node']);
         if (isset($channel['node']['routeguid']) and isset($this->referencedRoutes[$channel['node']['routeguid']])) {
             $data['routeid'] = $this->referencedRoutes[$channel['node']['routeguid']];
         }
         if (isset($channel['node']['parentguid']) and !empty($channel['node']['parentguid']) and ($parentId = $this->referencedParents[$channel['node']['parentguid']] or $parentId = vB_Xml_Import::getImportedId(vB_Xml_Import::TYPE_CHANNEL, $channel['node']['parentguid']))) {
             $data['parentid'] = $parentId;
         }
         $channelId = 0;
         $condition = array('guid' => $channel['guid']);
         // TODO: after talking with Ed, we decided it might be best not to allow node removal at all. Need to confirm with Kevin
         if ($oldChannel = $this->db->getRow('vBForum:channel', $condition)) {
             $channelId = $oldChannel['nodeid'];
         }
         if (empty($channelId)) {
             // We cannot use the API method for adding the root channel, since it requires a parentid.
             if (!isset($data['parentid'])) {
                 $channelContentTypeId = vB_Api::instanceInternal('contenttype')->fetchContentTypeIdFromClass('Channel');
                 $userId = vB::getCurrentSession()->get('userid');
                 // get all columns but the key
                 $channelTable = $this->db->fetchTableStructure('vbforum:channel');
                 $channelTableColumns = array_diff($channelTable['structure'], array($channelTable['key']));
                 $nodeTable = $this->db->fetchTableStructure('vbforum:node');
                 $nodeTableColumns = array_diff($nodeTable['structure'], array($nodeTable['key'], $channelTable['key']));
                 // insert root node
                 $nodeValues = array('userid' => $userId, 'contenttypeid' => $channelContentTypeId);
                 foreach ($nodeTableColumns as $col) {
                     if (isset($channel['node'][$col])) {
                         $nodeValues[$col] = $channel['node'][$col];
                     }
                 }
                 if (isset($data['routeid'])) {
                     $nodeValues['routeid'] = $data['routeid'];
                 }
                 $channelId = $this->db->insertIgnore('vBForum:node', $nodeValues);
                 if (is_array($channelId)) {
                     $channelId = array_pop($channelId);
                 }
                 // continue only if the node could be inserted
                 if ($channelId) {
                     $values = array();
                     foreach ($channelTableColumns as $col) {
                         if (isset($channel[$col])) {
                             $values[$col] = $channel[$col];
                         }
                     }
                     $values['nodeid'] = $channelId;
                     $this->db->insert('vBForum:channel', $values);
                 }
                 // insert in closure
                 $this->db->insert('vBForum:closure', array('parent' => $channelId, 'child' => $channelId, 'depth' => 0));
                 foreach ($rootPerms as $groupPerm) {
                     $channelPerm->setPermissions($channelId, $groupPerm['groupid'], $groupPerm, true);
                 }
             } else {
                 $response = $channelLib->add($data, array('nodeonly' => true, 'skipFloodCheck' => true, 'skipNotification' => true, 'skipDupCheck' => true));
                 $channelId = $response['nodeid'];
             }
         } else {
             /* Apparently routeid gets changed every update .... */
             if (isset($channel['node']['routeguid']) and isset($this->referencedRoutes[$channel['node']['routeguid']])) {
                 $data['routeid'] = $this->referencedRoutes[$channel['node']['routeguid']];
             }
         }
         if (is_array($channelId)) {
             $channelId = array_pop($channelId);
         }
         /* VBV-2536, $oldChannel check. This is to stop the
         			import blindly resetting permissions on every update */
         if (!$oldChannel and !empty($channelId)) {
             /* We don't know what usergroups exist currently. There may be the groups 1-8 we create on a new install,
             			 or there may not. If a group exists it may have a different meaning from what we create on a new install.
             			So here's what we have decided:
             			1) At root if there is at least one forum permission record:
             				a) you get any permissions you have in any existing root forum.
             				b) If you have "albumpermissions -> canalbum" you can create albums and photos.
             				c) If you have adminpermissions->canadminforums you can create channels.
             				d) If you can forumpermissions->canpostnew you can create all the other types
             			2) If the forumpermissions doesn't exist or is empty, treat this as a new install. Take the permissions
             				from the xml file, taking the id as systemgroupid.
             			3) At root everybody can create private messages.
             			4) 	For the blog and social groups channels, we have newly created usergroups with systemgroupid. Those two channels
             			are specified in the xml file.
             			5) For all other usergroups in those two channels-
             				a) if you have moderator permission canmoderateposts, no record. Just inherit.
             				b) otherwise, get your root permissions plus channel
             			6) For the report channel- if you have moderator permission canmoderateposts anywhere on the site
             				you inherit permissions. Otherwise you have none.
             			*/
             vB_Xml_Import::setImportedId(vB_Xml_Import::TYPE_CHANNEL, $channel['guid'], $channelId);
             switch ($data['guid']) {
                 case vB_Channel::DEFAULT_BLOG_PARENT:
                     foreach ($rootPerms as $groupPerm) {
                         $thisPerm = $groupPerm;
                         if ($groupPerm['createpermissions'] > 0) {
                             $thisPerm['createpermissions'] = $groupPerm['createpermissions'] | $this->contenttypes['vbforum_channel'];
                         }
                         //These four groups should not be able to start threads in the blog and social group channels.
                         if ($groupPerm['groupid'] == $blogMemberGroupId or $groupPerm['groupid'] == $sgMemberGroupId or $groupPerm['groupid'] == $registeredGroupId or $groupPerm['groupid'] == $unRegisteredGroupId) {
                             $thisPerm['forumpermissions'] = $thisPerm['forumpermissions'] & ~$forumpermissions['canpostnew'];
                             // but they should be able to reply to others' threads
                             $thisPerm['forumpermissions'] |= $forumpermissions['canreply'];
                             $thisPerm['createpermissions'] |= $this->contenttypes['vbforum_text'];
                             $thisPerm['forumpermissions2'] |= $forumpermissions2['cancomment'];
                         }
                         //Let the channel owner configure his/her channel
                         if ($groupPerm['groupid'] == $channelOwnerGroupId) {
                             $thisPerm['forumpermissions2'] |= $forumpermissions2['canconfigchannel'] | $forumpermissions2['candeletechannel'];
                             $thisPerm['forumpermissions'] |= $forumpermissions2['canuploadchannelicon'] | $forumpermissions2['candeletechannel'];
                         }
                         $channelPerm->setPermissions($channelId, $groupPerm['groupid'], $thisPerm, true);
                     }
                     break;
                 case vB_Channel::DEFAULT_SOCIALGROUP_PARENT:
                     foreach ($rootPerms as $groupPerm) {
                         $thisPerm = $groupPerm;
                         if ($groupPerm['createpermissions'] > 0) {
                             $thisPerm['createpermissions'] = $groupPerm['createpermissions'] | $this->contenttypes['vbforum_channel'];
                             if ($groupPerm['systemgroupid'] == vB_Api_UserGroup::CHANNEL_OWNER_SYSGROUPID or $groupPerm['systemgroupid'] == vB_Api_UserGroup::CHANNEL_MODERATOR_SYSGROUPID or $groupPerm['systemgroupid'] == vB_Api_UserGroup::CHANNEL_MEMBER_SYSGROUPID or $groupPerm['systemgroupid'] == vB_Api_UserGroup::ADMINISTRATOR or $groupPerm['systemgroupid'] == vB_Api_UserGroup::SUPER_MODERATOR) {
                                 $thisPerm['createpermissions'] |= $this->contenttypes['vbforum_text'];
                                 $thisPerm['createpermissions'] |= $this->contenttypes['vbforum_report'];
                                 //$thisPerm['createpermissions'] |= $this->contenttypes['vbforum_calendar'];
                                 $thisPerm['createpermissions'] |= $this->contenttypes['vbforum_gallery'];
                                 $thisPerm['createpermissions'] |= $this->contenttypes['vbforum_poll'];
                                 $thisPerm['createpermissions'] |= $this->contenttypes['vbforum_attach'];
                                 $thisPerm['createpermissions'] |= $this->contenttypes['vbforum_photo'];
                                 $thisPerm['createpermissions'] |= $this->contenttypes['vbforum_privatemessage'];
                                 $thisPerm['createpermissions'] |= $this->contenttypes['vbforum_video'];
                                 $thisPerm['createpermissions'] |= $this->contenttypes['vbforum_link'];
                             } else {
                                 $thisPerm['createpermissions'] &= ~$this->contenttypes['vbforum_text'];
                                 $thisPerm['createpermissions'] &= ~$this->contenttypes['vbforum_report'];
                                 //$thisPerm['createpermissions'] &= ~$this->contenttypes['vbforum_calendar'];
                                 $thisPerm['createpermissions'] &= ~$this->contenttypes['vbforum_gallery'];
                                 $thisPerm['createpermissions'] &= ~$this->contenttypes['vbforum_poll'];
                                 $thisPerm['createpermissions'] &= ~$this->contenttypes['vbforum_attach'];
                                 $thisPerm['createpermissions'] &= ~$this->contenttypes['vbforum_photo'];
                                 $thisPerm['createpermissions'] &= ~$this->contenttypes['vbforum_privatemessage'];
                                 $thisPerm['createpermissions'] &= ~$this->contenttypes['vbforum_video'];
                                 $thisPerm['createpermissions'] &= ~$this->contenttypes['vbforum_link'];
                             }
                             $rootPerms[$groupPerm['groupid']] = $thisPerm;
                         }
                         //These four groups should not be able to start threads in the blog and social group channels.
                         if ($groupPerm['groupid'] == $blogMemberGroupId or $groupPerm['groupid'] == $sgMemberGroupId or $groupPerm['groupid'] == $registeredGroupId or $groupPerm['groupid'] == $unRegisteredGroupId) {
                             $thisPerm['forumpermissions'] = $thisPerm['forumpermissions'] & ~$forumpermissions['canpostnew'];
                             $thisPerm['forumpermissions2'] |= $forumpermissions2['cancomment'];
                         }
                         //Let the channel owner configure his/her channel
                         if ($groupPerm['groupid'] == $channelOwnerGroupId) {
                             $thisPerm['forumpermissions2'] |= $forumpermissions2['canconfigchannel'] | $forumpermissions2['candeletechannel'];
                         }
                         $channelPerm->setPermissions($channelId, $groupPerm['groupid'], $thisPerm, true);
                     }
                     foreach ($sgperms as $index => $sgperm) {
                         $thisPerm = $rootPerms[$index];
                         if ($sgperm['socialgrouppermissions'] & $this->bf_socialgrouppermissions['cancreategroups']) {
                             $thisPerm['createpermissions'] |= $this->contenttypes['vbforum_channel'];
                         } else {
                             $thisPerm['createpermissions'] &= ~$this->contenttypes['vbforum_channel'];
                         }
                         foreach ($this->bf_forumpermissions as $name => $bitfield) {
                             switch ($name) {
                                 case 'canreply':
                                     if ($sgperm['socialgrouppermissions'] & $this->bf_socialgrouppermissions['canpostmessage']) {
                                         $thisPerm['forumpermissions'] |= $bitfield;
                                         $thisPerm['createpermissions'] |= $this->contenttypes['vbforum_text'];
                                     } else {
                                         $rootPerms[$index]['forumpermissions'] &= ~$bitfield;
                                         $thisPerm['forumpermissions'] &= ~$bitfield;
                                     }
                                     break;
                                 case 'canview':
                                 case 'canviewthreads':
                                 case 'canviewothers':
                                     if ($sgperm['socialgrouppermissions'] & $this->bf_socialgrouppermissions['canviewgroups']) {
                                         $thisPerm['forumpermissions'] |= $bitfield;
                                     } else {
                                         $rootPerms[$index]['forumpermissions'] &= ~$bitfield;
                                         $thisPerm['forumpermissions'] &= ~$bitfield;
                                     }
                                     break;
                                 case 'caneditpost':
                                 case 'candeletepost':
                                     if ($sgperm['socialgrouppermissions'] & $this->bf_socialgrouppermissions['canmanagemessages']) {
                                         $thisPerm['forumpermissions'] |= $bitfield;
                                     } else {
                                         $rootPerms[$index]['forumpermissions'] &= ~$bitfield;
                                         $thisPerm['forumpermissions'] &= ~$bitfield;
                                     }
                                     break;
                                 case 'canpostnew':
                                     if ($sgperm['socialgrouppermissions'] & $this->bf_socialgrouppermissions['cancreatediscussion']) {
                                         $thisPerm['forumpermissions'] |= $bitfield;
                                         $thisPerm['createpermissions'] |= $this->contenttypes['vbforum_text'];
                                     } else {
                                         $rootPerms[$index]['forumpermissions'] &= ~$bitfield;
                                         $thisPerm['forumpermissions'] &= ~$bitfield;
                                     }
                                     break;
                                 case 'canpostattachment':
                                     if ($sgperm['socialgrouppermissions'] & $this->bf_socialgrouppermissions['canupload']) {
                                         $thisPerm['forumpermissions'] |= $bitfield;
                                         $thisPerm['createpermissions'] |= $this->contenttypes['vbforum_photo'];
                                     } else {
                                         $rootPerms[$index]['forumpermissions'] &= ~$bitfield;
                                         $thisPerm['forumpermissions'] &= ~$bitfield;
                                     }
                                     break;
                                 case 'canjoin':
                                     if ($sgperm['socialgrouppermissions'] & $this->bf_socialgrouppermissions['canjoingroups']) {
                                         $thisPerm['forumpermissions'] |= $bitfield;
                                     } else {
                                         $rootPerms[$index]['forumpermissions'] &= ~$bitfield;
                                         $thisPerm['forumpermissions'] &= ~$bitfield;
                                     }
                                     break;
                                 case 'candeletethread':
                                     if ($sgperm['socialgrouppermissions'] & $this->bf_socialgrouppermissions['canmanagediscussions']) {
                                         $thisPerm['forumpermissions'] |= $bitfield;
                                     } else {
                                         $rootPerms[$index]['forumpermissions'] &= ~$bitfield;
                                         $thisPerm['forumpermissions'] &= ~$bitfield;
                                     }
                                     break;
                                 case 'canuploadchannelicon':
                                     if ($sgperm['socialgrouppermissions'] & $this->bf_socialgrouppermissions['canuploadgroupicon']) {
                                         $thisPerm['forumpermissions'] |= $bitfield;
                                     } else {
                                         $rootPerms[$index]['forumpermissions'] &= ~$bitfield;
                                         $thisPerm['forumpermissions'] &= ~$bitfield;
                                     }
                                     break;
                                 case 'cananimatedchannelicon':
                                     if ($sgperm['socialgrouppermissions'] & $this->bf_socialgrouppermissions['cananimategroupicon']) {
                                         $thisPerm['forumpermissions'] |= $bitfield;
                                     } else {
                                         $rootPerms[$index]['forumpermissions'] &= ~$bitfield;
                                         $thisPerm['forumpermissions'] &= ~$bitfield;
                                     }
                                     break;
                                 default:
                             }
                         }
                         foreach ($this->bf_forumpermissions2 as $name => $bitfield) {
                             switch ($name) {
                                 case 'canconfigchannel':
                                     if ($index == vB_Api_UserGroup::CHANNEL_OWNER_SYSGROUPID or $index == vB_Api_UserGroup::ADMINISTRATOR or $index == vB_Api_UserGroup::SUPER_MODERATOR) {
                                         if ($sgperm['socialgrouppermissions'] & $this->bf_socialgrouppermissions['caneditowngroups']) {
                                             $thisPerm['forumpermissions2'] |= $bitfield;
                                         } else {
                                             $rootPerms[$index]['forumpermissions2'] &= ~$bitfield;
                                             $thisPerm['forumpermissions2'] &= ~$bitfield;
                                         }
                                     }
                                     break;
                                 case 'candeletechannel':
                                 case 'canmanageownchannels':
                                     if ($index == vB_Api_UserGroup::CHANNEL_OWNER_SYSGROUPID or $index == vB_Api_UserGroup::ADMINISTRATOR or $index == vB_Api_UserGroup::SUPER_MODERATOR) {
                                         if ($sgperm['socialgrouppermissions'] & $this->bf_socialgrouppermissions['canmanageowngroups']) {
                                             $thisPerm['forumpermissions2'] |= $bitfield;
                                         } else {
                                             $rootPerms[$index]['forumpermissions2'] &= ~$bitfield;
                                             $thisPerm['forumpermissions2'] &= ~$bitfield;
                                         }
                                     }
                                     break;
                                 default:
                             }
                         }
                         $channelPerm->setPermissions($channelId, $index, $thisPerm, true);
                     }
                     break;
                 case vB_Channel::REPORT_CHANNEL:
                     foreach ($rootPerms as $groupPerm) {
                         if ($groupPerm['adminpermissions'] > 0) {
                             $channelPerm->setPermissions($channelId, $groupPerm['groupid'], $groupPerm, true);
                         } elseif ($groupPerm['systemgroupid'] == vB_Api_UserGroup::MODERATOR) {
                             // Moderators group do not have any admin permissions by default, but they should at least
                             // be able to view reports - VBV-7955
                             $modPerms = $this->fetchEmptyPermissions();
                             $modPerms['forumpermissions'] |= $forumpermissions['canview'] | $forumpermissions['canviewthreads'] | $forumpermissions['canviewothers'];
                             $channelPerm->setPermissions($channelId, $groupPerm['groupid'], $modPerms, true);
                         } else {
                             $channelPerm->setPermissions($channelId, $groupPerm['groupid'], $this->fetchEmptyPermissions(), true);
                         }
                     }
                     break;
                 case vB_Channel::INFRACTION_CHANNEL:
                     foreach ($rootPerms as $groupPerm) {
                         if ($groupPerm['adminpermissions'] > 0) {
                             $channelPerm->setPermissions($channelId, $groupPerm['groupid'], $groupPerm, true);
                         } elseif ($groupPerm['systemgroupid'] == vB_Api_UserGroup::MODERATOR) {
                             // Moderators group do not have any admin permissions by default, but they should at least
                             // be able to view reports - VBV-7955
                             $modPerms = $this->fetchEmptyPermissions();
                             $modPerms['forumpermissions'] |= $forumpermissions['canview'] | $forumpermissions['canviewthreads'] | $forumpermissions['canviewothers'];
                             $channelPerm->setPermissions($channelId, $groupPerm['groupid'], $modPerms, true);
                         } else {
                             $channelPerm->setPermissions($channelId, $groupPerm['groupid'], $this->fetchEmptyPermissions(), true);
                         }
                     }
                     break;
                 case vB_Channel::DEFAULT_ARTICLE_PARENT:
                     foreach ($rootPerms as $groupPerm) {
                         unset($groupPerm['permissionid']);
                         if ($groupPerm['systemgroupid'] == vB_Api_UserGroup::ADMINISTRATOR) {
                             $groupPerm['createpermissions'] |= $this->contenttypes['vbforum_text'] | $this->contenttypes['vbforum_gallery'] | $this->contenttypes['vbforum_poll'] | $this->contenttypes['vbforum_attach'] | $this->contenttypes['vbforum_photo'] | $this->contenttypes['vbforum_video'] | $this->contenttypes['vbforum_link'];
                             $groupPerm['forumpermissions2'] |= $this->bf_forumpermissions2['canalwaysview'];
                             $groupPerm['forumpermissions'] |= $this->bf_forumpermissions['canpostnew'];
                             $groupPerm['edit_time'] = 24 * 365;
                             $groupPerm['bf_forumpermissions2'] |= $this->bf_forumpermissions2['canpublish'];
                             $channelPerm->setPermissions($channelId, $groupPerm['groupid'], $groupPerm, true);
                         } else {
                             if ($groupPerm['systemgroupid'] != vB_Api_UserGroup::BANNED and $groupPerm['systemgroupid'] != vB_Api_UserGroup::UNREGISTERED_SYSGROUPID) {
                                 $groupPerm['createpermissions'] = $this->contenttypes['vbforum_text'] | $this->contenttypes['vbforum_gallery'] | $this->contenttypes['vbforum_poll'] | $this->contenttypes['vbforum_attach'] | $this->contenttypes['vbforum_photo'] | $this->contenttypes['vbforum_video'];
                                 $groupPerm['forumpermissions'] &= ~$this->bf_forumpermissions['canpostnew'];
                                 $groupPerm['forumpermissions'] |= $this->bf_forumpermissions['canview'] | $this->bf_forumpermissions['canviewthreads'] | $this->bf_forumpermissions['canviewothers'];
                                 $channelPerm->setPermissions($channelId, $groupPerm['groupid'], $groupPerm, true);
                             } else {
                                 if ($groupPerm['systemgroupid'] == vB_Api_UserGroup::REGISTERED_SYSGROUPID) {
                                     $defaultPerms = $groupPerm;
                                 }
                             }
                         }
                     }
                     //insert record for cms authors
                     $defaultPerms['createpermissions'] |= $this->contenttypes['vbforum_text'] | $this->contenttypes['vbforum_report'] | $this->contenttypes['vbforum_gallery'] | $this->contenttypes['vbforum_poll'] | $this->contenttypes['vbforum_attach'] | $this->contenttypes['vbforum_photo'] | $this->contenttypes['vbforum_privatemessage'] | $this->contenttypes['vbforum_video'] | $this->contenttypes['vbforum_link'];
                     $defaultPerms['forumpermissions2'] |= $this->bf_forumpermissions2['canalwaysview'] | $this->bf_forumpermissions2['cangetimgattachment'];
                     $defaultPerms['forumpermissions'] |= $this->bf_forumpermissions['canpostnew'] | $this->bf_forumpermissions['canseedelnotice'] | $this->bf_forumpermissions['cangetattachment'] | $this->bf_forumpermissions['canview'] | $this->bf_forumpermissions['canviewthreads'] | $this->bf_forumpermissions['canviewothers'] | $this->bf_forumpermissions['canpostattachment'] | $this->bf_forumpermissions['cantagown'];
                     $defaultPerms['forumpermissions2'] &= ~$this->bf_forumpermissions2['canpublish'];
                     $defaultPerms['edit_time'] = 24 * 365;
                     $channelPerm->setPermissions($channelId, $this->authorGroupid, $defaultPerms, true);
                     //and for cms editors.
                     $defaultPerms['forumpermissions'] |= $this->bf_forumpermissions['followforummoderation'] | $this->bf_forumpermissions['cantagothers'];
                     $defaultPerms['forumpermissions2'] |= $this->bf_forumpermissions2['canpublish'] | $this->bf_forumpermissions2['caneditothers'];
                     $channelPerm->setPermissions($channelId, $this->editorGroupId, $defaultPerms, true);
                     break;
                     //If it's anything else we don't set permissions.
             }
         }
     }
     $channelPerm->buildDefaultChannelPermsDatastore();
 }
 protected function import($onlyGuid = false)
 {
     if (empty($this->parsedXML['pagetemplate'])) {
         $this->parsedXML['pagetemplate'] = array();
     }
     $this->checkWidgets();
     // get all columns but the key
     $pageTemplateTable = $this->db->fetchTableStructure('pagetemplate');
     $pageTemplateTableColumns = array_diff($pageTemplateTable['structure'], array($pageTemplateTable['key']));
     $widgetInstanceTable = $this->db->fetchTableStructure('widgetinstance');
     $widgetInstanceTableColumns = array_diff($widgetInstanceTable['structure'], array($pageTemplateTable['key'], $widgetInstanceTable['key']));
     $pageTemplates = is_array($this->parsedXML['pagetemplate'][0]) ? $this->parsedXML['pagetemplate'] : array($this->parsedXML['pagetemplate']);
     // get the config items defined for each widget
     $widgetDefinitionCache = array();
     $widgetRows = vB::getDbAssertor()->getRows('widget');
     $widgetGuids = array();
     foreach ($widgetRows as $widgetRow) {
         $widgetGuids[$widgetRow['widgetid']] = $widgetRow['guid'];
     }
     $widgetDefRows = vB::getDbAssertor()->getRows('widgetdefinition');
     foreach ($widgetDefRows as $widgetDefRow) {
         $widgetGuid = $widgetGuids[$widgetDefRow['widgetid']];
         if (!isset($widgetDefinitionCache[$widgetGuid])) {
             $widgetDefinitionCache[$widgetGuid] = array();
         }
         // replace any "phrase:" placeholders in widget definitions
         $widgetDefRow = $this->replacePhrasePlaceholdersInWidgetConfig($widgetDefRow);
         $widgetDefinitionCache[$widgetGuid][] = $widgetDefRow;
     }
     unset($widgetDefRows, $widgetDefRow, $widgetRows, $widgetRow, $widgetRows, $widgetGuids, $widgetGuid, $phrases);
     // get screenlayoutguid => screenlayoutid lookup table
     $screenLayoutLookup = array();
     $screenLayouts = $this->db->assertQuery('screenlayout', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT));
     foreach ($screenLayouts as $screenLayout) {
         $screenLayoutLookup[$screenLayout['guid']] = $screenLayout['screenlayoutid'];
     }
     foreach ($pageTemplates as $pageTemplate) {
         if ($onlyGuid and $onlyGuid != $pageTemplate['guid']) {
             continue;
         }
         $values = array();
         foreach ($pageTemplateTableColumns as $col) {
             if (isset($pageTemplate[$col])) {
                 $values[$col] = $pageTemplate[$col];
             }
         }
         /*
          * Note, it wasn't trivial to just add finalUpgrade->step_5() before every instance of
          * finalUpgrade->step_6(), which is what's needed for the below check to NOT block upgrades.
          * I'm leaving this commented instead of just removing so that if people run into the issue
          * of pagetemplate.screenlayoutid = 0 in the future (VBV-13771), they have a starting point
          * into looking at what happened/how we solved the issue in the past. Also see
          * class_upgrade_514b3->step_2()
         // Ensure screenlayoutid exists. This may happen if upgrade final step_6 (import pagetemplates XML)
         // is called before step_5 (import screenlayouts XML).
         if (!isset($screenLayoutLookup[$pageTemplate['screenlayoutguid']]))
         {
         	throw new vB_Exception_Api(
         		'missing_screenlayoutid_for_guid_x_pagetemplate_y',
         		array(
         			$pageTemplate['screenlayoutguid'],
         			$pageTemplate['title']
         		)
         	);
         }
         */
         // add screenlayoutid
         $values['screenlayoutid'] = $screenLayoutLookup[$pageTemplate['screenlayoutguid']];
         $pageTemplateId = $oldTemplateId = 0;
         $condition = array('guid' => $pageTemplate['guid']);
         if ($oldPageTemplate = $this->db->getRow('pagetemplate', $condition)) {
             if ($this->options & self::OPTION_OVERWRITE) {
                 $oldTemplateId = $oldPageTemplate['pagetemplateid'];
                 // overwrite preexisting record
                 $this->db->delete('pagetemplate', $condition);
             } else {
                 $pageTemplateId = $oldPageTemplate['pagetemplateid'];
             }
         }
         if (empty($pageTemplateId)) {
             $pageTemplateId = $this->db->insertIgnore('pagetemplate', $values);
         }
         if (is_array($pageTemplateId)) {
             $pageTemplateId = array_pop($pageTemplateId);
         }
         // continue only if the widget could be inserted
         if ($pageTemplateId) {
             if ($oldTemplateId and $pageTemplateId != $oldTemplateId) {
                 // update pages that point to the old templateid
                 $this->db->update('page', array('pagetemplateid' => $pageTemplateId), array('pagetemplateid' => $oldTemplateId));
             }
             if ($this->options & self::OPTION_OVERWRITE) {
                 // if we are overwriting the template with the same templateid, remove associated widget instances
                 $this->db->delete('widgetinstance', array('pagetemplateid' => $pageTemplateId));
             }
             if (isset($pageTemplate['widgets']) and (!$oldPageTemplate or $this->options & self::OPTION_ADDWIDGETS)) {
                 $widgets = is_array($pageTemplate['widgets']['widgetinstance'][0]) ? $pageTemplate['widgets']['widgetinstance'] : array($pageTemplate['widgets']['widgetinstance']);
                 foreach ($widgets as $widget) {
                     $values = array();
                     foreach ($widgetInstanceTable['structure'] as $col) {
                         if (isset($widget[$col])) {
                             if ($col == 'adminconfig' and $widget[$col] != '') {
                                 // default admin config values are defined for this widget instance
                                 // in the vbulletin-pagetemplates.xml file. When setting these, make
                                 // sure we also pull in any additional default config items
                                 // for this widget
                                 $adminConfig = $widget[$col];
                                 if (($temp = unserialize($adminConfig)) !== false) {
                                     $adminConfig = $temp;
                                     unset($temp);
                                     // There are channel GUIDs in the serialized admin configs
                                     // these will be replaced with channel IDs in
                                     // replaceChannelGuidsInWidgetConfigs after channels have been
                                     // imported.
                                     // Replace "phrase:" placeholders in admin config
                                     $adminConfig = $this->replacePhrasePlaceholdersInWidgetConfig($adminConfig);
                                 }
                                 $defaultConfig = array();
                                 $configItems = $widgetDefinitionCache[$widget['widgetguid']];
                                 if (!empty($configItems)) {
                                     foreach ($configItems as $configItem) {
                                         if (!empty($configItem['name'])) {
                                             $defaultConfig[$configItem['name']] = $configItem['defaultvalue'];
                                         }
                                     }
                                 }
                                 unset($configItems, $configItem);
                                 $values[$col] = serialize($adminConfig + $defaultConfig);
                             } else {
                                 $values[$col] = $widget[$col];
                             }
                         }
                     }
                     $values['widgetid'] = $this->referencedWidgets[$widget['widgetguid']]['widgetid'];
                     $values['pagetemplateid'] = $pageTemplateId;
                     $widgetInstanceId = $this->db->insert('widgetinstance', $values);
                     if (is_array($widgetInstanceId)) {
                         $widgetInstanceId = array_pop($widgetInstanceId);
                     }
                     if (isset($widget['subModules'])) {
                         $subModules = is_array($widget['subModules']['widgetinstance'][0]) ? $widget['subModules']['widgetinstance'] : array($widget['subModules']['widgetinstance']);
                         foreach ($subModules as $widget) {
                             $values = array();
                             foreach ($widgetInstanceTable['structure'] as $col) {
                                 if (isset($widget[$col])) {
                                     $values[$col] = $widget[$col];
                                 }
                             }
                             $values['containerinstanceid'] = $widgetInstanceId;
                             $values['widgetid'] = $this->referencedWidgets[$widget['widgetguid']]['widgetid'];
                             $values['pagetemplateid'] = $pageTemplateId;
                             $this->db->insert('widgetinstance', $values);
                         }
                     }
                 }
             }
         }
         vB_Xml_Import::setImportedId(vB_Xml_Import::TYPE_PAGETEMPLATE, $pageTemplate['guid'], $pageTemplateId);
         // Insert phrases for pagetemplate title.
         $phraseLib = vB_Library::instance('phrase');
         $guidforphrase = $phraseLib->cleanGuidForPhrase($pageTemplate['guid']);
         $phraseLib->save('pagemeta', 'pagetemplate_' . $guidforphrase . '_title', array('text' => array($pageTemplate['title']), 'ismaster' => 1, 'product' => 'vbulletin', 't' => 0, 'oldvarname' => 'pagetemplate_' . $guidforphrase . '_title', 'oldfieldname' => 'pagemeta'));
     }
 }
Example #6
0
 public function importThemes($perpage = 1, $overwrite = false)
 {
     $themesdir = DIR . '/install/themes/';
     if (is_dir($themesdir)) {
         /*
          *	There's a bug in the upgrader where only the 'startat' parameter can be returned & used in
          *	the upgrade steps. Since the same upgrade step will be run for a single file, and we have
          *	multiple files to process, we need to keep track of 1) which file we were on and 2) which
          *	iteration of that file we are on. Since we only have 1 variable to keep track of at least
          *	multiple values, we need another way to keep track of data between sessions.
          */
         $datastore = vB::getDatastore();
         $dataTitle = "themeImportProgress";
         $importProgress = $datastore->getValue($dataTitle);
         if (is_null($importProgress)) {
             $importProgress = '';
         }
         $importProgress = json_decode($importProgress, true);
         /*
          * json_encode-d array of
          *	'finished' => 	{array of fully imported filenames},
          *	'current'  => 	{array
          *						'filename' => {current filename},
          *						'startat' => {current progress index} ,
          *						'styleid' => {styleid of added style record if we're not at startat==0}
          *					},
          *	'remaining'	=> 	{array of remaining filenames}
          *
          *	I'm not storing the parsed XML in here, because I'm not certain if the json_encoded data with the parsed
          *	XML can be guaranteed to be less than mediumtext's (type of datastore.data) limit of	2^24 + 3 bytes.
          */
         if (empty($importProgress)) {
             $importProgress = array('finished' => array(), 'remaining' => array_filter(scandir($themesdir), function ($filename) use($themesdir) {
                 return !is_dir($themesdir . '/' . $filename) and strtolower(pathinfo($filename, PATHINFO_EXTENSION)) === 'xml';
                 // skip directories and make sure it has xml extension
             }));
             // TODO: need better check to grab REAL files only. One approach is to use a filename prefix and check for that, like how customlanguages does it
         }
         // Let's grab the file to work on next if we don't have one
         if (empty($importProgress['current'])) {
             // we have no files remaining to import
             if (empty($importProgress['remaining'])) {
                 $datastore->build($dataTitle, '', 0);
                 return array('done' => true, 'continue' => false, 'output' => '');
             } else {
                 $importProgress['current']['filename'] = $themesdir . '/' . array_shift($importProgress['remaining']);
                 $importProgress['current']['startat'] = 0;
                 $importProgress['current']['styleid'] = -1;
             }
         }
         // make sure we have the theme parent, as any imported themes will be its children
         if (empty(self::$themeParent['guid'])) {
             $this->getDefaultParentTheme();
         }
         // fetch the XML file and parse it into something we can understand
         $this->parsedXML['theme'] = vB_Xml_Import::parseFile($importProgress['current']['filename']);
         // ensure that imported theme is a child of the blank parent theme. Any other kind of
         // default data setting global to all "auto-import @ install" themes should happen here.
         $this->parsedXML['theme']['parentid'] = self::$themeParent['styleid'];
         // overwrite check happens inside import()
         $info = $this->import($importProgress['current']['startat'], $perpage, $overwrite, $importProgress['current']['styleid'], true);
         if ($info['done']) {
             $importProgress['finished'][] = $importProgress['current']['filename'];
             unset($importProgress['current']);
         } else {
             $importProgress['current']['styleid'] = $info['overwritestyleid'];
             $importProgress['current']['startat'] += $perpage;
         }
         $importProgress = json_encode($importProgress);
         $datastore->build($dataTitle, $importProgress, 0);
         // move onto the next iteration of this file (or the next file, whichever is appropriate).
         return array('done' => false, 'continue' => true, 'output' => $info['output']);
     } else {
         // themes folder does not exist. nothing to import
         return array('done' => true, 'continue' => false, 'output' => '');
     }
 }
Example #7
0
 protected function import($onlyGuid = false)
 {
     if (empty($this->parsedXML['page'])) {
         $this->parsedXML['page'] = array();
     }
     $this->checkTemplates();
     // get all columns but the key
     $pageTable = $this->db->fetchTableStructure('page');
     $pageTableColumns = array_diff($pageTable['structure'], array($pageTable['key']));
     $pages = is_array($this->parsedXML['page'][0]) ? $this->parsedXML['page'] : array($this->parsedXML['page']);
     $phraseLib = vB_Library::instance('phrase');
     foreach ($pages as $page) {
         if ($onlyGuid and $onlyGuid != $page['guid']) {
             continue;
         }
         $values = array();
         foreach ($pageTableColumns as $col) {
             if (isset($page[$col])) {
                 $values[$col] = $page[$col];
             }
         }
         $values['pagetemplateid'] = $this->referencedTemplates[$page['pageTemplateGuid']]['pagetemplateid'];
         if (isset($page['parentGuid']) and !empty($page['parentGuid'])) {
             $parent = $this->db->getRow('page', array('guid' => $page['parentGuid']));
             if ($parent) {
                 $values['parentid'] = $parent['pageid'];
             } else {
                 if (!($this->options & vB_Xml_Import::OPTION_IGNOREMISSINGPARENTS)) {
                     throw new Exception('Couldn\'t find parent while attempting to import page ' . $page['guid']);
                 }
             }
         }
         $pageId = 0;
         $condition = array('guid' => $page['guid']);
         if ($this->options & self::OPTION_OVERWRITE) {
             // overwrite preexisting record
             $this->db->delete('page', $condition);
         } else {
             if ($existingPage = $this->db->getRow('page', $condition)) {
                 $pageId = $existingPage['pageid'];
             }
         }
         if (empty($pageId)) {
             $pageId = $this->db->insertIgnore('page', $values);
         }
         if (is_array($pageId)) {
             $pageId = array_pop($pageId);
         }
         vB_Xml_Import::setImportedId(vB_Xml_Import::TYPE_PAGE, $page['guid'], $pageId);
         // Insert phrases for page title, meta description.
         $guidforphrase = vB_Library::instance('phrase')->cleanGuidForPhrase($page['guid']);
         $productid = !empty($page['product']) ? $page['product'] : 'vbulletin';
         $phraseLib->save('pagemeta', 'page_' . $guidforphrase . '_title', array('text' => array($page['title']), 'ismaster' => 1, 'product' => $productid, 't' => 0, 'oldvarname' => 'page_' . $guidforphrase . '_title', 'oldfieldname' => 'global'));
         $phraseLib->save('pagemeta', 'page_' . $guidforphrase . '_metadesc', array('text' => array($page['metadescription']), 'ismaster' => 1, 'product' => $productid, 't' => 0, 'oldvarname' => 'page_' . $guidforphrase . '_metadesc', 'oldfieldname' => 'global'));
     }
 }
Example #8
0
 /**
  * Inserts or updates the widgets in the database. Adds the widget ID to the
  * passed array of widgets and returns it.
  *
  * @param  array The array of widgets to insert/update
  * @param  bool  Add the product ID to the inserted record, if needed. If false, productid will be skipped entirely.
  *
  * @return array The passed array of widgets with a new 'widgetid' element and indexed by widget ID.
  */
 private function saveWidgets($widgets, $addProductId = true)
 {
     $widgetTableColumns = $this->getTableColumnsToImport('widget');
     // insert or update widget records
     foreach ($widgets as $key => $widget) {
         // populate fields that are missing in the xml
         // with their default values
         $values = array();
         foreach ($widgetTableColumns as $col) {
             if ($col == 'product' and !empty($this->productid)) {
                 // If we don't want to add the productid,
                 // then we don't even set the key in $values
                 if ($addProductId) {
                     $values[$col] = $this->productid;
                 }
             } else {
                 if (isset($widget[$col])) {
                     $values[$col] = $widget[$col];
                 } else {
                     if ($col == 'canbemultiple' or $col == 'cloneable' or $col == 'isthirdparty') {
                         $values[$col] = 0;
                     } else {
                         $values[$col] = '';
                     }
                 }
             }
         }
         // update or insert
         $condition = array('guid' => $widget['guid']);
         if ($oldWidget = $this->db->getRow('widget', $condition)) {
             $widgetid = $oldWidget['widgetid'];
             if ($this->options & self::OPTION_OVERWRITE) {
                 // update widget
                 $this->db->update('widget', $values, $condition);
             }
         } else {
             $widgetid = $this->db->insert('widget', $values);
             if (is_array($widgetid)) {
                 $widgetid = array_pop($widgetid);
             }
             // mark record as inserted for updateWidgetParentids call
             $this->insertedWidgetIds[$widgetid] = $widgetid;
         }
         // save data needed for subsequent processing
         $widgets[$key]['widgetid'] = $widgetid;
         // track imported IDs
         vB_Xml_Import::setImportedId(vB_Xml_Import::TYPE_WIDGET, $widget['guid'], $widgetid);
     }
     $indexedWidgets = array();
     foreach ($widgets as $widgets) {
         $indexedWidgets[$widgets['widgetid']] = $widgets;
     }
     return $indexedWidgets;
 }