<div class="wrap rssap-form">

    <h2><span class="dashicons dashicons-rss"></span><?php echo esc_html( __( 'Add New Feed', 'rss-autopilot' ) ); ?></h2>

    <form method="post" action="<?php echo $this->menuUrl('rssap-feeds', 'add'); ?>" id="rssap-add-source-form">
        <input type="hidden" value="<?php echo $this->menuUrl('rssap-feeds', 'preview'); ?>" id="rssap-load-preview-url" />
        <input type="hidden" value="<?php echo $this->menuUrl('rssap-feeds', 'extract'); ?>" id="rssap-content-extractor-url" />
        <?php wp_nonce_field( 'rssap-save-rss-autopilot'); ?>
        <div id="rssap-add-source-form-container" class="metabox-holder">
            <div id="titlediv" class="rssap-field-container">
                <input type="text" name="title" size="80" value="" id="title" spellcheck="true" autocomplete="off" placeholder="<?php esc_attr_e('Enter source title', 'rss-autopilot'); ?>" />
            </div>
            <div id="rssap-types-list" class="meta-box-sortables">
                <div class="postbox">
                    <div class="handlediv" title="<?php esc_html_e('Click to toggle', 'rss-autopilot'); ?>"><br></div>
                    <h3 class="hndle ui-sortable-handle"><span><?php esc_html_e('General Options', 'rss-autopilot'); ?></span></h3>
                    <div class="inside">
                        <label for="rssap-url"><b><?php esc_html_e('Feed URL', 'rss-autopilot'); ?></b></label>
                        <div class="field rssap-field-container">
                            <input id="rssap-url" name="url" size="100" />
                        </div>
                        <table width="100%">
                            <tr>
                                <td>
                                    <div>
                                        <label for="rssap-author"><b><?php esc_html_e('Default Author', 'rss-autopilot'); ?></b></label>
                                        <div class="field rssap-field-container">
                                            <?php wp_dropdown_users(array('selected'=>get_current_user_id(), 'name'=>'author', 'id'=>'rssap-author')); ?>
                                        </div>
                                    </div>

                                    <div>
                                        <label for="rssap-status"><b><?php esc_html_e('Default Status', 'rss-autopilot'); ?></b></label>
                                        <div class="field rssap-field-container">
                                            <select id="rssap-status" name="status">
                                                <?php foreach ($statuses as $k=>$status) : ?>
                                                    <option value="<?php echo esc_attr($k); ?>"><?php echo esc_html($status); ?></option>
                                                <?php endforeach; ?>
                                            </select>
                                        </div>
                                    </div>

                                    <div>
                                        <label for="rssap-type"><b><?php esc_html_e('Post type', 'rss-autopilot'); ?></b></label>
                                        <div class="field rssap-field-container">
                                            <select id="rssap-type" name="type">
                                                <?php foreach ($postTypes as $type) : ?>
                                                    <option value="<?php echo esc_attr($type); ?>" <?php if ($type=='post') :?>selected="selected"<?php endif; ?>><?php echo esc_html($type); ?></option>
                                                <?php endforeach; ?>
                                            </select>
                                        </div>
                                    </div>

                                    <div>
                                        <label for="rssap-update-frequency"><b><?php esc_html_e('Update frequency', 'rss-autopilot'); ?></b></label>
                                        <div class="field rssap-field-container">
                                            <select id="rssap-update-frequency" name="update_frequency">
                                                <?php foreach ($updateFrequences as $k=>$frequency) : ?>
                                                    <option value="<?php echo esc_attr($k); ?>" <?php if ($k==1800): ?>selected="selected" <?php endif; ?>><?php echo esc_html($frequency); ?></option>
                                                <?php endforeach; ?>
                                            </select>
                                        </div>
                                    </div>
                                </td>
                                <td>
                                    <div class="field rssap-field-container">
                                        <p><label for="rssap-use-date"><input type="checkbox" value="1" name="use_date" id="rssap-use-date" /> <?php esc_html_e('Use date from feed', 'rss-autopilot'); ?></label><span class="rss-tooltip" title="<?php esc_html_e('By default post date and time are set to current on script execution', 'rss-autopilot'); ?>">?</span></p>
                                    </div>
                                    <div class="field rssap-field-container">
                                        <p><label for="rssap-download-images"><input type="checkbox" value="1" name="download_images" id="rssap-download-images" /> <?php esc_html_e('Download images', 'rss-autopilot'); ?></label><span class="rss-tooltip" title="<?php esc_html_e('By default images are referring to original website. You can download them to your server with this option.', 'rss-autopilot'); ?>">?</span></p>
                                    </div>

                                    <div class="field rssap-field-container">
                                        <p><label for="rssap-remove-links"><input type="checkbox" value="1" name="remove_links" id="rssap-remove-links" /> <?php esc_html_e('Remove Links', 'rss-autopilot'); ?></label><span class="rss-tooltip" title="<?php esc_html_e('Remove all links from the content', 'rss-autopilot'); ?>">?</span></p>
                                    </div>

                                    <div class="field rssap-field-container">
                                        <p><label for="rssap-overwrite-posts"><input type="checkbox" value="1" name="overwrite_posts" id="rssap-overwrite-posts" /> <?php esc_html_e('Overwrite posts', 'rss-autopilot'); ?></label><span class="rss-tooltip" title="<?php esc_html_e('Overwrite existing posts on every run', 'rss-autopilot'); ?>">?</span></p>
                                    </div>

                                    <div>
                                        <label for="rssap-posts-limit"><b><?php esc_html_e('Limit number of posts', 'rss-autopilot'); ?></b> <span class="rss-tooltip" title="<?php esc_html_e('Limit number of posts for a single run', 'rss-autopilot'); ?>">?</span></label>
                                        <div class="field rssap-field-container">
                                            <input size="3" id="rssap-posts-limit" name="posts_limit" value="50" />
                                        </div>
                                    </div>

                                    <div>
                                        <label for="rssap-translate"><b><?php esc_html_e('Translate posts', 'rss-autopilot'); ?></b></label>
                                        <div class="field rssap-field-container">
                                            <select id="rssap-translate" name="translate">
                                                <option value=""><?php esc_attr_e('[ Don\'t Translate ]', 'rss-autopilot'); ?></option>
                                                <?php foreach ($languages as $dir=>$lang) : ?>
                                                    <option value="<?php echo esc_attr($dir); ?>"><?php echo esc_html($lang); ?></option>
                                                <?php endforeach; ?>
                                            </select>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>

                <div class="postbox">
                    <div class="handlediv" title="<?php esc_html_e('Click to toggle', 'rss-autopilot'); ?>"><br></div>
                    <h3 class="hndle ui-sortable-handle"><span><?php esc_html_e('Categories', 'rss-autopilot'); ?></span></h3>
                    <div class="inside">
                        <p><label for="rssap-extract-categories"><input type="checkbox" value="1" name="extract_categories" id="rssap-extract-categories" /> <?php esc_html_e('Extract categories from feed (create categories automatically)', 'rss-autopilot'); ?></label></p>
                        <p><label for="rssap-extract-tags"><input type="checkbox" value="1" name="extract_tags" id="rssap-extract-tags" /> <?php esc_html_e('Extract categories from feed as tags', 'rss-autopilot'); ?></label></p>
                        <ul class="rssap-categories-list">
                        <?php wp_category_checklist(); ?>
                        </ul>
                        <div class="clear"></div>
                    </div>
                </div>

                <div class="postbox">
                    <div class="handlediv" title="<?php esc_html_e('Click to toggle', 'rss-autopilot'); ?>"><br></div>
                    <h3 class="hndle ui-sortable-handle"><span><?php esc_html_e('Content Options', 'rss-autopilot'); ?></span></h3>
                    <div class="inside">
                        <table width="100%">
                            <tr>
                                <td>
                            <p><label for="rssap-dont-add-excerpt"><input type="checkbox" value="1" name="dont_add_excerpt" id="rssap-dont-add-excerpt" /> <?php esc_html_e('Don\'t add excerpt', 'rss-autopilot'); ?></label></p>
                                </td>
                                <td id="rssap-limit-excerpt-block">
                                    <label for="rssap-limit-excerpt"><?php esc_html_e('Limit number of characters to', 'rss-autopilot'); ?></label>
                                    <input type="text" size="4" name="limit_excerpt" id="rssap-limit-excerpt" value="1000" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                            <p><label for="rssap-add-more-tag"><input type="checkbox" value="1" name="add_more_tag" id="rssap-add-more-tag" /> <?php esc_html_e('Add <!--more--> tag', 'rss-autopilot'); ?></label></p>
                                </td>
                                <td id="rssap-add-more-tag-block">
                                    <label for="rssap-paragraphs-num"><?php esc_html_e('after number of paragraphs', 'rss-autopilot'); ?></label>
                                    <input type="text" size="4" name="paragraphs_num" id="rssap-paragraphs-num" value="1" />
                                </td>
                            </tr>
                        </table>

                        <hr>

                        <p><b><?php esc_html_e('Post Content', 'rss-autopilot'); ?></b></p>
                        <div class="field rssap-field-container">
                            <p><label for="rssap-display-readmore"><input type="checkbox" value="1" name="display_readmore" id="rssap-display-readmore" /> <?php esc_html_e('Display link to source', 'rss-autopilot'); ?></label></p>
                            <input type="text" size="50" name="readmore_template" value="<?php echo esc_attr('<a href=%LINK%>مقاله اصلی</a>'); ?>" />
                            <span title="<?php esc_html_e('HTML allowed. Use %LINK% placeholder to add URL', 'rss-autopilot'); ?>" class="rss-tooltip">?</span>
                        </div>

                        <div class="field rssap-field-container">
                            <p><label for="rssap-enable-scrapper"><input type="checkbox" name="enable_scrapper" value="1" id="rssap-enable-scrapper" /> <?php esc_html_e('Enable web scraper', 'rss-autopilot'); ?></label><span class="rss-tooltip" title="<?php esc_html_e('You can enable web scraper to download full article contents. Please note, it takes more time to download.', 'rss-autopilot'); ?>">?</span></p>
                            <div class="content-extractor-options">
                                <p><a id="content-extractor-btn" href="#content-extractor" class="button"><?php esc_html_e('Configure content extractor', 'rss-autopilot'); ?></a></p>
                                <textarea rows="4" cols="30" name="content_extractor_rule" id="content-extractor-rule" placeholder="<?php esc_attr_e('XPath selector can be set here', 'rss-autopilot'); ?>"></textarea>
                                <textarea rows="4" cols="30" name="content_extractor_ignore_rule" id="content-extractor-ignore-rule" placeholder="<?php esc_attr_e('XPath selectors for ignored elements can be set here', 'rss-autopilot'); ?>"></textarea>
                            </div>
                        </div>

                        <hr>
                        <p><b><?php esc_html_e('Content wrapper', 'rss-autopilot'); ?></b></p>
                        <div class="field rssap-field-container">
                            <textarea rows="8" cols="80" name="content_wrapper" id="content-wrapper" placeholder="<?php esc_attr_e('قبل و بعد از مقاله متن و یا HTML را اضافه کنید. از %CONTENT% به عنوان محتوای مقاله دریافت شده استفاده کنید. برای نادیده گرفتن این گزینه آن را خالی بگذارید. برای مثال:

