27.01.2016, 16:59
Siemka,
Chciałem nieco rozbudować skrypt o możliwość wstawiania zmiennych wtyczki z poziomu opcji i po wprowadzeniu jednego zapytania do settings całkowita liczba zapytań, wyświetlana na dole wzrosła z 10 do 20. Czym to może być spowodowane?
Ta anomalia pojawiła się gdy wprowadziłem to ostatnie zapytanie.
Chciałem nieco rozbudować skrypt o możliwość wstawiania zmiennych wtyczki z poziomu opcji i po wprowadzeniu jednego zapytania do settings całkowita liczba zapytań, wyświetlana na dole wzrosła z 10 do 20. Czym to może być spowodowane?
Kod PHP:
<?php
/*************************************************************\
*This file is part of "LastPosterAvatarLight" plugin for MyBB.
* Copyright © 2016 @ Artur "Niespecjalny" Michalak @ All rights reserved
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
\*************************************************************/
if(!defined("IN_MYBB")) exit;
$plugins->add_hook("forumdisplay_thread", "lastposteravatarlight_threads");
$plugins->add_hook("build_forumbits_forum", "lastposteravatarlight_forums");
$plugins->add_hook('search_results_thread', 'lastposteravatarlight_search_thread');
$plugins->add_hook('search_results_post', 'lastposteravatarlight_search');
function lastposteravatarlight_info(){
global $lang;
$lang->load('config_lastposteravatarlight');
return array(
"name"=>"LastPosterAvatarLight",
"description"=>$lang->lastposteravatarlight_desc,
"website"=>"",
"author"=>"Niespecjalny",
"authorsite"=>"",
"version"=>"0.5",
"guid"=>"",
"codename" => "LastPosterAvatarLight",
"compatibility"=>"18*"
);
}
function lastposteravatarlight_is_installed()
{
global $db;
return $db->num_rows($db->simple_select("settinggroups", "*", "name=\"lastposteravatarlight\""));
}
function lastposteravatarlight_install(){
global $db,$cache,$lang;
$lang->load('config_lastposteravatarlight');
$max_disporder = $db->fetch_field($db->simple_select("settinggroups", "MAX(disporder) AS max_disporder"), "max_disporder");
$settinggroup = array(
"gid" => "",
"name" => "lastposteravatarlight",
"title" => "LastPosterAvatarLight",
"description" => $db->escape_string($lang->setting_group_lastposteravatarlight_desc),
"disporder" => $max_disporder + 1,
"isdefault" => "0"
);
$gid = $db->insert_query("settinggroups", $settinggroup);
$settings[] = array(
"sid" => "",
"name" => "lastposteravatarlight_fpal_thread",
"title" => $db->escape_string($lang->setting_lastposteravatarlight_1),
"description" => $db->escape_string($lang->setting_lastposteravatarlight_1_desc),
"optionscode" => "text",
"value" => $db->escape_string("<td class=\"\{\$bgcolor\}\{\$thread_type_class\}\">(.*?)\{\$attachment_count\}"),
"disporder" => "1",
"gid" => $gid,
"isdefault" => "0"
);
$settings[] = array(
"sid" => "",
"name" => "lastposteravatarlight_lpal_thread",
"title" => $db->escape_string($lang->setting_lastposteravatarlight_2),
"description" => $db->escape_string($lang->setting_lastposteravatarlight_2_desc),
"optionscode" => "text",
"value" => $db->escape_string("<td class=\"\{\$bgcolor\}\{\$thread_type_class\}\" style=\"white-space: nowrap; text-align: right;\">(.*?)<span class=\"lastpost smalltext\">"),
"disporder" => "2",
"gid" => $gid,
"isdefault" => "0"
);
$settings[] = array(
"sid" => "",
"name" => "lastposteravatarlight_fpal",
"title" => $db->escape_string($lang->setting_lastposteravatarlight_3),
"description" => $db->escape_string($lang->setting_lastposteravatarlight_3_desc),
"optionscode" => "text",
"value" => $db->escape_string("(.*?)<span class=\"smalltext\">"),
"disporder" => "3",
"gid" => $gid,
"isdefault" => "0"
);
$settings[] = array(
"sid" => "",
"name" => "lastposteravatarlight_lpal",
"title" => $db->escape_string($lang->setting_lastposteravatarlight_4),
"description" => $db->escape_string($lang->setting_lastposteravatarlight_4_desc),
"optionscode" => "text",
"value" => $db->escape_string("(.*?)<span class=\"smalltext\">"),
"disporder" => "4",
"gid" => $gid,
"isdefault" => "0"
);
$settings[] = array(
"sid" => "",
"name" => "lastposteravatarlight_fpal",
"title" => $db->escape_string($lang->setting_lastposteravatarlight_5),
"description" => $db->escape_string($lang->setting_lastposteravatarlight_5_desc),
"optionscode" => "text",
"value" => $db->escape_string("<td class=\"\{\$bgcolor\}\">(.*?)\{\$attachment_count\}"),
"disporder" => "5",
"gid" => $gid,
"isdefault" => "0"
);
$settings[] = array(
"sid" => "",
"name" => "lastposteravatarlight_lpal",
"title" => $db->escape_string($lang->setting_lastposteravatarlight_6),
"description" => $db->escape_string($lang->setting_lastposteravatarlight_6_desc),
"optionscode" => "text",
"value" => $db->escape_string("<td class=\"\{\$bgcolor\}\" style=\"white-space: nowrap\" align=\"right\">(.*?)<span class=\"smalltext\">"),
"disporder" => "6",
"gid" => $gid,
"isdefault" => "0"
);
$settings[] = array(
"sid" => "",
"name" => "lastposteravatarlight_lpal",
"title" => $db->escape_string($lang->setting_lastposteravatarlight_7),
"description" => $db->escape_string($lang->setting_lastposteravatarlight_7_desc),
"optionscode" => "text",
"value" => $db->escape_string("<td align=\"center\" class=\"\{\$bgcolor\}\">(.*?)\{\$post[\'profilelink\']\}</td>"),
"disporder" => "7",
"gid" => $gid,
"isdefault" => "0"
);
$settings[] = array(
"sid" => "",
"name" => "lastposteravatarlight_ref",
"title" => $db->escape_string($lang->setting_lastposteravatarlight_8),
"description" => $db->escape_string($lang->setting_lastposteravatarlight_8_desc),
"optionscode" => "yesno",
"value" => "1",
"disporder" => "8",
"gid" => $gid,
"isdefault" => "0"
);
$db->insert_query_multiple("settings", $settings);
rebuild_settings();
$install_lpal=$db->fetch_array($db->simple_select("themestylesheets", "COUNT(name)", "name=\"lastposteravatarlight.css\" AND tid=1", Null));
if($install_lpal>1){
$db->delete_query("themestylesheets", "name = \"lastposteravatarlight.css\" AND tid=1");
$install_lpal=0;
}
if($install_lpal==0)
{
$install_lpal_style=".lpal,.lpal>img{border-radius:100%}.lpal{overflow:auto;float:left;margin-right:5px}.lpal>img{border:1px solid #ccc}";
$install_lpal= array(
"sid" => "",
"name" => "lastposteravatarlight.css",
"cachefile" => "lastposteravatarlight.css",
"tid" => "1",
"attachedto" => "forumdisplay.php|index.php|search.php",
"stylesheet" => $db->escape_string($install_lpal_style),
"lastmodified" => TIME_NOW
);
$db->insert_query("themestylesheets", $install_lpal);
require_once MYBB_ADMIN_DIR."inc/functions_themes.php";
cache_stylesheet(1, "lastposteravatarlight.css", $install_lpal_style);
update_theme_stylesheet_list(1, false, true);
}
}
function lastposteravatarlight_uninstall(){
global $db,$cache,$mybb;
$db->delete_query("themestylesheets", "name=\"lastposteravatarlight.css\" AND tid=1");
require_once MYBB_ADMIN_DIR."inc/functions_themes.php";
@unlink(MYBB_ROOT."cache/themes/theme1/lastposteravatarlight.css");
@unlink(MYBB_ROOT."cache/themes/theme1/lastposteravatarlight.min.css");
update_theme_stylesheet_list(1, false, true);
$db->delete_query("settinggroups", "name = \"lastposteravatarlight\"");
$db->delete_query("settings", "name LIKE \"lastposteravatarlight%\"");
rebuild_settings();
}
function lastposteravatarlight_threads(){
global $thread,$mybb,$forum;
if($mybb->settings['lastposteravatarlight_ref']){lastposteravatarlight_options_ref();}
$user = get_user($thread['lastposteruid']);
$useravatar = format_avatar(htmlspecialchars_uni($user['avatar']), $user['avatardimensions'], my_strtolower("30x30"));
$forum['lpal']="<a href=\"{$mybb->settings['bburl']}/".get_profile_link($user['uid'])."\" class=\"lpal\"><img src=\"{$useravatar['image']}\" alt=\"{$user['username']}\" title=\"{$user['username']}\" {$useravatar['width_height']}/></a>";
$user = get_user($thread['uid']);
$useravatar = format_avatar(htmlspecialchars_uni($user['avatar']), $user['avatardimensions'], my_strtolower("30x30"));
$forum['fpal']="<a href=\"{$mybb->settings['bburl']}/".get_profile_link($user['uid'])."\" class=\"lpal\"><img src=\"{$useravatar['image']}\" alt=\"{$user['username']}\" title=\"{$user['username']}\" {$useravatar['width_height']}/></a>";
}
function lastposteravatarlight_forums(&$forum){
global $mybb;
if($mybb->settings['lastposteravatarlight_ref']){lastposteravatarlight_options_ref();}
$user=get_user($forum['lastposteruid']);
$useravatar = format_avatar(htmlspecialchars_uni($user['avatar']), $user['avatardimensions'], my_strtolower("45x45"));
$forum['lpal']="<a href=\"{$mybb->settings['bburl']}/".get_profile_link($user['uid'])."\" class=\"lpal\"><img src=\"{$useravatar['image']}\" alt=\"{$user['username']}\" title=\"{$user['username']}\" {$useravatar['width_height']}/></a>";
}
function lastposteravatarlight_search(){
global $mybb,$post,$forum;
if($mybb->settings['lastposteravatarlight_ref']){lastposteravatarlight_options_ref();}
$user=get_user($post['uid']);
$useravatar = format_avatar(htmlspecialchars_uni($user['avatar']), $user['avatardimensions'], my_strtolower("30x30"));
$forum['lpal']="<a href=\"{$mybb->settings['bburl']}/".get_profile_link($user['uid'])."\" class=\"lpal\" style=\"float:none;display:inline-block;vertical-align:middle;margin-right:5px\"><img src=\"{$useravatar['image']}\" alt=\"{$user['username']}\" title=\"{$user['username']}\" {$useravatar['width_height']}/></a>";
}
function lastposteravatarlight_search_thread(){
global $mybb,$thread,$forum;
if($mybb->settings['lastposteravatarlight_ref']){lastposteravatarlight_options_ref();}
$user=get_user($thread['lastposteruid']);
$useravatar = format_avatar(htmlspecialchars_uni($user['avatar']), $user['avatardimensions'], my_strtolower("30x30"));
$forum['lpal']="<a href=\"{$mybb->settings['bburl']}/".get_profile_link($user['uid'])."\" class=\"lpal\"><img src=\"{$useravatar['image']}\" alt=\"{$user['username']}\" title=\"{$user['username']}\" {$useravatar['width_height']}/></a>";
$user = get_user($thread['uid']);
$useravatar = format_avatar(htmlspecialchars_uni($user['avatar']), $user['avatardimensions'], my_strtolower("30x30"));
$forum['fpal']="<a href=\"{$mybb->settings['bburl']}/".get_profile_link($user['uid'])."\" class=\"lpal\"><img src=\"{$useravatar['image']}\" alt=\"{$user['username']}\" title=\"{$user['username']}\" {$useravatar['width_height']}/></a>";
}
function lastposteravatarlight_options_ref(){
global $db;
$db->update_query("settings", array("value"=>"0"), "`name`='lastposteravatarlight_ref'");
}
?>
Ta anomalia pojawiła się gdy wprowadziłem to ostatnie zapytanie.