Wednesday, October 31, 2018

remove html tags from string



Normally in the server side you could use a series of PHP functions (such as strip_tags) and to remove HTML and ugly formatting. However, if you're unable to use the server (or you use Node.js) to achieve this task, then you can still use Javascript to do it. In this article, you will find 3 ways to strip the html tags from a string in Javascript.

1. Create a temporary DOM element and retrieve the text

This is the preferred (and recommended) way to strip the HTML from a string with Javascript. The content of a temporary div element, will be the providen HTML string to strip, then from the div element return the innerText property:
/**
 * Returns the text from a HTML string
 * 
 * @param {html} String The html string
 */
function stripHtml(html){
    // Create a new div element
    var temporalDivElement = document.createElement("div");
    // Set the HTML content with the providen
    temporalDivElement.innerHTML = html;
    // Retrieve the text property of the element (cross-browser support)
    return temporalDivElement.textContent || temporalDivElement.innerText || "";
}

var htmlString= "

Hello World

\nIt's me, Mario
"
; //Hello World //It's me, Mario console.log(stripHtml(htmlString));
The only problem of this (and the advantage) is that the browser will handle the providen string as HTML, that means that if the HTML string contains some type of interpretable Javascript for the browser, then it will be executed:
// This won't do anything but retrieve the text
stripHtml("")

// But this ...
stripHtml("")
Therefore, you should use this only if you trust the source of the HTML string.

2. If you are using jQuery

If you use jQuery you can simplificate the code from the first step. The following code will do the same that the code in the first step (the warnings apply too):
var htmlString= "
\n

Hello World

\n This is the text that we should get.
\n Our Code World © 2017
\n
"
; var stripedHtml = $("
"
).html(htmlString).text(); // Hello World // This is the text that we should get. // Our Code World © 2017 console.log(stripedHtml);

3. With a regular expression

If you're working in a Node environment, where there's not either document or createElement method, then you can use a regular expression to replace all the HTML tags from a string:
var htmlString= "

Hello World

\nIt's me, Mario
"
; var stripedHtml = htmlString.replace(/<[^>]+>/g, ''); //Hello World //It's me, Mario console.log(stripedHtml);
This method will work perfectly, but it will only remove the less than and more than symbols (< and >), that means that the html entities aren't removed from the string as shown in the following example:
var htmlString= "
\n

Hello World

\n This is the text that we should get.
\n Our Code World © 2017
\n
"
; var stripedHtml = htmlString.replace(/<[^>]+>/g, ''); // Hello World // This is the text that we should get. // Our Code World © 2017 console.log(stripedHtml);
The © entity should be translated as a copyright symbol, however it still there as an html entity. That's clearly a disadvantage if you compare it with the first method, but don't worry not everything is lost (not yet). You can use Javascript to decode the htmlentities into readable characters (read this article to learn how to achieve it). The following example will strip all the html using the previous mentioned replace instruction and convert the htmlentities to human readable characters using the he library:
var htmlString= "
\n

Hello World

\n This is the text that we should get.
\n Our Code World © 2017
\n
"
; var stripedHtml = htmlString.replace(/<[^>]+>/g, ''); var decodedStripedHtml = he.decode(stripedHtml); // Hello World // This is the text that we should get. // Our Code World © 2017 console.log(stripedHtml); // Hello World // This is the text that we should get. // Our Code World © 2017 console.log(decodedStripedHtml);
As you can see, using the he library we converted the remaining html entities into its readable value. Note that you don't need to use necessarily the he library because you can create your own decode htmlentities function if you read this article.
Happy coding !

opera developer tools zoom reset

opera ---- setting ------ advanced ---------- browser

at bottom ----- reset to factory default

Tuesday, October 30, 2018

pin post on top

q2a

By add plugin, go to

https://github.com/NoahY/q2a-featured

download plugin,  unzip, copy whole folder to under qa-plugin/qa-featured

Then, navigate to your site, go to Admin -> Plugins, find the Featured Questions list, enter featured question ids seperated by commas, then click 'Save'.




carbon forum


I know when edit post, you can click 'Rise' button to pin it on top for 7 days.
If you click again, add 7 more days, and so on.
But I want to permanent pin post on top, no need to click click again again for 7 days.

Solution is make 7 days to 7000 days, by modify code

C:\Apache24\htdocs\carbon\controller\manage.php

// edit post, click sink, sink 7 days = 604800 second, 
                // I want 7000 days = 604800000
