void IWpPlugin.Configure(WpApp app) { // postpone admin actions app.AddFilter("admin_init", new Action(() => { // plugins_api app.AddFilter("plugins_api", new Func <PhpValue, string, object, PhpValue>(PluginsApi), accepted_args: 3); app.AddFilter("themes_api", new Func <PhpValue, string, object, PhpValue>(ThemesApi), accepted_args: 3); app.AddFilter("delete_plugin", new Action <string>(DeletePlugin)); app.AddFilter("upgrader_source_selection", new Func <string, PhpValue>(InstallSourceSelection), priority: 0); app.AddFilter("upgrader_post_install", new Func <bool, PhpArray, PhpArray, PhpValue>(PostInstall), priority: 0, accepted_args: 3); app.AddFilter("activate_plugin", new Action <string>(plugin_file => _packages.ActivatePackage(PackagesHelper.PluginFileToPluginId(plugin_file)))); app.AddFilter("deactivate_plugin", new Action <string>(plugin_file => _packages.DeactivatePackage(PackagesHelper.PluginFileToPluginId(plugin_file)))); app.AddFilter("switch_theme", new Action <string, WP_Theme, WP_Theme>(SwitchTheme), accepted_args: 3); app.AddFilter("install_plugins_tabs", new Func <PhpArray, PhpArray>(tabs => // remove unsupported tabs { //tabs.Remove(new IntStringKey("upload")); tabs.Remove(new IntStringKey("popular")); tabs.Remove(new IntStringKey("recommended")); tabs.Remove(new IntStringKey("favorites")); tabs["recommended"] = "Premium"; return(tabs); })); app.AddFilter("user_has_cap", new Func <PhpArray, PhpArray, PhpArray, PhpArray>((allcaps, cap, args) => { // remove 'update_core' allcaps["update_core"] = false; // return(allcaps); }), accepted_args: 3); // defined in PeachPied.WordPress.Standard: // app.Context.DefineConstant("FS_METHOD", "direct"); // overwrite how installing plugins is handled, skips the fs check })); }
public void Configure(WpApp app) { // // Dashboard: // // add information into Right Now section app.DashboardRightNow(DashboardRightNow); // do not allow editing of .php files: app.AddFilter("editable_extensions", new Func <IList, IList>(editable_extensions => { editable_extensions.Remove("php"); return(editable_extensions); })); // // Blogs: // // alter generator metadata app.AddFilter("get_the_generator_xhtml", new Func <string>(() => GeneratorHtml)); // add analytics }
public void Configure(WpApp app) { app.DashboardWidget("peachpied.widget.1", "Razor Partial View", writer => { app.Context.RenderPartial("DashboardWidget", this); }); }
public void Configure(WpApp app) { this.app = app; var demoWidget = new DemoWidget(app.Context); app.Context.Call("add_action", (PhpValue)"widgets_init", RegisterMyWidget()); }
void IWpPlugin.Configure(WpApp app) { // postpone admin actions app.AddFilter("admin_init", new Action(() => { app.AddFilter("user_has_cap", new Func <PhpArray, PhpArray, PhpArray, PhpArray>((allcaps, cap, args) => { allcaps["update_core"] = false; allcaps["update_php"] = false; // return(allcaps); }), accepted_args: 3); app.AddFilter("pre_site_transient_update_core", new Func <stdClass>(() => { // TODO: wpdotnet check for version update return(new PhpArray() { { "last_checked", Pchp.Library.DateTime.DateTimeFunctions.time() }, { "version_checked", app.Context.Globals["wp_version"].ToString() }, }.ToObject()); }), accepted_args: 0); })); // ensure "plugins" directory exists, otherwise eventual mkdir() in wp fails if (app.Context.TryGetConstant("WP_PLUGIN_DIR", out var plugindir)) { try { Directory.CreateDirectory(plugindir.ToString(app.Context)); } catch { } } }
public void Configure(WpApp app) { app.DashboardWidget("peachpied.widget.1", "Razor Partial View", writer => { // TODO: this is still a technical demo, it does not allow to use a bunch of Razor View features app.Context.GetHttpContext().RenderPartialAsync(writer, "DashboardWidget", this); }); }
public void Configure(WpApp app) { this.app = app; Del MyDel = RegisterMyWidget; var routineInfo = RoutineInfo.CreateUserRoutine("RegisterMyWidget", MyDel); app.Context.Call("add_action", (PhpValue)"widgets_init", routineInfo); }
void AdminNotice(WpApp app, string message, bool success) { app.OnAdminInit(() => { app.AdminNotices(() => $@"<div class='notice notice-{(success ? "success" : "warning")} is-dismissible' style='background:url({LogoUrl}) no-repeat 4px 4px;background-size:2.4em 2.4em;'> <p style='margin-left:3em;'><b>WpDotNet:</b> {System.Web.HttpUtility.HtmlEncode(message)}</p> </div>"); }); }
void DashboardRightNow(WpApp app, TextWriter output) { var frameworkVersion = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription ?? Assembly.GetEntryAssembly()?.GetCustomAttribute <TargetFrameworkAttribute>()?.FrameworkName; var process = System.Diagnostics.Process.GetCurrentProcess(); string licenseRow = ""; #if WPDOTNET_LICENSE string licensehtml = IsRegistered ? $@"<em>{app.GetSiteUrl()} is <a href='{WpDotNetUrl}#registered' target='_blank'>registered</a></em>" : $@"<a href='#' onclick='return wpdotnet_register_open();' tooltip=''>Register</a> | <a href='{PurchaseLink}' target='_blank' tooltip=''>Purchase</a>"; licenseRow = $"<b>License:</b> {licensehtml}<br/>"; #endif output.Write($@" <table style=""border:0;width:100%;""><tbody> <tr> <td><img src=""{LogoUrl}"" style=""width:76px;margin:8px;display:inline;""></td> <td> <b>Your WordPress runs on {frameworkVersion}</b> <div> <b title=""Memory allocated by the whole process."">Memory usage:</b> {process.WorkingSet64 / 1024 / 1024} MB<br/> <b title=""CPU time consumed by the whole process."">CPU usage:</b> {process.TotalProcessorTime:c}<br/> {licenseRow} </div> </td> </tr> </tbody></table>"); #if WPDOTNET_LICENSE if (!IsRegistered) { output.Write($@" <div id='{RegisterBoxId}' style='display:none;'> <hr/> <p> <p style=''>Please register your domain <b>{app.GetSiteUrl()}</b> using your purchase email or license key.</p> <form method='post'> <table style='border:0;width:100%;'><tbody> <tr> <td><b>E-mail or license key:</b></td> <td><input name='{RegisterKeyName}' type='text' class='regular-text' style='width:100%;' placeholder='*****@*****.**' required='required' value='{app.GetAdminEmail()}'></input></td> </tr> <tr> <td></td> <td style='text-align:right;'><input type='submit' class='button' value='Register' /></td> </tr> </tbody></table> </form> </p> </div> "); } #endif }
void IWpPlugin.Configure(WpApp app) { Action updated = () => { // existing cache records get invalidated LastPostUpdate = DateTime.UtcNow; }; app.AddFilter("save_post", updated); app.AddFilter("wp_insert_comment", updated); // edit_comment // trashed_comment(comment id, comment) // spammed_comment }
public void Configure(WpApp app) { app.AddShortcode("dotnetWpUser", new Func <string>(() => //new shortcode_handler((attrs, content) => { var user = (WP_User)app.Context.Call("wp_get_current_user", Array.Empty <PhpValue>()).AsObject(); if (user != null) { return($"Your WP_User ID is {user.ID}."); } else { return("You are not logged in."); } })); }
public void Configure(WpApp app) { // // Dashboard: // // add information into Right Now section app.DashboardRightNow(DashboardRightNow); // // Blogs: // // alter generator metadata app.AddFilter("get_the_generator_xhtml", new Func <string>(() => GeneratorHtml)); }
void IWpPlugin.Configure(WpApp app) { // postpone admin actions app.AddFilter("admin_init", new Action(() => { // plugins_api app.AddFilter("plugins_api", new Func <PhpValue, string, object, PhpValue>(PluginsApi), accepted_args: 3); app.AddFilter("themes_api", new Func <PhpValue, string, object, PhpValue>(ThemesApi), accepted_args: 3); app.AddFilter("delete_plugin", new Action <string>(DeletePlugin)); app.AddFilter("upgrader_source_selection", new Func <string, PhpValue>(InstallSourceSelection), priority: 0); app.AddFilter("upgrader_post_install", new Func <bool, PhpArray, PhpArray, PhpValue>(PostInstall), priority: 0, accepted_args: 3); app.AddFilter("activate_plugin", new Action <string>(plugin_file => _packages.ActivatePackage(PackagesHelper.PluginFileToPluginId(plugin_file)))); app.AddFilter("deactivate_plugin", new Action <string>(plugin_file => _packages.DeactivatePackage(PackagesHelper.PluginFileToPluginId(plugin_file)))); app.AddFilter("switch_theme", new Action <string, WP_Theme, WP_Theme>(SwitchTheme), accepted_args: 3); app.AddFilter("install_plugins_tabs", new Func <PhpArray, PhpArray>(tabs => // remove unsupported tabs { //tabs.Remove(new IntStringKey("upload")); tabs.Remove(new IntStringKey("popular")); tabs.Remove(new IntStringKey("recommended")); tabs.Remove(new IntStringKey("favorites")); tabs["recommended"] = "Premium"; return(tabs); })); app.AddFilter("user_has_cap", new Func <PhpArray, PhpArray, PhpArray, PhpArray>((allcaps, cap, args) => { // remove 'update_core' allcaps["update_core"] = false; // return(allcaps); }), accepted_args: 3); // defined in PeachPied.WordPress.Standard: // app.Context.DefineConstant("FS_METHOD", "direct"); // overwrite how installing plugins is handled, skips the fs check // ensure "plugins" directory exists, otherwise eventual mkdir() in wp fails if (app.Context.TryGetConstant("WP_PLUGIN_DIR", out var plugindir)) { try { Directory.CreateDirectory(plugindir.ToString(app.Context)); } catch { } } //// ensure "themes" directory exists (always exists) //var themedir = app.Context.Call("get_theme_root"); //try { Directory.CreateDirectory(themedir.ToString(app.Context)); } //catch { } })); }
void IWpPlugin.Configure(WpApp app) { Action updated = () => { // existing cache records get invalidated LastPostUpdate = DateTime.UtcNow; }; app.AddFilter("save_post", updated); // post updated app.AddFilter("wp_insert_comment", updated); // comment added app.AddFilter("activate_plugin", updated); // plugin activated app.AddFilter("deactivate_plugin", updated); // plugin deactivated app.AddFilter("switch_theme", updated); // theme changed // TODO: edit_comment // TODO: trashed_comment(comment id, comment) // TODO: spammed_comment }
void AdminInit(WpApp app) { // plugins_api app.AddFilter("plugins_api", new Func <PhpValue, string, object, PhpValue>(PluginsApi), accepted_args: 3); app.AddFilter("delete_plugin", new Action <string>(DeletePlugin)); app.AddFilter("upgrader_source_selection", new Func <string, PhpValue>(InstallSourceSelection), priority: 0); app.AddFilter("activate_plugin", new Action <string>(plugin_file => _packages.ActivatePackage(PackagesHelper.PluginFileToPluginId(plugin_file)))); app.AddFilter("deactivate_plugin", new Action <string>(plugin_file => _packages.DeactivatePackage(PackagesHelper.PluginFileToPluginId(plugin_file)))); app.AddFilter("install_plugins_tabs", new Func <PhpArray, PhpArray>(tabs => // remove unsupported tabs { //tabs.Remove(new IntStringKey("upload")); tabs.Remove(new IntStringKey("popular")); tabs.Remove(new IntStringKey("recommended")); tabs.Remove(new IntStringKey("favorites")); tabs["recommended"] = "Premium"; return(tabs); })); app.Context.DefineConstant("FS_METHOD", "direct"); // overwrite how installing plugins is handled, skips the fs check }
void IWpPlugin.Configure(WpApp app) { // postpone admin actions app.AddFilter("admin_init", new Action(() => AdminInit(app))); }
void IWpPlugin.Configure(WpApp app) { FirstRequest(); // delay the build action, // website is being just requested _pluginsCompiler.PostponeBuild(); _themesCompiler.PostponeBuild(); // wp hooks: app.OnAdminInit(() => { // render notices if there are compile time errors app.AdminNotices(() => CollectAdminNotices(app)); }); app.AdminMenu(() => { var hook = app.AddManagementPage("Code Problems", "Code Problems", "install_plugins", "list-problems", (output) => { var hasany = _pluginsCompiler.LastDiagnostics.Length != 0 || _themesCompiler.LastDiagnostics.Length != 0; var maxseverity = hasany ? _pluginsCompiler.LastDiagnostics.Concat(_themesCompiler.LastDiagnostics).Max(d => d.Severity) : DiagnosticSeverity.Hidden; var overallicon = hasany ? IconHtml(maxseverity) : IconHtmlSuccess(); output.Write($@" <div style='margin:16px;'> <div><h1>Code Problems</h1></div> <div class='hide-if-no-js orange'> <div>{overallicon} {(maxseverity != 0 ? "Should be checked." : "No problems.")}</div> </div> </div>"); if (_pluginsCompiler.LastDiagnostics.Length != 0 || _themesCompiler.LastDiagnostics.Length != 0) { output.Write("<div style='margin:24px;padding:8px;background:white;border:solid 1px #aaa;'>"); output.Write(CreateDiagnosticsTable(_pluginsCompiler.LastDiagnostics, true)); output.Write(CreateDiagnosticsTable(_themesCompiler.LastDiagnostics, true)); output.Write("</div>"); } }, 4); //app.AddFilter($"load-{hook}", new Action(() => //{ // // //})); }); app.Footer(output => { // output.Write(@$" // <div style='margin:4px auto;padding:6px;text-align:right;background:#eee;border-top:solid 1px #ccc;color:#444;font-size:13px;'> // Built with WordPress on .NET // </div>"); }); //// ajax hook to get the currently loaded assemblies version: //app.AddAjaxAction( // "hotplug_version", // () => (_pluginsCompiler.VersionLoaded.GetHashCode() ^ _themesCompiler.VersionLoaded.GetHashCode()).ToString("X")); //// TODO: add script to the footer that periodically checks ajax_hotplug_version for changes, //// in such case it refreshes the page // ... }
bool TryRegisterUser(WpApp app) { string key = null; if (app.Context.Post.TryGetValue(RegisterKeyName, out var keyvalue)) { key = keyvalue.AsString(); } else if (app.GetOption(RegisterKeyName).IsPhpArray(out var dataarray)) { try { var uri = new Uri(app.GetSiteUrl(), UriKind.Absolute); var data = ValidationData.FromArray(dataarray); if (data.Verify(uri)) { _isRegistered = true; AdminNotice(app, $"License is valid until {data.Expiration:d}.", success: true); return(true); } else if (data.Expiration <= DateTime.UtcNow && data.Key != null) { // AdminNotice(app, $"License has expired at {data.Expiration.ToString("d")}.", success: false); // try to update the registration automatically key = data.Key; } } catch { // ignore invalid data AdminNotice(app, $"Invalid license data. Please register again.", success: false); } _isRegistered = false; // do not try to verify again } // request user validation: if (key != null) { var siteurl = app.GetSiteUrl(); var uri = new Uri(siteurl, UriKind.Absolute); if (TryRequestUserValidation(key, siteurl, out var data)) { app.UpdateOption(RegisterKeyName, data.ToArray()); if (data.Verify(uri)) { _isRegistered = true; AdminNotice(app, $"Registration suceeded. Thank you! License is valid until {data.Expiration:d}, then it will be renewed automatically.", success: true); return(true); } else { AdminNotice(app, $"License has been verified, although it is no valid. Expiration date is {data.Expiration:d}.", success: false); } } else { AdminNotice(app, $"Invalid license '{key}'. Domain '{uri.Host}' has not been registered.", success: false); } } return(false); }
public void Configure(WpApp app) { if (_isRegistered.HasValue == false || app.Context.Post.Count != 0) { TryRegisterUser(app); } // // Dashboard: // // add information into Right Now section app.DashboardRightNow(output => DashboardRightNow(app, output)); // // Blogs: // // alter generator metadata app.AddFilter("get_the_generator_xhtml", new Func <string>(() => s_GeneratorHtml)); // app.AddFilter("wp_head", new Action(() => // { // app.Context.Output.Write(@"<style> // .foldtl { // position: relative; // -webkit-box-shadow: 5px -5px 5px rgba(0,0,0,0.2); // -moz-box-shadow: 5px -5px 5px rgba(0,0,0,0.2); // box-shadow: 5px -5px 5px rgba(0,0,0,0.2); // } // .foldtl:before { // content: """"; // position: absolute; // top: 0%; // left: 0%; // width: 0px; // height: 0px; // border-top: 70px solid rgba(255,255,255,0.8); // border-left: 70px solid #ededed; // -webkit-box-shadow: 7px -7px 7px rgba(0,0,0,0.2); // -moz-box-shadow: 7px -7px 7px rgba(0,0,0,0.2); // box-shadow: 7px -7px 7px rgba(0,0,0,0.2); // } // </style>"); // })); if (!IsRegistered) { app.Footer(output => { output.Write($@" <div style='position:fixed;text-align:center; width:192px; height:50px; bottom:0; right:0;padding:12px 0 12px 50px; margin:0 auto; vertical-align: middle;background:#68b227;background-image:url({LogoUrl});background-size:50px 50px;background-repeat:no-repeat;border-left:solid 10px rgba(255,255,255,.5);line-height:24px;' title='WpDotNet'> <a href='{WpDotNetUrl}?from=footer' style='color:#fff;font-size:16px;font-style:tahoma,helvetica;padding:0; margin:0;'>WpDotNet</a> </div> "); }); app.OnAdminInit(() => { app.AddFilter("admin_print_footer_scripts", new Action(() => { app.Context.Output.Write($@" <script type='text/javascript'> function wpdotnet_register_open() {{ jQuery('#{RegisterBoxId}').slideToggle('fast'); jQuery('#{RegisterBoxId} input[type=""text""]').focus(); return false; }} </script> "); })); }); } }
void IWpPlugin.Configure(WpApp app) { if (app.Context.TryGetConstant("WPDOTNET_HOTPLUG_ENABLE", out var evalue) && (bool)evalue == false) { // docs/configuration/WPDOTNET_HOTPLUG_ENABLE // disable listing online plugins from dashboard app.OnAdminInit(() => { // plugins_api app.AddFilter("plugins_api", new Func <PhpValue, string, object, PhpValue>(EmptyApi), accepted_args: 3); app.AddFilter("themes_api", new Func <PhpValue, string, object, PhpValue>(EmptyApi), accepted_args: 3); }); return; } FirstRequest(); // delay the build action, // website is being just requested FoldersAction(f => f.PostponeBuild()); // wp hooks: app.OnAdminInit(() => { // render notices if there are compile time errors app.AdminNotices(() => CollectAdminNotices(app)); }); app.AdminMenu(() => { var hook = app.AddManagementPage("Code Problems", "Code Problems", "install_plugins", "list-problems", (output) => { var diagnostics = FoldersDiagnostic; var hasany = diagnostics.Any(); var maxseverity = hasany ? diagnostics.Max(d => d.Severity) : DiagnosticSeverity.Hidden; var overallicon = hasany ? IconHtml(maxseverity) : IconHtmlSuccess(); output.Write($@" <div style='margin:16px;'> <div><h1>Code Problems</h1></div> <div class='hide-if-no-js orange'> <div>{overallicon} {(maxseverity != 0 ? "Should be checked." : "No problems.")}</div> </div> </div>"); if (hasany) { output.Write("<div style='margin:24px;padding:8px;background:white;border:solid 1px #aaa;'>"); output.Write(CreateDiagnosticsTable(diagnostics, true)); output.Write("</div>"); } }, 4); //app.AddFilter($"load-{hook}", new Action(() => //{ // // //})); }); //// ajax hook to get the currently loaded assemblies version: //app.AddAjaxAction( // "hotplug_version", // () => (_pluginsCompiler.VersionLoaded.GetHashCode() ^ _themesCompiler.VersionLoaded.GetHashCode()).ToString("X")); //// TODO: add script to the footer that periodically checks ajax_hotplug_version for changes, //// in such case it refreshes the page // ... }
void IWpPlugin.Configure(WpApp app) { // postpone admin actions app.OnAdminInit(() => { // plugins_api app.AddFilter("plugins_api", new Func <PhpValue, string, object, PhpValue>(PluginsApi), accepted_args: 3); app.AddFilter("themes_api", new Func <PhpValue, string, object, PhpValue>(ThemesApi), accepted_args: 3); app.AddFilter("delete_plugin", new Action <string>(DeletePlugin)); app.AddFilter("upgrader_source_selection", new Func <string, PhpValue>(InstallSourceSelection), priority: 0); app.AddFilter("upgrader_post_install", new Func <bool, PhpArray, PhpArray, PhpValue>(PostInstall), priority: 0, accepted_args: 3); app.AddFilter("activate_plugin", new Action <string>(plugin_file => _packages.ActivatePackage(PackagesHelper.PluginFileToPluginId(plugin_file)))); app.AddFilter("deactivate_plugin", new Action <string>(plugin_file => _packages.DeactivatePackage(PackagesHelper.PluginFileToPluginId(plugin_file)))); app.AddFilter("switch_theme", new Action <string, WP_Theme, WP_Theme>(SwitchTheme), accepted_args: 3); app.AddFilter("install_plugins_tabs", new Func <PhpArray, PhpArray>(tabs => // remove unsupported tabs { //tabs.Remove(new IntStringKey("upload")); tabs.Remove(new IntStringKey("popular")); tabs.Remove(new IntStringKey("recommended")); tabs.Remove(new IntStringKey("favorites")); tabs["recommended"] = "Premium"; return(tabs); })); app.AddFilter("site_transient_update_themes", new Func <PhpValue, stdClass>(current => { // TODO: wpdotnet check for version update return(new PhpArray() { { "last_checked", Pchp.Library.DateTime.DateTimeFunctions.time() }, //{ "checked", [name => version] }, //{ "response", [name => [package, url, new_version]] }, //{ "no_update", [name => [package, url, new_version]] }, //{ "translations", [] }, }.ToObject()); }), accepted_args: 1); app.AddFilter("site_transient_update_plugins", new Func <PhpValue, stdClass>(current => { // TODO: wpdotnet check for version update return(new PhpArray() { { "last_checked", Pchp.Library.DateTime.DateTimeFunctions.time() }, //{ "checked", [name => version] }, //{ "response", [name => [package, url, new_version]] }, //{ "no_update", [name => [package, url, new_version]] }, //{ "translations", [] }, }.ToObject()); }), accepted_args: 1); // do not allow editing of .php files: app.AddFilter("editable_extensions", new Func <PhpArray, PhpArray>(editable_extensions => { editable_extensions.Remove("php"); return(editable_extensions); })); // defined in PeachPied.WordPress.Standard: // app.Context.DefineConstant("FS_METHOD", "direct"); // overwrite how installing plugins is handled, skips the fs check //// ensure "themes" directory exists (always exists) //var themedir = app.Context.Call("get_theme_root"); //try { Directory.CreateDirectory(themedir.ToString(app.Context)); } //catch { } }); }