/** Executes the job.
  * @return string Returns a string describing the job result in case of success.
  * @throws Exception Throws an exception in case of errors.
  */
 public function run()
 {
     Cache::disableCache();
     Cache::disableLocalCache();
     try {
         $db = Loader::db();
         $instances = array('navigation' => Loader::helper('navigation'), 'dashboard' => Loader::helper('concrete/dashboard'), 'view_page' => PermissionKey::getByHandle('view_page'), 'guestGroup' => Group::getByID(GUEST_GROUP_ID), 'now' => new DateTime('now'), 'ak_exclude_sitemapxml' => CollectionAttributeKey::getByHandle('exclude_sitemapxml'), 'ak_sitemap_changefreq' => CollectionAttributeKey::getByHandle('sitemap_changefreq'), 'ak_sitemap_priority' => CollectionAttributeKey::getByHandle('sitemap_priority'));
         $instances['guestGroupAE'] = array(GroupPermissionAccessEntity::getOrCreate($instances['guestGroup']));
         $xmlDoc = new SimpleXMLElement('<' . '?xml version="1.0" encoding="' . APP_CHARSET . '"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" />');
         $rs = Loader::db()->Query('SELECT cID FROM Pages');
         while ($row = $rs->FetchRow()) {
             self::addPage($xmlDoc, intval($row['cID']), $instances);
         }
         $rs->Close();
         Events::fire('on_sitemap_xml_ready', $xmlDoc);
         $dom = dom_import_simplexml($xmlDoc)->ownerDocument;
         $dom->formatOutput = true;
         $addedPages = count($xmlDoc->url);
         $relName = ltrim(SITEMAPXML_FILE, '\\/');
         $osName = rtrim(DIR_BASE, '\\/') . '/' . $relName;
         $urlName = rtrim(BASE_URL . DIR_REL, '\\/') . '/' . $relName;
         if (!file_exists($osName)) {
             @touch($osName);
         }
         if (!is_writable($osName)) {
             throw new Exception(t('The file %s is not writable', $osName));
         }
         if (!($hFile = @fopen($osName, 'w'))) {
             throw new Exception(t('Cannot open file %s', $osName));
         }
         if (!@fwrite($hFile, $dom->saveXML())) {
             throw new Exception(t('Error writing to file %s', $osName));
         }
         @fflush($hFile);
         @fclose($hFile);
         unset($hFile);
         return t('%1$s file saved (%2$d pages).', sprintf('<a href="%s" target="_blank">%s</a>', $urlName, preg_replace('/^https?:\\/\\//i', '', $urlName)), $addedPages);
     } catch (Exception $x) {
         if (isset($hFile) && $hFile) {
             @fflush($hFile);
             @ftruncate($hFile, 0);
             @fclose($hFile);
             $hFile = null;
         }
         throw $x;
     }
 }
Example #2
0
 public function canGuestsViewThisBlock()
 {
     $pk = PermissionKey::getByHandle('view_block');
     $pk->setPermissionObject($this->getPermissionObject());
     $gg = GroupPermissionAccessEntity::getOrCreate(Group::getByID(GUEST_GROUP_ID));
     $accessEntities = array($gg);
     $valid = false;
     $list = $pk->getAccessListItems(PermissionKey::ACCESS_TYPE_ALL, $accessEntities);
     foreach ($list as $l) {
         if ($l->getAccessType() == PermissionKey::ACCESS_TYPE_INCLUDE) {
             $valid = true;
         }
         if ($l->getAccessType() == PermissionKey::ACCESS_TYPE_EXCLUDE) {
             $valid = false;
         }
     }
     return $valid;
 }
