Skip to content

Commit

Permalink
Updated for Redirector 2.0 + many (UI) fixes and new features
Browse files Browse the repository at this point in the history
  • Loading branch information
Bert Oost committed Mar 15, 2014
1 parent 902ceef commit b1ef604
Show file tree
Hide file tree
Showing 46 changed files with 1,405 additions and 534 deletions.
100 changes: 22 additions & 78 deletions _build/build.schema.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,103 +1,47 @@
<?php
/**
* Build Schema script
*
* @package redirector
* @subpackage build
*/
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = $mtime[1] + $mtime[0];
$tstart = $mtime;
set_time_limit(0);

define('PKG_NAME','Redirector');
define('PKG_NAME_LOWER','redirector');
define('PKG_NAME', 'Redirector');
define('PKG_NAME_LOWER', strtolower(PKG_NAME));

require_once dirname(__FILE__).'/build.config.php';
include_once MODX_CORE_PATH . 'model/modx/modx.class.php';
require_once dirname(__FILE__).'/build.properties.php';
$modx= new modX();

$modx = new modX();
$modx->initialize('mgr');
$modx->loadClass('transport.modPackageBuilder','',false, true);
echo '<pre>'; /* used for nice formatting of log messages */
$modx->setLogLevel(modX::LOG_LEVEL_INFO);
$modx->setLogTarget('ECHO');
$modx->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML');

