root/afridex/plugins/rb-internal-links/tmce_plugin.php

Revision 21, 7.1 kB (checked in by admin, 18 years ago)
Line 
1<?php 
2
3include("../../../wp-config.php");
4$linktext = isset($_REQUEST['linktext'])? str_replace('\"', '\'', $_REQUEST['linktext']) : ''; // get preselected html and remove "'s
5
6$action = $_REQUEST['action'];
7switch($action){
8        case 'get_pages':
9                $returnDiv = $_REQUEST['returnDiv'];
10                $category = $_REQUEST['category'];
11                if($category == 'pages')
12                        $articles = get_pages('numberposts=0&orderby='.get_option('rbinternal_page_orderby').'&order='.get_option('rbinternal_page_sort'));
13                else 
14                        $articles = get_posts('numberposts=0&category='.$category.'&orderby='.get_option('rbinternal_post_orderby').'&order='.get_option('rbinternal_post_sort'));
15                $posts = '<ul>';
16                foreach($articles AS $article)
17                        $posts .= '<li id="article_'.$article->ID.'"><span class="date">'.substr($article->post_date, 0, 10).'</span><a href="javascript:;" onclick="properties(\''.( get_option('rbinternal_return_param' == 'slug')? $article->post_name : $article->ID ).'\', \'post\');">'.$article->post_title.'</a></li>';
18                if(empty($articles)) $posts .= '<li>No posts found.</li>';
19                $posts .= '</ul>';
20                die("document.getElementById('".$returnDiv."').innerHTML = \"".addslashes(str_replace("\n", '', $posts))."\"");
21
22}
23
24?>
25
26<html xmlns="http://www.w3.org/1999/xhtml">
27<head>
28        <title>RB Internal Linker</title>
29        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
30        <script language="javascript" type="text/javascript">
31        var rbinternal_url = "<?php echo $rbinternal_url; ?>";
32        </script>
33        <script language="javascript" type="text/javascript" src="../../../wp-includes/js/tinymce/tiny_mce_popup.js"></script>
34  <?php wp_print_scripts( array( 'sack' )); ?>
35        <script language="javascript" type="text/javascript">
36        var the_postId = 0;
37       
38        function showcategories(){
39          document.getElementById('categoriesContainer').style.display='block';
40                document.getElementById('pagesContainer').style.display='none';
41                document.getElementById('propertiesContainer').style.display='none';
42                document.getElementById('pages').innerHTML='';
43                document.getElementById('linkText').value = '<?php echo addslashes($linktext); ?>';
44                document.getElementById('linkClass').value = '';
45                document.getElementById('linkTarget').value = '';
46        }
47       
48       
49        function getposts(category){
50        var mysack = new sack( "tmce_plugin.php" );
51        mysack.execute = 1;
52        mysack.method = 'POST';
53        mysack.setVar("action", "get_pages");
54                mysack.setVar("returnDiv", "pages");
55                mysack.setVar("category", category);
56        mysack.onError = function() { alert('AJAX error in voting' )};
57    mysack.runAJAX();
58 
59                document.getElementById('pages').innerHTML = 'Loading posts...';
60        document.getElementById('categoriesContainer').style.display='none';
61                document.getElementById('pagesContainer').style.display='block';
62 
63        return true;
64 
65  }
66       
67        function properties(postId, linkType){
68                the_postId = postId;
69                the_linkType = linkType;
70                document.getElementById('categoriesContainer').style.display='none';
71                document.getElementById('pagesContainer').style.display='none';
72                document.getElementById('propertiesContainer').style.display='block';
73        }
74       
75        function insertLink(){
76       
77        if(the_postId == 0){ showcategories(); return false; }
78       
79        the_text = document.getElementById('linkText').value;
80        the_class = document.getElementById('linkClass').value;
81        the_target = document.getElementById('linkTarget').value;
82        the_anchor = document.getElementById('linkAnchor').value;
83       
84        rCode = '<span class="rbIntLinkText">' + the_text + '<!--pintlink id="' + the_postId + '" type="' + the_linkType + '" text="' + the_text + '"';
85        if(the_class != '') rCode += ' class="' + the_class + '"';
86        if(the_target != '') rCode += ' target="' + the_target + '"';
87        if(the_anchor != '') rCode += ' anchor="' + the_anchor + '"';
88        rCode += '-->';
89       
90        tinyMCEPopup.execCommand("mceInsertContent", false, rCode);
91        tinyMCEPopup.close();
92
93        }
94       
95        </script>
96       
97        <style>
98        body{font-family: arial, verdana, tahoma, sans-serif; font-size: 12px;}
99        #container{ scroll: auto; overflow: auto; width: 100%; height: 100%; }
100        h2{font-size: 14px; font-weight: bold; margin-bottom: 8px;}
101        a{text-decoration: none;}
102        a:hover{text-decoration: underline;}
103        ul{list-style-type: none; margin: 0; padding: 0;}
104        li{position: relative; float: left; clear: left; padding: 2px;}
105        ul.children{position: relative; float: left; clear: left; margin-left: 10px;}
106        .options{position: relative; float: left; clear: left; margin-left: 10px; color: #999999; }
107        .options a:link{color: #999999; }
108        .date{background-color: #E5F3FF; margin-right: 2px; padding: 1px;}
109        .row{position: relative; float: left; clear: left; margin-bottom: 5px;}
110        .action{position: relative; float: left; clear: left; padding: 2px; background-color: #E5F3FF; width: 330px; text-align: right;}
111        .textinput{ width: 250px; }
112        .textinputsmall{ width: 150px; }
113        label{position: relative; float: left; clear: left; margin: 0 5px 5px 0; width: 80px; padding-top: 2px;}
114        .back{position: relative; float: left; clear: left; margin-top: 10px;}
115        </style>       
116       
117</head>
118<body>
119
120<div id="container">
121
122<div id="categoriesContainer">
123
124  <h2>Categories</h2>
125  <ul>
126  <?php
127  $categories = get_categories(array('type' => 'post', 'orderby' => 'name', 'hide_empty' => true));
128  rbinternal_tier_categories($categories, 0);
129 
130  function rbinternal_tier_categories($data, $parent){
131        foreach($data AS $cat){
132                if($cat->category_parent == $parent){
133                        echo '<li id="category_'.$cat->cat_ID.'"><a href="javascript:;" onclick="getposts('.$cat->cat_ID.');">'.$cat->cat_name.'</a>';
134                        echo '<span class="options"><a href="javascript:;" onclick="getposts('.$cat->cat_ID.');">browse</a> | <a href="javascript:;" onclick="properties('.$cat->cat_ID.', \'category\');">link to</a></span>';
135                        echo '<ul class="children">';
136                        echo rbinternal_tier_categories($data, $cat->cat_ID);
137                        echo '</ul></li>';
138                }
139        }       
140  }
141 
142  ?>
143        <li id="category_pages"><a href="javascript:;" onclick="getposts('pages');">Pages</a>
144  </ul>
145
146</div>
147
148<div id="pagesContainer" style="display: none;">
149  <h2>Pages</h2>
150  <div id="pages"></div>
151  <a href="javascript:;" onclick="showcategories();" class="back">Back to categories</a>
152</div>
153
154<div id="propertiesContainer" style="display: none;">
155        <h2>Properties</h2>
156        <div class="row">
157                <label>Link Text:</label><input type="text" class="textinput" id="linkText" value="<?php echo $linktext; ?>" />
158        </div>
159        <div class="row">
160                <label>Link Class:</label><input type="text" class="textinputsmall" id="linkClass" value="" />
161        </div>
162        <div class="row">
163        <label>Link Target:</label>
164                <select class="textinput" id="linkTarget" value="">
165                        <option value=""></option>
166                        <option value="_blank">_blank</option>
167                        <option value="_parent">_parent</option>
168                        <option value="_self">_self</option>
169                        <option value="_top">_top</option>
170                </select>
171        </div>
172        <div class="row">
173                <label>Link anchor:</label>#<input type="text" class="textinputsmall" id="linkAnchor" value="" />
174        </div>
175        <div class="action"><input type="button" value="Insert Link" onclick="insertLink();" /></div>
176        <a href="javascript:;" onclick="showcategories();" class="back">Back to categories</a>
177</div>
178
179</div>
180
181</body>
182</html>
Note: See TracBrowser for help on using the browser.