- május 2012 (1)
- január 2012 (1)
- július 2011 (1)
- május 2011 (1)
- február 2011 (1)
- január 2011 (3)
- december 2010 (2)
- november 2010 (2)
- október 2010 (3)
- szeptember 2010 (2)
- 1 / 2
- ››
Ez a bejegyzés egy korábbi cikk folytatása, melyben egy TinyMCE plugin alapjait írtam le. A Soundcloud filter modulban társfejlesztő vagyok, így úgy gondoltam azon megyek végig, így egy gyakorlati példát mutatok.
A kiegészítő létrehoz egy menüpontot ami a popup forrása lesz, és JavaScript-tel kezel textfield és checkbox input-okat. Az input-ok alapján legenerálja a filter forrást, illetve felülírja ha már létezik.
A hook_wysiwyg_plugin() implementálásáról már írtam a korábbi bejegyzésben, úgyhogy a hook_menu()-vel és a hook_perm()-mel kezdeném:
/** * Implementation of hook_menu(). * * @return An array of menu items. */ function soundcloud_filter_menu() { $items = array(); $items['soundcloud-filter/wysiwyg'] = array( 'title' => 'Wysiwyg Popup', 'page callback' => 'soundcloud_filter_wysiwyg_popup', 'access arguments' => array('access soundcloud filter wysiwyg popup'), 'type' => MENU_CALLBACK, ); return $items; } /** * Implementation of hook_perm(). * * @return array An array of valid permissions for the soundcloud_filter module */ function soundcloud_filter_perm() { return array('access soundcloud filter wysiwyg popup'); }
Látható, hogy a menü típusa MENU_CALLBACK, vagyis nem fog megjelenni és csak az 'access soundcloud filter wysiwyg popup' joggal rendelkező felhasználók érhetik majd el.
A soundcloud_filter_wysiwyg_popup() fgv-ben összeállítom a szükséges változókat és kiíratom a popup eredményét. A létrehozott változók:
/** * Load the WYSIWYG popup window. * * @return NULL */ function soundcloud_filter_wysiwyg_popup() { $path = base_path() . drupal_get_path('module', 'soundcloud_filter'); $tinymce_path = base_path() .'sites/all/libraries'; $tinymce_js = $tinymce_path .'/tinymce/jscripts/tiny_mce/tiny_mce_popup.js'; echo theme('soundcloud_filter_wysiwyg_popup', $path, $tinymce_path, $tinymce_js); return NULL; }
Megfigyelhetjük, hogy a popup eredményével nem visszatérünk, hanem kiíratjuk és a visszatérés NULL. Ez azért van, mert ha az eredménnyel térnénk vissza, akkor a sminkbe ágyazva kapnánk meg a forrást, tehát a legenerált popup csak a smink $content értéke lenne, de nekünk nem ez kell.
Látható, hogy a theme() fgv-el generálom le a popup ablakot, ez azért van, hogy a sminkkészítők felül tudják írni, ezért a hook_theme()-t is implementálni kellett:
/** * Implementation of hook_theme(). */ function soundcloud_filter_theme() { return array( 'soundcloud_filter_embed' => array( 'arguments' => array( 'params' => NULL, 'height' => NULL, 'widht' => NULL, 'host' => NULL, ), ), 'soundcloud_filter_wysiwyg_popup' => array( 'arguments' => array( 'path' => NULL, 'tinymce_path' => NULL, 'tinymce_js' => NULL, ), 'template' => 'soundcloud-filter-wysiwyg-popup', 'path' => drupal_get_path('module', 'soundcloud_filter') . '/theme', ), ); }
Nekünk itt a soundcloud_filter_wysiwyg_popup az érdekes, látható hogy template fájlt készítek neki, és a theme alkönyvtárba helyezem el. Ez nem kötelező, én így szeretem mert átláthatóbb a fájlrendszer.
A modul fájlunk szerkesztése itt véget is ért, nézzük meg soundcloud-filter-wysiwyg-popup.tpl.tpl.php-t:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>Soundcloud filter</title> <link type="text/css" rel="stylesheet" media="all" href="<?php echo $path ?>/wysiwyg/tinymce/popup.css" /> <script type="text/javascript" src="<?php echo $tinymce_js ?>"></script> <script type="text/javascript" src="<?php echo $path ?>/wysiwyg/tinymce/popup.js"></script> </head> <body id="soundcloud_filter_popup"> <form action="#" method="POST" onsubmit="insertSoundcloudFiltterCode();return false;" id="soundcloud_filter_popup_form"> <div class="tabs"> <ul> <li id="general_tab" class="current"> <span><a onmousedown="return false;" href="javascript:mcTabs.displayTab('general_tab','general_panel');">Insert/edit soundcloud</a></span> </li> </ul> </div> <div class="panel_wrapper"> <div id="general_panel" class="current"> <table cellpadding="4" cellspacing="0" border="0"> <tr> <td><label for="soundcloud_filter_url">Url:</label></td> <td><input type="text" id="soundcloud_filter_url" name="soundcloud_filter_url" value="" /></td> </tr> <tr> <td><label for="soundcloud_filter_width">Width:</label></td> <td><input type="text" id="soundcloud_filter_width" name="soundcloud_filter_width" value="" /></td> </tr> <tr> <td><label for="soundcloud_filter_height">Height:</label></td> <td><input type="text" id="soundcloud_filter_height" name="soundcloud_filter_height" value="" /></td> </tr> <tr> <td><label for="soundcloud_filter_color">Color:</label></td> <td><input type="text" id="soundcloud_filter_color" name="soundcloud_filter_color" value="" /></td> </tr> <tr> <td><label for="soundcloud_filter_showcomments">Show comments:</label></td> <td><input type="checkbox" id="soundcloud_filter_showcomments" name="soundcloud_filter_showcomments" /></td> </tr> <tr> <td><label for="soundcloud_filter_autoplay">Auto play:</label></td> <td><input type="checkbox" id="soundcloud_filter_autoplay" name="soundcloud_filter_autoplay" /></td> </tr> </table> </div> </div> <div class="mceActionPanel"> <div style="float: left;"><input id="insert" type="submit" value="Insert" /></div> <div style="float: right;"><input type="button" onclick="tinyMCEPopup.close();" value="Cancel" name="cancel" id="cancel" /></div> </div> </form> </body>