沉冰浮水

沉冰浮水

做最终到的事,成为最终成为的人!
github
bilibili
mastodon
zhihu
douban

"Z-BlogPHP" Database Analysis Plugin DIY Demo

I feel like I do a lot of things based on intuition.jpg

Database Analysis [Basic Dependency] - Z-Blog Application Center:

https://app.zblogcn.com/?id=20812

↑ The function of this plugin is to "retrieve data, process it, and store it back", which is suitable for modifying and managing data that cannot be directly implemented using SQL;

The plugin itself only encapsulates the traversal and reading of the data to be operated on, and specific modifications need to be implemented by registering and calling functions separately;

For this reason, I wrote another plugin -

Database Analysis [Custom Function] - Z-Blog Application Center:

https://app.zblogcn.com/?id=21305

↑ Essentially, it is still about preparing something first, and then using a customizable /usr/xxx.php to implement specific user requirements, instead of creating and maintaining a complete plugin for each user requirement; "This plugin is chargeable and can implement corresponding data modification functions according to your needs"

In fact, I wrote a plugin "Putting Indefinite Functions into One Plugin" earlier -

DIY Something - Z-Blog Application Center:

https://app.zblogcn.com/?id=1961

↑ It can also be used in conjunction with the "Database Analysis [Basic Dependency]" plugin to implement batch operations on the database;

  • Create a folder named DiyForDataBaseHD in /zb_users/plugin/diySth/usr/ according to the instructions;
  • Automatically create internal files by refreshing the "Management Page", CSS and JS files will be generated at the same time, no need to worry about them;
  • Write the following content in DiyForDataBaseHD.php and load the function by refreshing the "diySth" plugin management page;
  • Switch to the management page of "Database Analysis [Basic Dependency]", and you should be able to see the added function button;
<?php
// ----
// DiyForDataBaseHD_Filter
Add_Filter_Plugin('Filter_Plugin_Admin_Header', 'DiyForDataBaseHD_AddHook');

// ----
// DiyForDataBaseHD_Function
function DiyForDataBaseHD_AddHook()
{
  global $zbp;
  $fnList = $zbp->Config('DataBaseHD')->fnList;
  $fnList[] = array("fn" => "DiyForDataBaseHD_UpAlias", "mod" => "Post", "name" => "Alias Specification");
  $zbp->Config('DataBaseHD')->fnList = $fnList;
}

// For historical reasons, the length of the alias of some articles is only 10 digits, so add one more digit to filter them
function DiyForDataBaseHD_UpAlias(&$post, $csrfToken = "")
{
  $tpl = "<p style='color:-color-;'>-id- | -url- | -oldHash- | -newHash- | -Save- | \"-edit-\" | \"-del-\"</p>\n";

  $arrData = array();
  $arrData["-color-"] = "-black-";
  $arrData["-id-"] = $post->ID;
  $arrData["-url-"] = DataBaseHD_DIY_a($post->Url, $post->Title);
  $arrData["-oldHash-"] = crc32($post->Content);

  // Edit or delete button
  $arrData["-edit-"] = "<a class=\"style-visited\" title=\"{$post->Title}\" target=\"_blank\" href='../../../zb_system/admin/edit.php?act=ArticleEdt&id={$post->ID}'>Edit</a>";
  // $arrData["-del-"] = "<a class=\"style-visited\" title=\"{$post->Title}\" target=\"_blank\" onclick=\"return window.confirm('Deleting \"{$post->Title}\". Please confirm!');\" href=\"../../../zb_system/cmd.php?act=ArticleDel&id={$post->ID}&csrfToken={$csrfToken}\">Delete</a>";

  // Main function code ↓

  $intDefLen = strlen("20220806158") - 1;

  // Skip articles that do not meet the conditions
  if (strlen($post->Alias) !== $intDefLen || !is_numeric($post->Alias)) {
    return;
  }
  // Update alias
  $post->Alias = $post->Alias . "4";
  $bolRlt = $post->Save();
  // Update link
  $arrData["-url-"] = DataBaseHD_DIY_a($post->Url, $post->Title);
  // Save the result of the operation
  $arrData["-Save-"] = $bolRlt ? "Save successful" : "Save failed";

  // Main function code ↑

  echo strtr($tpl, $arrData);
}

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.