public function transfer($signature, $target = null, array $args = array()) { $result = false; $metadata = $this->info($signature); if (!empty($metadata)) { /** @var modTransportPackage $package */ $package = $this->xpdo->newObject('transport.modTransportPackage'); $package->set('signature', $signature); $package->set('state', 1); $package->set('workspace', 1); $package->set('created', date('Y-m-d h:i:s')); $package->set('provider', $this->get('id')); $package->set('metadata', $metadata); $package->set('package_name', $metadata['name']); $package->parseSignature(); $package->setPackageVersionData(); $locationArgs = isset($metadata['file']) ? array_merge($metadata['file'], $args) : $args; $url = $this->downloadUrl($signature, $this->arg('location', $locationArgs), $args); if (!empty($url)) { if (empty($target)) { $target = $this->xpdo->getOption('core_path', $args, MODX_CORE_PATH) . 'packages/'; } if ($package->transferPackage($url, $target)) { if ($package->save()) { $package->getTransport(); $result = $package; } } } } return $result; }
/** * Overrides xPDOObject::save to handle closure table edits. * * @param boolean $cacheFlag * @return boolean */ public function save($cacheFlag = null) { $new = $this->isNew(); if ($new) { if (!$this->get('createdon')) { $this->set('createdon', strftime('%Y-%m-%d %H:%M:%S')); } $ip = $this->get('ip'); if (empty($ip) && !empty($_SERVER['REMOTE_ADDR'])) { $this->set('ip', $_SERVER['REMOTE_ADDR']); } } $saved = parent::save($cacheFlag); if ($saved && $new) { $id = $this->get('id'); $parent = $this->get('parent'); /* create self closure */ $cl = $this->xpdo->newObject('quipCommentClosure'); $cl->set('ancestor', $id); $cl->set('descendant', $id); if ($cl->save() === false) { $this->remove(); return false; } /* create closures and calculate rank */ $c = $this->xpdo->newQuery('quipCommentClosure'); $c->where(array('descendant' => $parent, 'ancestor:!=' => 0)); $c->sortby('depth', 'DESC'); $gparents = $this->xpdo->getCollection('quipCommentClosure', $c); $cgps = count($gparents); $gps = array(); $i = $cgps; /** @var quipCommentClosure $gparent */ foreach ($gparents as $gparent) { $gps[] = str_pad($gparent->get('ancestor'), 10, '0', STR_PAD_LEFT); /** @var quipCommentClosure $obj */ $obj = $this->xpdo->newObject('quipCommentClosure'); $obj->set('ancestor', $gparent->get('ancestor')); $obj->set('descendant', $id); $obj->set('depth', $i); $obj->save(); $i--; } $gps[] = str_pad($id, 10, '0', STR_PAD_LEFT); /* add self closure too */ /* add root closure */ /** @var quipCommentClosure $cl */ $cl = $this->xpdo->newObject('quipCommentClosure'); $cl->set('ancestor', 0); $cl->set('descendant', $id); $cl->set('depth', $cgps); $cl->save(); /* set rank */ $rank = implode('-', $gps); $this->set('rank', $rank); $this->save(); } return $saved; }
/** * Join a User Group, and optionally assign a Role. * * @access public * @param mixed $groupId Either the name or ID of the User Group to join. * @param mixed $roleId Optional. Either the name or ID of the Role to * @param integer $rank Optional. * assign to for the group. * @return boolean True if successful. */ public function joinGroup($groupId, $roleId = null, $rank = null) { $joined = false; $groupPk = is_string($groupId) ? array('name' => $groupId) : $groupId; /** @var modUserGroup $userGroup */ $userGroup = $this->xpdo->getObject('modUserGroup', $groupPk); if (empty($userGroup)) { $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'User Group not found with key: ' . $groupId); return $joined; } /** @var modUserGroupRole $role */ if (!empty($roleId)) { $rolePk = is_string($roleId) ? array('name' => $roleId) : $roleId; $role = $this->xpdo->getObject('modUserGroupRole', $rolePk); if (empty($role)) { $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Role not found with key: ' . $role); return $joined; } } /** @var modUserGroupMember $member */ $member = $this->xpdo->getObject('modUserGroupMember', array('member' => $this->get('id'), 'user_group' => $userGroup->get('id'))); if (empty($member)) { if ($rank == null) { $rank = count($this->getMany('UserGroupMembers')); } $member = $this->xpdo->newObject('modUserGroupMember'); $member->set('member', $this->get('id')); $member->set('user_group', $userGroup->get('id')); $member->set('rank', $rank); if (!empty($role)) { $member->set('role', $role->get('id')); } $joined = $member->save(); if (!$joined) { $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'An unknown error occurred preventing adding the User to the User Group.'); } else { unset($_SESSION["modx.user.{$this->get('id')}.userGroupNames"], $_SESSION["modx.user.{$this->get('id')}.userGroups"]); } } else { $joined = true; } return $joined; }
} else { $xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not remove core/ and core.transport.zip before starting build.'); flush(); } /* create core transport package */ $package = new xPDOTransport($xpdo, 'core', $packageDirectory); unset($packageDirectory); $xpdo->setPackage('modx', MODX_CORE_PATH . 'model/'); $xpdo->loadClass('modAccess'); $xpdo->loadClass('modAccessibleObject'); $xpdo->loadClass('modAccessibleSimpleObject'); $xpdo->loadClass('modPrincipal'); $xpdo->log(xPDO::LOG_LEVEL_INFO, 'Core transport package created.'); flush(); /* core namespace */ $namespace = $xpdo->newObject('modNamespace'); $namespace->set('name', 'core'); $namespace->set('path', '{core_path}'); $namespace->set('assets_path', '{assets_path}'); $package->put($namespace, array(xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => true)); unset($namespace); $xpdo->log(xPDO::LOG_LEVEL_INFO, 'Core Namespace packaged.'); flush(); /* modWorkspace */ $collection = array(); $collection['1'] = $xpdo->newObject('modWorkspace'); $collection['1']->fromArray(array('id' => 1, 'name' => 'Default MODX workspace', 'path' => '{core_path}', 'active' => 1), '', true, true); $attributes = array(xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => false); foreach ($collection as $c) { $package->put($c, $attributes); }
/** * @param string $tpl * @param array $placeholders * @return string */ public function getFileChunk($tpl, array $placeholders = array()) { $output = ''; $file = $tpl; if (!file_exists($file)) { $file = $this->modx->getOption('manager_path') . 'templates/' . $this->modx->getOption('manager_theme', null, 'default') . '/' . $tpl; } if (!file_exists($file)) { $file = $this->modx->getOption('manager_path') . 'templates/default/' . $tpl; } if (file_exists($file)) { /** @var modChunk $chunk */ $chunk = $this->modx->newObject('modChunk'); $chunk->setCacheable(false); $tplContent = file_get_contents($file); $chunk->setContent($tplContent); $output = $chunk->process($placeholders); } return $output; }
/** * Mark all posts in this thread as read * @static * @param xPDO $modx * @param string $type * @return bool */ public static function readAll(xPDO &$modx, $type = 'message') { $userId = $modx->discuss->user->get('id'); $sql = 'SELECT `disThread`.`id` FROM ' . $modx->getTableName('disThread') . ' `disThread` INNER JOIN ' . $modx->getTableName('disThreadUser') . ' `ThreadUser` ON `ThreadUser`.`thread` = `disThread`.`id` LEFT JOIN ' . $modx->getTableName('disThreadRead') . ' `ThreadRead` ON `ThreadRead`.`thread` = `disThread`.`id` WHERE `ThreadUser`.`user` = ' . $userId . ' AND `ThreadRead`.`id` IS NULL AND `private` = 1 ORDER BY `disThread`.`id` DESC'; $stmt = $modx->query($sql); if (!$stmt) { return false; } while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $read = $modx->getCount('disThreadRead', array('thread' => $row['id'], 'user' => $userId)); if ($read == 0) { $read = $modx->newObject('disThreadRead'); $read->fromArray(array('thread' => $row['id'], 'board' => 0, 'user' => $userId)); $read->save(); } } $stmt->closeCursor(); return true; }