Esempio n. 1
0
function pagelinkurl($parts, $inherit = array())
{
    global $permlink_mode, $prefs;
    // $inherit can be used to add parameters to an existing url, e.g:
    // $url = pagelinkurl(array('pg'=>2), $pretext);
    $keys = array_merge($inherit, $parts);
    if (isset($prefs['custom_url_func']) and is_callable($prefs['custom_url_func']) and ($url = call_user_func($prefs['custom_url_func'], $keys, PAGELINKURL)) !== FALSE) {
        return $url;
    }
    // can't use this to link to an article
    if (isset($keys['id'])) {
        unset($keys['id']);
    }
    if (isset($keys['s']) && $keys['s'] == 'default') {
        unset($keys['s']);
    }
    // 'article' context is implicit, no need to add it to the page URL
    if (isset($keys['context']) && $keys['context'] == 'article') {
        unset($keys['context']);
    }
    if ($permlink_mode == 'messy') {
        return hu . 'index.php' . join_qs($keys);
    } else {
        // all clean URL modes use the same schemes for list pages
        $url = '';
        if (!empty($keys['rss'])) {
            $url = hu . 'rss/';
            unset($keys['rss']);
            return $url . join_qs($keys);
        } elseif (!empty($keys['atom'])) {
            $url = hu . 'atom/';
            unset($keys['atom']);
            return $url . join_qs($keys);
        } elseif (!empty($keys['s'])) {
            $url = hu . urlencode($keys['s']) . '/';
            unset($keys['s']);
            return $url . join_qs($keys);
        } elseif (!empty($keys['author'])) {
            $ct = empty($keys['context']) ? '' : strtolower(urlencode(gTxt($keys['context'] . '_context'))) . '/';
            $url = hu . strtolower(urlencode(gTxt('author'))) . '/' . $ct . urlencode($keys['author']) . '/';
            unset($keys['author'], $keys['context']);
            return $url . join_qs($keys);
        } elseif (!empty($keys['c'])) {
            $ct = empty($keys['context']) ? '' : strtolower(urlencode(gTxt($keys['context'] . '_context'))) . '/';
            $url = hu . strtolower(urlencode(gTxt('category'))) . '/' . $ct . urlencode($keys['c']) . '/';
            unset($keys['c'], $keys['context']);
            return $url . join_qs($keys);
        }
        return hu . join_qs($keys);
    }
}
Esempio n. 2
0
function pagelinkurl($parts, $inherit = array())
{
    global $permlink_mode;
    # $inherit can be used to add parameters to an existing url, e.g:
    # $url = pagelinkurl(array('pg'=>2), $pretext);
    $keys = array_merge($inherit, $parts);
    # can't use this to link to an article
    if (isset($keys['id'])) {
        unset($keys['id']);
    }
    if (@$keys['s'] == 'default') {
        unset($keys['s']);
    }
    if ($permlink_mode == 'messy') {
        return hu . 'index.php' . join_qs($keys);
    } else {
        # all clean URL modes use the same schemes for list pages
        $url = '';
        foreach ($keys as $k => $v) {
            $keys[$k] = urlencode($v);
        }
        if (!empty($keys['rss'])) {
            $url = hu . 'rss' . '/';
            unset($keys['rss']);
            return $url . join_qs($keys);
        } elseif (!empty($keys['atom'])) {
            $url = hu . 'atom' . '/';
            unset($keys['atom']);
            return $url . join_qs($keys);
        } elseif (!empty($keys['s'])) {
            $url = hu . $keys['s'] . '/';
            unset($keys['s']);
            return $url . join_qs($keys);
        } elseif (!empty($keys['author'])) {
            $url = hu . strtolower(urlencode(gTxt('author'))) . '/' . $keys['author'] . '/';
            unset($keys['author']);
            return $url . join_qs($keys);
        } elseif (!empty($keys['c'])) {
            $url = hu . strtolower(urlencode(gTxt('category'))) . '/' . $keys['c'] . '/';
            unset($keys['c']);
            return $url . join_qs($keys);
        }
        return hu . join_qs($keys);
    }
}
Esempio n. 3
0
/**
 * Gets a file download URL.
 *
 * @param   int    $id       The ID
 * @param   string $filename The filename
 * @return  string
 * @package File
 */
