File: /home/dtptviut/public_html/wp-content/plugins/comparisonfeed-wp/compare-feed-wp-metabox.php
<?php
add_action( 'add_meta_boxes', 'compare_metabox_add' );
function compare_metabox_add()
{
$screens = array( 'post', 'page' );
foreach ( $screens as $screen ) {
add_meta_box( 'adservice-comparison-feed', 'Comparison Feed Generator', 'compare_metabox', $screen, 'normal', 'high' );
}
}
function compare_metabox()
{
// $post is already set, and contains an object: the WordPress post
global $post;
$adservice_options = get_option("adservice_options");
if ($adservice_options['login']):
$values = get_post_custom( $post->ID );
$text = isset( $values['publisherID'][0] ) ? $values['publisherID'][0] : '';
$customRating = isset( $values['custom-rating'][0] ) ? $values['custom-rating'][0] : '';
$customOrder = isset( $values['custom-order'][0] ) ? $values['custom-order'][0] : '';
$removedItems = isset( $values['removed-items'][0] ) ? $values['removed-items'][0] : '';
$conditions = isset( $values['conditions'][0] ) ? $values['conditions'][0] : '';
$initialRows = isset( $values['initial-rows'][0] ) ? $values['initial-rows'][0] : '';
$maxRows = isset( $values['max-rows'][0] ) ? $values['max-rows'][0] : '';
$minRating = isset( $values['min-rating'][0] ) ? $values['min-rating'][0] : '60';
$selected = isset( $values['compare-template'][0] ) ? esc_attr( $values['compare-template'][0] ) : '';
$active_account = isset( $values['compare-account'][0] ) ? esc_attr( $values['compare-account'][0] ) : '';
$sub = isset( $values['subID'][0] ) ? $values['subID'][0] : '';
$mediaID = isset( $values['mediaID'][0] ) ? $values['mediaID'][0] : '0';
$feedID = isset( $values['feed-id'][0] ) ? $values['feed-id'][0] : '';
// Retrieving additional accounts for the publisher account
$adservice_options['accounts'] = getAccounts($adservice_options);
update_option('adservice_options', $adservice_options);
$accounts = $adservice_options['accounts'];
// Retrieving medias for the publisher account
$medias = [];
if ($active_account) {
$response = json_remote_get("https://api.adservice.com/v2/publisher/account/connected/" . $active_account . "/medias", $adservice_options);
if ($response && isset($response->data)) {
$medias = (isset($response->data->medias)) ? $response->data->medias : $response->data;
}
}
// Set useIframe to saved value or default to '1' if this is a new page.
$useIframe = '';
if (isset( $values['use-iframe'][0] )) {
$useIframe = $values['use-iframe'][0];
} else if (!isset( $values['compare-template'][0] ) && !isset( $values['compare-account'][0] )) {
$useIframe = '1';
}
$showFilter = isset( $values['show-filter'][0] ) ? $values['show-filter'][0] : '1';
$includeNewCampaigns = isset( $values['include-new-campaigns'][0] ) ? $values['include-new-campaigns'][0] : 'true';
$lazyLoading = isset( $values['lazy-loading'][0] ) ? $values['lazy-loading'][0] : 'true';
$buttonColor = isset( $values['button-color'][0] ) ? $values['button-color'][0] : '#82c075';
$buttonHoverColor = isset( $values['button-hover-color'][0] ) ? $values['button-hover-color'][0] : '#62b052';
$fontUrl = isset( $values['font-url'][0] ) ? $values['font-url'][0] : '';
$fontName = isset( $values['font-name'][0] ) ? $values['font-name'][0] : '';
$shortcode = ($useIframe) ? '[adservice-comparison-feed-iframe]' : '[adservice-comparison-feed]';
$usingFilterShortcode = has_shortcode($post->post_content, 'adservice-comparison-filter');
// We'll use this nonce field later on when saving.
wp_nonce_field( 'my_meta_box_nonce', 'meta_box_nonce' );?>
<div class="row" >
<a id="as-general-tab" class="as-tab <?php if (!($feedID || !$active_account)) { echo 'active'; } ?>" data-anchor="#as-general">General settings</a>
<a id="as-advanced-tab" class="as-tab" data-anchor="#as-advanced">Advanced settings</a>
<a id="as-expand-tab" class="as-tab" data-anchor="#as-expand">Expand market</a>
<a id="as-feed-builder-tab" class="as-tab <?php if ($feedID || !$active_account) { echo 'active'; } ?>" data-anchor="#as-feed-builder">
Feed Builder
</a>
<div id="as-general" class="as-anchor <?php if (!($feedID || !$active_account)) { echo 'active'; } ?>">
<div class="news-box">
<h2 style="margin-bottom: 0px;">Introducing a better way to manage your feeds with Feed Builder</h2>
<ul class="as-list">
<li>Create and manage all your feeds in one central place</li>
<li>Copy existing feeds to quickly make new variations</li>
<li>Reuse feeds across pages, posts and even sites to apply your changes everywhere at once</li>
</ul>
<a class="as-tab-link button button-primary button-large" data-anchor="#as-feed-builder"
title="Get started using the Feed Builder">
<li class="fa fa-lg fa-link" style="margin-right: 5px"></li>
Get started
</a>
</div>
<div class="legal-notice" style="margin-top: 20px;">
<h2><li class="fa fa-lg fa-warning" style="margin-right: 5px"></li>Feed Generator is deprecated</h2>
<p>This Feed Generator is retiring soon and won't receive new features or improvements anymore.</p>
<p>Please use our improved <a href="https://publisher.adservice.com/tools/comparisonfeed/feed"
title="Go to Feed Builder" target="_blank">Feed Builder</a> instead. Existing feeds can easily be <a class="as-tab-link" data-anchor="#as-feed-builder">exported</a> and reused.</p>
</div>
<p>To generate your comparison feed please choose your target country audience and choose the data category that you would like to display.</p>
<div class="as-generator-row">
<div class="col-left">
<label for="compare-account">Choose your target country audience for this page</label>
</div>
<div class="col-right">
<select name="compare-account" id="compare-account">
<option value="0" data-country=""> -- Choose country --</option>
<?php foreach ($accounts as $account => $value) { ?>
<?php if ($value['countrycode'] === 'dk') {
$country = "Denmark";
} else if ($value['countrycode'] === 'se') {
$country = "Sweden";
} else if ($value['countrycode'] === 'no') {
$country = "Norway";
} else if ($value['countrycode'] === 'fi') {
$country = "Finland";
} else if ($value['countrycode'] === 'de') {
$country = "Germany";
} else if ($value['countrycode'] === 'pl') {
$country = "Poland";
} else if ($value['countrycode'] === 'es') {
$country = "Spain";
} else if ($value['countrycode'] === 'mx') {
$country = "Mexico";
}
?>
<option value="<?php echo $value['id']; ?>"
data-country="<?php echo $value['countrycode']; ?>"
data-countryName="<?php echo $country; ?>"
data-accountName="<?php echo $value['company_name']; ?>" <?php selected( $active_account, $value['id'] ); ?>>
<?php echo $country;; ?> (<?php echo $value['company_name'] ?>)
</option>
<?php } ?>
</select>
</div>
</div>
<div class="clearfix"></div>
<div class="as-generator-row">
<div class="col-left">
<label for="compare-template">Choose feed category</label>
</div>
<div class="col-right">
<select name="compare-template" id="compare-template">
<option value="0"> -- Choose feed category --</option>
<option value="180,147" id="allLoans" <?php selected( $selected, '180,147' ); ?>>All loans</option>
<option value="180" id="quickloan" <?php selected( $selected, '180' ); ?>>Quick Loan</option>
<option value="147" id="loan" <?php selected( $selected, '147' ); ?>>Loan</option>
<option value="170" id="creditcard" <?php selected( $selected, '170' ); ?>>Creditcard</option>
<option value="164" id="socialSecurity" <?php selected( $selected, '164' ); ?>>Social security (Akasser)</option>
<option value="174" id="dating" <?php selected( $selected, '174' ); ?>>Dating</option>
<option value="64" id="hosting" <?php selected( $selected, '64' ); ?>>Hosting</option>
<option value="167" id="broadband" <?php selected( $selected, '167' ); ?>>Broadband</option>
<option value="184" id="casino" <?php selected( $selected, '184' ); ?>>Casino</option>
<option value="157" id="magazine" <?php selected( $selected, '157' ); ?>>Magazine</option>
<option value="153" id="mobileSubscription" <?php selected( $selected, '153' ); ?>>Mobile Subscription</option>
</select>
</div>
</div>
<?php if ( $medias > 0) { ?>
<div class="as-generator-row">
<div class="col-left">
<label for="mediaID">Choose a media</label>
</div>
<div class="col-right">
<select name="mediaID" id="mediaID">
<option value="0" <?php $mediaID == '0' ? ' selected="selected"' : '';?>> -- No media selected --</option>
<?php foreach ( (array) $medias as $media) { ?>
<option value="<?php echo $media->id; ?>" <?php if( $media->id == $mediaID ) { echo ' selected="selected"'; } else { echo ''; }?>><?php echo $media->medianame; ?><em> (<?php echo $media->url; ?>)</em></option>
<?php } ?>
</select>
</div>
</div>
<?php } ?>
<div class="as-generator-row">
<div class="col-left">
<label for="subID">Create a dynamic sub id</label>
</div>
<div class="col-right">
<input name="subID" id="subID" value="<?php echo $sub; ?>"/>
</div>
</div>
<div class="clearfix"></div>
<div class="as-generator-row">
<div class="col-left">
<label for="">Feed conditions</label>
<p>Show only campaigns matching certain conditions based on feed data values.</p>
</div>
<div class="col-right">
<a href="#TB_inline?height=auto&inlineId=feed-conditions" class="thickbox button button-primary button-large change-order disabled" name="Feed Conditions" style="white-space: normal;">
<li class="fa fa-lg fa-list" style="margin-right: 5px"></li>
Set conditions
</a>
</div>
</div>
<div class="as-generator-row">
<div class="col-left">
<label for="">Customize campaign order and ratings</label>
<p>Customize your feed by hiding certain campaigns or by changing the order / ratings.</p>
</div>
<div class="col-right">
<a href="#TB_inline?height=auto&inlineId=rating-and-order" class="thickbox button button-primary button-large change-order disabled" name="Drag and drop to change order and ratings" style="white-space: normal;">
<li class="fa fa-lg fa-cog" style="margin-right: 5px"></li>
Change order and ratings
</a>
</div>
</div>
<div class="as-generator-row">
<div class="col-left">
<label for="include-new-campaigns">Include new campaigns automatically</label>
<p>Choose whether or not you want new campaigns to be added to your feed automatically.</p>
</div>
<div class="col-right">
<label class="as-switch">
<input type="checkbox" name="include-new-campaigns" id="include-new-campaigns" placeholder="" value="<?php echo $includeNewCampaigns; ?>" onchange="updateIncludeNewCampaigns(this);"/>
<span class="as-slider round"></span>
</label>
</div>
</div>
<div class="as-generator-row">
<div class="col-left">
<label for="use-iframe">Use responsive iFrame</label>
<span class="as-tag"><li class="fa fa-check" style="margin-right: 5px;"></li>Recommended</span>
<p>Makes sure your feed always fits the available space and adapts to any device. All resources are fetched straight from us to guarantee the latest look and feel. <a href="admin.php?page=comparisonfeed-wp%2Fcompare-iframe-feeds.php" alt="Read more on iFrame feeds" title="Read more on iFrame feeds" target="_blank">Read more</a></p>
</div>
<div class="col-right">
<label class="as-switch">
<input type="checkbox" name="use-iframe" id="use-iframe" placeholder="" value="<?php echo $useIframe; ?>" onchange="updateUseIframe(this);"/>
<span class="as-slider round"></span>
</label>
</div>
</div>
<!-- Iframe Options -->
<div id="as-iframe-options" class="as-generator-row" style="display:none;">
<hr class="as-divider"/>
<div class="as-generator-row">
<div class="col-left">
<label for="show-filter">Show filter if available</label>
<p>Choose whether or not you want a filter displayed with the feed if available.</p>
</div>
<div class="col-right">
<label class="as-switch">
<input type="checkbox" name="show-filter" id="show-filter" placeholder="" value="<?php echo $showFilter; ?>" onchange="updateShowFilter(this);"/>
<span class="as-slider round"></span>
</label>
</div>
</div>
<div class="as-generator-row">
<div class="col-left">
<label for="button-color">Choose call-to-action button color</label>
<p>The color of the button shown next to each product in your feed.</p>
</div>
<div class="col-right">
<input type="color" class="as-input-color" name="button-color" id="button-color" value="<?php echo $buttonColor; ?>"/>
<li class="as-fa-button fa fa-refresh" onclick="jQuery('#button-color').val('#82c075');"></li>
</div>
</div>
<div class="as-generator-row">
<div class="col-left">
<label for="button-hover-color">Choose call-to-action button hover color</label>
<p>The color of the same button when you place your mouse over it.</p>
</div>
<div class="col-right">
<input type="color" class="as-input-color" name="button-hover-color" id="button-hover-color" value="<?php echo $buttonHoverColor; ?>"/>
<li class="as-fa-button fa fa-refresh" onclick="jQuery('#button-hover-color').val('#62b052');"></li>
</div>
</div>
<div class="as-generator-row">
<div class="col-left">
<label for="font-url">Enter font URL</label>
<p>You may override our default font with any font you like. If you want a non-standard font then enter a stylesheet link here.</p>
</div>
<div class="col-right">
<input type="url" name="font-url" id="font-url" value="<?php echo $fontUrl; ?>"
placeholder="https://fonts.googleapis.com/css?family=Open+Sans"/>
</div>
</div>
<div class="as-generator-row">
<div class="col-left">
<label for="font-url">Enter font name</label>
<p>Enter the name of your desired font. It can be the name of the font linked to above or a standard one like 'Arial' or 'Verdana'.</p>
</div>
<div class="col-right">
<input type="text" name="font-name" id="font-name" value="<?php echo $fontName; ?>"
placeholder="Open Sans"/>
</div>
</div>
</div>
<textarea name="custom-rating" class="hidden" id="custom-rating"><?php echo $customRating; ?></textarea>
<textarea name="custom-order" class="hidden" id="custom-order"><?php echo $customOrder; ?></textarea>
<textarea name="removed-items" class="hidden" id="removed-items"><?php echo $removedItems; ?></textarea>
<textarea name="conditions" class="hidden" id="conditions"><?php echo $conditions; ?></textarea>
<input id="using-filter-shortcode" type="hidden" value="<?php echo $usingFilterShortcode; ?>"/>
<input name="feed-id" id="feed-id" class="hidden" value="<?php echo $feedID; ?>"/>
</div> <!-- end ad-generel -->
<div id="as-advanced" class="as-anchor">
<div class="col-left">
<label for="initial-rows">Initial number of campaigns</label>
<p>Initially display this amount of campaigns in your feed along with a 'View more' button at the bottom, which expands the feed to include the remaining campaigns. This can be combined with setting a maximum number of campaigns below. Leave empty to display all campaigns.</p>
</div>
<div class="col-right">
<input type="text" name="initial-rows" id="initial-rows" placeholder="" value="<?php echo $initialRows; ?>" />
</div>
<div class="col-left">
<label for="max-rows">Max. number of campaigns</label>
<p>Limit the number of campaigns in the feed. Leave empty to display all campaigns.</p>
</div>
<div class="col-right">
<input type="text" name="max-rows" id="max-rows" placeholder="" value="<?php echo $maxRows; ?>" />
</div>
<div class="col-left">
<label for="min-rating">Min. star rating</label>
<p>Set a minimum rating for the campaigns (0 = no stars, 100 = 5 stars). Default rating: 60 (3 stars).</p>
</div>
<div class="col-right">
<input type="number" name="min-rating" id="min-rating" placeholder="60" value="<?php echo $minRating; ?>"
onchange="updateMinRating(this);"/>
</div>
<div class="as-generator-row">
<div class="col-left">
<label for="lazy-loading">Lazy loading of images</label>
<span class="as-tag"><li class="fa fa-check" style="margin-right: 5px;"></li>Recommended</span>
<p>When enabled, images are only loaded shortly before they are visible on the users screen. This improves page load times and reduces that amount of data to download.</p>
</div>
<div class="col-right">
<label class="as-switch">
<input type="checkbox" name="lazy-loading" id="lazy-loading"
placeholder="" value="<?php echo $lazyLoading; ?>"
onchange="updateLazyLoading(this);"/>
<span class="as-slider round"></span>
</label>
</div>
</div>
</div>
<!-- end ad-advanced -->
<div id="as-expand" class="as-anchor">
<h3>Expand your business to other countries</h3>
<p>If you want to display the comparison feed in other countries, that is currently not availalbe in your Adservice
publisher account dropdown above, then create and connect an account for your new country in the Adservice Publisher interface.</p>
This will give you the oppertunity to show comparison feeds for other countries, which is an easy way to expand your business.
<p>If you have any questions then feel free to contact us.</p>
<p><a href="https://publisher.adservice.com/edit-account/connected-accounts" target="_blank">Apply for an account in a new country</a></p>
</div>
<div id="as-feed-builder" class="as-anchor <?php if ($feedID || !$active_account) { echo 'active'; } ?>">
<p>Our <a href="https://publisher.adservice.com/tools/comparisonfeed/feed"
title="Go to Feed Builder" target="_blank">Feed Builder</a> simplifies the way you work with our comparison feeds.</p>
<h2>Benefits include</h2>
<ul class="as-list">
<li>Create and manage all your feeds in one central place</li>
<li>Copy existing feeds to quickly make new variations</li>
<li>Reuse feeds across pages, posts and even sites to apply your changes everywhere at once</li>
</ul>
<div id="try-feed-builder-section" style="display: none;">
<h2>Getting started</h2>
<p>Check out the Feed Builder on publisher.adservice.com, create your desired feed
and come back here with the provided shortcode to setup your feed.</p>
<br/>
<a class="button button-primary button-large" tile="Open Feed Builder"
href="https://publisher.adservice.com/tools/comparisonfeed/feed"
target="_blank">
<li class="fa fa-lg fa-external-link" style="margin-right: 5px"></li>
Open Feed Builder
</a>
</div>
<div id="export-feed-section" style="display: none;">
<h2>Getting started</h2>
<p>
You may export your existing feed to your Adservice publisher account to start managing it using
the Feed Builder.
</p>
<p>
<li class="fa fa-lg fa-info-circle" style="margin-right: 5px"></li>
Exporting your feed will not affect your current feed. It will simply save the feed settings on your publisher account.
</p>
<div id="export-feed-form">
<div class="as-generator-row">
<div class="col-left">
<label>Enter a name for your feed</label>
</div>
<div class="col-right">
<input id="feedName" type="text" placeholder="Example Feed Name"/>
</div>
</div>
<div class="as-generator-row">
<div class="col-left">
<label>Enter a unique ID representing this feed. <i>Cannot be changed later</i></label>
</div>
<div class="col-right">
<input id="feedID" type="text" placeholder="example-feed-id-123"/>
</div>
</div>
<br/><br/>
<div class="as-generator-row">
<button class="button button-primary button-large"
tile="Export your feed now" style="white-space: normal;"
onclick="exportFeed('<?php echo $adservice_options['pid'] ?>', '<?php echo $adservice_options['token'] ?>'); return false;">
<li class="fa fa-lg fa-share" style="margin-right: 5px"></li>
Export Feed & Update
</button>
<div id="export-feed-error" style="display: none;">
<li class="fa fa-lg fa-exclamation-circle"
style="margin-right: 5px;"></li>
<span></span>
</div>
</div>
</div>
</div>
<div id="export-feed-completed-section" class="news-box" style="display: none;">
<h2>Export succeeded</h2>
<p>
Your feed <b><span></span></b> was succesfully exported to your publisher account <b><span></span></b> in <b><span></span></b>.
</p>
<p>
Use the shortcode below to display it on any WordPress site running this plugin and
use the Feed Builder to manage the feed.
</p>
<p>
<li class="fa fa-lg fa-info-circle" style="margin-right: 5px"></li>
Only changes made using the Feed Builder will have an effect when using the shortcode below.
</p>
<p><code></code></p>
<br/>
<a class="button button-primary button-large" tile="Open Feed Builder"
href="https://publisher.adservice.com/tools/comparisonfeed/feed"
target="_blank">
<li class="fa fa-lg fa-external-link" style="margin-right: 5px"></li>
Open Feed Builder
</a>
</div>
</div>
</div>
<div class="legal-notice" style="display:none">
<h2>Legal notice</h2>
<p>Some countries have legal requirements for comparison sites such as the ones listed below. This currently applies to <b>Denmark</b> and <b>Norway</b> but may change over time.</p>
<ul class="as-list">
<li>It should be clear that the site is operated for commercial purposes. This should be stated where the comparison feed is available and on the “About” page, if you have one.</li>
<li>It should be clear that the site does not necessarily compare all available products on the market and thus does not fully cover the entire market.</li>
<li>Each product should be advertised as "sponsored" / "advertisement". We handle this for you in the cases we are aware of.</li>
</ul>
<p>It is your responsibility to always adhere to the latest marketing regulations of the target country on your site when using this product.</p>
</div>
<div class="code-generated" style="display:none">
<h2 style="margin-bottom:0px;">Here's your shortcode!</h2>
<p>Copy this shortcode <code id="as-feed-shortcode"><?php echo $shortcode; ?></code> into your editor where you want to display your comparison feed.<br/></p>
<p class="categoryFilter" style="display:none">Copy the <code>[adservice-comparison-filter]</code> shortcode where you want to display the filter for the comparison feed.</br>
Currently the filter is only available for: "All loans", "Loan", "Quick loan", "Broadband" and "Mobile Subscription".</p>
</div>
<?php add_thickbox(); ?>
<div id="rating-and-order" style="display:none;">
<p>
You can change the order and rating of the different campaigns in your feed. Just drag the different elements to order them the way you like.
<br/><br/>
<b>Note:</b> Using a custom order/rating means that you won't benefit from our automatic, performance based ordering.
</p>
<p>
If you are unable to load our content, then this might be due to an adblocker or certain browser/WordPress plugins e.i. caching tools. Please deactivate adblocker and/or attempt to identify the conflicting plugin.
</p>
<div id="loading">
<div class="spinner"></div>
</div>
<div id="adminTableHolder"
data-adserviceFeed="false"
data-categoryId="<?php echo $selected; ?>"
data-cleanLink="true"
data-conditions='<?php echo $conditions; ?>'
data-customOrder="<?php echo $customOrder; ?>"
data-customRating="<?php echo $customRating; ?>"
data-minEpc="0"
data-minRating="<?php echo $minRating; ?>"
data-publisherId="<?php echo $active_account; ?>"
data-template="#adminOutputTmpl">
</div>
<script id="adminOutputTmpl" type="text/x-jquery-tmpl">
<div id="adminTpl">
<ul>
<li class="heading">
<ul>
<li class="head1">
<p>Change order</p>
</li>
<li class="head2">
<p>Logo</p>
</li>
<li class="head3">
<p>Campaign name</p>
</li>
<li class="head4">
<p>Rating</p>
</li>
</ul>
</li>
</ul>
<ul id="sortable">
{{for data}}
<?php include( plugin_dir_path( __FILE__ ) . '/templates-admin/admin_tpl.html'); ?>
{{/for}}
</ul>
</div>
</script>
<div class="bottom-bar">
<span id="new-campaign-available" class="as-tag as-tag-big as-tag-green hidden"><i class="fa fa-exclamation" style="margin-right: 5px;"></i>New campaign available</span>
<span id="conditions-applied" class="as-tag as-tag-big as-tag-navy hidden"
title="Some campaigns might not be included because they don't match your conditions">
<i class="fa fa-exclamation" style="margin-right: 5px;"></i>
Conditions applied
</span>
<span id="using-custom-order" class="as-tag as-tag-big as-tag-yellow hidden"
title="The ordering is fixed according to your settings and therefore does not benefit from our automatic, performance based ordering">
<i class="fa fa-exclamation" style="margin-right: 5px;"></i>
Using custom order
</span>
<a href="#" class="button button-secondary button-large reset">Reset</a>
<a href="#" class="button button-primary button-large save" onclick="self.parent.tb_remove(); return false;">Save</a>
<a href="#" class="button button-primary button-large update" onclick="self.parent.tb_remove(); return false;">Save & Update</a>
</div>
</div>
<!-- Feed Conditions Modal -->
<div id="feed-conditions" style="display:none;">
<div id="feed-conditions-container">
<p>
You may define feed conditions to only include the campaigns that matches certain criteria in your feed.<br/>
If a campaign matches <b>all</b> your conditions then it will be shown in the comparison feed.
</p>
<p>You can still use filters for the feeds that offer one while using feed conditions.</p>
<b>Examples</b>
<ul class="as-conditions-ul">
<li>Loan feed showing loans available at 18 years old offering at least 50.000 DKK.</li>
<li>Mobile subscription feed showing subscriptions that includes roaming and at least 10 GB of data.</li>
<li>Quick loan feed showing loans offering 1.000 DKK without requiring a work income.</li>
</ul>
<h2 class="as-inline">Conditions</h2>
<a class="as-button-light" id="as-create-condition" onclick="createCondition(); return false;">
<span>
<li class="fa fa-plus-square" style="margin-right: 5px;"></li>
Create condition
</span>
</a>
<table id="as-conditions-table">
</table>
<p id="as-conditions-error" class="hidden">
Couldn't load feed field data. Try to reset conditions or refresh the page.
</p>
<!--
The template used to generate the conditions table.
The table will either be empty or contain previously saved conditions on page load.
It should be possible to edit the values right away, so selects should
contain the other available fields/operators.
-->
<script id="conditions-table-template" type="text/x-jsrender">
<tr>
<th class="as-conditions-th" style="width: 32%;">Field</th>
<th class="as-conditions-th" style="width: 32%;">Operator</th>
<th class="as-conditions-th" style="width: 32%;">Value</th>
<th class="as-conditions-th" style="width: 4%;"></th>
</tr>
<!-- The data here is previously saved conditions. -->
{{for conditions ~fields=fields ~operators=operators}}
<tr class="as-condition-row">
<td class="as-conditions-td">
<select name="condition-field" onchange="changeConditionField(this);">
{{for ~fields ~conditionName=name}}
<option value="{{:name}}" data-type="{{:fieldType}}"
data-values='{{:potentialValues}}'
{{if ~conditionName == name}}selected="selected"{{/if}}
>{{:name}}</option>
{{/for}}
</select>
</td>
<td class="as-conditions-td as-condition-operator">
<select name="condition-operator">
{{for ~operators ~conditionOperator=operator ~type=fieldType}}
{{if ~type == 'ENUM' || ~type == 'BOOLEAN'}}
{{if operator == 'equals' || operator == 'notEquals'}}
<option value="{{:operator}}"
{{if ~conditionOperator == operator}}selected="selected"{{/if}}
>{{:name}}</option>
{{/if}}
{{else ~type == 'NUMBER'}}
{{if operator != 'contains' && operator != 'notContains'}}
<option value="{{:operator}}"
{{if ~conditionOperator == operator}}selected="selected"{{/if}}
>{{:name}}</option>
{{/if}}
{{else}}
<option value="{{:operator}}"
{{if ~conditionOperator == operator}}selected="selected"{{/if}}
>{{:name}}</option>
{{/if}}
{{/for}}
</select>
</td>
<td class="as-conditions-td as-condition-value">
{{if fieldType == 'ENUM'}}
<select name="condition-value">
{{for potentialValues ~conditionValue=value}}
<option value="{{:#data}}"
{{if ~conditionValue == #data}}selected="selected"{{/if}}
>{{:#data}}</option>
{{/for}}
</select>
{{else fieldType == 'NUMBER'}}
<input name="condition-value" type="text" value="{{:value}}"
title="Please enter numbers like this: 1000, 75.50, 4.2"/>
{{else fieldType == 'BOOLEAN'}}
<select name="condition-value">
<option value="0" {{if value == 0}}selected="selected"{{/if}}>
No
</option>
<option value="1" {{if value == 1}}selected="selected"{{/if}}>
Yes
</option>
</select>
{{else}}
<input name="condition-value" type="text" value="{{:value}}"/>
{{/if}}
</td>
<td class="as-conditions-td">
<a class="as-delete-condition" title="Delete condition"
onclick="deleteCondition(this);">
<i class="fa fa-lg fa-trash-o"></i>
</a>
</td>
</tr>
{{/for}}
</script>
<!-- The template used for new conditions that are added to the table. -->
<script id="condition-template" type="text/x-jsrender">
<tr class="as-condition-row">
<td class="as-conditions-td">
<select name="condition-field" onchange="changeConditionField(this);">
<option value="0"> -- Choose field -- </option>
{{for fields}}
<option value="{{:name}}" data-type="{{:fieldType}}"
data-values='{{:potentialValues}}'>{{:name}}</option>
{{/for}}
</select>
</td>
<td class="as-conditions-td as-condition-operator"></td>
<td class="as-conditions-td as-condition-value"></td>
<td class="as-conditions-td">
<a class="as-delete-condition" title="Delete condition"
onclick="deleteCondition(this);">
<i class="fa fa-lg fa-trash-o"></i>
</a>
</td>
</tr>
</script>
<div class="bottom-bar">
<a class="button button-secondary button-large"
title="Reset to latest saved configuration"
onclick="resetConditions();">Reset</a>
<a class="button button-primary button-large"
onclick="saveConditions(self.parent); return false;" title="Save conditions">Save</a>
</div>
</div>
</div>
<!-- END - Feed Conditions Modal -->
<?php
else : ?>
<p>You have not connected your account yet - you can do it on the <a href="admin.php?page=comparisonfeed-wp%2Fcompare-admin.php">Adservice Settings page</a>.</p>
<?php endif; // display nothing if user has not connect account
}
add_action( 'save_post', 'compare_metabox_save' );
function compare_metabox_save( $post_id )
{
// Bail if we're doing an auto save
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
// if our nonce isn't there, or we can't verify it, bail
if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'my_meta_box_nonce' ) ) return;
// if our current user can't edit this post, bail
if( !current_user_can( 'edit_post', $post_id ) ) return;
// Make sure your data is set before trying to save it
if( isset( $_POST['publisherID'] ) )
update_post_meta( $post_id, 'publisherID', wp_kses( $_POST['publisherID'], wp_kses_allowed_html( 'post' )) );
if( isset( $_POST['initial-rows'] ) )
update_post_meta( $post_id, 'initial-rows', wp_kses( $_POST['initial-rows'], wp_kses_allowed_html( 'post' )) );
if( isset( $_POST['max-rows'] ) )
update_post_meta( $post_id, 'max-rows', wp_kses( $_POST['max-rows'], wp_kses_allowed_html( 'post' )) );
if( isset( $_POST['min-rating'] ) )
update_post_meta( $post_id, 'min-rating', wp_kses( $_POST['min-rating'], wp_kses_allowed_html( 'post' )) );
if( isset( $_POST['conditions'] ) )
update_post_meta( $post_id, 'conditions', wp_kses( $_POST['conditions'], wp_kses_allowed_html( 'post' )) );
if( isset( $_POST['custom-rating'] ) )
update_post_meta( $post_id, 'custom-rating', wp_kses( $_POST['custom-rating'], wp_kses_allowed_html( 'post' )) );
if( isset( $_POST['custom-order'] ) )
update_post_meta( $post_id, 'custom-order', wp_kses( $_POST['custom-order'], wp_kses_allowed_html( 'post' )) );
if( isset( $_POST['removed-items'] ) )
update_post_meta( $post_id, 'removed-items', wp_kses( $_POST['removed-items'], wp_kses_allowed_html( 'post' )) );
if( isset( $_POST['compare-template'] ) )
update_post_meta( $post_id, 'compare-template', esc_attr( $_POST['compare-template'] ) );
if( isset( $_POST['compare-account'] ) )
update_post_meta( $post_id, 'compare-account', esc_attr( $_POST['compare-account'] ) );
if( isset( $_POST['button-color'] ) )
update_post_meta( $post_id, 'button-color', esc_attr( $_POST['button-color'] ) );
if( isset( $_POST['button-hover-color'] ) )
update_post_meta( $post_id, 'button-hover-color', esc_attr( $_POST['button-hover-color'] ) );
if( isset( $_POST['font-url'] ) )
update_post_meta( $post_id, 'font-url', esc_attr( $_POST['font-url'] ) );
if( isset( $_POST['font-name'] ) )
update_post_meta( $post_id, 'font-name', esc_attr( $_POST['font-name'] ) );
if( isset($_POST['subID']) )
update_post_meta( $post_id, 'subID', esc_attr( $_POST['subID'] ) );
if( isset($_POST['mediaID']) )
update_post_meta( $post_id, 'mediaID', esc_attr( $_POST['mediaID'] ) );
if( isset($_POST['feed-id']) )
update_post_meta( $post_id, 'feed-id', esc_attr( $_POST['feed-id'] ) );
$useIframeVal = (isset( $_POST['use-iframe'] )) ? 1 : 0;
update_post_meta( $post_id, 'use-iframe', wp_kses( $useIframeVal, wp_kses_allowed_html( 'post' )) );
$showFilterVal = (isset( $_POST['show-filter'] )) ? 1 : 0;
update_post_meta( $post_id, 'show-filter', wp_kses( $showFilterVal, wp_kses_allowed_html( 'post' )) );
$includeNewCampaignsVal = (isset( $_POST['include-new-campaigns'] )) ? 'true' : 'false';
update_post_meta( $post_id, 'include-new-campaigns', wp_kses( $includeNewCampaignsVal,
wp_kses_allowed_html( 'post' )) );
$lazyLoadingVal = (isset( $_POST['lazy-loading'] )) ? 'true' : 'false';
update_post_meta( $post_id, 'lazy-loading', wp_kses( $lazyLoadingVal,
wp_kses_allowed_html( 'post' )) );
}
?>