Skip to content

Commit

Permalink
Enable Modal for Themes (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
KTS915 authored Apr 18, 2024
1 parent 2055350 commit 0ca025a
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 240 deletions.
75 changes: 24 additions & 51 deletions classes/PluginInstall.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ public function styles($hook)
if ($hook !== $this->page) {
return;
}
wp_enqueue_style('classicpress-directory-integration-css-plugin', plugins_url('../styles/plugin-page.css', __FILE__), []);
wp_enqueue_style( 'classicpress-directory-integration-css', plugins_url( '../styles/directory-integration.css', __FILE__ ), []) ;
}

public function scripts($hook)
{
if ($hook !== $this->page) {
return;
}
wp_enqueue_script( 'classicpress-directory-integration-js-plugin', plugins_url( '../scripts/plugin-page.js', __FILE__ ), array( 'wp-i18n' ), false, true );
wp_set_script_translations( 'classicpress-directory-integration-js-plugin', 'classicpress-directory-integration', plugin_dir_path( 'classicpress-directory-integration' ) . 'languages' );
wp_enqueue_script( 'classicpress-directory-integration-js', plugins_url( '../scripts/directory-integration.js', __FILE__ ), array( 'wp-i18n' ), false, true );
wp_set_script_translations( 'classicpress-directory-integration-js', 'classicpress-directory-integration', plugin_dir_path( 'classicpress-directory-integration' ) . 'languages' );
}

public function create_menu()
Expand Down Expand Up @@ -330,7 +330,7 @@ public function render_menu()

// Query the directory
$args = [
'per_page' => 10,
'per_page' => 12,
'page' => $page,
];

Expand Down Expand Up @@ -358,33 +358,34 @@ public function render_menu()

<div class="wrap plugin-install-tab">
<h1 class="wp-heading-inline"><?php echo esc_html__('Plugins', 'classicpress-directory-integration'); ?></h1>
<h2 class="screen-reader-text"><?php echo esc_html__('Plugins list', 'classicpress-directory-integration'); ?></h2>

<!-- Search form -->
<div class="cp-plugin-search-form">
<form method="GET" action="<?php echo esc_url(add_query_arg(['page' => 'classicpress-directory-integration-plugin-install'], remove_query_arg(['getpage']))); ?>">
<p class="cp-plugin-search-box">
<label for="searchfor" class="screen-reader-text" ><?php echo esc_html__('Search for plugins', 'classicpress-directory-integration'); ?></label><br>
<input type="text" id="searchfor" name="searchfor" class="wp-filter-search" placeholder="<?php echo esc_html__('Search for a plugin...', 'classicpress-directory-integration'); ?>"><br>
<?php
foreach ((array) $_GET as $key => $val) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
if (in_array($key, ['searchfor'])) {
continue;
}
echo '<input type="hidden" name="' . esc_attr($key) . '" value="' . esc_html($val) . '" />';
}
?>
</p>
</form>
</div>
<hr class="wp-header-end">

<div class="cp-plugins-page">
<h2 class="screen-reader-text"><?php echo esc_html__('Plugins list', 'classicpress-directory-integration'); ?></h2>
<!-- Search form -->
<div class="cp-plugin-search-form">
<form method="GET" action="<?php echo esc_url(add_query_arg(['page' => 'classicpress-directory-integration-plugin-install'], remove_query_arg(['getpage']))); ?>">
<p class="cp-plugin-search-box">
<label for="searchfor" class="screen-reader-text" ><?php echo esc_html__('Search for plugins', 'classicpress-directory-integration'); ?></label><br>
<input type="text" id="searchfor" name="searchfor" class="wp-filter-search" placeholder="<?php echo esc_html__('Search for a plugin...', 'classicpress-directory-integration'); ?>"><br>
<?php
foreach ((array) $_GET as $key => $val) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
if (in_array($key, ['searchfor'])) {
continue;
}
echo '<input type="hidden" name="' . esc_attr($key) . '" value="' . esc_html($val) . '" />';
}
?>
</p>
</form>
</div>
<div class="cp-plugin-cards">
<?php
foreach ( $plugins as $plugin ) {
$slug = $plugin['meta']['slug'];
$content = $plugin['content']['rendered'];
$markdown_contents = cp_get_markdown_plugin_contents( $content, '<div class="markdown-heading">', '</div>' );
$markdown_contents = cp_get_markdown_contents( $content, '<div class="markdown-heading">', '</div>' );
foreach ( $markdown_contents as $markdown_content ) {
$content = str_replace( '<div class="markdown-heading">' . $markdown_content . '</div>', $markdown_content, $content );
}
Expand Down Expand Up @@ -460,31 +461,3 @@ public function feedback($string, ...$args)
{
}
}

