plugin_name = $plugin_name; $this->plugin_path = $plugin_path; $this->load_config(); // handler $this->initialize_event_handler(); } /************************************************************************** * function: initialize_event_handler ************************************************************************** * Rôle: * Ajout des handlers nécessaires aux pages index et picture * si les droits l'autorisent. *************************************************************************/ function initialize_event_handler() { if ((($this->config['URLShackRight'] == "admin") && (is_admin())) || (($this->config['URLShackRight'] == "member") && (!is_a_guest())) || ($this->config['URLShackRight'] == "all")) { if (script_basename() != $this->plugin_name.'_controller') { add_event_handler('loc_end_index', array(&$this, 'handler_index')); add_event_handler('picture_pictures_data', array(&$this, 'handler_picture')); } } } /************************************************************************** * function: loading_lang ************************************************************************** * Rôle: * Chargement des données de langue *************************************************************************/ function loading_lang() { load_language('plugin.lang', $this->plugin_path); } /************************************************************************** * function: get_link_icon ************************************************************************** * in: * out: * code de l'action ************************************************************************** * Rôle: * Retourne le code de l'action d'ouverture piwishack *************************************************************************/ function get_link_icon($main_link) { global $page; if (empty($page['items'])) { return; } $this->loading_lang(); $link_title = l10n('open_window_piwishack'); $link_url = 'URLShack links popup'; return $link_url; } /************************************************************************** * function: handler_index ************************************************************************** * in: * out: * Code source ************************************************************************** * Rôle: * Handler dans le cas des pages d'index : ajoute le code javascript, * le code html du popup et l'icone d'ouverture piwishack. *************************************************************************/ function handler_index() { global $template; $link_url = $this->get_link_icon(duplicate_index_url()); if (!empty($link_url)) { $mystyle = ''; $template->block_html_head(null, $mystyle); // get button javascript code and add to page $code = $this->get_js_button_code(); $template->concat('PLUGIN_INDEX_CONTENT_AFTER', $code); // Add piwishack button in the list of action icons $template->concat('PLUGIN_INDEX_ACTIONS', '
  • '.$link_url.'
  • '); // get popup html code and add to page $popup = $this->get_html_popup_code("index"); $template->concat('PLUGIN_INDEX_CONTENT_AFTER', $popup); } } /************************************************************************** * function: handler_picture ************************************************************************** * in: * out: * Code source ************************************************************************** * Rôle: * Handler dans le cas des pages images : ajoute le code javascript, * le code html du popup et l'icone d'ouverture piwishack. *************************************************************************/ function handler_picture($pictures) { global $template; $link_url = $this->get_link_icon(duplicate_index_url()); if (!empty($link_url)) { $mystyle = ''; $template->block_html_head(null, $mystyle); // get button javascript code and add to page $code = $this->get_js_button_code(); $template->concat('PLUGIN_PICTURE_AFTER', $code); // Add piwishack button in the list of action icons $template->concat('PLUGIN_PICTURE_ACTIONS', $link_url); // get popup html code and add to page $popup = $this->get_html_popup_code("picture"); $template->concat('PLUGIN_PICTURE_AFTER', $popup); } return $pictures; } /************************************************************************** * function: get_js_button_code ************************************************************************** * in: * out: * Code source ************************************************************************** * Rôle: * Genere le code javascript de la page *************************************************************************/ function get_js_button_code() { $this->loading_lang(); $link_open = l10n('open_window_piwishack'); $link_close = l10n('close_window_piwishack'); $icon_open = get_root_url() . 'plugins/piwishack/icon/controller_open.png'; $icon_close = get_root_url() . 'plugins/piwishack/icon/controller_close.png'; $code = ' '; return $code; } /************************************************************************** * function: get_html_popup_code ************************************************************************** * in: * $pagetype (index ou picture) * out: * Code source ************************************************************************** * Rôle: * Genere le code html complet du popup piwishack *************************************************************************/ function get_html_popup_code($pagetype) { $prefix = 0; $icon_close = get_root_url() . 'plugins/piwishack/icon/controller_close.png'; $icon_open = get_root_url() . 'plugins/piwishack/icon/controller_open.png'; $this->get_data(); $listdisp = $this->config['Display']; asort($listdisp); $namedisp = array_keys($listdisp); $this->loading_lang(); $popup = "
    \n"; $popup .= "
      Piwishack
    \n"; $popup .= "
    \n"; $popup .= "

    " . l10n('Partage_me') . "

    \n"; $popup .= "
    \n"; $popup .= "\n"; $popup .= l10n('sheet_html') . "\n"; $popup .= "\n"; $popup .= l10n('sheet_bbcode') . "\n"; $popup .= "\n"; $popup .= l10n('sheet_custom') . "\n"; $popup .= "
    \n"; // A block is inserted for each format, bbcode and html // but displayed only for the selected (radio) format foreach (array("html", "bbcode") as $format) { $popup.= "
    \n"; foreach ($namedisp as $i) { if ($listdisp[$i] != 0) { // Compute code length $current_code = $this->get_codes($i, $format, $prefix); $nb_cols = 100; $nb_rows = min(1 + (strlen($current_code) / $nb_cols), 5); $popup .= "
    \n"; $popup .= "

    ". l10n('post_code_' .$i) . " :

    "; $popup .= ''; $popup .= "$i"; $popup .= "
    \n"; } } $popup .= "
    \n"; } $nb = count($this->config['ExtendedDisplay']); $popup .= "
    \n"; for ($i = 0; $i < $nb; $i++) { if ($this->config['ExtendedDisplay'][$i] != "") { // Compute code length $current_code = $this->get_list_pattern_result($this->config['ExtendedDisplay'][$i]); $nb_cols = 125; $nb_rows = min(1 + (strlen($current_code) / $nb_cols), 5); $popup .= "
    \n"; $popup .= "

    " . l10n('custom_code') . ($i+1) . " - " . $this->config['ExtendedLabel'][$i] . "

    "; $popup .= ''; $popup .= "
    \n"; } } $popup .= "
    \n"; $popup .= "
    \n"; $popup .= "\n"; $popup .= "
    \n"; return $popup; } /************************************************************************** * function: get_data ************************************************************************** * in: * out: ************************************************************************** * Rôle: * Remplit le tableau d'images en fonction du contexte *************************************************************************/ function get_data() { global $page; $this->list = array(); $S = ''; switch (script_basename()) { case 'index': { global $pictures; if (isset($pictures)) { $this->list = $pictures; } break; } case 'picture': { global $picture; if (isset($picture['current'])) { $this->list[] = $picture['current']; } break; } } if (empty($this->list) and !empty($page['items'])) { $rank_of = array_flip($page['items']); $query = ' SELECT * FROM '.IMAGES_TABLE.' WHERE id IN ('.implode(',', $page['items']).') ;'; $result = pwg_query($query); while ($row = pwg_db_fetch_assoc($result)) { $row['rank'] = $rank_of[ $row['id'] ]; array_push($this->list, $row); } usort($this->list, 'rank_compare'); } } /************************************************************************** * function: get_codes ************************************************************************** * in: * $type: type du code * $format: html ou bbcode * $prefix : indique si le nom doit précéder le code * out: * Code du type ************************************************************************** * Rôle: * Retourne le code (pattern) correspondant au type fourni * en le faisant précéder éventuellement du nom de l'image *************************************************************************/ function get_codes($type, $format, $prefix) { $pattern = ''; $target = $this->config['WebLinkOpenOnOtherWindow'] == "other" ? " target=_blank" : ""; if ($type === 'Thumbnail') { if ($format === 'html') { $pattern = ""; } if ($format === 'bbcode') { $pattern = "[img]##t[/img]"; } } else if ($type === 'ThumbnailToImage') { if ($format === 'html') { $pattern = ""; } if ($format === 'bbcode') { $pattern = "[url=##i][img]##t[/img][/url]"; } } else if ($type === 'ThumbnailToGallery') { if ($format === 'html') { $pattern = ""; } if ($format === 'bbcode') { $pattern = "[url=##g][img]##t[/img][/url]"; } } else if ($type === 'Image') { if ($format === 'html') { $pattern = ""; } if ($format === 'bbcode') { $pattern = "[img]##i[/img]"; } } else if ($type === 'ImageToGallery') { if ($format === 'html') { $pattern = ""; } if ($format === 'bbcode') { $pattern = "[url=##g][img]##i[/img][/url]"; } } else if ($type === 'NameToImage') { if ($format === 'html') { $pattern = "##n"; } if ($format === 'bbcode') { $pattern = "[url=##i]##n[/url]"; } } else if ($type === 'NameToGallery') { if ($format === 'html') { $pattern = "##n"; } if ($format === 'bbcode') { $pattern = "[url=##g]##n[/url]"; } } if ($prefix === 1) { // TO_DO : n'ajouter que si ##n n'est pas déjà dans la chaine ? $pattern = "##n: " . $pattern; } return $this->get_list_pattern_result($pattern); } /************************************************************************** * function: get_list_pattern_result ************************************************************************** * in: * $pattern * out: * Le code à afficher ************************************************************************** * Rôle: * Retourne la chaine à afficher pour le pattern fourni et pour * l'ensemble des images du contexte courant *************************************************************************/ function get_list_pattern_result($pattern) { global $page, $lang_info, $conf; // force $conf['derivative_url_style'] to 2 (script) to make sure // exported HTML/BBCode will use i.php?/upload and not _data/i/upload // because you don't know when the cache will be flushed $previous_derivative_url_style = $conf['derivative_url_style']; $conf['derivative_url_style'] = 2; $S = ''; if (!empty($this->list)) { set_make_full_url(); foreach ($this->list as $row) { $S .= $this->get_pattern_result($row, $pattern) . "\n"; } unset_make_full_url(); } // restore configuration setting $conf['derivative_url_style'] = $previous_derivative_url_style; return $S; } /************************************************************************** * function: get_pattern_result ************************************************************************** * in: * $pattern * out: * La chaine expansée ************************************************************************** * Rôle: * transformer le pattern fourni en résolvant les variables * ##i : image URL * ##t : thumbnail URL * ##g : galerie URL * ##n : nom de l'image *************************************************************************/ function get_pattern_result($row, $pattern) { global $page, $lang_info; include_once(PHPWG_ROOT_PATH.'/include/functions_picture.inc.php'); // nom image $name = (!empty($row['name']) ? $row['name'] : $row['file']); // lien image miniature $tbn = DerivativeImage::thumb_url($row); // lien image grand format $img = DerivativeImage::url(IMG_MEDIUM, $row); // lien image dans sa galerie $gal = duplicate_picture_url( array( 'image_id' => $row['id'], 'image_file' => $row['file'],)); $applic = str_replace('##i', $img, $pattern); $applic = str_replace('##t', $tbn, $applic); $applic = str_replace('##g', $gal, $applic); $applic = str_replace('##n', $name, $applic); return $applic; } /************************************************************************** * function: load_config ************************************************************************** * Rôle: * Chargement de la configuration du plugin * Definition des valeurs par défaut *************************************************************************/ function load_config() { $x = @file_get_contents( dirname(__FILE__).'/data.dat' ); if ($x!==false) { $c = unserialize($x); $this->config = $c; } if ( !isset($this->config)) { // Default configuration $this->config['URLShackRight'] = 'admin'; // admin, members, all $this->config['DefaultHtmlBBcode'] = 'bbcode'; // bbcode, html, custom $this->config['WebLinkOpenOnOtherWindow'] = 'local'; // local, other $this->config['ImageNameBeforeCode'] = 'list'; // no, list, all $this->config['Display']['Thumbnail'] = 1; $this->config['Display']['ThumbnailToGallery'] = 2; $this->config['Display']['ThumbnailToImage'] = 3; $this->config['Display']['Image'] = 4; $this->config['Display']['ImageToGallery'] = 5; $this->config['Display']['NameToImage'] = 0; $this->config['Display']['NameToGallery'] = 0; $this->config['ExtendedDisplay'][0] = "Thumbnail in Textile format"; $this->config['ExtendedLabel'][0] = "!##t(##n)!"; $this->config['ExtendedDisplay'][1] = "{{##i|##n}}"; $this->config['ExtendedLabel'][1] = "Image in Creole format"; $this->config['ExtendedDisplay'][2] = '
    ##t
    '; $this->config['ExtendedLabel'][2] = "Personnalised HTML format example"; $this->config['ExtendedDisplay'][3] = "##n : ##i"; $this->config['ExtendedLabel'][3] = "Image name + image URL"; $this->config['ExtendedDisplay'][4] = ""; $this->config['ExtendedLabel'][4] = ""; $this->config['ExtendedDisplay'][5] = ""; $this->config['ExtendedLabel'][5] = ""; $this->config['ExtendedDisplay'][6] = ""; $this->config['ExtendedLabel'][6] = ""; $this->save_config(); } } /************************************************************************** * function: save_config ************************************************************************** * Rôle: * Sauvegarde de la configuration du plugin *************************************************************************/ function save_config() { $file = fopen( dirname(__FILE__).'/data.dat', 'w' ); fwrite($file, serialize($this->config) ); fclose( $file ); } /************************************************************************** * function: plugin_admin_menu ************************************************************************** * in: menu * out: menu ************************************************************************** * Rôle: * Ajout du lien d'administration du plugin *************************************************************************/ function plugin_admin_menu($menu) { array_push($menu, array( 'NAME' => 'PiwiShack', 'URL' => get_admin_plugin_menu_link(dirname(__FILE__).'/admin/piwishack_admin.php') ) ); return $menu; } } ?>