Skip to content

Commit

Permalink
Some fixes + added i18n + added automatic redirection to CMPs
Browse files Browse the repository at this point in the history
  • Loading branch information
Romain Tripault committed Jun 24, 2011
1 parent 9e3af73 commit 95b8dcf
Show file tree
Hide file tree
Showing 13 changed files with 675 additions and 13 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
## cmpLauncher

cmpLauncher is an Extra for MODX Revolution CMF (http://modx.com).
It allows you to display a link to a particular CMP (Component/Extra page) based
on the template ID or the resource ID you are editing.
It allows you to display a link or redirect a user to a particular CMP (Component/Extra page)
based on the template ID or the resource ID you are editing.

## Usage

Once installed (via the package manager) edit the plugin property named "cmp" (check http://rtfm.modx.com/display/revolution20/Properties+and+Property+Sets#PropertiesandPropertySets-AssigningPropertySetstoElements for more infos on properties)
and use the following syntax:

`t:id:id,r:id:id,…`
`t:id:id,r:id:id:1,…`

Parameters:

* the first one is the constraint (t stand for template, r for resource)
* the second one is the template or resource ID
* the third one is the action ID
* the fourth parameter, if set, enables the automatic redirection to the CMP

Please, for now declare resources constraints after all your templates ones so
they can override. For example, let's say you want all resources using template ID 3
provide a link to the action ID 80, but you want the resource ID 20 (which uses the
template ID 3) to provide a link to action 79, you would have to use:
template ID 3) to automaticly redirect the user to action 79, you would have to use:

`t:3:80,r:20:79`
`t:3:80,r:20:79:1`


## Credits & support
Expand Down
38 changes: 38 additions & 0 deletions _build/build.config.sample.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* cmpLauncher
*
* Copyright 2011 by Romain Tripault // Melting Media <[email protected]>
*
* cmpLauncher is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* cmpLauncher is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* cmpLauncher; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*
* @package cmplauncher
*/
/**
* Define the MODX path constants necessary for installation
*
* @package cmplauncher
* @subpackage build
*/
define('MODX_BASE_PATH', dirname(dirname(dirname(dirname(__FILE__)))) . '/modx/');
define('MODX_CORE_PATH', MODX_BASE_PATH . 'core/');
define('MODX_MANAGER_PATH', MODX_BASE_PATH . 'manager/');
define('MODX_CONNECTORS_PATH', MODX_BASE_PATH . 'connectors/');
define('MODX_ASSETS_PATH', MODX_BASE_PATH . 'assets/');

define('MODX_BASE_URL','/modx/');
define('MODX_CORE_URL', MODX_BASE_URL . 'core/');
define('MODX_MANAGER_URL', MODX_BASE_URL . 'manager/');
define('MODX_CONNECTORS_URL', MODX_BASE_URL . 'connectors/');
define('MODX_ASSETS_URL', MODX_BASE_URL . 'assets/');
146 changes: 146 additions & 0 deletions _build/build.transport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<?php
/**
* cmpLauncher
*
* Copyright 2011 by Romain Tripault // Melting Media <[email protected]>
*
* cmpLauncher is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* cmpLauncher is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* cmpLauncher; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*
* @package cmplauncher
*/
/**
* cmpLauncher build script
*
* @package cmplauncher
* @subpackage build
*/
$mtime = microtime();
$mtime = explode(' ', $mtime);
$mtime = $mtime[1] + $mtime[0];
$tstart = $mtime;
set_time_limit(0);

/* define package */
define('PKG_NAME','cmpLauncher');
define('PKG_NAME_LOWER',strtolower(PKG_NAME));
define('PKG_VERSION','1.0.0');
define('PKG_RELEASE','beta2');

/* define sources */
$root = dirname(dirname(__FILE__)).'/';
$sources = array(
'root' => $root,
'build' => $root . '_build/',
'data' => $root . '_build/data/',
'resolvers' => $root . '_build/resolvers/',
'chunks' => $root.'core/components/'.PKG_NAME_LOWER.'/elements/chunks/',
'snippets' => $root.'core/components/'.PKG_NAME_LOWER.'/elements/snippets/',
'plugins' => $root.'core/components/'.PKG_NAME_LOWER.'/elements/plugins/',
'lexicon' => $root . 'core/components/'.PKG_NAME_LOWER.'/lexicon/',
'docs' => $root.'core/components/'.PKG_NAME_LOWER.'/docs/',
'pages' => $root.'core/components/'.PKG_NAME_LOWER.'/elements/pages/',
'source_assets' => $root.'assets/components/'.PKG_NAME_LOWER,
'source_core' => $root.'core/components/'.PKG_NAME_LOWER,
);
unset($root);

/* override with your own defines here (see build.config.sample.php) */
require_once $sources['build'] . '/build.config.php';
require_once MODX_CORE_PATH . 'model/modx/modx.class.php';
require_once $sources['build'] . '/includes/functions.php';

$modx= new modX();
$modx->initialize('mgr');
echo '<pre>'; /* used for nice formatting of log messages */
$modx->setLogLevel(modX::LOG_LEVEL_INFO);
$modx->setLogTarget('ECHO');

$modx->loadClass('transport.modPackageBuilder','',false, true);
$builder = new modPackageBuilder($modx);
$builder->createPackage(PKG_NAME_LOWER,PKG_VERSION,PKG_RELEASE);
$builder->registerNamespace(PKG_NAME_LOWER,false,true,'{core_path}components/'.PKG_NAME_LOWER.'/');
$modx->log(modX::LOG_LEVEL_INFO,'Created Transport Package and Namespace.');

/* create the plugin object */
$plugin= $modx->newObject('modPlugin');
$plugin->set('id',1);
$plugin->set('name', PKG_NAME);
$plugin->set('description', 'cmpLauncher allows you to display a link or redirect a user to a particular CMP.');
$plugin->set('plugincode', getSnippetContent($sources['plugins'] . '/plugin.cmplauncher.php'));
$plugin->set('category', 0);

/* add plugin events */
$events = include $sources['data'].'transport.plugin.events.php';
if (is_array($events) && !empty($events)) {
$plugin->addMany($events);
$modx->log(xPDO::LOG_LEVEL_INFO,'Packaged in '.count($events).' Plugin Events.'); flush();
} else {
$modx->log(xPDO::LOG_LEVEL_ERROR,'Could not find plugin events!');
}
unset($events);

/* load plugin properties */
$properties = include $sources['build'].'properties/properties.cmpLauncher.php';
if (is_array($properties)) {
$modx->log(xPDO::LOG_LEVEL_INFO,'Set '.count($properties).' plugin properties.'); flush();
$plugin->setProperties($properties);
} else {
$modx->log(xPDO::LOG_LEVEL_ERROR,'Could not set plugin properties.');
}

$attributes= array(
xPDOTransport::UNIQUE_KEY => 'name',
xPDOTransport::PRESERVE_KEYS => false,
xPDOTransport::UPDATE_OBJECT => true,
xPDOTransport::RELATED_OBJECTS => true,
xPDOTransport::RELATED_OBJECT_ATTRIBUTES => array (
'PluginEvents' => array(
xPDOTransport::PRESERVE_KEYS => true,
xPDOTransport::UPDATE_OBJECT => false,
xPDOTransport::UNIQUE_KEY => array('pluginid','event'),
),
),
);
$vehicle = $builder->createVehicle($plugin, $attributes);
$vehicle->resolve('file',array(
'source' => $sources['source_assets'],
'target' => "return MODX_ASSETS_PATH . 'components/';",
));
$vehicle->resolve('file',array(
'source' => $sources['source_core'],
'target' => "return MODX_CORE_PATH . 'components/';",
));
$builder->putVehicle($vehicle);

/* now pack in the license file, readme and setup options */
$builder->setPackageAttributes(array(
'license' => file_get_contents($sources['docs'] . 'license.txt'),
'readme' => file_get_contents($sources['docs'] . 'readme.txt'),
));
$modx->log(modX::LOG_LEVEL_INFO,'Added package attributes and setup options.');

/* zip up package */
$modx->log(modX::LOG_LEVEL_INFO,'Packing up transport package zip...');
$builder->pack();

$mtime= microtime();
$mtime= explode(" ", $mtime);
$mtime= $mtime[1] + $mtime[0];
$tend= $mtime;
$totalTime= ($tend - $tstart);
$totalTime= sprintf("%2.4f s", $totalTime);

$modx->log(modX::LOG_LEVEL_INFO,"\n<br />Package Built.<br />\nExecution time: {$totalTime}\n");

exit ();
38 changes: 38 additions & 0 deletions _build/data/transport.plugin.events.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* cmpLauncher
*
* Copyright 2011 by Romain Tripault // Melting Media <[email protected]>
*
* cmpLauncher is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* cmpLauncher is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* cmpLauncher; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*
* @package cmplauncher
*/
/**
* Add plugins to build
*
* @package cmplauncher
* @subpackage build
*/
$events = array();

$events['OnDocFormPrerender']= $modx->newObject('modPluginEvent');
$events['OnDocFormPrerender']->fromArray(array(
'event' => 'OnDocFormPrerender',
'priority' => 0,
'propertyset' => 0,
),'',true,true);


return $events;
13 changes: 13 additions & 0 deletions _build/includes/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/**
* Required function(s) to build transport packages
*
* Copyright 2011 by Shaun McCormick <[email protected]>
*/
function getSnippetContent($filename) {
$o = file_get_contents($filename);
$o = str_replace('<?php','',$o);
$o = str_replace('?>','',$o);
$o = trim($o);
return $o;
}
47 changes: 47 additions & 0 deletions _build/properties/properties.cmpLauncher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* cmpLauncher
*
* Copyright 2011 by Romain Tripault // Melting Media <[email protected]>
*
* cmpLauncher is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* cmpLauncher is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* cmpLauncher; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*
* @package cmplauncher
*/
/**
* Properties for the cmpLauncher plugin.
*
* @package cmplauncher
* @subpackage build
*/
$properties = array(
array(
'name' => 'debug',
'desc' => 'Enable debugging',
'type' => 'combo-boolean',
'options' => '',
'value' => '',
//'lexicon' => 'cmplauncher:properties',
),
array(
'name' => 'cmp',
'desc' => 'Set your constraints here',
'type' => 'textfield',
'options' => '',
'value' => '',
//'lexicon' => 'cmplauncher:properties',
),
);

return $properties;
7 changes: 6 additions & 1 deletion assets/components/cmplauncher/css/cmplauncher.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
position: absolute;
z-index: 12;
/**/
right: 460px;
right: 35px;
top: 45px;
/*height: 42px;*/
}
#cmp-launcher a {
Expand All @@ -20,4 +21,8 @@
}
#cmp-launcher a:hover {
border: 1px solid #9caf78;
}
#cmp-launcher a:focus, #cmp-launcher a:active {
background-color: #c1c1c1;
margin: 1px 0 -1px;
}
12 changes: 12 additions & 0 deletions core/components/cmplauncher/docs/changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Changelog for cmpLauncher.

2011/06/24 1.0.0-beta2
========================================================
- Added support for i18n
- Introduced automatic redirection to the CMPs
- Refactored the CSS that was causin issues with MODX
manager using a foreign language

2011/06/24 1.0.0-beta1
========================================================
- Initial release.
Loading

0 comments on commit 95b8dcf

Please sign in to comment.