Example #1
1
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 
}
Example #2
0
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>";
}