Example #3
0
 public function run()
 {
     $bt = BlockType::getByHandle('guestbook');
     if (is_object($bt)) {
         $bt->refresh();
     }
     // add user export users task permission
     $pk = PermissionKey::getByHandle('access_user_search_export');
     if (!$pk instanceof PermissionKey) {
         $pk = PermissionKey::add('user', 'access_user_search_export', 'Export Site Users', 'Controls whether a user can export site users or not', false, false);
         $pa = $pk->getPermissionAccessObject();
         if (!is_object($pa)) {
             $pa = PermissionAccess::create($pk);
         }
         $adminGroup = Group::getByID(ADMIN_GROUP_ID);
         //Make sure "Adminstrators" group still exists
         if ($adminGroup) {
             $adminGroupEntity = GroupPermissionAccessEntity::getOrCreate($adminGroup);
             $pa->addListItem($adminGroupEntity);
             $pt = $pk->getPermissionAssignmentObject();
             $pt->assignPermissionAccess($pa);
         }
     }
     if (!Config::get('SECURITY_TOKEN_JOBS')) {
         Config::save('SECURITY_TOKEN_JOBS', Loader::helper('validation/identifier')->getString(64));
     }
     if (!Config::get('SECURITY_TOKEN_ENCRYPTION')) {
         Config::save('SECURITY_TOKEN_ENCRYPTION', Loader::helper('validation/identifier')->getString(64));
     }
     if (!Config::get('SECURITY_TOKEN_VALIDATION')) {
         Config::save('SECURITY_TOKEN_VALIDATION', Loader::helper('validation/identifier')->getString(64));
     }
     $sp = Page::getByPath('/dashboard/system/mail/method/test_settings');
     if (!is_object($sp) || $sp->isError()) {
         $sp = SinglePage::add('/dashboard/system/mail/method/test_settings');
         $sp->update(array('cName' => t('Test Mail Settings')));
         $sp->setAttribute('meta_keywords', 'test smtp, test mail');
     }
 }
Example #4
0
	/** Executes the job.
	* @return string Returns a string describing the job result in case of success.
	* @throws Exception Throws an exception in case of errors.
	*/
	public function run() {
		Cache::disableCache();
		Cache::disableLocalCache();
		
		try {
			$db = Loader::db();
			$instances = array(
				'navigation' => Loader::helper('navigation'),
				'dashboard' => Loader::helper('concrete/dashboard'),
				'view_page' => PermissionKey::getByHandle('view_page'),
				'guestGroup' => Group::getByID(GUEST_GROUP_ID),
				'now' => new DateTime('now')
			);
			$instances['guestGroupAE'] = array(GroupPermissionAccessEntity::getOrCreate($instances['guestGroup']));
			$rsPages = $db->query('SELECT cID FROM Pages WHERE (cID > 1) ORDER BY cID');
			$relName = ltrim(SITEMAPXML_FILE, '\\/');
			$osName = rtrim(DIR_BASE, '\\/') . '/' . $relName;
			$urlName = rtrim(BASE_URL . DIR_REL, '\\/') . '/' . $relName;
			if(!file_exists($osName)) {
				@touch($osName);
			}
			if(!is_writable($osName)) {
				throw new Exception(t('The file %s is not writable', $osName));
			}
			if(!$hFile = fopen($osName, 'w')) {
				throw new Exception(t('Cannot open file %s', $osName));
			}
			if(!@fprintf($hFile, '<'.'?xml version="1.0" encoding="%s"?>' . self::EOL . '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">', APP_CHARSET)) {
				throw new Exception(t('Error writing header of %s', $osName));
			}
			$addedPages = 0;
			if(self::AddPage($hFile, 1, $instances)) {
				$addedPages++;
			}
			while($rowPage = $rsPages->FetchRow()) {
				if(self::AddPage($hFile, intval($rowPage['cID']), $instances)) {
					$addedPages++;
				}
			}
			$rsPages->Close();
			unset($rsPages);
			if(!@fwrite($hFile, self::EOL . '</urlset>')) {
				throw new Exception(t('Error writing footer of %s', $osName));
			}
			@fflush($hFile);
			@fclose($hFile);
			unset($hFile);
			return t('%1$s file saved (%2$d pages).', $urlName, $addedPages);
		}
		catch(Exception $x) {
			if(isset($rsPages) && $rsPages) {
				$rsPages->Close();
				$rsPages = null;
			}
			if(isset($hFile) && $hFile) {
				@fflush($hFile);
				@ftruncate($hFile, 0);
				@fclose($hFile);
				$hFile = null;
			}
			throw $x;
		}
	}
Example #5
0
<?php

