Changeset 38374
- Timestamp:
- 04/04/08 22:43:14 (3 months ago)
- Files:
-
- ad-minister/trunk/ad-minister-content.php (modified) (1 diff)
- ad-minister/trunk/ad-minister-create.php (modified) (5 diffs)
- ad-minister/trunk/ad-minister-functions.php (modified) (19 diffs)
- ad-minister/trunk/ad-minister-help.php (modified) (1 diff)
- ad-minister/trunk/ad-minister-positions.php (modified) (9 diffs)
- ad-minister/trunk/ad-minister-settings.php (modified) (5 diffs)
- ad-minister/trunk/ad-minister.css (modified) (6 diffs)
- ad-minister/trunk/ad-minister.php (modified) (3 diffs)
- ad-minister/trunk/ad-minister.po (modified) (2 diffs)
- ad-minister/trunk/img (deleted)
- ad-minister/trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
ad-minister/trunk/ad-minister-content.php
r29890 r38374 1 <!-- form method="post" action="options.php" name="post" -->2 1 3 <h3 style="font-size: 20px;"><?php _e('Content', 'ad-minister'); ?></h3> 4 5 <p><?php _e('Click Show/Hide to see the content.', 'ad-minister'); ?></p> 2 <p><?php _e('Here the content in Ad-minister is listed. Green rows indicate that the content is visible, and red that it is not. Click on the headers to sort the table according to the values of that column. To reverse the order click the arrow. To edit content click on the title.', 'ad-minister'); ?></p> 6 3 7 4 <div id="ads"> 8 <?php 9 10 // The cshow variable will open a particular bit of content 11 $cshow = $_GET['cshow']; 12 13 $contents = get_post_meta(get_option('administer_post_id'), 'administer_content', true); 14 $positions = get_post_meta(get_option('administer_post_id'), 'administer_positions', true); 15 16 17 echo '<pre>'; 18 // print_r($contents); 19 echo '</pre>'; 20 21 // Identify orphans 22 foreach ($contents as $ad) 23 if (!array_key_exists($ad['position'], $positions)) $contents[$ad['id']]['position'] = '-'; 24 25 // Save the changes 26 update_post_meta(get_option('administer_post_id'), 'administer_content', $contents); 27 28 // Group the content according to position & sort 29 $content = array(); 30 foreach($contents as $ad) { 31 $content[$ad['position']][$ad['id']] = $ad; 32 } 33 ksort($content); 34 35 // Create the JavaScript for toggling all of them 36 $js_toggle_all = ''; 37 38 $keys = array_keys($content); 39 for ($i = 0 ; $i < count($content); $i++) 40 if (!empty($content[$keys[$i]])) 41 $js_toggle_all .= "\$('pos_" . $i . "').toggle(); "; 42 43 ?> 44 45 <div class="ad_position_holder_title"> 46 <strong class="ad_position_key"><?php _e('Position', 'ad-minister'); ?> <span class="ad_position_count">(<?php _e('nbr', 'ad-minister'); ?>)</span></strong> 47 <div class="ad_position_toggle"> 48 <a href='#' onclick="<?php echo $js_toggle_all; ?>; return false;"><?php _e('Show/Hide All', 'ad-minister'); ?></a> 49 </div><strong class="ad_position_desc"><?php _e('Description', 'ad-minister'); ?></strong> 50 </div> 51 52 <?php 53 54 for ($i=0; $i<count($content); $i++) { 55 56 57 $desc = $positions[$keys[$i]]['description']; 58 if ($keys[$i] == '-') $desc = __('Orphaned content', 'ad-minister'); 59 if (!$desc) $desc = ' '; 60 $index = 0; 61 $position_key = ($keys[$i]) ? $keys[$i] : '-'; 62 $position = $content[$keys[$i]]; 63 // Due to how css works w. JS we can't put the visibilty with the css class. 64 $display_pos = ($_GET['cshow'] == $position_key) ? '' : 'style="display: none;"'; 65 // p2m_position_template($i, $i); 66 if (!empty($content[$keys[$i]])) { 67 ?> 68 69 <div class="ad_position_holder"> 70 <strong class="ad_position_key" ><?php echo $position_key; ?> <span class="ad_position_count">(<?php echo count($position); ?>)</span></strong> 71 <div class="ad_position_toggle"> 72 <a href='#' onclick="$('pos_<?php echo $i; ?>').toggle(); return false;"><?php _e('Show/Hide', 'ad-minister'); ?></a> 73 </div> 74 <strong class="ad_position_desc"> <?php echo $desc; ?></strong> 75 </div> 76 77 <div class="ad_holder" <?php echo $display_pos; ?> id="pos_<?php echo $i; ?>"> 78 79 <?php 80 foreach($position as $ad) { 81 administer_content_template($ad, $index++); 82 } 83 echo '</div>'; 84 } 85 } 86 ?> 87 </div><!-- END ADS --> 88 5 <?php administer_stats(); ?> 6 </div> ad-minister/trunk/ad-minister-create.php
r29890 r38374 1 1 <?php 2 2 3 global $wpdb; 3 print_r($post); 4 5 if ($_GET['resetimpressions'] == 'true') { 6 $idt = $_GET['id']; 7 $stats = get_post_meta(get_option('administer_post_id'), 'administer_stats', true); 8 unset($stats[$idt]['i']); 9 update_post_meta(get_option('administer_post_id'), 'administer_stats', $stats); 10 11 } 12 if ($_GET['resetclicks'] == 'true') { 13 $idt = $_GET['id']; 14 $stats = get_post_meta(get_option('administer_post_id'), 'administer_stats', true); 15 unset($stats[$idt]['c']); 16 update_post_meta(get_option('administer_post_id'), 'administer_stats', $stats); 17 } 4 18 5 19 // Check to see that we have everything we need 6 if ($code = $_POST['content']) { 20 if ($_POST['action'] == 'edit') { 21 if (!($code = $_POST['content'])) $all_ok = false; 7 22 if (!($position = $_POST['position'])) $all_ok = false; 8 23 else if (!($title = $_POST['title'])) $all_ok = false; 9 24 else $all_ok = true; 10 25 11 12 26 if ($all_ok) { 13 $id = administer_nbr_to_save(); //$_POST['nbr_to_save'];27 $id = ($_POST['id'] == '') ? administer_nbr_to_save() : $_POST['id']; 14 28 15 29 $content = get_post_meta(get_option('administer_post_id'), 'administer_content', true); … … 25 39 // Optional parameters 26 40 $content[$id]['scheduele'] = $_POST['scheduele']; 41 $content[$id]['impressions'] = $_POST['impressions']; 42 $content[$id]['clicks'] = $_POST['clicks']; 27 43 $content[$id]['show'] = ($_POST['show'] == 'on') ? 'true' : 'false'; 28 44 $content[$id]['weight'] = $_POST['weight']; … … 35 51 echo '<div id="message" class="updated fade"><p><strong>' . __('Saved!', 'ad-minister') . '</strong></p></div>'; 36 52 53 $value = $content[$id]; 54 37 55 } 56 } else if ($_POST['action'] == 'delete') { 57 $id = $_POST['id']; 58 $content = get_post_meta(get_option('administer_post_id'), 'administer_content', true); 59 $stats = get_post_meta(get_option('administer_post_id'), 'administer_stats', true); 60 if (is_array($stats)) { 61 unset($stats[$id]); 62 update_post_meta(get_option('administer_post_id'), 'administer_stats', $stats); 63 } 64 // Remove the evidence 65 unset($content[$id]); 66 67 // Save back down 68 update_post_meta(get_option('administer_post_id'), 'administer_content', $content); 69 70 // Notify 71 echo '<div id="message" class="updated fade"><p><strong>' . __('Deleted!', 'ad-minister') . '</strong></p></div>'; 38 72 } 39 73 … … 42 76 echo '<div id="message" class="updated fade"><p><strong>' . __('There is no content! Do make some.', 'ad-minister') . '</strong></p></div>'; 43 77 78 79 // Are we editing? 80 if ($_GET['action'] == 'edit') { 81 if (!$value) $value = $content[$_GET['id']]; 82 } 83 else $value = array(); 84 $checked_visible = ($value['visible'] == 'true' || !$value['visible']) ? 'checked="checked"' : ''; 85 $checked_wrap = ($value['wrap'] == 'true' || !$value['wrap']) ? 'checked="checked"' : ''; 86 87 44 88 ?> 45 89 46 <form method="POST" action="edit.php?page=ad-minister&tab=upload"> 47 <?php // onSubmit="return p2m_save_made_ad();" ?> 48 <h3 class="large">Create content:</h3> 49 50 <div id="class"> 51 <p><?php _e('To create static content, fill in the Title, Position and the html code that constitues the content. You can set the visibility of the ad and the weight. Use the file browser below to upload and add an image/file.', 'ad-minister'); ?></p> 52 </div> 53 54 <table class="create"> 90 <form name="post" method="POST" action="edit.php?page=ad-minister&tab=upload&action=edit" id="post"> 91 <div class="wrap"> 92 <?php 93 if ($_GET['action'] == 'edit') { 94 $stats = get_post_meta(get_option('administer_post_id'), 'administer_stats', true); 95 if (!is_array($stats)) $stats = array(); 96 97 $impressions = ($stats[$value['id']]['i']) ? $stats[$value['id']]['i'] : '0'; 98 $impressions = ($impressions == 1) ? '1 ' . __('impression', 'ad-minister') : $impressions . ' ' . __('impressions', 'ad-minister'); 99 100 $clicks = ($stats[$value['id']]['c']) ? $stats[$value['id']]['c'] : '0'; 101 $clicks = ($clicks == 1) ? '1 ' . __('click', 'ad-minister') : $clicks . ' ' . __('clicks', 'ad-minister'); 102 $url = get_option('siteurl') . '/wp-admin/edit.php?page=ad-minister&tab=upload&action=edit&id=' . $value['id'] . ''; 103 ?> 104 105 <h3>Content info:</h3> 106 <ul> 107 <li><?php echo $impressions; ?> | <a href="<?php echo $url . '&resetimpressions=true'; ?>" onclick="return confirm('<?php _e('Are you sure you want to set the impressions to zero?', 'ad-minister'); ?>')"><?php _e('Reset', 'ad-minister'); ?></a></li> 108 <li><?php echo $clicks; ?> | <a href="<?php echo $url . '&resetclicks=true'; ?>" onclick="return confirm('<?php _e('Are you sure you want to set the clicks to zero?', 'ad-minister'); ?>')"><?php _e('Reset', 'ad-minister'); ?></a></li> 109 <li><?php _e('Tracker url', 'ad-minister'); ?>: <em>%tracker%</em> or <em><?php echo administer_tracker_url($value['id']); ?></em><br>To track clicks, insert tracker url before link url, e.g. %tracker%http://labs.dagensskiva.com/</li> 110 </ul> 111 112 <?php } else { ?> 113 <h3>Create content</h3> 114 115 <p><?php _e('To create static content, fill in the Title, Position and the html code that constitues the content. You can set the visibility of the ad and the weight. Use the file browser below to upload and add an image/file.', 'ad-minister'); ?></p> 116 117 <?php } ?> 118 119 <table class="widefat"> 55 120 <tr class="title"> 56 121 <td class="cleft"> … … 58 123 </td> 59 124 <td> 60 <input class="create" name="title" id='title' type="text" >61 </td> 62 </tr> 63 64 <tr class=" param">125 <input class="create" name="title" id='title' type="text" value="<?php echo administer_f($value['title']); ?>"> 126 </td> 127 </tr> 128 129 <tr class="alternate"> 65 130 <td> 66 131 <label class="create" for="content"><?php _e('Html code', 'ad-minister'); ?>:</label> 67 132 </td> 68 133 <td> 69 <fieldset id="postdiv"> 70 <div id="quicktags"> 71 <script type='text/javascript' src='<?php echo get_option('siteurl') ?>/wp-includes/js/quicktags.js'></script> 72 </div> 73 <div><textarea class='mceEditor' rows='10' cols='40' name='content' id='content'></textarea></div> 74 <script type="text/javascript"> 75 //<!-- 76 edCanvas = document.getElementById('content'); 77 //--> 78 </script> 79 (<?php _e('may include JavaScript, but will not execute in the preview. Add files using the file browser below.'); ?>) 80 </fieldset> 81 </td> 82 </tr> 83 84 <tr class="param"> 85 <td> 86 <label class="create" for="scheduele"><?php _e('Scheduele', 'ad-minister'); ?>: </label> 87 </td> 88 <td> 89 <input class="create" name="scheduele" type="text" id="scheduele" /><br /> 134 <div id="postdiv" class="postarea"> 135 <?php the_editor(stripslashes($value['code'])); ?> 136 </div> 137 </td> 138 </tr> 139 140 <tr class="alternate"> 141 <td> 142 <label class="create" for="scheduele"><?php _e('Scheduele', 'ad-minister'); ?></label> 143 </td> 144 <td> 145 <input class="create" name="scheduele" type="text" id="scheduele" value="<?php echo $value['scheduele']; ?>" /><br /> 90 146 (<?php _e('Optional', 'ad-minister'); ?>, E.g. 2007-12-01:2008-01-01) 91 147 </td> 92 148 </tr> 93 149 94 <tr class="param"> 95 <td> 96 <label class="create" for="weight"><?php _e('Weight', 'ad-minister'); ?>: </label> 97 </td> 98 <td> 99 <input class="create" name="weight" type="text" id="weight" /><br /> 100 (<?php _e('Optional, should be a number', 'ad-minister'); ?>) 101 </td> 102 </tr> 103 104 <tr class="param"> 150 <tr class="alternate"> 105 151 <td> 106 152 <label class="create" for="ad_position_edit_"><?php _e('Position', 'ad-minister'); ?></label> 107 153 </td> 108 154 <td> 109 <?php echo administer_position_select(); ?> 110 </td> 111 </tr> 112 113 <tr class="param"> 155 <?php echo administer_position_select(0, $value['position']); ?> 156 </td> 157 </tr> 158 159 <tr class="alternate"> 160 <td> 161 <label class="create" for="impressions"><?php _e('Impressions', 'ad-minister'); ?>: </label> 162 </td> 163 <td> 164 <input name="impressions" type="text" id="impressions" value="<?php echo $value['impressions']; ?>" /> 165 (<?php _e('Optional', 'ad-minister'); ?>) 166 </td> 167 </tr> 168 169 <tr class="alternate"> 170 <td> 171 <label class="create" for="clicks"><?php _e('Clicks', 'ad-minister'); ?></label> 172 </td> 173 <td> 174 <input name="clicks" type="text" id="clicks" value="<?php echo $value['clicks']; ?>" /> 175 (<?php _e('Optional, see documentation on how to make this work.', 'ad-minister'); ?>) 176 </td> 177 </tr> 178 179 <tr class="alternate"> 180 <td> 181 <label class="create" for="weight"><?php _e('Weight', 'ad-minister'); ?></label> 182 </td> 183 <td> 184 <input name="weight" type="text" id="weight" value="<?php echo $value['weight']; ?>" /> 185 (<?php _e('Optional', 'ad-minister'); ?>) 186 </td> 187 </tr> 188 189 <tr class="alternate"> 114 190 <td> 115 191 <label class="create" for="show"><?php _e('Make visible?', 'ad-minister'); ?></label> 116 192 </td> 117 193 <td> 118 <label><input name="show" type="checkbox" id="show" checked="checked"/> (<?php _e('tick for yes', 'ad-minister'); ?>)</label>119 </td> 120 </tr> 121 122 <tr class=" param">194 <label><input name="show" type="checkbox" id="show" <?php echo $checked_visible; ?> /> (<?php _e('tick for yes', 'ad-minister'); ?>)</label> 195 </td> 196 </tr> 197 198 <tr class="alternate"> 123 199 <td> 124 200 <label class="create" for="wrap"><?php _e('Use wrapper?', 'ad-minister'); ?></label> 125 201 </td> 126 202 <td> 127 <label><input name="wrap" type="checkbox" id="wrap" checked="checked" /> (<?php _e('tick for yes', 'ad-minister'); ?>)</label> </td> 128 </tr> 129 <tr> 130 <td></td> 131 <td> 132 <input type="hidden" name="page" value="ad-minister/ad-minister.php"> 133 <input type="button" value="<?php _e('Preview', 'ad-minister'); ?>" onclick="p2m_preview_ad(); return false;"> 134 <input type="submit" value="<?php _e('Save', 'ad-minister'); ?>"> 135 </td> 136 <tr> 203 <label><input name="wrap" type="checkbox" id="wrap" <?php echo $checked_wrap; ?> /> (<?php _e('tick for yes', 'ad-minister'); ?>)</label> 204 </td> 205 </tr> 137 206 </table> 138 139 <?php /* 140 <div class="title2"> 141 <strong class="title2"><?php _e('Title', 'ad-minister'); ?>: </strong> 142 <div class="ad_field2"> 143 <input name="title" class="ad_field" id='ad_title_edit_' type="text" maxlength="30"> 144 </div> 207 <div style="padding: 10px; margin-left: 170px;"> 208 <input type="hidden" name="page" value="ad-minister/ad-minister.php"> 209 <input type="hidden" name="id" value="<?php echo $value['id']; ?>"> 210 <input type="hidden" name="action" value="edit"> 211 <!-- input class="button" type="button" value="<?php _e('Save & preview', 'ad-minister'); ?>" onclick="" --> 212 <input class="button" type="submit" value="<?php _e('Save', 'ad-minister'); ?>"> 213 </form> 214 <?php if ($_GET['action']) : ?> 215 <p> 216 <form method="POST" action="edit.php?page=ad-minister&tab=upload" onsubmit="return confirm('<?php _e('Are you sure you want to delete this content?', 'ad-minister'); ?>');"> 217 <input type="hidden" name="page" value="ad-minister/ad-minister.php"> 218 <input type="hidden" name="action" value="delete"> 219 <input type="hidden" name="id" value="<?php echo $value['id']; ?>"> 220 <input class="button" type="submit" value="<?php _e('Delete this', 'ad-minister'); ?>"> 221 </form> 222 </p> 223 <?php endif; ?> 145 224 </div> 146 225 147 <div id="create"> 148 <strong class="add_option"><?php _e('Html code', 'ad-minister'); ?>:</strong> 149 <div class="ad_field1"> 150 <fieldset id="postdiv"> 151 <div id="quicktags"> 152 <script type='text/javascript' src='<?php echo get_option('siteurl') ?>/wp-includes/js/quicktags.js'></script> 153 </div> 154 <div><textarea class='mceEditor' rows='10' cols='40' name='content' id='content'></textarea></div> 155 <script type="text/javascript"> 156 //<!-- 157 edCanvas = document.getElementById('content'); 158 //--> 159 </script> 160 (<?php _e('may include JavaScript, but will not execute in the preview. Add files using the file browser below.'); ?>) 161 </fieldset> 162 </div> 163 164 <p><strong class="add_option"><label for="ad_scheduele_edit_"><?php _e('Scheduele', 'ad-minister'); ?>: </label></strong><div class="ad_field2"><input name="scheduele" style="width: 99%;" type="text" id="ad_scheduele_edit_" /></div><div class="ad_field2">(<?php _e('Optional', 'ad-minister'); ?>, E.g. 2007-12-01:2008-01-01)</div></p> 165 <p><strong class="add_option"><label for="ad_quota_edit_"><?php _e('Weight', 'ad-minister'); ?>: </label></strong><div class="ad_field2"><input name="weight" class="add_option" type="text" id="ad_quota_edit_" /> (<?php _e('Optional', 'ad-minister'); ?>) </div></p> 166 <p><strong class="add_option"><?php _e('Position', 'ad-minister'); ?>: </strong><div class="ad_field2"><?php echo administer_position_select(); ?></div></p> 167 <p><strong class="add_option"><label for="ad_show_edit_"><?php _e('Make visible?', 'ad-minister'); ?></label></strong> <label><input name="show" type="checkbox" id="ad_show_edit_" checked="checked" /> (<?php _e('tick for yes', 'ad-minister'); ?>)</label></p> 168 <p><strong class="add_option"><label for="ad_wrap_edit_"><?php _e('Use wrapper?', 'ad-minister'); ?></label></strong> <label><input name="wrap" type="checkbox" id="ad_wrap_edit_" checked="checked" /> (<?php _e('tick for yes', 'ad-minister'); ?>)</label></p> 169 170 <div class="add_buttons" id="buttons"> 171 <input type="hidden" name="page" value="ad-minister/ad-minister.php"> 172 <input type="button" value="<?php _e('Preview', 'ad-minister'); ?>" onclick="p2m_preview_ad(); return false;"> 173 <input type="submit" value="<?php _e('Save', 'ad-minister'); ?>"> 174 <!-- input type="button" value="<?php _e('Discard', 'ad-minister'); ?>" onclick="$('content').value = ''; return false;" --> 175 </div> 176 </div> 177 */ 178 ?> 179 180 </form> 181 226 <?php 227 /* 182 228 <h3><?php _e('Preview', 'ad-minister'); ?>:</h3> 183 229 <div id="preview" ></div> 184 230 185 <h3><?php _e('Add/manage files', 'ad-minister'); ?>:</h3> 186 < p><?php _e("Click on the thumbnail of the file to get the option to insert it. Press 'Send to editor' to insert image/file.", 'ad-minister'); ?></p>187 188 <iframe id="uploading" name="uploading" frameborder="0" src="upload.php?style=inline&tab=browse&post_id=<?php echo get_option('administer_post_id'); ?>&_wpnonce=4b899edbfd">This feature requires iframe support.</iframe>231 232 <iframe id="uploading" name="uploading" frameborder="0" src="media-upload.php?post_id=-1206559419&type=image&TB_iframe=true&height=500&width=640" style="height: 500px">This feature requires iframe support.</iframe> 233 */ 234 ?> ad-minister/trunk/ad-minister-functions.php
r31069 r38374 8 8 function administer_main() { 9 9 10 $plugindir = ABSPATH . PLUGINDIR .'/ad-minister/';11 10 // Check that our statistics is set up 11 $stats = get_option(get_option('administer_post_id'), 'administer_stats', true); 12 12 $content = get_post_meta(get_option('administer_post_id'), 'administer_content', true); 13 13 $positions = get_post_meta(get_option('administer_post_id'), 'administer_positions', true); 14 14 15 // Default tab is 'content' 15 $plugindir = ABSPATH . PLUGINDIR .'/ ' . dirname(plugin_basename (__FILE__)) . '/'; 16 17 18 // $_GET['tab'] should be set in mf_queue_scripts, but still... 16 19 $tab = ($_GET['tab']) ? $_GET['tab'] : 'content'; 17 20 18 if ($tab == 'content' && !is_array($content)) $tab = 'upload';19 20 // If we're not installed, go to the settings for the setup.21 if (!administer_ok_to_go() && $tab != 'help') $tab = 'settings';22 23 // If there are not positions defined direct user to create some.24 if (empty($positions) && administer_ok_to_go() && $tab != 'settings' && $tab != 'help') $tab = 'positions';25 26 21 ?> 27 28 <link rel='stylesheet' href="<?php echo get_option('siteurl') . '/' . PLUGINDIR . '/' . dirname(plugin_basename (__FILE__)); ?>/ad-minister.css" type='text/css' />29 30 <script type='text/javascript' src="<?php echo get_option('siteurl') . '/' . WPINC; ?>/js/tw-sack.js?ver=1.6.1"></script>31 <script type='text/javascript' src="<?php echo get_option('siteurl') . '/' . WPINC; ?>/js/prototype.js?ver=1.5.1.1"></script>32 <script type='text/javascript' src="<?php echo get_option('siteurl') . '/' . WPINC; ?>/js/jquery/jquery.js"></script>33 <script type='text/javascript' src="<?php echo get_option('siteurl') . '/' . WPINC; ?>/js/quicktags.js"></script>34 22 35 23 <div class="wrap"> 36 <h2> 37 <div style="float: right; font-size: 18px; padding-right: 10px;"> 38 <a href="http://labs.dagensskiva.com/plugins/ad-minister/" style="border: 0px;" target="_blank"> 39 <img style="height: 50px" src="<?php echo get_option('siteurl') . '/' . PLUGINDIR . '/' . dirname(plugin_basename (__FILE__)); ?>/img/henrik.png"> 40 </a> 41 </div> 42 Ad-minister 43 </h2> 44 <ul id="submenu"> 24 <h2>Ad-minister</h2> 25 26 <ul class="tabs"> 45 27 <?php $url = 'edit.php?page=ad-minister'; ?> 46 <li><a <?php if ($tab == 'content') echo 'class=" current"'; ?> href="<?php echo $url; ?>&tab=content"><?php _e('Content'); ?></a></li>47 <li><a <?php if ($tab == 'upload') echo 'class=" current"'; ?> href="<?php echo $url; ?>&tab=upload"><?php _e('Create content'); ?></a></li>48 <li><a <?php if ($tab == 'positions') echo 'class=" current"'; ?>href="<?php echo $url; ?>&tab=positions"><?php _e('Positions/Widgets'); ?></a></li>49 <li><a <?php if ($tab == 'settings') echo 'class=" current"'; ?> href="<?php echo $url; ?>&tab=settings"><?php _e('Settings'); ?></a></li>50 <li><a <?php if ($tab == 'help') echo 'class=" current"'; ?> href="<?php echo $url; ?>&tab=help"><?php _e('Help'); ?>!</a></li>28 <li><a <?php if ($tab == 'content') echo 'class="tabs-current"'; ?> href="<?php echo $url; ?>&tab=content"><?php _e('Content'); ?></a></li> 29 <li><a <?php if ($tab == 'upload') echo 'class="tabs-current"'; ?> href="<?php echo $url; ?>&tab=upload"><?php _e('Create content'); ?></a></li> 30 <li><a <?php if ($tab == 'positions') echo 'class="tabs-current"'; ?>href="<?php echo $url; ?>&tab=positions"><?php _e('Positions/Widgets'); ?></a></li> 31 <li><a <?php if ($tab == 'settings') echo 'class="tabs-current"'; ?> href="<?php echo $url; ?>&tab=settings"><?php _e('Settings'); ?></a></li> 32 <li><a <?php if ($tab == 'help') echo 'class="tabs-current"'; ?> href="<?php echo $url; ?>&tab=help"><?php _e('Help'); ?>!</a></li> 51 33 </ul> 34 <div class="tabs-bottom"></div> 35 <div style="padding: 10px;"> 52 36 53 37 <?php 54 55 include('ad-minister-js.php');56 38 57 39 // Load the relevant tab … … 61 43 else if ($tab == 'help') include('ad-minister-help.php'); 62 44 else include('ad-minister-content.php'); 63 echo '</div>'; 64 } 65 66 function administer_content_template ($content, $index = 0) { echo administer_get_content_template($content, $index); } 67 function administer_get_content_template ($content, $index = 0) { 68 $url = get_option('siteurl') . '/' . PLUGINDIR . '/' . dirname(plugin_basename (__FILE__)); 69 70 $nbr = $content['id']; 71 72 // Get the position name 73 $position = stripslashes($content['position']); //p2m_meta('ad_position_' . $nbr); 74 if (!$position) $position = 'key_not_set'; 75 76 $show_checked = ($content['show'] == 'true') ? ' checked="checked"' : ''; 77 $title_edit = stripslashes($content['title']); 78 $title_show = ($title_edit) ? $title_edit : 'Title not set'; 79 // Handle Weight, handled internally as quota. 80 $weight = ($content['weight']) ? $content['weight'] : 'Automatic'; 81 82 $scheduele = $content['scheduele']; //p2m_meta('ad_scheduele_' . $nbr); 83 $scheduele_div = ($scheduele = str_replace(':', ' to ', $content['scheduele'])) ? '| <strong>Scheduele: </strong>' . $scheduele . '': ''; 84 $wrap_checked = ($content['wrap'] == 'true') ? ' checked="checked"' : ''; 85 $code = stripslashes($content['code']); 86 87 $class = ($index % 2) ? 'odd' : 'even'; 88 $html = ' 89 <div id="ad_%nbr%"> 90 <input type="hidden" id="ad_position_view_%nbr%" value="' . $position . '"> 91 <input type="hidden" id="ad_id_%nbr%" value="' . $content['id'] . '"> 92 <div id="ad_view_%nbr%" class="ad_view %class%"> 93 <div id="ad_position_view_div_%nbr%" class="position_view"> 94 95 <div class="notifier_content"><img id="aj_%nbr%" class="notifier_content" src="' . $url . '/img/rotating_arrow.gif" style="display: none;"></div> 96 97 <div style="float: right; margin-right: 10px;"> 98 <a href="#" onclick="p2m_edit_ad(%nbr%); return false;">Edit</a> | <a href="#" onclick="p2m_delete_ad(%nbr%); return false;">Delete</a> 99 </div> 100 101 <strong class="ftitle" id="ad_title_view_%nbr%">' . $title_show . '</strong> 102 </div> 103 <div style="background: #99ee99; padding: 10px;"> 104 <div> 105 <input id="ad_show_%nbr%" type="checkbox" onclick="p2m_toggle_show(%nbr%);" ' . $show_checked . ' /> <strong><label for="ad_show_%nbr%">Visible?</label></strong> | <strong>Weight:</strong> <span id="ad_quota_view_%nbr%">' . $weight . '</span> 106 107 <span id="ad_scheduele_view_%nbr%">' . $scheduele_div . '</span> 108 </div> </div> 109 <div id="ad_code_view_%nbr%" style="padding: 20px;">' . $code .' 110 </div> 111 </div> 112 113 114 <div id="ad_edit_%nbr%" class="ad_edit %class%" style="display: none;"> 115 <div class="position_view"> 116 <div class="notifier_content"><img id="aj_%nbr%" class="notifier_content" src="' . $url . '/img/rotating_arrow.gif" style="display: none;"></div> 117 118 <div style="float: right; margin-right: 10px;"> 119 <a href="#" onClick="p2m_save_ad(%nbr%); return false;">Save</a> 120 </div> 121 122 <label class="ad_field" for="ad_title_edit_%nbr%">Title: </label> 123 <div class="ad_field"><input class="ad_field" type="text" id="ad_title_edit_%nbr%" value="'. $title_edit . '"></div> 124 </div> 125 <div style="background: #99ee99; padding: 11px;"> 126 127 <label class="ad_field" for="ad_scheduele_edit_%nbr%">Scheduele: </label> 128 <div class="ad_field"><input class="ad_field" type="text" id="ad_scheduele_edit_%nbr%" name="ad_scheduele_edit_%nbr%" value="' . $content['scheduele'] . '"> (Optional)</div> 129 <label class="ad_field" for="ad_quota_edit_%nbr%">Weight: </label> 130 <div class="ad_field"><input class="ad_field_small" class="ad_field" type="text" id="ad_quota_edit_%nbr%" name="ad_quota_edit_%nbr%" value="' . $content['weight'] . '"> (Optional, should be a number) </div> 131 <label class="ad_field">Position key: </label> 132 <div>' . administer_position_select($nbr, $content['position']) . '</div> 133 <label for="ad_wrap_edit_%nbr%" class="ad_field">Use wrapper? </label> 134 <div class="ad_field"><input id="ad_wrap_edit_%nbr%" type="checkbox" ' . $wrap_checked . '></div> 135 136 137 </div> 138 <div class="code_edit"> 139 <textarea style="width: 100%; height: 200px;" id="ad_code_edit_%nbr%">' . $code. '</textarea> 140 </div> 141 </div> 142 </div> 143 '; 144 $html = str_replace('%nbr%', $nbr, $html); 145 $html = str_replace('%class%', $class, $html); 146 147 return $html; 148 } 149 // Position key: <input id="ad_position_edit_' . $nbr . '" type="text" style="width: 100px;" value="' . get_post_meta($ad_post_id, 'ad_position_' . $nbr, true) . '"> | <a href="#" onClick="p2m_save_ad(' . $nbr . '); return false;">Save</a> 45 echo '</div></div>'; 46 } 150 47 151 48 152 49 function administer_position_template ($position = array(), $nbr = 0) { echo administer_get_position_template($position, $nbr); } 153 50 function administer_get_position_template ($position = array(), $nbr = 0) { 154 $url = get_option('siteurl') . '/' . PLUGINDIR . '/' . dirname(plugin_basename (__FILE__));155 51 $key = $position['position']; // p2m_meta('position_key_' . $nbr); 156 52 $desc = $position['description']; //p2m_meta('position_desc_' . $nbr); 157 158 // $schecked = (p2m_meta('position_widget_' . $nbr) == 'true') ? ' checked="checked"' : ''; 159 53 160 54 // Set up css formatting 161 $class = ($nbr % 2) ? 'odd' : 'even'; 162 if ($nbr == 9999) $class = 'new'; 163 $style_view = (!$key) ? ' style="display: none;"': ''; 164 $style_edit = (!$key) ? '' : ' style="display: none;"'; 55 $class = ($nbr % 2) ? '' : 'alternate'; 165 56 $html = ' 166 <tr class="%class%" id="position_view_%nbr%" ' . $style_view . '>167 <td id="position_key_%nbr%">%key%</td>168 <td id="position_desc_%nbr%">%desc%</td>169 <td> <span id="position_before_%nbr%">' . htmlentities($position['before']) . '</span> <span id="position_after_%nbr%">' . htmlentities($position['after']) . '</span></td>57 <tr class="%class%"> 58 <td>' . $key . '</td> 59 <td>' . $desc . '</td> 60 <td>' . htmlentities($position['before']) . ' ' . htmlentities($position['after']) . '</td> 170 61 <td> 171 %edit_link%172 <a href=" #" onclick="p2m_delete_position(\'%nbr%\'); return false;">Remove</a>62 <a href="%url_edit%">' . __('Edit', 'ad-minister') . '</a> | 63 <a href="%url_remove%">' . __('Remove', 'ad-minister') . '</a> 173 64 </td> 174 <td><img id="aj_%nbr%" class="notifier" src="%url%/img/rotating_arrow.gif" style="display: none;"></td>175 65 </tr> 176 177 <tr class="%class%" id="position_edit_%nbr%" ' . $style_edit . '> 178 <td> 179 Name: <input class="position" type="text" id="position_key_edit_%nbr%" value="%key%"> 180 Description:<input class="position" type="text" id="position_desc_edit_%nbr%" value="%desc%"> 181 182 </td> 183 <td> 184 Code before: <input class="position" type="text" id="position_before_edit_%nbr%" value="' . htmlspecialchars($position['before']) . '"> 185 Code after: <input class="position" type="text" id="position_after_edit_%nbr%" value="' . htmlspecialchars($position['after']) . '"> 186 187 </td> 188 <td>' . $type . '</td> 189 <td><a href="#" onclick="p2m_save_position(%nbr%); return false;">Save</a></td> 190 <td><img id="aj_%nbr%" class="notifier" src="%url%/img/rotating_arrow.gif" style="display: none;"></td> 191 </tr> 192 '; 66 '; 67 193 68 // Inject template values 194 $edit_link = ($position['type'] != 'template') ? '<a href="#" onclick="p2m_edit_position(%nbr%); return false;">Edit</a> |' : ''; 195 $html = str_replace('%edit_link%', $edit_link, $html); 196 $html = str_replace('%nbr%', $nbr, $html); 197 $html = str_replace('%key%', $key, $html); 198 $html = str_replace('%desc%', $desc, $html); 199 $html = str_replace('%url%', $url, $html); 69 $url = get_option('siteurl') . '/' . PLUGINDIR . '/' . dirname(plugin_basename (__FILE__)); 70 $html = str_replace('%url_edit%', get_option('siteurl') . '/wp-admin/edit.php?page=' . dirname(plugin_basename(__FILE__)) . '&tab=positions&key=' . urlencode($key) . '&action=edit', $html); 71 $html = str_replace('%url_remove%', get_option('siteurl') . '/wp-admin/edit.php?page=' . dirname(plugin_basename(__FILE__)) . '&tab=positions&key=' . urlencode($key) . '&action=delete', $html); 200 72 $html = str_replace('%class%', $class, $html); 73 201 74 return $html; 202 75 } … … 208 81 */ 209 82 function administer_position_select ($nbr = '', $value = '') { 210 // $saved = administer_get_saved_numbers('position_key_'); 83 84 if ($value == '') $value = '-'; 85 211 86 $html = '<select name="position" id ="ad_position_edit_' . $nbr . '">'; 212 87 … … 214 89 215 90 $positions = get_post_meta(get_option('administer_post_id'), 'administer_positions', true); 91 if (!is_array($positions)) $positions = array(); 216 92 $position_keys = array_keys($positions); 217 93 sort($position_keys); … … 241 117 ** some content. 242 118 */ 243 function administer_nbr_to_save($ prefix = 'ad_code_') {119 function administer_nbr_to_save($what = 'content') { 244 120 245 121 $content = get_post_meta(get_option('administer_post_id'), 'administer_content', true); 246 122 247 if (!is_array($content)) return '0';248 if (empty($content)) return '0';123 if (!is_array($content)) return 0; 124 if (empty($content)) return 0; 249 125 250 126 // Store the ids in a separate array … … 258 134 259 135 /* 260 ** ok_to_go()136 ** administer_ok_to_go() 261 137 ** 262 138 ** Checks if the supplied post/page ID exists. … … 268 144 } 269 145 270 /** 271 *** administer_delete_position ( ) 272 *** 273 *** Ajax function 274 **/ 275 function administer_delete_position () { 276 277 // Parse and mould the ajax data. 278 $args = administer_parse_ajax_data(); 279 $position = $args['position']; 280 281 $positions = get_post_meta(get_option('administer_post_id'), 'administer_positions', true); 282 unset($positions[$position]); 283 284 update_post_meta(get_option('administer_post_id'), 'administer_positions', $positions); 285 286 if ($notification_domid = $_REQUEST['notification_domid']) die("p2m_ready('${notification_domid}');"); 287 } 288 289 /** 290 *** administer_delete_content ( ) 291 *** 292 *** Ajax function. 293 **/ 294 function administer_delete_content () { 295 296 // Parse and mould the ajax data. 297 $args = administer_parse_ajax_data(); 298 $id = $args['id']; 299 300 $content = get_post_meta(get_option('administer_post_id'), 'administer_content', true); 301 unset($content[$id]); 302 303 update_post_meta(get_option('administer_post_id'), 'administer_content', $content); 304 305 if ($notification_domid = $_REQUEST['notification_domid']) die("p2m_ready('${notification_domid}');"); 306 } 307 308 function administer_parse_args($content, $default) { 309 // This is equivalent to array_intersect_key 310 foreach (array_keys($content) as $key) 311 if (!isset($default)) 312 unset($content[$key]); 313 return $content; 314 } 315 316 /** 317 *** administer_save_content ( ) 318 *** 319 *** Ajax function. 320 **/ 321 322 323 324 function administer_save_content () { 325 326 // Parse and mould the ajax data. 327 $content_new = administer_parse_ajax_data(); 328 $default = array('title' => '', 'code' => '', 'scheduele' => '', 'weight' => '', 'id' => '', 'show' => '', 'wrap' => '', 'position' => ''); 329 $content_new = administer_parse_args($content_new, $default); 330 331 332 // Replace the data 333 $content = get_post_meta(get_option('administer_post_id'), 'administer_content', true); 334 $content[$content_new['id']] = $content_new; 335 336 // Save data to DB 337 update_post_meta(get_option('administer_post_id'), 'administer_content', $content); 338 339 if ($notification_domid = $_REQUEST['notification_domid']) die("p2m_ready('${notification_domid}');"); 340 341 } 342 343 /** 344 *** administer_parse_ajax_data ( ) 345 *** 346 *** Re-structure the variables passed through xmlhttprequest into a associative array. 347 **/ 348 function administer_parse_ajax_data () { 349 // Refactor the data we want to save 350 $content_new = array(); 351 for ($i = 0; $i < $_REQUEST['nbr_keys']; $i++) { 352 $key = $_REQUEST['key_' . $i]; 353 $value = stripslashes($_REQUEST['value_' . $i]); 354 $content_new[$key] = $value; 355 } 356 return $content_new; 357 } 358 /** 359 *** administer_save_position ( ) 360 *** 361 *** Ajax function. 362 **/ 363 function administer_save_position () { 364 365 // Get and filter out variables we don't want 366 $position = administer_parse_ajax_data(); 367 $position_old = $position['position_old']; 368 $default = array('position' => '', 'description' => '', 'before' => '', 'after' => '', 'type' => ''); 369 $position = administer_parse_args($position, $default); 370 371 // Get the stored positions 372 $positions = get_post_meta(get_option('administer_post_id'), 'administer_positions', true); 373 if (!is_array($positions)) $positions = array(); 374 375 // Remove old and add new data 376 unset($positions[$position_old]); 377 $positions[$position['position']] = $position; 378 379 // Update our Custom Fields 380 if (!add_post_meta(get_option('administer_post_id'), 'administer_positions', $positions, true)) 381 update_post_meta(get_option('administer_post_id'), 'administer_positions', $positions); 382 383 // Stop the spinning 384 if ($notification_domid = $_REQUEST['notification_domid']) die("p2m_ready('${notification_domid}');"); 385 } 386 387 388 146 /* 147 ** adminiseter_content_age() 148 ** 149 ** Calculates the age of a content. Returns a