/**
* Get all substrings within text that are found between two other, specified strings
*
* Avoids parsing HTML with regex
*
* Returns an array
*
* See https://stackoverflow.com/a/27078384
*/
function cp_get_markdown_plugin_contents( $str, $startDelimiter, $endDelimiter ) {
$contents = [];
$startDelimiterLength = strlen( $startDelimiter );
$endDelimiterLength = strlen( $endDelimiter );
$startFrom = $contentStart = $contentEnd = 0;

while ( $contentStart = strpos( $str, $startDelimiter, $startFrom ) ) {
$contentStart += $startDelimiterLength;
$contentEnd = strpos( $str, $endDelimiter, $contentStart );
if ( $contentEnd === false ) {
break;
}
$contents[] = substr( $str, $contentStart, $contentEnd - $contentStart );
$startFrom = $contentEnd + $endDelimiterLength;
}

return $contents;
}
50 changes: 29 additions & 21 deletions classes/ThemeInstall.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ public function styles($hook)
if ($hook !== $this->page) {
return;
}
wp_enqueue_style('classicpress-directory-integration-css-theme', plugins_url('../styles/theme-page.css', __FILE__), []);
wp_enqueue_style( 'classicpress-directory-integration-css', plugins_url( '../styles/directory-integration.css', __FILE__ ), [] );
}

public function scripts($hook)
{
if ($hook !== $this->page) {
return;
}
wp_enqueue_script('classicpress-directory-integration-js-theme', plugins_url('../scripts/theme-page.js', __FILE__), ['jquery'], false, true);
wp_enqueue_script( 'classicpress-directory-integration-js', plugins_url( '../scripts/directory-integration.js', __FILE__ ), array( 'wp-i18n' ), false, true );
wp_set_script_translations( 'classicpress-directory-integration-js', 'classicpress-directory-integration', plugin_dir_path( 'classicpress-directory-integration' ) . 'languages' );
}

public function create_menu()
Expand Down Expand Up @@ -315,7 +316,7 @@ public function render_menu()

// Query the directory
$args = [
'per_page' => 10,
'per_page' => 12,
'page' => $page,
];

Expand All @@ -342,16 +343,15 @@ public function render_menu()
?>

<div class="wrap plugin-install-tab">
<h1 class="wp-heading-inline"><?php esc_html__('Themes', 'classicpress-directory-integration'); ?></h1>
<hr class="wp-header-end">

<div class="cp-plugins-page">
<h3 class="screen-reader-text"><?php echo esc_html__('Themes list', 'classicpress-directory-integration'); ?></h3>
<!-- Search form -->
<div class="cp-plugin-search-form">
<form method="GET" action="<?php echo esc_url(add_query_arg(['page' => 'classicpress-directory-integration-theme-install'], remove_query_arg(['getpage']))); ?>">
<label for="searchfor"><?php echo esc_html__('Search', 'classicpress-directory-integration'); ?></label><br>
<input type="text" id="searchfor" name="searchfor" placeholder="<?php echo esc_html__('Search a theme...', 'classicpress-directory-integration'); ?>"><br>
<h1 class="wp-heading-inline"><?php echo esc_html__('Themes', 'classicpress-directory-integration'); ?></h1>
<h2 class="screen-reader-text"><?php echo esc_html__('Themes list', 'classicpress-directory-integration'); ?></h2>

<!-- Search form -->
<div class="cp-plugin-search-form">
<form method="GET" action="<?php echo esc_url(add_query_arg(['page' => 'classicpress-directory-integration-theme-install'], remove_query_arg(['getpage']))); ?>">
<p class="cp-plugin-search-box">
<label for="searchfor" class="screen-reader-text"><?php echo esc_html__('Search for a theme', 'classicpress-directory-integration'); ?></label><br>
<input type="text" id="searchfor" name="searchfor" class="wp-filter-search" placeholder="<?php echo esc_html__('Search for a theme...', 'classicpress-directory-integration'); ?>"><br>
<?php
foreach ((array) $_GET as $key => $val) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
if (in_array($key, ['searchfor'])) {
Expand All @@ -360,12 +360,21 @@ public function render_menu()
echo '<input type="hidden" name="' . esc_attr($key) . '" value="' . esc_html($val) . '" />';
}
?>
</form>
</div>
</p>
</form>
</div>
<hr class="wp-header-end">

