2018년 12월 19일 수요일

preg_replace /e to preg_replace_callback

$onAttributes = array('onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate', 'onbeforecopy', 'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint', 'onbeforeunload', 'onbeforeupdate', 'onblur', 'onbounce', 'oncellchange', 'onchange', 'onclick', 'oncontextmenu', 'oncontrolselect', 'oncopy', 'oncut', 'ondataavaible', 'ondatasetchanged', 'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag', 'ondragdrop', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'onerror', 'onerrorupdate', 'onfilterupdate', 'onfinish', 'onfocus', 'onfocusin', 'onfocusout', 'onhelp', 'onkeydown', 'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload', 'onlosecapture', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmoveout', 'onmouseover', 'onmouseup', 'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onpaste', 'onpropertychange', 'onreadystatechange', 'onreset', 'onresize', 'onresizeend', 'onresizestart', 'onrowexit', 'onrowsdelete', 'onrowsinserted', 'onscroll', 'onselect', 'onselectionchange', 'onselectstart', 'onstart', 'onstop', 'onsubmit', 'onunload');
/*
 * Bridge Light code 2018-12-19
 * PHP7에서는 preg_replace() 첫번째 인수에서 /e가 폐기 되었으므로 대체 코드 투입: line 45~47 대신 line 48~56
 */
// $str = preg_replace('/<(.*?)>/ie',
// "'<' . preg_replace(array('/javascript:[^\"\']*/i', '/(" . implode('|', $onAttributes) . ")[ \\t\\n]*=/i', '/\s+/'), array('', '', ' '), stripslashes('\\1')) . '>'",
// $str);
$str = preg_replace_callback(
'/<(.*?)>/i',
function($matches) use ($onAttributes) {
return preg_replace(
array('/javascript:[^"\']*/i', '/('.implode('|', $onAttributes) . ')[ \\t\\n]*=/i', '/\s+/'),
array('', '', ' '),
stripslashes($matches[0]));
},
$str);


kimsq ver.1.2.2 (update 20140407)
file: _core/function/lib/getContent.lib.php

LIB_getContents() 함수에서 preg_replace()를 /e 지시자 때문에 preg_replace_callback으로 대체함.

preg_replace & preg_replace_callback, understood!


2018년 7월 23일 월요일

Wordpress tips

Child theme's Javascript file is loaded earlier than parent theme's.

For example, global-child.js is loaded right after jquery-min.js loaded and global.js of the parent theme is located at the bottom of <body> tag in the code.


In child theme, JQuery variables without $ should be declared and defined in the $(document).ready().

Weirdly some variables were found 'undefined' in the debugger, if they are defined before/out of $(document).ready()  just like twenty seventeen theme's global.js.


Firing a code after a jquery animation:

    code it in the callback function of animation().

Firing a code after a CSS transition, for instance, 'transition: 0.6s ease' which is triggered by something like addClass( 'fade-in' ) call:

    $("#selector").one("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd", function(){ ... });

.one() means running the callback only once.

Source: https://stackoverflow.com/questions/9255279/callback-when-css3-transition-finishes


Loading a page/post-specific Javascript:
    function load_scripts() {
    global $post;
    if ( is_page() || is_single() ) {
        switch( $post->post_name ) {
            case 'home':
                wp_enqueue_script( 'home', get_template_directory_uri().'/js/home.js', array( 'jquery' ), '', false);
            case 'about-page':
                wp_enqueue_script( 'about', get_template_directory_uri().'/js/about-page.js', array( 'jquery' ), '', false);
        }
    }
    add_action( 'wp_enqueue_scripts', 'load_scripts' );

Source: https://wordpress.stackexchange.com/questions/67802/most-efficient-way-to-add-javascript-file-to-specific-post-and-or-pages



2018년 7월 8일 일요일

When Excel Prints Gray or Light-gray Colored Text in Black

(ver. MS-Office 2013)

File
Print
Page Setup (<- under the printing options)
Sheet tab
Option button (<- will lead you to Printing Preferences, but don't go there via Control Panel)
Print Quality tab
Advanced button
Print colored texts and borders in black to Disabled (<- this text is not exactly same to this, anyway disable it)

Ok, Ok, Apply, Ok, ... boom!

2018년 2월 20일 화요일

[Google Drive File Stream] I can't connect to other computers? (windows network drive to a shared folder)

Updated Help and Support answer list to a question 'Why I can't connect to other computers?'


    I found out today that MS recently updated one of the Help and Support answers about a local network connection in my Windows 7 and it was like the above. Haha...

    I was using Google Drive for PC by sharing the 'Google Drive' folder within a local network and connecting the folder from other computers via Network Drive feature of Windows. It was working well as a one-more-depth of security for shared files.
    After I installed Google's new 'Drive File Stream' which replaces Google Drive by making another 'My Drive' folder, so I tried to share the folder and it was visible in another computer, but it keeps alerting me the 'permission denied' dialogue. Actually monologue, because there is only one button 'OK' which does nothing for me.
    Probably I should go for Backup & Sync for now instead of migrating straightforwardly to Drive File Stream.


    P.S. I really like Google and their innovative moves in many different fields and I love their free-to-use software package including Gmail, Google Drive, Google Calendar, etc. Sometimes, however, they give an ordinary user like me a hassle despite following what they recommend; but it's usually untold what really will happen next.

Xubuntu: Installing a Printer (Canon G3060 PIXMA)

$ sudo apt install system-config-printer Download the proper driver for linux from Canon website. Turn on the printer and set up its WiFi. C...