defined('C5_EXECUTE') or die("Access Denied.");
if (Loader::helper('validation/token')->validate('process')) {
    $js = Loader::helper('json');
    $obj = new stdClass();
    $g = Group::getByID($_REQUEST['gID']);
    if (is_object($g)) {
        $pae = GroupPermissionAccessEntity::getOrCreate($g);
        $obj->peID = $pae->getAccessEntityID();
        $obj->label = $pae->getAccessEntityLabel();
    }
    print $js->encode($obj);
}
Example #6
0
 public function assignPermissions($userOrGroup, $permissions = array(), $accessType = PagePermissionKey::ACCESS_TYPE_INCLUDE)
 {
     if ($this->cInheritPermissionsFrom != 'OVERRIDE') {
         $this->setPermissionsToManualOverride();
         $this->clearPagePermissions();
     }
     if (is_array($userOrGroup)) {
         $pe = GroupCombinationPermissionAccessEntity::getOrCreate($userOrGroup);
         // group combination
     } else {
         if ($userOrGroup instanceof User || $userOrGroup instanceof UserInfo) {
             $pe = UserPermissionAccessEntity::getOrCreate($userOrGroup);
         } else {
             // group;
             $pe = GroupPermissionAccessEntity::getOrCreate($userOrGroup);
         }
     }
     foreach ($permissions as $pkHandle) {
         $pk = PagePermissionKey::getByHandle($pkHandle);
         $pk->setPermissionObject($this);
         $pa = $pk->getPermissionAccessObject();
         if (!is_object($pa)) {
             $pa = PermissionAccess::create($pk);
         }
         $pa->addListItem($pe, false, $accessType);
         $pt = $pk->getPermissionAssignmentObject();
         $pt->assignPermissionAccess($pa);
         $this->loadPermissionAssignments();
     }
 }
Example #7
0
 protected function migrateAccessEntity($row)
 {
     if ($row['uID'] > 0) {
         $ui = UserInfo::getByID($row['uID']);
         if ($ui) {
             $pe = UserPermissionAccessEntity::getOrCreate($ui);
         }
     } else {
         $g = Group::getByID($row['gID']);
         if ($g) {
             $pe = GroupPermissionAccessEntity::getOrCreate($g);
         }
     }
     return $pe;
 }
Example #8
0
 public function assignPermissions($userOrGroup, $permissions = array(), $accessType = FileSetPermissionKey::ACCESS_TYPE_INCLUDE)
 {
     $db = Loader::db();
     if ($this->fsID > 0) {
         $db->Execute("update FileSets set fsOverrideGlobalPermissions = 1 where fsID = ?", array($this->fsID));
         $this->fsOverrideGlobalPermissions = true;
     }
     if (is_array($userOrGroup)) {
         $pe = GroupCombinationPermissionAccessEntity::getOrCreate($userOrGroup);
         // group combination
     } else {
         if ($userOrGroup instanceof User || $userOrGroup instanceof UserInfo) {
             $pe = UserPermissionAccessEntity::getOrCreate($userOrGroup);
         } else {
             // group;
             $pe = GroupPermissionAccessEntity::getOrCreate($userOrGroup);
         }
     }
     foreach ($permissions as $pkHandle) {
         $pk = PermissionKey::getByHandle($pkHandle);
         $pk->setPermissionObject($this);
         $pa = $pk->getPermissionAccessObject();
         if (!is_object($pa)) {
             $pa = PermissionAccess::create($pk);
         } else {
             if ($pa->isPermissionAccessInUse()) {
                 $pa = $pa->duplicate();
             }
         }
         $pa->addListItem($pe, false, $accessType);
         $pt = $pk->getPermissionAssignmentObject();
         $pt->assignPermissionAccess($pa);
     }
 }
 /** Check if the specified page should be included in the sitemap.xml file; if so adds it to the file.
  * @param unknown_type $hFile
  * @param int $cID The page collection id.
  * @param array $instances Already instantiated helpers, models, ...
  * @return bool Returns true if the page has been added, false otherwise.
  * @throws Exception Throws an exception in case of errors.
  */
 private static function AddPage($hFile, $cID, $instances)
 {
     $page = Page::getByID($cID, 'ACTIVE');
     if ($page->isSystemPage()) {
         return false;
     }
     if ($page->isExternalLink()) {
         return false;
     }
     if ($instances['dashboard']->inDashboard($page)) {
         return false;
     }
     if ($page->getAttribute('exclude_sitemapxml')) {
         return false;
     }
     $instances['view_page']->setPermissionObject($page);
     $pa = $instances['view_page']->getPermissionAccessObject();
     if (!is_object($pa)) {
         return false;
     }
     $guest = Group::getByID(GUEST_GROUP_ID);
     $accessEntities[] = GroupPermissionAccessEntity::getOrCreate($guest);
     if (!$pa->validateAccessEntities($accessEntities)) {
         return false;
     }
     $lastmod = new DateTime($page->getCollectionDateLastModified());
     $changefreq = $page->getAttribute('sitemap_changefreq');
     $priority = $page->getAttribute('sitemap_priority');
     if (!@fprintf($hFile, "%1\$s\t<url>%1\$s\t\t<loc>%2\$s</loc>%1\$s\t\t<lastmod>%3\$s</lastmod>%1\$s\t\t<changefreq>%4\$s</changefreq>%1\$s\t\t<priority>%5\$s</priority>%1\$s\t</url>", self::EOL, $instances['navigation']->getCollectionURL($page), $lastmod->format(DateTime::ATOM), htmlspecialchars($changefreq == '' ? SITEMAPXML_DEFAULT_CHANGEFREQ : $changefreq), htmlspecialchars($priority == '' ? SITEMAPXML_DEFAULT_PRIORITY : $priority))) {
         throw new Exception(t('Error writing page with cID %d to sitemap.xml', $cID));
     }
     @fflush($hFile);
     return true;
 }
