Snippets
Created by
Niko Strijbol
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | <?php
if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) { die('You are not allowed to call this page directly.'); }
/*
Plugin Name: NextCellent Gallery Search
Plugin URI: http://wordpress.org/plugins/nextcellent-gallery-search-galleries/
Description: Adds a gallery search option to the NextCellent galleries menu. <strong>Please notice: </strong>you can only search galleries with this plugin. You can search for images by using the search option in the top right on the 'Manage Galleries' page.
Author: Mr.Lovebucket
Version: 1.0
Modified version of the latest NextGEN Gallery Search
Copyright (c) 2014
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* Add submenu to the NextCellent gallery menu.
**/
function add_wp_ngg_search() {
/*
* We HAVE to create a new menu in order to get the submenu working, but we fix that by making the initial menu invisible with CSS
*/
add_menu_page('Search a Gallery in NextCellent Galleries', __('Search Galleries','ngg-search'), 'upload_files', 'ngg-search', 'wp_ngg_search', plugin_dir_url( __FILE__ ).'icon.png');
add_submenu_page('nextcellent-gallery-nextgen-legacy', 'Search Galleries', 'Search Galleries', 'upload_files', 'ngg-search', wp_ngg_search);
}
add_action('admin_menu', 'add_wp_ngg_search');
/**
* Start the function
**/
function wp_ngg_search() {
?>
<!-- There was not a lot to style so we use an internal stylesheet -->
<style>
#search { float: left; margin: 0 0 23px 0; }
#help strong {font-size: 15px; }
#help { margin: -8px 0 0 21px; float: left; background: #FFFBCC; border: 1px solid #E6DB55; width: 398px; padding: 10px; border-radius: 5px; }
#toplevel_page_ngg-search { display: none; }
</style>
<!-- Start the table where the results will be shown -->
<div class="wrap">
<table class="wp-list-table widefat fixed" cellspacing="0">
<thead>
<tr>
<th id="id" class="manage-column column-id sortable asc" style="width:45px" scope="col">
<span style="padding: 7px 7px 8px;">ID</span>
</th>
<th id="title" class="manage-column column-title sortable desc" style="width:30%" scope="col">
<span style="padding: 7px 7px 8px;">Gallery</span>
</th>
<th id="description" class="manage-column column-description" style="width:65%" scope="col">Description</th>
</tr>
</thead>
<tfoot>
<tr>
<th id="id" class="manage-column column-id sortable asc" style="width:45px" scope="col">
<span style="padding: 7px 7px 8px;">ID</span>
</th>
<th id="title" class="manage-column column-title sortable desc" style="width:30%" scope="col">
<span style="padding: 7px 7px 8px;">Gallery</span>
</th>
<th id="description" class="manage-column column-description" style="width:65%" scope="col">Description</th>
</tr>
</tfoot>
<tbody id="the-list">
<div id="icon-NextCellent-gallery" class="icon32"></div>
<h2>Search Galleries</h2><br>
<!-- Here we begin our search form -->
<form action="admin.php?page=ngg-search" method="post">
<div id="search">
<!-- Checkbox for the 'add description' option -->
<input name="description" id="description" style="margin: 0 5px 0 0;" type="checkbox" value="description" <?php if(isset($_POST['description'])) echo "checked='checked'"; ?>>Also search in description</br>
<!-- Search input field -->
<input name="find" id="find" maxlength="255" title="" style="margin-right: 3px; padding: 4px 4px 5px; width: 300px;" value="<?php echo ($_POST['find']);?>" type="text">
<!--Break multiple inputs into a single variables -->
<?php if (isset($_POST['submit'])) {
$string = $_POST['find'];
/* We don't want to use explode here, just in case there are extra spaces in the search query */
$parts = preg_split('/\s+/', $string);
/* Find the last word in the query */
$last_word = end($parts);
/*
* Here we create all the search queries
* Each word in the search input field will get it's own LIKE query for mySQL, so it doesn't matter how many words are used
*/
foreach($parts as $part) {
/* Check to see if it's the last word in the query */
if($part == $last_word) {
$title .= 'title LIKE \'%'.$part.'%\'';
$desc .= 'galdesc LIKE \'%'.$part.'%\'';
} else {
$title .= 'title LIKE \'%'.$part.'%\' OR ';
$desc .= 'galdesc LIKE \'%'.$part.'%\' OR ';
}
}
}
?>
<input class="button" name="submit" type="submit" value="Search" style="margin-top: 5px;">
</div>
</form>
<?php
global $wpdb;
/*
* Get the prefix for the database
*/
$gallery = $wpdb->prefix . 'ngg_gallery';
/*
* Check if there is input and if the description checkbox is on, and show results
*/
if ($string != '') {
if(isset($_POST['description'])) {
/* if the 'add description' checkbox is on we use this line */
$result = $wpdb->get_results( "SELECT * FROM ". $gallery ." WHERE (". $title . " OR " . $desc . ") ");
} else {
/* if the 'add description' checkbox is off we use this line */
$result = $wpdb->get_results( "SELECT * FROM ". $gallery ." WHERE (". $title . ") ");
}
if (!empty($result)) {
foreach($result as $row) {
echo '<tr id="gallery-' .$row->gid. '">';
echo '<td class="id column-id">' .$row->gid. '</td>';
echo '<td class="title column-title">';
echo '<a class="edit" title="Bewerken" href="admin.php?page=nggallery-manage&mode=image&gid=' .$row->gid. '">' .$row->title. '</a>';
echo '<div class="row-actions"></div>';
echo '</td>';
echo '<td class="description column-description">' .$row->galdesc. '</td>';
echo '</tr>';
}
} else {
echo '<div id="help">No results. Please try again with part of the name.<br>For instance: <strong>int</strong> will find <strong>int</strong>ernet, but also w<strong>int</strong>er, ballpo<strong>int</strong>, sa<strong>int</strong>s etc.</div><br>';
}
}
?>
</tbody>
</table>
</div>
<?php }
/****************************************************************************************
* Check to make sure NextCellent Gallery is installed and activated.
* If not, show an admin notification to assist with the installation/activation process.
****************************************************************************************/
function nggs_NextCellent_installed_and_activated_check() {
global $pagenow;
if ($pagenow == 'plugins.php' || isset($_GET['page'])) {
// check if NextCellent gallery is installed
if (!get_plugins('/nextcellent-gallery-nextgen-legacy')) {
$nggs_NextCellent_check = '<div class="error"><p>';
$nggs_NextCellent_check.= '<b>NextCellent Gallery Search Error:</b><br />';
$nggs_NextCellent_check.= 'NextCellent Gallery Search is an add-on for the NextCellent Gallery WordPress plugin, but <b>NextCellent Gallery is not <i>installed</i>.</b><br />';
$nggs_NextCellent_check.= 'Please <a href="' . get_admin_url('', 'plugin-install.php?tab=search&s=NextCellent+Gallery') . '">download it here automatically</a> ';
$nggs_NextCellent_check.= 'or <a href="http://wordpress.org/extend/plugins/nextcellent-gallery-nextgen-legacy">manually from the WordPress repository</a>.';
$nggs_NextCellent_check.= '</p></div>';
echo $nggs_NextCellent_check;
}
// check if NextCellent gallery is installed and activated
if (get_plugins('/nextcellent-gallery-nextgen-legacy') && !is_plugin_active('nextcellent-gallery-nextgen-legacy/nggallery.php')) {
$nggs_NextCellent_check = '<div class="error"><p>';
$nggs_NextCellent_check.= '<b>NextCellent Gallery Search Error Notification:</b><br />';
$nggs_NextCellent_check.= 'NextCellent Gallery Search is an add-on for the NextCellent Gallery WordPress plugin, but <b>NextCellent Gallery is not <i>activated</i>.</b><br />';
$nggs_NextCellent_check.= 'Please click the "Activate" link under the "NextCellent Gallery" item on <a href="' . get_admin_url('', 'plugins.php') . '">your plugins page</a>.';
$nggs_NextCellent_check.= '</p></div>';
echo $nggs_NextCellent_check;
}
}
}
add_action('admin_notices', 'nggs_NextCellent_installed_and_activated_check');
?>
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.