sakkhho a écrit:
désolé pas le tps de m'y mettre...
Bin en fait, si je peux proposer ça :
main.inc.php
<?php /* Plugin Name: Statistics Version: 1.7.? Description: Add source code like Google Analytics on each page. Plugin URI: http://phpwebgallery.net/ext/extension_view.php?eid=174 Author: Ruben & Sakkhho Author URI: http://www.phpwebgallery.net */ if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); define('STAT_DIR' , basename(dirname(__FILE__))); define('STAT_PATH' , PHPWG_PLUGINS_PATH . STAT_DIR . '/'); function statistics_admin_menu($menu) { array_push($menu, array('NAME' => 'Statistics', 'URL' => get_admin_plugin_menu_link(STAT_PATH . 'admin/stat_admin.php'))); return $menu; } function stat_candoit() { global $conf, $user; $conf_statistics = explode("," , $conf['statistics']); $is_guest = (function_exists('is_a_guest') ? is_a_guest() : $user['is_the_guest']); if ( (($conf_statistics[0] == 'on') or ($conf_statistics[1] == 'on')) and (($conf_statistics[3] == 'on' and !is_admin()) or (empty($conf_statistics[3]))) and (($conf_statistics[4] == 'on' and !$is_guest) or (empty($conf_statistics[4]))) ) { return ' <!-- Plugin Statitics --> '.$conf_statistics[2].' <!-- Plugin Statitics -->'; } else { return false; } } function stat_tail() { global $template, $conf; $conf_statistics = explode("," , $conf['statistics']); if (($conf_statistics[1] == 'on') and ($code_stat = stat_candoit())) { $template->loadfile('tail'); $template->uncompiled_code['tail'] = str_replace('</div> <!-- the_page -->', $code_stat.' </div> <!-- the_page -->', $template->uncompiled_code['tail']); } } function stat_header() { global $template, $conf; $conf_statistics = explode("," , $conf['statistics']); if (($conf_statistics[0] == 'on') and ($code_stat = stat_candoit())) { $template->assign_block_vars('head_element', array('CONTENT' => $code_stat)); } } add_event_handler('get_admin_plugin_menu_links', 'statistics_admin_menu'); add_event_handler('loc_end_page_tail', 'stat_tail'); add_event_handler('loc_end_page_header', 'stat_header'); ?>
Je sais qu'il faut encore amélioré ce code, mais ça marche.
Ce qui m'embête, c'est qu'il y a trois fois le même appel à la base de données, mais mes connaissances en PHP ne me permettent pas de faire mieux.
Hors ligne
DalP a écrit:
Ce qui m'embête, c'est qu'il y a trois fois le même appel à la base de données, mais mes connaissances en PHP ne me permettent pas de faire mieux.
C'est quoi les 3 appels à la base de données?
Sinon, j'aurais plus mis le test du header et tail dans le candoit plutot que refaire des explode, etc...
Ca donnerai un truc du style:
<?php /* Plugin Name: Statistics Version: 1.7.? Description: Add source code like Google Analytics on each page. Plugin URI: http://phpwebgallery.net/ext/extension_view.php?eid=174 Author: Ruben & Sakkhho Author URI: http://www.phpwebgallery.net */ if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); define('STAT_DIR' , basename(dirname(__FILE__))); define('STAT_PATH' , PHPWG_PLUGINS_PATH . STAT_DIR . '/'); function statistics_admin_menu($menu) { array_push($menu, array('NAME' => 'Statistics', 'URL' => get_admin_plugin_menu_link(STAT_PATH . 'admin/stat_admin.php'))); return $menu; } function stat_candoit($type) { global $conf, $user; $conf_statistics = explode("," , $conf['statistics']); $is_guest = (function_exists('is_a_guest') ? is_a_guest() : $user['is_the_guest']); if ( (($conf_statistics[0] == 'on') and ($type == 'header')) and (($conf_statistics[1] == 'on') and ($type == 'tail')) and (($conf_statistics[3] == 'on' and !is_admin()) or (empty($conf_statistics[3]))) and (($conf_statistics[4] == 'on' and !$is_guest) or (empty($conf_statistics[4]))) ) { return ' <!-- Plugin Statitics --> '.$conf_statistics[2].' <!-- Plugin Statitics -->'; } else { return false; } } function stat_tail() { global $template; if ($code_stat = stat_candoit('tail')) { $template->loadfile('tail'); $template->uncompiled_code['tail'] = str_replace('</div> <!-- the_page -->', $code_stat.' </div> <!-- the_page -->', $template->uncompiled_code['tail']); } } function stat_header() { global $template; if ($code_stat = stat_candoit('header')) { $template->assign_block_vars('head_element', array('CONTENT' => $code_stat)); } } add_event_handler('get_admin_plugin_menu_links', 'statistics_admin_menu'); add_event_handler('loc_end_page_tail', 'stat_tail'); add_event_handler('loc_end_page_header', 'stat_header'); ?>
Attention, je ne l'ai pas testé!
Hors ligne
sakkhho a écrit:
ben j'ai mis la version de DalP en ligne elle marche
la tienne rub ne semble pas fonctionner. elle n'insert rien.
a+
sakkhho a écrit:
attention j'ai l'impression que la derniere version n'insert aucun code...
comprend pas.
C'est simple, j'avais écrit que je n'avais pas testé!
un or à la place du and et ca va mieux:
<?php /* Plugin Name: Statistics Version: 1.7.f Description: Add source code like Google Analytics on each page. Plugin URI: http://phpwebgallery.net/ext/extension_view.php?eid=174 Author: Ruben & Sakkhho Author URI: http://www.phpwebgallery.net */ if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); define('STAT_DIR' , basename(dirname(__FILE__))); define('STAT_PATH' , PHPWG_PLUGINS_PATH . STAT_DIR . '/'); function statistics_admin_menu($menu) { array_push($menu, array('NAME' => 'Statistics', 'URL' => get_admin_plugin_menu_link(STAT_PATH . 'admin/stat_admin.php'))); return $menu; } function stat_candoit($type) { global $conf, $user; $conf_statistics = explode("," , $conf['statistics']); $is_guest = (function_exists('is_a_guest') ? is_a_guest() : $user['is_the_guest']); if ( ( (($conf_statistics[0] == 'on') and ($type == 'header')) or (($conf_statistics[1] == 'on') and ($type == 'tail')) ) and (($conf_statistics[3] == 'on' and !is_admin()) or (empty($conf_statistics[3]))) and (($conf_statistics[4] == 'on' and !$is_guest) or (empty($conf_statistics[4]))) ) { return ' <!-- Plugin Statitics --> '.$conf_statistics[2].' <!-- Plugin Statitics -->'; } else { return false; } } function stat_tail() { global $template; if ($code_stat = stat_candoit('tail')) { $template->loadfile('tail'); $template->uncompiled_code['tail'] = str_replace('</div> <!-- the_page -->', $code_stat.' </div> <!-- the_page -->', $template->uncompiled_code['tail']); } } function stat_header() { global $template; if ($code_stat = stat_candoit('header')) { $template->assign_block_vars('head_element', array('CONTENT' => $code_stat)); } } add_event_handler('get_admin_plugin_menu_links', 'statistics_admin_menu'); add_event_handler('loc_end_page_tail', 'stat_tail'); add_event_handler('loc_end_page_header', 'stat_header'); ?>
Hors ligne
sakkhho, si tu as le temps, peux-tu:
1) changer le code de la fonction stat_tail par
function stat_tail() { global $template; if ($code_stat = stat_candoit('tail')) { $template->assign_block_vars('footer_element', array('CONTENT' => $code_stat)); } }
C'est compatible que 1.7.1 mais c'est surtout compatible Butterfly!
2)
Et as-vu les modifs ici:
http://forum.phpwebgallery.net/viewtopi … 674#p81674
Hors ligne
sakkhho a écrit:
j'integrerai les 2 modifs des que possible !
a+
cool & merci!
Hors ligne
Bonsoir,
J'ai installé l'excellentissime PluginManager et j'ai commencé à installer quelques plugins qui me manquaient. Et "statistics" me pose problème. Je me suis inscrit sur Google Analytics, récupéré le code, je l'ai mis dans le plugin et validé. Or 48 h après: rien.
J'ai cherché où j'avais pu commettre une bourde mais je ne trouve pas.
2 pistes: le lien fournit sur Google n'est pas bon ( que faut-il mettre ?) ou le code ne se colle pas (où devrait-il être pour être visible?)
Ah! 3eme piste: je suis chez Free :)
Version de PhpWebGallery
PhpWebGallery 1.7.1
Environnement
System d'exploitation: Linux
PHP: 5.1.3RC4-dev
MySQL: 5.0.45
http://argentanwebferro.free.fr/galerie/index.php
Merci
@+
Hors ligne