本文整理汇总了PHP中modX::newObject方法的典型用法代码示例。如果您正苦于以下问题:PHP modX::newObject方法的具体用法?PHP modX::newObject怎么用?PHP modX::newObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类modX
的用法示例。
在下文中一共展示了modX::newObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add
public static function add(phpThumbOn $ThumbOn, modX $modx)
{
$from = $ThumbOn->getOption('input');
$to = $ThumbOn->getOption('_cacheFileName');
$options = $ThumbOn->getOption('_options', array('f' => $ThumbOn::DEFAULT_EXT));
$noImage = $ThumbOn->getOption('noimage');
$modx->addPackage("phpthumbon", $ThumbOn->getOption('modelPath'));
switch ($ThumbOn->getOption('queue')) {
case 2:
//Отправляем в очередь и сжимаем картику noimage
$path = $ThumbOn->getOption('assetsPath', MODX_BASE_PATH . '/assets/') . "/components/phpthumbon/cache/";
$tmp = md5(serialize($options)) . "." . $options['f'];
$ThumbOn->makeDir($path);
if (file_exists($path . $tmp)) {
copy($path . $tmp, $to);
} else {
if ($to = $ThumbOn->loadResizer($noImage, $to)) {
copy($to, $path . $tmp);
}
}
$modx->newObject("ThumbImages", array('image' => $from, 'cache_image' => $to, 'config' => $options, 'isend' => $from == $noImage))->save();
break;
case 1:
default:
//Отправляем в очередь и сразу отдаем картинку noimage
if (!file_exists($to)) {
copy($noImage, $to);
}
$modx->newObject("ThumbImages", array('image' => $from, 'cache_image' => $to, 'config' => $options, 'isend' => 0))->save();
break;
}
return $to;
}
示例2: _getTplChunk
/**
* Returns a modChunk object from a template file.
*
* @access private
* @param string $name The name of the Chunk. Will parse to name.chunk.tpl by default.
* @param string $suffix The suffix to add to the chunk filename.
* @return modChunk/boolean Returns the modChunk object if found, otherwise
* false.
*/
private function _getTplChunk($name, $suffix = '.chunk.tpl')
{
$chunk = false;
$f = $this->config['chunksPath'] . strtolower($name) . $suffix;
if (file_exists($f)) {
$o = file_get_contents($f);
/** @var modChunk $chunk */
$chunk = $this->modx->newObject('modChunk');
$chunk->set('name', $name);
$chunk->setContent($o);
}
return $chunk;
}
示例3: getElement
/**
* Get a modElement instance taking advantage of the modX::$sourceCache.
*
* @param string $class The modElement derivative class to load.
* @param string $name An element name or raw tagName to identify the modElement instance.
* @return modElement|null An instance of the specified modElement derivative class.
*/
public function getElement($class, $name)
{
$realname = $this->realname($name);
if (array_key_exists($class, $this->modx->sourceCache) && array_key_exists($realname, $this->modx->sourceCache[$class])) {
/** @var modElement $element */
$element = $this->modx->newObject($class);
$element->fromArray($this->modx->sourceCache[$class][$realname]['fields'], '', true, true);
$element->setPolicies($this->modx->sourceCache[$class][$realname]['policies']);
if (!empty($this->modx->sourceCache[$class][$realname]['source'])) {
if (!empty($this->modx->sourceCache[$class][$realname]['source']['class_key'])) {
$sourceClassKey = $this->modx->sourceCache[$class][$realname]['source']['class_key'];
$this->modx->loadClass('sources.modMediaSource');
/* @var modMediaSource $source */
$source = $this->modx->newObject($sourceClassKey);
$source->fromArray($this->modx->sourceCache[$class][$realname]['source'], '', true, true);
$element->addOne($source, 'Source');
}
}
} else {
/** @var modElement $element */
$element = $this->modx->getObjectGraph($class, array('Source' => array()), array('name' => $realname), true);
if ($element && array_key_exists($class, $this->modx->sourceCache)) {
$this->modx->sourceCache[$class][$realname] = array('fields' => $element->toArray(), 'policies' => $element->getPolicies(), 'source' => $element->Source ? $element->Source->toArray() : array());
}
}
if ($element instanceof modElement) {
$element->set('name', $name);
}
return $element;
}
示例4: transfer
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;
}
示例5: postInstall
public function postInstall()
{
/* fix settings_version */
/** @var \modSystemSetting $object */
$object = $this->xpdo->getObject('modSystemSetting', array('key' => 'settings_version'));
if (!$object) {
$object = $this->xpdo->newObject('modSystemSetting');
$object->fromArray(array('key' => 'settings_version', 'area' => 'system', 'namespace' => 'core', 'xtype' => 'textfield'), '', true);
}
$object->set('value', $this->xpdo->version['full_version']);
$object->save(false);
/* fix session_cookie_domain */
$object = $this->xpdo->getObject('modSystemSetting', array('key' => 'session_cookie_domain'));
if (!$object) {
$object = $this->xpdo->newObject('modSystemSetting');
$object->fromArray(array('key' => 'session_cookie_domain', 'area' => 'session', 'namespace' => 'core', 'xtype' => 'textfield'), '', true);
}
$object->set('value', '');
$object->save(false);
/* fix session_cookie_path */
$object = $this->xpdo->getObject('modSystemSetting', array('key' => 'session_cookie_path'));
if (!$object) {
$object = $this->xpdo->newObject('modSystemSetting');
$object->fromArray(array('key' => 'session_cookie_path', 'area' => 'session', 'namespace' => 'core', 'xtype' => 'textfield'), '', true);
}
$object->set('value', $this->xpdo->getOption('base_url', null, MODX_BASE_URL));
$object->save(false);
}
示例6: getStatistics
/**
* Get the statistics for the bottom area of the forums
* @return void
*/
protected function getStatistics()
{
$this->setPlaceholder('totalPosts', number_format((int) $this->getPostCount()));
$this->setPlaceholder('totalTopics', number_format((int) $this->getThreadCount()));
$this->setPlaceholder('totalMembers', number_format((int) $this->modx->getCount('disUser')));
/* active in last 40 */
if ($this->modx->getOption('discuss.show_whos_online', null, true)) {
$this->setPlaceholder('activeUsers', $this->discuss->hooks->load('user/active_in_last'));
} else {
$this->setPlaceholder('activeUsers', '');
}
/* total active */
$this->setPlaceholder('totalMembersActive', number_format((int) $this->modx->getCount('disSession', array('user:!=' => 0))));
$this->setPlaceholder('totalVisitorsActive', number_format((int) $this->modx->getCount('disSession', array('user' => 0))));
/**
* forum activity
* @var disForumActivity $activity
*/
$activity = $this->modx->getObject('disForumActivity', array('day' => date('Y-m-d')));
if (!$activity) {
$activity = $this->modx->newObject('disForumActivity');
$activity->set('day', date('Y-m-d'));
$activity->save();
}
$this->setPlaceholders($activity->toArray('activity.'));
}
示例7: post
/**
* Method for routing POST requests. Can be overridden; default behavior automates xPDOObject, class-based requests.
* @abstract
*/
public function post()
{
$properties = $this->getProperties();
if (!empty($this->postRequiredFields)) {
if (!$this->checkRequiredFields($this->postRequiredFields)) {
return $this->failure($this->modx->lexicon('error'));
}
}
if (!empty($this->postRequiredRelatedObjects)) {
if (!$this->checkRequiredRelatedObjects($this->postRequiredRelatedObjects)) {
return $this->failure();
}
}
/** @var xPDOObject $object */
$this->object = $this->modx->newObject($this->classKey);
$this->object->fromArray($properties);
$beforePost = $this->beforePost();
if ($beforePost !== true && $beforePost !== null) {
return $this->failure($beforePost === false ? $this->errorMessage : $beforePost);
}
if (!$this->object->{$this->postMethod}()) {
$this->setObjectErrors();
if ($this->hasErrors()) {
return $this->failure();
} else {
return $this->failure($this->modx->lexicon('rest.err_class_save', array('class_key' => $this->classKey)));
}
}
$objectArray = $this->object->toArray();
$this->afterPost($objectArray);
return $this->success('', $objectArray);
}
示例8: checkPermissions
/**
* Checks user permissions to view the results
*
* @param array $rows
*
* @return array
*/
public function checkPermissions($rows = array())
{
$permissions = array();
if (!empty($this->config['checkPermissions'])) {
$tmp = array_map('trim', explode(',', $this->config['checkPermissions']));
foreach ($tmp as $v) {
$permissions[$v] = true;
}
} else {
return $rows;
}
$total = $this->modx->getPlaceholder($this->config['totalVar']);
foreach ($rows as $key => $row) {
/** @var modAccessibleObject $object */
$object = $this->modx->newObject($this->config['class']);
$object->_fields['id'] = $row['id'];
if ($object instanceof modAccessibleObject && !$object->checkPolicy($permissions)) {
unset($rows[$key]);
$this->addTime($this->config['class'] . ' #' . $row['id'] . ' was excluded from results, because you do not have enough permissions');
$total--;
}
}
$this->addTime('Checked for permissions "' . implode(',', array_keys($permissions)) . '"');
$this->modx->setPlaceholder($this->config['totalVar'], $total);
return $rows;
}
示例9: makeArchive
/**
* Setup this resource as an archive so that FURLs can be effectively mapped
*
* @param integer $resourceId The ID of the resource to allow as an archive
* @param string $prefix The filterPrefix used by that archive
*/
public function makeArchive($resourceId, $prefix = 'arc_')
{
$value = $resourceId . ':' . $prefix;
$isNew = false;
$setting = $this->modx->getObject('modSystemSetting', array('key' => 'archivist.archive_ids'));
if (!$setting) {
/** @var modSystemSetting $setting */
$setting = $this->modx->newObject('modSystemSetting');
$setting->fromArray(array('key' => 'archivist.archive_ids', 'namespace' => 'archivist', 'area' => 'furls', 'xtype' => 'textfield'), '', true, true);
$isNew = true;
} else {
$oldValue = $setting->get('value');
if (strpos($oldValue, $resourceId . ':') !== false) {
/* dont append if already there */
$value = $oldValue;
} else {
$value = $oldValue . ',' . $value;
}
}
$setting->set('value', $value);
$saved = $setting->save();
if ($isNew) {
$this->_clearCache();
}
return $saved;
}
示例10: save
/**
* 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;
}
示例11: getInstance
public static function getInstance(modX &$modx, $className, $properties = array())
{
$classKey = !empty($properties['class_key']) ? $properties['class_key'] : 'modDocument';
$object = $modx->newObject($classKey);
$className = 'msCategoryDisableCacheCreateProcessor';
$processor = new $className($modx, $properties);
return $processor;
}
示例12: parseChunk
/**
* Parse a chunk (with template bindings)
* Modified parseTplElement method from getResources package (https://github.com/opengeek/getResources)
*
* @param $type
* @param $source
* @param null $properties
* @return bool
*/
private function parseChunk($type, $source, $properties = null)
{
$output = false;
if (!is_string($type) || !in_array($type, $this->_validTypes)) {
$type = $this->modx->getOption('tplType', $properties, '@CHUNK');
}
$content = false;
switch ($type) {
case '@FILE':
$path = $this->modx->getOption('tplPath', $properties, $this->modx->getOption('assets_path', $properties, MODX_ASSETS_PATH) . 'elements/chunks/');
$key = $path . $source;
if (!isset($this->_tplCache['@FILE'])) {
$this->_tplCache['@FILE'] = array();
}
if (!array_key_exists($key, $this->_tplCache['@FILE'])) {
if (file_exists($key)) {
$content = file_get_contents($key);
}
$this->_tplCache['@FILE'][$key] = $content;
} else {
$content = $this->_tplCache['@FILE'][$key];
}
if (!empty($content) && $content !== '0') {
$chunk = $this->modx->newObject('modChunk', array('name' => $key));
$chunk->setCacheable(false);
$output = $chunk->process($properties, $content);
}
break;
case '@INLINE':
$uniqid = uniqid();
$chunk = $this->modx->newObject('modChunk', array('name' => "{$type}-{$uniqid}"));
$chunk->setCacheable(false);
$output = $chunk->process($properties, $source);
break;
case '@CHUNK':
default:
$chunk = null;
if (!isset($this->_tplCache['@CHUNK'])) {
$this->_tplCache['@CHUNK'] = array();
}
if (!array_key_exists($source, $this->_tplCache['@CHUNK'])) {
if ($chunk = $this->modx->getObject('modChunk', array('name' => $source))) {
$this->_tplCache['@CHUNK'][$source] = $chunk->toArray('', true);
} else {
$this->_tplCache['@CHUNK'][$source] = false;
}
} elseif (is_array($this->_tplCache['@CHUNK'][$source])) {
$chunk = $this->modx->newObject('modChunk');
$chunk->fromArray($this->_tplCache['@CHUNK'][$source], '', true, true, true);
}
if (is_object($chunk)) {
$chunk->setCacheable(false);
$output = $chunk->process($properties);
}
break;
}
return $output;
}
示例13: create
/**
* Creates an element object of the specified type
*
* @param modX $modx
* @param string $type
* @param string $name
*
* @return Element | boolean
*/
public static function create(modX $modx, $type, $name)
{
$element = $modx->newObject($type);
$element->set(Element::get_name_field($type), $name);
if ($element->save()) {
return new Element($element);
}
return false;
}
示例14: getRender
/**
* Gets the correct render given paths and type of render
*
* @param array $params The parameters to pass to the render
* @param mixed $value The value of the TV
* @param array $paths An array of paths to search
* @param string $method The type of Render (input/output/properties)
* @param integer $resourceId The ID of the current Resource
* @param string $type The type of render to display
* @return string
*/
public function getRender($params, $value, array $paths, $method, $resourceId = 0, $type = 'text')
{
if (empty($type)) {
$type = 'text';
}
if (empty($this->xpdo->resource)) {
if (!empty($resourceId)) {
$this->xpdo->resource = $this->xpdo->getObject('modResource', $resourceId);
}
if (empty($this->xpdo->resource) || empty($resourceId)) {
$this->xpdo->resource = $this->xpdo->newObject('modResource');
$this->xpdo->resource->set('id', 0);
}
}
if ($className = $this->checkForRegisteredRenderMethod($type, $method)) {
/** @var modTemplateVarOutputRender $render */
$render = new $className($this);
$output = $render->render($value, $params);
} else {
$deprecatedClassName = $method == 'input' ? 'modTemplateVarInputRenderDeprecated' : 'modTemplateVarOutputRenderDeprecated';
$render = new $deprecatedClassName($this);
foreach ($paths as $path) {
$renderFile = $path . $type . '.class.php';
if (file_exists($renderFile)) {
$className = (include $renderFile);
$this->registerRenderMethod($type, $method, $className);
if (class_exists($className)) {
/** @var modTemplateVarOutputRender $render */
$render = new $className($this);
}
break;
}
/* 2.1< backwards compat */
$renderFile = $path . $type . '.php';
if (file_exists($renderFile)) {
$render = new $deprecatedClassName($this);
$params['modx.renderFile'] = $renderFile;
break;
}
}
$output = $render->render($value, $params);
/* if no output, fallback to text */
if (empty($output)) {
$p = $this->xpdo->getOption('processors_path') . 'element/tv/renders/mgr/' . $method . '/';
$className = $method == 'output' ? 'modTemplateVarOutputRenderText' : 'modTemplateVarInputRenderText';
if (!class_exists($className) && file_exists($p . 'text.class.php')) {
$className = (include $p . 'text.class.php');
}
if (class_exists($className)) {
$render = new $className($this);
$output = $render->render($value, $params);
}
}
}
return $output;
}
示例15: getCache
/**
* Retrieve the menus for the given "container"
*
* @param string $name
*
* @return array
*/
protected function getCache($name)
{
$key = $this->getCacheKey($name);
$menus = $this->modx->cacheManager->get($key, array(xPDO::OPT_CACHE_KEY => $this->modx->getOption('cache_menu_key', null, 'menu'), xPDO::OPT_CACHE_HANDLER => $this->modx->getOption('cache_menu_handler', null, $this->modx->getOption(xPDO::OPT_CACHE_HANDLER)), xPDO::OPT_CACHE_FORMAT => (int) $this->modx->getOption('cache_menu_format', null, $this->modx->getOption(xPDO::OPT_CACHE_FORMAT, null, xPDOCacheManager::CACHE_PHP))));
if ($menus == null || !is_array($menus)) {
/** @var modMenu $menu */
$menu = $this->modx->newObject('modMenu');
$menus = $menu->rebuildCache($name);
unset($menu);
}
return $menus;
}