<?php

# PLUGIN PREVIEW BY TEXTPATTERN.INFO

if (@txpinterface == 'admin') {

    
// privs
    
add_privs('abl_droploader''1,2,3,4,6');
    
add_privs('plugin_lifecycle.abl_droploader''1,2');
    
add_privs('plugin_prefs.abl_droploader''1,2');

    
// inject js & css in html-header
    
register_callback('abl_droploader_head_end''admin_side''head_end');
    
// trigger (button/link) elements
    
register_callback('abl_droploader_article_ui''article_ui''extend_col_1');
    
// following callback has been replaced by javascript!
    //register_callback('abl_droploader_image_ui', 'image_ui', 'extend_controls');
    // ajax interface
    
register_callback('abl_droploader_ajax''abl_droploader');
    
// intercept image_uploaded-event from txp_image
    
register_callback('abl_droploader_image_uploaded''image_uploaded''image');
    
// lifecycle
    
register_callback('abl_droploader_lifecycle''plugin_lifecycle.abl_droploader');
    
// prefs
    
$abl_droploader_prefs abl_droploader_load_prefs(); // load hard-coded defaults
    
@require_plugin('soo_plugin_pref');
    
register_callback('abl_droploader_prefs''plugin_prefs.abl_droploader');

}


    
/**
     * handle plugin lifecycle events
     *
     * @param string $event (plugin_lifecycle.abl_droploader)
     * @param string $step (enabled, disabled, installed, deleted)
     */
    
function abl_droploader_lifecycle($event$step) {
        global 
$prefs;

        
$msg '';
        
$msg1 '';
        switch (
$step) {
            case 
'installed':
                if (
function_exists('soo_plugin_pref')) {
                    
abl_droploader_prefs($event$step);
                } else {
                    
$msg1 'Please install <em>soo_plugin_pref</em> to edit preferences (Default preferences apply).';
                }
                
$rc abl_droploader_install();
                if (
$rc == E_ERROR) {
                    
$msg '<strong>An error occurred. Please check the servers error-log.</strong>' . (($msg1 != '') ? ' ' $msg1 '');
                } elseif (
$rc == E_WARNING || $rc == E_NOTICE) {
                    
$msg '<em>abl_droploader</em> successfully installed. Please check the servers error-log.' . (($msg1 != '') ? ' ' $msg1 '');
                } else {
                    
$msg '<em>abl_droploader</em> successfully installed.' . (($msg1 != '') ? ' ' $msg1 '');
                }

                
// set txp's thumb prefs if they are not set (fresh install)
                
if (!isset($prefs['thumb_w'])) set_pref('thumb_w''100''image'PREF_HIDDEN);
                if (!isset(
$prefs['thumb_h'])) set_pref('thumb_h''100''image'PREF_HIDDEN);
                if (!isset(
$prefs['thumb_crop'])) set_pref('thumb_crop''1''image'PREF_HIDDEN);
                break;
            
//case 'deleted':
            //    break;
        
}
        return 
$msg;

    }

    
/**
     * add plugin prefs to database
     *
     * @param string $event (plugin_prefs.abl_droploader)
     * @param string $step (-)
     */
    
function abl_droploader_prefs($event$step) {
        if (
function_exists('soo_plugin_pref')) {
            
soo_plugin_pref($event$stepabl_droploader_defaults());
            return 
true;
        } else {
            
$msg 'Please install <em>soo_plugin_pref</em> to edit preferences (Default preferences apply).';
            
pagetop(gTxt('edit_preferences') . " &#8250; abl_droploader"$msg);
            
$default_prefs abl_droploader_defaults();
            
$html '<table id="list" align="center" border="0" cellpadding="3" cellspacing="0">
<thead>
<tr>
<th colspan="2"><h1>DropLoader default preferences</h1></th>
</tr>
<tr>
<th>Option</th>
<th>Value</th>
</tr>
</thead>
<tbody>
'
;
            foreach (
$default_prefs as $key => $pref) {
                
$html .= '<tr>
<td>' 
htmlspecialchars($pref['text']) . '</td>
<td>' 
htmlspecialchars($pref['val']) . '</td>
</tr>
'
;
            }
            
$html .= '</tbody>
</table>
'
;
            echo 
$html;
            return 
false;
        }
    }

    
