function EnqueueAdminScript() { ?> <script type="text/javascript"> function OnPageInfoLoaded(id, pac, text) { var id="Feedweb_PostDataLoadingImage_" + id; var img = document.getElementById(id); if (img == null || img == undefined) return; if (text == null || text == "") setTimeout(function () { LoadPageInfo(pac, id) }, 1000); else img.parentElement.innerHTML = text; } function LoadPageInfo(pac, id) { var request = new XMLHttpRequest(); request.onreadystatechange = function () { if (request.readyState == 4 && request.status == 200) OnPageInfoLoaded(id, pac, request.responseText); } var url = "<?php echo plugin_dir_url(__FILE__); ?> page_data.php?pac=" + pac + "&id=" + id; request.open("GET", url, true); request.send(); } function GetFeedwebPopupInfoClass() { return "FeedwebPostTablePopupInfoDiv"; } function HideFeedwebStats() { var popups = document.getElementsByClassName(GetFeedwebPopupInfoClass()); for (var index = 0; index < popups.length; index++) popups[index].style.visibility = "hidden"; } function ShowFeedwebStats(id) { var image_class = '<?php echo GetStatusImageClass(); ?> '; var image = document.getElementById(image_class + "_" + id); var answers = image.parentElement.getElementsByClassName("FeedwebPostAnswerData"); if (answers.length == 0) return; var container = document.getElementById("wpcontent"); if (container == null || container == undefined) return; var popup_class = GetFeedwebPopupInfoClass(); var popup_id = popup_class + "_" + id; var popup = document.getElementById(popup_id); if (popup == null || popup == undefined) { popup = document.createElement("DIV"); popup.setAttribute("style", "position: absolute; top: 0; left: 0; display: block; visibility: hidden; background-color: #969696; color: white; border: 2px solid #c0c0c0;"); popup.setAttribute("class", popup_class); popup.setAttribute("id", popup_id); var base = '<?php echo GetFeedwebUrl(); ?> ' + 'IMG/Plugin/'; var html = "<style>"+ " ." + popup_class + " table {margin: 4px 0px 4px 0px;}" + " ." + popup_class + " td {font-size: 8pt; text-align: center; padding: 0 8px 0 8px; min-width: 24px;}" + " ." + popup_class + " img {border: 1px solid white; margin-top: 4px;}" + " </style>"; html += "<table>"; html += "<tr><td style='text-align: left;'><img src='" + base + "Question.png'/></td>" + "<td><img src='" + base + "Yes.png'/></td>" + "<td><img src='" + base + "No.png'/></td></tr>"; for (var index = 0; index < answers.length; index++) { html += "<tr>"; var data = answers[index].value.split("|"); for (var pos = 0; pos < data.length; pos++) { html += "<td"; if(pos == 0) html += " style='text-align: left;'"; html += ">" + data[pos] + "</td>"; } html += "</tr>"; } html += "</table>"; popup.innerHTML = html; container.appendChild(popup); } setTimeout(function () { DisplayFeedwebStats(id) }, 100); } function DisplayFeedwebStats(id) { var container = document.getElementById("wpcontent"); var container_rect = container.getBoundingClientRect(); var image_class = '<?php echo GetStatusImageClass(); ?> '; var image = document.getElementById(image_class + "_" + id); var image_rect = image.getBoundingClientRect(); var popup_class = GetFeedwebPopupInfoClass(); var popup = document.getElementById(popup_class + "_" + id); popup.style.visibility = "visible"; popup.style.left = (image_rect.left - popup.clientWidth - 8).toString() + "px"; popup.style.top = (image_rect.top - container_rect.top - popup.clientHeight / 2 + 16).toString() + "px"; } </script> <?php $result = QueryPostStatus(); if ($result == null) { return; } $id = $result->post_id; switch ($result->meta_value) { case '0': // New Post $function = "DisplayInsertWidgetPrompt();"; $title = __("Insert Rating Widget", "FWTD"); $prompt = __("Do you wish to insert a Feedweb rating widget into your new post?", "FWTD"); $url = plugin_dir_url(__FILE__) . "widget_dialog.php?wp_post_id={$id}&mode=add&KeepThis=true&TB_iframe=true"; break; case '2': // Edited Post $pac = GetPac($id); $post = get_post($id); $data = GetPageData($pac, true); $server_url = $data["url"]; $server_title = $data["title"]; $local_url = get_permalink($id); $local_title = ConvertHtml($post->post_title); if ($server_url == $local_url && $server_title == $local_title) { return; } $prompt = __("The Title or Permalink of the post has been changed. Do you with to update the Rating Widget with new data?", "FWTD"); $action = "window.location.href='" . plugin_dir_url(__FILE__) . "widget_commit.php?wp_post_id={$id}&feedweb_cmd=NPW';"; $function = "DisplayUpdateWidgetPrompt();"; break; default: return; } ?> <script type="text/javascript"> var readyStateCheckInterval = setInterval( function() { if (document.readyState === "complete") { <?php echo $function; ?> clearInterval(readyStateCheckInterval); } }, 1000); function DisplayUpdateWidgetPrompt() { if (window.confirm('<?php echo $prompt; ?> ') == true) { <?php echo $action; ?> } } function DisplayInsertWidgetPrompt() { if (window.confirm('<?php echo $prompt; ?> ') == true) { tb_show('<?php echo $title; ?> ', '<?php echo $url; ?> '); var tb = document.getElementById("TB_window"); if (tb != null) { var frames = tb.getElementsByTagName("iframe"); frames[0].style.height = "400px"; frames[0].style.width = "700px"; tb.style.height = "400px"; tb.style.width = "700px"; } } } </script> <?php }
function UpdateWidgetTitleAndUrl($id) { global $alert; $pac = GetPac($id); $bac = GetBac(true); if ($pac == null || $bac == null) { $alert = __("Wordpress cannot modify your widget", "FWTD"); return; } $url = PrepareParam(get_permalink($id)); if ($url == "") { $alert = __("Error in the Post data", "FWTD"); return; } $post = get_post($id); $title = PrepareParam(ConvertHtml($post->post_title)); if ($title == "") { $alert = __("Error in the Post data", "FWTD"); return; } try { $params = array(); $params['page'] = $url; $params['title'] = $title; $query = GetFeedwebUrl() . "FBanner.aspx?action=npw&pac={$pac}&bac={$bac}"; $response = wp_remote_post($query, array('method' => 'POST', 'timeout' => 300, 'body' => $params)); if (is_wp_error($response)) { $alert = __("Cannot connect Feedweb server", "FWTD"); return; } $dom = new DOMDocument(); if ($dom->loadXML($response['body']) == true) { $el = $dom->documentElement; if ($el->tagName == "BANNER") { $alert = $el->getAttribute("error"); if ($alert == "") { $alert = __("The widget Title/Url have been updated", "FWTD"); } return; } } $alert = __("Feedweb service cannot update the widget", "FWTD"); } catch (Exception $e) { $alert = $e->getMessage(); } }
function GetRemoveWidgetPrompt() { $id = GetPostId(); $post = get_post($id); $format = __("The rating widget in the post '%s' will be removed", "FWTD"); printf($format, ConvertHtml($post->post_title)); }