function filedownloadurl($id, $filename = '')
{
    global $permlink_mode;
    if ($permlink_mode == 'messy') {
        return hu . 'index.php' . join_qs(array('s' => 'file_download', 'id' => (int) $id));
    }
    if ($filename) {
        $filename = '/' . urlencode($filename);
        // FIXME: work around yet another mod_deflate problem (double compression)
        // http://blogs.msdn.com/wndp/archive/2006/08/21/Content-Encoding-not-equal-Content-Type.aspx
        if (preg_match('/gz$/i', $filename)) {
            $filename .= a;
        }
    }
    return hu . urlencode(gTxt('file_download')) . '/' . intval($id) . $filename;
}
Esempio n. 4
0
/**
 * Renders a link element to hook up txpAsyncHref() with request parameters.
 *
 * See this function's JavaScript companion, txpAsyncHref(), in textpattern.js.
 *
 * @param  string       $item  Link text
 * @param  array        $parms Request parameters; array keys are 'event', 'step', 'thing', 'property'
 * @param  string|array $atts  HTML attributes
 * @return string HTML
 * @since  4.5.0
 * @example
 * echo asyncHref('Disable', array(
 *     'event'    => 'myEvent',
 *     'step'     => 'myStep',
 *     'thing'    => 'status',
 *     'property' => 'disable',
 * ));
 */
