public function move() { $this->search(); $gParentNodeID = Loader::helper('security')->sanitizeInt($_REQUEST['gParentNodeID']); if ($gParentNodeID) { $node = TreeNode::getByID($gParentNodeID); } if (!$node instanceof GroupTreeNode) { $this->error->add(t("Invalid target parent group.")); } $selectedGroups = array(); if (is_array($_POST['gID'])) { foreach ($_POST['gID'] as $gID) { $group = Group::getByID($gID); if (is_object($group)) { $selectedGroups[] = $group; } } } if (count($selectedGroups) == 0) { $this->error->add(t("You must select at least one group to move")); } if (!$this->error->has()) { $gParent = $node->getTreeNodeGroupObject(); $this->set('selectedGroups', $selectedGroups); $this->set('gParent', $gParent); $this->set('gParentNode', $node); } }
protected function getNode() { if (!isset($this->node)) { $this->node = \Concrete\Core\Tree\Node\Node::getByID(Loader::helper('security')->sanitizeInt($_REQUEST['treeNodeID'])); } return $this->node; }
public function add() { $filesystem = new Filesystem(); if ($this->request->request->has('currentFolder')) { $node = Node::getByID($this->request->request->get('currentFolder')); if (is_object($node) && $node instanceof FileFolder) { $folder = $node; } } if (!isset($folder)) { $folder = $filesystem->getRootFolder(); } $permissions = new \Permissions($folder); $error = $this->app->make('error'); $response = new EditResponse(); $response->setError($error); if (!$permissions->canAddTreeSubNode()) { $error->add(t('You do not have permission to add a folder here.')); } if (!$error->has()) { $folder = $filesystem->addFolder($folder, $this->request->request->get('folderName')); $response->setMessage(t('Folder added.')); $response->setAdditionalDataAttribute('folder', $folder); } $response->outputJSON(); }
public function postRemove(Entity $entity, LifecycleEventArgs $event) { $node = Node::getByID($entity->getEntityResultsNodeId()); if (is_object($node)) { $node->delete(); } }
protected function getNodes() { $sourceNodes = array(); if (!isset($this->nodes)) { if (isset($_REQUEST['sourceTreeNodeID'])) { $sourceNode = Node::getByID(Loader::helper('security')->sanitizeInt($_REQUEST['sourceTreeNodeID'])); if (is_object($sourceNode)) { $sourceNodes[] = $sourceNode; } } else { if (isset($_REQUEST['sourceTreeNodeIDs'])) { foreach ($_REQUEST['sourceTreeNodeIDs'] as $sourceTreeNodeID) { $sourceNode = Node::getByID(Loader::helper('security')->sanitizeInt($sourceTreeNodeID)); if (is_object($sourceNode)) { $sourceNodes[] = $sourceNode; } } } } $destNode = Node::getByID(Loader::helper('security')->sanitizeInt($_REQUEST['treeNodeParentID'])); if (is_array($sourceNodes) && count($sourceNodes) && is_object($destNode)) { $this->nodes = array($sourceNodes, $destNode); } else { $this->nodes = false; } } return $this->nodes; }
protected function renderList($treeNodeParentID = null) { $nodes = null; $parent = null; if ($treeNodeParentID) { $parent = Node::getByID($treeNodeParentID); if (is_object($parent)) { $tree = $parent->getTreeObject(); if (!$tree instanceof ExpressEntryResults) { unset($parent); } } } if (!isset($parent)) { $parent = $this->getResultsTreeNodeObject(); } $this->set('breadcrumb', $this->getBreadcrumb($parent)); if (isset($parent) && $parent instanceof \Concrete\Core\Tree\Node\Type\ExpressEntryResults) { // Get the express entry for which this applies. $entity = $this->entityManager->getRepository('Concrete\\Core\\Entity\\Express\\Entity')->findOneByResultsNode($parent); $search = new \Concrete\Controller\Search\Express\Entries(); $search->search($entity); $this->set('list', $search->getListObject()); $this->set('searchController', $search); $this->set('entity', $entity); $this->render('/dashboard/express/entries/entries', false); } else { $parent->populateDirectChildrenOnly(); $this->set('nodes', $parent->getChildNodes()); $this->render('/dashboard/express/entries/folder', false); } }
public function getResult($queryRow) { $f = Node::getByID($queryRow['treeNodeID']); if (is_object($f) && $this->checkPermissions($f)) { return $f; } }
/** * @param $entity ExpressEntity * @param \SimpleXMLElement $xml */ public function export($entity, \SimpleXMLElement $xml) { $node = $xml->addChild('entity'); $node->addAttribute('id', $entity->getID()); $node->addAttribute('handle', $entity->getHandle()); $node->addAttribute('plural_handle', $entity->getPluralHandle()); $node->addAttribute('name', $entity->getName()); $node->addAttribute('include_in_public_list', $entity->getIncludeInPublicList() ? '1' : ''); $node->addAttribute('description', h($entity->getDescription())); $node->addAttribute('default_view_form', $entity->getDefaultViewForm()->getID()); $node->addAttribute('default_edit_form', $entity->getDefaultEditForm()->getID()); $results = Node::getByID($entity->getEntityResultsNodeId()); if (is_object($results)) { $parent = $results->getTreeNodeParentObject(); $path = $parent->getTreeNodeDisplayPath(); $node->addAttribute('results-folder', $path); } $associations = $entity->getAssociations(); if (count($associations)) { $asn = $node->addChild('associations'); foreach ($associations as $association) { $exporter = $association->getExporter(); $exporter->export($association, $asn); } } $forms = $entity->getForms(); if (count($forms)) { $fsn = $node->addChild('forms'); foreach ($forms as $form) { $exporter = $form->getExporter(); $exporter->export($form, $fsn); } } return $node; }
public function remove_tree_node() { if ($this->token->validate('remove_tree_node')) { $node = TreeNode::getByID(Loader::helper('security')->sanitizeInt($_POST['treeNodeID'])); $tree = $node->getTreeObject(); $treeNodeID = $node->getTreeNodeID(); if (!is_object($node)) { $this->error->add(t('Invalid node.')); } if ($node->getTreeNodeParentID() == 0) { $this->error->add(t('You may not remove the top level node.')); } $np = new Permissions($node); if (!$np->canDeleteTreeNode()) { $this->error->add(t('You may not remove this node.')); } if ($tree->getTreeTypeHandle() != 'topic') { $this->error->add(t('Invalid tree type.')); } if (!$this->error->has()) { $node->delete(); $r = new \stdClass(); $r->treeNodeID = $treeNodeID; Loader::helper('ajax')->sendResult($r); } } else { $this->error->add($this->token->getErrorMessage()); } if ($this->error->has()) { Loader::helper('ajax')->sendError($this->error); } }
public static function getTreeNodeByGroupID($gID) { $db = Loader::db(); $treeNodeID = $db->GetOne('select treeNodeID from TreeGroupNodes where gID = ?', array($gID)); if ($treeNodeID) { $tn = TreeNode::getByID($treeNodeID); return $tn; } }
/** * @param TopicTreeNode $node */ public function setPermissionObject($node) { $this->permissionObject = $node; if ($node->overrideParentTreeNodePermissions()) { $this->permissionObjectToCheck = $node; } else { $parent = Node::getByID($node->getTreeNodePermissionsNodeID()); $this->permissionObjectToCheck = $parent; } }
protected function getExpressNodePermissions() { /** * @var $entry Entry */ $entity = $this->getPermissionObject(); if (is_object($entity)) { $node = Node::getByID($entity->getEntityResultsNodeId()); return new Permissions($node); } }
public function getSelectedTopicNodes() { $topics = array(); foreach ($this->topics as $selectedTopic) { $node = Node::getByID($selectedTopic->getTreeNodeID()); if (is_object($node)) { $topics[] = $node; } } return $topics; }
public function load() { $tree = $this->getTree(); if (is_array($this->request->request('treeNodeSelectedIDs'))) { $selectedIDs = []; foreach ($this->request->request('treeNodeSelectedIDs') as $nID) { $node = Node::getByID($nID); if ($node !== null && $node->getTreeID() == $tree->getTreeID()) { $selectedIDs[] = $node->getTreeNodeID(); } } $tree->setSelectedTreeNodeIDs($selectedIDs); } $tree->setRequest($this->request->request()); $result = $tree->getJSON(); return new JsonResponse($result); }
public function do_add() { $txt = $this->app->make('helper/text'); $valt = $this->app->make('helper/validation/token'); $gName = $txt->sanitize($this->request->post('gName')); $gDescription = $this->request->post('gDescription'); if (!$gName) { $this->error->add(t("Name required.")); } if (!$valt->validate('add_or_update_group')) { $this->error->add($valt->getErrorMessage()); } if ($this->request->post('gIsBadge')) { if (!$this->post('gBadgeDescription')) { $this->error->add(t('You must specify a description for this badge. It will be displayed publicly.')); } } $parentGroup = null; if ($this->request->post('gParentNodeID')) { $parentGroupNode = TreeNode::getByID($this->request->post('gParentNodeID')); if ($parentGroupNode instanceof GroupTreeNode) { $parentGroup = $parentGroupNode->getTreeNodeGroupObject(); } } if (is_object($parentGroup)) { $pp = new \Permissions($parentGroup); if (!$pp->canAddSubGroup()) { $this->error->add(t('You do not have permission to add a group beneath %s', $parentGroup->getGroupDisplayName())); } } if (!$this->error->has()) { $g = ConcreteGroup::add($gName, $this->request->post('gDescription'), $parentGroup); $this->checkExpirationOptions($g); $this->checkBadgeOptions($g); $this->checkAutomationOptions($g); $this->redirect('/dashboard/users/groups', 'group_added'); } $this->view(); }
public function move() { $this->search(); $gParentNodeID = $this->app->make('helper/security')->sanitizeInt($this->request('gParentNodeID')); $gParentNode = $gParentNodeID ? TreeNode::getByID($gParentNodeID) : null; if (!$gParentNode instanceof GroupTreeNode) { $gParentNode = null; $this->error->add(t("Invalid target parent group.")); } $selectedGroups = []; if (is_array($this->post('gID'))) { foreach ($this->post('gID') as $gID) { $group = Group::getByID($gID); if ($group !== null) { $groupNode = GroupTreeNode::getTreeNodeByGroupID($group->getGroupID()); if ($groupNode !== null) { if ($gParentNode !== null) { $error = $groupNode->checkMove($gParentNode); if ($error !== null) { $this->error->add($error); } } $selectedGroups[] = $group; } } } } if (empty($selectedGroups)) { $this->error->add(t("You must select at least one group to move")); } if (!$this->error->has()) { $gParent = $gParentNode->getTreeNodeGroupObject(); $this->set('selectedGroups', $selectedGroups); $this->set('gParent', $gParent); $this->set('gParentNode', $gParentNode); } }
public function getValue() { $nodes = $this->getSelectedOptions(); $topics = array(); foreach ($nodes as $node) { $topic = Node::getByID($node); if (is_object($topic)) { $topics[] = $topic; } } return $topics; }
<?php defined('C5_EXECUTE') or die("Access Denied."); use Concrete\Core\Tree\Node\Node as TreeNode; ?> <div id="topics-tree-node-permissions"> <?php $handle = $node->getPermissionObjectKeyCategoryHandle(); $enablePermissions = false; if (!$node->overrideParentTreeNodePermissions()) { $permNode = TreeNode::getByID($node->getTreeNodePermissionsNodeID()); ?> <div class="alert alert-info"> <?php echo t("Permissions for this node are currently inherited from <strong>%s</strong>.", $permNode->getTreeNodeDisplayName()); ?> <br/><br/> <a href="javascript:void(0)" class="btn btn-sm btn-warning" onclick="TopicsPermissions.setTreeNodePermissionsToOverride()"><?php echo t('Override Permissions'); ?> </a> </div> <?php } else { $enablePermissions = true; ?> <div class="alert alert-info"> <?php
public function upload() { /** @type ResponseFactory $responseFactory */ $responseFactory = $this->app->make(ResponseFactory::class); try { $folder = null; if ($this->request->request->has('currentFolder')) { $node = Node::getByID($this->request->request->get('currentFolder')); if ($node instanceof FileFolder) { $folder = $node; } } if ($folder) { $fp = new \Permissions($folder); } else { $fp = FilePermissions::getGlobal(); } if (!$fp->canAddFiles()) { throw new Exception(t("Unable to add files."), 400); } if ($post_max_size = \Loader::helper('number')->getBytes(ini_get('post_max_size'))) { if ($post_max_size < $_SERVER['CONTENT_LENGTH']) { throw new Exception(FileImporter::getErrorMessage(Importer::E_FILE_EXCEEDS_POST_MAX_FILE_SIZE), 400); } } if (!Loader::helper('validation/token')->validate()) { throw new Exception(Loader::helper('validation/token')->getErrorMessage(), 401); } if (isset($_FILES['file'])) { $files = $this->handleUpload('file', $folder); } if (isset($_FILES['files']['tmp_name'][0])) { $files = array(); for ($i = 0; $i < count($_FILES['files']['tmp_name']); ++$i) { $files = array_merge($files, $this->handleUpload('files', $folder, $i)); } } } catch (Exception $e) { if ($code = $e->getCode()) { return $responseFactory->error($e->getMessage(), $code); } // This error doesn't have a code, it's likely not what we're wanting. throw $e; } return $responseFactory->json($files); }
public function search(Query $query = null) { $searchRequest = new StickyRequest('file_manager_folder'); if ($this->request->get('folder')) { $searchRequest->resetSearchRequest(); $node = Node::getByID($this->request->get('folder')); if (is_object($node) && ($node instanceof \Concrete\Core\Tree\Node\Type\FileFolder || $node instanceof SearchPreset)) { $folder = $node; } } else { $req = $searchRequest->getSearchRequest(); if (isset($req['folder'])) { $node = Node::getByID($req['folder']); if (is_object($node) && ($node instanceof \Concrete\Core\Tree\Node\Type\FileFolder || $node instanceof SearchPreset)) { $folder = $node; } } } if (isset($folder)) { if ($folder instanceof SearchPreset) { $search = $folder->getSavedSearchObject(); $query = $search->getQuery(); $provider = \Core::make('Concrete\\Core\\File\\Search\\SearchProvider'); $ilr = $provider->getSearchResultFromQuery($query); $ilr->setBaseURL(\URL::to('/ccm/system/search/files/preset', $search->getID())); } $searchRequest->addToSearchRequest('folder', $folder->getTreeNodeID()); } if (!isset($ilr)) { if (!isset($folder)) { $folder = $this->filesystem->getRootFolder(); } $u = new \User(); $list = $folder->getFolderItemList($u, $this->request); $fields = $this->request->get('field'); $filters = array(); if (count($fields)) { // We are passing in something like "filter by images" $manager = ManagerFactory::get('file_folder'); $filters = $manager->getFieldsFromRequest($this->request->query->all()); } if (count($filters)) { /** * @var $field FieldInterface */ foreach ($filters as $field) { $field->filterList($list); } } $columns = new FolderSet(); $ilr = new Result($columns, $list, \URL::to('/ccm/system/file/folder/contents')); if ($filters) { $ilr->setFilters($filters); } } $breadcrumb = []; if ($folder->getTreeNodeParentID() > 0) { $nodes = array_reverse($folder->getTreeNodeParentArray()); $ilr->setFolder($folder); foreach ($nodes as $node) { $breadcrumb[] = ['active' => false, 'name' => $node->getTreeNodeDisplayName(), 'folder' => $node->getTreeNodeID(), 'url' => (string) \URL::to('/ccm/system/file/folder/contents'), 'menu' => $node->getTreeNodeMenu()]; } $breadcrumb[] = ['active' => true, 'name' => $folder->getTreeNodeDisplayName(), 'folder' => $folder->getTreeNodeID(), 'menu' => $folder->getTreeNodeMenu(), 'url' => (string) \URL::to('/ccm/system/file/folder/contents')]; } $ilr->setBreadcrumb($breadcrumb); $this->result = $ilr; }
public function form($additionalClass = false) { $this->load(); $this->requireAsset('core/topics'); $this->requireAsset('javascript', 'jquery/form'); if (is_object($this->attributeValue)) { $valueIDs = array(); foreach ($this->attributeValue->getValueObject()->getSelectedTopics() as $value) { $valueID = $value->getTreeNodeID(); $withinParentScope = false; $nodeObj = TreeNode::getByID($value->getTreeNodeID()); if (is_object($nodeObj)) { $parentNodeArray = $nodeObj->getTreeNodeParentArray(); // check to see if selected node is still within parent scope, in case it has been changed. foreach ($parentNodeArray as $parent) { if ($parent->treeNodeID == $this->akTopicParentNodeID) { $withinParentScope = true; break; } } if ($withinParentScope) { $valueIDs[] = $valueID; } } } $this->set('valueIDs', implode(',', $valueIDs)); } $this->set('valueIDArray', $valueIDs); $ak = $this->getAttributeKey(); $this->set('akID', $ak->getAttributeKeyID()); $this->set('parentNode', $this->akTopicParentNodeID); $this->set('treeID', $this->akTopicTreeID); }
/** * Removes a file, including all of its versions. */ public function delete($removeNode = true) { // first, we remove all files from the drive $db = Loader::db(); $em = $db->getEntityManager(); // fire an on_page_delete event $fve = new \Concrete\Core\File\Event\DeleteFile($this); $fve = Events::dispatch('on_file_delete', $fve); if (!$fve->proceed()) { return false; } // Delete the tree node for the file. if ($removeNode) { $nodeID = $db->fetchColumn('select treeNodeID from TreeFileNodes where fID = ?', [$this->getFileID()]); if ($nodeID) { $node = Node::getByID($nodeID); $node->delete(); } } $versions = $this->getVersionList(); foreach ($versions as $fv) { $fv->delete(true); } $db->Execute("delete from FileSetFiles where fID = ?", [$this->fID]); $db->Execute("delete from FileSearchIndexAttributes where fID = ?", [$this->fID]); $db->Execute("delete from DownloadStatistics where fID = ?", [$this->fID]); $db->Execute("delete from FilePermissionAssignments where fID = ?", [$this->fID]); $query = $em->createQuery('select fav from Concrete\\Core\\Entity\\Attribute\\Value\\Value\\ImageFileValue fav inner join fav.file f where f.fID = :fID'); $query->setParameter('fID', $this->getFileID()); $values = $query->getResult(); foreach ($values as $genericValue) { foreach (Category::getList() as $category) { $category = $category->getController(); /** * @var $category AbstractCategory */ $values = $category->getAttributeValueRepository()->findBy(['generic_value' => $genericValue]); foreach ($values as $attributeValue) { $category->deleteValue($attributeValue); } } } $db->Execute("delete from Files where fID = ?", [$this->fID]); }
<?php defined('C5_EXECUTE') or die("Access Denied."); use Concrete\Core\Tree\Node\Node as TreeNode; $sourceNode = TreeNode::getByID(Loader::helper('security')->sanitizeInt($_REQUEST['sourceTreeNodeID'])); $destNode = TreeNode::getByID(Loader::helper('security')->sanitizeInt($_REQUEST['treeNodeParentID'])); if (is_object($sourceNode) && is_object($destNode)) { $sp = new Permissions($sourceNode); $dp = new Permissions($destNode); if ($dp->canAddTreeSubNode()) { $sourceNode->move($destNode); $destNode->saveChildOrder($_POST['treeNodeID']); print Loader::helper('ajax')->sendResult($destNode->getTreeNodeJSON()); } else { $r = new stdClass(); $r->error = true; $r->message = t('You do not have permission to drag this node here.'); print Loader::helper('ajax')->sendResult($r); } }
public function edit() { $this->loadResultsFolderInformation(); $this->requireAsset('core/tree'); $this->clearSessionControls(); $list = Type::getList(); $attribute_fields = array(); foreach ($list as $type) { $attribute_fields[] = ['id' => 'attribute_key|' . $type->getAttributeTypeID(), 'displayName' => $type->getAttributeTypeDisplayName()]; } $select = array(); $select[0] = new \stdClass(); $select[0]->label = t('Input Field Types'); $select[0]->fields = $attribute_fields; $other_fields = array(); $other_fields[] = ['id' => 'entity_property|text', 'displayName' => t('Display Text')]; $select[1] = new \stdClass(); $select[1]->label = t('Other Fields'); $select[1]->fields = $other_fields; $controls = array(); $form = $this->getFormEntity(); if (is_object($form)) { $entity = $form->getEntity(); $controls = $form->getControls(); $this->set('formName', $entity->getName()); $this->set('submitLabel', $this->submitLabel); $node = Node::getByID($entity->getEntityResultsNodeId()); if (is_object($node)) { $folder = $node->getTreeNodeParentObject(); $this->set('resultsFolder', $folder->getTreeNodeID()); } } $this->set('controls', $controls); $this->set('types_select', $select); $tree = ExpressEntryResults::get(); $this->set('tree', $tree); }
<?php defined('C5_EXECUTE') or die("Access Denied."); use Concrete\Core\Tree\Tree; use Concrete\Core\Tree\Node\Node as TreeNode; $form = Loader::helper('form'); $treeID = Loader::helper('security')->sanitizeInt($_REQUEST['treeID']); $tree = Tree::getByID($treeID); if (!is_object($tree)) { exit; } if (is_array($_REQUEST['treeNodeSelectedIDs'])) { $selectedIDs = array(); foreach ($_REQUEST['treeNodeSelectedIDs'] as $nID) { $node = TreeNode::getByID($nID); if (is_object($node) && $node->getTreeID() == $tree->getTreeID()) { $selectedIDs[] = $node->getTreeNodeID(); } } $tree->setSelectedTreeNodeIDs($selectedIDs); } $tree->setRequest($_REQUEST); $result = $tree->getJSON(); print Loader::helper('ajax')->sendResult($result);
} while (file_exists($fpath . '/' . $fname)); } } //else { // if we can't get the filename from the file itself OR from the mime-type I'm not sure there's much else we can do //} if (strlen($fname)) { // write the downloaded file to a temporary location on disk $handle = fopen($fpath . '/' . $fname, "w"); fwrite($handle, $response->getBody()); fclose($handle); // import the file into concrete if ($fp->canAddFileType($cf->getExtension($fname))) { $folder = null; if (isset($_POST['currentFolder'])) { $node = \Concrete\Core\Tree\Node\Node::getByID($_POST['currentFolder']); if ($node instanceof \Concrete\Core\Tree\Node\Type\FileFolder) { $folder = $node; } } if (!$fr && $folder) { $fr = $folder; } $fi = new FileImporter(); $resp = $fi->import($fpath . '/' . $fname, $fname, $fr); $r->setMessage(t('File uploaded successfully.')); if (is_object($fr)) { $r->setMessage(t('File replaced successfully.')); } } else { $resp = FileImporter::E_FILE_INVALID_EXTENSION;
<?php defined('C5_EXECUTE') or die("Access Denied."); use Concrete\Core\Tree\Node\Node as TreeNode; if ($_REQUEST['treeNodeID'] > 0) { $node = TreeNode::getByID($_REQUEST['treeNodeID']); $np = new Permissions($node); if ($np->canEditTreeNodePermissions()) { Loader::element('permission/details/tree/node', array("node" => $node)); } }
public function getRootTreeNodeObject() { return TreeNode::getByID($this->rootTreeNodeID); }
<?php defined('C5_EXECUTE') or die("Access Denied."); $form = Loader::helper('form'); $node = \Concrete\Core\Tree\Node\Node::getByID(Loader::helper('security')->sanitizeInt($_REQUEST['treeNodeID'])); $np = new Permissions($node); $tree = $node->getTreeObject(); $canEdit = is_object($node) && $node->getTreeNodeTypeHandle() == 'topic' && $np->canEditTreeNode(); $url = View::url('/dashboard/system/attributes/topics', 'update_topic_node'); $al = Loader::helper("concrete/asset_library"); if ($canEdit) { ?> <div class="ccm-ui"> <form method="post" data-topic-form="update-topic-node" class="form-horizontal" action="<?php echo $url; ?> "> <?php echo Loader::helper('validation/token')->output('update_topic_node'); ?> <input type="hidden" name="treeNodeID" value="<?php echo $node->getTreeNodeID(); ?> " /> <div class="form-group"> <?php echo $form->label('treeNodeTopicName', t('Topic')); ?> <?php echo $form->text('treeNodeTopicName', $node->getTreeNodeDisplayName(), array('class' => 'span4'));
public function getRootTreeNodeObject() { return \Concrete\Core\Tree\Node\Node::getByID($this->rootTreeNodeID); }