Skip to content

Commit 0f4474f

Browse files
committed
Merge branch 'nb80dev'
2 parents 1ded59b + 2db9d66 commit 0f4474f

38 files changed

Lines changed: 1667 additions & 161 deletions

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
# About
1+
# NetBeans WordPress Plugin
2+
23
This is NetBeans plugin for WordPress.
34

5+
## How to enable
6+
7+
`enabled` option is unchecked as default. Please check it on `project properties > Frameworks > WordPress`
8+
49
## Environment
5-
- NetBeans 7.3+
10+
- NetBeans 8.0+
611
- WordPress 3.5+
712

813
## Features
@@ -20,6 +25,7 @@ This is NetBeans plugin for WordPress.
2025
- custom content name
2126
- run command (wp-cli)
2227
- upgrade notification
28+
- create a .htaccess file for permalink
2329

2430
### Impotant Files
2531
It contains wp-config.php
@@ -125,6 +131,13 @@ Furthermore, we can upgrade(run core update, core update-db, e.t.c.) WordPress w
125131

126132
If you don't want to check that, please uncheck `Check new version when project is opened` at Options.
127133

134+
### Create a .htaccess file for permalink
135+
136+
Right-click project node > WordPress > Create .htaccesss for permalink
137+
138+
#### Note
139+
.htaccess file for permalink can be also created with template.
140+
128141
## Version Number
129142

130143
| |stable |dev |

manifest.mf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ Manifest-Version: 1.0
22
OpenIDE-Module: org.netbeans.modules.php.wordpress
33
OpenIDE-Module-Layer: org/netbeans/modules/php/wordpress/resources/layer.xml
44
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/php/wordpress/Bundle.properties
5-
OpenIDE-Module-Specification-Version: 0.6.4
6-
OpenIDE-Module-Install: org/netbeans/modules/php/wordpress/WordPressModule.class
5+
OpenIDE-Module-Specification-Version: 0.7.2
6+
OpenIDE-Module-Install: org/netbeans/modules/php/wordpress/WordPressModuleInstall.class

src/org/netbeans/modules/php/wordpress/WordPressActionsExtender.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@
4848
import org.netbeans.modules.php.spi.framework.PhpModuleActionsExtender;
4949
import org.netbeans.modules.php.spi.framework.actions.RunCommandAction;
5050
import org.netbeans.modules.php.wordpress.commands.WordPressCli;
51-
import org.netbeans.modules.php.wordpress.ui.actions.RefreshCodeCompletionAction;
51+
import org.netbeans.modules.php.wordpress.ui.actions.CreatePermalinkHtaccessAction;
5252
import org.netbeans.modules.php.wordpress.ui.actions.CreatePluginAction;
5353
import org.netbeans.modules.php.wordpress.ui.actions.CreateThemeAction;
54+
import org.netbeans.modules.php.wordpress.ui.actions.RefreshCodeCompletionAction;
5455
import org.netbeans.modules.php.wordpress.ui.actions.WordPressRunCommandAction;
5556
import org.netbeans.modules.php.wordpress.ui.options.WordPressOptions;
5657
import org.openide.util.NbBundle;
@@ -87,6 +88,7 @@ public List<? extends Action> getActions() {
8788
actions.add(CreateThemeAction.getInstance());
8889
actions.add(CreatePluginAction.getInstance());
8990
actions.add(new RefreshCodeCompletionAction());
91+
actions.add(CreatePermalinkHtaccessAction.getInstance());
9092
return actions;
9193
}
9294
}