function asyncHref($item, $parms, $atts = '')
{
    global $event, $step;
    $parms = lAtts(array('event' => $event, 'step' => $step, 'thing' => '', 'property' => ''), $parms);
    $class = $parms['step'] . ' async';
    if (is_array($atts)) {
        $atts['class'] = $class;
    } else {
        $atts .= ' class="' . txpspecialchars($class) . '"';
    }
    return href($item, join_qs($parms), $atts);
}
Esempio n. 5
0
function smd_ebook_ui($msg = '', $listfile = '', $report = '', $retval = '', $ebook_folder = '')
{
    global $smd_ebook_event, $smd_ebook_prefs;
    pagetop(gTxt('smd_ebook_tab_name'), $msg);
    extract(smd_ebook_buttons('mgr'));
    $btnbar = has_privs('plugin_prefs.' . $smd_ebook_event) ? '<div class="txp-buttons">' . $btnMgr . n . $btnPrf . n . $btnCln . '</div>' : '';
    echo n . '<div id="' . $smd_ebook_event . '_control" class="txp-control-panel">' . $btnbar . '</div>';
    if (!$listfile) {
        // Stage 1: Gather the info and create the content
        // Figure out if the various fields are coming from CFs or from user-supplied text areas
        $fields = array('description' => array('html' => 'textarea'), 'authornote' => array('html' => 'textarea'), 'title' => array('html' => 'text_input', 'required' => true), 'chaptitle' => array('html' => 'text_input', 'hide_empty' => true), 'author' => array('html' => 'text_input'), 'publisher' => array('html' => 'text_input'), 'subject' => array('html' => 'text_input'), 'srp' => array('html' => 'text_input'), 'uid' => array('html' => 'text_input'));
        $cfs = getCustomFields();
        foreach ($fields as $field => $data) {
            $data['value'] = get_pref('smd_ebook_fld_' . $field, $smd_ebook_prefs['smd_ebook_fld_' . $field]['default']);
            $data['column'] = is_numeric($data['value']) ? 'custom_' . $data['value'] : $data['value'];
            $data['name'] = is_numeric($data['value']) && isset($cfs[$data['value']]) ? $cfs[$data['value']] : $data['value'];
            $data['content'] = $data['value'] === 'SMD_FIXED' ? get_pref('smd_ebook_fld_' . $field . '_fixed', '') : '';
            $data['required'] = isset($data['required']) ? $data['required'] : false;
            $data['hide_empty'] = isset($data['hide_empty']) ? $data['hide_empty'] : false;
            ${'ip_' . $field} = '<div class="smd_ebook_entity">' . ($data['content'] || $data['name'] === '' && $data['hide_empty'] ? hInput('smd_ebook_fld_' . $field, txpspecialchars($data['content'])) : '<label for="smd_ebook_fld_' . $field . '">' . gTxt('smd_ebook_lbl_' . $field) . '</label>' . ($data['column'] ? hInput('smd_ebook_fld_' . $field, 'SMD_FLD_' . $data['column']) . '<span class="smd_preselected">' . gTxt('smd_ebook_from') . ' ' . str_replace('SMD_FLD_', '', $data['name']) . '</span>' : ($data['html'] === 'textarea' ? text_area('smd_ebook_fld_' . $field, '150', '250', '', 'smd_ebook_fld_' . $field) : fInput('text', 'smd_ebook_fld_' . $field, '', '', '', '', '', '', 'smd_ebook_fld_' . $field, '', $data['required'])))) . '</div>';
        }
        $where = array('1=1');
        $sec = get_pref('smd_ebook_section', $smd_ebook_prefs['smd_ebook_section']['default']);
        if ($sec) {
            $where[] = "Section='" . doSlash($sec) . "'";
        }
        $articles = safe_rows('*', 'textpattern', join(' AND ', $where) . ' ORDER BY url_title');
        // Set up the book type options (if any)
        $book_types = smd_ebook_kindlegen_available() ? array('mobi' => gTxt('smd_ebook_lbl_mobi')) : array();
        $book_types = array_merge($book_types, smd_ebook_crush_options());
        $num_btypes = count($book_types);
        if ($num_btypes === 0) {
            $btype = graf(gTxt('smd_ebook_no_book_types'), ' class="error"');
        } elseif ($num_btypes === 1) {
            reset($book_types);
            $btype = hInput('smd_ebook_type', key($book_types));
        } else {
            $btype = '<span id="smd_ebook_type_opts">' . radioSet($book_types, 'smd_ebook_type', get_pref('smd_ebook_type', 'mobi')) . '</span>';
        }
        // Build dropdown list of articles: not using selectInput() because it doesn't support multiples
        $alist = array();
        $alist[] = '<select name="smd_ebook_articles[]" id="smd_ebook_articles" class="list multiple" multiple="multiple" size="12" required="">';
        foreach ($articles as $row) {
            $alist[] = '<option value="smd_ebook_article_' . txpspecialchars($row['ID']) . '">' . txpspecialchars($row['Title']) . '</option>';
        }
        $alist[] = '</select>';
        echo n . '<div id="' . $smd_ebook_event . '_container" class="txp-container">';
        echo n . '<form id="smd_ebook_form" action="index.php" method="post">';
        echo n . '<div class="smd_ebook_entity"><label for="smd_ebook_articles">' . gTxt('smd_ebook_lbl_articles') . '</label>';
        echo join(n, $alist);
        echo n . '</div>';
        echo n . $ip_description . n . $ip_authornote . n . $ip_title . n . $ip_chaptitle . n . $ip_author . n . $ip_publisher . n . $ip_subject . n . $ip_srp . n . $ip_uid;
        echo n . '<div class="smd_clear"></div>';
        echo n . '<label for="smd_ebook_pubfile">' . gTxt('smd_ebook_pubfile') . '</label>' . fInput('text', 'smd_ebook_pubfile', '', '', '', '', '', '', 'smd_ebook_pubfile') . br . $btype . ($num_btypes > 0 ? fInput('submit', 'smd_ebook_create', gTxt('smd_ebook_lbl_create'), 'publish', '', '', '', '', 'smd_ebook_create') : '');
        echo n . eInput($smd_ebook_event);
        echo n . sInput('smd_ebook_create');
        echo n . tInput();
        echo n . '</form>';
        echo n . '</div>';
    } else {
        // Stage 2: Edit the content and generate the ebook file
        $titlePrefix = gTxt('smd_ebook_preview_prefix');
        $ebType = ps('smd_ebook_type');
        $is_epub = $ebType === 'zip';
        $ebook_path = get_pref('tempdir') . DS . $ebook_folder . DS;
        $qs = array("event" => $smd_ebook_event);
        $qsVars = "index.php" . join_qs($qs);
        echo n . <<<EOJS
<script type="text/javascript">
var smd_ebook_currfile;

jQuery(function() {
    // Load a file into the editor
    jQuery('.smd_ebook_files .smd_ebook_edit').click(function(ev) {
        ev.preventDefault();
        var me = jQuery(this).prevAll('div');
        var name = me.text();

        // Spinner and user feedback
        var form = jQuery(this).closest('form');
        form.addClass('busy');
        s = jQuery(ev.currentTarget);
        s.after('<span class="spinner" />');

        smd_ebook_currfile = name;

        jQuery.post('{$qsVars}',
            {
                step: 'smd_ebook_loadfile',
                folder: '{$ebook_folder}',
                name: name,
                _txp_token: textpattern._txp_token
            },
            function(json) {
                jQuery('.smd_ebook_files .smd_ebook_file').removeClass('smd_selected');
                jQuery('#smd_ebook_editor').removeClass('smd_error');
                me.toggleClass('smd_selected');
                jQuery('#smd_ebook_editor').val(json.data);
                form.removeClass('busy');
                jQuery('span.spinner').remove();
            },
            'json'
        );
    });

    // Save the current file back to the file system
    jQuery('.smd_ebook_filesave').click(function(ev) {
        ev.preventDefault();

        // Spinner and user feedback
        var form = jQuery(this).closest('form');
        form.addClass('busy');
        s = jQuery(ev.currentTarget);
        s.after('<span class="spinner" />')

        var content = jQuery('#smd_ebook_editor').val();

        jQuery.post('{$qsVars}',
            {
                step: 'smd_ebook_savefile',
                folder: '{$ebook_folder}',
                name: smd_ebook_currfile,
                data: content,
                _txp_token: textpattern._txp_token
            },
            function(json) {
                if (json.result === 'ok') {
                    jQuery('.smd_ebook_files .smd_ebook_file').removeClass('smd_selected');
                    jQuery('#smd_ebook_editor').removeClass('smd_error');
                    jQuery('#smd_ebook_editor').val('');
                } else {
                    jQuery('#smd_ebook_editor').addClass('smd_error');
                }
                form.removeClass('busy');
                jQuery('span.spinner').remove();
            },
            'json'
        );
    });

    // Preview an html file in its own popup window
    var smd_ebook_previewing = 0;
    jQuery('.smd_ebook_files .smd_ebook_view').click(function(ev) {
        ev.preventDefault();
        var me = jQuery(this).prevAll('div');
        var name = me.text();

        // Spinner and user feedback
        var form = jQuery(this).closest('form');
        form.addClass('busy');
        s = jQuery(ev.currentTarget);
        s.after('<span class="spinner" />')

        jQuery.post('{$qsVars}',
            {
                step: 'smd_ebook_viewfile',
                folder: '{$ebook_folder}',
                name: name,
                _txp_token: textpattern._txp_token
            },
            function(json) {
                // Grab body text and inject it into the preview container
                jQuery('#smd_ebook_preview_content').empty().append(json.data);
                jQuery('#smd_ebook_preview_title').text('{$titlePrefix} ' + name);
                if ((jQuery(ev.target).hasClass('smd_ebook_view')) && !smd_ebook_previewing) {
                    smd_ebook_prevu();
                }
                form.removeClass('busy');
                jQuery('span.spinner').remove();
            },
            'json'
        );
    });

    // Preview an image file in its own popup window
    jQuery('.smd_ebook_files .smd_ebook_image').click(function(ev) {
        ev.preventDefault();
        var me = jQuery(this);
        var name = me.text();

        // Spinner and user feedback
        var form = jQuery(this).closest('form');
        form.addClass('busy');
        s = jQuery(ev.currentTarget);
        s.after('<span class="spinner" />')

        jQuery.post('{$qsVars}',
            {
                step: 'smd_ebook_viewimage',
                folder: '{$ebook_folder}',
                name: name,
                _txp_token: textpattern._txp_token
            },
            function(json) {
                if (json.src !== null) {
                    source = json.src;
                } else {
                    source = 'data:'+json.mime+';base64,'+json.data;
                }

                jQuery('#smd_ebook_preview_content').empty().append(jQuery('<img />').attr({'src': source, 'alt': 'Preview '+name}));
                jQuery('#smd_ebook_preview_title').text('{$titlePrefix} ' + name);

                if ((jQuery(ev.target).hasClass('smd_ebook_image')) && !smd_ebook_previewing) {
                    smd_ebook_prevu();
                }
                form.removeClass('busy');
                jQuery('span.spinner').remove();
            },
            'json'
        );
    });

    // Toggle individual image list on/off
    jQuery('.smd_ebook_files .smd_ebook_image_toggle').click(function(ev) {
        ev.preventDefault();
        jQuery(this).nextAll('ul').toggle('fast');
    });

    function smd_ebook_prevu() {
        jQuery('#smd_ebook_preview').toggle('fast');
        smd_ebook_previewing = !smd_ebook_previewing;
    }

    function smd_ebook_prevu_bind() {
        jQuery('#smd_ebook_preview_close').click(function(){
            smd_ebook_prevu();
        });
        jQuery(document).keypress(function(e){
            if(e.keyCode == 27 && smd_ebook_previewing) {
                smd_ebook_prevu();
            }
        });
    }
    smd_ebook_prevu_bind();
});
</script>
EOJS;
        echo n . '<div id="' . $smd_ebook_event . '_container" class="txp-container">';
        echo n . '<form id="smd_ebook_form" action="index.php" method="post">';
        echo n . '<div class="smd_ebook_report">' . hed(gTxt('smd_ebook_lbl_report'), 2) . '<textarea id="smd_ebook_report" cols=80 rows="6">' . $report . '</textarea>' . '</div>';
        echo n . '<div class="smd_ebook_manager">';
        // 'Generate book' and 'download' buttons
        echo '<div class="smd_ebook_pub_options">';
        echo n . fInput('submit', 'smd_ebook_generate', gTxt('smd_ebook_lbl_generate'), 'publish smd_ebook_pub');
        if ($retval <= 1) {
            $info = explode('.', $listfile);
            $basepart = array_slice($info, 0, count($info) - 1);
            $outfile = join('', $basepart);
            echo n . hInput('smd_ebook_pubfile', $outfile);
            echo n . hInput('smd_ebook_folder', $ebook_folder);
            echo n . fInput('submit', 'smd_ebook_to_files', gTxt('smd_ebook_lbl_to_files'), 'publish smd_ebook_pub');
            echo n . fInput('submit', 'smd_ebook_download', gTxt('smd_ebook_lbl_download'), 'publish smd_ebook_pub');
        }
        echo n . '</div>';
        echo n . hed(gTxt('smd_ebook_lbl_files'), 2);
        echo n . '<div class="smd_ebook_files">';
        $opf_edit = get_pref('smd_ebook_opf_edit', $smd_ebook_prefs['smd_ebook_opf_edit']['default']);
        $opf_allowed = do_list($opf_edit);
        $opf_allowed[] = '1';
        // Publishers can always edit .opf
        $can_opf = in_array($GLOBALS['privs'], $opf_allowed);
        $files = file($ebook_path . $listfile);
        $files = doArray($files, 'trim');
        $image_list = array();
        $content_file = $content_view = $content_edit = '';
        $is_cover = $has_css = false;
        echo n . '<div class="smd_ebook_file_group">';
        foreach ($files as $file) {
            $info = explode('.', $file);
            $lastpart = count($info) - 1;
            $ext = $info[$lastpart];
            $img_types = array('jpg', 'jpeg', 'gif', 'png');
            if ($ext === 'opf') {
                echo n . hInput('smd_ebook_opf_file', $file);
                echo n . hInput('smd_ebook_type', $ebType);
            }
            if ($ext !== 'opf' || $ext === 'opf' && $can_opf) {
                if (in_array($ext, $img_types)) {
                    $imglink = '<a href="#" class="smd_ebook_image">' . $file . '</a>';
                    if (strpos($file, 'cover') === 0) {
                        $image_list[] = $imglink;
                        $is_cover = true;
                    } else {
                        $image_list[] = '<li>' . $imglink . '</li>';
                        $is_cover = false;
                    }
                } else {
                    $content_file = '<div class="smd_ebook_file">' . $file . '</div>';
                    $content_edit = '[<a href="#" class="smd_ebook_edit">' . gTxt('edit') . '</a>]';
                }
                if ($ext === 'html') {
                    $content_view = '[<a href="#" class="smd_ebook_view">' . gTxt(strpos($file, '_toc.html') !== false || strpos($file, '_end.html') !== false ? 'smd_ebook_lbl_view_toc' : 'smd_ebook_lbl_view') . '</a>]';
                } else {
                    if ($ext === 'css') {
                        $has_css = true;
                    }
                    $content_view = '';
                }
                if (!in_array($ext, $img_types)) {
                    if ($image_list) {
                        if ($is_cover) {
                            if ($has_css) {
                                // Stupid hack because css appears first in the listfile
                                echo n . '</div>';
                                echo n . '<div class="smd_ebook_file_group">';
                            }
                            echo n . join(n, $image_list);
                            // Even though there's only one image
                        } else {
                            echo n . '[<a href="#" class="smd_ebook_image_toggle">' . gTxt('smd_ebook_lbl_img_list') . '</a>]' . tag(join(n, $image_list), 'ul');
                        }
                    }
                    $image_list = array();
                    echo n . '</div>';
                    echo n . '<div class="smd_ebook_file_group">';
                    echo n . $content_file . n . $content_view . n . $content_edit;
                }
            }
        }
        echo n . '</div>';
        echo n . '</div>';
        echo n . '<div class="smd_ebook_editor">';
        echo n . '<textarea id="smd_ebook_editor" cols="60" rows="25"></textarea>';
        echo n . '<button class="smd_ebook_filesave">' . gTxt('save') . '</button>';
        echo n . '</div>';
        echo n . '<div id="smd_ebook_preview">
            <div id="smd_ebook_preview_titlebar">
                <span id="smd_ebook_preview_title"></span>
                <a id="smd_ebook_preview_close">X</a>
            </div>
            <div id="smd_ebook_preview_content"></div>
            </div>';
        echo n . hInput('smd_ebook_listfile', $listfile);
        echo n . eInput($smd_ebook_event);
        echo n . sInput('smd_ebook_generate');
        echo n . tInput();
        echo n . '</div>';
        echo n . '</form>';
        echo n . '<div class="smd_clear"></div>';
        echo n . '</div>';
    }
}