$dbDriver = $modx->config['dbtype'];
$root = dirname(dirname(__FILE__)).'/';
$sources = array(
'root' => $root,
'core' => $root.'core/components/redirector/',
'model' => $root.'core/components/redirector/model/',
'schema' => $root.'core/components/redirector/model/schema/',
'schema_file' => $root.'core/components/redirector/model/schema/redirector.mysql.schema.xml',
'schema_file' => $root.'core/components/redirector/model/schema/redirector.'.$dbDriver.'.schema.xml',
'assets' => $root.'assets/components/redirector/',
);
foreach (array('mysql', 'sqlsrv') as $driver) {
$xpdo= new xPDO(
$properties["{$driver}_string_dsn_nodb"],
$properties["{$driver}_string_username"],
$properties["{$driver}_string_password"],
$properties["{$driver}_array_options"],
$properties["{$driver}_array_driverOptions"]
);
$xpdo->setPackage('modx', dirname(XPDO_CORE_PATH) . '/model/');
$xpdo->setDebug(true);

$manager= $xpdo->getManager();
$generator= $manager->getGenerator();

$manager= $xpdo->getManager();
$generator= $manager->getGenerator();
$manager= $modx->getManager();
$generator= $manager->getGenerator();

$generator->classTemplate= <<<EOD
<?php
/**
* [+phpdoc-package+]
*/
class [+class+] extends [+extends+] {
function [+class+](& \$xpdo) {
\$this->__construct(\$xpdo);
}
function __construct(& \$xpdo) {
parent :: __construct(\$xpdo);
}
}
?>
EOD;
$generator->platformTemplate= <<<EOD
<?php
/**
* [+phpdoc-package+]
*/
require_once (strtr(realpath(dirname(dirname(__FILE__))), '\\\\', '/') . '/[+class-lowercase+].class.php');
class [+class+]_[+platform+] extends [+class+] {
function [+class+]_[+platform+](& \$xpdo) {
\$this->__construct(\$xpdo);
}
function __construct(& \$xpdo) {
parent :: __construct(\$xpdo);
}
}
?>
EOD;
$generator->mapHeader= <<<EOD
<?php
/**
* [+phpdoc-package+]
*/
EOD;
$generator->parseSchema($sources['model'] . 'schema/'.PKG_NAME_LOWER.'.'.$driver.'.schema.xml', $sources['model']);
if(!is_dir($sources['model'])) {
$modx->log(modX::LOG_LEVEL_ERROR,'Model directory not found ('.$sources['model'].')!');
die();
}

if(!file_exists($sources['schema_file'])) {
$modx->log(modX::LOG_LEVEL_ERROR,'Schema file not found!');
die();
}

$mtime= microtime();
$mtime= explode(" ", $mtime);
$mtime= $mtime[1] + $mtime[0];
$tend= $mtime;
$totalTime= ($tend - $tstart);
$totalTime= sprintf("%2.4f s", $totalTime);
$generator->parseSchema($sources['schema_file'], $sources['model']);

echo "\nExecution time: {$totalTime}\n";
$modx->addPackage(PKG_NAME_LOWER, $sources['model']);
$manager->createObjectContainer('modRedirect');

exit ();
$manager->addField('modRedirect', 'context_key', array('after' => 'target'));
$manager->addIndex('modRedirect', 'pattern_context');
$manager->removeIndex('modRedirect', 'pattern');
57 changes: 43 additions & 14 deletions _build/build.transport.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/* define package names */
define('PKG_NAME','Redirector');
define('PKG_NAME_LOWER','redirector');
define('PKG_VERSION','1.0.3');
define('PKG_VERSION','2.0.0');
define('PKG_RELEASE','pl');

/* define build paths */
Expand Down Expand Up @@ -50,23 +50,36 @@
$builder->registerNamespace(PKG_NAME_LOWER,false,true,'{core_path}components/'.PKG_NAME_LOWER.'/');

/* add plugin */
$modx->log(modX::LOG_LEVEL_INFO,'Packaging in plugin...');
$modx->log(modX::LOG_LEVEL_INFO,'Packaging in Redirector plugin...');
$plugin= $modx->newObject('modPlugin');
$plugin->fromArray(array(
'id' => 1,
'name' => 'Redirector',
'description' => 'Handles site redirects.',
'plugincode' => getSnippetContent($sources['elements'].'plugins/plugin.redirector.php'),
),'',true,true);
$events = array();
$events['OnPageNotFound']= $modx->newObject('modPluginEvent');
$events['OnPageNotFound']->fromArray(array(
'event' => 'OnPageNotFound',
'priority' => 0,
'propertyset' => 0,
),'',true,true);
$plugin->addMany($events);
unset($events);

$events = array();
$events['OnPageNotFound']= $modx->newObject('modPluginEvent');
$events['OnPageNotFound']->fromArray(array(
'event' => 'OnPageNotFound',
'priority' => 0,
'propertyset' => 0,
),'',true,true);
$events['OnDocFormRender'] = $modx->newObject('modPluginEvent');
$events['OnDocFormRender']->fromArray(array(
'event' => 'OnDocFormRender',
'priority' => 0,
'propertyset' => 0,
),'',true,true);
$events['OnDocFormSave'] = $modx->newObject('modPluginEvent');
$events['OnDocFormSave']->fromArray(array(
'event' => 'OnDocFormSave',
'priority' => 0,
'propertyset' => 0,
),'',true,true);
$plugin->addMany($events);
unset($events);

$attributes= array(
xPDOTransport::UNIQUE_KEY => 'name',
Expand Down Expand Up @@ -94,6 +107,21 @@
));
$builder->putVehicle($vehicle);

/* settings */
$settings = include_once $sources['data'].'transport.settings.php';
$attributes= array(
xPDOTransport::UNIQUE_KEY => 'key',
xPDOTransport::PRESERVE_KEYS => true,
xPDOTransport::UPDATE_OBJECT => false,
);
if (!is_array($settings)) { $modx->log(modX::LOG_LEVEL_FATAL,'Adding settings failed.'); }
foreach ($settings as $setting) {
$vehicle = $builder->createVehicle($setting,$attributes);
$builder->putVehicle($vehicle);
}
$modx->log(modX::LOG_LEVEL_INFO,'Packaged in '.count($settings).' system settings.'); flush();
unset($settings,$setting,$attributes);

/* load menu */
$modx->log(modX::LOG_LEVEL_INFO,'Packaging in menu...');
$menu = include $sources['data'].'transport.menu.php';
Expand All @@ -115,6 +143,9 @@
$vehicle->resolve('php',array(
'source' => $sources['resolvers'] . 'resolve.tables.php',
));
$vehicle->resolve('php',array(
'source' => $sources['resolvers'] . 'resolve.dbchanges.php',
));
$builder->putVehicle($vehicle);
unset($vehicle,$menu);