<h1>مقاله دریافت شده از سایت domain.com</h1>
%CONTENT%
<a href="http://domain.com">لطفا از سایت دامین دیدن کنید!</a>', 'rss-autopilot'); ?>"></textarea>
                        </div>

                        <hr>
                        <div class="field rssap-field-container">
                            <p><b><?php esc_html_e('Set featured image', 'rss-autopilot'); ?></b></p>
                            <p><label><input type="radio" checked="checked" name="thumbnail" value="" /> <?php esc_html_e('None', 'rss-autopilot'); ?></label></p>
                            <p><label><input type="radio" name="thumbnail" value="feed" /> <?php esc_html_e('Thumbnail from feed', 'rss-autopilot'); ?></label><span class="rss-tooltip" title="<?php esc_attr_e('Set featured image from feed file', 'rss-autopilot'); ?>">?</span></p>
                            <p><label><input type="radio" name="thumbnail" value="content" /> <?php esc_html_e('Image from content', 'rss-autopilot'); ?></label><span class="rss-tooltip" title="<?php esc_attr_e('Set featured image from article summary or article content (if content extractor is in use)', 'rss-autopilot'); ?>">?</span></p>
                            <p><label><input type="radio" name="thumbnail" value="content_delete" /> <?php esc_html_e('Image from content (and delete)', 'rss-autopilot'); ?></label><span class="rss-tooltip" title="<?php esc_attr_e('Set featured image from article summary or article content (if content extractor is in use) and delete it from content - useful for themes that display featured images on post page', 'rss-autopilot'); ?>">?</span></p>
                            <p><label><input type="radio" name="thumbnail" value="media" id="featured-upload-option" /> <?php esc_html_e('Set image from media library', 'rss-autopilot'); ?></label><span class="rss-tooltip" title="<?php esc_attr_e('Set static featured image for all articles from media library', 'rss-autopilot'); ?>">?</span></p>

                            <div style="display:none" id="featured-upload-block">
                                <input type="text" id="upload-featured" name="upload_featured" value="" size="50">
                                <input type="hidden" id="upload-featured-id" name="upload_featured_id" value="">
                                <input type="button" value="<?php esc_attr_e('Upload file', 'rss-autopilot');?>" class="button rss-upload" data-type="image" data-target-field="upload-featured" data-target-hidden-field="upload-featured-id" data-dialog-title="<?php esc_attr_e('Upload Featured file', 'rss-autopilot');?>" data-button-text="<?php esc_attr_e('Use as featured', 'rss-autopilot');?>">
                        </div>

                        <div>
                            <p><b><?php esc_html_e('Fallback featured image', 'rss-autopilot'); ?></b></p>
                            <div id="fallback-upload-block">
                                <input type="text" id="upload-fallback" name="upload_fallback" value="" size="50">
                                <input type="hidden" id="upload-fallback-id" name="upload_fallback_id" value="">
                                <input type="button" value="<?php esc_attr_e('Upload file', 'rss-autopilot');?>" class="button rss-upload" data-type="image" data-target-field="upload-fallback" data-target-hidden-field="upload-fallback-id" data-dialog-title="<?php esc_attr_e('Upload Fallback Featured file', 'rss-autopilot');?>" data-button-text="<?php esc_attr_e('Use as fallback featured', 'rss-autopilot');?>">
                            </div>
                        </div>

                        <hr>
                        <div class="field rssap-field-container">
                            <p><label for="rssap-enable-filters"><input type="checkbox" name="enable_filters" value="1" id="rssap-enable-filters" /> <?php esc_html_e('Enable content filters', 'rss-autopilot'); ?></label><span class="rss-tooltip" title="<?php esc_html_e('Using this option you can filter articles by specified keywords', 'rss-autopilot'); ?>">?</span></p>
                            <div class="content-filter-options">
                                <p><label for="rssap-filter-must"><?php esc_html_e('Specify words any of which MUST be presented in a content in order to be added (comma separated):', 'rss-autopilot'); ?></label></p>
                                <textarea rows="3" cols="60" name="filter_keywords_must" id="rssap-filter-must" placeholder="<?php esc_attr_e('Comma separated words', 'rss-autopilot'); ?>"></textarea>

                                <p><label for="rssap-filter-block"><?php esc_html_e('Don\'t add articles containing any of following words (comma separated):', 'rss-autopilot'); ?></label></p>
                                <textarea rows="3" cols="60" name="filter_keywords_block" id="rssap-filter-block" placeholder="<?php esc_attr_e('Comma separated words', 'rss-autopilot'); ?>"></textarea>
                            </div>
                        </div>

                        <div class="field rssap-field-container">
                            <p><label for="rssap-add-canonical"><input type="checkbox" name="add_canonical" value="1" id="rssap-add-canonical" /> <?php esc_html_e('Add canonical URL to source', 'rss-autopilot'); ?></label></p>
                        </div>

                        <p><a href="#" class="button feed-preview-btn"><?php esc_html_e('Preview', 'rss-autopilot');?></a></p>
                    </div>
                </div>
            </div>

            <div id="rssap-preview" class="rssap-meta-box-container meta-box-sortables">
                <div class="postbox">
                    <div class="handlediv" title="<?php esc_html_e('Click to toggle', 'rss-autopilot'); ?>"><br></div>
                    <h3 class="hndle"><span><?php esc_html_e('Preview', 'rss-autopilot');?></span></h3>
                    <div class="inside"></div>
                </div>
            </div>

            <div class="save-rss-autopilot-form">
                <input type="submit" class="button-primary" name="save" value="<?php echo esc_attr( __( 'Save', 'rss-autopilot' ) ); ?>" />
            </div>
        </div>
    </form>
</div><br>
<div id="content-extractor" style="display:none;"><iframe id="content-extractor-iframe"></iframe></div>