/**
     * get plugin prefs default values
     *
     * @param string $values_only
     */
    
function abl_droploader_defaults($values_only false) {

        
$defaults = array(
            
'imageMaxUploadCount' => array(
                
'val'    => '10',
                
'html'    => 'text_input',
                
'text'    => gTxt('abl_droploader_prefs_image_max_upload_count'),
            ),
            
'reloadImagesTab' => array(
                
'val'    => '0',
                
'html'    => 'yesnoradio',
                
'text'    => gTxt('abl_droploader_prefs_reload_image_tab'),
            ),
            
'useDefaultStylesheet' => array(
                
'val'    => '1',
                
'html'    => 'yesnoradio',
                
'text'    => gTxt('abl_droploader_prefs_use_default_stylesheet'),
            ),
            
'customStylesheet' => array(
                
'val'    => '',
                
'html'    => 'text_input',
                
'text'    => gTxt('abl_droploader_prefs_custom_stylesheet'),
            ),
            
'articleImageFields' => array(
                
'val'    => '#article-image',
                
'html'    => 'text_input',
                
'text'    => gTxt('abl_droploader_prefs_article_image_fields'),
            ),
            
//'fileMaxUploadCount' => array(
            //    'val'    => '10',
            //    'html'    => 'text_input',
            //    'text'    => gTxt('abl_droploader_prefs_file_max_upload_count'),
            //),
        
);
        if (
$values_only)
            foreach (
$defaults as $name => $arr)
                
$defaults[$name] = $arr['val'];
        return 
$defaults;
    }


    
/**
     * Load plugin prefs
     *
     * @param string $values_only
     */
    
function abl_droploader_load_prefs() {
        return 
function_exists('soo_plugin_pref_vals')
            ? 
array_merge(abl_droploader_defaults(true), soo_plugin_pref_vals('abl_droploader'))
            : 
abl_droploader_defaults(true);
    }

    
/**
     * install plugin resources (css, js)
     *
     * @param mixed $resources
     * @param string $path
     */
    