Expand Down Expand Up @@ -142,6 +173,4 @@
$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 ();
$modx->log(modX::LOG_LEVEL_INFO, "\nPackage Built.\nExecution time: {$totalTime}\n");
2 changes: 1 addition & 1 deletion _build/data/transport.menu.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'id' => 1,
'namespace' => 'redirector',
'parent' => 0,
'controller' => 'index',
'controller' => 'controllers/index',
'haslayout' => true,
'lang_topics' => 'redirector:default',
'assets' => '',
Expand Down
36 changes: 27 additions & 9 deletions _build/data/transport.plugins.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,32 @@
'description' => 'Handles site redirects.',
'plugincode' => file_get_contents($sources['elements'].'plugins/plugin.redirector.php'),
),'',true,true);
$events = array();
$events['OnPageNotFound']= $modx->newObject('modPluginEvent');
$events['OnPageNotFound']->fromArray(array(
'event' => 'OnPageNotFound',
'priority' => 0,
'propertyset' => 0,
),'',true,true);
$plugins[1]->addMany($events);
unset($events);

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

/* new OnDocFormRender event, added by cc */
$events['OnDocFormRender'] = $modx->newObject('modPluginEvent');
$events['OnDocFormRender']->fromArray(array(
'event' => 'OnDocFormRender',
'priority' => 0,
'propertyset' => 0,
),'',true,true);

/* new OnDocFormSave event, added by cc */
$events['OnDocFormSave'] = $modx->newObject('modPluginEvent');
$events['OnDocFormSave']->fromArray(array(
'event' => 'OnDocFormSave',
'priority' => 0,
'propertyset' => 0,
),'',true,true);

$plugins[1]->addMany($events);
unset($events);

return $plugins;
27 changes: 27 additions & 0 deletions _build/data/transport.settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

$s = array(
'Manager' => array(
'track_alias_updates' => false,
),
);

$settings = array();
foreach ($s as $area => $sets) {
foreach ($sets as $key => $value) {

$xtype = 'textfield';
if(is_bool($value)) { $xtype = 'combo-boolean'; }

$settings['redirector.'.$key] = $modx->newObject('modSystemSetting');
$settings['redirector.'.$key]->set('key', 'redirector.'.$key);
$settings['redirector.'.$key]->fromArray(array(
'value' => $value,
'xtype' => $xtype,
'namespace' => 'redirector',
'area' => $area
));
}
}

return $settings;
28 changes: 28 additions & 0 deletions _build/resolvers/resolve.dbchanges.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

$modx =& $object->xpdo;

$modx->log(xPDO::LOG_LEVEL_INFO, 'Making database changes.');
switch($options[xPDOTransport::PACKAGE_ACTION]) {
case xPDOTransport::ACTION_INSTALL:
case xPDOTransport::ACTION_UPGRADE:

$modx =& $object->xpdo;
$modelPath = $modx->getOption('redirector.core_path', null, $modx->getOption('core_path').'components/redirector/').'model/';
$modx->addPackage('redirector', $modelPath);

$manager = $modx->getManager();

$manager->addField('modRedirect', 'context_key', array('after' => 'target'));
$manager->addIndex('modRedirect', 'pattern_context');
$manager->removeIndex('modRedirect', 'pattern');

// update controller location
$modAction = $modx->getObject('modAction', array('namespace' => 'redirector', 'controller' => 'index'));
if(!empty($modAction) && is_object($modAction)) {
$modAction->set('controller', 'controllers/index');
$modAction->save();
}

break;
}
30 changes: 30 additions & 0 deletions assets/components/redirector/css/mgr.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.grid-row-invalid table tr td { background: #ffd6d3 !important; }


/*
* FileUploadField component styles
*/
.x-form-file-wrap {
position: relative;
height: 22px;
}
.x-form-file-wrap .x-form-file {
position: absolute;
right: 0;
-moz-opacity: 0;
filter:alpha(opacity: 0);
opacity: 0;
z-index: 2;
height: 22px;
}
.x-form-file-wrap .x-form-file-btn {
position: absolute;
right: 0;
z-index: 1;
}
.x-form-file-wrap .x-form-file-text {
position: absolute;
left: 0;
z-index: 3;
color: #777;
}
Loading

0 comments on commit b1ef604

Please sign in to comment.