src/org/netbeans/modules/php/wordpress/WordPressModule.java renamed to src/org/netbeans/modules/php/wordpress/WordPressModuleInstall.java

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,44 @@
11
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright 2013 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7+
* Other names may be trademarks of their respective owners.
8+
*
9+
* The contents of this file are subject to the terms of either the GNU
10+
* General Public License Version 2 only ("GPL") or the Common
11+
* Development and Distribution License("CDDL") (collectively, the
12+
* "License"). You may not use this file except in compliance with the
13+
* License. You can obtain a copy of the License at
14+
* http://www.netbeans.org/cddl-gplv2.html
15+
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16+
* specific language governing permissions and limitations under the
17+
* License. When distributing the software, include this License Header
18+
* Notice in each file and include the License file at
19+
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
20+
* particular file as subject to the "Classpath" exception as provided
21+
* by Oracle in the GPL Version 2 section of the License file that
22+
* accompanied this code. If applicable, add the following below the
23+
* License Header, with the fields enclosed by brackets [] replaced by
24+
* your own identifying information:
25+
* "Portions Copyrighted [year] [name of copyright owner]"
26+
*
27+
* If you wish your version of this file to be governed by only the CDDL
28+
* or only the GPL Version 2, indicate your decision by adding
29+
* "[Contributor] elects to include this software in this distribution
30+
* under the [CDDL or GPL Version 2] license." If you do not indicate a
31+
* single choice of license, a recipient has the option to distribute
32+
* your version of this file under either the CDDL, the GPL Version 2 or
33+
* to extend the choice of license to its licensees as provided above.
34+
* However, if you add GPL Version 2 code and therefore, elected the GPL
35+
* Version 2 license, then the option applies only if the new code is
36+
* made subject to such option by the copyright holder.
37+
*
38+
* Contributor(s):
39+
*
40+
* Portions Copyrighted 2013 Sun Microsystems, Inc.
41+
*//*
242
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
343
*
444
* Copyright 2013 Oracle and/or its affiliates. All rights reserved.
@@ -57,9 +97,10 @@
5797
*
5898
* @author junichi11
5999
*/
60-
public class WordPressModule extends ModuleInstall {
100+
public class WordPressModuleInstall extends ModuleInstall {
61101

62-
private static final Logger LOGGER = Logger.getLogger(WordPressModule.class.getName());
102+
private static final Logger LOGGER = Logger.getLogger(WordPressModuleInstall.class.getName());
103+
private static final long serialVersionUID = 6916751777614125653L;
63104

64105
@NbBundle.Messages("WordPressModule.get.commands=Getting wp-cli commands...")
65106
@Override

src/org/netbeans/modules/php/wordpress/WordPressPhpProvider.java

Lines changed: 91 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,20 @@
4141
*/
4242
package org.netbeans.modules.php.wordpress;
4343

44-
import org.netbeans.modules.php.wordpress.update.WordPressUpgradeChecker;
44+
import java.awt.event.ActionEvent;
45+
import java.awt.event.ActionListener;
46+
import java.beans.PropertyChangeEvent;
4547
import java.io.File;
4648
import java.util.Collection;
4749
import java.util.HashSet;
4850
import java.util.LinkedList;
4951
import java.util.List;
5052
import java.util.Set;
53+
import java.util.concurrent.TimeUnit;
5154
import org.netbeans.modules.php.api.framework.BadgeIcon;
5255
import org.netbeans.modules.php.api.phpmodule.PhpModule;
5356
import org.netbeans.modules.php.api.phpmodule.PhpModuleProperties;
57+
import org.netbeans.modules.php.api.validation.ValidationResult;
5458
import org.netbeans.modules.php.spi.editor.EditorExtender;
5559
import org.netbeans.modules.php.spi.framework.PhpFrameworkProvider;
5660
import org.netbeans.modules.php.spi.framework.PhpModuleActionsExtender;
@@ -61,23 +65,30 @@
6165
import org.netbeans.modules.php.wordpress.commands.WordPressCommandSupport;
6266
import org.netbeans.modules.php.wordpress.customizer.WordPressCustomizerExtender;
6367
import org.netbeans.modules.php.wordpress.editor.WordPressEditorExtender;
68+
import org.netbeans.modules.php.wordpress.modules.WordPressModule;
6469
import org.netbeans.modules.php.wordpress.preferences.WordPressPreferences;
70+
import org.netbeans.modules.php.wordpress.update.WordPressUpgradeChecker;
71+
import org.netbeans.modules.php.wordpress.validators.WordPressModuleValidator;
72+
import org.openide.awt.Notification;
73+
import org.openide.awt.NotificationDisplayer;
6574
import org.openide.filesystems.FileObject;
6675
import org.openide.filesystems.FileUtil;
6776
import org.openide.util.ImageUtilities;
6877
import org.openide.util.Lookup;
6978
import org.openide.util.NbBundle;
79+
import org.openide.util.RequestProcessor;
7080

7181
/**
7282
*
7383
* @author junichi11
7484
*/
7585
public class WordPressPhpProvider extends PhpFrameworkProvider {
7686

87+
private static final RequestProcessor RP = new RequestProcessor(WordPressPhpProvider.class);
7788
private static final WordPressPhpProvider INSTANCE = new WordPressPhpProvider();
7889
private static final String ICON_PATH = "org/netbeans/modules/php/wordpress/resources/wordpress_badge_8.png"; // NOI18N
7990
private final BadgeIcon badgeIcon;
80-
private static final Set<String> WP_DIRS = new HashSet<String>();
91+
public static final Set<String> WP_DIRS = new HashSet<String>();
8192

8293
static {
8394
WP_DIRS.add("wp-admin"); // NOI18N
@@ -108,30 +119,16 @@ private WordPressPhpProvider() {
108119

109120
@Override
110121
public boolean isInPhpModule(PhpModule pm) {
111-
FileObject sourceDirectory = pm.getSourceDirectory();
112-
if (sourceDirectory != null) {
113-
for (String dir : WP_DIRS) {
114-
FileObject fileObject = sourceDirectory.getFileObject(dir);
115-
if (fileObject == null) {
116-
return false;
117-
}
118-
}
119-
120-
// content name
121-
FileObject content = sourceDirectory.getFileObject(WordPressPreferences.getCustomContentName(pm));
122-
if (content == null) {
123-
return false;
124-
}
125-
}
126-
return true;
122+
return WordPressPreferences.isEnabled(pm);
127123
}
128124

129125
@Override
130126
public File[] getConfigurationFiles(PhpModule pm) {
131127
List<File> files = new LinkedList<File>();
132-
FileObject sourceDirectory = pm.getSourceDirectory();
133-
if (sourceDirectory != null) {
134-
FileObject config = sourceDirectory.getFileObject("wp-config.php"); // NOI18N
128+
WordPressModule wpModuel = WordPressModule.Factory.forPhpModule(pm);
129+
FileObject wordPressRoot = wpModuel.getWordPressRootDirecotry();
130+
if (wordPressRoot != null) {
131+
FileObject config = wordPressRoot.getFileObject("wp-config.php"); // NOI18N
135132
if (config != null) {
136133
files.add(FileUtil.toFile(config));
137134
}
@@ -177,13 +174,81 @@ public EditorExtender getEditorExtender(PhpModule pm) {
177174
return new WordPressEditorExtender();
178175
}
179176

177+
@Override
178+
public void phpModuleClosed(PhpModule phpModule) {
179+
WordPressModule.Factory.remove(phpModule);
180+
}
181+
182+
@NbBundle.Messages({
183+
"# {0} - name",
184+
"WordPressPhpProvider.autoditection=WordPress autoditection : {0}",
185+
"WordPressPhpProvider.autoditection.action=If you want to enable as WordPress project, please click here."
186+
})
180187
@Override
181188
public void phpModuleOpened(PhpModule phpModule) {
182-
// check new version
183-
Collection<? extends WordPressUpgradeChecker> checkers = Lookup.getDefault().lookupAll(WordPressUpgradeChecker.class);
184-
for (WordPressUpgradeChecker checker : checkers) {
185-
if (checker.hasUpgrade(phpModule)) {
186-
checker.notifyUpgrade(phpModule);
189+
// this method is run for not only WordPress projects but also all php projects,
190+
// so need check i.e. avoid NPE
191+
if (isInPhpModule(phpModule)) {
192+
// check new version
193+
Collection<? extends WordPressUpgradeChecker> checkers = Lookup.getDefault().lookupAll(WordPressUpgradeChecker.class);
194+
for (WordPressUpgradeChecker checker : checkers) {
195+
if (checker.hasUpgrade(phpModule)) {
196+
checker.notifyUpgrade(phpModule);
197+
}
198+
}
199+
}
200+
RP.schedule(new WordPressAutoDetectionTask(phpModule), 1, TimeUnit.MINUTES);
201+
}
202+
203+
//~ Inner class
204+
private static class WordPressAutoDetectionTask implements Runnable {
205+
206+
private final PhpModule phpModule;
207+
private Notification notification;
208+
209+
public WordPressAutoDetectionTask(PhpModule phpModule) {
210+
this.phpModule = phpModule;
211+
}
212+
213+
@Override
214+
public void run() {
215+
// auto detection
216+
FileObject wordPressRoot = phpModule.getSourceDirectory();
217+
if (wordPressRoot == null) {
218+
return;
219+
}
220+
ValidationResult result = new WordPressModuleValidator()
221+
.validateWordPressDirectories(wordPressRoot, WordPressPreferences.getCustomContentName(phpModule))
222+
.getResult();
223+
if (result.hasWarnings()) {
224+
return;
225+
}
226+
227+
// show notification displayer
228+
if (!WordPressPreferences.isEnabled(phpModule)) {
229+
NotificationDisplayer notificationDisplayer = NotificationDisplayer.getDefault();
230+
notification = notificationDisplayer.notify(
231+
Bundle.WordPressPhpProvider_autoditection(phpModule.getDisplayName()), // title
232+
NotificationDisplayer.Priority.LOW.getIcon(), // icon
233+
Bundle.WordPressPhpProvider_autoditection_action(),
234+
new WordPressAutoDetectionActionListener(), // action
235+
NotificationDisplayer.Priority.LOW); // priority
236+
}
237+
238+
}
239+
240+
private class WordPressAutoDetectionActionListener implements ActionListener {
241+
242+
public WordPressAutoDetectionActionListener() {
243+
}
244+
245+
@Override
246+
public void actionPerformed(ActionEvent e) {
247+
WordPressPreferences.setEnabled(phpModule, true);
248+
WordPressModule module = WordPressModule.Factory.forPhpModule(phpModule);
249+
module.notifyPropertyChanged(new PropertyChangeEvent(this, WordPressModule.PROPERTY_CHANGE_WP, null, null));
250+
phpModule.notifyPropertyChanged(new PropertyChangeEvent(this, PhpModule.PROPERTY_FRAMEWORKS, null, null));
251+
notification.clear();
187252
}
188253
}
189254
}

src/org/netbeans/modules/php/wordpress/WordPressVersion.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
import java.util.HashMap;
4646
import java.util.Map;
4747
import org.netbeans.modules.php.api.phpmodule.PhpModule;
48+
import org.netbeans.modules.php.wordpress.modules.WordPressModule;
4849
import org.netbeans.modules.php.wordpress.ui.status.DebugStatusLineElement;
49-
import org.netbeans.modules.php.wordpress.util.WPFileUtils;
5050
import org.netbeans.modules.php.wordpress.util.WPUtils;
5151
import org.openide.awt.StatusLineElementProvider;
5252
import org.openide.filesystems.FileChangeAdapter;
@@ -74,7 +74,8 @@ public static WordPressVersion create(PhpModule phpModule) {
7474
return version;
7575
}
7676

77-
FileObject versionFile = WPFileUtils.getVersionFile(phpModule);
77+
WordPressModule wpModule = WordPressModule.Factory.forPhpModule(phpModule);
78+
FileObject versionFile = wpModule.getVersionFile();
7879
if (versionFile == null) {
7980
return null;
8081
}

src/org/netbeans/modules/php/wordpress/commands/WordPressCli.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import org.netbeans.modules.php.api.phpmodule.PhpModule;
6666
import org.netbeans.modules.php.api.util.StringUtils;
6767
import org.netbeans.modules.php.spi.framework.commands.FrameworkCommand;
68+
import org.netbeans.modules.php.wordpress.modules.WordPressModule;
6869
import org.netbeans.modules.php.wordpress.ui.options.WordPressOptions;
6970
import org.openide.DialogDisplayer;
7071
import org.openide.NotifyDescriptor;
@@ -258,8 +259,14 @@ public List<String> getThemeStatus(PhpModule phpModule) {
258259
*/
259260
private List<String> getStatus(String command, PhpModule phpModule) {
260261
HelpLineProcessor lineProcessor = new HelpLineProcessor();
262+
WordPressModule wpModule = WordPressModule.Factory.forPhpModule(phpModule);
263+
FileObject root = wpModule.getWordPressRootDirecotry();
264+
if (root == null) {
265+
lineProcessor.asLines();
266+
}
267+
261268
Future<Integer> result = createExecutable()
262-
.workDir(FileUtil.toFile(phpModule.getSourceDirectory()))
269+
.workDir(FileUtil.toFile(root))
263270
.additionalParameters(Arrays.asList(command, STATUS_COMMAND))
264271
.run(getSilentDescriptor(), getOutputProcessorFactory(lineProcessor));
265272
try {
@@ -466,12 +473,13 @@ public Future<Integer> runCommand(PhpModule phpModule, List<String> parameters)
466473
* @return PhpExecutable
467474
*/
468475
private PhpExecutable getExecutable(PhpModule phpModule) {
469-
FileObject sourceDirectory = phpModule.getSourceDirectory();
470-
if (sourceDirectory == null) {
476+
WordPressModule wpModule = WordPressModule.Factory.forPhpModule(phpModule);
477+
FileObject wordPressRootDirectory = wpModule.getWordPressRootDirecotry();
478+
if (wordPressRootDirectory == null) {
471479
return null;
472480
}
473481
return createExecutable()
474-
.workDir(FileUtil.toFile(sourceDirectory));
482+
.workDir(FileUtil.toFile(wordPressRootDirectory));
475483
}
476484

477485
/**
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
WordPressCustomizerExtenderPanel.customContentNameLabel.text=custom content name:
2-
WordPressCustomizerExtenderPanel.customContentNameLabel.text=custom content name:
2+
WordPressCustomizerExtenderPanel.customContentNameLabel.text=Custom content name:
33
WordPressCustomizerExtenderPanel.customContentNameTextField.text=
44
WordPressCustomizerExtenderPanel.customContentNameTextField.text=
5+
WordPressCustomizerExtenderPanel.toolTipText=Please check this if you want to enable as WordPress project
6+
WordPressCustomizerExtenderPanel.enabledCheckBox.text=Enabled
7+
WordPressCustomizerExtenderPanel.customDirectoryPathLabel.text=Custom directory paths from source directory:
8+
WordPressCustomizerExtenderPanel.pluginsLabel.text=plugins:
9+
WordPressCustomizerExtenderPanel.pluginsTextField.text=
10+
WordPressCustomizerExtenderPanel.themesLabel.text=themes:
11+
WordPressCustomizerExtenderPanel.wordPressRootLabel.text=WordPress Root:
12+
WordPressCustomizerExtenderPanel.wordPressRootTextField.text=
13+
WordPressCustomizerExtenderPanel.themesTextField.text=
14+
WordPressCustomizerExtenderPanel.customDirectoryPathLabel.toolTipText=empty is default directory structure

0 commit comments

Comments
 (0)