Example #10
0
 private function setPermissions()
 {
     /*
      * This only covers permissions in 5.6+ They changed quite massively at
      * that revision. Eventually, this package will have other branches for 
      * earlier versions.
      * 
      * Not everything shown here will work with simple permissions. People 
      * will just be set as able to view or admin, the nuanced stuff about 
      * sub page permissions, etc will not be applied
      * 
      * First off, we need to set up arrays of what people are allowed to do.
      */
     $viewOnly = array('view_page');
     $writePage = array('view_page', 'view_page_versions', 'edit_page_properties', 'edit_page_contents', 'approve_page_versions');
     $adminPage = array('edit_page_speed_settings', 'edit_page_permissions', 'edit_page_theme', 'schedule_page_contents_guest_access', 'edit_page_type', 'delete_page', 'preview_page_as_user', 'delete_page_versions', 'move_or_copy_page', 'edit_page_type');
     // Now to get the the group that we made for boilerplate
     $bpGroup = Group::getByName("Boilerplate Admins");
     // Then the current user, again, could be anyone
     $u = new User();
     $ui = UserInfo::getByID($u->getUserID());
     // and our sample page
     $bpPage = Page::getByPath('/boilerplate-sample');
     if (is_object($bpPage) && is_a($bpPage, "Page")) {
         // by passing in -1, we are saying that all permissions in the array are
         // not allowed
         //
         // After some more digging, it seems like saying can't view doesn't
         // work properly. It will hide the page from everyone. If you simply
         // don't assign any permissions for them at all, then it works properly
         // I don't get why that is, might be a bug.
         //
         //			$bpPage->assignPermissions(Group::getByID(GUEST_GROUP_ID), $viewOnly, -1);
         //			$bpPage->assignPermissions(Group::getByID(REGISTERED_GROUP_ID), $viewOnly, -1);
         $bpPage->assignPermissions(Group::getByID(ADMIN_GROUP_ID), $adminPage);
         $bpPage->assignPermissions(Group::getByID(ADMIN_GROUP_ID), $writePage);
         $bpPage->assignPermissions($bpGroup, $writePage);
         $bpPage->assignPermissions($ui, $writePage);
         // at this point, our page will let people edit, and others can't even view
         // in order to allow sub-pages to be added by our admins, we'll need to get
         // a _bit_ more complicated.
         // this could probbly be cleaned up a little, to be more efficient
         // first get the ctID of the page type we want them to be able to add
         $bpID = CollectionType::getByHandle('boilerplate')->getCollectionTypeID();
         // In order to allow the user to add sub pages, we need to do this
         $bpAdminUserPE = UserPermissionAccessEntity::getOrCreate($ui);
         $entities[] = $bpAdminUserPE;
         // lets them add external links
         $args = array();
         $args['allowExternalLinksIncluded'][$bpAdminUserPE->getAccessEntityID()] = 1;
         // I can't remember why it's "C" or what the other options are...
         $args['pageTypesIncluded'][$bpAdminUserPE->getAccessEntityID()] = 'C';
         // you can repeat this with as many different collection type IDs as you like
         $args['ctIDInclude'][$bpAdminUserPE->getAccessEntityID()][] = $bpID;
         // now to allow it for groups
         $bpAdminPE = GroupPermissionAccessEntity::getOrCreate($bpGroup);
         $entities[] = $bpAdminPE;
         $args['allowExternalLinksIncluded'][$bpAdminPE->getAccessEntityID()] = 1;
         $args['pageTypesIncluded'][$bpAdminPE->getAccessEntityID()] = 'C';
         $args['ctIDInclude'][$bpAdminPE->getAccessEntityID()][] = $bpID;
         // ordinary admins
         $adminPE = GroupPermissionAccessEntity::getOrCreate(Group::getByID(ADMIN_GROUP_ID));
         $entities[] = $adminPE;
         $args['allowExternalLinksIncluded'][$adminPE->getAccessEntityID()] = 1;
         $args['pageTypesIncluded'][$adminPE->getAccessEntityID()] = 'C';
         $args['ctIDInclude'][$adminPE->getAccessEntityID()][] = $bpID;
         // and now some crazy voodoo
         $pk = PagePermissionKey::getByHandle('add_subpage');
         $pk->setPermissionObject($bpPage);
         $pt = $pk->getPermissionAssignmentObject();
         $pa = $pk->getPermissionAccessObject();
         if (!is_object($pa)) {
             $pa = PermissionAccess::create($pk);
         }
         foreach ($entities as $pe) {
             $pa->addListItem($pe, false, PagePermissionKey::ACCESS_TYPE_INCLUDE);
         }
         $pa->save($args);
         $pt->assignPermissionAccess($pa);
         // and now we set it so that sub-pages added under this page
         // inherit the same permissions
         $pkr = new ChangeSubpageDefaultsInheritancePageWorkflowRequest();
         $pkr->setRequestedPage($bpPage);
         // if you pass in 0, they will inherit from page type default
         // permissions in the dashboard. That's what they would do anyway,
         // if you don't do any of this stuff.
         $pkr->setPagePermissionsInheritance(1);
         $pkr->setRequesterUserID($u->getUserID());
         $pkr->trigger();
     }
 }