function abl_droploader_install($resources=null$path='') {
        global 
$prefs;

        
$state 0;
        if (
$resources === null) {
            
$path $prefs['path_to_site'];
            
$resources = array();
            
$resources['/res/css/abl.droploader-app.css'] =  'H4sIAAAAAAAAA71X207jMBB9pl9hqVppF+EQUtKtwtP+xL6unNhJLRw7st0LIP59x3aSpm3a
wAotoCq+zZw5Z3occkVf0NvsRm2ZLoXa4X2G1pxSJp8Gky8ZMoVWQjzN3mf3t4jXpGJIcGPR
7f1s7od/CiUt7EERyQWmWjVCEco0Vg2TLgVEIjZDmldrC8FroisusR9m6IHVMFdCCP+MfjNN
iSR36JfmRNwhQ6TBhmlettvwjoWTuRLUwZrNT/IWQhnmElNuGkGghlyo4hnON8pwy5XMEMmN
EhvLYNKqJkOJh9FiilI/agilXFYZWjR79BDDx7J9gMVcacgFmGEKQnGK5kVRuHBsbzFlhdIk
pJJKujRAqeUFEZgIXkkH31pVdwfayYJJy3RPSPIPhNwUSigANk+SxOEkxXOl1UZSmCpLd+gV
c0kZ6L2AH3dgo4070Sgesr+PU5qtXV84YrsUpUtxroDbcpnqGB4EK2142nFq10BjHH+D0bot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sqYaiRkRqUKZ32nlXqC580K
zYlRLRRsGpGh1sSwq27oxOjovjdOLQStTWcySZ0LzY6n4cZ6nF9n7jHO9My1Nhuga93jx6G8
ocCkse83qc0dFuvHk6OklDxDYfTt4KA/csOQkalHjPLJkuk3EEH/9Q8np33TZlUiHam0ZoRE
UFj4Gn94qeuPQWTGSaT+wQgGzhTH3szLintKNunJ3sYBqsrMe65aMiNZRYZZ9wazlyO4cibV
SZWCqGd9HvmZS7WBMR27r3n231QDMy/QowK/QPPllplw0J4bk1cQiDAP2af8RjZnIVl+/XFX
xzoTv+4nM5qFE/SWZzEORtu2LStcEmNRxAuJx7Itek8HS4eXvOt+eu3R3SuivErX3QWm8m++
NTcFZn7RgbZQckLdloVumog7r+JyZcvwi279MEAByaoc7MD6fbed99marVlZ/dl83jaV5ddz
VCJQLecgGiVbd+fyhfXx7yyPnW/5rRUNCXzK3NCg3U6ttxmfVRy1qyMnVEJo9Td1vZc/VPOq
dVMta2pcr36YJTJBn1SljCdzOr/RaxSOGx3vYH6p4TVInzMGqZuvxDRdyEqj2TKlcWJzmP2f
e8EzRVH7pc7kd/124L/6mbFtvds+u9bpdpxfh2jj8Arq1ummWtffgc3rvYsOUcqZsLOYtV+U
fPTN1DwR1/i6b6NX9T/qMv1Gb5+kHQHeYvt+9Vj/GQQ4rPagIYuMH6uJgs2ZTlId1+lfJbjL
PsFL44KPPzTbnzH8cYL0lfbpy/88JX7y6qb+1q5T8wA3SWwVEJ2SxiT2aDIx6tNhq37Qpx9u
0XEiw6ZtiiPNVoaekrD7oV/l+QWRP3a61wG/6KE6r/4NQR0sVpL/RAkmuLFcGZHdhNGCied5
zPdkgA35Q5jczGbuoUL/KkvEVPqqFwGPhiUrwgiLFnvpqL5m6GbVVfKEmdrqbZLJJ/pZgTBq
GP3WQ7/1IsjwoprNjP5JrH4RgsK8HQY6yyPA/wBgnJmDIy0AAA=='
;
        }

        foreach(
$resources as $file => $resource) {
            
$newfile $path $file;
            if (
is_array($resource)) {
                
abl_droploader_install($resource$newfile '/');
            } else {
                
$ok is_dir(dirname($newfile));
                if (!
$ok) {
                    
$ok mkdir(dirname($newfile), 0755true);
                }
                if (
$ok) {
                    
$temp base64_decode($resource);
                    if (
strncmp($temp"\x1F\x8B"2) === 0) {
                        
$temp gzinflate(substr($temp10));
                    }
                    if (
file_exists($newfile)) unlink($newfile);
                    
$handle fopen($newfile'w');
                    if (
$handle !== false) {
                        
fwrite($handle$temp);
                        
chmod($newfile0644);
                        
fclose($handle);
                    } else {
                        
$state E_ERROR;
                        
error_log('abl_droploader: ERROR: Creating file \'' $newfile '\' failed.');
                    }
                } else {
                    
$state E_ERROR;
                    
error_log('abl_droploader: ERROR: Creating directory \'' dirname($newfile) . '\' failed.');
                }
            }
        }

        
// install new prefs (not present in previous plugin versions)
        
$pref_prefix 'abl_droploader.';
        
$pi_pref_defaults abl_droploader_defaults();
        
$max_pos safe_field('position''txp_prefs'"name like '" $pref_prefix "%' ORDER BY position DESC");
        if (
$max_pos === false) {
            
$max_pos 0;
        } else {
            
$max_pos++;
        }
        foreach (
$pi_pref_defaults as $name => $pref) {
            if (
get_pref($pref_prefix $name'nope'1) == 'nope') {
                
$rc set_pref(
                    
$pref_prefix $name,
                    
$pref['val'],
                    
'plugin_prefs',
                    
2,
                    
$pref['html'],
                    
$max_pos
                
);
                if (
$rc === false) {
                    
$state E_ERROR;
                    
error_log('abl_droploader: WARNING: Preference \'' $pref_prefix $name '\' not created.');
                }
                
$max_pos++;
            }
        }
        
// delete obsolete prefs (if any)
        
$current_prefs safe_column('name''txp_prefs'"name like '" $pref_prefix "%'");
        foreach (
$current_prefs as $current_pref) {
            
$p substr($current_prefstrlen($pref_prefix));
            if (!
array_key_exists($p$pi_pref_defaults)) {
                if (!
safe_delete('txp_prefs'"name = '" $pref_prefix $p ."'")) {
                    if (
$state == 0$state E_NOTICE;
                    
error_log('abl_droploader: Notice: Removal of obsolete preference \'' $pref_prefix $name '\' failed.');
                }
            }
        }
        
// order prefs
        
$pos 0;
        foreach (
$pi_pref_defaults as $name => $pref) {
            
safe_update('txp_prefs'"position = '" $pos "'""name = '" $pref_prefix $name "'");
            
$pos++;
        }

        
// set load order to 9 (important!)
        
if (!safe_update('txp_plugin''load_order = 9'"name='abl_droploader'")) {
            if (
$state == or $state == E_NOTICE$state E_WARNING;
            
error_log('abl_droploader: WARNING: Setting the plugin load order to 9 failed.');
        }
        return 
$state;

    }

    
/**
     * inject css & js in html-header
     *
     * @param string $evt (admin_side)
     * @param string $stp (head_end)
     */
    
function abl_droploader_head_end($evt$stp) {
        global 
$event$step$prefs$abl_droploader_prefs;

        if ((
$event == 'image'
            
&& (in_array($step, array('list''image_list''image_multi_edit''image_change_pageby''image_save'''))))
        || (
$event == 'article'
            
&& (in_array($step, array('create''edit'))))) {
            
$abl_droploader_prefs abl_droploader_load_prefs();
            
$css '';
            if (
intval($abl_droploader_prefs['useDefaultStylesheet']) != 0) {
                
$css .= '<link rel="stylesheet" href="../res/css/abl.droploader-app.css" type="text/css" media="screen,projection" />' n;
            }
            if (
$abl_droploader_prefs['customStylesheet'] != '') {
                
$css .= '<link rel="stylesheet" href="' $abl_droploader_prefs['customStylesheet'] . '" type="text/css" media="screen,projection" />' n;
            }
            if (
$css == '') {
                
$css '<link rel="stylesheet" href="../res/css/abl.droploader-app.css" type="text/css" media="screen,projection" />' n;
            }
            
$article_image_field_ids '"' implode('", "'explode(','$abl_droploader_prefs['articleImageFields'])) . '"';
            
$script '<script type="text/javascript">
    var file_max_upload_size = ' 
sprintf('%F', (intval($prefs['file_max_upload_size']) / 1048576)) . ';
    var file_max_files = 5;
    var image_max_upload_size = 1;
    var image_max_files = ' 
intval($abl_droploader_prefs['imageMaxUploadCount']) . ';
    var reload_image_tab = ' 
intval($abl_droploader_prefs['reloadImagesTab']) . ';
    var article_image_field_ids = new Array(' 
$article_image_field_ids ');
    var article_image_field = null;
</script>
<script src="../res/js/jquery.filedrop.js" type="text/javascript"></script>
<script src="../res/js/jquery.droploader.js" type="text/javascript"></script>
<script src="../res/js/abl.droploader-app.js" type="text/javascript"></script>' 
n;
            echo 
$css $script;
        }

    }


    
/**
     * Insert DropLoader link in column 1 on the write-tab
     *
     * @param string $event (article_ui)
     * @param string $step (extend_col_1)
     */
    
function abl_droploader_article_ui($event$step) {
        
$content '
<ul class="abl_droploader plain-list">
<li><a id="abl-droploader-open" class="abl-droploader-open" href="#" title="' 
gTxt('abl_droploader_open_title') . '">' gTxt('abl_droploader_open') . '</a></li>
</ul>'
;
        if (
is_callable('wrapRegion')) { // new in txp 4.6
            
return wrapRegion('abl_droploader_group'$content'abl_droploader_link''upload''article_abl_droploader');
        } else {
            return 
'
<div id="abl_droploader_group"><h3 class="plain lever"><a href="#abl_droploader-link">' 
gTxt('upload') . '</a></h3>
<div id="abl_droploader-link" class="toggle" style="display:none">' 
.
$content '
</div>
</div>
'
;
        }
    }

    
/**
     * Insert DropLoader link above the image-list on the image-tab
     *
     * @param string $event (image_ui)
     * @param string $step (extend_controls)
     */
    
function abl_droploader_image_ui($event$step) {
        return 
'<p class="plain"><a id="abl-droploader-open" class="abl-droploader-open" href="#" title="' gTxt('abl_droploader_open_title') . '">' gTxt('abl_droploader_open') . '</a></p>' n;
    }

    
/**
     * handle AJAX requests
     * return JSON and exit
     *
     * @param string $event (abl_droploader)
     * @param string $step (get_form_data, get_image_data)
     */
    
function abl_droploader_ajax($event$step) {

        if (
$event == 'abl_droploader') {
            switch (
$step) {
                case 
'get_form_data':
                    
$response = array(
                        
'status' => 0,
                        
'image_upload_link' => '',
                        
'image_upload_form' => '',
                        
'image_cat_select' => '',
                        
'l10n' => ''
                    
);
                    
$items explode(','gps('items'));
                    foreach (
$items as $item) {
                        switch (
$item) {
                            case 
'image_upload_link':
                                
$response['image_upload_link'] = abl_droploader_image_ui('''');
                                break;
                            case 
'image_upload_form':
                                
$response['image_upload_form'] = abl_droploader_get_image_upload_form();
                                break;
                            case 
'image_cat_select':
                                
$response['image_cat_select'] = abl_droploader_get_image_cat_select();
                                break;
                            case 
'l10n':
                                
$response['l10n'] = abl_droploader_get_localisation();
                                break;
                            case 
'all':
                                
$response['image_upload_link'] = abl_droploader_image_ui('''');
                                
$response['image_upload_form'] = abl_droploader_get_image_upload_form();
                                
$response['image_cat_select'] = abl_droploader_get_image_cat_select();
                                
$response['l10n'] = abl_droploader_get_localisation();
                                break;
                        }
                    }
                    
$response['status'] = 1;
                    break;
            }
            echo 
json_encode($response);
            exit;
        }

    }

    
/**
     * get image category-selector form element
     */
    
function abl_droploader_get_image_cat_select() {
        
$image_categories getTree('root''image');
        
//$image_categories_select = str_ireplace("\n", '', tag('<label for="image-category">' . gTxt('image_category') . '</label>' . br .
        //    treeSelectInput('category', $image_categories, '', 'image-category'), 'div', ' id="abl-droploader-image-cat-sel" class="category"'));
        //$alt_caption =    tag('<label for="alt-text">'.gTxt('alt_text').'</label>'.br.
        //        fInput('text', 'alt', '', 'edit', '', '', 50, '', 'alt-text'), 'div', ' class="alt text"').
        //    tag('<label for="caption">'.gTxt('caption').'</label>'.br.
        //        '<textarea id="caption" name="caption"></textarea>'
        //        , 'div', ' class="caption description text"');
        
$image_categories_select str_ireplace("\n"''tag(tag('<label for="image-category">'.gTxt('image_category').'</label>'.br.
                
treeSelectInput('category'$image_categories'''image-category'), 'div'' class="category"'), 'div'' id="abl-droploader-image-cat-sel"'));
        return 
$image_categories_select;
    }

    
/**
     * get image upload-form
     */
    
function abl_droploader_get_image_upload_form() {
        
$upload_form upload_form(gTxt('upload_image'), 'upload_image''image_insert''image''');
        
//return '<div id="droploader">' . n . $upload_form . n . '</div>' . n;
        
return $upload_form;
    }

    
/**
     * get localised items from textpack
     */
    
function abl_droploader_get_localisation() {
        
$l10n = array(
            
'open' => '',
            
'open_title' => '',
            
'close' => '',
            
'close_title' => '',
            
'error_method' => '',
            
'info_text' => '',
            
'err_invalid_filetype' => '',
            
'err_browser_not_supported' => '',
            
'err_too_many_files' => '',
            
'err_file_too_large' => '',
            
'all_files_uploaded' => '',
            
'no_files_uploaded' => '',
            
'some_files_uploaded' => '',
        );
        foreach (
$l10n as $k => $v) {
            
$l10n[$k] = gTxt('abl_droploader_' $k);
        }
        return 
$l10n;
    }

    
/**
     * image_uploaded callback (txp_image.php)
     * return JSON (image-id) and exit
     *
     * @param string $event (image_uploaded)
     * @param string $step (image)
     * @param string $id (image_id)
     */
    
function abl_droploader_image_uploaded($event$step$id) {
        if (
ps('abl_droploader') == '') return;
        
$response = array(
            
'status' => 1,
            
'image_id' => $id,
        );
        echo 
json_encode($response);
        exit;
    }