Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 404 logging + Regexp matching for redirection rules possibility. #28

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion _build/build.transport.php
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','1.0.4');
define('PKG_RELEASE','pl');

/* define build paths */
Expand Down Expand Up @@ -65,6 +65,13 @@
'priority' => 0,
'propertyset' => 0,
),'',true,true);
$events['OnSiteRefresh'] = $modx->newObject('modPluginEvent');
$events['OnSiteRefresh']->fromArray(array(
'event' => 'OnSiteRefresh',
'priority' => 0,
'propertyset' => 0,
),'',true,true);

$plugin->addMany($events);
unset($events);

Expand Down
25 changes: 0 additions & 25 deletions _build/data/transport.plugins.php

This file was deleted.

1 change: 1 addition & 0 deletions _build/resolvers/resolve.tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
$manager = $modx->getManager();

$manager->createObjectContainer('modRedirect');
$manager->createObjectContainer('modRedirectPageNotFound');

break;
case xPDOTransport::ACTION_UPGRADE:
Expand Down
10 changes: 10 additions & 0 deletions assets/components/redirector/js/mgr/widgets/home.panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ Redi.panel.Home = function(config) {
return {activeTab:this.items.indexOf(this.getActiveTab())};
}
,items: [{
title: _('redirector.errors')
,defaults: { autoHeight: true }
,items: [{
html: '<p>'+_('redirector.pnfdesc')+'</p><br />'
,border: false
},{
xtype: 'redirector-grid-pagenotfound'
,preventRender: true
}]
},{
title: _('redirector.redirects')
,defaults: { autoHeight: true }
,items: [{
Expand Down
138 changes: 138 additions & 0 deletions assets/components/redirector/js/mgr/widgets/pagenotfound.grid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
Redi.grid.PageNotFound = function(config) {
config = config || {};
Ext.applyIf(config,{
id: 'redirector-grid-pagenotfound'
,url: Redi.config.connector_url
,baseParams: { action: 'mgr/errors/getList' }
,fields: ['id','url','times','firsttime','lasttime','menu']
,paging: true
,autosave: true
,remoteSort: true
,anchor: '97%'
,autoExpandColumn: 'url'
,columns: [{
header: _('redirector.url')
,dataIndex: 'url'
,sortable: false
,width: 200
,editor: { xtype: 'textfield' }
},{
header: _('redirector.times')
,dataIndex: 'times'
,sortable: true
,width: 40
,editor: { xtype: 'textfield' }
},{
header: _('redirector.firsttime')
,dataIndex: 'firsttime'
,sortable: true
,width: 100
,editor: { xtype: 'textfield' }
},{
header: _('redirector.lasttime')
,dataIndex: 'lasttime'
,sortable: true
,width: 100
,editor: { xtype: 'textfield' }
}]
,tbar: [{
xtype: 'textfield'
,id: 'redirector-search-filter'
,emptyText: _('redirector.search...')
,listeners: {
'change': {fn:this.search,scope:this}
,'render': {fn: function(cmp) {
new Ext.KeyMap(cmp.getEl(), {
key: Ext.EventObject.ENTER
,fn: function() {
this.fireEvent('change',this.getValue());
this.blur();
return true; }
,scope: cmp
});
},scope:this}
}
}]
});
Redi.grid.PageNotFound.superclass.constructor.call(this,config)
};
Ext.extend(Redi.grid.PageNotFound,MODx.grid.Grid,{
search: function(tf,nv,ov) {
var s = this.getStore();
s.baseParams.query = tf.getValue();
this.getBottomToolbar().changePage(1);
this.refresh();
}

,removeRedirectPageNotFound: function() {
MODx.msg.confirm({
title: _('redirector.redirect_remove_page_not_found')
,text: _('redirector.redirect_remove_confirm')
,url: this.config.url
,params: {
action: 'mgr/errors/remove'
,id: this.menu.record.id
}
,listeners: {
'success': {fn:this.refresh,scope:this}
}
});

}
,createRedirectPageNotFound: function(btn,e){
if (!this.createRedirectPNFWindow) {
this.createRedirectPNFWindow = MODx.load({
xtype: 'redirector-window-redirect-create-from-pnf'
,record: {
pattern : this.menu.record.url.replace(/^\//, '')
,target: ''
,active: 1
,isregexp: 0
}
,listeners: {
'success': {fn:this.refresh,scope:this}
}
});
}
this.createRedirectPNFWindow.setValues(this.menu.record);
this.createRedirectPNFWindow.show(e.target);
}
});
Ext.reg('redirector-grid-pagenotfound',Redi.grid.PageNotFound);

//
Redi.window.CreateRedirectPageNotFound = function(config) {
config = config || {};
Ext.applyIf(config,{
title: _('redirector.redirect_create')
,url: Redi.config.connector_url
,baseParams: {
action: 'mgr/redirect/create'
}
,fields: [{
xtype: 'textfield'
,fieldLabel: _('redirector.pattern')
,name: 'pattern'
,width: 300
},{
xtype: 'textfield'
,fieldLabel: _('redirector.target')
,name: 'target'
,width: 300
},{
xtype: 'checkbox'
,fieldLabel: _('redirector.active')
,name: 'active'
,inputValue: 1
,checked: true
},{
xtype: 'checkbox'
,fieldLabel: _('redirector.isregexp')
,name: 'isregexp'
,inputValue: 1
}]
});
Redi.window.CreateRedirectPageNotFound.superclass.constructor.call(this,config);
};
Ext.extend(Redi.window.CreateRedirectPageNotFound,MODx.Window);
Ext.reg('redirector-window-redirect-create-from-pnf',Redi.window.CreateRedirectPageNotFound);
103 changes: 93 additions & 10 deletions assets/components/redirector/js/mgr/widgets/redirects.grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,53 @@ Redi.grid.Redirects = function(config) {
var cb = new Ext.ux.grid.CheckColumn({
header: _('redirector.active')
,dataIndex: 'active'
,width: 40
,width: 30
,sortable: true
,onMouseDown: this.saveCheckbox
});
var re = new Ext.ux.grid.CheckColumn({
header: _('redirector.isregexp')
,dataIndex: 'isregexp'
,width: 30
,sortable: true
,onMouseDown: this.saveCheckbox
});

Ext.applyIf(config,{
id: 'redirector-grid-redirects'
,url: Redi.config.connector_url
,baseParams: { action: 'mgr/redirect/getList' }
,baseParams: { action: 'mgr/redirect/getList', limit: 0, start: 0 }
,save_action: 'mgr/redirect/updateFromGrid'
,fields: ['id','pattern','target','active','menu']
,paging: true
,fields: ['id','pattern','target','active','isregexp','sortorder','menu']
,paging: false
,limit: 0
,autosave: true
,remoteSort: true
,anchor: '97%'
,autoExpandColumn: 'name'
,plugins: [cb]
,enableDragDrop: true
,ddGroup: 'redirect-dd'
,ddText: 'Yeah ! You\'re dragging me'
,plugins: [cb,re]
,columns: [{
header: _('redirector.pattern')
,dataIndex: 'pattern'
,sortable: true
,width: 200
,width: 150
,editor: { xtype: 'textfield' }
},{
header: _('redirector.target')
,dataIndex: 'target'
,sortable: false
,width: 200
,width: 150
,editor: { xtype: 'textfield' }
},cb]
},cb,re,
{
header: _('redirector.priority')
,dataIndex: 'sortorder'
,sortable: true
,width: 30
,editor: { xtype: 'numberfield' }
}]
,tbar: [{
xtype: 'textfield'
,id: 'redirector-search-filter'
Expand All @@ -53,11 +71,66 @@ Redi.grid.Redirects = function(config) {
text: _('redirector.redirect_create')
,handler: { xtype: 'redirector-window-redirect-create' ,blankValues: true }
}]
,listeners:{
"render": {
scope: this,
fn: function(grid){
var ddrow = new Ext.dd.DropTarget(grid.container, {
ddGroup : 'redirect-dd',
copy:false,
notifyDrop : function(dd, e, data){
var ds = grid.store;
var sm = grid.getSelectionModel();
var rows = sm.getSelections();
if(dd.getDragData(e)) {
var cindex=dd.getDragData(e).rowIndex;
if(typeof(cindex) != "undefined") {
for(i = 0; i < rows.length; i++) {
ds.remove(ds.getById(rows[i].id));
}
ds.insert(cindex,data.selections);
sm.clearSelections();
}
}
grid.collectItems();
}
});

this.setWidth('99%');
}
}
}
});


Redi.grid.Redirects.superclass.constructor.call(this,config)
};
Ext.extend(Redi.grid.Redirects,MODx.grid.Grid,{
search: function(tf,nv,ov) {
collectItems: function(){
var items=[];
// read jsons from grid-store-items
var griddata=this.store.data;
for(i = 0; i < griddata.length; i++) {
items.push(griddata.items[i].json);
}

items = Ext.util.JSON.encode(items);
MODx.Ajax.request({
url: Redi.config.connector_url
,params: {
action: 'mgr/redirect/sort'
,items: items
,start: this.start
,limit: this.limit
}
,listeners: {
'success': {fn:function(r) {
this.refresh();
},scope:this}
}
});
}
,search: function(tf,nv,ov) {
var s = this.getStore();
s.baseParams.query = tf.getValue();
this.getBottomToolbar().changePage(1);
Expand Down Expand Up @@ -148,6 +221,11 @@ Redi.window.CreateRedirect = function(config) {
,name: 'active'
,inputValue: 1
,checked: true
},{
xtype: 'checkbox'
,fieldLabel: _('redirector.isregexp')
,name: 'isregexp'
,inputValue: 1
}]
});
Redi.window.CreateRedirect.superclass.constructor.call(this,config);
Expand Down Expand Up @@ -182,6 +260,11 @@ Redi.window.UpdateRedirect = function(config) {
,fieldLabel: _('redirector.active')
,name: 'active'
,inputValue: 1
},{
xtype: 'checkbox'
,fieldLabel: _('redirector.isregexp')
,name: 'isregexp'
,inputValue: 1
}]
});
Redi.window.UpdateRedirect.superclass.constructor.call(this,config);
Expand Down
1 change: 1 addition & 0 deletions core/components/redirector/controllers/mgr/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @package redirector
* @subpackage controllers
*/
$modx->regClientStartupScript($redirector->config['jsUrl'].'mgr/widgets/pagenotfound.grid.js');
$modx->regClientStartupScript($redirector->config['jsUrl'].'mgr/widgets/redirects.grid.js');
$modx->regClientStartupScript($redirector->config['jsUrl'].'mgr/widgets/home.panel.js');
$modx->regClientStartupScript($redirector->config['jsUrl'].'mgr/sections/index.js');
Expand Down
6 changes: 6 additions & 0 deletions core/components/redirector/docs/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
Changelog file for Redirector component.

Redirector 1.0.4
====================================
- Add Regular Expression support
- Add 404 logging and easy way to create redirection from them
- Add priority for Redirection Rules

Redirector 1.0.3
====================================
- Add sqlsrv support
Expand Down
Loading