<div class="cp-plugins-page">
<div class="cp-plugin-cards">
<?php
foreach ($themes as $theme) {
$slug = $theme['meta']['slug'];
$content = $theme['content']['rendered'];
$markdown_contents = cp_get_markdown_contents( $content, '<div class="markdown-heading">', '</div>' );
foreach ( $markdown_contents as $markdown_content ) {
$content = str_replace( '<div class="markdown-heading">' . $markdown_content . '</div>', $markdown_content, $content );
}
?>
<article class="cp-plugin-card" id="cp-plugin-id-<?php echo esc_attr($slug); ?>">
<header class="cp-plugin-card-header">
Expand All @@ -375,19 +384,19 @@ public function render_menu()
<div class="cp-plugin-card-body">
<div class="cp-plugin-description"><?php echo wp_kses_post($theme['excerpt']['rendered']); ?></div>
</div>
<footer class="cp-plugin-card-footer">
<footer class="cp-plugin-card-footer" data-content="<?php echo esc_attr( $content ); ?>">
<div class="cp-plugin-installs"><?php echo esc_html($theme['meta']['active_installations'] === '' ? 0 : $theme['meta']['active_installations']) . esc_html__(' Active Installations', 'classicpress-directory-integration'); ?></div>
<div class="cp-plugin-actions">
<a href="https://directory.classicpress.net/themes/<?php echo esc_attr( $slug ); ?>" target="_blank" class="button link-txt"><?php esc_html_e('More Details', 'classicpress-directory-integration'); ?></a>
<a href="<?php echo esc_url( admin_url( 'themes.php?tab=theme-information&theme=' . $slug ) ); ?>" class="button link-txt"><?php esc_html_e('More Details', 'classicpress-directory-integration'); ?></a>
<?php
if (!array_key_exists($slug, $local_cp_themes)) {
echo '<a href="' . esc_url_raw(wp_nonce_url(add_query_arg(['action' => 'install', 'slug' => $slug]), 'install', '_cpdi')) . '" class="button install-now">' . esc_html__('Install', 'classicpress-directory-integration') . '</a>';
echo '<a href="' . esc_url(wp_nonce_url(add_query_arg(['action' => 'install', 'slug' => $slug]), 'install', '_cpdi')) . '" class="button install-now">' . esc_html__('Install', 'classicpress-directory-integration') . '</a>';
}
if ( array_key_exists($slug, $local_cp_themes) && ($local_cp_themes[$slug]['Active'] == $slug ) ) {
echo '<span class="cp-plugin-installed">' . esc_html__('Active', 'classicpress-directory-integration') . '</span>';
echo '<span class="button cp-plugin-installed" tabindex="0">' . esc_html__('Active', 'classicpress-directory-integration') . '</span>';
}
if ( array_key_exists($slug, $local_cp_themes) && ($local_cp_themes[$slug]['Active'] != $slug ) ) {
echo '<a href="' . esc_url_raw(wp_nonce_url(add_query_arg(['action' => 'activate', 'slug' => $slug]), 'activate', '_cpdi')) . '" class="button button-primary">' . esc_html__('Activate', 'classicpress-directory-integration') . '</a>';
echo '<a href="' . esc_url(wp_nonce_url(add_query_arg(['action' => 'activate', 'slug' => $slug]), 'activate', '_cpdi')) . '" class="button button-primary">' . esc_html__('Activate', 'classicpress-directory-integration') . '</a>';
}
?>
</div>
Expand All @@ -398,7 +407,6 @@ public function render_menu()
?>
</div>

<hr>
<nav aria-label="<?php esc_attr_e('theme search results navigation', 'classicpress-directory-integration'); ?>">
<ul class="cp-plugins-pagination">
<?php
Expand Down
27 changes: 27 additions & 0 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,30 @@
die();
}

/**
* Get all substrings within text that are found between two other, specified strings
*
* Avoids parsing HTML with regex
*
* Returns an array
*
* See https://stackoverflow.com/a/27078384
*/
function cp_get_markdown_contents( $str, $startDelimiter, $endDelimiter ) {
$contents = [];
$startDelimiterLength = strlen( $startDelimiter );
$endDelimiterLength = strlen( $endDelimiter );
$startFrom = $contentStart = $contentEnd = 0;

while ( $contentStart = strpos( $str, $startDelimiter, $startFrom ) ) {
$contentStart += $startDelimiterLength;
$contentEnd = strpos( $str, $endDelimiter, $contentStart );
if ( $contentEnd === false ) {
break;
}
$contents[] = substr( $str, $contentStart, $contentEnd - $contentStart );
$startFrom = $contentEnd + $endDelimiterLength;
}

return $contents;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @file Functionality for the ClassicPress plugin install screens.
* @file Functionality for the ClassicPress install screens.
*/
document.addEventListener( 'DOMContentLoaded', function() {

Expand Down
3 changes: 0 additions & 3 deletions scripts/theme-page.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
color: #fff;
border: 1px solid #269126;
background-color: #269126;
cursor: unset;
}

@media (min-width: 783px) {
Expand Down
Loading

0 comments on commit 0ca025a

Please sign in to comment.