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 DisplayWidgetIcon() { $id = $_GET["id"]; $pac = $_GET["pac"]; $data = GetPageData($pac, false); if ($data == null) { return; } if ($data['error'] != null && $data['error'] != "") { SetSortValue($id, -3); $src = GetFeedwebUrl() . "IMG/Remove.png"; if ($data['error'] == "Bad PAC") { $title = __("The widget data is invalid and cannot be used.", "FWTD"); echo "<script>function OnInvalidPAC() { if (window.confirm ('" . __("Remove Invalid Widget?", "FWTD") . "') == true) " . "window.location.href='" . plugin_dir_url(__FILE__) . "/widget_commit.php?feedweb_cmd=REM&wp_post_id=" . $id . "'; } " . "</script><a href='#' onclick='OnInvalidPAC()'><img title='{$title}' src='{$src}' style='padding-left: 4px;'/></a>"; return; } $title = __("Unknown error.", "FWTD") . __("\nPlease contact Feedweb (contact@feedweb.net)", "FWTD"); echo "<img title='{$title}' src='{$src}' style='padding-left: 4px;'/>"; return; } $src = GetFeedwebUrl() . "IMG/Edit.png"; $votes = $data['votes']; $score = $data['score']; if ($score != "") { SetSortValue($id, intval($votes)); $format = __("Edit / Remove Rating Widget\n(%s Votes. Average Score: %s)", "FWTD"); $title = sprintf($format, $votes, $score); if ($data['image'] != "") { $src = GetFileUrl($data['image']); } } else { SetSortValue($id, 0); $title = __("Edit / Remove Rating Widget\n(No votes yet)", "FWTD"); } $width = 675; $height = 360; $url = plugin_dir_url(__FILE__) . "widget_dialog.php?wp_post_id=" . $id . "&mode=edit&KeepThis=true&TB_iframe=true&height={$height}&width={$width}"; $div_class = GetStatusImageClass(); $image_id = $div_class . "_" . $id; echo "<div class='{$div_class}' style='display: inline;' onmouseover='ShowFeedwebStats({$id})' onmouseout='HideFeedwebStats()'>"; $answers = $data['answers']; if ($answers != null) { for ($index = 0; $index < count($answers); $index++) { $text = str_replace("'", "’", $answers[$index]); echo "<input type='hidden' class='FeedwebPostAnswerData' value='{$text}'/>"; } } echo "<input alt='{$url}' class='thickbox' id='{$image_id}' title='{$title}' type='image' src='{$src}'/></div>"; }
function RecLinkWordMatch($rec_word, $rec_idx) { global $NumSearchWords, $queryForSearch, $queryForURL, $query, $num_rec_words; global $SearchWords, $UseWildCards, $SearchAsSubstring, $ToLowerSearchWords; global $OutputBuffers, $OUTPUT_RECOMMENDED; global $PAGEDATA_URL, $PAGEDATA_TITLE, $PAGEDATA_DESC, $PAGEDATA_IMG, $UseZoomImage; global $zoom_target, $GotoHighlight, $PdfHighlight; global $num_recs_found; global $STR_RECOMMENDED; $bRecLinkFound = false; for ($sw = 0; $sw <= $NumSearchWords; $sw++) { // if finished with last search word, check the full search query $result = 1; if ($sw == $NumSearchWords) { $result = wordcasecmp($queryForSearch, $rec_word); } else { if (strlen($SearchWords[$sw]) > 0) { if ($UseWildCards[$sw] == 1) { $pattern = "/"; // match entire word if ($SearchAsSubstring == 0) { $pattern = $pattern . "\\A"; } $pattern = $pattern . $RegExpSearchWords[$sw]; if ($SearchAsSubstring == 0) { $pattern = $pattern . "\\Z"; } if ($ToLowerSearchWords != 0) { $pattern = $pattern . "/i"; } else { $pattern = $pattern . "/"; } $result = !preg_match($pattern, $rec_word); } else { if ($SearchAsSubstring == 0) { $result = wordcasecmp($SearchWords[$sw], $rec_word); } else { if (mystristr($rec_word, $SearchWords[$sw]) == FALSE) { $result = 1; } else { $result = 0; } // matched } } if ($result != 0) { // if not matched, we check if the word is a wildcard if (strpos($rec_word, "*") !== false || strpos($rec_word, "?") !== false) { $RecWordRegExp = "/\\A" . pattern2regexp($rec_word) . "\\Z/i"; $result = !preg_match($RecWordRegExp, $SearchWords[$sw]); } } } } if ($result == 0) { $bRecLinkFound = true; if ($num_recs_found == 0) { $OutputBuffers[$OUTPUT_RECOMMENDED] .= "<div class=\"recommended\">\n"; $OutputBuffers[$OUTPUT_RECOMMENDED] .= "<div class=\"recommended_heading\">{$STR_RECOMMENDED}</div>\n"; } $pgdata = GetPageData($rec_idx); $url = $pgdata[$PAGEDATA_URL]; $title = $pgdata[$PAGEDATA_TITLE]; $description = $pgdata[$PAGEDATA_DESC]; if ($UseZoomImage) { $image = $pgdata[$PAGEDATA_IMG]; } $urlLink = $url; //$urlLink = rtrim($urls[$rec_idx]); if ($GotoHighlight == 1) { if ($SearchAsSubstring == 1) { $urlLink = RecLinkAddParamToURL($urlLink, "zoom_highlightsub=" . $queryForURL); } else { $urlLink = RecLinkAddParamToURL($urlLink, "zoom_highlight=" . $queryForURL); } } if ($PdfHighlight == 1) { if (stristr($urlLink, ".pdf") != FALSE) { $urlLink = $urlLink . "#search=%22" . str_replace("\"", "", $query) . "%22"; } } $OutputBuffers[$OUTPUT_RECOMMENDED] .= "<div class=\"recommend_block\">\n"; if ($UseZoomImage) { if (strlen($image) > 0) { $OutputBuffers[$OUTPUT_RECOMMENDED] .= "<div class=\"recommend_image\">"; $OutputBuffers[$OUTPUT_RECOMMENDED] .= "<a href=\"" . $urlLink . "\"" . $zoom_target . "><img src=\"{$image}\" alt=\"\" class=\"recommend_image\"></a>"; $OutputBuffers[$OUTPUT_RECOMMENDED] .= "</div>"; } } $OutputBuffers[$OUTPUT_RECOMMENDED] .= "<div class=\"recommend_title\">"; $OutputBuffers[$OUTPUT_RECOMMENDED] .= "<a href=\"" . $urlLink . "\"" . $zoom_target . ">"; if (strlen($title) > 1) { $OutputBuffers[$OUTPUT_RECOMMENDED] .= PrintHighlightDescription($title); } else { $OutputBuffers[$OUTPUT_RECOMMENDED] .= PrintHighlightDescription($pgdata[$PAGEDATA_URL]); } $OutputBuffers[$OUTPUT_RECOMMENDED] .= "</a></div>\n"; $OutputBuffers[$OUTPUT_RECOMMENDED] .= "<div class=\"recommend_description\">"; $OutputBuffers[$OUTPUT_RECOMMENDED] .= PrintHighlightDescription($description); $OutputBuffers[$OUTPUT_RECOMMENDED] .= "</div>\n"; $OutputBuffers[$OUTPUT_RECOMMENDED] .= "<div class=\"recommend_infoline\">{$url}</div>\n"; $OutputBuffers[$OUTPUT_RECOMMENDED] .= "</div>"; $num_recs_found++; break; } } return $bRecLinkFound; }
function GetEditPageData() { global $edit_page_data; if ($edit_page_data == null) { $id = GetPostId(); $pac = GetPac($id); $edit_page_data = GetPageData($pac, true); } return $edit_page_data; }