$this->db->query("UPDATE " . PREFIX . "topics SET LastTime = LastTime-604800000 WHERE ID=:ID", array(
"ID" => $this->id


// edit post, click rise, will pin top for 7 days = 604800 second, 
                // I want 7000 days = 604800000
$this->db->query("UPDATE " . PREFIX . "topics SET LastTime = LastTime+604800000 WHERE ID=:ID", array(
"ID" => $this->id
));





Friday, October 26, 2018

embed iframe ckeditor

C:\Apache24\htdocs\cleargov1\qa-plugin\wysiwyg-editor\CUSTOMIZE.md


Customizing your editor
=============================

This Q2A plugin uses a custom build of CKEditor to keep it simple. However, if you would like to add new features it is straightforward to do so. All languages supported by Q2A are included, but if you are using a different language you can add add it using the tool, or remove all the languages you don't need to create an even smaller plugin.

1. Go to the CKEditor Builder: http://ckeditor.com/builder
2. Click the "Upload build-config.js" button in the top right, and select the `build-config.js` file from the `ckeditor` directory to start with the current config.
3. Use the various controls to modify your build. You can add plugins, choose a different skin and choose the language(s) you require.
4. Make sure "Optimized" is selected and download the custom package.
5. Delete the `ckeditor` folder inside `wysiwyg-editor`, then extract the downloaded package here, replacing the `ckeditor` folder.

=============================


1) go to
https://ckeditor.com/cke4/builder


2) upload current build-config.js (C:\Apache24\htdocs\cleargov1\qa-plugin\wysiwyg-editor\ckeditor\build-config.js)


3)now in available section select source area, iframe ,


4) click left arrow in middle to add selected to list.


5) download zip

6) replace unzipped ckeditor folder.


7) Now you see source button, iframe button at ckeditor, but iframe would not save.
you must filter out iframe.


8)C:\Apache24\htdocs\cleargov1\qa-plugin\wysiwyg-editor\qa-wysiwyg-editor.php
here is where to clean filter html:
'content' => qa_sanitize_html($html, false, true),




9)C:\Apache24\htdocs\cleargov1\qa-include\qa-base.php

 comment out 'safe' => 1,

htmLawed  library use to filter html.

http://www.bioinformatics.org/phplabware/internal_utilities/htmLawed/htmLawed_README.htm#s3.3


$safe = htmLawed($html, array(
// 'safe' => 1,     // exclude applet, audio, canvas, embed, iframe, object, script and video  http://www.bioinformatics.org/phplabware/internal_utilities/htmLawed/htmLawed_README.htm#s3.3
'elements' => '*+embed+object-form',
'schemes' => 'href: aim, feed, file, ftp, gopher, http, https, irc, mailto, news, nntp, sftp, ssh, telnet; *:file, http, https; style: !; classid:clsid',
'keep_bad' => 0,
'anti_link_spam' => array('/.*/', ''),
'hook_tag' => 'qa_sanitize_html_hook_tag',
));



10) done



Tuesday, October 23, 2018

embed iframe ueditor ckeditor


for carbon forum

  1. 添加你的iframe src 域名到白名单过滤器
    C:\Apache24\htdocs\glassgov1\common.php
open common.php, search "iframe", add your iframe src domain to white filter.
I add **'j2t.transparentgov.net', 'transparentgov.net', 'www.transparentgov.net',
            'ms1.transparentgov.net',**   

 to  **$hostWhiteList**
//跨站脚本白名单过滤 function XssEscape($html) { $filter = new WhiteHTMLFilter(); $urlFilter = function($url) { $token = parse_url($url); if (empty($token['scheme']) || in_array($token['scheme'], array('http', 'https')) === false) { return ''; } $hostWhiteList = array( 'j2t.transparentgov.net', 'transparentgov.net', 'www.transparentgov.net', 'ms1.transparentgov.net', 'www.youtube.com', 'youtube.com', 'www.youtu.be', 'youtu.be', 'player.youku.com', 'v.youku.com',
2)ueditor config 添加 iframe 元素,object 元素。
C:\Apache24\htdocs\glassgov1\static\editor\ueditor.config.js
Open ueditor.config.js, add below 3 line code at : window.UEDITOR_CONFIG = { )
            // allow embed iframe tag
            ,iframe: ['frameborder','src','width','height']
            ,object: ['type','data','width','height']
// allow embed iframe tag ,iframe: ['frameborder','src','width','height'] ,object: ['type','data','width','height']
Success embed iframe, object html tag




==============================================

Ueditor:

打开下载的ueditor目录中ueditor.config.js文件,找到如下标签白名单代码
在任意处加上如下代码,如果你所添加的iframe中还包含其它标签,只需要在数组中继续添加元素即可。
iframe: ['frameborder','src','width','height'],

=========================================================




for q2a  ckeditor











centos backup

cpanel, ----- backup ------ download full directory, download mysql db






whm   ---------- backup --------- 

Backup Restoration

Wednesday, October 17, 2018

domain with www not working




Domain does not work with "www"

If you can access your website using your Domain without "www." (example.com) but with "www." it won't load, most likely you need to check your DNS zone settings to see if you have an "A" record for "www" entry of your domain. The "A" record should point to the same IP as your default main Domain. The IP is also shown in your account's Details section. You can also setup CNAME record: "wwwIN CNAMEyourdomain.com".