001.
mark( 'afterLoad' ) : null; // CREATE THE APPLICATION $app = JRequest::getString('app', 'site'); $app = $app == 'site' ? 'site' : ($app == 'administrator' ? 'administrator' : 'site'); $app_path = $app == 'site' ? '../..' : '../../administrator'; $mainframe =& JFactory::getApplication($app); $doc =& JFactory::getDocument(); /** @var jlanguage $lang */ $lang =& JFactory::getLanguage(); $lang->load('plg_editors-xtd_googledocs', realpath(JPATH_BASE.DS.'administrator')); JHTML::_('behavior.mootools'); jimport( 'joomla.plugin.plugin' ) ; jimport( 'joomla.plugin.helper' ) ; $plugin = & JPluginHelper::getPlugin( 'content', 'googledocs' ) ; $pluginParams = new JParameter( $plugin->params ) ; $doctypes[] = JHTML::_('select.option', 'presentation', JText::_( 'Prezentacje' )); $doctypes[] = JHTML::_('select.option', 'spreadsheet', JText::_( 'Arkusz kalkulacyjny' )); $doctypes[] = JHTML::_('select.option', 'document' , JText::_( 'Doc' )); $doctypelist = JHTML::_('select.genericlist', $doctypes, 'doctype', 'onchange="doGDocRequest()"', 'value', 'text', $pluginParams->get('default_type') ); $sizes[] = JHTML::_('select.option', 's', JText::_( 'mały' )); $sizes[] = JHTML::_('select.option', 'm', JText::_( 'średni' )); $sizes[] = JHTML::_('select.option', 'l' , JText::_( 'duży' )); $sizelist = JHTML::_('select.genericlist', $sizes, 'size', null, 'value', 'text', $pluginParams->get('default_size') ); $frameborderlist = JHTML::_('select.integerlist', 0, 4, 1, 'frameborder', null, $pluginParams->get('frameborder')); $juri = JURI::getInstance(); ?> <link href="/%3C?php%20echo%20$app_path%20?%3E/templates/%3C?php%20echo%20$mainframe-%3EgetTemplate%28%29%20?%3E/css/template.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="/../../media/system/js/mootools.js"></script><script type="text/javascript" src="/<?php echo $juri->getScheme() ?>://www.google.com/jsapi"></script><script type="text/javascript">
002.
// Load the Google data JavaScript client library
003.
google.load("gdata", "1.x");
004.
// Set init() to be called after JavaScript libraries load
005.
google.setOnLoadCallback(init);
006.
007.
// Object for storing constants and global variables
008.
var gDocListAPI = {
009.
CURRENT_DOCUMENT: null,
010.
SELECTED_DOCTYPE: null,
011.
AUTHENTICATION_URL: '<?php echo $juri->getScheme() ?>://docs.google.com/feeds/documents',
012.
PERSONAL_DOC_LIST_URL: '<?php echo $juri->getScheme() ?>://docs.google.com/feeds/documents/private/full',
013.
014.
AUTHENTICATION_LINK: 'authenticationLink',
015.
MAIN_CONTENT_TABLE: 'mainContentTable',
016.
STATUS_CONTAINER: 'statusContainer',
017.
DOCTYPE_SELECT: 'doctype',
018.
DOCUMENT_SELECT: 'document_entries'
019.
};
020.
021.
/**
022.
* Onload handler: calls two initialization subroutines
023.
*/
024.
function init() {
025.
// Create service object for accessing private feeds using AuthSub
026.
gDocListAPI.service =
027.
new google.gdata.client.GoogleService("writely", "JoomlaPlugin-GoogleDocEmbed");
028.
initializeUI();
029.
}
030.
/**
031.
* Resets interface and retrieves user's private blog feed if user is
032.
* signed in
033.
*/
034.
function initializeUI() {
035.
var authenticationLink = $(gDocListAPI.AUTHENTICATION_LINK);
036.
037.
$("authenticationDiv").setStyle( "display", "" );
038.
039.
if (google.accounts.user.checkLogin(gDocListAPI.AUTHENTICATION_URL)) {
040.
if( opener ) { opener.initializeUI(); window.close(); }
041.
$("document_entries_row").setStyle( "display", "" );
042.
doGDocRequest();
043.
authenticationLink.setHTML("<?php echo JText::_('Sign out', true) ?>");
044.
authenticationLink.onclick = signOut;
045.
} else {
046.
$("document_entries_row").setStyle( "display", "none" );
047.
$(gDocListAPI.STATUS_CONTAINER).setStyle("display", "none");
048.
authenticationLink.setHTML("<?php echo JText::_('Sign in', true) ?>");
049.
authenticationLink.onclick = signIn;
050.
}
051.
052.
}
053.
/**
054.
* Function to retrieve the document feed from Google
055.
* Automatically filters by selected Document Type
056.
*/
057.
function doGDocRequest() {
058.
if (google.accounts.user.checkLogin(gDocListAPI.AUTHENTICATION_URL)) {
059.
$(gDocListAPI.DOCUMENT_SELECT).setStyle("display", "none");
060.
$(gDocListAPI.STATUS_CONTAINER).setStyle("display", "");
061.
gDocListAPI.service.getFeed(gDocListAPI.PERSONAL_DOC_LIST_URL + "/-/" + $(gDocListAPI.DOCTYPE_SELECT).getValue(),
062.
getDocFeedHandler, errorHandler, google.gdata.atom.Feed);
063.
}
064.
}
065.
/**
066.
* Requests an AuthSub token for interaction with the Blogger service
067.
*/
068.
function signIn() {
069.
var token = google.accounts.user.checkLogin(gDocListAPI.AUTHENTICATION_URL);
070.
if( !token ) {
071.
var authSubWin = window.open("<?php echo $juri->getScheme() ?>://www.google.com/accounts/AuthSubRequestJS?session=1&scope=http://docs.google.com/feeds/documents&;next=<?php echo urlencode( JURI::base() ."googledocs_form.php?app=site&e_name=text" ) ?>", "authsub", "width=600,height=400,scrollbars" );
072.
authSubWin.onclose = initializeUI;
073.
}
074.
}
075.
076.
/**
077.
* Revokes the AuthSub token and resets the interface
078.
*/
079.
function signOut() {
080.
google.accounts.user.logout();
081.
initializeUI();
082.
}
083.
084.
/**
085.
* Called after successful retrieval of document feed; populates drop-down
086.
* menu with titles of user's documents
087.
*
088.
* @param {Object} docFeedRoot Feed object containing collection of
089.
* document entries
090.
*/
091.
function getDocFeedHandler(docFeedRoot) {
092.
$(gDocListAPI.STATUS_CONTAINER).setStyle("display", "none");
093.
$(gDocListAPI.DOCUMENT_SELECT).setStyle("display", "block");
094.
var docArr = docFeedRoot.feed.getEntries();
095.
var documentSelect = $(gDocListAPI.DOCUMENT_SELECT);
096.
097.
for (var i = 0; i < docArr.length; i++) {
098.
var newOption = document.createElement("option");
099.
var docTitle = docArr[i].getTitle().getText();
100.
linkArr = docArr[i].getLinks();
101.
var docLocation = linkArr[0].getHref();
102.
103.
newOption.value = docLocation;
104.
newOption.innerHTML = docTitle;
105.
documentSelect.appendChild(newOption);
106.
}
107.
108.
}
109.
110.
/**
111.
* Called if Google Docs service is unable to retrieve a feed or insert an
112.
* entry properly; creates a popup alert notifying user of error of cause
113.
*
114.
* @param {Object} e Object containing error information
115.
*/
116.
function errorHandler(e) {
117.
alert(e.cause.status ? e.message + " (" + e.cause.status + ")" : e.message);
118.
}
119.
function getDocId( link ) {
120.
lastPos = link.indexOf("&") > 10 ? null : link.indexOf("&");
121.
return link.substring( link.indexOf("=")+1 );
122.
}
123.
function setDocId( id ) {
124.
$("docid").value = id;
125.
}
126.
function insertGoogleDoc(editor) {
127.
// Get the pagebreak title
128.
var docid = $("docid").getValue();
129.
if( docid == "" ) {
130.
alert( "<?php echo JText::_( 'Document ID is required', true ); ?>" );
131.
$("docid").focus();
132.
return false;
133.
}
134.
var type = $("doctype").getValue();
135.
if( type == "document" ) type = "doc";
136.
var size = $("size").getValue();
137.
var frameborder = $("frameborder").getValue();
138.
var width = $("width").getValue();
139.
var height = $("height").getValue();
140.
141.
if (width != '') {
142.
width = " width=\""+width+"\" ";
143.
}
144.
if (height != '') {
145.
height = " height=\""+height+"\" ";
146.
}
147.
148.
var tag = " {GoogleDoc docid=\""+docid+"\" type=\"" + type + "\" size=\"" + size + "\" frameborder=\"" + frameborder + "\""+ width + height + "} ";
149.
150.
window.parent.jInsertEditorText(tag, "<?php echo preg_replace( '#[^A-Z0-9\-\_\[\]]#i', '', JRequest::getVar('e_name') ); ?>");
151.
window.parent.document.getElementById('sbox-window').close();
152.
return false;
153.
}
154.
/**
155.
* Debug Function, that works like print_r for Objects in Javascript
156.
*/
157.
function var_dump(obj) {
158.
var vartext = "";
159.
for (var prop in obj) {
160.
if( isNaN( prop.toString() )) {
161.
vartext += "\t->"+prop+" = "+ eval( "obj."+prop.toString()) +"\n";
162.
}
163.
}
164.
if(typeof obj == "object") {
165.
return "Type: "+typeof(obj)+((obj.constructor) ? "\nConstructor: "+obj.constructor : "") + "\n" + vartext;
166.
} else {
167.
return "Type: "+typeof(obj)+"\n" + vartext;
168.
}
169.
}
170.
</script>
171.
172.
<img align="left" alt="lock" src="/../../administrator/images/checked_out.png" />
173.
<h1>
174.
<img align="middle" alt="GoogleDocs" src="/googledocs.gif" /> Wstaw Dokument GoogleDocs</h1>
175.
<form>
176.
<table class="admintable" id="mainContentTable" style="margin-left: 15px; width: 90%;">
177.
<tbody>
178.
<tr>
179.
<td align="right" class="key" width="30%">
180.
</td>
181.
<td width="70%">
182.
</td>
183.
</tr>
184.
<tr id="document_entries_row" style="display: none;">
185.
<td align="right" class="key">
186.
</td>
187.
<td>
188.
<select gtbfieldid="525" id="document_entries" name="document_entries" onchange="setDocId(getDocId(this.getValue()))"><option value=""></option></select> <img align="middle" alt="-*-" src="/googledocs_indicator.gif" /> </td>
189.
</tr>
190.
<tr>
191.
<td align="right" class="key">
192.
</td>
193.
<td>
194.
<input class="inputbox" gtbfieldid="526" id="docid" name="docid" type="text" /></td>
195.
</tr>
196.
<tr>
197.
<td align="right" class="key">
198.
</td>
199.
<td>
200.
</td>
201.
</tr>
202.
<tr>
203.
<td align="right" class="key">
204.
</td>
205.
<td>
206.
<input class="inputbox" gtbfieldid="527" id="height" name="height" size="5" type="text" value="<?php echo $pluginParams->get('iframe_height_custom') ?>" /> x <input class="inputbox" gtbfieldid="528" id="width" name="width" size="5" type="text" value="<?php echo $pluginParams->get('iframe_width_custom') ?>" /></td>
207.
</tr>
208.
<tr>
209.
<td align="right" class="key">
210.
</td>
211.
<td>
212.
</td>
213.
</tr>
214.
<tr>
215.
<td colspan="2">
216.
217.
218.
219.
220.
<input class="button" onclick="insertGoogleDoc();" type="button" value="<?php echo JText::_( 'Wstaw kod Joomla generujący wyświeltanie dokumentu' ); ?>" /></td>
221.
</tr>
222.
</tbody>
223.
</table>
224.
</form>
225.
226.