Example #11
0
				$pt->clearPermissionAssignment();
				if ($paID > 0) {
					$pa = PermissionAccess::getByID($paID, $pk);
					if (is_object($pa)) {
						$pt->assignPermissionAccess($pa);
					}			
				}
			}
		}

	}
	if ($p->canScheduleGuestAccess()) { 
		if ($_REQUEST['task'] == 'set_timed_guest_access' && Loader::helper("validation/token")->validate('set_timed_guest_access')) {
			if (!$b->overrideAreaPermissions()) {
				$b->doOverrideAreaPermissions();
			}
			$pk = PermissionKey::getByHandle('view_block');
			$pk->setPermissionObject($b);
			$pa = $pk->getPermissionAccessObject();
			if (!is_object($pa)) {
				$pa = PermissionAccess::create($pk);
			}
			$pe = GroupPermissionAccessEntity::getOrCreate(Group::getByID(GUEST_GROUP_ID));
			$pd = PermissionDuration::translateFromRequest();
			$pa->addListItem($pe, $pd, BlockPermissionKey::ACCESS_TYPE_INCLUDE);
			$pt = $pk->getPermissionAssignmentObject();
			$pt->assignPermissionAccess($pa);
		}
	}
}
Example #12
0
 public function view()
 {
     if (PERMISSIONS_MODEL != 'simple') {
         return;
     }
     $editAccess = array();
     $home = Page::getByID(1, "RECENT");
     $pk = PermissionKey::getByHandle('view_page');
     $pk->setPermissionObject($home);
     $assignments = $pk->getAccessListItems();
     foreach ($assignments as $asi) {
         $ae = $asi->getAccessEntityObject();
         if ($ae->getAccessEntityTypeHandle() == 'group' && $ae->getGroupObject()->getGroupID() == GUEST_GROUP_ID) {
             $this->set('guestCanRead', true);
         } else {
             if ($ae->getAccessEntityTypeHandle() == 'group' && $ae->getGroupObject()->getGroupID() == REGISTERED_GROUP_ID) {
                 $this->set('registeredCanRead', true);
             }
         }
     }
     Loader::model('search/group');
     $gl = new GroupSearch();
     $gl->filter('gID', REGISTERED_GROUP_ID, '>');
     $gIDs = $gl->get();
     $gArray = array();
     foreach ($gIDs as $gID) {
         $gArray[] = Group::getByID($gID['gID']);
     }
     $pk = PermissionKey::getByHandle('edit_page_contents');
     $pk->setPermissionObject($home);
     $assignments = $pk->getAccessListItems();
     foreach ($assignments as $asi) {
         $ae = $asi->getAccessEntityObject();
         if ($ae->getAccessEntityTypeHandle() == 'group') {
             $editAccess[] = $ae->getGroupObject()->getGroupID();
         }
     }
     $this->set('home', $home);
     $this->set('gArray', $gArray);
     $this->set('editAccess', $editAccess);
     if ($this->isPost()) {
         if ($this->token->validate('site_permissions_code')) {
             switch ($_POST['view']) {
                 case "ANYONE":
                     $viewObj = GroupPermissionAccessEntity::getOrCreate(Group::getByID(GUEST_GROUP_ID));
                     break;
                 case "USERS":
                     $viewObj = GroupPermissionAccessEntity::getOrCreate(Group::getByID(REGISTERED_GROUP_ID));
                     break;
                 case "PRIVATE":
                     $viewObj = GroupPermissionAccessEntity::getOrCreate(Group::getByID(ADMIN_GROUP_ID));
                     break;
             }
             $pk = PermissionKey::getByHandle('view_page');
             $pk->setPermissionObject($home);
             $pt = $pk->getPermissionAssignmentObject();
             $pt->clearPermissionAssignment();
             $pa = PermissionAccess::create($pk);
             $pa->addListItem($viewObj);
             $pt->assignPermissionAccess($pa);
             $editAccessEntities = array();
             if (is_array($_POST['gID'])) {
                 foreach ($_POST['gID'] as $gID) {
                     $editAccessEntities[] = GroupPermissionAccessEntity::getOrCreate(Group::getByID($gID));
                 }
             }
             $editPermissions = array('view_page_versions', 'edit_page_properties', 'edit_page_contents', 'edit_page_speed_settings', 'edit_page_theme', 'edit_page_type', 'edit_page_permissions', 'delete_page', 'preview_page_as_user', 'schedule_page_contents_guest_access', 'delete_page_versions', 'approve_page_versions', 'add_subpage', 'move_or_copy_page');
             foreach ($editPermissions as $pkHandle) {
                 $pk = PermissionKey::getByHandle($pkHandle);
                 $pk->setPermissionObject($home);
                 $pt = $pk->getPermissionAssignmentObject();
                 $pt->clearPermissionAssignment();
                 $pa = PermissionAccess::create($pk);
                 foreach ($editAccessEntities as $editObj) {
                     $pa->addListItem($editObj);
                 }
                 $pt->assignPermissionAccess($pa);
             }
             $pkx = PermissionKey::getbyHandle('add_block');
             $pt = $pkx->getPermissionAssignmentObject();
             $pt->clearPermissionAssignment();
             $pa = PermissionAccess::create($pkx);
             foreach ($editAccessEntities as $editObj) {
                 $pa->addListItem($editObj);
             }
             $pt->assignPermissionAccess($pa);
             $pkx = PermissionKey::getbyHandle('add_stack');
             $pt = $pkx->getPermissionAssignmentObject();
             $pt->clearPermissionAssignment();
             $pa = PermissionAccess::create($pkx);
             foreach ($editAccessEntities as $editObj) {
                 $pa->addListItem($editObj);
             }
             $pt->assignPermissionAccess($pa);
             Cache::flush();
             $this->redirect('/dashboard/system/permissions/site/', 'saved');
         } else {
             $this->error->add($this->token->getErrorMessage());
         }
     }
 }
