code
stringlengths
1
2.01M
repo_name
stringlengths
3
62
path
stringlengths
1
267
language
stringclasses
231 values
license
stringclasses
13 values
size
int64
1
2.01M
<!DOCTYPE html> <!-- Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.md or http://ckeditor.com/license --> <html> <head> <meta charset="utf-8"> <title>CKEDITOR.appendTo &mdash; CKEditor Sample</title> <script src="../ckeditor.js"></script> <link rel="stylesheet" href="sample.css"> </head> <body> <h1 class="samples"> <a href="index.html">CKEditor Samples</a> &raquo; Append To Page Element Using JavaScript Code </h1> <div id="section1"> <div class="description"> <p> <code>CKEDITOR.appendTo</code> is basically to place editors inside existing DOM elements. Unlike <code>CKEDITOR.replace</code>, a target container to be replaced is no longer necessary. A new editor instance is inserted directly wherever it is desired. </p> <pre class="samples">CKEDITOR.appendTo( '<em>container_id</em>', { /* Configuration options to be used. */ } 'Editor content to be used.' );</pre> </div> <script> // This call can be placed at any point after the // <textarea>, or inside a <head><script> in a // window.onload event handler. // Replace the <textarea id="editor"> with an CKEditor // instance, using default configurations. CKEDITOR.appendTo( 'section1', null, '<p>This is some <strong>sample text</strong>. You are using <a href="http://ckeditor.com/">CKEditor</a>.</p>' ); </script> </div> <br> <div id="footer"> <hr> <p> CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a> </p> <p id="copy"> Copyright &copy; 2003-2014, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico Knabben. All rights reserved. </p> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/shared/plugin/ckeditor/samples/appendto.html
HTML
gpl3
1,820
<!DOCTYPE html> <!-- Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.md or http://ckeditor.com/license --> <html> <head> <meta charset="utf-8"> <title>UI Color Picker &mdash; CKEditor Sample</title> <script src="../ckeditor.js"></script> <link rel="stylesheet" href="sample.css"> </head> <body> <h1 class="samples"> <a href="index.html">CKEditor Samples</a> &raquo; UI Color </h1> <div class="description"> <p> This sample shows how to automatically replace <code>&lt;textarea&gt;</code> elements with a CKEditor instance with an option to change the color of its user interface.<br> <strong>Note:</strong>The UI skin color feature depends on the CKEditor skin compatibility. The Moono and Kama skins are examples of skins that work with it. </p> </div> <form action="sample_posteddata.php" method="post"> <p> This editor instance has a UI color value defined in configuration to change the skin color, To specify the color of the user interface, set the <code>uiColor</code> property: </p> <pre class="samples"> CKEDITOR.replace( '<em>textarea_id</em>', { <strong>uiColor: '#14B8C4'</strong> });</pre> <p> Note that <code><em>textarea_id</em></code> in the code above is the <code>id</code> attribute of the <code>&lt;textarea&gt;</code> element to be replaced. </p> <p> <textarea cols="80" id="editor1" name="editor1" rows="10">&lt;p&gt;This is some &lt;strong&gt;sample text&lt;/strong&gt;. You are using &lt;a href="http://ckeditor.com/"&gt;CKEditor&lt;/a&gt;.&lt;/p&gt;</textarea> <script> // Replace the <textarea id="editor"> with an CKEditor // instance, using default configurations. CKEDITOR.replace( 'editor1', { uiColor: '#14B8C4', toolbar: [ [ 'Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink' ], [ 'FontSize', 'TextColor', 'BGColor' ] ] }); </script> </p> <p> <input type="submit" value="Submit"> </p> </form> <div id="footer"> <hr> <p> CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a> </p> <p id="copy"> Copyright &copy; 2003-2014, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico Knabben. All rights reserved. </p> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/shared/plugin/ckeditor/samples/uicolor.html
HTML
gpl3
2,407
<!DOCTYPE html> <!-- Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.md or http://ckeditor.com/license --> <html> <head> <meta charset="utf-8"> <title>API Usage &mdash; CKEditor Sample</title> <script src="../ckeditor.js"></script> <link href="sample.css" rel="stylesheet"> <script> // The instanceReady event is fired, when an instance of CKEditor has finished // its initialization. CKEDITOR.on( 'instanceReady', function( ev ) { // Show the editor name and description in the browser status bar. document.getElementById( 'eMessage' ).innerHTML = 'Instance <code>' + ev.editor.name + '<\/code> loaded.'; // Show this sample buttons. document.getElementById( 'eButtons' ).style.display = 'block'; }); function InsertHTML() { // Get the editor instance that we want to interact with. var editor = CKEDITOR.instances.editor1; var value = document.getElementById( 'htmlArea' ).value; // Check the active editing mode. if ( editor.mode == 'wysiwyg' ) { // Insert HTML code. // http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-insertHtml editor.insertHtml( value ); } else alert( 'You must be in WYSIWYG mode!' ); } function InsertText() { // Get the editor instance that we want to interact with. var editor = CKEDITOR.instances.editor1; var value = document.getElementById( 'txtArea' ).value; // Check the active editing mode. if ( editor.mode == 'wysiwyg' ) { // Insert as plain text. // http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-insertText editor.insertText( value ); } else alert( 'You must be in WYSIWYG mode!' ); } function SetContents() { // Get the editor instance that we want to interact with. var editor = CKEDITOR.instances.editor1; var value = document.getElementById( 'htmlArea' ).value; // Set editor contents (replace current contents). // http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-setData editor.setData( value ); } function GetContents() { // Get the editor instance that you want to interact with. var editor = CKEDITOR.instances.editor1; // Get editor contents // http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-getData alert( editor.getData() ); } function ExecuteCommand( commandName ) { // Get the editor instance that we want to interact with. var editor = CKEDITOR.instances.editor1; // Check the active editing mode. if ( editor.mode == 'wysiwyg' ) { // Execute the command. // http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-execCommand editor.execCommand( commandName ); } else alert( 'You must be in WYSIWYG mode!' ); } function CheckDirty() { // Get the editor instance that we want to interact with. var editor = CKEDITOR.instances.editor1; // Checks whether the current editor contents present changes when compared // to the contents loaded into the editor at startup // http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-checkDirty alert( editor.checkDirty() ); } function ResetDirty() { // Get the editor instance that we want to interact with. var editor = CKEDITOR.instances.editor1; // Resets the "dirty state" of the editor (see CheckDirty()) // http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-resetDirty editor.resetDirty(); alert( 'The "IsDirty" status has been reset' ); } function Focus() { CKEDITOR.instances.editor1.focus(); } function onFocus() { document.getElementById( 'eMessage' ).innerHTML = '<b>' + this.name + ' is focused </b>'; } function onBlur() { document.getElementById( 'eMessage' ).innerHTML = this.name + ' lost focus'; } </script> </head> <body> <h1 class="samples"> <a href="index.html">CKEditor Samples</a> &raquo; Using CKEditor JavaScript API </h1> <div class="description"> <p> This sample shows how to use the <a class="samples" href="http://docs.ckeditor.com/#!/api/CKEDITOR.editor">CKEditor JavaScript API</a> to interact with the editor at runtime. </p> <p> For details on how to create this setup check the source code of this sample page. </p> </div> <!-- This <div> holds alert messages to be display in the sample page. --> <div id="alerts"> <noscript> <p> <strong>CKEditor requires JavaScript to run</strong>. In a browser with no JavaScript support, like yours, you should still see the contents (HTML data) and you should be able to edit it normally, without a rich editor interface. </p> </noscript> </div> <form action="../../../samples/sample_posteddata.php" method="post"> <textarea cols="100" id="editor1" name="editor1" rows="10">&lt;p&gt;This is some &lt;strong&gt;sample text&lt;/strong&gt;. You are using &lt;a href="http://ckeditor.com/"&gt;CKEditor&lt;/a&gt;.&lt;/p&gt;</textarea> <script> // Replace the <textarea id="editor1"> with an CKEditor instance. CKEDITOR.replace( 'editor1', { on: { focus: onFocus, blur: onBlur, // Check for availability of corresponding plugins. pluginsLoaded: function( evt ) { var doc = CKEDITOR.document, ed = evt.editor; if ( !ed.getCommand( 'bold' ) ) doc.getById( 'exec-bold' ).hide(); if ( !ed.getCommand( 'link' ) ) doc.getById( 'exec-link' ).hide(); } } }); </script> <p id="eMessage"> </p> <div id="eButtons" style="display: none"> <input id="exec-bold" onclick="ExecuteCommand('bold');" type="button" value="Execute &quot;bold&quot; Command"> <input id="exec-link" onclick="ExecuteCommand('link');" type="button" value="Execute &quot;link&quot; Command"> <input onclick="Focus();" type="button" value="Focus"> <br><br> <input onclick="InsertHTML();" type="button" value="Insert HTML"> <input onclick="SetContents();" type="button" value="Set Editor Contents"> <input onclick="GetContents();" type="button" value="Get Editor Contents (HTML)"> <br> <textarea cols="100" id="htmlArea" rows="3">&lt;h2&gt;Test&lt;/h2&gt;&lt;p&gt;This is some &lt;a href="/Test1.html"&gt;sample&lt;/a&gt; HTML code.&lt;/p&gt;</textarea> <br> <br> <input onclick="InsertText();" type="button" value="Insert Text"> <br> <textarea cols="100" id="txtArea" rows="3"> First line with some leading whitespaces. Second line of text preceded by two line breaks.</textarea> <br> <br> <input onclick="CheckDirty();" type="button" value="checkDirty()"> <input onclick="ResetDirty();" type="button" value="resetDirty()"> </div> </form> <div id="footer"> <hr> <p> CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a> </p> <p id="copy"> Copyright &copy; 2003-2014, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico Knabben. All rights reserved. </p> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/shared/plugin/ckeditor/samples/api.html
HTML
gpl3
6,986
/* Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.md or http://ckeditor.com/license */ html, body, h1, h2, h3, h4, h5, h6, div, span, blockquote, p, address, form, fieldset, img, ul, ol, dl, dt, dd, li, hr, table, td, th, strong, em, sup, sub, dfn, ins, del, q, cite, var, samp, code, kbd, tt, pre { line-height: 1.5; } body { padding: 10px 30px; } input, textarea, select, option, optgroup, button, td, th { font-size: 100%; } pre, code, kbd, samp, tt { font-family: monospace,monospace; font-size: 1em; } body { width: 960px; margin: 0 auto; } code { background: #f3f3f3; border: 1px solid #ddd; padding: 1px 4px; -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; } abbr { border-bottom: 1px dotted #555; cursor: pointer; } .new, .beta { text-transform: uppercase; font-size: 10px; font-weight: bold; padding: 1px 4px; margin: 0 0 0 5px; color: #fff; float: right; -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; } .new { background: #FF7E00; border: 1px solid #DA8028; text-shadow: 0 1px 0 #C97626; -moz-box-shadow: 0 2px 3px 0 #FFA54E inset; -webkit-box-shadow: 0 2px 3px 0 #FFA54E inset; box-shadow: 0 2px 3px 0 #FFA54E inset; } .beta { background: #18C0DF; border: 1px solid #19AAD8; text-shadow: 0 1px 0 #048CAD; font-style: italic; -moz-box-shadow: 0 2px 3px 0 #50D4FD inset; -webkit-box-shadow: 0 2px 3px 0 #50D4FD inset; box-shadow: 0 2px 3px 0 #50D4FD inset; } h1.samples { color: #0782C1; font-size: 200%; font-weight: normal; margin: 0; padding: 0; } h1.samples a { color: #0782C1; text-decoration: none; border-bottom: 1px dotted #0782C1; } .samples a:hover { border-bottom: 1px dotted #0782C1; } h2.samples { color: #000000; font-size: 130%; margin: 15px 0 0 0; padding: 0; } p, blockquote, address, form, pre, dl, h1.samples, h2.samples { margin-bottom: 15px; } ul.samples { margin-bottom: 15px; } .clear { clear: both; } fieldset { margin: 0; padding: 10px; } body, input, textarea { color: #333333; font-family: Arial, Helvetica, sans-serif; } body { font-size: 75%; } a.samples { color: #189DE1; text-decoration: none; } form { margin: 0; padding: 0; } pre.samples { background-color: #F7F7F7; border: 1px solid #D7D7D7; overflow: auto; padding: 0.25em; white-space: pre-wrap; /* CSS 2.1 */ word-wrap: break-word; /* IE7 */ -moz-tab-size: 4; -o-tab-size: 4; -webkit-tab-size: 4; tab-size: 4; } #footer { clear: both; padding-top: 10px; } #footer hr { margin: 10px 0 15px 0; height: 1px; border: solid 1px gray; border-bottom: none; } #footer p { margin: 0 10px 10px 10px; float: left; } #footer #copy { float: right; } #outputSample { width: 100%; table-layout: fixed; } #outputSample thead th { color: #dddddd; background-color: #999999; padding: 4px; white-space: nowrap; } #outputSample tbody th { vertical-align: top; text-align: left; } #outputSample pre { margin: 0; padding: 0; } .description { border: 1px dotted #B7B7B7; margin-bottom: 10px; padding: 10px 10px 0; overflow: hidden; } label { display: block; margin-bottom: 6px; } /** * CKEditor editables are automatically set with the "cke_editable" class * plus cke_editable_(inline|themed) depending on the editor type. */ /* Style a bit the inline editables. */ .cke_editable.cke_editable_inline { cursor: pointer; } /* Once an editable element gets focused, the "cke_focus" class is added to it, so we can style it differently. */ .cke_editable.cke_editable_inline.cke_focus { box-shadow: inset 0px 0px 20px 3px #ddd, inset 0 0 1px #000; outline: none; background: #eee; cursor: text; } /* Avoid pre-formatted overflows inline editable. */ .cke_editable_inline pre { white-space: pre-wrap; word-wrap: break-word; } /** * Samples index styles. */ .twoColumns, .twoColumnsLeft, .twoColumnsRight { overflow: hidden; } .twoColumnsLeft, .twoColumnsRight { width: 45%; } .twoColumnsLeft { float: left; } .twoColumnsRight { float: right; } dl.samples { padding: 0 0 0 40px; } dl.samples > dt { display: list-item; list-style-type: disc; list-style-position: outside; margin: 0 0 3px; } dl.samples > dd { margin: 0 0 3px; } .warning { color: #ff0000; background-color: #FFCCBA; border: 2px dotted #ff0000; padding: 15px 10px; margin: 10px 0; } /* Used on inline samples */ blockquote { font-style: italic; font-family: Georgia, Times, "Times New Roman", serif; padding: 2px 0; border-style: solid; border-color: #ccc; border-width: 0; } .cke_contents_ltr blockquote { padding-left: 20px; padding-right: 8px; border-left-width: 5px; } .cke_contents_rtl blockquote { padding-left: 8px; padding-right: 20px; border-right-width: 5px; } img.right { border: 1px solid #ccc; float: right; margin-left: 15px; padding: 5px; } img.left { border: 1px solid #ccc; float: left; margin-right: 15px; padding: 5px; }
04-huanluyenviencanhan
trunk/master/shared/plugin/ckeditor/samples/sample.css
CSS
gpl3
5,373
<!DOCTYPE html> <!-- Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.md or http://ckeditor.com/license --> <html> <head> <meta charset="utf-8"> <title>XHTML Compliant Output &mdash; CKEditor Sample</title> <meta name="ckeditor-sample-required-plugins" content="sourcearea"> <script src="../ckeditor.js"></script> <script src="../samples/sample.js"></script> <link href="sample.css" rel="stylesheet"> </head> <body> <h1 class="samples"> <a href="index.html">CKEditor Samples</a> &raquo; Producing XHTML Compliant Output </h1> <div class="description"> <p> This sample shows how to configure CKEditor to output valid <a class="samples" href="http://www.w3.org/TR/xhtml11/">XHTML 1.1</a> code. Deprecated elements (<code>&lt;font&gt;</code>, <code>&lt;u&gt;</code>) or attributes (<code>size</code>, <code>face</code>) will be replaced with XHTML compliant code. </p> <p> To add a CKEditor instance outputting valid XHTML code, load the editor using a standard JavaScript call and define CKEditor features to use the XHTML compliant elements and styles. </p> <p> A snippet of the configuration code can be seen below; check the source of this page for full definition: </p> <pre class="samples"> CKEDITOR.replace( '<em>textarea_id</em>', { contentsCss: 'assets/outputxhtml.css', coreStyles_bold: { element: 'span', attributes: { 'class': 'Bold' } }, coreStyles_italic: { element: 'span', attributes: { 'class': 'Italic' } }, ... });</pre> </div> <form action="sample_posteddata.php" method="post"> <p> <label for="editor1"> Editor 1: </label> <textarea cols="80" id="editor1" name="editor1" rows="10">&lt;p&gt;This is some &lt;span class="Bold"&gt;sample text&lt;/span&gt;. You are using &lt;a href="http://ckeditor.com/"&gt;CKEditor&lt;/a&gt;.&lt;/p&gt;</textarea> <script> CKEDITOR.replace( 'editor1', { /* * Style sheet for the contents */ contentsCss: 'assets/outputxhtml/outputxhtml.css', /* * Special allowed content rules for spans used by * font face, size, and color buttons. * * Note: all rules have been written separately so * it was possible to specify required classes. */ extraAllowedContent: 'span(!FontColor1);span(!FontColor2);span(!FontColor3);' + 'span(!FontColor1BG);span(!FontColor2BG);span(!FontColor3BG);' + 'span(!FontComic);span(!FontCourier);span(!FontTimes);' + 'span(!FontSmaller);span(!FontLarger);span(!FontSmall);span(!FontBig);span(!FontDouble)', /* * Core styles. */ coreStyles_bold: { element: 'span', attributes: { 'class': 'Bold' } }, coreStyles_italic: { element: 'span', attributes: { 'class': 'Italic' } }, coreStyles_underline: { element: 'span', attributes: { 'class': 'Underline' } }, coreStyles_strike: { element: 'span', attributes: { 'class': 'StrikeThrough' }, overrides: 'strike' }, coreStyles_subscript: { element: 'span', attributes: { 'class': 'Subscript' }, overrides: 'sub' }, coreStyles_superscript: { element: 'span', attributes: { 'class': 'Superscript' }, overrides: 'sup' }, /* * Font face. */ // List of fonts available in the toolbar combo. Each font definition is // separated by a semi-colon (;). We are using class names here, so each font // is defined by {Combo Label}/{Class Name}. font_names: 'Comic Sans MS/FontComic;Courier New/FontCourier;Times New Roman/FontTimes', // Define the way font elements will be applied to the document. The "span" // element will be used. When a font is selected, the font name defined in the // above list is passed to this definition with the name "Font", being it // injected in the "class" attribute. // We must also instruct the editor to replace span elements that are used to // set the font (Overrides). font_style: { element: 'span', attributes: { 'class': '#(family)' }, overrides: [ { element: 'span', attributes: { 'class': /^Font(?:Comic|Courier|Times)$/ } } ] }, /* * Font sizes. */ fontSize_sizes: 'Smaller/FontSmaller;Larger/FontLarger;8pt/FontSmall;14pt/FontBig;Double Size/FontDouble', fontSize_style: { element: 'span', attributes: { 'class': '#(size)' }, overrides: [ { element: 'span', attributes: { 'class': /^Font(?:Smaller|Larger|Small|Big|Double)$/ } } ] } , /* * Font colors. */ colorButton_enableMore: false, colorButton_colors: 'FontColor1/FF9900,FontColor2/0066CC,FontColor3/F00', colorButton_foreStyle: { element: 'span', attributes: { 'class': '#(color)' }, overrides: [ { element: 'span', attributes: { 'class': /^FontColor(?:1|2|3)$/ } } ] }, colorButton_backStyle: { element: 'span', attributes: { 'class': '#(color)BG' }, overrides: [ { element: 'span', attributes: { 'class': /^FontColor(?:1|2|3)BG$/ } } ] }, /* * Indentation. */ indentClasses: [ 'Indent1', 'Indent2', 'Indent3' ], /* * Paragraph justification. */ justifyClasses: [ 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyFull' ], /* * Styles combo. */ stylesSet: [ { name: 'Strong Emphasis', element: 'strong' }, { name: 'Emphasis', element: 'em' }, { name: 'Computer Code', element: 'code' }, { name: 'Keyboard Phrase', element: 'kbd' }, { name: 'Sample Text', element: 'samp' }, { name: 'Variable', element: 'var' }, { name: 'Deleted Text', element: 'del' }, { name: 'Inserted Text', element: 'ins' }, { name: 'Cited Work', element: 'cite' }, { name: 'Inline Quotation', element: 'q' } ] }); </script> </p> <p> <input type="submit" value="Submit"> </p> </form> <div id="footer"> <hr> <p> CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a> </p> <p id="copy"> Copyright &copy; 2003-2014, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico Knabben. All rights reserved. </p> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/shared/plugin/ckeditor/samples/xhtmlstyle.html
HTML
gpl3
6,837
<!DOCTYPE html> <!-- Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.md or http://ckeditor.com/license --> <html> <head> <meta charset="utf-8"> <title>jQuery Adapter &mdash; CKEditor Sample</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script src="../ckeditor.js"></script> <script src="../adapters/jquery.js"></script> <link href="sample.css" rel="stylesheet"> <style> #editable { padding: 10px; float: left; } </style> <script> CKEDITOR.disableAutoInline = true; $( document ).ready( function() { $( '#editor1' ).ckeditor(); // Use CKEDITOR.replace() if element is <textarea>. $( '#editable' ).ckeditor(); // Use CKEDITOR.inline(). } ); function setValue() { $( '#editor1' ).val( $( 'input#val' ).val() ); } </script> </head> <body> <h1 class="samples"> <a href="index.html" id="a-test">CKEditor Samples</a> &raquo; Create Editors with jQuery </h1> <form action="sample_posteddata.php" method="post"> <div class="description"> <p> This sample shows how to use the <a href="http://docs.ckeditor.com/#!/guide/dev_jquery">jQuery adapter</a>. Note that you have to include both CKEditor and jQuery scripts before including the adapter. </p> <pre class="samples"> &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"&gt;&lt;/script&gt; &lt;script src="/ckeditor/ckeditor.js"&gt;&lt;/script&gt; &lt;script src="/ckeditor/adapters/jquery.js"&gt;&lt;/script&gt; </pre> <p>Then you can replace HTML elements with a CKEditor instance using the <code>ckeditor()</code> method.</p> <pre class="samples"> $( document ).ready( function() { $( 'textarea#editor1' ).ckeditor(); } ); </pre> </div> <h2 class="samples">Inline Example</h2> <div id="editable" contenteditable="true"> <p><img alt="Saturn V carrying Apollo 11" class="right" src="assets/sample.jpg"/><b>Apollo 11</b> was the spaceflight that landed the first humans, Americans <a href="http://en.wikipedia.org/wiki/Neil_Armstrong" title="Neil Armstrong">Neil Armstrong</a> and <a href="http://en.wikipedia.org/wiki/Buzz_Aldrin" title="Buzz Aldrin">Buzz Aldrin</a>, on the Moon on July 20, 1969, at 20:18 UTC. Armstrong became the first to step onto the lunar surface 6 hours later on July 21 at 02:56 UTC.</p> <p>Armstrong spent about <s>three and a half</s> two and a half hours outside the spacecraft, Aldrin slightly less; and together they collected 47.5 pounds (21.5&nbsp;kg) of lunar material for return to Earth. A third member of the mission, <a href="http://en.wikipedia.org/wiki/Michael_Collins_(astronaut)" title="Michael Collins (astronaut)">Michael Collins</a>, piloted the <a href="http://en.wikipedia.org/wiki/Apollo_Command/Service_Module" title="Apollo Command/Service Module">command</a> spacecraft alone in lunar orbit until Armstrong and Aldrin returned to it for the trip back to Earth. <p>Broadcast on live TV to a world-wide audience, Armstrong stepped onto the lunar surface and described the event as:</p> <blockquote><p>One small step for [a] man, one giant leap for mankind.</p></blockquote> <p>Apollo 11 effectively ended the <a href="http://en.wikipedia.org/wiki/Space_Race" title="Space Race">Space Race</a> and fulfilled a national goal proposed in 1961 by the late U.S. President <a href="http://en.wikipedia.org/wiki/John_F._Kennedy" title="John F. Kennedy">John F. Kennedy</a> in a speech before the United States Congress:</p> <blockquote><p>[...] before this decade is out, of landing a man on the Moon and returning him safely to the Earth.</p></blockquote> </div> <br style="clear: both"> <h2 class="samples">Classic (iframe-based) Example</h2> <textarea cols="80" id="editor1" name="editor1" rows="10"> &lt;h2&gt;Technical details &lt;a id=&quot;tech-details&quot; name=&quot;tech-details&quot;&gt;&lt;/a&gt;&lt;/h2&gt; &lt;table align=&quot;right&quot; border=&quot;1&quot; bordercolor=&quot;#ccc&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse:collapse;margin:10px 0 10px 15px;&quot;&gt; &lt;caption&gt;&lt;strong&gt;Mission crew&lt;/strong&gt;&lt;/caption&gt; &lt;thead&gt; &lt;tr&gt; &lt;th scope=&quot;col&quot;&gt;Position&lt;/th&gt; &lt;th scope=&quot;col&quot;&gt;Astronaut&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;Commander&lt;/td&gt; &lt;td&gt;Neil A. Armstrong&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Command Module Pilot&lt;/td&gt; &lt;td&gt;Michael Collins&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Lunar Module Pilot&lt;/td&gt; &lt;td&gt;Edwin &amp;quot;Buzz&amp;quot; E. Aldrin, Jr.&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;p&gt;Launched by a &lt;strong&gt;Saturn V&lt;/strong&gt; rocket from &lt;a href=&quot;http://en.wikipedia.org/wiki/Kennedy_Space_Center&quot; title=&quot;Kennedy Space Center&quot;&gt;Kennedy Space Center&lt;/a&gt; in Merritt Island, Florida on July 16, Apollo 11 was the fifth manned mission of &lt;a href=&quot;http://en.wikipedia.org/wiki/NASA&quot; title=&quot;NASA&quot;&gt;NASA&lt;/a&gt;&amp;#39;s Apollo program. The Apollo spacecraft had three parts:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;&lt;strong&gt;Command Module&lt;/strong&gt; with a cabin for the three astronauts which was the only part which landed back on Earth&lt;/li&gt; &lt;li&gt;&lt;strong&gt;Service Module&lt;/strong&gt; which supported the Command Module with propulsion, electrical power, oxygen and water&lt;/li&gt; &lt;li&gt;&lt;strong&gt;Lunar Module&lt;/strong&gt; for landing on the Moon.&lt;/li&gt; &lt;/ol&gt; &lt;p&gt;After being sent to the Moon by the Saturn V&amp;#39;s upper stage, the astronauts separated the spacecraft from it and travelled for three days until they entered into lunar orbit. Armstrong and Aldrin then moved into the Lunar Module and landed in the &lt;a href=&quot;http://en.wikipedia.org/wiki/Mare_Tranquillitatis&quot; title=&quot;Mare Tranquillitatis&quot;&gt;Sea of Tranquility&lt;/a&gt;. They stayed a total of about 21 and a half hours on the lunar surface. After lifting off in the upper part of the Lunar Module and rejoining Collins in the Command Module, they returned to Earth and landed in the &lt;a href=&quot;http://en.wikipedia.org/wiki/Pacific_Ocean&quot; title=&quot;Pacific Ocean&quot;&gt;Pacific Ocean&lt;/a&gt; on July 24.&lt;/p&gt; &lt;hr/&gt; &lt;p style=&quot;text-align: right;&quot;&gt;&lt;small&gt;Source: &lt;a href=&quot;http://en.wikipedia.org/wiki/Apollo_11&quot;&gt;Wikipedia.org&lt;/a&gt;&lt;/small&gt;&lt;/p&gt; </textarea> <p style="overflow: hidden"> <input style="float: left" type="submit" value="Submit"> <span style="float: right"> <input type="text" id="val" value="I'm using jQuery val()!" size="30"> <input onclick="setValue();" type="button" value="Set value"> </span> </p> </form> <div id="footer"> <hr> <p> CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a> </p> <p id="copy"> Copyright &copy; 2003-2014, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico Knabben. All rights reserved. </p> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/shared/plugin/ckeditor/samples/jquery.html
HTML
gpl3
7,348
<!DOCTYPE html> <!-- Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.md or http://ckeditor.com/license --> <html> <head> <meta charset="utf-8"> <title>User Interface Globalization &mdash; CKEditor Sample</title> <script src="../ckeditor.js"></script> <script src="assets/uilanguages/languages.js"></script> <link rel="stylesheet" href="sample.css"> </head> <body> <h1 class="samples"> <a href="index.html">CKEditor Samples</a> &raquo; User Interface Languages </h1> <div class="description"> <p> This sample shows how to automatically replace <code>&lt;textarea&gt;</code> elements with a CKEditor instance with an option to change the language of its user interface. </p> <p> It pulls the language list from CKEditor <code>_languages.js</code> file that contains the list of supported languages and creates a drop-down list that lets the user change the UI language. </p> <p> By default, CKEditor automatically localizes the editor to the language of the user. The UI language can be controlled with two configuration options: <code><a class="samples" href="http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-language">language</a></code> and <code><a class="samples" href="http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-defaultLanguage"> defaultLanguage</a></code>. The <code>defaultLanguage</code> setting specifies the default CKEditor language to be used when a localization suitable for user's settings is not available. </p> <p> To specify the user interface language that will be used no matter what language is specified in user's browser or operating system, set the <code>language</code> property: </p> <pre class="samples"> CKEDITOR.replace( '<em>textarea_id</em>', { // Load the German interface. <strong>language: 'de'</strong> });</pre> <p> Note that <code><em>textarea_id</em></code> in the code above is the <code>id</code> attribute of the <code>&lt;textarea&gt;</code> element to be replaced. </p> </div> <form action="sample_posteddata.php" method="post"> <p> Available languages (<span id="count"> </span> languages!):<br> <script> document.write( '<select disabled="disabled" id="languages" onchange="createEditor( this.value );">' ); // Get the language list from the _languages.js file. for ( var i = 0 ; i < window.CKEDITOR_LANGS.length ; i++ ) { document.write( '<option value="' + window.CKEDITOR_LANGS[i].code + '">' + window.CKEDITOR_LANGS[i].name + '</option>' ); } document.write( '</select>' ); </script> <br> <span style="color: #888888"> (You may see strange characters if your system does not support the selected language) </span> </p> <p> <textarea cols="80" id="editor1" name="editor1" rows="10">&lt;p&gt;This is some &lt;strong&gt;sample text&lt;/strong&gt;. You are using &lt;a href="http://ckeditor.com/"&gt;CKEditor&lt;/a&gt;.&lt;/p&gt;</textarea> <script> // Set the number of languages. document.getElementById( 'count' ).innerHTML = window.CKEDITOR_LANGS.length; var editor; function createEditor( languageCode ) { if ( editor ) editor.destroy(); // Replace the <textarea id="editor"> with an CKEditor // instance, using default configurations. editor = CKEDITOR.replace( 'editor1', { language: languageCode, on: { instanceReady: function() { // Wait for the editor to be ready to set // the language combo. var languages = document.getElementById( 'languages' ); languages.value = this.langCode; languages.disabled = false; } } }); } // At page startup, load the default language: createEditor( '' ); </script> </p> </form> <div id="footer"> <hr> <p> CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a> </p> <p id="copy"> Copyright &copy; 2003-2014, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico Knabben. All rights reserved. </p> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/shared/plugin/ckeditor/samples/uilanguages.html
HTML
gpl3
4,294
<!DOCTYPE html> <!-- Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.md or http://ckeditor.com/license --> <html> <head> <meta charset="utf-8"> <title>Toolbar Configuration &mdash; CKEditor Sample</title> <meta name="ckeditor-sample-name" content="Toolbar Configurations"> <meta name="ckeditor-sample-group" content="Advanced Samples"> <meta name="ckeditor-sample-description" content="Configuring CKEditor to display full or custom toolbar layout."> <script src="../../../ckeditor.js"></script> <link href="../../../samples/sample.css" rel="stylesheet"> </head> <body> <h1 class="samples"> <a href="../../../samples/index.html">CKEditor Samples</a> &raquo; Toolbar Configuration </h1> <div class="description"> <p> This sample page demonstrates editor with loaded <a href="#fullToolbar">full toolbar</a> (all registered buttons) and, if current editor's configuration modifies default settings, also editor with <a href="#currentToolbar">modified toolbar</a>. </p> <p>Since CKEditor 4 there are two ways to configure toolbar buttons.</p> <h2 class="samples">By <a href="http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-toolbar">config.toolbar</a></h2> <p> You can explicitly define which buttons are displayed in which groups and in which order. This is the more precise setting, but less flexible. If newly added plugin adds its own button you'll have to add it manually to your <code>config.toolbar</code> setting as well. </p> <p>To add a CKEditor instance with custom toolbar setting, insert the following JavaScript call to your code:</p> <pre class="samples"> CKEDITOR.replace( <em>'textarea_id'</em>, { <strong>toolbar:</strong> [ { name: 'document', items: [ 'Source', '-', 'NewPage', 'Preview', '-', 'Templates' ] }, // Defines toolbar group with name (used to create voice label) and items in 3 subgroups. [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ], // Defines toolbar group without name. '/', // Line break - next group will be placed in new line. { name: 'basicstyles', items: [ 'Bold', 'Italic' ] } ] });</pre> <h2 class="samples">By <a href="http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-toolbarGroups">config.toolbarGroups</a></h2> <p> You can define which groups of buttons (like e.g. <code>basicstyles</code>, <code>clipboard</code> and <code>forms</code>) are displayed and in which order. Registered buttons are associated with toolbar groups by <code>toolbar</code> property in their definition. This setting's advantage is that you don't have to modify toolbar configuration when adding/removing plugins which register their own buttons. </p> <p>To add a CKEditor instance with custom toolbar groups setting, insert the following JavaScript call to your code:</p> <pre class="samples"> CKEDITOR.replace( <em>'textarea_id'</em>, { <strong>toolbarGroups:</strong> [ { name: 'document', groups: [ 'mode', 'document' ] }, // Displays document group with its two subgroups. { name: 'clipboard', groups: [ 'clipboard', 'undo' ] }, // Group's name will be used to create voice label. '/', // Line break - next group will be placed in new line. { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] }, { name: 'links' } ] // NOTE: Remember to leave 'toolbar' property with the default value (null). });</pre> </div> <div id="currentToolbar" style="display: none"> <h2 class="samples">Current toolbar configuration</h2> <p>Below you can see editor with current toolbar definition.</p> <textarea cols="80" id="editorCurrent" name="editorCurrent" rows="10">&lt;p&gt;This is some &lt;strong&gt;sample text&lt;/strong&gt;. You are using &lt;a href="http://ckeditor.com/"&gt;CKEditor&lt;/a&gt;.&lt;/p&gt;</textarea> <pre id="editorCurrentCfg" class="samples"></pre> </div> <div id="fullToolbar"> <h2 class="samples">Full toolbar configuration</h2> <p>Below you can see editor with full toolbar, generated automatically by the editor.</p> <p> <strong>Note</strong>: To create editor instance with full toolbar you don't have to set anything. Just leave <code>toolbar</code> and <code>toolbarGroups</code> with the default, <code>null</code> values. </p> <textarea cols="80" id="editorFull" name="editorFull" rows="10">&lt;p&gt;This is some &lt;strong&gt;sample text&lt;/strong&gt;. You are using &lt;a href="http://ckeditor.com/"&gt;CKEditor&lt;/a&gt;.&lt;/p&gt;</textarea> <pre id="editorFullCfg" class="samples"></pre> </div> <script> (function() { 'use strict'; var buttonsNames; CKEDITOR.config.extraPlugins = 'toolbar'; CKEDITOR.on( 'instanceReady', function( evt ) { var editor = evt.editor, editorCurrent = editor.name == 'editorCurrent', defaultToolbar = !( editor.config.toolbar || editor.config.toolbarGroups || editor.config.removeButtons ), pre = CKEDITOR.document.getById( editor.name + 'Cfg' ), output = ''; if ( editorCurrent ) { // If default toolbar configuration has been modified, show "current toolbar" section. if ( !defaultToolbar ) CKEDITOR.document.getById( 'currentToolbar' ).show(); else return; } if ( !buttonsNames ) buttonsNames = createButtonsNamesHash( editor.ui.items ); // Toolbar isn't set explicitly, so it was created automatically from toolbarGroups. if ( !editor.config.toolbar ) { output += '// Toolbar configuration generated automatically by the editor based on config.toolbarGroups.\n' + dumpToolbarConfiguration( editor ) + '\n\n' + '// Toolbar groups configuration.\n' + dumpToolbarConfiguration( editor, true ) } // Toolbar groups doesn't count in this case - print only toolbar. else { output += '// Toolbar configuration.\n' + dumpToolbarConfiguration( editor ); } // Recreate to avoid old IE from loosing whitespaces on filling <pre> content. var preOutput = pre.getOuterHtml().replace( /(?=<\/)/, output ); CKEDITOR.dom.element.createFromHtml( preOutput ).replace( pre ); } ); CKEDITOR.replace( 'editorCurrent', { height: 100 } ); CKEDITOR.replace( 'editorFull', { // Reset toolbar settings, so full toolbar will be generated automatically. toolbar: null, toolbarGroups: null, removeButtons: null, height: 100 } ); function dumpToolbarConfiguration( editor, printGroups ) { var output = [], toolbar = editor.toolbar; for ( var i = 0; i < toolbar.length; ++i ) { var group = dumpToolbarGroup( toolbar[ i ], printGroups ); if ( group ) output.push( group ); } return 'config.toolbar' + ( printGroups ? 'Groups' : '' ) + ' = [\n\t' + output.join( ',\n\t' ) + '\n];'; } function dumpToolbarGroup( group, printGroups ) { var output = []; if ( typeof group == 'string' ) return '\'' + group + '\''; if ( CKEDITOR.tools.isArray( group ) ) return dumpToolbarItems( group ); // Skip group when printing entire toolbar configuration and there are no items in this group. if ( !printGroups && !group.items ) return; if ( group.name ) output.push( 'name: \'' + group.name + '\'' ); if ( group.groups ) output.push( 'groups: ' + dumpToolbarItems( group.groups ) ); if ( !printGroups ) output.push( 'items: ' + dumpToolbarItems( group.items ) ); return '{ ' + output.join( ', ' ) + ' }'; } function dumpToolbarItems( items ) { if ( typeof items == 'string' ) return '\'' + items + '\''; var names = [], i, item; for ( var i = 0; i < items.length; ++i ) { item = items[ i ]; if ( typeof item == 'string' ) names.push( item ); else { if ( item.type == CKEDITOR.UI_SEPARATOR ) names.push( '-' ); else names.push( buttonsNames[ item.name ] ); } } return '[ \'' + names.join( '\', \'' ) + '\' ]'; } // Creates { 'lowercased': 'LowerCased' } buttons names hash. function createButtonsNamesHash( items ) { var hash = {}, name; for ( name in items ) { hash[ items[ name ].name ] = name; } return hash; } })(); </script> <div id="footer"> <hr> <p> CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a> </p> <p id="copy"> Copyright &copy; 2003-2014, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico Knabben. All rights reserved. </p> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/shared/plugin/ckeditor/samples/plugins/toolbar/toolbar.html
HTML
gpl3
8,683
<!DOCTYPE html> <!-- Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.md or http://ckeditor.com/license --> <html> <head> <meta charset="utf-8"> <title>ENTER Key Configuration &mdash; CKEditor Sample</title> <script src="../../../ckeditor.js"></script> <link href="../../../samples/sample.css" rel="stylesheet"> <meta name="ckeditor-sample-name" content="Using the &quot;Enter&quot; key in CKEditor"> <meta name="ckeditor-sample-group" content="Advanced Samples"> <meta name="ckeditor-sample-description" content="Configuring the behavior of &lt;em&gt;Enter&lt;/em&gt; and &lt;em&gt;Shift+Enter&lt;/em&gt; keys."> <script> var editor; function changeEnter() { // If we already have an editor, let's destroy it first. if ( editor ) editor.destroy( true ); // Create the editor again, with the appropriate settings. editor = CKEDITOR.replace( 'editor1', { extraPlugins: 'enterkey', enterMode: Number( document.getElementById( 'xEnter' ).value ), shiftEnterMode: Number( document.getElementById( 'xShiftEnter' ).value ) }); } window.onload = changeEnter; </script> </head> <body> <h1 class="samples"> <a href="../../../samples/index.html">CKEditor Samples</a> &raquo; ENTER Key Configuration </h1> <div class="description"> <p> This sample shows how to configure the <em>Enter</em> and <em>Shift+Enter</em> keys to perform actions specified in the <a class="samples" href="http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-enterMode"><code>enterMode</code></a> and <a class="samples" href="http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-shiftEnterMode"><code>shiftEnterMode</code></a> parameters, respectively. You can choose from the following options: </p> <ul class="samples"> <li><strong><code>ENTER_P</code></strong> &ndash; new <code>&lt;p&gt;</code> paragraphs are created;</li> <li><strong><code>ENTER_BR</code></strong> &ndash; lines are broken with <code>&lt;br&gt;</code> elements;</li> <li><strong><code>ENTER_DIV</code></strong> &ndash; new <code>&lt;div&gt;</code> blocks are created.</li> </ul> <p> The sample code below shows how to configure CKEditor to create a <code>&lt;div&gt;</code> block when <em>Enter</em> key is pressed. </p> <pre class="samples"> CKEDITOR.replace( '<em>textarea_id</em>', { <strong>enterMode: CKEDITOR.ENTER_DIV</strong> });</pre> <p> Note that <code><em>textarea_id</em></code> in the code above is the <code>id</code> attribute of the <code>&lt;textarea&gt;</code> element to be replaced. </p> </div> <div style="float: left; margin-right: 20px"> When <em>Enter</em> is pressed:<br> <select id="xEnter" onchange="changeEnter();"> <option selected="selected" value="1">Create a new &lt;P&gt; (recommended)</option> <option value="3">Create a new &lt;DIV&gt;</option> <option value="2">Break the line with a &lt;BR&gt;</option> </select> </div> <div style="float: left"> When <em>Shift+Enter</em> is pressed:<br> <select id="xShiftEnter" onchange="changeEnter();"> <option value="1">Create a new &lt;P&gt;</option> <option value="3">Create a new &lt;DIV&gt;</option> <option selected="selected" value="2">Break the line with a &lt;BR&gt; (recommended)</option> </select> </div> <br style="clear: both"> <form action="../../../samples/sample_posteddata.php" method="post"> <p> <br> <textarea cols="80" id="editor1" name="editor1" rows="10">This is some &lt;strong&gt;sample text&lt;/strong&gt;. You are using &lt;a href="http://ckeditor.com/"&gt;CKEditor&lt;/a&gt;.</textarea> </p> <p> <input type="submit" value="Submit"> </p> </form> <div id="footer"> <hr> <p> CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a> </p> <p id="copy"> Copyright &copy; 2003-2014, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico Knabben. All rights reserved. </p> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/shared/plugin/ckeditor/samples/plugins/enterkey/enterkey.html
HTML
gpl3
4,149
<!DOCTYPE html> <!-- Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.md or http://ckeditor.com/license --> <html> <head> <meta charset="utf-8"> <title>Using Magicline plugin &mdash; CKEditor Sample</title> <script src="../../../ckeditor.js"></script> <link rel="stylesheet" href="../../../samples/sample.css"> <meta name="ckeditor-sample-name" content="Magicline plugin"> <meta name="ckeditor-sample-group" content="Plugins"> <meta name="ckeditor-sample-description" content="Using the Magicline plugin to access difficult focus spaces."> </head> <body> <h1 class="samples"> <a href="../../../samples/index.html">CKEditor Samples</a> &raquo; Using Magicline plugin </h1> <div class="description"> <p> This sample shows the advantages of <strong>Magicline</strong> plugin which is to enhance the editing process. Thanks to this plugin, a number of difficult focus spaces which are inaccessible due to browser issues can now be focused. </p> <p> <strong>Magicline</strong> plugin shows a red line with a handler which, when clicked, inserts a paragraph and allows typing. To see this, focus an editor and move your mouse above the focus space you want to access. The plugin is enabled by default so no additional configuration is necessary. </p> </div> <div> <label for="editor1"> Editor 1: </label> <div class="description"> <p> This editor uses a default <strong>Magicline</strong> setup. </p> </div> <textarea cols="80" id="editor1" name="editor1" rows="10"> &lt;table border=&quot;1&quot; cellpadding=&quot;1&quot; cellspacing=&quot;1&quot; style=&quot;width: 100%; &quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;This table&lt;/td&gt; &lt;td&gt;is the&lt;/td&gt; &lt;td&gt;very first&lt;/td&gt; &lt;td&gt;element of the document.&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;We are still&lt;/td&gt; &lt;td&gt;able to acces&lt;/td&gt; &lt;td&gt;the space before it.&lt;/td&gt; &lt;td&gt; &lt;table border=&quot;1&quot; cellpadding=&quot;1&quot; cellspacing=&quot;1&quot; style=&quot;width: 100%; &quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;This table is inside of a cell of another table.&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;We can type&amp;nbsp;either before or after it though.&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;p&gt;Two succesive horizontal lines (&lt;tt&gt;HR&lt;/tt&gt; tags). We can access the space in between:&lt;/p&gt; &lt;hr /&gt; &lt;hr /&gt; &lt;ol&gt; &lt;li&gt;This numbered list...&lt;/li&gt; &lt;li&gt;...is a neighbour of a horizontal line...&lt;/li&gt; &lt;li&gt;...and another list.&lt;/li&gt; &lt;/ol&gt; &lt;ul&gt; &lt;li&gt;We can type between the lists...&lt;/li&gt; &lt;li&gt;...thanks to &lt;strong&gt;Magicline&lt;/strong&gt;.&lt;/li&gt; &lt;/ul&gt; &lt;p&gt;Lorem ipsum dolor sit amet dui. Morbi vel turpis. Nullam et leo. Etiam rutrum, urna tellus dui vel tincidunt mattis egestas, justo fringilla vel, massa. Phasellus.&lt;/p&gt; &lt;p&gt;Quisque iaculis, dui lectus varius vitae, tortor. Proin lacus. Pellentesque ac lacus. Aenean nonummy commodo nec, pede. Etiam blandit risus elit.&lt;/p&gt; &lt;p&gt;Ut pretium. Vestibulum rutrum in, adipiscing elit. Sed in quam in purus sem vitae pede. Pellentesque bibendum, urna sem vel risus. Vivamus posuere metus. Aliquam gravida iaculis nisl. Nam enim. Aliquam erat ac lacus tellus ac felis.&lt;/p&gt; &lt;div style=&quot;border: 2px dashed green; background: #ddd; text-align: center;&quot;&gt; &lt;p&gt;This text is wrapped in a&amp;nbsp;&lt;tt&gt;DIV&lt;/tt&gt;&amp;nbsp;element. We can type after this element though.&lt;/p&gt; &lt;/div&gt; </textarea> <script> // This call can be placed at any point after the // <textarea>, or inside a <head><script> in a // window.onload event handler. CKEDITOR.replace( 'editor1', { extraPlugins: 'magicline', // Ensure that magicline plugin, which is required for this sample, is loaded. allowedContent: true // Switch off the ACF, so very complex content created to // show magicline's power isn't filtered. } ); </script> </div> <br> <div> <label for="editor2"> Editor 2: </label> <div class="description"> <p> This editor is using a blue line. </p> <pre class="samples"> CKEDITOR.replace( 'editor2', { magicline_color: 'blue' });</pre> </div> <textarea cols="80" id="editor2" name="editor2" rows="10"> &lt;table border=&quot;1&quot; cellpadding=&quot;1&quot; cellspacing=&quot;1&quot; style=&quot;width: 100%; &quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;This table&lt;/td&gt; &lt;td&gt;is the&lt;/td&gt; &lt;td&gt;very first&lt;/td&gt; &lt;td&gt;element of the document.&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;We are still&lt;/td&gt; &lt;td&gt;able to acces&lt;/td&gt; &lt;td&gt;the space before it.&lt;/td&gt; &lt;td&gt; &lt;table border=&quot;1&quot; cellpadding=&quot;1&quot; cellspacing=&quot;1&quot; style=&quot;width: 100%; &quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;This table is inside of a cell of another table.&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;We can type&amp;nbsp;either before or after it though.&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;p&gt;Two succesive horizontal lines (&lt;tt&gt;HR&lt;/tt&gt; tags). We can access the space in between:&lt;/p&gt; &lt;hr /&gt; &lt;hr /&gt; &lt;ol&gt; &lt;li&gt;This numbered list...&lt;/li&gt; &lt;li&gt;...is a neighbour of a horizontal line...&lt;/li&gt; &lt;li&gt;...and another list.&lt;/li&gt; &lt;/ol&gt; &lt;ul&gt; &lt;li&gt;We can type between the lists...&lt;/li&gt; &lt;li&gt;...thanks to &lt;strong&gt;Magicline&lt;/strong&gt;.&lt;/li&gt; &lt;/ul&gt; &lt;p&gt;Lorem ipsum dolor sit amet dui. Morbi vel turpis. Nullam et leo. Etiam rutrum, urna tellus dui vel tincidunt mattis egestas, justo fringilla vel, massa. Phasellus.&lt;/p&gt; &lt;p&gt;Quisque iaculis, dui lectus varius vitae, tortor. Proin lacus. Pellentesque ac lacus. Aenean nonummy commodo nec, pede. Etiam blandit risus elit.&lt;/p&gt; &lt;p&gt;Ut pretium. Vestibulum rutrum in, adipiscing elit. Sed in quam in purus sem vitae pede. Pellentesque bibendum, urna sem vel risus. Vivamus posuere metus. Aliquam gravida iaculis nisl. Nam enim. Aliquam erat ac lacus tellus ac felis.&lt;/p&gt; &lt;div style=&quot;border: 2px dashed green; background: #ddd; text-align: center;&quot;&gt; &lt;p&gt;This text is wrapped in a&amp;nbsp;&lt;tt&gt;DIV&lt;/tt&gt;&amp;nbsp;element. We can type after this element though.&lt;/p&gt; &lt;/div&gt; </textarea> <script> // This call can be placed at any point after the // <textarea>, or inside a <head><script> in a // window.onload event handler. CKEDITOR.replace( 'editor2', { extraPlugins: 'magicline', // Ensure that magicline plugin, which is required for this sample, is loaded. magicline_color: 'blue', // Blue line allowedContent: true // Switch off the ACF, so very complex content created to // show magicline's power isn't filtered. }); </script> </div> <div id="footer"> <hr> <p> CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a> </p> <p id="copy"> Copyright &copy; 2003-2014, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico Knabben. All rights reserved. </p> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/shared/plugin/ckeditor/samples/plugins/magicline/magicline.html
HTML
gpl3
8,176
<!DOCTYPE html> <!-- Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.md or http://ckeditor.com/license --> <html> <head> <meta charset="utf-8"> <title>Using API to Customize Dialog Windows &mdash; CKEditor Sample</title> <script src="../../../ckeditor.js"></script> <link rel="stylesheet" href="../../../samples/sample.css"> <meta name="ckeditor-sample-name" content="Using the JavaScript API to customize dialog windows"> <meta name="ckeditor-sample-group" content="Advanced Samples"> <meta name="ckeditor-sample-description" content="Using the dialog windows API to customize dialog windows without changing the original editor code."> <style> .cke_button__mybutton_icon { display: none !important; } .cke_button__mybutton_label { display: inline !important; } </style> <script> CKEDITOR.on( 'instanceCreated', function( ev ){ var editor = ev.editor; // Listen for the "pluginsLoaded" event, so we are sure that the // "dialog" plugin has been loaded and we are able to do our // customizations. editor.on( 'pluginsLoaded', function() { // If our custom dialog has not been registered, do that now. if ( !CKEDITOR.dialog.exists( 'myDialog' ) ) { // We need to do the following trick to find out the dialog // definition file URL path. In the real world, you would simply // point to an absolute path directly, like "/mydir/mydialog.js". var href = document.location.href.split( '/' ); href.pop(); href.push( 'assets/my_dialog.js' ); href = href.join( '/' ); // Finally, register the dialog. CKEDITOR.dialog.add( 'myDialog', href ); } // Register the command used to open the dialog. editor.addCommand( 'myDialogCmd', new CKEDITOR.dialogCommand( 'myDialog' ) ); // Add the a custom toolbar buttons, which fires the above // command.. editor.ui.add( 'MyButton', CKEDITOR.UI_BUTTON, { label: 'My Dialog', command: 'myDialogCmd' }); }); }); // When opening a dialog, its "definition" is created for it, for // each editor instance. The "dialogDefinition" event is then // fired. We should use this event to make customizations to the // definition of existing dialogs. CKEDITOR.on( 'dialogDefinition', function( ev ) { // Take the dialog name and its definition from the event data. var dialogName = ev.data.name; var dialogDefinition = ev.data.definition; // Check if the definition is from the dialog we're // interested on (the "Link" dialog). if ( dialogName == 'myDialog' && ev.editor.name == 'editor2' ) { // Get a reference to the "Link Info" tab. var infoTab = dialogDefinition.getContents( 'tab1' ); // Add a new text field to the "tab1" tab page. infoTab.add( { type: 'text', label: 'My Custom Field', id: 'customField', 'default': 'Sample!', validate: function() { if ( ( /\d/ ).test( this.getValue() ) ) return 'My Custom Field must not contain digits'; } }); // Remove the "select1" field from the "tab1" tab. infoTab.remove( 'select1' ); // Set the default value for "input1" field. var input1 = infoTab.get( 'input1' ); input1[ 'default' ] = 'www.example.com'; // Remove the "tab2" tab page. dialogDefinition.removeContents( 'tab2' ); // Add a new tab to the "Link" dialog. dialogDefinition.addContents( { id: 'customTab', label: 'My Tab', accessKey: 'M', elements: [ { id: 'myField1', type: 'text', label: 'My Text Field' }, { id: 'myField2', type: 'text', label: 'Another Text Field' } ] }); // Provide the focus handler to start initial focus in "customField" field. dialogDefinition.onFocus = function() { var urlField = this.getContentElement( 'tab1', 'customField' ); urlField.select(); }; } }); var config = { extraPlugins: 'dialog', toolbar: [ [ 'MyButton' ] ] }; </script> </head> <body> <h1 class="samples"> <a href="../../../samples/index.html">CKEditor Samples</a> &raquo; Using CKEditor Dialog API </h1> <div class="description"> <p> This sample shows how to use the <a class="samples" href="http://docs.ckeditor.com/#!/api/CKEDITOR.dialog">CKEditor Dialog API</a> to customize CKEditor dialog windows without changing the original editor code. The following customizations are being done in the example below: </p> <p> For details on how to create this setup check the source code of this sample page. </p> </div> <p>A custom dialog is added to the editors using the <code>pluginsLoaded</code> event, from an external <a target="_blank" href="assets/my_dialog.js">dialog definition file</a>:</p> <ol> <li><strong>Creating a custom dialog window</strong> &ndash; "My Dialog" dialog window opened with the "My Dialog" toolbar button.</li> <li><strong>Creating a custom button</strong> &ndash; Add button to open the dialog with "My Dialog" toolbar button.</li> </ol> <textarea cols="80" id="editor1" name="editor1" rows="10">&lt;p&gt;This is some &lt;strong&gt;sample text&lt;/strong&gt;. You are using &lt;a href="http://ckeditor.com/"&gt;CKEditor&lt;/a&gt;.&lt;/p&gt;</textarea> <script> // Replace the <textarea id="editor1"> with an CKEditor instance. CKEDITOR.replace( 'editor1', config ); </script> <p>The below editor modify the dialog definition of the above added dialog using the <code>dialogDefinition</code> event:</p> <ol> <li><strong>Adding dialog tab</strong> &ndash; Add new tab "My Tab" to dialog window.</li> <li><strong>Removing a dialog window tab</strong> &ndash; Remove "Second Tab" page from the dialog window.</li> <li><strong>Adding dialog window fields</strong> &ndash; Add "My Custom Field" to the dialog window.</li> <li><strong>Removing dialog window field</strong> &ndash; Remove "Select Field" selection field from the dialog window.</li> <li><strong>Setting default values for dialog window fields</strong> &ndash; Set default value of "Text Field" text field. </li> <li><strong>Setup initial focus for dialog window</strong> &ndash; Put initial focus on "My Custom Field" text field. </li> </ol> <textarea cols="80" id="editor2" name="editor2" rows="10">&lt;p&gt;This is some &lt;strong&gt;sample text&lt;/strong&gt;. You are using &lt;a href="http://ckeditor.com/"&gt;CKEditor&lt;/a&gt;.&lt;/p&gt;</textarea> <script> // Replace the <textarea id="editor1"> with an CKEditor instance. CKEDITOR.replace( 'editor2', config ); </script> <div id="footer"> <hr> <p> CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a> </p> <p id="copy"> Copyright &copy; 2003-2014, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico Knabben. All rights reserved. </p> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/shared/plugin/ckeditor/samples/plugins/dialog/dialog.html
HTML
gpl3
7,163
/** * Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md or http://ckeditor.com/license */ CKEDITOR.dialog.add( 'myDialog', function( editor ) { return { title: 'My Dialog', minWidth: 400, minHeight: 200, contents: [ { id: 'tab1', label: 'First Tab', title: 'First Tab', elements: [ { id: 'input1', type: 'text', label: 'Text Field' }, { id: 'select1', type: 'select', label: 'Select Field', items: [ [ 'option1', 'value1' ], [ 'option2', 'value2' ] ] } ] }, { id: 'tab2', label: 'Second Tab', title: 'Second Tab', elements: [ { id: 'button1', type: 'button', label: 'Button Field' } ] } ] }; } );
04-huanluyenviencanhan
trunk/master/shared/plugin/ckeditor/samples/plugins/dialog/assets/my_dialog.js
JavaScript
gpl3
885
<!DOCTYPE html> <!-- Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.md or http://ckeditor.com/license --> <html> <head> <meta charset="utf-8"> <title>Full Page Editing &mdash; CKEditor Sample</title> <script src="../../../ckeditor.js"></script> <script src="../../../samples/sample.js"></script> <link rel="stylesheet" href="../../../samples/sample.css"> <meta name="ckeditor-sample-required-plugins" content="sourcearea"> <meta name="ckeditor-sample-name" content="Full page support"> <meta name="ckeditor-sample-group" content="Plugins"> <meta name="ckeditor-sample-description" content="CKEditor inserted with a JavaScript call and used to edit the whole page from &lt;html&gt; to &lt;/html&gt;."> </head> <body> <h1 class="samples"> <a href="../../../samples/index.html">CKEditor Samples</a> &raquo; Full Page Editing </h1> <div class="description"> <p> This sample shows how to configure CKEditor to edit entire HTML pages, from the <code>&lt;html&gt;</code> tag to the <code>&lt;/html&gt;</code> tag. </p> <p> The CKEditor instance below is inserted with a JavaScript call using the following code: </p> <pre class="samples"> CKEDITOR.replace( '<em>textarea_id</em>', { <strong>fullPage: true</strong>, <strong>allowedContent: true</strong> }); </pre> <p> Note that <code><em>textarea_id</em></code> in the code above is the <code>id</code> attribute of the <code>&lt;textarea&gt;</code> element to be replaced. </p> <p> The <code><em>allowedContent</em></code> in the code above is set to <code>true</code> to disable content filtering. Setting this option is not obligatory, but in full page mode there is a strong chance that one may want be able to freely enter any HTML content in source mode without any limitations. </p> </div> <form action="../../../samples/sample_posteddata.php" method="post"> <label for="editor1"> CKEditor output the entire page including content outside of <code>&lt;body&gt;</code> element, so content like meta and title can be changed: </label> <textarea cols="80" id="editor1" name="editor1" rows="10"> &lt;h1&gt;&lt;img align=&quot;right&quot; alt=&quot;Saturn V carrying Apollo 11&quot; src=&quot;../../../samples/assets/sample.jpg&quot;/&gt; Apollo 11&lt;/h1&gt; &lt;p&gt;&lt;b&gt;Apollo 11&lt;/b&gt; was the spaceflight that landed the first humans, Americans &lt;a href=&quot;http://en.wikipedia.org/wiki/Neil_Armstrong&quot; title=&quot;Neil Armstrong&quot;&gt;Neil Armstrong&lt;/a&gt; and &lt;a href=&quot;http://en.wikipedia.org/wiki/Buzz_Aldrin&quot; title=&quot;Buzz Aldrin&quot;&gt;Buzz Aldrin&lt;/a&gt;, on the Moon on July 20, 1969, at 20:18 UTC. Armstrong became the first to step onto the lunar surface 6 hours later on July 21 at 02:56 UTC.&lt;/p&gt; &lt;p&gt;Armstrong spent about &lt;s&gt;three and a half&lt;/s&gt; two and a half hours outside the spacecraft, Aldrin slightly less; and together they collected 47.5 pounds (21.5&amp;nbsp;kg) of lunar material for return to Earth. A third member of the mission, &lt;a href=&quot;http://en.wikipedia.org/wiki/Michael_Collins_(astronaut)&quot; title=&quot;Michael Collins (astronaut)&quot;&gt;Michael Collins&lt;/a&gt;, piloted the &lt;a href=&quot;http://en.wikipedia.org/wiki/Apollo_Command/Service_Module&quot; title=&quot;Apollo Command/Service Module&quot;&gt;command&lt;/a&gt; spacecraft alone in lunar orbit until Armstrong and Aldrin returned to it for the trip back to Earth.&lt;/p&gt; &lt;h2&gt;Broadcasting and &lt;em&gt;quotes&lt;/em&gt; &lt;a id=&quot;quotes&quot; name=&quot;quotes&quot;&gt;&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;Broadcast on live TV to a world-wide audience, Armstrong stepped onto the lunar surface and described the event as:&lt;/p&gt; &lt;blockquote&gt;&lt;p&gt;One small step for [a] man, one giant leap for mankind.&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Apollo 11 effectively ended the &lt;a href=&quot;http://en.wikipedia.org/wiki/Space_Race&quot; title=&quot;Space Race&quot;&gt;Space Race&lt;/a&gt; and fulfilled a national goal proposed in 1961 by the late U.S. President &lt;a href=&quot;http://en.wikipedia.org/wiki/John_F._Kennedy&quot; title=&quot;John F. Kennedy&quot;&gt;John F. Kennedy&lt;/a&gt; in a speech before the United States Congress:&lt;/p&gt; &lt;blockquote&gt;&lt;p&gt;[...] before this decade is out, of landing a man on the Moon and returning him safely to the Earth.&lt;/p&gt;&lt;/blockquote&gt; &lt;h2&gt;Technical details &lt;a id=&quot;tech-details&quot; name=&quot;tech-details&quot;&gt;&lt;/a&gt;&lt;/h2&gt; &lt;table align=&quot;right&quot; border=&quot;1&quot; bordercolor=&quot;#ccc&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse:collapse;margin:10px 0 10px 15px;&quot;&gt; &lt;caption&gt;&lt;strong&gt;Mission crew&lt;/strong&gt;&lt;/caption&gt; &lt;thead&gt; &lt;tr&gt; &lt;th scope=&quot;col&quot;&gt;Position&lt;/th&gt; &lt;th scope=&quot;col&quot;&gt;Astronaut&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;Commander&lt;/td&gt; &lt;td&gt;Neil A. Armstrong&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Command Module Pilot&lt;/td&gt; &lt;td&gt;Michael Collins&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Lunar Module Pilot&lt;/td&gt; &lt;td&gt;Edwin &amp;quot;Buzz&amp;quot; E. Aldrin, Jr.&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;p&gt;Launched by a &lt;strong&gt;Saturn V&lt;/strong&gt; rocket from &lt;a href=&quot;http://en.wikipedia.org/wiki/Kennedy_Space_Center&quot; title=&quot;Kennedy Space Center&quot;&gt;Kennedy Space Center&lt;/a&gt; in Merritt Island, Florida on July 16, Apollo 11 was the fifth manned mission of &lt;a href=&quot;http://en.wikipedia.org/wiki/NASA&quot; title=&quot;NASA&quot;&gt;NASA&lt;/a&gt;&amp;#39;s Apollo program. The Apollo spacecraft had three parts:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;&lt;strong&gt;Command Module&lt;/strong&gt; with a cabin for the three astronauts which was the only part which landed back on Earth&lt;/li&gt; &lt;li&gt;&lt;strong&gt;Service Module&lt;/strong&gt; which supported the Command Module with propulsion, electrical power, oxygen and water&lt;/li&gt; &lt;li&gt;&lt;strong&gt;Lunar Module&lt;/strong&gt; for landing on the Moon.&lt;/li&gt; &lt;/ol&gt; &lt;p&gt;After being sent to the Moon by the Saturn V&amp;#39;s upper stage, the astronauts separated the spacecraft from it and travelled for three days until they entered into lunar orbit. Armstrong and Aldrin then moved into the Lunar Module and landed in the &lt;a href=&quot;http://en.wikipedia.org/wiki/Mare_Tranquillitatis&quot; title=&quot;Mare Tranquillitatis&quot;&gt;Sea of Tranquility&lt;/a&gt;. They stayed a total of about 21 and a half hours on the lunar surface. After lifting off in the upper part of the Lunar Module and rejoining Collins in the Command Module, they returned to Earth and landed in the &lt;a href=&quot;http://en.wikipedia.org/wiki/Pacific_Ocean&quot; title=&quot;Pacific Ocean&quot;&gt;Pacific Ocean&lt;/a&gt; on July 24.&lt;/p&gt; &lt;hr/&gt; &lt;p style=&quot;text-align: right;&quot;&gt;&lt;small&gt;Source: &lt;a href=&quot;http://en.wikipedia.org/wiki/Apollo_11&quot;&gt;Wikipedia.org&lt;/a&gt;&lt;/small&gt;&lt;/p&gt; </textarea> <script> CKEDITOR.replace( 'editor1', { fullPage: true, allowedContent: true, extraPlugins: 'wysiwygarea' }); </script> <p> <input type="submit" value="Submit"> </p> </form> <div id="footer"> <hr> <p> CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a> </p> <p id="copy"> Copyright &copy; 2003-2014, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico Knabben. All rights reserved. </p> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/shared/plugin/ckeditor/samples/plugins/wysiwygarea/fullpage.html
HTML
gpl3
7,895
<!DOCTYPE html> <!-- Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.md or http://ckeditor.com/license --> <html> <head> <meta charset="utf-8"> <title>HTML Compliant Output &mdash; CKEditor Sample</title> <script src="../../../ckeditor.js"></script> <script src="../../../samples/sample.js"></script> <link href="../../../samples/sample.css" rel="stylesheet"> <meta name="ckeditor-sample-required-plugins" content="sourcearea"> <meta name="ckeditor-sample-name" content="Output HTML"> <meta name="ckeditor-sample-group" content="Advanced Samples"> <meta name="ckeditor-sample-description" content="Configuring CKEditor to produce legacy HTML 4 code."> </head> <body> <h1 class="samples"> <a href="../../../samples/index.html">CKEditor Samples</a> &raquo; Producing HTML Compliant Output </h1> <div class="description"> <p> This sample shows how to configure CKEditor to output valid <a class="samples" href="http://www.w3.org/TR/html401/">HTML 4.01</a> code. Traditional HTML elements like <code>&lt;b&gt;</code>, <code>&lt;i&gt;</code>, and <code>&lt;font&gt;</code> are used in place of <code>&lt;strong&gt;</code>, <code>&lt;em&gt;</code>, and CSS styles. </p> <p> To add a CKEditor instance outputting legacy HTML 4.01 code, load the editor using a standard JavaScript call, and define CKEditor features to use the HTML compliant elements and attributes. </p> <p> A snippet of the configuration code can be seen below; check the source of this page for full definition: </p> <pre class="samples"> CKEDITOR.replace( '<em>textarea_id</em>', { coreStyles_bold: { element: 'b' }, coreStyles_italic: { element: 'i' }, fontSize_style: { element: 'font', attributes: { 'size': '#(size)' } } ... });</pre> </div> <form action="../../../samples/sample_posteddata.php" method="post"> <p> <label for="editor1"> Editor 1: </label> <textarea cols="80" id="editor1" name="editor1" rows="10">&lt;p&gt;This is some &lt;b&gt;sample text&lt;/b&gt;. You are using &lt;a href="http://ckeditor.com/"&gt;CKEditor&lt;/a&gt;.&lt;/p&gt;</textarea> <script> CKEDITOR.replace( 'editor1', { /* * Ensure that htmlwriter plugin, which is required for this sample, is loaded. */ extraPlugins: 'htmlwriter', /* * Style sheet for the contents */ contentsCss: 'body {color:#000; background-color#:FFF;}', /* * Simple HTML5 doctype */ docType: '<!DOCTYPE HTML>', /* * Allowed content rules which beside limiting allowed HTML * will also take care of transforming styles to attributes * (currently only for img - see transformation rules defined below). * * Read more: http://docs.ckeditor.com/#!/guide/dev_advanced_content_filter */ allowedContent: 'h1 h2 h3 p pre[align]; ' + 'blockquote code kbd samp var del ins cite q b i u strike ul ol li hr table tbody tr td th caption; ' + 'img[!src,alt,align,width,height]; font[!face]; font[!family]; font[!color]; font[!size]; font{!background-color}; a[!href]; a[!name]', /* * Core styles. */ coreStyles_bold: { element: 'b' }, coreStyles_italic: { element: 'i' }, coreStyles_underline: { element: 'u' }, coreStyles_strike: { element: 'strike' }, /* * Font face. */ // Define the way font elements will be applied to the document. // The "font" element will be used. font_style: { element: 'font', attributes: { 'face': '#(family)' } }, /* * Font sizes. */ fontSize_sizes: 'xx-small/1;x-small/2;small/3;medium/4;large/5;x-large/6;xx-large/7', fontSize_style: { element: 'font', attributes: { 'size': '#(size)' } }, /* * Font colors. */ colorButton_foreStyle: { element: 'font', attributes: { 'color': '#(color)' } }, colorButton_backStyle: { element: 'font', styles: { 'background-color': '#(color)' } }, /* * Styles combo. */ stylesSet: [ { name: 'Computer Code', element: 'code' }, { name: 'Keyboard Phrase', element: 'kbd' }, { name: 'Sample Text', element: 'samp' }, { name: 'Variable', element: 'var' }, { name: 'Deleted Text', element: 'del' }, { name: 'Inserted Text', element: 'ins' }, { name: 'Cited Work', element: 'cite' }, { name: 'Inline Quotation', element: 'q' } ], on: { pluginsLoaded: configureTransformations, loaded: configureHtmlWriter } }); /* * Add missing content transformations. */ function configureTransformations( evt ) { var editor = evt.editor; editor.dataProcessor.htmlFilter.addRules( { attributes: { style: function( value, element ) { // Return #RGB for background and border colors return CKEDITOR.tools.convertRgbToHex( value ); } } } ); // Default automatic content transformations do not yet take care of // align attributes on blocks, so we need to add our own transformation rules. function alignToAttribute( element ) { if ( element.styles[ 'text-align' ] ) { element.attributes.align = element.styles[ 'text-align' ]; delete element.styles[ 'text-align' ]; } } editor.filter.addTransformations( [ [ { element: 'p', right: alignToAttribute } ], [ { element: 'h1', right: alignToAttribute } ], [ { element: 'h2', right: alignToAttribute } ], [ { element: 'h3', right: alignToAttribute } ], [ { element: 'pre', right: alignToAttribute } ] ] ); } /* * Adjust the behavior of htmlWriter to make it output HTML like FCKeditor. */ function configureHtmlWriter( evt ) { var editor = evt.editor, dataProcessor = editor.dataProcessor; // Out self closing tags the HTML4 way, like <br>. dataProcessor.writer.selfClosingEnd = '>'; // Make output formatting behave similar to FCKeditor. var dtd = CKEDITOR.dtd; for ( var e in CKEDITOR.tools.extend( {}, dtd.$nonBodyContent, dtd.$block, dtd.$listItem, dtd.$tableContent ) ) { dataProcessor.writer.setRules( e, { indent: true, breakBeforeOpen: true, breakAfterOpen: false, breakBeforeClose: !dtd[ e ][ '#' ], breakAfterClose: true }); } } </script> </p> <p> <input type="submit" value="Submit"> </p> </form> <div id="footer"> <hr> <p> CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a> </p> <p id="copy"> Copyright &copy; 2003-2014, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico Knabben. All rights reserved. </p> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/shared/plugin/ckeditor/samples/plugins/htmlwriter/outputhtml.html
HTML
gpl3
7,135
<!DOCTYPE html> <!-- Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.md or http://ckeditor.com/license --> <html> <head> <meta charset="utf-8"> <title>Output for Flash &mdash; CKEditor Sample</title> <script src="../../../ckeditor.js"></script> <script src="../../../samples/sample.js"></script> <script src="assets/outputforflash/swfobject.js"></script> <link href="../../../samples/sample.css" rel="stylesheet"> <meta name="ckeditor-sample-required-plugins" content="sourcearea"> <meta name="ckeditor-sample-name" content="Output for Flash"> <meta name="ckeditor-sample-group" content="Advanced Samples"> <meta name="ckeditor-sample-description" content="Configuring CKEditor to produce HTML code that can be used with Adobe Flash."> <style> .alert { background: #ffa84c; padding: 10px 15px; font-weight: bold; display: block; margin-bottom: 20px; } </style> </head> <body> <h1 class="samples"> <a href="../../../samples/index.html">CKEditor Samples</a> &raquo; Producing Flash Compliant HTML Output </h1> <div class="description"> <p> This sample shows how to configure CKEditor to output HTML code that can be used with <a class="samples" href="http://www.adobe.com/livedocs/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&amp;file=00000922.html"> Adobe Flash</a>. The code will contain a subset of standard HTML elements like <code>&lt;b&gt;</code>, <code>&lt;i&gt;</code>, and <code>&lt;p&gt;</code> as well as HTML attributes. </p> <p> To add a CKEditor instance outputting Flash compliant HTML code, load the editor using a standard JavaScript call, and define CKEditor features to use HTML elements and attributes. </p> <p> For details on how to create this setup check the source code of this sample page. </p> </div> <p> To see how it works, create some content in the editing area of CKEditor on the left and send it to the Flash object on the right side of the page by using the <strong>Send to Flash</strong> button. </p> <table style="width: 100%; border-spacing: 0; border-collapse:collapse;"> <tr> <td style="width: 100%"> <textarea cols="80" id="editor1" name="editor1" rows="10">&lt;p&gt;&lt;b&gt;&lt;font size=&quot;18&quot; style=&quot;font-size:18px;&quot;&gt;Flash and HTML&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;It is possible to have &lt;a href=&quot;http://ckeditor.com&quot;&gt;CKEditor&lt;/a&gt; creating content that will be later loaded inside &lt;b&gt;Flash&lt;/b&gt; objects and animations.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Flash has a few limitations when dealing with HTML:&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;It has limited support on tags.&lt;/li&gt;&lt;li&gt;There is no margin between block elements, like paragraphs.&lt;/li&gt;&lt;/ul&gt;</textarea> <script> if ( document.location.protocol == 'file:' ) alert( 'Warning: This samples does not work when loaded from local filesystem' + 'due to security restrictions implemented in Flash.' + '\n\nPlease load the sample from a web server instead.' ); var editor = CKEDITOR.replace( 'editor1', { /* * Ensure that htmlwriter plugin, which is required for this sample, is loaded. */ extraPlugins: 'htmlwriter', height: 290, width: '100%', toolbar: [ [ 'Source', '-', 'Bold', 'Italic', 'Underline', '-', 'BulletedList', '-', 'Link', 'Unlink' ], [ 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock' ], '/', [ 'Font', 'FontSize' ], [ 'TextColor', '-', 'About' ] ], /* * Style sheet for the contents */ contentsCss: 'body {color:#000; background-color#FFF; font-family: Arial; font-size:80%;} p, ol, ul {margin-top: 0px; margin-bottom: 0px;}', /* * Quirks doctype */ docType: '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">', /* * Core styles. */ coreStyles_bold: { element: 'b' }, coreStyles_italic: { element: 'i' }, coreStyles_underline: { element: 'u' }, /* * Font face. */ // Define the way font elements will be applied to the document. The "font" // element will be used. font_style: { element: 'font', attributes: { 'face': '#(family)' } }, /* * Font sizes. */ // The CSS part of the font sizes isn't used by Flash, it is there to get the // font rendered correctly in CKEditor. fontSize_sizes: '8px/8;9px/9;10px/10;11px/11;12px/12;14px/14;16px/16;18px/18;20px/20;22px/22;24px/24;26px/26;28px/28;36px/36;48px/48;72px/72', fontSize_style: { element: 'font', attributes: { 'size': '#(size)' }, styles: { 'font-size': '#(size)px' } } , /* * Font colors. */ colorButton_enableMore: true, colorButton_foreStyle: { element: 'font', attributes: { 'color': '#(color)' } }, colorButton_backStyle: { element: 'font', styles: { 'background-color': '#(color)' } }, on: { 'instanceReady': configureFlashOutput } }); /* * Adjust the behavior of the dataProcessor to match the * requirements of Flash */ function configureFlashOutput( ev ) { var editor = ev.editor, dataProcessor = editor.dataProcessor, htmlFilter = dataProcessor && dataProcessor.htmlFilter; // Out self closing tags the HTML4 way, like <br>. dataProcessor.writer.selfClosingEnd = '>'; // Make output formatting match Flash expectations var dtd = CKEDITOR.dtd; for ( var e in CKEDITOR.tools.extend( {}, dtd.$nonBodyContent, dtd.$block, dtd.$listItem, dtd.$tableContent ) ) { dataProcessor.writer.setRules( e, { indent: false, breakBeforeOpen: false, breakAfterOpen: false, breakBeforeClose: false, breakAfterClose: false }); } dataProcessor.writer.setRules( 'br', { indent: false, breakBeforeOpen: false, breakAfterOpen: false, breakBeforeClose: false, breakAfterClose: false }); // Output properties as attributes, not styles. htmlFilter.addRules( { elements: { $: function( element ) { var style, match, width, height, align; // Output dimensions of images as width and height if ( element.name == 'img' ) { style = element.attributes.style; if ( style ) { // Get the width from the style. match = ( /(?:^|\s)width\s*:\s*(\d+)px/i ).exec( style ); width = match && match[1]; // Get the height from the style. match = ( /(?:^|\s)height\s*:\s*(\d+)px/i ).exec( style ); height = match && match[1]; if ( width ) { element.attributes.style = element.attributes.style.replace( /(?:^|\s)width\s*:\s*(\d+)px;?/i , '' ); element.attributes.width = width; } if ( height ) { element.attributes.style = element.attributes.style.replace( /(?:^|\s)height\s*:\s*(\d+)px;?/i , '' ); element.attributes.height = height; } } } // Output alignment of paragraphs using align if ( element.name == 'p' ) { style = element.attributes.style; if ( style ) { // Get the align from the style. match = ( /(?:^|\s)text-align\s*:\s*(\w*);?/i ).exec( style ); align = match && match[1]; if ( align ) { element.attributes.style = element.attributes.style.replace( /(?:^|\s)text-align\s*:\s*(\w*);?/i , '' ); element.attributes.align = align; } } } if ( element.attributes.style === '' ) delete element.attributes.style; return element; } } }); } function sendToFlash() { var html = CKEDITOR.instances.editor1.getData() ; // Quick fix for link color. html = html.replace( /<a /g, '<font color="#0000FF"><u><a ' ) html = html.replace( /<\/a>/g, '</a></u></font>' ) var flash = document.getElementById( 'ckFlashContainer' ) ; flash.setData( html ) ; } CKEDITOR.domReady( function() { if ( !swfobject.hasFlashPlayerVersion( '8' ) ) { CKEDITOR.dom.element.createFromHtml( '<span class="alert">' + 'At least Adobe Flash Player 8 is required to run this sample. ' + 'You can download it from <a href="http://get.adobe.com/flashplayer">Adobe\'s website</a>.' + '</span>' ).insertBefore( editor.element ); } swfobject.embedSWF( 'assets/outputforflash/outputforflash.swf', 'ckFlashContainer', '550', '400', '8', { wmode: 'transparent' } ); }); </script> <p> <input type="button" value="Send to Flash" onclick="sendToFlash();"> </p> </td> <td style="vertical-align: top; padding-left: 20px"> <div id="ckFlashContainer"></div> </td> </tr> </table> <div id="footer"> <hr> <p> CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a> </p> <p id="copy"> Copyright &copy; 2003-2014, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico Knabben. All rights reserved. </p> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/shared/plugin/ckeditor/samples/plugins/htmlwriter/outputforflash.html
HTML
gpl3
9,922
<!DOCTYPE html> <!-- Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.md or http://ckeditor.com/license --> <html> <head> <meta charset="utf-8"> <title>Replace Textarea by Code &mdash; CKEditor Sample</title> <script src="../ckeditor.js"></script> <link href="sample.css" rel="stylesheet"> </head> <body> <h1 class="samples"> <a href="index.html">CKEditor Samples</a> &raquo; Replace Textarea Elements Using JavaScript Code </h1> <form action="sample_posteddata.php" method="post"> <div class="description"> <p> This editor is using an <code>&lt;iframe&gt;</code> element-based editing area, provided by the <strong>Wysiwygarea</strong> plugin. </p> <pre class="samples"> CKEDITOR.replace( '<em>textarea_id</em>' ) </pre> </div> <textarea cols="80" id="editor1" name="editor1" rows="10"> &lt;h1&gt;&lt;img alt=&quot;Saturn V carrying Apollo 11&quot; class=&quot;right&quot; src=&quot;assets/sample.jpg&quot;/&gt; Apollo 11&lt;/h1&gt; &lt;p&gt;&lt;b&gt;Apollo 11&lt;/b&gt; was the spaceflight that landed the first humans, Americans &lt;a href=&quot;http://en.wikipedia.org/wiki/Neil_Armstrong&quot; title=&quot;Neil Armstrong&quot;&gt;Neil Armstrong&lt;/a&gt; and &lt;a href=&quot;http://en.wikipedia.org/wiki/Buzz_Aldrin&quot; title=&quot;Buzz Aldrin&quot;&gt;Buzz Aldrin&lt;/a&gt;, on the Moon on July 20, 1969, at 20:18 UTC. Armstrong became the first to step onto the lunar surface 6 hours later on July 21 at 02:56 UTC.&lt;/p&gt; &lt;p&gt;Armstrong spent about &lt;s&gt;three and a half&lt;/s&gt; two and a half hours outside the spacecraft, Aldrin slightly less; and together they collected 47.5 pounds (21.5&amp;nbsp;kg) of lunar material for return to Earth. A third member of the mission, &lt;a href=&quot;http://en.wikipedia.org/wiki/Michael_Collins_(astronaut)&quot; title=&quot;Michael Collins (astronaut)&quot;&gt;Michael Collins&lt;/a&gt;, piloted the &lt;a href=&quot;http://en.wikipedia.org/wiki/Apollo_Command/Service_Module&quot; title=&quot;Apollo Command/Service Module&quot;&gt;command&lt;/a&gt; spacecraft alone in lunar orbit until Armstrong and Aldrin returned to it for the trip back to Earth.&lt;/p&gt; &lt;h2&gt;Broadcasting and &lt;em&gt;quotes&lt;/em&gt; &lt;a id=&quot;quotes&quot; name=&quot;quotes&quot;&gt;&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;Broadcast on live TV to a world-wide audience, Armstrong stepped onto the lunar surface and described the event as:&lt;/p&gt; &lt;blockquote&gt;&lt;p&gt;One small step for [a] man, one giant leap for mankind.&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Apollo 11 effectively ended the &lt;a href=&quot;http://en.wikipedia.org/wiki/Space_Race&quot; title=&quot;Space Race&quot;&gt;Space Race&lt;/a&gt; and fulfilled a national goal proposed in 1961 by the late U.S. President &lt;a href=&quot;http://en.wikipedia.org/wiki/John_F._Kennedy&quot; title=&quot;John F. Kennedy&quot;&gt;John F. Kennedy&lt;/a&gt; in a speech before the United States Congress:&lt;/p&gt; &lt;blockquote&gt;&lt;p&gt;[...] before this decade is out, of landing a man on the Moon and returning him safely to the Earth.&lt;/p&gt;&lt;/blockquote&gt; &lt;h2&gt;Technical details &lt;a id=&quot;tech-details&quot; name=&quot;tech-details&quot;&gt;&lt;/a&gt;&lt;/h2&gt; &lt;table align=&quot;right&quot; border=&quot;1&quot; bordercolor=&quot;#ccc&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse:collapse;margin:10px 0 10px 15px;&quot;&gt; &lt;caption&gt;&lt;strong&gt;Mission crew&lt;/strong&gt;&lt;/caption&gt; &lt;thead&gt; &lt;tr&gt; &lt;th scope=&quot;col&quot;&gt;Position&lt;/th&gt; &lt;th scope=&quot;col&quot;&gt;Astronaut&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;Commander&lt;/td&gt; &lt;td&gt;Neil A. Armstrong&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Command Module Pilot&lt;/td&gt; &lt;td&gt;Michael Collins&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Lunar Module Pilot&lt;/td&gt; &lt;td&gt;Edwin &amp;quot;Buzz&amp;quot; E. Aldrin, Jr.&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;p&gt;Launched by a &lt;strong&gt;Saturn V&lt;/strong&gt; rocket from &lt;a href=&quot;http://en.wikipedia.org/wiki/Kennedy_Space_Center&quot; title=&quot;Kennedy Space Center&quot;&gt;Kennedy Space Center&lt;/a&gt; in Merritt Island, Florida on July 16, Apollo 11 was the fifth manned mission of &lt;a href=&quot;http://en.wikipedia.org/wiki/NASA&quot; title=&quot;NASA&quot;&gt;NASA&lt;/a&gt;&amp;#39;s Apollo program. The Apollo spacecraft had three parts:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;&lt;strong&gt;Command Module&lt;/strong&gt; with a cabin for the three astronauts which was the only part which landed back on Earth&lt;/li&gt; &lt;li&gt;&lt;strong&gt;Service Module&lt;/strong&gt; which supported the Command Module with propulsion, electrical power, oxygen and water&lt;/li&gt; &lt;li&gt;&lt;strong&gt;Lunar Module&lt;/strong&gt; for landing on the Moon.&lt;/li&gt; &lt;/ol&gt; &lt;p&gt;After being sent to the Moon by the Saturn V&amp;#39;s upper stage, the astronauts separated the spacecraft from it and travelled for three days until they entered into lunar orbit. Armstrong and Aldrin then moved into the Lunar Module and landed in the &lt;a href=&quot;http://en.wikipedia.org/wiki/Mare_Tranquillitatis&quot; title=&quot;Mare Tranquillitatis&quot;&gt;Sea of Tranquility&lt;/a&gt;. They stayed a total of about 21 and a half hours on the lunar surface. After lifting off in the upper part of the Lunar Module and rejoining Collins in the Command Module, they returned to Earth and landed in the &lt;a href=&quot;http://en.wikipedia.org/wiki/Pacific_Ocean&quot; title=&quot;Pacific Ocean&quot;&gt;Pacific Ocean&lt;/a&gt; on July 24.&lt;/p&gt; &lt;hr/&gt; &lt;p style=&quot;text-align: right;&quot;&gt;&lt;small&gt;Source: &lt;a href=&quot;http://en.wikipedia.org/wiki/Apollo_11&quot;&gt;Wikipedia.org&lt;/a&gt;&lt;/small&gt;&lt;/p&gt; </textarea> <script> // This call can be placed at any point after the // <textarea>, or inside a <head><script> in a // window.onload event handler. // Replace the <textarea id="editor"> with an CKEditor // instance, using default configurations. CKEDITOR.replace( 'editor1' ); </script> <p> <input type="submit" value="Submit"> </p> </form> <div id="footer"> <hr> <p> CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a> </p> <p id="copy"> Copyright &copy; 2003-2014, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico Knabben. All rights reserved. </p> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/shared/plugin/ckeditor/samples/replacebycode.html
HTML
gpl3
6,717
<!DOCTYPE html> <!-- Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.md or http://ckeditor.com/license --> <html> <head> <meta charset="utf-8"> <title>Massive inline editing &mdash; CKEditor Sample</title> <script src="../ckeditor.js"></script> <script> // This code is generally not necessary, but it is here to demonstrate // how to customize specific editor instances on the fly. This fits well // this demo because we have editable elements (like headers) that // require less features. // The "instanceCreated" event is fired for every editor instance created. CKEDITOR.on( 'instanceCreated', function( event ) { var editor = event.editor, element = editor.element; // Customize editors for headers and tag list. // These editors don't need features like smileys, templates, iframes etc. if ( element.is( 'h1', 'h2', 'h3' ) || element.getAttribute( 'id' ) == 'taglist' ) { // Customize the editor configurations on "configLoaded" event, // which is fired after the configuration file loading and // execution. This makes it possible to change the // configurations before the editor initialization takes place. editor.on( 'configLoaded', function() { // Remove unnecessary plugins to make the editor simpler. editor.config.removePlugins = 'colorbutton,find,flash,font,' + 'forms,iframe,image,newpage,removeformat,' + 'smiley,specialchar,stylescombo,templates'; // Rearrange the layout of the toolbar. editor.config.toolbarGroups = [ { name: 'editing', groups: [ 'basicstyles', 'links' ] }, { name: 'undo' }, { name: 'clipboard', groups: [ 'selection', 'clipboard' ] }, { name: 'about' } ]; }); } }); </script> <link href="sample.css" rel="stylesheet"> <style> /* The following styles are just to make the page look nice. */ /* Workaround to show Arial Black in Firefox. */ @font-face { font-family: 'arial-black'; src: local('Arial Black'); } *[contenteditable="true"] { padding: 10px; } #container { width: 960px; margin: 30px auto 0; } #header { overflow: hidden; padding: 0 0 30px; border-bottom: 5px solid #05B2D2; position: relative; } #headerLeft, #headerRight { width: 49%; overflow: hidden; } #headerLeft { float: left; padding: 10px 1px 1px; } #headerLeft h2, #headerLeft h3 { text-align: right; margin: 0; overflow: hidden; font-weight: normal; } #headerLeft h2 { font-family: "Arial Black",arial-black; font-size: 4.6em; line-height: 1.1; text-transform: uppercase; } #headerLeft h3 { font-size: 2.3em; line-height: 1.1; margin: .2em 0 0; color: #666; } #headerRight { float: right; padding: 1px; } #headerRight p { line-height: 1.8; text-align: justify; margin: 0; } #headerRight p + p { margin-top: 20px; } #headerRight > div { padding: 20px; margin: 0 0 0 30px; font-size: 1.4em; color: #666; } #columns { color: #333; overflow: hidden; padding: 20px 0; } #columns > div { float: left; width: 33.3%; } #columns #column1 > div { margin-left: 1px; } #columns #column3 > div { margin-right: 1px; } #columns > div > div { margin: 0px 10px; padding: 10px 20px; } #columns blockquote { margin-left: 15px; } #tagLine { border-top: 5px solid #05B2D2; padding-top: 20px; } #taglist { display: inline-block; margin-left: 20px; font-weight: bold; margin: 0 0 0 20px; } </style> </head> <body> <div> <h1 class="samples"><a href="index.html">CKEditor Samples</a> &raquo; Massive inline editing</h1> <div class="description"> <p>This sample page demonstrates the inline editing feature - CKEditor instances will be created automatically from page elements with <strong>contentEditable</strong> attribute set to value <strong>true</strong>:</p> <pre class="samples">&lt;div <strong>contenteditable="true</strong>" &gt; ... &lt;/div&gt;</pre> <p>Click inside of any element below to start editing.</p> </div> </div> <div id="container"> <div id="header"> <div id="headerLeft"> <h2 id="sampleTitle" contenteditable="true"> CKEditor<br> Goes Inline! </h2> <h3 contenteditable="true"> Lorem ipsum dolor sit amet dolor duis blandit vestibulum faucibus a, tortor. </h3> </div> <div id="headerRight"> <div contenteditable="true"> <p> Lorem ipsum dolor sit amet enim. Etiam ullamcorper. Suspendisse a pellentesque dui, non felis. Maecenas malesuada elit lectus felis, malesuada ultricies. </p> <p> Curabitur et ligula. Ut molestie a, ultricies porta urna. Vestibulum commodo volutpat a, convallis ac, laoreet enim. Phasellus fermentum in, dolor. Pellentesque facilisis. Nulla imperdiet sit amet magna. Vestibulum dapibus, mauris nec malesuada fames ac. </p> </div> </div> </div> <div id="columns"> <div id="column1"> <div contenteditable="true"> <h3> Fusce vitae porttitor </h3> <p> <strong> Lorem ipsum dolor sit amet dolor. Duis blandit vestibulum faucibus a, tortor. </strong> </p> <p> Proin nunc justo felis mollis tincidunt, risus risus pede, posuere cubilia Curae, Nullam euismod, enim. Etiam nibh ultricies dolor ac dignissim erat volutpat. Vivamus fermentum <a href="http://ckeditor.com/">nisl nulla sem in</a> metus. Maecenas wisi. Donec nec erat volutpat. </p> <blockquote> <p> Fusce vitae porttitor a, euismod convallis nisl, blandit risus tortor, pretium. Vehicula vitae, imperdiet vel, ornare enim vel sodales rutrum </p> </blockquote> <blockquote> <p> Libero nunc, rhoncus ante ipsum non ipsum. Nunc eleifend pede turpis id sollicitudin fringilla. Phasellus ultrices, velit ac arcu. </p> </blockquote> <p>Pellentesque nunc. Donec suscipit erat. Pellentesque habitant morbi tristique ullamcorper.</p> <p><s>Mauris mattis feugiat lectus nec mauris. Nullam vitae ante.</s></p> </div> </div> <div id="column2"> <div contenteditable="true"> <h3> Integer condimentum sit amet </h3> <p> <strong>Aenean nonummy a, mattis varius. Cras aliquet.</strong> Praesent <a href="http://ckeditor.com/">magna non mattis ac, rhoncus nunc</a>, rhoncus eget, cursus pulvinar mollis.</p> <p>Proin id nibh. Sed eu libero posuere sed, lectus. Phasellus dui gravida gravida feugiat mattis ac, felis.</p> <p>Integer condimentum sit amet, tempor elit odio, a dolor non ante at sapien. Sed ac lectus. Nulla ligula quis eleifend mi, id leo velit pede cursus arcu id nulla ac lectus. Phasellus vestibulum. Nunc viverra enim quis diam.</p> </div> <div contenteditable="true"> <h3> Praesent wisi accumsan sit amet nibh </h3> <p>Donec ullamcorper, risus tortor, pretium porttitor. Morbi quam quis lectus non leo.</p> <p style="margin-left: 40px; ">Integer faucibus scelerisque. Proin faucibus at, aliquet vulputate, odio at eros. Fusce <a href="http://ckeditor.com/">gravida, erat vitae augue</a>. Fusce urna fringilla gravida.</p> <p>In hac habitasse platea dictumst. Praesent wisi accumsan sit amet nibh. Maecenas orci luctus a, lacinia quam sem, posuere commodo, odio condimentum tempor, pede semper risus. Suspendisse pede. In hac habitasse platea dictumst. Nam sed laoreet sit amet erat. Integer.</p> </div> </div> <div id="column3"> <div contenteditable="true"> <p> <img src="assets/inlineall/logo.png" alt="CKEditor logo" style="float:left"> </p> <p>Quisque justo neque, mattis sed, fermentum ultrices <strong>posuere cubilia Curae</strong>, Vestibulum elit metus, quis placerat ut, lectus. Ut sagittis, nunc libero, egestas consequat lobortis velit rutrum ut, faucibus turpis. Fusce porttitor, nulla quis turpis. Nullam laoreet vel, consectetuer tellus suscipit ultricies, hendrerit wisi. Donec odio nec velit ac nunc sit amet, accumsan cursus aliquet. Vestibulum ante sit amet sagittis mi.</p> <h3> Nullam laoreet vel consectetuer tellus suscipit </h3> <ul> <li>Ut sagittis, nunc libero, egestas consequat lobortis velit rutrum ut, faucibus turpis.</li> <li>Fusce porttitor, nulla quis turpis. Nullam laoreet vel, consectetuer tellus suscipit ultricies, hendrerit wisi.</li> <li>Mauris eget tellus. Donec non felis. Nam eget dolor. Vestibulum enim. Donec.</li> </ul> <p>Quisque justo neque, mattis sed, <a href="http://ckeditor.com/">fermentum ultrices posuere cubilia</a> Curae, Vestibulum elit metus, quis placerat ut, lectus.</p> <p>Nullam laoreet vel, consectetuer tellus suscipit ultricies, hendrerit wisi. Ut sagittis, nunc libero, egestas consequat lobortis velit rutrum ut, faucibus turpis. Fusce porttitor, nulla quis turpis.</p> <p>Donec odio nec velit ac nunc sit amet, accumsan cursus aliquet. Vestibulum ante sit amet sagittis mi. Sed in nonummy faucibus turpis. Mauris eget tellus. Donec non felis. Nam eget dolor. Vestibulum enim. Donec.</p> </div> </div> </div> <div id="tagLine"> Tags of this article: <p id="taglist" contenteditable="true"> inline, editing, floating, CKEditor </p> </div> </div> <div id="footer"> <hr> <p> CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/"> http://ckeditor.com</a> </p> <p id="copy"> Copyright &copy; 2003-2014, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico Knabben. All rights reserved. </p> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/shared/plugin/ckeditor/samples/inlineall.html
HTML
gpl3
9,999
<?php /* <body><pre> ------------------------------------------------------------------------------------------- CKEditor - Posted Data We are sorry, but your Web server does not support the PHP language used in this script. Please note that CKEditor can be used with any other server-side language than just PHP. To save the content created with CKEditor you need to read the POST data on the server side and write it to a file or the database. Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.md or <a href="http://ckeditor.com/license">http://ckeditor.com/license</a> ------------------------------------------------------------------------------------------- </pre><div style="display:none"></body> */ include "assets/posteddata.php"; ?>
04-huanluyenviencanhan
trunk/master/shared/plugin/ckeditor/samples/sample_posteddata.php
PHP
gpl3
831
/** * Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md or http://ckeditor.com/license */ // Tool scripts for the sample pages. // This file can be ignored and is not required to make use of CKEditor. ( function() { CKEDITOR.on( 'instanceReady', function( ev ) { // Check for sample compliance. var editor = ev.editor, meta = CKEDITOR.document.$.getElementsByName( 'ckeditor-sample-required-plugins' ), requires = meta.length ? CKEDITOR.dom.element.get( meta[ 0 ] ).getAttribute( 'content' ).split( ',' ) : [], missing = [], i; if ( requires.length ) { for ( i = 0; i < requires.length; i++ ) { if ( !editor.plugins[ requires[ i ] ] ) missing.push( '<code>' + requires[ i ] + '</code>' ); } if ( missing.length ) { var warn = CKEDITOR.dom.element.createFromHtml( '<div class="warning">' + '<span>To fully experience this demo, the ' + missing.join( ', ' ) + ' plugin' + ( missing.length > 1 ? 's are' : ' is' ) + ' required.</span>' + '</div>' ); warn.insertBefore( editor.container ); } } // Set icons. var doc = new CKEDITOR.dom.document( document ), icons = doc.find( '.button_icon' ); for ( i = 0; i < icons.count(); i++ ) { var icon = icons.getItem( i ), name = icon.getAttribute( 'data-icon' ), style = CKEDITOR.skin.getIconStyle( name, ( CKEDITOR.lang.dir == 'rtl' ) ); icon.addClass( 'cke_button_icon' ); icon.addClass( 'cke_button__' + name + '_icon' ); icon.setAttribute( 'style', style ); icon.setStyle( 'float', 'none' ); } } ); } )();
04-huanluyenviencanhan
trunk/master/shared/plugin/ckeditor/samples/sample.js
JavaScript
gpl3
1,675
<!DOCTYPE html> <!-- Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.md or http://ckeditor.com/license --> <html> <head> <meta charset="utf-8"> <title>Ajax &mdash; CKEditor Sample</title> <script src="../ckeditor.js"></script> <link rel="stylesheet" href="sample.css"> <script> var editor, html = ''; function createEditor() { if ( editor ) return; // Create a new editor inside the <div id="editor">, setting its value to html var config = {}; editor = CKEDITOR.appendTo( 'editor', config, html ); } function removeEditor() { if ( !editor ) return; // Retrieve the editor contents. In an Ajax application, this data would be // sent to the server or used in any other way. document.getElementById( 'editorcontents' ).innerHTML = html = editor.getData(); document.getElementById( 'contents' ).style.display = ''; // Destroy the editor. editor.destroy(); editor = null; } </script> </head> <body> <h1 class="samples"> <a href="index.html">CKEditor Samples</a> &raquo; Create and Destroy Editor Instances for Ajax Applications </h1> <div class="description"> <p> This sample shows how to create and destroy CKEditor instances on the fly. After the removal of CKEditor the content created inside the editing area will be displayed in a <code>&lt;div&gt;</code> element. </p> <p> For details of how to create this setup check the source code of this sample page for JavaScript code responsible for the creation and destruction of a CKEditor instance. </p> </div> <p>Click the buttons to create and remove a CKEditor instance.</p> <p> <input onclick="createEditor();" type="button" value="Create Editor"> <input onclick="removeEditor();" type="button" value="Remove Editor"> </p> <!-- This div will hold the editor. --> <div id="editor"> </div> <div id="contents" style="display: none"> <p> Edited Contents: </p> <!-- This div will be used to display the editor contents. --> <div id="editorcontents"> </div> </div> <div id="footer"> <hr> <p> CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a> </p> <p id="copy"> Copyright &copy; 2003-2014, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico Knabben. All rights reserved. </p> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/shared/plugin/ckeditor/samples/ajax.html
HTML
gpl3
2,508
<!DOCTYPE html> <!-- Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.md or http://ckeditor.com/license --> <html> <head> <meta charset="utf-8"> <title>Replace DIV &mdash; CKEditor Sample</title> <script src="../ckeditor.js"></script> <link href="sample.css" rel="stylesheet"> <style> div.editable { border: solid 2px transparent; padding-left: 15px; padding-right: 15px; } div.editable:hover { border-color: black; } </style> <script> // Uncomment the following code to test the "Timeout Loading Method". // CKEDITOR.loadFullCoreTimeout = 5; window.onload = function() { // Listen to the double click event. if ( window.addEventListener ) document.body.addEventListener( 'dblclick', onDoubleClick, false ); else if ( window.attachEvent ) document.body.attachEvent( 'ondblclick', onDoubleClick ); }; function onDoubleClick( ev ) { // Get the element which fired the event. This is not necessarily the // element to which the event has been attached. var element = ev.target || ev.srcElement; // Find out the div that holds this element. var name; do { element = element.parentNode; } while ( element && ( name = element.nodeName.toLowerCase() ) && ( name != 'div' || element.className.indexOf( 'editable' ) == -1 ) && name != 'body' ); if ( name == 'div' && element.className.indexOf( 'editable' ) != -1 ) replaceDiv( element ); } var editor; function replaceDiv( div ) { if ( editor ) editor.destroy(); editor = CKEDITOR.replace( div ); } </script> </head> <body> <h1 class="samples"> <a href="index.html">CKEditor Samples</a> &raquo; Replace DIV with CKEditor on the Fly </h1> <div class="description"> <p> This sample shows how to automatically replace <code>&lt;div&gt;</code> elements with a CKEditor instance on the fly, following user's doubleclick. The content that was previously placed inside the <code>&lt;div&gt;</code> element will now be moved into CKEditor editing area. </p> <p> For details on how to create this setup check the source code of this sample page. </p> </div> <p> Double-click any of the following <code>&lt;div&gt;</code> elements to transform them into editor instances. </p> <div class="editable"> <h3> Part 1 </h3> <p> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Cras et ipsum quis mi semper accumsan. Integer pretium dui id massa. Suspendisse in nisl sit amet urna rutrum imperdiet. Nulla eu tellus. Donec ante nisi, ullamcorper quis, fringilla nec, sagittis eleifend, pede. Nulla commodo interdum massa. Donec id metus. Fusce eu ipsum. Suspendisse auctor. Phasellus fermentum porttitor risus. </p> </div> <div class="editable"> <h3> Part 2 </h3> <p> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Cras et ipsum quis mi semper accumsan. Integer pretium dui id massa. Suspendisse in nisl sit amet urna rutrum imperdiet. Nulla eu tellus. Donec ante nisi, ullamcorper quis, fringilla nec, sagittis eleifend, pede. Nulla commodo interdum massa. Donec id metus. Fusce eu ipsum. Suspendisse auctor. Phasellus fermentum porttitor risus. </p> <p> Donec velit. Mauris massa. Vestibulum non nulla. Nam suscipit arcu nec elit. Phasellus sollicitudin iaculis ante. Ut non mauris et sapien tincidunt adipiscing. Vestibulum vitae leo. Suspendisse nec mi tristique nulla laoreet vulputate. </p> </div> <div class="editable"> <h3> Part 3 </h3> <p> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Cras et ipsum quis mi semper accumsan. Integer pretium dui id massa. Suspendisse in nisl sit amet urna rutrum imperdiet. Nulla eu tellus. Donec ante nisi, ullamcorper quis, fringilla nec, sagittis eleifend, pede. Nulla commodo interdum massa. Donec id metus. Fusce eu ipsum. Suspendisse auctor. Phasellus fermentum porttitor risus. </p> </div> <div id="footer"> <hr> <p> CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a> </p> <p id="copy"> Copyright &copy; 2003-2014, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico Knabben. All rights reserved. </p> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/shared/plugin/ckeditor/samples/divreplace.html
HTML
gpl3
4,493
<!DOCTYPE html> <!-- Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.md or http://ckeditor.com/license --> <html> <head> <meta charset="utf-8"> <title>Data Filtering &mdash; CKEditor Sample</title> <script src="../ckeditor.js"></script> <link rel="stylesheet" href="sample.css"> <script> // Remove advanced tabs for all editors. CKEDITOR.config.removeDialogTabs = 'image:advanced;link:advanced;flash:advanced;creatediv:advanced;editdiv:advanced'; </script> </head> <body> <h1 class="samples"> <a href="index.html">CKEditor Samples</a> &raquo; Data Filtering and Features Activation </h1> <div class="description"> <p> This sample page demonstrates the idea of Advanced Content Filter (<abbr title="Advanced Content Filter">ACF</abbr>), a sophisticated tool that takes control over what kind of data is accepted by the editor and what kind of output is produced. </p> <h2>When and what is being filtered?</h2> <p> <abbr title="Advanced Content Filter">ACF</abbr> controls <strong>every single source of data</strong> that comes to the editor. It process both HTML that is inserted manually (i.e. pasted by the user) and programmatically like: </p> <pre class="samples"> editor.setData( '&lt;p&gt;Hello world!&lt;/p&gt;' ); </pre> <p> <abbr title="Advanced Content Filter">ACF</abbr> discards invalid, useless HTML tags and attributes so the editor remains "clean" during runtime. <abbr title="Advanced Content Filter">ACF</abbr> behaviour can be configured and adjusted for a particular case to prevent the output HTML (i.e. in CMS systems) from being polluted. This kind of filtering is a first, client-side line of defense against "<a href="http://en.wikipedia.org/wiki/Tag_soup">tag soups</a>", the tool that precisely restricts which tags, attributes and styles are allowed (desired). When properly configured, <abbr title="Advanced Content Filter">ACF</abbr> is an easy and fast way to produce a high-quality, intentionally filtered HTML. </p> <h3>How to configure or disable ACF?</h3> <p> Advanced Content Filter is enabled by default, working in "automatic mode", yet it provides a set of easy rules that allow adjusting filtering rules and disabling the entire feature when necessary. The config property responsible for this feature is <code><a class="samples" href="http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-allowedContent">config.allowedContent</a></code>. </p> <p> By "automatic mode" is meant that loaded plugins decide which kind of content is enabled and which is not. For example, if the link plugin is loaded it implies that <code>&lt;a&gt;</code> tag is automatically allowed. Each plugin is given a set of predefined <abbr title="Advanced Content Filter">ACF</abbr> rules that control the editor until <code><a class="samples" href="http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-allowedContent"> config.allowedContent</a></code> is defined manually. </p> <p> Let's assume our intention is to restrict the editor to accept (produce) <strong>paragraphs only: no attributes, no styles, no other tags</strong>. With <abbr title="Advanced Content Filter">ACF</abbr> this is very simple. Basically set <code><a class="samples" href="http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-allowedContent"> config.allowedContent</a></code> to <code>'p'</code>: </p> <pre class="samples"> var editor = CKEDITOR.replace( <em>textarea_id</em>, { <strong>allowedContent: 'p'</strong> } ); </pre> <p> Now try to play with allowed content: </p> <pre class="samples"> // Trying to insert disallowed tag and attribute. editor.setData( '&lt;p <strong>style="color: red"</strong>&gt;Hello <strong>&lt;em&gt;world&lt;/em&gt;</strong>!&lt;/p&gt;' ); alert( editor.getData() ); // Filtered data is returned. "&lt;p&gt;Hello world!&lt;/p&gt;" </pre> <p> What happened? Since <code>config.allowedContent: 'p'</code> is set the editor assumes that only plain <code>&lt;p&gt;</code> are accepted. Nothing more. This is why <code>style</code> attribute and <code>&lt;em&gt;</code> tag are gone. The same filtering would happen if we pasted disallowed HTML into this editor. </p> <p> This is just a small sample of what <abbr title="Advanced Content Filter">ACF</abbr> can do. To know more, please refer to the sample section below and <a href="http://docs.ckeditor.com/#!/guide/dev_advanced_content_filter">the official Advanced Content Filter guide</a>. </p> <p> You may, of course, want CKEditor to avoid filtering of any kind. To get rid of <abbr title="Advanced Content Filter">ACF</abbr>, basically set <code><a class="samples" href="http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-allowedContent"> config.allowedContent</a></code> to <code>true</code> like this: </p> <pre class="samples"> CKEDITOR.replace( <em>textarea_id</em>, { <strong>allowedContent: true</strong> } ); </pre> <h2>Beyond data flow: Features activation</h2> <p> <abbr title="Advanced Content Filter">ACF</abbr> is far more than <abbr title="Input/Output">I/O</abbr> control: the entire <abbr title="User Interface">UI</abbr> of the editor is adjusted to what filters restrict. For example: if <code>&lt;a&gt;</code> tag is <strong>disallowed</strong> by <abbr title="Advanced Content Filter">ACF</abbr>, then accordingly <code>link</code> command, toolbar button and link dialog are also disabled. Editor is smart: it knows which features must be removed from the interface to match filtering rules. </p> <p> CKEditor can be far more specific. If <code>&lt;a&gt;</code> tag is <strong>allowed</strong> by filtering rules to be used but it is restricted to have only one attribute (<code>href</code>) <code>config.allowedContent = 'a[!href]'</code>, then "Target" tab of the link dialog is automatically disabled as <code>target</code> attribute isn't included in <abbr title="Advanced Content Filter">ACF</abbr> rules for <code>&lt;a&gt;</code>. This behaviour applies to dialog fields, context menus and toolbar buttons. </p> <h2>Sample configurations</h2> <p> There are several editor instances below that present different <abbr title="Advanced Content Filter">ACF</abbr> setups. <strong>All of them, except the last inline instance, share the same HTML content</strong> to visualize how different filtering rules affect the same input data. </p> </div> <div> <label for="editor1"> Editor 1: </label> <div class="description"> <p> This editor is using default configuration ("automatic mode"). It means that <code><a class="samples" href="http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-allowedContent"> config.allowedContent</a></code> is defined by loaded plugins. Each plugin extends filtering rules to make it's own associated content available for the user. </p> </div> <textarea cols="80" id="editor1" name="editor1" rows="10"> &lt;h1&gt;&lt;img alt=&quot;Saturn V carrying Apollo 11&quot; class=&quot;right&quot; src=&quot;assets/sample.jpg&quot;/&gt; Apollo 11&lt;/h1&gt; &lt;p&gt;&lt;b&gt;Apollo 11&lt;/b&gt; was the spaceflight that landed the first humans, Americans &lt;a href=&quot;http://en.wikipedia.org/wiki/Neil_Armstrong&quot; title=&quot;Neil Armstrong&quot;&gt;Neil Armstrong&lt;/a&gt; and &lt;a href=&quot;http://en.wikipedia.org/wiki/Buzz_Aldrin&quot; title=&quot;Buzz Aldrin&quot;&gt;Buzz Aldrin&lt;/a&gt;, on the Moon on July 20, 1969, at 20:18 UTC. Armstrong became the first to step onto the lunar surface 6 hours later on July 21 at 02:56 UTC.&lt;/p&gt; &lt;p&gt;Armstrong spent about &lt;s&gt;three and a half&lt;/s&gt; two and a half hours outside the spacecraft, Aldrin slightly less; and together they collected 47.5 pounds (21.5&amp;nbsp;kg) of lunar material for return to Earth. A third member of the mission, &lt;a href=&quot;http://en.wikipedia.org/wiki/Michael_Collins_(astronaut)&quot; title=&quot;Michael Collins (astronaut)&quot;&gt;Michael Collins&lt;/a&gt;, piloted the &lt;a href=&quot;http://en.wikipedia.org/wiki/Apollo_Command/Service_Module&quot; title=&quot;Apollo Command/Service Module&quot;&gt;command&lt;/a&gt; spacecraft alone in lunar orbit until Armstrong and Aldrin returned to it for the trip back to Earth.&lt;/p&gt; &lt;h2&gt;Broadcasting and &lt;em&gt;quotes&lt;/em&gt; &lt;a id=&quot;quotes&quot; name=&quot;quotes&quot;&gt;&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;Broadcast on live TV to a world-wide audience, Armstrong stepped onto the lunar surface and described the event as:&lt;/p&gt; &lt;blockquote&gt;&lt;p&gt;One small step for [a] man, one giant leap for mankind.&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Apollo 11 effectively ended the &lt;a href=&quot;http://en.wikipedia.org/wiki/Space_Race&quot; title=&quot;Space Race&quot;&gt;Space Race&lt;/a&gt; and fulfilled a national goal proposed in 1961 by the late U.S. President &lt;a href=&quot;http://en.wikipedia.org/wiki/John_F._Kennedy&quot; title=&quot;John F. Kennedy&quot;&gt;John F. Kennedy&lt;/a&gt; in a speech before the United States Congress:&lt;/p&gt; &lt;blockquote&gt;&lt;p&gt;[...] before this decade is out, of landing a man on the Moon and returning him safely to the Earth.&lt;/p&gt;&lt;/blockquote&gt; &lt;h2&gt;Technical details &lt;a id=&quot;tech-details&quot; name=&quot;tech-details&quot;&gt;&lt;/a&gt;&lt;/h2&gt; &lt;table align=&quot;right&quot; border=&quot;1&quot; bordercolor=&quot;#ccc&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse:collapse;margin:10px 0 10px 15px;&quot;&gt; &lt;caption&gt;&lt;strong&gt;Mission crew&lt;/strong&gt;&lt;/caption&gt; &lt;thead&gt; &lt;tr&gt; &lt;th scope=&quot;col&quot;&gt;Position&lt;/th&gt; &lt;th scope=&quot;col&quot;&gt;Astronaut&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;Commander&lt;/td&gt; &lt;td&gt;Neil A. Armstrong&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Command Module Pilot&lt;/td&gt; &lt;td&gt;Michael Collins&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Lunar Module Pilot&lt;/td&gt; &lt;td&gt;Edwin &amp;quot;Buzz&amp;quot; E. Aldrin, Jr.&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;p&gt;Launched by a &lt;strong&gt;Saturn V&lt;/strong&gt; rocket from &lt;a href=&quot;http://en.wikipedia.org/wiki/Kennedy_Space_Center&quot; title=&quot;Kennedy Space Center&quot;&gt;Kennedy Space Center&lt;/a&gt; in Merritt Island, Florida on July 16, Apollo 11 was the fifth manned mission of &lt;a href=&quot;http://en.wikipedia.org/wiki/NASA&quot; title=&quot;NASA&quot;&gt;NASA&lt;/a&gt;&amp;#39;s Apollo program. The Apollo spacecraft had three parts:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;&lt;strong&gt;Command Module&lt;/strong&gt; with a cabin for the three astronauts which was the only part which landed back on Earth&lt;/li&gt; &lt;li&gt;&lt;strong&gt;Service Module&lt;/strong&gt; which supported the Command Module with propulsion, electrical power, oxygen and water&lt;/li&gt; &lt;li&gt;&lt;strong&gt;Lunar Module&lt;/strong&gt; for landing on the Moon.&lt;/li&gt; &lt;/ol&gt; &lt;p&gt;After being sent to the Moon by the Saturn V&amp;#39;s upper stage, the astronauts separated the spacecraft from it and travelled for three days until they entered into lunar orbit. Armstrong and Aldrin then moved into the Lunar Module and landed in the &lt;a href=&quot;http://en.wikipedia.org/wiki/Mare_Tranquillitatis&quot; title=&quot;Mare Tranquillitatis&quot;&gt;Sea of Tranquility&lt;/a&gt;. They stayed a total of about 21 and a half hours on the lunar surface. After lifting off in the upper part of the Lunar Module and rejoining Collins in the Command Module, they returned to Earth and landed in the &lt;a href=&quot;http://en.wikipedia.org/wiki/Pacific_Ocean&quot; title=&quot;Pacific Ocean&quot;&gt;Pacific Ocean&lt;/a&gt; on July 24.&lt;/p&gt; &lt;hr/&gt; &lt;p style=&quot;text-align: right;&quot;&gt;&lt;small&gt;Source: &lt;a href=&quot;http://en.wikipedia.org/wiki/Apollo_11&quot;&gt;Wikipedia.org&lt;/a&gt;&lt;/small&gt;&lt;/p&gt; </textarea> <script> CKEDITOR.replace( 'editor1' ); </script> </div> <br> <div> <label for="editor2"> Editor 2: </label> <div class="description"> <p> This editor is using a custom configuration for <abbr title="Advanced Content Filter">ACF</abbr>: </p> <pre class="samples"> CKEDITOR.replace( 'editor2', { allowedContent: 'h1 h2 h3 p blockquote strong em;' + 'a[!href];' + 'img(left,right)[!src,alt,width,height];' + 'table tr th td caption;' + 'span{!font-family};' +' 'span{!color};' + 'span(!marker);' + 'del ins' } ); </pre> <p> The following rules may require additional explanation: </p> <ul> <li> <code>h1 h2 h3 p blockquote strong em</code> - These tags are accepted by the editor. Any tag attributes will be discarded. </li> <li> <code>a[!href]</code> - <code>href</code> attribute is obligatory for <code>&lt;a&gt;</code> tag. Tags without this attribute are disarded. No other attribute will be accepted. </li> <li> <code>img(left,right)[!src,alt,width,height]</code> - <code>src</code> attribute is obligatory for <code>&lt;img&gt;</code> tag. <code>alt</code>, <code>width</code>, <code>height</code> and <code>class</code> attributes are accepted but <code>class</code> must be either <code>class="left"</code> or <code>class="right"</code> </li> <li> <code>table tr th td caption</code> - These tags are accepted by the editor. Any tag attributes will be discarded. </li> <li> <code>span{!font-family}</code>, <code>span{!color}</code>, <code>span(!marker)</code> - <code>&lt;span&gt;</code> tags will be accepted if either <code>font-family</code> or <code>color</code> style is set or <code>class="marker"</code> is present. </li> <li> <code>del ins</code> - These tags are accepted by the editor. Any tag attributes will be discarded. </li> </ul> <p> Please note that <strong><abbr title="User Interface">UI</abbr> of the editor is different</strong>. It's a response to what happened to the filters. Since <code>text-align</code> isn't allowed, the align toolbar is gone. The same thing happened to subscript/superscript, strike, underline (<code>&lt;u&gt;</code>, <code>&lt;sub&gt;</code>, <code>&lt;sup&gt;</code> are disallowed by <code><a class="samples" href="http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-allowedContent"> config.allowedContent</a></code>) and many other buttons. </p> </div> <textarea cols="80" id="editor2" name="editor2" rows="10"> &lt;h1&gt;&lt;img alt=&quot;Saturn V carrying Apollo 11&quot; class=&quot;right&quot; src=&quot;assets/sample.jpg&quot;/&gt; Apollo 11&lt;/h1&gt; &lt;p&gt;&lt;b&gt;Apollo 11&lt;/b&gt; was the spaceflight that landed the first humans, Americans &lt;a href=&quot;http://en.wikipedia.org/wiki/Neil_Armstrong&quot; title=&quot;Neil Armstrong&quot;&gt;Neil Armstrong&lt;/a&gt; and &lt;a href=&quot;http://en.wikipedia.org/wiki/Buzz_Aldrin&quot; title=&quot;Buzz Aldrin&quot;&gt;Buzz Aldrin&lt;/a&gt;, on the Moon on July 20, 1969, at 20:18 UTC. Armstrong became the first to step onto the lunar surface 6 hours later on July 21 at 02:56 UTC.&lt;/p&gt; &lt;p&gt;Armstrong spent about &lt;s&gt;three and a half&lt;/s&gt; two and a half hours outside the spacecraft, Aldrin slightly less; and together they collected 47.5 pounds (21.5&amp;nbsp;kg) of lunar material for return to Earth. A third member of the mission, &lt;a href=&quot;http://en.wikipedia.org/wiki/Michael_Collins_(astronaut)&quot; title=&quot;Michael Collins (astronaut)&quot;&gt;Michael Collins&lt;/a&gt;, piloted the &lt;a href=&quot;http://en.wikipedia.org/wiki/Apollo_Command/Service_Module&quot; title=&quot;Apollo Command/Service Module&quot;&gt;command&lt;/a&gt; spacecraft alone in lunar orbit until Armstrong and Aldrin returned to it for the trip back to Earth.&lt;/p&gt; &lt;h2&gt;Broadcasting and &lt;em&gt;quotes&lt;/em&gt; &lt;a id=&quot;quotes&quot; name=&quot;quotes&quot;&gt;&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;Broadcast on live TV to a world-wide audience, Armstrong stepped onto the lunar surface and described the event as:&lt;/p&gt; &lt;blockquote&gt;&lt;p&gt;One small step for [a] man, one giant leap for mankind.&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Apollo 11 effectively ended the &lt;a href=&quot;http://en.wikipedia.org/wiki/Space_Race&quot; title=&quot;Space Race&quot;&gt;Space Race&lt;/a&gt; and fulfilled a national goal proposed in 1961 by the late U.S. President &lt;a href=&quot;http://en.wikipedia.org/wiki/John_F._Kennedy&quot; title=&quot;John F. Kennedy&quot;&gt;John F. Kennedy&lt;/a&gt; in a speech before the United States Congress:&lt;/p&gt; &lt;blockquote&gt;&lt;p&gt;[...] before this decade is out, of landing a man on the Moon and returning him safely to the Earth.&lt;/p&gt;&lt;/blockquote&gt; &lt;h2&gt;Technical details &lt;a id=&quot;tech-details&quot; name=&quot;tech-details&quot;&gt;&lt;/a&gt;&lt;/h2&gt; &lt;table align=&quot;right&quot; border=&quot;1&quot; bordercolor=&quot;#ccc&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse:collapse;margin:10px 0 10px 15px;&quot;&gt; &lt;caption&gt;&lt;strong&gt;Mission crew&lt;/strong&gt;&lt;/caption&gt; &lt;thead&gt; &lt;tr&gt; &lt;th scope=&quot;col&quot;&gt;Position&lt;/th&gt; &lt;th scope=&quot;col&quot;&gt;Astronaut&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;Commander&lt;/td&gt; &lt;td&gt;Neil A. Armstrong&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Command Module Pilot&lt;/td&gt; &lt;td&gt;Michael Collins&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Lunar Module Pilot&lt;/td&gt; &lt;td&gt;Edwin &amp;quot;Buzz&amp;quot; E. Aldrin, Jr.&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;p&gt;Launched by a &lt;strong&gt;Saturn V&lt;/strong&gt; rocket from &lt;a href=&quot;http://en.wikipedia.org/wiki/Kennedy_Space_Center&quot; title=&quot;Kennedy Space Center&quot;&gt;Kennedy Space Center&lt;/a&gt; in Merritt Island, Florida on July 16, Apollo 11 was the fifth manned mission of &lt;a href=&quot;http://en.wikipedia.org/wiki/NASA&quot; title=&quot;NASA&quot;&gt;NASA&lt;/a&gt;&amp;#39;s Apollo program. The Apollo spacecraft had three parts:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;&lt;strong&gt;Command Module&lt;/strong&gt; with a cabin for the three astronauts which was the only part which landed back on Earth&lt;/li&gt; &lt;li&gt;&lt;strong&gt;Service Module&lt;/strong&gt; which supported the Command Module with propulsion, electrical power, oxygen and water&lt;/li&gt; &lt;li&gt;&lt;strong&gt;Lunar Module&lt;/strong&gt; for landing on the Moon.&lt;/li&gt; &lt;/ol&gt; &lt;p&gt;After being sent to the Moon by the Saturn V&amp;#39;s upper stage, the astronauts separated the spacecraft from it and travelled for three days until they entered into lunar orbit. Armstrong and Aldrin then moved into the Lunar Module and landed in the &lt;a href=&quot;http://en.wikipedia.org/wiki/Mare_Tranquillitatis&quot; title=&quot;Mare Tranquillitatis&quot;&gt;Sea of Tranquility&lt;/a&gt;. They stayed a total of about 21 and a half hours on the lunar surface. After lifting off in the upper part of the Lunar Module and rejoining Collins in the Command Module, they returned to Earth and landed in the &lt;a href=&quot;http://en.wikipedia.org/wiki/Pacific_Ocean&quot; title=&quot;Pacific Ocean&quot;&gt;Pacific Ocean&lt;/a&gt; on July 24.&lt;/p&gt; &lt;hr/&gt; &lt;p style=&quot;text-align: right;&quot;&gt;&lt;small&gt;Source: &lt;a href=&quot;http://en.wikipedia.org/wiki/Apollo_11&quot;&gt;Wikipedia.org&lt;/a&gt;&lt;/small&gt;&lt;/p&gt; </textarea> <script> CKEDITOR.replace( 'editor2', { allowedContent: 'h1 h2 h3 p blockquote strong em;' + 'a[!href];' + 'img(left,right)[!src,alt,width,height];' + 'table tr th td caption;' + 'span{!font-family};' + 'span{!color};' + 'span(!marker);' + 'del ins' } ); </script> </div> <br> <div> <label for="editor3"> Editor 3: </label> <div class="description"> <p> This editor is using a custom configuration for <abbr title="Advanced Content Filter">ACF</abbr>. Note that filters can be configured as an object literal as an alternative to a string-based definition. </p> <pre class="samples"> CKEDITOR.replace( 'editor3', { allowedContent: { 'b i ul ol big small': true, 'h1 h2 h3 p blockquote li': { styles: 'text-align' }, a: { attributes: '!href,target' }, img: { attributes: '!src,alt', styles: 'width,height', classes: 'left,right' } } } ); </pre> </div> <textarea cols="80" id="editor3" name="editor3" rows="10"> &lt;h1&gt;&lt;img alt=&quot;Saturn V carrying Apollo 11&quot; class=&quot;right&quot; src=&quot;assets/sample.jpg&quot;/&gt; Apollo 11&lt;/h1&gt; &lt;p&gt;&lt;b&gt;Apollo 11&lt;/b&gt; was the spaceflight that landed the first humans, Americans &lt;a href=&quot;http://en.wikipedia.org/wiki/Neil_Armstrong&quot; title=&quot;Neil Armstrong&quot;&gt;Neil Armstrong&lt;/a&gt; and &lt;a href=&quot;http://en.wikipedia.org/wiki/Buzz_Aldrin&quot; title=&quot;Buzz Aldrin&quot;&gt;Buzz Aldrin&lt;/a&gt;, on the Moon on July 20, 1969, at 20:18 UTC. Armstrong became the first to step onto the lunar surface 6 hours later on July 21 at 02:56 UTC.&lt;/p&gt; &lt;p&gt;Armstrong spent about &lt;s&gt;three and a half&lt;/s&gt; two and a half hours outside the spacecraft, Aldrin slightly less; and together they collected 47.5 pounds (21.5&amp;nbsp;kg) of lunar material for return to Earth. A third member of the mission, &lt;a href=&quot;http://en.wikipedia.org/wiki/Michael_Collins_(astronaut)&quot; title=&quot;Michael Collins (astronaut)&quot;&gt;Michael Collins&lt;/a&gt;, piloted the &lt;a href=&quot;http://en.wikipedia.org/wiki/Apollo_Command/Service_Module&quot; title=&quot;Apollo Command/Service Module&quot;&gt;command&lt;/a&gt; spacecraft alone in lunar orbit until Armstrong and Aldrin returned to it for the trip back to Earth.&lt;/p&gt; &lt;h2&gt;Broadcasting and &lt;em&gt;quotes&lt;/em&gt; &lt;a id=&quot;quotes&quot; name=&quot;quotes&quot;&gt;&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;Broadcast on live TV to a world-wide audience, Armstrong stepped onto the lunar surface and described the event as:&lt;/p&gt; &lt;blockquote&gt;&lt;p&gt;One small step for [a] man, one giant leap for mankind.&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Apollo 11 effectively ended the &lt;a href=&quot;http://en.wikipedia.org/wiki/Space_Race&quot; title=&quot;Space Race&quot;&gt;Space Race&lt;/a&gt; and fulfilled a national goal proposed in 1961 by the late U.S. President &lt;a href=&quot;http://en.wikipedia.org/wiki/John_F._Kennedy&quot; title=&quot;John F. Kennedy&quot;&gt;John F. Kennedy&lt;/a&gt; in a speech before the United States Congress:&lt;/p&gt; &lt;blockquote&gt;&lt;p&gt;[...] before this decade is out, of landing a man on the Moon and returning him safely to the Earth.&lt;/p&gt;&lt;/blockquote&gt; &lt;h2&gt;Technical details &lt;a id=&quot;tech-details&quot; name=&quot;tech-details&quot;&gt;&lt;/a&gt;&lt;/h2&gt; &lt;table align=&quot;right&quot; border=&quot;1&quot; bordercolor=&quot;#ccc&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse:collapse;margin:10px 0 10px 15px;&quot;&gt; &lt;caption&gt;&lt;strong&gt;Mission crew&lt;/strong&gt;&lt;/caption&gt; &lt;thead&gt; &lt;tr&gt; &lt;th scope=&quot;col&quot;&gt;Position&lt;/th&gt; &lt;th scope=&quot;col&quot;&gt;Astronaut&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;Commander&lt;/td&gt; &lt;td&gt;Neil A. Armstrong&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Command Module Pilot&lt;/td&gt; &lt;td&gt;Michael Collins&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Lunar Module Pilot&lt;/td&gt; &lt;td&gt;Edwin &amp;quot;Buzz&amp;quot; E. Aldrin, Jr.&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;p&gt;Launched by a &lt;strong&gt;Saturn V&lt;/strong&gt; rocket from &lt;a href=&quot;http://en.wikipedia.org/wiki/Kennedy_Space_Center&quot; title=&quot;Kennedy Space Center&quot;&gt;Kennedy Space Center&lt;/a&gt; in Merritt Island, Florida on July 16, Apollo 11 was the fifth manned mission of &lt;a href=&quot;http://en.wikipedia.org/wiki/NASA&quot; title=&quot;NASA&quot;&gt;NASA&lt;/a&gt;&amp;#39;s Apollo program. The Apollo spacecraft had three parts:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;&lt;strong&gt;Command Module&lt;/strong&gt; with a cabin for the three astronauts which was the only part which landed back on Earth&lt;/li&gt; &lt;li&gt;&lt;strong&gt;Service Module&lt;/strong&gt; which supported the Command Module with propulsion, electrical power, oxygen and water&lt;/li&gt; &lt;li&gt;&lt;strong&gt;Lunar Module&lt;/strong&gt; for landing on the Moon.&lt;/li&gt; &lt;/ol&gt; &lt;p&gt;After being sent to the Moon by the Saturn V&amp;#39;s upper stage, the astronauts separated the spacecraft from it and travelled for three days until they entered into lunar orbit. Armstrong and Aldrin then moved into the Lunar Module and landed in the &lt;a href=&quot;http://en.wikipedia.org/wiki/Mare_Tranquillitatis&quot; title=&quot;Mare Tranquillitatis&quot;&gt;Sea of Tranquility&lt;/a&gt;. They stayed a total of about 21 and a half hours on the lunar surface. After lifting off in the upper part of the Lunar Module and rejoining Collins in the Command Module, they returned to Earth and landed in the &lt;a href=&quot;http://en.wikipedia.org/wiki/Pacific_Ocean&quot; title=&quot;Pacific Ocean&quot;&gt;Pacific Ocean&lt;/a&gt; on July 24.&lt;/p&gt; &lt;hr/&gt; &lt;p style=&quot;text-align: right;&quot;&gt;&lt;small&gt;Source: &lt;a href=&quot;http://en.wikipedia.org/wiki/Apollo_11&quot;&gt;Wikipedia.org&lt;/a&gt;&lt;/small&gt;&lt;/p&gt; </textarea> <script> CKEDITOR.replace( 'editor3', { allowedContent: { 'b i ul ol big small': true, 'h1 h2 h3 p blockquote li': { styles: 'text-align' }, a: { attributes: '!href,target' }, img: { attributes: '!src,alt', styles: 'width,height', classes: 'left,right' } } } ); </script> </div> <br> <div> <label for="editor4"> Editor 4: </label> <div class="description"> <p> This editor is using a custom set of plugins and buttons. </p> <pre class="samples"> CKEDITOR.replace( 'editor4', { removePlugins: 'bidi,font,forms,flash,horizontalrule,iframe,justify,table,tabletools,smiley', removeButtons: 'Anchor,Underline,Strike,Subscript,Superscript,Image', format_tags: 'p;h1;h2;h3;pre;address' } ); </pre> <p> As you can see, removing plugins and buttons implies filtering. Several tags are not allowed in the editor because there's no plugin/button that is responsible for creating and editing this kind of content (for example: the image is missing because of <code>removeButtons: 'Image'</code>). The conclusion is that <abbr title="Advanced Content Filter">ACF</abbr> works "backwards" as well: <strong>modifying <abbr title="User Interface">UI</abbr> elements is changing allowed content rules</strong>. </p> </div> <textarea cols="80" id="editor4" name="editor4" rows="10"> &lt;h1&gt;&lt;img alt=&quot;Saturn V carrying Apollo 11&quot; class=&quot;right&quot; src=&quot;assets/sample.jpg&quot;/&gt; Apollo 11&lt;/h1&gt; &lt;p&gt;&lt;b&gt;Apollo 11&lt;/b&gt; was the spaceflight that landed the first humans, Americans &lt;a href=&quot;http://en.wikipedia.org/wiki/Neil_Armstrong&quot; title=&quot;Neil Armstrong&quot;&gt;Neil Armstrong&lt;/a&gt; and &lt;a href=&quot;http://en.wikipedia.org/wiki/Buzz_Aldrin&quot; title=&quot;Buzz Aldrin&quot;&gt;Buzz Aldrin&lt;/a&gt;, on the Moon on July 20, 1969, at 20:18 UTC. Armstrong became the first to step onto the lunar surface 6 hours later on July 21 at 02:56 UTC.&lt;/p&gt; &lt;p&gt;Armstrong spent about &lt;s&gt;three and a half&lt;/s&gt; two and a half hours outside the spacecraft, Aldrin slightly less; and together they collected 47.5 pounds (21.5&amp;nbsp;kg) of lunar material for return to Earth. A third member of the mission, &lt;a href=&quot;http://en.wikipedia.org/wiki/Michael_Collins_(astronaut)&quot; title=&quot;Michael Collins (astronaut)&quot;&gt;Michael Collins&lt;/a&gt;, piloted the &lt;a href=&quot;http://en.wikipedia.org/wiki/Apollo_Command/Service_Module&quot; title=&quot;Apollo Command/Service Module&quot;&gt;command&lt;/a&gt; spacecraft alone in lunar orbit until Armstrong and Aldrin returned to it for the trip back to Earth.&lt;/p&gt; &lt;h2&gt;Broadcasting and &lt;em&gt;quotes&lt;/em&gt; &lt;a id=&quot;quotes&quot; name=&quot;quotes&quot;&gt;&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;Broadcast on live TV to a world-wide audience, Armstrong stepped onto the lunar surface and described the event as:&lt;/p&gt; &lt;blockquote&gt;&lt;p&gt;One small step for [a] man, one giant leap for mankind.&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Apollo 11 effectively ended the &lt;a href=&quot;http://en.wikipedia.org/wiki/Space_Race&quot; title=&quot;Space Race&quot;&gt;Space Race&lt;/a&gt; and fulfilled a national goal proposed in 1961 by the late U.S. President &lt;a href=&quot;http://en.wikipedia.org/wiki/John_F._Kennedy&quot; title=&quot;John F. Kennedy&quot;&gt;John F. Kennedy&lt;/a&gt; in a speech before the United States Congress:&lt;/p&gt; &lt;blockquote&gt;&lt;p&gt;[...] before this decade is out, of landing a man on the Moon and returning him safely to the Earth.&lt;/p&gt;&lt;/blockquote&gt; &lt;h2&gt;Technical details &lt;a id=&quot;tech-details&quot; name=&quot;tech-details&quot;&gt;&lt;/a&gt;&lt;/h2&gt; &lt;table align=&quot;right&quot; border=&quot;1&quot; bordercolor=&quot;#ccc&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse:collapse;margin:10px 0 10px 15px;&quot;&gt; &lt;caption&gt;&lt;strong&gt;Mission crew&lt;/strong&gt;&lt;/caption&gt; &lt;thead&gt; &lt;tr&gt; &lt;th scope=&quot;col&quot;&gt;Position&lt;/th&gt; &lt;th scope=&quot;col&quot;&gt;Astronaut&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;Commander&lt;/td&gt; &lt;td&gt;Neil A. Armstrong&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Command Module Pilot&lt;/td&gt; &lt;td&gt;Michael Collins&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Lunar Module Pilot&lt;/td&gt; &lt;td&gt;Edwin &amp;quot;Buzz&amp;quot; E. Aldrin, Jr.&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;p&gt;Launched by a &lt;strong&gt;Saturn V&lt;/strong&gt; rocket from &lt;a href=&quot;http://en.wikipedia.org/wiki/Kennedy_Space_Center&quot; title=&quot;Kennedy Space Center&quot;&gt;Kennedy Space Center&lt;/a&gt; in Merritt Island, Florida on July 16, Apollo 11 was the fifth manned mission of &lt;a href=&quot;http://en.wikipedia.org/wiki/NASA&quot; title=&quot;NASA&quot;&gt;NASA&lt;/a&gt;&amp;#39;s Apollo program. The Apollo spacecraft had three parts:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;&lt;strong&gt;Command Module&lt;/strong&gt; with a cabin for the three astronauts which was the only part which landed back on Earth&lt;/li&gt; &lt;li&gt;&lt;strong&gt;Service Module&lt;/strong&gt; which supported the Command Module with propulsion, electrical power, oxygen and water&lt;/li&gt; &lt;li&gt;&lt;strong&gt;Lunar Module&lt;/strong&gt; for landing on the Moon.&lt;/li&gt; &lt;/ol&gt; &lt;p&gt;After being sent to the Moon by the Saturn V&amp;#39;s upper stage, the astronauts separated the spacecraft from it and travelled for three days until they entered into lunar orbit. Armstrong and Aldrin then moved into the Lunar Module and landed in the &lt;a href=&quot;http://en.wikipedia.org/wiki/Mare_Tranquillitatis&quot; title=&quot;Mare Tranquillitatis&quot;&gt;Sea of Tranquility&lt;/a&gt;. They stayed a total of about 21 and a half hours on the lunar surface. After lifting off in the upper part of the Lunar Module and rejoining Collins in the Command Module, they returned to Earth and landed in the &lt;a href=&quot;http://en.wikipedia.org/wiki/Pacific_Ocean&quot; title=&quot;Pacific Ocean&quot;&gt;Pacific Ocean&lt;/a&gt; on July 24.&lt;/p&gt; &lt;hr/&gt; &lt;p style=&quot;text-align: right;&quot;&gt;&lt;small&gt;Source: &lt;a href=&quot;http://en.wikipedia.org/wiki/Apollo_11&quot;&gt;Wikipedia.org&lt;/a&gt;&lt;/small&gt;&lt;/p&gt; </textarea> <script> CKEDITOR.replace( 'editor4', { removePlugins: 'bidi,div,font,forms,flash,horizontalrule,iframe,justify,table,tabletools,smiley', removeButtons: 'Anchor,Underline,Strike,Subscript,Superscript,Image', format_tags: 'p;h1;h2;h3;pre;address' } ); </script> </div> <br> <div> <label for="editor5"> Editor 5: </label> <div class="description"> <p> This editor is built on editable <code>&lt;h1&gt;</code> element. <abbr title="Advanced Content Filter">ACF</abbr> takes care of what can be included in <code>&lt;h1&gt;</code>. Note that there are no block styles in Styles combo. Also why lists, indentation, blockquote, div, form and other buttons are missing. </p> <p> <abbr title="Advanced Content Filter">ACF</abbr> makes sure that no disallowed tags will come to <code>&lt;h1&gt;</code> so the final markup is valid. If the user tried to paste some invalid HTML into this editor (let's say a list), it would be automatically converted into plain text. </p> </div> <h1 id="editor5" contenteditable="true"> <em>Apollo 11</em> was the spaceflight that landed the first humans, Americans <a href="http://en.wikipedia.org/wiki/Neil_Armstrong" title="Neil Armstrong">Neil Armstrong</a> and <a href="http://en.wikipedia.org/wiki/Buzz_Aldrin" title="Buzz Aldrin">Buzz Aldrin</a>, on the Moon on July 20, 1969, at 20:18 UTC. </h1> </div> <div id="footer"> <hr> <p> CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a> </p> <p id="copy"> Copyright &copy; 2003-2014, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico Knabben. All rights reserved. </p> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/shared/plugin/ckeditor/samples/datafiltering.html
HTML
gpl3
34,725
<!DOCTYPE html> <!-- Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.md or http://ckeditor.com/license --> <html> <head> <meta charset="utf-8"> <title>TAB Key-Based Navigation &mdash; CKEditor Sample</title> <script src="../ckeditor.js"></script> <link href="sample.css" rel="stylesheet"> <style> .cke_focused, .cke_editable.cke_focused { outline: 3px dotted blue !important; *border: 3px dotted blue !important; /* For IE7 */ } </style> <script> CKEDITOR.on( 'instanceReady', function( evt ) { var editor = evt.editor; editor.setData( 'This editor has it\'s tabIndex set to <strong>' + editor.tabIndex + '</strong>' ); // Apply focus class name. editor.on( 'focus', function() { editor.container.addClass( 'cke_focused' ); }); editor.on( 'blur', function() { editor.container.removeClass( 'cke_focused' ); }); // Put startup focus on the first editor in tab order. if ( editor.tabIndex == 1 ) editor.focus(); }); </script> </head> <body> <h1 class="samples"> <a href="index.html">CKEditor Samples</a> &raquo; TAB Key-Based Navigation </h1> <div class="description"> <p> This sample shows how tab key navigation among editor instances is affected by the <code>tabIndex</code> attribute from the original page element. Use TAB key to move between the editors. </p> </div> <p> <textarea class="ckeditor" cols="80" id="editor4" rows="10" tabindex="1"></textarea> </p> <div class="ckeditor" contenteditable="true" id="editor1" tabindex="4"></div> <p> <textarea class="ckeditor" cols="80" id="editor2" rows="10" tabindex="2"></textarea> </p> <p> <textarea class="ckeditor" cols="80" id="editor3" rows="10" tabindex="3"></textarea> </p> <div id="footer"> <hr> <p> CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a> </p> <p id="copy"> Copyright &copy; 2003-2014, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico Knabben. All rights reserved. </p> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/shared/plugin/ckeditor/samples/tabindex.html
HTML
gpl3
2,206
<!DOCTYPE html> <?php /* Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.md or http://ckeditor.com/license */ ?> <html> <head> <meta charset="utf-8"> <title>Sample &mdash; CKEditor</title> <link rel="stylesheet" href="sample.css"> </head> <body> <h1 class="samples"> CKEditor &mdash; Posted Data </h1> <table border="1" cellspacing="0" id="outputSample"> <colgroup><col width="120"></colgroup> <thead> <tr> <th>Field&nbsp;Name</th> <th>Value</th> </tr> </thead> <?php if (!empty($_POST)) { foreach ( $_POST as $key => $value ) { if ( ( !is_string($value) && !is_numeric($value) ) || !is_string($key) ) continue; if ( get_magic_quotes_gpc() ) $value = htmlspecialchars( stripslashes((string)$value) ); else $value = htmlspecialchars( (string)$value ); ?> <tr> <th style="vertical-align: top"><?php echo htmlspecialchars( (string)$key ); ?></th> <td><pre class="samples"><?php echo $value; ?></pre></td> </tr> <?php } } ?> </table> <div id="footer"> <hr> <p> CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a> </p> <p id="copy"> Copyright &copy; 2003-2014, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico Knabben. All rights reserved. </p> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/shared/plugin/ckeditor/samples/assets/posteddata.php
PHP
gpl3
1,443
/** * Required by tests (dom/document.html). */
04-huanluyenviencanhan
trunk/master/shared/plugin/ckeditor/samples/assets/sample.css
CSS
gpl3
53
/* * Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md or http://ckeditor.com/license * * Styles used by the XHTML 1.1 sample page (xhtml.html). */ /** * Basic definitions for the editing area. */ body { font-family: Arial, Verdana, sans-serif; font-size: 80%; color: #000000; background-color: #ffffff; padding: 5px; margin: 0px; } /** * Core styles. */ .Bold { font-weight: bold; } .Italic { font-style: italic; } .Underline { text-decoration: underline; } .StrikeThrough { text-decoration: line-through; } .Subscript { vertical-align: sub; font-size: smaller; } .Superscript { vertical-align: super; font-size: smaller; } /** * Font faces. */ .FontComic { font-family: 'Comic Sans MS'; } .FontCourier { font-family: 'Courier New'; } .FontTimes { font-family: 'Times New Roman'; } /** * Font sizes. */ .FontSmaller { font-size: smaller; } .FontLarger { font-size: larger; } .FontSmall { font-size: 8pt; } .FontBig { font-size: 14pt; } .FontDouble { font-size: 200%; } /** * Font colors. */ .FontColor1 { color: #ff9900; } .FontColor2 { color: #0066cc; } .FontColor3 { color: #ff0000; } .FontColor1BG { background-color: #ff9900; } .FontColor2BG { background-color: #0066cc; } .FontColor3BG { background-color: #ff0000; } /** * Indentation. */ .Indent1 { margin-left: 40px; } .Indent2 { margin-left: 80px; } .Indent3 { margin-left: 120px; } /** * Alignment. */ .JustifyLeft { text-align: left; } .JustifyRight { text-align: right; } .JustifyCenter { text-align: center; } .JustifyFull { text-align: justify; } /** * Other. */ code { font-family: courier, monospace; background-color: #eeeeee; padding-left: 1px; padding-right: 1px; border: #c0c0c0 1px solid; } kbd { padding: 0px 1px 0px 1px; border-width: 1px 2px 2px 1px; border-style: solid; } blockquote { color: #808080; }
04-huanluyenviencanhan
trunk/master/shared/plugin/ckeditor/samples/assets/outputxhtml/outputxhtml.css
CSS
gpl3
2,143
<!DOCTYPE html> <!-- Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.md or http://ckeditor.com/license --> <html> <head> <meta charset="utf-8"> <title>Using the CKEditor Read-Only API &mdash; CKEditor Sample</title> <script src="../ckeditor.js"></script> <link rel="stylesheet" href="sample.css"> <script> var editor; // The instanceReady event is fired, when an instance of CKEditor has finished // its initialization. CKEDITOR.on( 'instanceReady', function( ev ) { editor = ev.editor; // Show this "on" button. document.getElementById( 'readOnlyOn' ).style.display = ''; // Event fired when the readOnly property changes. editor.on( 'readOnly', function() { document.getElementById( 'readOnlyOn' ).style.display = this.readOnly ? 'none' : ''; document.getElementById( 'readOnlyOff' ).style.display = this.readOnly ? '' : 'none'; }); }); function toggleReadOnly( isReadOnly ) { // Change the read-only state of the editor. // http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-setReadOnly editor.setReadOnly( isReadOnly ); } </script> </head> <body> <h1 class="samples"> <a href="index.html">CKEditor Samples</a> &raquo; Using the CKEditor Read-Only API </h1> <div class="description"> <p> This sample shows how to use the <code><a class="samples" href="http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-setReadOnly">setReadOnly</a></code> API to put editor into the read-only state that makes it impossible for users to change the editor contents. </p> <p> For details on how to create this setup check the source code of this sample page. </p> </div> <form action="sample_posteddata.php" method="post"> <p> <textarea class="ckeditor" id="editor1" name="editor1" cols="100" rows="10">&lt;p&gt;This is some &lt;strong&gt;sample text&lt;/strong&gt;. You are using &lt;a href="http://ckeditor.com/"&gt;CKEditor&lt;/a&gt;.&lt;/p&gt;</textarea> </p> <p> <input id="readOnlyOn" onclick="toggleReadOnly();" type="button" value="Make it read-only" style="display:none"> <input id="readOnlyOff" onclick="toggleReadOnly( false );" type="button" value="Make it editable again" style="display:none"> </p> </form> <div id="footer"> <hr> <p> CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a> </p> <p id="copy"> Copyright &copy; 2003-2014, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico Knabben. All rights reserved. </p> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/shared/plugin/ckeditor/samples/readonly.html
HTML
gpl3
2,688
<?php //require section require_once dirname(dirname(__FILE__)) . '/shared/config/config.php'; require_once DOCUMENT_ROOT . DIR_INCLUDE . '/check_user_login.php'; require_once DOCUMENT_ROOT . DIR_SHARED_API . '/api_contact.php'; $title = 'Admin Panel'; ?> <!DOCTYPE html> <html> <head> <?php require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'head.php'; ?> </head> <body> <div class="uk-container uk-container-center uk-margin-top"> <?php require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'menu.php'; $contact = api_contact::get_contact(); $email = $contact['email']; $phone = $contact['phone']; if (!empty($_POST)) { if (!empty($_POST['txt_email'])) { $email = $_POST['txt_email']; } if (!empty($_POST['txt_phone'])) { $phone = $_POST['txt_phone']; } $error_show = api_contact::validate_contact($email, $phone); if (empty($error_show)) { if (api_contact::set_contact($email, $phone)) { $success_info = "Đã lưu thành công."; } } } ?> <section class="ts-body-container uk-panel uk-panel-box ts-padding-large"> <h2><strong>Thông Tin Liên Lạc</strong></h2> <?php if (!empty($error_show)) {?> <div class="error">Lỗi: <?php echo $error_show; ?></div> <?php } else if (!empty($success_info)) {?> <div class="success"><?php echo $success_info; ?></div> <?php }?> <form action="?" method="POST" name="form_save"> <table class="ts-table"> <tr> <th><label for="txt_email">Email:<span class="ts-alert">*</span></label></th> <td><input name="txt_email" class="uk-form-width-large" value="<?php echo $email; ?>" type="text" placeholder="Email" required></td> </tr> <tr> <th><label for="txt_phone">Số điện thoại liên lạc:<span class="ts-alert">*</span></label></th> <td><input name="txt_phone" class="uk-form-width-large" value="<?php echo $phone; ?>" type="text" placeholder="Số điện thoại" required></td> </tr> <tr> <th></th> <td><input type="submit" name="btn_submit" value="Lưu" class="uk-button uk-button-large uk-button-primary"></td> </tr> </table> </form> </section> <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'footer.php'; ?> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/admin/contact.php
PHP
gpl3
3,095
<?php //require section require_once dirname(dirname(__FILE__)) . '/shared/config/config.php'; require_once DOCUMENT_ROOT . DIR_INCLUDE . '/check_user_login.php'; require_once DOCUMENT_ROOT . DIR_SHARED_API . '/api_document.php'; require_once DOCUMENT_ROOT . DIR_SHARED_API . '/api_invoice.php'; require_once DOCUMENT_ROOT . DIR_SHARED_LIBRARIES . '/lib_pager.php'; require_once DOCUMENT_ROOT . DIR_SHARED_LIBRARIES . '/lib_upload.php'; $title = 'Admin Panel'; $id = 0; $email = ""; $first_name = ""; $last_name = ""; $address = ""; $phone = ""; $file = ""; $action = "Add"; $action_show = "Thêm"; if (!empty($_POST)) { if (!empty($_POST['Action']) && $_POST['Action'] === "Process") { echo "Dsgsgsd"; $id_process = 0; if (!empty($_POST['process_id'])) { $id_process = $_POST['process_id']; } api_invoice::process_invoice($id_process); $success_info = "Đã xử lý đơn hàng " . $id_process . " thành công"; } else if (!empty($_POST['Action']) && $_POST['Action'] === "Delete") { $id_delete = 0; if (!empty($_POST['delete_id'])) { $id_delete = $_POST['delete_id']; } api_invoice::delete_invoice($id_delete); $success_info = "Xóa đơn hàng thành công"; } } ?> <!DOCTYPE html> <html> <head> <?php require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'head.php'; ?> </head> <body> <div class="uk-container uk-container-center uk-margin-top"> <?php require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'menu.php'; ?> <section class="ts-body-container uk-panel uk-panel-box ts-padding-large"> <?php if (!empty($success_info)) { ?> <div class="success"><?php echo $success_info; ?></div> <?php }?> <hr/> <h2><strong>Chi tiết đơn hàng</strong></h2> <form action="?" method="POST" id="form_delete"> <input type="hidden" name="delete_id" value="0"/> <input type="hidden" name="Action" value="Delete"/> </form> <form action="?" method="POST" id="form_process"> <input type="hidden" name="process_id" value="0"/> <input type="hidden" name="Action" value="Process"/> </form> <table class="uk-table uk-table-hover uk-table-striped uk-table-condensed"> <thead> </thead> <tbody> <?php $invoice_id = 0; if (!empty($_GET['invoice_id'])) { $invoice_id = $_GET['invoice_id']; } $invoice_info = api_invoice::get_invoice_by_id($invoice_id); ?> <tr> <td><strong>Mã đơn </strong></td> <td><?php echo $invoice_info['invoice_id']; ?></td> </tr> <tr> <td><strong>Ngày tạo</strong></td> <?php $date = date_create($invoice_info["created_date"]); $date_str = date_format($date, "d/m/Y"); ?> <td><?php echo $date_str; ?></td> </tr> <tr> <td><strong>Trạng thái</strong></td> <td><?php echo $invoice_info['status_name']; ?></td> </tr> <tr> <td><strong>Tổng số lượng</strong></td> <td><?php echo $invoice_info['total_quantity']; ?></td> </tr> <tr> <td><strong>Tổng tiền</strong></td> <td><?php echo number_format($invoice_info['total_money'], 0, '.', ',') . " vnđ"; ?></td> </tr> <tr> <td><strong>Tên khách hàng</strong></td> <td><?php echo $invoice_info['customer_name']; ?></td> </tr> <tr> <td><strong>Email</strong></td> <td><?php echo $invoice_info['customer_email']; ?></td> </tr> <tr> <td><strong>Số điện thoại</strong></td> <td><?php echo $invoice_info['customer_phone']; ?></td> </tr> </tbody> </table> <h3><strong>Các món hàng</strong></h3> <table class="uk-table uk-table-hover uk-table-striped uk-table-condensed"> <thead> <tr> <th>STT</th> <th>Mã bài tập</th> <th>Tên bài tập</th> <th>Giá</th> <th>Số Lượng</th> </tr> </thead> <tbody> <?php $current_page = 1; $page_size = 10; if (!empty($_GET['p'])) { $current_page = $_GET['p']; } $list_total = api_invoice::get_all_lines_by_invoice_id($invoice_id); $lib_pager = new lib_pager(); $total_page = $lib_pager->get_total_page($list_total, $page_size); $current_page_list = $lib_pager->get_current_page_list($page_size, $current_page, $list_total); $count = 0; if (empty($current_page_list) || count($current_page_list) == 0) { echo "<tr><td>chưa có món hàng nào</td></td>"; } else { foreach ($current_page_list as $i => $item) { ?> <tr> <td><?php echo $i + 1; ?></td> <td><?php echo $item['doc_id'] ?></td> <td><?php echo $item['doc_name'] ?></td> <td><?php echo number_format($item['money'], 0, '.', ',') ?></td> <td><?php echo $item['quantity'] ?></td> </tr> <?php } } ?> <tr align="right" style="color:Black;background-color:#F7F7DE;"> <td colspan="8"> <table> <tbody> <tr align="right" style="color:Black;background-color:#F7F7DE;"> <td colspan="7"> <table> <tbody> <tr> <?php for ($a = 1; $a <= $total_page; $a++) { ?> <td> <span> <a href="?p=<?php echo $a; ?>" <?php if ($current_page != $a) echo 'style="color:Black;"'; ?>><?php echo $a; ?></a> </span> </td> <?php } ?> </tr> </tbody> </table> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </section> <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'footer.php'; ?> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/admin/invoice_detail.php
PHP
gpl3
7,601
<?php //require section require_once dirname(dirname(__FILE__)) . '/shared/config/config.php'; require_once DOCUMENT_ROOT . DIR_INCLUDE . '/check_user_login.php'; require_once DOCUMENT_ROOT . DIR_SHARED_API . '/api_news.php'; require_once DOCUMENT_ROOT . DIR_SHARED_LIBRARIES . '/lib_pager.php'; require_once DOCUMENT_ROOT . DIR_SHARED_LIBRARIES . '/lib_upload.php'; require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'ckeditor.php'; $title = 'Admin Panel'; $id = 0; $title = ""; $content = ""; $cat_news_id = ""; $image = ""; $action = "Add"; $action_show = "Thêm"; if (!empty($_GET['Action']) && $_GET['Action'] === 'Edit') { if (!empty($_GET['Id'])) { $id = $_GET['Id']; } $edit_item = api_news::get_news_by_id($id); $id = $edit_item['news_id']; $title = $edit_item['news_title']; $content = $edit_item['news_content']; $cat_news_id = $edit_item['cat_news_id']; $image = $edit_item['news_img_url']; $action = "Update"; $action_show = "Sửa"; } else if (!empty($_POST)) { $id_save = ""; if (!empty($_POST['id'])) { $id_save = $_POST['id']; } $title_save = ""; if (!empty($_POST['txt_title'])) { $title_save = $_POST['txt_title']; } $content_save = ""; if (!empty($_POST['txt_content'])) { $content_save = $_POST['txt_content']; } $address = ""; if (!empty($_POST['ddl_cat_id'])) { $address = $_POST['ddl_cat_id']; } $image_save = ""; if (!empty($_FILES['f_image']['size'])) { $lib_upload = new lib_upload(); if ($lib_upload->upload_file('f_image', DOCUMENT_ROOT . DIR_SHARED_UPLOAD_IMAGES_NEWS)) { $image_save = $_FILES['f_image']['name']; } } else if (!empty($_POST['hidd_image'])) { $image_save = $_POST['hidd_image']; } if (!empty($_POST['Action']) && ($_POST['Action'] === "Add" || $_POST['Action'] === "Update")) { $error_show = api_news::validate_news_fields($title_save, $content_save, $address, $image_save); if (empty($error_show)) { if (api_news::save_news($id_save, $title_save, $content_save, $address, $image_save)) { $success_info = "Thêm tin tức &lt;".$title_save."&gt; thành công."; if ($id_save > 0) { $success_info = "Sửa tin tức &lt;".$title_save."&gt; thành công."; } } } else { $id = $id_save; $title = $title_save; $content = $content_save; $cat_news_id = $address; $image = $image_save; $action = $_POST['Action']; $action_show = "Sửa"; if ($action === "Add") { $action_show = "Thêm"; } } } else if (!empty($_POST['Action']) && $_POST['Action'] === "Delete") { $id_delete = 0; if (!empty($_POST['delete_id'])) { $id_delete = $_POST['delete_id']; } api_news::delete_news($id_delete); $success_info = "Xóa tin tức thành công."; } } ?> <!DOCTYPE html> <html> <head> <?php require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'head.php'; ?> </head> <body> <div class="uk-container uk-container-center uk-margin-top"> <?php require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'menu.php'; ?> <section class="ts-body-container uk-panel uk-panel-box ts-padding-large"> <?php if (!empty($error_show)) {?> <div class="error">Lỗi: <?php echo $error_show; ?></div> <?php } else if (!empty($success_info)) {?> <div class="success"><?php echo $success_info; ?></div> <?php }?> <form action="?" method="POST" id="form_delete" > <input type="hidden" name="delete_id" value="0" /> <input type="hidden" name="Action" value="Delete" /> </form> <form name="form_data" id="form_data" method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" enctype="multipart/form-data" class="uk-form uk-width-medium-1-1"> <fieldset> <legend>Tin Tức</legend> <div class="ui form segment form-background"> <input type="hidden" name="id" value="<?php echo $id; ?>" /> <div class="uk-form-row"> <label for="Title">Tiêu đề <span class="required">*</span></label> <input id="Title" name="txt_title" value="<?php echo $title ?>" placeholder="" type="text"> </div> <div class="uk-form-row"> <label for="Description">Loại tin tức</label> <select name="ddl_cat_id"> <?php $list = api_news::get_all_news_categories(); foreach ($list as $i => $item) { ?> <option value="<?php echo $item['cat_news_id'] ?>" <?php if (!empty($edit_article_old)) { if ($item['cat_news_id'] == $cat_news_id) { echo 'selected'; } } ?> > <?php echo $item['cate_news_name'] ?> </option> <?php } ?> </select> </div> <div class="uk-form-row"> <label for="Poster">Hình ảnh minh họa <span class="required">*</span></label> <input type="file" name="f_image"/> <?php if (!empty($image)) { ?> <input type="hidden" name="hidd_image" value="<?php echo $image ?>"/> <img src="<?php echo LINK_ROOT . DIR_SHARED_UPLOAD_IMAGES_NEWS . $image; ?>" style="max-height: 100px;"> <?php } ?> </div> <div class="uk-form-row"> <label for="Description">Nội dung <span class="required">*</span></label> <textarea id="Description" class="ckeditor" name="txt_content" placeholder="Detail" class="form-control" rows="3"><?php echo $content; ?></textarea> </div> <div class="uk-form-row"> <input type="hidden" name="Action" value="<?php echo $action; ?>"> <button class="uk-button uk-button-primary" id="action-button" onclick="submit_data();"><?php echo $action_show; ?></button> <a href="?">Hủy</a> </div> </div> </fieldset> </form> <hr/> <h3><strong>Danh sách</strong></h3> <table class="uk-table uk-table-hover uk-table-striped uk-table-condensed"> <thead> <tr> <th>Tiêu đề</th> <th>Loại tin tức</th> <th>Nội dung</th> <th>Thao tác</th> </tr> </thead> <tbody> <?php $current_page = 1; $page_size = 10; if (!empty($_GET['p'])) { $current_page = $_GET['p']; } $list_total = api_news::get_all_news(); $lib_pager = new lib_pager(); $total_page = $lib_pager->get_total_page($list_total, $page_size); $current_page_list = $lib_pager->get_current_page_list($page_size, $current_page, $list_total); $count = 0; if (empty($current_page_list) || count($current_page_list) == 0) { echo "<tr><td>Chưa có dữ liệu</td></tr>"; } else { foreach ($current_page_list as $i => $item) {?> <tr> <td><?php echo $item['news_title']; ?></td> <td><?php echo $item['news_cat_name']; ?></td> <td><?php echo substr(strip_tags($item['news_content']), 0, 100); ?></td> <td> <a href="?Action=Edit&Id=<?php echo $item['news_id']; ?>"> <i class="uk-icon-edit"></i> </a> <i class="uk-icon-eraser" onclick="confirmDelete('<?php echo $item['news_id']; ?>')"></i> </td> </tr> <?php } } ?> <tr align="right" style="color:Black;background-color:#F7F7DE;"> <td colspan="7"> <table> <tbody> <tr align="right" style="color:Black;background-color:#F7F7DE;"> <td colspan="7"> <table> <tbody> <tr> <?php for ($a = 1; $a <= $total_page; $a++) { ?> <td> <span> <a href="?p=<?php echo $a; ?>" <?php if ($current_page != $a) echo 'style="color:Black;"'; ?>><?php echo $a; ?></a> </span> </td> <?php } ?> </tr> </tbody> </table> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </section> <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'footer.php'; ?> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/admin/news.php
PHP
gpl3
12,779
<?php //require section require_once dirname(dirname(__FILE__)) . '/shared/config/config.php'; require_once DOCUMENT_ROOT . DIR_INCLUDE . '/check_user_login.php'; $title = 'Admin Panel'; ?> <!DOCTYPE html> <html> <head> <?php require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'head.php'; ?> </head> <body> <div class="uk-container uk-container-center uk-margin-top"> <?php require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'menu.php'; ?> <section class="ts-body-container uk-panel uk-panel-box ts-padding-large"> <h2>Chào bạn, Bạn đang vào phần quản lý của Admin.</h2> </section> <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'footer.php'; ?> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/admin/index.php
PHP
gpl3
892
<?php //require section require_once dirname(dirname(__FILE__)) . '/shared/config/config.php'; require_once DOCUMENT_ROOT . DIR_INCLUDE . '/check_user_login.php'; require_once DOCUMENT_ROOT . DIR_SHARED_API . '/api_about_us.php'; require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'ckeditor.php'; $title = 'Admin Panel'; ?> <!DOCTYPE html> <html> <head> <?php require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'head.php'; ?> </head> <body> <div class="uk-container uk-container-center uk-margin-top"> <?php require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'menu.php'; $about_us = api_about_us::get_about_us(); $title = $about_us['title']; $content = $about_us['content']; if (!empty($_POST)) { if (!empty($_POST['txt_title'])) { $title = $_POST['txt_title']; } if (!empty($_POST['txt_content'])) { $content = $_POST['txt_content']; } if (api_about_us::set_about_us($title, $content)) { $success_info = "Đã lưu thành công."; } } ?> <section class="ts-body-container uk-panel uk-panel-box ts-padding-large"> <h2><strong>Thông Tin Trang Giới Thiệu</strong></h2> <?php if (!empty($error_show)) {?> <div class="error">Lỗi: <?php echo $error_show; ?></div> <?php } else if (!empty($success_info)) {?> <div class="success"><?php echo $success_info; ?></div> <?php }?> <form action="?" method="POST" name="form_save"> <table class="ts-table"> <tr> <th><label for="txt_title">Tiêu đề:<span class="ts-alert">*</span></label></th> <td><input name="txt_title" class="uk-form-width-large" value="<?php echo $title; ?>" type="text" placeholder="Title" required></td> </tr> <tr> <th><label for="txt_phone">Nội dung:<span class="ts-alert">*</span></label></th> <td><textarea class="ckeditor" name="txt_content" placeholder="Content" class="form-control" rows="3"><?php echo $content; ?></textarea></td> </tr> <tr> <th></th> <td><input type="submit" name="btn_submit" value="Lưu" class="uk-button uk-button-large uk-button-primary"></td> </tr> </table> </form> </section> <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'footer.php'; ?> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/admin/about_us.php
PHP
gpl3
3,014
<?php //require section require_once dirname(dirname(__FILE__)) . '/shared/config/config.php'; require_once DOCUMENT_ROOT . DIR_INCLUDE . '/check_user_login.php'; require_once DOCUMENT_ROOT . DIR_SHARED_API . '/api_news.php'; require_once DOCUMENT_ROOT . DIR_SHARED_LIBRARIES . '/lib_pager.php'; $title = 'Admin Panel'; $id = 0; $name = ""; $parent_id = ""; $action = "Add"; $action_show = "Thêm"; if (!empty($_GET['Action']) && $_GET['Action'] === 'Edit') { if (!empty($_GET['Id'])) { $id = $_GET['Id']; } $edit_item = api_news::get_news_category_by_id($id); $id = $edit_item['cat_news_id']; $name = $edit_item['cate_news_name']; $parent_id = $edit_item['parent_cat_news']; $action = "Update"; $action_show = "Sửa"; } else if (!empty($_POST)) { $id_save = ""; if (!empty($_POST['hidd_id'])) { $id_save = $_POST['hidd_id']; } $name_save = ""; if (!empty($_POST['txt_name'])) { $name_save = $_POST['txt_name']; } $parent_id_save = ""; if (!empty($_POST['ddl_parent_id'])) { $parent_id_save = $_POST['ddl_parent_id']; } if (!empty($_POST['Action']) && ($_POST['Action'] === "Add" || $_POST['Action'] === "Update")) { $error_show = api_news::validate_category_fields($name_save); if (empty($error_show)) { if (api_news::save_news_category($id_save, $name_save, $parent_id_save)) { $success_info = "Thêm loại tin tức &lt;".$name_save."&gt; thành công."; if ($id_save > 0) { $success_info = "Sửa loại tin tức &lt;".$name_save."&gt; thành công."; } } } else { $id = $id_save; $name = $name_save; $parent_id = $parent_id_save; $action = $_POST['Action']; $action_show = "Sửa"; if ($action === "Add") { $action_show = "Thêm"; } } } else if (!empty($_POST['Action']) && $_POST['Action'] === "Delete") { $id_delete = 0; if (!empty($_POST['delete_id'])) { $id_delete = $_POST['delete_id']; } api_news::delete_news_category($id_delete); $success_info = "Xóa loại tin tức thành công."; } } ?> <!DOCTYPE html> <html> <head> <?php require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'head.php'; ?> </head> <body> <div class="uk-container uk-container-center uk-margin-top"> <?php require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'menu.php'; ?> <section class="ts-body-container uk-panel uk-panel-box ts-padding-large"> <form action="?" method="POST" id="form_delete" > <input type="hidden" name="delete_id" value="0" /> <input type="hidden" name="Action" value="Delete" /> </form> <form name="form_data" id="form_data" method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" enctype="multipart/form-data" class="uk-form uk-width-medium-1-1"> <?php if (!empty($error_show)) {?> <div class="error">Lỗi: <?php echo $error_show; ?></div> <?php } else if (!empty($success_info)) {?> <div class="success"><?php echo $success_info; ?></div> <?php }?> <fieldset> <legend>Danh mục tin tức</legend> <input type="hidden" name="hidd_id" value="<?php echo $id; ?>" /> <div class="uk-form-row"> <label>Tên loại</label> <input type="text" name="txt_name" value="<?php echo $name; ?>" placeholder="Text input"> </div> <div class="uk-form-row"> <label>Loại tin tức cấp trên</label> <select name="ddl_parent_id"> <option value="0">-</option> <?php $list = api_news::get_all_news_categories(); foreach ($list as $i => $item) { ?> <option value="<?php echo $item['cat_news_id'] ?>" <?php if (!empty($parent_id)) { if ($item['cat_news_id'] == $parent_id) { echo 'selected'; } } ?> > <?php echo $item['cate_news_name'] ?> </option> <?php } ?> </select> </div> <div class="uk-form-row"> <input type="hidden" name="Action" value="<?php echo $action; ?>"> <button class="uk-button uk-button-primary" id="action-button" onclick="submit_data();"><?php echo $action_show; ?></button> <a href="?">Hủy</a> </div> </fieldset> </form> <hr/> <h3><strong>Danh sách</strong></h3> <table class="uk-table uk-table-hover uk-table-striped uk-table-condensed"> <thead> <tr> <th>Tên loại</th> <th>Loại tin tức cấp trên</th> <th>Thao tác</th> </tr> </thead> <tbody> <?php $current_page = 1; $page_size = 10; if (!empty($_GET['p'])) { $current_page = $_GET['p']; } $list_total = api_news::get_all_news_categories(); $lib_pager = new lib_pager(); $total_page = $lib_pager->get_total_page($list_total, $page_size); $current_page_list = $lib_pager->get_current_page_list($page_size, $current_page, $list_total); $count = 0; if (empty($current_page_list) || count($current_page_list) == 0) { echo "<tr><td>Chưa có dữ liệu</td></tr>"; } else { foreach ($current_page_list as $i => $item) {?> <tr> <td><?php echo $item['cate_news_name'] ?></td> <td><?php echo $item['parent_cat_name'] ?></td> <td> <a href="?Action=Edit&Id=<?php echo $item['cat_news_id']; ?>"> <i class="uk-icon-edit"></i> </a> <i class="uk-icon-eraser" onclick="confirmDelete('<?php echo $item['cat_news_id']; ?>')"></i> </td> </tr> <?php } } ?> <tr align="right" style="color:Black;background-color:#F7F7DE;"> <td colspan="4"> <table> <tbody> <tr align="right" style="color:Black;background-color:#F7F7DE;"> <td colspan="4"> <table> <tbody> <tr> <?php for ($a = 1; $a <= $total_page; $a++) { ?> <td> <span> <a href="articles.php?p=<?php echo $a; ?>" <?php if ($current_page != $a) echo 'style="color:Black;"'; ?>><?php echo $a; ?></a> </span> </td> <?php } ?> </tr> </tbody> </table> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </section> <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'footer.php'; ?> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/admin/news_category.php
PHP
gpl3
10,506
<?php //require section require_once dirname(dirname(__FILE__)) . '/shared/config/config.php'; require_once DOCUMENT_ROOT . DIR_INCLUDE . '/check_user_login.php'; require_once DOCUMENT_ROOT . DIR_SHARED_API . '/api_user.php'; require_once DOCUMENT_ROOT . DIR_SHARED_LIBRARIES . '/lib_pager.php'; $title = 'Admin Panel'; $id = 0; $email = ""; $first_name = ""; $last_name = ""; $address = ""; $phone = ""; $action = "Add"; $action_show = "Thêm"; if (!empty($_GET['Action']) && $_GET['Action'] === 'Edit') { if (!empty($_GET['Id'])) { $id = $_GET['Id']; } $edit_item = api_user::get_user_by_id($id); $id = $edit_item['user_id']; $email = $edit_item['email']; $first_name = $edit_item['first_name']; $last_name = $edit_item['last_name']; $address = $edit_item['address']; $phone = $edit_item['phone']; $action = "Update"; $action_show = "Sửa"; } else if (!empty($_POST)) { $id_save = ""; if (!empty($_POST['Id'])) { $id_save = $_POST['Id']; } $email_save = ""; if (!empty($_POST['txt_email'])) { $email_save = $_POST['txt_email']; } $first_name_save = ""; if (!empty($_POST['txt_first_name'])) { $first_name_save = $_POST['txt_first_name']; } $last_name_save = ""; if (!empty($_POST['txt_last_name'])) { $last_name_save = $_POST['txt_last_name']; } $address_save = ""; if (!empty($_POST['txt_address'])) { $address_save = $_POST['txt_address']; } $phone_save = ""; if (!empty($_POST['txt_phone'])) { $phone_save = $_POST['txt_phone']; } if (!empty($_POST['Action']) && ($_POST['Action'] === "Add" || $_POST['Action'] === "Update")) { $error_show = api_user::validate_user_fields($id_save, $email_save, $first_name_save, $last_name_save, $address_save, $phone_save); if (empty($error_show)) { if (api_user::save_user($id_save, $email_save, $first_name_save, $last_name_save, $address_save, $phone_save)) { $success_info = "Thêm khách hàng &lt;" . $email_save . "&gt; thành công. (mật khẩu mặc định là: 123456)"; if ($id_save > 0) { $success_info = "Sửa khách hàng &lt;" . $email_save . "&gt; thành công."; } } } else { $id = $id_save; $email = $email_save; $first_name = $first_name_save; $last_name = $last_name_save; $address = $address_save; $phone = $phone_save; $action = $_POST['Action']; $action_show = "Sửa"; if ($action === "Add") { $action_show = "Thêm"; } } } else if (!empty($_POST['Action']) && $_POST['Action'] === "Delete") { $id_delete = 0; if (!empty($_POST['delete_id'])) { $id_delete = $_POST['delete_id']; } api_user::delete_user($id_delete); $success_info = "Xóa khách hàng thành công"; } } ?> <!DOCTYPE html> <html> <head> <?php require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'head.php'; ?> </head> <body> <div class="uk-container uk-container-center uk-margin-top"> <?php require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'menu.php'; ?> <section class="ts-body-container uk-panel uk-panel-box ts-padding-large"> <form action="?" method="POST" id="form_delete"> <input type="hidden" name="delete_id" value="0"/> <input type="hidden" name="Action" value="Delete"/> </form> <form class="uk-form uk-width-medium-1-3" name="form_data" id="form_data" method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" enctype="multipart/form-data"> <?php if (!empty($error_show)) { ?> <div class="error">Lỗi: <?php echo $error_show; ?></div> <?php } else if (!empty($success_info)) { ?> <div class="success"><?php echo $success_info; ?></div> <?php }?> <fieldset> <legend>Khách Hàng</legend> <div class="ui form segment form-background"> <input type="hidden" name="Id" value="<?php echo $id; ?>"/> <div class="uk-form-row"> <label for="Title">Email <span class="required">*</span></label> <input id="Title" name="txt_email" value="<?php echo $email ?>" placeholder="" type="text"> </div> <div class="uk-form-row"> <label for="Title">Họ <span class="required">*</span></label> <input id="Title" name="txt_first_name" value="<?php echo $first_name ?>" placeholder="" type="text"> </div> <div class="uk-form-row"> <label for="Title">Tên <span class="required">*</span></label> <input id="Title" name="txt_last_name" value="<?php echo $last_name ?>" placeholder="" type="text"> </div> <div class="uk-form-row"> <label for="Title">Địa chỉ <span class="required">*</span></label> <input id="Title" name="txt_address" value="<?php echo $address ?>" placeholder="" type="text"> </div> <div class="uk-form-row"> <label for="Title">Số điện thoại <span class="required">*</span></label> <input id="Title" name="txt_phone" value="<?php echo $phone ?>" placeholder="" type="text"> </div> <div class="uk-form-row"> <input type="hidden" name="Action" value="<?php echo $action; ?>"> <button class="uk-button uk-button-primary" id="action-button" onclick="submit_data();"><?php echo $action_show; ?></button> <a href="?">Hủy</a> </div> </div> </fieldset> </form> <hr/> <h3><strong>Danh sách</strong></h3> <table class="uk-table uk-table-hover uk-table-striped uk-table-condensed"> <thead> <tr> <th>Email</th> <th>Họ</th> <th>Tên</th> <th>Địa chỉ</th> <th>Số điện thoai</th> <th>Thao tác</th> </tr> </thead> <tbody> <?php $current_page = 1; $page_size = 10; if (!empty($_GET['p'])) { $current_page = $_GET['p']; } $list_total = api_user::get_all_user(); $lib_pager = new lib_pager(); $total_page = $lib_pager->get_total_page($list_total, $page_size); $current_page_list = $lib_pager->get_current_page_list($page_size, $current_page, $list_total); $count = 0; if (empty($current_page_list) || count($current_page_list) == 0) { echo "<tr><td>Chưa có dữ liệu</td></tr>"; } else { foreach ($current_page_list as $i => $item) { ?> <tr> <td><?php echo $item['email'] ?></td> <td><?php echo $item['first_name'] ?></td> <td><?php echo $item['last_name'] ?></td> <td><?php echo $item['address'] ?></td> <td><?php echo $item['phone'] ?></td> <td> <a href="?Action=Edit&Id=<?php echo $item['user_id']; ?>"> <i class="uk-icon-edit"></i> </a> <i class="uk-icon-eraser" onclick="confirmDelete('<?php echo $item['user_id']; ?>')"></i> </td> </tr> <?php } } ?> <tr align="right" style="color:Black;background-color:#F7F7DE;"> <td colspan="7"> <table> <tbody> <tr align="right" style="color:Black;background-color:#F7F7DE;"> <td colspan="7"> <table> <tbody> <tr> <?php for ($a = 1; $a <= $total_page; $a++) { ?> <td> <span> <a href="?p=<?php echo $a; ?>" <?php if ($current_page != $a) echo 'style="color:Black;"'; ?>><?php echo $a; ?></a> </span> </td> <?php } ?> </tr> </tbody> </table> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </section> <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'footer.php'; ?> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/admin/user.php
PHP
gpl3
10,375
<?php //require section require_once dirname(dirname(__FILE__)) . '/shared/config/config.php'; require_once DOCUMENT_ROOT . DIR_INCLUDE . '/check_user_login.php'; require_once DOCUMENT_ROOT . DIR_SHARED_API . '/api_document.php'; require_once DOCUMENT_ROOT . DIR_SHARED_LIBRARIES . '/lib_pager.php'; $title = 'Admin Panel'; $id = 0; $email = ""; $parent_id = ""; $action = "Add"; $action_show = "Thêm"; if (!empty($_GET['Action']) && $_GET['Action'] === 'Edit') { if (!empty($_GET['Id'])) { $id = $_GET['Id']; } $edit_item = api_document::get_document_category_by_id($id); $id = $edit_item['cat_id']; $email = $edit_item['cat_name']; $parent_id = $edit_item['cat_parent_id']; $action = "Update"; $action_show = "Sửa"; } else if (!empty($_POST)) { $id_save = ""; if (!empty($_POST['hidd_id'])) { $id_save = $_POST['hidd_id']; } $first_name = ""; if (!empty($_POST['txt_name'])) { $first_name = $_POST['txt_name']; } $parent_id_save = ""; if (!empty($_POST['ddl_parent_id'])) { $parent_id_save = $_POST['ddl_parent_id']; } if (!empty($_POST['Action']) && ($_POST['Action'] === "Add" || $_POST['Action'] === "Update")) { $error_show = api_document::validate_category_fields($first_name); if (empty($error_show)) { if (api_document::save_document_category($id_save, $first_name, $parent_id_save)) { $success_info = "Thêm loai tài liệu &lt;".$first_name."&gt; thành công."; if ($id_save > 0) { $success_info = "Sửa loai tài liệu &lt;".$first_name."&gt; thành công."; } } } else { $id = $id_save; $email = $first_name; $parent_id = $parent_id_save; $action = $_POST['Action']; $action_show = "Sửa"; if ($action === "Add") { $action_show = "Thêm"; } } } else if (!empty($_POST['Action']) && $_POST['Action'] === "Delete") { $id_delete = 0; if (!empty($_POST['delete_id'])) { $id_delete = $_POST['delete_id']; } api_document::delete_document_category($id_delete); $success_info = "Xóa loại tài liệu thành công."; } } ?> <!DOCTYPE html> <html> <head> <?php require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'head.php'; ?> </head> <body> <div class="uk-container uk-container-center uk-margin-top"> <?php require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'menu.php'; ?> <section class="ts-body-container uk-panel uk-panel-box ts-padding-large"> <form action="?" method="POST" id="form_delete" > <input type="hidden" name="delete_id" value="0" /> <input type="hidden" name="Action" value="Delete" /> </form> <form name="form_data" id="form_data" method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" enctype="multipart/form-data" class="uk-form uk-width-medium-1-1"> <?php if (!empty($error_show)) {?> <div class="error">Lỗi: <?php echo $error_show; ?></div> <?php } else if (!empty($success_info)) {?> <div class="success"><?php echo $success_info; ?></div> <?php }?> <fieldset> <legend>Danh mục bài tập</legend> <input type="hidden" name="hidd_id" value="<?php echo $id; ?>" /> <div class="uk-form-row"> <label>Tên loại</label> <input type="text" name="txt_name" value="<?php echo $email; ?>" placeholder="Text input"> </div> <div class="uk-form-row"> <label>Loại tài liệu cấp trên</label> <select name="ddl_parent_id"> <option value="0">-</option> <?php $list = api_document::get_all_document_categories(); foreach ($list as $i => $item) { ?> <option value="<?php echo $item['cat_id'] ?>" <?php if (!empty($parent_id)) { if ($item['cat_id'] == $parent_id) { echo 'selected'; } } ?> > <?php echo $item['cat_name'] ?> </option> <?php } ?> </select> </div> <div class="uk-form-row"> <input type="hidden" name="Action" value="<?php echo $action; ?>"> <button class="uk-button uk-button-primary" id="action-button" onclick="submit_data();"><?php echo $action_show; ?></button> <a href="?">Hủy</a> </div> </fieldset> </form> <hr/> <h3><strong>Danh sách</strong></h3> <table class="uk-table uk-table-hover uk-table-striped uk-table-condensed"> <thead> <tr> <th>Tên loại</th> <th>Loại tài liệu cấp trên</th> <th>Thao tác</th> </tr> </thead> <tbody> <?php $current_page = 1; $page_size = 10; if (!empty($_GET['p'])) { $current_page = $_GET['p']; } $list_total = api_document::get_all_document_categories(); $lib_pager = new lib_pager(); $total_page = $lib_pager->get_total_page($list_total, $page_size); $current_page_list = $lib_pager->get_current_page_list($page_size, $current_page, $list_total); $count = 0; if (empty($current_page_list) || count($current_page_list) == 0) { echo "<tr><td>Chưa có dữ liệu</td></tr>"; } else { foreach ($current_page_list as $i => $item) {?> <tr> <td><?php echo $item['cat_name'] ?></td> <td><?php echo $item['cat_parent_name'] ?></td> <td> <a href="?Action=Edit&Id=<?php echo $item['cat_id']; ?>"> <i class="uk-icon-edit"></i> </a> <i class="uk-icon-eraser" onclick="confirmDelete('<?php echo $item['cat_id']; ?>')"></i> </td> </tr> <?php } } ?> <tr align="right" style="color:Black;background-color:#F7F7DE;"> <td colspan="4"> <table> <tbody> <tr align="right" style="color:Black;background-color:#F7F7DE;"> <td colspan="4"> <table> <tbody> <tr> <?php for ($a = 1; $a <= $total_page; $a++) { ?> <td> <span> <a href="?p=<?php echo $a; ?>" <?php if ($current_page != $a) echo 'style="color:Black;"'; ?>><?php echo $a; ?></a> </span> </td> <?php } ?> </tr> </tbody> </table> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </section> <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'footer.php'; ?> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/admin/document_category.php
PHP
gpl3
10,312
<?php //require section require_once dirname(dirname(__FILE__)) . '/shared/config/config.php'; require_once DOCUMENT_ROOT . DIR_INCLUDE . '/check_user_login.php'; require_once DOCUMENT_ROOT . DIR_SHARED_API . '/api_document.php'; require_once DOCUMENT_ROOT . DIR_SHARED_LIBRARIES . '/lib_pager.php'; require_once DOCUMENT_ROOT . DIR_SHARED_LIBRARIES . '/lib_upload.php'; $title = 'Admin Panel'; $id = 0; $name = ""; $detail = ""; $cat_id = ""; $price = ""; $image = ""; $file = ""; $action = "Add"; $action_show = "Thêm"; if (!empty($_GET['Action']) && $_GET['Action'] === 'Edit') { if (!empty($_GET['Id'])) { $id = $_GET['Id']; } $edit_item = api_document::get_document_by_id($id); $id = $edit_item['doc_id']; $name = $edit_item['doc_name']; $detail = $edit_item['doc_detail']; $cat_id = $edit_item['doc_cat_id']; $price = $edit_item['doc_price']; $image = $edit_item['doc_img_url']; $file = $edit_item['doc_file']; $action = "Update"; $action_show = "Sửa"; } else if (!empty($_POST)) { $id_save = ""; if (!empty($_POST['Id'])) { $id_save = $_POST['Id']; } $name_save = ""; if (!empty($_POST['txt_name'])) { $name_save = $_POST['txt_name']; } $detail_save = ""; if (!empty($_POST['txt_detail'])) { $detail_save = $_POST['txt_detail']; } $cat_id_save = ""; if (!empty($_POST['ddl_cat_id'])) { $cat_id_save = $_POST['ddl_cat_id']; } $price_save = ""; if (!empty($_POST['txt_price'])) { $price_save = $_POST['txt_price']; } $image_save = ""; if (!empty($_FILES['f_image']['size'])) { $lib_upload = new lib_upload(); if ($lib_upload->upload_file('f_image', DOCUMENT_ROOT . DIR_SHARED_UPLOAD_IMAGES_DOCUMENT)) { $image_save = $_FILES['f_image']['name']; } } else if (!empty($_POST['hidd_image'])) { $image_save = $_POST['hidd_image']; } $file_save = ""; if (!empty($_FILES['f_file']['size'])) { $lib_upload = new lib_upload(); if ($lib_upload->upload_file('f_file', DOCUMENT_ROOT . DIR_SHARED_UPLOAD_DOCUMENTS)) { $file_save = $_FILES['f_file']['name']; } } else if (!empty($_POST['hidd_file'])) { $file_save = $_POST['hidd_file']; } if (!empty($_POST['Action']) && ($_POST['Action'] === "Add" || $_POST['Action'] === "Update")) { $error_show = api_document::validate_document_fields($name_save, $detail_save, $cat_id_save, $price_save, $image_save, $file_save); if (empty($error_show)) { if (api_document::save_document($id_save, $name_save, $detail_save, $cat_id_save, $price_save, $image_save, $file_save)) { $success_info = "Thêm tài liệu &lt;" . $name_save . "&gt; thành công."; if ($id_save > 0) { $success_info = "Sửa tài liệu &lt;" . $name_save . "&gt; thành công."; } } } else { $id = $id_save; $name = $name_save; $detail = $detail_save; $cat_id = $cat_id_save; $price = $price_save; $image = $image_save; $file = $file_save; $action = $_POST['Action']; $action_show = "Sửa"; if ($action === "Add") { $action_show = "Thêm"; } } } else if (!empty($_POST['Action']) && $_POST['Action'] === "Delete") { $id_delete = 0; if (!empty($_POST['delete_id'])) { $id_delete = $_POST['delete_id']; } api_document::delete_document($id_delete); $success_info = "Xóa tài liệu thành công"; } } ?> <!DOCTYPE html> <html> <head> <?php require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'head.php'; ?> </head> <body> <div class="uk-container uk-container-center uk-margin-top"> <?php require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'menu.php'; ?> <section class="ts-body-container uk-panel uk-panel-box ts-padding-large"> <form action="?" method="POST" id="form_delete"> <input type="hidden" name="delete_id" value="0"/> <input type="hidden" name="Action" value="Delete"/> </form> <form class="uk-form uk-width-medium-1-1" name="form_data" id="form_data" method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" enctype="multipart/form-data"> <?php if (!empty($error_show)) { ?> <div class="error">Lỗi: <?php echo $error_show; ?></div> <?php } else if (!empty($success_info)) { ?> <div class="success"><?php echo $success_info; ?></div> <?php }?> <fieldset> <legend><h2>Bài tập</h2></legend> <div class="ui form segment form-background"> <input type="hidden" name="Id" value="<?php echo $id; ?>"/> <div class="uk-form-row"> <label for="Title">Tên tài liệu <span class="required">*</span></label> <input id="Title" name="txt_name" value="<?php echo $name ?>" placeholder="" type="text"> </div> <div class="uk-form-row"> <label for="Description">Loại tài liệu</label> <select name="ddl_cat_id"> <?php $list = api_document::get_all_document_categories(); foreach ($list as $i => $item) { ?> <option value="<?php echo $item['cat_id'] ?>" <?php if (!empty($edit_article_old)) { if ($item['cat_id'] == $cat_id) { echo 'selected'; } } ?> > <?php echo $item['cat_name'] ?> </option> <?php } ?> </select> </div> <div class="uk-form-row"> <label for="Description">Chi tiết <span class="required">*</span></label> <textarea id="Description" name="txt_detail" placeholder="Detail" class="form-control" rows="3"><?php echo $detail; ?></textarea> </div> <div class="uk-form-row"> <label for="Title">Giá <span class="required">*</span></label> <input id="Title" name="txt_price" value="<?php echo $price ?>" placeholder="" type="text"> </div> <div class="uk-form-row"> <label for="Poster">Hình ảnh <span class="required">*</span></label> <input type="file" name="f_image"/> <?php if (!empty($image)) { ?> <input type="hidden" name="hidd_image" value="<?php echo $image ?>"/> <img src="<?php echo LINK_ROOT . DIR_SHARED_UPLOAD_IMAGES_DOCUMENT . $image; ?>" style="max-height: 100px;"> <?php } ?> </div> <div class="uk-form-row"> <label for="Poster">Tài liệu <span class="required">*</span></label> <input type="file" name="f_file"/> <?php if (!empty($file)) { ?> <input type="hidden" name="hidd_file" value="<?php echo $file ?>"/> <?php echo $file; ?> <?php } ?> </div> <div class="uk-form-row"> <input type="hidden" name="Action" value="<?php echo $action; ?>"> <button class="uk-button uk-button-primary" id="action-button" onclick="submit_data();"><?php echo $action_show; ?></button> <a href="?">Hủy</a> </div> </div> </fieldset> </form> <hr/> <h3><strong>Danh sách</strong></h3> <table class="uk-table uk-table-hover uk-table-striped uk-table-condensed"> <thead> <tr> <th>Tên tài liệu</th> <th>Loại tài liệu</th> <th>Chi tiết</th> <th>Giá</th> <th>Hình ảnh</th> <th>Tài liệu</th> <th>Thao tác</th> </tr> </thead> <tbody> <?php $current_page = 1; $page_size = 10; if (!empty($_GET['p'])) { $current_page = $_GET['p']; } $list_total = api_document::get_all_documents(); $lib_pager = new lib_pager(); $total_page = $lib_pager->get_total_page($list_total, $page_size); $current_page_list = $lib_pager->get_current_page_list($page_size, $current_page, $list_total); $count = 0; if (empty($current_page_list) || count($current_page_list) == 0) { echo "<tr><td>Chưa có dữ liệu</td></tr>"; } else { foreach ($current_page_list as $i => $item) { ?> <tr> <td><?php echo $item['doc_name'] ?></td> <td><?php echo $item['doc_cat_name'] ?></td> <td><?php echo $item['doc_detail'] ?></td> <td><?php echo number_format($item['doc_price'], 0, '.', ',') . ' vnđ' ?></td> <td> <a href="<?php echo LINK_ROOT . DIR_SHARED_UPLOAD_IMAGES_DOCUMENT . $item['doc_img_url'] ?>">Hình ảnh</a></td> <td><a href="<?php echo LINK_ROOT . DIR_SHARED_UPLOAD_DOCUMENTS . $item['doc_file'] ?>">Tập tin</a></td> <td> <a href="?Action=Edit&Id=<?php echo $item['doc_id']; ?>"> <i class="uk-icon-edit"></i> </a> <i class="uk-icon-eraser" onclick="confirmDelete('<?php echo $item['doc_id']; ?>')"></i> </td> </tr> <?php } }?> <tr align="right" style="color:Black;background-color:#F7F7DE;"> <td colspan="7"> <table> <tbody> <tr align="right" style="color:Black;background-color:#F7F7DE;"> <td colspan="7"> <table> <tbody> <tr> <?php for ($a = 1; $a <= $total_page; $a++) { ?> <td> <span> <a href="?p=<?php echo $a; ?>" <?php if ($current_page != $a) echo 'style="color:Black;"'; ?>><?php echo $a; ?></a> </span> </td> <?php } ?> </tr> </tbody> </table> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </section> <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'footer.php'; ?> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/admin/document.php
PHP
gpl3
13,449
<?php //require section require_once dirname(dirname(__FILE__)) . '/shared/config/config.php'; require_once DOCUMENT_ROOT . DIR_INCLUDE . '/check_user_login.php'; require_once DOCUMENT_ROOT . DIR_SHARED_API . '/api_document.php'; require_once DOCUMENT_ROOT . DIR_SHARED_API . '/api_invoice.php'; require_once DOCUMENT_ROOT . DIR_SHARED_LIBRARIES . '/lib_pager.php'; require_once DOCUMENT_ROOT . DIR_SHARED_LIBRARIES . '/lib_upload.php'; $title = 'Admin Panel'; $id = 0; $email = ""; $first_name = ""; $last_name = ""; $address = ""; $phone = ""; $file = ""; $action = "Add"; $action_show = "Thêm"; if (!empty($_POST)) { if (!empty($_POST['Action']) && $_POST['Action'] === "Process") { $id_process = 0; if (!empty($_POST['process_id'])) { $id_process = $_POST['process_id']; } api_invoice::process_invoice($id_process); $success_info = "Đã xử lý đơn hàng " . $id_process . " thành công"; } else if (!empty($_POST['Action']) && $_POST['Action'] === "Delete") { $id_delete = 0; if (!empty($_POST['delete_id'])) { $id_delete = $_POST['delete_id']; } api_invoice::delete_invoice($id_delete); $success_info = "Xóa đơn hàng thành công"; } } ?> <!DOCTYPE html> <html> <head> <?php require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'head.php'; ?> </head> <body> <div class="uk-container uk-container-center uk-margin-top"> <?php require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'menu.php'; ?> <section class="ts-body-container uk-panel uk-panel-box ts-padding-large"> <?php if (!empty($success_info)) { ?> <div class="success"><?php echo $success_info; ?></div> <?php }?> <hr/> <h3><strong>Đơn hàng chờ xử lý</strong></h3> <form action="?" method="POST" id="form_delete"> <input type="hidden" name="delete_id" value="0"/> <input type="hidden" name="Action" value="Delete"/> </form> <form action="?" method="POST" id="form_process"> <input type="hidden" name="process_id" value="0"/> <input type="hidden" name="Action" value="Process"/> </form> <table class="uk-table uk-table-hover uk-table-striped uk-table-condensed"> <thead> <tr> <th>STT</th> <th>Mã đơn hàng</th> <th>Khách hàng</th> <th>Trạng thái</th> <th>Tổng tiền</th> <th>Tổng số tài liệu</th> <th>Ngày tạo</th> <th>Thao tác</th> </tr> </thead> <tbody> <?php $current_page = 1; $page_size = 10; if (!empty($_GET['p'])) { $current_page = $_GET['p']; } $list_total = api_invoice::get_all_unpaid_invoices(); $lib_pager = new lib_pager(); $total_page = $lib_pager->get_total_page($list_total, $page_size); $current_page_list = $lib_pager->get_current_page_list($page_size, $current_page, $list_total); $count = 0; if (empty($current_page_list) || count($current_page_list) == 0) { echo "<tr><td>chưa có đơn hàng nào</td></td>"; } else { foreach ($current_page_list as $i => $item) { ?> <tr> <td><?php echo $i + 1; ?></td> <td><?php echo $item['invoice_id'] ?></td> <td><?php echo $item['email'] ?></td> <td><?php echo $item['inv_status_name'] ?></td> <td><?php echo number_format($item['total_money'], 0, '.', ',') . " vnđ" ?></td> <td><?php echo $item['total_quantity'] ?></td> <?php $date = date_create($item["created_date"]); $date_str = date_format($date, "d/m/Y"); ?> <td><?php echo $date_str; ?></td> <td> <i class="uk-icon-check" title data-uk-tooltip data-cached-title="Xử lý đơn hàng" onclick="confirmProcess('<?php echo $item['invoice_id']; ?>')"></i> <a href="invoice_detail.php?invoice_id=<?php echo $item['invoice_id']; ?>"><i class="uk-icon-search"></i></a> <i class="uk-icon-eraser" onclick="confirmDelete('<?php echo $item['invoice_id']; ?>')"></i> </td> </tr> <?php } } ?> <tr align="right" style="color:Black;background-color:#F7F7DE;"> <td colspan="8"> <table> <tbody> <tr align="right" style="color:Black;background-color:#F7F7DE;"> <td colspan="7"> <table> <tbody> <tr> <?php for ($a = 1; $a <= $total_page; $a++) { ?> <td> <span> <a href="?p=<?php echo $a; ?>" <?php if ($current_page != $a) echo 'style="color:Black;"'; ?>><?php echo $a; ?></a> </span> </td> <?php } ?> </tr> </tbody> </table> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </section> <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'footer.php'; ?> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/admin/invoice.php
PHP
gpl3
6,707
<script type="text/javascript" src="<?php echo LINK_ROOT . DIR_SHARED_PLUGIN; ?>ckeditor/ckeditor.js"></script> <script type="text/javascript" src="<?php echo LINK_ROOT . DIR_SHARED_PLUGIN; ?>ckeditor/config.js"></script> <link href="<?php echo LINK_ROOT . DIR_SHARED_PLUGIN; ?>ckeditor/contents.css" rel="stylesheet">
04-huanluyenviencanhan
trunk/master/admin/include/ckeditor.php
PHP
gpl3
320
<script type="text/javascript"> function notify(message){ $.uikit.notify(message); } function submit_data() { $("#form_data").submit(); } function confirmDelete(id) { if (confirm('Are you sure?')) { $('#form_delete input[name="delete_id"]').val(id); $("#form_delete").submit(); } else { return false; } } function confirmProcess(id) { if (confirm('Are you sure?')) { $('#form_process input[name="process_id"]').val(id); $("#form_process").submit(); } else { return false; } } </script>
04-huanluyenviencanhan
trunk/master/admin/include/head_script.php
PHP
gpl3
752
<!-- Menu --> <nav id="main-menu" class="uk-navbar uk-margin-large-bottom" data-uk-sticky> <a href="<?php echo LINK_ROOT . DIR_ADMIN . 'index.php' ?>" class="uk-navbar-brand uk-hidden-small" data-uk-tooltip title="Trang Quản Trị">Admin Panel</a> <ul class="uk-navbar-nav uk-hidden-small"> <li> <a href="<?php echo LINK_ROOT . DIR_ADMIN . 'document_category.php' ?>" data-uk-tooltip title="Quản lý danh mục bài tập">DM bài tập</a> </li> <li> <a href="<?php echo LINK_ROOT . DIR_ADMIN . 'document.php' ?>" data-uk-tooltip title="Quản lý bài tập">Bài tập</a> </li> <li> <a href="<?php echo LINK_ROOT . DIR_ADMIN . 'news_category.php' ?>" data-uk-tooltip title="Quản lý danh mục tin tức">DM tin tức</a> </li> <li> <a href="<?php echo LINK_ROOT . DIR_ADMIN . 'news.php' ?>" data-uk-tooltip title="Quản lý tin tức">Tin tức</a> </li> <li> <a href="<?php echo LINK_ROOT . DIR_ADMIN . 'invoice.php' ?>" data-uk-tooltip title="Quản lý đơn hàng chưa thanh toán">Đơn hàng chờ</a> </li> <li> <a href="<?php echo LINK_ROOT . DIR_ADMIN . 'invoice_paid.php' ?>" data-uk-tooltip title="Quản lý đơn hàng đã thanh toán">Đơn hàng đã xử lý</a> </li> <li> <a href="<?php echo LINK_ROOT . DIR_ADMIN . 'user.php' ?>" data-uk-tooltip title="Quản lý khách hàng">Khách hàng</a> </li> <li> <a href="<?php echo LINK_ROOT . DIR_ADMIN . 'contact.php' ?>" data-uk-tooltip title="Quản lý thông tin liên lạc">Liên hệ</a> </li> <li> <a href="<?php echo LINK_ROOT . DIR_ADMIN . 'about_us.php' ?>" data-uk-tooltip title="Quản lý bài viết giới thiệu">Giới thiệu</a> </li> <li> <a href="<?php echo LINK_ROOT . '/logout.php' ?>" data-uk-tooltip title="Đăng xuất">Thoát</a> </li> <li> <a href="<?php echo LINK_ROOT . '/index.php' ?>" data-uk-tooltip title="Trở về trang chủ">Trở về</a> </li> </ul> <a data-uk-offcanvas="" class="uk-navbar-toggle uk-visible-small" href="#offcanvas"></a> <div class="uk-navbar-brand uk-navbar-center uk-visible-small">Admin Panel</div> </nav> <!-- Offcanvas Menu --> <div class="uk-offcanvas" id="offcanvas"> <div class="uk-offcanvas-bar"> <ul class="uk-nav uk-nav-offcanvas" data-uk-nav=""> <li> <a href="<?php echo LINK_ROOT . DIR_ADMIN . 'document_category.php' ?>" data-uk-tooltip title="Quản lý danh mục bài tập">Danh mục bài tập</a> </li> <li> <a href="<?php echo LINK_ROOT . DIR_ADMIN . 'document.php' ?>" data-uk-tooltip title="Quản lý bài tập">Bài tập</a> </li> <li> <a href="<?php echo LINK_ROOT . DIR_ADMIN . 'news_category.php' ?>" data-uk-tooltip title="Quản lý danh mục tin tức">Danh mục tin tức</a> </li> <li> <a href="<?php echo LINK_ROOT . DIR_ADMIN . 'news.php' ?>" data-uk-tooltip title="Quản lý tin tức">Tin tức</a> </li> <li> <a href="<?php echo LINK_ROOT . DIR_ADMIN . 'invoice.php' ?>" data-uk-tooltip title="Quản lý hóa đơn">Hóa đơn</a> </li> <li> <a href="<?php echo LINK_ROOT . DIR_ADMIN . 'user.php' ?>" data-uk-tooltip title="Quản lý khách hàng">Khách hàng</a> </li> <li> <a href="<?php echo LINK_ROOT . DIR_ADMIN . 'contact.php' ?>" data-uk-tooltip title="Quản lý thông tin liên lạc">Liên hệ</a> </li> <li> <a href="<?php echo LINK_ROOT . DIR_ADMIN . 'about_us.php' ?>" data-uk-tooltip title="Quản lý bài viết giới thiệu">Giới thiệu</a> </li> </ul> </div> </div> <!-- End Offcanvas Menu --> <!-- End Menu -->
04-huanluyenviencanhan
trunk/master/admin/include/menu.php
PHP
gpl3
4,492
<link rel="stylesheet" href="<?php echo LINK_ROOT . DIR_SHARED_LAYOUT_CSS ?>site.css"> <link rel="stylesheet" href="<?php echo LINK_ROOT . DIR_SHARED_LAYOUT_CSS ?>ts.css">
04-huanluyenviencanhan
trunk/master/admin/include/head_css.php
PHP
gpl3
174
<footer> <div class="ts-center"> Designed by <a href="http://facebook.com/TechStormTeam">TechStorm</a> </div> </footer>
04-huanluyenviencanhan
trunk/master/admin/include/footer.php
Hack
gpl3
127
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title><?php echo $title; ?></title> <!-- Favicon --> <link rel="icon" type="image/png" href="<?php echo LINK_ROOT . '/favicon.png' ?>"> <!-- UIKit CSS --> <link href="<?php echo LINK_ROOT . DIR_SHARED_LAYOUT_UIKIT_CSS ?>uikit.min.css" rel="stylesheet" > <link href="<?php echo LINK_ROOT . DIR_SHARED_LAYOUT_UIKIT_CSS ?>uikit.gradient.min.css" rel="stylesheet" > <link href="<?php echo LINK_ROOT . DIR_SHARED_LAYOUT_UIKIT_CSS ?>/addons/uikit.gradient.addons.min.css" rel="stylesheet" > <!-- Slider CSS --> <link href="<?php echo LINK_ROOT . DIR_SHARED_PLUGIN_WOWSLIDER_CSS ?>slider.css" rel="stylesheet" > <!-- Jquery v1.11.1 + UIKit JS --> <script src="<?php echo LINK_ROOT . DIR_SHARED_LAYOUT_JS ?>jquery-1.11.1.min.js" type="text/javascript"></script> <script src="<?php echo LINK_ROOT . DIR_SHARED_LAYOUT_UIKIT_JS ?>uikit.min.js"></script> <script src="<?php echo LINK_ROOT . DIR_SHARED_LAYOUT_UIKIT_JS ?>addons/notify.min.js"></script> <script src="<?php echo LINK_ROOT . DIR_SHARED_LAYOUT_UIKIT_JS ?>addons/datepicker.min.js"></script> <script src="<?php echo LINK_ROOT . DIR_SHARED_LAYOUT_UIKIT_JS ?>addons/sticky.min.js"></script> <!-- Addon CSS files + Javascripts Functions--> <?php require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'head_css.php'; require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'head_script.php'; ?>
04-huanluyenviencanhan
trunk/master/admin/include/head.php
PHP
gpl3
1,429
<?php //require section require_once dirname(dirname(__FILE__)) . '/shared/config/config.php'; require_once DOCUMENT_ROOT . DIR_INCLUDE . '/check_user_login.php'; require_once DOCUMENT_ROOT . DIR_SHARED_API . '/api_document.php'; require_once DOCUMENT_ROOT . DIR_SHARED_API . '/api_invoice.php'; require_once DOCUMENT_ROOT . DIR_SHARED_LIBRARIES . '/lib_pager.php'; require_once DOCUMENT_ROOT . DIR_SHARED_LIBRARIES . '/lib_upload.php'; $title = 'Admin Panel'; $id = 0; $email = ""; $first_name = ""; $last_name = ""; $address = ""; $phone = ""; $file = ""; $action = "Add"; $action_show = "Thêm"; if (!empty($_GET['Action']) && $_GET['Action'] === 'Edit') { if (!empty($_GET['Id'])) { $id = $_GET['Id']; } $edit_item = api_document::get_document_by_id($id); $id = $edit_item['doc_id']; $email = $edit_item['doc_name']; $first_name = $edit_item['doc_detail']; $last_name = $edit_item['doc_cat_id']; $address = $edit_item['doc_price']; $phone = $edit_item['doc_img_url']; $file = $edit_item['doc_file']; $action = "Update"; $action_show = "Sửa"; } else if (!empty($_POST)) { $id_save = ""; if (!empty($_POST['Id'])) { $id_save = $_POST['Id']; } $first_name = ""; if (!empty($_POST['txt_name'])) { $first_name = $_POST['txt_name']; } $last_name = ""; if (!empty($_POST['txt_detail'])) { $last_name = $_POST['txt_detail']; } $address = ""; if (!empty($_POST['ddl_cat_id'])) { $address = $_POST['ddl_cat_id']; } $phone_save = ""; if (!empty($_POST['txt_price'])) { $phone_save = $_POST['txt_price']; } $image_save = ""; if (!empty($_FILES['f_image']['size'])) { $lib_upload = new lib_upload(); if ($lib_upload->upload_file('f_image', DOCUMENT_ROOT . DIR_SHARED_UPLOAD_IMAGES)) { $image_save = $_FILES['f_image']['name']; } } else if (!empty($_POST['hidd_image'])) { $image_save = $_POST['hidd_image']; } $file_save = ""; if (!empty($_FILES['f_file']['size'])) { $lib_upload = new lib_upload(); if ($lib_upload->upload_file('f_file', DOCUMENT_ROOT . DIR_SHARED_UPLOAD_DOCUMENTS)) { $file_save = $_FILES['f_file']['name']; } } else if (!empty($_POST['hidd_file'])) { $file_save = $_POST['hidd_file']; } if (!empty($_POST['Action']) && ($_POST['Action'] === "Add" || $_POST['Action'] === "Update")) { $error_show = api_document::validate_document_fields($first_name, $last_name, $address, $phone_save, $image_save, $file_save); if (empty($error_show)) { if (api_document::save_document($id_save, $first_name, $last_name, $address, $phone_save, $image_save, $file_save)) { $success_info = "Thêm tài liệu &lt;" . $first_name . "&gt; thành công."; if ($id_save > 0) { $success_info = "Sửa tài liệu &lt;" . $first_name . "&gt; thành công."; } } } else { $id = $id_save; $email = $first_name; $first_name = $last_name; $last_name = $address; $address = $phone_save; $phone = $image_save; $file = $file_save; $action = $_POST['Action']; $action_show = "Sửa"; if ($action === "Add") { $action_show = "Thêm"; } } } else if (!empty($_POST['Action']) && $_POST['Action'] === "Delete") { $id_delete = 0; if (!empty($_POST['delete_id'])) { $id_delete = $_POST['delete_id']; } api_invoice::delete_invoice($id_delete); $success_info = "Xóa tài liệu thành công"; } } ?> <!DOCTYPE html> <html> <head> <?php require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'head.php'; ?> </head> <body> <div class="uk-container uk-container-center uk-margin-top"> <?php require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'menu.php'; ?> <section class="ts-body-container uk-panel uk-panel-box ts-padding-large"> <hr/> <h3><strong>Đơn hàng đã xử lý</strong></h3> <form action="?" method="POST" id="form_delete"> <input type="hidden" name="delete_id" value="0"/> <input type="hidden" name="Action" value="Delete"/> </form> <form action="?" method="POST" id="form_process"> <input type="hidden" name="process_id" value="0"/> <input type="hidden" name="Action" value="Process"/> </form> <table class="uk-table uk-table-hover uk-table-striped uk-table-condensed"> <thead> <tr> <th>STT</th> <th>Mã đơn hàng</th> <th>Khách hàng</th> <th>Trạng thái</th> <th>Tổng tiền</th> <th>Tổng số tài liệu</th> <th>Ngày tạo</th> <th>Thao tác</th> </tr> </thead> <tbody> <?php $current_page = 1; $page_size = 10; if (!empty($_GET['p'])) { $current_page = $_GET['p']; } $list_total = api_invoice::get_all_paid_invoices(); $lib_pager = new lib_pager(); $total_page = $lib_pager->get_total_page($list_total, $page_size); $current_page_list = $lib_pager->get_current_page_list($page_size, $current_page, $list_total); $count = 0; if (empty($current_page_list) || count($current_page_list) == 0) { echo "<tr><td>chưa có đơn hàng nào được xử lý</td></td>"; } else { foreach ($current_page_list as $i => $item) { ?> <tr> <td><?php echo $i + 1; ?></td> <td><?php echo $item['invoice_id'] ?></td> <td><?php echo $item['email'] ?></td> <td><?php echo $item['inv_status_name'] ?></td> <td><?php echo number_format($item['total_money'],0,'.',',') ?></td> <td><?php echo $item['total_quantity'] ?></td> <?php $date = date_create($item["created_date"]); $date_str = date_format($date, "d/m/Y"); ?> <td><?php echo $date_str; ?></td> <td> <a href="invoice_detail.php?invoice_id=<?php echo $item['invoice_id']; ?>"><i class="uk-icon-search"></i></a> </td> </tr> <?php } } ?> <tr align="right" style="color:Black;background-color:#F7F7DE;"> <td colspan="8"> <table> <tbody> <tr align="right" style="color:Black;background-color:#F7F7DE;"> <td colspan="7"> <table> <tbody> <tr> <?php for ($a = 1; $a <= $total_page; $a++) { ?> <td> <span> <a href="?p=<?php echo $a; ?>" <?php if ($current_page != $a) echo 'style="color:Black;"'; ?>><?php echo $a; ?></a> </span> </td> <?php } ?> </tr> </tbody> </table> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </section> <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'footer.php'; ?> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/admin/invoice_paid.php
PHP
gpl3
9,034
<?php //require section require_once dirname(__FILE__) . '/shared/config/config.php'; require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_document.php'; require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_multi_level.php'; require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_statistics.php'; $title = 'Danh sách bài tập'; require_once DOCUMENT_ROOT . DIR_INCLUDE . 'usable_functions.php'; ?> <!DOCTYPE html> <html> <head> <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'head.php'; ?> </head> <body> <div class="uk-container uk-container-center uk-margin-top"> <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'menu.php'; require_once DOCUMENT_ROOT . DIR_INCLUDE . 'slider.php'; ?> <section id="main-content" class="ts-body-container"> <div class="ts-left-wrapper"> <?php $cat_id = 0; if (!empty($_GET['cat_id'])) { $cat_id = $_GET['cat_id']; $category = api_document::get_document_category_by_id($cat_id); show_category_group($category, -1); } else { ?> <div class="uk-panel uk-margin-bottom"> <!-- <h1 style="color: #fff"><span style='color: cyan; text-decoration: underline;'></span></h1>--> <h3 class="ts-category-title uk-text-center" data-uk-tooltip title="Danh sách <b style='color: #fff'>tất cả bài tập</b>"> <i class="uk-icon-folder-open"></i> Tất cả bài tập <span>(<?php echo api_document::count_all_documents(); ?> bài)</span> </h3> <?php $list = api_document::get_all_documents(); show_content_group($list); ?> </div> <?php } ?> <h1 style="color: #fff"><span style='color: cyan; text-decoration: underline;'></span></h1> </div> <script type="text/javascript"> function filldata(value) { $.ajax({ type: "GET", url: "<?php echo LINK_ROOT . DIR_AJAX; ?>document_folder_category.php", data: "category_choosen_id=" + value, success: function (result) { $("#category-list").html(result); } }); } $(document).ready(function () { filldata('<?php echo $cat_id; ?>'); }); </script> <div class="ts-right-wrapper"> <div class="uk-panel uk-margin-bottom"> <div class="ts-category-title"><i class="uk-icon-list-ul"></i> Danh mục bài tập</div> <ul class="ts-category-list" id="category-list"> <!-- ajax loading --> <?php show_root_list(); ?> </ul> </div> <div class="uk-panel uk-margin-bottom"> <div class="ts-category-title"><i class="uk-icon-users"></i> Thống kê truy cập</div> <div class="ts-category-content">Tổng số lượt truy cập: <b><?php echo api_statistics::get_access_number(); ?></b></div> </div> </div> </section> <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'footer.php'; ?> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/document.php
PHP
gpl3
3,760
<?php //require section require_once dirname(__FILE__) . '/shared/config/config.php'; require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_document.php'; require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_cart.php'; $title = 'Giỏ Hàng'; ?> <!DOCTYPE html> <html> <head> <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'head.php'; ?> </head> <body> <div class="uk-container uk-container-center uk-margin-top"> <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'menu.php'; require_once DOCUMENT_ROOT . DIR_INCLUDE . 'slider.php'; if (!empty($_POST['destroy'])) { $_SESSION['cart'][$_SESSION['user']] = array(); lib_redirect::Redirect('/index.php'); } if (empty($_SESSION['cart'][$_SESSION['user']]) || count($_SESSION['cart'][$_SESSION['user']]) == 0) { lib_redirect::Redirect('/index.php'); } $remove_cart_id = 0; if (!empty($_POST['remove_id'])) { $remove_cart_id = $_POST['remove_id']; } api_cart::remove_doc_id_from_cart($remove_cart_id, "cart"); ?> <section id="main-content" class="ts-body-container uk-panel uk-panel-box ts-padding-large"> <form action="?" method="POST" id="form_destroy_cart"> <input type="hidden" name="destroy" value="1"/> </form> <form action="?" method="POST" id="form_remove_cart" > <input type="hidden" name="remove_id" value="0" /> </form> <table id="cart_table" class="uk-table uk-table-hover"> <caption>Danh sách bài tập muốn mua trong giỏ hàng</caption> <thead> <tr> <th>STT</th> <th>Mã bài tập</th> <th>Tên bài tập</th> <th>Giá</th> <th class="uk-text-center">Xóa khỏi giỏ hàng</th> </tr> </thead> <tbody> <?php $list = array(); if (!empty($_SESSION['cart'][$_SESSION['user']])) { $list = $_SESSION['cart'][$_SESSION['user']]; } $total_money = 0; foreach ($list as $num => $item_id) { $item = api_document::get_document_by_id($item_id); $total_money += $item['doc_price']; ?> <tr> <td><?php echo $num + 1; ?></td> <td><?php echo $item['doc_id']; ?></td> <td><?php echo $item['doc_name']; ?></td> <td class="uk-text-bold"><?php echo number_format($item['doc_price'], 0, '.', ','); ?> vnđ</td> <td class="uk-text-center"> <a href="javascript::void(0);" onclick="confirmRemoveCart('<?php echo $item['doc_id']; ?>');" style="padding: 10px;"> <i class="uk-icon-ban"></i> </a> </td> </tr> <?php }?> </tbody> <tfoot> <tr> <td colspan="3" class="uk-text-large">Tổng cộng:</td> <td class="uk-text-bold uk-text-large"><?php echo number_format($total_money,0,'.',','); ?> vnđ</td> </tr> </tfoot> </table> <div class="uk-text-center"> <input type="submit" onclick="confirmDestroyCart();" name="btn_destroy" class="uk-button" value="Hủy giỏ hàng"> <input type="submit" name="btn_submit" onclick="return window.location = 'checkout.php#cart_table'" class="uk-button uk-button-primary" value="Tiếp theo"> </div> </section> <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'footer.php'; ?> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/cart.php
PHP
gpl3
4,468
<script type="text/javascript"> function notify(message) { $.uikit.notify(message); } $(document).ready(function() { $('#main-menu > ul > li').on('click', function() { $('#main-menu > ul > li').removeClass('uk-active'); $(this).addClass('uk-active'); }); }); function confirmRemoveCart(id) { if (confirm('Are you sure?')) { $('#form_remove_cart input[name="remove_id"]').val(id); $("#form_remove_cart").submit(); } else { return false; } } function confirmDestroyCart() { if (confirm('Are you sure?')) { $("#form_destroy_cart").submit(); } else { return false; } } function confirmCreateInvoice() { if (confirm('Are you sure?')) { $("#form_create_invoice").submit(); } else { return false; } } </script>
04-huanluyenviencanhan
trunk/master/include/head_script.php
PHP
gpl3
997
<?php require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_statistics.php'; session_start(); $time_out = 60; if(empty($_SESSION['timeout'])){ $_SESSION['timeout'] = time(); api_statistics::increase_access_number(); } else { $inactive_time = time() - $_SESSION['timeout']; if($inactive_time > $time_out){ api_statistics::increase_access_number(); $_SESSION['timeout'] = time(); } } // // if (empty($_SESSION['access_number'])) { // api_statistics::increase_access_number(); // $_SESSION['access_number'] = 1; // } require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_document.php'; ?> <!-- Menu --> <nav id="main-menu" class="uk-navbar uk-margin-large-bottom" data-uk-sticky> <a href="<?php echo LINK_ROOT . '/index.php#main-content' ?>" class="uk-navbar-brand uk-hidden-small" data-uk-tooltip title="Trang Chủ"><i class="uk-icon-home"></i></a> <ul class="uk-navbar-nav uk-hidden-small"> <li> <a href="<?php echo LINK_ROOT . '/about_us.php#main-content' ?>" data-uk-tooltip title="Giới thiệu">Giới Thiệu</a> </li> <li data-uk-dropdown="" class="uk-parent"> <a href="<?php echo LINK_ROOT . '/document.php#main-content' ?>">Danh Mục</a> <?php $categories = api_document::get_all_document_categories(); if (!empty($categories) && count($categories) > 0) { ?> <div class="uk-dropdown uk-dropdown-navbar" style=""> <ul class="uk-nav uk-nav-navbar"> <?php foreach ($categories as $item) { ?> <li> <a href="<?php echo LINK_ROOT . '/document.php?cat_id=' . $item['cat_id'] ?>#main-content"><?php echo $item['cat_name']; ?></a> </li> <?php } ?> </ul> </div> <?php }?> </li> <li> <a href="document.php#main-content" data-uk-tooltip title="Danh sách toàn bộ bài tập">Bài Tập</a> </li> <li> <a href="news.php#main-content" data-uk-tooltip title="Xem những tin tức của chúng tôi">Tin Tức</a> </li> <li> <a href="contact.php#form_data" data-uk-tooltip title="Gửi câu hỏi của bạn qua email của chúng tôi">Hỏi Đáp</a> </li> <?php if (empty($_SESSION['user_login'])) { ?> <li> <a href="register.php#main-content" data-uk-tooltip title="Đăng kí tài khoản khách hàng">Đăng Kí</a> </li> <li> <a href="login.php#form_data" data-uk-tooltip title="Đăng nhập vào khu vực khách hàng">Đăng Nhập</a> </li> <?php } if (!empty($_SESSION['user_login'])) { ?> <li> <a href="document_manage.php#main-content" data-uk-tooltip title="Quản lý các bài tập đã đặt mua">Quản lý bài tập</a> </li> <li> <a href="change_password.php#main-content" data-uk-tooltip title="Đổi mật khẩu khách hàng">Đổi Mật Khẩu</a> </li> <li> <a href="logout.php" data-uk-tooltip title="Đăng xuất khỏi khu vực khách hàng">Thoát</a> </li> <?php } ?> </ul> <div class="uk-navbar-flip"> <ul class="uk-navbar-nav"> <?php if (!empty($_SESSION['user_login'])) { ?> <li style="padding: 10px;">Xin chào <?php echo $_SESSION['user']; ?></li> <?php } ?> <li><a href="<?php echo LINK_ROOT . '/cart.php' ?>" data-uk-tooltip title="Giỏ hàng"><i class="uk-icon-shopping-cart"></i></a></li> </ul> </div> <a data-uk-offcanvas="" class="uk-navbar-toggle uk-visible-small" href="#offcanvas"></a> <div class="uk-navbar-brand uk-navbar-center uk-visible-small">huanluyenviencanhan.com.vn</div> </nav> <!-- Offcanvas Menu --> <div class="uk-offcanvas" id="offcanvas"> <div class="uk-offcanvas-bar"> <ul class="uk-nav uk-nav-offcanvas" data-uk-nav=""> <li> <a href="<?php echo LINK_ROOT . '/about_us.php' ?>" data-uk-tooltip title="Giới thiệu">Giới Thiệu</a> </li> <li> <a href="document.php#main-content" data-uk-tooltip title="Danh mục các bài tập">Danh Mục</a> </li> <li> <a href="document.php#main-content" data-uk-tooltip title="Danh sách toàn bộ bài tập">Bài Tập</a> </li> <li> <a href="news.php#main-content" data-uk-tooltip title="Danh sách toàn bộ bài tập">Tin Tức</a> </li> <li> <a href="contact.php#main-content" data-uk-tooltip title="Liên hệ với chúng tôi">Hỏi Đáp</a> </li> <li> <a href="cart.php#main-content" data-uk-tooltip title="Danh sách toàn bộ bài tập">Giỏ Hàng</a> </li> <?php if (empty($_SESSION['user_login'])) { ?> <li> <a href="register.php#main-content" data-uk-tooltip title="Đăng kí tài khoản khách hàng">Đăng Kí</a> </li> <li> <a href="login.php#form_data" data-uk-tooltip title="Đăng nhập vào khu vực khách hàng">Đăng Nhập</a> </li> <?php } if (!empty($_SESSION['user_login'])) { ?> <li> <a href="document_manage.php#main-content" data-uk-tooltip title="Quản lý các bài tập đã đặt mua">Quản lý bài tập</a> </li> <li> <a href="change_password.php#main-content" data-uk-tooltip title="Đổi mật khẩu khách hàng">Đổi Mật Khẩu</a> </li> <li> <a href="logout.php" data-uk-tooltip title="Đăng xuất khỏi khu vực khách hàng">Thoát</a> </li> <?php } ?> </ul> </div> </div> <!-- End Offcanvas Menu --> <!-- End Menu -->
04-huanluyenviencanhan
trunk/master/include/menu.php
PHP
gpl3
7,191
<?php session_start(); require_once dirname(dirname(__FILE__)) . '/shared/libraries/lib_redirect.php'; if (empty($_SESSION['user_login']) || !($_SESSION['user'] === 'Admin')) { lib_redirect::Redirect('/login.php'); }
04-huanluyenviencanhan
trunk/master/include/check_user_login.php
PHP
gpl3
227
<?php function latest_news($news_num) { $list = api_news::get_all_latest_news($news_num); if (empty($list) || count($list) == 0) { echo "Chưa có bài báo nào."; } else { foreach ($list as $item) { ?> <div class="ts-latest-news-item"> <table> <tr> <td> <a href="news_detail.php?news_id=<?php echo $item['news_id']; ?>"> <img src="<?php echo LINK_ROOT . DIR_SHARED_LAYOUT_IMAGES_ICONS . 'news.png' ?>" alt="News"/> </a> </td> <td rowspan="2"> <div class='ts-item-title'><a href="news_detail.php?news_id=<?php echo $item['news_id']; ?>"><?php echo $item['news_title']; ?></a> </div> <?php $date = date_create($item["news_added_date"]); $date_str = date_format($date, "d/m/Y H:i"); ?> <div class='ts-item-date'>Ngày gửi: <?php echo $date_str; ?></div> </td> </tr> </table> </div> <?php } } } function show_news_category_group($category) { $count_total_newses = api_news::count_news_by_category_id($category['cat_news_id']); $newses = api_news::get_all_news_by_category_id($category['cat_news_id']); $list = $newses; ?> <div class="uk-panel uk-margin-bottom"> <h3 class="ts-category-title"> <a href="<?php echo LINK_ROOT ?>/news.php" data-uk-tooltip title="Xem tin tức thuộc <b style='color: #fff;'><?php echo $category['cate_news_name']; ?></b>"> <i class="uk-icon-folder-open"></i> <?php echo $category['cate_news_name']; ?> <span>(<?php echo $count_total_newses; ?> tin)</span> </a> </h3> <div class="ts-category-content"> <?php if (empty($list) || count($list) == 0) { echo "Chưa có tin tức nào"; } else { foreach ($list as $item) { ?> <div class="ts-item"> <table> <tr> <td> <a href="news_detail.php?news_id=<?php echo $item['news_id']; ?>"> <img src="<?php echo LINK_ROOT . DIR_SHARED_LAYOUT_IMAGES_ICONS . 'news.png' ?>" alt="News"/> </a> </td> <td rowspan="2"> <div class='ts-item-title'><a href="news_detail.php?news_id=<?php echo $item['news_id']; ?>"><?php echo $item['news_title'] ?></a> </div> <?php $date = date_create($item["news_added_date"]); $date_str = date_format($date, "d/m/Y H:i"); ?> <div class='ts-item-date'>Ngày gửi: <?php echo $date_str; ?></div> </td> </tr> </table> </div> <?php } } ?> </div> </div> <?php } function show_category_group($category, $maximum_docs_show) { $count_total_docs = api_document::count_document_by_category_id($category['cat_id']); $documents = api_document::get_all_documents_by_category_id($category['cat_id']); $list = array(); if (count($documents) < $maximum_docs_show || $maximum_docs_show == -1) { $list = $documents; } else { $random_keys = array_rand($documents, $maximum_docs_show); for ($index = 0; $index < $maximum_docs_show; $index++) { $list[count($list)] = $documents[$random_keys[$index]]; } } ?> <div class="uk-panel uk-margin-bottom"> <h3 class="ts-category-title"> <a href="<?php echo LINK_ROOT ?>/document.php?cat_id=<?php echo $category['cat_id']; ?>" data-uk-tooltip title="Xem bài tập thuộc <b style='color: #fff;'><?php echo $category['cat_name']; ?></b>"> <i class="uk-icon-folder-open"></i> <?php echo $category['cat_name']; ?> <span>(<?php echo $count_total_docs; ?> bài)</span> </a> </h3> <?php show_content_group($list); ?> </div> <?php } function show_content_group($list) { ?> <div class="ts-category-content"> <?php if (empty($list) || count($list) == 0) { echo "Không có bài tập nào."; } else { foreach ($list as $item) { $doc_img = "doc.png"; if (!empty($item['doc_img_url'])) { $doc_img = $item['doc_img_url']; } ?> <div class="ts-item"> <table> <tr> <td> <a href="document_detail.php?doc_id=<?php echo $item['doc_id']; ?>"> <img src="<?php echo LINK_ROOT . DIR_SHARED_UPLOAD_IMAGES_DOCUMENT . $doc_img; ?>" alt="Document"/> </a> </td> <td rowspan="2"> <div class='ts-item-title'><a href="document_detail.php?doc_id=<?php echo $item['doc_id']; ?>"><?php echo $item['doc_name'] ?></a> </div> <?php $date = date_create($item["doc_added_date"]); $date_str = date_format($date, "d/m/Y H:i"); ?> <div class='ts-item-date'>Ngày gửi: <?php echo $date_str; ?></div> </td> </tr> </table> </div> <?php } } ?> </div> <?php } function show_root_list() { $root_list = api_multi_level::get_root_document_categories(); if (empty($root_list) || count($root_list) == 0) { echo "Chưa có danh mục nào."; } else { foreach ($root_list as $root_item) { ?> <li onclick="filldata('<?php echo $root_item['cat_id']; ?>');"> <a href="javascript:void(0)"><i class="uk-icon-plus"></i></a> <a href="document.php?cat_id=<?php echo $root_item['cat_id']; ?>"><i class="uk-icon-folder"></i> <?php echo $root_item['cat_name']; ?></a> </li> <?php } } } function show_news_root_list() { $root_list = api_multi_level::get_root_news_categories(); if (empty($root_list) || count($root_list) == 0) { echo "Chưa có danh mục nào."; } else { foreach ($root_list as $root_item) { ?> <li onclick="filldata('<?php echo $root_item['cat_news_id']; ?>');"> <a href="javascript:void(0)"><i class="uk-icon-plus"></i></a> <a href="news.php?cat_id=<?php echo $root_item['cat_news_id']; ?>"><i class="uk-icon-folder"></i> <?php echo $root_item['cate_news_name']; ?></a> </li> <?php } } }
04-huanluyenviencanhan
trunk/master/include/usable_functions.php
PHP
gpl3
9,377
<link rel="stylesheet" href="<?php echo LINK_ROOT . DIR_SHARED_LAYOUT_CSS ?>site.css"> <link rel="stylesheet" href="<?php echo LINK_ROOT . DIR_SHARED_LAYOUT_CSS ?>ts.css">
04-huanluyenviencanhan
trunk/master/include/head_css.php
PHP
gpl3
174
<footer> <div class="ts-center"> Designed by <a href="http://facebook.com/TechStormTeam">TechStorm</a> </div> </footer>
04-huanluyenviencanhan
trunk/master/include/footer.php
Hack
gpl3
127
<!-- Slider --> <div id="wowslider-container1" style="margin-top: 50px;"> <div class="ws_images"><ul> <li><img src="<?php echo LINK_ROOT . DIR_SHARED_LAYOUT_IMAGES_SLIDESHOW ?>images/1.jpg" alt="huanluyenviencanhan.com.vn" title="huanluyenviencanhan.com.vn" id="wows1_0"/></li> <li><img src="<?php echo LINK_ROOT . DIR_SHARED_LAYOUT_IMAGES_SLIDESHOW ?>images/2.jpg" alt="huanluyenviencanhan.com.vn" title="huanluyenviencanhan.com.vn" id="wows1_1"/></li> <li><img src="<?php echo LINK_ROOT . DIR_SHARED_LAYOUT_IMAGES_SLIDESHOW ?>images/3.jpg" alt="huanluyenviencanhan.com.vn" title="huanluyenviencanhan.com.vn" id="wows1_2"/></li> </ul></div> <div class="ws_bullets"><div> <a href="#" title="1"><img src="<?php echo LINK_ROOT . DIR_SHARED_LAYOUT_IMAGES_SLIDESHOW ?>tooltips/1.jpg" alt="1"/>1</a> <a href="#" title="2"><img src="<?php echo LINK_ROOT . DIR_SHARED_LAYOUT_IMAGES_SLIDESHOW ?>tooltips/2.jpg" alt="2"/>2</a> <a href="#" title="3"><img src="<?php echo LINK_ROOT . DIR_SHARED_LAYOUT_IMAGES_SLIDESHOW ?>tooltips/3.jpg" alt="3"/>3</a> </div></div> </div> <script type="text/javascript" src="<?php echo LINK_ROOT . DIR_SHARED_PLUGIN_WOWSLIDER_JS ?>wowslider.js"></script> <script type="text/javascript" src="<?php echo LINK_ROOT . DIR_SHARED_PLUGIN_WOWSLIDER_JS ?>script.js"></script> <!-- End Slider -->
04-huanluyenviencanhan
trunk/master/include/slider.php
PHP
gpl3
1,340
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="description" content="chuyên tư vấn thiết kế giáo án giảm cân, giáo án tăng cân, giáo án thể hình... an toàn hiệu quả | liên hệ : 0933337258"> <meta name="title" content="cách giảm cân | giáo án giảm cân"> <meta name="author" content="Huỳnh Ngọc An"> <meta name="keyword" content="giam can , giảm cân, huan luyen vien ca nhan, huấn luyện viên cá nhân, giao an the hinh, giáo án thể hình"> <title><?php echo $title; ?></title> <!-- Favicon --> <link rel="icon" type="image/png" href="<?php echo LINK_ROOT . '/favicon.png' ?>"> <!-- UIKit CSS --> <link href="<?php echo LINK_ROOT . DIR_SHARED_LAYOUT_UIKIT_CSS ?>uikit.min.css" rel="stylesheet" > <link href="<?php echo LINK_ROOT . DIR_SHARED_LAYOUT_UIKIT_CSS ?>uikit.gradient.min.css" rel="stylesheet" > <link href="<?php echo LINK_ROOT . DIR_SHARED_LAYOUT_UIKIT_CSS ?>/addons/uikit.gradient.addons.min.css" rel="stylesheet" > <!-- Slider CSS --> <link href="<?php echo LINK_ROOT . DIR_SHARED_PLUGIN_WOWSLIDER_CSS ?>slider.css" rel="stylesheet" > <!-- Jquery v1.11.1 + UIKit JS --> <script src="<?php echo LINK_ROOT . DIR_SHARED_LAYOUT_JS ?>jquery-1.11.1.min.js" type="text/javascript"></script> <script src="<?php echo LINK_ROOT . DIR_SHARED_LAYOUT_UIKIT_JS ?>uikit.min.js"></script> <script src="<?php echo LINK_ROOT . DIR_SHARED_LAYOUT_UIKIT_JS ?>addons/notify.min.js"></script> <script src="<?php echo LINK_ROOT . DIR_SHARED_LAYOUT_UIKIT_JS ?>addons/datepicker.min.js"></script> <script src="<?php echo LINK_ROOT . DIR_SHARED_LAYOUT_UIKIT_JS ?>addons/sticky.min.js"></script> <!-- Addon CSS files + Javascripts Functions--> <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'head_css.php'; require_once DOCUMENT_ROOT . DIR_INCLUDE . 'head_script.php'; ?>
04-huanluyenviencanhan
trunk/master/include/head.php
PHP
gpl3
1,884
<?php //require section require_once dirname(__FILE__) . '/shared/config/config.php'; require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_security.php'; $title = 'Đăng Nhập'; ?> <!DOCTYPE html> <html> <head> <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'head.php'; ?> </head> <body> <?php if (!empty($_POST)) { $txt_email = $_POST['txt_email']; $txt_password = $_POST['txt_password']; $result = api_security::login($txt_email, $txt_password); if ($result['user_login'] === 'success') { session_start(); $_SESSION['user_login'] = 'logined'; if ($result['user_type'] == 1) { $_SESSION['user'] = 'Admin'; lib_redirect::Redirect('/admin/index.php'); } else { $_SESSION['user'] = $result['email']; $_SESSION['user_info'] = $result; lib_redirect::Redirect('/index.php'); } } else { $error = "Đăng nhập thất bại."; } } ?> <div class="uk-container uk-container-center uk-margin-top"> <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'menu.php'; require_once DOCUMENT_ROOT . DIR_INCLUDE . 'slider.php'; ?> <!-- Changable content --> <section id="main-content" class="ts-body-container uk-panel uk-panel-box ts-padding-large"> <article class="uk-article"> <h1 class="uk-article-title ts-color-primary">Đăng Nhập</h1> <hr class="uk-article-divider"> <div> <form name="form_data" id="form_data" class="uk-form" method="POST" enctype="multipart/form-data" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>"> <!-- Hidden Value Section --> <!-- End Hidden Value Section --> <div class="error"> <?php if (!empty($error)) { echo $error; } ?> </div> <table class="ts-table"> <tr> <th><label for="txt_email">Email:<span class="ts-alert">*</span></label></th> <td><input name="txt_email" class="uk-form-width-large" type="text" placeholder="Email" required></td> </tr> <tr> <th><label for="txt_password">Mật khẩu:<span class="ts-alert">*</span></label></th> <td><input name="txt_password" class="uk-form-width-large" type="password" placeholder="Mật khẩu" required></td> </tr> <tr> <th></th> <td><input type="submit" name="btn_submit" value="Đăng Nhập" class="uk-button uk-button-large uk-button-primary"></td> </tr> </table> </form> </div> </article> </section> <!-- End changable content --> <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'footer.php'; ?> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/login.php
PHP
gpl3
3,515
<?php //require section require_once dirname(__FILE__) . '/shared/config/config.php'; require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_security.php'; $title = 'Đổi Mật Khẩu'; ?> <!DOCTYPE html> <html> <head> <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'head.php'; ?> </head> <body> <div class="uk-container uk-container-center uk-margin-top"> <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'menu.php'; require_once DOCUMENT_ROOT . DIR_INCLUDE . 'slider.php'; $email = $_SESSION['user']; $password_old = ""; $password = ""; $password_confirm = ""; if (!empty($_POST)) { if (!empty($_POST['txt_password_old'])) { $password_old = $_POST['txt_password_old']; } if (!empty($_POST['txt_password'])) { $password = $_POST['txt_password']; } if (!empty($_POST['txt_password_confirm'])) { $password_confirm = $_POST['txt_password_confirm']; } $error_show = api_security::validate_change_password($email, $password_old, $password, $password_confirm); if (empty($error_show)) { if (api_security::change_password($email, $password)) { $success_info = "Đổi mật khẩu thành công."; } } } ?> <!-- Changable content --> <section id="main-content" class="ts-body-container uk-panel uk-panel-box ts-padding-large"> <article class="uk-article"> <h1 class="uk-article-title ts-color-primary">Đổi mật khẩu</h1> <hr class="uk-article-divider"> <div> <form name="form_data" id="form_data" class="uk-form" method="POST" enctype="multipart/form-data" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>"> <!-- Hidden Value Section --> <!-- End Hidden Value Section --> <?php if (!empty($error_show)) {?> <div class="error">Lỗi: <?php echo $error_show; ?></div> <?php } else if (!empty($success_info)) {?> <div class="success"><?php echo $success_info; ?></div> <?php }?> <table class="ts-table"> <tr> <th><label for="txt_password_old">Mật Mã Cũ:<span class="ts-alert">*</span></label></th> <td><input name="txt_password_old" class="uk-form-width-large" value="" type="password" placeholder="Mật mã cũ" required></td> </tr> <tr> <th><label for="txt_password">Mật Mã Mới:<span class="ts-alert">*</span></label></th> <td><input name="txt_password" class="uk-form-width-large" value="" type="password" placeholder="Mật mã mới" required></td> </tr> <tr> <th><label for="txt_password_confirm">Xác Nhận Mật Mã Mới:<span class="ts-alert">*</span></label></th> <td><input name="txt_password_confirm" class="uk-form-width-large" value="" type="password" placeholder="Xác nhận mật mã mới" required></td> </tr> <tr> <th></th> <td><input type="submit" name="btn_submit" value="Đổi mật khẩu" class="uk-button uk-button-large uk-button-primary"></td> </tr> </table> </form> </div> </article> </section> <!-- End changable content --> <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'footer.php'; ?> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/change_password.php
PHP
gpl3
4,466
<?php //require section require_once dirname(__FILE__) . '/shared/config/config.php'; require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_document.php'; require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_document_manage.php'; require_once DOCUMENT_ROOT . DIR_SHARED_LIBRARIES . 'lib_redirect.php'; $title = 'Chi tiết bài tập'; $doc_id = 0; if (!empty($_GET['doc_id'])) { $doc_id = $_GET['doc_id']; } else { lib_redirect::Redirect('/document_manage.php'); } $document = api_document::get_document_by_id($doc_id); ?> <!DOCTYPE html> <html> <head> <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'head.php'; ?> <link href="<?php echo LINK_ROOT . DIR_SHARED_LAYOUT_CSS . 'lightbox.css' ?>" rel='stylesheet'> </head> <body> <!--script to close opened image by keypress--> <script type="text/javascript"> $(document).keypress(function () { if (window.location.href.indexOf("img-box") > -1) { window.location = '#main-content'; } }); </script> <div class="uk-container uk-container-center uk-margin-top"> <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'menu.php'; require_once DOCUMENT_ROOT . DIR_INCLUDE . 'slider.php'; $user = $_SESSION['user_info']; $buy_status = api_document_manage::check_if_doc_paid($user['user_id'], $document['doc_id']); ?> <section id='main-content' class="ts-body-container uk-panel uk-panel-box ts-padding-large"> <?php if (empty($document)) { echo "<h2>Tài liệu không tìm thấy.</h2>"; } else { $doc_img = "doc.png"; if (!empty($document['doc_img_url'])) { $doc_img = $document['doc_img_url']; } ?> <h2>Chi tiết tài liệu</h2> <?php if (!empty($success_info)) { ?> <h3> <div class="success"><?php echo $success_info; ?></div> </h3> <?php } ?> <div class="ts-detail-wrapper"> <div class="ts-img-left"> <!--image in document image folder--> <a class="lightbox" href="#img-box"> <img src="<?php echo LINK_ROOT . DIR_SHARED_UPLOAD_IMAGES_DOCUMENT . $doc_img; ?>"/> </a> <div class="lightbox-target" id="img-box" onclick="window.location = '#main-content'"> <img src="<?php echo LINK_ROOT . DIR_SHARED_UPLOAD_IMAGES_DOCUMENT . $doc_img; ?>"/> <a class="lightbox-close" href="#main-content"></a> </div> <div class="uk-text-center"><i><?php echo $document['doc_name']; ?></i></div> </div> <div class="ts-content-right"> <table> <tr> <th>Mã bài tập:</th> <td><?php echo $document['doc_id']; ?></td> </tr> <tr> <th>Tên bài tập:</th> <td><?php echo $document['doc_name']; ?></td> </tr> <tr> <th>Mô tả:</th> <td> <?php echo $document['doc_detail']; ?> </td> </tr> <tr> <th>Thuộc danh mục:</th> <td><?php echo $document['doc_cat_name']; ?></td> </tr> <tr> <th>Giá:</th> <td> <b style="color: #d35400;"><?php echo number_format($document['doc_price'], 0, '.', ','); ?> vnđ</b></td> </tr> <tr> <th>Ngày tạo:</th> <?php $date = date_create($document["doc_added_date"]); $date_str = date_format($date, "d/m/Y H:i"); ?> <td><?php echo $date_str; ?></td> </tr> </table> </div> </div> <form action="?doc_id=<?php echo $document['doc_id']; ?>" name="form_add_to_card" method="POST"> <?php if($buy_status) : ?> <div class="uk-text-center uk-margin-bottom"> Để tải tài liệu, bạn hãy bấm nút <b>"Tải về"</b> hoặc bấm <b>chuột phải</b> vào nút <b>"Tải về"</b> chọn <b>"Save Link As..."</b> </div> <?php endif; ?> <div class="uk-text-center"> <a href="document_manage.php" class='uk-button'>Quay lại</a> <?php if ($buy_status) : ?> <a href="<?php echo LINK_ROOT . DIR_SHARED_UPLOAD_DOCUMENTS . $document['doc_file']; ?>" class="uk-button uk-button-primary">Tải về</a> <?php endif; ?> </div> </form> <?php } ?> </section> <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'footer.php'; ?> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/doc_bought_detail.php
PHP
gpl3
5,994
<?php //require section require_once dirname(__FILE__) . '/shared/config/config.php'; require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_document.php'; require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_document_manage.php'; require_once DOCUMENT_ROOT . DIR_SHARED_LIBRARIES . 'lib_redirect.php'; $title = 'Chi tiết bài tập'; $doc_id = 0; if (!empty($_GET['doc_id'])) { $doc_id = $_GET['doc_id']; } $document = api_document::get_document_by_id($doc_id); ?> <!DOCTYPE html> <html> <head> <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'head.php'; ?> <link href="<?php echo LINK_ROOT . DIR_SHARED_LAYOUT_CSS . 'lightbox.css' ?>" rel='stylesheet'> </head> <body> <!--script to close opened image by keypress--> <script type="text/javascript"> $(document).keypress(function () { if (window.location.href.indexOf("img-box") > -1) { window.location = '#main-content'; } }); </script> <div class="uk-container uk-container-center uk-margin-top"> <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'menu.php'; require_once DOCUMENT_ROOT . DIR_INCLUDE . 'slider.php'; $add_doc_id = 0; if (!empty($_POST['add_doc_id'])) { $add_doc_id = $_POST['add_doc_id']; } if ($add_doc_id != 0) { if (empty($_SESSION['user_login'])) { $success_info = "Bạn chưa đăng nhập, vui lòng đăng nhập trước khi thêm giỏ hàng."; } else { if (empty($_SESSION['cart'][$_SESSION['user']])) { $cart = array(); $cart[$_SESSION['user']] = array(); $_SESSION['cart'] = $cart; } if (in_array($add_doc_id, $_SESSION['cart'][$_SESSION['user']])) { $success_info = "Tài liệu này đã có trong giỏ hàng, hãy chọn cái khác."; } else { $count = count($_SESSION['cart'][$_SESSION['user']]); $array_cart = $_SESSION['cart'][$_SESSION['user']]; $array_cart[$count] = $add_doc_id; $_SESSION['cart'][$_SESSION['user']] = $array_cart; $success_info = "Đã thêm vào giỏ hàng với mã hàng là: " . $add_doc_id; } } } ?> <section id='main-content' class="ts-body-container uk-panel uk-panel-box ts-padding-large"> <?php if (empty($document)) { echo "<h2>Tài liệu không tìm thấy.</h2>"; } else { $doc_img = "doc.png"; if (!empty($document['doc_img_url'])) { $doc_img = $document['doc_img_url']; } ?> <h2>Chi tiết tài liệu</h2> <?php if (!empty($success_info)) { ?> <h3> <div class="success"><?php echo $success_info; ?></div> </h3> <?php } ?> <div class="ts-detail-wrapper"> <div class="ts-img-left"> <!--image in document image folder--> <a class="lightbox" href="#img-box"> <img src="<?php echo LINK_ROOT . DIR_SHARED_UPLOAD_IMAGES_DOCUMENT . $doc_img; ?>"/> </a> <div class="lightbox-target" id="img-box" onclick="window.location = '#main-content'"> <img src="<?php echo LINK_ROOT . DIR_SHARED_UPLOAD_IMAGES_DOCUMENT . $doc_img; ?>"/> <a class="lightbox-close" href="#main-content"></a> </div> <div class="uk-text-center"><i><?php echo $document['doc_name']; ?></i></div> </div> <div class="ts-content-right"> <table> <tr> <th>Mã bài tập:</th> <td><?php echo $document['doc_id']; ?></td> </tr> <tr> <th>Tên bài tập:</th> <td><?php echo $document['doc_name']; ?></td> </tr> <tr> <th>Mô tả:</th> <td> <?php echo $document['doc_detail']; ?> </td> </tr> <tr> <th>Thuộc danh mục:</th> <td><?php echo $document['doc_cat_name']; ?></td> </tr> <tr> <th>Giá:</th> <td> <b style="color: #d35400;"><?php echo number_format($document['doc_price'], 0, '.', ','); ?> vnđ</b></td> </tr> <tr> <th>Ngày tạo:</th> <?php $date = date_create($document["doc_added_date"]); $date_str = date_format($date, "d/m/Y H:i"); ?> <td><?php echo $date_str; ?></td> </tr> </table> </div> </div> <form action="?doc_id=<?php echo $document['doc_id']; ?>" name="form_add_to_card" method="POST"> <div class="uk-text-center"> <a href="document.php" class='uk-button'>Quay lại</a> <input type="hidden" name="add_doc_id" value="<?php echo $document['doc_id']; ?>"/> <?php $user = NULL; $check_buy = NULL; $check_wait = NULL; if (!empty($_SESSION['user_info'])) { $user = $_SESSION['user_info']; $check_buy = api_document_manage::check_if_doc_paid($user['user_id'], $doc_id); $check_wait = api_document_manage::check_if_doc_wait($user['user_id'], $doc_id); } if ($check_buy == TRUE) { ?> <span style="color: green;"><i class="uk-icon-check-circle"></i> Đã Mua!</span> <?php } else if ($check_wait == TRUE) { ?> <span style="color: #D35400;"><i class="uk-icon-exclamation-circle"></i> Chờ duyệt!</span> <?php } else { ?> <input type="submit" name="btn_submit" class="uk-button uk-button-primary" value="Thêm vào giỏ hàng"> <?php } ?> </div> </form> <?php } ?> </section> <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'footer.php'; ?> </div> </body> </html>
04-huanluyenviencanhan
trunk/master/document_detail.php
PHP
gpl3
7,780
VERSION 5.00 Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx" Begin VB.Form frm0file Caption = "0-Length File Creator" ClientHeight = 2100 ClientLeft = 60 ClientTop = 345 ClientWidth = 5385 Icon = "frm0file.frx":0000 LinkTopic = "Form1" ScaleHeight = 2100 ScaleWidth = 5385 StartUpPosition = 3 'Windows Default Begin VB.OptionButton optFile Caption = "Only this file" Enabled = 0 'False Height = 255 Left = 0 TabIndex = 7 Top = 840 Value = -1 'True Width = 1335 End Begin VB.OptionButton optDir Caption = "Entire directory" Enabled = 0 'False Height = 255 Left = 1320 TabIndex = 6 Top = 840 Width = 1455 End Begin VB.Frame fraAbout Height = 975 Left = 0 TabIndex = 5 Top = 1080 Width = 5295 Begin MSComDlg.CommonDialog cdgApri Left = 4440 Top = 120 _ExtentX = 847 _ExtentY = 847 _Version = 393216 End Begin VB.Label Label1 Caption = $"frm0file.frx":0442 Height = 615 Left = 120 TabIndex = 8 Top = 240 Width = 4935 End End Begin VB.CommandButton cmdGo Caption = "Go" Height = 255 Left = 3480 TabIndex = 4 Top = 840 Width = 1815 End Begin VB.CommandButton cmdOutput Caption = "Set Output Dir" Height = 255 Left = 4080 TabIndex = 3 Top = 480 Width = 1215 End Begin VB.CommandButton cmdInput Caption = "Set Input File" Height = 255 Left = 4080 TabIndex = 2 Top = 120 Width = 1215 End Begin VB.TextBox txtOutput Height = 285 Left = 0 TabIndex = 1 Top = 480 Width = 3975 End Begin VB.TextBox txtInput Height = 285 Left = 0 TabIndex = 0 Top = 120 Width = 3975 End End Attribute VB_Name = "frm0file" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Dim InputFile As String Dim OutputFile As String 'esegui il lavoro Private Sub cmdGo_Click() If optFile.Value = True Then Call CreateStubFile(txtInput.Text, txtOutput.Text) Else Call ProcessaDirectory(Mid(txtInput.Text, 1, InStrRev(txtInput.Text, "\")), txtOutput.Text) End If End Sub 'sceglia il file di input Private Sub cmdInput_Click() optFile.Value = True cdgApri.InitDir = App.Path cdgApri.DialogTitle = "Choose the input file" cdgApri.ShowOpen If cdgApri.fileName <> vbNullString Then InputFile = cdgApri.fileName 'Mid(cdgApri.FileName, InStrRev(cdgApri.FileName, "\") + 1) txtInput.Text = InputFile If (txtOutput.Text <> vbNullString) Then optFile.Enabled = True optDir.Enabled = True End If End If End Sub 'scegli il file di output Private Sub cmdOutput_Click() optFile.Value = True cdgApri.InitDir = App.Path cdgApri.DialogTitle = "Choose the output file" cdgApri.ShowSave If cdgApri.fileName <> vbNullString Then OutputFile = cdgApri.fileName txtOutput.Text = OutputFile If (txtInput.Text <> vbNullString) Then optFile.Enabled = True optDir.Enabled = True End If End If End Sub 'imposta il percorso di uscita come directory Private Sub optDir_Click() OutputFile = Mid(OutputFile, 1, InStrRev(OutputFile, "\")) txtOutput.Text = OutputFile 'InputFile = Mid(InputFile, 1, InStrRev(InputFile, "\")) 'txtInput.Text = InputFile End Sub 'ipmosta il percorso di uscita su un file Private Sub optFile_Click() OutputFile = OutputFile & Mid(InputFile, InStrRev(InputFile, "\") + 1) txtOutput.Text = OutputFile End Sub 'data una directory, crea uno stub per ogni file Private Sub ProcessaDirectory(ByRef directory As String, ByRef outDir As String) Dim dir As Variant Dim t As Variant Dim item As Variant Set t = New FileSystemObject Set dir = t.GetFolder(directory) 'dir.Path (directory) For Each item In dir.Files Call CreateStubFile(item.Name, outDir) Next item Set dir = Nothing Set t = Nothing End Sub 'crea un file di lunghezza 0 Private Sub CreateStubFile(ByRef infileName As String, ByRef outfileName As String) Dim inFile As String Dim outDir As String inFile = Mid(infileName, InStrRev(infileName, "\") + 1) outDir = Mid(outfileName, 1, InStrRev(outfileName, "\")) Open outDir & inFile For Output As #2 Close #2 End Sub
0-file-creator
trunk/frm0file.frm
Visual Basic 6.0
gpl2
5,618
del 0fileCreator.ex~ upx -9 -k 0fileCreator.exe
0-file-creator
trunk/UPX-Compressa.bat
Batchfile
gpl2
48
/* * Copyright 2011 Rodrigo Damazio * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.comm.encryption; import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import javax.crypto.spec.SecretKeySpec; public class PassKey { private static final String HASH_ALGORITHM = "MD5"; private static final String ENCRYPTION_KEY_TYPE = "AES"; private final byte[] keyBytes; private byte[] iv; private SecretKeySpec keySpec; public PassKey(String passPhrase, int numHashes) { // Use an MD5 to generate an arbitrary initialization vector this.keyBytes = passPhraseToKey(passPhrase, HASH_ALGORITHM, numHashes); } public PassKey(byte[] keyBytes) { this.keyBytes = keyBytes; } public byte[] getKeyBytes() { return keyBytes; } public SecretKeySpec getKeySpec() { if (keySpec == null) { keySpec = new SecretKeySpec(keyBytes, ENCRYPTION_KEY_TYPE); } return keySpec; } public byte[] getInitVector() { if (iv == null) { iv = doDigest(keyBytes, "MD5"); } return iv; } /** * Converts a user-entered pass phrase into a hashed binary value which is * used as the encryption key. */ private byte[] passPhraseToKey(String passphrase, String hashAlgorithm, int numHashes) { if (numHashes < 1) { throw new IllegalArgumentException("Need a positive hash count"); } byte[] passPhraseBytes; try { passPhraseBytes = passphrase.getBytes("UTF8"); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException("Bad passphrase encoding", e); } // Hash it multiple times to keep the paranoid people happy :) byte[] keyBytes = passPhraseBytes; for (int i = 0; i < numHashes; i++) { keyBytes = doDigest(keyBytes, hashAlgorithm); } return keyBytes; } private byte[] doDigest(byte[] data, String algorithm) { try { MessageDigest md = MessageDigest.getInstance(algorithm); md.update(data); return md.digest(); } catch (NoSuchAlgorithmException e) { throw new IllegalArgumentException("Algorithm not available", e); } } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/comm/encryption/PassKey.java
Java
asf20
2,727
/* * Copyright 2011 Rodrigo Damazio * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.comm.encryption; import java.io.InputStream; import java.io.OutputStream; import java.security.GeneralSecurityException; import javax.crypto.Cipher; import javax.crypto.CipherInputStream; import javax.crypto.CipherOutputStream; import javax.crypto.spec.IvParameterSpec; /** * Helper class for encrypting and decrypting payloads using arbitrary string passphrases. * This requires converting the passphrase into a byte array key. * This class also includes utilities for encoding that byte array in a string-safe way * for storage. * * @author Rodrigo Damazio */ public class Coder { static final String ENCRYPTION_ALGORITHM = "AES/CBC/PKCS7Padding"; private final PassKey key; public Coder(PassKey key) { this.key = key; } public byte[] encrypt(byte[] unencrypted) throws GeneralSecurityException { return doCipher(unencrypted, Cipher.ENCRYPT_MODE); } public byte[] decrypt(byte[] encrypted) throws GeneralSecurityException { return doCipher(encrypted, Cipher.DECRYPT_MODE); } private byte[] doCipher(byte[] original, int mode) throws GeneralSecurityException { Cipher cipher = createCipher(mode); return cipher.doFinal(original); } public InputStream wrapInputStream(InputStream inputStream) throws GeneralSecurityException { return new CipherInputStream(inputStream, createCipher(Cipher.DECRYPT_MODE)); } public OutputStream wrapOutputStream(OutputStream outputStream) throws GeneralSecurityException { return new CipherOutputStream(outputStream, createCipher(Cipher.ENCRYPT_MODE)); } private Cipher createCipher(int mode) throws GeneralSecurityException { Cipher cipher = Cipher.getInstance(ENCRYPTION_ALGORITHM); cipher.init(mode, key.getKeySpec(), new IvParameterSpec(key.getInitVector())); return cipher; } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/comm/encryption/Coder.java
Java
asf20
2,434
package org.damazio.notifier.comm.pairing; import java.util.Collection; import java.util.HashMap; import java.util.Map; public class DeviceManager { public static class Device { public final long deviceId; public final String ipAddress; public final String bluetoothAddress; public Device(long deviceId, String ipAddress, String bluetoothAddress) { this.deviceId = deviceId; this.ipAddress = ipAddress; this.bluetoothAddress = bluetoothAddress; } } private final Map<Long, Device> devicesById = new HashMap<Long, DeviceManager.Device>(); public Device getDeviceForId(long deviceId) { return devicesById.get(deviceId); } public Collection<Device> getAllDevices() { return devicesById.values(); } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/comm/pairing/DeviceManager.java
Java
asf20
770
package org.damazio.notifier.comm.transport.cloud; import static org.damazio.notifier.Constants.TAG; import java.util.Arrays; import org.damazio.notifier.event.EventManager; import org.damazio.notifier.protocol.Common.Event; import com.google.protobuf.InvalidProtocolBufferException; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; public class CloudMessageReceiver extends BroadcastReceiver { private static final String EVENT_EXTRA = "event"; @Override public void onReceive(Context context, Intent intent) { if (!"com.google.android.c2dm.intent.RECEIVE".equals(intent.getAction())) { Log.e(TAG, "Bad C2DM intent: " + intent); return; } // TODO: Handle payload > 1024 bytes byte[] eventBytes = intent.getExtras().getByteArray(EVENT_EXTRA); Event event; try { event = Event.parseFrom(eventBytes); } catch (InvalidProtocolBufferException e) { Log.e(TAG, "Got bad payload: " + Arrays.toString(eventBytes)); return; } EventManager eventManager = new EventManager(context); eventManager.handleRemoteEvent(event); } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/comm/transport/cloud/CloudMessageReceiver.java
Java
asf20
1,184
package org.damazio.notifier.comm.transport.cloud; import static org.damazio.notifier.Constants.TAG; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; public class RegistrationReceiver extends BroadcastReceiver { private static final String REGISTRATION_ACTION = "com.google.android.c2dm.intent.REGISTRATION"; @Override public void onReceive(Context context, Intent intent) { if (!intent.getAction().equals(REGISTRATION_ACTION)) { Log.e(TAG, "Got bad intent at C2DM registration receiver: " + intent); return; } String error = intent.getStringExtra("error"); if (error != null) { RegistrationManager.handleError(error); } String registrationId = intent.getStringExtra("registration_id"); RegistrationManager.registrationIdReceived(context, registrationId); } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/comm/transport/cloud/RegistrationReceiver.java
Java
asf20
902
package org.damazio.notifier.comm.transport; public enum TransportType { IP, BLUETOOTH, USB, CLOUD; }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/comm/transport/TransportType.java
Java
asf20
111
/* * Copyright 2011 Rodrigo Damazio * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.comm.transport; import org.damazio.notifier.NotifierService.NotifierServiceModule; import org.damazio.notifier.event.EventContext; import org.damazio.notifier.prefs.Preferences.PreferenceListener; /** * Listens to and receives remote events. * * @author Rodrigo Damazio */ public class RemoteEventReceiver implements NotifierServiceModule { private final EventContext eventContext; private final PreferenceListener preferenceListener = new PreferenceListener() { // TODO }; public RemoteEventReceiver(EventContext eventContext) { this.eventContext = eventContext; } public void onCreate() { // Register to learn about changes in transport methods. // This will also trigger the initial starting of the enabled ones. eventContext.getPreferences().registerListener(preferenceListener, true); } public void onDestroy() { eventContext.getPreferences().unregisterListener(preferenceListener); } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/comm/transport/RemoteEventReceiver.java
Java
asf20
1,572
package org.damazio.notifier.comm.transport; import static org.damazio.notifier.Constants.TAG; import org.damazio.notifier.event.EventContext; import org.damazio.notifier.protocol.Common.Event; import android.os.Handler; import android.os.HandlerThread; import android.os.Message; import android.os.Process; import android.util.Log; // TODO: Maybe this is overkill - should we use the DB for retries? public abstract class BaseEventSender { private static final int MSG_EVENT = 42; private static final long RETRY_BACKOFF_MS = 200L; private static final int MAX_RETRIES = 10; private static class EventState { public EventContext context; public Event event; public long eventId; public int retries = 0; public EventState(EventContext context, long eventId, Event event) { this.context = context; this.event = event; this.eventId = eventId; } } private class EventHandler implements Handler.Callback { public boolean handleMessage(Message msg) { if (msg.what != MSG_EVENT) { Log.e(TAG, "Got bad message type: " + msg.what); return true; } Object msgObj = msg.obj; if (!(msgObj instanceof Event)) { Log.e(TAG, "Got bad event object: " + msgObj.getClass().getName()); return true; } EventState state = (EventState) msgObj; boolean handled = handleEvent(state.context, state.eventId, state.event); if (handled) { state.context.getEventManager().markEventProcessed(state.eventId); } if (handled || !scheduleRetry(msg, state)) { // We're done with this message msg.recycle(); } return true; } } private HandlerThread sendThread; private Handler sendHandler; public void start() { sendThread = new HandlerThread( "sender-" + getTransportType(), Process.THREAD_PRIORITY_BACKGROUND); sendThread.start(); sendHandler = new Handler(sendThread.getLooper(), new EventHandler()); } private boolean scheduleRetry(Message msg, EventState state) { if (state.retries >= MAX_RETRIES) { Log.w(TAG, "Too many retries, giving up."); return false; } // Schedule a retry state.retries++; long delayMs = state.retries * RETRY_BACKOFF_MS; sendHandler.sendMessageDelayed(msg, delayMs); return true; } public void sendEvent(EventContext context, long eventId, Event event) { EventState state = new EventState(context, eventId, event); Message message = Message.obtain(sendHandler, MSG_EVENT, state); message.sendToTarget(); } public void shutdown() { sendThread.quit(); try { sendThread.join(); } catch (InterruptedException e) { Log.w(TAG, "Got exception waiting for send thread for " + getTransportType(), e); } } protected abstract boolean handleEvent(EventContext context, long eventId, Event event); protected abstract TransportType getTransportType(); }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/comm/transport/BaseEventSender.java
Java
asf20
2,975
package org.damazio.notifier.comm.transport; import java.util.EnumMap; import java.util.EnumSet; import org.damazio.notifier.NotifierService.NotifierServiceModule; import org.damazio.notifier.comm.transport.ip.IpEventSender; import org.damazio.notifier.event.EventContext; import org.damazio.notifier.event.EventListener; import org.damazio.notifier.prefs.Preferences; import org.damazio.notifier.prefs.Preferences.PreferenceListener; import org.damazio.notifier.protocol.Common.Event; import org.damazio.notifier.util.DeviceUtils; /** * Sends local events to remote devices. * * @author Rodrigo Damazio */ public class LocalEventSender implements EventListener, NotifierServiceModule { private final EnumMap<TransportType, BaseEventSender> senders = new EnumMap<TransportType, BaseEventSender>(TransportType.class); private final PreferenceListener preferenceListener = new PreferenceListener() { @Override public void onTransportStateChanged(TransportType type, boolean enabled) { synchronized (senders) { if (enabled) { onTransportEnabled(type); } else { onTransportDisabled(type); } } } }; private final EventContext eventContext; public LocalEventSender(EventContext eventContext) { this.eventContext = eventContext; } public void onCreate() { // Register for changes on transport types, and initially get a // notification about the current types. eventContext.getPreferences().registerListener(preferenceListener, true); } public void onDestroy() { eventContext.getPreferences().unregisterListener(preferenceListener); // Shutdown all transports. synchronized (senders) { for (TransportType type : TransportType.values()) { onTransportDisabled(type); } } } private void onTransportEnabled(TransportType type) { BaseEventSender sender = null; switch (type) { case BLUETOOTH: // TODO break; case CLOUD: // TODO break; case IP: sender = new IpEventSender(eventContext); break; case USB: // TODO break; } if (sender != null) { sender.start(); senders.put(type, sender); } } private void onTransportDisabled(TransportType type) { BaseEventSender sender = senders.remove(type); if (sender != null) { sender.shutdown(); } } @Override public void onNewEvent(EventContext context, long eventId, Event event, boolean isLocal, boolean isCommand) { if (!isLocal) { // Non-local events should not be sent. return; } // Add source device ID to the event. event = event.toBuilder() .setSourceDeviceId(DeviceUtils.getDeviceId(context.getAndroidContext())) .build(); Preferences preferences = context.getPreferences(); EnumSet<TransportType> transportTypes = preferences.getEnabledTransports(); synchronized (senders) { for (TransportType transportType : transportTypes) { BaseEventSender sender = senders.get(transportType); sender.sendEvent(context, eventId, event); } } } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/comm/transport/LocalEventSender.java
Java
asf20
3,173
package org.damazio.notifier.comm.transport.ip; import static org.damazio.notifier.Constants.TAG; import java.io.IOException; import java.io.OutputStream; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; import java.net.SocketAddress; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Collection; import org.damazio.notifier.comm.pairing.DeviceManager; import org.damazio.notifier.comm.pairing.DeviceManager.Device; import org.damazio.notifier.comm.transport.BaseEventSender; import org.damazio.notifier.comm.transport.TransportType; import org.damazio.notifier.event.EventContext; import org.damazio.notifier.prefs.Preferences; import org.damazio.notifier.protocol.Common.Event; import android.content.Context; import android.net.ConnectivityManager; import android.net.wifi.WifiManager; import android.util.Log; public class IpEventSender extends BaseEventSender { private static final int DEFAULT_PORT = 10600; private static final int TCP_CONNECT_TIMEOUT_MS = 10 * 1000; private final EventContext context; private final WifiManager wifi; private final ConnectivityManager connectivity; public IpEventSender(EventContext context) { this.context = context; Context androidContext = context.getAndroidContext(); this.wifi = (WifiManager) androidContext.getSystemService(Context.WIFI_SERVICE); this.connectivity = (ConnectivityManager) androidContext.getSystemService(Context.CONNECTIVITY_SERVICE); } @Override protected boolean handleEvent(EventContext context, long eventId, Event event) { byte[] payload = event.toByteArray(); Preferences preferences = context.getPreferences(); // TODO: This belongs somewhere common to all transports DeviceManager deviceManager = context.getDeviceManager(); Collection<Device> targetDevices; if (event.getTargetDeviceIdCount() > 0) { targetDevices = new ArrayList<DeviceManager.Device>(event.getTargetDeviceIdCount()); for (long targetDeviceId : event.getTargetDeviceIdList()) { Device device = deviceManager.getDeviceForId(targetDeviceId); if (device != null) { targetDevices.add(device); } } } else { targetDevices = deviceManager.getAllDevices(); } // TODO: Enabling wifi, wifi lock, send over 3G, check background data. for (Device device : targetDevices) { if (preferences.isIpOverTcp()) { // Try sending over TCP. if (trySendOverTcp(context, payload, device)) { // Stop when the first delivery succeeds. return true; } } } return false; } private boolean trySendOverTcp(EventContext context, byte[] payload, Device device) { Log.d(TAG, "Sending over TCP"); try { InetAddress address = InetAddress.getByName(device.ipAddress); Socket socket = new Socket(); // TODO: Custom port SocketAddress remoteAddr = new InetSocketAddress(address, DEFAULT_PORT); socket.connect(remoteAddr, TCP_CONNECT_TIMEOUT_MS); socket.setSendBufferSize(payload.length * 2); OutputStream stream = socket.getOutputStream(); stream.write(payload); stream.flush(); socket.close(); Log.d(TAG, "Sent over TCP"); return true; } catch (UnknownHostException e) { Log.w(TAG, "Failed to send over TCP", e); return false; } catch (IOException e) { Log.w(TAG, "Failed to send over TCP", e); return false; } } private boolean trySendOverUdp(EventContext context, byte[] payload) { return false; } @Override protected TransportType getTransportType() { return TransportType.IP; } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/comm/transport/ip/IpEventSender.java
Java
asf20
3,723
/* * Copyright 2011 Rodrigo Damazio * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.event.display; import org.damazio.notifier.R; import org.damazio.notifier.event.EventContext; import org.damazio.notifier.event.EventListener; import org.damazio.notifier.prefs.Preferences; import org.damazio.notifier.protocol.Common.Event; import android.app.Notification; import android.app.NotificationManager; import android.content.Context; import android.content.Intent; import android.widget.Toast; /** * Locally displays remote notifications. * * @author Rodrigo Damazio */ public class RemoteNotificationDisplayer implements EventListener { public void onNewEvent(EventContext context, long eventId, Event event, boolean isLocal, boolean isCommand) { // Only care about remote notifications. if (isLocal || isCommand) { return; } // TODO: Proper text String shortText = event.toString(); Preferences preferences = context.getPreferences(); Context androidContext = context.getAndroidContext(); if (preferences.isSystemDisplayEnabled()) { Notification notification = new Notification(R.drawable.icon, shortText, System.currentTimeMillis()); // TODO: Intent = event log // TODO: Configurable defaults notification.defaults = Notification.DEFAULT_ALL; notification.flags |= Notification.FLAG_AUTO_CANCEL; NotificationManager notificationManager = (NotificationManager) androidContext.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify( "display", (int) (event.getTimestamp() & Integer.MAX_VALUE), notification); } if (preferences.isToastDisplayEnabled()) { Toast.makeText(androidContext, shortText, Toast.LENGTH_LONG).show(); } if (preferences.isPopupDisplayEnabled()) { Intent intent = new Intent(androidContext, PopupDisplayActivity.class); intent.putExtra(PopupDisplayActivity.EXTRA_POPUP_TEXT, shortText); } context.getEventManager().markEventProcessed(eventId); } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/event/display/RemoteNotificationDisplayer.java
Java
asf20
2,609
/* * Copyright 2011 Rodrigo Damazio * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.event.display; import org.damazio.notifier.R; import android.app.Activity; import android.app.AlertDialog; import android.content.Intent; import android.os.Bundle; /** * Simple activity which displays a pop-up. * * @author Rodrigo Damazio */ public class PopupDisplayActivity extends Activity { public static final String EXTRA_POPUP_TEXT = "popup_text"; @Override public void onCreate(Bundle savedState) { Intent intent = getIntent(); String text = intent.getStringExtra(EXTRA_POPUP_TEXT); AlertDialog popup = new AlertDialog.Builder(this) .setCancelable(true) .setTitle(R.string.popup_display_title) .setMessage(text) .setNeutralButton(android.R.string.ok, null) .create(); popup.show(); } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/event/display/PopupDisplayActivity.java
Java
asf20
1,398
/* * Copyright 2011 Rodrigo Damazio * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.event; import org.damazio.notifier.protocol.Common.Event; public interface EventListener { void onNewEvent(EventContext context, long eventId, Event event, boolean isLocal, boolean isCommand); }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/event/EventListener.java
Java
asf20
829
/* * Copyright 2011 Rodrigo Damazio * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.event.util; import static org.damazio.notifier.Constants.TAG; import org.damazio.notifier.protocol.Common.PhoneNumber; import org.damazio.notifier.protocol.Common.PhoneNumber.Builder; import android.content.Context; import android.database.Cursor; import android.net.Uri; import android.provider.ContactsContract.CommonDataKinds.Phone; import android.provider.ContactsContract.PhoneLookup; import android.util.Log; public class PhoneNumberUtils { private final Context context; public PhoneNumberUtils(Context context) { this.context = context; } public PhoneNumber resolvePhoneNumber(String number) { Builder numberBuilder = PhoneNumber.newBuilder(); if (number == null) { return numberBuilder.build(); } numberBuilder.setNumber(number); // Do the contact lookup by number Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number)); Cursor cursor = null; try { cursor = context.getContentResolver().query(uri, new String[] { PhoneLookup.DISPLAY_NAME, PhoneLookup.TYPE, PhoneLookup.LABEL }, null, null, null); } catch (IllegalArgumentException e) { Log.w(TAG, "Unable to look up caller ID", e); } // Take the first match only if (cursor != null && cursor.moveToFirst()) { int nameIndex = cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME); int typeIndex = cursor.getColumnIndex(PhoneLookup.TYPE); int labelIndex = cursor.getColumnIndex(PhoneLookup.LABEL); if (nameIndex != -1) { numberBuilder.setName(cursor.getString(nameIndex)); // Get the phone type if possible if (typeIndex != -1) { int numberType = cursor.getInt(typeIndex); String label = ""; if (labelIndex != -1) { label = cursor.getString(labelIndex); } numberBuilder.setNumberType( Phone.getTypeLabel(context.getResources(), numberType, label).toString()); } } } return numberBuilder.build(); } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/event/util/PhoneNumberUtils.java
Java
asf20
2,666
/* * Copyright 2011 Rodrigo Damazio * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.event; import org.damazio.notifier.comm.pairing.DeviceManager; import org.damazio.notifier.event.util.PhoneNumberUtils; import org.damazio.notifier.prefs.Preferences; import android.content.Context; public class EventContext { private final Context context; private final EventManager eventManager; private final DeviceManager deviceManager; private final Preferences preferences; private PhoneNumberUtils numberUtils; public EventContext(Context context, EventManager eventManager, DeviceManager deviceManager, Preferences preferences) { this.context = context; this.eventManager = eventManager; this.preferences = preferences; this.deviceManager = deviceManager; } public synchronized PhoneNumberUtils getNumberUtils() { if (numberUtils == null) { numberUtils = new PhoneNumberUtils(context); } return numberUtils; } public Context getAndroidContext() { return context; } public Preferences getPreferences() { return preferences; } public EventManager getEventManager() { return eventManager; } public DeviceManager getDeviceManager() { return deviceManager; } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/event/EventContext.java
Java
asf20
1,792
/* * Copyright 2011 Rodrigo Damazio * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.event.receivers.sms; import static org.damazio.notifier.Constants.TAG; import org.damazio.notifier.event.EventContext; import org.damazio.notifier.event.receivers.EventBroadcastReceiver; import org.damazio.notifier.protocol.Common.Event; import org.damazio.notifier.protocol.Common.Event.Type; import org.damazio.notifier.protocol.Notifications.SmsNotification; import android.content.Intent; import android.os.Bundle; import android.util.Log; public class SmsReceiver extends EventBroadcastReceiver { private static final String ACTION = "android.provider.Telephony.SMS_RECEIVED"; @Override protected void onReceiveEvent(EventContext context, Intent intent) { // Create the notification contents using the SMS contents boolean notificationSent = false; Bundle bundle = intent.getExtras(); if (bundle != null) { Object[] pdus = (Object[]) bundle.get("pdus"); SmsDecoder decoder = new SmsDecoder(context.getAndroidContext(), context.getNumberUtils()); for (int i = 0; i < pdus.length; i++) { SmsNotification sms = decoder.decodeSms(pdus[i]); if (sms == null) { continue; } handleEvent(sms); notificationSent = true; } } if (!notificationSent) { // If no notification sent (extra info was not there), send one without info Log.w(TAG, "Got SMS but failed to extract details."); handleEvent(null); } } @Override protected Type getEventType() { return Event.Type.NOTIFICATION_SMS; } @Override protected String getExpectedAction() { return ACTION; } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/event/receivers/sms/SmsReceiver.java
Java
asf20
2,232
/* * Copyright 2011 Rodrigo Damazio * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.event.receivers.sms; import static org.damazio.notifier.Constants.TAG; import org.damazio.notifier.R; import org.damazio.notifier.event.util.PhoneNumberUtils; import org.damazio.notifier.protocol.Common.PhoneNumber; import org.damazio.notifier.protocol.Notifications.SmsNotification; import android.content.Context; import android.telephony.SmsMessage; import android.util.Log; /** * Class which handles decoding SMS messages in the proper way depending on the * version of Android being run. * * @author Rodrigo Damazio */ class SmsDecoder { private final Context context; private final PhoneNumberUtils numberUtils; public SmsDecoder(Context context, PhoneNumberUtils numberUtils) { this.context = context; this.numberUtils = numberUtils; } public SmsNotification decodeSms(Object pdu) { SmsMessage message = null; try { message = SmsMessage.createFromPdu((byte[]) pdu); } catch (NullPointerException e) { // Workaround for Android bug // http://code.google.com/p/android/issues/detail?id=11345 Log.w(TAG, "Invalid PDU", e); return null; } PhoneNumber number = numberUtils.resolvePhoneNumber(message.getOriginatingAddress()); String body = message.getMessageBody(); if (body == null) { body = context.getString(R.string.sms_body_unavailable); } return SmsNotification.newBuilder() .setSender(number) .setText(body) .build(); } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/event/receivers/sms/SmsDecoder.java
Java
asf20
2,088
/* * Copyright 2011 Rodrigo Damazio * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.event.receivers.battery; import static org.damazio.notifier.Constants.TAG; import java.util.HashMap; import java.util.Map; import org.damazio.notifier.event.EventContext; import org.damazio.notifier.event.receivers.EventBroadcastReceiver; import org.damazio.notifier.prefs.Preferences; import org.damazio.notifier.protocol.Common.Event; import org.damazio.notifier.protocol.Common.Event.Type; import org.damazio.notifier.protocol.Notifications.BatteryNotification; import org.damazio.notifier.protocol.Notifications.BatteryNotification.State; import android.content.Intent; import android.os.BatteryManager; import android.os.Bundle; import android.util.Log; public class BatteryEventReceiver extends EventBroadcastReceiver { private static final Map<Integer, State> STATE_MAP = new HashMap<Integer, State>(); static { STATE_MAP.put(BatteryManager.BATTERY_STATUS_CHARGING, State.CHARGING); STATE_MAP.put(BatteryManager.BATTERY_STATUS_DISCHARGING, State.DISCHARGING); STATE_MAP.put(BatteryManager.BATTERY_STATUS_FULL, State.FULL); STATE_MAP.put(BatteryManager.BATTERY_STATUS_NOT_CHARGING, State.NOT_CHARGING); STATE_MAP.put(BatteryManager.BATTERY_STATUS_UNKNOWN, null); } private int lastLevelPercentage; private State lastState; @Override protected void onReceiveEvent(EventContext context, Intent intent) { // Try to read extras from intent Bundle extras = intent.getExtras(); if (extras == null) { return; } int level = extras.getInt(BatteryManager.EXTRA_LEVEL, -1); int maxLevel = extras.getInt(BatteryManager.EXTRA_SCALE, -1); int status = extras.getInt(BatteryManager.EXTRA_STATUS, -1); BatteryNotification.Builder notificationBuilder = BatteryNotification.newBuilder(); State state = STATE_MAP.get(status); if (state != null) { notificationBuilder.setState(state); } int levelPercentage = -1; if (level != -1 && maxLevel != -1) { levelPercentage = 100 * level / maxLevel; notificationBuilder.setChargePercentage(levelPercentage); } Log.d(TAG, "Got battery level=" + levelPercentage + "; state=" + state); if (!shouldReport(state, levelPercentage, context.getPreferences())) { Log.d(TAG, "Not reporting battery state"); return; } lastLevelPercentage = levelPercentage; lastState = state; handleEvent(notificationBuilder.build()); } private boolean shouldReport(State state, int levelPercentage, Preferences preferences) { if (state != lastState) { // State changed return true; } int maxPercentage = preferences.getMaxBatteryLevel(); int minPercentage = preferences.getMinBatteryLevel(); if (levelPercentage > maxPercentage || levelPercentage < minPercentage) { // Outside the range return false; } if (levelPercentage == maxPercentage || levelPercentage == minPercentage) { // About to go in or out of range, always make a first/last report return true; } int percentageChange = Math.abs(levelPercentage - lastLevelPercentage); if (percentageChange < preferences.getMinBatteryLevelChange()) { // Too small change return false; } // With range and above or equal to min change return true; } @Override protected Type getEventType() { return Event.Type.NOTIFICATION_BATTERY; } @Override protected String getExpectedAction() { return Intent.ACTION_BATTERY_CHANGED; } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/event/receivers/battery/BatteryEventReceiver.java
Java
asf20
4,114
/* * Copyright 2011 Rodrigo Damazio * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.event.receivers.phone; import org.damazio.notifier.event.EventContext; import org.damazio.notifier.protocol.Common.Event; import org.damazio.notifier.protocol.Notifications.VoicemailNotification; import android.telephony.PhoneStateListener; public class VoicemailListener extends PhoneStateListener { private final EventContext eventContext; public VoicemailListener(EventContext eventContext) { this.eventContext = eventContext; } @Override public void onMessageWaitingIndicatorChanged(boolean mwi) { if (!eventContext.getPreferences().isEventTypeEnabled(Event.Type.NOTIFICATION_VOICEMAIL)) { return; } VoicemailNotification notification = VoicemailNotification.newBuilder() .setHasVoicemail(mwi) .build(); eventContext.getEventManager().handleLocalEvent(Event.Type.NOTIFICATION_VOICEMAIL, notification); } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/event/receivers/phone/VoicemailListener.java
Java
asf20
1,499
/* * Copyright 2011 Rodrigo Damazio * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.event.receivers.phone; import org.damazio.notifier.event.EventContext; import org.damazio.notifier.event.receivers.EventBroadcastReceiver; import org.damazio.notifier.event.util.PhoneNumberUtils; import org.damazio.notifier.protocol.Common.Event; import org.damazio.notifier.protocol.Common.Event.Type; import org.damazio.notifier.protocol.Common.PhoneNumber; import org.damazio.notifier.protocol.Notifications.RingNotification; import android.content.Intent; import android.telephony.TelephonyManager; public class RingReceiver extends EventBroadcastReceiver { @Override protected void onReceiveEvent(EventContext context, Intent intent) { String stateStr = intent.getStringExtra(TelephonyManager.EXTRA_STATE); if (TelephonyManager.EXTRA_STATE_RINGING.equals(stateStr)) { PhoneNumberUtils numberUtils = context.getNumberUtils(); String incomingNumberStr = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); PhoneNumber incomingNumber = numberUtils.resolvePhoneNumber(incomingNumberStr); RingNotification ring = RingNotification.newBuilder() .setNumber(incomingNumber) .build(); handleEvent(ring); } } @Override protected Type getEventType() { return Event.Type.NOTIFICATION_RING; } @Override protected String getExpectedAction() { return TelephonyManager.ACTION_PHONE_STATE_CHANGED; } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/event/receivers/phone/RingReceiver.java
Java
asf20
2,023
/* * Copyright 2011 Rodrigo Damazio * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.event.receivers.phone; import org.damazio.notifier.event.EventContext; import org.damazio.notifier.event.EventManager; import org.damazio.notifier.event.util.PhoneNumberUtils; import org.damazio.notifier.protocol.Common.Event; import org.damazio.notifier.protocol.Common.PhoneNumber; import org.damazio.notifier.protocol.Notifications.MissedCallNotification; import android.content.ContentResolver; import android.database.ContentObserver; import android.database.Cursor; import android.os.Handler; import android.provider.CallLog; public class MissedCallListener { private class CallLogObserver extends ContentObserver { private CallLogObserver(Handler handler) { super(handler); } public void onChange(boolean selfChange) { super.onChange(selfChange); onCallLogChanged(); } } private final EventContext eventContext; private final ContentResolver resolver; private final CallLogObserver observer; private long lastMissedCall; public MissedCallListener(EventContext eventContext) { this.eventContext = eventContext; this.resolver = eventContext.getAndroidContext().getContentResolver(); this.observer = new CallLogObserver(new Handler()); } public void onCreate() { this.lastMissedCall = System.currentTimeMillis(); resolver.registerContentObserver(CallLog.Calls.CONTENT_URI, false, observer); } public void onDestroy() { resolver.unregisterContentObserver(observer); } private void onCallLogChanged() { Cursor cursor = resolver.query( CallLog.Calls.CONTENT_URI, new String[] { CallLog.Calls.NUMBER, CallLog.Calls.DATE }, CallLog.Calls.DATE + " > ? AND " + CallLog.Calls.TYPE + " = ?", new String[] { Long.toString(lastMissedCall), Integer.toString(CallLog.Calls.MISSED_TYPE) }, CallLog.Calls.DATE + " DESC"); EventManager eventManager = eventContext.getEventManager(); PhoneNumberUtils numberUtils = eventContext.getNumberUtils(); while (cursor.moveToNext()) { int numberIdx = cursor.getColumnIndexOrThrow(CallLog.Calls.NUMBER); int dateIdx = cursor.getColumnIndexOrThrow(CallLog.Calls.DATE); if (cursor.isNull(numberIdx) || cursor.isNull(dateIdx)) { eventManager.handleLocalEvent(Event.Type.NOTIFICATION_MISSED_CALL, null); continue; } String number = cursor.getString(numberIdx); long callDate = cursor.getLong(dateIdx); PhoneNumber phoneNumber = numberUtils.resolvePhoneNumber(number); MissedCallNotification notification = MissedCallNotification.newBuilder() .setTimestamp((int) (callDate / 1000L)) .setNumber(phoneNumber) .build(); eventManager.handleLocalEvent(Event.Type.NOTIFICATION_MISSED_CALL, notification); lastMissedCall = callDate; } } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/event/receivers/phone/MissedCallListener.java
Java
asf20
3,473
/* * Copyright (C) 2007 Esmertec AG. * Copyright (C) 2007 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.event.receivers.mms; import java.io.UnsupportedEncodingException; import java.util.HashMap; class CharacterSets { /** * IANA assigned MIB enum numbers. * * From wap-230-wsp-20010705-a.pdf * Any-charset = <Octet 128> * Equivalent to the special RFC2616 charset value "*" */ public static final int ANY_CHARSET = 0x00; public static final int US_ASCII = 0x03; public static final int ISO_8859_1 = 0x04; public static final int ISO_8859_2 = 0x05; public static final int ISO_8859_3 = 0x06; public static final int ISO_8859_4 = 0x07; public static final int ISO_8859_5 = 0x08; public static final int ISO_8859_6 = 0x09; public static final int ISO_8859_7 = 0x0A; public static final int ISO_8859_8 = 0x0B; public static final int ISO_8859_9 = 0x0C; public static final int SHIFT_JIS = 0x11; public static final int UTF_8 = 0x6A; public static final int BIG5 = 0x07EA; public static final int UCS2 = 0x03E8; public static final int UTF_16 = 0x03F7; /** * If the encoding of given data is unsupported, use UTF_8 to decode it. */ public static final int DEFAULT_CHARSET = UTF_8; /** * Array of MIB enum numbers. */ private static final int[] MIBENUM_NUMBERS = { ANY_CHARSET, US_ASCII, ISO_8859_1, ISO_8859_2, ISO_8859_3, ISO_8859_4, ISO_8859_5, ISO_8859_6, ISO_8859_7, ISO_8859_8, ISO_8859_9, SHIFT_JIS, UTF_8, BIG5, UCS2, UTF_16, }; /** * The Well-known-charset Mime name. */ public static final String MIMENAME_ANY_CHARSET = "*"; public static final String MIMENAME_US_ASCII = "us-ascii"; public static final String MIMENAME_ISO_8859_1 = "iso-8859-1"; public static final String MIMENAME_ISO_8859_2 = "iso-8859-2"; public static final String MIMENAME_ISO_8859_3 = "iso-8859-3"; public static final String MIMENAME_ISO_8859_4 = "iso-8859-4"; public static final String MIMENAME_ISO_8859_5 = "iso-8859-5"; public static final String MIMENAME_ISO_8859_6 = "iso-8859-6"; public static final String MIMENAME_ISO_8859_7 = "iso-8859-7"; public static final String MIMENAME_ISO_8859_8 = "iso-8859-8"; public static final String MIMENAME_ISO_8859_9 = "iso-8859-9"; public static final String MIMENAME_SHIFT_JIS = "shift_JIS"; public static final String MIMENAME_UTF_8 = "utf-8"; public static final String MIMENAME_BIG5 = "big5"; public static final String MIMENAME_UCS2 = "iso-10646-ucs-2"; public static final String MIMENAME_UTF_16 = "utf-16"; public static final String DEFAULT_CHARSET_NAME = MIMENAME_UTF_8; /** * Array of the names of character sets. */ private static final String[] MIME_NAMES = { MIMENAME_ANY_CHARSET, MIMENAME_US_ASCII, MIMENAME_ISO_8859_1, MIMENAME_ISO_8859_2, MIMENAME_ISO_8859_3, MIMENAME_ISO_8859_4, MIMENAME_ISO_8859_5, MIMENAME_ISO_8859_6, MIMENAME_ISO_8859_7, MIMENAME_ISO_8859_8, MIMENAME_ISO_8859_9, MIMENAME_SHIFT_JIS, MIMENAME_UTF_8, MIMENAME_BIG5, MIMENAME_UCS2, MIMENAME_UTF_16, }; private static final HashMap<Integer, String> MIBENUM_TO_NAME_MAP; private static final HashMap<String, Integer> NAME_TO_MIBENUM_MAP; static { // Create the HashMaps. MIBENUM_TO_NAME_MAP = new HashMap<Integer, String>(); NAME_TO_MIBENUM_MAP = new HashMap<String, Integer>(); assert(MIBENUM_NUMBERS.length == MIME_NAMES.length); int count = MIBENUM_NUMBERS.length - 1; for(int i = 0; i <= count; i++) { MIBENUM_TO_NAME_MAP.put(MIBENUM_NUMBERS[i], MIME_NAMES[i]); NAME_TO_MIBENUM_MAP.put(MIME_NAMES[i], MIBENUM_NUMBERS[i]); } } private CharacterSets() {} // Non-instantiatable /** * Map an MIBEnum number to the name of the charset which this number * is assigned to by IANA. * * @param mibEnumValue An IANA assigned MIBEnum number. * @return The name string of the charset. * @throws UnsupportedEncodingException */ public static String getMimeName(int mibEnumValue) throws UnsupportedEncodingException { String name = MIBENUM_TO_NAME_MAP.get(mibEnumValue); if (name == null) { throw new UnsupportedEncodingException(); } return name; } /** * Map a well-known charset name to its assigned MIBEnum number. * * @param mimeName The charset name. * @return The MIBEnum number assigned by IANA for this charset. * @throws UnsupportedEncodingException */ public static int getMibEnumValue(String mimeName) throws UnsupportedEncodingException { if(null == mimeName) { return -1; } Integer mibEnumValue = NAME_TO_MIBENUM_MAP.get(mimeName); if (mibEnumValue == null) { throw new UnsupportedEncodingException(); } return mibEnumValue; } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/event/receivers/mms/CharacterSets.java
Java
asf20
5,938
/* * Copyright 2011 Rodrigo Damazio * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.event.receivers.mms; import static org.damazio.notifier.Constants.TAG; import org.damazio.notifier.event.EventContext; import org.damazio.notifier.event.receivers.EventBroadcastReceiver; import org.damazio.notifier.event.util.PhoneNumberUtils; import org.damazio.notifier.protocol.Common.Event; import org.damazio.notifier.protocol.Common.Event.Type; import org.damazio.notifier.protocol.Common.PhoneNumber; import org.damazio.notifier.protocol.Notifications.MmsNotification; import android.content.Intent; import android.util.Log; public class MmsReceiver extends EventBroadcastReceiver { private static final String DATA_TYPE = "application/vnd.wap.mms-message"; @Override protected void onReceiveEvent(EventContext context, Intent intent) { if (!DATA_TYPE.equals(intent.getType())) { Log.e(TAG, "Got wrong data type for MMS: " + intent.getType()); return; } // Parse the WAP push contents PduParser parser = new PduParser(); PduHeaders headers = parser.parseHeaders(intent.getByteArrayExtra("data")); if (headers == null) { Log.e(TAG, "Couldn't parse headers for WAP PUSH."); return; } int messageType = headers.getMessageType(); Log.d(TAG, "WAP PUSH message type: 0x" + Integer.toHexString(messageType)); // Check if it's a MMS notification if (messageType == PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND) { String fromStr = null; EncodedStringValue encodedFrom = headers.getFrom(); if (encodedFrom != null) { fromStr = encodedFrom.getString(); } PhoneNumberUtils numberUtils = context.getNumberUtils(); PhoneNumber from = numberUtils.resolvePhoneNumber(fromStr); // TODO: Add text/image/etc. MmsNotification mms = MmsNotification.newBuilder() .setSender(from) .build(); handleEvent(mms); } } @Override protected String getExpectedAction() { return "android.provider.Telephony.WAP_PUSH_RECEIVED"; } @Override protected Type getEventType() { return Event.Type.NOTIFICATION_MMS; } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/event/receivers/mms/MmsReceiver.java
Java
asf20
2,709
/* * Copyright (C) 2007-2008 Esmertec AG. * Copyright (C) 2007-2008 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.event.receivers.mms; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.UnsupportedEncodingException; import java.util.Arrays; import java.util.HashMap; import android.util.Log; class PduParser { /** * The next are WAP values defined in WSP specification. */ private static final int QUOTE = 127; private static final int LENGTH_QUOTE = 31; private static final int TEXT_MIN = 32; private static final int TEXT_MAX = 127; private static final int SHORT_INTEGER_MAX = 127; private static final int SHORT_LENGTH_MAX = 30; private static final int LONG_INTEGER_LENGTH_MAX = 8; private static final int QUOTED_STRING_FLAG = 34; private static final int END_STRING_FLAG = 0x00; //The next two are used by the interface "parseWapString" to //distinguish Text-String and Quoted-String. private static final int TYPE_TEXT_STRING = 0; private static final int TYPE_QUOTED_STRING = 1; private static final int TYPE_TOKEN_STRING = 2; /** * The log tag. */ private static final String LOG_TAG = "PduParser"; /** * Parse the pdu. * * @return the pdu structure if parsing successfully. * null if parsing error happened or mandatory fields are not set. */ public PduHeaders parseHeaders(byte[] pduData){ ByteArrayInputStream pduDataStream = new ByteArrayInputStream(pduData); /* parse headers */ PduHeaders headers = parseHeaders(pduDataStream); if (null == headers) { // Parse headers failed. return null; } /* check mandatory header fields */ if (false == checkMandatoryHeader(headers)) { log("check mandatory headers failed!"); return null; } return headers; } /** * Parse pdu headers. * * @param pduDataStream pdu data input stream * @return headers in PduHeaders structure, null when parse fail */ protected PduHeaders parseHeaders(ByteArrayInputStream pduDataStream){ if (pduDataStream == null) { return null; } boolean keepParsing = true; PduHeaders headers = new PduHeaders(); while (keepParsing && (pduDataStream.available() > 0)) { int headerField = extractByteValue(pduDataStream); switch (headerField) { case PduHeaders.MESSAGE_TYPE: { int messageType = extractByteValue(pduDataStream); switch (messageType) { // We don't support these kind of messages now. case PduHeaders.MESSAGE_TYPE_FORWARD_REQ: case PduHeaders.MESSAGE_TYPE_FORWARD_CONF: case PduHeaders.MESSAGE_TYPE_MBOX_STORE_REQ: case PduHeaders.MESSAGE_TYPE_MBOX_STORE_CONF: case PduHeaders.MESSAGE_TYPE_MBOX_VIEW_REQ: case PduHeaders.MESSAGE_TYPE_MBOX_VIEW_CONF: case PduHeaders.MESSAGE_TYPE_MBOX_UPLOAD_REQ: case PduHeaders.MESSAGE_TYPE_MBOX_UPLOAD_CONF: case PduHeaders.MESSAGE_TYPE_MBOX_DELETE_REQ: case PduHeaders.MESSAGE_TYPE_MBOX_DELETE_CONF: case PduHeaders.MESSAGE_TYPE_MBOX_DESCR: case PduHeaders.MESSAGE_TYPE_DELETE_REQ: case PduHeaders.MESSAGE_TYPE_DELETE_CONF: case PduHeaders.MESSAGE_TYPE_CANCEL_REQ: case PduHeaders.MESSAGE_TYPE_CANCEL_CONF: return null; } try { headers.setOctet(messageType, headerField); } catch(IllegalArgumentException e) { log("Set invalid Octet value: " + messageType + " into the header filed: " + headerField); return null; } catch(RuntimeException e) { log(headerField + "is not Octet header field!"); return null; } break; } /* Octect value */ case PduHeaders.REPORT_ALLOWED: case PduHeaders.ADAPTATION_ALLOWED: case PduHeaders.DELIVERY_REPORT: case PduHeaders.DRM_CONTENT: case PduHeaders.DISTRIBUTION_INDICATOR: case PduHeaders.QUOTAS: case PduHeaders.READ_REPORT: case PduHeaders.STORE: case PduHeaders.STORED: case PduHeaders.TOTALS: case PduHeaders.SENDER_VISIBILITY: case PduHeaders.READ_STATUS: case PduHeaders.CANCEL_STATUS: case PduHeaders.PRIORITY: case PduHeaders.STATUS: case PduHeaders.REPLY_CHARGING: case PduHeaders.MM_STATE: case PduHeaders.RECOMMENDED_RETRIEVAL_MODE: case PduHeaders.CONTENT_CLASS: case PduHeaders.RETRIEVE_STATUS: case PduHeaders.STORE_STATUS: /** * The following field has a different value when * used in the M-Mbox-Delete.conf and M-Delete.conf PDU. * For now we ignore this fact, since we do not support these PDUs */ case PduHeaders.RESPONSE_STATUS: { int value = extractByteValue(pduDataStream); try { headers.setOctet(value, headerField); } catch(IllegalArgumentException e) { log("Set invalid Octet value: " + value + " into the header filed: " + headerField); return null; } catch(RuntimeException e) { log(headerField + "is not Octet header field!"); return null; } break; } /* Long-Integer */ case PduHeaders.DATE: case PduHeaders.REPLY_CHARGING_SIZE: case PduHeaders.MESSAGE_SIZE: { try { long value = parseLongInteger(pduDataStream); headers.setLongInteger(value, headerField); } catch(RuntimeException e) { log(headerField + "is not Long-Integer header field!"); return null; } break; } /* Integer-Value */ case PduHeaders.MESSAGE_COUNT: case PduHeaders.START: case PduHeaders.LIMIT: { try { long value = parseIntegerValue(pduDataStream); headers.setLongInteger(value, headerField); } catch(RuntimeException e) { log(headerField + "is not Long-Integer header field!"); return null; } break; } /* Text-String */ case PduHeaders.TRANSACTION_ID: case PduHeaders.REPLY_CHARGING_ID: case PduHeaders.AUX_APPLIC_ID: case PduHeaders.APPLIC_ID: case PduHeaders.REPLY_APPLIC_ID: /** * The next three header fields are email addresses * as defined in RFC2822, * not including the characters "<" and ">" */ case PduHeaders.MESSAGE_ID: case PduHeaders.REPLACE_ID: case PduHeaders.CANCEL_ID: /** * The following field has a different value when * used in the M-Mbox-Delete.conf and M-Delete.conf PDU. * For now we ignore this fact, since we do not support these PDUs */ case PduHeaders.CONTENT_LOCATION: { byte[] value = parseWapString(pduDataStream, TYPE_TEXT_STRING); if (null != value) { try { headers.setTextString(value, headerField); } catch(NullPointerException e) { log("null pointer error!"); } catch(RuntimeException e) { log(headerField + "is not Text-String header field!"); return null; } } break; } /* Encoded-string-value */ case PduHeaders.SUBJECT: case PduHeaders.RECOMMENDED_RETRIEVAL_MODE_TEXT: case PduHeaders.RETRIEVE_TEXT: case PduHeaders.STATUS_TEXT: case PduHeaders.STORE_STATUS_TEXT: /* the next one is not support * M-Mbox-Delete.conf and M-Delete.conf now */ case PduHeaders.RESPONSE_TEXT: { EncodedStringValue value = parseEncodedStringValue(pduDataStream); if (null != value) { try { headers.setEncodedStringValue(value, headerField); } catch(NullPointerException e) { log("null pointer error!"); } catch (RuntimeException e) { log(headerField + "is not Encoded-String-Value header field!"); return null; } } break; } /* Addressing model */ case PduHeaders.BCC: case PduHeaders.CC: case PduHeaders.TO: { EncodedStringValue value = parseEncodedStringValue(pduDataStream); if (null != value) { byte[] address = value.getTextString(); if (null != address) { String str = new String(address); int endIndex = str.indexOf("/"); if (endIndex > 0) { str = str.substring(0, endIndex); } try { value.setTextString(str.getBytes()); } catch(NullPointerException e) { log("null pointer error!"); return null; } } try { headers.appendEncodedStringValue(value, headerField); } catch(NullPointerException e) { log("null pointer error!"); } catch(RuntimeException e) { log(headerField + "is not Encoded-String-Value header field!"); return null; } } break; } /* Value-length * (Absolute-token Date-value | Relative-token Delta-seconds-value) */ case PduHeaders.DELIVERY_TIME: case PduHeaders.EXPIRY: case PduHeaders.REPLY_CHARGING_DEADLINE: { /* parse Value-length */ parseValueLength(pduDataStream); /* Absolute-token or Relative-token */ int token = extractByteValue(pduDataStream); /* Date-value or Delta-seconds-value */ long timeValue; try { timeValue = parseLongInteger(pduDataStream); } catch(RuntimeException e) { log(headerField + "is not Long-Integer header field!"); return null; } if (PduHeaders.VALUE_RELATIVE_TOKEN == token) { /* need to convert the Delta-seconds-value * into Date-value */ timeValue = System.currentTimeMillis()/1000 + timeValue; } try { headers.setLongInteger(timeValue, headerField); } catch(RuntimeException e) { log(headerField + "is not Long-Integer header field!"); return null; } break; } case PduHeaders.FROM: { /* From-value = * Value-length * (Address-present-token Encoded-string-value | Insert-address-token) */ EncodedStringValue from = null; parseValueLength(pduDataStream); /* parse value-length */ /* Address-present-token or Insert-address-token */ int fromToken = extractByteValue(pduDataStream); /* Address-present-token or Insert-address-token */ if (PduHeaders.FROM_ADDRESS_PRESENT_TOKEN == fromToken) { /* Encoded-string-value */ from = parseEncodedStringValue(pduDataStream); if (null != from) { byte[] address = from.getTextString(); if (null != address) { String str = new String(address); int endIndex = str.indexOf("/"); if (endIndex > 0) { str = str.substring(0, endIndex); } try { from.setTextString(str.getBytes()); } catch(NullPointerException e) { log("null pointer error!"); return null; } } } } else { try { from = new EncodedStringValue( PduHeaders.FROM_INSERT_ADDRESS_TOKEN_STR.getBytes()); } catch(NullPointerException e) { log(headerField + "is not Encoded-String-Value header field!"); return null; } } try { headers.setEncodedStringValue(from, PduHeaders.FROM); } catch(NullPointerException e) { log("null pointer error!"); } catch(RuntimeException e) { log(headerField + "is not Encoded-String-Value header field!"); return null; } break; } case PduHeaders.MESSAGE_CLASS: { /* Message-class-value = Class-identifier | Token-text */ pduDataStream.mark(1); int messageClass = extractByteValue(pduDataStream); if (messageClass >= PduHeaders.MESSAGE_CLASS_PERSONAL) { /* Class-identifier */ try { if (PduHeaders.MESSAGE_CLASS_PERSONAL == messageClass) { headers.setTextString( PduHeaders.MESSAGE_CLASS_PERSONAL_STR.getBytes(), PduHeaders.MESSAGE_CLASS); } else if (PduHeaders.MESSAGE_CLASS_ADVERTISEMENT == messageClass) { headers.setTextString( PduHeaders.MESSAGE_CLASS_ADVERTISEMENT_STR.getBytes(), PduHeaders.MESSAGE_CLASS); } else if (PduHeaders.MESSAGE_CLASS_INFORMATIONAL == messageClass) { headers.setTextString( PduHeaders.MESSAGE_CLASS_INFORMATIONAL_STR.getBytes(), PduHeaders.MESSAGE_CLASS); } else if (PduHeaders.MESSAGE_CLASS_AUTO == messageClass) { headers.setTextString( PduHeaders.MESSAGE_CLASS_AUTO_STR.getBytes(), PduHeaders.MESSAGE_CLASS); } } catch(NullPointerException e) { log("null pointer error!"); } catch(RuntimeException e) { log(headerField + "is not Text-String header field!"); return null; } } else { /* Token-text */ pduDataStream.reset(); byte[] messageClassString = parseWapString(pduDataStream, TYPE_TEXT_STRING); if (null != messageClassString) { try { headers.setTextString(messageClassString, PduHeaders.MESSAGE_CLASS); } catch(NullPointerException e) { log("null pointer error!"); } catch(RuntimeException e) { log(headerField + "is not Text-String header field!"); return null; } } } break; } case PduHeaders.MMS_VERSION: { int version = parseShortInteger(pduDataStream); try { headers.setOctet(version, PduHeaders.MMS_VERSION); } catch(IllegalArgumentException e) { log("Set invalid Octet value: " + version + " into the header filed: " + headerField); return null; } catch(RuntimeException e) { log(headerField + "is not Octet header field!"); return null; } break; } case PduHeaders.PREVIOUSLY_SENT_BY: { /* Previously-sent-by-value = * Value-length Forwarded-count-value Encoded-string-value */ /* parse value-length */ parseValueLength(pduDataStream); /* parse Forwarded-count-value */ try { parseIntegerValue(pduDataStream); } catch(RuntimeException e) { log(headerField + " is not Integer-Value"); return null; } /* parse Encoded-string-value */ EncodedStringValue previouslySentBy = parseEncodedStringValue(pduDataStream); if (null != previouslySentBy) { try { headers.setEncodedStringValue(previouslySentBy, PduHeaders.PREVIOUSLY_SENT_BY); } catch(NullPointerException e) { log("null pointer error!"); } catch(RuntimeException e) { log(headerField + "is not Encoded-String-Value header field!"); return null; } } break; } case PduHeaders.PREVIOUSLY_SENT_DATE: { /* Previously-sent-date-value = * Value-length Forwarded-count-value Date-value */ /* parse value-length */ parseValueLength(pduDataStream); /* parse Forwarded-count-value */ try { parseIntegerValue(pduDataStream); } catch(RuntimeException e) { log(headerField + " is not Integer-Value"); return null; } /* Date-value */ try { long perviouslySentDate = parseLongInteger(pduDataStream); headers.setLongInteger(perviouslySentDate, PduHeaders.PREVIOUSLY_SENT_DATE); } catch(RuntimeException e) { log(headerField + "is not Long-Integer header field!"); return null; } break; } case PduHeaders.MM_FLAGS: { /* MM-flags-value = * Value-length * ( Add-token | Remove-token | Filter-token ) * Encoded-string-value */ /* parse Value-length */ parseValueLength(pduDataStream); /* Add-token | Remove-token | Filter-token */ extractByteValue(pduDataStream); /* Encoded-string-value */ parseEncodedStringValue(pduDataStream); /* not store this header filed in "headers", * because now PduHeaders doesn't support it */ break; } /* Value-length * (Message-total-token | Size-total-token) Integer-Value */ case PduHeaders.MBOX_TOTALS: case PduHeaders.MBOX_QUOTAS: { /* Value-length */ parseValueLength(pduDataStream); /* Message-total-token | Size-total-token */ extractByteValue(pduDataStream); /*Integer-Value*/ try { parseIntegerValue(pduDataStream); } catch(RuntimeException e) { log(headerField + " is not Integer-Value"); return null; } /* not store these headers filed in "headers", because now PduHeaders doesn't support them */ break; } case PduHeaders.ELEMENT_DESCRIPTOR: { parseContentType(pduDataStream, null); /* not store this header filed in "headers", because now PduHeaders doesn't support it */ break; } case PduHeaders.CONTENT_TYPE: { HashMap<Integer, Object> map = new HashMap<Integer, Object>(); byte[] contentType = parseContentType(pduDataStream, map); if (null != contentType) { try { headers.setTextString(contentType, PduHeaders.CONTENT_TYPE); } catch(NullPointerException e) { log("null pointer error!"); } catch(RuntimeException e) { log(headerField + "is not Text-String header field!"); return null; } } keepParsing = false; break; } case PduHeaders.CONTENT: case PduHeaders.ADDITIONAL_HEADERS: case PduHeaders.ATTRIBUTES: default: { log("Unknown header"); } } } return headers; } /** * Log status. * * @param text log information */ private static void log(String text) { Log.v(LOG_TAG, text); } /** * Parse unsigned integer. * * @param pduDataStream pdu data input stream * @return the integer, -1 when failed */ protected static int parseUnsignedInt(ByteArrayInputStream pduDataStream) { /** * From wap-230-wsp-20010705-a.pdf * The maximum size of a uintvar is 32 bits. * So it will be encoded in no more than 5 octets. */ assert(null != pduDataStream); int result = 0; int temp = pduDataStream.read(); if (temp == -1) { return temp; } while((temp & 0x80) != 0) { result = result << 7; result |= temp & 0x7F; temp = pduDataStream.read(); if (temp == -1) { return temp; } } result = result << 7; result |= temp & 0x7F; return result; } /** * Parse value length. * * @param pduDataStream pdu data input stream * @return the integer */ protected static int parseValueLength(ByteArrayInputStream pduDataStream) { /** * From wap-230-wsp-20010705-a.pdf * Value-length = Short-length | (Length-quote Length) * Short-length = <Any octet 0-30> * Length-quote = <Octet 31> * Length = Uintvar-integer * Uintvar-integer = 1*5 OCTET */ assert(null != pduDataStream); int temp = pduDataStream.read(); assert(-1 != temp); int first = temp & 0xFF; if (first <= SHORT_LENGTH_MAX) { return first; } else if (first == LENGTH_QUOTE) { return parseUnsignedInt(pduDataStream); } throw new RuntimeException ("Value length > LENGTH_QUOTE!"); } /** * Parse encoded string value. * * @param pduDataStream pdu data input stream * @return the EncodedStringValue */ protected static EncodedStringValue parseEncodedStringValue(ByteArrayInputStream pduDataStream){ /** * From OMA-TS-MMS-ENC-V1_3-20050927-C.pdf * Encoded-string-value = Text-string | Value-length Char-set Text-string */ assert(null != pduDataStream); pduDataStream.mark(1); EncodedStringValue returnValue = null; int charset = 0; int temp = pduDataStream.read(); assert(-1 != temp); int first = temp & 0xFF; pduDataStream.reset(); if (first < TEXT_MIN) { parseValueLength(pduDataStream); charset = parseShortInteger(pduDataStream); //get the "Charset" } byte[] textString = parseWapString(pduDataStream, TYPE_TEXT_STRING); try { if (0 != charset) { returnValue = new EncodedStringValue(charset, textString); } else { returnValue = new EncodedStringValue(textString); } } catch(Exception e) { return null; } return returnValue; } /** * Parse Text-String or Quoted-String. * * @param pduDataStream pdu data input stream * @param stringType TYPE_TEXT_STRING or TYPE_QUOTED_STRING * @return the string without End-of-string in byte array */ protected static byte[] parseWapString(ByteArrayInputStream pduDataStream, int stringType) { assert(null != pduDataStream); /** * From wap-230-wsp-20010705-a.pdf * Text-string = [Quote] *TEXT End-of-string * If the first character in the TEXT is in the range of 128-255, * a Quote character must precede it. * Otherwise the Quote character must be omitted. * The Quote is not part of the contents. * Quote = <Octet 127> * End-of-string = <Octet 0> * * Quoted-string = <Octet 34> *TEXT End-of-string * * Token-text = Token End-of-string */ // Mark supposed beginning of Text-string // We will have to mark again if first char is QUOTE or QUOTED_STRING_FLAG pduDataStream.mark(1); // Check first char int temp = pduDataStream.read(); assert(-1 != temp); if ((TYPE_QUOTED_STRING == stringType) && (QUOTED_STRING_FLAG == temp)) { // Mark again if QUOTED_STRING_FLAG and ignore it pduDataStream.mark(1); } else if ((TYPE_TEXT_STRING == stringType) && (QUOTE == temp)) { // Mark again if QUOTE and ignore it pduDataStream.mark(1); } else { // Otherwise go back to origin pduDataStream.reset(); } // We are now definitely at the beginning of string /** * Return *TOKEN or *TEXT (Text-String without QUOTE, * Quoted-String without QUOTED_STRING_FLAG and without End-of-string) */ return getWapString(pduDataStream, stringType); } /** * Check TOKEN data defined in RFC2616. * @param ch checking data * @return true when ch is TOKEN, false when ch is not TOKEN */ protected static boolean isTokenCharacter(int ch) { /** * Token = 1*<any CHAR except CTLs or separators> * separators = "("(40) | ")"(41) | "<"(60) | ">"(62) | "@"(64) * | ","(44) | ";"(59) | ":"(58) | "\"(92) | <">(34) * | "/"(47) | "["(91) | "]"(93) | "?"(63) | "="(61) * | "{"(123) | "}"(125) | SP(32) | HT(9) * CHAR = <any US-ASCII character (octets 0 - 127)> * CTL = <any US-ASCII control character * (octets 0 - 31) and DEL (127)> * SP = <US-ASCII SP, space (32)> * HT = <US-ASCII HT, horizontal-tab (9)> */ if((ch < 33) || (ch > 126)) { return false; } switch(ch) { case '"': /* '"' */ case '(': /* '(' */ case ')': /* ')' */ case ',': /* ',' */ case '/': /* '/' */ case ':': /* ':' */ case ';': /* ';' */ case '<': /* '<' */ case '=': /* '=' */ case '>': /* '>' */ case '?': /* '?' */ case '@': /* '@' */ case '[': /* '[' */ case '\\': /* '\' */ case ']': /* ']' */ case '{': /* '{' */ case '}': /* '}' */ return false; } return true; } /** * Check TEXT data defined in RFC2616. * @param ch checking data * @return true when ch is TEXT, false when ch is not TEXT */ protected static boolean isText(int ch) { /** * TEXT = <any OCTET except CTLs, * but including LWS> * CTL = <any US-ASCII control character * (octets 0 - 31) and DEL (127)> * LWS = [CRLF] 1*( SP | HT ) * CRLF = CR LF * CR = <US-ASCII CR, carriage return (13)> * LF = <US-ASCII LF, linefeed (10)> */ if(((ch >= 32) && (ch <= 126)) || ((ch >= 128) && (ch <= 255))) { return true; } switch(ch) { case '\t': /* '\t' */ case '\n': /* '\n' */ case '\r': /* '\r' */ return true; } return false; } protected static byte[] getWapString(ByteArrayInputStream pduDataStream, int stringType) { assert(null != pduDataStream); ByteArrayOutputStream out = new ByteArrayOutputStream(); int temp = pduDataStream.read(); assert(-1 != temp); while((-1 != temp) && ('\0' != temp)) { // check each of the character if (stringType == TYPE_TOKEN_STRING) { if (isTokenCharacter(temp)) { out.write(temp); } } else { if (isText(temp)) { out.write(temp); } } temp = pduDataStream.read(); assert(-1 != temp); } if (out.size() > 0) { return out.toByteArray(); } return null; } /** * Extract a byte value from the input stream. * * @param pduDataStream pdu data input stream * @return the byte */ protected static int extractByteValue(ByteArrayInputStream pduDataStream) { assert(null != pduDataStream); int temp = pduDataStream.read(); assert(-1 != temp); return temp & 0xFF; } /** * Parse Short-Integer. * * @param pduDataStream pdu data input stream * @return the byte */ protected static int parseShortInteger(ByteArrayInputStream pduDataStream) { /** * From wap-230-wsp-20010705-a.pdf * Short-integer = OCTET * Integers in range 0-127 shall be encoded as a one * octet value with the most significant bit set to one (1xxx xxxx) * and with the value in the remaining least significant bits. */ assert(null != pduDataStream); int temp = pduDataStream.read(); assert(-1 != temp); return temp & 0x7F; } /** * Parse Long-Integer. * * @param pduDataStream pdu data input stream * @return long integer */ protected static long parseLongInteger(ByteArrayInputStream pduDataStream) { /** * From wap-230-wsp-20010705-a.pdf * Long-integer = Short-length Multi-octet-integer * The Short-length indicates the length of the Multi-octet-integer * Multi-octet-integer = 1*30 OCTET * The content octets shall be an unsigned integer value * with the most significant octet encoded first (big-endian representation). * The minimum number of octets must be used to encode the value. * Short-length = <Any octet 0-30> */ assert(null != pduDataStream); int temp = pduDataStream.read(); assert(-1 != temp); int count = temp & 0xFF; if (count > LONG_INTEGER_LENGTH_MAX) { throw new RuntimeException("Octet count greater than 8 and I can't represent that!"); } long result = 0; for (int i = 0 ; i < count ; i++) { temp = pduDataStream.read(); assert(-1 != temp); result <<= 8; result += (temp & 0xFF); } return result; } /** * Parse Integer-Value. * * @param pduDataStream pdu data input stream * @return long integer */ protected static long parseIntegerValue(ByteArrayInputStream pduDataStream) { /** * From wap-230-wsp-20010705-a.pdf * Integer-Value = Short-integer | Long-integer */ assert(null != pduDataStream); pduDataStream.mark(1); int temp = pduDataStream.read(); assert(-1 != temp); pduDataStream.reset(); if (temp > SHORT_INTEGER_MAX) { return parseShortInteger(pduDataStream); } else { return parseLongInteger(pduDataStream); } } /** * To skip length of the wap value. * * @param pduDataStream pdu data input stream * @param length area size * @return the values in this area */ protected static int skipWapValue(ByteArrayInputStream pduDataStream, int length) { assert(null != pduDataStream); byte[] area = new byte[length]; int readLen = pduDataStream.read(area, 0, length); if (readLen < length) { //The actually read length is lower than the length return -1; } else { return readLen; } } /** * Parse content type parameters. For now we just support * four parameters used in mms: "type", "start", "name", "charset". * * @param pduDataStream pdu data input stream * @param map to store parameters of Content-Type field * @param length length of all the parameters */ protected static void parseContentTypeParams(ByteArrayInputStream pduDataStream, HashMap<Integer, Object> map, Integer length) { /** * From wap-230-wsp-20010705-a.pdf * Parameter = Typed-parameter | Untyped-parameter * Typed-parameter = Well-known-parameter-token Typed-value * the actual expected type of the value is implied by the well-known parameter * Well-known-parameter-token = Integer-value * the code values used for parameters are specified in the Assigned Numbers appendix * Typed-value = Compact-value | Text-value * In addition to the expected type, there may be no value. * If the value cannot be encoded using the expected type, it shall be encoded as text. * Compact-value = Integer-value | * Date-value | Delta-seconds-value | Q-value | Version-value | * Uri-value * Untyped-parameter = Token-text Untyped-value * the type of the value is unknown, but it shall be encoded as an integer, * if that is possible. * Untyped-value = Integer-value | Text-value */ assert(null != pduDataStream); assert(length > 0); int startPos = pduDataStream.available(); int tempPos = 0; int lastLen = length; while(0 < lastLen) { int param = pduDataStream.read(); assert(-1 != param); lastLen--; switch (param) { /** * From rfc2387, chapter 3.1 * The type parameter must be specified and its value is the MIME media * type of the "root" body part. It permits a MIME user agent to * determine the content-type without reference to the enclosed body * part. If the value of the type parameter and the root body part's * content-type differ then the User Agent's behavior is undefined. * * From wap-230-wsp-20010705-a.pdf * type = Constrained-encoding * Constrained-encoding = Extension-Media | Short-integer * Extension-media = *TEXT End-of-string */ case PduPart.P_TYPE: case PduPart.P_CT_MR_TYPE: pduDataStream.mark(1); int first = extractByteValue(pduDataStream); pduDataStream.reset(); if (first > TEXT_MAX) { // Short-integer (well-known type) int index = parseShortInteger(pduDataStream); if (index < PduContentTypes.contentTypes.length) { byte[] type = (PduContentTypes.contentTypes[index]).getBytes(); map.put(PduPart.P_TYPE, type); } else { //not support this type, ignore it. } } else { // Text-String (extension-media) byte[] type = parseWapString(pduDataStream, TYPE_TEXT_STRING); if ((null != type) && (null != map)) { map.put(PduPart.P_TYPE, type); } } tempPos = pduDataStream.available(); lastLen = length - (startPos - tempPos); break; /** * From oma-ts-mms-conf-v1_3.pdf, chapter 10.2.3. * Start Parameter Referring to Presentation * * From rfc2387, chapter 3.2 * The start parameter, if given, is the content-ID of the compound * object's "root". If not present the "root" is the first body part in * the Multipart/Related entity. The "root" is the element the * applications processes first. * * From wap-230-wsp-20010705-a.pdf * start = Text-String */ case PduPart.P_START: case PduPart.P_DEP_START: byte[] start = parseWapString(pduDataStream, TYPE_TEXT_STRING); if ((null != start) && (null != map)) { map.put(PduPart.P_START, start); } tempPos = pduDataStream.available(); lastLen = length - (startPos - tempPos); break; /** * From oma-ts-mms-conf-v1_3.pdf * In creation, the character set SHALL be either us-ascii * (IANA MIBenum 3) or utf-8 (IANA MIBenum 106)[Unicode]. * In retrieval, both us-ascii and utf-8 SHALL be supported. * * From wap-230-wsp-20010705-a.pdf * charset = Well-known-charset|Text-String * Well-known-charset = Any-charset | Integer-value * Both are encoded using values from Character Set * Assignments table in Assigned Numbers * Any-charset = <Octet 128> * Equivalent to the special RFC2616 charset value "*" */ case PduPart.P_CHARSET: pduDataStream.mark(1); int firstValue = extractByteValue(pduDataStream); pduDataStream.reset(); //Check first char if (((firstValue > TEXT_MIN) && (firstValue < TEXT_MAX)) || (END_STRING_FLAG == firstValue)) { //Text-String (extension-charset) byte[] charsetStr = parseWapString(pduDataStream, TYPE_TEXT_STRING); try { int charsetInt = CharacterSets.getMibEnumValue( new String(charsetStr)); map.put(PduPart.P_CHARSET, charsetInt); } catch (UnsupportedEncodingException e) { // Not a well-known charset, use "*". Log.e(LOG_TAG, Arrays.toString(charsetStr), e); map.put(PduPart.P_CHARSET, CharacterSets.ANY_CHARSET); } } else { //Well-known-charset int charset = (int) parseIntegerValue(pduDataStream); if (map != null) { map.put(PduPart.P_CHARSET, charset); } } tempPos = pduDataStream.available(); lastLen = length - (startPos - tempPos); break; /** * From oma-ts-mms-conf-v1_3.pdf * A name for multipart object SHALL be encoded using name-parameter * for Content-Type header in WSP multipart headers. * * From wap-230-wsp-20010705-a.pdf * name = Text-String */ case PduPart.P_DEP_NAME: case PduPart.P_NAME: byte[] name = parseWapString(pduDataStream, TYPE_TEXT_STRING); if ((null != name) && (null != map)) { map.put(PduPart.P_NAME, name); } tempPos = pduDataStream.available(); lastLen = length - (startPos - tempPos); break; default: Log.v(LOG_TAG, "Not supported Content-Type parameter"); if (-1 == skipWapValue(pduDataStream, lastLen)) { Log.e(LOG_TAG, "Corrupt Content-Type"); } else { lastLen = 0; } break; } } if (0 != lastLen) { Log.e(LOG_TAG, "Corrupt Content-Type"); } } /** * Parse content type. * * @param pduDataStream pdu data input stream * @param map to store parameters in Content-Type header field * @return Content-Type value */ protected static byte[] parseContentType(ByteArrayInputStream pduDataStream, HashMap<Integer, Object> map) { /** * From wap-230-wsp-20010705-a.pdf * Content-type-value = Constrained-media | Content-general-form * Content-general-form = Value-length Media-type * Media-type = (Well-known-media | Extension-Media) *(Parameter) */ assert(null != pduDataStream); byte[] contentType = null; pduDataStream.mark(1); int temp = pduDataStream.read(); assert(-1 != temp); pduDataStream.reset(); int cur = (temp & 0xFF); if (cur < TEXT_MIN) { int length = parseValueLength(pduDataStream); int startPos = pduDataStream.available(); pduDataStream.mark(1); temp = pduDataStream.read(); assert(-1 != temp); pduDataStream.reset(); int first = (temp & 0xFF); if ((first >= TEXT_MIN) && (first <= TEXT_MAX)) { contentType = parseWapString(pduDataStream, TYPE_TEXT_STRING); } else if (first > TEXT_MAX) { int index = parseShortInteger(pduDataStream); if (index < PduContentTypes.contentTypes.length) { //well-known type contentType = (PduContentTypes.contentTypes[index]).getBytes(); } else { pduDataStream.reset(); contentType = parseWapString(pduDataStream, TYPE_TEXT_STRING); } } else { Log.e(LOG_TAG, "Corrupt content-type"); return (PduContentTypes.contentTypes[0]).getBytes(); //"*/*" } int endPos = pduDataStream.available(); int parameterLen = length - (startPos - endPos); if (parameterLen > 0) {//have parameters parseContentTypeParams(pduDataStream, map, parameterLen); } if (parameterLen < 0) { Log.e(LOG_TAG, "Corrupt MMS message"); return (PduContentTypes.contentTypes[0]).getBytes(); //"*/*" } } else if (cur <= TEXT_MAX) { contentType = parseWapString(pduDataStream, TYPE_TEXT_STRING); } else { contentType = (PduContentTypes.contentTypes[parseShortInteger(pduDataStream)]).getBytes(); } return contentType; } /** * Check mandatory headers of a pdu. * * @param headers pdu headers * @return true if the pdu has all of the mandatory headers, false otherwise. */ protected static boolean checkMandatoryHeader(PduHeaders headers) { if (null == headers) { return false; } /* get message type */ int messageType = headers.getOctet(PduHeaders.MESSAGE_TYPE); /* check Mms-Version field */ int mmsVersion = headers.getOctet(PduHeaders.MMS_VERSION); if (0 == mmsVersion) { // Every message should have Mms-Version field. return false; } /* check mandatory header fields */ switch (messageType) { case PduHeaders.MESSAGE_TYPE_SEND_REQ: // Content-Type field. byte[] srContentType = headers.getTextString(PduHeaders.CONTENT_TYPE); if (null == srContentType) { return false; } // From field. EncodedStringValue srFrom = headers.getEncodedStringValue(PduHeaders.FROM); if (null == srFrom) { return false; } // Transaction-Id field. byte[] srTransactionId = headers.getTextString(PduHeaders.TRANSACTION_ID); if (null == srTransactionId) { return false; } break; case PduHeaders.MESSAGE_TYPE_SEND_CONF: // Response-Status field. int scResponseStatus = headers.getOctet(PduHeaders.RESPONSE_STATUS); if (0 == scResponseStatus) { return false; } // Transaction-Id field. byte[] scTransactionId = headers.getTextString(PduHeaders.TRANSACTION_ID); if (null == scTransactionId) { return false; } break; case PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND: // Content-Location field. byte[] niContentLocation = headers.getTextString(PduHeaders.CONTENT_LOCATION); if (null == niContentLocation) { return false; } // Expiry field. long niExpiry = headers.getLongInteger(PduHeaders.EXPIRY); if (-1 == niExpiry) { return false; } // Message-Class field. byte[] niMessageClass = headers.getTextString(PduHeaders.MESSAGE_CLASS); if (null == niMessageClass) { return false; } // Message-Size field. long niMessageSize = headers.getLongInteger(PduHeaders.MESSAGE_SIZE); if (-1 == niMessageSize) { return false; } // Transaction-Id field. byte[] niTransactionId = headers.getTextString(PduHeaders.TRANSACTION_ID); if (null == niTransactionId) { return false; } break; case PduHeaders.MESSAGE_TYPE_NOTIFYRESP_IND: // Status field. int nriStatus = headers.getOctet(PduHeaders.STATUS); if (0 == nriStatus) { return false; } // Transaction-Id field. byte[] nriTransactionId = headers.getTextString(PduHeaders.TRANSACTION_ID); if (null == nriTransactionId) { return false; } break; case PduHeaders.MESSAGE_TYPE_RETRIEVE_CONF: // Content-Type field. byte[] rcContentType = headers.getTextString(PduHeaders.CONTENT_TYPE); if (null == rcContentType) { return false; } // Date field. long rcDate = headers.getLongInteger(PduHeaders.DATE); if (-1 == rcDate) { return false; } break; case PduHeaders.MESSAGE_TYPE_DELIVERY_IND: // Date field. long diDate = headers.getLongInteger(PduHeaders.DATE); if (-1 == diDate) { return false; } // Message-Id field. byte[] diMessageId = headers.getTextString(PduHeaders.MESSAGE_ID); if (null == diMessageId) { return false; } // Status field. int diStatus = headers.getOctet(PduHeaders.STATUS); if (0 == diStatus) { return false; } // To field. EncodedStringValue[] diTo = headers.getEncodedStringValues(PduHeaders.TO); if (null == diTo) { return false; } break; case PduHeaders.MESSAGE_TYPE_ACKNOWLEDGE_IND: // Transaction-Id field. byte[] aiTransactionId = headers.getTextString(PduHeaders.TRANSACTION_ID); if (null == aiTransactionId) { return false; } break; case PduHeaders.MESSAGE_TYPE_READ_ORIG_IND: // Date field. long roDate = headers.getLongInteger(PduHeaders.DATE); if (-1 == roDate) { return false; } // From field. EncodedStringValue roFrom = headers.getEncodedStringValue(PduHeaders.FROM); if (null == roFrom) { return false; } // Message-Id field. byte[] roMessageId = headers.getTextString(PduHeaders.MESSAGE_ID); if (null == roMessageId) { return false; } // Read-Status field. int roReadStatus = headers.getOctet(PduHeaders.READ_STATUS); if (0 == roReadStatus) { return false; } // To field. EncodedStringValue[] roTo = headers.getEncodedStringValues(PduHeaders.TO); if (null == roTo) { return false; } break; case PduHeaders.MESSAGE_TYPE_READ_REC_IND: // From field. EncodedStringValue rrFrom = headers.getEncodedStringValue(PduHeaders.FROM); if (null == rrFrom) { return false; } // Message-Id field. byte[] rrMessageId = headers.getTextString(PduHeaders.MESSAGE_ID); if (null == rrMessageId) { return false; } // Read-Status field. int rrReadStatus = headers.getOctet(PduHeaders.READ_STATUS); if (0 == rrReadStatus) { return false; } // To field. EncodedStringValue[] rrTo = headers.getEncodedStringValues(PduHeaders.TO); if (null == rrTo) { return false; } break; default: // Parser doesn't support this message type in this version. return false; } return true; } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/event/receivers/mms/PduParser.java
Java
asf20
56,305
/* * Copyright (C) 2007 Esmertec AG. * Copyright (C) 2007 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.event.receivers.mms; class PduContentTypes { /** * All content types. From: * http://www.openmobilealliance.org/tech/omna/omna-wsp-content-type.htm */ static final String[] contentTypes = { "*/*", /* 0x00 */ "text/*", /* 0x01 */ "text/html", /* 0x02 */ "text/plain", /* 0x03 */ "text/x-hdml", /* 0x04 */ "text/x-ttml", /* 0x05 */ "text/x-vCalendar", /* 0x06 */ "text/x-vCard", /* 0x07 */ "text/vnd.wap.wml", /* 0x08 */ "text/vnd.wap.wmlscript", /* 0x09 */ "text/vnd.wap.wta-event", /* 0x0A */ "multipart/*", /* 0x0B */ "multipart/mixed", /* 0x0C */ "multipart/form-data", /* 0x0D */ "multipart/byterantes", /* 0x0E */ "multipart/alternative", /* 0x0F */ "application/*", /* 0x10 */ "application/java-vm", /* 0x11 */ "application/x-www-form-urlencoded", /* 0x12 */ "application/x-hdmlc", /* 0x13 */ "application/vnd.wap.wmlc", /* 0x14 */ "application/vnd.wap.wmlscriptc", /* 0x15 */ "application/vnd.wap.wta-eventc", /* 0x16 */ "application/vnd.wap.uaprof", /* 0x17 */ "application/vnd.wap.wtls-ca-certificate", /* 0x18 */ "application/vnd.wap.wtls-user-certificate", /* 0x19 */ "application/x-x509-ca-cert", /* 0x1A */ "application/x-x509-user-cert", /* 0x1B */ "image/*", /* 0x1C */ "image/gif", /* 0x1D */ "image/jpeg", /* 0x1E */ "image/tiff", /* 0x1F */ "image/png", /* 0x20 */ "image/vnd.wap.wbmp", /* 0x21 */ "application/vnd.wap.multipart.*", /* 0x22 */ "application/vnd.wap.multipart.mixed", /* 0x23 */ "application/vnd.wap.multipart.form-data", /* 0x24 */ "application/vnd.wap.multipart.byteranges", /* 0x25 */ "application/vnd.wap.multipart.alternative", /* 0x26 */ "application/xml", /* 0x27 */ "text/xml", /* 0x28 */ "application/vnd.wap.wbxml", /* 0x29 */ "application/x-x968-cross-cert", /* 0x2A */ "application/x-x968-ca-cert", /* 0x2B */ "application/x-x968-user-cert", /* 0x2C */ "text/vnd.wap.si", /* 0x2D */ "application/vnd.wap.sic", /* 0x2E */ "text/vnd.wap.sl", /* 0x2F */ "application/vnd.wap.slc", /* 0x30 */ "text/vnd.wap.co", /* 0x31 */ "application/vnd.wap.coc", /* 0x32 */ "application/vnd.wap.multipart.related", /* 0x33 */ "application/vnd.wap.sia", /* 0x34 */ "text/vnd.wap.connectivity-xml", /* 0x35 */ "application/vnd.wap.connectivity-wbxml", /* 0x36 */ "application/pkcs7-mime", /* 0x37 */ "application/vnd.wap.hashed-certificate", /* 0x38 */ "application/vnd.wap.signed-certificate", /* 0x39 */ "application/vnd.wap.cert-response", /* 0x3A */ "application/xhtml+xml", /* 0x3B */ "application/wml+xml", /* 0x3C */ "text/css", /* 0x3D */ "application/vnd.wap.mms-message", /* 0x3E */ "application/vnd.wap.rollover-certificate", /* 0x3F */ "application/vnd.wap.locc+wbxml", /* 0x40 */ "application/vnd.wap.loc+xml", /* 0x41 */ "application/vnd.syncml.dm+wbxml", /* 0x42 */ "application/vnd.syncml.dm+xml", /* 0x43 */ "application/vnd.syncml.notification", /* 0x44 */ "application/vnd.wap.xhtml+xml", /* 0x45 */ "application/vnd.wv.csp.cir", /* 0x46 */ "application/vnd.oma.dd+xml", /* 0x47 */ "application/vnd.oma.drm.message", /* 0x48 */ "application/vnd.oma.drm.content", /* 0x49 */ "application/vnd.oma.drm.rights+xml", /* 0x4A */ "application/vnd.oma.drm.rights+wbxml", /* 0x4B */ "application/vnd.wv.csp+xml", /* 0x4C */ "application/vnd.wv.csp+wbxml", /* 0x4D */ "application/vnd.syncml.ds.notification", /* 0x4E */ "audio/*", /* 0x4F */ "video/*", /* 0x50 */ "application/vnd.oma.dd2+xml", /* 0x51 */ "application/mikey" /* 0x52 */ }; }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/event/receivers/mms/PduContentTypes.java
Java
asf20
6,303
/* * Copyright (C) 2007 Esmertec AG. * Copyright (C) 2007 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.event.receivers.mms; import java.util.ArrayList; import java.util.HashMap; class PduHeaders { /** * All pdu header fields. */ public static final int BCC = 0x81; public static final int CC = 0x82; public static final int CONTENT_LOCATION = 0x83; public static final int CONTENT_TYPE = 0x84; public static final int DATE = 0x85; public static final int DELIVERY_REPORT = 0x86; public static final int DELIVERY_TIME = 0x87; public static final int EXPIRY = 0x88; public static final int FROM = 0x89; public static final int MESSAGE_CLASS = 0x8A; public static final int MESSAGE_ID = 0x8B; public static final int MESSAGE_TYPE = 0x8C; public static final int MMS_VERSION = 0x8D; public static final int MESSAGE_SIZE = 0x8E; public static final int PRIORITY = 0x8F; public static final int READ_REPLY = 0x90; public static final int READ_REPORT = 0x90; public static final int REPORT_ALLOWED = 0x91; public static final int RESPONSE_STATUS = 0x92; public static final int RESPONSE_TEXT = 0x93; public static final int SENDER_VISIBILITY = 0x94; public static final int STATUS = 0x95; public static final int SUBJECT = 0x96; public static final int TO = 0x97; public static final int TRANSACTION_ID = 0x98; public static final int RETRIEVE_STATUS = 0x99; public static final int RETRIEVE_TEXT = 0x9A; public static final int READ_STATUS = 0x9B; public static final int REPLY_CHARGING = 0x9C; public static final int REPLY_CHARGING_DEADLINE = 0x9D; public static final int REPLY_CHARGING_ID = 0x9E; public static final int REPLY_CHARGING_SIZE = 0x9F; public static final int PREVIOUSLY_SENT_BY = 0xA0; public static final int PREVIOUSLY_SENT_DATE = 0xA1; public static final int STORE = 0xA2; public static final int MM_STATE = 0xA3; public static final int MM_FLAGS = 0xA4; public static final int STORE_STATUS = 0xA5; public static final int STORE_STATUS_TEXT = 0xA6; public static final int STORED = 0xA7; public static final int ATTRIBUTES = 0xA8; public static final int TOTALS = 0xA9; public static final int MBOX_TOTALS = 0xAA; public static final int QUOTAS = 0xAB; public static final int MBOX_QUOTAS = 0xAC; public static final int MESSAGE_COUNT = 0xAD; public static final int CONTENT = 0xAE; public static final int START = 0xAF; public static final int ADDITIONAL_HEADERS = 0xB0; public static final int DISTRIBUTION_INDICATOR = 0xB1; public static final int ELEMENT_DESCRIPTOR = 0xB2; public static final int LIMIT = 0xB3; public static final int RECOMMENDED_RETRIEVAL_MODE = 0xB4; public static final int RECOMMENDED_RETRIEVAL_MODE_TEXT = 0xB5; public static final int STATUS_TEXT = 0xB6; public static final int APPLIC_ID = 0xB7; public static final int REPLY_APPLIC_ID = 0xB8; public static final int AUX_APPLIC_ID = 0xB9; public static final int CONTENT_CLASS = 0xBA; public static final int DRM_CONTENT = 0xBB; public static final int ADAPTATION_ALLOWED = 0xBC; public static final int REPLACE_ID = 0xBD; public static final int CANCEL_ID = 0xBE; public static final int CANCEL_STATUS = 0xBF; /** * X-Mms-Message-Type field types. */ public static final int MESSAGE_TYPE_SEND_REQ = 0x80; public static final int MESSAGE_TYPE_SEND_CONF = 0x81; public static final int MESSAGE_TYPE_NOTIFICATION_IND = 0x82; public static final int MESSAGE_TYPE_NOTIFYRESP_IND = 0x83; public static final int MESSAGE_TYPE_RETRIEVE_CONF = 0x84; public static final int MESSAGE_TYPE_ACKNOWLEDGE_IND = 0x85; public static final int MESSAGE_TYPE_DELIVERY_IND = 0x86; public static final int MESSAGE_TYPE_READ_REC_IND = 0x87; public static final int MESSAGE_TYPE_READ_ORIG_IND = 0x88; public static final int MESSAGE_TYPE_FORWARD_REQ = 0x89; public static final int MESSAGE_TYPE_FORWARD_CONF = 0x8A; public static final int MESSAGE_TYPE_MBOX_STORE_REQ = 0x8B; public static final int MESSAGE_TYPE_MBOX_STORE_CONF = 0x8C; public static final int MESSAGE_TYPE_MBOX_VIEW_REQ = 0x8D; public static final int MESSAGE_TYPE_MBOX_VIEW_CONF = 0x8E; public static final int MESSAGE_TYPE_MBOX_UPLOAD_REQ = 0x8F; public static final int MESSAGE_TYPE_MBOX_UPLOAD_CONF = 0x90; public static final int MESSAGE_TYPE_MBOX_DELETE_REQ = 0x91; public static final int MESSAGE_TYPE_MBOX_DELETE_CONF = 0x92; public static final int MESSAGE_TYPE_MBOX_DESCR = 0x93; public static final int MESSAGE_TYPE_DELETE_REQ = 0x94; public static final int MESSAGE_TYPE_DELETE_CONF = 0x95; public static final int MESSAGE_TYPE_CANCEL_REQ = 0x96; public static final int MESSAGE_TYPE_CANCEL_CONF = 0x97; /** * X-Mms-Delivery-Report | * X-Mms-Read-Report | * X-Mms-Report-Allowed | * X-Mms-Sender-Visibility | * X-Mms-Store | * X-Mms-Stored | * X-Mms-Totals | * X-Mms-Quotas | * X-Mms-Distribution-Indicator | * X-Mms-DRM-Content | * X-Mms-Adaptation-Allowed | * field types. */ public static final int VALUE_YES = 0x80; public static final int VALUE_NO = 0x81; /** * Delivery-Time | * Expiry and Reply-Charging-Deadline | * field type components. */ public static final int VALUE_ABSOLUTE_TOKEN = 0x80; public static final int VALUE_RELATIVE_TOKEN = 0x81; /** * X-Mms-MMS-Version field types. */ public static final int MMS_VERSION_1_3 = ((1 << 4) | 3); public static final int MMS_VERSION_1_2 = ((1 << 4) | 2); public static final int MMS_VERSION_1_1 = ((1 << 4) | 1); public static final int MMS_VERSION_1_0 = ((1 << 4) | 0); // Current version is 1.2. public static final int CURRENT_MMS_VERSION = MMS_VERSION_1_2; /** * From field type components. */ public static final int FROM_ADDRESS_PRESENT_TOKEN = 0x80; public static final int FROM_INSERT_ADDRESS_TOKEN = 0x81; public static final String FROM_ADDRESS_PRESENT_TOKEN_STR = "address-present-token"; public static final String FROM_INSERT_ADDRESS_TOKEN_STR = "insert-address-token"; /** * X-Mms-Status Field. */ public static final int STATUS_EXPIRED = 0x80; public static final int STATUS_RETRIEVED = 0x81; public static final int STATUS_REJECTED = 0x82; public static final int STATUS_DEFERRED = 0x83; public static final int STATUS_UNRECOGNIZED = 0x84; public static final int STATUS_INDETERMINATE = 0x85; public static final int STATUS_FORWARDED = 0x86; public static final int STATUS_UNREACHABLE = 0x87; /** * MM-Flags field type components. */ public static final int MM_FLAGS_ADD_TOKEN = 0x80; public static final int MM_FLAGS_REMOVE_TOKEN = 0x81; public static final int MM_FLAGS_FILTER_TOKEN = 0x82; /** * X-Mms-Message-Class field types. */ public static final int MESSAGE_CLASS_PERSONAL = 0x80; public static final int MESSAGE_CLASS_ADVERTISEMENT = 0x81; public static final int MESSAGE_CLASS_INFORMATIONAL = 0x82; public static final int MESSAGE_CLASS_AUTO = 0x83; public static final String MESSAGE_CLASS_PERSONAL_STR = "personal"; public static final String MESSAGE_CLASS_ADVERTISEMENT_STR = "advertisement"; public static final String MESSAGE_CLASS_INFORMATIONAL_STR = "informational"; public static final String MESSAGE_CLASS_AUTO_STR = "auto"; /** * X-Mms-Priority field types. */ public static final int PRIORITY_LOW = 0x80; public static final int PRIORITY_NORMAL = 0x81; public static final int PRIORITY_HIGH = 0x82; /** * X-Mms-Response-Status field types. */ public static final int RESPONSE_STATUS_OK = 0x80; public static final int RESPONSE_STATUS_ERROR_UNSPECIFIED = 0x81; public static final int RESPONSE_STATUS_ERROR_SERVICE_DENIED = 0x82; public static final int RESPONSE_STATUS_ERROR_MESSAGE_FORMAT_CORRUPT = 0x83; public static final int RESPONSE_STATUS_ERROR_SENDING_ADDRESS_UNRESOLVED = 0x84; public static final int RESPONSE_STATUS_ERROR_MESSAGE_NOT_FOUND = 0x85; public static final int RESPONSE_STATUS_ERROR_NETWORK_PROBLEM = 0x86; public static final int RESPONSE_STATUS_ERROR_CONTENT_NOT_ACCEPTED = 0x87; public static final int RESPONSE_STATUS_ERROR_UNSUPPORTED_MESSAGE = 0x88; public static final int RESPONSE_STATUS_ERROR_TRANSIENT_FAILURE = 0xC0; public static final int RESPONSE_STATUS_ERROR_TRANSIENT_SENDNG_ADDRESS_UNRESOLVED = 0xC1; public static final int RESPONSE_STATUS_ERROR_TRANSIENT_MESSAGE_NOT_FOUND = 0xC2; public static final int RESPONSE_STATUS_ERROR_TRANSIENT_NETWORK_PROBLEM = 0xC3; public static final int RESPONSE_STATUS_ERROR_TRANSIENT_PARTIAL_SUCCESS = 0xC4; public static final int RESPONSE_STATUS_ERROR_PERMANENT_FAILURE = 0xE0; public static final int RESPONSE_STATUS_ERROR_PERMANENT_SERVICE_DENIED = 0xE1; public static final int RESPONSE_STATUS_ERROR_PERMANENT_MESSAGE_FORMAT_CORRUPT = 0xE2; public static final int RESPONSE_STATUS_ERROR_PERMANENT_SENDING_ADDRESS_UNRESOLVED = 0xE3; public static final int RESPONSE_STATUS_ERROR_PERMANENT_MESSAGE_NOT_FOUND = 0xE4; public static final int RESPONSE_STATUS_ERROR_PERMANENT_CONTENT_NOT_ACCEPTED = 0xE5; public static final int RESPONSE_STATUS_ERROR_PERMANENT_REPLY_CHARGING_LIMITATIONS_NOT_MET = 0xE6; public static final int RESPONSE_STATUS_ERROR_PERMANENT_REPLY_CHARGING_REQUEST_NOT_ACCEPTED = 0xE6; public static final int RESPONSE_STATUS_ERROR_PERMANENT_REPLY_CHARGING_FORWARDING_DENIED = 0xE8; public static final int RESPONSE_STATUS_ERROR_PERMANENT_REPLY_CHARGING_NOT_SUPPORTED = 0xE9; public static final int RESPONSE_STATUS_ERROR_PERMANENT_ADDRESS_HIDING_NOT_SUPPORTED = 0xEA; public static final int RESPONSE_STATUS_ERROR_PERMANENT_LACK_OF_PREPAID = 0xEB; public static final int RESPONSE_STATUS_ERROR_PERMANENT_END = 0xFF; /** * X-Mms-Retrieve-Status field types. */ public static final int RETRIEVE_STATUS_OK = 0x80; public static final int RETRIEVE_STATUS_ERROR_TRANSIENT_FAILURE = 0xC0; public static final int RETRIEVE_STATUS_ERROR_TRANSIENT_MESSAGE_NOT_FOUND = 0xC1; public static final int RETRIEVE_STATUS_ERROR_TRANSIENT_NETWORK_PROBLEM = 0xC2; public static final int RETRIEVE_STATUS_ERROR_PERMANENT_FAILURE = 0xE0; public static final int RETRIEVE_STATUS_ERROR_PERMANENT_SERVICE_DENIED = 0xE1; public static final int RETRIEVE_STATUS_ERROR_PERMANENT_MESSAGE_NOT_FOUND = 0xE2; public static final int RETRIEVE_STATUS_ERROR_PERMANENT_CONTENT_UNSUPPORTED = 0xE3; public static final int RETRIEVE_STATUS_ERROR_END = 0xFF; /** * X-Mms-Sender-Visibility field types. */ public static final int SENDER_VISIBILITY_HIDE = 0x80; public static final int SENDER_VISIBILITY_SHOW = 0x81; /** * X-Mms-Read-Status field types. */ public static final int READ_STATUS_READ = 0x80; public static final int READ_STATUS__DELETED_WITHOUT_BEING_READ = 0x81; /** * X-Mms-Cancel-Status field types. */ public static final int CANCEL_STATUS_REQUEST_SUCCESSFULLY_RECEIVED = 0x80; public static final int CANCEL_STATUS_REQUEST_CORRUPTED = 0x81; /** * X-Mms-Reply-Charging field types. */ public static final int REPLY_CHARGING_REQUESTED = 0x80; public static final int REPLY_CHARGING_REQUESTED_TEXT_ONLY = 0x81; public static final int REPLY_CHARGING_ACCEPTED = 0x82; public static final int REPLY_CHARGING_ACCEPTED_TEXT_ONLY = 0x83; /** * X-Mms-MM-State field types. */ public static final int MM_STATE_DRAFT = 0x80; public static final int MM_STATE_SENT = 0x81; public static final int MM_STATE_NEW = 0x82; public static final int MM_STATE_RETRIEVED = 0x83; public static final int MM_STATE_FORWARDED = 0x84; /** * X-Mms-Recommended-Retrieval-Mode field types. */ public static final int RECOMMENDED_RETRIEVAL_MODE_MANUAL = 0x80; /** * X-Mms-Content-Class field types. */ public static final int CONTENT_CLASS_TEXT = 0x80; public static final int CONTENT_CLASS_IMAGE_BASIC = 0x81; public static final int CONTENT_CLASS_IMAGE_RICH = 0x82; public static final int CONTENT_CLASS_VIDEO_BASIC = 0x83; public static final int CONTENT_CLASS_VIDEO_RICH = 0x84; public static final int CONTENT_CLASS_MEGAPIXEL = 0x85; public static final int CONTENT_CLASS_CONTENT_BASIC = 0x86; public static final int CONTENT_CLASS_CONTENT_RICH = 0x87; /** * X-Mms-Store-Status field types. */ public static final int STORE_STATUS_SUCCESS = 0x80; public static final int STORE_STATUS_ERROR_TRANSIENT_FAILURE = 0xC0; public static final int STORE_STATUS_ERROR_TRANSIENT_NETWORK_PROBLEM = 0xC1; public static final int STORE_STATUS_ERROR_PERMANENT_FAILURE = 0xE0; public static final int STORE_STATUS_ERROR_PERMANENT_SERVICE_DENIED = 0xE1; public static final int STORE_STATUS_ERROR_PERMANENT_MESSAGE_FORMAT_CORRUPT = 0xE2; public static final int STORE_STATUS_ERROR_PERMANENT_MESSAGE_NOT_FOUND = 0xE3; public static final int STORE_STATUS_ERROR_PERMANENT_MMBOX_FULL = 0xE4; public static final int STORE_STATUS_ERROR_END = 0xFF; /** * The map contains the value of all headers. */ private HashMap<Integer, Object> mHeaderMap = null; /** * Constructor of PduHeaders. */ public PduHeaders() { mHeaderMap = new HashMap<Integer, Object>(); } /** * Get octet value by header field. * * @param field the field * @return the octet value of the pdu header * with specified header field. Return 0 if * the value is not set. */ protected int getOctet(int field) { Integer octet = (Integer) mHeaderMap.get(field); if (null == octet) { return 0; } return octet; } /** * Set octet value to pdu header by header field. * * @param value the value * @param field the field * @throws InvalidHeaderValueException if the value is invalid. */ protected void setOctet(int value, int field) throws IllegalArgumentException{ /** * Check whether this field can be set for specific * header and check validity of the field. */ switch (field) { case REPORT_ALLOWED: case ADAPTATION_ALLOWED: case DELIVERY_REPORT: case DRM_CONTENT: case DISTRIBUTION_INDICATOR: case QUOTAS: case READ_REPORT: case STORE: case STORED: case TOTALS: case SENDER_VISIBILITY: if ((VALUE_YES != value) && (VALUE_NO != value)) { // Invalid value. throw new IllegalArgumentException("Invalid Octet value!"); } break; case READ_STATUS: if ((READ_STATUS_READ != value) && (READ_STATUS__DELETED_WITHOUT_BEING_READ != value)) { // Invalid value. throw new IllegalArgumentException("Invalid Octet value!"); } break; case CANCEL_STATUS: if ((CANCEL_STATUS_REQUEST_SUCCESSFULLY_RECEIVED != value) && (CANCEL_STATUS_REQUEST_CORRUPTED != value)) { // Invalid value. throw new IllegalArgumentException("Invalid Octet value!"); } break; case PRIORITY: if ((value < PRIORITY_LOW) || (value > PRIORITY_HIGH)) { // Invalid value. throw new IllegalArgumentException("Invalid Octet value!"); } break; case STATUS: if ((value < STATUS_EXPIRED) || (value > STATUS_UNREACHABLE)) { // Invalid value. throw new IllegalArgumentException("Invalid Octet value!"); } break; case REPLY_CHARGING: if ((value < REPLY_CHARGING_REQUESTED) || (value > REPLY_CHARGING_ACCEPTED_TEXT_ONLY)) { // Invalid value. throw new IllegalArgumentException("Invalid Octet value!"); } break; case MM_STATE: if ((value < MM_STATE_DRAFT) || (value > MM_STATE_FORWARDED)) { // Invalid value. throw new IllegalArgumentException("Invalid Octet value!"); } break; case RECOMMENDED_RETRIEVAL_MODE: if (RECOMMENDED_RETRIEVAL_MODE_MANUAL != value) { // Invalid value. throw new IllegalArgumentException("Invalid Octet value!"); } break; case CONTENT_CLASS: if ((value < CONTENT_CLASS_TEXT) || (value > CONTENT_CLASS_CONTENT_RICH)) { // Invalid value. throw new IllegalArgumentException("Invalid Octet value!"); } break; case RETRIEVE_STATUS: // According to oma-ts-mms-enc-v1_3, section 7.3.50, we modify the invalid value. if ((value > RETRIEVE_STATUS_ERROR_TRANSIENT_NETWORK_PROBLEM) && (value < RETRIEVE_STATUS_ERROR_PERMANENT_FAILURE)) { value = RETRIEVE_STATUS_ERROR_TRANSIENT_FAILURE; } else if ((value > RETRIEVE_STATUS_ERROR_PERMANENT_CONTENT_UNSUPPORTED) && (value <= RETRIEVE_STATUS_ERROR_END)) { value = RETRIEVE_STATUS_ERROR_PERMANENT_FAILURE; } else if ((value < RETRIEVE_STATUS_OK) || ((value > RETRIEVE_STATUS_OK) && (value < RETRIEVE_STATUS_ERROR_TRANSIENT_FAILURE)) || (value > RETRIEVE_STATUS_ERROR_END)) { value = RETRIEVE_STATUS_ERROR_PERMANENT_FAILURE; } break; case STORE_STATUS: // According to oma-ts-mms-enc-v1_3, section 7.3.58, we modify the invalid value. if ((value > STORE_STATUS_ERROR_TRANSIENT_NETWORK_PROBLEM) && (value < STORE_STATUS_ERROR_PERMANENT_FAILURE)) { value = STORE_STATUS_ERROR_TRANSIENT_FAILURE; } else if ((value > STORE_STATUS_ERROR_PERMANENT_MMBOX_FULL) && (value <= STORE_STATUS_ERROR_END)) { value = STORE_STATUS_ERROR_PERMANENT_FAILURE; } else if ((value < STORE_STATUS_SUCCESS) || ((value > STORE_STATUS_SUCCESS) && (value < STORE_STATUS_ERROR_TRANSIENT_FAILURE)) || (value > STORE_STATUS_ERROR_END)) { value = STORE_STATUS_ERROR_PERMANENT_FAILURE; } break; case RESPONSE_STATUS: // According to oma-ts-mms-enc-v1_3, section 7.3.48, we modify the invalid value. if ((value > RESPONSE_STATUS_ERROR_TRANSIENT_PARTIAL_SUCCESS) && (value < RESPONSE_STATUS_ERROR_PERMANENT_FAILURE)) { value = RESPONSE_STATUS_ERROR_TRANSIENT_FAILURE; } else if (((value > RESPONSE_STATUS_ERROR_PERMANENT_LACK_OF_PREPAID) && (value <= RESPONSE_STATUS_ERROR_PERMANENT_END)) || (value < RESPONSE_STATUS_OK) || ((value > RESPONSE_STATUS_ERROR_UNSUPPORTED_MESSAGE) && (value < RESPONSE_STATUS_ERROR_TRANSIENT_FAILURE)) || (value > RESPONSE_STATUS_ERROR_PERMANENT_END)) { value = RESPONSE_STATUS_ERROR_PERMANENT_FAILURE; } break; case MMS_VERSION: if ((value < MMS_VERSION_1_0)|| (value > MMS_VERSION_1_3)) { value = CURRENT_MMS_VERSION; // Current version is the default value. } break; case MESSAGE_TYPE: if ((value < MESSAGE_TYPE_SEND_REQ) || (value > MESSAGE_TYPE_CANCEL_CONF)) { // Invalid value. throw new IllegalArgumentException("Invalid Octet value!"); } break; default: // This header value should not be Octect. throw new RuntimeException("Invalid header field!"); } mHeaderMap.put(field, value); } /** * Get TextString value by header field. * * @param field the field * @return the TextString value of the pdu header * with specified header field */ protected byte[] getTextString(int field) { return (byte[]) mHeaderMap.get(field); } /** * Set TextString value to pdu header by header field. * * @param value the value * @param field the field * @return the TextString value of the pdu header * with specified header field * @throws NullPointerException if the value is null. */ protected void setTextString(byte[] value, int field) { /** * Check whether this field can be set for specific * header and check validity of the field. */ if (null == value) { throw new NullPointerException(); } switch (field) { case TRANSACTION_ID: case REPLY_CHARGING_ID: case AUX_APPLIC_ID: case APPLIC_ID: case REPLY_APPLIC_ID: case MESSAGE_ID: case REPLACE_ID: case CANCEL_ID: case CONTENT_LOCATION: case MESSAGE_CLASS: case CONTENT_TYPE: break; default: // This header value should not be Text-String. throw new RuntimeException("Invalid header field!"); } mHeaderMap.put(field, value); } /** * Get EncodedStringValue value by header field. * * @param field the field * @return the EncodedStringValue value of the pdu header * with specified header field */ protected EncodedStringValue getEncodedStringValue(int field) { return (EncodedStringValue) mHeaderMap.get(field); } /** * Get TO, CC or BCC header value. * * @param field the field * @return the EncodeStringValue array of the pdu header * with specified header field */ protected EncodedStringValue[] getEncodedStringValues(int field) { @SuppressWarnings("unchecked") ArrayList<EncodedStringValue> list = (ArrayList<EncodedStringValue>) mHeaderMap.get(field); if (null == list) { return null; } EncodedStringValue[] values = new EncodedStringValue[list.size()]; return list.toArray(values); } /** * Set EncodedStringValue value to pdu header by header field. * * @param value the value * @param field the field * @return the EncodedStringValue value of the pdu header * with specified header field * @throws NullPointerException if the value is null. */ protected void setEncodedStringValue(EncodedStringValue value, int field) { /** * Check whether this field can be set for specific * header and check validity of the field. */ if (null == value) { throw new NullPointerException(); } switch (field) { case SUBJECT: case RECOMMENDED_RETRIEVAL_MODE_TEXT: case RETRIEVE_TEXT: case STATUS_TEXT: case STORE_STATUS_TEXT: case RESPONSE_TEXT: case FROM: case PREVIOUSLY_SENT_BY: case MM_FLAGS: break; default: // This header value should not be Encoded-String-Value. throw new RuntimeException("Invalid header field!"); } mHeaderMap.put(field, value); } /** * Set TO, CC or BCC header value. * * @param value the value * @param field the field * @return the EncodedStringValue value array of the pdu header * with specified header field * @throws NullPointerException if the value is null. */ protected void setEncodedStringValues(EncodedStringValue[] value, int field) { /** * Check whether this field can be set for specific * header and check validity of the field. */ if (null == value) { throw new NullPointerException(); } switch (field) { case BCC: case CC: case TO: break; default: // This header value should not be Encoded-String-Value. throw new RuntimeException("Invalid header field!"); } ArrayList<EncodedStringValue> list = new ArrayList<EncodedStringValue>(); for (int i = 0; i < value.length; i++) { list.add(value[i]); } mHeaderMap.put(field, list); } /** * Append one EncodedStringValue to another. * * @param value the EncodedStringValue to append * @param field the field * @throws NullPointerException if the value is null. */ protected void appendEncodedStringValue(EncodedStringValue value, int field) { if (null == value) { throw new NullPointerException(); } switch (field) { case BCC: case CC: case TO: break; default: throw new RuntimeException("Invalid header field!"); } @SuppressWarnings("unchecked") ArrayList<EncodedStringValue> list = (ArrayList<EncodedStringValue>) mHeaderMap.get(field); if (null == list) { list = new ArrayList<EncodedStringValue>(); } list.add(value); mHeaderMap.put(field, list); } /** * Get LongInteger value by header field. * * @param field the field * @return the LongInteger value of the pdu header * with specified header field. if return -1, the * field is not existed in pdu header. */ protected long getLongInteger(int field) { Long longInteger = (Long) mHeaderMap.get(field); if (null == longInteger) { return -1; } return longInteger.longValue(); } /** * Set LongInteger value to pdu header by header field. * * @param value the value * @param field the field */ protected void setLongInteger(long value, int field) { /** * Check whether this field can be set for specific * header and check validity of the field. */ switch (field) { case DATE: case REPLY_CHARGING_SIZE: case MESSAGE_SIZE: case MESSAGE_COUNT: case START: case LIMIT: case DELIVERY_TIME: case EXPIRY: case REPLY_CHARGING_DEADLINE: case PREVIOUSLY_SENT_DATE: break; default: // This header value should not be LongInteger. throw new RuntimeException("Invalid header field!"); } mHeaderMap.put(field, value); } public int getMessageType() { return getOctet(PduHeaders.MESSAGE_TYPE); } public EncodedStringValue getFrom() { return getEncodedStringValue(PduHeaders.FROM); } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/event/receivers/mms/PduHeaders.java
Java
asf20
31,431
/* * Copyright (C) 2007-2008 Esmertec AG. * Copyright (C) 2007-2008 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.event.receivers.mms; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import android.util.Log; /** * Encoded-string-value = Text-string | Value-length Char-set Text-string */ class EncodedStringValue implements Cloneable { private static final String TAG = "EncodedStringValue"; /** * The Char-set value. */ private int mCharacterSet; /** * The Text-string value. */ private byte[] mData; /** * Constructor. * * @param charset the Char-set value * @param data the Text-string value * @throws NullPointerException if Text-string value is null. */ public EncodedStringValue(int charset, byte[] data) { // TODO: CharSet needs to be validated against MIBEnum. if(null == data) { throw new NullPointerException("EncodedStringValue: Text-string is null."); } mCharacterSet = charset; mData = new byte[data.length]; System.arraycopy(data, 0, mData, 0, data.length); } /** * Constructor. * * @param data the Text-string value * @throws NullPointerException if Text-string value is null. */ public EncodedStringValue(byte[] data) { this(CharacterSets.DEFAULT_CHARSET, data); } public EncodedStringValue(String data) { try { mData = data.getBytes(CharacterSets.DEFAULT_CHARSET_NAME); mCharacterSet = CharacterSets.DEFAULT_CHARSET; } catch (UnsupportedEncodingException e) { Log.e(TAG, "Default encoding must be supported.", e); } } /** * Get Char-set value. * * @return the value */ public int getCharacterSet() { return mCharacterSet; } /** * Set Char-set value. * * @param charset the Char-set value */ public void setCharacterSet(int charset) { // TODO: CharSet needs to be validated against MIBEnum. mCharacterSet = charset; } /** * Get Text-string value. * * @return the value */ public byte[] getTextString() { byte[] byteArray = new byte[mData.length]; System.arraycopy(mData, 0, byteArray, 0, mData.length); return byteArray; } /** * Set Text-string value. * * @param textString the Text-string value * @throws NullPointerException if Text-string value is null. */ public void setTextString(byte[] textString) { if(null == textString) { throw new NullPointerException("EncodedStringValue: Text-string is null."); } mData = new byte[textString.length]; System.arraycopy(textString, 0, mData, 0, textString.length); } /** * Convert this object to a {@link java.lang.String}. If the encoding of * the EncodedStringValue is null or unsupported, it will be * treated as iso-8859-1 encoding. * * @return The decoded String. */ public String getString() { if (CharacterSets.ANY_CHARSET == mCharacterSet) { return new String(mData); // system default encoding. } else { try { String name = CharacterSets.getMimeName(mCharacterSet); return new String(mData, name); } catch (UnsupportedEncodingException e) { try { return new String(mData, CharacterSets.MIMENAME_ISO_8859_1); } catch (UnsupportedEncodingException _) { return new String(mData); // system default encoding. } } } } /** * Append to Text-string. * * @param textString the textString to append * @throws NullPointerException if the text String is null * or an IOException occured. */ public void appendTextString(byte[] textString) { if(null == textString) { throw new NullPointerException("Text-string is null."); } if(null == mData) { mData = new byte[textString.length]; System.arraycopy(textString, 0, mData, 0, textString.length); } else { ByteArrayOutputStream newTextString = new ByteArrayOutputStream(); try { newTextString.write(mData); newTextString.write(textString); } catch (IOException e) { e.printStackTrace(); throw new NullPointerException( "appendTextString: failed when write a new Text-string"); } mData = newTextString.toByteArray(); } } /* * (non-Javadoc) * @see java.lang.Object#clone() */ @Override public Object clone() throws CloneNotSupportedException { super.clone(); int len = mData.length; byte[] dstBytes = new byte[len]; System.arraycopy(mData, 0, dstBytes, 0, len); try { return new EncodedStringValue(mCharacterSet, dstBytes); } catch (Exception e) { Log.e(TAG, "failed to clone an EncodedStringValue: " + this); e.printStackTrace(); throw new CloneNotSupportedException(e.getMessage()); } } /** * Split this encoded string around matches of the given pattern. * * @param pattern the delimiting pattern * @return the array of encoded strings computed by splitting this encoded * string around matches of the given pattern */ public EncodedStringValue[] split(String pattern) { String[] temp = getString().split(pattern); EncodedStringValue[] ret = new EncodedStringValue[temp.length]; for (int i = 0; i < ret.length; ++i) { try { ret[i] = new EncodedStringValue(mCharacterSet, temp[i].getBytes()); } catch (NullPointerException _) { // Can't arrive here return null; } } return ret; } /** * Extract an EncodedStringValue[] from a given String. */ public static EncodedStringValue[] extract(String src) { String[] values = src.split(";"); ArrayList<EncodedStringValue> list = new ArrayList<EncodedStringValue>(); for (int i = 0; i < values.length; i++) { if (values[i].length() > 0) { list.add(new EncodedStringValue(values[i])); } } int len = list.size(); if (len > 0) { return list.toArray(new EncodedStringValue[len]); } else { return null; } } /** * Concatenate an EncodedStringValue[] into a single String. */ public static String concat(EncodedStringValue[] addr) { StringBuilder sb = new StringBuilder(); int maxIndex = addr.length - 1; for (int i = 0; i <= maxIndex; i++) { sb.append(addr[i].getString()); if (i < maxIndex) { sb.append(";"); } } return sb.toString(); } public static EncodedStringValue copy(EncodedStringValue value) { if (value == null) { return null; } return new EncodedStringValue(value.mCharacterSet, value.mData); } public static EncodedStringValue[] encodeStrings(String[] array) { int count = array.length; if (count > 0) { EncodedStringValue[] encodedArray = new EncodedStringValue[count]; for (int i = 0; i < count; i++) { encodedArray[i] = new EncodedStringValue(array[i]); } return encodedArray; } return null; } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/event/receivers/mms/EncodedStringValue.java
Java
asf20
8,501
/* * Copyright (C) 2007-2008 Esmertec AG. * Copyright (C) 2007-2008 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.event.receivers.mms; /** * The pdu part. */ class PduPart { /** * Well-Known Parameters. */ public static final int P_Q = 0x80; public static final int P_CHARSET = 0x81; public static final int P_LEVEL = 0x82; public static final int P_TYPE = 0x83; public static final int P_DEP_NAME = 0x85; public static final int P_DEP_FILENAME = 0x86; public static final int P_DIFFERENCES = 0x87; public static final int P_PADDING = 0x88; // This value of "TYPE" s used with Content-Type: multipart/related public static final int P_CT_MR_TYPE = 0x89; public static final int P_DEP_START = 0x8A; public static final int P_DEP_START_INFO = 0x8B; public static final int P_DEP_COMMENT = 0x8C; public static final int P_DEP_DOMAIN = 0x8D; public static final int P_MAX_AGE = 0x8E; public static final int P_DEP_PATH = 0x8F; public static final int P_SECURE = 0x90; public static final int P_SEC = 0x91; public static final int P_MAC = 0x92; public static final int P_CREATION_DATE = 0x93; public static final int P_MODIFICATION_DATE = 0x94; public static final int P_READ_DATE = 0x95; public static final int P_SIZE = 0x96; public static final int P_NAME = 0x97; public static final int P_FILENAME = 0x98; public static final int P_START = 0x99; public static final int P_START_INFO = 0x9A; public static final int P_COMMENT = 0x9B; public static final int P_DOMAIN = 0x9C; public static final int P_PATH = 0x9D; /** * Header field names. */ public static final int P_CONTENT_TYPE = 0x91; public static final int P_CONTENT_LOCATION = 0x8E; public static final int P_CONTENT_ID = 0xC0; public static final int P_DEP_CONTENT_DISPOSITION = 0xAE; public static final int P_CONTENT_DISPOSITION = 0xC5; // The next header is unassigned header, use reserved header(0x48) value. public static final int P_CONTENT_TRANSFER_ENCODING = 0xC8; /** * Content=Transfer-Encoding string. */ public static final String CONTENT_TRANSFER_ENCODING = "Content-Transfer-Encoding"; /** * Value of Content-Transfer-Encoding. */ public static final String P_BINARY = "binary"; public static final String P_7BIT = "7bit"; public static final String P_8BIT = "8bit"; public static final String P_BASE64 = "base64"; public static final String P_QUOTED_PRINTABLE = "quoted-printable"; /** * Value of disposition can be set to PduPart when the value is octet in * the PDU. * "from-data" instead of Form-data<Octet 128>. * "attachment" instead of Attachment<Octet 129>. * "inline" instead of Inline<Octet 130>. */ static final byte[] DISPOSITION_FROM_DATA = "from-data".getBytes(); static final byte[] DISPOSITION_ATTACHMENT = "attachment".getBytes(); static final byte[] DISPOSITION_INLINE = "inline".getBytes(); /** * Content-Disposition value. */ public static final int P_DISPOSITION_FROM_DATA = 0x80; public static final int P_DISPOSITION_ATTACHMENT = 0x81; public static final int P_DISPOSITION_INLINE = 0x82; private PduPart() { } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/event/receivers/mms/PduPart.java
Java
asf20
4,271
/* * Copyright 2011 Rodrigo Damazio * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.event.receivers; import static org.damazio.notifier.Constants.TAG; import org.damazio.notifier.NotifierService.NotifierServiceModule; import org.damazio.notifier.event.EventContext; import org.damazio.notifier.event.receivers.battery.BatteryEventReceiver; import org.damazio.notifier.event.receivers.phone.MissedCallListener; import org.damazio.notifier.event.receivers.phone.VoicemailListener; import org.damazio.notifier.prefs.Preferences.PreferenceListener; import org.damazio.notifier.protocol.Common.Event.Type; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.telephony.PhoneStateListener; import android.telephony.TelephonyManager; import android.util.Log; /** * Module which manages local event receivers. * (except those driven by broadcasts, which are registered directly in the Manifest) * * @author Rodrigo Damazio */ public class LocalEventReceiver implements NotifierServiceModule { private final EventContext eventContext; private final PreferenceListener preferenceListener = new PreferenceListener() { @Override public synchronized void onSendEventStateChanged(Type type, boolean enabled) { switch (type) { case NOTIFICATION_MISSED_CALL: onMissedCallStateChanged(enabled); break; case NOTIFICATION_BATTERY: onBatteryStateChanged(enabled); break; case NOTIFICATION_VOICEMAIL: onVoicemailStateChanged(enabled); break; case NOTIFICATION_RING: case NOTIFICATION_SMS: case NOTIFICATION_MMS: case NOTIFICATION_THIRD_PARTY: // These come in via global broadcast receivers, nothing to do. break; default: Log.w(TAG, "Unknown event type's state changed: " + type); } } }; private VoicemailListener voicemailListener; private BatteryEventReceiver batteryReceiver; private MissedCallListener missedCallListener; public LocalEventReceiver(EventContext eventContext) { this.eventContext = eventContext; } public void onCreate() { if (voicemailListener != null) { throw new IllegalStateException("Already started"); } // Register for preference changes, and also do an initial notification of // the current values. eventContext.getPreferences().registerListener(preferenceListener, true); } public void onDestroy() { eventContext.getPreferences().unregisterListener(preferenceListener); // Disable all events. onMissedCallStateChanged(false); onBatteryStateChanged(false); onVoicemailStateChanged(false); } private synchronized void onVoicemailStateChanged(boolean enabled) { if (voicemailListener != null ^ !enabled) { Log.d(TAG, "Voicemail state didn't change"); return; } TelephonyManager telephonyManager = (TelephonyManager) eventContext.getAndroidContext().getSystemService(Context.TELEPHONY_SERVICE); if (enabled) { voicemailListener = new VoicemailListener(eventContext); telephonyManager.listen(voicemailListener, PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR); } else { telephonyManager.listen(voicemailListener, PhoneStateListener.LISTEN_NONE); voicemailListener = null; } } private void onBatteryStateChanged(boolean enabled) { if (batteryReceiver != null ^ !enabled) { Log.d(TAG, "Battery state didn't change"); return; } if (enabled) { // Register the battery receiver // (can't be registered in the manifest for some reason) batteryReceiver = new BatteryEventReceiver(); eventContext.getAndroidContext().registerReceiver( batteryReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); } else { eventContext.getAndroidContext().unregisterReceiver(batteryReceiver); } } private synchronized void onMissedCallStateChanged(boolean enabled) { if (missedCallListener != null ^ !enabled) { Log.d(TAG, "Missed call state didn't change"); return; } if (enabled) { missedCallListener = new MissedCallListener(eventContext); missedCallListener.onCreate(); } else { missedCallListener.onDestroy(); missedCallListener = null; } } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/event/receivers/LocalEventReceiver.java
Java
asf20
4,916
/* * Copyright 2011 Rodrigo Damazio * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.event.receivers; import static org.damazio.notifier.Constants.TAG; import org.damazio.notifier.NotifierService; import org.damazio.notifier.comm.pairing.DeviceManager; import org.damazio.notifier.event.EventContext; import org.damazio.notifier.event.EventManager; import org.damazio.notifier.prefs.Preferences; import org.damazio.notifier.protocol.Common.Event; import org.damazio.notifier.protocol.Common.Event.Type; import com.google.protobuf.MessageLite; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; /** * Base class for all broadcast receivers which receive events. * * @author Rodrigo Damazio */ public abstract class EventBroadcastReceiver extends BroadcastReceiver { private EventManager eventManager; @Override public final void onReceive(Context context, Intent intent) { Type eventType = getEventType(); if (!intent.getAction().equals(getExpectedAction())) { Log.e(TAG, "Wrong intent received by receiver for " + eventType.name() + ": " + intent.getAction()); return; } NotifierService.startIfNotRunning(context); Preferences preferences = new Preferences(context); if (!preferences.isEventTypeEnabled(eventType)) { return; } synchronized (this) { DeviceManager deviceManager = new DeviceManager(); eventManager = new EventManager(context, deviceManager, preferences); onReceiveEvent(eventManager.getEventContext(), intent); eventManager = null; } } protected void handleEvent(MessageLite notification) { eventManager.handleLocalEvent(getEventType(), notification); } /** * Returns the event type being generated. */ protected abstract Event.Type getEventType(); /** * Returns the broadcast action this receiver handles. */ protected abstract String getExpectedAction(); /** * Processes the broadcast intent and calls {@link #handleEvent} with the results. */ protected abstract void onReceiveEvent(EventContext context, Intent intent); }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/event/receivers/EventBroadcastReceiver.java
Java
asf20
2,705
/* * Copyright 2011 Rodrigo Damazio * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.event.log; import android.net.Uri; import android.provider.BaseColumns; public interface EventLogColumns extends BaseColumns { public static final Uri URI = Uri.parse("content://org.damazio.notifier.eventlog/events"); public static final String URI_AUTHORITY = "org.damazio.notifier.eventlog"; public static final String TABLE_TYPE = "vnd.android.cursor.dir/vnd.damazio.event"; public static final String ITEM_TYPE = "vnd.android.cursor.item/vnd.damazio.event"; public static final String TABLE_NAME = "events"; public static final String COLUMN_TIMESTAMP = "timestamp"; public static final String COLUMN_SOURCE_DEVICE_ID = "source_device_id"; public static final String COLUMN_PROCESSED = "processed"; public static final String COLUMN_EVENT_TYPE = "event_type"; public static final String COLUMN_PAYLOAD = "payload"; }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/event/log/EventLogColumns.java
Java
asf20
1,474
/* * Copyright 2011 Rodrigo Damazio * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.event.log; import static org.damazio.notifier.Constants.TAG; import java.util.Arrays; import android.content.ContentProvider; import android.content.ContentResolver; import android.content.ContentUris; import android.content.ContentValues; import android.content.UriMatcher; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.net.Uri; import android.util.Log; /** * Content provider for the event log. * * @author Rodrigo Damazio */ public class EventLogProvider extends ContentProvider { /** If at least this many rows are deleted, we'll vacuum the database. */ private static final int VACUUM_DELETION_TRESHOLD = 100; private static final int MATCH_DIR = 1; private static final int MATCH_ITEM = 2; private LogDbHelper dbHelper; private SQLiteDatabase db; private UriMatcher uriMatcher; private ContentResolver contentResolver; public EventLogProvider() { this.uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); uriMatcher.addURI(EventLogColumns.URI_AUTHORITY, "events", MATCH_DIR); uriMatcher.addURI(EventLogColumns.URI_AUTHORITY, "events/#", MATCH_ITEM); } @Override public boolean onCreate() { this.contentResolver = getContext().getContentResolver(); this.dbHelper = new LogDbHelper(getContext()); this.db = dbHelper.getWritableDatabase(); return db != null; } @Override public int delete(Uri uri, String selection, String[] selectionArgs) { // TODO: Extract if (matchUriOrThrow(uri) == MATCH_ITEM) { String id = uri.getLastPathSegment(); if (selection != null) { selection = "(" + selection + ") AND _id = ?"; } else { selection = "_id = ?"; } if (selectionArgs != null) { selectionArgs = Arrays.copyOf(selectionArgs, selectionArgs.length + 1); } else { selectionArgs = new String[1]; } selectionArgs[selectionArgs.length - 1] = id; } int rows = db.delete(EventLogColumns.TABLE_NAME, selection, selectionArgs); contentResolver.notifyChange(uri, null); if (rows > VACUUM_DELETION_TRESHOLD) { Log.i(TAG, "Vacuuming the database"); db.execSQL("VACUUM"); } return rows; } @Override public String getType(Uri uri) { switch (uriMatcher.match(uri)) { case MATCH_DIR: return EventLogColumns.TABLE_TYPE; case MATCH_ITEM: return EventLogColumns.ITEM_TYPE; default: throw new IllegalArgumentException("Invalid URI type for '" + uri + "'."); } } @Override public Uri insert(Uri uri, ContentValues values) { if (matchUriOrThrow(uri) != MATCH_DIR) { throw new IllegalStateException("Cannot insert inside an item"); } long rowId = db.insertOrThrow(EventLogColumns.TABLE_NAME, null, values); Uri insertedUri = ContentUris.withAppendedId(uri, rowId); contentResolver.notifyChange(insertedUri, null); return insertedUri; } @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { if (matchUriOrThrow(uri) == MATCH_ITEM) { String id = uri.getLastPathSegment(); if (selection != null) { selection = "(" + selection + ") AND _id = ?"; } else { selection = "_id = ?"; } if (selectionArgs != null) { selectionArgs = Arrays.copyOf(selectionArgs, selectionArgs.length + 1); } else { selectionArgs = new String[1]; } selectionArgs[selectionArgs.length - 1] = id; } Cursor cursor = db.query(EventLogColumns.TABLE_NAME, projection, selection, selectionArgs, null, null, sortOrder); cursor.setNotificationUri(contentResolver, uri); return cursor; } @Override public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { if (matchUriOrThrow(uri) == MATCH_ITEM) { String id = uri.getLastPathSegment(); if (selection != null) { selection = "(" + selection + ") AND _id = ?"; } else { selection = "_id = ?"; } if (selectionArgs != null) { selectionArgs = Arrays.copyOf(selectionArgs, selectionArgs.length + 1); } else { selectionArgs = new String[1]; } selectionArgs[selectionArgs.length - 1] = id; } int numRows = db.update(EventLogColumns.TABLE_NAME, values, selection, selectionArgs); contentResolver.notifyChange(uri, null); return numRows; } private int matchUriOrThrow(Uri uri) { int match = uriMatcher.match(uri); if (match == UriMatcher.NO_MATCH) { throw new IllegalArgumentException("Invalid URI type for '" + uri + "'."); } return match; } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/event/log/EventLogProvider.java
Java
asf20
5,353
/* * Copyright 2011 Rodrigo Damazio * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.event.log; import static org.damazio.notifier.Constants.TAG; import org.damazio.notifier.protocol.Common.Event; import org.damazio.notifier.protocol.Common.Event.Builder; import com.google.protobuf.ByteString; import android.content.ContentResolver; import android.content.ContentValues; import android.database.ContentObserver; import android.database.Cursor; import android.net.Uri; import android.util.Log; public class EventLogHelper { private final ContentResolver contentResolver; public EventLogHelper(ContentResolver contentResolver) { this.contentResolver = contentResolver; } /** * * @param type * @param payload * @param timestamp * @param sourceDeviceId the ID of the device that sent the notification, or null if it was generated locally */ public void insertEvent(Event.Type type, byte[] payload, long timestamp, Long sourceDeviceId) { ContentValues values = new ContentValues(5); values.put(EventLogColumns.COLUMN_EVENT_TYPE, type.getNumber()); values.put(EventLogColumns.COLUMN_SOURCE_DEVICE_ID, sourceDeviceId); values.put(EventLogColumns.COLUMN_TIMESTAMP, timestamp); values.put(EventLogColumns.COLUMN_PAYLOAD, payload); Uri inserted = contentResolver.insert(EventLogColumns.URI, values); Log.d(TAG, "Created event row " + inserted); } public void registerContentObserver(ContentObserver observer) { contentResolver.registerContentObserver( EventLogColumns.URI, true, observer); } public void unregisterContentObserver(ContentObserver observber) { contentResolver.unregisterContentObserver(observber); } public Cursor getUnprocessedEvents(long minEventId) { return contentResolver.query(EventLogColumns.URI, null, EventLogColumns.COLUMN_PROCESSED + " = FALSE AND" + EventLogColumns._ID + " >= ?", new String[] { Long.toString(minEventId) }, null); } public Event buildEvent(Cursor cursor) { int typeIdx = cursor.getColumnIndexOrThrow(EventLogColumns.COLUMN_EVENT_TYPE); int sourceDeviceIdx = cursor.getColumnIndex(EventLogColumns.COLUMN_SOURCE_DEVICE_ID); int timestampIdx = cursor.getColumnIndexOrThrow(EventLogColumns.COLUMN_TIMESTAMP); int payloadIdx = cursor.getColumnIndex(EventLogColumns.COLUMN_PAYLOAD); Builder eventBuilder = Event.newBuilder(); eventBuilder.setTimestamp(cursor.getLong(timestampIdx)); eventBuilder.setType(Event.Type.valueOf(cursor.getInt(typeIdx))); if (payloadIdx != -1 && !cursor.isNull(payloadIdx)) { eventBuilder.setPayload(ByteString.copyFrom(cursor.getBlob(payloadIdx))); } if (sourceDeviceIdx != -1 && !cursor.isNull(sourceDeviceIdx)) { eventBuilder.setSourceDeviceId(cursor.getLong(sourceDeviceIdx)); } return eventBuilder.build(); } public void markEventProcessed(long eventId) { Uri uri = getEventUri(eventId); ContentValues values = new ContentValues(1); values.put(EventLogColumns.COLUMN_PROCESSED, true); contentResolver.update(uri, values , null, null); Log.d(TAG, "Marked event " + eventId + " as processed"); } public void deleteEvent(long eventId) { Uri uri = getEventUri(eventId); contentResolver.delete(uri, null, null); Log.d(TAG, "Deleted event" + eventId); } private Uri getEventUri(long eventId) { return Uri.withAppendedPath(EventLogColumns.URI, Long.toString(eventId)); } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/event/log/EventLogHelper.java
Java
asf20
4,022
/* * Copyright 2011 Rodrigo Damazio * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.event.log; import static org.damazio.notifier.Constants.TAG; import java.io.InputStream; import java.util.Scanner; import org.damazio.notifier.R; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; public class LogDbHelper extends SQLiteOpenHelper { private static final int CURRENT_DB_VERSION = 1; private static final String DB_NAME = "eventlog"; private final Context context; public LogDbHelper(Context context) { super(context, DB_NAME, null, CURRENT_DB_VERSION); this.context = context; } @Override public void onCreate(SQLiteDatabase db) { InputStream schemaStream = context.getResources().openRawResource(R.raw.logdb_schema); Scanner schemaScanner = new Scanner(schemaStream, "UTF-8"); schemaScanner.useDelimiter(";"); Log.i(TAG, "Creating database"); try { db.beginTransaction(); while (schemaScanner.hasNext()) { String statement = schemaScanner.next(); Log.d(TAG, "Creating database: " + statement); db.execSQL(statement); } db.setTransactionSuccessful(); } finally { db.endTransaction(); } } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // No upgrade for now. } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/event/log/LogDbHelper.java
Java
asf20
1,972
/* * Copyright 2011 Rodrigo Damazio * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.event; import static org.damazio.notifier.Constants.TAG; import java.util.HashSet; import java.util.Set; import org.damazio.notifier.comm.pairing.DeviceManager; import org.damazio.notifier.event.log.EventLogColumns; import org.damazio.notifier.event.log.EventLogHelper; import org.damazio.notifier.prefs.Preferences; import org.damazio.notifier.protocol.Common.Event; import android.content.Context; import android.database.ContentObserver; import android.database.Cursor; import android.os.Handler; import android.os.HandlerThread; import android.util.Log; import com.google.protobuf.MessageLite; public class EventManager { private final EventLogHelper logHelper; private final Preferences preferences; private final EventContext eventContext; private HandlerThread eventThread; private final Set<EventListener> listeners = new HashSet<EventListener>(); private ContentObserver logObserver; private long lastEventId; public EventManager(Context context) { this(context, new DeviceManager(), new Preferences(context)); } public EventManager(Context context, DeviceManager deviceManager, Preferences preferences) { this.logHelper = new EventLogHelper(context.getContentResolver()); this.preferences = preferences; // TODO: Cut this circular dependency this.eventContext = new EventContext(context, this, deviceManager, preferences); } public EventContext getEventContext() { return eventContext; } // TODO: How to ensure a wake lock is kept until the event is handled? public void handleLocalEvent(Event.Type eventType, MessageLite payload) { // Save the event to the event log. // Listeners will be notified by the logObserver. Log.d(TAG, "Saved event with type=" + eventType + "; payload=" + payload); logHelper.insertEvent(eventType, payload.toByteArray(), System.currentTimeMillis(), null); } public void handleRemoteEvent(Event event) { // Save the event to the event log. // Listeners will be notified by the logObserver. Log.d(TAG, "Received event " + event); logHelper.insertEvent(event.getType(), event.getPayload().toByteArray(), event.getTimestamp(), event.getSourceDeviceId()); } public void markEventProcessed(long eventId) { if (preferences.shouldPruneLog() && preferences.getPruneLogDays() == 0) { // Prune immediately. logHelper.deleteEvent(eventId); } else { logHelper.markEventProcessed(eventId); } } public void registerEventListeners(EventListener... addedListeners) { synchronized (listeners) { if (listeners.isEmpty()) { registerEventLogListener(); } for (EventListener listener : addedListeners) { listeners.add(listener); } } } public void unregisterEventListeners(EventListener... removedListeners) { synchronized (listeners) { for (EventListener listener : removedListeners) { listeners.remove(listener); } if (listeners.isEmpty()) { unregisterEventLogListener(); } } } public void forceRetryProcessing() { logObserver.dispatchChange(false); } private void registerEventLogListener() { if (eventThread != null) return; // Listen for new events in the event log. eventThread = new HandlerThread("EventObserverThread"); eventThread.start(); Handler handler = new Handler(eventThread.getLooper()); logObserver = new ContentObserver(handler) { @Override public void onChange(boolean selfChange) { notifyNewEvents(); } }; logHelper.registerContentObserver(logObserver); // Do an initial run to ensure any missed events are delivered. logObserver.dispatchChange(false); } private void unregisterEventLogListener() { if (eventThread == null) return; logHelper.unregisterContentObserver(logObserver); eventThread.quit(); try { eventThread.join(1000); } catch (InterruptedException e) { Log.e(TAG, "Failed to join event thread", e); } eventThread = null; logObserver = null; } private void notifyNewEvents() { // Get all unprocessed events since the last one. // TODO: Also retry older ones, up to a certain deadline, but not too quickly. Cursor cursor = logHelper.getUnprocessedEvents(lastEventId + 1); synchronized (listeners) { while (cursor.moveToNext()) { Event event = logHelper.buildEvent(cursor); Log.d(TAG, "Notifying about " + event.toString()); boolean isLocal = !event.hasSourceDeviceId(); boolean isCommand = ((event.getType().getNumber() & Event.Type.COMMAND_MASK_VALUE) != 0); lastEventId = cursor.getLong(cursor.getColumnIndexOrThrow(EventLogColumns._ID)); for (EventListener listener : listeners) { listener.onNewEvent(eventContext, lastEventId, event, isLocal, isCommand); } } } } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/event/EventManager.java
Java
asf20
5,533
/* * Copyright 2011 Rodrigo Damazio * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.prefs; import org.damazio.notifier.Constants; import android.app.backup.BackupAgentHelper; import android.app.backup.SharedPreferencesBackupHelper; /** * Backup agent for notifier data. * * @author Rodrigo Damazio */ public class BackupAgent extends BackupAgentHelper { @Override public void onCreate() { super.onCreate(); addHelper("sharedPrefs", new SharedPreferencesBackupHelper(this, Constants.PREFERENCES_NAME)); // TODO: Backup event log } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/prefs/BackupAgent.java
Java
asf20
1,102
/* * Copyright 2011 Rodrigo Damazio * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.prefs; import java.util.EnumSet; import java.util.HashSet; import java.util.Set; import org.damazio.notifier.Constants; import org.damazio.notifier.R; import org.damazio.notifier.comm.transport.TransportType; import org.damazio.notifier.protocol.Common.Event; import org.damazio.notifier.protocol.Common.Event.Type; import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; /** * Wrapper for preference access. * * @author Rodrigo Damazio */ public class Preferences { private final SharedPreferences prefs; private final Context context; private final Set<PreferenceListener> listeners = new HashSet<Preferences.PreferenceListener>(); private final OnSharedPreferenceChangeListener prefsListener = new OnSharedPreferenceChangeListener() { public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { notifyPreferenceChanged(key); } }; /** Semantic listener for preference changes. */ public static abstract class PreferenceListener { public void onStartForegroundChanged(boolean startForeground) {} public void onSendEventStateChanged(Event.Type type, boolean enabled) {} public void onTransportStateChanged(TransportType type, boolean enabled) {} } public Preferences(Context ctx) { this(ctx, ctx.getSharedPreferences(Constants.PREFERENCES_NAME, Context.MODE_PRIVATE)); } public Preferences(Context ctx, SharedPreferences prefs) { this.context = ctx; this.prefs = prefs; } public void registerListener(PreferenceListener listener) { registerListener(listener, false); } public void registerListener(PreferenceListener listener, boolean initialNotification) { synchronized (listeners) { if (listeners.isEmpty()) { prefs.registerOnSharedPreferenceChangeListener(prefsListener); } listeners.add(listener); if (initialNotification) { notifyAllPreferencesTo(listener); } } } public void unregisterListener(PreferenceListener listener) { synchronized (listeners) { listeners.remove(listener); if (listeners.isEmpty()) { prefs.unregisterOnSharedPreferenceChangeListener(prefsListener); } } } private void notifyPreferenceChanged(String key) { if (context.getString(R.string.prefkey_start_foreground).equals(key)) { synchronized (listeners) { boolean startForeground = startForeground(); for (PreferenceListener listener : listeners) { listener.onStartForegroundChanged(startForeground); } } } // TODO: Transport and event states } private void notifyAllPreferencesTo(PreferenceListener listener) { listener.onStartForegroundChanged(startForeground()); EnumSet<TransportType> enabledSendTransports = getEnabledTransports(); for (TransportType type : TransportType.values()) { listener.onTransportStateChanged(type, enabledSendTransports.contains(type)); } EnumSet<Type> enabledSendEventTypes = getEnabledSendEventTypes(); for (Event.Type type : Event.Type.values()) { listener.onSendEventStateChanged(type, enabledSendEventTypes.contains(type)); } } public boolean isEventTypeEnabled(Event.Type type) { String prefName = context.getString(R.string.prefkey_event_type_format, type.name()); return prefs.getBoolean(prefName, true); } public boolean startForeground() { return prefs.getBoolean(context.getString(R.string.prefkey_start_foreground), true); } public int getMaxBatteryLevel() { return prefs.getInt(context.getString(R.string.prefkey_max_battery_level), 100); } public int getMinBatteryLevel() { return prefs.getInt(context.getString(R.string.prefkey_min_battery_level), 0); } public int getMinBatteryLevelChange() { return prefs.getInt(context.getString(R.string.prefkey_min_battery_level_change), 5); } public boolean shouldPruneLog() { return prefs.getBoolean(context.getString(R.string.prefkey_prune_log), false); } public int getPruneLogDays() { String daysStr = prefs.getString(context.getString(R.string.prefkey_prune_log_days), "7"); return Integer.parseInt(daysStr); } public boolean isSystemDisplayEnabled() { return prefs.getBoolean(context.getString(R.string.prefkey_display_system), true); } public boolean isToastDisplayEnabled() { return prefs.getBoolean(context.getString(R.string.prefkey_display_toast), false); } public boolean isPopupDisplayEnabled() { return prefs.getBoolean(context.getString(R.string.prefkey_display_popup), false); } public EnumSet<TransportType> getEnabledTransports() { EnumSet<TransportType> transports = EnumSet.noneOf(TransportType.class); if (prefs.getBoolean(context.getString(R.string.prefkey_comm_method_bluetooth), false)) { transports.add(TransportType.BLUETOOTH); } if (prefs.getBoolean(context.getString(R.string.prefkey_comm_method_ip), false)) { transports.add(TransportType.IP); } if (prefs.getBoolean(context.getString(R.string.prefkey_comm_method_usb), false)) { transports.add(TransportType.USB); } if (prefs.getBoolean(context.getString(R.string.prefkey_comm_method_cloud), false)) { transports.add(TransportType.CLOUD); } return transports; } public EnumSet<Event.Type> getEnabledSendEventTypes() { EnumSet<Event.Type> events = EnumSet.noneOf(Event.Type.class); if (!prefs.getBoolean(context.getString(R.string.prefkey_send_notifications), true)) { // Master switch disabled. return events; } if (prefs.getBoolean(context.getString(R.string.prefkey_send_battery), true)) { events.add(Event.Type.NOTIFICATION_BATTERY); } if (prefs.getBoolean(context.getString(R.string.prefkey_send_missed_call), true)) { events.add(Event.Type.NOTIFICATION_MISSED_CALL); } if (prefs.getBoolean(context.getString(R.string.prefkey_send_mms), true)) { events.add(Event.Type.NOTIFICATION_MMS); } if (prefs.getBoolean(context.getString(R.string.prefkey_send_ring), true)) { events.add(Event.Type.NOTIFICATION_RING); } if (prefs.getBoolean(context.getString(R.string.prefkey_send_sms), true)) { events.add(Event.Type.NOTIFICATION_SMS); } if (prefs.getBoolean(context.getString(R.string.prefkey_send_third_party), true)) { events.add(Event.Type.NOTIFICATION_THIRD_PARTY); } if (prefs.getBoolean(context.getString(R.string.prefkey_send_voicemail), true)) { events.add(Event.Type.NOTIFICATION_VOICEMAIL); } return events; } public boolean isIpOverTcp() { // TODO Auto-generated method stub return false; } public void setC2dmRegistrationId(String registrationId) { // TODO Auto-generated method stub } public void setC2dmServerRegistered(boolean b) { // TODO Auto-generated method stub } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/prefs/Preferences.java
Java
asf20
7,605
/* * Copyright 2011 Rodrigo Damazio * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.prefs; import org.damazio.notifier.R; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.os.Bundle; import android.preference.PreferenceManager; public class PreferenceActivity extends android.preference.PreferenceActivity { private SharedPreferences preferences; private OnSharedPreferenceChangeListener backupListener; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); preferences = PreferenceManager.getDefaultSharedPreferences(this); backupListener = BackupPreferenceListener.create(this); addPreferencesFromResource(R.xml.prefs); } @Override protected void onStart() { super.onStart(); preferences.registerOnSharedPreferenceChangeListener(backupListener); } @Override protected void onStop() { preferences.unregisterOnSharedPreferenceChangeListener(backupListener); super.onStop(); } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/prefs/PreferenceActivity.java
Java
asf20
1,614
/* * Copyright 2011 Rodrigo Damazio * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier.prefs; import android.app.backup.BackupManager; import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.os.Build; public class BackupPreferenceListener { /** * Real implementation of the listener, which calls the {@link BackupManager}. */ private static class BackupPreferencesListenerImpl implements OnSharedPreferenceChangeListener{ private final BackupManager backupManager; public BackupPreferencesListenerImpl(Context context) { this.backupManager = new BackupManager(context); } public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { backupManager.dataChanged(); } } /** * Creates and returns a proper instance of the listener for this device. */ public static OnSharedPreferenceChangeListener create(Context context) { if (Build.VERSION.SDK_INT >= 8) { return new BackupPreferencesListenerImpl(context); } else { return null; } } private BackupPreferenceListener() {} }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/prefs/BackupPreferenceListener.java
Java
asf20
1,736
/* * Copyright 2011 Rodrigo Damazio * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.damazio.notifier; import static org.damazio.notifier.Constants.TAG; import org.damazio.notifier.prefs.Preferences; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; public class BootServiceStarter extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction() != Intent.ACTION_BOOT_COMPLETED) { Log.w(TAG, "Received unexpected intent: " + intent); return; } Preferences preferences = new Preferences(context); // TODO: Check if start at boot requested. context.startService(new Intent(context, NotifierService.class)); } }
1301599827-notifier
AndroidNotifier/src/org/damazio/notifier/BootServiceStarter.java
Java
asf20
1,312