Example #13
0
	protected function importPermissions(SimpleXMLElement $sx) {
		if (isset($sx->permissionkeys)) {
			foreach($sx->permissionkeys->permissionkey as $pk) {
				$pkc = PermissionKeyCategory::getByHandle((string) $pk['category']);
				$pkg = ContentImporter::getPackageObject($pk['package']);
				$txt = Loader::helper('text');
				$className = $txt->camelcase($pkc->getPermissionKeyCategoryHandle());
				$c1 = $className . 'PermissionKey';
				$pkx = call_user_func(array($c1, 'import'), $pk);	
				if (isset($pk->access)) {
					foreach($pk->access->children() as $ch) {
						if ($ch->getName() == 'group') {
							$g = Group::getByName($ch['name']);
							if (!is_object($g)) {
								$g = Group::add($g['name'], $g['description']);
							}
							$pae = GroupPermissionAccessEntity::getOrCreate($g);
							$pa = PermissionAccess::create($pkx);
							$pa->addListItem($pae);
							$pt = $pkx->getPermissionAssignmentObject();
							$pt->assignPermissionAccess($pa);
						}
					}
				}
			
			}
		}
	}
 $c->setPermissionsToManualOverride();
 $pk = PermissionKey::getByHandle('view_page');
 $pk->setPermissionObject($c);
 $pt = $pk->getPermissionAssignmentObject();
 $pt->clearPermissionAssignment();
 $pa = PermissionAccess::create($pk);
 if (is_array($_POST['readGID'])) {
     foreach ($_POST['readGID'] as $gID) {
         $pa->addListItem(GroupPermissionAccessEntity::getOrCreate(Group::getByID($gID)));
     }
 }
 $pt->assignPermissionAccess($pa);
 $editAccessEntities = array();
 if (is_array($_POST['editGID'])) {
     foreach ($_POST['editGID'] as $gID) {
         $editAccessEntities[] = GroupPermissionAccessEntity::getOrCreate(Group::getByID($gID));
     }
 }
 $editPermissions = array('view_page_versions', 'edit_page_properties', 'edit_page_contents', 'edit_page_speed_settings', 'edit_page_theme', 'edit_page_type', 'edit_page_permissions', 'preview_page_as_user', 'schedule_page_contents_guest_access', 'delete_page', 'delete_page_versions', 'approve_page_versions', 'add_subpage', 'move_or_copy_page');
 foreach ($editPermissions as $pkHandle) {
     $pk = PermissionKey::getByHandle($pkHandle);
     $pk->setPermissionObject($c);
     $pt = $pk->getPermissionAssignmentObject();
     $pt->clearPermissionAssignment();
     $pa = PermissionAccess::create($pk);
     foreach ($editAccessEntities as $editObj) {
         $pa->addListItem($editObj);
     }
     $pt->assignPermissionAccess($pa);
 }
 if ($_POST['rel'] == 'SITEMAP') {
 function run()
 {
     if (!defined('ENABLE_MULTILINGUAL_SITEMAPXML') || !ENABLE_MULTILINGUAL_SITEMAPXML) {
         return t("This job is disabled because it may cause excessive load depending on the size of your site.  To enable this job, you must define the constant ENABLE_MULTILINGUAL_SITEMAPXML as true.");
     }
     $ni = Loader::helper('navigation');
     $tp = Loader::helper('translated_pages', 'multilingual');
     $xmlFile = DIR_BASE . '/sitemap.xml';
     $xmlHead = "<" . "?" . "xml version=\"1.0\" encoding=\"" . APP_CHARSET . "\"?>\n" . "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">\n";
     $home = '';
     $c = Page::getByID(1, "ACTIVE");
     $changefreq = $c->getAttribute('sitemap_changefreq');
     $priority = $c->getAttribute("sitemap_priority");
     if ($changefreq == '') {
         $changefreq = 'weekly';
     }
     if ($priority == '') {
         $priority = '1.0';
     }
     $home .= "<url>\n";
     $home .= "<loc>" . BASE_URL . DIR_REL . "</loc>\n";
     $home .= "  <lastmod> " . date('Y-m-d') . "</lastmod>\n";
     $home .= "  <changefreq>" . $changefreq . "</changefreq>\n";
     $home .= "  <priority>" . $priority . "</priority>\n";
     $translated_pages = $tp->getTranslatedPages($c);
     foreach ($translated_pages as $locale => $page) {
         $home .= "  " . $tp->altMeta($locale, $page, 'xhtml:link') . "\n";
     }
     $home .= "</url>\n";
     $xmlFoot = "</urlset>\n";
     if (!file_exists($xmlFile)) {
         @touch($xmlFile);
     }
     if (is_writable($xmlFile)) {
         if (!($handle = fopen($xmlFile, 'w'))) {
             throw new Exception(t("Cannot open file %s", $xmlFile));
         }
         fwrite($handle, $xmlHead);
         fwrite($handle, $home);
         fflush($handle);
         $db = Loader::db();
         $collection_attributes = Loader::model('collection_attributes');
         $r = $db->query("select cID from Pages where cID > 1 order by cID asc");
         $nh = Loader::helper('navigation');
         $dh = Loader::helper('concrete/dashboard');
         $g = Group::getByID(GUEST_GROUP_ID);
         $groupPermissionEntity = GroupPermissionAccessEntity::getOrCreate($g);
         while ($row = $r->fetchRow()) {
             $c = Page::getByID($row['cID'], 'ACTIVE');
             $g->setPermissionsForObject($c);
             if ($c->isSystemPage() || $c->getAttribute("exclude_sitemapxml") || $c->isExternalLink() || $dh->inDashboard($c)) {
                 continue;
             }
             $gcanRead = false;
             do {
                 if (method_exists($g, 'canRead')) {
                     if ($g->canRead()) {
                         $gcanRead = true;
                     }
                 } else {
                     $pk = PermissionKey::getByHandle('view_page');
                     $pk->setPermissionObject($c);
                     $pa = $pk->getPermissionAccessObject();
                     if (!is_object($pa)) {
                         break;
                     }
                     $accessEntities[] = GroupPermissionAccessEntity::getOrCreate($g);
                     if (!$pa->validateAccessEntities($accessEntities)) {
                         break;
                     }
                 }
                 $gcanRead = true;
             } while (false);
             if ($gcanRead) {
                 $viewPageKey = PermissionKey::getByHandle('view_page');
                 $viewPageKey->setPermissionObject($c);
                 $pa = $viewPageKey->getPermissionAccessObject();
                 if (is_object($pa) && $pa->validateAccessEntities(array($groupPermissionEntity))) {
                     $name = $c->getCollectionName() ? $c->getCollectionName() : '(No name)';
                     $cPath = $ni->getCollectionURL($c);
                     $changefreq = $c->getAttribute('sitemap_changefreq');
                     $priority = $c->getAttribute("sitemap_priority");
                     if ($changefreq == '') {
                         $changefreq = 'weekly';
                     }
                     if ($priority == '') {
                         $priority = '0.' . round(rand(1, 5));
                     }
                     $node .= "<url>\n";
                     $node .= "<loc>" . $cPath . "</loc>\n";
                     $node .= "  <lastmod>" . substr($c->getCollectionDateLastModified(), 0, 10) . "</lastmod>\n";
                     $node .= "  <changefreq>" . $changefreq . "</changefreq>\n";
                     $node .= "  <priority>" . $priority . "</priority>\n";
                     $translated_pages = $tp->getTranslatedPages($c, 'NONE');
                     foreach ($translated_pages as $locale => $page) {
                         $node .= "  " . $tp->altMeta($locale, $page, 'xhtml:link') . "\n";
                     }
                 }
                 $node .= "</url>\n";
                 fwrite($handle, $node);
                 fflush($handle);
             }
         }
         fwrite($handle, $xmlFoot);
         fflush($handle);
         fclose($handle);
         return t("Sitemap XML File Saved.");
     } else {
         throw new Exception(t("The file %s is not writable", $xmlFile));
     }
 }